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