Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-meanings.c
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.h"
16
17 static
18 int set_int_field_class_meaning_by_name(struct ctf_field_class *fc,
19 const char *field_name, const char *id_name,
20 enum ctf_field_class_meaning meaning)
21 {
22 int ret = 0;
23 uint64_t i;
24
25 if (!fc) {
26 goto end;
27 }
28
29 switch (fc->type) {
30 case CTF_FIELD_CLASS_TYPE_INT:
31 case CTF_FIELD_CLASS_TYPE_ENUM:
32 {
33 struct ctf_field_class_int *int_fc = (void *) fc;
34
35 if (field_name && strcmp(field_name, id_name) == 0) {
36 int_fc->meaning = meaning;
37 }
38
39 break;
40 }
41 case CTF_FIELD_CLASS_TYPE_STRUCT:
42 {
43 struct ctf_field_class_struct *struct_fc = (void *) fc;
44
45 for (i = 0; i < struct_fc->members->len; i++) {
46 struct ctf_named_field_class *named_fc =
47 ctf_field_class_struct_borrow_member_by_index(
48 struct_fc, i);
49
50 ret = set_int_field_class_meaning_by_name(named_fc->fc,
51 named_fc->name->str, id_name, meaning);
52 if (ret) {
53 goto end;
54 }
55 }
56
57 break;
58 }
59 case CTF_FIELD_CLASS_TYPE_VARIANT:
60 {
61 struct ctf_field_class_variant *var_fc = (void *) fc;
62
63 for (i = 0; i < var_fc->options->len; i++) {
64 struct ctf_named_field_class *named_fc =
65 ctf_field_class_variant_borrow_option_by_index(
66 var_fc, i);
67
68 ret = set_int_field_class_meaning_by_name(named_fc->fc,
69 NULL, id_name, meaning);
70 if (ret) {
71 goto end;
72 }
73 }
74
75 break;
76 }
77 case CTF_FIELD_CLASS_TYPE_ARRAY:
78 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
79 {
80 struct ctf_field_class_array_base *array_fc = (void *) fc;
81
82 ret = set_int_field_class_meaning_by_name(array_fc->elem_fc,
83 NULL, id_name, meaning);
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 static
99 int update_stream_class_meanings(struct ctf_stream_class *sc)
100 {
101 int ret = 0;
102 struct ctf_field_class_int *int_fc;
103 uint64_t i;
104
105 if (!sc->is_translated) {
106 if (sc->packet_context_fc) {
107 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
108 (void *) sc->packet_context_fc, "timestamp_begin");
109 if (int_fc) {
110 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME;
111 }
112
113 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
114 (void *) sc->packet_context_fc, "timestamp_end");
115 if (int_fc) {
116 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_END_TIME;
117
118 /*
119 * Remove mapped clock class to avoid updating
120 * the clock immediately when decoding.
121 */
122 int_fc->mapped_clock_class = NULL;
123 }
124
125 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
126 (void *) sc->packet_context_fc, "events_discarded");
127 if (int_fc) {
128 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT;
129 }
130
131 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
132 (void *) sc->packet_context_fc, "packet_seq_num");
133 if (int_fc) {
134 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT;
135
136 }
137
138 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
139 (void *) sc->packet_context_fc, "packet_size");
140 if (int_fc) {
141 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE;
142 }
143
144 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
145 (void *) sc->packet_context_fc, "content_size");
146 if (int_fc) {
147 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE;
148 }
149 }
150
151 if (sc->event_header_fc) {
152 ret = set_int_field_class_meaning_by_name(
153 sc->event_header_fc, NULL, "id",
154 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID);
155 if (ret) {
156 goto end;
157 }
158 }
159 }
160
161 for (i = 0; i < sc->event_classes->len; i++) {
162 struct ctf_event_class *ec = sc->event_classes->pdata[i];
163
164 if (ec->is_translated) {
165 continue;
166 }
167 }
168
169 end:
170 return ret;
171 }
172
173 BT_HIDDEN
174 int ctf_trace_class_update_meanings(struct ctf_trace_class *ctf_tc)
175 {
176 int ret = 0;
177 struct ctf_field_class_int *int_fc;
178 struct ctf_named_field_class *named_fc;
179 uint64_t i;
180
181 if (!ctf_tc->is_translated && ctf_tc->packet_header_fc) {
182 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
183 (void *) ctf_tc->packet_header_fc, "magic");
184 if (int_fc) {
185 int_fc->meaning = CTF_FIELD_CLASS_MEANING_MAGIC;
186 }
187
188 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
189 (void *) ctf_tc->packet_header_fc, "stream_id");
190 if (int_fc) {
191 int_fc->meaning = CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID;
192 }
193
194 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
195 (void *) ctf_tc->packet_header_fc,
196 "stream_instance_id");
197 if (int_fc) {
198 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID;
199 }
200
201 named_fc = ctf_field_class_struct_borrow_member_by_name(
202 (void *) ctf_tc->packet_header_fc, "uuid");
203 if (named_fc && named_fc->fc->type == CTF_FIELD_CLASS_TYPE_ARRAY) {
204 struct ctf_field_class_array *array_fc =
205 (void *) named_fc->fc;
206
207 array_fc->meaning = CTF_FIELD_CLASS_MEANING_UUID;
208 }
209 }
210
211 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
212 ret = update_stream_class_meanings(
213 ctf_tc->stream_classes->pdata[i]);
214 if (ret) {
215 goto end;
216 }
217 }
218
219 end:
220 return ret;
221 }
This page took 0.033508 seconds and 4 git commands to generate.