Don't automatically generate a clock UUID in _bt_ctf_clock_create
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Oct 2014 16:11:58 +0000 (12:11 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Oct 2014 17:52:41 +0000 (13:52 -0400)
While the public clock constructor still generates a UUID,
it should not be done when creating a clock during TSDL metadata
parsing.

This makes it possible to use bt_ctf_clock_get_uuid to check
if a UUID has already been set during clock definition parsing.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/clock.c
include/babeltrace/ctf-ir/clock-internal.h

index f0213868c3ad32a4ab9b1fb17f244a562ceabd22..195f83716bf3840c79f98fa15861a1783d80c34b 100644 (file)
@@ -26,7 +26,6 @@
  * SOFTWARE.
  */
 
-#include <babeltrace/ctf-writer/clock.h>
 #include <babeltrace/ctf-ir/clock-internal.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
 #include <babeltrace/compiler.h>
@@ -47,7 +46,6 @@ struct bt_ctf_clock *_bt_ctf_clock_create(void)
 
        clock->precision = 1;
        clock->frequency = 1000000000;
-       uuid_generate(clock->uuid);
        bt_ctf_ref_init(&clock->ref_count);
 end:
        return clock;
@@ -92,6 +90,12 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
                goto error_destroy;
        }
 
+       ret = babeltrace_uuid_generate(clock->uuid);
+       if (ret) {
+               goto error_destroy;
+       }
+
+       clock->uuid_set = 1;
        return clock;
 error_destroy:
        bt_ctf_clock_destroy(&clock->ref_count);
@@ -284,7 +288,7 @@ const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock)
 {
        const unsigned char *ret;
 
-       if (!clock) {
+       if (!clock || !clock->uuid_set) {
                ret = NULL;
                goto end;
        }
@@ -298,12 +302,13 @@ int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock, const unsigned char *uuid)
 {
        int ret = 0;
 
-       if (!clock || !uuid) {
+       if (!clock || !uuid || clock->frozen) {
                ret = -1;
                goto end;
        }
 
        memcpy(clock->uuid, uuid, sizeof(uuid_t));
+       clock->uuid_set = 1;
 end:
        return ret;
 }
index 9e800ac55b6358fa7e0655236837b400f263c077..f876cd3034fa81e204f2adc0369d35c0ae910b11 100644 (file)
@@ -32,7 +32,7 @@
 #include <babeltrace/ctf-ir/trace-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <glib.h>
-#include <uuid/uuid.h>
+#include <babeltrace/compat/uuid.h>
 
 struct bt_ctf_clock {
        struct bt_ctf_ref ref_count;
@@ -44,6 +44,7 @@ struct bt_ctf_clock {
        uint64_t offset;        /* Offset in ticks */
        uint64_t time;          /* Current clock value */
        uuid_t uuid;
+       int uuid_set;
        int absolute;
        /*
         * A clock's properties can't be modified once it is added to a stream
This page took 0.025993 seconds and 4 git commands to generate.