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
16 #include <babeltrace2/babeltrace.h>
18 #include "common/assert.h"
19 #include "common/common.h"
20 #include "common/uuid.h"
22 enum fs_sink_ctf_field_class_type
24 FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL,
25 FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY,
26 FS_SINK_CTF_FIELD_CLASS_TYPE_INT,
27 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
28 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING,
29 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT,
30 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY,
31 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE,
32 FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION,
33 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT,
36 struct fs_sink_ctf_field_class
38 enum fs_sink_ctf_field_class_type type;
41 const bt_field_class *ir_fc;
43 unsigned int alignment;
45 /* Index of the field class within its own parent */
46 uint64_t index_in_parent;
49 struct fs_sink_ctf_field_class_bit_array
51 struct fs_sink_ctf_field_class base;
55 struct fs_sink_ctf_field_class_bool
57 struct fs_sink_ctf_field_class_bit_array base;
60 struct fs_sink_ctf_field_class_int
62 struct fs_sink_ctf_field_class_bit_array base;
66 struct fs_sink_ctf_field_class_float
68 struct fs_sink_ctf_field_class_bit_array base;
71 struct fs_sink_ctf_field_class_string
73 struct fs_sink_ctf_field_class base;
76 struct fs_sink_ctf_named_field_class
81 struct fs_sink_ctf_field_class *fc;
84 struct fs_sink_ctf_field_class_struct
86 struct fs_sink_ctf_field_class base;
88 /* Array of `struct fs_sink_ctf_named_field_class` */
92 struct fs_sink_ctf_field_class_option
94 struct fs_sink_ctf_field_class base;
95 struct fs_sink_ctf_field_class *content_fc;
99 struct fs_sink_ctf_field_class_variant
101 struct fs_sink_ctf_field_class base;
105 /* Array of `struct fs_sink_ctf_named_field_class` */
109 struct fs_sink_ctf_field_class_array_base
111 struct fs_sink_ctf_field_class base;
112 struct fs_sink_ctf_field_class *elem_fc;
115 struct fs_sink_ctf_field_class_array
117 struct fs_sink_ctf_field_class_array_base base;
121 struct fs_sink_ctf_field_class_sequence
123 struct fs_sink_ctf_field_class_array_base base;
125 bool length_is_before;
128 static inline fs_sink_ctf_field_class_bit_array *
129 fs_sink_ctf_field_class_as_bit_array(fs_sink_ctf_field_class *fc)
131 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY ||
132 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT ||
133 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL ||
134 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT));
136 return (fs_sink_ctf_field_class_bit_array *) fc;
139 static inline fs_sink_ctf_field_class_bool *
140 fs_sink_ctf_field_class_as_bool(fs_sink_ctf_field_class *fc)
142 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL);
144 return (fs_sink_ctf_field_class_bool *) fc;
147 static inline fs_sink_ctf_field_class_int *
148 fs_sink_ctf_field_class_as_int(fs_sink_ctf_field_class *fc)
150 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT);
152 return (fs_sink_ctf_field_class_int *) fc;
155 static inline fs_sink_ctf_field_class_float *
156 fs_sink_ctf_field_class_as_float(fs_sink_ctf_field_class *fc)
158 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT);
160 return (fs_sink_ctf_field_class_float *) fc;
163 static inline fs_sink_ctf_field_class_string *
164 fs_sink_ctf_field_class_as_string(fs_sink_ctf_field_class *fc)
166 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRING);
168 return (fs_sink_ctf_field_class_string *) fc;
171 static inline fs_sink_ctf_field_class_struct *
172 fs_sink_ctf_field_class_as_struct(fs_sink_ctf_field_class *fc)
174 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT);
176 return (fs_sink_ctf_field_class_struct *) fc;
179 static inline fs_sink_ctf_field_class_array_base *
180 fs_sink_ctf_field_class_as_array_base(fs_sink_ctf_field_class *fc)
182 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY ||
183 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE));
185 return (fs_sink_ctf_field_class_array_base *) fc;
188 static inline fs_sink_ctf_field_class_array *
189 fs_sink_ctf_field_class_as_array(fs_sink_ctf_field_class *fc)
191 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY);
193 return (fs_sink_ctf_field_class_array *) fc;
196 static inline fs_sink_ctf_field_class_sequence *
197 fs_sink_ctf_field_class_as_sequence(fs_sink_ctf_field_class *fc)
199 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE);
201 return (fs_sink_ctf_field_class_sequence *) fc;
204 static inline fs_sink_ctf_field_class_option *
205 fs_sink_ctf_field_class_as_option(fs_sink_ctf_field_class *fc)
207 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION);
209 return (fs_sink_ctf_field_class_option *) fc;
212 static inline fs_sink_ctf_field_class_variant *
213 fs_sink_ctf_field_class_as_variant(fs_sink_ctf_field_class *fc)
215 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT);
217 return (fs_sink_ctf_field_class_variant *) fc;
220 struct fs_sink_ctf_stream_class;
222 struct fs_sink_ctf_event_class
225 const bt_event_class *ir_ec;
228 struct fs_sink_ctf_stream_class *sc;
231 struct fs_sink_ctf_field_class *spec_context_fc;
234 struct fs_sink_ctf_field_class *payload_fc;
237 struct fs_sink_ctf_trace;
239 struct fs_sink_ctf_stream_class
242 struct fs_sink_ctf_trace *trace;
245 const bt_stream_class *ir_sc;
248 const bt_clock_class *default_clock_class;
250 GString *default_clock_class_name;
252 bool packets_have_ts_begin;
253 bool packets_have_ts_end;
254 bool has_discarded_events;
255 bool discarded_events_has_ts;
256 bool discarded_packets_has_ts;
259 struct fs_sink_ctf_field_class *packet_context_fc;
262 struct fs_sink_ctf_field_class *event_common_context_fc;
264 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
265 GPtrArray *event_classes;
268 * `const bt_event_class *` (weak) ->
269 * `struct fs_sink_ctf_event_class *` (weak)
271 GHashTable *event_classes_from_ir;
274 struct fs_sink_ctf_trace
277 const bt_trace *ir_trace;
280 const bt_trace_class *ir_tc;
284 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
285 GPtrArray *stream_classes;
288 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc);
290 static inline void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class *fc,
291 enum fs_sink_ctf_field_class_type type,
292 const bt_field_class *ir_fc,
293 unsigned int alignment, uint64_t index_in_parent)
298 fc->alignment = alignment;
299 fc->index_in_parent = index_in_parent;
302 static inline void _fs_sink_ctf_field_class_bit_array_init(
303 struct fs_sink_ctf_field_class_bit_array *fc, enum fs_sink_ctf_field_class_type type,
304 const bt_field_class *ir_fc, unsigned int size, uint64_t index_in_parent)
306 _fs_sink_ctf_field_class_init(&fc->base, type, ir_fc, size % 8 == 0 ? 8 : 1, index_in_parent);
310 static inline void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int *fc,
311 enum fs_sink_ctf_field_class_type type,
312 const bt_field_class *ir_fc,
313 uint64_t index_in_parent)
315 bt_field_class_type ir_fc_type = bt_field_class_get_type(ir_fc);
317 _fs_sink_ctf_field_class_bit_array_init(
318 &fc->base, type, ir_fc, (unsigned int) bt_field_class_integer_get_field_value_range(ir_fc),
320 fc->is_signed = bt_field_class_type_is(ir_fc_type, BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
324 _fs_sink_ctf_named_field_class_init(struct fs_sink_ctf_named_field_class *named_fc)
327 named_fc->name = g_string_new(NULL);
328 BT_ASSERT(named_fc->name);
332 _fs_sink_ctf_named_field_class_fini(struct fs_sink_ctf_named_field_class *named_fc)
336 if (named_fc->name) {
337 g_string_free(named_fc->name, TRUE);
338 named_fc->name = NULL;
341 fs_sink_ctf_field_class_destroy(named_fc->fc);
345 static inline struct fs_sink_ctf_field_class_bit_array *
346 fs_sink_ctf_field_class_bit_array_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
348 struct fs_sink_ctf_field_class_bit_array *fc =
349 g_new0(struct fs_sink_ctf_field_class_bit_array, 1);
352 _fs_sink_ctf_field_class_bit_array_init(
353 fc, FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc,
354 (unsigned int) bt_field_class_bit_array_get_length(ir_fc), index_in_parent);
358 static inline struct fs_sink_ctf_field_class_bool *
359 fs_sink_ctf_field_class_bool_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
361 struct fs_sink_ctf_field_class_bool *fc = g_new0(struct fs_sink_ctf_field_class_bool, 1);
366 * CTF 1.8 has no boolean field class type, so this component
367 * translates it to an 8-bit unsigned integer field class.
369 _fs_sink_ctf_field_class_bit_array_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc, 8,
374 static inline struct fs_sink_ctf_field_class_int *
375 fs_sink_ctf_field_class_int_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
377 struct fs_sink_ctf_field_class_int *fc = g_new0(struct fs_sink_ctf_field_class_int, 1);
380 _fs_sink_ctf_field_class_int_init(fc, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, ir_fc, index_in_parent);
384 static inline struct fs_sink_ctf_field_class_float *
385 fs_sink_ctf_field_class_float_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
387 struct fs_sink_ctf_field_class_float *fc = g_new0(struct fs_sink_ctf_field_class_float, 1);
390 _fs_sink_ctf_field_class_bit_array_init(
391 &fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, ir_fc,
392 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
397 static inline struct fs_sink_ctf_field_class_string *
398 fs_sink_ctf_field_class_string_create(const bt_field_class *ir_fc, uint64_t index_in_parent)
400 struct fs_sink_ctf_field_class_string *fc = g_new0(struct fs_sink_ctf_field_class_string, 1);
403 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, ir_fc, 8,
408 static inline struct fs_sink_ctf_field_class_struct *
409 fs_sink_ctf_field_class_struct_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
411 struct fs_sink_ctf_field_class_struct *fc = g_new0(struct fs_sink_ctf_field_class_struct, 1);
414 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, ir_fc, 1,
416 fc->members = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
417 BT_ASSERT(fc->members);
421 static inline struct fs_sink_ctf_field_class_option *
422 fs_sink_ctf_field_class_option_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
424 struct fs_sink_ctf_field_class_option *fc = g_new0(struct fs_sink_ctf_field_class_option, 1);
427 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc, 1,
429 fc->tag_ref = g_string_new(NULL);
430 BT_ASSERT(fc->tag_ref);
434 static inline struct fs_sink_ctf_field_class_variant *
435 fs_sink_ctf_field_class_variant_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
437 struct fs_sink_ctf_field_class_variant *fc = g_new0(struct fs_sink_ctf_field_class_variant, 1);
440 _fs_sink_ctf_field_class_init(&fc->base, FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, ir_fc, 1,
442 fc->options = g_array_new(FALSE, TRUE, sizeof(struct fs_sink_ctf_named_field_class));
443 BT_ASSERT(fc->options);
444 fc->tag_ref = g_string_new(NULL);
445 BT_ASSERT(fc->tag_ref);
446 fc->tag_is_before = bt_field_class_get_type(fc->base.ir_fc) ==
447 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD;
451 static inline struct fs_sink_ctf_field_class_array *
452 fs_sink_ctf_field_class_array_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
454 struct fs_sink_ctf_field_class_array *fc = g_new0(struct fs_sink_ctf_field_class_array, 1);
457 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc, 1,
459 fc->length = bt_field_class_array_static_get_length(ir_fc);
463 static inline struct fs_sink_ctf_field_class_sequence *
464 fs_sink_ctf_field_class_sequence_create_empty(const bt_field_class *ir_fc, uint64_t index_in_parent)
466 struct fs_sink_ctf_field_class_sequence *fc =
467 g_new0(struct fs_sink_ctf_field_class_sequence, 1);
470 _fs_sink_ctf_field_class_init(&fc->base.base, FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE, ir_fc, 1,
472 fc->length_ref = g_string_new(NULL);
473 BT_ASSERT(fc->length_ref);
474 fc->length_is_before =
475 bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD;
479 static inline struct fs_sink_ctf_named_field_class *
480 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
483 static inline struct fs_sink_ctf_named_field_class *
484 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
487 static inline void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc)
493 _fs_sink_ctf_field_class_bit_array_destroy(struct fs_sink_ctf_field_class_bit_array *fc)
496 _fs_sink_ctf_field_class_fini(&fc->base);
500 static inline void _fs_sink_ctf_field_class_bool_destroy(struct fs_sink_ctf_field_class_bool *fc)
503 _fs_sink_ctf_field_class_fini(&fc->base.base);
507 static inline void _fs_sink_ctf_field_class_int_destroy(struct fs_sink_ctf_field_class_int *fc)
510 _fs_sink_ctf_field_class_fini(&fc->base.base);
514 static inline void _fs_sink_ctf_field_class_float_destroy(struct fs_sink_ctf_field_class_float *fc)
517 _fs_sink_ctf_field_class_fini(&fc->base.base);
522 _fs_sink_ctf_field_class_string_destroy(struct fs_sink_ctf_field_class_string *fc)
525 _fs_sink_ctf_field_class_fini(&fc->base);
530 _fs_sink_ctf_field_class_struct_destroy(struct fs_sink_ctf_field_class_struct *fc)
533 _fs_sink_ctf_field_class_fini(&fc->base);
538 for (i = 0; i < fc->members->len; i++) {
539 struct fs_sink_ctf_named_field_class *named_fc =
540 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
542 _fs_sink_ctf_named_field_class_fini(named_fc);
545 g_array_free(fc->members, TRUE);
553 _fs_sink_ctf_field_class_array_base_fini(struct fs_sink_ctf_field_class_array_base *fc)
556 _fs_sink_ctf_field_class_fini(&fc->base);
557 fs_sink_ctf_field_class_destroy(fc->elem_fc);
561 static inline void _fs_sink_ctf_field_class_array_destroy(struct fs_sink_ctf_field_class_array *fc)
564 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
569 _fs_sink_ctf_field_class_sequence_destroy(struct fs_sink_ctf_field_class_sequence *fc)
572 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
574 if (fc->length_ref) {
575 g_string_free(fc->length_ref, TRUE);
576 fc->length_ref = NULL;
583 _fs_sink_ctf_field_class_option_destroy(struct fs_sink_ctf_field_class_option *fc)
586 _fs_sink_ctf_field_class_fini(&fc->base);
587 fs_sink_ctf_field_class_destroy(fc->content_fc);
590 g_string_free(fc->tag_ref, TRUE);
598 _fs_sink_ctf_field_class_variant_destroy(struct fs_sink_ctf_field_class_variant *fc)
601 _fs_sink_ctf_field_class_fini(&fc->base);
606 for (i = 0; i < fc->options->len; i++) {
607 struct fs_sink_ctf_named_field_class *named_fc =
608 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
610 _fs_sink_ctf_named_field_class_fini(named_fc);
613 g_array_free(fc->options, TRUE);
618 g_string_free(fc->tag_ref, TRUE);
625 static inline void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
632 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL:
633 _fs_sink_ctf_field_class_bool_destroy(fs_sink_ctf_field_class_as_bool(fc));
635 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY:
636 _fs_sink_ctf_field_class_bit_array_destroy(fs_sink_ctf_field_class_as_bit_array(fc));
638 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT:
639 _fs_sink_ctf_field_class_int_destroy(fs_sink_ctf_field_class_as_int(fc));
641 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT:
642 _fs_sink_ctf_field_class_float_destroy(fs_sink_ctf_field_class_as_float(fc));
644 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING:
645 _fs_sink_ctf_field_class_string_destroy(fs_sink_ctf_field_class_as_string(fc));
647 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
648 _fs_sink_ctf_field_class_struct_destroy(fs_sink_ctf_field_class_as_struct(fc));
650 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
651 _fs_sink_ctf_field_class_array_destroy(fs_sink_ctf_field_class_as_array(fc));
653 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
654 _fs_sink_ctf_field_class_sequence_destroy(fs_sink_ctf_field_class_as_sequence(fc));
656 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION:
657 _fs_sink_ctf_field_class_option_destroy(fs_sink_ctf_field_class_as_option(fc));
659 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
660 _fs_sink_ctf_field_class_variant_destroy(fs_sink_ctf_field_class_as_variant(fc));
667 static inline struct fs_sink_ctf_named_field_class *
668 fs_sink_ctf_field_class_struct_borrow_member_by_index(struct fs_sink_ctf_field_class_struct *fc,
672 BT_ASSERT_DBG(index < fc->members->len);
673 return &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, index);
676 static inline struct fs_sink_ctf_named_field_class *
677 fs_sink_ctf_field_class_struct_borrow_member_by_name(struct fs_sink_ctf_field_class_struct *fc,
681 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
686 for (i = 0; i < fc->members->len; i++) {
687 struct fs_sink_ctf_named_field_class *named_fc =
688 fs_sink_ctf_field_class_struct_borrow_member_by_index(fc, i);
690 if (strcmp(name, named_fc->name->str) == 0) {
691 ret_named_fc = named_fc;
700 static inline struct fs_sink_ctf_field_class *
701 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
702 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
704 struct fs_sink_ctf_named_field_class *named_fc = NULL;
705 struct fs_sink_ctf_field_class *fc = NULL;
711 named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_name(struct_fc, name);
722 static inline struct fs_sink_ctf_field_class_int *
723 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
724 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
726 struct fs_sink_ctf_field_class_int *int_fc = NULL;
728 int_fc = fs_sink_ctf_field_class_as_int(
729 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(struct_fc, name));
734 if (int_fc->base.base.type != FS_SINK_CTF_FIELD_CLASS_TYPE_INT) {
744 fs_sink_ctf_field_class_struct_align_at_least(struct fs_sink_ctf_field_class_struct *fc,
745 unsigned int alignment)
747 if (alignment > fc->base.alignment) {
748 fc->base.alignment = alignment;
753 fs_sink_ctf_field_class_struct_append_member(struct fs_sink_ctf_field_class_struct *fc,
755 struct fs_sink_ctf_field_class *member_fc)
757 struct fs_sink_ctf_named_field_class *named_fc;
761 g_array_set_size(fc->members, fc->members->len + 1);
764 &bt_g_array_index(fc->members, struct fs_sink_ctf_named_field_class, fc->members->len - 1);
765 _fs_sink_ctf_named_field_class_init(named_fc);
766 g_string_assign(named_fc->name, name);
767 named_fc->fc = member_fc;
768 fs_sink_ctf_field_class_struct_align_at_least(fc, member_fc->alignment);
771 static inline struct fs_sink_ctf_named_field_class *
772 fs_sink_ctf_field_class_variant_borrow_option_by_index(struct fs_sink_ctf_field_class_variant *fc,
776 BT_ASSERT_DBG(index < fc->options->len);
777 return &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, index);
780 static inline struct fs_sink_ctf_named_field_class *
781 fs_sink_ctf_field_class_variant_borrow_option_by_name(struct fs_sink_ctf_field_class_variant *fc,
785 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
790 for (i = 0; i < fc->options->len; i++) {
791 struct fs_sink_ctf_named_field_class *named_fc =
792 fs_sink_ctf_field_class_variant_borrow_option_by_index(fc, i);
794 if (strcmp(name, named_fc->name->str) == 0) {
795 ret_named_fc = named_fc;
805 fs_sink_ctf_field_class_variant_append_option(struct fs_sink_ctf_field_class_variant *fc,
807 struct fs_sink_ctf_field_class *option_fc)
809 struct fs_sink_ctf_named_field_class *named_fc;
813 g_array_set_size(fc->options, fc->options->len + 1);
816 &bt_g_array_index(fc->options, struct fs_sink_ctf_named_field_class, fc->options->len - 1);
817 _fs_sink_ctf_named_field_class_init(named_fc);
818 g_string_assign(named_fc->name, name);
819 named_fc->fc = option_fc;
822 static inline struct fs_sink_ctf_event_class *
823 fs_sink_ctf_event_class_create(struct fs_sink_ctf_stream_class *sc, const bt_event_class *ir_ec)
825 struct fs_sink_ctf_event_class *ec = g_new0(struct fs_sink_ctf_event_class, 1);
832 g_ptr_array_add(sc->event_classes, ec);
833 g_hash_table_insert(sc->event_classes_from_ir, (gpointer) ir_ec, ec);
837 static inline void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec)
843 fs_sink_ctf_field_class_destroy(ec->spec_context_fc);
844 ec->spec_context_fc = NULL;
845 fs_sink_ctf_field_class_destroy(ec->payload_fc);
846 ec->payload_fc = NULL;
850 static inline struct fs_sink_ctf_stream_class *
851 fs_sink_ctf_stream_class_create(struct fs_sink_ctf_trace *trace, const bt_stream_class *ir_sc)
853 struct fs_sink_ctf_stream_class *sc = g_new0(struct fs_sink_ctf_stream_class, 1);
860 sc->default_clock_class = bt_stream_class_borrow_default_clock_class_const(ir_sc);
861 sc->default_clock_class_name = g_string_new(NULL);
862 BT_ASSERT(sc->default_clock_class_name);
864 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_event_class_destroy);
865 BT_ASSERT(sc->event_classes);
866 sc->event_classes_from_ir = g_hash_table_new(g_direct_hash, g_direct_equal);
867 BT_ASSERT(sc->event_classes_from_ir);
868 sc->has_packets = bt_stream_class_supports_packets(ir_sc);
869 sc->packets_have_ts_begin =
870 bt_stream_class_packets_have_beginning_default_clock_snapshot(ir_sc);
871 sc->packets_have_ts_end = bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
872 sc->has_discarded_events = bt_stream_class_supports_discarded_events(ir_sc);
874 if (sc->has_discarded_events) {
875 sc->discarded_events_has_ts =
876 bt_stream_class_discarded_events_have_default_clock_snapshots(ir_sc);
879 if (bt_stream_class_supports_discarded_packets(ir_sc)) {
880 sc->discarded_packets_has_ts =
881 bt_stream_class_discarded_packets_have_default_clock_snapshots(ir_sc);
884 g_ptr_array_add(trace->stream_classes, sc);
888 static inline void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class *sc)
894 if (sc->default_clock_class_name) {
895 g_string_free(sc->default_clock_class_name, TRUE);
896 sc->default_clock_class_name = NULL;
899 if (sc->event_classes) {
900 g_ptr_array_free(sc->event_classes, TRUE);
901 sc->event_classes = NULL;
904 if (sc->event_classes_from_ir) {
905 g_hash_table_destroy(sc->event_classes_from_ir);
906 sc->event_classes_from_ir = NULL;
909 fs_sink_ctf_field_class_destroy(sc->packet_context_fc);
910 sc->packet_context_fc = NULL;
911 fs_sink_ctf_field_class_destroy(sc->event_common_context_fc);
912 sc->event_common_context_fc = NULL;
916 static inline void fs_sink_ctf_stream_class_append_event_class(struct fs_sink_ctf_stream_class *sc,
917 struct fs_sink_ctf_event_class *ec)
919 g_ptr_array_add(sc->event_classes, ec);
922 static inline void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace)
928 if (trace->stream_classes) {
929 g_ptr_array_free(trace->stream_classes, TRUE);
930 trace->stream_classes = NULL;
936 static inline struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
938 struct fs_sink_ctf_trace *trace = g_new0(struct fs_sink_ctf_trace, 1);
942 bt_uuid_generate(trace->uuid);
944 trace->ir_trace = ir_trace;
945 trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
946 trace->stream_classes =
947 g_ptr_array_new_with_free_func((GDestroyNotify) fs_sink_ctf_stream_class_destroy);
948 BT_ASSERT(trace->stream_classes);
953 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */