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