ir: allow the creation of an empty clock (nameless)
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sun, 14 Aug 2016 19:08:38 +0000 (15:08 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 17:41:38 +0000 (13:41 -0400)
bt_ctf_clock_create_empty() is used to create an empty clock object.
This clock has no name, and it cannot be added to any other object
until its name is set using bt_ctf_clock_set_name().

This helps the creation of a clock object when its name is not known
in advance, just like the other properties.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/clock.c
formats/ctf/ir/field-types.c
formats/ctf/ir/stream-class.c
formats/ctf/ir/trace.c
include/babeltrace/ctf-ir/clock-internal.h
include/babeltrace/ctf-ir/clock.h

index 9256bc1f26f58ef5cb4f04a8ca9a92d32dc364e7..002b72058fd4d6a14731d1581a7ff62720b8a5fa 100644 (file)
@@ -37,8 +37,7 @@
 static
 void bt_ctf_clock_destroy(struct bt_object *obj);
 
-BT_HIDDEN
-struct bt_ctf_clock *_bt_ctf_clock_create(void)
+struct bt_ctf_clock *bt_ctf_clock_create_empty(void)
 {
        struct bt_ctf_clock *clock = g_new0(
                struct bt_ctf_clock, 1);
@@ -55,11 +54,21 @@ end:
 }
 
 BT_HIDDEN
+bool bt_ctf_clock_is_valid(struct bt_ctf_clock *clock)
+{
+       return clock && clock->name;
+}
+
 int bt_ctf_clock_set_name(struct bt_ctf_clock *clock,
                const char *name)
 {
        int ret = 0;
 
+       if (!clock || clock->frozen) {
+               ret = -1;
+               goto end;
+       }
+
        if (bt_ctf_validate_identifier(name)) {
                ret = -1;
                goto end;
@@ -84,7 +93,7 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
        int ret;
        struct bt_ctf_clock *clock = NULL;
 
-       clock = _bt_ctf_clock_create();
+       clock = bt_ctf_clock_create_empty();
        if (!clock) {
                goto error;
        }
index 4f2bc03449bd438c5d3f648907aab4c66c9d6dac..5aecd99c4fbfc5f95d2a2a12b9ce3c9e0ba5ec2f 100644 (file)
@@ -844,7 +844,7 @@ int bt_ctf_field_type_integer_set_mapped_clock(
        struct bt_ctf_field_type_integer *integer;
        int ret = 0;
 
-       if (!type || type->frozen) {
+       if (!type || type->frozen || !bt_ctf_clock_is_valid(clock)) {
                ret = -1;
                goto end;
        }
index 877a9c4aa595d92c3fa02b93e44cbcdbc0c17e9b..4c59744e826bab3e1d15aff9f249c02e8515364f 100644 (file)
@@ -147,7 +147,8 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class,
        int ret = 0;
        struct bt_ctf_field_type *timestamp_field = NULL;
 
-       if (!stream_class || !clock || stream_class->frozen) {
+       if (!stream_class || stream_class->frozen ||
+                       !bt_ctf_clock_is_valid(clock)) {
                ret = -1;
                goto end;
        }
index 8ead3792785c82355b41fcf59d801dfed15b13c6..4476c8f057baa257775622ed72a7a139d848298f 100644 (file)
@@ -353,7 +353,7 @@ int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace,
        int ret = 0;
        struct search_query query = { .value = clock, .found = 0 };
 
-       if (!trace || !clock) {
+       if (!trace || !bt_ctf_clock_is_valid(clock)) {
                ret = -1;
                goto end;
        }
index 8f7b5f07e31f9d9b77dfe8ab800e4143bb2be51a..ac13a8e3fc42713053218041d6bb56689ddd3454 100644 (file)
@@ -63,24 +63,6 @@ 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);
 
@@ -88,4 +70,7 @@ BT_HIDDEN
 void bt_ctf_clock_serialize(struct bt_ctf_clock *clock,
                struct metadata_context *context);
 
+BT_HIDDEN
+bool bt_ctf_clock_is_valid(struct bt_ctf_clock *clock);
+
 #endif /* BABELTRACE_CTF_IR_CLOCK_INTERNAL_H */
index e35882e05eb7155e879b1b4cabd95023adbaf55a..5858a711ef7b0c00e0f02d8c95f2eea662794c46 100644 (file)
@@ -49,6 +49,10 @@ struct bt_ctf_clock;
  */
 extern struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
 
+extern struct bt_ctf_clock *bt_ctf_clock_create_empty(void);
+
+extern int bt_ctf_clock_set_name(struct bt_ctf_clock *clock, const char *name);
+
 /*
  * bt_ctf_clock_get_name: get a clock's name.
  *
This page took 0.030009 seconds and 4 git commands to generate.