Add internal nameless clock creation API
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 19 Oct 2014 17:39:58 +0000 (13:39 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Oct 2014 12:05:15 +0000 (08:05 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/clock.c
include/babeltrace/ctf-ir/clock-internal.h

index 5ebaf046bbedc81f5e3f55a3a31cc2889be3598c..f0213868c3ad32a4ab9b1fb17f244a562ceabd22 100644 (file)
 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);
index 89c271d3cb58bb42936192e26bdad3ac76198c05..9e800ac55b6358fa7e0655236837b400f263c077 100644 (file)
@@ -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);
 
This page took 0.026526 seconds and 4 git commands to generate.