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