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
14 #include <babeltrace2/babeltrace.h>
16 #include "common/assert.h"
17 #include "common/common.h"
18 #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;
44 struct fs_sink_ctf_field_class_bit_array
46 struct fs_sink_ctf_field_class base;
50 struct fs_sink_ctf_field_class_bool
52 struct fs_sink_ctf_field_class_bit_array base;
55 struct fs_sink_ctf_field_class_int
57 struct fs_sink_ctf_field_class_bit_array base;
61 struct fs_sink_ctf_field_class_float
63 struct fs_sink_ctf_field_class_bit_array base;
66 struct fs_sink_ctf_field_class_string
68 struct fs_sink_ctf_field_class base;
71 struct fs_sink_ctf_named_field_class
76 struct fs_sink_ctf_field_class *fc;
79 struct fs_sink_ctf_field_class_struct
81 struct fs_sink_ctf_field_class base;
83 /* Array of `struct fs_sink_ctf_named_field_class` */
87 struct fs_sink_ctf_field_class_option
89 struct fs_sink_ctf_field_class base;
90 struct fs_sink_ctf_field_class *content_fc;
94 struct fs_sink_ctf_field_class_variant
96 struct fs_sink_ctf_field_class base;
100 /* Array of `struct fs_sink_ctf_named_field_class` */
104 struct fs_sink_ctf_field_class_array_base
106 struct fs_sink_ctf_field_class base;
107 struct fs_sink_ctf_field_class *elem_fc;
110 struct fs_sink_ctf_field_class_array
112 struct fs_sink_ctf_field_class_array_base base;
116 struct fs_sink_ctf_field_class_sequence
118 struct fs_sink_ctf_field_class_array_base base;
120 bool length_is_before;
123 static inline fs_sink_ctf_field_class_bit_array *
124 fs_sink_ctf_field_class_as_bit_array(fs_sink_ctf_field_class *fc)
126 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY ||
127 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT ||
128 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL ||
129 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT));
131 return (fs_sink_ctf_field_class_bit_array *) fc;
134 static inline fs_sink_ctf_field_class_bool *
135 fs_sink_ctf_field_class_as_bool(fs_sink_ctf_field_class *fc)
137 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL);
139 return (fs_sink_ctf_field_class_bool *) fc;
142 static inline fs_sink_ctf_field_class_int *
143 fs_sink_ctf_field_class_as_int(fs_sink_ctf_field_class *fc)
145 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT);
147 return (fs_sink_ctf_field_class_int *) fc;
150 static inline fs_sink_ctf_field_class_float *
151 fs_sink_ctf_field_class_as_float(fs_sink_ctf_field_class *fc)
153 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT);
155 return (fs_sink_ctf_field_class_float *) fc;
158 static inline fs_sink_ctf_field_class_string *
159 fs_sink_ctf_field_class_as_string(fs_sink_ctf_field_class *fc)
161 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRING);
163 return (fs_sink_ctf_field_class_string *) fc;
166 static inline fs_sink_ctf_field_class_struct *
167 fs_sink_ctf_field_class_as_struct(fs_sink_ctf_field_class *fc)
169 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT);
171 return (fs_sink_ctf_field_class_struct *) fc;
174 static inline fs_sink_ctf_field_class_array_base *
175 fs_sink_ctf_field_class_as_array_base(fs_sink_ctf_field_class *fc)
177 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY ||
178 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE));
180 return (fs_sink_ctf_field_class_array_base *) fc;
183 static inline fs_sink_ctf_field_class_array *
184 fs_sink_ctf_field_class_as_array(fs_sink_ctf_field_class *fc)
186 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY);
188 return (fs_sink_ctf_field_class_array *) fc;
191 static inline fs_sink_ctf_field_class_sequence *
192 fs_sink_ctf_field_class_as_sequence(fs_sink_ctf_field_class *fc)
194 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE);
196 return (fs_sink_ctf_field_class_sequence *) fc;
199 static inline fs_sink_ctf_field_class_option *
200 fs_sink_ctf_field_class_as_option(fs_sink_ctf_field_class *fc)
202 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION);
204 return (fs_sink_ctf_field_class_option *) fc;
207 static inline fs_sink_ctf_field_class_variant *
208 fs_sink_ctf_field_class_as_variant(fs_sink_ctf_field_class *fc)
210 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT);
212 return (fs_sink_ctf_field_class_variant *) fc;
215 struct fs_sink_ctf_stream_class;
217 struct fs_sink_ctf_event_class
220 const bt_event_class *ir_ec;
223 struct fs_sink_ctf_stream_class *sc;
226 struct fs_sink_ctf_field_class *spec_context_fc;
229 struct fs_sink_ctf_field_class *payload_fc;
232 struct fs_sink_ctf_trace;
234 struct fs_sink_ctf_stream_class
237 struct fs_sink_ctf_trace *trace;
240 const bt_stream_class *ir_sc;
243 const bt_clock_class *default_clock_class;
245 GString *default_clock_class_name;
247 bool packets_have_ts_begin;
248 bool packets_have_ts_end;
249 bool has_discarded_events;
250 bool discarded_events_has_ts;
251 bool discarded_packets_has_ts;
254 struct fs_sink_ctf_field_class *packet_context_fc;
257 struct fs_sink_ctf_field_class *event_common_context_fc;
259 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
260 GPtrArray *event_classes;
263 * `const bt_event_class *` (weak) ->
264 * `struct fs_sink_ctf_event_class *` (weak)
266 GHashTable *event_classes_from_ir;
269 struct fs_sink_ctf_trace
272 const bt_trace *ir_trace;
275 const bt_trace_class *ir_tc;
279 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
280 GPtrArray *stream_classes;
283 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc);
285 static inline void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class *fc,
286 enum fs_sink_ctf_field_class_type type,
287 const bt_field_class *ir_fc,
288 unsigned int alignment)
293 fc->alignment = alignment;
297 _fs_sink_ctf_field_class_bit_array_init(struct fs_sink_ctf_field_class_bit_array *fc,
298 enum fs_sink_ctf_field_class_type type,
299 const bt_field_class *ir_fc, unsigned int size)
301 _fs_sink_ctf_field_class_init(&fc->base, type, ir_fc, size % 8 == 0 ? 8 : 1);
305 static inline void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int *fc,
306 enum fs_sink_ctf_field_class_type type,
307 const bt_field_class *ir_fc)
309 bt_field_class_type ir_fc_type = bt_field_class_get_type(ir_fc);
311 _fs_sink_ctf_field_class_bit_array_init(
312 &fc->base, type, ir_fc, (unsigned int) bt_field_class_integer_get_field_value_range(ir_fc));
313 fc->is_signed = bt_field_class_type_is(ir_fc_type, BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
317 _fs_sink_ctf_named_field_class_init(struct fs_sink_ctf_named_field_class *named_fc)
320 named_fc->name = g_string_new(NULL);
321 BT_ASSERT(named_fc->name);
325 _fs_sink_ctf_named_field_class_fini(struct fs_sink_ctf_named_field_class *named_fc)
329 if (named_fc->name) {
330 g_string_free(named_fc->name, TRUE);
331 named_fc->name = NULL;
334 fs_sink_ctf_field_class_destroy(named_fc->fc);
338 static inline struct fs_sink_ctf_field_class_bit_array *
339 fs_sink_ctf_field_class_bit_array_create(const bt_field_class *ir_fc)
341 struct fs_sink_ctf_field_class_bit_array *fc =
342 g_new0(struct fs_sink_ctf_field_class_bit_array, 1);
345 _fs_sink_ctf_field_class_bit_array_init(
346 fc, FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc,
347 (unsigned int) bt_field_class_bit_array_get_length(ir_fc));
351 static inline struct fs_sink_ctf_field_class_bool *
352 fs_sink_ctf_field_class_bool_create(const bt_field_class *ir_fc)
354 struct fs_sink_ctf_field_class_bool *fc = g_new0(struct fs_sink_ctf_field_class_bool, 1);
359 * CTF 1.8 has no boolean field class type, so this component
360 * translates it to an 8-bit unsigned integer field class.
362 _fs_sink_ctf_field_class_bit_array_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc, 8);
366 static inline struct fs_sink_ctf_field_class_int *
367 fs_sink_ctf_field_class_int_create(const bt_field_class *ir_fc)
369 struct fs_sink_ctf_field_class_int *fc = g_new0(struct fs_sink_ctf_field_class_int, 1);
372 _fs_sink_ctf_field_class_int_init(fc, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, ir_fc);
376 static inline struct fs_sink_ctf_field_class_float *
377 fs_sink_ctf_field_class_float_create(const bt_field_class *ir_fc)
379 struct fs_sink_ctf_field_class_float *fc = g_new0(struct fs_sink_ctf_field_class_float, 1);
382 _fs_sink_ctf_field_class_bit_array_init(
383 &fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, ir_fc,
384 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64);
388 static inline struct fs_sink_ctf_field_class_string *
389 fs_sink_ctf_field_class_string_create(const bt_field_class *ir_fc)
391 struct fs_sink_ctf_field_class_string *fc = g_new0(struct fs_sink_ctf_field_class_string, 1);
394 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, ir_fc, 8);
398 static inline struct fs_sink_ctf_field_class_struct *
399 fs_sink_ctf_field_class_struct_create_empty(const bt_field_class *ir_fc)
401 struct fs_sink_ctf_field_class_struct *fc = g_new0(struct fs_sink_ctf_field_class_struct, 1);
404 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, ir_fc, 1);
405 fc->members = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
406 BT_ASSERT(fc->members);
410 static inline struct fs_sink_ctf_field_class_option *
411 fs_sink_ctf_field_class_option_create_empty(const bt_field_class *ir_fc)
413 struct fs_sink_ctf_field_class_option *fc = g_new0(struct fs_sink_ctf_field_class_option, 1);
416 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc, 1);
417 fc->tag_ref = g_string_new(NULL);
418 BT_ASSERT(fc->tag_ref);
422 static inline struct fs_sink_ctf_field_class_variant *
423 fs_sink_ctf_field_class_variant_create_empty(const bt_field_class *ir_fc)
425 struct fs_sink_ctf_field_class_variant *fc = g_new0(struct fs_sink_ctf_field_class_variant, 1);
428 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, ir_fc, 1);
429 fc->options = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
430 BT_ASSERT(fc->options);
431 fc->tag_ref = g_string_new(NULL);
432 BT_ASSERT(fc->tag_ref);
433 fc->tag_is_before = bt_field_class_get_type(fc->base.ir_fc) ==
434 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD;
438 static inline struct fs_sink_ctf_field_class_array *
439 fs_sink_ctf_field_class_array_create_empty(const bt_field_class *ir_fc)
441 struct fs_sink_ctf_field_class_array *fc = g_new0(struct fs_sink_ctf_field_class_array, 1);
444 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc, 1);
445 fc->length = bt_field_class_array_static_get_length(ir_fc);
449 static inline struct fs_sink_ctf_field_class_sequence *
450 fs_sink_ctf_field_class_sequence_create_empty(const bt_field_class *ir_fc)
452 struct fs_sink_ctf_field_class_sequence *fc =
453 g_new0(struct fs_sink_ctf_field_class_sequence, 1);
456 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE, ir_fc, 1);
457 fc->length_ref = g_string_new(NULL);
458 BT_ASSERT(fc->length_ref);
459 fc->length_is_before =
460 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD;
464 static inline struct fs_sink_ctf_named_field_class *
465 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
468 static inline struct fs_sink_ctf_named_field_class *
469 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
472 static inline void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc)
478 _fs_sink_ctf_field_class_bit_array_destroy(struct fs_sink_ctf_field_class_bit_array *fc)
481 _fs_sink_ctf_field_class_fini(&fc->base);
485 static inline void _fs_sink_ctf_field_class_bool_destroy(struct fs_sink_ctf_field_class_bool *fc)
488 _fs_sink_ctf_field_class_fini(&fc->base.base);
492 static inline void _fs_sink_ctf_field_class_int_destroy(struct fs_sink_ctf_field_class_int *fc)
495 _fs_sink_ctf_field_class_fini(&fc->base.base);
499 static inline void _fs_sink_ctf_field_class_float_destroy(struct fs_sink_ctf_field_class_float *fc)
502 _fs_sink_ctf_field_class_fini(&fc->base.base);
507 _fs_sink_ctf_field_class_string_destroy(struct fs_sink_ctf_field_class_string *fc)
510 _fs_sink_ctf_field_class_fini(&fc->base);
515 _fs_sink_ctf_field_class_struct_destroy(struct fs_sink_ctf_field_class_struct *fc)
518 _fs_sink_ctf_field_class_fini(&fc->base);
523 for (i = 0; i < fc->members->len; i++) {
524 struct fs_sink_ctf_named_field_class *named_fc =
525 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
527 _fs_sink_ctf_named_field_class_fini(named_fc);
530 g_array_free(fc->members, TRUE);
538 _fs_sink_ctf_field_class_array_base_fini(struct fs_sink_ctf_field_class_array_base *fc)
541 _fs_sink_ctf_field_class_fini(&fc->base);
542 fs_sink_ctf_field_class_destroy(fc->elem_fc);
546 static inline void _fs_sink_ctf_field_class_array_destroy(struct fs_sink_ctf_field_class_array *fc)
549 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
554 _fs_sink_ctf_field_class_sequence_destroy(struct fs_sink_ctf_field_class_sequence *fc)
557 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
559 if (fc->length_ref) {
560 g_string_free(fc->length_ref, TRUE);
561 fc->length_ref = NULL;
568 _fs_sink_ctf_field_class_option_destroy(struct fs_sink_ctf_field_class_option *fc)
571 _fs_sink_ctf_field_class_fini(&fc->base);
572 fs_sink_ctf_field_class_destroy(fc->content_fc);
575 g_string_free(fc->tag_ref, TRUE);
583 _fs_sink_ctf_field_class_variant_destroy(struct fs_sink_ctf_field_class_variant *fc)
586 _fs_sink_ctf_field_class_fini(&fc->base);
591 for (i = 0; i < fc->options->len; i++) {
592 struct fs_sink_ctf_named_field_class *named_fc =
593 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
595 _fs_sink_ctf_named_field_class_fini(named_fc);
598 g_array_free(fc->options, TRUE);
603 g_string_free(fc->tag_ref, TRUE);
610 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
617 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL:
618 _fs_sink_ctf_field_class_bool_destroy(fs_sink_ctf_field_class_as_bool(fc));
620 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY:
621 _fs_sink_ctf_field_class_bit_array_destroy(fs_sink_ctf_field_class_as_bit_array(fc));
623 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT:
624 _fs_sink_ctf_field_class_int_destroy(fs_sink_ctf_field_class_as_int(fc));
626 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT:
627 _fs_sink_ctf_field_class_float_destroy(fs_sink_ctf_field_class_as_float(fc));
629 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING:
630 _fs_sink_ctf_field_class_string_destroy(fs_sink_ctf_field_class_as_string(fc));
632 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
633 _fs_sink_ctf_field_class_struct_destroy(fs_sink_ctf_field_class_as_struct(fc));
635 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
636 _fs_sink_ctf_field_class_array_destroy(fs_sink_ctf_field_class_as_array(fc));
638 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
639 _fs_sink_ctf_field_class_sequence_destroy(fs_sink_ctf_field_class_as_sequence(fc));
641 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION:
642 _fs_sink_ctf_field_class_option_destroy(fs_sink_ctf_field_class_as_option(fc));
644 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
645 _fs_sink_ctf_field_class_variant_destroy(fs_sink_ctf_field_class_as_variant(fc));
652 static inline struct fs_sink_ctf_named_field_class *
653 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
657 BT_ASSERT_DBG(index < fc->members->len);
658 return &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, index);
661 static inline struct fs_sink_ctf_named_field_class *
662 fs_sink_ctf_field_class_struct_borrow_member_by_name(struct fs_sink_ctf_field_class_struct *fc,
666 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
671 for (i = 0; i < fc->members->len; i++) {
672 struct fs_sink_ctf_named_field_class *named_fc =
673 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
675 if (strcmp(name, named_fc->name->str) == 0) {
676 ret_named_fc = named_fc;
685 static inline struct fs_sink_ctf_field_class *
686 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
687 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
689 struct fs_sink_ctf_named_field_class *named_fc = NULL;
690 struct fs_sink_ctf_field_class *fc = NULL;
696 named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_name(struct_fc, name);
707 static inline struct fs_sink_ctf_field_class_int *
708 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
709 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
711 struct fs_sink_ctf_field_class_int *int_fc = NULL;
713 int_fc = fs_sink_ctf_field_class_as_int(
714 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(struct_fc, name));
719 if (int_fc->base.base.type != FS_SINK_CTF_FIELD_CLASS_TYPE_INT) {
729 fs_sink_ctf_field_class_struct_align_at_least(struct fs_sink_ctf_field_class_struct *fc,
730 unsigned int alignment)
732 if (alignment > fc->base.alignment) {
733 fc->base.alignment = alignment;
738 fs_sink_ctf_field_class_struct_append_member(struct fs_sink_ctf_field_class_struct *fc,
740 struct fs_sink_ctf_field_class *member_fc)
742 struct fs_sink_ctf_named_field_class *named_fc;
746 g_array_set_size(fc->members, fc->members->len + 1);
749 &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, fc->members->len - 1);
750 _fs_sink_ctf_named_field_class_init(named_fc);
751 g_string_assign(named_fc->name, name);
752 named_fc->fc = member_fc;
753 fs_sink_ctf_field_class_struct_align_at_least(fc, member_fc->alignment);
756 static inline struct fs_sink_ctf_named_field_class *
757 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
761 BT_ASSERT_DBG(index < fc->options->len);
762 return &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, index);
765 static inline struct fs_sink_ctf_named_field_class *
766 fs_sink_ctf_field_class_variant_borrow_option_by_name(struct fs_sink_ctf_field_class_variant *fc,
770 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
775 for (i = 0; i < fc->options->len; i++) {
776 struct fs_sink_ctf_named_field_class *named_fc =
777 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
779 if (strcmp(name, named_fc->name->str) == 0) {
780 ret_named_fc = named_fc;
790 fs_sink_ctf_field_class_variant_append_option(struct fs_sink_ctf_field_class_variant *fc,
792 struct fs_sink_ctf_field_class *option_fc)
794 struct fs_sink_ctf_named_field_class *named_fc;
798 g_array_set_size(fc->options, fc->options->len + 1);
801 &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, fc->options->len - 1);
802 _fs_sink_ctf_named_field_class_init(named_fc);
803 g_string_assign(named_fc->name, name);
804 named_fc->fc = option_fc;
807 static inline struct fs_sink_ctf_event_class *
808 fs_sink_ctf_event_class_create(struct fs_sink_ctf_stream_class *sc, const bt_event_class *ir_ec)
810 struct fs_sink_ctf_event_class *ec = g_new0(struct fs_sink_ctf_event_class, 1);
817 g_ptr_array_add(sc->event_classes, ec);
818 g_hash_table_insert(sc->event_classes_from_ir, (gpointer) ir_ec, ec);
822 static inline void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec)
828 fs_sink_ctf_field_class_destroy(ec->spec_context_fc);
829 ec->spec_context_fc = NULL;
830 fs_sink_ctf_field_class_destroy(ec->payload_fc);
831 ec->payload_fc = NULL;
835 static inline struct fs_sink_ctf_stream_class *
836 fs_sink_ctf_stream_class_create(struct fs_sink_ctf_trace *trace, const bt_stream_class *ir_sc)
838 struct fs_sink_ctf_stream_class *sc = g_new0(struct fs_sink_ctf_stream_class, 1);
845 sc->default_clock_class = bt_stream_class_borrow_default_clock_class_const(ir_sc);
846 sc->default_clock_class_name = g_string_new(NULL);
847 BT_ASSERT(sc->default_clock_class_name);
849 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_event_class_destroy);
850 BT_ASSERT(sc->event_classes);
851 sc->event_classes_from_ir = g_hash_table_new(g_direct_hash, g_direct_equal);
852 BT_ASSERT(sc->event_classes_from_ir);
853 sc->has_packets = bt_stream_class_supports_packets(ir_sc);
854 sc->packets_have_ts_begin =
855 bt_stream_class_packets_have_beginning_default_clock_snapshot(ir_sc);
856 sc->packets_have_ts_end = bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
857 sc->has_discarded_events = bt_stream_class_supports_discarded_events(ir_sc);
859 if (sc->has_discarded_events) {
860 sc->discarded_events_has_ts =
861 bt_stream_class_discarded_events_have_default_clock_snapshots(ir_sc);
864 if (bt_stream_class_supports_discarded_packets(ir_sc)) {
865 sc->discarded_packets_has_ts =
866 bt_stream_class_discarded_packets_have_default_clock_snapshots(ir_sc);
869 g_ptr_array_add(trace->stream_classes, sc);
873 static inline void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class *sc)
879 if (sc->default_clock_class_name) {
880 g_string_free(sc->default_clock_class_name, TRUE);
881 sc->default_clock_class_name = NULL;
884 if (sc->event_classes) {
885 g_ptr_array_free(sc->event_classes, TRUE);
886 sc->event_classes = NULL;
889 if (sc->event_classes_from_ir) {
890 g_hash_table_destroy(sc->event_classes_from_ir);
891 sc->event_classes_from_ir = NULL;
894 fs_sink_ctf_field_class_destroy(sc->packet_context_fc);
895 sc->packet_context_fc = NULL;
896 fs_sink_ctf_field_class_destroy(sc->event_common_context_fc);
897 sc->event_common_context_fc = NULL;
901 static inline void fs_sink_ctf_stream_class_append_event_class(struct fs_sink_ctf_stream_class *sc,
902 struct fs_sink_ctf_event_class *ec)
904 g_ptr_array_add(sc->event_classes, ec);
907 static inline void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace)
913 if (trace->stream_classes) {
914 g_ptr_array_free(trace->stream_classes, TRUE);
915 trace->stream_classes = NULL;
921 static inline struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
923 struct fs_sink_ctf_trace *trace = g_new0(struct fs_sink_ctf_trace, 1);
927 bt_uuid_generate(trace->uuid);
929 trace->ir_trace = ir_trace;
930 trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
931 trace->stream_classes =
932 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_stream_class_destroy);
933 BT_ASSERT(trace->stream_classes);
938 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */