X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fevent.c;h=c168854e244ad4f81d61df6e5e2009f5663a646c;hb=9c4c8f6e75e53013a3db715f4d7c0058b77fd9cc;hp=d8def6252464919cea9790dcc4972bc33b1e4138;hpb=b8248cc00f72ac2448c697c76033c8862d8db673;p=babeltrace.git diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index d8def625..c168854e 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -36,6 +36,7 @@ #include #include #include +#include #include static @@ -137,7 +138,7 @@ end: int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class) { struct bt_object *obj = NULL; - int64_t ret; + int64_t ret = 0; if (!event_class) { ret = -1; @@ -525,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) { @@ -545,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; @@ -616,6 +623,22 @@ end: return event_class; } +struct bt_ctf_stream *bt_ctf_event_get_stream(struct bt_ctf_event *event) +{ + struct bt_ctf_stream *stream = NULL; + + if (!event) { + goto end; + } + + stream = event->stream; + if (stream) { + bt_ctf_stream_get(stream); + } +end: + return stream; +} + struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event) { struct bt_ctf_clock *clock = NULL; @@ -1185,3 +1208,93 @@ end: } return ret; } + +BT_HIDDEN +int bt_ctf_event_set_stream(struct bt_ctf_event *event, + struct bt_ctf_stream *stream) +{ + int ret = 0; + + if (!event) { + ret = -1; + goto end; + } + + if (event->stream && stream) { + /* Already attached to a stream */ + ret = -1; + goto end; + } + + event->stream = stream; +end: + return ret; +} + +struct bt_ctf_event *bt_ctf_event_copy(struct bt_ctf_event *event) +{ + struct bt_ctf_event *copy = NULL; + + if (!event) { + goto error; + } + + copy = g_new0(struct bt_ctf_event, 1); + if (!copy) { + goto error; + } + + bt_ctf_ref_init(©->ref_count); + copy->event_class = event->event_class; + bt_ctf_event_class_get(copy->event_class); + copy->stream = event->stream; + + if (event->event_header) { + copy->event_header = bt_ctf_field_copy(event->event_header); + + if (!copy->event_header) { + goto error; + } + } + + if (event->context_payload) { + copy->context_payload = bt_ctf_field_copy( + event->context_payload); + + if (!copy->context_payload) { + goto error; + } + } + + if (event->fields_payload) { + copy->fields_payload = bt_ctf_field_copy(event->fields_payload); + + if (!copy->fields_payload) { + goto error; + } + } + + return copy; + +error: + if (copy) { + if (copy->event_class) { + bt_ctf_event_class_put(copy->event_class); + } + + if (copy->event_header) { + bt_ctf_field_put(copy->event_header); + } + + if (copy->context_payload) { + bt_ctf_field_put(copy->context_payload); + } + + if (copy->fields_payload) { + bt_ctf_field_put(copy->fields_payload); + } + } + + g_free(copy); + return NULL; +}