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