From af181248caf97d9c4e22182181f70a16b40ffead Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 9 Dec 2014 19:05:47 -0500 Subject: [PATCH] Add stream_event_context accessors MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-fields.c | 2 - formats/ctf/ir/stream-class.c | 47 ++++++++++++++++++- formats/ctf/ir/stream.c | 16 ++++++- .../babeltrace/ctf-ir/stream-class-internal.h | 1 - include/babeltrace/ctf-ir/stream-class.h | 25 ++++++++++ include/babeltrace/ctf-ir/stream-internal.h | 1 + include/babeltrace/ctf-ir/stream.h | 25 ++++++++++ 7 files changed, 111 insertions(+), 6 deletions(-) diff --git a/formats/ctf/ir/event-fields.c b/formats/ctf/ir/event-fields.c index e49a17be..bde69a22 100644 --- a/formats/ctf/ir/event-fields.c +++ b/formats/ctf/ir/event-fields.c @@ -993,13 +993,11 @@ struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field) enum ctf_type_id type_id; if (!field) { - ret = -1; goto end; } type_id = bt_ctf_field_type_get_type_id(field->type); if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) { - ret = -1; goto end; } diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 6ccaac3c..edbd43b6 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -306,6 +306,47 @@ end: return ret; } +struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type( + struct bt_ctf_stream_class *stream_class) +{ + struct bt_ctf_field_type *ret = NULL; + + if (!stream_class || !stream_class->event_context_type) { + goto end; + } + + assert(stream_class->event_context_type); + bt_ctf_field_type_get(stream_class->event_context_type); + ret = stream_class->event_context_type; +end: + return ret; +} + +int bt_ctf_stream_class_set_event_context_type( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_field_type *event_context_type) +{ + int ret = 0; + + if (!stream_class || !event_context_type || stream_class->frozen) { + ret = -1; + goto end; + } + + if (bt_ctf_field_type_get_type_id(event_context_type) != + CTF_TYPE_STRUCT) { + /* A packet context must be a structure */ + ret = -1; + goto end; + } + + bt_ctf_field_type_put(stream_class->event_context_type); + bt_ctf_field_type_get(event_context_type); + stream_class->event_context_type = event_context_type; +end: + return ret; +} + void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class) { if (!stream_class) { @@ -333,6 +374,7 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class) stream_class->frozen = 1; bt_ctf_field_type_freeze(stream_class->packet_context_type); + bt_ctf_field_type_freeze(stream_class->event_context_type); bt_ctf_clock_freeze(stream_class->clock); g_ptr_array_foreach(stream_class->event_classes, (GFunc)bt_ctf_event_class_freeze, NULL); @@ -440,8 +482,9 @@ void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref) bt_ctf_field_type_put(stream_class->event_header_type); bt_ctf_field_put(stream_class->event_header); bt_ctf_field_type_put(stream_class->packet_context_type); - bt_ctf_field_type_put(stream_class->event_context_type); - bt_ctf_field_put(stream_class->event_context); + if (stream_class->event_context_type) { + bt_ctf_field_type_put(stream_class->event_context_type); + } g_free(stream_class); } diff --git a/formats/ctf/ir/stream.c b/formats/ctf/ir/stream.c index 57b89379..d4e1be15 100644 --- a/formats/ctf/ir/stream.c +++ b/formats/ctf/ir/stream.c @@ -67,7 +67,20 @@ struct bt_ctf_stream *bt_ctf_stream_create( goto error_destroy; } - /* Initialize events_discarded*/ + /* + * A stream class may not have a stream event context defined + * in which case this stream will never have a stream_event_context + * member since, after a stream's creation, the parent stream class + * is "frozen" (immutable). + */ + if (stream_class->event_context_type) { + stream->event_context = bt_ctf_field_create( + stream_class->event_context_type); + if (!stream->packet_context) { + goto error_destroy; + } + } + ret = set_structure_field_integer(stream->packet_context, "events_discarded", 0); if (ret) { @@ -252,6 +265,7 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, { int ret = 0; uint64_t timestamp; + struct bt_ctf_field *event_context_copy = NULL; if (!stream || !event) { ret = -1; diff --git a/include/babeltrace/ctf-ir/stream-class-internal.h b/include/babeltrace/ctf-ir/stream-class-internal.h index 67a9d17b..55ad787e 100644 --- a/include/babeltrace/ctf-ir/stream-class-internal.h +++ b/include/babeltrace/ctf-ir/stream-class-internal.h @@ -48,7 +48,6 @@ struct bt_ctf_stream_class { struct bt_ctf_field *event_header; struct bt_ctf_field_type *packet_context_type; struct bt_ctf_field_type *event_context_type; - struct bt_ctf_field *event_context; int frozen; }; diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index d64e7141..71b10679 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -194,6 +194,31 @@ extern int bt_ctf_stream_class_set_packet_context_type( struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type); +/* + * bt_ctf_stream_class_get_event_context_type: get the stream class' + * event context type. + * + * @param stream_class Stream class. + * + * Returns the stream event context's type (a structure), NULL on error. + */ +extern struct bt_ctf_field_type * +bt_ctf_stream_class_get_event_context_type( + struct bt_ctf_stream_class *stream_class); + +/* + * bt_ctf_stream_class_set_event_context_type: set the stream class' + * event context type. + * + * @param stream_class Stream class. + * @param event_context_type Event context type (must be a structure). + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_class_set_event_context_type( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_field_type *event_context_type); + /* * bt_ctf_stream_class_get and bt_ctf_stream_class_put: increment and * decrement the stream class' reference count. diff --git a/include/babeltrace/ctf-ir/stream-internal.h b/include/babeltrace/ctf-ir/stream-internal.h index afbb9ff5..0bd39ba4 100644 --- a/include/babeltrace/ctf-ir/stream-internal.h +++ b/include/babeltrace/ctf-ir/stream-internal.h @@ -53,6 +53,7 @@ struct bt_ctf_stream { struct ctf_stream_pos pos; unsigned int flushed_packet_count; struct bt_ctf_field *packet_context; + struct bt_ctf_field *event_context; }; BT_HIDDEN diff --git a/include/babeltrace/ctf-ir/stream.h b/include/babeltrace/ctf-ir/stream.h index d9e2bc26..ab0a8c7e 100644 --- a/include/babeltrace/ctf-ir/stream.h +++ b/include/babeltrace/ctf-ir/stream.h @@ -109,6 +109,31 @@ extern int bt_ctf_stream_set_packet_context( struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context); +/* + * bt_ctf_stream_get_event_context: get a stream's event context. + * + * @param stream Stream instance. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_stream_get_event_context( + struct bt_ctf_stream *stream); + +/* + * bt_ctf_stream_set_event_context: set a stream's event context. + * + * The event context's type must match the stream class' event + * context type. + * + * @param stream Stream instance. + * @param event_context Event context field instance. + * + * Returns a field instance on success, NULL on error. + */ +extern int bt_ctf_stream_set_event_context( + struct bt_ctf_stream *stream, + struct bt_ctf_field *event_context); + /* * bt_ctf_stream_flush: flush a stream. * -- 2.34.1