ir: add optional name property to stream
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 17 Feb 2016 23:57:04 +0000 (18:57 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 22 Feb 2016 18:05:17 +0000 (13:05 -0500)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/stream.c
formats/ctf/writer/writer.c
include/babeltrace/ctf-ir/stream-internal.h
include/babeltrace/ctf-ir/stream.h
tests/lib/test_ctf_writer.c

index b3081de487749d101906d92e33438720b305f14e..f2706169bd488a05264efcec5d2b336c62ef20e8 100644 (file)
@@ -299,7 +299,8 @@ end:
 }
 
 struct bt_ctf_stream *bt_ctf_stream_create(
-               struct bt_ctf_stream_class *stream_class)
+               struct bt_ctf_stream_class *stream_class,
+               const char *name)
 {
        int ret;
        struct bt_ctf_stream *stream = NULL;
@@ -307,17 +308,17 @@ struct bt_ctf_stream *bt_ctf_stream_create(
        struct bt_ctf_writer *writer = NULL;
 
        if (!stream_class) {
-               goto end;
+               goto error;
        }
 
        trace = bt_ctf_stream_class_get_trace(stream_class);
        if (!trace) {
-               goto end;
+               goto error;
        }
 
        stream = g_new0(struct bt_ctf_stream, 1);
        if (!stream) {
-               goto end;
+               goto error;
        }
 
        bt_object_init(stream, bt_ctf_stream_destroy);
@@ -330,6 +331,13 @@ struct bt_ctf_stream *bt_ctf_stream_create(
        stream->stream_class = stream_class;
        stream->pos.fd = -1;
 
+       if (name) {
+               stream->name = g_string_new(name);
+               if (!stream->name) {
+                       goto error;
+               }
+       }
+
        if (trace->is_created_by_writer) {
                int fd;
                writer = (struct bt_ctf_writer *)
@@ -400,7 +408,6 @@ struct bt_ctf_stream *bt_ctf_stream_create(
        /* Add this stream to the trace's streams */
        g_ptr_array_add(trace->streams, stream);
 
-end:
        BT_PUT(trace);
        BT_PUT(writer);
        return stream;
@@ -906,6 +913,10 @@ void bt_ctf_stream_destroy(struct bt_object *obj)
        if (stream->events) {
                g_ptr_array_free(stream->events, TRUE);
        }
+
+       if (stream->name) {
+               g_string_free(stream->name, TRUE);
+       }
        bt_put(stream->packet_header);
        bt_put(stream->packet_context);
        bt_put(stream->event_context);
@@ -961,3 +972,17 @@ end:
        bt_put(field_type);
        return ret;
 }
+
+const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream)
+{
+       const char *name = NULL;
+
+       if (!stream) {
+               goto end;
+       }
+
+       name = stream->name ? stream->name->str : NULL;
+
+end:
+       return name;
+}
index fe6f52cbf918372094a18d95c00e65702c150a01..6c294931c49cb47ac1c55fc731a531342423d142 100644 (file)
@@ -181,7 +181,7 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer,
                }
        }
 
-       stream = bt_ctf_stream_create(stream_class);
+       stream = bt_ctf_stream_create(stream_class, NULL);
        if (!stream) {
                goto error;
        }
index 155794042d0eee1b89963d0e498ed9cd4257b2cd..5ffe815ee089ca86ef89ebb3110e966331045975 100644 (file)
@@ -44,6 +44,7 @@ struct bt_ctf_stream {
        GPtrArray *events;
        struct ctf_stream_pos pos;
        unsigned int flushed_packet_count;
+       GString *name;
        struct bt_ctf_field *packet_header;
        struct bt_ctf_field *packet_context;
        struct bt_ctf_field *event_header;
index 53f02da676dcad49444b5bcae776e3ce2f6751fe..a08e327f5d38de1a28c223796c9aef7366d094e3 100644 (file)
@@ -41,7 +41,10 @@ struct bt_ctf_event;
 struct bt_ctf_stream;
 
 extern struct bt_ctf_stream *bt_ctf_stream_create(
-               struct bt_ctf_stream_class *stream_class);
+               struct bt_ctf_stream_class *stream_class,
+               const char *name);
+
+extern const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream);
 
 /*
  * bt_ctf_stream_get_stream_class: get a stream's class.
index 53a5a41dc336853d46617ad7c9cca38c20bb562b..a2fbd2e4a3fbd1544f5b7f39eb30441d5391f18f 100644 (file)
@@ -58,7 +58,7 @@
 #define DEFAULT_CLOCK_TIME 0
 #define DEFAULT_CLOCK_VALUE 0
 
-#define NR_TESTS 589
+#define NR_TESTS 590
 
 static int64_t current_time = 42;
 
@@ -2670,6 +2670,7 @@ void test_create_writer_stream_from_stream_class(void)
 {
        int ret;
        char trace_path[] = "/tmp/ctfwriter_XXXXXX";
+       const char *writer_stream_name = "writer stream instance";
        struct bt_ctf_writer *writer = NULL;
        struct bt_ctf_trace *writer_trace = NULL;
        struct bt_ctf_stream_class *writer_sc = NULL;
@@ -2702,8 +2703,10 @@ void test_create_writer_stream_from_stream_class(void)
        assert(!ret);
        ret = bt_ctf_trace_add_stream_class(writer_trace, writer_sc);
        assert(!ret);
-       writer_stream = bt_ctf_stream_create(writer_sc);
+       writer_stream = bt_ctf_stream_create(writer_sc, writer_stream_name);
        assert(writer_stream);
+       ok(!strcmp(bt_ctf_stream_get_name(writer_stream), writer_stream_name),
+               "bt_ctf_stream_get_name() returns the stream's name");
 
        /* Create non-writer trace, stream class, and stream */
        non_writer_trace = bt_ctf_trace_create();
@@ -2715,7 +2718,7 @@ void test_create_writer_stream_from_stream_class(void)
        assert(!ret);
        ret = bt_ctf_trace_add_stream_class(non_writer_trace, non_writer_sc);
        assert(!ret);
-       non_writer_stream = bt_ctf_stream_create(non_writer_sc);
+       non_writer_stream = bt_ctf_stream_create(non_writer_sc, NULL);
        assert(non_writer_stream);
 
        /* Create event class and event */
This page took 0.029727 seconds and 4 git commands to generate.