Map default event header timestamp field to the stream class' clock
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 13 Feb 2015 01:12:44 +0000 (20:12 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 13 Feb 2015 01:12:44 +0000 (20:12 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-types.c
formats/ctf/ir/stream-class.c

index ee81257149673373ed00c7d94af1a637a47ec4d4..ad569c6ce12c20cae71220df09b0570d40bc1033 100644 (file)
@@ -1871,7 +1871,9 @@ void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref)
        integer = container_of(
                container_of(ref, struct bt_ctf_field_type, ref_count),
                struct bt_ctf_field_type_integer, parent);
-       bt_ctf_clock_put(integer->mapped_clock);
+       if (integer->mapped_clock) {
+               bt_ctf_clock_put(integer->mapped_clock);
+       }
        g_free(integer);
 }
 
index cd87dffa8624c4493042be22bef19f544c0b3202..18ae57eaccadc7ba733d8d36288af8b0f3f578a4 100644 (file)
@@ -120,12 +120,37 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class,
                struct bt_ctf_clock *clock)
 {
        int ret = 0;
+       struct bt_ctf_field_type *timestamp_field = NULL;
 
        if (!stream_class || !clock || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
+       /*
+        * Look for a "timestamp" field in the stream class' event header type
+        * and map the stream's clock to that field if no current mapping is
+        * currently set.
+        */
+       timestamp_field = bt_ctf_field_type_structure_get_field_type_by_name(
+               stream_class->event_header_type, "timestamp");
+       if (timestamp_field) {
+               struct bt_ctf_clock *mapped_clock;
+
+               mapped_clock = bt_ctf_field_type_integer_get_mapped_clock(
+                       timestamp_field);
+               if (mapped_clock) {
+                       bt_ctf_clock_put(mapped_clock);
+                       goto end;
+               }
+
+               ret = bt_ctf_field_type_integer_set_mapped_clock(
+                       timestamp_field, clock);
+               if (ret) {
+                       goto end;
+               }
+       }
+
        if (stream_class->clock) {
                bt_ctf_clock_put(stream_class->clock);
        }
@@ -133,6 +158,9 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class,
        stream_class->clock = clock;
        bt_ctf_clock_get(clock);
 end:
+       if (timestamp_field) {
+               bt_ctf_field_type_put(timestamp_field);
+       }
        return ret;
 }
 
This page took 0.027374 seconds and 4 git commands to generate.