Exemple #1
0
BT_HIDDEN
int bt_ctf_event_set_payload_field(struct bt_ctf_event *event,
		struct bt_ctf_field *payload)
{
	int ret = 0;
	struct bt_ctf_field_type *payload_type = NULL;

	if (!event || !payload || event->frozen) {
		ret = -1;
		goto end;
	}

	payload_type = bt_ctf_field_get_type(payload);
	if (!payload_type) {
		ret = -1;
		goto end;
	}

	if (bt_ctf_field_type_get_type_id(payload_type) !=
			CTF_TYPE_STRUCT) {
		ret = -1;
		goto end;
	}

	bt_get(payload);
	bt_put(event->fields_payload);
	event->fields_payload = payload;

end:
	bt_put(payload_type);
	return ret;
}
Exemple #2
0
BT_HIDDEN
int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream,
		struct bt_ctf_field *field)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type;

	if (!stream || !field || stream->pos.fd < 0) {
		ret = -1;
		goto end;
	}

	field_type = bt_ctf_field_get_type(field);
	if (bt_ctf_field_type_compare(field_type,
			stream->stream_class->packet_context_type)) {
		ret = -1;
		goto end;
	}

	bt_put(field_type);
	bt_get(field);
	bt_put(stream->packet_context);
	stream->packet_context = field;
end:
	return ret;
}
Exemple #3
0
BT_HIDDEN
int bt_ctf_event_set_stream_event_context(struct bt_ctf_event *event,
		struct bt_ctf_field *stream_event_context)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_stream_class *stream_class = NULL;

	if (!event || !stream_event_context || event->frozen) {
		ret = -1;
		goto end;
	}

	stream_class = bt_ctf_event_class_get_stream_class(event->event_class);
	/*
	 * We should not have been able to create the event without associating
	 * the event class to a stream class.
	 */
	assert(stream_class);

	field_type = bt_ctf_field_get_type(stream_event_context);
	if (bt_ctf_field_type_compare(field_type,
			stream_class->event_context_type)) {
		ret = -1;
		goto end;
	}

	bt_get(stream_event_context);
	BT_MOVE(event->stream_event_context, stream_event_context);
end:
	BT_PUT(stream_class);
	bt_put(field_type);
	return ret;
}
Exemple #4
0
int bt_ctf_stream_get_discarded_events_count(
		struct bt_ctf_stream *stream, uint64_t *count)
{
	int64_t ret = 0;
	int field_signed;
	struct bt_ctf_field *events_discarded_field = NULL;
	struct bt_ctf_field_type *events_discarded_field_type = NULL;

	if (!stream || !count || !stream->packet_context) {
		ret = -1;
		goto end;
	}

	events_discarded_field = bt_ctf_field_structure_get_field(
		stream->packet_context, "events_discarded");
	if (!events_discarded_field) {
		ret = -1;
		goto end;
	}

	events_discarded_field_type = bt_ctf_field_get_type(
		events_discarded_field);
	if (!events_discarded_field_type) {
		ret = -1;
		goto end;
	}

	field_signed = bt_ctf_field_type_integer_get_signed(
		events_discarded_field_type);
	if (field_signed < 0) {
		ret = field_signed;
		goto end;
	}

	if (field_signed) {
		int64_t signed_count;

		ret = bt_ctf_field_signed_integer_get_value(
			events_discarded_field, &signed_count);
		if (ret) {
			goto end;
		}
		if (signed_count < 0) {
			/* Invalid value */
			ret = -1;
			goto end;
		}
		*count = (uint64_t) signed_count;
	} else {
		ret = bt_ctf_field_unsigned_integer_get_value(
			events_discarded_field, count);
		if (ret) {
			goto end;
		}
	}
end:
	bt_put(events_discarded_field);
	bt_put(events_discarded_field_type);
	return ret;
}
Exemple #5
0
BT_HIDDEN
int bt_ctf_event_set_event_context(struct bt_ctf_event *event,
		struct bt_ctf_field *context)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;

	if (!event || !context || event->frozen) {
		ret = -1;
		goto end;
	}

	field_type = bt_ctf_field_get_type(context);
	if (bt_ctf_field_type_compare(field_type,
			event->event_class->context)) {
		ret = -1;
		goto end;
	}

	bt_get(context);
	bt_put(event->context_payload);
	event->context_payload = context;
end:
	bt_put(field_type);
	return ret;
}
Exemple #6
0
BT_HIDDEN
int bt_ctf_event_set_header(struct bt_ctf_event *event,
		struct bt_ctf_field *header)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_stream_class *stream_class = NULL;

	if (!event || !header || event->frozen) {
		ret = -1;
		goto end;
	}

	stream_class = (struct bt_ctf_stream_class *) bt_object_get_parent(
		event->event_class);
	/*
	 * Ensure the provided header's type matches the one registered to the
	 * stream class.
	 */
	field_type = bt_ctf_field_get_type(header);
	if (bt_ctf_field_type_compare(field_type,
			stream_class->event_header_type)) {
		ret = -1;
		goto end;
	}

	bt_get(header);
	bt_put(event->event_header);
	event->event_header = header;
end:
	bt_put(stream_class);
	bt_put(field_type);
	return ret;
}
Exemple #7
0
BT_HIDDEN
int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
		struct bt_ctf_field *field)
{
	int ret = 0;
	struct bt_ctf_trace *trace = NULL;
	struct bt_ctf_field_type *field_type = NULL;

	if (!stream || !field || stream->pos.fd < 0) {
		ret = -1;
		goto end;
	}

	trace = (struct bt_ctf_trace *) bt_object_get_parent(stream);
	field_type = bt_ctf_field_get_type(field);
	if (bt_ctf_field_type_compare(field_type, trace->packet_header_type)) {
		ret = -1;
		goto end;
	}

	bt_get(field);
	bt_put(stream->packet_header);
	stream->packet_header = field;
end:
	BT_PUT(trace);
	bt_put(field_type);
	return ret;
}
Exemple #8
0
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 || event->frozen) {
		ret = -1;
		goto end;
	}

	if (name) {
		ret = bt_ctf_field_structure_set_field(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 {
			ret = -1;
		}

		bt_put(payload_type);
	}
end:
	return ret;
}
Exemple #9
0
void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
		uint64_t event_count)
{
	int ret;
	int field_signed;
	uint64_t previous_count;
	uint64_t new_count;
	struct bt_ctf_field *events_discarded_field = NULL;
	struct bt_ctf_field_type *events_discarded_field_type = NULL;

	if (!stream || !stream->packet_context) {
		goto end;
	}

	ret = bt_ctf_stream_get_discarded_events_count(stream,
		&previous_count);
	if (ret) {
		goto end;
	}

	events_discarded_field = bt_ctf_field_structure_get_field(
		stream->packet_context, "events_discarded");
	if (!events_discarded_field) {
		goto end;
	}

	events_discarded_field_type = bt_ctf_field_get_type(
		events_discarded_field);
	if (!events_discarded_field_type) {
		goto end;
	}

	field_signed = bt_ctf_field_type_integer_get_signed(
		events_discarded_field_type);
	if (field_signed < 0) {
		goto end;
	}

	new_count = previous_count + event_count;
	if (field_signed) {
		ret = bt_ctf_field_signed_integer_set_value(
			events_discarded_field, (int64_t) new_count);
		if (ret) {
			goto end;
		}
	} else {
		ret = bt_ctf_field_unsigned_integer_set_value(
			events_discarded_field, new_count);
		if (ret) {
			goto end;
		}
	}

end:
	bt_put(events_discarded_field);
	bt_put(events_discarded_field_type);
}
Exemple #10
0
const char *bt_ctf_field_enumeration_get_mapping_name(
	struct bt_ctf_field *field)
{
	int ret;
	const char *name = NULL;
	struct bt_ctf_field *container = NULL;
	struct bt_ctf_field_type *container_type = NULL;
	struct bt_ctf_field_type_integer *integer_type = NULL;
	struct bt_ctf_field_type_enumeration *enumeration_type = NULL;

	container = bt_ctf_field_enumeration_get_container(field);
	if (!container) {
		goto end;
	}

	container_type = bt_ctf_field_get_type(container);
	if (!container_type) {
		goto error_put_container;
	}

	integer_type = container_of(container_type,
		struct bt_ctf_field_type_integer, parent);
	enumeration_type = container_of(field->type,
		struct bt_ctf_field_type_enumeration, parent);

	if (!integer_type->declaration.signedness) {
		uint64_t value;
		ret = bt_ctf_field_unsigned_integer_get_value(container,
		      &value);
		if (ret) {
			goto error_put_container_type;
		}

		name = bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
			enumeration_type, value);
	} else {
		int64_t value;
		ret = bt_ctf_field_signed_integer_get_value(container,
		      &value);
		if (ret) {
			goto error_put_container_type;
		}

		name = bt_ctf_field_type_enumeration_get_mapping_name_signed(
			enumeration_type, value);
	}

error_put_container_type:
	bt_ctf_field_type_put(container_type);
error_put_container:
	bt_ctf_field_put(container);
end:
	return name;
}
Exemple #11
0
BT_HIDDEN
int bt_ctf_event_populate_event_header(struct bt_ctf_event *event)
{
	int ret = 0;
	struct bt_ctf_field *id_field = NULL, *timestamp_field = NULL;

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

	id_field = bt_ctf_field_structure_get_field(event->event_header, "id");
	if (id_field) {
		ret = set_integer_field_value(id_field,
			(uint64_t) bt_ctf_event_class_get_id(
				event->event_class));
		if (ret) {
			goto end;
		}
	}

	timestamp_field = bt_ctf_field_structure_get_field(event->event_header,
		"timestamp");
	if (timestamp_field) {
		struct bt_ctf_field_type *timestamp_field_type =
			bt_ctf_field_get_type(timestamp_field);
		struct bt_ctf_clock *mapped_clock;

		assert(timestamp_field_type);
		mapped_clock = bt_ctf_field_type_integer_get_mapped_clock(
			timestamp_field_type);
		bt_put(timestamp_field_type);
		if (mapped_clock) {
			int64_t timestamp;

			ret = bt_ctf_clock_get_time(mapped_clock, &timestamp);
			bt_put(mapped_clock);
			if (ret) {
				goto end;
			}

			ret = set_integer_field_value(timestamp_field,
				timestamp);
			if (ret) {
				goto end;
			}
		}
	}
end:
	bt_put(id_field);
	bt_put(timestamp_field);
	return ret;
}
Exemple #12
0
struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index(
		struct bt_ctf_field *field, size_t index)
{
	int ret;
	const char *field_name;
	struct bt_ctf_field_structure *structure;
	struct bt_ctf_field_type *structure_type;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_field *ret_field = NULL;

	if (!field ||
		bt_ctf_field_type_get_type_id(field->type) != CTF_TYPE_STRUCT) {
		goto end;
	}

	structure = container_of(field, struct bt_ctf_field_structure, parent);
	if (index >= structure->fields->len) {
		goto error;
	}

	ret_field = structure->fields->pdata[index];
	if (ret_field) {
		goto end;
	}

	/* Field has not been instanciated yet, create it */
	structure_type = bt_ctf_field_get_type(field);
	if (!structure_type) {
		goto error;
	}

	ret = bt_ctf_field_type_structure_get_field(structure_type,
		&field_name, &field_type, index);
	bt_ctf_field_type_put(structure_type);
	if (ret) {
		goto error;
	}

	ret_field = bt_ctf_field_create(field_type);
	if (!ret_field) {
		goto error;
	}

	structure->fields->pdata[index] = ret_field;
end:
	bt_ctf_field_get(ret_field);
error:
	if (field_type) {
		bt_ctf_field_type_put(field_type);
	}
	return ret_field;
}
Exemple #13
0
static
int set_structure_field_integer(struct bt_ctf_field *structure, char *name,
		uint64_t value)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;
	struct bt_ctf_field *integer =
		bt_ctf_field_structure_get_field(structure, name);

	if (!structure || !name) {
		ret = -1;
		goto end;
	}

	if (!integer) {
		/* Field not found, not an error. */
		goto end;
	}

	/* Make sure the payload has not already been set. */
	if (!bt_ctf_field_validate(integer)) {
		/* Payload already set, not an error */
		goto end;
	}

	field_type = bt_ctf_field_get_type(integer);
	/* Something is serioulsly wrong */
	assert(field_type);
	if (bt_ctf_field_type_get_type_id(field_type) != CTF_TYPE_INTEGER) {
		/*
		 * The user most likely meant for us to populate this field
		 * automatically. However, we can only do this if the field
		 * is an integer. Return an error.
		 */
		ret = -1;
		goto end;
	}

	if (bt_ctf_field_type_integer_get_signed(field_type)) {
		ret = bt_ctf_field_signed_integer_set_value(integer,
			(int64_t) value);
	} else {
		ret = bt_ctf_field_unsigned_integer_set_value(integer, value);
	}
end:
	bt_put(integer);
	bt_put(field_type);
	return ret;
}
Exemple #14
0
static
int set_packet_header_magic(struct bt_ctf_stream *stream)
{
	int ret = 0;
	struct bt_ctf_field_type *magic_field_type = NULL;
	struct bt_ctf_field *magic_field = bt_ctf_field_structure_get_field(
		stream->packet_header, "magic");

	if (!magic_field) {
		/* No magic field found. Not an error, skip. */
		goto end;
	}

	if (!bt_ctf_field_validate(magic_field)) {
		/* Value already set. Not an error, skip. */
		goto end;
	}

	magic_field_type = bt_ctf_field_get_type(magic_field);
	assert(magic_field_type);

	if (bt_ctf_field_type_get_type_id(magic_field_type) !=
		CTF_TYPE_INTEGER) {
		/* Magic field is not an integer. Not an error, skip. */
		goto end;
	}

	if (bt_ctf_field_type_integer_get_size(magic_field_type) != 32) {
		/*
		 * Magic field is not of the expected size.
		 * Not an error, skip.
		 */
		goto end;
	}

	ret = bt_ctf_field_type_integer_get_signed(magic_field_type);
	assert(ret >= 0);
	if (ret) {
		ret = bt_ctf_field_signed_integer_set_value(magic_field,
			(int64_t) 0xC1FC1FC1);
	} else {
		ret = bt_ctf_field_unsigned_integer_set_value(magic_field,
			(uint64_t) 0xC1FC1FC1);
	}
end:
	bt_put(magic_field);
	bt_put(magic_field_type);
	return ret;
}
Exemple #15
0
static
int get_event_header_timestamp(struct bt_ctf_field *event_header, uint64_t *timestamp)
{
	int ret = 0;
	struct bt_ctf_field *timestamp_field = NULL;
	struct bt_ctf_field_type *timestamp_field_type = NULL;

	timestamp_field = bt_ctf_field_structure_get_field(event_header,
		"timestamp");
	if (!timestamp_field) {
		ret = -1;
		goto end;
	}

	timestamp_field_type = bt_ctf_field_get_type(timestamp_field);
	assert(timestamp_field_type);
	if (bt_ctf_field_type_get_type_id(timestamp_field_type) !=
		CTF_TYPE_INTEGER) {
		ret = -1;
		goto end;
	}

	if (bt_ctf_field_type_integer_get_signed(timestamp_field_type)) {
		int64_t val;

		ret = bt_ctf_field_signed_integer_get_value(timestamp_field,
			&val);
		if (ret) {
			goto end;
		}
		*timestamp = (uint64_t) val;
	} else {
		ret = bt_ctf_field_unsigned_integer_get_value(timestamp_field,
			timestamp);
		if (ret) {
			goto end;
		}
	}
end:
	bt_put(timestamp_field);
	bt_put(timestamp_field_type);
	return ret;
}
Exemple #16
0
static
int set_integer_field_value(struct bt_ctf_field* field, uint64_t value)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;

	if (!field) {
		ret = -1;
		goto end;
	}

	if (!bt_ctf_field_validate(field)) {
		/* Payload already set, skip! (not an error) */
		goto end;
	}

	field_type = bt_ctf_field_get_type(field);
	assert(field_type);

	if (bt_ctf_field_type_get_type_id(field_type) !=
			CTF_TYPE_INTEGER) {
		/* Not an integer and the value is unset, error. */
		ret = -1;
		goto end;
	}

	if (bt_ctf_field_type_integer_get_signed(field_type)) {
		ret = bt_ctf_field_signed_integer_set_value(field, (int64_t) value);
		if (ret) {
			/* Value is out of range, error. */
			goto end;
		}
	} else {
		ret = bt_ctf_field_unsigned_integer_set_value(field, value);
		if (ret) {
			/* Value is out of range, error. */
			goto end;
		}
	}
end:
	bt_put(field_type);
	return ret;
}
Exemple #17
0
static
int set_packet_header_stream_id(struct bt_ctf_stream *stream)
{
	int ret = 0;
	uint32_t stream_id;
	struct bt_ctf_field_type *stream_id_field_type = NULL;
	struct bt_ctf_field *stream_id_field = bt_ctf_field_structure_get_field(
		stream->packet_header, "stream_id");

	if (!stream_id_field) {
		/* No stream_id field found. Not an error, skip. */
		goto end;
	}

	if (!bt_ctf_field_validate(stream_id_field)) {
		/* Value already set. Not an error, skip. */
		goto end;
	}

	stream_id_field_type = bt_ctf_field_get_type(stream_id_field);
	assert(stream_id_field_type);
	if (bt_ctf_field_type_get_type_id(stream_id_field_type) !=
		CTF_TYPE_INTEGER) {
		/* stream_id field is not an integer. Not an error, skip. */
		goto end;
	}

	stream_id = stream->stream_class->id;
	ret = bt_ctf_field_type_integer_get_signed(stream_id_field_type);
	assert(ret >= 0);
	if (ret) {
		ret = bt_ctf_field_signed_integer_set_value(stream_id_field,
			(int64_t) stream_id);
	} else {
		ret = bt_ctf_field_unsigned_integer_set_value(stream_id_field,
			(uint64_t) stream_id);
	}
end:
	bt_put(stream_id_field);
	bt_put(stream_id_field_type);
	return ret;
}
Exemple #18
0
int bt_ctf_packet_set_header(struct bt_ctf_packet *packet,
		struct bt_ctf_field *header)
{
	int ret = 0;
	struct bt_ctf_trace *trace = NULL;
	struct bt_ctf_stream_class *stream_class = NULL;
	struct bt_ctf_field_type *header_field_type = NULL;
	struct bt_ctf_field_type *expected_header_field_type = NULL;

	if (!packet || !header || packet->frozen) {
		ret = -1;
		goto end;
	}

	stream_class = bt_ctf_stream_get_class(packet->stream);
	assert(stream_class);
	trace = bt_ctf_stream_class_get_trace(stream_class);
	assert(trace);
	header_field_type = bt_ctf_field_get_type(header);
	assert(header_field_type);
	expected_header_field_type = bt_ctf_trace_get_packet_header_type(trace);

	if (bt_ctf_field_type_compare(header_field_type,
			expected_header_field_type)) {
		ret = -1;
		goto end;
	}

	bt_put(packet->header);
	packet->header = bt_get(header);

end:
	BT_PUT(trace);
	BT_PUT(stream_class);
	BT_PUT(header_field_type);
	BT_PUT(expected_header_field_type);

	return ret;
}
Exemple #19
0
int bt_ctf_packet_set_context(struct bt_ctf_packet *packet,
		struct bt_ctf_field *context)
{
	int ret = 0;
	struct bt_ctf_stream_class *stream_class = NULL;
	struct bt_ctf_field_type *context_field_type = NULL;
	struct bt_ctf_field_type *expected_context_field_type = NULL;

	if (!packet || !context || packet->frozen) {
		ret = -1;
		goto end;
	}

	stream_class = bt_ctf_stream_get_class(packet->stream);
	assert(stream_class);
	context_field_type = bt_ctf_field_get_type(context);
	assert(context_field_type);
	expected_context_field_type =
		bt_ctf_stream_class_get_packet_context_type(stream_class);

	if (bt_ctf_field_type_compare(context_field_type,
			expected_context_field_type)) {
		ret = -1;
		goto end;
	}

	bt_put(packet->context);
	packet->context = bt_get(context);

end:
	BT_PUT(stream_class);
	BT_PUT(context_field_type);
	BT_PUT(expected_context_field_type);

	return ret;
}
Exemple #20
0
int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
		struct bt_ctf_field *field)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;

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

	field_type = bt_ctf_field_get_type(field);
	if (field_type != stream->trace->packet_header_type) {
		ret = -1;
		goto end;
	}

	bt_get(field);
	bt_put(stream->packet_header);
	stream->packet_header = field;
end:
	bt_put(field_type);
	return ret;
}
Exemple #21
0
int bt_ctf_stream_set_event_context(struct bt_ctf_stream *stream,
		struct bt_ctf_field *field)
{
	int ret = 0;
	struct bt_ctf_field_type *field_type = NULL;

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

	field_type = bt_ctf_field_get_type(field);
	if (field_type != stream->stream_class->event_context_type) {
		ret = -1;
		goto end;
	}

	bt_get(field);
	bt_put(stream->event_context);
	stream->event_context = field;
end:
	bt_put(field_type);
	return ret;
}
Exemple #22
0
static
int set_packet_header_uuid(struct bt_ctf_stream *stream)
{
	int i, ret = 0;
	struct bt_ctf_field_type *uuid_field_type = NULL;
	struct bt_ctf_field_type *element_field_type = NULL;
	struct bt_ctf_field *uuid_field = bt_ctf_field_structure_get_field(
		stream->packet_header, "uuid");

	if (!uuid_field) {
		/* No uuid field found. Not an error, skip. */
		goto end;
	}

	if (!bt_ctf_field_validate(uuid_field)) {
		/* Value already set. Not an error, skip. */
		goto end;
	}

	uuid_field_type = bt_ctf_field_get_type(uuid_field);
	assert(uuid_field_type);
	if (bt_ctf_field_type_get_type_id(uuid_field_type) !=
		CTF_TYPE_ARRAY) {
		/* UUID field is not an array. Not an error, skip. */
		goto end;
	}

	if (bt_ctf_field_type_array_get_length(uuid_field_type) != 16) {
		/*
		 * UUID field is not of the expected size.
		 * Not an error, skip.
		 */
		goto end;
	}

	element_field_type = bt_ctf_field_type_array_get_element_type(
		uuid_field_type);
	assert(element_field_type);
	if (bt_ctf_field_type_get_type_id(element_field_type) !=
		CTF_TYPE_INTEGER) {
		/* UUID array elements are not integers. Not an error, skip */
		goto end;
	}

	for (i = 0; i < 16; i++) {
		struct bt_ctf_field *uuid_element =
			bt_ctf_field_array_get_field(uuid_field, i);

		ret = bt_ctf_field_type_integer_get_signed(element_field_type);
		assert(ret >= 0);

		if (ret) {
			ret = bt_ctf_field_signed_integer_set_value(
				uuid_element, (int64_t) stream->trace->uuid[i]);
		} else {
			ret = bt_ctf_field_unsigned_integer_set_value(
				uuid_element,
				(uint64_t) stream->trace->uuid[i]);
		}
		bt_put(uuid_element);
		if (ret) {
			goto end;
		}
	}

end:
	bt_put(uuid_field);
	bt_put(uuid_field_type);
	bt_put(element_field_type);
	return ret;
}
Exemple #23
0
BT_HIDDEN
void bt_ctf_stream_update_clock_value(struct bt_ctf_stream *stream,
		struct bt_ctf_field *value_field)
{
	struct bt_ctf_field_type *value_type = NULL;
	struct bt_ctf_clock *clock = NULL;
	uint64_t requested_new_value;
	uint64_t requested_new_value_mask;
	uint64_t *cur_value;
	uint64_t cur_value_masked;
	int requested_new_value_size;
	int ret;

	assert(stream);
	assert(clock);
	assert(value_field);
	value_type = bt_ctf_field_get_type(value_field);
	assert(value_type);
	clock = bt_ctf_field_type_integer_get_mapped_clock(value_type);
	assert(clock);
	requested_new_value_size =
		bt_ctf_field_type_integer_get_size(value_type);
	assert(requested_new_value_size > 0);
	ret = bt_ctf_field_unsigned_integer_get_value(value_field,
		&requested_new_value);
	assert(!ret);
	cur_value = g_hash_table_lookup(stream->clock_values, clock);

	if (!cur_value) {
		/*
		 * Updating the value of a clock which is not registered
		 * yet, so register it with the new value as its initial
		 * value.
		 */
		uint64_t *requested_new_value_ptr = g_new0(uint64_t, 1);

		*requested_new_value_ptr = requested_new_value;
		g_hash_table_insert(stream->clock_values, clock,
			requested_new_value_ptr);
		goto end;
	}

	/*
	 * Special case for a 64-bit new value, which is the limit
	 * of a clock value as of this version: overwrite the
	 * current value directly.
	 */
	if (requested_new_value_size == 64) {
		*cur_value = requested_new_value;
		goto end;
	}

	requested_new_value_mask = (1ULL << requested_new_value_size) - 1;
	cur_value_masked = *cur_value & requested_new_value_mask;

	if (requested_new_value < cur_value_masked) {
		/*
		 * It looks like a wrap happened on the number of bits
		 * of the requested new value. Assume that the clock
		 * value wrapped only one time.
		 */
		*cur_value += requested_new_value_mask + 1;
	}

	/* Clear the low bits of the current clock value */
	*cur_value &= ~requested_new_value_mask;

	/* Set the low bits of the current clock value */
	*cur_value |= requested_new_value;

end:
	bt_put(clock);
	bt_put(value_type);
}
Exemple #24
0
BT_HIDDEN
enum bt_component_status update_packet_context_field(FILE *err,
		struct bt_ctf_packet *writer_packet,
		const char *name, int64_t value)
{
	enum bt_component_status ret;
	struct bt_ctf_field *packet_context = NULL, *writer_packet_context = NULL;
	struct bt_ctf_field_type *struct_type = NULL, *field_type = NULL;
	struct bt_ctf_field *field = NULL, *writer_field = NULL;
	int nr_fields, i, int_ret;

	packet_context = bt_ctf_packet_get_context(writer_packet);
	if (!packet_context) {
		fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
				__LINE__);
		goto error;
	}

	struct_type = bt_ctf_field_get_type(packet_context);
	if (!struct_type) {
		fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
				__LINE__);
		goto error;
	}

	writer_packet_context = bt_ctf_packet_get_context(writer_packet);
	if (!writer_packet_context) {
		fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
				__LINE__);
		goto error;
	}

	nr_fields = bt_ctf_field_type_structure_get_field_count(struct_type);
	for (i = 0; i < nr_fields; i++) {
		const char *field_name;

		field = bt_ctf_field_structure_get_field_by_index(
				packet_context, i);
		if (!field) {
			fprintf(err, "[error] %s in %s:%d\n", __func__,
					__FILE__, __LINE__);
			goto error;
		}
		if (bt_ctf_field_type_structure_get_field(struct_type,
					&field_name, &field_type, i) < 0) {
			fprintf(err, "[error] %s in %s:%d\n", __func__,
					__FILE__, __LINE__);
			goto error;
		}
		if (strcmp(field_name, name)) {
			BT_PUT(field_type);
			BT_PUT(field);
			continue;
		}
		if (bt_ctf_field_type_get_type_id(field_type) != BT_CTF_FIELD_TYPE_ID_INTEGER) {
			fprintf(err, "[error] Unexpected packet context field type\n");
			goto error;
		}
		writer_field = bt_ctf_field_structure_get_field(writer_packet_context,
				field_name);
		if (!writer_field) {
			fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
					__LINE__);
			goto error;
		}

		int_ret = bt_ctf_field_unsigned_integer_set_value(writer_field, value);
		if (int_ret < 0) {
			fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
					__LINE__);
			goto error;
		}
		BT_PUT(writer_field);
		BT_PUT(field_type);
		BT_PUT(field);
	}

	ret = BT_COMPONENT_STATUS_OK;
	goto end;

error:
	bt_put(writer_field);
	bt_put(field_type);
	bt_put(field);
	ret = BT_COMPONENT_STATUS_ERROR;
end:
	bt_put(struct_type);
	bt_put(packet_context);
	return ret;
}