ir: add user byte order to integer/float types
[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 * Array of integers (int) indicating the index in either
59 * structures or variants that make-up the path to a field.
60 */
61 GArray *path_indexes;
62 };
63
64 struct bt_ctf_field_type {
65 struct bt_object base;
66 struct bt_declaration *declaration;
67 type_freeze_func freeze;
68 type_serialize_func serialize;
69 /*
70 * A type can't be modified once it is added to an event or after a
71 * a field has been instanciated from it.
72 */
73 int frozen;
74 };
75
76 struct bt_ctf_field_type_integer {
77 struct bt_ctf_field_type parent;
78 struct declaration_integer declaration;
79 struct bt_ctf_clock *mapped_clock;
80
81 /*
82 * This is what the user sets and is never modified by internal
83 * code.
84 *
85 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
86 */
87 enum bt_ctf_byte_order user_byte_order;
88 };
89
90 struct enumeration_mapping {
91 union {
92 uint64_t _unsigned;
93 int64_t _signed;
94 } range_start;
95
96 union {
97 uint64_t _unsigned;
98 int64_t _signed;
99 } range_end;
100 GQuark string;
101 };
102
103 struct bt_ctf_field_type_enumeration {
104 struct bt_ctf_field_type parent;
105 struct bt_ctf_field_type *container;
106 GPtrArray *entries; /* Array of pointers to struct enum_mapping */
107 struct declaration_enum declaration;
108 };
109
110 struct bt_ctf_field_type_floating_point {
111 struct bt_ctf_field_type parent;
112 struct declaration_float declaration;
113 struct declaration_integer sign;
114 struct declaration_integer mantissa;
115 struct declaration_integer exp;
116
117 /*
118 * This is what the user sets and is never modified by internal
119 * code.
120 *
121 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
122 */
123 enum bt_ctf_byte_order user_byte_order;
124 };
125
126 struct structure_field {
127 GQuark name;
128 struct bt_ctf_field_type *type;
129 };
130
131 struct bt_ctf_field_type_structure {
132 struct bt_ctf_field_type parent;
133 GHashTable *field_name_to_index;
134 GPtrArray *fields; /* Array of pointers to struct structure_field */
135 struct declaration_struct declaration;
136 };
137
138 struct bt_ctf_field_type_variant {
139 struct bt_ctf_field_type parent;
140 GString *tag_name;
141 struct bt_ctf_field_type_enumeration *tag;
142 struct bt_ctf_field_path *tag_path;
143 GHashTable *field_name_to_index;
144 GPtrArray *fields; /* Array of pointers to struct structure_field */
145 struct declaration_variant declaration;
146 };
147
148 struct bt_ctf_field_type_array {
149 struct bt_ctf_field_type parent;
150 struct bt_ctf_field_type *element_type;
151 unsigned int length; /* Number of elements */
152 struct declaration_array declaration;
153 };
154
155 struct bt_ctf_field_type_sequence {
156 struct bt_ctf_field_type parent;
157 struct bt_ctf_field_type *element_type;
158 GString *length_field_name;
159 struct bt_ctf_field_path *length_field_path;
160 struct declaration_sequence declaration;
161 };
162
163 struct bt_ctf_field_type_string {
164 struct bt_ctf_field_type parent;
165 struct declaration_string declaration;
166 };
167
168 BT_HIDDEN
169 void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type);
170
171 BT_HIDDEN
172 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed(
173 struct bt_ctf_field_type_variant *variant, int64_t tag_value);
174
175 BT_HIDDEN
176 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned(
177 struct bt_ctf_field_type_variant *variant, uint64_t tag_value);
178
179 BT_HIDDEN
180 int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type,
181 struct metadata_context *context);
182
183 BT_HIDDEN
184 int bt_ctf_field_type_validate(struct bt_ctf_field_type *type);
185
186 BT_HIDDEN
187 const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
188 struct bt_ctf_field_type_enumeration *enumeration_type,
189 uint64_t value);
190
191 BT_HIDDEN
192 const char *bt_ctf_field_type_enumeration_get_mapping_name_signed(
193 struct bt_ctf_field_type_enumeration *enumeration_type,
194 int64_t value);
195
196 /* Override field type's byte order only if it is set to "native" */
197 BT_HIDDEN
198 void bt_ctf_field_type_set_native_byte_order(
199 struct bt_ctf_field_type *type, int byte_order);
200
201 /* Deep copy a field type */
202 BT_HIDDEN
203 struct bt_ctf_field_type *bt_ctf_field_type_copy(
204 struct bt_ctf_field_type *type);
205
206 BT_HIDDEN
207 struct bt_ctf_field_path *bt_ctf_field_path_create(void);
208
209 BT_HIDDEN
210 struct bt_ctf_field_path *bt_ctf_field_path_copy(
211 struct bt_ctf_field_path *path);
212
213 BT_HIDDEN
214 void bt_ctf_field_path_destroy(struct bt_ctf_field_path *path);
215
216 BT_HIDDEN
217 int bt_ctf_field_type_structure_get_field_name_index(
218 struct bt_ctf_field_type *structure, const char *name);
219
220 /* Replace an existing field's type in a structure */
221 BT_HIDDEN
222 int bt_ctf_field_type_structure_set_field_index(
223 struct bt_ctf_field_type *structure,
224 struct bt_ctf_field_type *field, int index);
225
226 BT_HIDDEN
227 int bt_ctf_field_type_variant_get_field_name_index(
228 struct bt_ctf_field_type *variant, const char *name);
229
230 BT_HIDDEN
231 int bt_ctf_field_type_sequence_set_length_field_path(
232 struct bt_ctf_field_type *type,
233 struct bt_ctf_field_path *path);
234
235 BT_HIDDEN
236 struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path(
237 struct bt_ctf_field_type *type);
238
239 BT_HIDDEN
240 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type,
241 struct bt_ctf_field_path *path);
242
243 BT_HIDDEN
244 struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path(
245 struct bt_ctf_field_type *type);
246
247 BT_HIDDEN
248 int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type,
249 struct bt_ctf_field_type *tag);
250
251 /* Replace an existing field's type in a variant */
252 BT_HIDDEN
253 int bt_ctf_field_type_variant_set_field_index(
254 struct bt_ctf_field_type *variant,
255 struct bt_ctf_field_type *field, int index);
256
257 BT_HIDDEN
258 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array,
259 struct bt_ctf_field_type *element_type);
260
261 BT_HIDDEN
262 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array,
263 struct bt_ctf_field_type *element_type);
264
265 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */
This page took 0.035061 seconds and 4 git commands to generate.