Fix: lock stream class after assigning stream id
[babeltrace.git] / formats / ctf / ir / stream.c
index 80d13111c1a4ee18b310fb74e3f16cfb2b461077..6a71466ca3a60022a178b684b43508e4bed6a5be 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)
 {
@@ -617,6 +631,50 @@ end:
        return ret;
 }
 
+struct bt_ctf_field *bt_ctf_stream_get_packet_header(
+               struct bt_ctf_stream *stream)
+{
+       struct bt_ctf_field *packet_header = NULL;
+
+       if (!stream) {
+               goto end;
+       }
+
+       packet_header = stream->packet_header;
+       if (packet_header) {
+               bt_ctf_field_get(packet_header);
+       }
+end:
+       return packet_header;
+}
+
+int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
+               struct bt_ctf_field *field)
+{
+       int ret = 0;
+       struct bt_ctf_field_type *field_type = NULL;
+
+       if (!stream || !field) {
+               ret = -1;
+               goto end;
+       }
+
+       field_type = bt_ctf_field_get_type(field);
+       if (field_type != stream->trace->packet_header_type) {
+               ret = -1;
+               goto end;
+       }
+
+       bt_ctf_field_get(field);
+       bt_ctf_field_put(stream->packet_header);
+       stream->packet_header = field;
+end:
+       if (field_type) {
+               bt_ctf_field_type_put(field_type);
+       }
+       return ret;
+}
+
 int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
 {
        int ret = 0;
This page took 0.026788 seconds and 4 git commands to generate.