Add support for custom event headers
[babeltrace.git] / formats / ctf / ir / trace.c
index 68bfd67afdab8e71ad38189ac104c397a2a5c98e..495df226999baf28af3aa348dd10419ce2f82cb1 100644 (file)
@@ -143,13 +143,6 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace,
                goto error;
        }
 
-       ret = bt_ctf_stream_class_set_byte_order(stream_class,
-               trace->byte_order == LITTLE_ENDIAN ?
-               BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN);
-       if (ret) {
-               goto error;
-       }
-
        stream = bt_ctf_stream_create(stream_class, trace);
        if (!stream) {
                goto error;
@@ -185,9 +178,25 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace,
 
        bt_ctf_stream_get(stream);
        g_ptr_array_add(trace->streams, stream);
+
+       /*
+        * Freeze the trace and its packet header.
+        *
+        * All field type byte orders set as "native" byte ordering can now be
+        * safely set to trace's own endianness, including the stream class'.
+        */
+       bt_ctf_field_type_set_native_byte_order(trace->packet_header_type,
+               trace->byte_order);
+       ret = bt_ctf_stream_class_set_byte_order(stream_class,
+               trace->byte_order == LITTLE_ENDIAN ?
+               BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN);
+       if (ret) {
+               goto error;
+       }
+
+       bt_ctf_stream_class_freeze(stream_class);
        trace->frozen = 1;
        return stream;
-
 error:
        bt_ctf_stream_put(stream);
        return NULL;
@@ -433,7 +442,16 @@ int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace,
 
        switch (byte_order) {
        case BT_CTF_BYTE_ORDER_NATIVE:
-               internal_byte_order =  (G_BYTE_ORDER == G_LITTLE_ENDIAN) ?
+               /*
+                * This doesn't make sense since the CTF specification defines
+                * the "native" byte order as "the byte order described in the
+                * trace description". However, this behavior had been
+                * implemented as part of v1.2 and is kept to maintain
+                * compatibility.
+                *
+                * This may be changed on a major version bump only.
+                */
+               internal_byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN) ?
                        LITTLE_ENDIAN : BIG_ENDIAN;
                break;
        case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
@@ -449,9 +467,6 @@ int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace,
        }
 
        trace->byte_order = internal_byte_order;
-       if (trace->packet_header_type) {
-               init_trace_packet_header(trace);
-       }
 end:
        return ret;
 }
@@ -549,14 +564,6 @@ int init_trace_packet_header(struct bt_ctf_trace *trace)
                goto end;
        }
 
-       ret = bt_ctf_field_type_set_byte_order(_uint32_t,
-               (trace->byte_order == LITTLE_ENDIAN ?
-               BT_CTF_BYTE_ORDER_LITTLE_ENDIAN :
-               BT_CTF_BYTE_ORDER_BIG_ENDIAN));
-       if (ret) {
-               goto end;
-       }
-
        ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
                _uint32_t, "magic");
        if (ret) {
@@ -575,17 +582,18 @@ int init_trace_packet_header(struct bt_ctf_trace *trace)
                goto end;
        }
 
-       bt_ctf_field_type_put(trace->packet_header_type);
-       trace->packet_header_type = trace_packet_header_type;
+       ret = bt_ctf_trace_set_packet_header_type(trace,
+               trace_packet_header_type);
+       if (ret) {
+               goto end;
+       }
 end:
        bt_ctf_field_type_put(uuid_array_type);
        bt_ctf_field_type_put(_uint32_t);
        bt_ctf_field_type_put(_uint8_t);
        bt_ctf_field_put(magic);
        bt_ctf_field_put(uuid_array);
-       if (ret) {
-               bt_ctf_field_type_put(trace_packet_header_type);
-       }
+       bt_ctf_field_type_put(trace_packet_header_type);
 
        return ret;
 }
This page took 0.025153 seconds and 4 git commands to generate.