struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
		struct bt_ctf_field_type *structure, size_t index)
{
	int ret;
	const char *name;
	struct bt_ctf_field_type *type;

	ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
		index);
	return !ret ? type : NULL;
}
Example #2
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;
}
const char *_bt_python_ctf_field_type_structure_get_field_name(
		struct bt_ctf_field_type *structure, size_t index)
{
	int ret;
	const char *name;
	struct bt_ctf_field_type *type;

	ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
		index);
	if (ret) {
		name = NULL;
		goto end;
	}

	bt_ctf_field_type_put(type);
end:
	return name;
}
Example #4
0
BT_HIDDEN
int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class,
		const char **field_name, struct bt_ctf_field_type **field_type,
		int index)
{
	int ret;

	if (!event_class || index < 0) {
		ret = -1;
		goto end;
	}

	if (bt_ctf_field_type_get_type_id(event_class->fields) !=
		CTF_TYPE_STRUCT) {
		ret = -1;
		goto end;
	}

	ret = bt_ctf_field_type_structure_get_field(event_class->fields,
		field_name, field_type, index);
end:
	return ret;
}
Example #5
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;
}