ir: bt_ctf_trace_add_stream_class(): add stream class's clock
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 16 Feb 2016 19:50:21 +0000 (14:50 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 22 Feb 2016 17:49:16 +0000 (12:49 -0500)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/trace.c

index 660a2ed5c6abf438687345aa0083b3dbb6667f71..2c0e7670f627600ef4bf7dc8ab3e7cbbd1aa02be 100644 (file)
@@ -440,6 +440,7 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
        struct bt_ctf_field_type *event_header_type = NULL;
        struct bt_ctf_field_type *stream_event_ctx_type = NULL;
        int event_class_count;
+       struct bt_ctf_clock *clock_to_add_to_trace = NULL;
 
        if (!trace || !stream_class) {
                ret = -1;
@@ -459,6 +460,32 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                }
        }
 
+       /*
+        * If the stream class has a clock, register this clock to this
+        * trace if not already done.
+        */
+       if (stream_class->clock) {
+               const char *clock_name =
+                       bt_ctf_clock_get_name(stream_class->clock);
+               struct bt_ctf_clock *trace_clock;
+
+               assert(clock_name);
+               trace_clock = bt_ctf_trace_get_clock_by_name(trace, clock_name);
+               bt_put(trace_clock);
+               if (trace_clock) {
+                       if (trace_clock != stream_class->clock) {
+                               /*
+                                * Error: two different clocks in the
+                                * trace would share the same name.
+                                */
+                               ret = -1;
+                               goto end;
+                       }
+               } else {
+                       clock_to_add_to_trace = bt_get(stream_class->clock);
+               }
+       }
+
        /*
         * We're about to freeze both the trace and the stream class.
         * Also, each event class contained in this stream class are
@@ -621,6 +648,13 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                trace->byte_order);
        bt_ctf_stream_class_set_byte_order(stream_class, trace->byte_order);
 
+       /* Add stream class's clock if it exists */
+       if (clock_to_add_to_trace) {
+               int add_clock_ret =
+                       bt_ctf_trace_add_clock(trace, clock_to_add_to_trace);
+               assert(add_clock_ret == 0);
+       }
+
        /*
         * Freeze the trace and the stream class.
         */
@@ -641,6 +675,7 @@ end:
 
        g_free(ec_validation_outputs);
        bt_ctf_validation_output_put_types(&trace_sc_validation_output);
+       BT_PUT(clock_to_add_to_trace);
        assert(!packet_header_type);
        assert(!packet_context_type);
        assert(!event_header_type);
This page took 0.025801 seconds and 4 git commands to generate.