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