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