Re-format new C++ files
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-translate.cpp
CommitLineData
44c440bc 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
44c440bc 3 *
0235b0db 4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
44c440bc
PP
5 */
6
3fadfbc0 7#include <babeltrace2/babeltrace.h>
91d81473 8#include "common/macros.h"
578e048b 9#include "common/assert.h"
44c440bc 10#include <glib.h>
c4f23e30 11#include <stdbool.h>
44c440bc
PP
12#include <stdint.h>
13#include <string.h>
14#include <inttypes.h>
15
087cd0f5 16#include "ctf-meta-visitors.hpp"
44c440bc 17
4164020e
SM
18struct ctx
19{
20 bt_self_component *self_comp;
21 bt_trace_class *ir_tc;
22 bt_stream_class *ir_sc;
23 struct ctf_trace_class *tc;
24 struct ctf_stream_class *sc;
25 struct ctf_event_class *ec;
26 enum ctf_scope scope;
83ebb7f1
PP
27};
28
4164020e 29static inline bt_field_class *ctf_field_class_to_ir(struct ctx *ctx, struct ctf_field_class *fc);
44c440bc 30
4164020e
SM
31static inline void ctf_field_class_int_set_props(struct ctf_field_class_int *fc,
32 bt_field_class *ir_fc)
44c440bc 33{
4164020e
SM
34 bt_field_class_integer_set_field_value_range(ir_fc, fc->base.size);
35 bt_field_class_integer_set_preferred_display_base(ir_fc, fc->disp_base);
44c440bc
PP
36}
37
4164020e
SM
38static inline bt_field_class *ctf_field_class_int_to_ir(struct ctx *ctx,
39 struct ctf_field_class_int *fc)
44c440bc 40{
4164020e 41 bt_field_class *ir_fc;
44c440bc 42
4164020e
SM
43 if (fc->is_signed) {
44 ir_fc = bt_field_class_integer_signed_create(ctx->ir_tc);
45 } else {
46 ir_fc = bt_field_class_integer_unsigned_create(ctx->ir_tc);
47 }
44c440bc 48
4164020e
SM
49 BT_ASSERT(ir_fc);
50 ctf_field_class_int_set_props(fc, ir_fc);
51 return ir_fc;
44c440bc
PP
52}
53
4164020e
SM
54static inline bt_field_class *ctf_field_class_enum_to_ir(struct ctx *ctx,
55 struct ctf_field_class_enum *fc)
44c440bc 56{
4164020e
SM
57 int ret;
58 bt_field_class *ir_fc;
59 uint64_t i;
60
61 if (fc->base.is_signed) {
62 ir_fc = bt_field_class_enumeration_signed_create(ctx->ir_tc);
63 } else {
64 ir_fc = bt_field_class_enumeration_unsigned_create(ctx->ir_tc);
65 }
66
67 BT_ASSERT(ir_fc);
68 ctf_field_class_int_set_props(&fc->base, ir_fc);
69
70 for (i = 0; i < fc->mappings->len; i++) {
71 struct ctf_field_class_enum_mapping *mapping =
72 ctf_field_class_enum_borrow_mapping_by_index(fc, i);
73 bt_integer_range_set_signed *range_set_signed = NULL;
74 bt_integer_range_set_unsigned *range_set_unsigned = NULL;
75 uint64_t range_i;
76
77 if (fc->base.is_signed) {
78 range_set_signed = bt_integer_range_set_signed_create();
79 BT_ASSERT(range_set_signed);
80 } else {
81 range_set_unsigned = bt_integer_range_set_unsigned_create();
82 BT_ASSERT(range_set_unsigned);
83 }
84
85 for (range_i = 0; range_i < mapping->ranges->len; range_i++) {
86 struct ctf_range *range =
87 ctf_field_class_enum_mapping_borrow_range_by_index(mapping, range_i);
88
89 if (fc->base.is_signed) {
90 ret = bt_integer_range_set_signed_add_range(range_set_signed, range->lower.i,
91 range->upper.i);
92 } else {
93 ret = bt_integer_range_set_unsigned_add_range(range_set_unsigned, range->lower.u,
94 range->upper.u);
95 }
96
97 BT_ASSERT(ret == 0);
98 }
99
100 if (fc->base.is_signed) {
101 ret = bt_field_class_enumeration_signed_add_mapping(ir_fc, mapping->label->str,
102 range_set_signed);
103 BT_INTEGER_RANGE_SET_SIGNED_PUT_REF_AND_RESET(range_set_signed);
104 } else {
105 ret = bt_field_class_enumeration_unsigned_add_mapping(ir_fc, mapping->label->str,
106 range_set_unsigned);
107 BT_INTEGER_RANGE_SET_UNSIGNED_PUT_REF_AND_RESET(range_set_unsigned);
108 }
109
110 BT_ASSERT(ret == 0);
111 }
112
113 return ir_fc;
44c440bc
PP
114}
115
4164020e
SM
116static inline bt_field_class *ctf_field_class_float_to_ir(struct ctx *ctx,
117 struct ctf_field_class_float *fc)
44c440bc 118{
4164020e 119 bt_field_class *ir_fc;
44c440bc 120
4164020e
SM
121 if (fc->base.size == 32) {
122 ir_fc = bt_field_class_real_single_precision_create(ctx->ir_tc);
123 } else {
124 ir_fc = bt_field_class_real_double_precision_create(ctx->ir_tc);
125 }
126 BT_ASSERT(ir_fc);
44c440bc 127
4164020e 128 return ir_fc;
44c440bc
PP
129}
130
4164020e
SM
131static inline bt_field_class *ctf_field_class_string_to_ir(struct ctx *ctx,
132 struct ctf_field_class_string *fc)
44c440bc 133{
4164020e 134 bt_field_class *ir_fc = bt_field_class_string_create(ctx->ir_tc);
44c440bc 135
4164020e
SM
136 BT_ASSERT(ir_fc);
137 return ir_fc;
44c440bc
PP
138}
139
4164020e
SM
140static inline void translate_struct_field_class_members(struct ctx *ctx,
141 struct ctf_field_class_struct *fc,
142 bt_field_class *ir_fc,
143 bool with_header_prefix,
144 struct ctf_field_class_struct *context_fc)
44c440bc 145{
4164020e
SM
146 uint64_t i;
147 int ret;
148
149 for (i = 0; i < fc->members->len; i++) {
150 struct ctf_named_field_class *named_fc =
151 ctf_field_class_struct_borrow_member_by_index(fc, i);
152 bt_field_class *member_ir_fc;
153 const char *name = named_fc->name->str;
154
155 if (!named_fc->fc->in_ir) {
156 continue;
157 }
158
159 member_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc);
160 BT_ASSERT(member_ir_fc);
161 ret = bt_field_class_structure_append_member(ir_fc, name, member_ir_fc);
162 BT_ASSERT(ret == 0);
163 bt_field_class_put_ref(member_ir_fc);
164 }
83ebb7f1 165}
44c440bc 166
4164020e
SM
167static inline bt_field_class *ctf_field_class_struct_to_ir(struct ctx *ctx,
168 struct ctf_field_class_struct *fc)
83ebb7f1 169{
4164020e 170 bt_field_class *ir_fc = bt_field_class_structure_create(ctx->ir_tc);
83ebb7f1 171
4164020e
SM
172 BT_ASSERT(ir_fc);
173 translate_struct_field_class_members(ctx, fc, ir_fc, false, NULL);
174 return ir_fc;
44c440bc
PP
175}
176
4164020e
SM
177static inline bt_field_class *borrow_ir_fc_from_field_path(struct ctx *ctx,
178 struct ctf_field_path *field_path)
44c440bc 179{
4164020e
SM
180 bt_field_class *ir_fc = NULL;
181 struct ctf_field_class *fc =
182 ctf_field_path_borrow_field_class(field_path, ctx->tc, ctx->sc, ctx->ec);
44c440bc 183
4164020e 184 BT_ASSERT(fc);
44c440bc 185
4164020e
SM
186 if (fc->in_ir) {
187 ir_fc = fc->ir_fc;
188 }
44c440bc 189
4164020e 190 return ir_fc;
44c440bc
PP
191}
192
4164020e
SM
193static inline const bt_field_class_enumeration_mapping *
194find_ir_enum_field_class_mapping_by_label(const bt_field_class *fc, const char *label,
195 bool is_signed)
45c51519 196{
4164020e
SM
197 const bt_field_class_enumeration_mapping *mapping = NULL;
198 uint64_t i;
199
200 for (i = 0; i < bt_field_class_enumeration_get_mapping_count(fc); i++) {
201 const bt_field_class_enumeration_mapping *this_mapping;
202 const bt_field_class_enumeration_signed_mapping *signed_this_mapping = NULL;
203 const bt_field_class_enumeration_unsigned_mapping *unsigned_this_mapping = NULL;
204
205 if (is_signed) {
206 signed_this_mapping =
207 bt_field_class_enumeration_signed_borrow_mapping_by_index_const(fc, i);
208 BT_ASSERT(signed_this_mapping);
209 this_mapping =
210 bt_field_class_enumeration_signed_mapping_as_mapping_const(signed_this_mapping);
211 } else {
212 unsigned_this_mapping =
213 bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(fc, i);
214 BT_ASSERT(unsigned_this_mapping);
215 this_mapping =
216 bt_field_class_enumeration_unsigned_mapping_as_mapping_const(unsigned_this_mapping);
217 }
218
219 BT_ASSERT(this_mapping);
220
221 if (strcmp(bt_field_class_enumeration_mapping_get_label(this_mapping), label) == 0) {
222 mapping = this_mapping;
223 goto end;
224 }
225 }
45c51519
PP
226
227end:
4164020e 228 return mapping;
45c51519
PP
229}
230
4164020e
SM
231static inline bt_field_class *ctf_field_class_variant_to_ir(struct ctx *ctx,
232 struct ctf_field_class_variant *fc)
44c440bc 233{
4164020e
SM
234 int ret;
235 bt_field_class *ir_fc;
236 uint64_t i;
237 bt_field_class *ir_tag_fc = NULL;
238
239 if (fc->tag_path.root != CTF_SCOPE_PACKET_HEADER &&
240 fc->tag_path.root != CTF_SCOPE_EVENT_HEADER) {
241 ir_tag_fc = borrow_ir_fc_from_field_path(ctx, &fc->tag_path);
242 BT_ASSERT(ir_tag_fc);
243 }
244
245 ir_fc = bt_field_class_variant_create(ctx->ir_tc, ir_tag_fc);
246 BT_ASSERT(ir_fc);
247
248 for (i = 0; i < fc->options->len; i++) {
249 struct ctf_named_field_class *named_fc =
250 ctf_field_class_variant_borrow_option_by_index(fc, i);
251 bt_field_class *option_ir_fc;
252
253 BT_ASSERT(named_fc->fc->in_ir);
254 option_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc);
255 BT_ASSERT(option_ir_fc);
256
257 if (ir_tag_fc) {
258 /*
259 * At this point the trace IR selector
260 * (enumeration) field class already exists if
261 * the variant is tagged (`ir_tag_fc`). This one
262 * already contains range sets for its mappings,
263 * so we just reuse the same, finding them by
264 * matching a variant field class's option's
265 * _original_ name (with a leading underscore,
266 * possibly) with a selector field class's
267 * mapping name.
268 */
269 if (fc->tag_fc->base.is_signed) {
270 const bt_field_class_enumeration_signed_mapping *mapping =
271 (bt_field_class_enumeration_signed_mapping *)
272 find_ir_enum_field_class_mapping_by_label(ir_tag_fc,
273 named_fc->orig_name->str, true);
274 const bt_integer_range_set_signed *range_set;
275
276 BT_ASSERT(mapping);
277 range_set = bt_field_class_enumeration_signed_mapping_borrow_ranges_const(mapping);
278 BT_ASSERT(range_set);
279 ret = bt_field_class_variant_with_selector_field_integer_signed_append_option(
280 ir_fc, named_fc->name->str, option_ir_fc, range_set);
281 } else {
282 const bt_field_class_enumeration_unsigned_mapping *mapping =
283 (bt_field_class_enumeration_unsigned_mapping *)
284 find_ir_enum_field_class_mapping_by_label(ir_tag_fc,
285 named_fc->orig_name->str, false);
286 const bt_integer_range_set_unsigned *range_set;
287
288 BT_ASSERT(mapping);
289 range_set =
290 bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(mapping);
291 BT_ASSERT(range_set);
292 ret = bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
293 ir_fc, named_fc->name->str, option_ir_fc, range_set);
294 }
295 } else {
296 ret = bt_field_class_variant_without_selector_append_option(ir_fc, named_fc->name->str,
297 option_ir_fc);
298 }
299
300 BT_ASSERT(ret == 0);
301 bt_field_class_put_ref(option_ir_fc);
302 }
303
304 return ir_fc;
44c440bc
PP
305}
306
4164020e
SM
307static inline bt_field_class *ctf_field_class_array_to_ir(struct ctx *ctx,
308 struct ctf_field_class_array *fc)
44c440bc 309{
4164020e
SM
310 bt_field_class *ir_fc;
311 bt_field_class *elem_ir_fc;
312
313 if (fc->base.is_text) {
314 ir_fc = bt_field_class_string_create(ctx->ir_tc);
315 BT_ASSERT(ir_fc);
316 goto end;
317 }
318
319 elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc);
320 BT_ASSERT(elem_ir_fc);
321 ir_fc = bt_field_class_array_static_create(ctx->ir_tc, elem_ir_fc, fc->length);
322 BT_ASSERT(ir_fc);
323 bt_field_class_put_ref(elem_ir_fc);
44c440bc
PP
324
325end:
4164020e 326 return ir_fc;
44c440bc
PP
327}
328
4164020e
SM
329static inline bt_field_class *ctf_field_class_sequence_to_ir(struct ctx *ctx,
330 struct ctf_field_class_sequence *fc)
44c440bc 331{
4164020e
SM
332 bt_field_class *ir_fc;
333 bt_field_class *elem_ir_fc;
334 bt_field_class *length_fc = NULL;
335
336 if (fc->base.is_text) {
337 ir_fc = bt_field_class_string_create(ctx->ir_tc);
338 BT_ASSERT(ir_fc);
339 goto end;
340 }
341
342 elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc);
343 BT_ASSERT(elem_ir_fc);
344
345 if (fc->length_path.root != CTF_SCOPE_PACKET_HEADER &&
346 fc->length_path.root != CTF_SCOPE_EVENT_HEADER) {
347 length_fc = borrow_ir_fc_from_field_path(ctx, &fc->length_path);
348 BT_ASSERT(length_fc);
349 }
350
351 ir_fc = bt_field_class_array_dynamic_create(ctx->ir_tc, elem_ir_fc, length_fc);
352 BT_ASSERT(ir_fc);
353 bt_field_class_put_ref(elem_ir_fc);
354 BT_ASSERT(ir_fc);
1367bc7c 355
44c440bc 356end:
4164020e 357 return ir_fc;
44c440bc
PP
358}
359
4164020e 360static inline bt_field_class *ctf_field_class_to_ir(struct ctx *ctx, struct ctf_field_class *fc)
44c440bc 361{
4164020e
SM
362 bt_field_class *ir_fc = NULL;
363
364 BT_ASSERT(fc);
365 BT_ASSERT(fc->in_ir);
366
367 switch (fc->type) {
368 case CTF_FIELD_CLASS_TYPE_INT:
369 ir_fc = ctf_field_class_int_to_ir(ctx, ctf_field_class_as_int(fc));
370 break;
371 case CTF_FIELD_CLASS_TYPE_ENUM:
372 ir_fc = ctf_field_class_enum_to_ir(ctx, ctf_field_class_as_enum(fc));
373 break;
374 case CTF_FIELD_CLASS_TYPE_FLOAT:
375 ir_fc = ctf_field_class_float_to_ir(ctx, ctf_field_class_as_float(fc));
376 break;
377 case CTF_FIELD_CLASS_TYPE_STRING:
378 ir_fc = ctf_field_class_string_to_ir(ctx, ctf_field_class_as_string(fc));
379 break;
380 case CTF_FIELD_CLASS_TYPE_STRUCT:
381 ir_fc = ctf_field_class_struct_to_ir(ctx, ctf_field_class_as_struct(fc));
382 break;
383 case CTF_FIELD_CLASS_TYPE_ARRAY:
384 ir_fc = ctf_field_class_array_to_ir(ctx, ctf_field_class_as_array(fc));
385 break;
386 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
387 ir_fc = ctf_field_class_sequence_to_ir(ctx, ctf_field_class_as_sequence(fc));
388 break;
389 case CTF_FIELD_CLASS_TYPE_VARIANT:
390 ir_fc = ctf_field_class_variant_to_ir(ctx, ctf_field_class_as_variant(fc));
391 break;
392 default:
393 bt_common_abort();
394 }
395
396 fc->ir_fc = ir_fc;
397 return ir_fc;
44c440bc
PP
398}
399
4164020e
SM
400static inline bool
401ctf_field_class_struct_has_immediate_member_in_ir(struct ctf_field_class_struct *fc)
44c440bc 402{
4164020e
SM
403 uint64_t i;
404 bool has_immediate_member_in_ir = false;
405
406 /*
407 * If the structure field class has no members at all, then it
408 * was an empty structure in the beginning, so leave it existing
409 * and empty.
410 */
411 if (fc->members->len == 0) {
412 has_immediate_member_in_ir = true;
413 goto end;
414 }
415
416 for (i = 0; i < fc->members->len; i++) {
417 struct ctf_named_field_class *named_fc =
418 ctf_field_class_struct_borrow_member_by_index(fc, i);
419
420 if (named_fc->fc->in_ir) {
421 has_immediate_member_in_ir = true;
422 goto end;
423 }
424 }
44c440bc
PP
425
426end:
4164020e 427 return has_immediate_member_in_ir;
44c440bc
PP
428}
429
4164020e 430static inline bt_field_class *scope_ctf_field_class_to_ir(struct ctx *ctx)
44c440bc 431{
4164020e
SM
432 bt_field_class *ir_fc = NULL;
433 struct ctf_field_class *fc = NULL;
434
435 switch (ctx->scope) {
436 case CTF_SCOPE_PACKET_CONTEXT:
437 fc = ctx->sc->packet_context_fc;
438 break;
439 case CTF_SCOPE_EVENT_COMMON_CONTEXT:
440 fc = ctx->sc->event_common_context_fc;
441 break;
442 case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT:
443 fc = ctx->ec->spec_context_fc;
444 break;
445 case CTF_SCOPE_EVENT_PAYLOAD:
446 fc = ctx->ec->payload_fc;
447 break;
448 default:
449 bt_common_abort();
450 }
451
452 if (fc && ctf_field_class_struct_has_immediate_member_in_ir(ctf_field_class_as_struct(fc))) {
453 ir_fc = ctf_field_class_to_ir(ctx, fc);
454 }
455
456 return ir_fc;
44c440bc
PP
457}
458
4164020e 459static inline void ctf_event_class_to_ir(struct ctx *ctx)
44c440bc 460{
4164020e
SM
461 int ret;
462 bt_event_class *ir_ec = NULL;
463 bt_field_class *ir_fc;
464
465 BT_ASSERT(ctx->ec);
466
467 if (ctx->ec->is_translated) {
468 ir_ec = bt_stream_class_borrow_event_class_by_id(ctx->ir_sc, ctx->ec->id);
469 BT_ASSERT(ir_ec);
470 goto end;
471 }
472
473 ir_ec = bt_event_class_create_with_id(ctx->ir_sc, ctx->ec->id);
474 BT_ASSERT(ir_ec);
475 bt_event_class_put_ref(ir_ec);
476 ctx->scope = CTF_SCOPE_EVENT_SPECIFIC_CONTEXT;
477 ir_fc = scope_ctf_field_class_to_ir(ctx);
478 if (ir_fc) {
479 ret = bt_event_class_set_specific_context_field_class(ir_ec, ir_fc);
480 BT_ASSERT(ret == 0);
481 bt_field_class_put_ref(ir_fc);
482 }
483
484 ctx->scope = CTF_SCOPE_EVENT_PAYLOAD;
485 ir_fc = scope_ctf_field_class_to_ir(ctx);
486 if (ir_fc) {
487 ret = bt_event_class_set_payload_field_class(ir_ec, ir_fc);
488 BT_ASSERT(ret == 0);
489 bt_field_class_put_ref(ir_fc);
490 }
491
492 if (ctx->ec->name->len > 0) {
493 ret = bt_event_class_set_name(ir_ec, ctx->ec->name->str);
494 BT_ASSERT(ret == 0);
495 }
496
497 if (ctx->ec->emf_uri->len > 0) {
498 ret = bt_event_class_set_emf_uri(ir_ec, ctx->ec->emf_uri->str);
499 BT_ASSERT(ret == 0);
500 }
501
502 if (ctx->ec->is_log_level_set) {
503 bt_event_class_set_log_level(ir_ec, ctx->ec->log_level);
504 }
505
506 ctx->ec->is_translated = true;
507 ctx->ec->ir_ec = ir_ec;
44c440bc
PP
508
509end:
4164020e 510 return;
44c440bc
PP
511}
512
4164020e 513static inline void ctf_stream_class_to_ir(struct ctx *ctx)
44c440bc 514{
4164020e
SM
515 int ret;
516 bt_field_class *ir_fc;
517
518 BT_ASSERT(ctx->sc);
519
520 if (ctx->sc->is_translated) {
521 ctx->ir_sc = bt_trace_class_borrow_stream_class_by_id(ctx->ir_tc, ctx->sc->id);
522 BT_ASSERT(ctx->ir_sc);
523 goto end;
524 }
525
526 ctx->ir_sc = bt_stream_class_create_with_id(ctx->ir_tc, ctx->sc->id);
527 BT_ASSERT(ctx->ir_sc);
528 bt_stream_class_put_ref(ctx->ir_sc);
529
530 if (ctx->sc->default_clock_class) {
531 BT_ASSERT(ctx->sc->default_clock_class->ir_cc);
532 ret = bt_stream_class_set_default_clock_class(ctx->ir_sc,
533 ctx->sc->default_clock_class->ir_cc);
534 BT_ASSERT(ret == 0);
535 }
536
537 bt_stream_class_set_supports_packets(ctx->ir_sc, BT_TRUE, ctx->sc->packets_have_ts_begin,
538 ctx->sc->packets_have_ts_end);
539 bt_stream_class_set_supports_discarded_events(ctx->ir_sc, ctx->sc->has_discarded_events,
540 ctx->sc->discarded_events_have_default_cs);
541 bt_stream_class_set_supports_discarded_packets(ctx->ir_sc, ctx->sc->has_discarded_packets,
542 ctx->sc->discarded_packets_have_default_cs);
543 ctx->scope = CTF_SCOPE_PACKET_CONTEXT;
544 ir_fc = scope_ctf_field_class_to_ir(ctx);
545 if (ir_fc) {
546 ret = bt_stream_class_set_packet_context_field_class(ctx->ir_sc, ir_fc);
547 BT_ASSERT(ret == 0);
548 bt_field_class_put_ref(ir_fc);
549 }
550
551 ctx->scope = CTF_SCOPE_EVENT_COMMON_CONTEXT;
552 ir_fc = scope_ctf_field_class_to_ir(ctx);
553 if (ir_fc) {
554 ret = bt_stream_class_set_event_common_context_field_class(ctx->ir_sc, ir_fc);
555 BT_ASSERT(ret == 0);
556 bt_field_class_put_ref(ir_fc);
557 }
558
559 bt_stream_class_set_assigns_automatic_event_class_id(ctx->ir_sc, BT_FALSE);
560 bt_stream_class_set_assigns_automatic_stream_id(ctx->ir_sc, BT_FALSE);
561
562 ctx->sc->is_translated = true;
563 ctx->sc->ir_sc = ctx->ir_sc;
44c440bc
PP
564
565end:
4164020e 566 return;
44c440bc
PP
567}
568
4164020e 569static inline void ctf_clock_class_to_ir(bt_clock_class *ir_cc, struct ctf_clock_class *cc)
0f2d58c9 570{
4164020e 571 int ret;
0f2d58c9 572
4164020e
SM
573 if (strlen(cc->name->str) > 0) {
574 ret = bt_clock_class_set_name(ir_cc, cc->name->str);
575 BT_ASSERT(ret == 0);
576 }
0f2d58c9 577
4164020e
SM
578 if (strlen(cc->description->str) > 0) {
579 ret = bt_clock_class_set_description(ir_cc, cc->description->str);
580 BT_ASSERT(ret == 0);
581 }
0f2d58c9 582
4164020e
SM
583 bt_clock_class_set_frequency(ir_cc, cc->frequency);
584 bt_clock_class_set_precision(ir_cc, cc->precision);
585 bt_clock_class_set_offset(ir_cc, cc->offset_seconds, cc->offset_cycles);
0f2d58c9 586
4164020e
SM
587 if (cc->has_uuid) {
588 bt_clock_class_set_uuid(ir_cc, cc->uuid);
589 }
0f2d58c9 590
4164020e 591 bt_clock_class_set_origin_is_unix_epoch(ir_cc, cc->is_absolute);
0f2d58c9
PP
592}
593
4164020e 594static inline int ctf_trace_class_to_ir(struct ctx *ctx)
44c440bc 595{
4164020e
SM
596 int ret = 0;
597 uint64_t i;
44c440bc 598
4164020e
SM
599 BT_ASSERT(ctx->tc);
600 BT_ASSERT(ctx->ir_tc);
44c440bc 601
4164020e
SM
602 if (ctx->tc->is_translated) {
603 goto end;
604 }
44c440bc 605
4164020e
SM
606 for (i = 0; i < ctx->tc->clock_classes->len; i++) {
607 ctf_clock_class *cc = (ctf_clock_class *) ctx->tc->clock_classes->pdata[i];
0f2d58c9 608
4164020e
SM
609 cc->ir_cc = bt_clock_class_create(ctx->self_comp);
610 ctf_clock_class_to_ir(cc->ir_cc, cc);
611 }
0f2d58c9 612
4164020e
SM
613 bt_trace_class_set_assigns_automatic_stream_class_id(ctx->ir_tc, BT_FALSE);
614 ctx->tc->is_translated = true;
615 ctx->tc->ir_tc = ctx->ir_tc;
44c440bc
PP
616
617end:
4164020e 618 return ret;
44c440bc
PP
619}
620
621BT_HIDDEN
4164020e
SM
622int ctf_trace_class_translate(bt_self_component *self_comp, bt_trace_class *ir_tc,
623 struct ctf_trace_class *tc)
44c440bc 624{
4164020e
SM
625 int ret = 0;
626 uint64_t i;
627 struct ctx ctx = {0};
44c440bc 628
4164020e
SM
629 ctx.self_comp = self_comp;
630 ctx.tc = tc;
631 ctx.ir_tc = ir_tc;
632 ret = ctf_trace_class_to_ir(&ctx);
633 if (ret) {
634 goto end;
635 }
44c440bc 636
4164020e
SM
637 for (i = 0; i < tc->stream_classes->len; i++) {
638 uint64_t j;
639 ctx.sc = (ctf_stream_class *) tc->stream_classes->pdata[i];
44c440bc 640
4164020e 641 ctf_stream_class_to_ir(&ctx);
44c440bc 642
4164020e
SM
643 for (j = 0; j < ctx.sc->event_classes->len; j++) {
644 ctx.ec = (ctf_event_class *) ctx.sc->event_classes->pdata[j];
44c440bc 645
4164020e
SM
646 ctf_event_class_to_ir(&ctx);
647 ctx.ec = NULL;
648 }
83ebb7f1 649
4164020e
SM
650 ctx.sc = NULL;
651 }
44c440bc
PP
652
653end:
4164020e 654 return ret;
44c440bc 655}
This page took 0.094152 seconds and 4 git commands to generate.