Add support for custom event headers
[babeltrace.git] / formats / ctf / ir / stream.c
index 18c9edfd96000e03b8e6bd65dd81dd4e0f6d4bb6..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) {
@@ -355,6 +354,21 @@ void bt_ctf_stream_set_trace(struct bt_ctf_stream *stream,
        stream->trace = trace;
 }
 
+struct bt_ctf_stream_class *bt_ctf_stream_get_class(
+               struct bt_ctf_stream *stream)
+{
+       struct bt_ctf_stream_class *stream_class = NULL;
+
+       if (!stream) {
+               goto end;
+       }
+
+       stream_class = stream->stream_class;
+       bt_ctf_stream_class_get(stream_class);
+end:
+       return stream_class;
+}
+
 int bt_ctf_stream_get_discarded_events_count(
                struct bt_ctf_stream *stream, uint64_t *count)
 {
@@ -494,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) {
@@ -666,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;
 
@@ -688,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(
@@ -764,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.02625 seconds and 4 git commands to generate.