lib: split trace API into trace class and trace APIs
[babeltrace.git] / plugins / ctf / common / metadata / ctf-meta.h
... / ...
CommitLineData
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_class_type {
26 CTF_FIELD_CLASS_TYPE_INT,
27 CTF_FIELD_CLASS_TYPE_ENUM,
28 CTF_FIELD_CLASS_TYPE_FLOAT,
29 CTF_FIELD_CLASS_TYPE_STRING,
30 CTF_FIELD_CLASS_TYPE_STRUCT,
31 CTF_FIELD_CLASS_TYPE_ARRAY,
32 CTF_FIELD_CLASS_TYPE_SEQUENCE,
33 CTF_FIELD_CLASS_TYPE_VARIANT,
34};
35
36enum ctf_field_class_meaning {
37 CTF_FIELD_CLASS_MEANING_NONE,
38 CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME,
39 CTF_FIELD_CLASS_MEANING_PACKET_END_TIME,
40 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID,
41 CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID,
42 CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID,
43 CTF_FIELD_CLASS_MEANING_MAGIC,
44 CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT,
45 CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT,
46 CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE,
47 CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE,
48 CTF_FIELD_CLASS_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_class {
63 enum ctf_field_class_type type;
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_class *ir_fc;
70};
71
72struct ctf_field_class_bit_array {
73 struct ctf_field_class base;
74 enum ctf_byte_order byte_order;
75 unsigned int size;
76};
77
78struct ctf_field_class_int {
79 struct ctf_field_class_bit_array base;
80 enum ctf_field_class_meaning meaning;
81 bool is_signed;
82 enum bt_field_class_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_class_enum_mapping {
103 GString *label;
104 struct ctf_range range;
105};
106
107struct ctf_field_class_enum {
108 struct ctf_field_class_int base;
109
110 /* Array of `struct ctf_field_class_enum_mapping` */
111 GArray *mappings;
112};
113
114struct ctf_field_class_float {
115 struct ctf_field_class_bit_array base;
116};
117
118struct ctf_field_class_string {
119 struct ctf_field_class base;
120 enum ctf_encoding encoding;
121};
122
123struct ctf_named_field_class {
124 GString *name;
125
126 /* Owned by this */
127 struct ctf_field_class *fc;
128};
129
130struct ctf_field_class_struct {
131 struct ctf_field_class base;
132
133 /* Array of `struct ctf_named_field_class` */
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_class_variant_range {
145 struct ctf_range range;
146 uint64_t option_index;
147};
148
149struct ctf_field_class_variant {
150 struct ctf_field_class 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_class` */
156 GArray *options;
157
158 /* Array of `struct ctf_field_class_variant_range` */
159 GArray *ranges;
160
161 /* Weak */
162 struct ctf_field_class_enum *tag_fc;
163};
164
165struct ctf_field_class_array_base {
166 struct ctf_field_class base;
167 struct ctf_field_class *elem_fc;
168 bool is_text;
169};
170
171struct ctf_field_class_array {
172 struct ctf_field_class_array_base base;
173 enum ctf_field_class_meaning meaning;
174 uint64_t length;
175};
176
177struct ctf_field_class_sequence {
178 struct ctf_field_class_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_class_int *length_fc;
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_class *spec_context_fc;
196
197 /* Owned by this */
198 struct ctf_field_class *payload_fc;
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_class *packet_context_fc;
210
211 /* Owned by this */
212 struct ctf_field_class *event_header_fc;
213
214 /* Owned by this */
215 struct ctf_field_class *event_common_context_fc;
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 unsigned int major;
250 unsigned int minor;
251 uint8_t uuid[16];
252 bool is_uuid_set;
253 enum ctf_byte_order default_byte_order;
254
255 /* Owned by this */
256 struct ctf_field_class *packet_header_fc;
257
258 uint64_t stored_value_count;
259
260 /* Array of `struct bt_clock_class *` (owned by this) */
261 GPtrArray *clock_classes;
262
263 /* Array of `struct ctf_stream_class *` */
264 GPtrArray *stream_classes;
265
266 /* Array of `struct ctf_trace_class_env_entry` */
267 GArray *env_entries;
268
269 bool is_translated;
270
271 /* Weak, set during translation */
272 struct bt_trace_class *ir_tc;
273};
274
275static inline
276void ctf_field_class_destroy(struct ctf_field_class *fc);
277
278static inline
279void _ctf_field_class_init(struct ctf_field_class *fc,
280 enum ctf_field_class_type type, unsigned int alignment)
281{
282 BT_ASSERT(fc);
283 fc->type = type;
284 fc->alignment = alignment;
285 fc->in_ir = false;
286}
287
288static inline
289void _ctf_field_class_bit_array_init(struct ctf_field_class_bit_array *fc,
290 enum ctf_field_class_type type)
291{
292 _ctf_field_class_init((void *) fc, type, 1);
293}
294
295static inline
296void _ctf_field_class_int_init(struct ctf_field_class_int *fc,
297 enum ctf_field_class_type type)
298{
299 _ctf_field_class_bit_array_init((void *) fc, type);
300 fc->meaning = CTF_FIELD_CLASS_MEANING_NONE;
301 fc->storing_index = -1;
302}
303
304static inline
305void ctf_field_path_init(struct ctf_field_path *field_path)
306{
307 BT_ASSERT(field_path);
308 field_path->path = g_array_new(FALSE, TRUE, sizeof(int64_t));
309 BT_ASSERT(field_path->path);
310}
311
312static inline
313void ctf_field_path_fini(struct ctf_field_path *field_path)
314{
315 BT_ASSERT(field_path);
316
317 if (field_path->path) {
318 g_array_free(field_path->path, TRUE);
319 }
320}
321
322static inline
323void _ctf_named_field_class_init(struct ctf_named_field_class *named_fc)
324{
325 BT_ASSERT(named_fc);
326 named_fc->name = g_string_new(NULL);
327 BT_ASSERT(named_fc->name);
328}
329
330static inline
331void _ctf_named_field_class_fini(struct ctf_named_field_class *named_fc)
332{
333 BT_ASSERT(named_fc);
334
335 if (named_fc->name) {
336 g_string_free(named_fc->name, TRUE);
337 }
338
339 ctf_field_class_destroy(named_fc->fc);
340}
341
342static inline
343void _ctf_field_class_enum_mapping_init(
344 struct ctf_field_class_enum_mapping *mapping)
345{
346 BT_ASSERT(mapping);
347 mapping->label = g_string_new(NULL);
348 BT_ASSERT(mapping->label);
349}
350
351static inline
352void _ctf_field_class_enum_mapping_fini(
353 struct ctf_field_class_enum_mapping *mapping)
354{
355 BT_ASSERT(mapping);
356
357 if (mapping->label) {
358 g_string_free(mapping->label, TRUE);
359 }
360}
361
362static inline
363struct ctf_field_class_int *ctf_field_class_int_create(void)
364{
365 struct ctf_field_class_int *fc = g_new0(struct ctf_field_class_int, 1);
366
367 BT_ASSERT(fc);
368 _ctf_field_class_int_init(fc, CTF_FIELD_CLASS_TYPE_INT);
369 return fc;
370}
371
372static inline
373struct ctf_field_class_float *ctf_field_class_float_create(void)
374{
375 struct ctf_field_class_float *fc =
376 g_new0(struct ctf_field_class_float, 1);
377
378 BT_ASSERT(fc);
379 _ctf_field_class_bit_array_init((void *) fc, CTF_FIELD_CLASS_TYPE_FLOAT);
380 return fc;
381}
382
383static inline
384struct ctf_field_class_string *ctf_field_class_string_create(void)
385{
386 struct ctf_field_class_string *fc =
387 g_new0(struct ctf_field_class_string, 1);
388
389 BT_ASSERT(fc);
390 _ctf_field_class_init((void *) fc, CTF_FIELD_CLASS_TYPE_STRING, 8);
391 return fc;
392}
393
394static inline
395struct ctf_field_class_enum *ctf_field_class_enum_create(void)
396{
397 struct ctf_field_class_enum *fc = g_new0(struct ctf_field_class_enum, 1);
398
399 BT_ASSERT(fc);
400 _ctf_field_class_int_init((void *) fc, CTF_FIELD_CLASS_TYPE_ENUM);
401 fc->mappings = g_array_new(FALSE, TRUE,
402 sizeof(struct ctf_field_class_enum_mapping));
403 BT_ASSERT(fc->mappings);
404 return fc;
405}
406
407static inline
408struct ctf_field_class_struct *ctf_field_class_struct_create(void)
409{
410 struct ctf_field_class_struct *fc =
411 g_new0(struct ctf_field_class_struct, 1);
412
413 BT_ASSERT(fc);
414 _ctf_field_class_init((void *) fc, CTF_FIELD_CLASS_TYPE_STRUCT, 1);
415 fc->members = g_array_new(FALSE, TRUE,
416 sizeof(struct ctf_named_field_class));
417 BT_ASSERT(fc->members);
418 fc->base.is_compound = true;
419 return fc;
420}
421
422static inline
423struct ctf_field_class_variant *ctf_field_class_variant_create(void)
424{
425 struct ctf_field_class_variant *fc =
426 g_new0(struct ctf_field_class_variant, 1);
427
428 BT_ASSERT(fc);
429 _ctf_field_class_init((void *) fc, CTF_FIELD_CLASS_TYPE_VARIANT, 1);
430 fc->options = g_array_new(FALSE, TRUE,
431 sizeof(struct ctf_named_field_class));
432 BT_ASSERT(fc->options);
433 fc->ranges = g_array_new(FALSE, TRUE,
434 sizeof(struct ctf_field_class_variant_range));
435 BT_ASSERT(fc->ranges);
436 fc->tag_ref = g_string_new(NULL);
437 BT_ASSERT(fc->tag_ref);
438 ctf_field_path_init(&fc->tag_path);
439 fc->base.is_compound = true;
440 return fc;
441}
442
443static inline
444struct ctf_field_class_array *ctf_field_class_array_create(void)
445{
446 struct ctf_field_class_array *fc =
447 g_new0(struct ctf_field_class_array, 1);
448
449 BT_ASSERT(fc);
450 _ctf_field_class_init((void *) fc, CTF_FIELD_CLASS_TYPE_ARRAY, 1);
451 fc->base.base.is_compound = true;
452 return fc;
453}
454
455static inline
456struct ctf_field_class_sequence *ctf_field_class_sequence_create(void)
457{
458 struct ctf_field_class_sequence *fc =
459 g_new0(struct ctf_field_class_sequence, 1);
460
461 BT_ASSERT(fc);
462 _ctf_field_class_init((void *) fc, CTF_FIELD_CLASS_TYPE_SEQUENCE, 1);
463 fc->length_ref = g_string_new(NULL);
464 BT_ASSERT(fc->length_ref);
465 ctf_field_path_init(&fc->length_path);
466 fc->base.base.is_compound = true;
467 return fc;
468}
469
470static inline
471void _ctf_field_class_int_destroy(struct ctf_field_class_int *fc)
472{
473 BT_ASSERT(fc);
474 bt_object_put_ref(fc->mapped_clock_class);
475 g_free(fc);
476}
477
478static inline
479void _ctf_field_class_enum_destroy(struct ctf_field_class_enum *fc)
480{
481 BT_ASSERT(fc);
482 bt_object_put_ref(fc->base.mapped_clock_class);
483
484 if (fc->mappings) {
485 uint64_t i;
486
487 for (i = 0; i < fc->mappings->len; i++) {
488 struct ctf_field_class_enum_mapping *mapping =
489 &g_array_index(fc->mappings,
490 struct ctf_field_class_enum_mapping, i);
491
492 _ctf_field_class_enum_mapping_fini(mapping);
493 }
494
495 g_array_free(fc->mappings, TRUE);
496 }
497
498 g_free(fc);
499}
500
501static inline
502void _ctf_field_class_float_destroy(struct ctf_field_class_float *fc)
503{
504 BT_ASSERT(fc);
505 g_free(fc);
506}
507
508static inline
509void _ctf_field_class_string_destroy(struct ctf_field_class_string *fc)
510{
511 BT_ASSERT(fc);
512 g_free(fc);
513}
514
515static inline
516void _ctf_field_class_struct_destroy(struct ctf_field_class_struct *fc)
517{
518 BT_ASSERT(fc);
519
520 if (fc->members) {
521 uint64_t i;
522
523 for (i = 0; i < fc->members->len; i++) {
524 struct ctf_named_field_class *named_fc =
525 &g_array_index(fc->members,
526 struct ctf_named_field_class, i);
527
528 _ctf_named_field_class_fini(named_fc);
529 }
530
531 g_array_free(fc->members, TRUE);
532 }
533
534 g_free(fc);
535}
536
537static inline
538void _ctf_field_class_array_base_fini(struct ctf_field_class_array_base *fc)
539{
540 BT_ASSERT(fc);
541 ctf_field_class_destroy(fc->elem_fc);
542}
543
544static inline
545void _ctf_field_class_array_destroy(struct ctf_field_class_array *fc)
546{
547 BT_ASSERT(fc);
548 _ctf_field_class_array_base_fini((void *) fc);
549 g_free(fc);
550}
551
552static inline
553void _ctf_field_class_sequence_destroy(struct ctf_field_class_sequence *fc)
554{
555 BT_ASSERT(fc);
556 _ctf_field_class_array_base_fini((void *) fc);
557
558 if (fc->length_ref) {
559 g_string_free(fc->length_ref, TRUE);
560 }
561
562 ctf_field_path_fini(&fc->length_path);
563 g_free(fc);
564}
565
566static inline
567void _ctf_field_class_variant_destroy(struct ctf_field_class_variant *fc)
568{
569 BT_ASSERT(fc);
570
571 if (fc->options) {
572 uint64_t i;
573
574 for (i = 0; i < fc->options->len; i++) {
575 struct ctf_named_field_class *named_fc =
576 &g_array_index(fc->options,
577 struct ctf_named_field_class, i);
578
579 _ctf_named_field_class_fini(named_fc);
580 }
581
582 g_array_free(fc->options, TRUE);
583 }
584
585 if (fc->ranges) {
586 g_array_free(fc->ranges, TRUE);
587 }
588
589 if (fc->tag_ref) {
590 g_string_free(fc->tag_ref, TRUE);
591 }
592
593 ctf_field_path_fini(&fc->tag_path);
594 g_free(fc);
595}
596
597static inline
598void ctf_field_class_destroy(struct ctf_field_class *fc)
599{
600 if (!fc) {
601 return;
602 }
603
604 switch (fc->type) {
605 case CTF_FIELD_CLASS_TYPE_INT:
606 _ctf_field_class_int_destroy((void *) fc);
607 break;
608 case CTF_FIELD_CLASS_TYPE_ENUM:
609 _ctf_field_class_enum_destroy((void *) fc);
610 break;
611 case CTF_FIELD_CLASS_TYPE_FLOAT:
612 _ctf_field_class_float_destroy((void *) fc);
613 break;
614 case CTF_FIELD_CLASS_TYPE_STRING:
615 _ctf_field_class_string_destroy((void *) fc);
616 break;
617 case CTF_FIELD_CLASS_TYPE_STRUCT:
618 _ctf_field_class_struct_destroy((void *) fc);
619 break;
620 case CTF_FIELD_CLASS_TYPE_ARRAY:
621 _ctf_field_class_array_destroy((void *) fc);
622 break;
623 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
624 _ctf_field_class_sequence_destroy((void *) fc);
625 break;
626 case CTF_FIELD_CLASS_TYPE_VARIANT:
627 _ctf_field_class_variant_destroy((void *) fc);
628 break;
629 default:
630 abort();
631 }
632}
633
634static inline
635void ctf_field_class_enum_append_mapping(struct ctf_field_class_enum *fc,
636 const char *label, uint64_t u_lower, uint64_t u_upper)
637{
638 struct ctf_field_class_enum_mapping *mapping;
639
640 BT_ASSERT(fc);
641 BT_ASSERT(label);
642 g_array_set_size(fc->mappings, fc->mappings->len + 1);
643
644 mapping = &g_array_index(fc->mappings,
645 struct ctf_field_class_enum_mapping, fc->mappings->len - 1);
646 _ctf_field_class_enum_mapping_init(mapping);
647 g_string_assign(mapping->label, label);
648 mapping->range.lower.u = u_lower;
649 mapping->range.upper.u = u_upper;
650}
651
652static inline
653struct ctf_field_class_enum_mapping *ctf_field_class_enum_borrow_mapping_by_index(
654 struct ctf_field_class_enum *fc, uint64_t index)
655{
656 BT_ASSERT(fc);
657 BT_ASSERT(index < fc->mappings->len);
658 return &g_array_index(fc->mappings, struct ctf_field_class_enum_mapping,
659 index);
660}
661
662static inline
663struct ctf_named_field_class *ctf_field_class_struct_borrow_member_by_index(
664 struct ctf_field_class_struct *fc, uint64_t index)
665{
666 BT_ASSERT(fc);
667 BT_ASSERT(index < fc->members->len);
668 return &g_array_index(fc->members, struct ctf_named_field_class,
669 index);
670}
671
672static inline
673struct ctf_named_field_class *ctf_field_class_struct_borrow_member_by_name(
674 struct ctf_field_class_struct *fc, const char *name)
675{
676 uint64_t i;
677 struct ctf_named_field_class *ret_named_fc = NULL;
678
679 BT_ASSERT(fc);
680 BT_ASSERT(name);
681
682 for (i = 0; i < fc->members->len; i++) {
683 struct ctf_named_field_class *named_fc =
684 ctf_field_class_struct_borrow_member_by_index(fc, i);
685
686 if (strcmp(name, named_fc->name->str) == 0) {
687 ret_named_fc = named_fc;
688 goto end;
689 }
690 }
691
692end:
693 return ret_named_fc;
694}
695
696static inline
697struct ctf_field_class *ctf_field_class_struct_borrow_member_field_class_by_name(
698 struct ctf_field_class_struct *struct_fc, const char *name)
699{
700 struct ctf_named_field_class *named_fc = NULL;
701 struct ctf_field_class *fc = NULL;
702
703 if (!struct_fc) {
704 goto end;
705 }
706
707 named_fc = ctf_field_class_struct_borrow_member_by_name(struct_fc, name);
708 if (!named_fc) {
709 goto end;
710 }
711
712 fc = named_fc->fc;
713
714end:
715 return fc;
716}
717
718static inline
719struct ctf_field_class_int *
720ctf_field_class_struct_borrow_member_int_field_class_by_name(
721 struct ctf_field_class_struct *struct_fc, const char *name)
722{
723 struct ctf_field_class_int *int_fc = NULL;
724
725 int_fc = (void *)
726 ctf_field_class_struct_borrow_member_field_class_by_name(
727 struct_fc, name);
728 if (!int_fc) {
729 goto end;
730 }
731
732 if (int_fc->base.base.type != CTF_FIELD_CLASS_TYPE_INT &&
733 int_fc->base.base.type != CTF_FIELD_CLASS_TYPE_ENUM) {
734 int_fc = NULL;
735 goto end;
736 }
737
738end:
739 return int_fc;
740}
741
742
743static inline
744void ctf_field_class_struct_append_member(struct ctf_field_class_struct *fc,
745 const char *name, struct ctf_field_class *member_fc)
746{
747 struct ctf_named_field_class *named_fc;
748
749 BT_ASSERT(fc);
750 BT_ASSERT(name);
751 g_array_set_size(fc->members, fc->members->len + 1);
752
753 named_fc = &g_array_index(fc->members, struct ctf_named_field_class,
754 fc->members->len - 1);
755 _ctf_named_field_class_init(named_fc);
756 g_string_assign(named_fc->name, name);
757 named_fc->fc = member_fc;
758
759 if (member_fc->alignment > fc->base.alignment) {
760 fc->base.alignment = member_fc->alignment;
761 }
762}
763
764static inline
765struct ctf_named_field_class *ctf_field_class_variant_borrow_option_by_index(
766 struct ctf_field_class_variant *fc, uint64_t index)
767{
768 BT_ASSERT(fc);
769 BT_ASSERT(index < fc->options->len);
770 return &g_array_index(fc->options, struct ctf_named_field_class,
771 index);
772}
773
774static inline
775struct ctf_named_field_class *ctf_field_class_variant_borrow_option_by_name(
776 struct ctf_field_class_variant *fc, const char *name)
777{
778 uint64_t i;
779 struct ctf_named_field_class *ret_named_fc = NULL;
780
781 BT_ASSERT(fc);
782 BT_ASSERT(name);
783
784 for (i = 0; i < fc->options->len; i++) {
785 struct ctf_named_field_class *named_fc =
786 ctf_field_class_variant_borrow_option_by_index(fc, i);
787
788 if (strcmp(name, named_fc->name->str) == 0) {
789 ret_named_fc = named_fc;
790 goto end;
791 }
792 }
793
794end:
795 return ret_named_fc;
796}
797
798static inline
799struct ctf_field_class_variant_range *
800ctf_field_class_variant_borrow_range_by_index(
801 struct ctf_field_class_variant *fc, uint64_t index)
802{
803 BT_ASSERT(fc);
804 BT_ASSERT(index < fc->ranges->len);
805 return &g_array_index(fc->ranges, struct ctf_field_class_variant_range,
806 index);
807}
808
809static inline
810void ctf_field_class_variant_append_option(struct ctf_field_class_variant *fc,
811 const char *name, struct ctf_field_class *option_fc)
812{
813 struct ctf_named_field_class *named_fc;
814
815 BT_ASSERT(fc);
816 BT_ASSERT(name);
817 g_array_set_size(fc->options, fc->options->len + 1);
818
819 named_fc = &g_array_index(fc->options, struct ctf_named_field_class,
820 fc->options->len - 1);
821 _ctf_named_field_class_init(named_fc);
822 g_string_assign(named_fc->name, name);
823 named_fc->fc = option_fc;
824}
825
826static inline
827void ctf_field_class_variant_set_tag_field_class(
828 struct ctf_field_class_variant *fc,
829 struct ctf_field_class_enum *tag_fc)
830{
831 uint64_t option_i;
832
833 BT_ASSERT(fc);
834 BT_ASSERT(tag_fc);
835 fc->tag_fc = tag_fc;
836
837 for (option_i = 0; option_i < fc->options->len; option_i++) {
838 uint64_t mapping_i;
839 struct ctf_named_field_class *named_fc =
840 ctf_field_class_variant_borrow_option_by_index(
841 fc, option_i);
842
843 for (mapping_i = 0; mapping_i < tag_fc->mappings->len;
844 mapping_i++) {
845 struct ctf_field_class_enum_mapping *mapping =
846 ctf_field_class_enum_borrow_mapping_by_index(
847 tag_fc, mapping_i);
848
849 if (strcmp(named_fc->name->str,
850 mapping->label->str) == 0) {
851 struct ctf_field_class_variant_range range;
852
853 range.range = mapping->range;
854 range.option_index = option_i;
855 g_array_append_val(fc->ranges, range);
856 }
857 }
858 }
859}
860
861static inline
862struct ctf_field_class *ctf_field_class_compound_borrow_field_class_by_index(
863 struct ctf_field_class *comp_fc, uint64_t index)
864{
865 struct ctf_field_class *fc = NULL;
866
867 switch (comp_fc->type) {
868 case CTF_FIELD_CLASS_TYPE_STRUCT:
869 {
870 struct ctf_named_field_class *named_fc =
871 ctf_field_class_struct_borrow_member_by_index(
872 (void *) comp_fc, index);
873
874 BT_ASSERT(named_fc);
875 fc = named_fc->fc;
876 break;
877 }
878 case CTF_FIELD_CLASS_TYPE_VARIANT:
879 {
880 struct ctf_named_field_class *named_fc =
881 ctf_field_class_variant_borrow_option_by_index(
882 (void *) comp_fc, index);
883
884 BT_ASSERT(named_fc);
885 fc = named_fc->fc;
886 break;
887 }
888 case CTF_FIELD_CLASS_TYPE_ARRAY:
889 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
890 {
891 struct ctf_field_class_array_base *array_fc = (void *) comp_fc;
892
893 fc = array_fc->elem_fc;
894 break;
895 }
896 default:
897 break;
898 }
899
900 return fc;
901}
902
903static inline
904uint64_t ctf_field_class_compound_get_field_class_count(struct ctf_field_class *fc)
905{
906 uint64_t field_count;
907
908 switch (fc->type) {
909 case CTF_FIELD_CLASS_TYPE_STRUCT:
910 {
911 struct ctf_field_class_struct *struct_fc = (void *) fc;
912
913 field_count = struct_fc->members->len;
914 break;
915 }
916 case CTF_FIELD_CLASS_TYPE_VARIANT:
917 {
918 struct ctf_field_class_variant *var_fc = (void *) fc;
919
920 field_count = var_fc->options->len;
921 break;
922 }
923 case CTF_FIELD_CLASS_TYPE_ARRAY:
924 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
925 /*
926 * Array and sequence types always contain a single
927 * member (the element type).
928 */
929 field_count = 1;
930 break;
931 default:
932 abort();
933 }
934
935 return field_count;
936}
937
938static inline
939int64_t ctf_field_class_compound_get_field_class_index_from_name(
940 struct ctf_field_class *fc, const char *name)
941{
942 int64_t ret_index = -1;
943 uint64_t i;
944
945 switch (fc->type) {
946 case CTF_FIELD_CLASS_TYPE_STRUCT:
947 {
948 struct ctf_field_class_struct *struct_fc = (void *) fc;
949
950 for (i = 0; i < struct_fc->members->len; i++) {
951 struct ctf_named_field_class *named_fc =
952 ctf_field_class_struct_borrow_member_by_index(
953 struct_fc, i);
954
955 if (strcmp(name, named_fc->name->str) == 0) {
956 ret_index = (int64_t) i;
957 goto end;
958 }
959 }
960
961 break;
962 }
963 case CTF_FIELD_CLASS_TYPE_VARIANT:
964 {
965 struct ctf_field_class_variant *var_fc = (void *) fc;
966
967 for (i = 0; i < var_fc->options->len; i++) {
968 struct ctf_named_field_class *named_fc =
969 ctf_field_class_variant_borrow_option_by_index(
970 var_fc, i);
971
972 if (strcmp(name, named_fc->name->str) == 0) {
973 ret_index = (int64_t) i;
974 goto end;
975 }
976 }
977
978 break;
979 }
980 default:
981 break;
982 }
983
984end:
985 return ret_index;
986}
987
988static inline
989void ctf_field_path_append_index(struct ctf_field_path *fp, int64_t index)
990{
991 BT_ASSERT(fp);
992 g_array_append_val(fp->path, index);
993}
994
995static inline
996int64_t ctf_field_path_borrow_index_by_index(struct ctf_field_path *fp,
997 uint64_t index)
998{
999 BT_ASSERT(fp);
1000 BT_ASSERT(index < fp->path->len);
1001 return g_array_index(fp->path, int64_t, index);
1002}
1003
1004static inline
1005void ctf_field_path_clear(struct ctf_field_path *fp)
1006{
1007 BT_ASSERT(fp);
1008 g_array_set_size(fp->path, 0);
1009}
1010
1011static inline
1012GString *ctf_field_path_string(struct ctf_field_path *path)
1013{
1014 GString *str = g_string_new(NULL);
1015 uint64_t i;
1016
1017 BT_ASSERT(path);
1018
1019 if (!str) {
1020 goto end;
1021 }
1022
1023 g_string_append_printf(str, "[%s", bt_common_scope_string(
1024 path->root));
1025
1026 for (i = 0; i < path->path->len; i++) {
1027 g_string_append_printf(str, ", %" PRId64,
1028 ctf_field_path_borrow_index_by_index(path, i));
1029 }
1030
1031 g_string_append(str, "]");
1032
1033end:
1034 return str;
1035}
1036
1037static inline
1038struct ctf_field_class *ctf_field_path_borrow_field_class(
1039 struct ctf_field_path *field_path,
1040 struct ctf_trace_class *tc,
1041 struct ctf_stream_class *sc,
1042 struct ctf_event_class *ec)
1043{
1044 uint64_t i;
1045 struct ctf_field_class *fc;
1046
1047 switch (field_path->root) {
1048 case BT_SCOPE_PACKET_HEADER:
1049 fc = tc->packet_header_fc;
1050 break;
1051 case BT_SCOPE_PACKET_CONTEXT:
1052 fc = sc->packet_context_fc;
1053 break;
1054 case BT_SCOPE_EVENT_HEADER:
1055 fc = sc->event_header_fc;
1056 break;
1057 case BT_SCOPE_EVENT_COMMON_CONTEXT:
1058 fc = sc->event_common_context_fc;
1059 break;
1060 case BT_SCOPE_EVENT_SPECIFIC_CONTEXT:
1061 fc = ec->spec_context_fc;
1062 break;
1063 case BT_SCOPE_EVENT_PAYLOAD:
1064 fc = ec->payload_fc;
1065 break;
1066 default:
1067 abort();
1068 }
1069
1070 BT_ASSERT(fc);
1071
1072 for (i = 0; i < field_path->path->len; i++) {
1073 int64_t child_index =
1074 ctf_field_path_borrow_index_by_index(field_path, i);
1075 struct ctf_field_class *child_fc =
1076 ctf_field_class_compound_borrow_field_class_by_index(
1077 fc, child_index);
1078 BT_ASSERT(child_fc);
1079 fc = child_fc;
1080 }
1081
1082 BT_ASSERT(fc);
1083 return fc;
1084}
1085
1086static inline
1087struct ctf_field_class *ctf_field_class_copy(struct ctf_field_class *fc);
1088
1089static inline
1090void ctf_field_class_bit_array_copy_content(
1091 struct ctf_field_class_bit_array *dst_fc,
1092 struct ctf_field_class_bit_array *src_fc)
1093{
1094 BT_ASSERT(dst_fc);
1095 BT_ASSERT(src_fc);
1096 dst_fc->byte_order = src_fc->byte_order;
1097 dst_fc->size = src_fc->size;
1098}
1099
1100static inline
1101void ctf_field_class_int_copy_content(
1102 struct ctf_field_class_int *dst_fc,
1103 struct ctf_field_class_int *src_fc)
1104{
1105 ctf_field_class_bit_array_copy_content((void *) dst_fc, (void *) src_fc);
1106 dst_fc->meaning = src_fc->meaning;
1107 dst_fc->is_signed = src_fc->is_signed;
1108 dst_fc->disp_base = src_fc->disp_base;
1109 dst_fc->encoding = src_fc->encoding;
1110 dst_fc->mapped_clock_class = src_fc->mapped_clock_class;
1111 bt_object_get_ref(dst_fc->mapped_clock_class);
1112 dst_fc->storing_index = src_fc->storing_index;
1113}
1114
1115static inline
1116struct ctf_field_class_int *_ctf_field_class_int_copy(
1117 struct ctf_field_class_int *fc)
1118{
1119 struct ctf_field_class_int *copy_fc = ctf_field_class_int_create();
1120
1121 BT_ASSERT(copy_fc);
1122 ctf_field_class_int_copy_content(copy_fc, fc);
1123 return copy_fc;
1124}
1125
1126static inline
1127struct ctf_field_class_enum *_ctf_field_class_enum_copy(
1128 struct ctf_field_class_enum *fc)
1129{
1130 struct ctf_field_class_enum *copy_fc = ctf_field_class_enum_create();
1131 uint64_t i;
1132
1133 BT_ASSERT(copy_fc);
1134 ctf_field_class_int_copy_content((void *) copy_fc, (void *) fc);
1135
1136 for (i = 0; i < fc->mappings->len; i++) {
1137 struct ctf_field_class_enum_mapping *mapping =
1138 &g_array_index(fc->mappings,
1139 struct ctf_field_class_enum_mapping, i);
1140
1141 ctf_field_class_enum_append_mapping(copy_fc, mapping->label->str,
1142 mapping->range.lower.u, mapping->range.upper.u);
1143 }
1144
1145 return copy_fc;
1146}
1147
1148static inline
1149struct ctf_field_class_float *_ctf_field_class_float_copy(
1150 struct ctf_field_class_float *fc)
1151{
1152 struct ctf_field_class_float *copy_fc = ctf_field_class_float_create();
1153
1154 BT_ASSERT(copy_fc);
1155 ctf_field_class_bit_array_copy_content((void *) copy_fc, (void *) fc);
1156 return copy_fc;
1157}
1158
1159static inline
1160struct ctf_field_class_string *_ctf_field_class_string_copy(
1161 struct ctf_field_class_string *fc)
1162{
1163 struct ctf_field_class_string *copy_fc = ctf_field_class_string_create();
1164
1165 BT_ASSERT(copy_fc);
1166 return copy_fc;
1167}
1168
1169static inline
1170struct ctf_field_class_struct *_ctf_field_class_struct_copy(
1171 struct ctf_field_class_struct *fc)
1172{
1173 struct ctf_field_class_struct *copy_fc = ctf_field_class_struct_create();
1174 uint64_t i;
1175
1176 BT_ASSERT(copy_fc);
1177
1178 for (i = 0; i < fc->members->len; i++) {
1179 struct ctf_named_field_class *named_fc =
1180 &g_array_index(fc->members,
1181 struct ctf_named_field_class, i);
1182
1183 ctf_field_class_struct_append_member(copy_fc,
1184 named_fc->name->str,
1185 ctf_field_class_copy(named_fc->fc));
1186 }
1187
1188 return copy_fc;
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_class_variant *_ctf_field_class_variant_copy(
1212 struct ctf_field_class_variant *fc)
1213{
1214 struct ctf_field_class_variant *copy_fc =
1215 ctf_field_class_variant_create();
1216 uint64_t i;
1217
1218 BT_ASSERT(copy_fc);
1219
1220 for (i = 0; i < fc->options->len; i++) {
1221 struct ctf_named_field_class *named_fc =
1222 &g_array_index(fc->options,
1223 struct ctf_named_field_class, i);
1224
1225 ctf_field_class_variant_append_option(copy_fc,
1226 named_fc->name->str,
1227 ctf_field_class_copy(named_fc->fc));
1228 }
1229
1230 for (i = 0; i < fc->ranges->len; i++) {
1231 struct ctf_field_class_variant_range *range =
1232 &g_array_index(fc->ranges,
1233 struct ctf_field_class_variant_range, i);
1234
1235 g_array_append_val(copy_fc->ranges, *range);
1236 }
1237
1238 ctf_field_path_copy_content(&copy_fc->tag_path, &fc->tag_path);
1239 g_string_assign(copy_fc->tag_ref, fc->tag_ref->str);
1240 copy_fc->stored_tag_index = fc->stored_tag_index;
1241 return copy_fc;
1242}
1243
1244static inline
1245void ctf_field_class_array_base_copy_content(
1246 struct ctf_field_class_array_base *dst_fc,
1247 struct ctf_field_class_array_base *src_fc)
1248{
1249 BT_ASSERT(dst_fc);
1250 BT_ASSERT(src_fc);
1251 dst_fc->elem_fc = ctf_field_class_copy(src_fc->elem_fc);
1252 dst_fc->is_text = src_fc->is_text;
1253}
1254
1255static inline
1256struct ctf_field_class_array *_ctf_field_class_array_copy(
1257 struct ctf_field_class_array *fc)
1258{
1259 struct ctf_field_class_array *copy_fc = ctf_field_class_array_create();
1260
1261 BT_ASSERT(copy_fc);
1262 ctf_field_class_array_base_copy_content((void *) copy_fc, (void *) fc);
1263 copy_fc->length = fc->length;
1264 return copy_fc;
1265}
1266
1267static inline
1268struct ctf_field_class_sequence *_ctf_field_class_sequence_copy(
1269 struct ctf_field_class_sequence *fc)
1270{
1271 struct ctf_field_class_sequence *copy_fc =
1272 ctf_field_class_sequence_create();
1273
1274 BT_ASSERT(copy_fc);
1275 ctf_field_class_array_base_copy_content((void *) copy_fc, (void *) fc);
1276 ctf_field_path_copy_content(&copy_fc->length_path, &fc->length_path);
1277 g_string_assign(copy_fc->length_ref, fc->length_ref->str);
1278 copy_fc->stored_length_index = fc->stored_length_index;
1279 return copy_fc;
1280}
1281
1282static inline
1283struct ctf_field_class *ctf_field_class_copy(struct ctf_field_class *fc)
1284{
1285 struct ctf_field_class *copy_fc = NULL;
1286
1287 if (!fc) {
1288 goto end;
1289 }
1290
1291 /*
1292 * Translation should not have happened yet.
1293 */
1294 BT_ASSERT(!fc->ir_fc);
1295
1296 switch (fc->type) {
1297 case CTF_FIELD_CLASS_TYPE_INT:
1298 copy_fc = (void *) _ctf_field_class_int_copy((void *) fc);
1299 break;
1300 case CTF_FIELD_CLASS_TYPE_ENUM:
1301 copy_fc = (void *) _ctf_field_class_enum_copy((void *) fc);
1302 break;
1303 case CTF_FIELD_CLASS_TYPE_FLOAT:
1304 copy_fc = (void *) _ctf_field_class_float_copy((void *) fc);
1305 break;
1306 case CTF_FIELD_CLASS_TYPE_STRING:
1307 copy_fc = (void *) _ctf_field_class_string_copy((void *) fc);
1308 break;
1309 case CTF_FIELD_CLASS_TYPE_STRUCT:
1310 copy_fc = (void *) _ctf_field_class_struct_copy((void *) fc);
1311 break;
1312 case CTF_FIELD_CLASS_TYPE_ARRAY:
1313 copy_fc = (void *) _ctf_field_class_array_copy((void *) fc);
1314 break;
1315 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
1316 copy_fc = (void *) _ctf_field_class_sequence_copy((void *) fc);
1317 break;
1318 case CTF_FIELD_CLASS_TYPE_VARIANT:
1319 copy_fc = (void *) _ctf_field_class_variant_copy((void *) fc);
1320 break;
1321 default:
1322 abort();
1323 }
1324
1325 copy_fc->type = fc->type;
1326 copy_fc->alignment = fc->alignment;
1327 copy_fc->in_ir = fc->in_ir;
1328
1329end:
1330 return copy_fc;
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_class_destroy(ec->spec_context_fc);
1363 ctf_field_class_destroy(ec->payload_fc);
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_class_destroy(sc->packet_context_fc);
1398 ctf_field_class_destroy(sc->event_header_fc);
1399 ctf_field_class_destroy(sc->event_common_context_fc);
1400 bt_object_put_ref(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 type)
1416{
1417 BT_ASSERT(sc);
1418 return g_hash_table_lookup(sc->event_classes_by_id,
1419 GUINT_TO_POINTER((guint) type));
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->default_byte_order = -1;
1453 tc->clock_classes = g_ptr_array_new_with_free_func(
1454 (GDestroyNotify) bt_object_put_ref);
1455 BT_ASSERT(tc->clock_classes);
1456 tc->stream_classes = g_ptr_array_new_with_free_func(
1457 (GDestroyNotify) ctf_stream_class_destroy);
1458 BT_ASSERT(tc->stream_classes);
1459 tc->env_entries = g_array_new(FALSE, TRUE,
1460 sizeof(struct ctf_trace_class_env_entry));
1461 return tc;
1462}
1463
1464static inline
1465void ctf_trace_class_destroy(struct ctf_trace_class *tc)
1466{
1467 if (!tc) {
1468 return;
1469 }
1470
1471 ctf_field_class_destroy(tc->packet_header_fc);
1472
1473 if (tc->clock_classes) {
1474 g_ptr_array_free(tc->clock_classes, TRUE);
1475 }
1476
1477 if (tc->stream_classes) {
1478 g_ptr_array_free(tc->stream_classes, TRUE);
1479 }
1480
1481 if (tc->env_entries) {
1482 uint64_t i;
1483
1484 for (i = 0; i < tc->env_entries->len; i++) {
1485 struct ctf_trace_class_env_entry *entry =
1486 &g_array_index(tc->env_entries,
1487 struct ctf_trace_class_env_entry, i);
1488
1489 _ctf_trace_class_env_entry_fini(entry);
1490 }
1491
1492 g_array_free(tc->env_entries, TRUE);
1493 }
1494
1495 g_free(tc);
1496}
1497
1498static inline
1499void ctf_trace_class_append_env_entry(struct ctf_trace_class *tc,
1500 const char *name, enum ctf_trace_class_env_entry_type type,
1501 const char *str_value, int64_t i_value)
1502{
1503 struct ctf_trace_class_env_entry *entry;
1504
1505 BT_ASSERT(tc);
1506 BT_ASSERT(name);
1507 g_array_set_size(tc->env_entries, tc->env_entries->len + 1);
1508
1509 entry = &g_array_index(tc->env_entries,
1510 struct ctf_trace_class_env_entry, tc->env_entries->len - 1);
1511 entry->type = type;
1512 _ctf_trace_class_env_entry_init(entry);
1513 g_string_assign(entry->name, name);
1514
1515 if (str_value) {
1516 g_string_assign(entry->value.str, str_value);
1517 }
1518
1519 entry->value.i = i_value;
1520}
1521
1522static inline
1523struct ctf_stream_class *ctf_trace_class_borrow_stream_class_by_id(
1524 struct ctf_trace_class *tc, uint64_t id)
1525{
1526 uint64_t i;
1527 struct ctf_stream_class *ret_sc = NULL;
1528
1529 BT_ASSERT(tc);
1530
1531 for (i = 0; i < tc->stream_classes->len; i++) {
1532 struct ctf_stream_class *sc = tc->stream_classes->pdata[i];
1533
1534 if (sc->id == id) {
1535 ret_sc = sc;
1536 goto end;
1537 }
1538 }
1539
1540end:
1541 return ret_sc;
1542}
1543
1544static inline
1545struct bt_clock_class *ctf_trace_class_borrow_clock_class_by_name(
1546 struct ctf_trace_class *tc, const char *name)
1547{
1548 uint64_t i;
1549 struct bt_clock_class *ret_cc = NULL;
1550
1551 BT_ASSERT(tc);
1552 BT_ASSERT(name);
1553
1554 for (i = 0; i < tc->clock_classes->len; i++) {
1555 struct bt_clock_class *cc = tc->clock_classes->pdata[i];
1556 const char *cc_name = bt_clock_class_get_name(cc);
1557
1558 BT_ASSERT(cc_name);
1559 if (strcmp(cc_name, name) == 0) {
1560 ret_cc = cc;
1561 goto end;
1562 }
1563 }
1564
1565end:
1566 return ret_cc;
1567}
1568
1569static inline
1570struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_index(
1571 struct ctf_trace_class *tc, uint64_t index)
1572{
1573 BT_ASSERT(tc);
1574 BT_ASSERT(index < tc->env_entries->len);
1575 return &g_array_index(tc->env_entries, struct ctf_trace_class_env_entry,
1576 index);
1577}
1578
1579static inline
1580struct ctf_trace_class_env_entry *ctf_trace_class_borrow_env_entry_by_name(
1581 struct ctf_trace_class *tc, const char *name)
1582{
1583 struct ctf_trace_class_env_entry *ret_entry = NULL;
1584 uint64_t i;
1585
1586 BT_ASSERT(tc);
1587 BT_ASSERT(name);
1588
1589 for (i = 0; i < tc->env_entries->len; i++) {
1590 struct ctf_trace_class_env_entry *env_entry =
1591 ctf_trace_class_borrow_env_entry_by_index(tc, i);
1592
1593 if (strcmp(env_entry->name->str, name) == 0) {
1594 ret_entry = env_entry;
1595 goto end;
1596 }
1597 }
1598
1599end:
1600 return ret_entry;
1601}
1602
1603#endif /* _CTF_META_H */
This page took 0.027529 seconds and 4 git commands to generate.