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
;
112 struct fs_sink_ctf_stream_class
;
114 struct fs_sink_ctf_event_class
{
116 const bt_event_class
*ir_ec
;
119 struct fs_sink_ctf_stream_class
*sc
;
122 struct fs_sink_ctf_field_class
*spec_context_fc
;
125 struct fs_sink_ctf_field_class
*payload_fc
;
128 struct fs_sink_ctf_trace
;
130 struct fs_sink_ctf_stream_class
{
132 struct fs_sink_ctf_trace
*trace
;
135 const bt_stream_class
*ir_sc
;
138 const bt_clock_class
*default_clock_class
;
140 GString
*default_clock_class_name
;
142 bool packets_have_ts_begin
;
143 bool packets_have_ts_end
;
144 bool has_discarded_events
;
145 bool discarded_events_has_ts
;
146 bool discarded_packets_has_ts
;
149 struct fs_sink_ctf_field_class
*packet_context_fc
;
152 struct fs_sink_ctf_field_class
*event_common_context_fc
;
154 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
155 GPtrArray
*event_classes
;
158 * `const bt_event_class *` (weak) ->
159 * `struct fs_sink_ctf_event_class *` (weak)
161 GHashTable
*event_classes_from_ir
;
164 struct fs_sink_ctf_trace
{
166 const bt_trace
*ir_trace
;
169 const bt_trace_class
*ir_tc
;
173 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
174 GPtrArray
*stream_classes
;
178 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class
*fc
);
181 void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class
*fc
,
182 enum fs_sink_ctf_field_class_type type
,
183 const bt_field_class
*ir_fc
, unsigned int alignment
,
184 uint64_t index_in_parent
)
189 fc
->alignment
= alignment
;
190 fc
->index_in_parent
= index_in_parent
;
194 void _fs_sink_ctf_field_class_bit_array_init(
195 struct fs_sink_ctf_field_class_bit_array
*fc
,
196 enum fs_sink_ctf_field_class_type type
,
197 const bt_field_class
*ir_fc
, unsigned int size
,
198 uint64_t index_in_parent
)
200 _fs_sink_ctf_field_class_init((void *) fc
, type
, ir_fc
,
201 size
% 8 == 0 ? 8 : 1, index_in_parent
);
206 void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int
*fc
,
207 enum fs_sink_ctf_field_class_type type
,
208 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
210 bt_field_class_type ir_fc_type
= bt_field_class_get_type(ir_fc
);
212 _fs_sink_ctf_field_class_bit_array_init((void *) fc
, type
, ir_fc
,
213 (unsigned int) bt_field_class_integer_get_field_value_range(
216 fc
->is_signed
= bt_field_class_type_is(ir_fc_type
,
217 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
221 void _fs_sink_ctf_named_field_class_init(
222 struct fs_sink_ctf_named_field_class
*named_fc
)
225 named_fc
->name
= g_string_new(NULL
);
226 BT_ASSERT(named_fc
->name
);
230 void _fs_sink_ctf_named_field_class_fini(
231 struct fs_sink_ctf_named_field_class
*named_fc
)
235 if (named_fc
->name
) {
236 g_string_free(named_fc
->name
, TRUE
);
237 named_fc
->name
= NULL
;
240 fs_sink_ctf_field_class_destroy(named_fc
->fc
);
245 struct fs_sink_ctf_field_class_bit_array
*
246 fs_sink_ctf_field_class_bit_array_create(
247 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
249 struct fs_sink_ctf_field_class_bit_array
*fc
=
250 g_new0(struct fs_sink_ctf_field_class_bit_array
, 1);
253 _fs_sink_ctf_field_class_bit_array_init((void *) fc
,
254 FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY
, ir_fc
,
255 (unsigned int) bt_field_class_bit_array_get_length(ir_fc
),
261 struct fs_sink_ctf_field_class_bool
*fs_sink_ctf_field_class_bool_create(
262 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
264 struct fs_sink_ctf_field_class_bool
*fc
=
265 g_new0(struct fs_sink_ctf_field_class_bool
, 1);
270 * CTF 1.8 has no boolean field class type, so this component
271 * translates it to an 8-bit unsigned integer field class.
273 _fs_sink_ctf_field_class_bit_array_init((void *) fc
,
274 FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
, ir_fc
,
280 struct fs_sink_ctf_field_class_int
*fs_sink_ctf_field_class_int_create(
281 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
283 struct fs_sink_ctf_field_class_int
*fc
=
284 g_new0(struct fs_sink_ctf_field_class_int
, 1);
287 _fs_sink_ctf_field_class_int_init(fc
, FS_SINK_CTF_FIELD_CLASS_TYPE_INT
,
288 ir_fc
, index_in_parent
);
293 struct fs_sink_ctf_field_class_float
*fs_sink_ctf_field_class_float_create(
294 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
296 struct fs_sink_ctf_field_class_float
*fc
=
297 g_new0(struct fs_sink_ctf_field_class_float
, 1);
300 _fs_sink_ctf_field_class_bit_array_init((void *) fc
,
301 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
,
303 bt_field_class_get_type(ir_fc
) ==
304 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
? 32 : 64,
310 struct fs_sink_ctf_field_class_string
*fs_sink_ctf_field_class_string_create(
311 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
313 struct fs_sink_ctf_field_class_string
*fc
=
314 g_new0(struct fs_sink_ctf_field_class_string
, 1);
317 _fs_sink_ctf_field_class_init((void *) fc
,
318 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
, ir_fc
,
324 struct fs_sink_ctf_field_class_struct
*fs_sink_ctf_field_class_struct_create_empty(
325 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
327 struct fs_sink_ctf_field_class_struct
*fc
=
328 g_new0(struct fs_sink_ctf_field_class_struct
, 1);
331 _fs_sink_ctf_field_class_init((void *) fc
,
332 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
, ir_fc
, 1, index_in_parent
);
333 fc
->members
= g_array_new(FALSE
, TRUE
,
334 sizeof(struct fs_sink_ctf_named_field_class
));
335 BT_ASSERT(fc
->members
);
340 struct fs_sink_ctf_field_class_option
*fs_sink_ctf_field_class_option_create_empty(
341 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
343 struct fs_sink_ctf_field_class_option
*fc
=
344 g_new0(struct fs_sink_ctf_field_class_option
, 1);
347 _fs_sink_ctf_field_class_init((void *) fc
,
348 FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
, ir_fc
,
350 fc
->tag_ref
= g_string_new(NULL
);
351 BT_ASSERT(fc
->tag_ref
);
356 struct fs_sink_ctf_field_class_variant
*fs_sink_ctf_field_class_variant_create_empty(
357 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
359 struct fs_sink_ctf_field_class_variant
*fc
=
360 g_new0(struct fs_sink_ctf_field_class_variant
, 1);
363 _fs_sink_ctf_field_class_init((void *) fc
,
364 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
, ir_fc
,
366 fc
->options
= g_array_new(FALSE
, TRUE
,
367 sizeof(struct fs_sink_ctf_named_field_class
));
368 BT_ASSERT(fc
->options
);
369 fc
->tag_ref
= g_string_new(NULL
);
370 BT_ASSERT(fc
->tag_ref
);
372 bt_field_class_get_type(fc
->base
.ir_fc
) ==
373 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
;
378 struct fs_sink_ctf_field_class_array
*fs_sink_ctf_field_class_array_create_empty(
379 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
381 struct fs_sink_ctf_field_class_array
*fc
=
382 g_new0(struct fs_sink_ctf_field_class_array
, 1);
385 _fs_sink_ctf_field_class_init((void *) fc
,
386 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
, ir_fc
,
388 fc
->length
= bt_field_class_array_static_get_length(ir_fc
);
393 struct fs_sink_ctf_field_class_sequence
*fs_sink_ctf_field_class_sequence_create_empty(
394 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
396 struct fs_sink_ctf_field_class_sequence
*fc
=
397 g_new0(struct fs_sink_ctf_field_class_sequence
, 1);
400 _fs_sink_ctf_field_class_init((void *) fc
,
401 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
,
402 ir_fc
, 1, index_in_parent
);
403 fc
->length_ref
= g_string_new(NULL
);
404 BT_ASSERT(fc
->length_ref
);
405 fc
->length_is_before
=
406 bt_field_class_get_type(ir_fc
) ==
407 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
;
412 struct fs_sink_ctf_named_field_class
*
413 fs_sink_ctf_field_class_struct_borrow_member_by_index(
414 struct fs_sink_ctf_field_class_struct
*fc
, uint64_t index
);
417 struct fs_sink_ctf_named_field_class
*
418 fs_sink_ctf_field_class_variant_borrow_option_by_index(
419 struct fs_sink_ctf_field_class_variant
*fc
, uint64_t index
);
422 void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class
*fc
)
428 void _fs_sink_ctf_field_class_bit_array_destroy(
429 struct fs_sink_ctf_field_class_int
*fc
)
432 _fs_sink_ctf_field_class_fini((void *) fc
);
437 void _fs_sink_ctf_field_class_bool_destroy(
438 struct fs_sink_ctf_field_class_int
*fc
)
441 _fs_sink_ctf_field_class_fini((void *) fc
);
446 void _fs_sink_ctf_field_class_int_destroy(
447 struct fs_sink_ctf_field_class_int
*fc
)
450 _fs_sink_ctf_field_class_fini((void *) fc
);
455 void _fs_sink_ctf_field_class_float_destroy(
456 struct fs_sink_ctf_field_class_float
*fc
)
459 _fs_sink_ctf_field_class_fini((void *) fc
);
464 void _fs_sink_ctf_field_class_string_destroy(
465 struct fs_sink_ctf_field_class_string
*fc
)
468 _fs_sink_ctf_field_class_fini((void *) fc
);
473 void _fs_sink_ctf_field_class_struct_destroy(
474 struct fs_sink_ctf_field_class_struct
*fc
)
477 _fs_sink_ctf_field_class_fini((void *) fc
);
482 for (i
= 0; i
< fc
->members
->len
; i
++) {
483 struct fs_sink_ctf_named_field_class
*named_fc
=
484 fs_sink_ctf_field_class_struct_borrow_member_by_index(
487 _fs_sink_ctf_named_field_class_fini(named_fc
);
490 g_array_free(fc
->members
, TRUE
);
498 void _fs_sink_ctf_field_class_array_base_fini(
499 struct fs_sink_ctf_field_class_array_base
*fc
)
502 _fs_sink_ctf_field_class_fini((void *) fc
);
503 fs_sink_ctf_field_class_destroy(fc
->elem_fc
);
508 void _fs_sink_ctf_field_class_array_destroy(
509 struct fs_sink_ctf_field_class_array
*fc
)
512 _fs_sink_ctf_field_class_array_base_fini((void *) fc
);
517 void _fs_sink_ctf_field_class_sequence_destroy(
518 struct fs_sink_ctf_field_class_sequence
*fc
)
521 _fs_sink_ctf_field_class_array_base_fini((void *) fc
);
523 if (fc
->length_ref
) {
524 g_string_free(fc
->length_ref
, TRUE
);
525 fc
->length_ref
= NULL
;
532 void _fs_sink_ctf_field_class_option_destroy(
533 struct fs_sink_ctf_field_class_option
*fc
)
536 _fs_sink_ctf_field_class_fini((void *) fc
);
537 fs_sink_ctf_field_class_destroy(fc
->content_fc
);
540 g_string_free(fc
->tag_ref
, TRUE
);
548 void _fs_sink_ctf_field_class_variant_destroy(
549 struct fs_sink_ctf_field_class_variant
*fc
)
552 _fs_sink_ctf_field_class_fini((void *) fc
);
557 for (i
= 0; i
< fc
->options
->len
; i
++) {
558 struct fs_sink_ctf_named_field_class
*named_fc
=
559 fs_sink_ctf_field_class_variant_borrow_option_by_index(
562 _fs_sink_ctf_named_field_class_fini(named_fc
);
565 g_array_free(fc
->options
, TRUE
);
570 g_string_free(fc
->tag_ref
, TRUE
);
578 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class
*fc
)
585 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
:
586 _fs_sink_ctf_field_class_bool_destroy((void *) fc
);
588 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY
:
589 _fs_sink_ctf_field_class_bit_array_destroy((void *) fc
);
591 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
592 _fs_sink_ctf_field_class_int_destroy((void *) fc
);
594 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
595 _fs_sink_ctf_field_class_float_destroy((void *) fc
);
597 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
598 _fs_sink_ctf_field_class_string_destroy((void *) fc
);
600 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
601 _fs_sink_ctf_field_class_struct_destroy((void *) fc
);
603 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
604 _fs_sink_ctf_field_class_array_destroy((void *) fc
);
606 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
607 _fs_sink_ctf_field_class_sequence_destroy((void *) fc
);
609 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
:
610 _fs_sink_ctf_field_class_option_destroy((void *) fc
);
612 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
613 _fs_sink_ctf_field_class_variant_destroy((void *) fc
);
621 struct fs_sink_ctf_named_field_class
*
622 fs_sink_ctf_field_class_struct_borrow_member_by_index(
623 struct fs_sink_ctf_field_class_struct
*fc
, uint64_t index
)
626 BT_ASSERT_DBG(index
< fc
->members
->len
);
627 return &g_array_index(fc
->members
, struct fs_sink_ctf_named_field_class
,
632 struct fs_sink_ctf_named_field_class
*
633 fs_sink_ctf_field_class_struct_borrow_member_by_name(
634 struct fs_sink_ctf_field_class_struct
*fc
, const char *name
)
637 struct fs_sink_ctf_named_field_class
*ret_named_fc
= NULL
;
642 for (i
= 0; i
< fc
->members
->len
; i
++) {
643 struct fs_sink_ctf_named_field_class
*named_fc
=
644 fs_sink_ctf_field_class_struct_borrow_member_by_index(
647 if (strcmp(name
, named_fc
->name
->str
) == 0) {
648 ret_named_fc
= named_fc
;
658 struct fs_sink_ctf_field_class
*
659 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
660 struct fs_sink_ctf_field_class_struct
*struct_fc
, const char *name
)
662 struct fs_sink_ctf_named_field_class
*named_fc
= NULL
;
663 struct fs_sink_ctf_field_class
*fc
= NULL
;
669 named_fc
= fs_sink_ctf_field_class_struct_borrow_member_by_name(
682 struct fs_sink_ctf_field_class_int
*
683 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
684 struct fs_sink_ctf_field_class_struct
*struct_fc
,
687 struct fs_sink_ctf_field_class_int
*int_fc
= NULL
;
690 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
696 if (int_fc
->base
.base
.type
!= FS_SINK_CTF_FIELD_CLASS_TYPE_INT
) {
706 void fs_sink_ctf_field_class_struct_align_at_least(
707 struct fs_sink_ctf_field_class_struct
*fc
,
708 unsigned int alignment
)
710 if (alignment
> fc
->base
.alignment
) {
711 fc
->base
.alignment
= alignment
;
716 void fs_sink_ctf_field_class_struct_append_member(
717 struct fs_sink_ctf_field_class_struct
*fc
,
718 const char *name
, struct fs_sink_ctf_field_class
*member_fc
)
720 struct fs_sink_ctf_named_field_class
*named_fc
;
724 g_array_set_size(fc
->members
, fc
->members
->len
+ 1);
726 named_fc
= &g_array_index(fc
->members
,
727 struct fs_sink_ctf_named_field_class
, fc
->members
->len
- 1);
728 _fs_sink_ctf_named_field_class_init(named_fc
);
729 g_string_assign(named_fc
->name
, name
);
730 named_fc
->fc
= member_fc
;
731 fs_sink_ctf_field_class_struct_align_at_least(fc
, member_fc
->alignment
);
735 struct fs_sink_ctf_named_field_class
*
736 fs_sink_ctf_field_class_variant_borrow_option_by_index(
737 struct fs_sink_ctf_field_class_variant
*fc
, uint64_t index
)
740 BT_ASSERT_DBG(index
< fc
->options
->len
);
741 return &g_array_index(fc
->options
, struct fs_sink_ctf_named_field_class
,
746 struct fs_sink_ctf_named_field_class
*
747 fs_sink_ctf_field_class_variant_borrow_option_by_name(
748 struct fs_sink_ctf_field_class_variant
*fc
, const char *name
)
751 struct fs_sink_ctf_named_field_class
*ret_named_fc
= NULL
;
756 for (i
= 0; i
< fc
->options
->len
; i
++) {
757 struct fs_sink_ctf_named_field_class
*named_fc
=
758 fs_sink_ctf_field_class_variant_borrow_option_by_index(
761 if (strcmp(name
, named_fc
->name
->str
) == 0) {
762 ret_named_fc
= named_fc
;
772 void fs_sink_ctf_field_class_variant_append_option(
773 struct fs_sink_ctf_field_class_variant
*fc
,
774 const char *name
, struct fs_sink_ctf_field_class
*option_fc
)
776 struct fs_sink_ctf_named_field_class
*named_fc
;
780 g_array_set_size(fc
->options
, fc
->options
->len
+ 1);
782 named_fc
= &g_array_index(fc
->options
,
783 struct fs_sink_ctf_named_field_class
, fc
->options
->len
- 1);
784 _fs_sink_ctf_named_field_class_init(named_fc
);
785 g_string_assign(named_fc
->name
, name
);
786 named_fc
->fc
= option_fc
;
790 struct fs_sink_ctf_event_class
*fs_sink_ctf_event_class_create(
791 struct fs_sink_ctf_stream_class
*sc
,
792 const bt_event_class
*ir_ec
)
794 struct fs_sink_ctf_event_class
*ec
=
795 g_new0(struct fs_sink_ctf_event_class
, 1);
802 g_ptr_array_add(sc
->event_classes
, ec
);
803 g_hash_table_insert(sc
->event_classes_from_ir
, (gpointer
) ir_ec
, ec
);
808 void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class
*ec
)
814 fs_sink_ctf_field_class_destroy(ec
->spec_context_fc
);
815 ec
->spec_context_fc
= NULL
;
816 fs_sink_ctf_field_class_destroy(ec
->payload_fc
);
817 ec
->payload_fc
= NULL
;
822 struct fs_sink_ctf_stream_class
*fs_sink_ctf_stream_class_create(
823 struct fs_sink_ctf_trace
*trace
,
824 const bt_stream_class
*ir_sc
)
826 struct fs_sink_ctf_stream_class
*sc
=
827 g_new0(struct fs_sink_ctf_stream_class
, 1);
834 sc
->default_clock_class
=
835 bt_stream_class_borrow_default_clock_class_const(ir_sc
);
836 sc
->default_clock_class_name
= g_string_new(NULL
);
837 BT_ASSERT(sc
->default_clock_class_name
);
838 sc
->event_classes
= g_ptr_array_new_with_free_func(
839 (GDestroyNotify
) fs_sink_ctf_event_class_destroy
);
840 BT_ASSERT(sc
->event_classes
);
841 sc
->event_classes_from_ir
= g_hash_table_new(g_direct_hash
,
843 BT_ASSERT(sc
->event_classes_from_ir
);
844 sc
->has_packets
= bt_stream_class_supports_packets(ir_sc
);
845 sc
->packets_have_ts_begin
=
846 bt_stream_class_packets_have_beginning_default_clock_snapshot(
848 sc
->packets_have_ts_end
=
849 bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc
);
850 sc
->has_discarded_events
=
851 bt_stream_class_supports_discarded_events(ir_sc
);
853 if (sc
->has_discarded_events
) {
854 sc
->discarded_events_has_ts
=
855 bt_stream_class_discarded_events_have_default_clock_snapshots(
859 if (bt_stream_class_supports_discarded_packets(ir_sc
)) {
860 sc
->discarded_packets_has_ts
=
861 bt_stream_class_discarded_packets_have_default_clock_snapshots(
865 g_ptr_array_add(trace
->stream_classes
, sc
);
870 void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class
*sc
)
876 if (sc
->default_clock_class_name
) {
877 g_string_free(sc
->default_clock_class_name
, TRUE
);
878 sc
->default_clock_class_name
= NULL
;
881 if (sc
->event_classes
) {
882 g_ptr_array_free(sc
->event_classes
, TRUE
);
883 sc
->event_classes
= NULL
;
886 if (sc
->event_classes_from_ir
) {
887 g_hash_table_destroy(sc
->event_classes_from_ir
);
888 sc
->event_classes_from_ir
= NULL
;
891 fs_sink_ctf_field_class_destroy(sc
->packet_context_fc
);
892 sc
->packet_context_fc
= NULL
;
893 fs_sink_ctf_field_class_destroy(sc
->event_common_context_fc
);
894 sc
->event_common_context_fc
= NULL
;
899 void fs_sink_ctf_stream_class_append_event_class(
900 struct fs_sink_ctf_stream_class
*sc
,
901 struct fs_sink_ctf_event_class
*ec
)
903 g_ptr_array_add(sc
->event_classes
, ec
);
907 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
;
922 struct fs_sink_ctf_trace
*fs_sink_ctf_trace_create(const bt_trace
*ir_trace
)
924 struct fs_sink_ctf_trace
*trace
=
925 g_new0(struct fs_sink_ctf_trace
, 1);
929 bt_uuid_generate(trace
->uuid
);
931 trace
->ir_trace
= ir_trace
;
932 trace
->ir_tc
= bt_trace_borrow_class_const(ir_trace
);
933 trace
->stream_classes
= g_ptr_array_new_with_free_func(
934 (GDestroyNotify
) fs_sink_ctf_stream_class_destroy
);
935 BT_ASSERT(trace
->stream_classes
);
940 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */