Commit | Line | Data |
---|---|---|
7b33a0e0 PP |
1 | /* |
2 | * Copyright 2018 - Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | */ | |
14 | ||
15 | #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-TRANSLATE" | |
16 | #include "logging.h" | |
17 | ||
18 | #include <babeltrace/babeltrace.h> | |
19 | #include <babeltrace/babeltrace-internal.h> | |
20 | #include <babeltrace/assert-internal.h> | |
21 | #include <glib.h> | |
22 | #include <stdint.h> | |
23 | #include <string.h> | |
24 | #include <inttypes.h> | |
25 | ||
26 | #include "ctf-meta-visitors.h" | |
27 | ||
28 | static inline | |
8eee8ea2 | 29 | bt_field_class *ctf_field_class_to_ir(struct ctf_field_class *fc, |
7b33a0e0 PP |
30 | struct ctf_trace_class *tc, |
31 | struct ctf_stream_class *sc, | |
32 | struct ctf_event_class *ec); | |
33 | ||
34 | static inline | |
939190b3 | 35 | void ctf_field_class_int_set_props(struct ctf_field_class_int *fc, |
8eee8ea2 | 36 | bt_field_class *ir_fc) |
7b33a0e0 | 37 | { |
78cf9df6 | 38 | bt_field_class_integer_set_field_value_range(ir_fc, |
9e550e5f | 39 | fc->base.size); |
78cf9df6 | 40 | bt_field_class_integer_set_preferred_display_base(ir_fc, |
939190b3 | 41 | fc->disp_base); |
7b33a0e0 PP |
42 | } |
43 | ||
44 | static inline | |
8eee8ea2 | 45 | bt_field_class *ctf_field_class_int_to_ir( |
9e550e5f | 46 | struct ctf_field_class_int *fc) |
7b33a0e0 | 47 | { |
8eee8ea2 | 48 | bt_field_class *ir_fc; |
7b33a0e0 | 49 | |
939190b3 | 50 | if (fc->is_signed) { |
78cf9df6 | 51 | ir_fc = bt_field_class_signed_integer_create(); |
7b33a0e0 | 52 | } else { |
78cf9df6 | 53 | ir_fc = bt_field_class_unsigned_integer_create(); |
7b33a0e0 PP |
54 | } |
55 | ||
939190b3 PP |
56 | BT_ASSERT(ir_fc); |
57 | ctf_field_class_int_set_props(fc, ir_fc); | |
58 | return ir_fc; | |
7b33a0e0 PP |
59 | } |
60 | ||
61 | static inline | |
8eee8ea2 | 62 | bt_field_class *ctf_field_class_enum_to_ir( |
9e550e5f | 63 | struct ctf_field_class_enum *fc) |
7b33a0e0 PP |
64 | { |
65 | int ret; | |
8eee8ea2 | 66 | bt_field_class *ir_fc; |
7b33a0e0 PP |
67 | uint64_t i; |
68 | ||
939190b3 | 69 | if (fc->base.is_signed) { |
78cf9df6 | 70 | ir_fc = bt_field_class_signed_enumeration_create(); |
7b33a0e0 | 71 | } else { |
78cf9df6 | 72 | ir_fc = bt_field_class_unsigned_enumeration_create(); |
7b33a0e0 PP |
73 | } |
74 | ||
939190b3 PP |
75 | BT_ASSERT(ir_fc); |
76 | ctf_field_class_int_set_props((void *) fc, ir_fc); | |
7b33a0e0 | 77 | |
939190b3 PP |
78 | for (i = 0; i < fc->mappings->len; i++) { |
79 | struct ctf_field_class_enum_mapping *mapping = | |
80 | ctf_field_class_enum_borrow_mapping_by_index(fc, i); | |
7b33a0e0 | 81 | |
939190b3 | 82 | if (fc->base.is_signed) { |
78cf9df6 | 83 | ret = bt_field_class_signed_enumeration_map_range( |
939190b3 | 84 | ir_fc, mapping->label->str, |
7b33a0e0 PP |
85 | mapping->range.lower.i, mapping->range.upper.i); |
86 | } else { | |
78cf9df6 | 87 | ret = bt_field_class_unsigned_enumeration_map_range( |
939190b3 | 88 | ir_fc, mapping->label->str, |
7b33a0e0 PP |
89 | mapping->range.lower.u, mapping->range.upper.u); |
90 | } | |
91 | ||
92 | BT_ASSERT(ret == 0); | |
93 | } | |
94 | ||
939190b3 | 95 | return ir_fc; |
7b33a0e0 PP |
96 | } |
97 | ||
98 | static inline | |
8eee8ea2 | 99 | bt_field_class *ctf_field_class_float_to_ir( |
939190b3 | 100 | struct ctf_field_class_float *fc) |
7b33a0e0 | 101 | { |
8eee8ea2 | 102 | bt_field_class *ir_fc; |
7b33a0e0 | 103 | |
78cf9df6 | 104 | ir_fc = bt_field_class_real_create(); |
939190b3 | 105 | BT_ASSERT(ir_fc); |
7b33a0e0 | 106 | |
939190b3 | 107 | if (fc->base.size == 32) { |
78cf9df6 | 108 | bt_field_class_real_set_is_single_precision(ir_fc, |
7b33a0e0 | 109 | BT_TRUE); |
7b33a0e0 PP |
110 | } |
111 | ||
939190b3 | 112 | return ir_fc; |
7b33a0e0 PP |
113 | } |
114 | ||
115 | static inline | |
8eee8ea2 | 116 | bt_field_class *ctf_field_class_string_to_ir( |
939190b3 | 117 | struct ctf_field_class_string *fc) |
7b33a0e0 | 118 | { |
8eee8ea2 | 119 | bt_field_class *ir_fc = |
78cf9df6 | 120 | bt_field_class_string_create(); |
7b33a0e0 | 121 | |
939190b3 PP |
122 | BT_ASSERT(ir_fc); |
123 | return ir_fc; | |
7b33a0e0 PP |
124 | } |
125 | ||
126 | static inline | |
8eee8ea2 | 127 | bt_field_class *ctf_field_class_struct_to_ir( |
939190b3 | 128 | struct ctf_field_class_struct *fc, |
7b33a0e0 PP |
129 | struct ctf_trace_class *tc, |
130 | struct ctf_stream_class *sc, | |
131 | struct ctf_event_class *ec) | |
132 | { | |
133 | int ret; | |
8eee8ea2 | 134 | bt_field_class *ir_fc = |
78cf9df6 | 135 | bt_field_class_structure_create(); |
7b33a0e0 PP |
136 | uint64_t i; |
137 | ||
939190b3 | 138 | BT_ASSERT(ir_fc); |
7b33a0e0 | 139 | |
939190b3 PP |
140 | for (i = 0; i < fc->members->len; i++) { |
141 | struct ctf_named_field_class *named_fc = | |
142 | ctf_field_class_struct_borrow_member_by_index(fc, i); | |
8eee8ea2 | 143 | bt_field_class *member_ir_fc; |
7b33a0e0 | 144 | |
939190b3 | 145 | if (!named_fc->fc->in_ir) { |
7b33a0e0 PP |
146 | continue; |
147 | } | |
148 | ||
939190b3 PP |
149 | member_ir_fc = ctf_field_class_to_ir(named_fc->fc, tc, sc, ec); |
150 | BT_ASSERT(member_ir_fc); | |
78cf9df6 | 151 | ret = bt_field_class_structure_append_member( |
9e550e5f | 152 | ir_fc, named_fc->name->str, member_ir_fc); |
7b33a0e0 | 153 | BT_ASSERT(ret == 0); |
8c6884d9 | 154 | bt_field_class_put_ref(member_ir_fc); |
7b33a0e0 PP |
155 | } |
156 | ||
939190b3 | 157 | return ir_fc; |
7b33a0e0 PP |
158 | } |
159 | ||
160 | static inline | |
8eee8ea2 | 161 | bt_field_class *borrow_ir_ft_from_field_path( |
7b33a0e0 PP |
162 | struct ctf_field_path *field_path, |
163 | struct ctf_trace_class *tc, | |
164 | struct ctf_stream_class *sc, | |
165 | struct ctf_event_class *ec) | |
166 | { | |
8eee8ea2 | 167 | bt_field_class *ir_fc = NULL; |
939190b3 | 168 | struct ctf_field_class *fc = ctf_field_path_borrow_field_class( |
7b33a0e0 PP |
169 | field_path, tc, sc, ec); |
170 | ||
939190b3 | 171 | BT_ASSERT(fc); |
7b33a0e0 | 172 | |
939190b3 PP |
173 | if (fc->in_ir) { |
174 | ir_fc = fc->ir_fc; | |
7b33a0e0 PP |
175 | } |
176 | ||
939190b3 | 177 | return ir_fc; |
7b33a0e0 PP |
178 | } |
179 | ||
180 | static inline | |
8eee8ea2 | 181 | bt_field_class *ctf_field_class_variant_to_ir( |
939190b3 | 182 | struct ctf_field_class_variant *fc, |
7b33a0e0 PP |
183 | struct ctf_trace_class *tc, |
184 | struct ctf_stream_class *sc, | |
185 | struct ctf_event_class *ec) | |
186 | { | |
187 | int ret; | |
8eee8ea2 | 188 | bt_field_class *ir_fc = |
78cf9df6 | 189 | bt_field_class_variant_create(); |
7b33a0e0 PP |
190 | uint64_t i; |
191 | ||
939190b3 | 192 | BT_ASSERT(ir_fc); |
78cf9df6 | 193 | ret = bt_field_class_variant_set_selector_field_class( |
9e550e5f | 194 | ir_fc, borrow_ir_ft_from_field_path(&fc->tag_path, tc, sc, ec)); |
7b33a0e0 PP |
195 | BT_ASSERT(ret == 0); |
196 | ||
939190b3 PP |
197 | for (i = 0; i < fc->options->len; i++) { |
198 | struct ctf_named_field_class *named_fc = | |
199 | ctf_field_class_variant_borrow_option_by_index(fc, i); | |
8eee8ea2 | 200 | bt_field_class *option_ir_fc; |
7b33a0e0 | 201 | |
939190b3 PP |
202 | BT_ASSERT(named_fc->fc->in_ir); |
203 | option_ir_fc = ctf_field_class_to_ir(named_fc->fc, tc, sc, ec); | |
204 | BT_ASSERT(option_ir_fc); | |
78cf9df6 | 205 | ret = bt_field_class_variant_append_option( |
9e550e5f | 206 | ir_fc, named_fc->name->str, option_ir_fc); |
7b33a0e0 | 207 | BT_ASSERT(ret == 0); |
8c6884d9 | 208 | bt_field_class_put_ref(option_ir_fc); |
7b33a0e0 PP |
209 | } |
210 | ||
939190b3 | 211 | return ir_fc; |
7b33a0e0 PP |
212 | } |
213 | ||
214 | static inline | |
8eee8ea2 | 215 | bt_field_class *ctf_field_class_array_to_ir( |
939190b3 | 216 | struct ctf_field_class_array *fc, |
7b33a0e0 PP |
217 | struct ctf_trace_class *tc, |
218 | struct ctf_stream_class *sc, | |
219 | struct ctf_event_class *ec) | |
220 | { | |
8eee8ea2 PP |
221 | bt_field_class *ir_fc; |
222 | bt_field_class *elem_ir_fc; | |
7b33a0e0 | 223 | |
939190b3 | 224 | if (fc->base.is_text) { |
78cf9df6 | 225 | ir_fc = bt_field_class_string_create(); |
939190b3 | 226 | BT_ASSERT(ir_fc); |
7b33a0e0 PP |
227 | goto end; |
228 | } | |
229 | ||
939190b3 PP |
230 | elem_ir_fc = ctf_field_class_to_ir(fc->base.elem_fc, tc, sc, ec); |
231 | BT_ASSERT(elem_ir_fc); | |
78cf9df6 | 232 | ir_fc = bt_field_class_static_array_create(elem_ir_fc, |
9e550e5f | 233 | fc->length); |
939190b3 | 234 | BT_ASSERT(ir_fc); |
8c6884d9 | 235 | bt_field_class_put_ref(elem_ir_fc); |
7b33a0e0 PP |
236 | |
237 | end: | |
939190b3 | 238 | return ir_fc; |
7b33a0e0 PP |
239 | } |
240 | ||
241 | static inline | |
8eee8ea2 | 242 | bt_field_class *ctf_field_class_sequence_to_ir( |
939190b3 | 243 | struct ctf_field_class_sequence *fc, |
7b33a0e0 PP |
244 | struct ctf_trace_class *tc, |
245 | struct ctf_stream_class *sc, | |
246 | struct ctf_event_class *ec) | |
247 | { | |
248 | int ret; | |
8eee8ea2 PP |
249 | bt_field_class *ir_fc; |
250 | bt_field_class *elem_ir_fc; | |
7b33a0e0 | 251 | |
939190b3 | 252 | if (fc->base.is_text) { |
78cf9df6 | 253 | ir_fc = bt_field_class_string_create(); |
939190b3 | 254 | BT_ASSERT(ir_fc); |
7b33a0e0 PP |
255 | goto end; |
256 | } | |
257 | ||
939190b3 PP |
258 | elem_ir_fc = ctf_field_class_to_ir(fc->base.elem_fc, tc, sc, ec); |
259 | BT_ASSERT(elem_ir_fc); | |
78cf9df6 | 260 | ir_fc = bt_field_class_dynamic_array_create(elem_ir_fc); |
939190b3 | 261 | BT_ASSERT(ir_fc); |
8c6884d9 | 262 | bt_field_class_put_ref(elem_ir_fc); |
939190b3 | 263 | BT_ASSERT(ir_fc); |
78cf9df6 | 264 | ret = bt_field_class_dynamic_array_set_length_field_class( |
9e550e5f | 265 | ir_fc, |
939190b3 | 266 | borrow_ir_ft_from_field_path(&fc->length_path, tc, sc, ec)); |
7b33a0e0 PP |
267 | BT_ASSERT(ret == 0); |
268 | ||
269 | end: | |
939190b3 | 270 | return ir_fc; |
7b33a0e0 PP |
271 | } |
272 | ||
273 | static inline | |
8eee8ea2 | 274 | bt_field_class *ctf_field_class_to_ir(struct ctf_field_class *fc, |
7b33a0e0 PP |
275 | struct ctf_trace_class *tc, |
276 | struct ctf_stream_class *sc, | |
277 | struct ctf_event_class *ec) | |
278 | { | |
8eee8ea2 | 279 | bt_field_class *ir_fc = NULL; |
7b33a0e0 | 280 | |
939190b3 PP |
281 | BT_ASSERT(fc); |
282 | BT_ASSERT(fc->in_ir); | |
7b33a0e0 | 283 | |
af0c18e3 PP |
284 | switch (fc->type) { |
285 | case CTF_FIELD_CLASS_TYPE_INT: | |
939190b3 | 286 | ir_fc = ctf_field_class_int_to_ir((void *) fc); |
7b33a0e0 | 287 | break; |
af0c18e3 | 288 | case CTF_FIELD_CLASS_TYPE_ENUM: |
939190b3 | 289 | ir_fc = ctf_field_class_enum_to_ir((void *) fc); |
7b33a0e0 | 290 | break; |
af0c18e3 | 291 | case CTF_FIELD_CLASS_TYPE_FLOAT: |
939190b3 | 292 | ir_fc = ctf_field_class_float_to_ir((void *) fc); |
7b33a0e0 | 293 | break; |
af0c18e3 | 294 | case CTF_FIELD_CLASS_TYPE_STRING: |
939190b3 | 295 | ir_fc = ctf_field_class_string_to_ir((void *) fc); |
7b33a0e0 | 296 | break; |
af0c18e3 | 297 | case CTF_FIELD_CLASS_TYPE_STRUCT: |
939190b3 | 298 | ir_fc = ctf_field_class_struct_to_ir((void *) fc, tc, sc, ec); |
7b33a0e0 | 299 | break; |
af0c18e3 | 300 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
939190b3 | 301 | ir_fc = ctf_field_class_array_to_ir((void *) fc, tc, sc, ec); |
7b33a0e0 | 302 | break; |
af0c18e3 | 303 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: |
939190b3 | 304 | ir_fc = ctf_field_class_sequence_to_ir((void *) fc, tc, sc, ec); |
7b33a0e0 | 305 | break; |
af0c18e3 | 306 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
939190b3 | 307 | ir_fc = ctf_field_class_variant_to_ir((void *) fc, tc, sc, ec); |
7b33a0e0 PP |
308 | break; |
309 | default: | |
310 | abort(); | |
311 | } | |
312 | ||
939190b3 PP |
313 | fc->ir_fc = ir_fc; |
314 | return ir_fc; | |
7b33a0e0 PP |
315 | } |
316 | ||
317 | static inline | |
939190b3 PP |
318 | bool ctf_field_class_struct_has_immediate_member_in_ir( |
319 | struct ctf_field_class_struct *fc) | |
7b33a0e0 PP |
320 | { |
321 | uint64_t i; | |
322 | bool has_immediate_member_in_ir = false; | |
323 | ||
939190b3 PP |
324 | for (i = 0; i < fc->members->len; i++) { |
325 | struct ctf_named_field_class *named_fc = | |
326 | ctf_field_class_struct_borrow_member_by_index(fc, i); | |
7b33a0e0 | 327 | |
939190b3 | 328 | if (named_fc->fc->in_ir) { |
7b33a0e0 PP |
329 | has_immediate_member_in_ir = true; |
330 | goto end; | |
331 | } | |
332 | } | |
333 | ||
334 | end: | |
335 | return has_immediate_member_in_ir; | |
336 | } | |
337 | ||
338 | static inline | |
8eee8ea2 | 339 | bt_field_class *scope_ctf_field_class_to_ir(struct ctf_field_class *fc, |
7b33a0e0 PP |
340 | struct ctf_trace_class *tc, |
341 | struct ctf_stream_class *sc, | |
342 | struct ctf_event_class *ec) | |
343 | { | |
8eee8ea2 | 344 | bt_field_class *ir_fc = NULL; |
7b33a0e0 | 345 | |
939190b3 | 346 | if (!fc) { |
7b33a0e0 PP |
347 | goto end; |
348 | } | |
349 | ||
af0c18e3 | 350 | BT_ASSERT(fc->type == CTF_FIELD_CLASS_TYPE_STRUCT); |
7b33a0e0 | 351 | |
939190b3 | 352 | if (!ctf_field_class_struct_has_immediate_member_in_ir((void *) fc)) { |
7b33a0e0 PP |
353 | /* |
354 | * Nothing for IR in this scope: typical for packet | |
355 | * header, packet context, and event header. | |
356 | */ | |
357 | goto end; | |
358 | } | |
359 | ||
939190b3 | 360 | ir_fc = ctf_field_class_to_ir(fc, tc, sc, ec); |
7b33a0e0 PP |
361 | |
362 | end: | |
939190b3 | 363 | return ir_fc; |
7b33a0e0 PP |
364 | } |
365 | ||
366 | static inline | |
939190b3 PP |
367 | struct ctf_field_class_int *borrow_named_int_field_class( |
368 | struct ctf_field_class_struct *struct_fc, const char *name) | |
7b33a0e0 | 369 | { |
939190b3 PP |
370 | struct ctf_named_field_class *named_fc = NULL; |
371 | struct ctf_field_class_int *int_fc = NULL; | |
7b33a0e0 | 372 | |
939190b3 | 373 | if (!struct_fc) { |
7b33a0e0 PP |
374 | goto end; |
375 | } | |
376 | ||
939190b3 PP |
377 | named_fc = ctf_field_class_struct_borrow_member_by_name(struct_fc, name); |
378 | if (!named_fc) { | |
7b33a0e0 PP |
379 | goto end; |
380 | } | |
381 | ||
af0c18e3 PP |
382 | if (named_fc->fc->type != CTF_FIELD_CLASS_TYPE_INT && |
383 | named_fc->fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { | |
7b33a0e0 PP |
384 | goto end; |
385 | } | |
386 | ||
939190b3 | 387 | int_fc = (void *) named_fc->fc; |
7b33a0e0 PP |
388 | |
389 | end: | |
939190b3 | 390 | return int_fc; |
7b33a0e0 PP |
391 | } |
392 | ||
393 | static inline | |
8eee8ea2 PP |
394 | bt_event_class *ctf_event_class_to_ir(struct ctf_event_class *ec, |
395 | bt_stream_class *ir_sc, struct ctf_trace_class *tc, | |
7b33a0e0 PP |
396 | struct ctf_stream_class *sc) |
397 | { | |
398 | int ret; | |
8eee8ea2 | 399 | bt_event_class *ir_ec = NULL; |
7b33a0e0 PP |
400 | |
401 | if (ec->is_translated) { | |
78cf9df6 | 402 | ir_ec = bt_stream_class_borrow_event_class_by_id( |
7b33a0e0 PP |
403 | ir_sc, ec->id); |
404 | BT_ASSERT(ir_ec); | |
405 | goto end; | |
406 | } | |
407 | ||
78cf9df6 | 408 | ir_ec = bt_event_class_create_with_id(ir_sc, ec->id); |
7b33a0e0 | 409 | BT_ASSERT(ir_ec); |
8c6884d9 | 410 | bt_event_class_put_ref(ir_ec); |
7b33a0e0 | 411 | |
939190b3 | 412 | if (ec->spec_context_fc) { |
8eee8ea2 | 413 | bt_field_class *ir_fc = scope_ctf_field_class_to_ir( |
939190b3 | 414 | ec->spec_context_fc, tc, sc, ec); |
7b33a0e0 | 415 | |
939190b3 | 416 | if (ir_fc) { |
78cf9df6 | 417 | ret = bt_event_class_set_specific_context_field_class( |
939190b3 | 418 | ir_ec, ir_fc); |
7b33a0e0 | 419 | BT_ASSERT(ret == 0); |
8c6884d9 | 420 | bt_field_class_put_ref(ir_fc); |
7b33a0e0 PP |
421 | } |
422 | } | |
423 | ||
939190b3 | 424 | if (ec->payload_fc) { |
8eee8ea2 | 425 | bt_field_class *ir_fc = scope_ctf_field_class_to_ir( |
939190b3 | 426 | ec->payload_fc, tc, sc, ec); |
7b33a0e0 | 427 | |
939190b3 | 428 | if (ir_fc) { |
78cf9df6 | 429 | ret = bt_event_class_set_payload_field_class(ir_ec, |
939190b3 | 430 | ir_fc); |
7b33a0e0 | 431 | BT_ASSERT(ret == 0); |
8c6884d9 | 432 | bt_field_class_put_ref(ir_fc); |
7b33a0e0 PP |
433 | } |
434 | } | |
435 | ||
436 | if (ec->name->len > 0) { | |
78cf9df6 | 437 | ret = bt_event_class_set_name(ir_ec, ec->name->str); |
7b33a0e0 PP |
438 | BT_ASSERT(ret == 0); |
439 | } | |
440 | ||
441 | if (ec->emf_uri->len > 0) { | |
78cf9df6 | 442 | ret = bt_event_class_set_emf_uri(ir_ec, ec->emf_uri->str); |
7b33a0e0 PP |
443 | BT_ASSERT(ret == 0); |
444 | } | |
445 | ||
446 | if (ec->log_level != -1) { | |
78cf9df6 | 447 | bt_event_class_set_log_level(ir_ec, ec->log_level); |
7b33a0e0 PP |
448 | } |
449 | ||
450 | ec->is_translated = true; | |
451 | ec->ir_ec = ir_ec; | |
452 | ||
453 | end: | |
454 | return ir_ec; | |
455 | } | |
456 | ||
457 | ||
458 | static inline | |
8eee8ea2 PP |
459 | bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc, |
460 | bt_trace_class *ir_tc, struct ctf_trace_class *tc) | |
7b33a0e0 PP |
461 | { |
462 | int ret; | |
8eee8ea2 | 463 | bt_stream_class *ir_sc = NULL; |
939190b3 | 464 | struct ctf_field_class_int *int_fc; |
7b33a0e0 PP |
465 | |
466 | if (sc->is_translated) { | |
10b7a2e4 | 467 | ir_sc = bt_trace_class_borrow_stream_class_by_id(ir_tc, sc->id); |
7b33a0e0 PP |
468 | BT_ASSERT(ir_sc); |
469 | goto end; | |
470 | } | |
471 | ||
10b7a2e4 | 472 | ir_sc = bt_stream_class_create_with_id(ir_tc, sc->id); |
7b33a0e0 | 473 | BT_ASSERT(ir_sc); |
8c6884d9 | 474 | bt_stream_class_put_ref(ir_sc); |
7b33a0e0 | 475 | |
939190b3 | 476 | if (sc->packet_context_fc) { |
8eee8ea2 | 477 | bt_field_class *ir_fc = scope_ctf_field_class_to_ir( |
939190b3 | 478 | sc->packet_context_fc, tc, sc, NULL); |
7b33a0e0 | 479 | |
939190b3 | 480 | if (ir_fc) { |
78cf9df6 | 481 | ret = bt_stream_class_set_packet_context_field_class( |
939190b3 | 482 | ir_sc, ir_fc); |
7b33a0e0 | 483 | BT_ASSERT(ret == 0); |
8c6884d9 | 484 | bt_field_class_put_ref(ir_fc); |
7b33a0e0 PP |
485 | } |
486 | } | |
487 | ||
939190b3 | 488 | if (sc->event_header_fc) { |
8eee8ea2 | 489 | bt_field_class *ir_fc = scope_ctf_field_class_to_ir( |
939190b3 | 490 | sc->event_header_fc, tc, sc, NULL); |
7b33a0e0 | 491 | |
939190b3 | 492 | if (ir_fc) { |
78cf9df6 | 493 | ret = bt_stream_class_set_event_header_field_class( |
9e550e5f | 494 | ir_sc, ir_fc); |
7b33a0e0 | 495 | BT_ASSERT(ret == 0); |
8c6884d9 | 496 | bt_field_class_put_ref(ir_fc); |
7b33a0e0 PP |
497 | } |
498 | } | |
499 | ||
939190b3 | 500 | if (sc->event_common_context_fc) { |
8eee8ea2 | 501 | bt_field_class *ir_fc = scope_ctf_field_class_to_ir( |
939190b3 | 502 | sc->event_common_context_fc, tc, sc, NULL); |
7b33a0e0 | 503 | |
939190b3 | 504 | if (ir_fc) { |
78cf9df6 | 505 | ret = bt_stream_class_set_event_common_context_field_class( |
939190b3 | 506 | ir_sc, ir_fc); |
7b33a0e0 | 507 | BT_ASSERT(ret == 0); |
8c6884d9 | 508 | bt_field_class_put_ref(ir_fc); |
7b33a0e0 PP |
509 | } |
510 | } | |
511 | ||
78cf9df6 | 512 | bt_stream_class_set_assigns_automatic_event_class_id(ir_sc, |
7b33a0e0 | 513 | BT_FALSE); |
78cf9df6 | 514 | bt_stream_class_set_assigns_automatic_stream_id(ir_sc, BT_FALSE); |
7b33a0e0 PP |
515 | |
516 | if (sc->default_clock_class) { | |
35fa110e | 517 | BT_ASSERT(sc->default_clock_class->ir_cc); |
78cf9df6 | 518 | ret = bt_stream_class_set_default_clock_class(ir_sc, |
35fa110e | 519 | sc->default_clock_class->ir_cc); |
7b33a0e0 PP |
520 | BT_ASSERT(ret == 0); |
521 | } | |
522 | ||
939190b3 | 523 | int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc, |
7b33a0e0 | 524 | "events_discarded"); |
939190b3 PP |
525 | if (int_fc) { |
526 | if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT) { | |
78cf9df6 | 527 | bt_stream_class_set_packets_have_discarded_event_counter_snapshot( |
7b33a0e0 | 528 | ir_sc, BT_TRUE); |
7b33a0e0 PP |
529 | } |
530 | } | |
531 | ||
939190b3 | 532 | int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc, |
7b33a0e0 | 533 | "packet_seq_num"); |
939190b3 PP |
534 | if (int_fc) { |
535 | if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT) { | |
78cf9df6 | 536 | bt_stream_class_set_packets_have_packet_counter_snapshot( |
7b33a0e0 | 537 | ir_sc, BT_TRUE); |
7b33a0e0 PP |
538 | } |
539 | } | |
540 | ||
939190b3 | 541 | int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc, |
7b33a0e0 | 542 | "timestamp_begin"); |
939190b3 PP |
543 | if (int_fc) { |
544 | if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME) { | |
ecbb78c0 | 545 | bt_stream_class_set_packets_have_default_beginning_clock_snapshot( |
7b33a0e0 | 546 | ir_sc, BT_TRUE); |
7b33a0e0 PP |
547 | } |
548 | } | |
549 | ||
939190b3 | 550 | int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc, |
7b33a0e0 | 551 | "timestamp_end"); |
939190b3 PP |
552 | if (int_fc) { |
553 | if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_END_TIME) { | |
ecbb78c0 | 554 | bt_stream_class_set_packets_have_default_end_clock_snapshot( |
7b33a0e0 | 555 | ir_sc, BT_TRUE); |
7b33a0e0 PP |
556 | } |
557 | } | |
558 | ||
559 | sc->is_translated = true; | |
560 | sc->ir_sc = ir_sc; | |
561 | ||
562 | end: | |
563 | return ir_sc; | |
564 | } | |
565 | ||
566 | static inline | |
35fa110e PP |
567 | void ctf_clock_class_to_ir(bt_clock_class *ir_cc, struct ctf_clock_class *cc) |
568 | { | |
569 | int ret; | |
570 | ||
571 | if (strlen(cc->name->str) > 0) { | |
572 | ret = bt_clock_class_set_name(ir_cc, cc->name->str); | |
573 | BT_ASSERT(ret == 0); | |
574 | } | |
575 | ||
576 | if (strlen(cc->description->str) > 0) { | |
577 | ret = bt_clock_class_set_description(ir_cc, cc->description->str); | |
578 | BT_ASSERT(ret == 0); | |
579 | } | |
580 | ||
581 | bt_clock_class_set_frequency(ir_cc, cc->frequency); | |
582 | bt_clock_class_set_precision(ir_cc, cc->precision); | |
583 | bt_clock_class_set_offset(ir_cc, cc->offset_seconds, cc->offset_cycles); | |
584 | ||
585 | if (cc->has_uuid) { | |
586 | bt_clock_class_set_uuid(ir_cc, cc->uuid); | |
587 | } | |
588 | ||
589 | bt_clock_class_set_is_absolute(ir_cc, cc->is_absolute); | |
590 | } | |
591 | ||
592 | static inline | |
593 | int ctf_trace_class_to_ir(bt_trace_class *ir_tc, struct ctf_trace_class *tc) | |
7b33a0e0 PP |
594 | { |
595 | int ret = 0; | |
596 | uint64_t i; | |
597 | ||
598 | if (tc->is_translated) { | |
599 | goto end; | |
600 | } | |
601 | ||
939190b3 | 602 | if (tc->packet_header_fc) { |
8eee8ea2 | 603 | bt_field_class *ir_fc = scope_ctf_field_class_to_ir( |
939190b3 | 604 | tc->packet_header_fc, tc, NULL, NULL); |
7b33a0e0 | 605 | |
939190b3 | 606 | if (ir_fc) { |
10b7a2e4 PP |
607 | ret = bt_trace_class_set_packet_header_field_class( |
608 | ir_tc, ir_fc); | |
7b33a0e0 | 609 | BT_ASSERT(ret == 0); |
8c6884d9 | 610 | bt_field_class_put_ref(ir_fc); |
7b33a0e0 PP |
611 | } |
612 | } | |
613 | ||
7b33a0e0 | 614 | if (tc->is_uuid_set) { |
10b7a2e4 | 615 | bt_trace_class_set_uuid(ir_tc, tc->uuid); |
7b33a0e0 PP |
616 | } |
617 | ||
618 | for (i = 0; i < tc->env_entries->len; i++) { | |
619 | struct ctf_trace_class_env_entry *env_entry = | |
620 | ctf_trace_class_borrow_env_entry_by_index(tc, i); | |
621 | ||
622 | switch (env_entry->type) { | |
623 | case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT: | |
10b7a2e4 PP |
624 | ret = bt_trace_class_set_environment_entry_integer( |
625 | ir_tc, env_entry->name->str, | |
7b33a0e0 PP |
626 | env_entry->value.i); |
627 | break; | |
628 | case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR: | |
10b7a2e4 PP |
629 | ret = bt_trace_class_set_environment_entry_string( |
630 | ir_tc, env_entry->name->str, | |
7b33a0e0 PP |
631 | env_entry->value.str->str); |
632 | break; | |
633 | default: | |
634 | abort(); | |
635 | } | |
636 | ||
637 | if (ret) { | |
638 | goto end; | |
639 | } | |
640 | } | |
641 | ||
35fa110e PP |
642 | for (i = 0; i < tc->clock_classes->len; i++) { |
643 | struct ctf_clock_class *cc = tc->clock_classes->pdata[i]; | |
644 | ||
645 | cc->ir_cc = bt_clock_class_create(ir_tc); | |
646 | ctf_clock_class_to_ir(cc->ir_cc, cc); | |
647 | } | |
648 | ||
10b7a2e4 | 649 | bt_trace_class_set_assigns_automatic_stream_class_id(ir_tc, |
7b33a0e0 | 650 | BT_FALSE); |
7b33a0e0 | 651 | tc->is_translated = true; |
10b7a2e4 | 652 | tc->ir_tc = ir_tc; |
7b33a0e0 PP |
653 | |
654 | end: | |
655 | return ret; | |
656 | } | |
657 | ||
658 | BT_HIDDEN | |
8eee8ea2 | 659 | int ctf_trace_class_translate(bt_trace_class *ir_tc, |
7b33a0e0 PP |
660 | struct ctf_trace_class *tc) |
661 | { | |
662 | int ret = 0; | |
663 | uint64_t i; | |
664 | ||
10b7a2e4 | 665 | ret = ctf_trace_class_to_ir(ir_tc, tc); |
7b33a0e0 PP |
666 | if (ret) { |
667 | goto end; | |
668 | } | |
669 | ||
670 | for (i = 0; i < tc->stream_classes->len; i++) { | |
671 | uint64_t j; | |
672 | struct ctf_stream_class *sc = tc->stream_classes->pdata[i]; | |
8eee8ea2 | 673 | bt_stream_class *ir_sc; |
7b33a0e0 | 674 | |
10b7a2e4 | 675 | ir_sc = ctf_stream_class_to_ir(sc, ir_tc, tc); |
7b33a0e0 PP |
676 | if (!ir_sc) { |
677 | ret = -1; | |
678 | goto end; | |
679 | } | |
680 | ||
681 | for (j = 0; j < sc->event_classes->len; j++) { | |
682 | struct ctf_event_class *ec = sc->event_classes->pdata[j]; | |
8eee8ea2 | 683 | bt_event_class *ir_ec; |
7b33a0e0 PP |
684 | |
685 | ir_ec = ctf_event_class_to_ir(ec, ir_sc, tc, sc); | |
686 | if (!ir_ec) { | |
687 | ret = -1; | |
688 | goto end; | |
689 | } | |
690 | } | |
691 | } | |
692 | ||
693 | end: | |
694 | return ret; | |
695 | } |