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