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 {
21 FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL,
22 FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY,
23 FS_SINK_CTF_FIELD_CLASS_TYPE_INT,
24 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
25 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING,
26 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT,
27 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY,
28 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE,
29 FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION,
30 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT,
33 struct fs_sink_ctf_field_class {
34 enum fs_sink_ctf_field_class_type type;
37 const bt_field_class *ir_fc;
39 unsigned int alignment;
41 /* Index of the field class within its own parent */
42 uint64_t index_in_parent;
45 struct fs_sink_ctf_field_class_bit_array {
46 struct fs_sink_ctf_field_class base;
50 struct fs_sink_ctf_field_class_bool {
51 struct fs_sink_ctf_field_class_bit_array base;
54 struct fs_sink_ctf_field_class_int {
55 struct fs_sink_ctf_field_class_bit_array base;
59 struct fs_sink_ctf_field_class_float {
60 struct fs_sink_ctf_field_class_bit_array base;
63 struct fs_sink_ctf_field_class_string {
64 struct fs_sink_ctf_field_class base;
67 struct fs_sink_ctf_named_field_class {
71 struct fs_sink_ctf_field_class *fc;
74 struct fs_sink_ctf_field_class_struct {
75 struct fs_sink_ctf_field_class base;
77 /* Array of `struct fs_sink_ctf_named_field_class` */
81 struct fs_sink_ctf_field_class_option {
82 struct fs_sink_ctf_field_class base;
83 struct fs_sink_ctf_field_class *content_fc;
87 struct fs_sink_ctf_field_class_variant {
88 struct fs_sink_ctf_field_class base;
92 /* Array of `struct fs_sink_ctf_named_field_class` */
96 struct fs_sink_ctf_field_class_array_base {
97 struct fs_sink_ctf_field_class base;
98 struct fs_sink_ctf_field_class *elem_fc;
101 struct fs_sink_ctf_field_class_array {
102 struct fs_sink_ctf_field_class_array_base base;
106 struct fs_sink_ctf_field_class_sequence {
107 struct fs_sink_ctf_field_class_array_base base;
109 bool length_is_before;
113 fs_sink_ctf_field_class_bit_array *fs_sink_ctf_field_class_as_bit_array(
114 fs_sink_ctf_field_class *fc)
116 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY ||
117 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT ||
118 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL ||
119 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT));
121 return (fs_sink_ctf_field_class_bit_array *) fc;
125 fs_sink_ctf_field_class_bool *fs_sink_ctf_field_class_as_bool(
126 fs_sink_ctf_field_class *fc)
128 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL);
130 return (fs_sink_ctf_field_class_bool *) fc;
134 fs_sink_ctf_field_class_int *fs_sink_ctf_field_class_as_int(
135 fs_sink_ctf_field_class *fc)
137 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT);
139 return (fs_sink_ctf_field_class_int *) fc;
143 fs_sink_ctf_field_class_float *fs_sink_ctf_field_class_as_float(
144 fs_sink_ctf_field_class *fc)
146 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT);
148 return (fs_sink_ctf_field_class_float *) fc;
152 fs_sink_ctf_field_class_string *fs_sink_ctf_field_class_as_string(
153 fs_sink_ctf_field_class *fc)
155 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRING);
157 return (fs_sink_ctf_field_class_string *) fc;
161 fs_sink_ctf_field_class_struct *fs_sink_ctf_field_class_as_struct(
162 fs_sink_ctf_field_class *fc)
164 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT);
166 return (fs_sink_ctf_field_class_struct *) fc;
170 fs_sink_ctf_field_class_array_base *fs_sink_ctf_field_class_as_array_base(
171 fs_sink_ctf_field_class *fc)
173 BT_ASSERT_DBG(!fc || (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY ||
174 fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE));
176 return (fs_sink_ctf_field_class_array_base *) fc;
180 fs_sink_ctf_field_class_array *fs_sink_ctf_field_class_as_array(
181 fs_sink_ctf_field_class *fc)
183 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY);
185 return (fs_sink_ctf_field_class_array *) fc;
189 fs_sink_ctf_field_class_sequence *fs_sink_ctf_field_class_as_sequence(
190 fs_sink_ctf_field_class *fc)
192 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE);
194 return (fs_sink_ctf_field_class_sequence *) fc;
198 fs_sink_ctf_field_class_option *fs_sink_ctf_field_class_as_option(
199 fs_sink_ctf_field_class *fc)
201 BT_ASSERT_DBG(!fc || fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION);
203 return (fs_sink_ctf_field_class_option *) fc;
207 fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_as_variant(
208 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 {
219 const bt_event_class *ir_ec;
222 struct fs_sink_ctf_stream_class *sc;
225 struct fs_sink_ctf_field_class *spec_context_fc;
228 struct fs_sink_ctf_field_class *payload_fc;
231 struct fs_sink_ctf_trace;
233 struct fs_sink_ctf_stream_class {
235 struct fs_sink_ctf_trace *trace;
238 const bt_stream_class *ir_sc;
241 const bt_clock_class *default_clock_class;
243 GString *default_clock_class_name;
245 bool packets_have_ts_begin;
246 bool packets_have_ts_end;
247 bool has_discarded_events;
248 bool discarded_events_has_ts;
249 bool discarded_packets_has_ts;
252 struct fs_sink_ctf_field_class *packet_context_fc;
255 struct fs_sink_ctf_field_class *event_common_context_fc;
257 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
258 GPtrArray *event_classes;
261 * `const bt_event_class *` (weak) ->
262 * `struct fs_sink_ctf_event_class *` (weak)
264 GHashTable *event_classes_from_ir;
267 struct fs_sink_ctf_trace {
269 const bt_trace *ir_trace;
272 const bt_trace_class *ir_tc;
276 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
277 GPtrArray *stream_classes;
281 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc);
284 void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class *fc,
285 enum fs_sink_ctf_field_class_type type,
286 const bt_field_class *ir_fc, unsigned int alignment,
287 uint64_t index_in_parent)
292 fc->alignment = alignment;
293 fc->index_in_parent = index_in_parent;
297 void _fs_sink_ctf_field_class_bit_array_init(
298 struct fs_sink_ctf_field_class_bit_array *fc,
299 enum fs_sink_ctf_field_class_type type,
300 const bt_field_class *ir_fc, unsigned int size,
301 uint64_t index_in_parent)
303 _fs_sink_ctf_field_class_init(&fc->base, type, ir_fc,
304 size % 8 == 0 ? 8 : 1, index_in_parent);
309 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, 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(&fc->base, type, ir_fc,
316 (unsigned int) bt_field_class_integer_get_field_value_range(
319 fc->is_signed = bt_field_class_type_is(ir_fc_type,
320 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
324 void _fs_sink_ctf_named_field_class_init(
325 struct fs_sink_ctf_named_field_class *named_fc)
328 named_fc->name = g_string_new(NULL);
329 BT_ASSERT(named_fc->name);
333 void _fs_sink_ctf_named_field_class_fini(
334 struct fs_sink_ctf_named_field_class *named_fc)
338 if (named_fc->name) {
339 g_string_free(named_fc->name, TRUE);
340 named_fc->name = NULL;
343 fs_sink_ctf_field_class_destroy(named_fc->fc);
348 struct fs_sink_ctf_field_class_bit_array *
349 fs_sink_ctf_field_class_bit_array_create(
350 const bt_field_class *ir_fc, uint64_t index_in_parent)
352 struct fs_sink_ctf_field_class_bit_array *fc =
353 g_new0(struct fs_sink_ctf_field_class_bit_array, 1);
356 _fs_sink_ctf_field_class_bit_array_init(fc,
357 FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc,
358 (unsigned int) bt_field_class_bit_array_get_length(ir_fc),
364 struct fs_sink_ctf_field_class_bool *fs_sink_ctf_field_class_bool_create(
365 const bt_field_class *ir_fc, uint64_t index_in_parent)
367 struct fs_sink_ctf_field_class_bool *fc =
368 g_new0(struct fs_sink_ctf_field_class_bool, 1);
373 * CTF 1.8 has no boolean field class type, so this component
374 * translates it to an 8-bit unsigned integer field class.
376 _fs_sink_ctf_field_class_bit_array_init(&fc->base,
377 FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc,
383 struct fs_sink_ctf_field_class_int *fs_sink_ctf_field_class_int_create(
384 const bt_field_class *ir_fc, uint64_t index_in_parent)
386 struct fs_sink_ctf_field_class_int *fc =
387 g_new0(struct fs_sink_ctf_field_class_int, 1);
390 _fs_sink_ctf_field_class_int_init(fc, FS_SINK_CTF_FIELD_CLASS_TYPE_INT,
391 ir_fc, index_in_parent);
396 struct fs_sink_ctf_field_class_float *fs_sink_ctf_field_class_float_create(
397 const bt_field_class *ir_fc, uint64_t index_in_parent)
399 struct fs_sink_ctf_field_class_float *fc =
400 g_new0(struct fs_sink_ctf_field_class_float, 1);
403 _fs_sink_ctf_field_class_bit_array_init(&fc->base,
404 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
406 bt_field_class_get_type(ir_fc) ==
407 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
413 struct fs_sink_ctf_field_class_string *fs_sink_ctf_field_class_string_create(
414 const bt_field_class *ir_fc, uint64_t index_in_parent)
416 struct fs_sink_ctf_field_class_string *fc =
417 g_new0(struct fs_sink_ctf_field_class_string, 1);
420 _fs_sink_ctf_field_class_init(&fc->base,
421 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, ir_fc,
427 struct fs_sink_ctf_field_class_struct *fs_sink_ctf_field_class_struct_create_empty(
428 const bt_field_class *ir_fc, uint64_t index_in_parent)
430 struct fs_sink_ctf_field_class_struct *fc =
431 g_new0(struct fs_sink_ctf_field_class_struct, 1);
434 _fs_sink_ctf_field_class_init(&fc->base,
435 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, ir_fc, 1, index_in_parent);
436 fc->members = g_array_new(FALSE, TRUE,
437 sizeof(struct fs_sink_ctf_named_field_class));
438 BT_ASSERT(fc->members);
443 struct fs_sink_ctf_field_class_option *fs_sink_ctf_field_class_option_create_empty(
444 const bt_field_class *ir_fc, uint64_t index_in_parent)
446 struct fs_sink_ctf_field_class_option *fc =
447 g_new0(struct fs_sink_ctf_field_class_option, 1);
450 _fs_sink_ctf_field_class_init(&fc->base,
451 FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc,
453 fc->tag_ref = g_string_new(NULL);
454 BT_ASSERT(fc->tag_ref);
459 struct fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_variant_create_empty(
460 const bt_field_class *ir_fc, uint64_t index_in_parent)
462 struct fs_sink_ctf_field_class_variant *fc =
463 g_new0(struct fs_sink_ctf_field_class_variant, 1);
466 _fs_sink_ctf_field_class_init(&fc->base,
467 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, ir_fc,
469 fc->options = g_array_new(FALSE, TRUE,
470 sizeof(struct fs_sink_ctf_named_field_class));
471 BT_ASSERT(fc->options);
472 fc->tag_ref = g_string_new(NULL);
473 BT_ASSERT(fc->tag_ref);
475 bt_field_class_get_type(fc->base.ir_fc) ==
476 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD;
481 struct fs_sink_ctf_field_class_array *fs_sink_ctf_field_class_array_create_empty(
482 const bt_field_class *ir_fc, uint64_t index_in_parent)
484 struct fs_sink_ctf_field_class_array *fc =
485 g_new0(struct fs_sink_ctf_field_class_array, 1);
488 _fs_sink_ctf_field_class_init(&fc->base.base,
489 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc,
491 fc->length = bt_field_class_array_static_get_length(ir_fc);
496 struct fs_sink_ctf_field_class_sequence *fs_sink_ctf_field_class_sequence_create_empty(
497 const bt_field_class *ir_fc, uint64_t index_in_parent)
499 struct fs_sink_ctf_field_class_sequence *fc =
500 g_new0(struct fs_sink_ctf_field_class_sequence, 1);
503 _fs_sink_ctf_field_class_init(&fc->base.base,
504 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE,
505 ir_fc, 1, index_in_parent);
506 fc->length_ref = g_string_new(NULL);
507 BT_ASSERT(fc->length_ref);
508 fc->length_is_before =
509 bt_field_class_get_type(ir_fc) ==
510 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD;
515 struct fs_sink_ctf_named_field_class *
516 fs_sink_ctf_field_class_struct_borrow_member_by_index(
517 struct fs_sink_ctf_field_class_struct *fc, uint64_t index);
520 struct fs_sink_ctf_named_field_class *
521 fs_sink_ctf_field_class_variant_borrow_option_by_index(
522 struct fs_sink_ctf_field_class_variant *fc, uint64_t index);
525 void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc)
531 void _fs_sink_ctf_field_class_bit_array_destroy(
532 struct fs_sink_ctf_field_class_bit_array *fc)
535 _fs_sink_ctf_field_class_fini(&fc->base);
540 void _fs_sink_ctf_field_class_bool_destroy(
541 struct fs_sink_ctf_field_class_bool *fc)
544 _fs_sink_ctf_field_class_fini(&fc->base.base);
549 void _fs_sink_ctf_field_class_int_destroy(
550 struct fs_sink_ctf_field_class_int *fc)
553 _fs_sink_ctf_field_class_fini(&fc->base.base);
558 void _fs_sink_ctf_field_class_float_destroy(
559 struct fs_sink_ctf_field_class_float *fc)
562 _fs_sink_ctf_field_class_fini(&fc->base.base);
567 void _fs_sink_ctf_field_class_string_destroy(
568 struct fs_sink_ctf_field_class_string *fc)
571 _fs_sink_ctf_field_class_fini(&fc->base);
576 void _fs_sink_ctf_field_class_struct_destroy(
577 struct fs_sink_ctf_field_class_struct *fc)
580 _fs_sink_ctf_field_class_fini(&fc->base);
585 for (i = 0; i < fc->members->len; i++) {
586 struct fs_sink_ctf_named_field_class *named_fc =
587 fs_sink_ctf_field_class_struct_borrow_member_by_index(
590 _fs_sink_ctf_named_field_class_fini(named_fc);
593 g_array_free(fc->members, TRUE);
601 void _fs_sink_ctf_field_class_array_base_fini(
602 struct fs_sink_ctf_field_class_array_base *fc)
605 _fs_sink_ctf_field_class_fini(&fc->base);
606 fs_sink_ctf_field_class_destroy(fc->elem_fc);
611 void _fs_sink_ctf_field_class_array_destroy(
612 struct fs_sink_ctf_field_class_array *fc)
615 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
620 void _fs_sink_ctf_field_class_sequence_destroy(
621 struct fs_sink_ctf_field_class_sequence *fc)
624 _fs_sink_ctf_field_class_array_base_fini(&fc->base);
626 if (fc->length_ref) {
627 g_string_free(fc->length_ref, TRUE);
628 fc->length_ref = NULL;
635 void _fs_sink_ctf_field_class_option_destroy(
636 struct fs_sink_ctf_field_class_option *fc)
639 _fs_sink_ctf_field_class_fini(&fc->base);
640 fs_sink_ctf_field_class_destroy(fc->content_fc);
643 g_string_free(fc->tag_ref, TRUE);
651 void _fs_sink_ctf_field_class_variant_destroy(
652 struct fs_sink_ctf_field_class_variant *fc)
655 _fs_sink_ctf_field_class_fini(&fc->base);
660 for (i = 0; i < fc->options->len; i++) {
661 struct fs_sink_ctf_named_field_class *named_fc =
662 fs_sink_ctf_field_class_variant_borrow_option_by_index(
665 _fs_sink_ctf_named_field_class_fini(named_fc);
668 g_array_free(fc->options, TRUE);
673 g_string_free(fc->tag_ref, TRUE);
681 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
688 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL:
689 _fs_sink_ctf_field_class_bool_destroy(fs_sink_ctf_field_class_as_bool(fc));
691 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY:
692 _fs_sink_ctf_field_class_bit_array_destroy(fs_sink_ctf_field_class_as_bit_array(fc));
694 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT:
695 _fs_sink_ctf_field_class_int_destroy(fs_sink_ctf_field_class_as_int(fc));
697 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT:
698 _fs_sink_ctf_field_class_float_destroy(fs_sink_ctf_field_class_as_float(fc));
700 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING:
701 _fs_sink_ctf_field_class_string_destroy(fs_sink_ctf_field_class_as_string(fc));
703 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
704 _fs_sink_ctf_field_class_struct_destroy(fs_sink_ctf_field_class_as_struct(fc));
706 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
707 _fs_sink_ctf_field_class_array_destroy(fs_sink_ctf_field_class_as_array(fc));
709 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
710 _fs_sink_ctf_field_class_sequence_destroy(fs_sink_ctf_field_class_as_sequence(fc));
712 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION:
713 _fs_sink_ctf_field_class_option_destroy(fs_sink_ctf_field_class_as_option(fc));
715 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
716 _fs_sink_ctf_field_class_variant_destroy(fs_sink_ctf_field_class_as_variant(fc));
724 struct fs_sink_ctf_named_field_class *
725 fs_sink_ctf_field_class_struct_borrow_member_by_index(
726 struct fs_sink_ctf_field_class_struct *fc, uint64_t index)
729 BT_ASSERT_DBG(index < fc->members->len);
730 return &g_array_index(fc->members, struct fs_sink_ctf_named_field_class,
735 struct fs_sink_ctf_named_field_class *
736 fs_sink_ctf_field_class_struct_borrow_member_by_name(
737 struct fs_sink_ctf_field_class_struct *fc, const char *name)
740 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
745 for (i = 0; i < fc->members->len; i++) {
746 struct fs_sink_ctf_named_field_class *named_fc =
747 fs_sink_ctf_field_class_struct_borrow_member_by_index(
750 if (strcmp(name, named_fc->name->str) == 0) {
751 ret_named_fc = named_fc;
761 struct fs_sink_ctf_field_class *
762 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
763 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
765 struct fs_sink_ctf_named_field_class *named_fc = NULL;
766 struct fs_sink_ctf_field_class *fc = NULL;
772 named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_name(
785 struct fs_sink_ctf_field_class_int *
786 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
787 struct fs_sink_ctf_field_class_struct *struct_fc,
790 struct fs_sink_ctf_field_class_int *int_fc = NULL;
792 int_fc = fs_sink_ctf_field_class_as_int(
793 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
799 if (int_fc->base.base.type != FS_SINK_CTF_FIELD_CLASS_TYPE_INT) {
809 void fs_sink_ctf_field_class_struct_align_at_least(
810 struct fs_sink_ctf_field_class_struct *fc,
811 unsigned int alignment)
813 if (alignment > fc->base.alignment) {
814 fc->base.alignment = alignment;
819 void fs_sink_ctf_field_class_struct_append_member(
820 struct fs_sink_ctf_field_class_struct *fc,
821 const char *name, struct fs_sink_ctf_field_class *member_fc)
823 struct fs_sink_ctf_named_field_class *named_fc;
827 g_array_set_size(fc->members, fc->members->len + 1);
829 named_fc = &g_array_index(fc->members,
830 struct fs_sink_ctf_named_field_class, fc->members->len - 1);
831 _fs_sink_ctf_named_field_class_init(named_fc);
832 g_string_assign(named_fc->name, name);
833 named_fc->fc = member_fc;
834 fs_sink_ctf_field_class_struct_align_at_least(fc, member_fc->alignment);
838 struct fs_sink_ctf_named_field_class *
839 fs_sink_ctf_field_class_variant_borrow_option_by_index(
840 struct fs_sink_ctf_field_class_variant *fc, uint64_t index)
843 BT_ASSERT_DBG(index < fc->options->len);
844 return &g_array_index(fc->options, struct fs_sink_ctf_named_field_class,
849 struct fs_sink_ctf_named_field_class *
850 fs_sink_ctf_field_class_variant_borrow_option_by_name(
851 struct fs_sink_ctf_field_class_variant *fc, const char *name)
854 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
859 for (i = 0; i < fc->options->len; i++) {
860 struct fs_sink_ctf_named_field_class *named_fc =
861 fs_sink_ctf_field_class_variant_borrow_option_by_index(
864 if (strcmp(name, named_fc->name->str) == 0) {
865 ret_named_fc = named_fc;
875 void fs_sink_ctf_field_class_variant_append_option(
876 struct fs_sink_ctf_field_class_variant *fc,
877 const char *name, struct fs_sink_ctf_field_class *option_fc)
879 struct fs_sink_ctf_named_field_class *named_fc;
883 g_array_set_size(fc->options, fc->options->len + 1);
885 named_fc = &g_array_index(fc->options,
886 struct fs_sink_ctf_named_field_class, fc->options->len - 1);
887 _fs_sink_ctf_named_field_class_init(named_fc);
888 g_string_assign(named_fc->name, name);
889 named_fc->fc = option_fc;
893 struct fs_sink_ctf_event_class *fs_sink_ctf_event_class_create(
894 struct fs_sink_ctf_stream_class *sc,
895 const bt_event_class *ir_ec)
897 struct fs_sink_ctf_event_class *ec =
898 g_new0(struct fs_sink_ctf_event_class, 1);
905 g_ptr_array_add(sc->event_classes, ec);
906 g_hash_table_insert(sc->event_classes_from_ir, (gpointer) ir_ec, ec);
911 void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec)
917 fs_sink_ctf_field_class_destroy(ec->spec_context_fc);
918 ec->spec_context_fc = NULL;
919 fs_sink_ctf_field_class_destroy(ec->payload_fc);
920 ec->payload_fc = NULL;
925 struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create(
926 struct fs_sink_ctf_trace *trace,
927 const bt_stream_class *ir_sc)
929 struct fs_sink_ctf_stream_class *sc =
930 g_new0(struct fs_sink_ctf_stream_class, 1);
937 sc->default_clock_class =
938 bt_stream_class_borrow_default_clock_class_const(ir_sc);
939 sc->default_clock_class_name = g_string_new(NULL);
940 BT_ASSERT(sc->default_clock_class_name);
941 sc->event_classes = g_ptr_array_new_with_free_func(
942 (GDestroyNotify) fs_sink_ctf_event_class_destroy);
943 BT_ASSERT(sc->event_classes);
944 sc->event_classes_from_ir = g_hash_table_new(g_direct_hash,
946 BT_ASSERT(sc->event_classes_from_ir);
947 sc->has_packets = bt_stream_class_supports_packets(ir_sc);
948 sc->packets_have_ts_begin =
949 bt_stream_class_packets_have_beginning_default_clock_snapshot(
951 sc->packets_have_ts_end =
952 bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
953 sc->has_discarded_events =
954 bt_stream_class_supports_discarded_events(ir_sc);
956 if (sc->has_discarded_events) {
957 sc->discarded_events_has_ts =
958 bt_stream_class_discarded_events_have_default_clock_snapshots(
962 if (bt_stream_class_supports_discarded_packets(ir_sc)) {
963 sc->discarded_packets_has_ts =
964 bt_stream_class_discarded_packets_have_default_clock_snapshots(
968 g_ptr_array_add(trace->stream_classes, sc);
973 void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class *sc)
979 if (sc->default_clock_class_name) {
980 g_string_free(sc->default_clock_class_name, TRUE);
981 sc->default_clock_class_name = NULL;
984 if (sc->event_classes) {
985 g_ptr_array_free(sc->event_classes, TRUE);
986 sc->event_classes = NULL;
989 if (sc->event_classes_from_ir) {
990 g_hash_table_destroy(sc->event_classes_from_ir);
991 sc->event_classes_from_ir = NULL;
994 fs_sink_ctf_field_class_destroy(sc->packet_context_fc);
995 sc->packet_context_fc = NULL;
996 fs_sink_ctf_field_class_destroy(sc->event_common_context_fc);
997 sc->event_common_context_fc = NULL;
1002 void fs_sink_ctf_stream_class_append_event_class(
1003 struct fs_sink_ctf_stream_class *sc,
1004 struct fs_sink_ctf_event_class *ec)
1006 g_ptr_array_add(sc->event_classes, ec);
1010 void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace)
1016 if (trace->stream_classes) {
1017 g_ptr_array_free(trace->stream_classes, TRUE);
1018 trace->stream_classes = NULL;
1025 struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
1027 struct fs_sink_ctf_trace *trace =
1028 g_new0(struct fs_sink_ctf_trace, 1);
1032 bt_uuid_generate(trace->uuid);
1034 trace->ir_trace = ir_trace;
1035 trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
1036 trace->stream_classes = g_ptr_array_new_with_free_func(
1037 (GDestroyNotify) fs_sink_ctf_stream_class_destroy);
1038 BT_ASSERT(trace->stream_classes);
1043 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */