Commit | Line | Data |
---|---|---|
46bdd3e0 PP |
1 | #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H |
2 | #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H | |
3 | ||
4 | /* | |
5 | * Copyright 2018-2019 - 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 | ||
71c5da58 | 18 | #include <babeltrace2/babeltrace.h> |
57952005 MJ |
19 | #include "common/common.h" |
20 | #include "common/assert.h" | |
d126826c | 21 | #include "common/uuid.h" |
46bdd3e0 PP |
22 | #include <glib.h> |
23 | #include <stdint.h> | |
24 | #include <string.h> | |
25 | #include <stdbool.h> | |
26 | #include <ctype.h> | |
27 | ||
28 | enum fs_sink_ctf_field_class_type { | |
dc9cc972 | 29 | FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, |
adec7d09 | 30 | FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, |
46bdd3e0 PP |
31 | FS_SINK_CTF_FIELD_CLASS_TYPE_INT, |
32 | FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, | |
33 | FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, | |
34 | FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, | |
35 | FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, | |
36 | FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE, | |
c27259b0 | 37 | FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, |
46bdd3e0 PP |
38 | FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, |
39 | }; | |
40 | ||
41 | struct fs_sink_ctf_field_class { | |
42 | enum fs_sink_ctf_field_class_type type; | |
43 | ||
44 | /* Weak */ | |
45 | const bt_field_class *ir_fc; | |
46 | ||
47 | unsigned int alignment; | |
48 | ||
49 | /* Index of the field class within its own parent */ | |
50 | uint64_t index_in_parent; | |
51 | }; | |
52 | ||
53 | struct fs_sink_ctf_field_class_bit_array { | |
54 | struct fs_sink_ctf_field_class base; | |
55 | unsigned int size; | |
56 | }; | |
57 | ||
dc9cc972 PP |
58 | struct fs_sink_ctf_field_class_bool { |
59 | struct fs_sink_ctf_field_class_bit_array base; | |
60 | }; | |
61 | ||
46bdd3e0 PP |
62 | struct fs_sink_ctf_field_class_int { |
63 | struct fs_sink_ctf_field_class_bit_array base; | |
64 | bool is_signed; | |
65 | }; | |
66 | ||
67 | struct fs_sink_ctf_field_class_float { | |
68 | struct fs_sink_ctf_field_class_bit_array base; | |
69 | }; | |
70 | ||
71 | struct fs_sink_ctf_field_class_string { | |
72 | struct fs_sink_ctf_field_class base; | |
73 | }; | |
74 | ||
75 | struct fs_sink_ctf_named_field_class { | |
76 | GString *name; | |
77 | ||
78 | /* Owned by this */ | |
79 | struct fs_sink_ctf_field_class *fc; | |
80 | }; | |
81 | ||
82 | struct fs_sink_ctf_field_class_struct { | |
83 | struct fs_sink_ctf_field_class base; | |
84 | ||
85 | /* Array of `struct fs_sink_ctf_named_field_class` */ | |
86 | GArray *members; | |
87 | }; | |
88 | ||
c27259b0 PP |
89 | struct fs_sink_ctf_field_class_option { |
90 | struct fs_sink_ctf_field_class base; | |
91 | struct fs_sink_ctf_field_class *content_fc; | |
92 | GString *tag_ref; | |
93 | }; | |
94 | ||
46bdd3e0 PP |
95 | struct fs_sink_ctf_field_class_variant { |
96 | struct fs_sink_ctf_field_class base; | |
97 | GString *tag_ref; | |
98 | bool tag_is_before; | |
99 | ||
100 | /* Array of `struct fs_sink_ctf_named_field_class` */ | |
101 | GArray *options; | |
102 | }; | |
103 | ||
104 | struct fs_sink_ctf_field_class_array_base { | |
105 | struct fs_sink_ctf_field_class base; | |
106 | struct fs_sink_ctf_field_class *elem_fc; | |
107 | }; | |
108 | ||
109 | struct fs_sink_ctf_field_class_array { | |
110 | struct fs_sink_ctf_field_class_array_base base; | |
111 | uint64_t length; | |
112 | }; | |
113 | ||
114 | struct fs_sink_ctf_field_class_sequence { | |
115 | struct fs_sink_ctf_field_class_array_base base; | |
116 | GString *length_ref; | |
117 | bool length_is_before; | |
118 | }; | |
119 | ||
120 | struct fs_sink_ctf_stream_class; | |
121 | ||
122 | struct fs_sink_ctf_event_class { | |
123 | /* Weak */ | |
124 | const bt_event_class *ir_ec; | |
125 | ||
126 | /* Weak */ | |
127 | struct fs_sink_ctf_stream_class *sc; | |
128 | ||
129 | /* Owned by this */ | |
130 | struct fs_sink_ctf_field_class *spec_context_fc; | |
131 | ||
132 | /* Owned by this */ | |
133 | struct fs_sink_ctf_field_class *payload_fc; | |
134 | }; | |
135 | ||
cd03c43c | 136 | struct fs_sink_ctf_trace; |
46bdd3e0 PP |
137 | |
138 | struct fs_sink_ctf_stream_class { | |
139 | /* Weak */ | |
cd03c43c | 140 | struct fs_sink_ctf_trace *trace; |
46bdd3e0 PP |
141 | |
142 | /* Weak */ | |
143 | const bt_stream_class *ir_sc; | |
144 | ||
145 | /* Weak */ | |
146 | const bt_clock_class *default_clock_class; | |
147 | ||
148 | GString *default_clock_class_name; | |
37a93d41 | 149 | bool has_packets; |
032880f0 PP |
150 | bool packets_have_ts_begin; |
151 | bool packets_have_ts_end; | |
152 | bool has_discarded_events; | |
153 | bool discarded_events_has_ts; | |
154 | bool discarded_packets_has_ts; | |
46bdd3e0 PP |
155 | |
156 | /* Owned by this */ | |
157 | struct fs_sink_ctf_field_class *packet_context_fc; | |
158 | ||
159 | /* Owned by this */ | |
160 | struct fs_sink_ctf_field_class *event_common_context_fc; | |
161 | ||
162 | /* Array of `struct fs_sink_ctf_event_class *` (owned by this) */ | |
163 | GPtrArray *event_classes; | |
164 | ||
165 | /* | |
166 | * `const bt_event_class *` (weak) -> | |
167 | * `struct fs_sink_ctf_event_class *` (weak) | |
168 | */ | |
169 | GHashTable *event_classes_from_ir; | |
170 | }; | |
171 | ||
cd03c43c PP |
172 | struct fs_sink_ctf_trace { |
173 | /* Weak */ | |
174 | const bt_trace *ir_trace; | |
175 | ||
46bdd3e0 PP |
176 | /* Weak */ |
177 | const bt_trace_class *ir_tc; | |
178 | ||
d126826c | 179 | bt_uuid_t uuid; |
46bdd3e0 PP |
180 | |
181 | /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */ | |
182 | GPtrArray *stream_classes; | |
183 | }; | |
184 | ||
185 | static inline | |
186 | void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc); | |
187 | ||
188 | static inline | |
189 | void _fs_sink_ctf_field_class_init(struct fs_sink_ctf_field_class *fc, | |
190 | enum fs_sink_ctf_field_class_type type, | |
191 | const bt_field_class *ir_fc, unsigned int alignment, | |
192 | uint64_t index_in_parent) | |
193 | { | |
194 | BT_ASSERT(fc); | |
195 | fc->type = type; | |
196 | fc->ir_fc = ir_fc; | |
197 | fc->alignment = alignment; | |
198 | fc->index_in_parent = index_in_parent; | |
199 | } | |
200 | ||
201 | static inline | |
202 | void _fs_sink_ctf_field_class_bit_array_init( | |
203 | struct fs_sink_ctf_field_class_bit_array *fc, | |
204 | enum fs_sink_ctf_field_class_type type, | |
205 | const bt_field_class *ir_fc, unsigned int size, | |
206 | uint64_t index_in_parent) | |
207 | { | |
208 | _fs_sink_ctf_field_class_init((void *) fc, type, ir_fc, | |
209 | size % 8 == 0 ? 8 : 1, index_in_parent); | |
210 | fc->size = size; | |
211 | } | |
212 | ||
213 | static inline | |
214 | void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int *fc, | |
215 | enum fs_sink_ctf_field_class_type type, | |
216 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
217 | { | |
218 | bt_field_class_type ir_fc_type = bt_field_class_get_type(ir_fc); | |
219 | ||
220 | _fs_sink_ctf_field_class_bit_array_init((void *) fc, type, ir_fc, | |
221 | (unsigned int) bt_field_class_integer_get_field_value_range( | |
222 | ir_fc), | |
223 | index_in_parent); | |
224 | fc->is_signed = (ir_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || | |
225 | ir_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); | |
226 | } | |
227 | ||
228 | static inline | |
229 | void _fs_sink_ctf_named_field_class_init( | |
230 | struct fs_sink_ctf_named_field_class *named_fc) | |
231 | { | |
232 | BT_ASSERT(named_fc); | |
233 | named_fc->name = g_string_new(NULL); | |
234 | BT_ASSERT(named_fc->name); | |
235 | } | |
236 | ||
237 | static inline | |
238 | void _fs_sink_ctf_named_field_class_fini( | |
239 | struct fs_sink_ctf_named_field_class *named_fc) | |
240 | { | |
241 | BT_ASSERT(named_fc); | |
242 | ||
243 | if (named_fc->name) { | |
244 | g_string_free(named_fc->name, TRUE); | |
245 | named_fc->name = NULL; | |
246 | } | |
247 | ||
248 | fs_sink_ctf_field_class_destroy(named_fc->fc); | |
249 | named_fc->fc = NULL; | |
250 | } | |
251 | ||
adec7d09 PP |
252 | static inline |
253 | struct fs_sink_ctf_field_class_bit_array * | |
254 | fs_sink_ctf_field_class_bit_array_create( | |
255 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
256 | { | |
257 | struct fs_sink_ctf_field_class_bit_array *fc = | |
258 | g_new0(struct fs_sink_ctf_field_class_bit_array, 1); | |
259 | ||
260 | BT_ASSERT(fc); | |
261 | _fs_sink_ctf_field_class_bit_array_init((void *) fc, | |
262 | FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc, | |
263 | (unsigned int) bt_field_class_bit_array_get_length(ir_fc), | |
264 | index_in_parent); | |
265 | return fc; | |
266 | } | |
267 | ||
dc9cc972 PP |
268 | static inline |
269 | struct fs_sink_ctf_field_class_bool *fs_sink_ctf_field_class_bool_create( | |
270 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
271 | { | |
272 | struct fs_sink_ctf_field_class_bool *fc = | |
273 | g_new0(struct fs_sink_ctf_field_class_bool, 1); | |
274 | ||
275 | BT_ASSERT(fc); | |
276 | ||
277 | /* | |
278 | * CTF 1.8 has no boolean field class type, so this component | |
279 | * translates it to an 8-bit unsigned integer field class. | |
280 | */ | |
281 | _fs_sink_ctf_field_class_bit_array_init((void *) fc, | |
282 | FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc, | |
283 | 8, index_in_parent); | |
284 | return fc; | |
285 | } | |
286 | ||
46bdd3e0 PP |
287 | static inline |
288 | struct fs_sink_ctf_field_class_int *fs_sink_ctf_field_class_int_create( | |
289 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
290 | { | |
291 | struct fs_sink_ctf_field_class_int *fc = | |
292 | g_new0(struct fs_sink_ctf_field_class_int, 1); | |
293 | ||
294 | BT_ASSERT(fc); | |
295 | _fs_sink_ctf_field_class_int_init(fc, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, | |
296 | ir_fc, index_in_parent); | |
297 | return fc; | |
298 | } | |
299 | ||
300 | static inline | |
301 | struct fs_sink_ctf_field_class_float *fs_sink_ctf_field_class_float_create( | |
302 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
303 | { | |
304 | struct fs_sink_ctf_field_class_float *fc = | |
305 | g_new0(struct fs_sink_ctf_field_class_float, 1); | |
306 | ||
307 | BT_ASSERT(fc); | |
308 | _fs_sink_ctf_field_class_bit_array_init((void *) fc, | |
309 | FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, | |
310 | ir_fc, bt_field_class_real_is_single_precision(ir_fc) ? 32 : 64, | |
311 | index_in_parent); | |
312 | return fc; | |
313 | } | |
314 | ||
315 | static inline | |
316 | struct fs_sink_ctf_field_class_string *fs_sink_ctf_field_class_string_create( | |
317 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
318 | { | |
319 | struct fs_sink_ctf_field_class_string *fc = | |
320 | g_new0(struct fs_sink_ctf_field_class_string, 1); | |
321 | ||
322 | BT_ASSERT(fc); | |
323 | _fs_sink_ctf_field_class_init((void *) fc, | |
324 | FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, ir_fc, | |
325 | 8, index_in_parent); | |
326 | return fc; | |
327 | } | |
328 | ||
329 | static inline | |
330 | struct fs_sink_ctf_field_class_struct *fs_sink_ctf_field_class_struct_create_empty( | |
331 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
332 | { | |
333 | struct fs_sink_ctf_field_class_struct *fc = | |
334 | g_new0(struct fs_sink_ctf_field_class_struct, 1); | |
335 | ||
336 | BT_ASSERT(fc); | |
337 | _fs_sink_ctf_field_class_init((void *) fc, | |
338 | FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, ir_fc, 1, index_in_parent); | |
339 | fc->members = g_array_new(FALSE, TRUE, | |
340 | sizeof(struct fs_sink_ctf_named_field_class)); | |
341 | BT_ASSERT(fc->members); | |
342 | return fc; | |
343 | } | |
344 | ||
c27259b0 PP |
345 | static inline |
346 | struct fs_sink_ctf_field_class_option *fs_sink_ctf_field_class_option_create_empty( | |
347 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
348 | { | |
349 | struct fs_sink_ctf_field_class_option *fc = | |
350 | g_new0(struct fs_sink_ctf_field_class_option, 1); | |
351 | ||
352 | BT_ASSERT(fc); | |
353 | _fs_sink_ctf_field_class_init((void *) fc, | |
354 | FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc, | |
355 | 1, index_in_parent); | |
356 | fc->tag_ref = g_string_new(NULL); | |
357 | BT_ASSERT(fc->tag_ref); | |
358 | return fc; | |
359 | } | |
360 | ||
46bdd3e0 PP |
361 | static inline |
362 | struct fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_variant_create_empty( | |
363 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
364 | { | |
365 | struct fs_sink_ctf_field_class_variant *fc = | |
366 | g_new0(struct fs_sink_ctf_field_class_variant, 1); | |
367 | ||
368 | BT_ASSERT(fc); | |
369 | _fs_sink_ctf_field_class_init((void *) fc, | |
370 | FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, ir_fc, | |
371 | 1, index_in_parent); | |
372 | fc->options = g_array_new(FALSE, TRUE, | |
373 | sizeof(struct fs_sink_ctf_named_field_class)); | |
374 | BT_ASSERT(fc->options); | |
375 | fc->tag_ref = g_string_new(NULL); | |
376 | BT_ASSERT(fc->tag_ref); | |
377 | fc->tag_is_before = | |
02b61fe0 PP |
378 | bt_field_class_get_type(fc->base.ir_fc) == |
379 | BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR; | |
46bdd3e0 PP |
380 | return fc; |
381 | } | |
382 | ||
383 | static inline | |
384 | struct fs_sink_ctf_field_class_array *fs_sink_ctf_field_class_array_create_empty( | |
385 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
386 | { | |
387 | struct fs_sink_ctf_field_class_array *fc = | |
388 | g_new0(struct fs_sink_ctf_field_class_array, 1); | |
389 | ||
390 | BT_ASSERT(fc); | |
391 | _fs_sink_ctf_field_class_init((void *) fc, | |
392 | FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc, | |
393 | 1, index_in_parent); | |
60bbfc7c | 394 | fc->length = bt_field_class_array_static_get_length(ir_fc); |
46bdd3e0 PP |
395 | return fc; |
396 | } | |
397 | ||
398 | static inline | |
399 | struct fs_sink_ctf_field_class_sequence *fs_sink_ctf_field_class_sequence_create_empty( | |
400 | const bt_field_class *ir_fc, uint64_t index_in_parent) | |
401 | { | |
402 | struct fs_sink_ctf_field_class_sequence *fc = | |
403 | g_new0(struct fs_sink_ctf_field_class_sequence, 1); | |
404 | ||
405 | BT_ASSERT(fc); | |
406 | _fs_sink_ctf_field_class_init((void *) fc, | |
407 | FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE, | |
408 | ir_fc, 1, index_in_parent); | |
409 | fc->length_ref = g_string_new(NULL); | |
410 | BT_ASSERT(fc->length_ref); | |
411 | fc->length_is_before = | |
60bbfc7c | 412 | bt_field_class_array_dynamic_borrow_length_field_path_const(ir_fc) == |
46bdd3e0 PP |
413 | NULL; |
414 | return fc; | |
415 | } | |
416 | ||
417 | static inline | |
418 | struct fs_sink_ctf_named_field_class * | |
419 | fs_sink_ctf_field_class_struct_borrow_member_by_index( | |
420 | struct fs_sink_ctf_field_class_struct *fc, uint64_t index); | |
421 | ||
422 | static inline | |
423 | struct fs_sink_ctf_named_field_class * | |
424 | fs_sink_ctf_field_class_variant_borrow_option_by_index( | |
425 | struct fs_sink_ctf_field_class_variant *fc, uint64_t index); | |
426 | ||
427 | static inline | |
428 | void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc) | |
429 | { | |
430 | BT_ASSERT(fc); | |
431 | } | |
432 | ||
adec7d09 PP |
433 | static inline |
434 | void _fs_sink_ctf_field_class_bit_array_destroy( | |
435 | struct fs_sink_ctf_field_class_int *fc) | |
436 | { | |
437 | BT_ASSERT(fc); | |
438 | _fs_sink_ctf_field_class_fini((void *) fc); | |
439 | g_free(fc); | |
440 | } | |
441 | ||
dc9cc972 PP |
442 | static inline |
443 | void _fs_sink_ctf_field_class_bool_destroy( | |
444 | struct fs_sink_ctf_field_class_int *fc) | |
445 | { | |
446 | BT_ASSERT(fc); | |
447 | _fs_sink_ctf_field_class_fini((void *) fc); | |
448 | g_free(fc); | |
449 | } | |
450 | ||
46bdd3e0 PP |
451 | static inline |
452 | void _fs_sink_ctf_field_class_int_destroy( | |
453 | struct fs_sink_ctf_field_class_int *fc) | |
454 | { | |
455 | BT_ASSERT(fc); | |
456 | _fs_sink_ctf_field_class_fini((void *) fc); | |
457 | g_free(fc); | |
458 | } | |
459 | ||
460 | static inline | |
461 | void _fs_sink_ctf_field_class_float_destroy( | |
462 | struct fs_sink_ctf_field_class_float *fc) | |
463 | { | |
464 | BT_ASSERT(fc); | |
465 | _fs_sink_ctf_field_class_fini((void *) fc); | |
466 | g_free(fc); | |
467 | } | |
468 | ||
469 | static inline | |
470 | void _fs_sink_ctf_field_class_string_destroy( | |
471 | struct fs_sink_ctf_field_class_string *fc) | |
472 | { | |
473 | BT_ASSERT(fc); | |
474 | _fs_sink_ctf_field_class_fini((void *) fc); | |
475 | g_free(fc); | |
476 | } | |
477 | ||
478 | static inline | |
479 | void _fs_sink_ctf_field_class_struct_destroy( | |
480 | struct fs_sink_ctf_field_class_struct *fc) | |
481 | { | |
482 | BT_ASSERT(fc); | |
483 | _fs_sink_ctf_field_class_fini((void *) fc); | |
484 | ||
485 | if (fc->members) { | |
486 | uint64_t i; | |
487 | ||
488 | for (i = 0; i < fc->members->len; i++) { | |
489 | struct fs_sink_ctf_named_field_class *named_fc = | |
490 | fs_sink_ctf_field_class_struct_borrow_member_by_index( | |
491 | fc, i); | |
492 | ||
493 | _fs_sink_ctf_named_field_class_fini(named_fc); | |
494 | } | |
495 | ||
496 | g_array_free(fc->members, TRUE); | |
497 | fc->members = NULL; | |
498 | } | |
499 | ||
500 | g_free(fc); | |
501 | } | |
502 | ||
503 | static inline | |
504 | void _fs_sink_ctf_field_class_array_base_fini( | |
505 | struct fs_sink_ctf_field_class_array_base *fc) | |
506 | { | |
507 | BT_ASSERT(fc); | |
508 | _fs_sink_ctf_field_class_fini((void *) fc); | |
509 | fs_sink_ctf_field_class_destroy(fc->elem_fc); | |
510 | fc->elem_fc = NULL; | |
511 | } | |
512 | ||
513 | static inline | |
514 | void _fs_sink_ctf_field_class_array_destroy( | |
515 | struct fs_sink_ctf_field_class_array *fc) | |
516 | { | |
517 | BT_ASSERT(fc); | |
518 | _fs_sink_ctf_field_class_array_base_fini((void *) fc); | |
519 | g_free(fc); | |
520 | } | |
521 | ||
522 | static inline | |
523 | void _fs_sink_ctf_field_class_sequence_destroy( | |
524 | struct fs_sink_ctf_field_class_sequence *fc) | |
525 | { | |
526 | BT_ASSERT(fc); | |
527 | _fs_sink_ctf_field_class_array_base_fini((void *) fc); | |
528 | ||
529 | if (fc->length_ref) { | |
530 | g_string_free(fc->length_ref, TRUE); | |
531 | fc->length_ref = NULL; | |
532 | } | |
533 | ||
534 | g_free(fc); | |
535 | } | |
536 | ||
c27259b0 PP |
537 | static inline |
538 | void _fs_sink_ctf_field_class_option_destroy( | |
539 | struct fs_sink_ctf_field_class_option *fc) | |
540 | { | |
541 | BT_ASSERT(fc); | |
542 | _fs_sink_ctf_field_class_fini((void *) fc); | |
543 | fs_sink_ctf_field_class_destroy(fc->content_fc); | |
544 | ||
545 | if (fc->tag_ref) { | |
546 | g_string_free(fc->tag_ref, TRUE); | |
547 | fc->tag_ref = NULL; | |
548 | } | |
549 | ||
550 | g_free(fc); | |
551 | } | |
552 | ||
46bdd3e0 PP |
553 | static inline |
554 | void _fs_sink_ctf_field_class_variant_destroy( | |
555 | struct fs_sink_ctf_field_class_variant *fc) | |
556 | { | |
557 | BT_ASSERT(fc); | |
558 | _fs_sink_ctf_field_class_fini((void *) fc); | |
559 | ||
560 | if (fc->options) { | |
561 | uint64_t i; | |
562 | ||
563 | for (i = 0; i < fc->options->len; i++) { | |
564 | struct fs_sink_ctf_named_field_class *named_fc = | |
565 | fs_sink_ctf_field_class_variant_borrow_option_by_index( | |
566 | fc, i); | |
567 | ||
568 | _fs_sink_ctf_named_field_class_fini(named_fc); | |
569 | } | |
570 | ||
571 | g_array_free(fc->options, TRUE); | |
572 | fc->options = NULL; | |
573 | } | |
574 | ||
575 | if (fc->tag_ref) { | |
576 | g_string_free(fc->tag_ref, TRUE); | |
577 | fc->tag_ref = NULL; | |
578 | } | |
579 | ||
580 | g_free(fc); | |
581 | } | |
582 | ||
583 | static inline | |
584 | void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc) | |
585 | { | |
586 | if (!fc) { | |
587 | return; | |
588 | } | |
589 | ||
590 | switch (fc->type) { | |
dc9cc972 PP |
591 | case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: |
592 | _fs_sink_ctf_field_class_bool_destroy((void *) fc); | |
593 | break; | |
adec7d09 PP |
594 | case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY: |
595 | _fs_sink_ctf_field_class_bit_array_destroy((void *) fc); | |
596 | break; | |
46bdd3e0 PP |
597 | case FS_SINK_CTF_FIELD_CLASS_TYPE_INT: |
598 | _fs_sink_ctf_field_class_int_destroy((void *) fc); | |
599 | break; | |
600 | case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT: | |
601 | _fs_sink_ctf_field_class_float_destroy((void *) fc); | |
602 | break; | |
603 | case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING: | |
604 | _fs_sink_ctf_field_class_string_destroy((void *) fc); | |
605 | break; | |
606 | case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT: | |
607 | _fs_sink_ctf_field_class_struct_destroy((void *) fc); | |
608 | break; | |
609 | case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY: | |
610 | _fs_sink_ctf_field_class_array_destroy((void *) fc); | |
611 | break; | |
612 | case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
613 | _fs_sink_ctf_field_class_sequence_destroy((void *) fc); | |
614 | break; | |
c27259b0 PP |
615 | case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION: |
616 | _fs_sink_ctf_field_class_option_destroy((void *) fc); | |
617 | break; | |
46bdd3e0 PP |
618 | case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT: |
619 | _fs_sink_ctf_field_class_variant_destroy((void *) fc); | |
620 | break; | |
621 | default: | |
622 | abort(); | |
623 | } | |
624 | } | |
625 | ||
626 | static inline | |
627 | struct fs_sink_ctf_named_field_class * | |
628 | fs_sink_ctf_field_class_struct_borrow_member_by_index( | |
629 | struct fs_sink_ctf_field_class_struct *fc, uint64_t index) | |
630 | { | |
631 | BT_ASSERT(fc); | |
632 | BT_ASSERT(index < fc->members->len); | |
633 | return &g_array_index(fc->members, struct fs_sink_ctf_named_field_class, | |
634 | index); | |
635 | } | |
636 | ||
637 | static inline | |
638 | struct fs_sink_ctf_named_field_class * | |
639 | fs_sink_ctf_field_class_struct_borrow_member_by_name( | |
640 | struct fs_sink_ctf_field_class_struct *fc, const char *name) | |
641 | { | |
642 | uint64_t i; | |
643 | struct fs_sink_ctf_named_field_class *ret_named_fc = NULL; | |
644 | ||
645 | BT_ASSERT(fc); | |
646 | BT_ASSERT(name); | |
647 | ||
648 | for (i = 0; i < fc->members->len; i++) { | |
649 | struct fs_sink_ctf_named_field_class *named_fc = | |
650 | fs_sink_ctf_field_class_struct_borrow_member_by_index( | |
651 | fc, i); | |
652 | ||
653 | if (strcmp(name, named_fc->name->str) == 0) { | |
654 | ret_named_fc = named_fc; | |
655 | goto end; | |
656 | } | |
657 | } | |
658 | ||
659 | end: | |
660 | return ret_named_fc; | |
661 | } | |
662 | ||
663 | static inline | |
664 | struct fs_sink_ctf_field_class * | |
665 | fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name( | |
666 | struct fs_sink_ctf_field_class_struct *struct_fc, const char *name) | |
667 | { | |
668 | struct fs_sink_ctf_named_field_class *named_fc = NULL; | |
669 | struct fs_sink_ctf_field_class *fc = NULL; | |
670 | ||
671 | if (!struct_fc) { | |
672 | goto end; | |
673 | } | |
674 | ||
675 | named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_name( | |
676 | struct_fc, name); | |
677 | if (!named_fc) { | |
678 | goto end; | |
679 | } | |
680 | ||
681 | fc = named_fc->fc; | |
682 | ||
683 | end: | |
684 | return fc; | |
685 | } | |
686 | ||
687 | static inline | |
688 | struct fs_sink_ctf_field_class_int * | |
689 | fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name( | |
690 | struct fs_sink_ctf_field_class_struct *struct_fc, | |
691 | const char *name) | |
692 | { | |
693 | struct fs_sink_ctf_field_class_int *int_fc = NULL; | |
694 | ||
695 | int_fc = (void *) | |
696 | fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name( | |
697 | struct_fc, name); | |
698 | if (!int_fc) { | |
699 | goto end; | |
700 | } | |
701 | ||
702 | if (int_fc->base.base.type != FS_SINK_CTF_FIELD_CLASS_TYPE_INT) { | |
703 | int_fc = NULL; | |
704 | goto end; | |
705 | } | |
706 | ||
707 | end: | |
708 | return int_fc; | |
709 | } | |
710 | ||
711 | static inline | |
712 | void fs_sink_ctf_field_class_struct_align_at_least( | |
713 | struct fs_sink_ctf_field_class_struct *fc, | |
714 | unsigned int alignment) | |
715 | { | |
716 | if (alignment > fc->base.alignment) { | |
717 | fc->base.alignment = alignment; | |
718 | } | |
719 | } | |
720 | ||
721 | static inline | |
722 | void fs_sink_ctf_field_class_struct_append_member( | |
723 | struct fs_sink_ctf_field_class_struct *fc, | |
724 | const char *name, struct fs_sink_ctf_field_class *member_fc) | |
725 | { | |
726 | struct fs_sink_ctf_named_field_class *named_fc; | |
727 | ||
728 | BT_ASSERT(fc); | |
729 | BT_ASSERT(name); | |
730 | g_array_set_size(fc->members, fc->members->len + 1); | |
731 | ||
732 | named_fc = &g_array_index(fc->members, | |
733 | struct fs_sink_ctf_named_field_class, fc->members->len - 1); | |
734 | _fs_sink_ctf_named_field_class_init(named_fc); | |
735 | g_string_assign(named_fc->name, name); | |
736 | named_fc->fc = member_fc; | |
737 | fs_sink_ctf_field_class_struct_align_at_least(fc, member_fc->alignment); | |
738 | } | |
739 | ||
740 | static inline | |
741 | struct fs_sink_ctf_named_field_class * | |
742 | fs_sink_ctf_field_class_variant_borrow_option_by_index( | |
743 | struct fs_sink_ctf_field_class_variant *fc, uint64_t index) | |
744 | { | |
745 | BT_ASSERT(fc); | |
746 | BT_ASSERT(index < fc->options->len); | |
747 | return &g_array_index(fc->options, struct fs_sink_ctf_named_field_class, | |
748 | index); | |
749 | } | |
750 | ||
751 | static inline | |
752 | struct fs_sink_ctf_named_field_class * | |
753 | fs_sink_ctf_field_class_variant_borrow_option_by_name( | |
754 | struct fs_sink_ctf_field_class_variant *fc, const char *name) | |
755 | { | |
756 | uint64_t i; | |
757 | struct fs_sink_ctf_named_field_class *ret_named_fc = NULL; | |
758 | ||
759 | BT_ASSERT(fc); | |
760 | BT_ASSERT(name); | |
761 | ||
762 | for (i = 0; i < fc->options->len; i++) { | |
763 | struct fs_sink_ctf_named_field_class *named_fc = | |
764 | fs_sink_ctf_field_class_variant_borrow_option_by_index( | |
765 | fc, i); | |
766 | ||
767 | if (strcmp(name, named_fc->name->str) == 0) { | |
768 | ret_named_fc = named_fc; | |
769 | goto end; | |
770 | } | |
771 | } | |
772 | ||
773 | end: | |
774 | return ret_named_fc; | |
775 | } | |
776 | ||
777 | static inline | |
778 | void fs_sink_ctf_field_class_variant_append_option( | |
779 | struct fs_sink_ctf_field_class_variant *fc, | |
780 | const char *name, struct fs_sink_ctf_field_class *option_fc) | |
781 | { | |
782 | struct fs_sink_ctf_named_field_class *named_fc; | |
783 | ||
784 | BT_ASSERT(fc); | |
785 | BT_ASSERT(name); | |
786 | g_array_set_size(fc->options, fc->options->len + 1); | |
787 | ||
788 | named_fc = &g_array_index(fc->options, | |
789 | struct fs_sink_ctf_named_field_class, fc->options->len - 1); | |
790 | _fs_sink_ctf_named_field_class_init(named_fc); | |
791 | g_string_assign(named_fc->name, name); | |
792 | named_fc->fc = option_fc; | |
793 | } | |
794 | ||
795 | static inline | |
796 | struct fs_sink_ctf_event_class *fs_sink_ctf_event_class_create( | |
797 | struct fs_sink_ctf_stream_class *sc, | |
798 | const bt_event_class *ir_ec) | |
799 | { | |
800 | struct fs_sink_ctf_event_class *ec = | |
801 | g_new0(struct fs_sink_ctf_event_class, 1); | |
802 | ||
803 | BT_ASSERT(sc); | |
804 | BT_ASSERT(ir_ec); | |
805 | BT_ASSERT(ec); | |
806 | ec->ir_ec = ir_ec; | |
807 | ec->sc = sc; | |
808 | g_ptr_array_add(sc->event_classes, ec); | |
809 | g_hash_table_insert(sc->event_classes_from_ir, (gpointer) ir_ec, ec); | |
810 | return ec; | |
811 | } | |
812 | ||
813 | static inline | |
814 | void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec) | |
815 | { | |
816 | if (!ec) { | |
817 | return; | |
818 | } | |
819 | ||
820 | fs_sink_ctf_field_class_destroy(ec->spec_context_fc); | |
821 | ec->spec_context_fc = NULL; | |
822 | fs_sink_ctf_field_class_destroy(ec->payload_fc); | |
823 | ec->payload_fc = NULL; | |
824 | g_free(ec); | |
825 | } | |
826 | ||
827 | static inline | |
828 | struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create( | |
cd03c43c | 829 | struct fs_sink_ctf_trace *trace, |
46bdd3e0 PP |
830 | const bt_stream_class *ir_sc) |
831 | { | |
832 | struct fs_sink_ctf_stream_class *sc = | |
833 | g_new0(struct fs_sink_ctf_stream_class, 1); | |
834 | ||
cd03c43c | 835 | BT_ASSERT(trace); |
46bdd3e0 PP |
836 | BT_ASSERT(ir_sc); |
837 | BT_ASSERT(sc); | |
cd03c43c | 838 | sc->trace = trace; |
46bdd3e0 PP |
839 | sc->ir_sc = ir_sc; |
840 | sc->default_clock_class = | |
841 | bt_stream_class_borrow_default_clock_class_const(ir_sc); | |
842 | sc->default_clock_class_name = g_string_new(NULL); | |
843 | BT_ASSERT(sc->default_clock_class_name); | |
844 | sc->event_classes = g_ptr_array_new_with_free_func( | |
845 | (GDestroyNotify) fs_sink_ctf_event_class_destroy); | |
846 | BT_ASSERT(sc->event_classes); | |
847 | sc->event_classes_from_ir = g_hash_table_new(g_direct_hash, | |
848 | g_direct_equal); | |
849 | BT_ASSERT(sc->event_classes_from_ir); | |
37a93d41 | 850 | sc->has_packets = bt_stream_class_supports_packets(ir_sc); |
032880f0 | 851 | sc->packets_have_ts_begin = |
5ef34326 | 852 | bt_stream_class_packets_have_beginning_default_clock_snapshot( |
032880f0 PP |
853 | ir_sc); |
854 | sc->packets_have_ts_end = | |
5ef34326 | 855 | bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc); |
032880f0 PP |
856 | sc->has_discarded_events = |
857 | bt_stream_class_supports_discarded_events(ir_sc); | |
858 | ||
859 | if (sc->has_discarded_events) { | |
860 | sc->discarded_events_has_ts = | |
861 | bt_stream_class_discarded_events_have_default_clock_snapshots( | |
862 | ir_sc); | |
863 | } | |
864 | ||
865 | if (bt_stream_class_supports_discarded_packets(ir_sc)) { | |
866 | sc->discarded_packets_has_ts = | |
867 | bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
868 | ir_sc); | |
869 | } | |
870 | ||
cd03c43c | 871 | g_ptr_array_add(trace->stream_classes, sc); |
46bdd3e0 PP |
872 | return sc; |
873 | } | |
874 | ||
875 | static inline | |
876 | void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class *sc) | |
877 | { | |
878 | if (!sc) { | |
879 | return; | |
880 | } | |
881 | ||
882 | if (sc->default_clock_class_name) { | |
883 | g_string_free(sc->default_clock_class_name, TRUE); | |
884 | sc->default_clock_class_name = NULL; | |
885 | } | |
886 | ||
887 | if (sc->event_classes) { | |
888 | g_ptr_array_free(sc->event_classes, TRUE); | |
889 | sc->event_classes = NULL; | |
890 | } | |
891 | ||
892 | if (sc->event_classes_from_ir) { | |
893 | g_hash_table_destroy(sc->event_classes_from_ir); | |
894 | sc->event_classes_from_ir = NULL; | |
895 | } | |
896 | ||
897 | fs_sink_ctf_field_class_destroy(sc->packet_context_fc); | |
898 | sc->packet_context_fc = NULL; | |
899 | fs_sink_ctf_field_class_destroy(sc->event_common_context_fc); | |
900 | sc->event_common_context_fc = NULL; | |
901 | g_free(sc); | |
902 | } | |
903 | ||
904 | static inline | |
905 | void fs_sink_ctf_stream_class_append_event_class( | |
906 | struct fs_sink_ctf_stream_class *sc, | |
907 | struct fs_sink_ctf_event_class *ec) | |
908 | { | |
909 | g_ptr_array_add(sc->event_classes, ec); | |
910 | } | |
911 | ||
912 | static inline | |
cd03c43c | 913 | void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace) |
46bdd3e0 | 914 | { |
cd03c43c | 915 | if (!trace) { |
46bdd3e0 PP |
916 | return; |
917 | } | |
918 | ||
cd03c43c PP |
919 | if (trace->stream_classes) { |
920 | g_ptr_array_free(trace->stream_classes, TRUE); | |
921 | trace->stream_classes = NULL; | |
46bdd3e0 PP |
922 | } |
923 | ||
cd03c43c | 924 | g_free(trace); |
46bdd3e0 PP |
925 | } |
926 | ||
927 | static inline | |
cd03c43c | 928 | struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace) |
46bdd3e0 | 929 | { |
cd03c43c PP |
930 | struct fs_sink_ctf_trace *trace = |
931 | g_new0(struct fs_sink_ctf_trace, 1); | |
46bdd3e0 | 932 | |
cd03c43c | 933 | BT_ASSERT(trace); |
46bdd3e0 | 934 | |
d126826c | 935 | bt_uuid_generate(trace->uuid); |
46bdd3e0 | 936 | |
cd03c43c PP |
937 | trace->ir_trace = ir_trace; |
938 | trace->ir_tc = bt_trace_borrow_class_const(ir_trace); | |
939 | trace->stream_classes = g_ptr_array_new_with_free_func( | |
46bdd3e0 | 940 | (GDestroyNotify) fs_sink_ctf_stream_class_destroy); |
cd03c43c | 941 | BT_ASSERT(trace->stream_classes); |
46bdd3e0 | 942 | |
cd03c43c | 943 | return trace; |
46bdd3e0 PP |
944 | } |
945 | ||
46bdd3e0 | 946 | #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */ |