lib: add clock class namespace and UID properties
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 7 May 2024 20:18:47 +0000 (16:18 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Add the namespace and UID properties to clock class objects.  This is
needed to support CTF 2.

Philippe updated the documentation.

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

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

index c7f25fdb5b5eeeec0d9679a5ed4b03639eb8cfbf..1222547bfaab29a35aaef0ee34d15fe2f11fbca1 100644 (file)
@@ -876,6 +876,80 @@ See the \ref api-tir-clock-cls-prop-origin "origin" property.
 extern const char *bt_clock_class_get_origin_uid(
        const bt_clock_class *clock_class) __BT_NOEXCEPT;
 
+/*!
+@brief
+    Status codes for bt_clock_class_set_namespace().
+*/
+typedef enum bt_clock_class_set_namespace_status {
+       /*!
+       @brief
+           Success.
+       */
+       BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_OK                  = __BT_FUNC_STATUS_OK,
+
+       /*!
+       @brief
+           Out of memory.
+       */
+       BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR        = __BT_FUNC_STATUS_MEMORY_ERROR,
+} bt_clock_class_set_namespace_status;
+
+/*!
+@brief
+    Sets the namespace of the clock class \bt_p{clock_class} to
+    a copy of \bt_p{ns}.
+
+See the \ref api-tir-clock-cls-prop-iden "identity" property.
+
+@param[in] clock_class
+    Clock class of which to set the namespace to \bt_p{ns}.
+@param[in] namespace
+    New namespace of \bt_p{clock_class} (copied).
+
+@retval #BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_OK
+    Success.
+@retval #BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR
+    Out of memory.
+
+@bt_pre_not_null{clock_class}
+@bt_pre_hot{clock_class}
+@bt_pre_clock_cls_with_mip{clock_class, 1}
+@bt_pre_not_null{namespace}
+
+@sa bt_clock_class_get_namespace() &mdash;
+    Returns the namespace of a clock class.
+*/
+extern bt_clock_class_set_namespace_status bt_clock_class_set_namespace(
+               bt_clock_class *clock_class, const char *ns) __BT_NOEXCEPT;
+
+/*!
+@brief
+    Returns the namespace of the clock class \bt_p{clock_class}.
+
+See the \ref api-tir-clock-cls-prop-iden "identity" property.
+
+If \bt_p{clock_class} has no namespace, this function returns \c NULL.
+
+@param[in] clock_class
+    Clock class of which to get the namespace.
+
+@returns
+    @parblock
+    Namespace of \bt_p{clock_class}, or \c NULL if none.
+
+    The returned pointer remains valid as long as \bt_p{clock_class}
+    is not modified.
+    @endparblock
+
+@bt_pre_not_null{clock_class}
+@bt_pre_clock_cls_with_mip{clock_class, 1}
+
+@sa bt_clock_class_set_namespace() &mdash;
+    Sets the namespace of a clock class.
+*/
+extern const char *bt_clock_class_get_namespace(
+               const bt_clock_class *clock_class) __BT_NOEXCEPT;
+
 /*!
 @brief
     Status codes for bt_clock_class_set_name().
@@ -948,6 +1022,81 @@ If \bt_p{clock_class} has no name, this function returns \c NULL.
 extern const char *bt_clock_class_get_name(
                const bt_clock_class *clock_class) __BT_NOEXCEPT;
 
+/*!
+@brief
+    Status codes for bt_clock_class_set_uid().
+*/
+typedef enum bt_clock_class_set_uid_status {
+       /*!
+       @brief
+           Success.
+       */
+       BT_CLOCK_CLASS_SET_UID_STATUS_OK                = __BT_FUNC_STATUS_OK,
+
+       /*!
+       @brief
+           Out of memory.
+       */
+       BT_CLOCK_CLASS_SET_UID_STATUS_MEMORY_ERROR      = __BT_FUNC_STATUS_MEMORY_ERROR,
+} bt_clock_class_set_uid_status;
+
+/*!
+@brief
+    Sets the
+    <a href="https://en.wikipedia.org/wiki/Unique_identifier">unique identifier</a>
+    (UID) of the clock class \bt_p{clock_class} to a copy of \bt_p{uid}.
+
+See the \ref api-tir-clock-cls-prop-iden "identity" property.
+
+@param[in] clock_class
+    Clock class of which to set the UID to \bt_p{uid}.
+@param[in] UID
+    New UID of \bt_p{clock_class} (copied).
+
+@retval #BT_CLOCK_CLASS_SET_UID_STATUS_OK
+    Success.
+@retval #BT_CLOCK_CLASS_SET_UID_STATUS_MEMORY_ERROR
+    Out of memory.
+
+@bt_pre_not_null{clock_class}
+@bt_pre_hot{clock_class}
+@bt_pre_clock_cls_with_mip{clock_class, 1}
+@bt_pre_not_null{uid}
+
+@sa bt_clock_class_get_uid() &mdash;
+    Returns the UID of a clock class.
+*/
+extern bt_clock_class_set_uid_status bt_clock_class_set_uid(
+               bt_clock_class *clock_class, const char *uid) __BT_NOEXCEPT;
+
+/*!
+@brief
+    Returns the UID of the clock class \bt_p{clock_class}.
+
+See the \ref api-tir-clock-cls-prop-iden "identity" property.
+
+If \bt_p{clock_class} has no UID, this function returns \c NULL.
+
+@param[in] clock_class
+    Clock class of which to get the UID.
+
+@returns
+    @parblock
+    UID of \bt_p{clock_class}, or \c NULL if none.
+
+    The returned pointer remains valid as long as \bt_p{clock_class}
+    is not modified.
+    @endparblock
+
+@bt_pre_not_null{clock_class}
+@bt_pre_clock_cls_with_mip{clock_class, 1}
+
+@sa bt_clock_class_set_uid() &mdash;
+    Sets the UID of a clock class.
+*/
+extern const char *
+bt_clock_class_get_uid(const bt_clock_class *clock_class) __BT_NOEXCEPT;
+
 /*!
 @brief
     Status codes for bt_clock_class_set_description().
index f87a748f835698f77371c3958fd8c4160f5d43a5..30cf4736661d42b76f51498ca0d9707339f75c39 100644 (file)
@@ -884,10 +884,18 @@ static inline void format_clock_class(char **buf_ch, bool extended,
 {
        char tmp_prefix[TMP_PREFIX_LEN];
 
+       if (clock_class->ns) {
+               BUF_APPEND(", %snamepace=\"%s\"", PRFIELD(clock_class->ns));
+       }
+
        if (clock_class->name) {
                BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name));
        }
 
+       if (clock_class->uid) {
+               BUF_APPEND(", %suid=\"%s\"", PRFIELD(clock_class->uid));
+       }
+
        BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency));
 
        if (!extended) {
index 2939b5a8550f382d7aa3545bb4271fb1ef6e4ec4..bb75fb9c13d0dce26a5d395042043239685c8866 100644 (file)
@@ -69,7 +69,9 @@ void destroy_clock_class(struct bt_object *obj)
        BT_LIB_LOGD("Destroying clock class: %!+K", clock_class);
        BT_OBJECT_PUT_REF_AND_RESET(clock_class->user_attributes);
 
+       g_free(clock_class->ns);
        g_free(clock_class->name);
+       g_free(clock_class->uid);
        g_free(clock_class->description);
        free_clock_class_origin_data(clock_class);
        bt_object_pool_finalize(&clock_class->cs_pool);
@@ -164,6 +166,30 @@ end:
        return clock_class;
 }
 
+BT_EXPORT
+const char *bt_clock_class_get_namespace(
+               const struct bt_clock_class *clock_class)
+{
+       BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(clock_class);
+       BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1);
+       return clock_class->ns;
+}
+
+BT_EXPORT
+enum bt_clock_class_set_namespace_status bt_clock_class_set_namespace(
+               struct bt_clock_class *clock_class, const char *ns)
+{
+       BT_ASSERT_PRE_NO_ERROR();
+       BT_ASSERT_PRE_CLK_CLS_NON_NULL(clock_class);
+       BT_ASSERT_PRE_NAME_NON_NULL(ns);
+       BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class);
+       BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1);
+       g_free(clock_class->ns);
+       clock_class->ns = g_strdup(ns);
+       BT_LIB_LOGD("Set clock class's namespace: %!+K", clock_class);
+       return BT_FUNC_STATUS_OK;
+}
+
 BT_EXPORT
 const char *bt_clock_class_get_name(const struct bt_clock_class *clock_class)
 {
@@ -185,6 +211,30 @@ enum bt_clock_class_set_name_status bt_clock_class_set_name(
        return BT_FUNC_STATUS_OK;
 }
 
+BT_EXPORT
+const char *bt_clock_class_get_uid(const struct bt_clock_class *clock_class)
+{
+       BT_ASSERT_PRE_NO_ERROR();
+       BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(clock_class);
+       BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1);
+       return clock_class->uid;
+}
+
+BT_EXPORT
+enum bt_clock_class_set_uid_status bt_clock_class_set_uid(
+               struct bt_clock_class *clock_class, const char *uid)
+{
+       BT_ASSERT_PRE_NO_ERROR();
+       BT_ASSERT_PRE_CLK_CLS_NON_NULL(clock_class);
+       BT_ASSERT_PRE_NAME_NON_NULL(uid);
+       BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class);
+       BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1);
+       g_free(clock_class->uid);
+       clock_class->uid = g_strdup(uid);
+       BT_LIB_LOGD("Set clock class's UID: %!+K", clock_class);
+       return BT_FUNC_STATUS_OK;
+}
+
 BT_EXPORT
 const char *bt_clock_class_get_description(
                const struct bt_clock_class *clock_class)
index bca58088030ec4d29ec4b22ea301101734cc5ec1..e4b88a1f7a466038b4d5a09e533b2e12505c567e 100644 (file)
@@ -30,7 +30,9 @@ struct bt_clock_class {
        /* Owned by this */
        struct bt_value *user_attributes;
 
+       gchar *ns;
        gchar *name;
+       gchar *uid;
        gchar *description;
 
        uint64_t frequency;
This page took 0.027471 seconds and 4 git commands to generate.