From c06116f32e056500c8c64364d65d04665a77644b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sun, 14 Aug 2016 15:08:38 -0400 Subject: [PATCH] ir: allow the creation of an empty clock (nameless) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/clock.c | 15 ++++++++++++--- formats/ctf/ir/field-types.c | 2 +- formats/ctf/ir/stream-class.c | 3 ++- formats/ctf/ir/trace.c | 2 +- include/babeltrace/ctf-ir/clock-internal.h | 21 +++------------------ include/babeltrace/ctf-ir/clock.h | 4 ++++ 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index 9256bc1f..002b7205 100644 --- a/formats/ctf/ir/clock.c +++ b/formats/ctf/ir/clock.c @@ -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; } diff --git a/formats/ctf/ir/field-types.c b/formats/ctf/ir/field-types.c index 4f2bc034..5aecd99c 100644 --- a/formats/ctf/ir/field-types.c +++ b/formats/ctf/ir/field-types.c @@ -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; } diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 877a9c4a..4c59744e 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -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; } diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 8ead3792..4476c8f0 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -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; } diff --git a/include/babeltrace/ctf-ir/clock-internal.h b/include/babeltrace/ctf-ir/clock-internal.h index 8f7b5f07..ac13a8e3 100644 --- a/include/babeltrace/ctf-ir/clock-internal.h +++ b/include/babeltrace/ctf-ir/clock-internal.h @@ -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 */ diff --git a/include/babeltrace/ctf-ir/clock.h b/include/babeltrace/ctf-ir/clock.h index e35882e0..5858a711 100644 --- a/include/babeltrace/ctf-ir/clock.h +++ b/include/babeltrace/ctf-ir/clock.h @@ -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. * -- 2.34.1