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