int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event) { int ret = 0; if (!stream || !event || stream->pos.fd < 0) { ret = -1; goto end; } /* * The event is not supposed to have a parent stream at this * point. The only other way an event can have a parent stream * is if it was assigned when setting a packet to the event, * in which case the packet's stream is not a writer stream, * and thus the user is trying to append an event which belongs * to another stream. */ if (event->base.parent) { ret = -1; goto end; } bt_object_set_parent(event, stream); ret = bt_ctf_event_populate_event_header(event); if (ret) { goto error; } /* Make sure the various scopes of the event are set */ ret = bt_ctf_event_validate(event); if (ret) { goto error; } /* Save the new event and freeze it */ bt_ctf_event_freeze(event); g_ptr_array_add(stream->events, event); /* * Event had to hold a reference to its event class as long as it wasn't * part of the same trace hierarchy. From now on, the event and its * class share the same lifetime guarantees and the reference is no * longer needed. */ bt_put(event->event_class); end: return ret; error: /* * Orphan the event; we were not successful in associating it to * a stream. */ bt_object_set_parent(event, NULL); return ret; }
struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event, struct bt_clock_class_priority_map *cc_prio_map) { struct bt_notification_event *notification = NULL; if (!event || !cc_prio_map) { goto error; } if (!bt_ctf_event_borrow_packet(event)) { goto error; } if (!event_has_trace(event)) { goto error; } notification = g_new0(struct bt_notification_event, 1); if (!notification) { goto error; } bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, bt_notification_event_destroy); notification->event = bt_get(event); notification->cc_prio_map = bt_get(cc_prio_map); if (!validate_clock_classes(notification)) { goto error; } bt_ctf_event_freeze(notification->event); bt_clock_class_priority_map_freeze(notification->cc_prio_map); return ¬ification->parent; error: bt_put(notification); return NULL; }