Add bt_ctf_trace_get_stream_count() and bt_ctf_trace_get_stream()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 26 Apr 2017 13:14:43 +0000 (09:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:41 +0000 (12:57 -0400)
With the two new functions you can access the streams of a trace. The
use case is for any component to be able to check if it has received a
"stream end" notification for each stream of a given trace and discard
anything associated with this trace if it's the case.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/ctf-ir/trace.h
lib/ctf-ir/trace.c
tests/lib/test_ctf_writer.c
tests/lib/test_trace_listener.c

index 91b09f80eb409be76244dd7c4ff55a333344c194..858d9681624c6311671f4a1cac9068f26b8b5ae4 100644 (file)
@@ -76,6 +76,10 @@ can add an event class to a stream class with
 bt_ctf_stream_class_add_event_class(). You can add a stream class to a
 trace class with bt_ctf_trace_add_stream_class().
 
+You can access the streams of a trace, that is, the streams which were
+created from the trace's stream classes with bt_ctf_stream_create(),
+with bt_ctf_trace_get_stream().
+
 A trace class owns the <strong>trace packet header</strong>
 \link ctfirfieldtypes field type\endlink, which represents the
 \c trace.packet.header CTF scope. This field type describes the
@@ -720,6 +724,46 @@ extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace_class,
 
 /** @} */
 
+/**
+@name Stream children functions
+@{
+*/
+
+/**
+@brief  Returns the number of streams contained in the CTF IR trace
+       class \p trace_class.
+
+@param[in] trace_class Trace class of which to get the number
+                       of children streams.
+@returns               Number of children streams
+                       contained in \p trace_class, or a negative
+                       value on error.
+
+@prenotnull{trace_class}
+@postrefcountsame{trace_class}
+*/
+extern int bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace_class);
+
+/**
+@brief  Returns the stream at index \p index in the CTF IR trace
+       class \p trace_class.
+
+@param[in] trace_class Trace class of which to get the stream.
+@param[in] index       Index of the stream to find.
+@returns               Stream at index \p index, or \c NULL
+                       on error.
+
+@prenotnull{trace_class}
+@pre \p index is lesser than the number of streams contained in
+       the trace class \p trace_class (see
+       bt_ctf_trace_get_stream_count()).
+@postrefcountsame{trace_class}
+*/
+extern struct bt_ctf_stream *bt_ctf_trace_get_stream(
+               struct bt_ctf_trace *trace_class, int index);
+
+/** @} */
+
 /**
 @name Misc. functions
 @{
index 9514c6d7ffa58a464d87ea7601af46551263856f..b850b4ffe6e35495fcc07bad3eea2c2105a41a75 100644 (file)
@@ -715,6 +715,36 @@ end:
        return ret;
 }
 
+int bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace)
+{
+       int ret;
+
+       if (!trace) {
+               ret = -1;
+               goto end;
+       }
+
+       ret = trace->streams->len;
+
+end:
+       return ret;
+}
+
+struct bt_ctf_stream *bt_ctf_trace_get_stream(struct bt_ctf_trace *trace,
+               int index)
+{
+       struct bt_ctf_stream *stream = NULL;
+
+       if (!trace || index >= trace->streams->len) {
+               goto end;
+       }
+
+       stream = bt_get(g_ptr_array_index(trace->streams, index));
+
+end:
+       return stream;
+}
+
 int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace)
 {
        int ret;
index 9f76f7b37704bf8ac8d76580eaedb201a0d3c14e..1995d3d93bb79ab7e7e03d750de186e80023320a 100644 (file)
@@ -2795,6 +2795,7 @@ int main(int argc, char **argv)
        struct bt_ctf_clock_class *ret_clock_class;
        struct bt_ctf_stream_class *stream_class, *ret_stream_class;
        struct bt_ctf_stream *stream1;
+       struct bt_ctf_stream *stream;
        const char *ret_string;
        const unsigned char *ret_uuid;
        unsigned char tmp_uuid[16] = { 0 };
@@ -3272,8 +3273,16 @@ int main(int argc, char **argv)
        /* Instantiate a stream and append events */
        ret = bt_ctf_writer_add_clock(writer, clock);
        assert(ret == 0);
+       ok(bt_ctf_trace_get_stream_count(trace) == 0,
+               "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (0)");
        stream1 = bt_ctf_writer_create_stream(writer, stream_class);
        ok(stream1, "Instanciate a stream class from writer");
+       ok(bt_ctf_trace_get_stream_count(trace) == 1,
+               "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (1)");
+       stream = bt_ctf_trace_get_stream(trace, 0);
+       ok(stream == stream1,
+               "bt_ctf_trace_get_stream() succeeds and returns the correct value");
+       BT_PUT(stream);
 
        /*
         * Creating a stream through a writer adds the given stream
index 469399fb3ba9fd106b4785a0edb262bb7cb07b75..18255eea0c0eacc47c8226dc79e074c9828059b6 100644 (file)
@@ -24,6 +24,7 @@
 #include <babeltrace/ctf-ir/field-types.h>
 #include <babeltrace/ctf-ir/stream-class.h>
 #include <babeltrace/ctf-ir/trace.h>
+#include <babeltrace/ctf-ir/trace-internal.h>
 #include <stdlib.h>
 #include <string.h>
 
This page took 0.030457 seconds and 4 git commands to generate.