Exemplo n.º 1
0
/**
 * Returns a structure containing the following fields:
 *     - uint8_t payload_8;
 *     - uint16_t payload_16;
 *     - uint32_t payload_32;
 */
static struct bt_ctf_field_type *create_integer_struct(void)
{
	int ret;
	struct bt_ctf_field_type *structure = NULL;
	struct bt_ctf_field_type *ui8 = NULL, *ui16 = NULL, *ui32 = NULL;

	structure = bt_ctf_field_type_structure_create();
	if (!structure) {
		goto error;
	}

	ui8 = bt_ctf_field_type_integer_create(8);
	if (!ui8) {
		diag("Failed to create uint8_t type");
		goto error;
	}
	ret = bt_ctf_field_type_structure_add_field(structure, ui8,
		        "payload_8");
	if (ret) {
		diag("Failed to add uint8_t to structure");
		goto error;
	}
	ui16 = bt_ctf_field_type_integer_create(16);
	if (!ui16) {
		diag("Failed to create uint16_t type");
		goto error;
	}
	ret = bt_ctf_field_type_structure_add_field(structure, ui16,
		        "payload_16");
	if (ret) {
		diag("Failed to add uint16_t to structure");
		goto error;
	}
	ui32 = bt_ctf_field_type_integer_create(32);
	if (!ui32) {
		diag("Failed to create uint32_t type");
		goto error;
	}
	ret = bt_ctf_field_type_structure_add_field(structure, ui32,
		        "payload_32");
	if (ret) {
		diag("Failed to add uint32_t to structure");
		goto error;
	}
end:
	BT_PUT(ui8);
	BT_PUT(ui16);
	BT_PUT(ui32);
	return structure;
error:
	BT_PUT(structure);
	goto end;
}
Exemplo n.º 2
0
BT_HIDDEN
struct bt_ctf_field_type *get_field_type(enum field_type_alias alias)
{
	unsigned int alignment, size;
	struct bt_ctf_field_type *field_type;

	if (alias >= NR_FIELD_TYPE_ALIAS) {
		return NULL;
	}

	alignment = field_type_aliases_alignments[alias];
	size = field_type_aliases_sizes[alias];
	field_type = bt_ctf_field_type_integer_create(size);
	bt_ctf_field_type_set_alignment(field_type, alignment);
	return field_type;
}