From 4c426c1774cb217fabc9c0b5d9947417919b852a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 19 Oct 2014 13:39:58 -0400 Subject: [PATCH] Add internal nameless clock creation API MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/clock.c | 55 ++++++++++++++++++---- include/babeltrace/ctf-ir/clock-internal.h | 18 +++++++ 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index 5ebaf046..f0213868 100644 --- a/formats/ctf/ir/clock.c +++ b/formats/ctf/ir/clock.c @@ -35,28 +35,63 @@ 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; + uuid_generate(clock->uuid); + 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) { - goto error; + if (clock->name) { + g_string_free(clock->name, TRUE); } 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; + } + + 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); return clock; error_destroy: bt_ctf_clock_destroy(&clock->ref_count); diff --git a/include/babeltrace/ctf-ir/clock-internal.h b/include/babeltrace/ctf-ir/clock-internal.h index 89c271d3..9e800ac5 100644 --- a/include/babeltrace/ctf-ir/clock-internal.h +++ b/include/babeltrace/ctf-ir/clock-internal.h @@ -52,6 +52,24 @@ struct bt_ctf_clock { int frozen; }; +/* + * This is not part of the public API to prevent users from creating clocks + * in an invalid state (being nameless, in this case). + * + * The only legitimate use-case for this function is to allocate a clock + * while the TSDL metadata is being parsed. + */ +BT_HIDDEN +struct bt_ctf_clock *_bt_ctf_clock_create(void); + +/* + * Not exposed as part of the public API since the only usecase + * for this is when we are creating clocks from the TSDL metadata. + */ +BT_HIDDEN +int bt_ctf_clock_set_name(struct bt_ctf_clock *clock, + const char *name); + BT_HIDDEN void bt_ctf_clock_freeze(struct bt_ctf_clock *clock); -- 2.34.1