- /*
- * At this point we know the trace (if associated to the stream
- * class), the stream class, and the event class, with their
- * current types, are valid. We may proceed with creating
- * the event.
- */
- event = g_new0(struct bt_ctf_event, 1);
- if (!event) {
- goto error;
- }
-
- bt_object_init(event, bt_ctf_event_destroy);
-
- /*
- * event does not share a common ancestor with the event class; it has
- * to guarantee its existence by holding a reference. This reference
- * shall be released once the event is associated to a stream since,
- * from that point, the event and its class will share the same
- * lifetime.
- */
- event->event_class = bt_get(event_class);
- event->clock_values = g_hash_table_new_full(g_direct_hash,
- g_direct_equal, bt_put, bt_put);
- event_header =
- bt_ctf_field_create(validation_output.event_header_type);
- if (!event_header) {
- goto error;
- }
-
- if (validation_output.stream_event_ctx_type) {
- stream_event_context = bt_ctf_field_create(
- validation_output.stream_event_ctx_type);
- if (!stream_event_context) {
- goto error;
- }
- }
-
- if (validation_output.event_context_type) {
- event_context = bt_ctf_field_create(
- validation_output.event_context_type);
- if (!event_context) {
- goto error;
- }
- }
-
- if (validation_output.event_payload_type) {
- event_payload = bt_ctf_field_create(
- validation_output.event_payload_type);
- if (!event_payload) {
- goto error;
- }
- }
-
- /*
- * At this point all the fields are created, potentially from
- * validated copies of field types, so that the field types and
- * fields can be replaced in the trace, stream class,
- * event class, and created event.
- */
- bt_ctf_validation_replace_types(trace, stream_class,
- event_class, &validation_output, validation_flags);
- BT_MOVE(event->event_header, event_header);
- BT_MOVE(event->stream_event_context, stream_event_context);
- BT_MOVE(event->context_payload, event_context);
- BT_MOVE(event->fields_payload, event_payload);
-
- /*
- * Put what was not moved in bt_ctf_validation_replace_types().
- */
- bt_ctf_validation_output_put_types(&validation_output);
-
- /*
- * Freeze the stream class since the event header must not be changed
- * anymore.
- */
- bt_ctf_stream_class_freeze(stream_class);
-
- /*
- * Mark stream class, and event class as valid since
- * they're all frozen now.
- */
- stream_class->valid = 1;
- event_class->valid = 1;
-
- /* Put stuff we borrowed from the event class */
- BT_PUT(stream_class);
- BT_PUT(trace);
-
- return event;
-
-error:
- bt_ctf_validation_output_put_types(&validation_output);
- BT_PUT(event);
- BT_PUT(stream_class);
- BT_PUT(trace);
- BT_PUT(event_header);
- BT_PUT(stream_event_context);
- BT_PUT(event_context);
- BT_PUT(event_payload);
- assert(!packet_header_type);
- assert(!packet_context_type);
- assert(!event_header_type);
- assert(!stream_event_ctx_type);
- assert(!event_context_type);
- assert(!event_payload_type);
-
- return event;