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