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 "common/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
;
125 struct fs_sink_ctf_stream_class
{
127 struct fs_sink_ctf_trace
*trace
;
130 const bt_stream_class
*ir_sc
;
133 const bt_clock_class
*default_clock_class
;
135 GString
*default_clock_class_name
;
137 bool packets_have_ts_begin
;
138 bool packets_have_ts_end
;
139 bool has_discarded_events
;
140 bool discarded_events_has_ts
;
141 bool discarded_packets_has_ts
;
144 struct fs_sink_ctf_field_class
*packet_context_fc
;
147 struct fs_sink_ctf_field_class
*event_common_context_fc
;
149 /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */
150 GPtrArray
*event_classes
;
153 * `const bt_event_class *` (weak) ->
154 * `struct fs_sink_ctf_event_class *` (weak)
156 GHashTable
*event_classes_from_ir
;
159 struct fs_sink_ctf_trace
{
161 const bt_trace
*ir_trace
;
164 const bt_trace_class
*ir_tc
;
168 /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
169 GPtrArray
*stream_classes
;
173 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class
*fc
);
176 void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class
*fc
,
177 enum fs_sink_ctf_field_class_type type
,
178 const bt_field_class
*ir_fc
, unsigned int alignment
,
179 uint64_t index_in_parent
)
184 fc
->alignment
= alignment
;
185 fc
->index_in_parent
= index_in_parent
;
189 void _fs_sink_ctf_field_class_bit_array_init(
190 struct fs_sink_ctf_field_class_bit_array
*fc
,
191 enum fs_sink_ctf_field_class_type type
,
192 const bt_field_class
*ir_fc
, unsigned int size
,
193 uint64_t index_in_parent
)
195 _fs_sink_ctf_field_class_init((void *) fc
, type
, ir_fc
,
196 size
% 8 == 0 ? 8 : 1, index_in_parent
);
201 void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int
*fc
,
202 enum fs_sink_ctf_field_class_type type
,
203 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
205 bt_field_class_type ir_fc_type
= bt_field_class_get_type(ir_fc
);
207 _fs_sink_ctf_field_class_bit_array_init((void *) fc
, type
, ir_fc
,
208 (unsigned int) bt_field_class_integer_get_field_value_range(
211 fc
->is_signed
= (ir_fc_type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
212 ir_fc_type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
216 void _fs_sink_ctf_named_field_class_init(
217 struct fs_sink_ctf_named_field_class
*named_fc
)
220 named_fc
->name
= g_string_new(NULL
);
221 BT_ASSERT(named_fc
->name
);
225 void _fs_sink_ctf_named_field_class_fini(
226 struct fs_sink_ctf_named_field_class
*named_fc
)
230 if (named_fc
->name
) {
231 g_string_free(named_fc
->name
, TRUE
);
232 named_fc
->name
= NULL
;
235 fs_sink_ctf_field_class_destroy(named_fc
->fc
);
240 struct fs_sink_ctf_field_class_int
*fs_sink_ctf_field_class_int_create(
241 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
243 struct fs_sink_ctf_field_class_int
*fc
=
244 g_new0(struct fs_sink_ctf_field_class_int
, 1);
247 _fs_sink_ctf_field_class_int_init(fc
, FS_SINK_CTF_FIELD_CLASS_TYPE_INT
,
248 ir_fc
, index_in_parent
);
253 struct fs_sink_ctf_field_class_float
*fs_sink_ctf_field_class_float_create(
254 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
256 struct fs_sink_ctf_field_class_float
*fc
=
257 g_new0(struct fs_sink_ctf_field_class_float
, 1);
260 _fs_sink_ctf_field_class_bit_array_init((void *) fc
,
261 FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
,
262 ir_fc
, bt_field_class_real_is_single_precision(ir_fc
) ? 32 : 64,
268 struct fs_sink_ctf_field_class_string
*fs_sink_ctf_field_class_string_create(
269 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
271 struct fs_sink_ctf_field_class_string
*fc
=
272 g_new0(struct fs_sink_ctf_field_class_string
, 1);
275 _fs_sink_ctf_field_class_init((void *) fc
,
276 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
, ir_fc
,
282 struct fs_sink_ctf_field_class_struct
*fs_sink_ctf_field_class_struct_create_empty(
283 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
285 struct fs_sink_ctf_field_class_struct
*fc
=
286 g_new0(struct fs_sink_ctf_field_class_struct
, 1);
289 _fs_sink_ctf_field_class_init((void *) fc
,
290 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
, ir_fc
, 1, index_in_parent
);
291 fc
->members
= g_array_new(FALSE
, TRUE
,
292 sizeof(struct fs_sink_ctf_named_field_class
));
293 BT_ASSERT(fc
->members
);
298 struct fs_sink_ctf_field_class_variant
*fs_sink_ctf_field_class_variant_create_empty(
299 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
301 struct fs_sink_ctf_field_class_variant
*fc
=
302 g_new0(struct fs_sink_ctf_field_class_variant
, 1);
305 _fs_sink_ctf_field_class_init((void *) fc
,
306 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
, ir_fc
,
308 fc
->options
= g_array_new(FALSE
, TRUE
,
309 sizeof(struct fs_sink_ctf_named_field_class
));
310 BT_ASSERT(fc
->options
);
311 fc
->tag_ref
= g_string_new(NULL
);
312 BT_ASSERT(fc
->tag_ref
);
314 bt_field_class_variant_borrow_selector_field_path_const(ir_fc
) ==
320 struct fs_sink_ctf_field_class_array
*fs_sink_ctf_field_class_array_create_empty(
321 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
323 struct fs_sink_ctf_field_class_array
*fc
=
324 g_new0(struct fs_sink_ctf_field_class_array
, 1);
327 _fs_sink_ctf_field_class_init((void *) fc
,
328 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
, ir_fc
,
330 fc
->length
= bt_field_class_static_array_get_length(ir_fc
);
335 struct fs_sink_ctf_field_class_sequence
*fs_sink_ctf_field_class_sequence_create_empty(
336 const bt_field_class
*ir_fc
, uint64_t index_in_parent
)
338 struct fs_sink_ctf_field_class_sequence
*fc
=
339 g_new0(struct fs_sink_ctf_field_class_sequence
, 1);
342 _fs_sink_ctf_field_class_init((void *) fc
,
343 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
,
344 ir_fc
, 1, index_in_parent
);
345 fc
->length_ref
= g_string_new(NULL
);
346 BT_ASSERT(fc
->length_ref
);
347 fc
->length_is_before
=
348 bt_field_class_dynamic_array_borrow_length_field_path_const(ir_fc
) ==
354 struct fs_sink_ctf_named_field_class
*
355 fs_sink_ctf_field_class_struct_borrow_member_by_index(
356 struct fs_sink_ctf_field_class_struct
*fc
, uint64_t index
);
359 struct fs_sink_ctf_named_field_class
*
360 fs_sink_ctf_field_class_variant_borrow_option_by_index(
361 struct fs_sink_ctf_field_class_variant
*fc
, uint64_t index
);
364 void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class
*fc
)
370 void _fs_sink_ctf_field_class_int_destroy(
371 struct fs_sink_ctf_field_class_int
*fc
)
374 _fs_sink_ctf_field_class_fini((void *) fc
);
379 void _fs_sink_ctf_field_class_float_destroy(
380 struct fs_sink_ctf_field_class_float
*fc
)
383 _fs_sink_ctf_field_class_fini((void *) fc
);
388 void _fs_sink_ctf_field_class_string_destroy(
389 struct fs_sink_ctf_field_class_string
*fc
)
392 _fs_sink_ctf_field_class_fini((void *) fc
);
397 void _fs_sink_ctf_field_class_struct_destroy(
398 struct fs_sink_ctf_field_class_struct
*fc
)
401 _fs_sink_ctf_field_class_fini((void *) fc
);
406 for (i
= 0; i
< fc
->members
->len
; i
++) {
407 struct fs_sink_ctf_named_field_class
*named_fc
=
408 fs_sink_ctf_field_class_struct_borrow_member_by_index(
411 _fs_sink_ctf_named_field_class_fini(named_fc
);
414 g_array_free(fc
->members
, TRUE
);
422 void _fs_sink_ctf_field_class_array_base_fini(
423 struct fs_sink_ctf_field_class_array_base
*fc
)
426 _fs_sink_ctf_field_class_fini((void *) fc
);
427 fs_sink_ctf_field_class_destroy(fc
->elem_fc
);
432 void _fs_sink_ctf_field_class_array_destroy(
433 struct fs_sink_ctf_field_class_array
*fc
)
436 _fs_sink_ctf_field_class_array_base_fini((void *) fc
);
441 void _fs_sink_ctf_field_class_sequence_destroy(
442 struct fs_sink_ctf_field_class_sequence
*fc
)
445 _fs_sink_ctf_field_class_array_base_fini((void *) fc
);
447 if (fc
->length_ref
) {
448 g_string_free(fc
->length_ref
, TRUE
);
449 fc
->length_ref
= NULL
;
456 void _fs_sink_ctf_field_class_variant_destroy(
457 struct fs_sink_ctf_field_class_variant
*fc
)
460 _fs_sink_ctf_field_class_fini((void *) fc
);
465 for (i
= 0; i
< fc
->options
->len
; i
++) {
466 struct fs_sink_ctf_named_field_class
*named_fc
=
467 fs_sink_ctf_field_class_variant_borrow_option_by_index(
470 _fs_sink_ctf_named_field_class_fini(named_fc
);
473 g_array_free(fc
->options
, TRUE
);
478 g_string_free(fc
->tag_ref
, TRUE
);
486 void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class
*fc
)
493 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
494 _fs_sink_ctf_field_class_int_destroy((void *) fc
);
496 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
497 _fs_sink_ctf_field_class_float_destroy((void *) fc
);
499 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
500 _fs_sink_ctf_field_class_string_destroy((void *) fc
);
502 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
503 _fs_sink_ctf_field_class_struct_destroy((void *) fc
);
505 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
506 _fs_sink_ctf_field_class_array_destroy((void *) fc
);
508 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
509 _fs_sink_ctf_field_class_sequence_destroy((void *) fc
);
511 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
512 _fs_sink_ctf_field_class_variant_destroy((void *) fc
);
520 struct fs_sink_ctf_named_field_class
*
521 fs_sink_ctf_field_class_struct_borrow_member_by_index(
522 struct fs_sink_ctf_field_class_struct
*fc
, uint64_t index
)
525 BT_ASSERT(index
< fc
->members
->len
);
526 return &g_array_index(fc
->members
, struct fs_sink_ctf_named_field_class
,
531 struct fs_sink_ctf_named_field_class
*
532 fs_sink_ctf_field_class_struct_borrow_member_by_name(
533 struct fs_sink_ctf_field_class_struct
*fc
, const char *name
)
536 struct fs_sink_ctf_named_field_class
*ret_named_fc
= NULL
;
541 for (i
= 0; i
< fc
->members
->len
; i
++) {
542 struct fs_sink_ctf_named_field_class
*named_fc
=
543 fs_sink_ctf_field_class_struct_borrow_member_by_index(
546 if (strcmp(name
, named_fc
->name
->str
) == 0) {
547 ret_named_fc
= named_fc
;
557 struct fs_sink_ctf_field_class
*
558 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
559 struct fs_sink_ctf_field_class_struct
*struct_fc
, const char *name
)
561 struct fs_sink_ctf_named_field_class
*named_fc
= NULL
;
562 struct fs_sink_ctf_field_class
*fc
= NULL
;
568 named_fc
= fs_sink_ctf_field_class_struct_borrow_member_by_name(
581 struct fs_sink_ctf_field_class_int
*
582 fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
583 struct fs_sink_ctf_field_class_struct
*struct_fc
,
586 struct fs_sink_ctf_field_class_int
*int_fc
= NULL
;
589 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
595 if (int_fc
->base
.base
.type
!= FS_SINK_CTF_FIELD_CLASS_TYPE_INT
) {
605 void fs_sink_ctf_field_class_struct_align_at_least(
606 struct fs_sink_ctf_field_class_struct
*fc
,
607 unsigned int alignment
)
609 if (alignment
> fc
->base
.alignment
) {
610 fc
->base
.alignment
= alignment
;
615 void fs_sink_ctf_field_class_struct_append_member(
616 struct fs_sink_ctf_field_class_struct
*fc
,
617 const char *name
, struct fs_sink_ctf_field_class
*member_fc
)
619 struct fs_sink_ctf_named_field_class
*named_fc
;
623 g_array_set_size(fc
->members
, fc
->members
->len
+ 1);
625 named_fc
= &g_array_index(fc
->members
,
626 struct fs_sink_ctf_named_field_class
, fc
->members
->len
- 1);
627 _fs_sink_ctf_named_field_class_init(named_fc
);
628 g_string_assign(named_fc
->name
, name
);
629 named_fc
->fc
= member_fc
;
630 fs_sink_ctf_field_class_struct_align_at_least(fc
, member_fc
->alignment
);
634 struct fs_sink_ctf_named_field_class
*
635 fs_sink_ctf_field_class_variant_borrow_option_by_index(
636 struct fs_sink_ctf_field_class_variant
*fc
, uint64_t index
)
639 BT_ASSERT(index
< fc
->options
->len
);
640 return &g_array_index(fc
->options
, struct fs_sink_ctf_named_field_class
,
645 struct fs_sink_ctf_named_field_class
*
646 fs_sink_ctf_field_class_variant_borrow_option_by_name(
647 struct fs_sink_ctf_field_class_variant
*fc
, const char *name
)
650 struct fs_sink_ctf_named_field_class
*ret_named_fc
= NULL
;
655 for (i
= 0; i
< fc
->options
->len
; i
++) {
656 struct fs_sink_ctf_named_field_class
*named_fc
=
657 fs_sink_ctf_field_class_variant_borrow_option_by_index(
660 if (strcmp(name
, named_fc
->name
->str
) == 0) {
661 ret_named_fc
= named_fc
;
671 void fs_sink_ctf_field_class_variant_append_option(
672 struct fs_sink_ctf_field_class_variant
*fc
,
673 const char *name
, struct fs_sink_ctf_field_class
*option_fc
)
675 struct fs_sink_ctf_named_field_class
*named_fc
;
679 g_array_set_size(fc
->options
, fc
->options
->len
+ 1);
681 named_fc
= &g_array_index(fc
->options
,
682 struct fs_sink_ctf_named_field_class
, fc
->options
->len
- 1);
683 _fs_sink_ctf_named_field_class_init(named_fc
);
684 g_string_assign(named_fc
->name
, name
);
685 named_fc
->fc
= option_fc
;
689 struct fs_sink_ctf_event_class
*fs_sink_ctf_event_class_create(
690 struct fs_sink_ctf_stream_class
*sc
,
691 const bt_event_class
*ir_ec
)
693 struct fs_sink_ctf_event_class
*ec
=
694 g_new0(struct fs_sink_ctf_event_class
, 1);
701 g_ptr_array_add(sc
->event_classes
, ec
);
702 g_hash_table_insert(sc
->event_classes_from_ir
, (gpointer
) ir_ec
, ec
);
707 void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class
*ec
)
713 fs_sink_ctf_field_class_destroy(ec
->spec_context_fc
);
714 ec
->spec_context_fc
= NULL
;
715 fs_sink_ctf_field_class_destroy(ec
->payload_fc
);
716 ec
->payload_fc
= NULL
;
721 struct fs_sink_ctf_stream_class
*fs_sink_ctf_stream_class_create(
722 struct fs_sink_ctf_trace
*trace
,
723 const bt_stream_class
*ir_sc
)
725 struct fs_sink_ctf_stream_class
*sc
=
726 g_new0(struct fs_sink_ctf_stream_class
, 1);
733 sc
->default_clock_class
=
734 bt_stream_class_borrow_default_clock_class_const(ir_sc
);
735 sc
->default_clock_class_name
= g_string_new(NULL
);
736 BT_ASSERT(sc
->default_clock_class_name
);
737 sc
->event_classes
= g_ptr_array_new_with_free_func(
738 (GDestroyNotify
) fs_sink_ctf_event_class_destroy
);
739 BT_ASSERT(sc
->event_classes
);
740 sc
->event_classes_from_ir
= g_hash_table_new(g_direct_hash
,
742 BT_ASSERT(sc
->event_classes_from_ir
);
743 sc
->has_packets
= bt_stream_class_supports_packets(ir_sc
);
744 sc
->packets_have_ts_begin
=
745 bt_stream_class_packets_have_beginning_default_clock_snapshot(
747 sc
->packets_have_ts_end
=
748 bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc
);
749 sc
->has_discarded_events
=
750 bt_stream_class_supports_discarded_events(ir_sc
);
752 if (sc
->has_discarded_events
) {
753 sc
->discarded_events_has_ts
=
754 bt_stream_class_discarded_events_have_default_clock_snapshots(
758 if (bt_stream_class_supports_discarded_packets(ir_sc
)) {
759 sc
->discarded_packets_has_ts
=
760 bt_stream_class_discarded_packets_have_default_clock_snapshots(
764 g_ptr_array_add(trace
->stream_classes
, sc
);
769 void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class
*sc
)
775 if (sc
->default_clock_class_name
) {
776 g_string_free(sc
->default_clock_class_name
, TRUE
);
777 sc
->default_clock_class_name
= NULL
;
780 if (sc
->event_classes
) {
781 g_ptr_array_free(sc
->event_classes
, TRUE
);
782 sc
->event_classes
= NULL
;
785 if (sc
->event_classes_from_ir
) {
786 g_hash_table_destroy(sc
->event_classes_from_ir
);
787 sc
->event_classes_from_ir
= NULL
;
790 fs_sink_ctf_field_class_destroy(sc
->packet_context_fc
);
791 sc
->packet_context_fc
= NULL
;
792 fs_sink_ctf_field_class_destroy(sc
->event_common_context_fc
);
793 sc
->event_common_context_fc
= NULL
;
798 void fs_sink_ctf_stream_class_append_event_class(
799 struct fs_sink_ctf_stream_class
*sc
,
800 struct fs_sink_ctf_event_class
*ec
)
802 g_ptr_array_add(sc
->event_classes
, ec
);
806 void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace
*trace
)
812 if (trace
->stream_classes
) {
813 g_ptr_array_free(trace
->stream_classes
, TRUE
);
814 trace
->stream_classes
= NULL
;
821 struct fs_sink_ctf_trace
*fs_sink_ctf_trace_create(const bt_trace
*ir_trace
)
823 struct fs_sink_ctf_trace
*trace
=
824 g_new0(struct fs_sink_ctf_trace
, 1);
828 bt_uuid_generate(trace
->uuid
);
830 trace
->ir_trace
= ir_trace
;
831 trace
->ir_tc
= bt_trace_borrow_class_const(ir_trace
);
832 trace
->stream_classes
= g_ptr_array_new_with_free_func(
833 (GDestroyNotify
) fs_sink_ctf_stream_class_destroy
);
834 BT_ASSERT(trace
->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 */