Add bt_common_abort() and use it instead of abort() directly
[babeltrace.git] / src / plugins / ctf / fs-sink / fs-sink-ctf-meta.h
CommitLineData
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
28enum 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
41struct 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
53struct fs_sink_ctf_field_class_bit_array {
54 struct fs_sink_ctf_field_class base;
55 unsigned int size;
56};
57
dc9cc972
PP
58struct fs_sink_ctf_field_class_bool {
59 struct fs_sink_ctf_field_class_bit_array base;
60};
61
46bdd3e0
PP
62struct fs_sink_ctf_field_class_int {
63 struct fs_sink_ctf_field_class_bit_array base;
64 bool is_signed;
65};
66
67struct fs_sink_ctf_field_class_float {
68 struct fs_sink_ctf_field_class_bit_array base;
69};
70
71struct fs_sink_ctf_field_class_string {
72 struct fs_sink_ctf_field_class base;
73};
74
75struct fs_sink_ctf_named_field_class {
76 GString *name;
77
78 /* Owned by this */
79 struct fs_sink_ctf_field_class *fc;
80};
81
82struct 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
89struct 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
95struct 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
104struct 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
109struct fs_sink_ctf_field_class_array {
110 struct fs_sink_ctf_field_class_array_base base;
111 uint64_t length;
112};
113
114struct 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
120struct fs_sink_ctf_stream_class;
121
122struct 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 136struct fs_sink_ctf_trace;
46bdd3e0
PP
137
138struct 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
172struct 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
185static inline
186void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc);
187
188static inline
189void _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
201static inline
202void _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
213static inline
214void _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);
94847783
PP
224 fc->is_signed = bt_field_class_type_is(ir_fc_type,
225 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
46bdd3e0
PP
226}
227
228static inline
229void _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
237static inline
238void _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
252static inline
253struct fs_sink_ctf_field_class_bit_array *
254fs_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
268static inline
269struct 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
287static inline
288struct 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
300static inline
301struct 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,
76276a81 310 ir_fc,
94847783
PP
311 bt_field_class_get_type(ir_fc) ==
312 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
46bdd3e0
PP
313 index_in_parent);
314 return fc;
315}
316
317static inline
318struct fs_sink_ctf_field_class_string *fs_sink_ctf_field_class_string_create(
319 const bt_field_class *ir_fc, uint64_t index_in_parent)
320{
321 struct fs_sink_ctf_field_class_string *fc =
322 g_new0(struct fs_sink_ctf_field_class_string, 1);
323
324 BT_ASSERT(fc);
325 _fs_sink_ctf_field_class_init((void *) fc,
326 FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, ir_fc,
327 8, index_in_parent);
328 return fc;
329}
330
331static inline
332struct fs_sink_ctf_field_class_struct *fs_sink_ctf_field_class_struct_create_empty(
333 const bt_field_class *ir_fc, uint64_t index_in_parent)
334{
335 struct fs_sink_ctf_field_class_struct *fc =
336 g_new0(struct fs_sink_ctf_field_class_struct, 1);
337
338 BT_ASSERT(fc);
339 _fs_sink_ctf_field_class_init((void *) fc,
340 FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT, ir_fc, 1, index_in_parent);
341 fc->members = g_array_new(FALSE, TRUE,
342 sizeof(struct fs_sink_ctf_named_field_class));
343 BT_ASSERT(fc->members);
344 return fc;
345}
346
c27259b0
PP
347static inline
348struct fs_sink_ctf_field_class_option *fs_sink_ctf_field_class_option_create_empty(
349 const bt_field_class *ir_fc, uint64_t index_in_parent)
350{
351 struct fs_sink_ctf_field_class_option *fc =
352 g_new0(struct fs_sink_ctf_field_class_option, 1);
353
354 BT_ASSERT(fc);
355 _fs_sink_ctf_field_class_init((void *) fc,
356 FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc,
357 1, index_in_parent);
358 fc->tag_ref = g_string_new(NULL);
359 BT_ASSERT(fc->tag_ref);
360 return fc;
361}
362
46bdd3e0
PP
363static inline
364struct fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_variant_create_empty(
365 const bt_field_class *ir_fc, uint64_t index_in_parent)
366{
367 struct fs_sink_ctf_field_class_variant *fc =
368 g_new0(struct fs_sink_ctf_field_class_variant, 1);
369
370 BT_ASSERT(fc);
371 _fs_sink_ctf_field_class_init((void *) fc,
372 FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT, ir_fc,
373 1, index_in_parent);
374 fc->options = g_array_new(FALSE, TRUE,
375 sizeof(struct fs_sink_ctf_named_field_class));
376 BT_ASSERT(fc->options);
377 fc->tag_ref = g_string_new(NULL);
378 BT_ASSERT(fc->tag_ref);
379 fc->tag_is_before =
02b61fe0 380 bt_field_class_get_type(fc->base.ir_fc) ==
8bc207af 381 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD;
46bdd3e0
PP
382 return fc;
383}
384
385static inline
386struct fs_sink_ctf_field_class_array *fs_sink_ctf_field_class_array_create_empty(
387 const bt_field_class *ir_fc, uint64_t index_in_parent)
388{
389 struct fs_sink_ctf_field_class_array *fc =
390 g_new0(struct fs_sink_ctf_field_class_array, 1);
391
392 BT_ASSERT(fc);
393 _fs_sink_ctf_field_class_init((void *) fc,
394 FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc,
395 1, index_in_parent);
60bbfc7c 396 fc->length = bt_field_class_array_static_get_length(ir_fc);
46bdd3e0
PP
397 return fc;
398}
399
400static inline
401struct fs_sink_ctf_field_class_sequence *fs_sink_ctf_field_class_sequence_create_empty(
402 const bt_field_class *ir_fc, uint64_t index_in_parent)
403{
404 struct fs_sink_ctf_field_class_sequence *fc =
405 g_new0(struct fs_sink_ctf_field_class_sequence, 1);
406
407 BT_ASSERT(fc);
408 _fs_sink_ctf_field_class_init((void *) fc,
409 FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE,
410 ir_fc, 1, index_in_parent);
411 fc->length_ref = g_string_new(NULL);
412 BT_ASSERT(fc->length_ref);
413 fc->length_is_before =
b8ddb4f0
PP
414 bt_field_class_get_type(ir_fc) ==
415 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD;
46bdd3e0
PP
416 return fc;
417}
418
419static inline
420struct fs_sink_ctf_named_field_class *
421fs_sink_ctf_field_class_struct_borrow_member_by_index(
422 struct fs_sink_ctf_field_class_struct *fc, uint64_t index);
423
424static inline
425struct fs_sink_ctf_named_field_class *
426fs_sink_ctf_field_class_variant_borrow_option_by_index(
427 struct fs_sink_ctf_field_class_variant *fc, uint64_t index);
428
429static inline
430void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc)
431{
432 BT_ASSERT(fc);
433}
434
adec7d09
PP
435static inline
436void _fs_sink_ctf_field_class_bit_array_destroy(
437 struct fs_sink_ctf_field_class_int *fc)
438{
439 BT_ASSERT(fc);
440 _fs_sink_ctf_field_class_fini((void *) fc);
441 g_free(fc);
442}
443
dc9cc972
PP
444static inline
445void _fs_sink_ctf_field_class_bool_destroy(
446 struct fs_sink_ctf_field_class_int *fc)
447{
448 BT_ASSERT(fc);
449 _fs_sink_ctf_field_class_fini((void *) fc);
450 g_free(fc);
451}
452
46bdd3e0
PP
453static inline
454void _fs_sink_ctf_field_class_int_destroy(
455 struct fs_sink_ctf_field_class_int *fc)
456{
457 BT_ASSERT(fc);
458 _fs_sink_ctf_field_class_fini((void *) fc);
459 g_free(fc);
460}
461
462static inline
463void _fs_sink_ctf_field_class_float_destroy(
464 struct fs_sink_ctf_field_class_float *fc)
465{
466 BT_ASSERT(fc);
467 _fs_sink_ctf_field_class_fini((void *) fc);
468 g_free(fc);
469}
470
471static inline
472void _fs_sink_ctf_field_class_string_destroy(
473 struct fs_sink_ctf_field_class_string *fc)
474{
475 BT_ASSERT(fc);
476 _fs_sink_ctf_field_class_fini((void *) fc);
477 g_free(fc);
478}
479
480static inline
481void _fs_sink_ctf_field_class_struct_destroy(
482 struct fs_sink_ctf_field_class_struct *fc)
483{
484 BT_ASSERT(fc);
485 _fs_sink_ctf_field_class_fini((void *) fc);
486
487 if (fc->members) {
488 uint64_t i;
489
490 for (i = 0; i < fc->members->len; i++) {
491 struct fs_sink_ctf_named_field_class *named_fc =
492 fs_sink_ctf_field_class_struct_borrow_member_by_index(
493 fc, i);
494
495 _fs_sink_ctf_named_field_class_fini(named_fc);
496 }
497
498 g_array_free(fc->members, TRUE);
499 fc->members = NULL;
500 }
501
502 g_free(fc);
503}
504
505static inline
506void _fs_sink_ctf_field_class_array_base_fini(
507 struct fs_sink_ctf_field_class_array_base *fc)
508{
509 BT_ASSERT(fc);
510 _fs_sink_ctf_field_class_fini((void *) fc);
511 fs_sink_ctf_field_class_destroy(fc->elem_fc);
512 fc->elem_fc = NULL;
513}
514
515static inline
516void _fs_sink_ctf_field_class_array_destroy(
517 struct fs_sink_ctf_field_class_array *fc)
518{
519 BT_ASSERT(fc);
520 _fs_sink_ctf_field_class_array_base_fini((void *) fc);
521 g_free(fc);
522}
523
524static inline
525void _fs_sink_ctf_field_class_sequence_destroy(
526 struct fs_sink_ctf_field_class_sequence *fc)
527{
528 BT_ASSERT(fc);
529 _fs_sink_ctf_field_class_array_base_fini((void *) fc);
530
531 if (fc->length_ref) {
532 g_string_free(fc->length_ref, TRUE);
533 fc->length_ref = NULL;
534 }
535
536 g_free(fc);
537}
538
c27259b0
PP
539static inline
540void _fs_sink_ctf_field_class_option_destroy(
541 struct fs_sink_ctf_field_class_option *fc)
542{
543 BT_ASSERT(fc);
544 _fs_sink_ctf_field_class_fini((void *) fc);
545 fs_sink_ctf_field_class_destroy(fc->content_fc);
546
547 if (fc->tag_ref) {
548 g_string_free(fc->tag_ref, TRUE);
549 fc->tag_ref = NULL;
550 }
551
552 g_free(fc);
553}
554
46bdd3e0
PP
555static inline
556void _fs_sink_ctf_field_class_variant_destroy(
557 struct fs_sink_ctf_field_class_variant *fc)
558{
559 BT_ASSERT(fc);
560 _fs_sink_ctf_field_class_fini((void *) fc);
561
562 if (fc->options) {
563 uint64_t i;
564
565 for (i = 0; i < fc->options->len; i++) {
566 struct fs_sink_ctf_named_field_class *named_fc =
567 fs_sink_ctf_field_class_variant_borrow_option_by_index(
568 fc, i);
569
570 _fs_sink_ctf_named_field_class_fini(named_fc);
571 }
572
573 g_array_free(fc->options, TRUE);
574 fc->options = NULL;
575 }
576
577 if (fc->tag_ref) {
578 g_string_free(fc->tag_ref, TRUE);
579 fc->tag_ref = NULL;
580 }
581
582 g_free(fc);
583}
584
585static inline
586void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
587{
588 if (!fc) {
589 return;
590 }
591
592 switch (fc->type) {
dc9cc972
PP
593 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL:
594 _fs_sink_ctf_field_class_bool_destroy((void *) fc);
595 break;
adec7d09
PP
596 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY:
597 _fs_sink_ctf_field_class_bit_array_destroy((void *) fc);
598 break;
46bdd3e0
PP
599 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT:
600 _fs_sink_ctf_field_class_int_destroy((void *) fc);
601 break;
602 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT:
603 _fs_sink_ctf_field_class_float_destroy((void *) fc);
604 break;
605 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING:
606 _fs_sink_ctf_field_class_string_destroy((void *) fc);
607 break;
608 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
609 _fs_sink_ctf_field_class_struct_destroy((void *) fc);
610 break;
611 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
612 _fs_sink_ctf_field_class_array_destroy((void *) fc);
613 break;
614 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
615 _fs_sink_ctf_field_class_sequence_destroy((void *) fc);
616 break;
c27259b0
PP
617 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION:
618 _fs_sink_ctf_field_class_option_destroy((void *) fc);
619 break;
46bdd3e0
PP
620 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
621 _fs_sink_ctf_field_class_variant_destroy((void *) fc);
622 break;
623 default:
24847fc7 624 bt_common_abort();
46bdd3e0
PP
625 }
626}
627
628static inline
629struct fs_sink_ctf_named_field_class *
630fs_sink_ctf_field_class_struct_borrow_member_by_index(
631 struct fs_sink_ctf_field_class_struct *fc, uint64_t index)
632{
ec4a3354
PP
633 BT_ASSERT_DBG(fc);
634 BT_ASSERT_DBG(index < fc->members->len);
46bdd3e0
PP
635 return &g_array_index(fc->members, struct fs_sink_ctf_named_field_class,
636 index);
637}
638
639static inline
640struct fs_sink_ctf_named_field_class *
641fs_sink_ctf_field_class_struct_borrow_member_by_name(
642 struct fs_sink_ctf_field_class_struct *fc, const char *name)
643{
644 uint64_t i;
645 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
646
ec4a3354
PP
647 BT_ASSERT_DBG(fc);
648 BT_ASSERT_DBG(name);
46bdd3e0
PP
649
650 for (i = 0; i < fc->members->len; i++) {
651 struct fs_sink_ctf_named_field_class *named_fc =
652 fs_sink_ctf_field_class_struct_borrow_member_by_index(
653 fc, i);
654
655 if (strcmp(name, named_fc->name->str) == 0) {
656 ret_named_fc = named_fc;
657 goto end;
658 }
659 }
660
661end:
662 return ret_named_fc;
663}
664
665static inline
666struct fs_sink_ctf_field_class *
667fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
668 struct fs_sink_ctf_field_class_struct *struct_fc, const char *name)
669{
670 struct fs_sink_ctf_named_field_class *named_fc = NULL;
671 struct fs_sink_ctf_field_class *fc = NULL;
672
673 if (!struct_fc) {
674 goto end;
675 }
676
677 named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_name(
678 struct_fc, name);
679 if (!named_fc) {
680 goto end;
681 }
682
683 fc = named_fc->fc;
684
685end:
686 return fc;
687}
688
689static inline
690struct fs_sink_ctf_field_class_int *
691fs_sink_ctf_field_class_struct_borrow_member_int_field_class_by_name(
692 struct fs_sink_ctf_field_class_struct *struct_fc,
693 const char *name)
694{
695 struct fs_sink_ctf_field_class_int *int_fc = NULL;
696
697 int_fc = (void *)
698 fs_sink_ctf_field_class_struct_borrow_member_field_class_by_name(
699 struct_fc, name);
700 if (!int_fc) {
701 goto end;
702 }
703
704 if (int_fc->base.base.type != FS_SINK_CTF_FIELD_CLASS_TYPE_INT) {
705 int_fc = NULL;
706 goto end;
707 }
708
709end:
710 return int_fc;
711}
712
713static inline
714void fs_sink_ctf_field_class_struct_align_at_least(
715 struct fs_sink_ctf_field_class_struct *fc,
716 unsigned int alignment)
717{
718 if (alignment > fc->base.alignment) {
719 fc->base.alignment = alignment;
720 }
721}
722
723static inline
724void fs_sink_ctf_field_class_struct_append_member(
725 struct fs_sink_ctf_field_class_struct *fc,
726 const char *name, struct fs_sink_ctf_field_class *member_fc)
727{
728 struct fs_sink_ctf_named_field_class *named_fc;
729
730 BT_ASSERT(fc);
731 BT_ASSERT(name);
732 g_array_set_size(fc->members, fc->members->len + 1);
733
734 named_fc = &g_array_index(fc->members,
735 struct fs_sink_ctf_named_field_class, fc->members->len - 1);
736 _fs_sink_ctf_named_field_class_init(named_fc);
737 g_string_assign(named_fc->name, name);
738 named_fc->fc = member_fc;
739 fs_sink_ctf_field_class_struct_align_at_least(fc, member_fc->alignment);
740}
741
742static inline
743struct fs_sink_ctf_named_field_class *
744fs_sink_ctf_field_class_variant_borrow_option_by_index(
745 struct fs_sink_ctf_field_class_variant *fc, uint64_t index)
746{
ec4a3354
PP
747 BT_ASSERT_DBG(fc);
748 BT_ASSERT_DBG(index < fc->options->len);
46bdd3e0
PP
749 return &g_array_index(fc->options, struct fs_sink_ctf_named_field_class,
750 index);
751}
752
753static inline
754struct fs_sink_ctf_named_field_class *
755fs_sink_ctf_field_class_variant_borrow_option_by_name(
756 struct fs_sink_ctf_field_class_variant *fc, const char *name)
757{
758 uint64_t i;
759 struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
760
ec4a3354
PP
761 BT_ASSERT_DBG(fc);
762 BT_ASSERT_DBG(name);
46bdd3e0
PP
763
764 for (i = 0; i < fc->options->len; i++) {
765 struct fs_sink_ctf_named_field_class *named_fc =
766 fs_sink_ctf_field_class_variant_borrow_option_by_index(
767 fc, i);
768
769 if (strcmp(name, named_fc->name->str) == 0) {
770 ret_named_fc = named_fc;
771 goto end;
772 }
773 }
774
775end:
776 return ret_named_fc;
777}
778
779static inline
780void fs_sink_ctf_field_class_variant_append_option(
781 struct fs_sink_ctf_field_class_variant *fc,
782 const char *name, struct fs_sink_ctf_field_class *option_fc)
783{
784 struct fs_sink_ctf_named_field_class *named_fc;
785
786 BT_ASSERT(fc);
787 BT_ASSERT(name);
788 g_array_set_size(fc->options, fc->options->len + 1);
789
790 named_fc = &g_array_index(fc->options,
791 struct fs_sink_ctf_named_field_class, fc->options->len - 1);
792 _fs_sink_ctf_named_field_class_init(named_fc);
793 g_string_assign(named_fc->name, name);
794 named_fc->fc = option_fc;
795}
796
797static inline
798struct fs_sink_ctf_event_class *fs_sink_ctf_event_class_create(
799 struct fs_sink_ctf_stream_class *sc,
800 const bt_event_class *ir_ec)
801{
802 struct fs_sink_ctf_event_class *ec =
803 g_new0(struct fs_sink_ctf_event_class, 1);
804
805 BT_ASSERT(sc);
806 BT_ASSERT(ir_ec);
807 BT_ASSERT(ec);
808 ec->ir_ec = ir_ec;
809 ec->sc = sc;
810 g_ptr_array_add(sc->event_classes, ec);
811 g_hash_table_insert(sc->event_classes_from_ir, (gpointer) ir_ec, ec);
812 return ec;
813}
814
815static inline
816void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec)
817{
818 if (!ec) {
819 return;
820 }
821
822 fs_sink_ctf_field_class_destroy(ec->spec_context_fc);
823 ec->spec_context_fc = NULL;
824 fs_sink_ctf_field_class_destroy(ec->payload_fc);
825 ec->payload_fc = NULL;
826 g_free(ec);
827}
828
829static inline
830struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create(
cd03c43c 831 struct fs_sink_ctf_trace *trace,
46bdd3e0
PP
832 const bt_stream_class *ir_sc)
833{
834 struct fs_sink_ctf_stream_class *sc =
835 g_new0(struct fs_sink_ctf_stream_class, 1);
836
cd03c43c 837 BT_ASSERT(trace);
46bdd3e0
PP
838 BT_ASSERT(ir_sc);
839 BT_ASSERT(sc);
cd03c43c 840 sc->trace = trace;
46bdd3e0
PP
841 sc->ir_sc = ir_sc;
842 sc->default_clock_class =
843 bt_stream_class_borrow_default_clock_class_const(ir_sc);
844 sc->default_clock_class_name = g_string_new(NULL);
845 BT_ASSERT(sc->default_clock_class_name);
846 sc->event_classes = g_ptr_array_new_with_free_func(
847 (GDestroyNotify) fs_sink_ctf_event_class_destroy);
848 BT_ASSERT(sc->event_classes);
849 sc->event_classes_from_ir = g_hash_table_new(g_direct_hash,
850 g_direct_equal);
851 BT_ASSERT(sc->event_classes_from_ir);
37a93d41 852 sc->has_packets = bt_stream_class_supports_packets(ir_sc);
032880f0 853 sc->packets_have_ts_begin =
5ef34326 854 bt_stream_class_packets_have_beginning_default_clock_snapshot(
032880f0
PP
855 ir_sc);
856 sc->packets_have_ts_end =
5ef34326 857 bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
032880f0
PP
858 sc->has_discarded_events =
859 bt_stream_class_supports_discarded_events(ir_sc);
860
861 if (sc->has_discarded_events) {
862 sc->discarded_events_has_ts =
863 bt_stream_class_discarded_events_have_default_clock_snapshots(
864 ir_sc);
865 }
866
867 if (bt_stream_class_supports_discarded_packets(ir_sc)) {
868 sc->discarded_packets_has_ts =
869 bt_stream_class_discarded_packets_have_default_clock_snapshots(
870 ir_sc);
871 }
872
cd03c43c 873 g_ptr_array_add(trace->stream_classes, sc);
46bdd3e0
PP
874 return sc;
875}
876
877static inline
878void fs_sink_ctf_stream_class_destroy(struct fs_sink_ctf_stream_class *sc)
879{
880 if (!sc) {
881 return;
882 }
883
884 if (sc->default_clock_class_name) {
885 g_string_free(sc->default_clock_class_name, TRUE);
886 sc->default_clock_class_name = NULL;
887 }
888
889 if (sc->event_classes) {
890 g_ptr_array_free(sc->event_classes, TRUE);
891 sc->event_classes = NULL;
892 }
893
894 if (sc->event_classes_from_ir) {
895 g_hash_table_destroy(sc->event_classes_from_ir);
896 sc->event_classes_from_ir = NULL;
897 }
898
899 fs_sink_ctf_field_class_destroy(sc->packet_context_fc);
900 sc->packet_context_fc = NULL;
901 fs_sink_ctf_field_class_destroy(sc->event_common_context_fc);
902 sc->event_common_context_fc = NULL;
903 g_free(sc);
904}
905
906static inline
907void fs_sink_ctf_stream_class_append_event_class(
908 struct fs_sink_ctf_stream_class *sc,
909 struct fs_sink_ctf_event_class *ec)
910{
911 g_ptr_array_add(sc->event_classes, ec);
912}
913
914static inline
cd03c43c 915void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace)
46bdd3e0 916{
cd03c43c 917 if (!trace) {
46bdd3e0
PP
918 return;
919 }
920
cd03c43c
PP
921 if (trace->stream_classes) {
922 g_ptr_array_free(trace->stream_classes, TRUE);
923 trace->stream_classes = NULL;
46bdd3e0
PP
924 }
925
cd03c43c 926 g_free(trace);
46bdd3e0
PP
927}
928
929static inline
cd03c43c 930struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
46bdd3e0 931{
cd03c43c
PP
932 struct fs_sink_ctf_trace *trace =
933 g_new0(struct fs_sink_ctf_trace, 1);
46bdd3e0 934
cd03c43c 935 BT_ASSERT(trace);
46bdd3e0 936
d126826c 937 bt_uuid_generate(trace->uuid);
46bdd3e0 938
cd03c43c
PP
939 trace->ir_trace = ir_trace;
940 trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
941 trace->stream_classes = g_ptr_array_new_with_free_func(
46bdd3e0 942 (GDestroyNotify) fs_sink_ctf_stream_class_destroy);
cd03c43c 943 BT_ASSERT(trace->stream_classes);
46bdd3e0 944
cd03c43c 945 return trace;
46bdd3e0
PP
946}
947
46bdd3e0 948#endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_CTF_META_H */
This page took 0.081745 seconds and 4 git commands to generate.