lib/ctf-ir/field-types.c: add logging
[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
b75277fb
JG
42typedef void (*type_freeze_func)(struct bt_ctf_field_type *);
43typedef int (*type_serialize_func)(struct bt_ctf_field_type *,
273b65be
JG
44 struct metadata_context *);
45
46struct bt_ctf_field_type {
83509119 47 struct bt_object base;
1487a16a 48 enum bt_ctf_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
66struct bt_ctf_field_type_integer {
67 struct bt_ctf_field_type parent;
ac0c6bdd 68 struct bt_ctf_clock_class *mapped_clock;
445c3471 69 enum bt_ctf_byte_order user_byte_order;
c55a9f58 70 bt_bool is_signed;
dc3fffef
PP
71 unsigned int size;
72 enum bt_ctf_integer_base base;
73 enum bt_ctf_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
89struct bt_ctf_field_type_enumeration {
90 struct bt_ctf_field_type parent;
91 struct bt_ctf_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
d49e1284 97enum bt_ctf_field_type_enumeration_mapping_iterator_type {
96e8f959
MD
98 ITERATOR_BY_NAME,
99 ITERATOR_BY_SIGNED_VALUE,
100 ITERATOR_BY_UNSIGNED_VALUE,
101};
102
103struct bt_ctf_field_type_enumeration_mapping_iterator {
104 struct bt_object base;
105 struct bt_ctf_field_type_enumeration *enumeration_type;
d49e1284 106 enum bt_ctf_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
115struct bt_ctf_field_type_floating_point {
116 struct bt_ctf_field_type parent;
445c3471 117 enum bt_ctf_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;
124 struct bt_ctf_field_type *type;
125};
126
127struct bt_ctf_field_type_structure {
128 struct bt_ctf_field_type parent;
129 GHashTable *field_name_to_index;
130 GPtrArray *fields; /* Array of pointers to struct structure_field */
273b65be
JG
131};
132
133struct bt_ctf_field_type_variant {
134 struct bt_ctf_field_type parent;
135 GString *tag_name;
136 struct bt_ctf_field_type_enumeration *tag;
b011f6b0 137 struct bt_ctf_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
142struct bt_ctf_field_type_array {
143 struct bt_ctf_field_type parent;
144 struct bt_ctf_field_type *element_type;
145 unsigned int length; /* Number of elements */
273b65be
JG
146};
147
148struct bt_ctf_field_type_sequence {
149 struct bt_ctf_field_type parent;
150 struct bt_ctf_field_type *element_type;
151 GString *length_field_name;
aa4e271c 152 struct bt_ctf_field_path *length_field_path;
273b65be
JG
153};
154
155struct bt_ctf_field_type_string {
156 struct bt_ctf_field_type parent;
dc3fffef 157 enum bt_ctf_string_encoding encoding;
273b65be
JG
158};
159
160BT_HIDDEN
161void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type);
162
163BT_HIDDEN
b92ddaaa
JG
164struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed(
165 struct bt_ctf_field_type_variant *variant, int64_t tag_value);
273b65be
JG
166
167BT_HIDDEN
b92ddaaa
JG
168struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned(
169 struct bt_ctf_field_type_variant *variant, uint64_t tag_value);
273b65be
JG
170
171BT_HIDDEN
172int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type,
173 struct metadata_context *context);
174
9ce21c30
JG
175BT_HIDDEN
176int bt_ctf_field_type_validate(struct bt_ctf_field_type *type);
177
39a5e0db
JG
178BT_HIDDEN
179int bt_ctf_field_type_structure_get_field_name_index(
180 struct bt_ctf_field_type *structure, const char *name);
736133f1 181
5cec03e4
JG
182/* Replace an existing field's type in a structure */
183BT_HIDDEN
184int bt_ctf_field_type_structure_set_field_index(
185 struct bt_ctf_field_type *structure,
186 struct bt_ctf_field_type *field, int index);
187
736133f1
JG
188BT_HIDDEN
189int bt_ctf_field_type_variant_get_field_name_index(
190 struct bt_ctf_field_type *variant, const char *name);
aa4e271c
JG
191
192BT_HIDDEN
193int bt_ctf_field_type_sequence_set_length_field_path(
194 struct bt_ctf_field_type *type,
195 struct bt_ctf_field_path *path);
4a1e8671
JG
196
197BT_HIDDEN
198int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type,
199 struct bt_ctf_field_path *path);
3f39933a
JG
200
201BT_HIDDEN
4b5fcb78
PP
202int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type,
203 struct bt_ctf_field_type *tag_type);
3f39933a 204
626e93aa
PP
205BT_HIDDEN
206int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array,
207 struct bt_ctf_field_type *element_type);
208
209BT_HIDDEN
210int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array,
211 struct bt_ctf_field_type *element_type);
212
09840de5 213BT_HIDDEN
544d0515 214int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type);
09840de5
PP
215
216BT_HIDDEN
217struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index(
218 struct bt_ctf_field_type *type, int index);
219
220BT_HIDDEN
221int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type,
222 const char *name);
223
b7a73f0f
PP
224static inline
225const char *bt_ctf_field_type_id_string(enum bt_ctf_field_type_id type_id)
226{
227 switch (type_id) {
228 case BT_CTF_FIELD_TYPE_ID_UNKNOWN:
229 return "BT_CTF_FIELD_TYPE_ID_UNKNOWN";
230 case BT_CTF_FIELD_TYPE_ID_INTEGER:
231 return "BT_CTF_FIELD_TYPE_ID_INTEGER";
232 case BT_CTF_FIELD_TYPE_ID_FLOAT:
233 return "BT_CTF_FIELD_TYPE_ID_FLOAT";
234 case BT_CTF_FIELD_TYPE_ID_ENUM:
235 return "BT_CTF_FIELD_TYPE_ID_ENUM";
236 case BT_CTF_FIELD_TYPE_ID_STRING:
237 return "BT_CTF_FIELD_TYPE_ID_STRING";
238 case BT_CTF_FIELD_TYPE_ID_STRUCT:
239 return "BT_CTF_FIELD_TYPE_ID_STRUCT";
240 case BT_CTF_FIELD_TYPE_ID_ARRAY:
241 return "BT_CTF_FIELD_TYPE_ID_ARRAY";
242 case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
243 return "BT_CTF_FIELD_TYPE_ID_SEQUENCE";
244 case BT_CTF_FIELD_TYPE_ID_VARIANT:
245 return "BT_CTF_FIELD_TYPE_ID_VARIANT";
246 default:
247 return "(unknown)";
248 }
249};
250
251static inline
4e8304f7 252const char *bt_ctf_byte_order_string(enum bt_ctf_byte_order bo)
b7a73f0f
PP
253{
254 switch (bo) {
255 case BT_CTF_BYTE_ORDER_UNKNOWN:
256 return "BT_CTF_BYTE_ORDER_UNKNOWN";
257 case BT_CTF_BYTE_ORDER_NATIVE:
258 return "BT_CTF_BYTE_ORDER_NATIVE";
259 case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
260 return "BT_CTF_BYTE_ORDER_LITTLE_ENDIAN";
261 case BT_CTF_BYTE_ORDER_BIG_ENDIAN:
262 return "BT_CTF_BYTE_ORDER_BIG_ENDIAN";
263 case BT_CTF_BYTE_ORDER_NETWORK:
264 return "BT_CTF_BYTE_ORDER_NETWORK";
265 default:
266 return "(unknown)";
267 }
268};
269
4e8304f7
PP
270static inline
271const char *bt_ctf_string_encoding_string(enum bt_ctf_string_encoding encoding)
272{
273 switch (encoding) {
274 case BT_CTF_STRING_ENCODING_UNKNOWN:
275 return "BT_CTF_STRING_ENCODING_UNKNOWN";
276 case BT_CTF_STRING_ENCODING_NONE:
277 return "BT_CTF_STRING_ENCODING_NONE";
278 case BT_CTF_STRING_ENCODING_UTF8:
279 return "BT_CTF_STRING_ENCODING_UTF8";
280 case BT_CTF_STRING_ENCODING_ASCII:
281 return "BT_CTF_STRING_ENCODING_ASCII";
282 default:
283 return "(unknown)";
284 }
285};
286
287static inline
288const char *bt_ctf_integer_base_string(enum bt_ctf_integer_base base)
289{
290 switch (base) {
291 case BT_CTF_INTEGER_BASE_UNKNOWN:
292 return "BT_CTF_INTEGER_BASE_UNKNOWN";
293 case BT_CTF_INTEGER_BASE_BINARY:
294 return "BT_CTF_INTEGER_BASE_BINARY";
295 case BT_CTF_INTEGER_BASE_OCTAL:
296 return "BT_CTF_INTEGER_BASE_OCTAL";
297 case BT_CTF_INTEGER_BASE_DECIMAL:
298 return "BT_CTF_INTEGER_BASE_DECIMAL";
299 case BT_CTF_INTEGER_BASE_HEXADECIMAL:
300 return "BT_CTF_INTEGER_BASE_HEXADECIMAL";
301 default:
302 return "(unknown)";
303 }
304}
305
306static inline
307const char *bt_ctf_scope_string(enum bt_ctf_scope scope)
308{
309 switch (scope) {
310 case BT_CTF_SCOPE_UNKNOWN:
311 return "BT_CTF_SCOPE_UNKNOWN";
312 case BT_CTF_SCOPE_TRACE_PACKET_HEADER:
313 return "BT_CTF_SCOPE_TRACE_PACKET_HEADER";
314 case BT_CTF_SCOPE_STREAM_PACKET_CONTEXT:
315 return "BT_CTF_SCOPE_STREAM_PACKET_CONTEXT";
316 case BT_CTF_SCOPE_STREAM_EVENT_HEADER:
317 return "BT_CTF_SCOPE_STREAM_EVENT_HEADER";
318 case BT_CTF_SCOPE_STREAM_EVENT_CONTEXT:
319 return "BT_CTF_SCOPE_STREAM_EVENT_CONTEXT";
320 case BT_CTF_SCOPE_EVENT_CONTEXT:
321 return "BT_CTF_SCOPE_EVENT_CONTEXT";
322 case BT_CTF_SCOPE_EVENT_PAYLOAD:
323 return "BT_CTF_SCOPE_EVENT_PAYLOAD";
324 case BT_CTF_SCOPE_ENV:
325 return "BT_CTF_SCOPE_ENV";
326 default:
327 return "(unknown)";
328 }
329}
330
2e33ac5a 331#endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */
This page took 0.051202 seconds and 4 git commands to generate.