Allow stream_id change in event class attributes
[babeltrace.git] / formats / ctf / ir / event-class.c
index 84976e808f21f56ba983c583887896b8fc962e64..fa5756d65930d1cc90276b97d3b7009b9dd76752 100644 (file)
@@ -38,6 +38,7 @@
 #include <babeltrace/ref.h>
 #include <babeltrace/ctf-ir/attributes-internal.h>
 #include <babeltrace/compiler.h>
+#include <babeltrace/endian.h>
 
 static
 void bt_ctf_event_class_destroy(struct bt_object *obj);
@@ -57,6 +58,7 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name)
                goto error;
        }
 
+       event_class->id = -1;
        bt_object_init(event_class, bt_ctf_event_class_destroy);
        event_class->fields = bt_ctf_field_type_structure_create();
        if (!event_class->fields) {
@@ -111,6 +113,11 @@ const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class)
                goto end;
        }
 
+       if (event_class->name) {
+               name = event_class->name;
+               goto end;
+       }
+
        obj = bt_ctf_attributes_get_field_value(event_class->attributes,
                BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX);
        if (!obj) {
@@ -136,6 +143,11 @@ int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class)
                goto end;
        }
 
+       if (event_class->id >= 0) {
+               ret = event_class->id;
+               goto end;
+       }
+
        obj = bt_ctf_attributes_get_field_value(event_class->attributes,
                BT_CTF_EVENT_CLASS_ATTR_ID_INDEX);
        if (!obj) {
@@ -208,7 +220,8 @@ int bt_ctf_event_class_set_attribute(
                goto end;
        }
 
-       if (!strcmp(name, "id") || !strcmp(name, "loglevel")) {
+       if (!strcmp(name, "id") || !strcmp(name, "loglevel") ||
+                       !strcmp(name, "stream_id")) {
                if (!bt_value_is_integer(value)) {
                        ret = -1;
                        goto end;
@@ -241,7 +254,7 @@ int bt_ctf_event_class_set_attribute(
        }
 
        ret = bt_ctf_attributes_set_field_value(event_class->attributes,
-               name, value);
+                       name, value);
 
 end:
        return ret;
@@ -546,6 +559,8 @@ void bt_ctf_event_class_freeze(struct bt_ctf_event_class *event_class)
 {
        assert(event_class);
        event_class->frozen = 1;
+       event_class->name = bt_ctf_event_class_get_name(event_class);
+       event_class->id = bt_ctf_event_class_get_id(event_class);
        bt_ctf_field_type_freeze(event_class->context);
        bt_ctf_field_type_freeze(event_class->fields);
        bt_ctf_attributes_freeze(event_class->attributes);
This page took 0.026012 seconds and 4 git commands to generate.