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