- /*
- * 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);
- BT_LOGD("Created event object: addr=%p, event-class-name=\"%s\", "
- "event-class-id=%" PRId64,
- event, bt_ctf_event_class_get_name(event->event_class),
- bt_ctf_event_class_get_id(event_class));
- 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;
-}
-
-struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event)
-{
- struct bt_ctf_event_class *event_class = NULL;
-
- if (!event) {
- BT_LOGW_STR("Invalid parameter: event is NULL.");
- goto end;
- }
-
- event_class = bt_get(bt_ctf_event_borrow_event_class(event));
-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) {
- BT_LOGW_STR("Invalid parameter: event is NULL.");
- goto end;
- }
-
- /*
- * If the event has a parent, then this is its (writer) stream.
- * If the event has no parent, then if it has a packet, this
- * is its (non-writer) stream.
- */
- if (event->base.parent) {
- stream = (struct bt_ctf_stream *) bt_object_get_parent(event);
- } else {
- if (event->packet) {
- stream = bt_get(event->packet->stream);
- }
- }
-
-end:
- return stream;
-}
-
-int bt_ctf_event_set_payload(struct bt_ctf_event *event,
- const char *name,
- struct bt_ctf_field *payload)
-{
- int ret = 0;
-
- if (!event || !payload) {
- BT_LOGW("Invalid parameter: event or payload field is NULL: "
- "event-addr=%p, payload-field-addr=%p",
- event, payload);
- ret = -1;
- goto end;
- }
-
- if (event->frozen) {
- BT_LOGW("Invalid parameter: event is frozen: addr=%p, "
- "event-class-name=\"%s\", event-class-id=%" PRId64,
- event, bt_ctf_event_class_get_name(event->event_class),
- bt_ctf_event_class_get_id(event->event_class));
- ret = -1;
- goto end;
- }
-
- if (name) {
- ret = bt_ctf_field_structure_set_field_by_name(
- event->fields_payload, name, payload);
- } else {
- struct bt_ctf_field_type *payload_type;
-
- payload_type = bt_ctf_field_get_type(payload);
-
- if (bt_ctf_field_type_compare(payload_type,
- event->event_class->fields) == 0) {
- bt_put(event->fields_payload);
- bt_get(payload);
- event->fields_payload = payload;
- } else {
- BT_LOGW("Invalid parameter: payload field type is different from the expected field type: "
- "event-addr=%p, event-class-name=\"%s\", "
- "event-class-id=%" PRId64,
- event,
- bt_ctf_event_class_get_name(event->event_class),
- bt_ctf_event_class_get_id(event->event_class));
- ret = -1;