Clock class API: use status
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 8 Dec 2018 19:23:13 +0000 (14:23 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace/trace-ir/clock-class-const.h
include/babeltrace/trace-ir/clock-class.h
lib/trace-ir/clock-class.c

index 0974facc848b0740a0db303aa8c9e7ef82035ef2..f7afc24802b491d4e19628571b296da6dc2cfd4c 100644 (file)
 extern "C" {
 #endif
 
+enum bt_clock_class_status {
+       BT_CLOCK_CLASS_STATUS_OK = 0,
+       BT_CLOCK_CLASS_STATUS_NOMEM = -12,
+       BT_CLOCK_CLASS_STATUS_OVERFLOW = -75,
+};
+
 extern const char *bt_clock_class_get_name(
                const bt_clock_class *clock_class);
 
@@ -57,7 +63,7 @@ extern bt_bool bt_clock_class_is_absolute(
 extern bt_uuid bt_clock_class_get_uuid(
                const bt_clock_class *clock_class);
 
-extern int bt_clock_class_cycles_to_ns_from_origin(
+extern enum bt_clock_class_status bt_clock_class_cycles_to_ns_from_origin(
                const bt_clock_class *clock_class,
                uint64_t cycles, int64_t *ns_from_origin);
 
index 5fae62ca1964f825932bc5c20164e2a240ceabaf..e0d877308c203b3be9bf925118c0ad85f9126e7f 100644 (file)
 /* For bt_bool, bt_uuid, bt_clock_class */
 #include <babeltrace/types.h>
 
+/* For enum bt_clock_class_status */
+#include <babeltrace/trace-ir/clock-class-const.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 extern bt_clock_class *bt_clock_class_create(void);
 
-extern int bt_clock_class_set_name(bt_clock_class *clock_class,
-               const char *name);
+extern enum bt_clock_class_status bt_clock_class_set_name(
+               bt_clock_class *clock_class, const char *name);
 
-extern int bt_clock_class_set_description(bt_clock_class *clock_class,
-               const char *description);
+extern enum bt_clock_class_status bt_clock_class_set_description(
+               bt_clock_class *clock_class, const char *description);
 
 extern void bt_clock_class_set_frequency(bt_clock_class *clock_class,
                uint64_t freq);
index a2465b41396bebe7b0e05261c32960b320b723bc..273d8f58a544d39b788fb5f7e9750066091bc910 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <babeltrace/assert-pre-internal.h>
 #include <babeltrace/compat/uuid-internal.h>
+#include <babeltrace/trace-ir/clock-class-const.h>
+#include <babeltrace/trace-ir/clock-class.h>
 #include <babeltrace/trace-ir/clock-class-internal.h>
 #include <babeltrace/trace-ir/clock-snapshot-internal.h>
 #include <babeltrace/trace-ir/utils-internal.h>
@@ -160,8 +162,8 @@ const char *bt_clock_class_get_name(const struct bt_clock_class *clock_class)
        return clock_class->name.value;
 }
 
-int bt_clock_class_set_name(struct bt_clock_class *clock_class,
-               const char *name)
+enum bt_clock_class_status bt_clock_class_set_name(
+               struct bt_clock_class *clock_class, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
@@ -169,7 +171,7 @@ int bt_clock_class_set_name(struct bt_clock_class *clock_class,
        g_string_assign(clock_class->name.str, name);
        clock_class->name.value = clock_class->name.str->str;
        BT_LIB_LOGV("Set clock class's name: %!+K", clock_class);
-       return 0;
+       return BT_CLOCK_CLASS_STATUS_OK;
 }
 
 const char *bt_clock_class_get_description(
@@ -179,8 +181,8 @@ const char *bt_clock_class_get_description(
        return clock_class->description.value;
 }
 
-int bt_clock_class_set_description(struct bt_clock_class *clock_class,
-               const char *descr)
+enum bt_clock_class_status bt_clock_class_set_description(
+               struct bt_clock_class *clock_class, const char *descr)
 {
        BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
        BT_ASSERT_PRE_NON_NULL(descr, "Description");
@@ -189,7 +191,7 @@ int bt_clock_class_set_description(struct bt_clock_class *clock_class,
        clock_class->description.value = clock_class->description.str->str;
        BT_LIB_LOGV("Set clock class's description: %!+K",
                clock_class);
-       return 0;
+       return BT_CLOCK_CLASS_STATUS_OK;
 }
 
 uint64_t bt_clock_class_get_frequency(const struct bt_clock_class *clock_class)
@@ -302,7 +304,7 @@ void _bt_clock_class_freeze(const struct bt_clock_class *clock_class)
        ((struct bt_clock_class *) clock_class)->frozen = 1;
 }
 
-int bt_clock_class_cycles_to_ns_from_origin(
+enum bt_clock_class_status bt_clock_class_cycles_to_ns_from_origin(
                const struct bt_clock_class *clock_class,
                uint64_t cycles, int64_t *ns)
 {
@@ -312,6 +314,7 @@ int bt_clock_class_cycles_to_ns_from_origin(
        BT_ASSERT_PRE_NON_NULL(ns, "Nanoseconds (output)");
        ret = bt_util_ns_from_origin(clock_class, cycles, ns);
        if (ret) {
+               ret = BT_CLOCK_CLASS_STATUS_OVERFLOW;
                BT_LIB_LOGW("Cannot convert cycles to nanoseconds "
                        "from origin for given clock class: "
                        "value overflows the signed 64-bit integer range: "
This page took 0.026838 seconds and 4 git commands to generate.