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