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