Make API CTF-agnostic
[babeltrace.git] / plugins / ctf / common / metadata / ctf-meta-update-meanings.c
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-UPDATE-MEANINGS"
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
28 static
29 int set_int_field_type_meaning_by_name(struct ctf_field_type *ft,
30 const char *field_name, const char *id_name,
31 enum ctf_field_type_meaning meaning)
32 {
33 int ret = 0;
34 uint64_t i;
35
36 if (!ft) {
37 goto end;
38 }
39
40 switch (ft->id) {
41 case CTF_FIELD_TYPE_ID_INT:
42 case CTF_FIELD_TYPE_ID_ENUM:
43 {
44 struct ctf_field_type_int *int_ft = (void *) ft;
45
46 if (field_name && strcmp(field_name, id_name) == 0) {
47 int_ft->meaning = meaning;
48 }
49
50 break;
51 }
52 case CTF_FIELD_TYPE_ID_STRUCT:
53 {
54 struct ctf_field_type_struct *struct_ft = (void *) ft;
55
56 for (i = 0; i < struct_ft->members->len; i++) {
57 struct ctf_named_field_type *named_ft =
58 ctf_field_type_struct_borrow_member_by_index(
59 struct_ft, i);
60
61 ret = set_int_field_type_meaning_by_name(named_ft->ft,
62 named_ft->name->str, id_name, meaning);
63 if (ret) {
64 goto end;
65 }
66 }
67
68 break;
69 }
70 case CTF_FIELD_TYPE_ID_VARIANT:
71 {
72 struct ctf_field_type_variant *var_ft = (void *) ft;
73
74 for (i = 0; i < var_ft->options->len; i++) {
75 struct ctf_named_field_type *named_ft =
76 ctf_field_type_variant_borrow_option_by_index(
77 var_ft, i);
78
79 ret = set_int_field_type_meaning_by_name(named_ft->ft,
80 NULL, id_name, meaning);
81 if (ret) {
82 goto end;
83 }
84 }
85
86 break;
87 }
88 case CTF_FIELD_TYPE_ID_ARRAY:
89 case CTF_FIELD_TYPE_ID_SEQUENCE:
90 {
91 struct ctf_field_type_array_base *array_ft = (void *) ft;
92
93 ret = set_int_field_type_meaning_by_name(array_ft->elem_ft,
94 NULL, id_name, meaning);
95 if (ret) {
96 goto end;
97 }
98
99 break;
100 }
101 default:
102 break;
103 }
104
105 end:
106 return ret;
107 }
108
109 static
110 int update_stream_class_meanings(struct ctf_stream_class *sc)
111 {
112 int ret = 0;
113 struct ctf_field_type_int *int_ft;
114 uint64_t i;
115
116 if (!sc->is_translated) {
117 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
118 (void *) sc->packet_context_ft, "timestamp_begin");
119 if (int_ft) {
120 int_ft->meaning = CTF_FIELD_TYPE_MEANING_PACKET_BEGINNING_TIME;
121 }
122
123 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
124 (void *) sc->packet_context_ft, "timestamp_end");
125 if (int_ft) {
126 int_ft->meaning = CTF_FIELD_TYPE_MEANING_PACKET_END_TIME;
127
128 /*
129 * Remove mapped clock class to avoid updating
130 * the clock immediately when decoding.
131 */
132 int_ft->mapped_clock_class = NULL;
133 }
134
135 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
136 (void *) sc->packet_context_ft, "events_discarded");
137 if (int_ft) {
138 int_ft->meaning = CTF_FIELD_TYPE_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT;
139 }
140
141 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
142 (void *) sc->packet_context_ft, "packet_seq_num");
143 if (int_ft) {
144 int_ft->meaning = CTF_FIELD_TYPE_MEANING_PACKET_COUNTER_SNAPSHOT;
145
146 }
147
148 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
149 (void *) sc->packet_context_ft, "packet_size");
150 if (int_ft) {
151 int_ft->meaning = CTF_FIELD_TYPE_MEANING_EXP_PACKET_TOTAL_SIZE;
152 }
153
154 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
155 (void *) sc->packet_context_ft, "content_size");
156 if (int_ft) {
157 int_ft->meaning = CTF_FIELD_TYPE_MEANING_EXP_PACKET_CONTENT_SIZE;
158 }
159
160 ret = set_int_field_type_meaning_by_name(
161 sc->event_header_ft, NULL, "id",
162 CTF_FIELD_TYPE_MEANING_EVENT_CLASS_ID);
163 if (ret) {
164 goto end;
165 }
166 }
167
168 for (i = 0; i < sc->event_classes->len; i++) {
169 struct ctf_event_class *ec = sc->event_classes->pdata[i];
170
171 if (ec->is_translated) {
172 continue;
173 }
174 }
175
176 end:
177 return ret;
178 }
179
180 BT_HIDDEN
181 int ctf_trace_class_update_meanings(struct ctf_trace_class *ctf_tc)
182 {
183 int ret = 0;
184 struct ctf_field_type_int *int_ft;
185 struct ctf_named_field_type *named_ft;
186 uint64_t i;
187
188 if (!ctf_tc->is_translated) {
189 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
190 (void *) ctf_tc->packet_header_ft, "magic");
191 if (int_ft) {
192 int_ft->meaning = CTF_FIELD_TYPE_MEANING_MAGIC;
193 }
194
195 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
196 (void *) ctf_tc->packet_header_ft, "stream_id");
197 if (int_ft) {
198 int_ft->meaning = CTF_FIELD_TYPE_MEANING_STREAM_CLASS_ID;
199 }
200
201 int_ft = ctf_field_type_struct_borrow_member_int_field_type_by_name(
202 (void *) ctf_tc->packet_header_ft,
203 "stream_instance_id");
204 if (int_ft) {
205 int_ft->meaning = CTF_FIELD_TYPE_MEANING_DATA_STREAM_ID;
206 }
207
208 named_ft = ctf_field_type_struct_borrow_member_by_name(
209 (void *) ctf_tc->packet_header_ft, "uuid");
210 if (named_ft && named_ft->ft->id == CTF_FIELD_TYPE_ID_ARRAY) {
211 struct ctf_field_type_array *array_ft =
212 (void *) named_ft->ft;
213
214 array_ft->meaning = CTF_FIELD_TYPE_MEANING_UUID;
215 }
216 }
217
218 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
219 ret = update_stream_class_meanings(
220 ctf_tc->stream_classes->pdata[i]);
221 if (ret) {
222 goto end;
223 }
224 }
225
226 end:
227 return ret;
228 }
This page took 0.03386 seconds and 4 git commands to generate.