Re-format new C++ files
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-text-array-sequence.cpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #include <babeltrace2/babeltrace.h>
8 #include "common/macros.h"
9 #include "common/assert.h"
10 #include <glib.h>
11 #include <stdint.h>
12 #include <string.h>
13 #include <inttypes.h>
14
15 #include "ctf-meta-visitors.hpp"
16
17 static inline int set_text_array_sequence_field_class(struct ctf_field_class *fc)
18 {
19 int ret = 0;
20 uint64_t i;
21
22 if (!fc) {
23 goto end;
24 }
25
26 switch (fc->type) {
27 case CTF_FIELD_CLASS_TYPE_STRUCT:
28 {
29 struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc);
30
31 for (i = 0; i < struct_fc->members->len; i++) {
32 struct ctf_named_field_class *named_fc =
33 ctf_field_class_struct_borrow_member_by_index(struct_fc, i);
34
35 ret = set_text_array_sequence_field_class(named_fc->fc);
36 if (ret) {
37 goto end;
38 }
39 }
40
41 break;
42 }
43 case CTF_FIELD_CLASS_TYPE_VARIANT:
44 {
45 struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc);
46
47 for (i = 0; i < var_fc->options->len; i++) {
48 struct ctf_named_field_class *named_fc =
49 ctf_field_class_variant_borrow_option_by_index(var_fc, i);
50
51 ret = set_text_array_sequence_field_class(named_fc->fc);
52 if (ret) {
53 goto end;
54 }
55 }
56
57 break;
58 }
59 case CTF_FIELD_CLASS_TYPE_ARRAY:
60 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
61 {
62 struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc);
63
64 if (array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_INT ||
65 array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_ENUM) {
66 struct ctf_field_class_int *int_fc = ctf_field_class_as_int(array_fc->elem_fc);
67
68 if (int_fc->base.base.alignment == 8 && int_fc->base.size == 8 &&
69 int_fc->encoding == CTF_ENCODING_UTF8) {
70 array_fc->is_text = true;
71
72 /*
73 * Force integer element to be unsigned;
74 * this makes the decoder enter a single
75 * path when reading a text
76 * array/sequence and we can safely
77 * decode bytes as characters anyway.
78 */
79 int_fc->is_signed = false;
80 }
81 }
82
83 ret = set_text_array_sequence_field_class(array_fc->elem_fc);
84 if (ret) {
85 goto end;
86 }
87
88 break;
89 }
90 default:
91 break;
92 }
93
94 end:
95 return ret;
96 }
97
98 BT_HIDDEN
99 int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class *ctf_tc)
100 {
101 int ret = 0;
102 uint64_t i;
103
104 if (!ctf_tc->is_translated) {
105 ret = set_text_array_sequence_field_class(ctf_tc->packet_header_fc);
106 if (ret) {
107 goto end;
108 }
109 }
110
111 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
112 ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i];
113 uint64_t j;
114
115 if (!sc->is_translated) {
116 ret = set_text_array_sequence_field_class(sc->packet_context_fc);
117 if (ret) {
118 goto end;
119 }
120
121 ret = set_text_array_sequence_field_class(sc->event_header_fc);
122 if (ret) {
123 goto end;
124 }
125
126 ret = set_text_array_sequence_field_class(sc->event_common_context_fc);
127 if (ret) {
128 goto end;
129 }
130 }
131
132 for (j = 0; j < sc->event_classes->len; j++) {
133 struct ctf_event_class *ec = (ctf_event_class *) sc->event_classes->pdata[j];
134
135 if (ec->is_translated) {
136 continue;
137 }
138
139 ret = set_text_array_sequence_field_class(ec->spec_context_fc);
140 if (ret) {
141 goto end;
142 }
143
144 ret = set_text_array_sequence_field_class(ec->payload_fc);
145 if (ret) {
146 goto end;
147 }
148 }
149 }
150
151 end:
152 return ret;
153 }
This page took 0.032332 seconds and 4 git commands to generate.