Add internal BT_ASSERT() and BT_ASSERT_PRE() helpers
[babeltrace.git] / include / babeltrace / ctf-ir / field-types-internal.h
CommitLineData
2e33ac5a
PP
1#ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
2#define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
273b65be
JG
3
4/*
2e33ac5a 5 * BabelTrace - CTF IR: Event field types internal
273b65be 6 *
de9dd397 7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
JG
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
544d0515 30#include <stdint.h>
273b65be 31#include <babeltrace/ctf-writer/event-types.h>
273b65be
JG
32#include <babeltrace/ctf-writer/event-fields.h>
33#include <babeltrace/ctf-writer/writer.h>
bc37ae52 34#include <babeltrace/ctf-ir/trace-internal.h>
ac0c6bdd 35#include <babeltrace/ctf-ir/clock-class.h>
4e8304f7 36#include <babeltrace/ctf-ir/field-types.h>
273b65be 37#include <babeltrace/babeltrace-internal.h>
83509119 38#include <babeltrace/object-internal.h>
c55a9f58 39#include <babeltrace/types.h>
273b65be
JG
40#include <glib.h>
41
50842bdc
PP
42typedef void (*type_freeze_func)(struct bt_field_type *);
43typedef int (*type_serialize_func)(struct bt_field_type *,
273b65be
JG
44 struct metadata_context *);
45
50842bdc 46struct bt_field_type {
83509119 47 struct bt_object base;
50842bdc 48 enum bt_field_type_id id;
dc3fffef 49 unsigned int alignment;
273b65be
JG
50 type_freeze_func freeze;
51 type_serialize_func serialize;
52 /*
53 * A type can't be modified once it is added to an event or after a
54 * a field has been instanciated from it.
55 */
56 int frozen;
81e36fac
PP
57
58 /*
59 * This flag indicates if the field type is valid. A valid
60 * field type is _always_ frozen. All the nested field types of
61 * a valid field type are also valid (and thus frozen).
62 */
63 int valid;
273b65be
JG
64};
65
50842bdc
PP
66struct bt_field_type_integer {
67 struct bt_field_type parent;
68 struct bt_clock_class *mapped_clock;
69 enum bt_byte_order user_byte_order;
c55a9f58 70 bt_bool is_signed;
dc3fffef 71 unsigned int size;
50842bdc
PP
72 enum bt_integer_base base;
73 enum bt_string_encoding encoding;
273b65be
JG
74};
75
76struct enumeration_mapping {
b92ddaaa
JG
77 union {
78 uint64_t _unsigned;
79 int64_t _signed;
80 } range_start;
81
82 union {
83 uint64_t _unsigned;
84 int64_t _signed;
85 } range_end;
273b65be
JG
86 GQuark string;
87};
88
50842bdc
PP
89struct bt_field_type_enumeration {
90 struct bt_field_type parent;
91 struct bt_field_type *container;
db8ef253 92 GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */
d49e1284 93 /* Only set during validation. */
c55a9f58 94 bt_bool has_overlapping_ranges;
96e8f959
MD
95};
96
50842bdc 97enum bt_field_type_enumeration_mapping_iterator_type {
96e8f959
MD
98 ITERATOR_BY_NAME,
99 ITERATOR_BY_SIGNED_VALUE,
100 ITERATOR_BY_UNSIGNED_VALUE,
101};
102
50842bdc 103struct bt_field_type_enumeration_mapping_iterator {
96e8f959 104 struct bt_object base;
50842bdc
PP
105 struct bt_field_type_enumeration *enumeration_type;
106 enum bt_field_type_enumeration_mapping_iterator_type type;
96e8f959
MD
107 int index;
108 union {
109 GQuark name_quark;
110 int64_t signed_value;
111 uint64_t unsigned_value;
112 } u;
273b65be
JG
113};
114
50842bdc
PP
115struct bt_field_type_floating_point {
116 struct bt_field_type parent;
117 enum bt_byte_order user_byte_order;
dc3fffef
PP
118 unsigned int exp_dig;
119 unsigned int mant_dig;
273b65be
JG
120};
121
122struct structure_field {
123 GQuark name;
50842bdc 124 struct bt_field_type *type;
273b65be
JG
125};
126
50842bdc
PP
127struct bt_field_type_structure {
128 struct bt_field_type parent;
273b65be
JG
129 GHashTable *field_name_to_index;
130 GPtrArray *fields; /* Array of pointers to struct structure_field */
273b65be
JG
131};
132
50842bdc
PP
133struct bt_field_type_variant {
134 struct bt_field_type parent;
273b65be 135 GString *tag_name;
50842bdc
PP
136 struct bt_field_type_enumeration *tag;
137 struct bt_field_path *tag_field_path;
273b65be
JG
138 GHashTable *field_name_to_index;
139 GPtrArray *fields; /* Array of pointers to struct structure_field */
273b65be
JG
140};
141
50842bdc
PP
142struct bt_field_type_array {
143 struct bt_field_type parent;
144 struct bt_field_type *element_type;
273b65be 145 unsigned int length; /* Number of elements */
273b65be
JG
146};
147
50842bdc
PP
148struct bt_field_type_sequence {
149 struct bt_field_type parent;
150 struct bt_field_type *element_type;
273b65be 151 GString *length_field_name;
50842bdc 152 struct bt_field_path *length_field_path;
273b65be
JG
153};
154
50842bdc
PP
155struct bt_field_type_string {
156 struct bt_field_type parent;
157 enum bt_string_encoding encoding;
273b65be
JG
158};
159
160BT_HIDDEN
50842bdc 161void bt_field_type_freeze(struct bt_field_type *type);
273b65be
JG
162
163BT_HIDDEN
50842bdc
PP
164struct bt_field_type *bt_field_type_variant_get_field_type_signed(
165 struct bt_field_type_variant *variant, int64_t tag_value);
273b65be
JG
166
167BT_HIDDEN
50842bdc
PP
168struct bt_field_type *bt_field_type_variant_get_field_type_unsigned(
169 struct bt_field_type_variant *variant, uint64_t tag_value);
273b65be
JG
170
171BT_HIDDEN
50842bdc 172int bt_field_type_serialize(struct bt_field_type *type,
273b65be
JG
173 struct metadata_context *context);
174
9ce21c30 175BT_HIDDEN
50842bdc 176int bt_field_type_validate(struct bt_field_type *type);
9ce21c30 177
39a5e0db 178BT_HIDDEN
50842bdc
PP
179int bt_field_type_structure_get_field_name_index(
180 struct bt_field_type *structure, const char *name);
736133f1
JG
181
182BT_HIDDEN
79422a2b
PP
183int bt_field_type_structure_replace_field(struct bt_field_type *type,
184 const char *field_name, struct bt_field_type *field_type);
185
186BT_HIDDEN
50842bdc
PP
187int bt_field_type_variant_get_field_name_index(
188 struct bt_field_type *variant, const char *name);
aa4e271c
JG
189
190BT_HIDDEN
50842bdc
PP
191int bt_field_type_sequence_set_length_field_path(
192 struct bt_field_type *type,
193 struct bt_field_path *path);
4a1e8671
JG
194
195BT_HIDDEN
50842bdc
PP
196int bt_field_type_variant_set_tag_field_path(struct bt_field_type *type,
197 struct bt_field_path *path);
3f39933a
JG
198
199BT_HIDDEN
50842bdc
PP
200int bt_field_type_variant_set_tag_field_type(struct bt_field_type *type,
201 struct bt_field_type *tag_type);
3f39933a 202
626e93aa 203BT_HIDDEN
50842bdc
PP
204int bt_field_type_array_set_element_type(struct bt_field_type *array,
205 struct bt_field_type *element_type);
626e93aa
PP
206
207BT_HIDDEN
50842bdc
PP
208int bt_field_type_sequence_set_element_type(struct bt_field_type *array,
209 struct bt_field_type *element_type);
626e93aa 210
09840de5 211BT_HIDDEN
50842bdc 212int64_t bt_field_type_get_field_count(struct bt_field_type *type);
09840de5
PP
213
214BT_HIDDEN
50842bdc
PP
215struct bt_field_type *bt_field_type_get_field_at_index(
216 struct bt_field_type *type, int index);
09840de5
PP
217
218BT_HIDDEN
50842bdc 219int bt_field_type_get_field_index(struct bt_field_type *type,
09840de5
PP
220 const char *name);
221
e011d2c1 222BT_HIDDEN
50842bdc
PP
223int bt_field_type_integer_set_mapped_clock_class_no_check(
224 struct bt_field_type *int_field_type,
225 struct bt_clock_class *clock_class);
e011d2c1 226
b7a73f0f 227static inline
50842bdc 228const char *bt_field_type_id_string(enum bt_field_type_id type_id)
b7a73f0f
PP
229{
230 switch (type_id) {
50842bdc
PP
231 case BT_FIELD_TYPE_ID_UNKNOWN:
232 return "BT_FIELD_TYPE_ID_UNKNOWN";
233 case BT_FIELD_TYPE_ID_INTEGER:
234 return "BT_FIELD_TYPE_ID_INTEGER";
235 case BT_FIELD_TYPE_ID_FLOAT:
236 return "BT_FIELD_TYPE_ID_FLOAT";
237 case BT_FIELD_TYPE_ID_ENUM:
238 return "BT_FIELD_TYPE_ID_ENUM";
239 case BT_FIELD_TYPE_ID_STRING:
240 return "BT_FIELD_TYPE_ID_STRING";
241 case BT_FIELD_TYPE_ID_STRUCT:
242 return "BT_FIELD_TYPE_ID_STRUCT";
243 case BT_FIELD_TYPE_ID_ARRAY:
244 return "BT_FIELD_TYPE_ID_ARRAY";
245 case BT_FIELD_TYPE_ID_SEQUENCE:
246 return "BT_FIELD_TYPE_ID_SEQUENCE";
247 case BT_FIELD_TYPE_ID_VARIANT:
248 return "BT_FIELD_TYPE_ID_VARIANT";
b7a73f0f
PP
249 default:
250 return "(unknown)";
251 }
252};
253
254static inline
50842bdc 255const char *bt_byte_order_string(enum bt_byte_order bo)
b7a73f0f
PP
256{
257 switch (bo) {
50842bdc
PP
258 case BT_BYTE_ORDER_UNKNOWN:
259 return "BT_BYTE_ORDER_UNKNOWN";
260 case BT_BYTE_ORDER_UNSPECIFIED:
261 return "BT_BYTE_ORDER_UNSPECIFIED";
262 case BT_BYTE_ORDER_NATIVE:
263 return "BT_BYTE_ORDER_NATIVE";
264 case BT_BYTE_ORDER_LITTLE_ENDIAN:
265 return "BT_BYTE_ORDER_LITTLE_ENDIAN";
266 case BT_BYTE_ORDER_BIG_ENDIAN:
267 return "BT_BYTE_ORDER_BIG_ENDIAN";
268 case BT_BYTE_ORDER_NETWORK:
269 return "BT_BYTE_ORDER_NETWORK";
b7a73f0f
PP
270 default:
271 return "(unknown)";
272 }
273};
274
4e8304f7 275static inline
50842bdc 276const char *bt_string_encoding_string(enum bt_string_encoding encoding)
4e8304f7
PP
277{
278 switch (encoding) {
50842bdc
PP
279 case BT_STRING_ENCODING_UNKNOWN:
280 return "BT_STRING_ENCODING_UNKNOWN";
281 case BT_STRING_ENCODING_NONE:
282 return "BT_STRING_ENCODING_NONE";
283 case BT_STRING_ENCODING_UTF8:
284 return "BT_STRING_ENCODING_UTF8";
285 case BT_STRING_ENCODING_ASCII:
286 return "BT_STRING_ENCODING_ASCII";
4e8304f7
PP
287 default:
288 return "(unknown)";
289 }
290};
291
292static inline
50842bdc 293const char *bt_integer_base_string(enum bt_integer_base base)
4e8304f7
PP
294{
295 switch (base) {
50842bdc
PP
296 case BT_INTEGER_BASE_UNKNOWN:
297 return "BT_INTEGER_BASE_UNKNOWN";
298 case BT_INTEGER_BASE_UNSPECIFIED:
299 return "BT_INTEGER_BASE_UNSPECIFIED";
300 case BT_INTEGER_BASE_BINARY:
301 return "BT_INTEGER_BASE_BINARY";
302 case BT_INTEGER_BASE_OCTAL:
303 return "BT_INTEGER_BASE_OCTAL";
304 case BT_INTEGER_BASE_DECIMAL:
305 return "BT_INTEGER_BASE_DECIMAL";
306 case BT_INTEGER_BASE_HEXADECIMAL:
307 return "BT_INTEGER_BASE_HEXADECIMAL";
4e8304f7
PP
308 default:
309 return "(unknown)";
310 }
311}
312
313static inline
50842bdc 314const char *bt_scope_string(enum bt_scope scope)
4e8304f7
PP
315{
316 switch (scope) {
50842bdc
PP
317 case BT_SCOPE_UNKNOWN:
318 return "BT_SCOPE_UNKNOWN";
319 case BT_SCOPE_TRACE_PACKET_HEADER:
320 return "BT_SCOPE_TRACE_PACKET_HEADER";
321 case BT_SCOPE_STREAM_PACKET_CONTEXT:
322 return "BT_SCOPE_STREAM_PACKET_CONTEXT";
323 case BT_SCOPE_STREAM_EVENT_HEADER:
324 return "BT_SCOPE_STREAM_EVENT_HEADER";
325 case BT_SCOPE_STREAM_EVENT_CONTEXT:
326 return "BT_SCOPE_STREAM_EVENT_CONTEXT";
327 case BT_SCOPE_EVENT_CONTEXT:
328 return "BT_SCOPE_EVENT_CONTEXT";
329 case BT_SCOPE_EVENT_PAYLOAD:
330 return "BT_SCOPE_EVENT_PAYLOAD";
331 case BT_SCOPE_ENV:
332 return "BT_SCOPE_ENV";
4e8304f7
PP
333 default:
334 return "(unknown)";
335 }
336}
337
2e33ac5a 338#endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */
This page took 0.062857 seconds and 4 git commands to generate.