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