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