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