1 #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H
2 #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H
5 * Copyright 2018-2019 - Philippe Proulx <pproulx@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
18 #include <babeltrace2/babeltrace.h>
19 #include "common/common.h"
20 #include "common/assert.h"
21 #include "compat/uuid.h"
28 enum fs_sink_ctf_field_class_type
{
29 FS_SINK_CTF_FIELD_CLASS_TYPE_INT
,
30 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
,
31 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
,
32 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
,
33 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
,
34 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
,
35 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
,
38 struct fs_sink_ctf_field_class
{
39 enum fs_sink_ctf_field_class_type type
;
42 const bt_field_class
*ir_fc
;
44 unsigned int alignment
;
46 /* Index of the field class within its own parent */
47 uint64_t index_in_parent
;
50 struct fs_sink_ctf_field_class_bit_array
{
51 struct fs_sink_ctf_field_class base
;
55 struct fs_sink_ctf_field_class_int
{
56 struct fs_sink_ctf_field_class_bit_array base
;
60 struct fs_sink_ctf_field_class_float
{
61 struct fs_sink_ctf_field_class_bit_array base
;
64 struct fs_sink_ctf_field_class_string
{
65 struct fs_sink_ctf_field_class base
;
68 struct fs_sink_ctf_named_field_class
{
72 struct fs_sink_ctf_field_class
*fc
;
75 struct fs_sink_ctf_field_class_struct
{
76 struct fs_sink_ctf_field_class base
;
78 /* Array of `struct fs_sink_ctf_named_field_class` */
82 struct fs_sink_ctf_field_class_variant
{
83 struct fs_sink_ctf_field_class base
;
87 /* Array of `struct fs_sink_ctf_named_field_class` */
91 struct fs_sink_ctf_field_class_array_base
{
92 struct fs_sink_ctf_field_class base
;
93 struct fs_sink_ctf_field_class
*elem_fc
;
96 struct fs_sink_ctf_field_class_array
{
97 struct fs_sink_ctf_field_class_array_base base
;
101 struct fs_sink_ctf_field_class_sequence
{
102 struct fs_sink_ctf_field_class_array_base base
;
104 bool length_is_before
;
107 struct fs_sink_ctf_stream_class
;
109 struct fs_sink_ctf_event_class
{
111 const bt_event_class
*ir_ec
;
114 struct fs_sink_ctf_stream_class
*sc
;
117 struct fs_sink_ctf_field_class
*spec_context_fc
;
120 struct fs_sink_ctf_field_class
*payload_fc
;
123 struct fs_sink_ctf_trace_class
;
125 struct fs_sink_ctf_stream_class
{
127 struct fs_sink_ctf_trace_class
*tc
;
130 const bt_stream_class
*ir_sc
;
133 const bt_clock_class
*default_clock_class
;
135 GString
*default_clock_class_name
;
136 bool packets_have_ts_begin
;
137 bool packets_have_ts_end
;
138 bool has_discarded_events
;
139 bool discarded_events_has_ts
;
140 bool discarded_packets_has_ts
;
143 struct fs_sink_ctf_field_class
*packet_context_fc
;
146 struct fs_sink_ctf_field_class
*event_common_context_fc
;
148 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
149 GPtrArray
*event_classes
;
152 * `const bt_event_class *` (weak) ->
153 * `struct fs_sink_ctf_event_class *` (weak)
155 GHashTable
*event_classes_from_ir
;
158 struct fs_sink_ctf_trace_class
{
160 const bt_trace_class
*ir_tc
;
162 unsigned char uuid
[BABELTRACE_UUID_LEN
];
164 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
165 GPtrArray
*stream_classes
;
169 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class
*fc
);
172 void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class
*fc
,
173 enum fs_sink_ctf_field_class_type type
,
174 const bt_field_class
*ir_fc
, unsigned int alignment
,
175 uint64_t index_in_parent
)
180 fc
->alignment
= alignment
;
181 fc
->index_in_parent
= index_in_parent
;
185 void _fs_sink_ctf_field_class_bit_array_init(
186 struct fs_sink_ctf_field_class_bit_array
*fc
,
187 enum fs_sink_ctf_field_class_type type
,
188 const bt_field_class
*ir_fc
, unsigned int size
,
189 uint64_t index_in_parent
)
191 _fs_sink_ctf_field_class_init((void *) fc
, type
, ir_fc
,
192 size
% 8 == 0 ? 8 : 1, index_in_parent
);
197 void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int
*fc
,
198 enum fs_sink_ctf_field_class_type type
,
199 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
201 bt_field_class_type ir_fc_type
= bt_field_class_get_type(ir_fc
);
203 _fs_sink_ctf_field_class_bit_array_init((void *) fc
, type
, ir_fc
,
204 (unsigned int) bt_field_class_integer_get_field_value_range(
207 fc
->is_signed
= (ir_fc_type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
208 ir_fc_type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
212 void _fs_sink_ctf_named_field_class_init(
213 struct fs_sink_ctf_named_field_class
*named_fc
)
216 named_fc
->name
= g_string_new(NULL
);
217 BT_ASSERT(named_fc
->name
);
221 void _fs_sink_ctf_named_field_class_fini(
222 struct fs_sink_ctf_named_field_class
*named_fc
)
226 if (named_fc
->name
) {
227 g_string_free(named_fc
->name
, TRUE
);
228 named_fc
->name
= NULL
;
231 fs_sink_ctf_field_class_destroy(named_fc
->fc
);
236 struct fs_sink_ctf_field_class_int
*fs_sink_ctf_field_class_int_create(
237 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
239 struct fs_sink_ctf_field_class_int
*fc
=
240 g_new0(struct fs_sink_ctf_field_class_int
, 1);
243 _fs_sink_ctf_field_class_int_init(fc
, FS_SINK_CTF_FIELD_CLASS_TYPE_INT
,
244 ir_fc
, index_in_parent
);
249 struct fs_sink_ctf_field_class_float
*fs_sink_ctf_field_class_float_create(
250 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
252 struct fs_sink_ctf_field_class_float
*fc
=
253 g_new0(struct fs_sink_ctf_field_class_float
, 1);
256 _fs_sink_ctf_field_class_bit_array_init((void *) fc
,
257 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
,
258 ir_fc
, bt_field_class_real_is_single_precision(ir_fc
) ? 32 : 64,
264 struct fs_sink_ctf_field_class_string
*fs_sink_ctf_field_class_string_create(
265 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
267 struct fs_sink_ctf_field_class_string
*fc
=
268 g_new0(struct fs_sink_ctf_field_class_string
, 1);
271 _fs_sink_ctf_field_class_init((void *) fc
,
272 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
, ir_fc
,
278 struct fs_sink_ctf_field_class_struct
*fs_sink_ctf_field_class_struct_create_empty(
279 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
281 struct fs_sink_ctf_field_class_struct
*fc
=
282 g_new0(struct fs_sink_ctf_field_class_struct
, 1);
285 _fs_sink_ctf_field_class_init((void *) fc
,
286 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
, ir_fc
, 1, index_in_parent
);
287 fc
->members
= g_array_new(FALSE
, TRUE
,
288 sizeof(struct fs_sink_ctf_named_field_class
));
289 BT_ASSERT(fc
->members
);
294 struct fs_sink_ctf_field_class_variant
*fs_sink_ctf_field_class_variant_create_empty(
295 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
297 struct fs_sink_ctf_field_class_variant
*fc
=
298 g_new0(struct fs_sink_ctf_field_class_variant
, 1);
301 _fs_sink_ctf_field_class_init((void *) fc
,
302 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
, ir_fc
,
304 fc
->options
= g_array_new(FALSE
, TRUE
,
305 sizeof(struct fs_sink_ctf_named_field_class
));
306 BT_ASSERT(fc
->options
);
307 fc
->tag_ref
= g_string_new(NULL
);
308 BT_ASSERT(fc
->tag_ref
);
310 bt_field_class_variant_borrow_selector_field_path_const(ir_fc
) ==
316 struct fs_sink_ctf_field_class_array
*fs_sink_ctf_field_class_array_create_empty(
317 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
319 struct fs_sink_ctf_field_class_array
*fc
=
320 g_new0(struct fs_sink_ctf_field_class_array
, 1);
323 _fs_sink_ctf_field_class_init((void *) fc
,
324 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
, ir_fc
,
326 fc
->length
= bt_field_class_static_array_get_length(ir_fc
);
331 struct fs_sink_ctf_field_class_sequence
*fs_sink_ctf_field_class_sequence_create_empty(
332 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
334 struct fs_sink_ctf_field_class_sequence
*fc
=
335 g_new0(struct fs_sink_ctf_field_class_sequence
, 1);
338 _fs_sink_ctf_field_class_init((void *) fc
,
339 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
,
340 ir_fc
, 1, index_in_parent
);
341 fc
->length_ref
= g_string_new(NULL
);
342 BT_ASSERT(fc
->length_ref
);
343 fc
->length_is_before
=
344 bt_field_class_dynamic_array_borrow_length_field_path_const(ir_fc
) ==
350 struct fs_sink_ctf_named_field_class
*
351 fs_sink_ctf_field_class_struct_borrow_member_by_index(
352 struct fs_sink_ctf_field_class_struct
*fc
, uint64_t index
);
355 struct fs_sink_ctf_named_field_class
*
356 fs_sink_ctf_field_class_variant_borrow_option_by_index(
357 struct fs_sink_ctf_field_class_variant
*fc
, uint64_t index
);
360 void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class
*fc
)
366 void _fs_sink_ctf_field_class_int_destroy(
367 struct fs_sink_ctf_field_class_int
*fc
)
370 _fs_sink_ctf_field_class_fini((void *) fc
);
375 void _fs_sink_ctf_field_class_float_destroy(
376 struct fs_sink_ctf_field_class_float
*fc
)
379 _fs_sink_ctf_field_class_fini((void *) fc
);
384 void _fs_sink_ctf_field_class_string_destroy(
385 struct fs_sink_ctf_field_class_string
*fc
)
388 _fs_sink_ctf_field_class_fini((void *) fc
);
393 void _fs_sink_ctf_field_class_struct_destroy(
394 struct fs_sink_ctf_field_class_struct
*fc
)
397 _fs_sink_ctf_field_class_fini((void *) fc
);
402 for (i
= 0; i
< fc
->members
->len
; i
++) {
403 struct fs_sink_ctf_named_field_class
*named_fc
=
404 fs_sink_ctf_field_class_struct_borrow_member_by_index(
407 _fs_sink_ctf_named_field_class_fini(named_fc
);
410 g_array_free(fc
->members
, TRUE
);
418 void _fs_sink_ctf_field_class_array_base_fini(
419 struct fs_sink_ctf_field_class_array_base
*fc
)
422 _fs_sink_ctf_field_class_fini((void *) fc
);
423 fs_sink_ctf_field_class_destroy(fc
->elem_fc
);
428 void _fs_sink_ctf_field_class_array_destroy(
429 struct fs_sink_ctf_field_class_array
*fc
)
432 _fs_sink_ctf_field_class_array_base_fini((void *) fc
);
437 void _fs_sink_ctf_field_class_sequence_destroy(
438 struct fs_sink_ctf_field_class_sequence
*fc
)
441 _fs_sink_ctf_field_class_array_base_fini((void *) fc
);
443 if (fc
->length_ref
) {
444 g_string_free(fc
->length_ref
, TRUE
);
445 fc
->length_ref
= NULL
;
452 void _fs_sink_ctf_field_class_variant_destroy(
453 struct fs_sink_ctf_field_class_variant
*fc
)
456 _fs_sink_ctf_field_class_fini((void *) fc
);
461 for (i
= 0; i
< fc
->options
->len
; i
++) {
462 struct fs_sink_ctf_named_field_class
*named_fc
=
463 fs_sink_ctf_field_class_variant_borrow_option_by_index(
466 _fs_sink_ctf_named_field_class_fini(named_fc
);
469 g_array_free(fc
->options
, TRUE
);
474 g_string_free(fc
->tag_ref
, TRUE
);
482 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class
*fc
)
489 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
490 _fs_sink_ctf_field_class_int_destroy((void *) fc
);
492 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
493 _fs_sink_ctf_field_class_float_destroy((void *) fc
);
495 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
496 _fs_sink_ctf_field_class_string_destroy((void *) fc
);
498 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
499 _fs_sink_ctf_field_class_struct_destroy((void *) fc
);
501 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
502 _fs_sink_ctf_field_class_array_destroy((void *) fc
);
504 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
505 _fs_sink_ctf_field_class_sequence_destroy((void *) fc
);
507 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
508 _fs_sink_ctf_field_class_variant_destroy((void *) fc
);
516 struct fs_sink_ctf_named_field_class
*
517 fs_sink_ctf_field_class_struct_borrow_member_by_index(
518 struct fs_sink_ctf_field_class_struct
*fc
, uint64_t index
)
521 BT_ASSERT(index
< fc
->members
->len
);
522 return &g_array_index(fc
->members
, struct fs_sink_ctf_named_field_class
,
527 struct fs_sink_ctf_named_field_class
*
528 fs_sink_ctf_field_class_struct_borrow_member_by_name(
529 struct fs_sink_ctf_field_class_struct
*fc
, const char *name
)
532 struct fs_sink_ctf_named_field_class
*ret_named_fc
= NULL
;
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(
542 if (strcmp(name
, named_fc
->name
->str
) == 0) {
543 ret_named_fc
= named_fc
;
553 struct fs_sink_ctf_field_class
*
554 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
555 struct fs_sink_ctf_field_class_struct
*struct_fc
, const char *name
)
557 struct fs_sink_ctf_named_field_class
*named_fc
= NULL
;
558 struct fs_sink_ctf_field_class
*fc
= NULL
;
564 named_fc
= fs_sink_ctf_field_class_struct_borrow_member_by_name(
577 struct fs_sink_ctf_field_class_int
*
578 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
579 struct fs_sink_ctf_field_class_struct
*struct_fc
,
582 struct fs_sink_ctf_field_class_int
*int_fc
= NULL
;
585 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
591 if (int_fc
->base
.base
.type
!= FS_SINK_CTF_FIELD_CLASS_TYPE_INT
) {
601 void fs_sink_ctf_field_class_struct_align_at_least(
602 struct fs_sink_ctf_field_class_struct
*fc
,
603 unsigned int alignment
)
605 if (alignment
> fc
->base
.alignment
) {
606 fc
->base
.alignment
= alignment
;
611 void fs_sink_ctf_field_class_struct_append_member(
612 struct fs_sink_ctf_field_class_struct
*fc
,
613 const char *name
, struct fs_sink_ctf_field_class
*member_fc
)
615 struct fs_sink_ctf_named_field_class
*named_fc
;
619 g_array_set_size(fc
->members
, fc
->members
->len
+ 1);
621 named_fc
= &g_array_index(fc
->members
,
622 struct fs_sink_ctf_named_field_class
, fc
->members
->len
- 1);
623 _fs_sink_ctf_named_field_class_init(named_fc
);
624 g_string_assign(named_fc
->name
, name
);
625 named_fc
->fc
= member_fc
;
626 fs_sink_ctf_field_class_struct_align_at_least(fc
, member_fc
->alignment
);
630 struct fs_sink_ctf_named_field_class
*
631 fs_sink_ctf_field_class_variant_borrow_option_by_index(
632 struct fs_sink_ctf_field_class_variant
*fc
, uint64_t index
)
635 BT_ASSERT(index
< fc
->options
->len
);
636 return &g_array_index(fc
->options
, struct fs_sink_ctf_named_field_class
,
641 struct fs_sink_ctf_named_field_class
*
642 fs_sink_ctf_field_class_variant_borrow_option_by_name(
643 struct fs_sink_ctf_field_class_variant
*fc
, const char *name
)
646 struct fs_sink_ctf_named_field_class
*ret_named_fc
= NULL
;
651 for (i
= 0; i
< fc
->options
->len
; i
++) {
652 struct fs_sink_ctf_named_field_class
*named_fc
=
653 fs_sink_ctf_field_class_variant_borrow_option_by_index(
656 if (strcmp(name
, named_fc
->name
->str
) == 0) {
657 ret_named_fc
= named_fc
;
667 void fs_sink_ctf_field_class_variant_append_option(
668 struct fs_sink_ctf_field_class_variant
*fc
,
669 const char *name
, struct fs_sink_ctf_field_class
*option_fc
)
671 struct fs_sink_ctf_named_field_class
*named_fc
;
675 g_array_set_size(fc
->options
, fc
->options
->len
+ 1);
677 named_fc
= &g_array_index(fc
->options
,
678 struct fs_sink_ctf_named_field_class
, fc
->options
->len
- 1);
679 _fs_sink_ctf_named_field_class_init(named_fc
);
680 g_string_assign(named_fc
->name
, name
);
681 named_fc
->fc
= option_fc
;
685 struct fs_sink_ctf_event_class
*fs_sink_ctf_event_class_create(
686 struct fs_sink_ctf_stream_class
*sc
,
687 const bt_event_class
*ir_ec
)
689 struct fs_sink_ctf_event_class
*ec
=
690 g_new0(struct fs_sink_ctf_event_class
, 1);
697 g_ptr_array_add(sc
->event_classes
, ec
);
698 g_hash_table_insert(sc
->event_classes_from_ir
, (gpointer
) ir_ec
, ec
);
703 void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class
*ec
)
709 fs_sink_ctf_field_class_destroy(ec
->spec_context_fc
);
710 ec
->spec_context_fc
= NULL
;
711 fs_sink_ctf_field_class_destroy(ec
->payload_fc
);
712 ec
->payload_fc
= NULL
;
717 struct fs_sink_ctf_stream_class
*fs_sink_ctf_stream_class_create(
718 struct fs_sink_ctf_trace_class
*tc
,
719 const bt_stream_class
*ir_sc
)
721 struct fs_sink_ctf_stream_class
*sc
=
722 g_new0(struct fs_sink_ctf_stream_class
, 1);
729 sc
->default_clock_class
=
730 bt_stream_class_borrow_default_clock_class_const(ir_sc
);
731 sc
->default_clock_class_name
= g_string_new(NULL
);
732 BT_ASSERT(sc
->default_clock_class_name
);
733 sc
->event_classes
= g_ptr_array_new_with_free_func(
734 (GDestroyNotify
) fs_sink_ctf_event_class_destroy
);
735 BT_ASSERT(sc
->event_classes
);
736 sc
->event_classes_from_ir
= g_hash_table_new(g_direct_hash
,
738 BT_ASSERT(sc
->event_classes_from_ir
);
739 sc
->packets_have_ts_begin
=
740 bt_stream_class_packets_have_beginning_default_clock_snapshot(
742 sc
->packets_have_ts_end
=
743 bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc
);
744 sc
->has_discarded_events
=
745 bt_stream_class_supports_discarded_events(ir_sc
);
747 if (sc
->has_discarded_events
) {
748 sc
->discarded_events_has_ts
=
749 bt_stream_class_discarded_events_have_default_clock_snapshots(
753 if (bt_stream_class_supports_discarded_packets(ir_sc
)) {
754 sc
->discarded_packets_has_ts
=
755 bt_stream_class_discarded_packets_have_default_clock_snapshots(
759 g_ptr_array_add(tc
->stream_classes
, sc
);
764 void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class
*sc
)
770 if (sc
->default_clock_class_name
) {
771 g_string_free(sc
->default_clock_class_name
, TRUE
);
772 sc
->default_clock_class_name
= NULL
;
775 if (sc
->event_classes
) {
776 g_ptr_array_free(sc
->event_classes
, TRUE
);
777 sc
->event_classes
= NULL
;
780 if (sc
->event_classes_from_ir
) {
781 g_hash_table_destroy(sc
->event_classes_from_ir
);
782 sc
->event_classes_from_ir
= NULL
;
785 fs_sink_ctf_field_class_destroy(sc
->packet_context_fc
);
786 sc
->packet_context_fc
= NULL
;
787 fs_sink_ctf_field_class_destroy(sc
->event_common_context_fc
);
788 sc
->event_common_context_fc
= NULL
;
793 void fs_sink_ctf_stream_class_append_event_class(
794 struct fs_sink_ctf_stream_class
*sc
,
795 struct fs_sink_ctf_event_class
*ec
)
797 g_ptr_array_add(sc
->event_classes
, ec
);
801 void fs_sink_ctf_trace_class_destroy(struct fs_sink_ctf_trace_class
*tc
)
807 if (tc
->stream_classes
) {
808 g_ptr_array_free(tc
->stream_classes
, TRUE
);
809 tc
->stream_classes
= NULL
;
816 struct fs_sink_ctf_trace_class
*fs_sink_ctf_trace_class_create(
817 const bt_trace_class
*ir_tc
)
819 struct fs_sink_ctf_trace_class
*tc
=
820 g_new0(struct fs_sink_ctf_trace_class
, 1);
824 if (bt_uuid_generate(tc
->uuid
)) {
825 fs_sink_ctf_trace_class_destroy(tc
);
831 tc
->stream_classes
= g_ptr_array_new_with_free_func(
832 (GDestroyNotify
) fs_sink_ctf_stream_class_destroy
);
833 BT_ASSERT(tc
->stream_classes
);
840 bool fs_sink_ctf_ist_valid_identifier(const char *name
)
844 bool ist_valid
= true;
845 static const char *reserved_keywords
[] = {
876 /* Make sure the name is not a reserved keyword */
877 for (i
= 0; i
< sizeof(reserved_keywords
) / sizeof(*reserved_keywords
);
879 if (strcmp(name
, reserved_keywords
[i
]) == 0) {
885 /* Make sure the name is not an empty string */
886 if (strlen(name
) == 0) {
891 /* Make sure the name starts with a letter or `_` */
892 if (!isalpha(name
[0]) && name
[0] != '_') {
897 /* Make sure the name only contains letters, digits, and `_` */
898 for (at
= name
; *at
!= '\0'; at
++) {
899 if (!isalnum(*at
) && *at
!= '_') {
910 int fs_sink_ctf_protect_name(GString
*name
)
914 if (!fs_sink_ctf_ist_valid_identifier(name
->str
)) {
919 /* Prepend `_` to protect it */
920 g_string_prepend_c(name
, '_');
926 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */