Make API CTF-agnostic
[babeltrace.git] / plugins / ctf / common / metadata / ctf-meta.h
CommitLineData
7b33a0e0
PP
1#ifndef _CTF_META_H
2#define _CTF_META_H
3
4/*
5 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 */
17
18#include <babeltrace/babeltrace.h>
19#include <babeltrace/common-internal.h>
20#include <babeltrace/assert-internal.h>
21#include <glib.h>
22#include <stdint.h>
23#include <string.h>
24
25enum ctf_field_type_id {
26 CTF_FIELD_TYPE_ID_INT,
27 CTF_FIELD_TYPE_ID_ENUM,
28 CTF_FIELD_TYPE_ID_FLOAT,
29 CTF_FIELD_TYPE_ID_STRING,
30 CTF_FIELD_TYPE_ID_STRUCT,
31 CTF_FIELD_TYPE_ID_ARRAY,
32 CTF_FIELD_TYPE_ID_SEQUENCE,
33 CTF_FIELD_TYPE_ID_VARIANT,
34};
35
36enum ctf_field_type_meaning {
37 CTF_FIELD_TYPE_MEANING_NONE,
38 CTF_FIELD_TYPE_MEANING_PACKET_BEGINNING_TIME,
39 CTF_FIELD_TYPE_MEANING_PACKET_END_TIME,
40 CTF_FIELD_TYPE_MEANING_EVENT_CLASS_ID,
41 CTF_FIELD_TYPE_MEANING_STREAM_CLASS_ID,
42 CTF_FIELD_TYPE_MEANING_DATA_STREAM_ID,
43 CTF_FIELD_TYPE_MEANING_MAGIC,
44 CTF_FIELD_TYPE_MEANING_PACKET_COUNTER_SNAPSHOT,
45 CTF_FIELD_TYPE_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT,
46 CTF_FIELD_TYPE_MEANING_EXP_PACKET_TOTAL_SIZE,
47 CTF_FIELD_TYPE_MEANING_EXP_PACKET_CONTENT_SIZE,
48 CTF_FIELD_TYPE_MEANING_UUID,
49};
50
51enum ctf_byte_order {
52 CTF_BYTE_ORDER_DEFAULT,
53 CTF_BYTE_ORDER_LITTLE,
54 CTF_BYTE_ORDER_BIG,
55};
56
57enum ctf_encoding {
58 CTF_ENCODING_NONE,
59 CTF_ENCODING_UTF8,
60};
61
62struct ctf_field_type {
63 enum ctf_field_type_id id;
64 unsigned int alignment;
65 bool is_compound;
66 bool in_ir;
67
68 /* Weak, set during translation. NULL if `in_ir` is false below. */
69 struct bt_field_type *ir_ft;
70};
71
72struct ctf_field_type_bit_array {
73 struct ctf_field_type base;
74 enum ctf_byte_order byte_order;
75 unsigned int size;
76};
77
78struct ctf_field_type_int {
79 struct ctf_field_type_bit_array base;
80 enum ctf_field_type_meaning meaning;
81 bool is_signed;
82 enum bt_field_type_integer_preferred_display_base disp_base;
83 enum ctf_encoding encoding;
84 int64_t storing_index;
85
86 /* Owned by this */
87 struct bt_clock_class *mapped_clock_class;
88};
89
90struct ctf_range {
91 union {
92 uint64_t u;
93 int64_t i;
94 } lower;
95
96 union {
97 uint64_t u;
98 int64_t i;
99 } upper;
100};
101
102struct ctf_field_type_enum_mapping {
103 GString *label;
104 struct ctf_range range;
105};
106
107struct ctf_field_type_enum {
108 struct ctf_field_type_int base;
109
110 /* Array of `struct ctf_field_type_enum_mapping` */
111 GArray *mappings;
112};
113
114struct ctf_field_type_float {
115 struct ctf_field_type_bit_array base;
116};
117
118struct ctf_field_type_string {
119 struct ctf_field_type base;
120 enum ctf_encoding encoding;
121};
122
123struct ctf_named_field_type {
124 GString *name;
125
126 /* Owned by this */
127 struct ctf_field_type *ft;
128};
129
130struct ctf_field_type_struct {
131 struct ctf_field_type base;
132
133 /* Array of `struct ctf_named_field_type` */
134 GArray *members;
135};
136
137struct ctf_field_path {
138 enum bt_scope root;
139
140 /* Array of `int64_t` */
141 GArray *path;
142};
143
144struct ctf_field_type_variant_range {
145 struct ctf_range range;
146 uint64_t option_index;
147};
148
149struct ctf_field_type_variant {
150 struct ctf_field_type base;
151 GString *tag_ref;
152 struct ctf_field_path tag_path;
153 uint64_t stored_tag_index;
154
155 /* Array of `struct ctf_named_field_type` */
156 GArray *options;
157
158 /* Array of `struct ctf_field_type_variant_range` */
159 GArray *ranges;
160
161 /* Weak */
162 struct ctf_field_type_enum *tag_ft;
163};
164
165struct ctf_field_type_array_base {
166 struct ctf_field_type base;
167 struct ctf_field_type *elem_ft;
168 bool is_text;
169};
170
171struct ctf_field_type_array {
172 struct ctf_field_type_array_base base;
173 enum ctf_field_type_meaning meaning;
174 uint64_t length;
175};
176
177struct ctf_field_type_sequence {
178 struct ctf_field_type_array_base base;
179 GString *length_ref;
180 struct ctf_field_path length_path;
181 uint64_t stored_length_index;
182
183 /* Weak */
184 struct ctf_field_type_int *length_ft;
185};
186
187struct ctf_event_class {
188 GString *name;
189 uint64_t id;
190 GString *emf_uri;
191 enum bt_event_class_log_level log_level;
192 bool is_translated;
193
194 /* Owned by this */
195 struct ctf_field_type *spec_context_ft;
196
197 /* Owned by this */
198 struct ctf_field_type *payload_ft;
199
200 /* Weak, set during translation */
201 struct bt_event_class *ir_ec;
202};
203
204struct ctf_stream_class {
205 uint64_t id;
206 bool is_translated;
207
208 /* Owned by this */
209 struct ctf_field_type *packet_context_ft;
210
211 /* Owned by this */
212 struct ctf_field_type *event_header_ft;
213
214 /* Owned by this */
215 struct ctf_field_type *event_common_context_ft;
216
217 /* Array of `struct ctf_event_class *`, owned by this */
218 GPtrArray *event_classes;
219
220 /*
221 * Hash table mapping event class IDs to `struct ctf_event_class *`,
222 * weak.
223 */
224 GHashTable *event_classes_by_id;
225
226 /* Owned by this */
227 struct bt_clock_class *default_clock_class;
228
229 /* Weak, set during translation */
230 struct bt_stream_class *ir_sc;
231};
232
233enum ctf_trace_class_env_entry_type {
234 CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT,
235 CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR,
236};
237
238struct ctf_trace_class_env_entry {
239 enum ctf_trace_class_env_entry_type type;
240 GString *name;
241
242 struct {
243 int64_t i;
244 GString *str;
245 } value;
246};
247
248struct ctf_trace_class {
249 GString *name;
250 unsigned int major;
251 unsigned int minor;
252 uint8_t uuid[16];
253 bool is_uuid_set;
254 enum ctf_byte_order default_byte_order;
255
256 /* Owned by this */
257 struct ctf_field_type *packet_header_ft;
258
259 uint64_t stored_value_count;
260
261 /* Array of `struct bt_clock_class *` (owned by this) */
262 GPtrArray *clock_classes;
263
264 /* Array of `struct ctf_stream_class *` */
265 GPtrArray *stream_classes;
266
267 /* Array of `struct ctf_trace_class_env_entry` */
268 GArray *env_entries;
269
270 bool is_translated;
271
272 /* Weak, set during translation */
273 struct bt_trace *ir_tc;
274};
275
276static inline
277void ctf_field_type_destroy(struct ctf_field_type *ft);
278
279static inline
280void _ctf_field_type_init(struct ctf_field_type *ft, enum ctf_field_type_id id,
281 unsigned int alignment)
282{
283 BT_ASSERT(ft);
284 ft->id = id;
285 ft->alignment = alignment;
286 ft->in_ir = false;
287}
288
289static inline
290void _ctf_field_type_bit_array_init(struct ctf_field_type_bit_array *ft,
291 enum ctf_field_type_id id)
292{
293 _ctf_field_type_init((void *) ft, id, 1);
294}
295
296static inline
297void _ctf_field_type_int_init(struct ctf_field_type_int *ft,
298 enum ctf_field_type_id id)
299{
300 _ctf_field_type_bit_array_init((void *) ft, id);
301 ft->meaning = CTF_FIELD_TYPE_MEANING_NONE;
302 ft->storing_index = -1;
303}
304
305static inline
306void ctf_field_path_init(struct ctf_field_path *field_path)
307{
308 BT_ASSERT(field_path);
309 field_path->path = g_array_new(FALSE, TRUE, sizeof(int64_t));
310 BT_ASSERT(field_path->path);
311}
312
313static inline
314void ctf_field_path_fini(struct ctf_field_path *field_path)
315{
316 BT_ASSERT(field_path);
317
318 if (field_path->path) {
319 g_array_free(field_path->path, TRUE);
320 }
321}
322
323static inline
324void _ctf_named_field_type_init(struct ctf_named_field_type *named_ft)
325{
326 BT_ASSERT(named_ft);
327 named_ft->name = g_string_new(NULL);
328 BT_ASSERT(named_ft->name);
329}
330
331static inline
332void _ctf_named_field_type_fini(struct ctf_named_field_type *named_ft)
333{
334 BT_ASSERT(named_ft);
335
336 if (named_ft->name) {
337 g_string_free(named_ft->name, TRUE);
338 }
339
340 ctf_field_type_destroy(named_ft->ft);
341}
342
343static inline
344void _ctf_field_type_enum_mapping_init(
345 struct ctf_field_type_enum_mapping *mapping)
346{
347 BT_ASSERT(mapping);
348 mapping->label = g_string_new(NULL);
349 BT_ASSERT(mapping->label);
350}
351
352static inline
353void _ctf_field_type_enum_mapping_fini(
354 struct ctf_field_type_enum_mapping *mapping)
355{
356 BT_ASSERT(mapping);
357
358 if (mapping->label) {
359 g_string_free(mapping->label, TRUE);
360 }
361}
362
363static inline
364struct ctf_field_type_int *ctf_field_type_int_create(void)
365{
366 struct ctf_field_type_int *ft = g_new0(struct ctf_field_type_int, 1);
367
368 BT_ASSERT(ft);
369 _ctf_field_type_int_init(ft, CTF_FIELD_TYPE_ID_INT);
370 return ft;
371}
372
373static inline
374struct ctf_field_type_float *ctf_field_type_float_create(void)
375{
376 struct ctf_field_type_float *ft =
377 g_new0(struct ctf_field_type_float, 1);
378
379 BT_ASSERT(ft);
380 _ctf_field_type_bit_array_init((void *) ft, CTF_FIELD_TYPE_ID_FLOAT);
381 return ft;
382}
383
384static inline
385struct ctf_field_type_string *ctf_field_type_string_create(void)
386{
387 struct ctf_field_type_string *ft =
388 g_new0(struct ctf_field_type_string, 1);
389
390 BT_ASSERT(ft);
391 _ctf_field_type_init((void *) ft, CTF_FIELD_TYPE_ID_STRING, 8);
392 return ft;
393}
394
395static inline
396struct ctf_field_type_enum *ctf_field_type_enum_create(void)
397{
398 struct ctf_field_type_enum *ft = g_new0(struct ctf_field_type_enum, 1);
399
400 BT_ASSERT(ft);
401 _ctf_field_type_int_init((void *) ft, CTF_FIELD_TYPE_ID_ENUM);
402 ft->mappings = g_array_new(FALSE, TRUE,
403 sizeof(struct ctf_field_type_enum_mapping));
404 BT_ASSERT(ft->mappings);
405 return ft;
406}
407
408static inline
409struct ctf_field_type_struct *ctf_field_type_struct_create(void)
410{
411 struct ctf_field_type_struct *ft =
412 g_new0(struct ctf_field_type_struct, 1);
413
414 BT_ASSERT(ft);
415 _ctf_field_type_init((void *) ft, CTF_FIELD_TYPE_ID_STRUCT, 1);
416 ft->members = g_array_new(FALSE, TRUE,
417 sizeof(struct ctf_named_field_type));
418 BT_ASSERT(ft->members);
419 ft->base.is_compound = true;
420 return ft;
421}
422
423static inline
424struct ctf_field_type_variant *ctf_field_type_variant_create(void)
425{
426 struct ctf_field_type_variant *ft =
427 g_new0(struct ctf_field_type_variant, 1);
428
429 BT_ASSERT(ft);
430 _ctf_field_type_init((void *) ft, CTF_FIELD_TYPE_ID_VARIANT, 1);
431 ft->options = g_array_new(FALSE, TRUE,
432 sizeof(struct ctf_named_field_type));
433 BT_ASSERT(ft->options);
434 ft->ranges = g_array_new(FALSE, TRUE,
435 sizeof(struct ctf_field_type_variant_range));
436 BT_ASSERT(ft->ranges);
437 ft->tag_ref = g_string_new(NULL);
438 BT_ASSERT(ft->tag_ref);
439 ctf_field_path_init(&ft->tag_path);
440 ft->base.is_compound = true;
441 return ft;
442}
443
444static inline
445struct ctf_field_type_array *ctf_field_type_array_create(void)
446{
447 struct ctf_field_type_array *ft =
448 g_new0(struct ctf_field_type_array, 1);
449
450 BT_ASSERT(ft);
451 _ctf_field_type_init((void *) ft, CTF_FIELD_TYPE_ID_ARRAY, 1);
452 ft->base.base.is_compound = true;
453 return ft;
454}
455
456static inline
457struct ctf_field_type_sequence *ctf_field_type_sequence_create(void)
458{
459 struct ctf_field_type_sequence *ft =
460 g_new0(struct ctf_field_type_sequence, 1);
461
462 BT_ASSERT(ft);
463 _ctf_field_type_init((void *) ft, CTF_FIELD_TYPE_ID_SEQUENCE, 1);
464 ft->length_ref = g_string_new(NULL);
465 BT_ASSERT(ft->length_ref);
466 ctf_field_path_init(&ft->length_path);
467 ft->base.base.is_compound = true;
468 return ft;
469}
470
471static inline
472void _ctf_field_type_int_destroy(struct ctf_field_type_int *ft)
473{
474 BT_ASSERT(ft);
475 bt_put(ft->mapped_clock_class);
476 g_free(ft);
477}
478
479static inline
480void _ctf_field_type_enum_destroy(struct ctf_field_type_enum *ft)
481{
482 BT_ASSERT(ft);
483 bt_put(ft->base.mapped_clock_class);
484
485 if (ft->mappings) {
486 uint64_t i;
487
488 for (i = 0; i < ft->mappings->len; i++) {
489 struct ctf_field_type_enum_mapping *mapping =
490 &g_array_index(ft->mappings,
491 struct ctf_field_type_enum_mapping, i);
492
493 _ctf_field_type_enum_mapping_fini(mapping);
494 }
495
496 g_array_free(ft->mappings, TRUE);
497 }
498
499 g_free(ft);
500}
501
502static inline
503void _ctf_field_type_float_destroy(struct ctf_field_type_float *ft)
504{
505 BT_ASSERT(ft);
506 g_free(ft);
507}
508
509static inline
510void _ctf_field_type_string_destroy(struct ctf_field_type_string *ft)
511{
512 BT_ASSERT(ft);
513 g_free(ft);
514}
515
516static inline
517void _ctf_field_type_struct_destroy(struct ctf_field_type_struct *ft)
518{
519 BT_ASSERT(ft);
520
521 if (ft->members) {
522 uint64_t i;
523
524 for (i = 0; i < ft->members->len; i++) {
525 struct ctf_named_field_type *named_ft =
526 &g_array_index(ft->members,
527 struct ctf_named_field_type, i);
528
529 _ctf_named_field_type_fini(named_ft);
530 }
531
532 g_array_free(ft->members, TRUE);
533 }
534
535 g_free(ft);
536}
537
538static inline
539void _ctf_field_type_array_base_fini(struct ctf_field_type_array_base *ft)
540{
541 BT_ASSERT(ft);
542 ctf_field_type_destroy(ft->elem_ft);
543}
544
545static inline
546void _ctf_field_type_array_destroy(struct ctf_field_type_array *ft)
547{
548 BT_ASSERT(ft);
549 _ctf_field_type_array_base_fini((void *) ft);
550 g_free(ft);
551}
552
553static inline
554void _ctf_field_type_sequence_destroy(struct ctf_field_type_sequence *ft)
555{
556 BT_ASSERT(ft);
557 _ctf_field_type_array_base_fini((void *) ft);
558
559 if (ft->length_ref) {
560 g_string_free(ft->length_ref, TRUE);
561 }
562
563 ctf_field_path_fini(&ft->length_path);
564 g_free(ft);
565}
566
567static inline
568void _ctf_field_type_variant_destroy(struct ctf_field_type_variant *ft)
569{
570 BT_ASSERT(ft);
571
572 if (ft->options) {
573 uint64_t i;
574
575 for (i = 0; i < ft->options->len; i++) {
576 struct ctf_named_field_type *named_ft =
577 &g_array_index(ft->options,
578 struct ctf_named_field_type, i);
579
580 _ctf_named_field_type_fini(named_ft);
581 }
582
583 g_array_free(ft->options, TRUE);
584 }
585
586 if (ft->ranges) {
587 g_array_free(ft->ranges, TRUE);
588 }
589
590 if (ft->tag_ref) {
591 g_string_free(ft->tag_ref, TRUE);
592 }
593
594 ctf_field_path_fini(&ft->tag_path);
595 g_free(ft);
596}
597
598static inline
599void ctf_field_type_destroy(struct ctf_field_type *ft)
600{
601 if (!ft) {
602 return;
603 }
604
605 switch (ft->id) {
606 case CTF_FIELD_TYPE_ID_INT:
607 _ctf_field_type_int_destroy((void *) ft);
608 break;
609 case CTF_FIELD_TYPE_ID_ENUM:
610 _ctf_field_type_enum_destroy((void *) ft);
611 break;
612 case CTF_FIELD_TYPE_ID_FLOAT:
613 _ctf_field_type_float_destroy((void *) ft);
614 break;
615 case CTF_FIELD_TYPE_ID_STRING:
616 _ctf_field_type_string_destroy((void *) ft);
617 break;
618 case CTF_FIELD_TYPE_ID_STRUCT:
619 _ctf_field_type_struct_destroy((void *) ft);
620 break;
621 case CTF_FIELD_TYPE_ID_ARRAY:
622 _ctf_field_type_array_destroy((void *) ft);
623 break;
624 case CTF_FIELD_TYPE_ID_SEQUENCE:
625 _ctf_field_type_sequence_destroy((void *) ft);
626 break;
627 case CTF_FIELD_TYPE_ID_VARIANT:
628 _ctf_field_type_variant_destroy((void *) ft);
629 break;
630 default:
631 abort();
632 }
633}
634
635static inline
636void ctf_field_type_enum_append_mapping(struct ctf_field_type_enum *ft,
637 const char *label, uint64_t u_lower, uint64_t u_upper)
638{
639 struct ctf_field_type_enum_mapping *mapping;
640
641 BT_ASSERT(ft);
642 BT_ASSERT(label);
643 g_array_set_size(ft->mappings, ft->mappings->len + 1);
644
645 mapping = &g_array_index(ft->mappings,
646 struct ctf_field_type_enum_mapping, ft->mappings->len - 1);
647 _ctf_field_type_enum_mapping_init(mapping);
648 g_string_assign(mapping->label, label);
649 mapping->range.lower.u = u_lower;
650 mapping->range.upper.u = u_upper;
651}
652
653static inline
654struct ctf_field_type_enum_mapping *ctf_field_type_enum_borrow_mapping_by_index(
655 struct ctf_field_type_enum *ft, uint64_t index)
656{
657 BT_ASSERT(ft);
658 BT_ASSERT(index < ft->mappings->len);
659 return &g_array_index(ft->mappings, struct ctf_field_type_enum_mapping,
660 index);
661}
662
663static inline
664struct ctf_named_field_type *ctf_field_type_struct_borrow_member_by_index(
665 struct ctf_field_type_struct *ft, uint64_t index)
666{
667 BT_ASSERT(ft);
668 BT_ASSERT(index < ft->members->len);
669 return &g_array_index(ft->members, struct ctf_named_field_type,
670 index);
671}
672
673static inline
674struct ctf_named_field_type *ctf_field_type_struct_borrow_member_by_name(
675 struct ctf_field_type_struct *ft, const char *name)
676{
677 uint64_t i;
678 struct ctf_named_field_type *ret_named_ft = NULL;
679
680 BT_ASSERT(ft);
681 BT_ASSERT(name);
682
683 for (i = 0; i < ft->members->len; i++) {
684 struct ctf_named_field_type *named_ft =
685 ctf_field_type_struct_borrow_member_by_index(ft, i);
686
687 if (strcmp(name, named_ft->name->str) == 0) {
688 ret_named_ft = named_ft;
689 goto end;
690 }
691 }
692
693end:
694 return ret_named_ft;
695}
696
697static inline
698struct ctf_field_type *ctf_field_type_struct_borrow_member_field_type_by_name(
699 struct ctf_field_type_struct *struct_ft, const char *name)
700{
701 struct ctf_named_field_type *named_ft = NULL;
702 struct ctf_field_type *ft = NULL;
703
704 if (!struct_ft) {
705 goto end;
706 }
707
708 named_ft = ctf_field_type_struct_borrow_member_by_name(struct_ft, name);
709 if (!named_ft) {
710 goto end;
711 }
712
713 ft = named_ft->ft;
714
715end:
716 return ft;
717}
718
719static inline
720struct ctf_field_type_int *
721ctf_field_type_struct_borrow_member_int_field_type_by_name(
722 struct ctf_field_type_struct *struct_ft, const char *name)
723{
724 struct ctf_field_type_int *int_ft = NULL;
725
726 int_ft = (void *)
727 ctf_field_type_struct_borrow_member_field_type_by_name(
728 struct_ft, name);
729 if (!int_ft) {
730 goto end;
731 }
732
733 if (int_ft->base.base.id != CTF_FIELD_TYPE_ID_INT &&
734 int_ft->base.base.id != CTF_FIELD_TYPE_ID_ENUM) {
735 int_ft = NULL;
736 goto end;
737 }
738
739end:
740 return int_ft;
741}
742
743
744static inline
745void ctf_field_type_struct_append_member(struct ctf_field_type_struct *ft,
746 const char *name, struct ctf_field_type *member_ft)
747{
748 struct ctf_named_field_type *named_ft;
749
750 BT_ASSERT(ft);
751 BT_ASSERT(name);
752 g_array_set_size(ft->members, ft->members->len + 1);
753
754 named_ft = &g_array_index(ft->members, struct ctf_named_field_type,
755 ft->members->len - 1);
756 _ctf_named_field_type_init(named_ft);
757 g_string_assign(named_ft->name, name);
758 named_ft->ft = member_ft;
759
760 if (member_ft->alignment > ft->base.alignment) {
761 ft->base.alignment = member_ft->alignment;
762 }
763}
764
765static inline
766struct ctf_named_field_type *ctf_field_type_variant_borrow_option_by_index(
767 struct ctf_field_type_variant *ft, uint64_t index)
768{
769 BT_ASSERT(ft);
770 BT_ASSERT(index < ft->options->len);
771 return &g_array_index(ft->options, struct ctf_named_field_type,
772 index);
773}
774
775static inline
776struct ctf_named_field_type *ctf_field_type_variant_borrow_option_by_name(
777 struct ctf_field_type_variant *ft, const char *name)
778{
779 uint64_t i;
780 struct ctf_named_field_type *ret_named_ft = NULL;
781
782 BT_ASSERT(ft);
783 BT_ASSERT(name);
784
785 for (i = 0; i < ft->options->len; i++) {
786 struct ctf_named_field_type *named_ft =
787 ctf_field_type_variant_borrow_option_by_index(ft, i);
788
789 if (strcmp(name, named_ft->name->str) == 0) {
790 ret_named_ft = named_ft;
791 goto end;
792 }
793 }
794
795end:
796 return ret_named_ft;
797}
798
799static inline
800struct ctf_field_type_variant_range *
801ctf_field_type_variant_borrow_range_by_index(
802 struct ctf_field_type_variant *ft, uint64_t index)
803{
804 BT_ASSERT(ft);
805 BT_ASSERT(index < ft->ranges->len);
806 return &g_array_index(ft->ranges, struct ctf_field_type_variant_range,
807 index);
808}
809
810static inline
811void ctf_field_type_variant_append_option(struct ctf_field_type_variant *ft,
812 const char *name, struct ctf_field_type *option_ft)
813{
814 struct ctf_named_field_type *named_ft;
815
816 BT_ASSERT(ft);
817 BT_ASSERT(name);
818 g_array_set_size(ft->options, ft->options->len + 1);
819
820 named_ft = &g_array_index(ft->options, struct ctf_named_field_type,
821 ft->options->len - 1);
822 _ctf_named_field_type_init(named_ft);
823 g_string_assign(named_ft->name, name);
824 named_ft->ft = option_ft;
825}
826
827static inline
828void ctf_field_type_variant_set_tag_field_type(
829 struct ctf_field_type_variant *ft,
830 struct ctf_field_type_enum *tag_ft)
831{
832 uint64_t option_i;
833
834 BT_ASSERT(ft);
835 BT_ASSERT(tag_ft);
836 ft->tag_ft = tag_ft;
837
838 for (option_i = 0; option_i < ft->options->len; option_i++) {
839 uint64_t mapping_i;
840 struct ctf_named_field_type *named_ft =
841 ctf_field_type_variant_borrow_option_by_index(
842 ft, option_i);
843
844 for (mapping_i = 0; mapping_i < tag_ft->mappings->len;
845 mapping_i++) {
846 struct ctf_field_type_enum_mapping *mapping =
847 ctf_field_type_enum_borrow_mapping_by_index(
848 tag_ft, mapping_i);
849
850 if (strcmp(named_ft->name->str,
851 mapping->label->str) == 0) {
852 struct ctf_field_type_variant_range range;
853
854 range.range = mapping->range;
855 range.option_index = option_i;
856 g_array_append_val(ft->ranges, range);
857 }
858 }
859 }
860}
861
862static inline
863struct ctf_field_type *ctf_field_type_compound_borrow_field_type_by_index(
864 struct ctf_field_type *comp_ft, uint64_t index)
865{
866 struct ctf_field_type *ft = NULL;
867
868 switch (comp_ft->id) {
869 case CTF_FIELD_TYPE_ID_STRUCT:
870 {
871 struct ctf_named_field_type *named_ft =
872 ctf_field_type_struct_borrow_member_by_index(
873 (void *) comp_ft, index);
874
875 BT_ASSERT(named_ft);
876 ft = named_ft->ft;
877 break;
878 }
879 case CTF_FIELD_TYPE_ID_VARIANT:
880 {
881 struct ctf_named_field_type *named_ft =
882 ctf_field_type_variant_borrow_option_by_index(
883 (void *) comp_ft, index);
884
885 BT_ASSERT(named_ft);
886 ft = named_ft->ft;
887 break;
888 }
889 case CTF_FIELD_TYPE_ID_ARRAY:
890 case CTF_FIELD_TYPE_ID_SEQUENCE:
891 {
892 struct ctf_field_type_array_base *array_ft = (void *) comp_ft;
893
894 ft = array_ft->elem_ft;
895 break;
896 }
897 default:
898 break;
899 }
900
901 return ft;
902}
903
904static inline
905uint64_t ctf_field_type_compound_get_field_type_count(struct ctf_field_type *ft)
906{
907 uint64_t field_count;
908
909 switch (ft->id) {
910 case CTF_FIELD_TYPE_ID_STRUCT:
911 {
912 struct ctf_field_type_struct *struct_ft = (void *) ft;
913
914 field_count = struct_ft->members->len;
915 break;
916 }
917 case CTF_FIELD_TYPE_ID_VARIANT:
918 {
919 struct ctf_field_type_variant *var_ft = (void *) ft;
920
921 field_count = var_ft->options->len;
922 break;
923 }
924 case CTF_FIELD_TYPE_ID_ARRAY:
925 case CTF_FIELD_TYPE_ID_SEQUENCE:
926 /*
927 * Array and sequence types always contain a single
928 * member (the element type).
929 */
930 field_count = 1;
931 break;
932 default:
933 abort();
934 }
935
936 return field_count;
937}
938
939static inline
940int64_t ctf_field_type_compound_get_field_type_index_from_name(
941 struct ctf_field_type *ft, const char *name)
942{
943 int64_t ret_index = -1;
944 uint64_t i;
945
946 switch (ft->id) {
947 case CTF_FIELD_TYPE_ID_STRUCT:
948 {
949 struct ctf_field_type_struct *struct_ft = (void *) ft;
950
951 for (i = 0; i < struct_ft->members->len; i++) {
952 struct ctf_named_field_type *named_ft =
953 ctf_field_type_struct_borrow_member_by_index(
954 struct_ft, i);
955
956 if (strcmp(name, named_ft->name->str) == 0) {
957 ret_index = (int64_t) i;
958 goto end;
959 }
960 }
961
962 break;
963 }
964 case CTF_FIELD_TYPE_ID_VARIANT:
965 {
966 struct ctf_field_type_variant *var_ft = (void *) ft;
967
968 for (i = 0; i < var_ft->options->len; i++) {
969 struct ctf_named_field_type *named_ft =
970 ctf_field_type_variant_borrow_option_by_index(
971 var_ft, i);
972
973 if (strcmp(name, named_ft->name->str) == 0) {
974 ret_index = (int64_t) i;
975 goto end;
976 }
977 }
978
979 break;
980 }
981 default:
982 break;
983 }
984
985end:
986 return ret_index;
987}
988
989static inline
990void ctf_field_path_append_index(struct ctf_field_path *fp, int64_t index)
991{
992 BT_ASSERT(fp);
993 g_array_append_val(fp->path, index);
994}
995
996static inline
997int64_t ctf_field_path_borrow_index_by_index(struct ctf_field_path *fp,
998 uint64_t index)
999{
1000 BT_ASSERT(fp);
1001 BT_ASSERT(index < fp->path->len);
1002 return g_array_index(fp->path, int64_t, index);
1003}
1004
1005static inline
1006void ctf_field_path_clear(struct ctf_field_path *fp)
1007{
1008 BT_ASSERT(fp);
1009 g_array_set_size(fp->path, 0);
1010}
1011
1012static inline
1013GString *ctf_field_path_string(struct ctf_field_path *path)
1014{
1015 GString *str = g_string_new(NULL);
1016 uint64_t i;
1017
1018 BT_ASSERT(path);
1019
1020 if (!str) {
1021 goto end;
1022 }
1023
1024 g_string_append_printf(str, "[%s", bt_common_scope_string(
1025 path->root));
1026
1027 for (i = 0; i < path->path->len; i++) {
1028 g_string_append_printf(str, ", %" PRId64,
1029 ctf_field_path_borrow_index_by_index(path, i));
1030 }
1031
1032 g_string_append(str, "]");
1033
1034end:
1035 return str;
1036}
1037
1038static inline
1039struct ctf_field_type *ctf_field_path_borrow_field_type(
1040 struct ctf_field_path *field_path,
1041 struct ctf_trace_class *tc,
1042 struct ctf_stream_class *sc,
1043 struct ctf_event_class *ec)
1044{
1045 uint64_t i;
1046 struct ctf_field_type *ft;
1047
1048 switch (field_path->root) {
1049 case BT_SCOPE_PACKET_HEADER:
1050 ft = tc->packet_header_ft;
1051 break;
1052 case BT_SCOPE_PACKET_CONTEXT:
1053 ft = sc->packet_context_ft;
1054 break;
1055 case BT_SCOPE_EVENT_HEADER:
1056 ft = sc->event_header_ft;
1057 break;
1058 case BT_SCOPE_EVENT_COMMON_CONTEXT:
1059 ft = sc->event_common_context_ft;
1060 break;
1061 case BT_SCOPE_EVENT_SPECIFIC_CONTEXT:
1062 ft = ec->spec_context_ft;
1063 break;
1064 case BT_SCOPE_EVENT_PAYLOAD:
1065 ft = ec->payload_ft;
1066 break;
1067 default:
1068 abort();
1069 }
1070
1071 BT_ASSERT(ft);
1072
1073 for (i = 0; i < field_path->path->len; i++) {
1074 int64_t child_index =
1075 ctf_field_path_borrow_index_by_index(field_path, i);
1076 struct ctf_field_type *child_ft =
1077 ctf_field_type_compound_borrow_field_type_by_index(
1078 ft, child_index);
1079 BT_ASSERT(child_ft);
1080 ft = child_ft;
1081 }
1082
1083 BT_ASSERT(ft);
1084 return ft;
1085}
1086
1087static inline
1088struct ctf_field_type *ctf_field_type_copy(struct ctf_field_type *ft);
1089
1090static inline
1091void ctf_field_type_bit_array_copy_content(
1092 struct ctf_field_type_bit_array *dst_ft,
1093 struct ctf_field_type_bit_array *src_ft)
1094{
1095 BT_ASSERT(dst_ft);
1096 BT_ASSERT(src_ft);
1097 dst_ft->byte_order = src_ft->byte_order;
1098 dst_ft->size = src_ft->size;
1099}
1100
1101static inline
1102void ctf_field_type_int_copy_content(
1103 struct ctf_field_type_int *dst_ft,
1104 struct ctf_field_type_int *src_ft)
1105{
1106 ctf_field_type_bit_array_copy_content((void *) dst_ft, (void *) src_ft);
1107 dst_ft->meaning = src_ft->meaning;
1108 dst_ft->is_signed = src_ft->is_signed;
1109 dst_ft->disp_base = src_ft->disp_base;
1110 dst_ft->encoding = src_ft->encoding;
1111 dst_ft->mapped_clock_class = bt_get(src_ft->mapped_clock_class);
1112 dst_ft->storing_index = src_ft->storing_index;
1113}
1114
1115static inline
1116struct ctf_field_type_int *_ctf_field_type_int_copy(
1117 struct ctf_field_type_int *ft)
1118{
1119 struct ctf_field_type_int *copy_ft = ctf_field_type_int_create();
1120
1121 BT_ASSERT(copy_ft);
1122 ctf_field_type_int_copy_content(copy_ft, ft);
1123 return copy_ft;
1124}
1125
1126static inline
1127struct ctf_field_type_enum *_ctf_field_type_enum_copy(
1128 struct ctf_field_type_enum *ft)
1129{
1130 struct ctf_field_type_enum *copy_ft = ctf_field_type_enum_create();
1131 uint64_t i;
1132
1133 BT_ASSERT(copy_ft);
1134 ctf_field_type_int_copy_content((void *) copy_ft, (void *) ft);
1135
1136 for (i = 0; i < ft->mappings->len; i++) {
1137 struct ctf_field_type_enum_mapping *mapping =
1138 &g_array_index(ft->mappings,
1139 struct ctf_field_type_enum_mapping, i);
1140
1141 ctf_field_type_enum_append_mapping(copy_ft, mapping->label->str,
1142 mapping->range.lower.u, mapping->range.upper.u);
1143 }
1144
1145 return copy_ft;
1146}
1147
1148static inline
1149struct ctf_field_type_float *_ctf_field_type_float_copy(
1150 struct ctf_field_type_float *ft)
1151{
1152 struct ctf_field_type_float *copy_ft = ctf_field_type_float_create();
1153
1154 BT_ASSERT(copy_ft);
1155 ctf_field_type_bit_array_copy_content((void *) copy_ft, (void *) ft);
1156 return copy_ft;
1157}
1158
1159static inline
1160struct ctf_field_type_string *_ctf_field_type_string_copy(
1161 struct ctf_field_type_string *ft)
1162{
1163 struct ctf_field_type_string *copy_ft = ctf_field_type_string_create();
1164
1165 BT_ASSERT(copy_ft);
1166 return copy_ft;
1167}
1168
1169static inline
1170struct ctf_field_type_struct *_ctf_field_type_struct_copy(
1171 struct ctf_field_type_struct *ft)
1172{
1173 struct ctf_field_type_struct *copy_ft = ctf_field_type_struct_create();
1174 uint64_t i;
1175
1176 BT_ASSERT(copy_ft);
1177
1178 for (i = 0; i < ft->members->len; i++) {
1179 struct ctf_named_field_type *named_ft =
1180 &g_array_index(ft->members,
1181 struct ctf_named_field_type, i);
1182
1183 ctf_field_type_struct_append_member(copy_ft,
1184 named_ft->name->str,
1185 ctf_field_type_copy(named_ft->ft));
1186 }
1187
1188 return copy_ft;
1189}
1190
1191static inline
1192void ctf_field_path_copy_content(struct ctf_field_path *dst_fp,
1193 struct ctf_field_path *src_fp)
1194{
1195 uint64_t i;
1196
1197 BT_ASSERT(dst_fp);
1198 BT_ASSERT(src_fp);
1199 dst_fp->root = src_fp->root;
1200 ctf_field_path_clear(dst_fp);
1201
1202 for (i = 0; i < src_fp->path->len; i++) {
1203 int64_t index = ctf_field_path_borrow_index_by_index(
1204 src_fp, i);
1205
1206 ctf_field_path_append_index(dst_fp, index);
1207 }
1208}
1209
1210static inline
1211struct ctf_field_type_variant *_ctf_field_type_variant_copy(
1212 struct ctf_field_type_variant *ft)
1213{
1214 struct ctf_field_type_variant *copy_ft =
1215 ctf_field_type_variant_create();
1216 uint64_t i;
1217
1218 BT_ASSERT(copy_ft);
1219
1220 for (i = 0; i < ft->options->len; i++) {
1221 struct ctf_named_field_type *named_ft =
1222 &g_array_index(ft->options,
1223 struct ctf_named_field_type, i);
1224
1225 ctf_field_type_variant_append_option(copy_ft,
1226 named_ft->name->str,
1227 ctf_field_type_copy(named_ft->ft));
1228 }
1229
1230 for (i = 0; i < ft->ranges->len; i++) {
1231 struct ctf_field_type_variant_range *range =
1232 &g_array_index(ft->ranges,
1233 struct ctf_field_type_variant_range, i);
1234
1235 g_array_append_val(copy_ft->ranges, *range);
1236 }
1237
1238 ctf_field_path_copy_content(&copy_ft->tag_path, &ft->tag_path);
1239 g_string_assign(copy_ft->tag_ref, ft->tag_ref->str);
1240 copy_ft->stored_tag_index = ft->stored_tag_index;
1241 return copy_ft;
1242}
1243
1244static inline
1245void ctf_field_type_array_base_copy_content(
1246 struct ctf_field_type_array_base *dst_ft,
1247 struct ctf_field_type_array_base *src_ft)
1248{
1249 BT_ASSERT(dst_ft);
1250 BT_ASSERT(src_ft);
1251 dst_ft->elem_ft = ctf_field_type_copy(src_ft->elem_ft);
1252 dst_ft->is_text = src_ft->is_text;
1253}
1254
1255static inline
1256struct ctf_field_type_array *_ctf_field_type_array_copy(
1257 struct ctf_field_type_array *ft)
1258{
1259 struct ctf_field_type_array *copy_ft = ctf_field_type_array_create();
1260
1261 BT_ASSERT(copy_ft);
1262 ctf_field_type_array_base_copy_content((void *) copy_ft, (void *) ft);
1263 copy_ft->length = ft->length;
1264 return copy_ft;
1265}
1266
1267static inline
1268struct ctf_field_type_sequence *_ctf_field_type_sequence_copy(
1269 struct ctf_field_type_sequence *ft)
1270{
1271 struct ctf_field_type_sequence *copy_ft =
1272 ctf_field_type_sequence_create();
1273
1274 BT_ASSERT(copy_ft);
1275 ctf_field_type_array_base_copy_content((void *) copy_ft, (void *) ft);
1276 ctf_field_path_copy_content(&copy_ft->length_path, &ft->length_path);
1277 g_string_assign(copy_ft->length_ref, ft->length_ref->str);
1278 copy_ft->stored_length_index = ft->stored_length_index;
1279 return copy_ft;
1280}
1281
1282static inline
1283struct ctf_field_type *ctf_field_type_copy(struct ctf_field_type *ft)
1284{
1285 struct ctf_field_type *copy_ft = NULL;
1286
1287 if (!ft) {
1288 goto end;
1289 }
1290
1291 /*
1292 * Translation should not have happened yet.
1293 */
1294 BT_ASSERT(!ft->ir_ft);
1295
1296 switch (ft->id) {
1297 case CTF_FIELD_TYPE_ID_INT:
1298 copy_ft = (void *) _ctf_field_type_int_copy((void *) ft);
1299 break;
1300 case CTF_FIELD_TYPE_ID_ENUM:
1301 copy_ft = (void *) _ctf_field_type_enum_copy((void *) ft);
1302 break;
1303 case CTF_FIELD_TYPE_ID_FLOAT:
1304 copy_ft = (void *) _ctf_field_type_float_copy((void *) ft);
1305 break;
1306 case CTF_FIELD_TYPE_ID_STRING:
1307 copy_ft = (void *) _ctf_field_type_string_copy((void *) ft);
1308 break;
1309 case CTF_FIELD_TYPE_ID_STRUCT:
1310 copy_ft = (void *) _ctf_field_type_struct_copy((void *) ft);
1311 break;
1312 case CTF_FIELD_TYPE_ID_ARRAY:
1313 copy_ft = (void *) _ctf_field_type_array_copy((void *) ft);
1314 break;
1315 case CTF_FIELD_TYPE_ID_SEQUENCE:
1316 copy_ft = (void *) _ctf_field_type_sequence_copy((void *) ft);
1317 break;
1318 case CTF_FIELD_TYPE_ID_VARIANT:
1319 copy_ft = (void *) _ctf_field_type_variant_copy((void *) ft);
1320 break;
1321 default:
1322 abort();
1323 }
1324
1325 copy_ft->id = ft->id;
1326 copy_ft->alignment = ft->alignment;
1327 copy_ft->in_ir = ft->in_ir;
1328
1329end:
1330 return copy_ft;
1331}
1332
1333static inline
1334struct ctf_event_class *ctf_event_class_create(void)
1335{
1336 struct ctf_event_class *ec = g_new0(struct ctf_event_class, 1);
1337
1338 BT_ASSERT(ec);
1339 ec->name = g_string_new(NULL);
1340 BT_ASSERT(ec->name);
1341 ec->emf_uri = g_string_new(NULL);
1342 BT_ASSERT(ec->emf_uri);
1343 ec->log_level = -1;
1344 return ec;
1345}
1346
1347static inline
1348void ctf_event_class_destroy(struct ctf_event_class *ec)
1349{
1350 if (!ec) {
1351 return;
1352 }
1353
1354 if (ec->name) {
1355 g_string_free(ec->name, TRUE);
1356 }
1357
1358 if (ec->emf_uri) {
1359 g_string_free(ec->emf_uri, TRUE);
1360 }
1361
1362 ctf_field_type_destroy(ec->spec_context_ft);
1363 ctf_field_type_destroy(ec->payload_ft);
1364 g_free(ec);
1365}
1366
1367static inline
1368struct ctf_stream_class *ctf_stream_class_create(void)
1369{
1370 struct ctf_stream_class *sc = g_new0(struct ctf_stream_class, 1);
1371
1372 BT_ASSERT(sc);
1373 sc->event_classes = g_ptr_array_new_with_free_func(
1374 (GDestroyNotify) ctf_event_class_destroy);
1375 BT_ASSERT(sc->event_classes);
1376 sc->event_classes_by_id = g_hash_table_new(g_direct_hash,
1377 g_direct_equal);
1378 BT_ASSERT(sc->event_classes_by_id);
1379 return sc;
1380}
1381
1382static inline
1383void ctf_stream_class_destroy(struct ctf_stream_class *sc)
1384{
1385 if (!sc) {
1386 return;
1387 }
1388
1389 if (sc->event_classes) {
1390 g_ptr_array_free(sc->event_classes, TRUE);
1391 }
1392
1393 if (sc->event_classes_by_id) {
1394 g_hash_table_destroy(sc->event_classes_by_id);
1395 }
1396
1397 ctf_field_type_destroy(sc->packet_context_ft);
1398 ctf_field_type_destroy(sc->event_header_ft);
1399 ctf_field_type_destroy(sc->event_common_context_ft);
1400 bt_put(sc->default_clock_class);
1401 g_free(sc);
1402}
1403
1404static inline
1405void ctf_stream_class_append_event_class(struct ctf_stream_class *sc,
1406 struct ctf_event_class *ec)
1407{
1408 g_ptr_array_add(sc->event_classes, ec);
1409 g_hash_table_insert(sc->event_classes_by_id,
1410 GUINT_TO_POINTER((guint) ec->id), ec);
1411}
1412
1413static inline
1414struct ctf_event_class *ctf_stream_class_borrow_event_class_by_id(
1415 struct ctf_stream_class *sc, uint64_t id)
1416{
1417 BT_ASSERT(sc);
1418 return g_hash_table_lookup(sc->event_classes_by_id,
1419 GUINT_TO_POINTER((guint) id));
1420}
1421
1422static inline
1423void _ctf_trace_class_env_entry_init(struct ctf_trace_class_env_entry *entry)
1424{
1425 BT_ASSERT(entry);
1426 entry->name = g_string_new(NULL);
1427 BT_ASSERT(entry->name);
1428 entry->value.str = g_string_new(NULL);
1429 BT_ASSERT(entry->value.str);
1430}
1431
1432static inline
1433void _ctf_trace_class_env_entry_fini(struct ctf_trace_class_env_entry *entry)
1434{
1435 BT_ASSERT(entry);
1436
1437 if (entry->name) {
1438 g_string_free(entry->name, TRUE);
1439 }
1440
1441 if (entry->value.str) {
1442 g_string_free(entry->value.str, TRUE);
1443 }
1444}
1445
1446static inline
1447struct ctf_trace_class *ctf_trace_class_create(void)
1448{
1449 struct ctf_trace_class *tc = g_new0(struct ctf_trace_class, 1);
1450
1451 BT_ASSERT(tc);
1452 tc->name = g_string_new(NULL);
1453 tc->default_byte_order = -1;
1454 BT_ASSERT(tc->name);
1455 tc->clock_classes = g_ptr_array_new_with_free_func(
1456 (GDestroyNotify) bt_put);
1457 BT_ASSERT(tc->clock_classes);
1458 tc->stream_classes = g_ptr_array_new_with_free_func(
1459 (GDestroyNotify) ctf_stream_class_destroy);
1460 BT_ASSERT(tc->stream_classes);
1461 tc->env_entries = g_array_new(FALSE, TRUE,
1462 sizeof(struct ctf_trace_class_env_entry));
1463 return tc;
1464}
1465
1466static inline
1467void ctf_trace_class_destroy(struct ctf_trace_class *tc)
1468{
1469 if (!tc) {
1470 return;
1471 }
1472
1473 if (tc->name) {
1474 g_string_free(tc->name, TRUE);
1475 }
1476
1477 ctf_field_type_destroy(tc->packet_header_ft);
1478
1479 if (tc->clock_classes) {
1480 g_ptr_array_free(tc->clock_classes, TRUE);
1481 }
1482
1483 if (tc->stream_classes) {
1484 g_ptr_array_free(tc->stream_classes, TRUE);
1485 }
1486
1487 if (tc->env_entries) {
1488 uint64_t i;
1489
1490 for (i = 0; i < tc->env_entries->len; i++) {
1491 struct ctf_trace_class_env_entry *entry =
1492 &g_array_index(tc->env_entries,
1493 struct ctf_trace_class_env_entry, i);
1494
1495 _ctf_trace_class_env_entry_fini(entry);
1496 }
1497
1498 g_array_free(tc->env_entries, TRUE);
1499 }
1500
1501 g_free(tc);
1502}
1503
1504static inline
1505void ctf_trace_class_append_env_entry(struct ctf_trace_class *tc,
1506 const char *name, enum ctf_trace_class_env_entry_type type,
1507 const char *str_value, int64_t i_value)
1508{
1509 struct ctf_trace_class_env_entry *entry;
1510
1511 BT_ASSERT(tc);
1512 BT_ASSERT(name);
1513 g_array_set_size(tc->env_entries, tc->env_entries->len + 1);
1514
1515 entry = &g_array_index(tc->env_entries,
1516 struct ctf_trace_class_env_entry, tc->env_entries->len - 1);
1517 entry->type = type;
1518 _ctf_trace_class_env_entry_init(entry);
1519 g_string_assign(entry->name, name);
1520
1521 if (str_value) {
1522 g_string_assign(entry->value.str, str_value);
1523 }
1524
1525 entry->value.i = i_value;
1526}
1527
1528static inline
1529struct ctf_stream_class *ctf_trace_class_borrow_stream_class_by_id(
1530 struct ctf_trace_class *tc, uint64_t id)
1531{
1532 uint64_t i;
1533 struct ctf_stream_class *ret_sc = NULL;
1534
1535 BT_ASSERT(tc);
1536
1537 for (i = 0; i < tc->stream_classes->len; i++) {
1538 struct ctf_stream_class *sc = tc->stream_classes->pdata[i];
1539
1540 if (sc->id == id) {
1541 ret_sc = sc;
1542 goto end;
1543 }
1544 }
1545
1546end:
1547 return ret_sc;
1548}
1549
1550static inline
1551struct bt_clock_class *ctf_trace_class_borrow_clock_class_by_name(
1552 struct ctf_trace_class *tc, const char *name)
1553{
1554 uint64_t i;
1555 struct bt_clock_class *ret_cc = NULL;
1556
1557 BT_ASSERT(tc);
1558 BT_ASSERT(name);
1559
1560 for (i = 0; i < tc->clock_classes->len; i++) {
1561 struct bt_clock_class *cc = tc->clock_classes->pdata[i];
1562 const char *cc_name = bt_clock_class_get_name(cc);
1563
1564 BT_ASSERT(cc_name);
1565 if (strcmp(cc_name, name) == 0) {
1566 ret_cc = cc;
1567 goto end;
1568 }
1569 }
1570
1571end:
1572 return ret_cc;
1573}
1574
1575static inline
1576struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_index(
1577 struct ctf_trace_class *tc, uint64_t index)
1578{
1579 BT_ASSERT(tc);
1580 BT_ASSERT(index < tc->env_entries->len);
1581 return &g_array_index(tc->env_entries, struct ctf_trace_class_env_entry,
1582 index);
1583}
1584
1585static inline
1586struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_name(
1587 struct ctf_trace_class *tc, const char *name)
1588{
1589 struct ctf_trace_class_env_entry *ret_entry = NULL;
1590 uint64_t i;
1591
1592 BT_ASSERT(tc);
1593 BT_ASSERT(name);
1594
1595 for (i = 0; i < tc->env_entries->len; i++) {
1596 struct ctf_trace_class_env_entry *env_entry =
1597 ctf_trace_class_borrow_env_entry_by_index(tc, i);
1598
1599 if (strcmp(env_entry->name->str, name) == 0) {
1600 ret_entry = env_entry;
1601 goto end;
1602 }
1603 }
1604
1605end:
1606 return ret_entry;
1607}
1608
1609#endif /* _CTF_META_H */
This page took 0.082399 seconds and 4 git commands to generate.