X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fclock.c;h=22a5d7475e30083b90dd9ae741f7718a99cbe4b4;hb=de3dd40e6fcad56e227f5fc8a8290fbaa88b4e07;hp=d8df956df2ed6a9f84c03690d7f0f39d36aafc1d;hpb=11b0cdc8d08794b52c9b07561fac1abac9b809a9;p=babeltrace.git diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index d8df956d..22a5d747 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,48 +26,116 @@ * 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_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 (validate_identifier(name)) { - goto error; + if (!clock) { + goto end; + } + + clock->precision = 1; + clock->frequency = 1000000000; + bt_ctf_base_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; } - 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->description = g_string_new(NULL); - if (!clock->description) { + ret = babeltrace_uuid_generate(clock->uuid); + if (ret) { goto error_destroy; } - 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); + bt_ctf_clock_destroy(&clock->base.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 +147,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 +180,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 +207,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 +234,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 +261,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 +288,48 @@ 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; + + 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; @@ -172,20 +347,12 @@ end: void bt_ctf_clock_get(struct bt_ctf_clock *clock) { - if (!clock) { - return; - } - - bt_ctf_ref_get(&clock->ref_count); + bt_ctf_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_ctf_put(clock); } BT_HIDDEN @@ -218,7 +385,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); } @@ -236,22 +403,18 @@ 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) +void bt_ctf_clock_destroy(struct bt_ref *ref) { struct bt_ctf_clock *clock; + struct bt_ctf_base *base; if (!ref) { return; } - clock = container_of(ref, struct bt_ctf_clock, ref_count); + base = container_of(ref, struct bt_ctf_base, ref_count); + clock = container_of(base, struct bt_ctf_clock, base); if (clock->name) { g_string_free(clock->name, TRUE); }