Implement CTF-IR Clock getters
[babeltrace.git] / formats / ctf / ir / clock.c
index d8df956df2ed6a9f84c03690d7f0f39d36aafc1d..2860e01039aba31b44c0b801cb92994e6e9ac018 100644 (file)
@@ -53,11 +53,6 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
                goto error_destroy;
        }
 
-       clock->description = g_string_new(NULL);
-       if (!clock->description) {
-               goto error_destroy;
-       }
-
        clock->precision = 1;
        clock->frequency = 1000000000;
        uuid_generate(clock->uuid);
@@ -66,8 +61,38 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
 error_destroy:
        bt_ctf_clock_destroy(&clock->ref_count);
 error:
-       clock = NULL;
-       return clock;
+       return NULL;
+}
+
+const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock)
+{
+       const char *ret = NULL;
+
+       if (!clock) {
+               goto end;
+       }
+
+       if (clock->name) {
+               ret = clock->name->str;
+       }
+
+end:
+       return ret;
+}
+
+const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock)
+{
+       const char *ret = NULL;
+
+       if (!clock) {
+               goto end;
+       }
+
+       if (clock->description) {
+               ret = clock->description->str;
+       }
+end:
+       return ret;
 }
 
 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc)
@@ -79,12 +104,25 @@ int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc)
                goto end;
        }
 
-       clock->description = g_string_assign(clock->description, desc);
+       clock->description = g_string_new(desc);
        ret = clock->description ? 0 : -1;
 end:
        return ret;
 }
 
+uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock)
+{
+       uint64_t ret = -1ULL;
+
+       if (!clock) {
+               goto end;
+       }
+
+       ret = clock->frequency;
+end:
+       return ret;
+}
+
 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq)
 {
        int ret = 0;
@@ -99,6 +137,19 @@ end:
        return ret;
 }
 
+uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock)
+{
+       uint64_t ret = -1ULL;
+
+       if (!clock) {
+               goto end;
+       }
+
+       ret = clock->precision;
+end:
+       return ret;
+}
+
 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision)
 {
        int ret = 0;
@@ -113,6 +164,19 @@ end:
        return ret;
 }
 
+uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock)
+{
+       uint64_t ret = -1ULL;
+
+       if (!clock) {
+               goto end;
+       }
+
+       ret = clock->offset_s;
+end:
+       return ret;
+}
+
 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s)
 {
        int ret = 0;
@@ -127,6 +191,19 @@ end:
        return ret;
 }
 
+uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock)
+{
+       uint64_t ret = -1ULL;
+
+       if (!clock) {
+               goto end;
+       }
+
+       ret = clock->offset;
+end:
+       return ret;
+}
+
 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset)
 {
        int ret = 0;
@@ -141,6 +218,19 @@ end:
        return ret;
 }
 
+int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock)
+{
+       int ret = -1;
+
+       if (!clock) {
+               goto end;
+       }
+
+       ret = clock->absolute;
+end:
+       return ret;
+}
+
 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute)
 {
        int ret = 0;
@@ -155,6 +245,19 @@ end:
        return ret;
 }
 
+uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock)
+{
+       uint64_t ret = -1ULL;
+
+       if (!clock) {
+               goto end;
+       }
+
+       ret = clock->time;
+end:
+       return ret;
+}
+
 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time)
 {
        int ret = 0;
@@ -236,12 +339,6 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock,
        g_string_append(context->string, "};\n\n");
 }
 
-BT_HIDDEN
-uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock)
-{
-       return clock ? clock->time : 0;
-}
-
 static
 void bt_ctf_clock_destroy(struct bt_ctf_ref *ref)
 {
This page took 0.02455 seconds and 4 git commands to generate.