static int init_trace_packet_header(struct bt_ctf_writer *writer) { size_t i; int ret = 0; struct bt_ctf_field *trace_packet_header = NULL, *magic = NULL, *uuid_array = NULL; struct bt_ctf_field_type *_uint32_t = get_field_type(FIELD_TYPE_ALIAS_UINT32_T); struct bt_ctf_field_type *_uint8_t = get_field_type(FIELD_TYPE_ALIAS_UINT8_T); struct bt_ctf_field_type *trace_packet_header_type = bt_ctf_field_type_structure_create(); struct bt_ctf_field_type *uuid_array_type = bt_ctf_field_type_array_create(_uint8_t, 16); if (!trace_packet_header_type || !uuid_array_type) { ret = -1; goto end; } ret = bt_ctf_field_type_set_byte_order(_uint32_t, (writer->byte_order == LITTLE_ENDIAN ? BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN)); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "magic"); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, uuid_array_type, "uuid"); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "stream_id"); if (ret) { goto end; } trace_packet_header = bt_ctf_field_create(trace_packet_header_type); if (!trace_packet_header) { ret = -1; goto end; } magic = bt_ctf_field_structure_get_field(trace_packet_header, "magic"); ret = bt_ctf_field_unsigned_integer_set_value(magic, 0xC1FC1FC1); if (ret) { goto end; } uuid_array = bt_ctf_field_structure_get_field(trace_packet_header, "uuid"); for (i = 0; i < 16; i++) { struct bt_ctf_field *uuid_element = bt_ctf_field_array_get_field(uuid_array, i); ret = bt_ctf_field_unsigned_integer_set_value(uuid_element, writer->uuid[i]); bt_ctf_field_put(uuid_element); if (ret) { goto end; } } bt_ctf_field_type_put(writer->trace_packet_header_type); bt_ctf_field_put(writer->trace_packet_header); writer->trace_packet_header_type = trace_packet_header_type; writer->trace_packet_header = trace_packet_header; end: bt_ctf_field_type_put(uuid_array_type); bt_ctf_field_type_put(_uint32_t); bt_ctf_field_type_put(_uint8_t); bt_ctf_field_put(magic); bt_ctf_field_put(uuid_array); if (ret) { bt_ctf_field_type_put(trace_packet_header_type); bt_ctf_field_put(trace_packet_header); } return ret; }
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; }