X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fclock.c;h=45ed14762512d72dd5cd4b23ca396da7140e6907;hb=e1ae7645ef265eb69a0a500c8f4d6620c50543da;hp=5ebaf046bbedc81f5e3f55a3a31cc2889be3598c;hpb=d2dc44b6775655cf77a13a3901898c3f1ca26baa;p=babeltrace.git diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index 5ebaf046..45ed1476 100644 --- a/formats/ctf/ir/clock.c +++ b/formats/ctf/ir/clock.c @@ -26,7 +26,6 @@ * SOFTWARE. */ -#include #include #include #include @@ -35,28 +34,69 @@ static void bt_ctf_clock_destroy(struct bt_ctf_ref *ref); -struct bt_ctf_clock *bt_ctf_clock_create(const char *name) +BT_HIDDEN +struct bt_ctf_clock *_bt_ctf_clock_create(void) { - struct bt_ctf_clock *clock = NULL; + struct bt_ctf_clock *clock = g_new0( + struct bt_ctf_clock, 1); + + if (!clock) { + goto end; + } + + clock->precision = 1; + clock->frequency = 1000000000; + bt_ctf_ref_init(&clock->ref_count); +end: + return clock; +} + +BT_HIDDEN +int bt_ctf_clock_set_name(struct bt_ctf_clock *clock, + const char *name) +{ + int ret = 0; if (validate_identifier(name)) { - goto error; + ret = -1; + goto end; } - clock = g_new0(struct bt_ctf_clock, 1); + if (clock->name) { + g_string_assign(clock->name, name); + } else { + clock->name = g_string_new(name); + if (!clock->name) { + ret = -1; + goto end; + } + } + +end: + return ret; +} + +struct bt_ctf_clock *bt_ctf_clock_create(const char *name) +{ + int ret; + struct bt_ctf_clock *clock = NULL; + + clock = _bt_ctf_clock_create(); if (!clock) { goto error; } - clock->name = g_string_new(name); - if (!clock->name) { + ret = bt_ctf_clock_set_name(clock, name); + if (ret) { goto error_destroy; } - clock->precision = 1; - clock->frequency = 1000000000; - uuid_generate(clock->uuid); - bt_ctf_ref_init(&clock->ref_count); + 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); @@ -249,7 +289,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; } @@ -263,12 +303,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; }