Remove BT_CTF_FIELD_TYPE_UNTAGGED_VARIANT
[babeltrace.git] / plugins / libctfcopytrace / clock-fields.c
1 /*
2 * clock-fields.c
3 *
4 * Babeltrace - Update clock fields to write uint64 values
5 *
6 * Copyright 2017 Julien Desfossez <jdesfossez@efficios.com>
7 *
8 * Author: Julien Desfossez <jdesfossez@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29 #include <babeltrace/ctf-ir/event.h>
30 #include <babeltrace/ctf-ir/packet.h>
31 #include <babeltrace/ctf-ir/event-class.h>
32 #include <babeltrace/ctf-ir/stream.h>
33 #include <babeltrace/ctf-ir/stream-class.h>
34 #include <babeltrace/ctf-ir/clock-class.h>
35 #include <babeltrace/ctf-ir/fields.h>
36 #include <babeltrace/ctf-writer/stream.h>
37 #include <babeltrace/ctf-ir/field-types.h>
38 #include <assert.h>
39 #include <stdio.h>
40
41 #include "clock-fields.h"
42
43 static
44 int find_update_struct_clock_fields(FILE *err, struct bt_ctf_field_type *type,
45 struct bt_ctf_clock_class *writer_clock_class);
46 static
47 int find_update_array_clock_fields(FILE *err, struct bt_ctf_field_type *type,
48 struct bt_ctf_clock_class *writer_clock_class);
49 static
50 int find_update_enum_clock_fields(FILE *err, struct bt_ctf_field_type *type,
51 struct bt_ctf_clock_class *writer_clock_class);
52 static
53 int find_update_sequence_clock_fields(FILE *err, struct bt_ctf_field_type *type,
54 struct bt_ctf_clock_class *writer_clock_class);
55 static
56 int find_update_variant_clock_fields(FILE *err, struct bt_ctf_field_type *type,
57 struct bt_ctf_clock_class *writer_clock_class);
58
59 static
60 int copy_find_clock_int_field(FILE *err,
61 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
62 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
63 struct bt_ctf_field *copy_field);
64 static
65 int copy_find_clock_struct_field(FILE *err,
66 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
67 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
68 struct bt_ctf_field *copy_field);
69 static
70 int copy_find_clock_array_field(FILE *err,
71 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
72 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
73 struct bt_ctf_field *copy_field);
74 static
75 int copy_find_clock_sequence_field(FILE *err,
76 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
77 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
78 struct bt_ctf_field *copy_field);
79 static
80 int copy_find_clock_variant_field(FILE *err, struct bt_ctf_event *event,
81 struct bt_ctf_event *writer_event, struct bt_ctf_field *field,
82 struct bt_ctf_field_type *type, struct bt_ctf_field *copy_field);
83 static
84 int copy_find_clock_enum_field(FILE *err, struct bt_ctf_event *event,
85 struct bt_ctf_event *writer_event, struct bt_ctf_field *field,
86 struct bt_ctf_field_type *type, struct bt_ctf_field *copy_field);
87
88 static
89 int update_header_clock_int_field_type(FILE *err, struct bt_ctf_field_type *type,
90 struct bt_ctf_clock_class *writer_clock_class)
91 {
92 struct bt_ctf_clock_class *clock = NULL;
93 int ret;
94
95 clock = bt_ctf_field_type_integer_get_mapped_clock_class(type);
96 if (!clock) {
97 return 0;
98 }
99 BT_PUT(clock);
100
101 ret = bt_ctf_field_type_integer_set_size(type, 64);
102 if (ret) {
103 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
104 __LINE__);
105 goto end;
106 }
107
108 ret = bt_ctf_field_type_integer_set_mapped_clock_class(type,
109 writer_clock_class);
110 if (ret) {
111 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
112 __LINE__);
113 goto end;
114 }
115
116 end:
117 return ret;
118 }
119
120 static
121 int find_update_clock_fields(FILE *err, struct bt_ctf_field_type *type,
122 struct bt_ctf_clock_class *writer_clock_class)
123 {
124 int ret;
125
126 switch (bt_ctf_field_type_get_type_id(type)) {
127 case BT_CTF_FIELD_TYPE_ID_INTEGER:
128 return update_header_clock_int_field_type(err, type,
129 writer_clock_class);
130 case BT_CTF_FIELD_TYPE_ID_STRUCT:
131 return find_update_struct_clock_fields(err, type,
132 writer_clock_class);
133 case BT_CTF_FIELD_TYPE_ID_ARRAY:
134 return find_update_array_clock_fields(err, type,
135 writer_clock_class);
136 case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
137 return find_update_sequence_clock_fields(err, type,
138 writer_clock_class);
139 case BT_CTF_FIELD_TYPE_ID_VARIANT:
140 return find_update_variant_clock_fields(err, type,
141 writer_clock_class);
142 case BT_CTF_FIELD_TYPE_ID_ENUM:
143 return find_update_enum_clock_fields(err, type,
144 writer_clock_class);
145 break;
146 default:
147 break;
148 }
149
150 ret = 0;
151
152 return ret;
153 }
154
155 static
156 int find_update_variant_clock_fields(FILE *err, struct bt_ctf_field_type *type,
157 struct bt_ctf_clock_class *writer_clock_class)
158 {
159 int count, i, ret;
160 struct bt_ctf_field_type *entry_type = NULL;
161
162 count = bt_ctf_field_type_variant_get_field_count(type);
163 for (i = 0; i < count; i++) {
164 const char *entry_name;
165
166 ret = bt_ctf_field_type_variant_get_field(type,
167 &entry_name, &entry_type, i);
168 if (ret) {
169 fprintf(err, "[error] %s in %s:%d\n",
170 __func__, __FILE__, __LINE__);
171 goto error;
172 }
173 ret = find_update_clock_fields(err, entry_type,
174 writer_clock_class);
175 if (ret) {
176 fprintf(err, "[error] %s in %s:%d\n",
177 __func__, __FILE__, __LINE__);
178 goto error;
179 }
180 BT_PUT(entry_type);
181 }
182
183 ret = 0;
184 goto end;
185
186 error:
187 ret = -1;
188 end:
189 bt_put(entry_type);
190 return ret;
191 }
192
193 static
194 int find_update_struct_clock_fields(FILE *err, struct bt_ctf_field_type *type,
195 struct bt_ctf_clock_class *writer_clock_class)
196 {
197 int count, i, ret;
198 struct bt_ctf_field_type *entry_type = NULL;
199
200 count = bt_ctf_field_type_structure_get_field_count(type);
201 for (i = 0; i < count; i++) {
202 const char *entry_name;
203
204 ret = bt_ctf_field_type_structure_get_field(type,
205 &entry_name, &entry_type, i);
206 if (ret) {
207 fprintf(err, "[error] %s in %s:%d\n",
208 __func__, __FILE__, __LINE__);
209 goto error;
210 }
211 ret = find_update_clock_fields(err, entry_type,
212 writer_clock_class);
213 if (ret) {
214 fprintf(err, "[error] %s in %s:%d\n",
215 __func__, __FILE__, __LINE__);
216 goto error;
217 }
218 BT_PUT(entry_type);
219 }
220
221 ret = 0;
222 goto end;
223
224 error:
225 bt_put(entry_type);
226 end:
227 return ret;
228 }
229
230 static
231 int find_update_sequence_clock_fields(FILE *err, struct bt_ctf_field_type *type,
232 struct bt_ctf_clock_class *writer_clock_class)
233 {
234 int ret;
235 struct bt_ctf_field_type *entry_type = NULL;
236
237 entry_type = bt_ctf_field_type_sequence_get_element_type(type);
238 if (!entry_type) {
239 fprintf(err, "[error] %s in %s:%d\n",
240 __func__, __FILE__, __LINE__);
241 goto error;
242 }
243 ret = find_update_clock_fields(err, entry_type, writer_clock_class);
244 BT_PUT(entry_type);
245 if (ret) {
246 fprintf(err, "[error] %s in %s:%d\n",
247 __func__, __FILE__, __LINE__);
248 goto error;
249 }
250
251 ret = 0;
252 goto end;
253
254 error:
255 ret = -1;
256 end:
257 return ret;
258 }
259
260 static
261 int find_update_array_clock_fields(FILE *err, struct bt_ctf_field_type *type,
262 struct bt_ctf_clock_class *writer_clock_class)
263 {
264 int ret;
265 struct bt_ctf_field_type *entry_type = NULL;
266
267 entry_type = bt_ctf_field_type_array_get_element_type(type);
268 if (!entry_type) {
269 fprintf(err, "[error] %s in %s:%d\n",
270 __func__, __FILE__, __LINE__);
271 goto error;
272 }
273 ret = find_update_clock_fields(err, entry_type, writer_clock_class);
274 BT_PUT(entry_type);
275 if (ret) {
276 fprintf(err, "[error] %s in %s:%d\n",
277 __func__, __FILE__, __LINE__);
278 ret = -1;
279 goto end;
280 }
281
282 ret = 0;
283 goto end;
284
285 error:
286 ret = -1;
287 end:
288 return ret;
289 }
290
291 static
292 int find_update_enum_clock_fields(FILE *err, struct bt_ctf_field_type *type,
293 struct bt_ctf_clock_class *writer_clock_class)
294 {
295 int ret;
296 struct bt_ctf_field_type *entry_type = NULL;
297
298 entry_type = bt_ctf_field_type_enumeration_get_container_type(type);
299 if (!entry_type) {
300 fprintf(err, "[error] %s in %s:%d\n",
301 __func__, __FILE__, __LINE__);
302 goto error;
303 }
304 ret = find_update_clock_fields(err, entry_type, writer_clock_class);
305 BT_PUT(entry_type);
306 if (ret) {
307 fprintf(err, "[error] %s in %s:%d\n",
308 __func__, __FILE__, __LINE__);
309 goto error;
310 }
311
312 ret = 0;
313 goto end;
314
315 error:
316 ret = -1;
317 end:
318 return ret;
319 }
320
321 BT_HIDDEN
322 struct bt_ctf_field_type *override_header_type(FILE *err,
323 struct bt_ctf_field_type *type,
324 struct bt_ctf_trace *writer_trace)
325 {
326 struct bt_ctf_field_type *new_type = NULL;
327 struct bt_ctf_clock_class *writer_clock_class = NULL;
328 int ret;
329
330 /* FIXME multi-clock? */
331 writer_clock_class = bt_ctf_trace_get_clock_class_by_index(writer_trace, 0);
332 if (!writer_clock_class) {
333 fprintf(err, "[error] %s in %s:%d\n",
334 __func__, __FILE__, __LINE__);
335 goto error;
336 }
337
338 new_type = bt_ctf_field_type_copy(type);
339 if (!new_type) {
340 fprintf(err, "[error] %s in %s:%d\n",
341 __func__, __FILE__, __LINE__);
342 goto error;
343 }
344
345 if (bt_ctf_field_type_get_type_id(new_type) != BT_CTF_FIELD_TYPE_ID_STRUCT) {
346 fprintf(err, "[error] Unexpected header field type\n");
347 goto error;
348 }
349
350 ret = find_update_struct_clock_fields(err, new_type, writer_clock_class);
351 if (ret) {
352 fprintf(err, "[error] %s in %s:%d\n",
353 __func__, __FILE__, __LINE__);
354 goto error;
355 }
356 BT_PUT(writer_clock_class);
357
358 goto end;
359
360 error:
361 bt_put(writer_clock_class);
362 BT_PUT(new_type);
363 end:
364 return new_type;
365 }
366
367 static
368 int copy_float_field(FILE *err, struct bt_ctf_field *field,
369 struct bt_ctf_field_type *type,
370 struct bt_ctf_field *copy_field)
371 {
372 double value;
373 int ret;
374
375 ret = bt_ctf_field_floating_point_get_value(field, &value);
376 if (ret) {
377 ret = -1;
378 fprintf(err, "[error] %s in %s:%d\n", __func__,
379 __FILE__, __LINE__);
380 goto end;
381 }
382 ret = bt_ctf_field_floating_point_set_value(copy_field, value);
383 if (ret) {
384 ret = -1;
385 fprintf(err, "[error] %s in %s:%d\n", __func__,
386 __FILE__, __LINE__);
387 goto end;
388 }
389
390 ret = 0;
391
392 end:
393 return ret;
394 }
395
396 static
397 int copy_string_field(FILE *err, struct bt_ctf_field *field,
398 struct bt_ctf_field_type *type,
399 struct bt_ctf_field *copy_field)
400 {
401 const char *value;
402 int ret;
403
404 value = bt_ctf_field_string_get_value(field);
405 if (!value) {
406 ret = -1;
407 fprintf(err, "[error] %s in %s:%d\n", __func__,
408 __FILE__, __LINE__);
409 goto end;
410 }
411 ret = bt_ctf_field_string_set_value(copy_field, value);
412 if (ret) {
413 ret = -1;
414 fprintf(err, "[error] %s in %s:%d\n", __func__,
415 __FILE__, __LINE__);
416 goto end;
417 }
418
419 ret = 0;
420
421 end:
422 return ret;
423 }
424
425 BT_HIDDEN
426 int copy_override_field(FILE *err, struct bt_ctf_event *event,
427 struct bt_ctf_event *writer_event, struct bt_ctf_field *field,
428 struct bt_ctf_field *copy_field)
429 {
430 struct bt_ctf_field_type *type = NULL;
431 int ret;
432
433 type = bt_ctf_field_get_type(field);
434 if (!type) {
435 ret = -1;
436 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
437 __LINE__);
438 goto end;
439 }
440
441 switch (bt_ctf_field_type_get_type_id(type)) {
442 case BT_CTF_FIELD_TYPE_ID_INTEGER:
443 ret = copy_find_clock_int_field(err, event, writer_event,
444 field, type, copy_field);
445 break;
446 case BT_CTF_FIELD_TYPE_ID_STRUCT:
447 ret = copy_find_clock_struct_field(err, event, writer_event,
448 field, type, copy_field);
449 break;
450 case BT_CTF_FIELD_TYPE_ID_FLOAT:
451 ret = copy_float_field(err, field, type, copy_field);
452 break;
453 case BT_CTF_FIELD_TYPE_ID_ENUM:
454 ret = copy_find_clock_enum_field(err, event, writer_event,
455 field, type, copy_field);
456 break;
457 case BT_CTF_FIELD_TYPE_ID_STRING:
458 ret = copy_string_field(err, field, type, copy_field);
459 break;
460 case BT_CTF_FIELD_TYPE_ID_ARRAY:
461 ret = copy_find_clock_array_field(err, event, writer_event,
462 field, type, copy_field);
463 break;
464 case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
465 ret = copy_find_clock_sequence_field(err, event, writer_event,
466 field, type, copy_field);
467 break;
468 case BT_CTF_FIELD_TYPE_ID_VARIANT:
469 ret = copy_find_clock_variant_field(err, event, writer_event,
470 field, type, copy_field);
471 break;
472 /* No default, we want to catch missing field types. */
473 case BT_CTF_FIELD_TYPE_ID_UNKNOWN:
474 case BT_CTF_NR_TYPE_IDS:
475 break;
476 }
477
478 ret = 0;
479 BT_PUT(type);
480
481 end:
482 return ret;
483 }
484
485 static
486 int copy_find_clock_enum_field(FILE *err, struct bt_ctf_event *event,
487 struct bt_ctf_event *writer_event, struct bt_ctf_field *field,
488 struct bt_ctf_field_type *type, struct bt_ctf_field *copy_field)
489 {
490 int ret;
491 struct bt_ctf_field *container = NULL, *copy_container = NULL;
492
493 container = bt_ctf_field_enumeration_get_container(field);
494 if (!container) {
495 ret = -1;
496 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
497 __LINE__);
498 goto end;
499 }
500
501 copy_container = bt_ctf_field_enumeration_get_container(copy_field);
502 if (!copy_container) {
503 ret = -1;
504 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
505 __LINE__);
506 goto error;
507 }
508
509 ret = copy_override_field(err, event, writer_event, container,
510 copy_container);
511 if (ret) {
512 ret = -1;
513 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
514 __LINE__);
515 goto error;
516 }
517
518 ret = 0;
519 goto end;
520
521 error:
522 ret = -1;
523 end:
524 bt_put(copy_container);
525 bt_put(container);
526 return ret;
527 }
528
529 static
530 int copy_find_clock_variant_field(FILE *err, struct bt_ctf_event *event,
531 struct bt_ctf_event *writer_event, struct bt_ctf_field *field,
532 struct bt_ctf_field_type *type, struct bt_ctf_field *copy_field)
533 {
534 int ret;
535 struct bt_ctf_field *tag = NULL;
536 struct bt_ctf_field *variant_field = NULL, *copy_variant_field = NULL;
537
538 tag = bt_ctf_field_variant_get_tag(field);
539 if (!tag) {
540 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
541 __LINE__);
542 goto error;
543 }
544
545 variant_field = bt_ctf_field_variant_get_field(field, tag);
546 if (!variant_field) {
547 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
548 __LINE__);
549 goto error;
550 }
551
552 copy_variant_field = bt_ctf_field_variant_get_field(copy_field, tag);
553 if (!copy_variant_field) {
554 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
555 __LINE__);
556 goto error;
557 }
558
559 ret = copy_override_field(err, event, writer_event, variant_field,
560 copy_variant_field);
561 if (ret) {
562 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
563 __LINE__);
564 goto error;
565 }
566
567 ret = 0;
568 goto end;
569
570 error:
571 ret = -1;
572 end:
573 bt_put(copy_variant_field);
574 bt_put(variant_field);
575 bt_put(tag);
576 return ret;
577 }
578
579 static
580 int copy_find_clock_sequence_field(FILE *err,
581 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
582 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
583 struct bt_ctf_field *copy_field)
584 {
585 int ret;
586 uint64_t i, count;
587 struct bt_ctf_field *length_field = NULL;
588 struct bt_ctf_field *entry_field = NULL, *entry_copy = NULL;
589
590 length_field = bt_ctf_field_sequence_get_length(field);
591 if (!length_field) {
592 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
593 __LINE__);
594 goto error;
595 }
596
597 ret = bt_ctf_field_unsigned_integer_get_value(length_field, &count);
598 if (ret) {
599 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
600 __LINE__);
601 goto error;
602 }
603
604 ret = bt_ctf_field_sequence_set_length(copy_field, length_field);
605 if (ret) {
606 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
607 __LINE__);
608 goto error;
609 }
610 BT_PUT(length_field);
611
612 for (i = 0; i < count; i++) {
613 entry_field = bt_ctf_field_sequence_get_field(field, i);
614 if (!entry_field) {
615 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
616 __LINE__);
617 goto error;
618 }
619
620 entry_copy = bt_ctf_field_sequence_get_field(copy_field, i);
621 if (!entry_copy) {
622 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
623 __LINE__);
624 goto error;
625 }
626
627 ret = copy_override_field(err, event, writer_event, entry_field,
628 entry_copy);
629 if (ret) {
630 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
631 __LINE__);
632 goto error;
633 }
634 BT_PUT(entry_field);
635 BT_PUT(entry_copy);
636 }
637
638 ret = 0;
639 goto end;
640
641 error:
642 bt_put(length_field);
643 bt_put(entry_field);
644 bt_put(entry_copy);
645 ret = -1;
646 end:
647 return ret;
648 }
649
650 static
651 int copy_find_clock_array_field(FILE *err,
652 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
653 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
654 struct bt_ctf_field *copy_field)
655 {
656 int ret, count, i;
657 struct bt_ctf_field *entry_field = NULL, *entry_copy = NULL;
658
659 count = bt_ctf_field_type_array_get_length(type);
660 for (i = 0; i < count; i++) {
661 entry_field = bt_ctf_field_array_get_field(field, i);
662 if (!entry_field) {
663 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
664 __LINE__);
665 goto error;
666 }
667
668 entry_copy = bt_ctf_field_array_get_field(copy_field, i);
669 if (!entry_copy) {
670 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
671 __LINE__);
672 goto error;
673 }
674
675 ret = copy_override_field(err, event, writer_event, entry_field,
676 entry_copy);
677 if (ret) {
678 ret = -1;
679 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
680 __LINE__);
681 goto error;
682 }
683 BT_PUT(entry_field);
684 BT_PUT(entry_copy);
685 }
686
687 ret = 0;
688 goto end;
689
690 error:
691 bt_put(entry_field);
692 bt_put(entry_copy);
693
694 end:
695 return ret;
696 }
697
698 static
699 int copy_find_clock_struct_field(FILE *err,
700 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
701 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
702 struct bt_ctf_field *copy_field)
703 {
704 int count, i, ret;
705 struct bt_ctf_field_type *entry_type = NULL;
706 struct bt_ctf_field *entry_field = NULL, *entry_copy = NULL;
707
708 count = bt_ctf_field_type_structure_get_field_count(type);
709 for (i = 0; i < count; i++) {
710 const char *entry_name;
711
712 entry_field = bt_ctf_field_structure_get_field_by_index(field, i);
713 if (!entry_field) {
714 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
715 __LINE__);
716 goto error;
717 }
718
719 ret = bt_ctf_field_type_structure_get_field(type, &entry_name,
720 &entry_type, i);
721 if (ret) {
722 fprintf(err, "[error] %s in %s:%d\n",
723 __func__, __FILE__, __LINE__);
724 goto error;
725 }
726
727 entry_copy = bt_ctf_field_structure_get_field_by_index(copy_field, i);
728 if (!entry_copy) {
729 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
730 __LINE__);
731 goto error;
732 }
733
734 ret = copy_override_field(err, event, writer_event, entry_field,
735 entry_copy);
736 if (ret) {
737 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
738 __LINE__);
739 goto error;
740 }
741 BT_PUT(entry_copy);
742 BT_PUT(entry_field);
743 BT_PUT(entry_type);
744 }
745
746 ret = 0;
747 goto end;
748
749 error:
750 bt_put(entry_type);
751 bt_put(entry_field);
752 bt_put(entry_copy);
753 ret = -1;
754 end:
755 return ret;
756 }
757
758 static
759 int set_int_value(FILE *err, struct bt_ctf_field *field,
760 struct bt_ctf_field *copy_field,
761 struct bt_ctf_field_type *type)
762 {
763 uint64_t uvalue;
764 int64_t value;
765 int ret;
766
767 if (bt_ctf_field_type_integer_get_signed(type)) {
768 ret = bt_ctf_field_signed_integer_get_value(field, &value);
769 if (ret) {
770 ret = -1;
771 fprintf(err, "[error] %s in %s:%d\n", __func__,
772 __FILE__, __LINE__);
773 goto end;
774 }
775 ret = bt_ctf_field_signed_integer_set_value(copy_field, value);
776 if (ret) {
777 ret = -1;
778 fprintf(err, "[error] %s in %s:%d\n", __func__,
779 __FILE__, __LINE__);
780 goto end;
781 }
782 } else {
783 ret = bt_ctf_field_unsigned_integer_get_value(field,
784 &uvalue);
785 if (ret) {
786 ret = -1;
787 fprintf(err, "[error] %s in %s:%d\n", __func__,
788 __FILE__, __LINE__);
789 goto end;
790 }
791 ret = bt_ctf_field_unsigned_integer_set_value(copy_field, uvalue);
792 if (ret) {
793 ret = -1;
794 fprintf(err, "[error] %s in %s:%d\n", __func__,
795 __FILE__, __LINE__);
796 goto end;
797 }
798 }
799 ret = 0;
800
801 end:
802 return ret;
803 }
804
805 struct bt_ctf_clock_class *stream_class_get_clock_class(FILE *err,
806 struct bt_ctf_stream_class *stream_class)
807 {
808 struct bt_ctf_trace *trace = NULL;
809 struct bt_ctf_clock_class *clock_class = NULL;
810
811 trace = bt_ctf_stream_class_get_trace(stream_class);
812 if (!trace) {
813 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
814 __LINE__);
815 goto end;
816 }
817
818 /* FIXME multi-clock? */
819 clock_class = bt_ctf_trace_get_clock_class_by_index(trace, 0);
820
821 bt_put(trace);
822 end:
823 return clock_class;
824 }
825
826 struct bt_ctf_clock_class *event_get_clock_class(FILE *err, struct bt_ctf_event *event)
827 {
828 struct bt_ctf_event_class *event_class = NULL;
829 struct bt_ctf_stream_class *stream_class = NULL;
830 struct bt_ctf_clock_class *clock_class = NULL;
831
832 event_class = bt_ctf_event_get_class(event);
833 if (!event_class) {
834 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
835 __LINE__);
836 goto end;
837 }
838
839 stream_class = bt_ctf_event_class_get_stream_class(event_class);
840 BT_PUT(event_class);
841 if (!stream_class) {
842 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
843 __LINE__);
844 goto end;
845 }
846
847 clock_class = stream_class_get_clock_class(err, stream_class);
848 bt_put(stream_class);
849
850 end:
851 return clock_class;
852 }
853
854 static
855 int copy_find_clock_int_field(FILE *err,
856 struct bt_ctf_event *event, struct bt_ctf_event *writer_event,
857 struct bt_ctf_field *field, struct bt_ctf_field_type *type,
858 struct bt_ctf_field *copy_field)
859 {
860 struct bt_ctf_clock_class *clock_class = NULL, *writer_clock_class = NULL;
861 struct bt_ctf_clock_value *clock_value = NULL, *writer_clock_value = NULL;
862 uint64_t value;
863 int ret;
864
865 clock_class = bt_ctf_field_type_integer_get_mapped_clock_class(type);
866 if (!clock_class) {
867 return set_int_value(err, field, copy_field, type);
868 }
869
870 clock_value = bt_ctf_event_get_clock_value(event, clock_class);
871 BT_PUT(clock_class);
872 if (!clock_value) {
873 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
874 __LINE__);
875 goto error;
876 }
877
878 ret = bt_ctf_clock_value_get_value(clock_value, &value);
879 BT_PUT(clock_value);
880 if (ret) {
881 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
882 __LINE__);
883 goto error;
884 }
885
886 ret = bt_ctf_field_unsigned_integer_set_value(copy_field, value);
887 if (ret) {
888 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
889 __LINE__);
890 goto error;
891 }
892
893 writer_clock_class = event_get_clock_class(err, writer_event);
894 if (!writer_clock_class) {
895 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
896 __LINE__);
897 goto error;
898 }
899
900 writer_clock_value = bt_ctf_clock_value_create(writer_clock_class, value);
901 BT_PUT(writer_clock_class);
902 if (!writer_clock_value) {
903 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
904 __LINE__);
905 goto error;
906 }
907
908 ret = bt_ctf_event_set_clock_value(writer_event, writer_clock_value);
909 BT_PUT(writer_clock_value);
910 if (ret) {
911 fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
912 __LINE__);
913 goto error;
914 }
915
916 ret = 0;
917 goto end;
918
919 error:
920 ret = -1;
921 end:
922 return ret;
923 }
924
This page took 0.0519269999999999 seconds and 5 git commands to generate.