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