From 9c4c8f6e75e53013a3db715f4d7c0058b77fd9cc Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 7 Apr 2015 19:24:17 -0400 Subject: [PATCH] ir: add bt_ctf_event_copy() (event deep copy) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event.c | 68 +++++++++++++++++++++++++++++++ include/babeltrace/ctf-ir/event.h | 13 ++++++ 2 files changed, 81 insertions(+) diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index db55b26b..c168854e 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -1230,3 +1230,71 @@ int bt_ctf_event_set_stream(struct bt_ctf_event *event, 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; +} diff --git a/include/babeltrace/ctf-ir/event.h b/include/babeltrace/ctf-ir/event.h index 316c6eed..63bd74e5 100644 --- a/include/babeltrace/ctf-ir/event.h +++ b/include/babeltrace/ctf-ir/event.h @@ -474,6 +474,19 @@ extern struct bt_ctf_field *bt_ctf_event_get_event_context( extern int bt_ctf_event_set_event_context(struct bt_ctf_event *event, struct bt_ctf_field *context); +/* + * bt_ctf_event_copy: Deep-copy an event. + * + * Get an event's deep copy. + * + * On success, the returned copy has its reference count set to 1. + * + * @param event Event to copy. + * + * Returns the deep-copied event on success, NULL on error. + */ +extern struct bt_ctf_event *bt_ctf_event_copy(struct bt_ctf_event *event); + /* * bt_ctf_event_get and bt_ctf_event_put: increment and decrement * the event's reference count. -- 2.34.1