struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) { int ret; struct bt_value *obj = NULL; struct bt_ctf_event_class *event_class = NULL; if (bt_ctf_validate_identifier(name)) { goto error; } event_class = g_new0(struct bt_ctf_event_class, 1); if (!event_class) { goto error; } bt_object_init(event_class, bt_ctf_event_class_destroy); event_class->fields = bt_ctf_field_type_structure_create(); if (!event_class->fields) { goto error; } event_class->attributes = bt_ctf_attributes_create(); if (!event_class->attributes) { goto error; } obj = bt_value_integer_create_init(-1); if (!obj) { goto error; } ret = bt_ctf_attributes_set_field_value(event_class->attributes, "id", obj); if (ret) { goto error; } BT_PUT(obj); obj = bt_value_string_create_init(name); if (!obj) { goto error; } ret = bt_ctf_attributes_set_field_value(event_class->attributes, "name", obj); if (ret) { goto error; } BT_PUT(obj); return event_class; error: BT_PUT(event_class); BT_PUT(obj); return event_class; }
/** * 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; }
static int init_trace_packet_header(struct bt_ctf_trace *trace) { int ret = 0; struct bt_ctf_field *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_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; } ret = bt_ctf_trace_set_packet_header_type(trace, trace_packet_header_type); if (ret) { goto end; } end: bt_put(uuid_array_type); bt_put(_uint32_t); bt_put(_uint8_t); bt_put(magic); bt_put(uuid_array); bt_put(trace_packet_header_type); return ret; }
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; }