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