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
15 #include <babeltrace2/babeltrace.h>
17 #include "common/assert.h"
18 #include "common/common.h"
19 #include "common/uuid.h"
21 enum fs_sink_ctf_field_class_type
23 FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL,
24 FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY,
25 FS_SINK_CTF_FIELD_CLASS_TYPE_INT,
26 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
27 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING,
28 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT,
29 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY,
30 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE,
31 FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION,
32 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT,
35 struct fs_sink_ctf_field_class
37 enum fs_sink_ctf_field_class_type type;
40 const bt_field_class *ir_fc;
42 unsigned int alignment;
44 /* Index of the field class within its own parent */
45 uint64_t index_in_parent;
48 struct fs_sink_ctf_field_class_bit_array
50 struct fs_sink_ctf_field_class base;
54 struct fs_sink_ctf_field_class_bool
56 struct fs_sink_ctf_field_class_bit_array base;
59 struct fs_sink_ctf_field_class_int
61 struct fs_sink_ctf_field_class_bit_array base;
65 struct fs_sink_ctf_field_class_float
67 struct fs_sink_ctf_field_class_bit_array base;
70 struct fs_sink_ctf_field_class_string
72 struct fs_sink_ctf_field_class base;
75 struct fs_sink_ctf_named_field_class
80 struct fs_sink_ctf_field_class *fc;
83 struct fs_sink_ctf_field_class_struct
85 struct fs_sink_ctf_field_class base;
87 /* Array of `struct fs_sink_ctf_named_field_class` */
91 struct fs_sink_ctf_field_class_option
93 struct fs_sink_ctf_field_class base;
94 struct fs_sink_ctf_field_class *content_fc;
98 struct fs_sink_ctf_field_class_variant
100 struct fs_sink_ctf_field_class base;
104 /* Array of `struct fs_sink_ctf_named_field_class` */
108 struct fs_sink_ctf_field_class_array_base
110 struct fs_sink_ctf_field_class base;
111 struct fs_sink_ctf_field_class *elem_fc;
114 struct fs_sink_ctf_field_class_array
116 struct fs_sink_ctf_field_class_array_base base;
120 struct fs_sink_ctf_field_class_sequence
122 struct fs_sink_ctf_field_class_array_base base;
124 bool length_is_before;
127 static inline fs_sink_ctf_field_class_bit_array *
128 fs_sink_ctf_field_class_as_bit_array(fs_sink_ctf_field_class *fc)
130 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY ||
131 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT ||
132 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL ||
133 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT));
135 return (fs_sink_ctf_field_class_bit_array *) fc;
138 static inline fs_sink_ctf_field_class_bool *
139 fs_sink_ctf_field_class_as_bool(fs_sink_ctf_field_class *fc)
141 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL);
143 return (fs_sink_ctf_field_class_bool *) fc;
146 static inline fs_sink_ctf_field_class_int *
147 fs_sink_ctf_field_class_as_int(fs_sink_ctf_field_class *fc)
149 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT);
151 return (fs_sink_ctf_field_class_int *) fc;
154 static inline fs_sink_ctf_field_class_float *
155 fs_sink_ctf_field_class_as_float(fs_sink_ctf_field_class *fc)
157 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT);
159 return (fs_sink_ctf_field_class_float *) fc;
162 static inline fs_sink_ctf_field_class_string *
163 fs_sink_ctf_field_class_as_string(fs_sink_ctf_field_class *fc)
165 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRING);
167 return (fs_sink_ctf_field_class_string *) fc;
170 static inline fs_sink_ctf_field_class_struct *
171 fs_sink_ctf_field_class_as_struct(fs_sink_ctf_field_class *fc)
173 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT);
175 return (fs_sink_ctf_field_class_struct *) fc;
178 static inline fs_sink_ctf_field_class_array_base *
179 fs_sink_ctf_field_class_as_array_base(fs_sink_ctf_field_class *fc)
181 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY ||
182 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE));
184 return (fs_sink_ctf_field_class_array_base *) fc;
187 static inline fs_sink_ctf_field_class_array *
188 fs_sink_ctf_field_class_as_array(fs_sink_ctf_field_class *fc)
190 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY);
192 return (fs_sink_ctf_field_class_array *) fc;
195 static inline fs_sink_ctf_field_class_sequence *
196 fs_sink_ctf_field_class_as_sequence(fs_sink_ctf_field_class *fc)
198 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE);
200 return (fs_sink_ctf_field_class_sequence *) fc;
203 static inline fs_sink_ctf_field_class_option *
204 fs_sink_ctf_field_class_as_option(fs_sink_ctf_field_class *fc)
206 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION);
208 return (fs_sink_ctf_field_class_option *) fc;
211 static inline fs_sink_ctf_field_class_variant *
212 fs_sink_ctf_field_class_as_variant(fs_sink_ctf_field_class *fc)
214 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT);
216 return (fs_sink_ctf_field_class_variant *) fc;
219 struct fs_sink_ctf_stream_class;
221 struct fs_sink_ctf_event_class
224 const bt_event_class *ir_ec;
227 struct fs_sink_ctf_stream_class *sc;
230 struct fs_sink_ctf_field_class *spec_context_fc;
233 struct fs_sink_ctf_field_class *payload_fc;
236 struct fs_sink_ctf_trace;
238 struct fs_sink_ctf_stream_class
241 struct fs_sink_ctf_trace *trace;
244 const bt_stream_class *ir_sc;
247 const bt_clock_class *default_clock_class;
249 GString *default_clock_class_name;
251 bool packets_have_ts_begin;
252 bool packets_have_ts_end;
253 bool has_discarded_events;
254 bool discarded_events_has_ts;
255 bool discarded_packets_has_ts;
258 struct fs_sink_ctf_field_class *packet_context_fc;
261 struct fs_sink_ctf_field_class *event_common_context_fc;
263 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
264 GPtrArray *event_classes;
267 * `const bt_event_class *` (weak) ->
268 * `struct fs_sink_ctf_event_class *` (weak)
270 GHashTable *event_classes_from_ir;
273 struct fs_sink_ctf_trace
276 const bt_trace *ir_trace;
279 const bt_trace_class *ir_tc;
283 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
284 GPtrArray *stream_classes;
287 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc);
289 static inline void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class *fc,
290 enum fs_sink_ctf_field_class_type type,
291 const bt_field_class *ir_fc,
292 unsigned int alignment, uint64_t index_in_parent)
297 fc->alignment = alignment;
298 fc->index_in_parent = index_in_parent;
301 static inline void _fs_sink_ctf_field_class_bit_array_init(
302 struct fs_sink_ctf_field_class_bit_array *fc, enum fs_sink_ctf_field_class_type type,
303 const bt_field_class *ir_fc, unsigned int size, uint64_t index_in_parent)
305 _fs_sink_ctf_field_class_init(&fc->base, type, ir_fc, size % 8 == 0 ? 8 : 1, index_in_parent);
309 static inline void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int *fc,
310 enum fs_sink_ctf_field_class_type type,
311 const bt_field_class *ir_fc,
312 uint64_t index_in_parent)
314 bt_field_class_type ir_fc_type = bt_field_class_get_type(ir_fc);
316 _fs_sink_ctf_field_class_bit_array_init(
317 &fc->base, type, ir_fc, (unsigned int) bt_field_class_integer_get_field_value_range(ir_fc),
319 fc->is_signed = bt_field_class_type_is(ir_fc_type, BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
323 _fs_sink_ctf_named_field_class_init(struct fs_sink_ctf_named_field_class *named_fc)
326 named_fc->name = g_string_new(NULL);
327 BT_ASSERT(named_fc->name);
331 _fs_sink_ctf_named_field_class_fini(struct fs_sink_ctf_named_field_class *named_fc)
335 if (named_fc->name) {
336 g_string_free(named_fc->name, TRUE);
337 named_fc->name = NULL;
340 fs_sink_ctf_field_class_destroy(named_fc->fc);
344 static inline struct fs_sink_ctf_field_class_bit_array *
345 fs_sink_ctf_field_class_bit_array_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
347 struct fs_sink_ctf_field_class_bit_array *fc =
348 g_new0(struct fs_sink_ctf_field_class_bit_array, 1);
351 _fs_sink_ctf_field_class_bit_array_init(
352 fc, FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc,
353 (unsigned int) bt_field_class_bit_array_get_length(ir_fc), index_in_parent);
357 static inline struct fs_sink_ctf_field_class_bool *
358 fs_sink_ctf_field_class_bool_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
360 struct fs_sink_ctf_field_class_bool *fc = g_new0(struct fs_sink_ctf_field_class_bool, 1);
365 * CTF 1.8 has no boolean field class type, so this component
366 * translates it to an 8-bit unsigned integer field class.
368 _fs_sink_ctf_field_class_bit_array_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc, 8,
373 static inline struct fs_sink_ctf_field_class_int *
374 fs_sink_ctf_field_class_int_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
376 struct fs_sink_ctf_field_class_int *fc = g_new0(struct fs_sink_ctf_field_class_int, 1);
379 _fs_sink_ctf_field_class_int_init(fc, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, ir_fc, index_in_parent);
383 static inline struct fs_sink_ctf_field_class_float *
384 fs_sink_ctf_field_class_float_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
386 struct fs_sink_ctf_field_class_float *fc = g_new0(struct fs_sink_ctf_field_class_float, 1);
389 _fs_sink_ctf_field_class_bit_array_init(
390 &fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, ir_fc,
391 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
396 static inline struct fs_sink_ctf_field_class_string *
397 fs_sink_ctf_field_class_string_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
399 struct fs_sink_ctf_field_class_string *fc = g_new0(struct fs_sink_ctf_field_class_string, 1);
402 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, ir_fc, 8,
407 static inline struct fs_sink_ctf_field_class_struct *
408 fs_sink_ctf_field_class_struct_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
410 struct fs_sink_ctf_field_class_struct *fc = g_new0(struct fs_sink_ctf_field_class_struct, 1);
413 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, ir_fc, 1,
415 fc->members = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
416 BT_ASSERT(fc->members);
420 static inline struct fs_sink_ctf_field_class_option *
421 fs_sink_ctf_field_class_option_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
423 struct fs_sink_ctf_field_class_option *fc = g_new0(struct fs_sink_ctf_field_class_option, 1);
426 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc, 1,
428 fc->tag_ref = g_string_new(NULL);
429 BT_ASSERT(fc->tag_ref);
433 static inline struct fs_sink_ctf_field_class_variant *
434 fs_sink_ctf_field_class_variant_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
436 struct fs_sink_ctf_field_class_variant *fc = g_new0(struct fs_sink_ctf_field_class_variant, 1);
439 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, ir_fc, 1,
441 fc->options = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
442 BT_ASSERT(fc->options);
443 fc->tag_ref = g_string_new(NULL);
444 BT_ASSERT(fc->tag_ref);
445 fc->tag_is_before = bt_field_class_get_type(fc->base.ir_fc) ==
446 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD;
450 static inline struct fs_sink_ctf_field_class_array *
451 fs_sink_ctf_field_class_array_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
453 struct fs_sink_ctf_field_class_array *fc = g_new0(struct fs_sink_ctf_field_class_array, 1);
456 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc, 1,
458 fc->length = bt_field_class_array_static_get_length(ir_fc);
462 static inline struct fs_sink_ctf_field_class_sequence *
463 fs_sink_ctf_field_class_sequence_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
465 struct fs_sink_ctf_field_class_sequence *fc =
466 g_new0(struct fs_sink_ctf_field_class_sequence, 1);
469 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE, ir_fc, 1,
471 fc->length_ref = g_string_new(NULL);
472 BT_ASSERT(fc->length_ref);
473 fc->length_is_before =
474 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD;
478 static inline struct fs_sink_ctf_named_field_class *
479 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
482 static inline struct fs_sink_ctf_named_field_class *
483 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
486 static inline void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc)
492 _fs_sink_ctf_field_class_bit_array_destroy(struct fs_sink_ctf_field_class_bit_array *fc)
495 _fs_sink_ctf_field_class_fini(&fc->base);
499 static inline void _fs_sink_ctf_field_class_bool_destroy(struct fs_sink_ctf_field_class_bool *fc)
502 _fs_sink_ctf_field_class_fini(&fc->base.base);
506 static inline void _fs_sink_ctf_field_class_int_destroy(struct fs_sink_ctf_field_class_int *fc)
509 _fs_sink_ctf_field_class_fini(&fc->base.base);
513 static inline void _fs_sink_ctf_field_class_float_destroy(struct fs_sink_ctf_field_class_float *fc)
516 _fs_sink_ctf_field_class_fini(&fc->base.base);
521 _fs_sink_ctf_field_class_string_destroy(struct fs_sink_ctf_field_class_string *fc)
524 _fs_sink_ctf_field_class_fini(&fc->base);
529 _fs_sink_ctf_field_class_struct_destroy(struct fs_sink_ctf_field_class_struct *fc)
532 _fs_sink_ctf_field_class_fini(&fc->base);
537 for (i = 0; i < fc->members->len; i++) {
538 struct fs_sink_ctf_named_field_class *named_fc =
539 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
541 _fs_sink_ctf_named_field_class_fini(named_fc);
544 g_array_free(fc->members, TRUE);
552 _fs_sink_ctf_field_class_array_base_fini(struct fs_sink_ctf_field_class_array_base *fc)
555 _fs_sink_ctf_field_class_fini(&fc->base);
556 fs_sink_ctf_field_class_destroy(fc->elem_fc);
560 static inline void _fs_sink_ctf_field_class_array_destroy(struct fs_sink_ctf_field_class_array *fc)
563 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
568 _fs_sink_ctf_field_class_sequence_destroy(struct fs_sink_ctf_field_class_sequence *fc)
571 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
573 if (fc->length_ref) {
574 g_string_free(fc->length_ref, TRUE);
575 fc->length_ref = NULL;
582 _fs_sink_ctf_field_class_option_destroy(struct fs_sink_ctf_field_class_option *fc)
585 _fs_sink_ctf_field_class_fini(&fc->base);
586 fs_sink_ctf_field_class_destroy(fc->content_fc);
589 g_string_free(fc->tag_ref, TRUE);
597 _fs_sink_ctf_field_class_variant_destroy(struct fs_sink_ctf_field_class_variant *fc)
600 _fs_sink_ctf_field_class_fini(&fc->base);
605 for (i = 0; i < fc->options->len; i++) {
606 struct fs_sink_ctf_named_field_class *named_fc =
607 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
609 _fs_sink_ctf_named_field_class_fini(named_fc);
612 g_array_free(fc->options, TRUE);
617 g_string_free(fc->tag_ref, TRUE);
624 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
631 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL:
632 _fs_sink_ctf_field_class_bool_destroy(fs_sink_ctf_field_class_as_bool(fc));
634 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY:
635 _fs_sink_ctf_field_class_bit_array_destroy(fs_sink_ctf_field_class_as_bit_array(fc));
637 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT:
638 _fs_sink_ctf_field_class_int_destroy(fs_sink_ctf_field_class_as_int(fc));
640 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT:
641 _fs_sink_ctf_field_class_float_destroy(fs_sink_ctf_field_class_as_float(fc));
643 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING:
644 _fs_sink_ctf_field_class_string_destroy(fs_sink_ctf_field_class_as_string(fc));
646 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
647 _fs_sink_ctf_field_class_struct_destroy(fs_sink_ctf_field_class_as_struct(fc));
649 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
650 _fs_sink_ctf_field_class_array_destroy(fs_sink_ctf_field_class_as_array(fc));
652 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
653 _fs_sink_ctf_field_class_sequence_destroy(fs_sink_ctf_field_class_as_sequence(fc));
655 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION:
656 _fs_sink_ctf_field_class_option_destroy(fs_sink_ctf_field_class_as_option(fc));
658 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
659 _fs_sink_ctf_field_class_variant_destroy(fs_sink_ctf_field_class_as_variant(fc));
666 static inline struct fs_sink_ctf_named_field_class *
667 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
671 BT_ASSERT_DBG(index < fc->members->len);
672 return &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, index);
675 static inline struct fs_sink_ctf_named_field_class *
676 fs_sink_ctf_field_class_struct_borrow_member_by_name(struct fs_sink_ctf_field_class_struct *fc,
680 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
685 for (i = 0; i < fc->members->len; i++) {
686 struct fs_sink_ctf_named_field_class *named_fc =
687 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
689 if (strcmp(name, named_fc->name->str) == 0) {
690 ret_named_fc = named_fc;
699 static inline struct fs_sink_ctf_field_class *
700 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
701 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
703 struct fs_sink_ctf_named_field_class *named_fc = NULL;
704 struct fs_sink_ctf_field_class *fc = NULL;
710 named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_name(struct_fc, name);
721 static inline struct fs_sink_ctf_field_class_int *
722 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
723 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
725 struct fs_sink_ctf_field_class_int *int_fc = NULL;
727 int_fc = fs_sink_ctf_field_class_as_int(
728 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(struct_fc, name));
733 if (int_fc->base.base.type != FS_SINK_CTF_FIELD_CLASS_TYPE_INT) {
743 fs_sink_ctf_field_class_struct_align_at_least(struct fs_sink_ctf_field_class_struct *fc,
744 unsigned int alignment)
746 if (alignment > fc->base.alignment) {
747 fc->base.alignment = alignment;
752 fs_sink_ctf_field_class_struct_append_member(struct fs_sink_ctf_field_class_struct *fc,
754 struct fs_sink_ctf_field_class *member_fc)
756 struct fs_sink_ctf_named_field_class *named_fc;
760 g_array_set_size(fc->members, fc->members->len + 1);
763 &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, fc->members->len - 1);
764 _fs_sink_ctf_named_field_class_init(named_fc);
765 g_string_assign(named_fc->name, name);
766 named_fc->fc = member_fc;
767 fs_sink_ctf_field_class_struct_align_at_least(fc, member_fc->alignment);
770 static inline struct fs_sink_ctf_named_field_class *
771 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
775 BT_ASSERT_DBG(index < fc->options->len);
776 return &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, index);
779 static inline struct fs_sink_ctf_named_field_class *
780 fs_sink_ctf_field_class_variant_borrow_option_by_name(struct fs_sink_ctf_field_class_variant *fc,
784 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
789 for (i = 0; i < fc->options->len; i++) {
790 struct fs_sink_ctf_named_field_class *named_fc =
791 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
793 if (strcmp(name, named_fc->name->str) == 0) {
794 ret_named_fc = named_fc;
804 fs_sink_ctf_field_class_variant_append_option(struct fs_sink_ctf_field_class_variant *fc,
806 struct fs_sink_ctf_field_class *option_fc)
808 struct fs_sink_ctf_named_field_class *named_fc;
812 g_array_set_size(fc->options, fc->options->len + 1);
815 &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, fc->options->len - 1);
816 _fs_sink_ctf_named_field_class_init(named_fc);
817 g_string_assign(named_fc->name, name);
818 named_fc->fc = option_fc;
821 static inline struct fs_sink_ctf_event_class *
822 fs_sink_ctf_event_class_create(struct fs_sink_ctf_stream_class *sc, const bt_event_class *ir_ec)
824 struct fs_sink_ctf_event_class *ec = g_new0(struct fs_sink_ctf_event_class, 1);
831 g_ptr_array_add(sc->event_classes, ec);
832 g_hash_table_insert(sc->event_classes_from_ir, (gpointer) ir_ec, ec);
836 static inline void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec)
842 fs_sink_ctf_field_class_destroy(ec->spec_context_fc);
843 ec->spec_context_fc = NULL;
844 fs_sink_ctf_field_class_destroy(ec->payload_fc);
845 ec->payload_fc = NULL;
849 static inline struct fs_sink_ctf_stream_class *
850 fs_sink_ctf_stream_class_create(struct fs_sink_ctf_trace *trace, const bt_stream_class *ir_sc)
852 struct fs_sink_ctf_stream_class *sc = g_new0(struct fs_sink_ctf_stream_class, 1);
859 sc->default_clock_class = bt_stream_class_borrow_default_clock_class_const(ir_sc);
860 sc->default_clock_class_name = g_string_new(NULL);
861 BT_ASSERT(sc->default_clock_class_name);
863 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_event_class_destroy);
864 BT_ASSERT(sc->event_classes);
865 sc->event_classes_from_ir = g_hash_table_new(g_direct_hash, g_direct_equal);
866 BT_ASSERT(sc->event_classes_from_ir);
867 sc->has_packets = bt_stream_class_supports_packets(ir_sc);
868 sc->packets_have_ts_begin =
869 bt_stream_class_packets_have_beginning_default_clock_snapshot(ir_sc);
870 sc->packets_have_ts_end = bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
871 sc->has_discarded_events = bt_stream_class_supports_discarded_events(ir_sc);
873 if (sc->has_discarded_events) {
874 sc->discarded_events_has_ts =
875 bt_stream_class_discarded_events_have_default_clock_snapshots(ir_sc);
878 if (bt_stream_class_supports_discarded_packets(ir_sc)) {
879 sc->discarded_packets_has_ts =
880 bt_stream_class_discarded_packets_have_default_clock_snapshots(ir_sc);
883 g_ptr_array_add(trace->stream_classes, sc);
887 static inline void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class *sc)
893 if (sc->default_clock_class_name) {
894 g_string_free(sc->default_clock_class_name, TRUE);
895 sc->default_clock_class_name = NULL;
898 if (sc->event_classes) {
899 g_ptr_array_free(sc->event_classes, TRUE);
900 sc->event_classes = NULL;
903 if (sc->event_classes_from_ir) {
904 g_hash_table_destroy(sc->event_classes_from_ir);
905 sc->event_classes_from_ir = NULL;
908 fs_sink_ctf_field_class_destroy(sc->packet_context_fc);
909 sc->packet_context_fc = NULL;
910 fs_sink_ctf_field_class_destroy(sc->event_common_context_fc);
911 sc->event_common_context_fc = NULL;
915 static inline void fs_sink_ctf_stream_class_append_event_class(struct fs_sink_ctf_stream_class *sc,
916 struct fs_sink_ctf_event_class *ec)
918 g_ptr_array_add(sc->event_classes, ec);
921 static inline void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace)
927 if (trace->stream_classes) {
928 g_ptr_array_free(trace->stream_classes, TRUE);
929 trace->stream_classes = NULL;
935 static inline struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
937 struct fs_sink_ctf_trace *trace = g_new0(struct fs_sink_ctf_trace, 1);
941 bt_uuid_generate(trace->uuid);
943 trace->ir_trace = ir_trace;
944 trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
945 trace->stream_classes =
946 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_stream_class_destroy);
947 BT_ASSERT(trace->stream_classes);
952 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */