lib: add stream class UID property
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 7 May 2024 20:41:55 +0000 (16:41 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Add a UID property to stream class objects.  This is needed to
support CTF 2.

Philippe updated the documentation.

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

include/babeltrace2/trace-ir/stream-class.h
src/lib/lib-logging.c
src/lib/trace-ir/stream-class.c
src/lib/trace-ir/stream-class.h

index 251f220d84c1a05e760e3029aa0bea26029cc60c..30a147ebdca06883b2a6dd535aadd0f080910c83 100644 (file)
@@ -198,6 +198,21 @@ A stream class has the following properties:
     Use bt_stream_class_set_name() and bt_stream_class_get_name().
   </dd>
 
+  <dt>
+    \anchor api-tir-stream-cls-prop-uid
+    \bt_dt_opt UID
+    (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>
+    <a href="https://en.wikipedia.org/wiki/Unique_identifier">Unique identifier</a>
+    (UID) of the stream class.
+
+    Use bt_stream_class_set_uid() and
+    bt_stream_class_get_uid().
+  </dd>
+
   <dt>
     \anchor api-tir-stream-cls-prop-def-clock-cls
     \bt_dt_opt Default clock class
@@ -519,6 +534,9 @@ On success, the returned stream class has the following property values:
   <tr>
     <td>\ref api-tir-stream-cls-prop-name "Name"
     <td>\em None
+  <tr>
+    <td>\bt_mip version&nbsp;1: \ref api-tir-stream-cls-prop-uid "UID"
+    <td>\em None
   <tr>
     <td>\ref api-tir-stream-cls-prop-def-clock-cls "Default clock class"
     <td>\em None
@@ -613,6 +631,9 @@ On success, the returned stream class has the following property values:
   <tr>
     <td>\ref api-tir-stream-cls-prop-name "Name"
     <td>\em None
+  <tr>
+    <td>\bt_mip version&nbsp;1: \ref api-tir-stream-cls-prop-uid "UID"
+    <td>\em None
   <tr>
     <td>\ref api-tir-stream-cls-prop-def-clock-cls "Default clock class"
     <td>\em None
@@ -1004,6 +1025,82 @@ If \bt_p{stream_class} has no name, this function returns \c NULL.
 extern const char *bt_stream_class_get_name(
                const bt_stream_class *stream_class) __BT_NOEXCEPT;
 
+/*!
+@brief
+    Status codes for bt_stream_class_set_uid().
+*/
+typedef enum bt_stream_class_set_uid_status {
+       /*!
+       @brief
+           Success.
+       */
+       BT_STREAM_CLASS_SET_UID_STATUS_OK                       = __BT_FUNC_STATUS_OK,
+
+       /*!
+       @brief
+           Out of memory.
+       */
+       BT_STREAM_CLASS_SET_UID_STATUS_MEMORY_ERROR     = __BT_FUNC_STATUS_MEMORY_ERROR,
+} bt_stream_class_set_uid_status;
+
+/*!
+@brief
+    Sets the
+    <a href="https://en.wikipedia.org/wiki/Unique_identifier">unique identifier</a> (UID)
+    of the stream class \bt_p{stream_class} to
+    a copy of \bt_p{uid}.
+
+See the \ref api-tir-stream-cls-prop-uid "UID" property.
+
+@param[in] stream_class
+    Stream class of which to set the UID to \bt_p{uid}.
+@param[in] name
+    New UID of \bt_p{stream_class} (copied).
+
+@retval #BT_STREAM_CLASS_SET_UID_STATUS_OK
+    Success.
+@retval #BT_STREAM_CLASS_SET_UID_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{uid}
+
+@sa bt_stream_class_get_uid() &mdash;
+    Returns the UID of a stream class.
+*/
+extern bt_stream_class_set_uid_status bt_stream_class_set_uid(
+               bt_stream_class *stream_class, const char *uid) __BT_NOEXCEPT;
+
+/*!
+@brief
+    Returns the UID of the stream class \bt_p{stream_class}.
+
+See the \ref api-tir-stream-cls-prop-uid "UID" property.
+
+If \bt_p{stream_class} has no UID, this function returns \c NULL.
+
+@param[in] stream_class
+    Stream class of which to get the UID.
+
+@returns
+    @parblock
+    UID 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_uid() &mdash;
+    Sets the UID of a stream class.
+*/
+extern const char *bt_stream_class_get_uid(
+               const bt_stream_class *stream_class) __BT_NOEXCEPT;
+
 /*!
 @brief
     Status codes for bt_stream_class_set_default_clock_class().
index e49b5e735ab4e8eadd473a1af6f77e34d0c10d39..0486756989e0f64fa78282322e5c1068b16e87b1 100644 (file)
@@ -647,6 +647,10 @@ static inline void format_stream_class(char **buf_ch, bool extended,
                BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class->name));
        }
 
+       if (stream_class->uid) {
+               BUF_APPEND(", %suid=\"%s\"", PRFIELD(stream_class->uid));
+       }
+
        if (!extended) {
                return;
        }
index 152ae909f762a9e180ef9c08917f16b0407b8cbb..9f1d2dd538ce739d6d45ecb02df5057b95a723ba 100644 (file)
@@ -49,6 +49,7 @@ void destroy_stream_class(struct bt_object *obj)
 
        g_free(stream_class->ns);
        g_free(stream_class->name);
+       g_free(stream_class->uid);
        BT_LOGD_STR("Putting packet context field class.");
        BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc);
        BT_LOGD_STR("Putting event common context field class.");
@@ -236,6 +237,30 @@ enum bt_stream_class_set_name_status bt_stream_class_set_name(
        return BT_FUNC_STATUS_OK;
 }
 
+BT_EXPORT
+const char *bt_stream_class_get_uid(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->uid;
+}
+
+BT_EXPORT
+enum bt_stream_class_set_uid_status bt_stream_class_set_uid(
+               struct bt_stream_class *stream_class,
+               const char *uid)
+{
+       BT_ASSERT_PRE_NO_ERROR();
+       BT_ASSERT_PRE_SC_NON_NULL(stream_class);
+       BT_ASSERT_PRE_NAME_NON_NULL(uid);
+       BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
+       BT_ASSERT_PRE_SC_MIP_VERSION_GE(stream_class, 1);
+       g_free(stream_class->uid);
+       stream_class->uid = g_strdup(uid);
+       BT_LIB_LOGD("Set stream class's UID: %!+S", stream_class);
+       return BT_FUNC_STATUS_OK;
+}
+
 BT_EXPORT
 uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class)
 {
index c44c121baac2e1b000b634fc288648816dec6a24..17aa48a0d51f53e2786818ce4bed4d43baa9c90b 100644 (file)
@@ -25,6 +25,7 @@ struct bt_stream_class {
 
        gchar *ns;
        gchar *name;
+       gchar *uid;
 
        uint64_t id;
        bool assigns_automatic_event_class_id;
This page took 0.028192 seconds and 4 git commands to generate.