From: Jérémie Galarneau Date: Tue, 6 Jan 2015 22:17:57 +0000 (-0500) Subject: Add stream packet header accessors X-Git-Tag: v2.0.0-pre1~1436 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=263a7df55e73a6c558020d4ad5efdc9e4a6b386b Add stream packet header accessors Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/stream.c b/formats/ctf/ir/stream.c index 80d13111..18c9edfd 100644 --- a/formats/ctf/ir/stream.c +++ b/formats/ctf/ir/stream.c @@ -617,6 +617,50 @@ end: return ret; } +struct bt_ctf_field *bt_ctf_stream_get_packet_header( + struct bt_ctf_stream *stream) +{ + struct bt_ctf_field *packet_header = NULL; + + if (!stream) { + goto end; + } + + packet_header = stream->packet_header; + if (packet_header) { + bt_ctf_field_get(packet_header); + } +end: + return packet_header; +} + +int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream, + struct bt_ctf_field *field) +{ + int ret = 0; + struct bt_ctf_field_type *field_type = NULL; + + if (!stream || !field) { + ret = -1; + goto end; + } + + field_type = bt_ctf_field_get_type(field); + if (field_type != stream->trace->packet_header_type) { + ret = -1; + goto end; + } + + bt_ctf_field_get(field); + bt_ctf_field_put(stream->packet_header); + stream->packet_header = field; +end: + if (field_type) { + bt_ctf_field_type_put(field_type); + } + return ret; +} + int bt_ctf_stream_flush(struct bt_ctf_stream *stream) { int ret = 0; diff --git a/include/babeltrace/ctf-ir/stream.h b/include/babeltrace/ctf-ir/stream.h index 9cf02554..73fc5369 100644 --- a/include/babeltrace/ctf-ir/stream.h +++ b/include/babeltrace/ctf-ir/stream.h @@ -137,6 +137,31 @@ extern int bt_ctf_stream_set_event_context( struct bt_ctf_stream *stream, struct bt_ctf_field *event_context); +/* + * bt_ctf_stream_get_packet_header: get a stream's packet header. + * + * @param stream Stream instance. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_stream_get_packet_header( + struct bt_ctf_stream *stream); + +/* + * bt_ctf_stream_set_packet_header: set a stream's packet header. + * + * The packet header's type must match the trace's packet header + * type. + * + * @param stream Stream instance. + * @param packet_header Packet header instance. + * + * Returns a field instance on success, NULL on error. + */ +extern int bt_ctf_stream_set_packet_header( + struct bt_ctf_stream *stream, + struct bt_ctf_field *packet_header); + /* * bt_ctf_stream_flush: flush a stream. *