ctf: compile plugin as C++
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta.hpp
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7#ifndef _CTF_META_H
8#define _CTF_META_H
9
10#include <babeltrace2/babeltrace.h>
11#include "common/common.h"
12#include "common/uuid.h"
13#include "common/assert.h"
14#include <glib.h>
15#include <stdbool.h>
16#include <stdint.h>
17#include <string.h>
18
19enum ctf_field_class_type {
20 CTF_FIELD_CLASS_TYPE_INT,
21 CTF_FIELD_CLASS_TYPE_ENUM,
22 CTF_FIELD_CLASS_TYPE_FLOAT,
23 CTF_FIELD_CLASS_TYPE_STRING,
24 CTF_FIELD_CLASS_TYPE_STRUCT,
25 CTF_FIELD_CLASS_TYPE_ARRAY,
26 CTF_FIELD_CLASS_TYPE_SEQUENCE,
27 CTF_FIELD_CLASS_TYPE_VARIANT,
28};
29
30enum ctf_field_class_meaning {
31 CTF_FIELD_CLASS_MEANING_NONE,
32 CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME,
33 CTF_FIELD_CLASS_MEANING_PACKET_END_TIME,
34 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID,
35 CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID,
36 CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID,
37 CTF_FIELD_CLASS_MEANING_MAGIC,
38 CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT,
39 CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT,
40 CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE,
41 CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE,
42 CTF_FIELD_CLASS_MEANING_UUID,
43};
44
45enum ctf_byte_order {
46 CTF_BYTE_ORDER_UNKNOWN,
47 CTF_BYTE_ORDER_DEFAULT,
48 CTF_BYTE_ORDER_LITTLE,
49 CTF_BYTE_ORDER_BIG,
50};
51
52enum ctf_encoding {
53 CTF_ENCODING_NONE,
54 CTF_ENCODING_UTF8,
55};
56
57enum ctf_scope {
58 CTF_SCOPE_PACKET_UNKNOWN = -1,
59 CTF_SCOPE_PACKET_HEADER = 0,
60 CTF_SCOPE_PACKET_CONTEXT,
61 CTF_SCOPE_EVENT_HEADER,
62 CTF_SCOPE_EVENT_COMMON_CONTEXT,
63 CTF_SCOPE_EVENT_SPECIFIC_CONTEXT,
64 CTF_SCOPE_EVENT_PAYLOAD,
65};
66
67struct ctf_clock_class {
68 GString *name;
69 GString *description;
70 uint64_t frequency;
71 uint64_t precision;
72 int64_t offset_seconds;
73 uint64_t offset_cycles;
74 bt_uuid_t uuid;
75 bool has_uuid;
76 bool is_absolute;
77
78 /* Weak, set during translation */
79 bt_clock_class *ir_cc;
80};
81
82struct ctf_field_class {
83 enum ctf_field_class_type type;
84 unsigned int alignment;
85 bool is_compound;
86 bool in_ir;
87
88 /* Weak, set during translation. NULL if `in_ir` is false below. */
89 bt_field_class *ir_fc;
90};
91
92struct ctf_field_class_bit_array {
93 struct ctf_field_class base;
94 enum ctf_byte_order byte_order;
95 unsigned int size;
96};
97
98struct ctf_field_class_int {
99 struct ctf_field_class_bit_array base;
100 enum ctf_field_class_meaning meaning;
101 bool is_signed;
102 bt_field_class_integer_preferred_display_base disp_base;
103 enum ctf_encoding encoding;
104 int64_t storing_index;
105
106 /* Weak */
107 struct ctf_clock_class *mapped_clock_class;
108};
109
110struct ctf_range {
111 union {
112 uint64_t u;
113 int64_t i;
114 } lower;
115
116 union {
117 uint64_t u;
118 int64_t i;
119 } upper;
120};
121
122struct ctf_field_class_enum_mapping {
123 GString *label;
124
125 /* Array of `struct ctf_range` */
126 GArray *ranges;
127};
128
129struct ctf_field_class_enum {
130 struct ctf_field_class_int base;
131
132 /* Array of `struct ctf_field_class_enum_mapping` */
133 GArray *mappings;
134};
135
136struct ctf_field_class_float {
137 struct ctf_field_class_bit_array base;
138};
139
140struct ctf_field_class_string {
141 struct ctf_field_class base;
142 enum ctf_encoding encoding;
143};
144
145struct ctf_named_field_class {
146 /* Original name which can include a leading `_` */
147 GString *orig_name;
148
149 /* Name as translated to trace IR (leading `_` removed) */
150 GString *name;
151
152 /* Owned by this */
153 struct ctf_field_class *fc;
154};
155
156struct ctf_field_class_struct {
157 struct ctf_field_class base;
158
159 /* Array of `struct ctf_named_field_class` */
160 GArray *members;
161};
162
163struct ctf_field_path {
164 enum ctf_scope root;
165
166 /* Array of `int64_t` */
167 GArray *path;
168};
169
170struct ctf_field_class_variant_range {
171 struct ctf_range range;
172 uint64_t option_index;
173};
174
175struct ctf_field_class_variant {
176 struct ctf_field_class base;
177 GString *tag_ref;
178 struct ctf_field_path tag_path;
179 uint64_t stored_tag_index;
180
181 /* Array of `struct ctf_named_field_class` */
182 GArray *options;
183
184 /* Array of `struct ctf_field_class_variant_range` */
185 GArray *ranges;
186
187 /* Weak */
188 struct ctf_field_class_enum *tag_fc;
189};
190
191struct ctf_field_class_array_base {
192 struct ctf_field_class base;
193 struct ctf_field_class *elem_fc;
194 bool is_text;
195};
196
197struct ctf_field_class_array {
198 struct ctf_field_class_array_base base;
199 enum ctf_field_class_meaning meaning;
200 uint64_t length;
201};
202
203struct ctf_field_class_sequence {
204 struct ctf_field_class_array_base base;
205 GString *length_ref;
206 struct ctf_field_path length_path;
207 uint64_t stored_length_index;
208
209 /* Weak */
210 struct ctf_field_class_int *length_fc;
211};
212
213struct ctf_event_class {
214 GString *name;
215 uint64_t id;
216 GString *emf_uri;
217 bt_event_class_log_level log_level;
218 bool is_translated;
219 bool is_log_level_set;
220
221 /* Owned by this */
222 struct ctf_field_class *spec_context_fc;
223
224 /* Owned by this */
225 struct ctf_field_class *payload_fc;
226
227 /* Weak, set during translation */
228 bt_event_class *ir_ec;
229};
230
231struct ctf_stream_class {
232 uint64_t id;
233 bool is_translated;
234 bool packets_have_ts_begin;
235 bool packets_have_ts_end;
236 bool has_discarded_events;
237 bool has_discarded_packets;
238 bool discarded_events_have_default_cs;
239 bool discarded_packets_have_default_cs;
240
241 /* Owned by this */
242 struct ctf_field_class *packet_context_fc;
243
244 /* Owned by this */
245 struct ctf_field_class *event_header_fc;
246
247 /* Owned by this */
248 struct ctf_field_class *event_common_context_fc;
249
250 /* Array of `struct ctf_event_class *`, owned by this */
251 GPtrArray *event_classes;
252
253 /*
254 * Hash table mapping event class IDs to `struct ctf_event_class *`,
255 * weak.
256 */
257 GHashTable *event_classes_by_id;
258
259 /* Weak */
260 struct ctf_clock_class *default_clock_class;
261
262 /* Weak, set during translation */
263 bt_stream_class *ir_sc;
264};
265
266enum ctf_trace_class_env_entry_type {
267 CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT,
268 CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR,
269};
270
271struct ctf_trace_class_env_entry {
272 enum ctf_trace_class_env_entry_type type;
273 GString *name;
274
275 struct {
276 int64_t i;
277 GString *str;
278 } value;
279};
280
281struct ctf_trace_class {
282 unsigned int major;
283 unsigned int minor;
284 bt_uuid_t uuid;
285 bool is_uuid_set;
286 enum ctf_byte_order default_byte_order;
287
288 /* Owned by this */
289 struct ctf_field_class *packet_header_fc;
290
291 uint64_t stored_value_count;
292
293 /* Array of `struct ctf_clock_class *` (owned by this) */
294 GPtrArray *clock_classes;
295
296 /* Array of `struct ctf_stream_class *` */
297 GPtrArray *stream_classes;
298
299 /* Array of `struct ctf_trace_class_env_entry` */
300 GArray *env_entries;
301
302 bool is_translated;
303
304 /* Weak, set during translation */
305 bt_trace_class *ir_tc;
306
307 struct {
308 bool lttng_crash;
309 bool lttng_event_after_packet;
310 bool barectf_event_before_packet;
311 } quirks;
312};
313
314static inline
315ctf_field_class_bit_array *ctf_field_class_as_bit_array(ctf_field_class *fc)
316{
317 BT_ASSERT_DBG(!fc || (fc->type == CTF_FIELD_CLASS_TYPE_INT ||
318 fc->type == CTF_FIELD_CLASS_TYPE_ENUM ||
319 fc->type == CTF_FIELD_CLASS_TYPE_FLOAT));
320 return (ctf_field_class_bit_array *) fc;
321}
322
323static inline
324ctf_field_class_int *ctf_field_class_as_int(ctf_field_class *fc)
325{
326 BT_ASSERT_DBG(!fc || (fc->type == CTF_FIELD_CLASS_TYPE_INT ||
327 fc->type == CTF_FIELD_CLASS_TYPE_ENUM));
328 return (ctf_field_class_int *) fc;
329}
330
331static inline
332ctf_field_class_enum *ctf_field_class_as_enum(ctf_field_class *fc)
333{
334 BT_ASSERT_DBG(!fc || fc->type == CTF_FIELD_CLASS_TYPE_ENUM);
335 return (ctf_field_class_enum *) fc;
336}
337
338static inline
339ctf_field_class_float *ctf_field_class_as_float(ctf_field_class *fc)
340{
341 BT_ASSERT_DBG(!fc || fc->type == CTF_FIELD_CLASS_TYPE_FLOAT);
342 return (ctf_field_class_float *) fc;
343}
344
345static inline
346ctf_field_class_string *ctf_field_class_as_string(ctf_field_class *fc)
347{
348 BT_ASSERT_DBG(!fc || fc->type == CTF_FIELD_CLASS_TYPE_STRING);
349 return (ctf_field_class_string *) fc;
350}
351
352static inline
353ctf_field_class_struct *ctf_field_class_as_struct(ctf_field_class *fc)
354{
355 BT_ASSERT_DBG(!fc || fc->type == CTF_FIELD_CLASS_TYPE_STRUCT);
356 return (ctf_field_class_struct *) fc;
357}
358
359static inline
360ctf_field_class_array_base *ctf_field_class_as_array_base(ctf_field_class *fc)
361{
362 BT_ASSERT_DBG(!fc || (fc->type == CTF_FIELD_CLASS_TYPE_ARRAY ||
363 fc->type == CTF_FIELD_CLASS_TYPE_SEQUENCE));
364 return (ctf_field_class_array_base *) fc;
365}
366
367static inline
368ctf_field_class_array *ctf_field_class_as_array(ctf_field_class *fc)
369{
370 BT_ASSERT_DBG(!fc || fc->type == CTF_FIELD_CLASS_TYPE_ARRAY);
371 return (ctf_field_class_array *) fc;
372}
373
374static inline
375ctf_field_class_sequence *ctf_field_class_as_sequence(ctf_field_class *fc)
376{
377 BT_ASSERT_DBG(!fc || fc->type == CTF_FIELD_CLASS_TYPE_SEQUENCE);
378 return (ctf_field_class_sequence *) fc;
379}
380
381static inline
382ctf_field_class_variant *ctf_field_class_as_variant(
383 ctf_field_class *fc)
384{
385 BT_ASSERT_DBG(!fc || fc->type == CTF_FIELD_CLASS_TYPE_VARIANT);
386 return (ctf_field_class_variant *) fc;
387}
388
389
390static inline
391void ctf_field_class_destroy(struct ctf_field_class *fc);
392
393static inline
394void _ctf_field_class_init(struct ctf_field_class *fc,
395 enum ctf_field_class_type type, unsigned int alignment)
396{
397 BT_ASSERT(fc);
398 fc->type = type;
399 fc->alignment = alignment;
400 fc->in_ir = false;
401}
402
403static inline
404void _ctf_field_class_bit_array_init(struct ctf_field_class_bit_array *fc,
405 enum ctf_field_class_type type)
406{
407 _ctf_field_class_init(&fc->base, type, 1);
408}
409
410static inline
411void _ctf_field_class_int_init(struct ctf_field_class_int *fc,
412 enum ctf_field_class_type type)
413{
414 _ctf_field_class_bit_array_init(&fc->base, type);
415 fc->meaning = CTF_FIELD_CLASS_MEANING_NONE;
416 fc->storing_index = -1;
417}
418
419static inline
420void ctf_field_path_init(struct ctf_field_path *field_path)
421{
422 BT_ASSERT(field_path);
423 field_path->path = g_array_new(FALSE, TRUE, sizeof(int64_t));
424 BT_ASSERT(field_path->path);
425}
426
427static inline
428void ctf_field_path_fini(struct ctf_field_path *field_path)
429{
430 BT_ASSERT(field_path);
431
432 if (field_path->path) {
433 g_array_free(field_path->path, TRUE);
434 }
435}
436
437static inline
438void _ctf_named_field_class_init(struct ctf_named_field_class *named_fc)
439{
440 BT_ASSERT(named_fc);
441 named_fc->name = g_string_new(NULL);
442 BT_ASSERT(named_fc->name);
443 named_fc->orig_name = g_string_new(NULL);
444 BT_ASSERT(named_fc->orig_name);
445}
446
447static inline
448void _ctf_named_field_class_fini(struct ctf_named_field_class *named_fc)
449{
450 BT_ASSERT(named_fc);
451
452 if (named_fc->name) {
453 g_string_free(named_fc->name, TRUE);
454 }
455
456 if (named_fc->orig_name) {
457 g_string_free(named_fc->orig_name, TRUE);
458 }
459
460 ctf_field_class_destroy(named_fc->fc);
461}
462
463static inline
464void _ctf_field_class_enum_mapping_init(
465 struct ctf_field_class_enum_mapping *mapping)
466{
467 BT_ASSERT(mapping);
468 mapping->label = g_string_new(NULL);
469 BT_ASSERT(mapping->label);
470 mapping->ranges = g_array_new(FALSE, TRUE, sizeof(struct ctf_range));
471 BT_ASSERT(mapping->ranges);
472}
473
474static inline
475void _ctf_field_class_enum_mapping_fini(
476 struct ctf_field_class_enum_mapping *mapping)
477{
478 BT_ASSERT(mapping);
479
480 if (mapping->label) {
481 g_string_free(mapping->label, TRUE);
482 }
483
484 if (mapping->ranges) {
485 g_array_free(mapping->ranges, TRUE);
486 }
487}
488
489static inline
490struct ctf_field_class_int *ctf_field_class_int_create(void)
491{
492 struct ctf_field_class_int *fc = g_new0(struct ctf_field_class_int, 1);
493
494 BT_ASSERT(fc);
495 _ctf_field_class_int_init(fc, CTF_FIELD_CLASS_TYPE_INT);
496 return fc;
497}
498
499static inline
500struct ctf_field_class_float *ctf_field_class_float_create(void)
501{
502 struct ctf_field_class_float *fc =
503 g_new0(struct ctf_field_class_float, 1);
504
505 BT_ASSERT(fc);
506 _ctf_field_class_bit_array_init(&fc->base, CTF_FIELD_CLASS_TYPE_FLOAT);
507 return fc;
508}
509
510static inline
511struct ctf_field_class_string *ctf_field_class_string_create(void)
512{
513 struct ctf_field_class_string *fc =
514 g_new0(struct ctf_field_class_string, 1);
515
516 BT_ASSERT(fc);
517 _ctf_field_class_init(&fc->base, CTF_FIELD_CLASS_TYPE_STRING, 8);
518 return fc;
519}
520
521static inline
522struct ctf_field_class_enum *ctf_field_class_enum_create(void)
523{
524 struct ctf_field_class_enum *fc = g_new0(struct ctf_field_class_enum, 1);
525
526 BT_ASSERT(fc);
527 _ctf_field_class_int_init(&fc->base, CTF_FIELD_CLASS_TYPE_ENUM);
528 fc->mappings = g_array_new(FALSE, TRUE,
529 sizeof(struct ctf_field_class_enum_mapping));
530 BT_ASSERT(fc->mappings);
531 return fc;
532}
533
534static inline
535struct ctf_field_class_struct *ctf_field_class_struct_create(void)
536{
537 struct ctf_field_class_struct *fc =
538 g_new0(struct ctf_field_class_struct, 1);
539
540 BT_ASSERT(fc);
541 _ctf_field_class_init(&fc->base, CTF_FIELD_CLASS_TYPE_STRUCT, 1);
542 fc->members = g_array_new(FALSE, TRUE,
543 sizeof(struct ctf_named_field_class));
544 BT_ASSERT(fc->members);
545 fc->base.is_compound = true;
546 return fc;
547}
548
549static inline
550struct ctf_field_class_variant *ctf_field_class_variant_create(void)
551{
552 struct ctf_field_class_variant *fc =
553 g_new0(struct ctf_field_class_variant, 1);
554
555 BT_ASSERT(fc);
556 _ctf_field_class_init(&fc->base, CTF_FIELD_CLASS_TYPE_VARIANT, 1);
557 fc->options = g_array_new(FALSE, TRUE,
558 sizeof(struct ctf_named_field_class));
559 BT_ASSERT(fc->options);
560 fc->ranges = g_array_new(FALSE, TRUE,
561 sizeof(struct ctf_field_class_variant_range));
562 BT_ASSERT(fc->ranges);
563 fc->tag_ref = g_string_new(NULL);
564 BT_ASSERT(fc->tag_ref);
565 ctf_field_path_init(&fc->tag_path);
566 fc->base.is_compound = true;
567 return fc;
568}
569
570static inline
571struct ctf_field_class_array *ctf_field_class_array_create(void)
572{
573 struct ctf_field_class_array *fc =
574 g_new0(struct ctf_field_class_array, 1);
575
576 BT_ASSERT(fc);
577 _ctf_field_class_init(&fc->base.base, CTF_FIELD_CLASS_TYPE_ARRAY, 1);
578 fc->base.base.is_compound = true;
579 return fc;
580}
581
582static inline
583struct ctf_field_class_sequence *ctf_field_class_sequence_create(void)
584{
585 struct ctf_field_class_sequence *fc =
586 g_new0(struct ctf_field_class_sequence, 1);
587
588 BT_ASSERT(fc);
589 _ctf_field_class_init(&fc->base.base, CTF_FIELD_CLASS_TYPE_SEQUENCE, 1);
590 fc->length_ref = g_string_new(NULL);
591 BT_ASSERT(fc->length_ref);
592 ctf_field_path_init(&fc->length_path);
593 fc->base.base.is_compound = true;
594 return fc;
595}
596
597static inline
598void _ctf_field_class_int_destroy(struct ctf_field_class_int *fc)
599{
600 BT_ASSERT(fc);
601 g_free(fc);
602}
603
604static inline
605void _ctf_field_class_enum_destroy(struct ctf_field_class_enum *fc)
606{
607 BT_ASSERT(fc);
608
609 if (fc->mappings) {
610 uint64_t i;
611
612 for (i = 0; i < fc->mappings->len; i++) {
613 struct ctf_field_class_enum_mapping *mapping =
614 &g_array_index(fc->mappings,
615 struct ctf_field_class_enum_mapping, i);
616
617 _ctf_field_class_enum_mapping_fini(mapping);
618 }
619
620 g_array_free(fc->mappings, TRUE);
621 }
622
623 g_free(fc);
624}
625
626static inline
627void _ctf_field_class_float_destroy(struct ctf_field_class_float *fc)
628{
629 BT_ASSERT(fc);
630 g_free(fc);
631}
632
633static inline
634void _ctf_field_class_string_destroy(struct ctf_field_class_string *fc)
635{
636 BT_ASSERT(fc);
637 g_free(fc);
638}
639
640static inline
641void _ctf_field_class_struct_destroy(struct ctf_field_class_struct *fc)
642{
643 BT_ASSERT(fc);
644
645 if (fc->members) {
646 uint64_t i;
647
648 for (i = 0; i < fc->members->len; i++) {
649 struct ctf_named_field_class *named_fc =
650 &g_array_index(fc->members,
651 struct ctf_named_field_class, i);
652
653 _ctf_named_field_class_fini(named_fc);
654 }
655
656 g_array_free(fc->members, TRUE);
657 }
658
659 g_free(fc);
660}
661
662static inline
663void _ctf_field_class_array_base_fini(struct ctf_field_class_array_base *fc)
664{
665 BT_ASSERT(fc);
666 ctf_field_class_destroy(fc->elem_fc);
667}
668
669static inline
670void _ctf_field_class_array_destroy(struct ctf_field_class_array *fc)
671{
672 BT_ASSERT(fc);
673 _ctf_field_class_array_base_fini(&fc->base);
674 g_free(fc);
675}
676
677static inline
678void _ctf_field_class_sequence_destroy(struct ctf_field_class_sequence *fc)
679{
680 BT_ASSERT(fc);
681 _ctf_field_class_array_base_fini(&fc->base);
682
683 if (fc->length_ref) {
684 g_string_free(fc->length_ref, TRUE);
685 }
686
687 ctf_field_path_fini(&fc->length_path);
688 g_free(fc);
689}
690
691static inline
692void _ctf_field_class_variant_destroy(struct ctf_field_class_variant *fc)
693{
694 BT_ASSERT(fc);
695
696 if (fc->options) {
697 uint64_t i;
698
699 for (i = 0; i < fc->options->len; i++) {
700 struct ctf_named_field_class *named_fc =
701 &g_array_index(fc->options,
702 struct ctf_named_field_class, i);
703
704 _ctf_named_field_class_fini(named_fc);
705 }
706
707 g_array_free(fc->options, TRUE);
708 }
709
710 if (fc->ranges) {
711 g_array_free(fc->ranges, TRUE);
712 }
713
714 if (fc->tag_ref) {
715 g_string_free(fc->tag_ref, TRUE);
716 }
717
718 ctf_field_path_fini(&fc->tag_path);
719 g_free(fc);
720}
721
722static inline
723void ctf_field_class_destroy(struct ctf_field_class *fc)
724{
725 if (!fc) {
726 return;
727 }
728
729 switch (fc->type) {
730 case CTF_FIELD_CLASS_TYPE_INT:
731 _ctf_field_class_int_destroy(ctf_field_class_as_int(fc));
732 break;
733 case CTF_FIELD_CLASS_TYPE_ENUM:
734 _ctf_field_class_enum_destroy(ctf_field_class_as_enum(fc));
735 break;
736 case CTF_FIELD_CLASS_TYPE_FLOAT:
737 _ctf_field_class_float_destroy(ctf_field_class_as_float(fc));
738 break;
739 case CTF_FIELD_CLASS_TYPE_STRING:
740 _ctf_field_class_string_destroy(ctf_field_class_as_string(fc));
741 break;
742 case CTF_FIELD_CLASS_TYPE_STRUCT:
743 _ctf_field_class_struct_destroy(ctf_field_class_as_struct(fc));
744 break;
745 case CTF_FIELD_CLASS_TYPE_ARRAY:
746 _ctf_field_class_array_destroy(ctf_field_class_as_array(fc));
747 break;
748 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
749 _ctf_field_class_sequence_destroy(ctf_field_class_as_sequence(fc));
750 break;
751 case CTF_FIELD_CLASS_TYPE_VARIANT:
752 _ctf_field_class_variant_destroy(ctf_field_class_as_variant(fc));
753 break;
754 default:
755 bt_common_abort();
756 }
757}
758
759static inline
760struct ctf_range *ctf_field_class_enum_mapping_borrow_range_by_index(
761 struct ctf_field_class_enum_mapping *mapping, uint64_t index)
762{
763 BT_ASSERT_DBG(mapping);
764 BT_ASSERT_DBG(index < mapping->ranges->len);
765 return &g_array_index(mapping->ranges, struct ctf_range, index);
766}
767
768static inline
769struct ctf_field_class_enum_mapping *ctf_field_class_enum_borrow_mapping_by_index(
770 struct ctf_field_class_enum *fc, uint64_t index)
771{
772 BT_ASSERT_DBG(fc);
773 BT_ASSERT_DBG(index < fc->mappings->len);
774 return &g_array_index(fc->mappings, struct ctf_field_class_enum_mapping,
775 index);
776}
777
778static inline
779struct ctf_field_class_enum_mapping *ctf_field_class_enum_borrow_mapping_by_label(
780 struct ctf_field_class_enum *fc, const char *label)
781{
782 struct ctf_field_class_enum_mapping *ret_mapping = NULL;
783 uint64_t i;
784
785 BT_ASSERT_DBG(fc);
786 BT_ASSERT_DBG(label);
787
788 for (i = 0; i < fc->mappings->len; i++) {
789 struct ctf_field_class_enum_mapping *mapping =
790 ctf_field_class_enum_borrow_mapping_by_index(fc, i);
791
792 if (strcmp(mapping->label->str, label) == 0) {
793 ret_mapping = mapping;
794 goto end;
795 }
796 }
797
798end:
799 return ret_mapping;
800}
801
802static inline
803void ctf_field_class_enum_map_range(struct ctf_field_class_enum *fc,
804 const char *label, uint64_t u_lower, uint64_t u_upper)
805{
806 struct ctf_field_class_enum_mapping *mapping = NULL;
807 struct ctf_range range = {
808 .lower = {
809 .u = u_lower,
810 },
811 .upper = {
812 .u = u_upper,
813 },
814 };
815 uint64_t i;
816
817 BT_ASSERT(fc);
818 BT_ASSERT(label);
819
820 for (i = 0; i < fc->mappings->len; i++) {
821 mapping = ctf_field_class_enum_borrow_mapping_by_index(
822 fc, i);
823
824 if (strcmp(mapping->label->str, label) == 0) {
825 break;
826 }
827 }
828
829 if (i == fc->mappings->len) {
830 mapping = NULL;
831 }
832
833 if (!mapping) {
834 g_array_set_size(fc->mappings, fc->mappings->len + 1);
835 mapping = ctf_field_class_enum_borrow_mapping_by_index(
836 fc, fc->mappings->len - 1);
837 _ctf_field_class_enum_mapping_init(mapping);
838 g_string_assign(mapping->label, label);
839 }
840
841 g_array_append_val(mapping->ranges, range);
842}
843
844static inline
845struct ctf_named_field_class *ctf_field_class_struct_borrow_member_by_index(
846 struct ctf_field_class_struct *fc, uint64_t index)
847{
848 BT_ASSERT_DBG(fc);
849 BT_ASSERT_DBG(index < fc->members->len);
850 return &g_array_index(fc->members, struct ctf_named_field_class,
851 index);
852}
853
854static inline
855struct ctf_named_field_class *ctf_field_class_struct_borrow_member_by_name(
856 struct ctf_field_class_struct *fc, const char *name)
857{
858 uint64_t i;
859 struct ctf_named_field_class *ret_named_fc = NULL;
860
861 BT_ASSERT_DBG(fc);
862 BT_ASSERT_DBG(name);
863
864 for (i = 0; i < fc->members->len; i++) {
865 struct ctf_named_field_class *named_fc =
866 ctf_field_class_struct_borrow_member_by_index(fc, i);
867
868 if (strcmp(name, named_fc->name->str) == 0) {
869 ret_named_fc = named_fc;
870 goto end;
871 }
872 }
873
874end:
875 return ret_named_fc;
876}
877
878static inline
879struct ctf_field_class *ctf_field_class_struct_borrow_member_field_class_by_name(
880 struct ctf_field_class_struct *struct_fc, const char *name)
881{
882 struct ctf_named_field_class *named_fc = NULL;
883 struct ctf_field_class *fc = NULL;
884
885 if (!struct_fc) {
886 goto end;
887 }
888
889 named_fc = ctf_field_class_struct_borrow_member_by_name(struct_fc, name);
890 if (!named_fc) {
891 goto end;
892 }
893
894 fc = named_fc->fc;
895
896end:
897 return fc;
898}
899
900static inline
901struct ctf_field_class_int *
902ctf_field_class_struct_borrow_member_int_field_class_by_name(
903 struct ctf_field_class_struct *struct_fc, const char *name)
904{
905 struct ctf_field_class_int *int_fc = NULL;
906
907 int_fc = ctf_field_class_as_int(
908 ctf_field_class_struct_borrow_member_field_class_by_name(
909 struct_fc, name));
910 if (!int_fc) {
911 goto end;
912 }
913
914 if (int_fc->base.base.type != CTF_FIELD_CLASS_TYPE_INT &&
915 int_fc->base.base.type != CTF_FIELD_CLASS_TYPE_ENUM) {
916 int_fc = NULL;
917 goto end;
918 }
919
920end:
921 return int_fc;
922}
923
924static inline
925void _ctf_named_field_class_unescape_orig_name(
926 struct ctf_named_field_class *named_fc)
927{
928 const char *name = named_fc->orig_name->str;
929
930 if (name[0] == '_') {
931 name++;
932 }
933
934 g_string_assign(named_fc->name, name);
935}
936
937static inline
938void ctf_field_class_struct_append_member(struct ctf_field_class_struct *fc,
939 const char *orig_name, struct ctf_field_class *member_fc)
940{
941 struct ctf_named_field_class *named_fc;
942
943 BT_ASSERT(fc);
944 BT_ASSERT(orig_name);
945 g_array_set_size(fc->members, fc->members->len + 1);
946
947 named_fc = &g_array_index(fc->members, struct ctf_named_field_class,
948 fc->members->len - 1);
949 _ctf_named_field_class_init(named_fc);
950 g_string_assign(named_fc->orig_name, orig_name);
951 _ctf_named_field_class_unescape_orig_name(named_fc);
952 named_fc->fc = member_fc;
953
954 if (member_fc->alignment > fc->base.alignment) {
955 fc->base.alignment = member_fc->alignment;
956 }
957}
958
959static inline
960struct ctf_named_field_class *ctf_field_class_variant_borrow_option_by_index(
961 struct ctf_field_class_variant *fc, uint64_t index)
962{
963 BT_ASSERT_DBG(fc);
964 BT_ASSERT_DBG(index < fc->options->len);
965 return &g_array_index(fc->options, struct ctf_named_field_class,
966 index);
967}
968
969static inline
970struct ctf_named_field_class *ctf_field_class_variant_borrow_option_by_name(
971 struct ctf_field_class_variant *fc, const char *name)
972{
973 uint64_t i;
974 struct ctf_named_field_class *ret_named_fc = NULL;
975
976 BT_ASSERT_DBG(fc);
977 BT_ASSERT_DBG(name);
978
979 for (i = 0; i < fc->options->len; i++) {
980 struct ctf_named_field_class *named_fc =
981 ctf_field_class_variant_borrow_option_by_index(fc, i);
982
983 if (strcmp(name, named_fc->name->str) == 0) {
984 ret_named_fc = named_fc;
985 goto end;
986 }
987 }
988
989end:
990 return ret_named_fc;
991}
992
993static inline
994struct ctf_field_class_variant_range *
995ctf_field_class_variant_borrow_range_by_index(
996 struct ctf_field_class_variant *fc, uint64_t index)
997{
998 BT_ASSERT_DBG(fc);
999 BT_ASSERT_DBG(index < fc->ranges->len);
1000 return &g_array_index(fc->ranges, struct ctf_field_class_variant_range,
1001 index);
1002}
1003
1004static inline
1005void ctf_field_class_variant_append_option(struct ctf_field_class_variant *fc,
1006 const char *orig_name, struct ctf_field_class *option_fc)
1007{
1008 struct ctf_named_field_class *named_fc;
1009
1010 BT_ASSERT(fc);
1011 BT_ASSERT(orig_name);
1012 g_array_set_size(fc->options, fc->options->len + 1);
1013
1014 named_fc = &g_array_index(fc->options, struct ctf_named_field_class,
1015 fc->options->len - 1);
1016 _ctf_named_field_class_init(named_fc);
1017 g_string_assign(named_fc->orig_name, orig_name);
1018 _ctf_named_field_class_unescape_orig_name(named_fc);
1019 named_fc->fc = option_fc;
1020}
1021
1022static inline
1023void ctf_field_class_variant_set_tag_field_class(
1024 struct ctf_field_class_variant *fc,
1025 struct ctf_field_class_enum *tag_fc)
1026{
1027 uint64_t option_i;
1028
1029 BT_ASSERT(fc);
1030 BT_ASSERT(tag_fc);
1031 fc->tag_fc = tag_fc;
1032
1033 for (option_i = 0; option_i < fc->options->len; option_i++) {
1034 uint64_t range_i;
1035 struct ctf_named_field_class *named_fc =
1036 ctf_field_class_variant_borrow_option_by_index(
1037 fc, option_i);
1038 struct ctf_field_class_enum_mapping *mapping;
1039
1040 mapping = ctf_field_class_enum_borrow_mapping_by_label(
1041 tag_fc, named_fc->orig_name->str);
1042 if (!mapping) {
1043 continue;
1044 }
1045
1046 for (range_i = 0; range_i < mapping->ranges->len;
1047 range_i++) {
1048 struct ctf_range *range =
1049 ctf_field_class_enum_mapping_borrow_range_by_index(
1050 mapping, range_i);
1051 struct ctf_field_class_variant_range var_range;
1052
1053 var_range.range = *range;
1054 var_range.option_index = option_i;
1055 g_array_append_val(fc->ranges, var_range);
1056 }
1057 }
1058}
1059
1060static inline
1061struct ctf_field_class *ctf_field_class_compound_borrow_field_class_by_index(
1062 struct ctf_field_class *comp_fc, uint64_t index)
1063{
1064 struct ctf_field_class *fc = NULL;
1065
1066 switch (comp_fc->type) {
1067 case CTF_FIELD_CLASS_TYPE_STRUCT:
1068 {
1069 struct ctf_named_field_class *named_fc =
1070 ctf_field_class_struct_borrow_member_by_index(
1071 (struct ctf_field_class_struct *) comp_fc, index);
1072
1073 BT_ASSERT_DBG(named_fc);
1074 fc = named_fc->fc;
1075 break;
1076 }
1077 case CTF_FIELD_CLASS_TYPE_VARIANT:
1078 {
1079 struct ctf_named_field_class *named_fc =
1080 ctf_field_class_variant_borrow_option_by_index(
1081 (struct ctf_field_class_variant *) comp_fc, index);
1082
1083 BT_ASSERT_DBG(named_fc);
1084 fc = named_fc->fc;
1085 break;
1086 }
1087 case CTF_FIELD_CLASS_TYPE_ARRAY:
1088 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
1089 {
1090 struct ctf_field_class_array_base *array_fc =
1091 (struct ctf_field_class_array_base *) comp_fc;
1092
1093 fc = array_fc->elem_fc;
1094 break;
1095 }
1096 default:
1097 break;
1098 }
1099
1100 return fc;
1101}
1102
1103static inline
1104uint64_t ctf_field_class_compound_get_field_class_count(struct ctf_field_class *fc)
1105{
1106 uint64_t field_count;
1107
1108 switch (fc->type) {
1109 case CTF_FIELD_CLASS_TYPE_STRUCT:
1110 {
1111 struct ctf_field_class_struct *struct_fc =
1112 (struct ctf_field_class_struct *) fc;
1113
1114 field_count = struct_fc->members->len;
1115 break;
1116 }
1117 case CTF_FIELD_CLASS_TYPE_VARIANT:
1118 {
1119 struct ctf_field_class_variant *var_fc =
1120 (struct ctf_field_class_variant *) fc;
1121
1122 field_count = var_fc->options->len;
1123 break;
1124 }
1125 case CTF_FIELD_CLASS_TYPE_ARRAY:
1126 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
1127 /*
1128 * Array and sequence types always contain a single
1129 * member (the element type).
1130 */
1131 field_count = 1;
1132 break;
1133 default:
1134 bt_common_abort();
1135 }
1136
1137 return field_count;
1138}
1139
1140static inline
1141int64_t ctf_field_class_compound_get_field_class_index_from_orig_name(
1142 struct ctf_field_class *fc, const char *orig_name)
1143{
1144 int64_t ret_index = -1;
1145 uint64_t i;
1146
1147 switch (fc->type) {
1148 case CTF_FIELD_CLASS_TYPE_STRUCT:
1149 {
1150 struct ctf_field_class_struct *struct_fc =
1151 (struct ctf_field_class_struct *) fc;
1152
1153 for (i = 0; i < struct_fc->members->len; i++) {
1154 struct ctf_named_field_class *named_fc =
1155 ctf_field_class_struct_borrow_member_by_index(
1156 struct_fc, i);
1157
1158 if (strcmp(orig_name, named_fc->orig_name->str) == 0) {
1159 ret_index = (int64_t) i;
1160 goto end;
1161 }
1162 }
1163
1164 break;
1165 }
1166 case CTF_FIELD_CLASS_TYPE_VARIANT:
1167 {
1168 struct ctf_field_class_variant *var_fc
1169 = (struct ctf_field_class_variant *) fc;
1170
1171 for (i = 0; i < var_fc->options->len; i++) {
1172 struct ctf_named_field_class *named_fc =
1173 ctf_field_class_variant_borrow_option_by_index(
1174 var_fc, i);
1175
1176 if (strcmp(orig_name, named_fc->orig_name->str) == 0) {
1177 ret_index = (int64_t) i;
1178 goto end;
1179 }
1180 }
1181
1182 break;
1183 }
1184 default:
1185 break;
1186 }
1187
1188end:
1189 return ret_index;
1190}
1191
1192static inline
1193void ctf_field_path_append_index(struct ctf_field_path *fp, int64_t index)
1194{
1195 BT_ASSERT(fp);
1196 g_array_append_val(fp->path, index);
1197}
1198
1199static inline
1200int64_t ctf_field_path_borrow_index_by_index(struct ctf_field_path *fp,
1201 uint64_t index)
1202{
1203 BT_ASSERT_DBG(fp);
1204 BT_ASSERT_DBG(index < fp->path->len);
1205 return g_array_index(fp->path, int64_t, index);
1206}
1207
1208static inline
1209void ctf_field_path_clear(struct ctf_field_path *fp)
1210{
1211 BT_ASSERT(fp);
1212 g_array_set_size(fp->path, 0);
1213}
1214
1215static inline
1216const char *ctf_scope_string(enum ctf_scope scope)
1217{
1218 switch (scope) {
1219 case CTF_SCOPE_PACKET_HEADER:
1220 return "PACKET_HEADER";
1221 case CTF_SCOPE_PACKET_CONTEXT:
1222 return "PACKET_CONTEXT";
1223 case CTF_SCOPE_EVENT_HEADER:
1224 return "EVENT_HEADER";
1225 case CTF_SCOPE_EVENT_COMMON_CONTEXT:
1226 return "EVENT_COMMON_CONTEXT";
1227 case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT:
1228 return "EVENT_SPECIFIC_CONTEXT";
1229 case CTF_SCOPE_EVENT_PAYLOAD:
1230 return "EVENT_PAYLOAD";
1231 default:
1232 bt_common_abort();
1233 }
1234}
1235
1236static inline
1237GString *ctf_field_path_string(struct ctf_field_path *path)
1238{
1239 GString *str = g_string_new(NULL);
1240 uint64_t i;
1241
1242 BT_ASSERT(path);
1243
1244 if (!str) {
1245 goto end;
1246 }
1247
1248 g_string_append_printf(str, "[%s", ctf_scope_string(path->root));
1249
1250 for (i = 0; i < path->path->len; i++) {
1251 g_string_append_printf(str, ", %" PRId64,
1252 ctf_field_path_borrow_index_by_index(path, i));
1253 }
1254
1255 g_string_append(str, "]");
1256
1257end:
1258 return str;
1259}
1260
1261static inline
1262struct ctf_field_class *ctf_field_path_borrow_field_class(
1263 struct ctf_field_path *field_path,
1264 struct ctf_trace_class *tc,
1265 struct ctf_stream_class *sc,
1266 struct ctf_event_class *ec)
1267{
1268 uint64_t i;
1269 struct ctf_field_class *fc;
1270
1271 switch (field_path->root) {
1272 case CTF_SCOPE_PACKET_HEADER:
1273 fc = tc->packet_header_fc;
1274 break;
1275 case CTF_SCOPE_PACKET_CONTEXT:
1276 fc = sc->packet_context_fc;
1277 break;
1278 case CTF_SCOPE_EVENT_HEADER:
1279 fc = sc->event_header_fc;
1280 break;
1281 case CTF_SCOPE_EVENT_COMMON_CONTEXT:
1282 fc = sc->event_common_context_fc;
1283 break;
1284 case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT:
1285 fc = ec->spec_context_fc;
1286 break;
1287 case CTF_SCOPE_EVENT_PAYLOAD:
1288 fc = ec->payload_fc;
1289 break;
1290 default:
1291 bt_common_abort();
1292 }
1293
1294 BT_ASSERT_DBG(fc);
1295
1296 for (i = 0; i < field_path->path->len; i++) {
1297 int64_t child_index =
1298 ctf_field_path_borrow_index_by_index(field_path, i);
1299 struct ctf_field_class *child_fc =
1300 ctf_field_class_compound_borrow_field_class_by_index(
1301 fc, child_index);
1302 BT_ASSERT_DBG(child_fc);
1303 fc = child_fc;
1304 }
1305
1306 BT_ASSERT_DBG(fc);
1307 return fc;
1308}
1309
1310static inline
1311struct ctf_field_class *ctf_field_class_copy(struct ctf_field_class *fc);
1312
1313static inline
1314void ctf_field_class_bit_array_copy_content(
1315 struct ctf_field_class_bit_array *dst_fc,
1316 struct ctf_field_class_bit_array *src_fc)
1317{
1318 BT_ASSERT(dst_fc);
1319 BT_ASSERT(src_fc);
1320 dst_fc->byte_order = src_fc->byte_order;
1321 dst_fc->size = src_fc->size;
1322}
1323
1324static inline
1325void ctf_field_class_int_copy_content(
1326 struct ctf_field_class_int *dst_fc,
1327 struct ctf_field_class_int *src_fc)
1328{
1329 ctf_field_class_bit_array_copy_content(&dst_fc->base, &src_fc->base);
1330 dst_fc->meaning = src_fc->meaning;
1331 dst_fc->is_signed = src_fc->is_signed;
1332 dst_fc->disp_base = src_fc->disp_base;
1333 dst_fc->encoding = src_fc->encoding;
1334 dst_fc->mapped_clock_class = src_fc->mapped_clock_class;
1335 dst_fc->storing_index = src_fc->storing_index;
1336}
1337
1338static inline
1339struct ctf_field_class_int *_ctf_field_class_int_copy(
1340 struct ctf_field_class_int *fc)
1341{
1342 struct ctf_field_class_int *copy_fc = ctf_field_class_int_create();
1343
1344 BT_ASSERT(copy_fc);
1345 ctf_field_class_int_copy_content(copy_fc, fc);
1346 return copy_fc;
1347}
1348
1349static inline
1350struct ctf_field_class_enum *_ctf_field_class_enum_copy(
1351 struct ctf_field_class_enum *fc)
1352{
1353 struct ctf_field_class_enum *copy_fc = ctf_field_class_enum_create();
1354 uint64_t i;
1355
1356 BT_ASSERT(copy_fc);
1357 ctf_field_class_int_copy_content(&copy_fc->base, &fc->base);
1358
1359 for (i = 0; i < fc->mappings->len; i++) {
1360 uint64_t range_i;
1361
1362 struct ctf_field_class_enum_mapping *mapping =
1363 &g_array_index(fc->mappings,
1364 struct ctf_field_class_enum_mapping, i);
1365
1366 for (range_i = 0; range_i < mapping->ranges->len; range_i++) {
1367 struct ctf_range *range =
1368 &g_array_index(mapping->ranges,
1369 struct ctf_range, range_i);
1370
1371 ctf_field_class_enum_map_range(copy_fc,
1372 mapping->label->str, range->lower.u,
1373 range->upper.u);
1374 }
1375 }
1376
1377 return copy_fc;
1378}
1379
1380static inline
1381struct ctf_field_class_float *_ctf_field_class_float_copy(
1382 struct ctf_field_class_float *fc)
1383{
1384 struct ctf_field_class_float *copy_fc = ctf_field_class_float_create();
1385
1386 BT_ASSERT(copy_fc);
1387 ctf_field_class_bit_array_copy_content(&copy_fc->base, &fc->base);
1388 return copy_fc;
1389}
1390
1391static inline
1392struct ctf_field_class_string *_ctf_field_class_string_copy(
1393 struct ctf_field_class_string *fc)
1394{
1395 struct ctf_field_class_string *copy_fc = ctf_field_class_string_create();
1396
1397 BT_ASSERT(copy_fc);
1398 return copy_fc;
1399}
1400
1401static inline
1402struct ctf_field_class_struct *_ctf_field_class_struct_copy(
1403 struct ctf_field_class_struct *fc)
1404{
1405 struct ctf_field_class_struct *copy_fc = ctf_field_class_struct_create();
1406 uint64_t i;
1407
1408 BT_ASSERT(copy_fc);
1409
1410 for (i = 0; i < fc->members->len; i++) {
1411 struct ctf_named_field_class *named_fc =
1412 &g_array_index(fc->members,
1413 struct ctf_named_field_class, i);
1414
1415 ctf_field_class_struct_append_member(copy_fc,
1416 named_fc->name->str,
1417 ctf_field_class_copy(named_fc->fc));
1418 }
1419
1420 return copy_fc;
1421}
1422
1423static inline
1424void ctf_field_path_copy_content(struct ctf_field_path *dst_fp,
1425 struct ctf_field_path *src_fp)
1426{
1427 uint64_t i;
1428
1429 BT_ASSERT(dst_fp);
1430 BT_ASSERT(src_fp);
1431 dst_fp->root = src_fp->root;
1432 ctf_field_path_clear(dst_fp);
1433
1434 for (i = 0; i < src_fp->path->len; i++) {
1435 int64_t index = ctf_field_path_borrow_index_by_index(
1436 src_fp, i);
1437
1438 ctf_field_path_append_index(dst_fp, index);
1439 }
1440}
1441
1442static inline
1443struct ctf_field_class_variant *_ctf_field_class_variant_copy(
1444 struct ctf_field_class_variant *fc)
1445{
1446 struct ctf_field_class_variant *copy_fc =
1447 ctf_field_class_variant_create();
1448 uint64_t i;
1449
1450 BT_ASSERT(copy_fc);
1451
1452 for (i = 0; i < fc->options->len; i++) {
1453 struct ctf_named_field_class *named_fc =
1454 &g_array_index(fc->options,
1455 struct ctf_named_field_class, i);
1456
1457 ctf_field_class_variant_append_option(copy_fc,
1458 named_fc->name->str,
1459 ctf_field_class_copy(named_fc->fc));
1460 }
1461
1462 for (i = 0; i < fc->ranges->len; i++) {
1463 struct ctf_field_class_variant_range *range =
1464 &g_array_index(fc->ranges,
1465 struct ctf_field_class_variant_range, i);
1466
1467 g_array_append_val(copy_fc->ranges, *range);
1468 }
1469
1470 ctf_field_path_copy_content(&copy_fc->tag_path, &fc->tag_path);
1471 g_string_assign(copy_fc->tag_ref, fc->tag_ref->str);
1472 copy_fc->stored_tag_index = fc->stored_tag_index;
1473 return copy_fc;
1474}
1475
1476static inline
1477void ctf_field_class_array_base_copy_content(
1478 struct ctf_field_class_array_base *dst_fc,
1479 struct ctf_field_class_array_base *src_fc)
1480{
1481 BT_ASSERT(dst_fc);
1482 BT_ASSERT(src_fc);
1483 dst_fc->elem_fc = ctf_field_class_copy(src_fc->elem_fc);
1484 dst_fc->is_text = src_fc->is_text;
1485}
1486
1487static inline
1488struct ctf_field_class_array *_ctf_field_class_array_copy(
1489 struct ctf_field_class_array *fc)
1490{
1491 struct ctf_field_class_array *copy_fc = ctf_field_class_array_create();
1492
1493 BT_ASSERT(copy_fc);
1494 ctf_field_class_array_base_copy_content(&copy_fc->base, &fc->base);
1495 copy_fc->length = fc->length;
1496 return copy_fc;
1497}
1498
1499static inline
1500struct ctf_field_class_sequence *_ctf_field_class_sequence_copy(
1501 struct ctf_field_class_sequence *fc)
1502{
1503 struct ctf_field_class_sequence *copy_fc =
1504 ctf_field_class_sequence_create();
1505
1506 BT_ASSERT(copy_fc);
1507 ctf_field_class_array_base_copy_content(&copy_fc->base, &fc->base);
1508 ctf_field_path_copy_content(&copy_fc->length_path, &fc->length_path);
1509 g_string_assign(copy_fc->length_ref, fc->length_ref->str);
1510 copy_fc->stored_length_index = fc->stored_length_index;
1511 return copy_fc;
1512}
1513
1514static inline
1515struct ctf_field_class *ctf_field_class_copy(struct ctf_field_class *fc)
1516{
1517 struct ctf_field_class *copy_fc = NULL;
1518
1519 if (!fc) {
1520 goto end;
1521 }
1522
1523 /*
1524 * Translation should not have happened yet.
1525 */
1526 BT_ASSERT(!fc->ir_fc);
1527
1528 switch (fc->type) {
1529 case CTF_FIELD_CLASS_TYPE_INT:
1530 copy_fc = &_ctf_field_class_int_copy(ctf_field_class_as_int (fc))->base.base;
1531 break;
1532 case CTF_FIELD_CLASS_TYPE_ENUM:
1533 copy_fc = &_ctf_field_class_enum_copy(ctf_field_class_as_enum (fc))->base.base.base;
1534 break;
1535 case CTF_FIELD_CLASS_TYPE_FLOAT:
1536 copy_fc = &_ctf_field_class_float_copy(ctf_field_class_as_float (fc))->base.base;
1537 break;
1538 case CTF_FIELD_CLASS_TYPE_STRING:
1539 copy_fc = &_ctf_field_class_string_copy(ctf_field_class_as_string (fc))->base;
1540 break;
1541 case CTF_FIELD_CLASS_TYPE_STRUCT:
1542 copy_fc = &_ctf_field_class_struct_copy(ctf_field_class_as_struct (fc))->base;
1543 break;
1544 case CTF_FIELD_CLASS_TYPE_ARRAY:
1545 copy_fc = &_ctf_field_class_array_copy(ctf_field_class_as_array(fc))->base.base;
1546 break;
1547 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
1548 copy_fc = &_ctf_field_class_sequence_copy(ctf_field_class_as_sequence (fc))->base.base;
1549 break;
1550 case CTF_FIELD_CLASS_TYPE_VARIANT:
1551 copy_fc = &_ctf_field_class_variant_copy(ctf_field_class_as_variant (fc))->base;
1552 break;
1553 default:
1554 bt_common_abort();
1555 }
1556
1557 copy_fc->type = fc->type;
1558 copy_fc->alignment = fc->alignment;
1559 copy_fc->in_ir = fc->in_ir;
1560
1561end:
1562 return copy_fc;
1563}
1564
1565static inline
1566struct ctf_event_class *ctf_event_class_create(void)
1567{
1568 struct ctf_event_class *ec = g_new0(struct ctf_event_class, 1);
1569
1570 BT_ASSERT(ec);
1571 ec->name = g_string_new(NULL);
1572 BT_ASSERT(ec->name);
1573 ec->emf_uri = g_string_new(NULL);
1574 BT_ASSERT(ec->emf_uri);
1575 ec->is_log_level_set = false;
1576 return ec;
1577}
1578
1579static inline
1580void ctf_event_class_set_log_level(struct ctf_event_class *ec,
1581 enum bt_event_class_log_level log_level)
1582{
1583 BT_ASSERT(ec);
1584 ec->log_level = log_level;
1585 ec->is_log_level_set = true;
1586}
1587
1588static inline
1589void ctf_event_class_destroy(struct ctf_event_class *ec)
1590{
1591 if (!ec) {
1592 return;
1593 }
1594
1595 if (ec->name) {
1596 g_string_free(ec->name, TRUE);
1597 }
1598
1599 if (ec->emf_uri) {
1600 g_string_free(ec->emf_uri, TRUE);
1601 }
1602
1603 ctf_field_class_destroy(ec->spec_context_fc);
1604 ctf_field_class_destroy(ec->payload_fc);
1605 g_free(ec);
1606}
1607
1608static inline
1609struct ctf_stream_class *ctf_stream_class_create(void)
1610{
1611 struct ctf_stream_class *sc = g_new0(struct ctf_stream_class, 1);
1612
1613 BT_ASSERT(sc);
1614 sc->event_classes = g_ptr_array_new_with_free_func(
1615 (GDestroyNotify) ctf_event_class_destroy);
1616 BT_ASSERT(sc->event_classes);
1617 sc->event_classes_by_id = g_hash_table_new(g_direct_hash,
1618 g_direct_equal);
1619 BT_ASSERT(sc->event_classes_by_id);
1620 return sc;
1621}
1622
1623static inline
1624void ctf_stream_class_destroy(struct ctf_stream_class *sc)
1625{
1626 if (!sc) {
1627 return;
1628 }
1629
1630 if (sc->event_classes) {
1631 g_ptr_array_free(sc->event_classes, TRUE);
1632 }
1633
1634 if (sc->event_classes_by_id) {
1635 g_hash_table_destroy(sc->event_classes_by_id);
1636 }
1637
1638 ctf_field_class_destroy(sc->packet_context_fc);
1639 ctf_field_class_destroy(sc->event_header_fc);
1640 ctf_field_class_destroy(sc->event_common_context_fc);
1641 g_free(sc);
1642}
1643
1644static inline
1645void ctf_stream_class_append_event_class(struct ctf_stream_class *sc,
1646 struct ctf_event_class *ec)
1647{
1648 g_ptr_array_add(sc->event_classes, ec);
1649 g_hash_table_insert(sc->event_classes_by_id,
1650 GUINT_TO_POINTER((guint) ec->id), ec);
1651}
1652
1653static inline
1654struct ctf_event_class *ctf_stream_class_borrow_event_class_by_id(
1655 struct ctf_stream_class *sc, uint64_t type)
1656{
1657 BT_ASSERT_DBG(sc);
1658 return (struct ctf_event_class *) g_hash_table_lookup(sc->event_classes_by_id,
1659 GUINT_TO_POINTER((guint) type));
1660}
1661
1662static inline
1663void _ctf_trace_class_env_entry_init(struct ctf_trace_class_env_entry *entry)
1664{
1665 BT_ASSERT(entry);
1666 entry->name = g_string_new(NULL);
1667 BT_ASSERT(entry->name);
1668 entry->value.str = g_string_new(NULL);
1669 BT_ASSERT(entry->value.str);
1670}
1671
1672static inline
1673void _ctf_trace_class_env_entry_fini(struct ctf_trace_class_env_entry *entry)
1674{
1675 BT_ASSERT(entry);
1676
1677 if (entry->name) {
1678 g_string_free(entry->name, TRUE);
1679 }
1680
1681 if (entry->value.str) {
1682 g_string_free(entry->value.str, TRUE);
1683 }
1684}
1685
1686static inline
1687struct ctf_clock_class *ctf_clock_class_create(void)
1688{
1689 struct ctf_clock_class *cc = g_new0(struct ctf_clock_class, 1);
1690
1691 BT_ASSERT(cc);
1692 cc->name = g_string_new(NULL);
1693 BT_ASSERT(cc->name);
1694 cc->description = g_string_new(NULL);
1695 BT_ASSERT(cc->description);
1696 return cc;
1697}
1698
1699static inline
1700void ctf_clock_class_destroy(struct ctf_clock_class *cc)
1701{
1702 if (!cc) {
1703 return;
1704 }
1705
1706 if (cc->name) {
1707 g_string_free(cc->name, TRUE);
1708 }
1709
1710 if (cc->description) {
1711 g_string_free(cc->description, TRUE);
1712 }
1713
1714 bt_clock_class_put_ref(cc->ir_cc);
1715 g_free(cc);
1716}
1717
1718static inline
1719struct ctf_trace_class *ctf_trace_class_create(void)
1720{
1721 struct ctf_trace_class *tc = g_new0(struct ctf_trace_class, 1);
1722
1723 BT_ASSERT(tc);
1724 tc->default_byte_order = CTF_BYTE_ORDER_UNKNOWN;
1725 tc->clock_classes = g_ptr_array_new_with_free_func(
1726 (GDestroyNotify) ctf_clock_class_destroy);
1727 BT_ASSERT(tc->clock_classes);
1728 tc->stream_classes = g_ptr_array_new_with_free_func(
1729 (GDestroyNotify) ctf_stream_class_destroy);
1730 BT_ASSERT(tc->stream_classes);
1731 tc->env_entries = g_array_new(FALSE, TRUE,
1732 sizeof(struct ctf_trace_class_env_entry));
1733 return tc;
1734}
1735
1736static inline
1737void ctf_trace_class_destroy(struct ctf_trace_class *tc)
1738{
1739 if (!tc) {
1740 return;
1741 }
1742
1743 ctf_field_class_destroy(tc->packet_header_fc);
1744
1745 if (tc->clock_classes) {
1746 g_ptr_array_free(tc->clock_classes, TRUE);
1747 }
1748
1749 if (tc->stream_classes) {
1750 g_ptr_array_free(tc->stream_classes, TRUE);
1751 }
1752
1753 if (tc->env_entries) {
1754 uint64_t i;
1755
1756 for (i = 0; i < tc->env_entries->len; i++) {
1757 struct ctf_trace_class_env_entry *entry =
1758 &g_array_index(tc->env_entries,
1759 struct ctf_trace_class_env_entry, i);
1760
1761 _ctf_trace_class_env_entry_fini(entry);
1762 }
1763
1764 g_array_free(tc->env_entries, TRUE);
1765 }
1766
1767 g_free(tc);
1768}
1769
1770static inline
1771void ctf_trace_class_append_env_entry(struct ctf_trace_class *tc,
1772 const char *name, enum ctf_trace_class_env_entry_type type,
1773 const char *str_value, int64_t i_value)
1774{
1775 struct ctf_trace_class_env_entry *entry;
1776
1777 BT_ASSERT(tc);
1778 BT_ASSERT(name);
1779 g_array_set_size(tc->env_entries, tc->env_entries->len + 1);
1780
1781 entry = &g_array_index(tc->env_entries,
1782 struct ctf_trace_class_env_entry, tc->env_entries->len - 1);
1783 entry->type = type;
1784 _ctf_trace_class_env_entry_init(entry);
1785 g_string_assign(entry->name, name);
1786
1787 if (str_value) {
1788 g_string_assign(entry->value.str, str_value);
1789 }
1790
1791 entry->value.i = i_value;
1792}
1793
1794static inline
1795struct ctf_stream_class *ctf_trace_class_borrow_stream_class_by_id(
1796 struct ctf_trace_class *tc, uint64_t id)
1797{
1798 uint64_t i;
1799 struct ctf_stream_class *ret_sc = NULL;
1800
1801 BT_ASSERT_DBG(tc);
1802
1803 for (i = 0; i < tc->stream_classes->len; i++) {
1804 struct ctf_stream_class *sc =
1805 (struct ctf_stream_class *) tc->stream_classes->pdata[i];
1806
1807 if (sc->id == id) {
1808 ret_sc = sc;
1809 goto end;
1810 }
1811 }
1812
1813end:
1814 return ret_sc;
1815}
1816
1817static inline
1818struct ctf_clock_class *ctf_trace_class_borrow_clock_class_by_name(
1819 struct ctf_trace_class *tc, const char *name)
1820{
1821 uint64_t i;
1822 struct ctf_clock_class *ret_cc = NULL;
1823
1824 BT_ASSERT_DBG(tc);
1825 BT_ASSERT_DBG(name);
1826
1827 for (i = 0; i < tc->clock_classes->len; i++) {
1828 struct ctf_clock_class *cc =
1829 (struct ctf_clock_class *) tc->clock_classes->pdata[i];
1830
1831 BT_ASSERT_DBG(cc->name);
1832 if (strcmp(cc->name->str, name) == 0) {
1833 ret_cc = cc;
1834 goto end;
1835 }
1836 }
1837
1838end:
1839 return ret_cc;
1840}
1841
1842static inline
1843struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_index(
1844 struct ctf_trace_class *tc, uint64_t index)
1845{
1846 BT_ASSERT_DBG(tc);
1847 BT_ASSERT_DBG(index < tc->env_entries->len);
1848 return &g_array_index(tc->env_entries, struct ctf_trace_class_env_entry,
1849 index);
1850}
1851
1852static inline
1853struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_name(
1854 struct ctf_trace_class *tc, const char *name)
1855{
1856 struct ctf_trace_class_env_entry *ret_entry = NULL;
1857 uint64_t i;
1858
1859 BT_ASSERT_DBG(tc);
1860 BT_ASSERT_DBG(name);
1861
1862 for (i = 0; i < tc->env_entries->len; i++) {
1863 struct ctf_trace_class_env_entry *env_entry =
1864 ctf_trace_class_borrow_env_entry_by_index(tc, i);
1865
1866 if (strcmp(env_entry->name->str, name) == 0) {
1867 ret_entry = env_entry;
1868 goto end;
1869 }
1870 }
1871
1872end:
1873 return ret_entry;
1874}
1875
1876#endif /* _CTF_META_H */
This page took 0.029712 seconds and 4 git commands to generate.