X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Ftrace-ir%2Fclock-class.c;h=8a3640bcac56fc8592ced72f615782b33c9c0cc0;hb=7704a0af9f2275321f8294df8c02f8a299b3134e;hp=fb0d108c502bad23b157c7b9f843cf29e33afeea;hpb=790240ebca89a45e300dbd5b1b2fe585bf66283d;p=babeltrace.git diff --git a/src/lib/trace-ir/clock-class.c b/src/lib/trace-ir/clock-class.c index fb0d108c..8a3640bc 100644 --- a/src/lib/trace-ir/clock-class.c +++ b/src/lib/trace-ir/clock-class.c @@ -26,7 +26,6 @@ #include "lib/assert-pre.h" #include "common/uuid.h" -#include #include #include "clock-class.h" #include "clock-snapshot.h" @@ -35,9 +34,11 @@ #include #include "compat/string.h" #include +#include #include "lib/object.h" #include "common/assert.h" #include "lib/func-status.h" +#include "lib/value.h" #define BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(_cc) \ BT_ASSERT_PRE_DEV_HOT((_cc), "Clock class", ": %!+K", (_cc)) @@ -48,6 +49,7 @@ void destroy_clock_class(struct bt_object *obj) struct bt_clock_class *clock_class = (void *) obj; BT_LIB_LOGD("Destroying clock class: %!+K", clock_class); + BT_OBJECT_PUT_REF_AND_RESET(clock_class->user_attributes); if (clock_class->name.str) { g_string_free(clock_class->name.str, TRUE); @@ -85,6 +87,7 @@ struct bt_clock_class *bt_clock_class_create(bt_self_component *self_comp) int ret; struct bt_clock_class *clock_class = NULL; + BT_ASSERT_PRE_NO_ERROR(); BT_ASSERT_PRE_NON_NULL(self_comp, "Self component"); BT_LOGD_STR("Creating default clock class object"); @@ -95,6 +98,14 @@ struct bt_clock_class *bt_clock_class_create(bt_self_component *self_comp) } bt_object_init_shared(&clock_class->base, destroy_clock_class); + + clock_class->user_attributes = bt_value_map_create(); + if (!clock_class->user_attributes) { + BT_LIB_LOGE_APPEND_CAUSE( + "Failed to create a map value object."); + goto error; + } + clock_class->name.str = g_string_new(NULL); if (!clock_class->name.str) { BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); @@ -141,6 +152,7 @@ const char *bt_clock_class_get_name(const struct bt_clock_class *clock_class) enum bt_clock_class_set_name_status bt_clock_class_set_name( struct bt_clock_class *clock_class, const char *name) { + BT_ASSERT_PRE_NO_ERROR(); BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); BT_ASSERT_PRE_NON_NULL(name, "Name"); BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class); @@ -160,6 +172,7 @@ const char *bt_clock_class_get_description( enum bt_clock_class_set_description_status bt_clock_class_set_description( struct bt_clock_class *clock_class, const char *descr) { + BT_ASSERT_PRE_NO_ERROR(); BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); BT_ASSERT_PRE_NON_NULL(descr, "Description"); BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class); @@ -276,6 +289,9 @@ void _bt_clock_class_freeze(const struct bt_clock_class *clock_class) return; } + BT_LIB_LOGD("Freezing clock class's user attributes: %!+v", + clock_class->user_attributes); + bt_value_freeze(clock_class->user_attributes); BT_LIB_LOGD("Freezing clock class: %!+K", clock_class); ((struct bt_clock_class *) clock_class)->frozen = 1; } @@ -287,6 +303,7 @@ bt_clock_class_cycles_to_ns_from_origin( { int ret; + BT_ASSERT_PRE_DEV_NO_ERROR(); BT_ASSERT_PRE_DEV_NON_NULL(clock_class, "Clock class"); BT_ASSERT_PRE_DEV_NON_NULL(ns, "Nanoseconds (output)"); ret = bt_util_ns_from_origin_clock_class(clock_class, cycles, ns); @@ -296,12 +313,40 @@ bt_clock_class_cycles_to_ns_from_origin( "value overflows the signed 64-bit integer range: " "%![cc-]+K, cycles=%" PRIu64, clock_class, cycles); - ret = BT_FUNC_STATUS_OVERFLOW; + ret = BT_FUNC_STATUS_OVERFLOW_ERROR; } return ret; } +const struct bt_value *bt_clock_class_borrow_user_attributes_const( + const struct bt_clock_class *clock_class) +{ + BT_ASSERT_PRE_DEV_NON_NULL(clock_class, "Clock class"); + return clock_class->user_attributes; +} + +struct bt_value *bt_clock_class_borrow_user_attributes( + struct bt_clock_class *clock_class) +{ + return (void *) bt_clock_class_borrow_user_attributes_const( + (void *) clock_class); +} + +void bt_clock_class_set_user_attributes( + struct bt_clock_class *clock_class, + const struct bt_value *user_attributes) +{ + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); + BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, + "User attributes object is not a map value object."); + BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class); + bt_object_put_ref_no_null_check(clock_class->user_attributes); + clock_class->user_attributes = (void *) user_attributes; + bt_object_get_ref_no_null_check(clock_class->user_attributes); +} + void bt_clock_class_get_ref(const struct bt_clock_class *clock_class) { bt_object_get_ref(clock_class);