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