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