2 * SPDX-License-Identifier: MIT
4 * Copyright 2018-2019 Philippe Proulx <pproulx@efficios.com>
7 #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H
8 #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H
10 #include <babeltrace2/babeltrace.h>
11 #include "common/common.h"
12 #include "common/assert.h"
13 #include "common/uuid.h"
20 enum fs_sink_ctf_field_class_type
22 FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL,
23 FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY,
24 FS_SINK_CTF_FIELD_CLASS_TYPE_INT,
25 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
26 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING,
27 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT,
28 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY,
29 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE,
30 FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION,
31 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT,
34 struct fs_sink_ctf_field_class
36 enum fs_sink_ctf_field_class_type type;
39 const bt_field_class *ir_fc;
41 unsigned int alignment;
43 /* Index of the field class within its own parent */
44 uint64_t index_in_parent;
47 struct fs_sink_ctf_field_class_bit_array
49 struct fs_sink_ctf_field_class base;
53 struct fs_sink_ctf_field_class_bool
55 struct fs_sink_ctf_field_class_bit_array base;
58 struct fs_sink_ctf_field_class_int
60 struct fs_sink_ctf_field_class_bit_array base;
64 struct fs_sink_ctf_field_class_float
66 struct fs_sink_ctf_field_class_bit_array base;
69 struct fs_sink_ctf_field_class_string
71 struct fs_sink_ctf_field_class base;
74 struct fs_sink_ctf_named_field_class
79 struct fs_sink_ctf_field_class *fc;
82 struct fs_sink_ctf_field_class_struct
84 struct fs_sink_ctf_field_class base;
86 /* Array of `struct fs_sink_ctf_named_field_class` */
90 struct fs_sink_ctf_field_class_option
92 struct fs_sink_ctf_field_class base;
93 struct fs_sink_ctf_field_class *content_fc;
97 struct fs_sink_ctf_field_class_variant
99 struct fs_sink_ctf_field_class base;
103 /* Array of `struct fs_sink_ctf_named_field_class` */
107 struct fs_sink_ctf_field_class_array_base
109 struct fs_sink_ctf_field_class base;
110 struct fs_sink_ctf_field_class *elem_fc;
113 struct fs_sink_ctf_field_class_array
115 struct fs_sink_ctf_field_class_array_base base;
119 struct fs_sink_ctf_field_class_sequence
121 struct fs_sink_ctf_field_class_array_base base;
123 bool length_is_before;
126 static inline fs_sink_ctf_field_class_bit_array *
127 fs_sink_ctf_field_class_as_bit_array(fs_sink_ctf_field_class *fc)
129 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY ||
130 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT ||
131 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL ||
132 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT));
134 return (fs_sink_ctf_field_class_bit_array *) fc;
137 static inline fs_sink_ctf_field_class_bool *
138 fs_sink_ctf_field_class_as_bool(fs_sink_ctf_field_class *fc)
140 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL);
142 return (fs_sink_ctf_field_class_bool *) fc;
145 static inline fs_sink_ctf_field_class_int *
146 fs_sink_ctf_field_class_as_int(fs_sink_ctf_field_class *fc)
148 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT);
150 return (fs_sink_ctf_field_class_int *) fc;
153 static inline fs_sink_ctf_field_class_float *
154 fs_sink_ctf_field_class_as_float(fs_sink_ctf_field_class *fc)
156 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT);
158 return (fs_sink_ctf_field_class_float *) fc;
161 static inline fs_sink_ctf_field_class_string *
162 fs_sink_ctf_field_class_as_string(fs_sink_ctf_field_class *fc)
164 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRING);
166 return (fs_sink_ctf_field_class_string *) fc;
169 static inline fs_sink_ctf_field_class_struct *
170 fs_sink_ctf_field_class_as_struct(fs_sink_ctf_field_class *fc)
172 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT);
174 return (fs_sink_ctf_field_class_struct *) fc;
177 static inline fs_sink_ctf_field_class_array_base *
178 fs_sink_ctf_field_class_as_array_base(fs_sink_ctf_field_class *fc)
180 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY ||
181 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE));
183 return (fs_sink_ctf_field_class_array_base *) fc;
186 static inline fs_sink_ctf_field_class_array *
187 fs_sink_ctf_field_class_as_array(fs_sink_ctf_field_class *fc)
189 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY);
191 return (fs_sink_ctf_field_class_array *) fc;
194 static inline fs_sink_ctf_field_class_sequence *
195 fs_sink_ctf_field_class_as_sequence(fs_sink_ctf_field_class *fc)
197 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE);
199 return (fs_sink_ctf_field_class_sequence *) fc;
202 static inline fs_sink_ctf_field_class_option *
203 fs_sink_ctf_field_class_as_option(fs_sink_ctf_field_class *fc)
205 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION);
207 return (fs_sink_ctf_field_class_option *) fc;
210 static inline fs_sink_ctf_field_class_variant *
211 fs_sink_ctf_field_class_as_variant(fs_sink_ctf_field_class *fc)
213 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT);
215 return (fs_sink_ctf_field_class_variant *) fc;
218 struct fs_sink_ctf_stream_class;
220 struct fs_sink_ctf_event_class
223 const bt_event_class *ir_ec;
226 struct fs_sink_ctf_stream_class *sc;
229 struct fs_sink_ctf_field_class *spec_context_fc;
232 struct fs_sink_ctf_field_class *payload_fc;
235 struct fs_sink_ctf_trace;
237 struct fs_sink_ctf_stream_class
240 struct fs_sink_ctf_trace *trace;
243 const bt_stream_class *ir_sc;
246 const bt_clock_class *default_clock_class;
248 GString *default_clock_class_name;
250 bool packets_have_ts_begin;
251 bool packets_have_ts_end;
252 bool has_discarded_events;
253 bool discarded_events_has_ts;
254 bool discarded_packets_has_ts;
257 struct fs_sink_ctf_field_class *packet_context_fc;
260 struct fs_sink_ctf_field_class *event_common_context_fc;
262 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
263 GPtrArray *event_classes;
266 * `const bt_event_class *` (weak) ->
267 * `struct fs_sink_ctf_event_class *` (weak)
269 GHashTable *event_classes_from_ir;
272 struct fs_sink_ctf_trace
275 const bt_trace *ir_trace;
278 const bt_trace_class *ir_tc;
282 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
283 GPtrArray *stream_classes;
286 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc);
288 static inline void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class *fc,
289 enum fs_sink_ctf_field_class_type type,
290 const bt_field_class *ir_fc,
291 unsigned int alignment, uint64_t index_in_parent)
296 fc->alignment = alignment;
297 fc->index_in_parent = index_in_parent;
300 static inline void _fs_sink_ctf_field_class_bit_array_init(
301 struct fs_sink_ctf_field_class_bit_array *fc, enum fs_sink_ctf_field_class_type type,
302 const bt_field_class *ir_fc, unsigned int size, uint64_t index_in_parent)
304 _fs_sink_ctf_field_class_init(&fc->base, type, ir_fc, size % 8 == 0 ? 8 : 1, index_in_parent);
308 static inline void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int *fc,
309 enum fs_sink_ctf_field_class_type type,
310 const bt_field_class *ir_fc,
311 uint64_t index_in_parent)
313 bt_field_class_type ir_fc_type = bt_field_class_get_type(ir_fc);
315 _fs_sink_ctf_field_class_bit_array_init(
316 &fc->base, type, ir_fc, (unsigned int) bt_field_class_integer_get_field_value_range(ir_fc),
318 fc->is_signed = bt_field_class_type_is(ir_fc_type, BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
322 _fs_sink_ctf_named_field_class_init(struct fs_sink_ctf_named_field_class *named_fc)
325 named_fc->name = g_string_new(NULL);
326 BT_ASSERT(named_fc->name);
330 _fs_sink_ctf_named_field_class_fini(struct fs_sink_ctf_named_field_class *named_fc)
334 if (named_fc->name) {
335 g_string_free(named_fc->name, TRUE);
336 named_fc->name = NULL;
339 fs_sink_ctf_field_class_destroy(named_fc->fc);
343 static inline struct fs_sink_ctf_field_class_bit_array *
344 fs_sink_ctf_field_class_bit_array_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
346 struct fs_sink_ctf_field_class_bit_array *fc =
347 g_new0(struct fs_sink_ctf_field_class_bit_array, 1);
350 _fs_sink_ctf_field_class_bit_array_init(
351 fc, FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc,
352 (unsigned int) bt_field_class_bit_array_get_length(ir_fc), index_in_parent);
356 static inline struct fs_sink_ctf_field_class_bool *
357 fs_sink_ctf_field_class_bool_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
359 struct fs_sink_ctf_field_class_bool *fc = g_new0(struct fs_sink_ctf_field_class_bool, 1);
364 * CTF 1.8 has no boolean field class type, so this component
365 * translates it to an 8-bit unsigned integer field class.
367 _fs_sink_ctf_field_class_bit_array_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc, 8,
372 static inline struct fs_sink_ctf_field_class_int *
373 fs_sink_ctf_field_class_int_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
375 struct fs_sink_ctf_field_class_int *fc = g_new0(struct fs_sink_ctf_field_class_int, 1);
378 _fs_sink_ctf_field_class_int_init(fc, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, ir_fc, index_in_parent);
382 static inline struct fs_sink_ctf_field_class_float *
383 fs_sink_ctf_field_class_float_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
385 struct fs_sink_ctf_field_class_float *fc = g_new0(struct fs_sink_ctf_field_class_float, 1);
388 _fs_sink_ctf_field_class_bit_array_init(
389 &fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, ir_fc,
390 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
395 static inline struct fs_sink_ctf_field_class_string *
396 fs_sink_ctf_field_class_string_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
398 struct fs_sink_ctf_field_class_string *fc = g_new0(struct fs_sink_ctf_field_class_string, 1);
401 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, ir_fc, 8,
406 static inline struct fs_sink_ctf_field_class_struct *
407 fs_sink_ctf_field_class_struct_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
409 struct fs_sink_ctf_field_class_struct *fc = g_new0(struct fs_sink_ctf_field_class_struct, 1);
412 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, ir_fc, 1,
414 fc->members = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
415 BT_ASSERT(fc->members);
419 static inline struct fs_sink_ctf_field_class_option *
420 fs_sink_ctf_field_class_option_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
422 struct fs_sink_ctf_field_class_option *fc = g_new0(struct fs_sink_ctf_field_class_option, 1);
425 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc, 1,
427 fc->tag_ref = g_string_new(NULL);
428 BT_ASSERT(fc->tag_ref);
432 static inline struct fs_sink_ctf_field_class_variant *
433 fs_sink_ctf_field_class_variant_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
435 struct fs_sink_ctf_field_class_variant *fc = g_new0(struct fs_sink_ctf_field_class_variant, 1);
438 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, ir_fc, 1,
440 fc->options = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
441 BT_ASSERT(fc->options);
442 fc->tag_ref = g_string_new(NULL);
443 BT_ASSERT(fc->tag_ref);
444 fc->tag_is_before = bt_field_class_get_type(fc->base.ir_fc) ==
445 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD;
449 static inline struct fs_sink_ctf_field_class_array *
450 fs_sink_ctf_field_class_array_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
452 struct fs_sink_ctf_field_class_array *fc = g_new0(struct fs_sink_ctf_field_class_array, 1);
455 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc, 1,
457 fc->length = bt_field_class_array_static_get_length(ir_fc);
461 static inline struct fs_sink_ctf_field_class_sequence *
462 fs_sink_ctf_field_class_sequence_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
464 struct fs_sink_ctf_field_class_sequence *fc =
465 g_new0(struct fs_sink_ctf_field_class_sequence, 1);
468 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE, ir_fc, 1,
470 fc->length_ref = g_string_new(NULL);
471 BT_ASSERT(fc->length_ref);
472 fc->length_is_before =
473 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD;
477 static inline struct fs_sink_ctf_named_field_class *
478 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
481 static inline struct fs_sink_ctf_named_field_class *
482 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
485 static inline void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc)
491 _fs_sink_ctf_field_class_bit_array_destroy(struct fs_sink_ctf_field_class_bit_array *fc)
494 _fs_sink_ctf_field_class_fini(&fc->base);
498 static inline void _fs_sink_ctf_field_class_bool_destroy(struct fs_sink_ctf_field_class_bool *fc)
501 _fs_sink_ctf_field_class_fini(&fc->base.base);
505 static inline void _fs_sink_ctf_field_class_int_destroy(struct fs_sink_ctf_field_class_int *fc)
508 _fs_sink_ctf_field_class_fini(&fc->base.base);
512 static inline void _fs_sink_ctf_field_class_float_destroy(struct fs_sink_ctf_field_class_float *fc)
515 _fs_sink_ctf_field_class_fini(&fc->base.base);
520 _fs_sink_ctf_field_class_string_destroy(struct fs_sink_ctf_field_class_string *fc)
523 _fs_sink_ctf_field_class_fini(&fc->base);
528 _fs_sink_ctf_field_class_struct_destroy(struct fs_sink_ctf_field_class_struct *fc)
531 _fs_sink_ctf_field_class_fini(&fc->base);
536 for (i = 0; i < fc->members->len; i++) {
537 struct fs_sink_ctf_named_field_class *named_fc =
538 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
540 _fs_sink_ctf_named_field_class_fini(named_fc);
543 g_array_free(fc->members, TRUE);
551 _fs_sink_ctf_field_class_array_base_fini(struct fs_sink_ctf_field_class_array_base *fc)
554 _fs_sink_ctf_field_class_fini(&fc->base);
555 fs_sink_ctf_field_class_destroy(fc->elem_fc);
559 static inline void _fs_sink_ctf_field_class_array_destroy(struct fs_sink_ctf_field_class_array *fc)
562 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
567 _fs_sink_ctf_field_class_sequence_destroy(struct fs_sink_ctf_field_class_sequence *fc)
570 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
572 if (fc->length_ref) {
573 g_string_free(fc->length_ref, TRUE);
574 fc->length_ref = NULL;
581 _fs_sink_ctf_field_class_option_destroy(struct fs_sink_ctf_field_class_option *fc)
584 _fs_sink_ctf_field_class_fini(&fc->base);
585 fs_sink_ctf_field_class_destroy(fc->content_fc);
588 g_string_free(fc->tag_ref, TRUE);
596 _fs_sink_ctf_field_class_variant_destroy(struct fs_sink_ctf_field_class_variant *fc)
599 _fs_sink_ctf_field_class_fini(&fc->base);
604 for (i = 0; i < fc->options->len; i++) {
605 struct fs_sink_ctf_named_field_class *named_fc =
606 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
608 _fs_sink_ctf_named_field_class_fini(named_fc);
611 g_array_free(fc->options, TRUE);
616 g_string_free(fc->tag_ref, TRUE);
623 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
630 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL:
631 _fs_sink_ctf_field_class_bool_destroy(fs_sink_ctf_field_class_as_bool(fc));
633 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY:
634 _fs_sink_ctf_field_class_bit_array_destroy(fs_sink_ctf_field_class_as_bit_array(fc));
636 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT:
637 _fs_sink_ctf_field_class_int_destroy(fs_sink_ctf_field_class_as_int(fc));
639 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT:
640 _fs_sink_ctf_field_class_float_destroy(fs_sink_ctf_field_class_as_float(fc));
642 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING:
643 _fs_sink_ctf_field_class_string_destroy(fs_sink_ctf_field_class_as_string(fc));
645 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
646 _fs_sink_ctf_field_class_struct_destroy(fs_sink_ctf_field_class_as_struct(fc));
648 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
649 _fs_sink_ctf_field_class_array_destroy(fs_sink_ctf_field_class_as_array(fc));
651 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
652 _fs_sink_ctf_field_class_sequence_destroy(fs_sink_ctf_field_class_as_sequence(fc));
654 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION:
655 _fs_sink_ctf_field_class_option_destroy(fs_sink_ctf_field_class_as_option(fc));
657 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
658 _fs_sink_ctf_field_class_variant_destroy(fs_sink_ctf_field_class_as_variant(fc));
665 static inline struct fs_sink_ctf_named_field_class *
666 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
670 BT_ASSERT_DBG(index < fc->members->len);
671 return &g_array_index(fc->members, struct fs_sink_ctf_named_field_class, index);
674 static inline struct fs_sink_ctf_named_field_class *
675 fs_sink_ctf_field_class_struct_borrow_member_by_name(struct fs_sink_ctf_field_class_struct *fc,
679 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
684 for (i = 0; i < fc->members->len; i++) {
685 struct fs_sink_ctf_named_field_class *named_fc =
686 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
688 if (strcmp(name, named_fc->name->str) == 0) {
689 ret_named_fc = named_fc;
698 static inline struct fs_sink_ctf_field_class *
699 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
700 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
702 struct fs_sink_ctf_named_field_class *named_fc = NULL;
703 struct fs_sink_ctf_field_class *fc = NULL;
709 named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_name(struct_fc, name);
720 static inline struct fs_sink_ctf_field_class_int *
721 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
722 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
724 struct fs_sink_ctf_field_class_int *int_fc = NULL;
726 int_fc = fs_sink_ctf_field_class_as_int(
727 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(struct_fc, name));
732 if (int_fc->base.base.type != FS_SINK_CTF_FIELD_CLASS_TYPE_INT) {
742 fs_sink_ctf_field_class_struct_align_at_least(struct fs_sink_ctf_field_class_struct *fc,
743 unsigned int alignment)
745 if (alignment > fc->base.alignment) {
746 fc->base.alignment = alignment;
751 fs_sink_ctf_field_class_struct_append_member(struct fs_sink_ctf_field_class_struct *fc,
753 struct fs_sink_ctf_field_class *member_fc)
755 struct fs_sink_ctf_named_field_class *named_fc;
759 g_array_set_size(fc->members, fc->members->len + 1);
762 &g_array_index(fc->members, struct fs_sink_ctf_named_field_class, fc->members->len - 1);
763 _fs_sink_ctf_named_field_class_init(named_fc);
764 g_string_assign(named_fc->name, name);
765 named_fc->fc = member_fc;
766 fs_sink_ctf_field_class_struct_align_at_least(fc, member_fc->alignment);
769 static inline struct fs_sink_ctf_named_field_class *
770 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
774 BT_ASSERT_DBG(index < fc->options->len);
775 return &g_array_index(fc->options, struct fs_sink_ctf_named_field_class, index);
778 static inline struct fs_sink_ctf_named_field_class *
779 fs_sink_ctf_field_class_variant_borrow_option_by_name(struct fs_sink_ctf_field_class_variant *fc,
783 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
788 for (i = 0; i < fc->options->len; i++) {
789 struct fs_sink_ctf_named_field_class *named_fc =
790 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
792 if (strcmp(name, named_fc->name->str) == 0) {
793 ret_named_fc = named_fc;
803 fs_sink_ctf_field_class_variant_append_option(struct fs_sink_ctf_field_class_variant *fc,
805 struct fs_sink_ctf_field_class *option_fc)
807 struct fs_sink_ctf_named_field_class *named_fc;
811 g_array_set_size(fc->options, fc->options->len + 1);
814 &g_array_index(fc->options, struct fs_sink_ctf_named_field_class, fc->options->len - 1);
815 _fs_sink_ctf_named_field_class_init(named_fc);
816 g_string_assign(named_fc->name, name);
817 named_fc->fc = option_fc;
820 static inline struct fs_sink_ctf_event_class *
821 fs_sink_ctf_event_class_create(struct fs_sink_ctf_stream_class *sc, const bt_event_class *ir_ec)
823 struct fs_sink_ctf_event_class *ec = g_new0(struct fs_sink_ctf_event_class, 1);
830 g_ptr_array_add(sc->event_classes, ec);
831 g_hash_table_insert(sc->event_classes_from_ir, (gpointer) ir_ec, ec);
835 static inline void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec)
841 fs_sink_ctf_field_class_destroy(ec->spec_context_fc);
842 ec->spec_context_fc = NULL;
843 fs_sink_ctf_field_class_destroy(ec->payload_fc);
844 ec->payload_fc = NULL;
848 static inline struct fs_sink_ctf_stream_class *
849 fs_sink_ctf_stream_class_create(struct fs_sink_ctf_trace *trace, const bt_stream_class *ir_sc)
851 struct fs_sink_ctf_stream_class *sc = g_new0(struct fs_sink_ctf_stream_class, 1);
858 sc->default_clock_class = bt_stream_class_borrow_default_clock_class_const(ir_sc);
859 sc->default_clock_class_name = g_string_new(NULL);
860 BT_ASSERT(sc->default_clock_class_name);
862 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_event_class_destroy);
863 BT_ASSERT(sc->event_classes);
864 sc->event_classes_from_ir = g_hash_table_new(g_direct_hash, g_direct_equal);
865 BT_ASSERT(sc->event_classes_from_ir);
866 sc->has_packets = bt_stream_class_supports_packets(ir_sc);
867 sc->packets_have_ts_begin =
868 bt_stream_class_packets_have_beginning_default_clock_snapshot(ir_sc);
869 sc->packets_have_ts_end = bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
870 sc->has_discarded_events = bt_stream_class_supports_discarded_events(ir_sc);
872 if (sc->has_discarded_events) {
873 sc->discarded_events_has_ts =
874 bt_stream_class_discarded_events_have_default_clock_snapshots(ir_sc);
877 if (bt_stream_class_supports_discarded_packets(ir_sc)) {
878 sc->discarded_packets_has_ts =
879 bt_stream_class_discarded_packets_have_default_clock_snapshots(ir_sc);
882 g_ptr_array_add(trace->stream_classes, sc);
886 static inline void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class *sc)
892 if (sc->default_clock_class_name) {
893 g_string_free(sc->default_clock_class_name, TRUE);
894 sc->default_clock_class_name = NULL;
897 if (sc->event_classes) {
898 g_ptr_array_free(sc->event_classes, TRUE);
899 sc->event_classes = NULL;
902 if (sc->event_classes_from_ir) {
903 g_hash_table_destroy(sc->event_classes_from_ir);
904 sc->event_classes_from_ir = NULL;
907 fs_sink_ctf_field_class_destroy(sc->packet_context_fc);
908 sc->packet_context_fc = NULL;
909 fs_sink_ctf_field_class_destroy(sc->event_common_context_fc);
910 sc->event_common_context_fc = NULL;
914 static inline void fs_sink_ctf_stream_class_append_event_class(struct fs_sink_ctf_stream_class *sc,
915 struct fs_sink_ctf_event_class *ec)
917 g_ptr_array_add(sc->event_classes, ec);
920 static inline void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace)
926 if (trace->stream_classes) {
927 g_ptr_array_free(trace->stream_classes, TRUE);
928 trace->stream_classes = NULL;
934 static inline struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
936 struct fs_sink_ctf_trace *trace = g_new0(struct fs_sink_ctf_trace, 1);
940 bt_uuid_generate(trace->uuid);
942 trace->ir_trace = ir_trace;
943 trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
944 trace->stream_classes =
945 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_stream_class_destroy);
946 BT_ASSERT(trace->stream_classes);
951 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */