ir: refactor FT validation and resolving
[babeltrace.git] / include / babeltrace / ctf-ir / event-types-internal.h
1 #ifndef BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H
2 #define BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H
3
4 /*
5 * BabelTrace - CTF IR: Event types internal
6 *
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 *
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30 #include <babeltrace/ctf-writer/event-types.h>
31 #include <babeltrace/ctf-writer/event-fields.h>
32 #include <babeltrace/ctf-writer/writer.h>
33 #include <babeltrace/ctf-ir/trace-internal.h>
34 #include <babeltrace/babeltrace-internal.h>
35 #include <babeltrace/object-internal.h>
36 #include <babeltrace/types.h>
37 #include <babeltrace/ctf/events.h>
38 #include <glib.h>
39
40 typedef void (*type_freeze_func)(struct bt_ctf_field_type *);
41 typedef int (*type_serialize_func)(struct bt_ctf_field_type *,
42 struct metadata_context *);
43
44 enum bt_ctf_node {
45 CTF_NODE_UNKNOWN = -1,
46 CTF_NODE_ENV = 0,
47 CTF_NODE_TRACE_PACKET_HEADER = 1,
48 CTF_NODE_STREAM_PACKET_CONTEXT = 2,
49 CTF_NODE_STREAM_EVENT_HEADER = 3,
50 CTF_NODE_STREAM_EVENT_CONTEXT = 4,
51 CTF_NODE_EVENT_CONTEXT = 5,
52 CTF_NODE_EVENT_FIELDS = 6,
53 };
54
55 struct bt_ctf_field_path {
56 enum bt_ctf_node root;
57
58 /*
59 * Array of integers (int) indicating the index in either
60 * structures, variants, arrays, or sequences that make up
61 * the path to a field type. -1 means the "current element
62 * of an array or sequence type".
63 */
64 GArray *path_indexes;
65 };
66
67 struct bt_ctf_field_type {
68 struct bt_object base;
69 struct bt_declaration *declaration;
70 type_freeze_func freeze;
71 type_serialize_func serialize;
72 /*
73 * A type can't be modified once it is added to an event or after a
74 * a field has been instanciated from it.
75 */
76 int frozen;
77
78 /*
79 * This flag indicates if the field type is valid. A valid
80 * field type is _always_ frozen. All the nested field types of
81 * a valid field type are also valid (and thus frozen).
82 */
83 int valid;
84 };
85
86 struct bt_ctf_field_type_integer {
87 struct bt_ctf_field_type parent;
88 struct declaration_integer declaration;
89 struct bt_ctf_clock *mapped_clock;
90
91 /*
92 * This is what the user sets and is never modified by internal
93 * code.
94 *
95 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
96 */
97 enum bt_ctf_byte_order user_byte_order;
98 };
99
100 struct enumeration_mapping {
101 union {
102 uint64_t _unsigned;
103 int64_t _signed;
104 } range_start;
105
106 union {
107 uint64_t _unsigned;
108 int64_t _signed;
109 } range_end;
110 GQuark string;
111 };
112
113 struct bt_ctf_field_type_enumeration {
114 struct bt_ctf_field_type parent;
115 struct bt_ctf_field_type *container;
116 GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */
117 struct declaration_enum declaration;
118 };
119
120 struct bt_ctf_field_type_floating_point {
121 struct bt_ctf_field_type parent;
122 struct declaration_float declaration;
123
124 /*
125 * The `declaration` field above contains 3 pointers pointing
126 * to the fields below. This avoids unnecessary dynamic
127 * allocations.
128 */
129 struct declaration_integer sign;
130 struct declaration_integer mantissa;
131 struct declaration_integer exp;
132
133 /*
134 * This is what the user sets and is never modified by internal
135 * code.
136 *
137 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
138 */
139 enum bt_ctf_byte_order user_byte_order;
140 };
141
142 struct structure_field {
143 GQuark name;
144 struct bt_ctf_field_type *type;
145 };
146
147 struct bt_ctf_field_type_structure {
148 struct bt_ctf_field_type parent;
149 GHashTable *field_name_to_index;
150 GPtrArray *fields; /* Array of pointers to struct structure_field */
151 struct declaration_struct declaration;
152 };
153
154 struct bt_ctf_field_type_variant {
155 struct bt_ctf_field_type parent;
156 GString *tag_name;
157 struct bt_ctf_field_type_enumeration *tag;
158 struct bt_ctf_field_path *tag_path;
159 GHashTable *field_name_to_index;
160 GPtrArray *fields; /* Array of pointers to struct structure_field */
161 struct declaration_variant declaration;
162 };
163
164 struct bt_ctf_field_type_array {
165 struct bt_ctf_field_type parent;
166 struct bt_ctf_field_type *element_type;
167 unsigned int length; /* Number of elements */
168 struct declaration_array declaration;
169 };
170
171 struct bt_ctf_field_type_sequence {
172 struct bt_ctf_field_type parent;
173 struct bt_ctf_field_type *element_type;
174 GString *length_field_name;
175 struct bt_ctf_field_path *length_field_path;
176 struct declaration_sequence declaration;
177 };
178
179 struct bt_ctf_field_type_string {
180 struct bt_ctf_field_type parent;
181 struct declaration_string declaration;
182 };
183
184 BT_HIDDEN
185 void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type);
186
187 BT_HIDDEN
188 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed(
189 struct bt_ctf_field_type_variant *variant, int64_t tag_value);
190
191 BT_HIDDEN
192 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned(
193 struct bt_ctf_field_type_variant *variant, uint64_t tag_value);
194
195 BT_HIDDEN
196 int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type,
197 struct metadata_context *context);
198
199 BT_HIDDEN
200 int bt_ctf_field_type_validate(struct bt_ctf_field_type *type);
201
202 BT_HIDDEN
203 const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
204 struct bt_ctf_field_type_enumeration *enumeration_type,
205 uint64_t value);
206
207 BT_HIDDEN
208 const char *bt_ctf_field_type_enumeration_get_mapping_name_signed(
209 struct bt_ctf_field_type_enumeration *enumeration_type,
210 int64_t value);
211
212 /* Override field type's byte order only if it is set to "native" */
213 BT_HIDDEN
214 void bt_ctf_field_type_set_native_byte_order(
215 struct bt_ctf_field_type *type, int byte_order);
216
217 /* Deep copy a field type */
218 BT_HIDDEN
219 struct bt_ctf_field_type *bt_ctf_field_type_copy(
220 struct bt_ctf_field_type *type);
221
222 BT_HIDDEN
223 struct bt_ctf_field_path *bt_ctf_field_path_create(void);
224
225 BT_HIDDEN
226 void bt_ctf_field_path_clear(struct bt_ctf_field_path *field_path);
227
228 BT_HIDDEN
229 struct bt_ctf_field_path *bt_ctf_field_path_copy(
230 struct bt_ctf_field_path *path);
231
232 BT_HIDDEN
233 void bt_ctf_field_path_destroy(struct bt_ctf_field_path *path);
234
235 BT_HIDDEN
236 int bt_ctf_field_type_structure_get_field_name_index(
237 struct bt_ctf_field_type *structure, const char *name);
238
239 /* Replace an existing field's type in a structure */
240 BT_HIDDEN
241 int bt_ctf_field_type_structure_set_field_index(
242 struct bt_ctf_field_type *structure,
243 struct bt_ctf_field_type *field, int index);
244
245 BT_HIDDEN
246 int bt_ctf_field_type_variant_get_field_name_index(
247 struct bt_ctf_field_type *variant, const char *name);
248
249 BT_HIDDEN
250 int bt_ctf_field_type_sequence_set_length_field_path(
251 struct bt_ctf_field_type *type,
252 struct bt_ctf_field_path *path);
253
254 BT_HIDDEN
255 struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path(
256 struct bt_ctf_field_type *type);
257
258 BT_HIDDEN
259 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type,
260 struct bt_ctf_field_path *path);
261
262 BT_HIDDEN
263 struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path(
264 struct bt_ctf_field_type *type);
265
266 BT_HIDDEN
267 int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type,
268 struct bt_ctf_field_type *tag);
269
270 /* Replace an existing field's type in a variant */
271 BT_HIDDEN
272 int bt_ctf_field_type_variant_set_field_index(
273 struct bt_ctf_field_type *variant,
274 struct bt_ctf_field_type *field, int index);
275
276 BT_HIDDEN
277 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array,
278 struct bt_ctf_field_type *element_type);
279
280 BT_HIDDEN
281 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array,
282 struct bt_ctf_field_type *element_type);
283
284 BT_HIDDEN
285 int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type);
286
287 BT_HIDDEN
288 struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index(
289 struct bt_ctf_field_type *type, int index);
290
291 BT_HIDDEN
292 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type,
293 const char *name);
294
295 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */
This page took 0.035693 seconds and 4 git commands to generate.