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