Fix: ir: make sure "stream_id" attr is always right
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 13 Apr 2015 22:14:59 +0000 (18:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 14 Apr 2015 15:41:25 +0000 (11:41 -0400)
Make sure the "stream_id" attribute of all the event
classes of a given stream class is updated at the following
places:

  * user sets the stream class ID manually: calling
    bt_ctf_stream_class_set_id()
  * stream class ID is automatically set: in
    bt_ctf_trace_add_stream_class()
  * an event class is added to an existing stream
    class: in bt_ctf_stream_class_add_event_class()

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event.c
formats/ctf/ir/stream-class.c
formats/ctf/ir/trace.c
include/babeltrace/ctf-ir/event-internal.h
include/babeltrace/ctf-ir/stream-class-internal.h

index 2d15c83480f5fc074be98478427c6ad1ea0600e9..db55b26b5e68c0798ae7121151821954d85c14e5 100644 (file)
@@ -526,10 +526,31 @@ void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class)
        bt_ctf_ref_put(&event_class->ref_count, bt_ctf_event_class_destroy);
 }
 
+BT_HIDDEN
+int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class *event_class,
+               uint32_t stream_id)
+{
+       int ret = 0;
+       struct bt_object *obj;
+
+       obj = bt_object_integer_create_init(stream_id);
+
+       if (!obj) {
+               ret = -1;
+               goto end;
+       }
+
+       ret = bt_ctf_attributes_set_field_value(event_class->attributes,
+               "stream_id", obj);
+
+end:
+       BT_OBJECT_PUT(obj);
+
+       return ret;
+}
+
 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
 {
-       int ret;
-       struct bt_object *obj = NULL;
        struct bt_ctf_event *event = NULL;
 
        if (!event_class) {
@@ -546,21 +567,6 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
                goto end;
        }
        assert(event_class->stream_class->event_header_type);
-
-       /* set "stream_id" attribute now that we know its value */
-       obj = bt_object_integer_create_init(event_class->stream_class->id);
-       if (!obj) {
-               goto end;
-       }
-
-       ret = bt_ctf_attributes_set_field_value(event_class->attributes,
-               "stream_id", obj);
-       BT_OBJECT_PUT(obj);
-
-       if (ret) {
-               goto end;
-       }
-
        event = g_new0(struct bt_ctf_event, 1);
        if (!event) {
                goto end;
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);
index 94a332d162e4052ff9530baf63e0952d45a9b3af..5abfcc79c7ef197db758c781e6c4180a28b28776 100644 (file)
@@ -462,8 +462,7 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                        }
                }
 
-               if (_bt_ctf_stream_class_set_id(stream_class,
-                       stream_id)) {
+               if (bt_ctf_stream_class_set_id_no_check(stream_class, stream_id)) {
                        /* TODO Should retry with a different stream id */
                        ret = -1;
                        goto end;
index 2a172a94589d33e9970ad439b73e3b6f14573cb5..5201ee53b7c54e353cd24789d97a4dc93054c125 100644 (file)
@@ -81,6 +81,10 @@ void bt_ctf_event_class_set_native_byte_order(
                struct bt_ctf_event_class *event_class,
                int byte_order);
 
+BT_HIDDEN
+int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class *event_class,
+               uint32_t stream_id);
+
 BT_HIDDEN
 int bt_ctf_event_validate(struct bt_ctf_event *event);
 
index 3b368d1de2230bb26619b7a8763f09a052319af2..c88be91c02fa0ffe129938b3c941e60c38c56155 100644 (file)
@@ -70,6 +70,10 @@ BT_HIDDEN
 int _bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class,
                uint32_t id);
 
+BT_HIDDEN
+int bt_ctf_stream_class_set_id_no_check(
+               struct bt_ctf_stream_class *stream_class, uint32_t id);
+
 BT_HIDDEN
 int bt_ctf_stream_class_set_trace(struct bt_ctf_stream_class *stream_class,
                struct bt_ctf_trace *trace);
This page took 0.02812 seconds and 4 git commands to generate.