From e0e2946b83c6317aaa2a9ab3abde33fb7366fa42 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 2 May 2017 15:19:20 -0400 Subject: [PATCH] Add bt_ctf_stream_class_create_empty() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The new bt_ctf_stream_class_create_empty() function creates a new stream class object with its packet context, event header, and event context field types set to empty structure field types. This is more appropriate for source components which do not need the default fields that bt_ctf_stream_class_create() creates. bt_ctf_stream_class_create() is kept as is for backward compatibility with pre-2.0 CTF writer. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/babeltrace/ctf-ir/stream-class.h | 35 +++++++++++++++-- lib/ctf-ir/stream-class.c | 49 ++++++++++++++++++------ 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index 63d7e7d0..e66ab7da 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -110,7 +110,10 @@ You cannot modify a frozen stream class: it is considered immutable, except for: - Adding an event class to it with - bt_ctf_stream_class_add_event_class(). + bt_ctf_stream_class_add_event_class(). If the stream class's parent + \link ctfirtraceclass trace class\endlink is static, however, + you cannot call bt_ctf_stream_class_add_event_class() + (see bt_ctf_trace_is_static() and bt_ctf_trace_set_is_static()). - \link refs Reference counting\endlink. @sa ctfirstream @@ -140,6 +143,28 @@ struct bt_ctf_clock; @{ */ +/** +@brief Creates an empty CTF IR stream class named \p name, or an + unnamed empty stream class if \p name is \c NULL. + +On success, the packet context, event header, and event context field +types are empty structure field types. You can modify those default +field types after the stream class is created with +bt_ctf_stream_class_set_packet_context_type(), +bt_ctf_stream_class_set_event_header_type(), and +bt_ctf_stream_class_set_event_context_type(). + +@param[in] name Name of the stream class to create (copied on success), + or \c NULL to create an unnamed stream class. +@returns Created empty stream class, or \c NULL on error. + +@postsuccessrefcountret1 + +@sa bt_ctf_stream_class_create(): Creates a default stream class. +*/ +extern struct bt_ctf_stream_class *bt_ctf_stream_class_create_empty( + const char *name); + /** @brief Creates a default CTF IR stream class named \p name­, or a default unnamed stream class if \p name is \c NULL. @@ -163,11 +188,13 @@ You can modify those default field types after the stream class is created with bt_ctf_stream_class_set_packet_context_type() and bt_ctf_stream_class_set_event_header_type(). -@param[in] name Name of the stream class to create (can be \c NULL to - create an unnamed stream class). -@returns Created stream class, or \c NULL on error. +@param[in] name Name of the stream class to create (copied on success), + or \c NULL to create an unnamed stream class. +@returns Created default stream class, or \c NULL on error. @postsuccessrefcountret1 + +@sa bt_ctf_stream_class_create_empty(): Creates an empty stream class. */ extern struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name); diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index 97b6e659..4da65f32 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -56,7 +56,33 @@ int init_packet_context(struct bt_ctf_stream_class *stream_class); struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) { + struct bt_ctf_stream_class *stream_class = + bt_ctf_stream_class_create_empty(name); int ret; + + if (!stream_class) { + goto error; + } + + ret = init_event_header(stream_class); + if (ret) { + goto error; + } + + ret = init_packet_context(stream_class); + if (ret) { + goto error; + } + + return stream_class; + +error: + BT_PUT(stream_class); + return stream_class; +} + +struct bt_ctf_stream_class *bt_ctf_stream_class_create_empty(const char *name) +{ struct bt_ctf_stream_class *stream_class = NULL; if (name && bt_ctf_validate_identifier(name)) { @@ -78,13 +104,18 @@ struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) stream_class->event_classes_ht = g_hash_table_new_full(g_int64_hash, g_int64_equal, g_free, NULL); - ret = init_event_header(stream_class); - if (ret) { + stream_class->packet_context_type = bt_ctf_field_type_structure_create(); + if (!stream_class->packet_context_type) { goto error; } - ret = init_packet_context(stream_class); - if (ret) { + stream_class->event_header_type = bt_ctf_field_type_structure_create(); + if (!stream_class->event_header_type) { + goto error; + } + + stream_class->event_context_type = bt_ctf_field_type_structure_create(); + if (!stream_class->event_context_type) { goto error; } @@ -92,7 +123,7 @@ struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) return stream_class; error: - BT_PUT(stream_class); + BT_PUT(stream_class); return stream_class; } @@ -828,10 +859,7 @@ int init_event_header(struct bt_ctf_stream_class *stream_class) goto end; } - if (stream_class->event_header_type) { - bt_put(stream_class->event_header_type); - } - stream_class->event_header_type = event_header_type; + BT_MOVE(stream_class->event_header_type, event_header_type); end: if (ret) { bt_put(event_header_type); @@ -890,8 +918,7 @@ int init_packet_context(struct bt_ctf_stream_class *stream_class) goto end; } - bt_put(stream_class->packet_context_type); - stream_class->packet_context_type = packet_context_type; + BT_MOVE(stream_class->packet_context_type, packet_context_type); end: if (ret) { bt_put(packet_context_type); -- 2.34.1