Fix: ir: make sure "stream_id" attr is always right
[babeltrace.git] / formats / ctf / ir / stream-class.c
index 572d7424e658a0c6532f7734a69982b36b0dd9ab..aba76cd17229dbc452c45312670ff0950705b0c8 100644 (file)
@@ -219,13 +219,36 @@ int _bt_ctf_stream_class_set_id(
        return 0;
 }
 
-int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class,
-               uint32_t id)
+struct event_class_set_stream_id_data {
+       uint32_t stream_id;
+       int ret;
+};
+
+static
+void event_class_set_stream_id(gpointer event_class, gpointer data)
+{
+       struct event_class_set_stream_id_data *typed_data = data;
+
+       typed_data->ret |= bt_ctf_event_class_set_stream_id(event_class,
+               typed_data->stream_id);
+}
+
+BT_HIDDEN
+int bt_ctf_stream_class_set_id_no_check(
+               struct bt_ctf_stream_class *stream_class, uint32_t id)
 {
        int ret = 0;
+       struct event_class_set_stream_id_data data =
+               { .stream_id = id, .ret = 0 };
 
-       if (!stream_class || stream_class->frozen) {
-               ret = -1;
+       /*
+        * Make sure all event classes have their "stream_id" attribute
+        * set to this value.
+        */
+       g_ptr_array_foreach(stream_class->event_classes,
+               event_class_set_stream_id, &data);
+       ret = data.ret;
+       if (ret) {
                goto end;
        }
 
@@ -237,6 +260,21 @@ end:
        return ret;
 }
 
+int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class,
+               uint32_t id)
+{
+       int ret = 0;
+
+       if (!stream_class || stream_class->frozen) {
+               ret = -1;
+               goto end;
+       }
+
+       ret = bt_ctf_stream_class_set_id_no_check(stream_class, id);
+end:
+       return ret;
+}
+
 static
 void event_class_exists(gpointer element, gpointer query)
 {
@@ -317,6 +355,11 @@ int bt_ctf_stream_class_add_event_class(
                goto end;
        }
 
+       ret = bt_ctf_event_class_set_stream_id(event_class, stream_class->id);
+       if (ret) {
+               goto end;
+       }
+
        bt_ctf_event_class_get(event_class);
        g_ptr_array_add(stream_class->event_classes, event_class);
        bt_ctf_event_class_freeze(event_class);
This page took 0.024903 seconds and 4 git commands to generate.