X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fclock.c;h=d5c980abe44a49bb311f1411e9667a0fc8ed94d3;hb=19dd40dbdf4184fd43851c47f30d2ccf664a91e7;hp=2860e01039aba31b44c0b801cb92994e6e9ac018;hpb=87d76bb1f3202bcdd577df14bbbf2231a26c244c;p=babeltrace.git diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index 2860e010..d5c980ab 100644 --- a/formats/ctf/ir/clock.c +++ b/formats/ctf/ir/clock.c @@ -1,9 +1,9 @@ /* * clock.c * - * Babeltrace CTF Writer + * Babeltrace CTF IR - Clock * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -26,42 +26,84 @@ * SOFTWARE. */ -#include #include +#include +#include #include +#include #include #include static -void bt_ctf_clock_destroy(struct bt_ctf_ref *ref); +void bt_ctf_clock_destroy(struct bt_object *obj); + +BT_HIDDEN +struct bt_ctf_clock *_bt_ctf_clock_create(void) +{ + struct bt_ctf_clock *clock = g_new0( + struct bt_ctf_clock, 1); + + if (!clock) { + goto end; + } + + clock->precision = 1; + clock->frequency = 1000000000; + bt_object_init(clock, bt_ctf_clock_destroy); +end: + return clock; +} + +BT_HIDDEN +int bt_ctf_clock_set_name(struct bt_ctf_clock *clock, + const char *name) +{ + int ret = 0; + + if (bt_ctf_validate_identifier(name)) { + ret = -1; + goto end; + } + + 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; - if (validate_identifier(name)) { + clock = _bt_ctf_clock_create(); + if (!clock) { goto error; } - clock = g_new0(struct bt_ctf_clock, 1); - if (!clock) { + ret = bt_ctf_clock_set_name(clock, name); + if (ret) { goto error; } - clock->name = g_string_new(name); - if (!clock->name) { - goto error_destroy; + ret = bt_uuid_generate(clock->uuid); + if (ret) { + goto error; } - clock->precision = 1; - clock->frequency = 1000000000; - uuid_generate(clock->uuid); - bt_ctf_ref_init(&clock->ref_count); + clock->uuid_set = 1; return clock; -error_destroy: - bt_ctf_clock_destroy(&clock->ref_count); error: - return NULL; + BT_PUT(clock); + return clock; } const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock) @@ -245,6 +287,35 @@ end: return ret; } +const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock) +{ + const unsigned char *ret; + + if (!clock || !clock->uuid_set) { + ret = NULL; + goto end; + } + + ret = clock->uuid; +end: + return ret; +} + +int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock, const unsigned char *uuid) +{ + int ret = 0; + + if (!clock || !uuid || clock->frozen) { + ret = -1; + goto end; + } + + memcpy(clock->uuid, uuid, sizeof(uuid_t)); + clock->uuid_set = 1; +end: + return ret; +} + uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock) { uint64_t ret = -1ULL; @@ -275,20 +346,12 @@ end: void bt_ctf_clock_get(struct bt_ctf_clock *clock) { - if (!clock) { - return; - } - - bt_ctf_ref_get(&clock->ref_count); + bt_get(clock); } void bt_ctf_clock_put(struct bt_ctf_clock *clock) { - if (!clock) { - return; - } - - bt_ctf_ref_put(&clock->ref_count, bt_ctf_clock_destroy); + bt_put(clock); } BT_HIDDEN @@ -321,7 +384,7 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); - if (clock->description->len) { + if (clock->description) { g_string_append_printf(context->string, "\tdescription = \"%s\";\n", clock->description->str); } @@ -340,15 +403,11 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, } static -void bt_ctf_clock_destroy(struct bt_ctf_ref *ref) +void bt_ctf_clock_destroy(struct bt_object *obj) { struct bt_ctf_clock *clock; - if (!ref) { - return; - } - - clock = container_of(ref, struct bt_ctf_clock, ref_count); + clock = container_of(obj, struct bt_ctf_clock, base); if (clock->name) { g_string_free(clock->name, TRUE); }