lib: add namespace property to stream classes
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 7 May 2024 19:51:03 +0000 (15:51 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Add the namespace property to stream classes, with the intent to support
namespace properties on data stream classes in CTF2‑SPEC‑2.0 [1].

Copy everything from the existing name property, and rename it to
"namespace."

Both new public functions have a `MIP >= 1` pre-condition check.

Philippe updated the documentation.

[1] https://diamon.org/ctf/CTF2-SPEC-2.0.html

Change-Id: Ibdfc9c924fc6347f5020c5ba06f14a7737cbf76b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7380
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12688

doc/api/libbabeltrace2/Doxyfile.in
include/babeltrace2/trace-ir/stream-class.h
src/lib/assert-cond.h
src/lib/lib-logging.c
src/lib/trace-ir/stream-class.c
src/lib/trace-ir/stream-class.h

index 64a4e89be0857d46314f320553ef01afe0af767d..a18353a14769bd8ea5d1da0525653e475e50f96a 100644 (file)
@@ -132,6 +132,7 @@ ALIASES                += bt_pre_fc_with_mip{2}="@pre \bt_p{\1} was created from
 ALIASES                += bt_pre_field_with_mip{2}="@pre The class of \bt_p{\1} was created from a \bt_trace_cls which was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version&nbsp;\2."
 ALIASES                += bt_pre_trace_with_mip{2}="@pre The \link api-tir-trace-cls class\endlink of \bt_p{\1} was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version&nbsp;\2."
 ALIASES                += bt_pre_clock_cls_with_mip{2}="@pre \bt_p{\1} was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version&nbsp;\2."
+ALIASES                += bt_pre_stream_cls_with_mip{2}="@pre \bt_p{\1} was created from a \bt_trace_cls which was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version&nbsp;\2."
 
 # Aliases: field class object types: singular
 ALIASES                += bt_fc="\link api-tir-fc field class\endlink"
index e74d3cc3593996ede96465f67b7b9dc5433ee487..251f220d84c1a05e760e3029aa0bea26029cc60c 100644 (file)
@@ -177,6 +177,20 @@ A stream class has the following properties:
     Get a stream class's numeric ID with bt_stream_class_get_id().
   </dd>
 
+  <dt>
+    \anchor api-tir-stream-cls-prop-ns
+    \bt_dt_opt Namespace
+    (only available when the parent \bt_trace_cls was created
+    from a \bt_comp which belongs to a trace processing \bt_graph
+    with the effective \bt_mip version&nbsp;1)
+  </dt>
+  <dd>
+    Namespace of the stream class.
+
+    Use bt_stream_class_set_namespace() and
+    bt_stream_class_get_namespace().
+  </dd>
+
   <dt>\anchor api-tir-stream-cls-prop-name \bt_dt_opt Name</dt>
   <dd>
     Name of the stream class.
@@ -499,6 +513,9 @@ On success, the returned stream class has the following property values:
   <tr>
     <td>\ref api-tir-stream-cls-prop-id "Numeric ID"
     <td>Automatically assigned by \bt_p{trace_class}
+  <tr>
+    <td>\bt_mip version&nbsp;1: \ref api-tir-stream-cls-prop-ns "namespace"
+    <td>\em None
   <tr>
     <td>\ref api-tir-stream-cls-prop-name "Name"
     <td>\em None
@@ -590,6 +607,9 @@ On success, the returned stream class has the following property values:
   <tr>
     <td>\ref api-tir-stream-cls-prop-id "Numeric ID"
     <td>\bt_p{id}
+  <tr>
+    <td>\bt_mip version&nbsp;1: \ref api-tir-stream-cls-prop-ns "namespace"
+    <td>\em None
   <tr>
     <td>\ref api-tir-stream-cls-prop-name "Name"
     <td>\em None
@@ -838,6 +858,80 @@ See the \ref api-tir-stream-cls-prop-id "numeric ID" property.
 extern uint64_t bt_stream_class_get_id(
                const bt_stream_class *stream_class) __BT_NOEXCEPT;
 
+/*!
+@brief
+    Status codes for bt_stream_class_set_namespace().
+*/
+typedef enum bt_stream_class_set_namespace_status {
+       /*!
+       @brief
+           Success.
+       */
+       BT_STREAM_CLASS_SET_NAMESPACE_STATUS_OK                 = __BT_FUNC_STATUS_OK,
+
+       /*!
+       @brief
+           Out of memory.
+       */
+       BT_STREAM_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR       = __BT_FUNC_STATUS_MEMORY_ERROR,
+} bt_stream_class_set_namespace_status;
+
+/*!
+@brief
+    Sets the namespace of the stream class \bt_p{stream_class} to
+    a copy of \bt_p{ns}.
+
+See the \ref api-tir-stream-cls-prop-ns "namespace" property.
+
+@param[in] stream_class
+    Stream class of which to set the namespace to \bt_p{ns}.
+@param[in] name
+    New namespace of \bt_p{stream_class} (copied).
+
+@retval #BT_STREAM_CLASS_SET_NAMESPACE_STATUS_OK
+    Success.
+@retval #BT_STREAM_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR
+    Out of memory.
+
+@bt_pre_not_null{stream_class}
+@bt_pre_hot{stream_class}
+@bt_pre_stream_cls_with_mip{stream_class, 1}
+@bt_pre_not_null{ns}
+
+@sa bt_stream_class_get_namespace() &mdash;
+    Returns the namespace of a stream class.
+*/
+extern bt_stream_class_set_namespace_status bt_stream_class_set_namespace(
+               bt_stream_class *stream_class, const char *ns) __BT_NOEXCEPT;
+
+/*!
+@brief
+    Returns the namespace of the stream class \bt_p{stream_class}.
+
+See the \ref api-tir-stream-cls-prop-ns "namespace" property.
+
+If \bt_p{stream_class} has no namespace, this function returns \c NULL.
+
+@param[in] stream_class
+    Stream class of which to get the namespace.
+
+@returns
+    @parblock
+    Namespace of \bt_p{stream_class}, or \c NULL if none.
+
+    The returned pointer remains valid as long as \bt_p{stream_class}
+    is not modified.
+    @endparblock
+
+@bt_pre_not_null{stream_class}
+@bt_pre_stream_cls_with_mip{stream_class, 1}
+
+@sa bt_stream_class_set_namespace() &mdash;
+    Sets the namespace of a stream class.
+*/
+extern const char *bt_stream_class_get_namespace(
+               const bt_stream_class *stream_class) __BT_NOEXCEPT;
+
 /*!
 @brief
     Status codes for bt_stream_class_set_name().
index 368164dd77d3f82baf260147271b20d96cdd5a75..a666c52a0b7e4f9ea85425b2d5abfe132bea3974 100644 (file)
 #define BT_ASSERT_PRE_TC_MIP_VERSION_GE(_trace_class, _val)            \
        BT_ASSERT_PRE_MIP_VERSION_GE((_trace_class)->mip_version, _val)
 
+/*
+ * Asserts that the effective MIP version for `_stream_class` is greater than or
+ * equal to `_val`.
+ */
+#define BT_ASSERT_PRE_SC_MIP_VERSION_GE(_stream_class, _val)                   \
+       BT_ASSERT_PRE_TC_MIP_VERSION_GE(                                        \
+               bt_stream_class_borrow_trace_class_inline(_stream_class),       \
+               _val)
+
 /*
  * Asserts that the effective MIP version for `_field_class` is equal to `_val`.
  */
 #define BT_ASSERT_PRE_FC_MIP_VERSION_EQ(_field_class, _val)            \
        BT_ASSERT_PRE_MIP_VERSION_EQ((_field_class)->mip_version, _val)
 
-/* Asserts that the effective MIP version for `_field_class` is equal to `_val`. */
+/*
+ * Asserts that the effective MIP version for `_field_class` is equal to `_val`.
+ */
 #define BT_ASSERT_PRE_DEV_FC_MIP_VERSION_EQ(_field_class, _val)                \
        BT_ASSERT_PRE_DEV_MIP_VERSION_EQ((_field_class)->mip_version, _val)
 
 #define _BT_ASSERT_PRE_NAMESPACE_NAME  "Namespace"
 #define _BT_ASSERT_PRE_NAMESPACE_ID    "namespace"
 
-#define BT_ASSERT_PRE_NAMESPACE_NON_NULL(_name)                                \
-       BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_NAMESPACE_ID, (_name),    \
+#define BT_ASSERT_PRE_NAMESPACE_NON_NULL(_namespace)                           \
+       BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_NAMESPACE_ID, (_namespace),       \
                _BT_ASSERT_PRE_NAMESPACE_NAME)
 
 #define _BT_ASSERT_PRE_DESCR_NAME      "Description"
index 9128645886930554e5d62262ec0a38d29ec12fe9..3342b73910f96744bd6fd339ab8ed36fe1f02e8f 100644 (file)
@@ -635,9 +635,12 @@ static inline void format_stream_class(char **buf_ch, bool extended,
 
        BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id));
 
+       if (stream_class->ns) {
+               BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(stream_class->ns));
+       }
+
        if (stream_class->name) {
-               BUF_APPEND(", %sname=\"%s\"",
-                       PRFIELD(stream_class->name));
+               BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class->name));
        }
 
        if (!extended) {
index 47e5e1558f1d17d5aa336111fe2ecb987d3cf4d7..152ae909f762a9e180ef9c08917f16b0407b8cbb 100644 (file)
@@ -47,6 +47,7 @@ void destroy_stream_class(struct bt_object *obj)
                stream_class->event_classes = NULL;
        }
 
+       g_free(stream_class->ns);
        g_free(stream_class->name);
        BT_LOGD_STR("Putting packet context field class.");
        BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc);
@@ -188,6 +189,31 @@ const struct bt_trace_class *bt_stream_class_borrow_trace_class_const(
        return bt_stream_class_borrow_trace_class((void *) stream_class);
 }
 
+BT_EXPORT
+const char *bt_stream_class_get_namespace(
+               const struct bt_stream_class *stream_class)
+{
+       BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class);
+       BT_ASSERT_PRE_SC_MIP_VERSION_GE(stream_class, 1);
+       return stream_class->ns;
+}
+
+BT_EXPORT
+enum bt_stream_class_set_namespace_status bt_stream_class_set_namespace(
+               struct bt_stream_class *stream_class,
+               const char *ns)
+{
+       BT_ASSERT_PRE_NO_ERROR();
+       BT_ASSERT_PRE_SC_NON_NULL(stream_class);
+       BT_ASSERT_PRE_SC_MIP_VERSION_GE(stream_class, 1);
+       BT_ASSERT_PRE_NAMESPACE_NON_NULL(ns);
+       BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
+       g_free(stream_class->ns);
+       stream_class->ns = g_strdup(ns);
+       BT_LIB_LOGD("Set stream class's namespace: %!+S", stream_class);
+       return BT_FUNC_STATUS_OK;
+}
+
 BT_EXPORT
 const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class)
 {
index 7ebb1d02b34f552e0680998a1e014e5562114a70..c44c121baac2e1b000b634fc288648816dec6a24 100644 (file)
@@ -23,6 +23,7 @@ struct bt_stream_class {
        /* Owned by this */
        struct bt_value *user_attributes;
 
+       gchar *ns;
        gchar *name;
 
        uint64_t id;
This page took 0.029305 seconds and 4 git commands to generate.