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