Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
		struct bt_ctf_event *event)
{
	int ret = 0;
	struct bt_ctf_field *event_context_copy = NULL;

	if (!stream || !event) {
		ret = -1;
		goto end;
	}

	ret = bt_ctf_event_set_stream(event, stream);
	if (ret) {
		/* Event was already associated to a stream */
		ret = -1;
		goto end;
	}

	ret = bt_ctf_event_populate_event_header(event);
	if (ret) {
		goto end;
	}

	/* Make sure the event's payload is set */
	ret = bt_ctf_event_validate(event);
	if (ret) {
		goto end;
	}

	/* Sample the current stream event context by copying it */
	if (stream->event_context) {
		/* Make sure the event context's payload is set */
		ret = bt_ctf_field_validate(stream->event_context);
		if (ret) {
			goto end;
		}

		event_context_copy = bt_ctf_field_copy(stream->event_context);
		if (!event_context_copy) {
			ret = -1;
			goto end;
		}
	}

	bt_get(event);
	/* Save the new event along with its associated stream event context */
	g_ptr_array_add(stream->events, event);
	if (event_context_copy) {
		g_ptr_array_add(stream->event_contexts, event_context_copy);
	}
end:
	if (ret) {
		(void) bt_ctf_event_set_stream(event, NULL);
	}
	return ret;
}