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