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