Add support for custom event headers
[babeltrace.git] / formats / ctf / ir / stream.c
index d291981eaace2fe1eb9fd16070755b5ee3d2fcac..93982b3b48b13796a61f194862f1bc30a04c0b44 100644 (file)
@@ -296,7 +296,6 @@ struct bt_ctf_stream *bt_ctf_stream_create(
        stream->id = stream_class->next_stream_id++;
        stream->stream_class = stream_class;
        bt_ctf_stream_class_get(stream_class);
-       bt_ctf_stream_class_freeze(stream_class);
        stream->events = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_ctf_event_put);
        if (!stream->events) {
@@ -509,6 +508,11 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
                goto end;
        }
 
+       ret = bt_ctf_event_populate_event_header(event);
+       if (ret) {
+               goto end;
+       }
+
        /* Make sure the event's payload is set */
        ret = bt_ctf_event_validate(event);
        if (ret) {
@@ -681,7 +685,6 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        int ret = 0;
        size_t i;
        uint64_t timestamp_begin, timestamp_end, events_discarded;
-       struct bt_ctf_stream_class *stream_class;
        struct bt_ctf_field *integer = NULL;
        struct ctf_stream_pos packet_context_pos;
 
@@ -703,17 +706,14 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                goto end;
        }
 
-       if (stream->flushed_packet_count) {
-               /* ctf_init_pos has already initialized the first packet */
-               ctf_packet_seek(&stream->pos.parent, 0, SEEK_CUR);
-       }
+       /* mmap the next packet */
+       ctf_packet_seek(&stream->pos.parent, 0, SEEK_CUR);
 
        ret = bt_ctf_field_serialize(stream->packet_header, &stream->pos);
        if (ret) {
                goto end;
        }
 
-       stream_class = stream->stream_class;
        timestamp_begin = ((struct bt_ctf_event *) g_ptr_array_index(
                stream->events, 0))->timestamp;
        timestamp_end = ((struct bt_ctf_event *) g_ptr_array_index(
@@ -779,24 +779,24 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                        event->event_class);
                uint64_t timestamp = bt_ctf_event_get_timestamp(event);
 
-               ret = bt_ctf_field_reset(stream_class->event_header);
+               ret = bt_ctf_field_reset(event->event_header);
                if (ret) {
                        goto end;
                }
 
-               ret = set_structure_field_integer(stream_class->event_header,
+               ret = set_structure_field_integer(event->event_header,
                        "id", event_id);
                if (ret) {
                        goto end;
                }
-               ret = set_structure_field_integer(stream_class->event_header,
+               ret = set_structure_field_integer(event->event_header,
                        "timestamp", timestamp);
                if (ret) {
                        goto end;
                }
 
                /* Write event header */
-               ret = bt_ctf_field_serialize(stream_class->event_header,
+               ret = bt_ctf_field_serialize(event->event_header,
                        &stream->pos);
                if (ret) {
                        goto end;
This page took 0.024132 seconds and 4 git commands to generate.