Trace IR and notification APIs: split into private and public APIs
[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
e5be10ef 29struct bt_private_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 35void ctf_field_class_int_set_props(struct ctf_field_class_int *fc,
e5be10ef 36 struct bt_private_field_class *ir_fc)
44c440bc
PP
37{
38 int ret;
39
e5be10ef
PP
40 ret = bt_private_field_class_integer_set_field_value_range(ir_fc,
41 fc->base.size);
44c440bc 42 BT_ASSERT(ret == 0);
e5be10ef 43 ret = bt_private_field_class_integer_set_preferred_display_base(ir_fc,
5cd6d0e5 44 fc->disp_base);
44c440bc
PP
45 BT_ASSERT(ret == 0);
46}
47
48static inline
e5be10ef
PP
49struct bt_private_field_class *ctf_field_class_int_to_ir(
50 struct ctf_field_class_int *fc)
44c440bc 51{
e5be10ef 52 struct bt_private_field_class *ir_fc;
44c440bc 53
5cd6d0e5 54 if (fc->is_signed) {
e5be10ef 55 ir_fc = bt_private_field_class_signed_integer_create();
44c440bc 56 } else {
e5be10ef 57 ir_fc = bt_private_field_class_unsigned_integer_create();
44c440bc
PP
58 }
59
5cd6d0e5
PP
60 BT_ASSERT(ir_fc);
61 ctf_field_class_int_set_props(fc, ir_fc);
62 return ir_fc;
44c440bc
PP
63}
64
65static inline
e5be10ef
PP
66struct bt_private_field_class *ctf_field_class_enum_to_ir(
67 struct ctf_field_class_enum *fc)
44c440bc
PP
68{
69 int ret;
e5be10ef 70 struct bt_private_field_class *ir_fc;
44c440bc
PP
71 uint64_t i;
72
5cd6d0e5 73 if (fc->base.is_signed) {
e5be10ef 74 ir_fc = bt_private_field_class_signed_enumeration_create();
44c440bc 75 } else {
e5be10ef 76 ir_fc = bt_private_field_class_unsigned_enumeration_create();
44c440bc
PP
77 }
78
5cd6d0e5
PP
79 BT_ASSERT(ir_fc);
80 ctf_field_class_int_set_props((void *) fc, ir_fc);
44c440bc 81
5cd6d0e5
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);
44c440bc 85
5cd6d0e5 86 if (fc->base.is_signed) {
e5be10ef 87 ret = bt_private_field_class_signed_enumeration_map_range(
5cd6d0e5 88 ir_fc, mapping->label->str,
44c440bc
PP
89 mapping->range.lower.i, mapping->range.upper.i);
90 } else {
e5be10ef 91 ret = bt_private_field_class_unsigned_enumeration_map_range(
5cd6d0e5 92 ir_fc, mapping->label->str,
44c440bc
PP
93 mapping->range.lower.u, mapping->range.upper.u);
94 }
95
96 BT_ASSERT(ret == 0);
97 }
98
5cd6d0e5 99 return ir_fc;
44c440bc
PP
100}
101
102static inline
e5be10ef 103struct bt_private_field_class *ctf_field_class_float_to_ir(
5cd6d0e5 104 struct ctf_field_class_float *fc)
44c440bc 105{
e5be10ef 106 struct bt_private_field_class *ir_fc;
44c440bc
PP
107 int ret;
108
e5be10ef 109 ir_fc = bt_private_field_class_real_create();
5cd6d0e5 110 BT_ASSERT(ir_fc);
44c440bc 111
5cd6d0e5 112 if (fc->base.size == 32) {
e5be10ef 113 ret = bt_private_field_class_real_set_is_single_precision(ir_fc,
44c440bc
PP
114 BT_TRUE);
115 BT_ASSERT(ret == 0);
116 }
117
5cd6d0e5 118 return ir_fc;
44c440bc
PP
119}
120
121static inline
e5be10ef 122struct bt_private_field_class *ctf_field_class_string_to_ir(
5cd6d0e5 123 struct ctf_field_class_string *fc)
44c440bc 124{
e5be10ef
PP
125 struct bt_private_field_class *ir_fc =
126 bt_private_field_class_string_create();
44c440bc 127
5cd6d0e5
PP
128 BT_ASSERT(ir_fc);
129 return ir_fc;
44c440bc
PP
130}
131
132static inline
e5be10ef 133struct bt_private_field_class *ctf_field_class_struct_to_ir(
5cd6d0e5 134 struct ctf_field_class_struct *fc,
44c440bc
PP
135 struct ctf_trace_class *tc,
136 struct ctf_stream_class *sc,
137 struct ctf_event_class *ec)
138{
139 int ret;
e5be10ef
PP
140 struct bt_private_field_class *ir_fc =
141 bt_private_field_class_structure_create();
44c440bc
PP
142 uint64_t i;
143
5cd6d0e5 144 BT_ASSERT(ir_fc);
44c440bc 145
5cd6d0e5
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);
e5be10ef 149 struct bt_private_field_class *member_ir_fc;
44c440bc 150
5cd6d0e5 151 if (!named_fc->fc->in_ir) {
44c440bc
PP
152 continue;
153 }
154
5cd6d0e5
PP
155 member_ir_fc = ctf_field_class_to_ir(named_fc->fc, tc, sc, ec);
156 BT_ASSERT(member_ir_fc);
e5be10ef
PP
157 ret = bt_private_field_class_structure_append_private_member(
158 ir_fc, named_fc->name->str, member_ir_fc);
44c440bc 159 BT_ASSERT(ret == 0);
65300d60 160 bt_object_put_ref(member_ir_fc);
44c440bc
PP
161 }
162
5cd6d0e5 163 return ir_fc;
44c440bc
PP
164}
165
166static inline
e5be10ef 167struct bt_private_field_class *borrow_ir_ft_from_field_path(
44c440bc
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{
e5be10ef 173 struct bt_private_field_class *ir_fc = NULL;
5cd6d0e5 174 struct ctf_field_class *fc = ctf_field_path_borrow_field_class(
44c440bc
PP
175 field_path, tc, sc, ec);
176
5cd6d0e5 177 BT_ASSERT(fc);
44c440bc 178
5cd6d0e5
PP
179 if (fc->in_ir) {
180 ir_fc = fc->ir_fc;
44c440bc
PP
181 }
182
5cd6d0e5 183 return ir_fc;
44c440bc
PP
184}
185
186static inline
e5be10ef 187struct bt_private_field_class *ctf_field_class_variant_to_ir(
5cd6d0e5 188 struct ctf_field_class_variant *fc,
44c440bc
PP
189 struct ctf_trace_class *tc,
190 struct ctf_stream_class *sc,
191 struct ctf_event_class *ec)
192{
193 int ret;
e5be10ef
PP
194 struct bt_private_field_class *ir_fc =
195 bt_private_field_class_variant_create();
44c440bc
PP
196 uint64_t i;
197
5cd6d0e5 198 BT_ASSERT(ir_fc);
e5be10ef
PP
199 ret = bt_private_field_class_variant_set_selector_private_field_class(
200 ir_fc, borrow_ir_ft_from_field_path(&fc->tag_path, tc, sc, ec));
44c440bc
PP
201 BT_ASSERT(ret == 0);
202
5cd6d0e5
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);
e5be10ef 206 struct bt_private_field_class *option_ir_fc;
44c440bc 207
5cd6d0e5
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);
e5be10ef
PP
211 ret = bt_private_field_class_variant_append_private_option(
212 ir_fc, named_fc->name->str, option_ir_fc);
44c440bc 213 BT_ASSERT(ret == 0);
65300d60 214 bt_object_put_ref(option_ir_fc);
44c440bc
PP
215 }
216
5cd6d0e5 217 return ir_fc;
44c440bc
PP
218}
219
220static inline
e5be10ef 221struct bt_private_field_class *ctf_field_class_array_to_ir(
5cd6d0e5 222 struct ctf_field_class_array *fc,
44c440bc
PP
223 struct ctf_trace_class *tc,
224 struct ctf_stream_class *sc,
225 struct ctf_event_class *ec)
226{
e5be10ef
PP
227 struct bt_private_field_class *ir_fc;
228 struct bt_private_field_class *elem_ir_fc;
44c440bc 229
5cd6d0e5 230 if (fc->base.is_text) {
e5be10ef 231 ir_fc = bt_private_field_class_string_create();
5cd6d0e5 232 BT_ASSERT(ir_fc);
44c440bc
PP
233 goto end;
234 }
235
5cd6d0e5
PP
236 elem_ir_fc = ctf_field_class_to_ir(fc->base.elem_fc, tc, sc, ec);
237 BT_ASSERT(elem_ir_fc);
e5be10ef
PP
238 ir_fc = bt_private_field_class_static_array_create(elem_ir_fc,
239 fc->length);
5cd6d0e5 240 BT_ASSERT(ir_fc);
65300d60 241 bt_object_put_ref(elem_ir_fc);
44c440bc
PP
242
243end:
5cd6d0e5 244 return ir_fc;
44c440bc
PP
245}
246
247static inline
e5be10ef 248struct bt_private_field_class *ctf_field_class_sequence_to_ir(
5cd6d0e5 249 struct ctf_field_class_sequence *fc,
44c440bc
PP
250 struct ctf_trace_class *tc,
251 struct ctf_stream_class *sc,
252 struct ctf_event_class *ec)
253{
254 int ret;
e5be10ef
PP
255 struct bt_private_field_class *ir_fc;
256 struct bt_private_field_class *elem_ir_fc;
44c440bc 257
5cd6d0e5 258 if (fc->base.is_text) {
e5be10ef 259 ir_fc = bt_private_field_class_string_create();
5cd6d0e5 260 BT_ASSERT(ir_fc);
44c440bc
PP
261 goto end;
262 }
263
5cd6d0e5
PP
264 elem_ir_fc = ctf_field_class_to_ir(fc->base.elem_fc, tc, sc, ec);
265 BT_ASSERT(elem_ir_fc);
e5be10ef 266 ir_fc = bt_private_field_class_dynamic_array_create(elem_ir_fc);
5cd6d0e5 267 BT_ASSERT(ir_fc);
65300d60 268 bt_object_put_ref(elem_ir_fc);
5cd6d0e5 269 BT_ASSERT(ir_fc);
e5be10ef
PP
270 ret = bt_private_field_class_dynamic_array_set_length_private_field_class(
271 ir_fc,
5cd6d0e5 272 borrow_ir_ft_from_field_path(&fc->length_path, tc, sc, ec));
44c440bc
PP
273 BT_ASSERT(ret == 0);
274
275end:
5cd6d0e5 276 return ir_fc;
44c440bc
PP
277}
278
279static inline
e5be10ef 280struct bt_private_field_class *ctf_field_class_to_ir(struct ctf_field_class *fc,
44c440bc
PP
281 struct ctf_trace_class *tc,
282 struct ctf_stream_class *sc,
283 struct ctf_event_class *ec)
284{
e5be10ef 285 struct bt_private_field_class *ir_fc = NULL;
44c440bc 286
5cd6d0e5
PP
287 BT_ASSERT(fc);
288 BT_ASSERT(fc->in_ir);
44c440bc 289
864cad70
PP
290 switch (fc->type) {
291 case CTF_FIELD_CLASS_TYPE_INT:
5cd6d0e5 292 ir_fc = ctf_field_class_int_to_ir((void *) fc);
44c440bc 293 break;
864cad70 294 case CTF_FIELD_CLASS_TYPE_ENUM:
5cd6d0e5 295 ir_fc = ctf_field_class_enum_to_ir((void *) fc);
44c440bc 296 break;
864cad70 297 case CTF_FIELD_CLASS_TYPE_FLOAT:
5cd6d0e5 298 ir_fc = ctf_field_class_float_to_ir((void *) fc);
44c440bc 299 break;
864cad70 300 case CTF_FIELD_CLASS_TYPE_STRING:
5cd6d0e5 301 ir_fc = ctf_field_class_string_to_ir((void *) fc);
44c440bc 302 break;
864cad70 303 case CTF_FIELD_CLASS_TYPE_STRUCT:
5cd6d0e5 304 ir_fc = ctf_field_class_struct_to_ir((void *) fc, tc, sc, ec);
44c440bc 305 break;
864cad70 306 case CTF_FIELD_CLASS_TYPE_ARRAY:
5cd6d0e5 307 ir_fc = ctf_field_class_array_to_ir((void *) fc, tc, sc, ec);
44c440bc 308 break;
864cad70 309 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
5cd6d0e5 310 ir_fc = ctf_field_class_sequence_to_ir((void *) fc, tc, sc, ec);
44c440bc 311 break;
864cad70 312 case CTF_FIELD_CLASS_TYPE_VARIANT:
5cd6d0e5 313 ir_fc = ctf_field_class_variant_to_ir((void *) fc, tc, sc, ec);
44c440bc
PP
314 break;
315 default:
316 abort();
317 }
318
5cd6d0e5
PP
319 fc->ir_fc = ir_fc;
320 return ir_fc;
44c440bc
PP
321}
322
323static inline
5cd6d0e5
PP
324bool ctf_field_class_struct_has_immediate_member_in_ir(
325 struct ctf_field_class_struct *fc)
44c440bc
PP
326{
327 uint64_t i;
328 bool has_immediate_member_in_ir = false;
329
5cd6d0e5
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);
44c440bc 333
5cd6d0e5 334 if (named_fc->fc->in_ir) {
44c440bc
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
e5be10ef 345struct bt_private_field_class *scope_ctf_field_class_to_ir(struct ctf_field_class *fc,
44c440bc
PP
346 struct ctf_trace_class *tc,
347 struct ctf_stream_class *sc,
348 struct ctf_event_class *ec)
349{
e5be10ef 350 struct bt_private_field_class *ir_fc = NULL;
44c440bc 351
5cd6d0e5 352 if (!fc) {
44c440bc
PP
353 goto end;
354 }
355
864cad70 356 BT_ASSERT(fc->type == CTF_FIELD_CLASS_TYPE_STRUCT);
44c440bc 357
5cd6d0e5 358 if (!ctf_field_class_struct_has_immediate_member_in_ir((void *) fc)) {
44c440bc
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
5cd6d0e5 366 ir_fc = ctf_field_class_to_ir(fc, tc, sc, ec);
44c440bc
PP
367
368end:
5cd6d0e5 369 return ir_fc;
44c440bc
PP
370}
371
372static inline
5cd6d0e5
PP
373struct ctf_field_class_int *borrow_named_int_field_class(
374 struct ctf_field_class_struct *struct_fc, const char *name)
44c440bc 375{
5cd6d0e5
PP
376 struct ctf_named_field_class *named_fc = NULL;
377 struct ctf_field_class_int *int_fc = NULL;
44c440bc 378
5cd6d0e5 379 if (!struct_fc) {
44c440bc
PP
380 goto end;
381 }
382
5cd6d0e5
PP
383 named_fc = ctf_field_class_struct_borrow_member_by_name(struct_fc, name);
384 if (!named_fc) {
44c440bc
PP
385 goto end;
386 }
387
864cad70
PP
388 if (named_fc->fc->type != CTF_FIELD_CLASS_TYPE_INT &&
389 named_fc->fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
44c440bc
PP
390 goto end;
391 }
392
5cd6d0e5 393 int_fc = (void *) named_fc->fc;
44c440bc
PP
394
395end:
5cd6d0e5 396 return int_fc;
44c440bc
PP
397}
398
399static inline
e5be10ef
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,
44c440bc
PP
402 struct ctf_stream_class *sc)
403{
404 int ret;
e5be10ef 405 struct bt_private_event_class *ir_ec = NULL;
44c440bc
PP
406
407 if (ec->is_translated) {
e5be10ef 408 ir_ec = bt_private_stream_class_borrow_private_event_class_by_id(
44c440bc
PP
409 ir_sc, ec->id);
410 BT_ASSERT(ir_ec);
411 goto end;
412 }
413
e5be10ef 414 ir_ec = bt_private_event_class_create_with_id(ir_sc, ec->id);
44c440bc 415 BT_ASSERT(ir_ec);
65300d60 416 bt_object_put_ref(ir_ec);
44c440bc 417
5cd6d0e5 418 if (ec->spec_context_fc) {
e5be10ef 419 struct bt_private_field_class *ir_fc = scope_ctf_field_class_to_ir(
5cd6d0e5 420 ec->spec_context_fc, tc, sc, ec);
44c440bc 421
5cd6d0e5 422 if (ir_fc) {
e5be10ef 423 ret = bt_private_event_class_set_specific_context_private_field_class(
5cd6d0e5 424 ir_ec, ir_fc);
44c440bc 425 BT_ASSERT(ret == 0);
65300d60 426 bt_object_put_ref(ir_fc);
44c440bc
PP
427 }
428 }
429
5cd6d0e5 430 if (ec->payload_fc) {
e5be10ef 431 struct bt_private_field_class *ir_fc = scope_ctf_field_class_to_ir(
5cd6d0e5 432 ec->payload_fc, tc, sc, ec);
44c440bc 433
5cd6d0e5 434 if (ir_fc) {
e5be10ef 435 ret = bt_private_event_class_set_payload_private_field_class(ir_ec,
5cd6d0e5 436 ir_fc);
44c440bc 437 BT_ASSERT(ret == 0);
65300d60 438 bt_object_put_ref(ir_fc);
44c440bc
PP
439 }
440 }
441
442 if (ec->name->len > 0) {
e5be10ef 443 ret = bt_private_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) {
e5be10ef 448 ret = bt_private_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) {
e5be10ef 453 ret = bt_private_event_class_set_log_level(ir_ec, ec->log_level);
44c440bc
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
e5be10ef
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)
44c440bc
PP
468{
469 int ret;
e5be10ef 470 struct bt_private_stream_class *ir_sc = NULL;
5cd6d0e5 471 struct ctf_field_class_int *int_fc;
44c440bc
PP
472
473 if (sc->is_translated) {
e5be10ef
PP
474 ir_sc = bt_private_trace_borrow_private_stream_class_by_id(
475 ir_trace, sc->id);
44c440bc
PP
476 BT_ASSERT(ir_sc);
477 goto end;
478 }
479
e5be10ef 480 ir_sc = bt_private_stream_class_create_with_id(ir_trace, sc->id);
44c440bc 481 BT_ASSERT(ir_sc);
65300d60 482 bt_object_put_ref(ir_sc);
44c440bc 483
5cd6d0e5 484 if (sc->packet_context_fc) {
e5be10ef 485 struct bt_private_field_class *ir_fc = scope_ctf_field_class_to_ir(
5cd6d0e5 486 sc->packet_context_fc, tc, sc, NULL);
44c440bc 487
5cd6d0e5 488 if (ir_fc) {
e5be10ef 489 ret = bt_private_stream_class_set_packet_context_private_field_class(
5cd6d0e5 490 ir_sc, ir_fc);
44c440bc 491 BT_ASSERT(ret == 0);
65300d60 492 bt_object_put_ref(ir_fc);
44c440bc
PP
493 }
494 }
495
5cd6d0e5 496 if (sc->event_header_fc) {
e5be10ef 497 struct bt_private_field_class *ir_fc = scope_ctf_field_class_to_ir(
5cd6d0e5 498 sc->event_header_fc, tc, sc, NULL);
44c440bc 499
5cd6d0e5 500 if (ir_fc) {
e5be10ef
PP
501 ret = bt_private_stream_class_set_event_header_private_field_class(
502 ir_sc, ir_fc);
44c440bc 503 BT_ASSERT(ret == 0);
65300d60 504 bt_object_put_ref(ir_fc);
44c440bc
PP
505 }
506 }
507
5cd6d0e5 508 if (sc->event_common_context_fc) {
e5be10ef 509 struct bt_private_field_class *ir_fc = scope_ctf_field_class_to_ir(
5cd6d0e5 510 sc->event_common_context_fc, tc, sc, NULL);
44c440bc 511
5cd6d0e5 512 if (ir_fc) {
e5be10ef 513 ret = bt_private_stream_class_set_event_common_context_private_field_class(
5cd6d0e5 514 ir_sc, ir_fc);
44c440bc 515 BT_ASSERT(ret == 0);
65300d60 516 bt_object_put_ref(ir_fc);
44c440bc
PP
517 }
518 }
519
e5be10ef 520 ret = bt_private_stream_class_set_assigns_automatic_event_class_id(ir_sc,
44c440bc
PP
521 BT_FALSE);
522 BT_ASSERT(ret == 0);
e5be10ef 523 ret = bt_private_stream_class_set_assigns_automatic_stream_id(ir_sc, BT_FALSE);
44c440bc
PP
524 BT_ASSERT(ret == 0);
525
526 if (sc->default_clock_class) {
e5be10ef
PP
527 ret = bt_private_stream_class_set_default_clock_class(ir_sc,
528 bt_clock_class_borrow_from_private(sc->default_clock_class));
44c440bc
PP
529 BT_ASSERT(ret == 0);
530 }
531
5cd6d0e5 532 int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
44c440bc 533 "events_discarded");
5cd6d0e5
PP
534 if (int_fc) {
535 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT) {
e5be10ef 536 ret = bt_private_stream_class_set_packets_have_discarded_event_counter_snapshot(
44c440bc
PP
537 ir_sc, BT_TRUE);
538 BT_ASSERT(ret == 0);
539 }
540 }
541
5cd6d0e5 542 int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
44c440bc 543 "packet_seq_num");
5cd6d0e5
PP
544 if (int_fc) {
545 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT) {
e5be10ef 546 ret = bt_private_stream_class_set_packets_have_packet_counter_snapshot(
44c440bc
PP
547 ir_sc, BT_TRUE);
548 BT_ASSERT(ret == 0);
549 }
550 }
551
5cd6d0e5 552 int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
44c440bc 553 "timestamp_begin");
5cd6d0e5
PP
554 if (int_fc) {
555 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME) {
e5be10ef 556 ret = bt_private_stream_class_set_packets_have_default_beginning_clock_value(
44c440bc
PP
557 ir_sc, BT_TRUE);
558 BT_ASSERT(ret == 0);
559 }
560 }
561
5cd6d0e5 562 int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
44c440bc 563 "timestamp_end");
5cd6d0e5
PP
564 if (int_fc) {
565 if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_END_TIME) {
e5be10ef 566 ret = bt_private_stream_class_set_packets_have_default_end_clock_value(
44c440bc
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
e5be10ef 580int ctf_trace_class_to_ir(struct bt_private_trace *ir_trace,
44c440bc
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
5cd6d0e5 590 if (tc->packet_header_fc) {
e5be10ef 591 struct bt_private_field_class *ir_fc = scope_ctf_field_class_to_ir(
5cd6d0e5 592 tc->packet_header_fc, tc, NULL, NULL);
44c440bc 593
5cd6d0e5 594 if (ir_fc) {
e5be10ef
PP
595 ret = bt_private_trace_set_packet_header_private_field_class(
596 ir_trace, ir_fc);
44c440bc 597 BT_ASSERT(ret == 0);
65300d60 598 bt_object_put_ref(ir_fc);
44c440bc
PP
599 }
600 }
601
602 if (tc->name->len > 0) {
e5be10ef 603 ret = bt_private_trace_set_name(ir_trace, tc->name->str);
44c440bc
PP
604 if (ret) {
605 goto end;
606 }
607 }
608
609 if (tc->is_uuid_set) {
e5be10ef 610 ret = bt_private_trace_set_uuid(ir_trace, tc->uuid);
44c440bc
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:
e5be10ef 622 ret = bt_private_trace_set_private_environment_entry_integer(
44c440bc
PP
623 ir_trace, env_entry->name->str,
624 env_entry->value.i);
625 break;
626 case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR:
e5be10ef 627 ret = bt_private_trace_set_private_environment_entry_string(
44c440bc
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
e5be10ef 640 ret = bt_private_trace_set_assigns_automatic_stream_class_id(ir_trace,
44c440bc
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
e5be10ef 654int ctf_trace_class_translate(struct bt_private_trace *ir_trace,
44c440bc
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];
e5be10ef 668 struct bt_private_stream_class *ir_sc;
44c440bc
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];
e5be10ef 678 struct bt_private_event_class *ir_ec;
44c440bc
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.058393 seconds and 4 git commands to generate.