Commit | Line | Data |
---|---|---|
adc315b8 JG |
1 | #ifndef BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H |
2 | #define BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H | |
273b65be JG |
3 | |
4 | /* | |
adc315b8 | 5 | * BabelTrace - CTF IR: Event 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 | ||
30 | #include <babeltrace/ctf-writer/event-types.h> | |
273b65be JG |
31 | #include <babeltrace/ctf-writer/event-fields.h> |
32 | #include <babeltrace/ctf-writer/writer.h> | |
bc37ae52 | 33 | #include <babeltrace/ctf-ir/trace-internal.h> |
273b65be | 34 | #include <babeltrace/babeltrace-internal.h> |
83509119 | 35 | #include <babeltrace/object-internal.h> |
273b65be JG |
36 | #include <babeltrace/types.h> |
37 | #include <babeltrace/ctf/events.h> | |
38 | #include <glib.h> | |
39 | ||
b75277fb JG |
40 | typedef void (*type_freeze_func)(struct bt_ctf_field_type *); |
41 | typedef int (*type_serialize_func)(struct bt_ctf_field_type *, | |
273b65be JG |
42 | struct metadata_context *); |
43 | ||
6b64f185 JG |
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 | ||
273b65be | 64 | struct bt_ctf_field_type { |
83509119 | 65 | struct bt_object base; |
273b65be JG |
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; | |
81e36fac PP |
74 | |
75 | /* | |
76 | * This flag indicates if the field type is valid. A valid | |
77 | * field type is _always_ frozen. All the nested field types of | |
78 | * a valid field type are also valid (and thus frozen). | |
79 | */ | |
80 | int valid; | |
273b65be JG |
81 | }; |
82 | ||
83 | struct bt_ctf_field_type_integer { | |
84 | struct bt_ctf_field_type parent; | |
85 | struct declaration_integer declaration; | |
6cfb906f | 86 | struct bt_ctf_clock *mapped_clock; |
445c3471 PP |
87 | |
88 | /* | |
89 | * This is what the user sets and is never modified by internal | |
90 | * code. | |
91 | * | |
92 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. | |
93 | */ | |
94 | enum bt_ctf_byte_order user_byte_order; | |
273b65be JG |
95 | }; |
96 | ||
97 | struct enumeration_mapping { | |
b92ddaaa JG |
98 | union { |
99 | uint64_t _unsigned; | |
100 | int64_t _signed; | |
101 | } range_start; | |
102 | ||
103 | union { | |
104 | uint64_t _unsigned; | |
105 | int64_t _signed; | |
106 | } range_end; | |
273b65be JG |
107 | GQuark string; |
108 | }; | |
109 | ||
110 | struct bt_ctf_field_type_enumeration { | |
111 | struct bt_ctf_field_type parent; | |
112 | struct bt_ctf_field_type *container; | |
db8ef253 | 113 | GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */ |
273b65be JG |
114 | struct declaration_enum declaration; |
115 | }; | |
116 | ||
117 | struct bt_ctf_field_type_floating_point { | |
118 | struct bt_ctf_field_type parent; | |
119 | struct declaration_float declaration; | |
d480b699 PP |
120 | |
121 | /* | |
122 | * The `declaration` field above contains 3 pointers pointing | |
123 | * to the fields below. This avoids unnecessary dynamic | |
124 | * allocations. | |
125 | */ | |
273b65be JG |
126 | struct declaration_integer sign; |
127 | struct declaration_integer mantissa; | |
128 | struct declaration_integer exp; | |
445c3471 PP |
129 | |
130 | /* | |
131 | * This is what the user sets and is never modified by internal | |
132 | * code. | |
133 | * | |
134 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. | |
135 | */ | |
136 | enum bt_ctf_byte_order user_byte_order; | |
273b65be JG |
137 | }; |
138 | ||
139 | struct structure_field { | |
140 | GQuark name; | |
141 | struct bt_ctf_field_type *type; | |
142 | }; | |
143 | ||
144 | struct bt_ctf_field_type_structure { | |
145 | struct bt_ctf_field_type parent; | |
146 | GHashTable *field_name_to_index; | |
147 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
24724933 | 148 | struct declaration_struct declaration; |
273b65be JG |
149 | }; |
150 | ||
151 | struct bt_ctf_field_type_variant { | |
152 | struct bt_ctf_field_type parent; | |
153 | GString *tag_name; | |
154 | struct bt_ctf_field_type_enumeration *tag; | |
4a1e8671 | 155 | struct bt_ctf_field_path *tag_path; |
273b65be JG |
156 | GHashTable *field_name_to_index; |
157 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
158 | struct declaration_variant declaration; | |
159 | }; | |
160 | ||
161 | struct bt_ctf_field_type_array { | |
162 | struct bt_ctf_field_type parent; | |
163 | struct bt_ctf_field_type *element_type; | |
164 | unsigned int length; /* Number of elements */ | |
165 | struct declaration_array declaration; | |
166 | }; | |
167 | ||
168 | struct bt_ctf_field_type_sequence { | |
169 | struct bt_ctf_field_type parent; | |
170 | struct bt_ctf_field_type *element_type; | |
171 | GString *length_field_name; | |
aa4e271c | 172 | struct bt_ctf_field_path *length_field_path; |
273b65be JG |
173 | struct declaration_sequence declaration; |
174 | }; | |
175 | ||
176 | struct bt_ctf_field_type_string { | |
177 | struct bt_ctf_field_type parent; | |
178 | struct declaration_string declaration; | |
179 | }; | |
180 | ||
181 | BT_HIDDEN | |
182 | void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); | |
183 | ||
184 | BT_HIDDEN | |
b92ddaaa JG |
185 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( |
186 | struct bt_ctf_field_type_variant *variant, int64_t tag_value); | |
273b65be JG |
187 | |
188 | BT_HIDDEN | |
b92ddaaa JG |
189 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( |
190 | struct bt_ctf_field_type_variant *variant, uint64_t tag_value); | |
273b65be JG |
191 | |
192 | BT_HIDDEN | |
193 | int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, | |
194 | struct metadata_context *context); | |
195 | ||
9ce21c30 JG |
196 | BT_HIDDEN |
197 | int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); | |
198 | ||
e5958c30 JG |
199 | BT_HIDDEN |
200 | const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned( | |
201 | struct bt_ctf_field_type_enumeration *enumeration_type, | |
202 | uint64_t value); | |
203 | ||
204 | BT_HIDDEN | |
205 | const char *bt_ctf_field_type_enumeration_get_mapping_name_signed( | |
206 | struct bt_ctf_field_type_enumeration *enumeration_type, | |
207 | int64_t value); | |
208 | ||
c35a1669 JG |
209 | /* Override field type's byte order only if it is set to "native" */ |
210 | BT_HIDDEN | |
211 | void bt_ctf_field_type_set_native_byte_order( | |
212 | struct bt_ctf_field_type *type, int byte_order); | |
24724933 JG |
213 | |
214 | /* Deep copy a field type */ | |
215 | BT_HIDDEN | |
216 | struct bt_ctf_field_type *bt_ctf_field_type_copy( | |
217 | struct bt_ctf_field_type *type); | |
218 | ||
6b64f185 JG |
219 | BT_HIDDEN |
220 | struct bt_ctf_field_path *bt_ctf_field_path_create(void); | |
221 | ||
7073124e PP |
222 | BT_HIDDEN |
223 | void bt_ctf_field_path_clear(struct bt_ctf_field_path *field_path); | |
224 | ||
6b64f185 JG |
225 | BT_HIDDEN |
226 | struct bt_ctf_field_path *bt_ctf_field_path_copy( | |
227 | struct bt_ctf_field_path *path); | |
228 | ||
229 | BT_HIDDEN | |
230 | void bt_ctf_field_path_destroy(struct bt_ctf_field_path *path); | |
39a5e0db JG |
231 | |
232 | BT_HIDDEN | |
233 | int bt_ctf_field_type_structure_get_field_name_index( | |
234 | struct bt_ctf_field_type *structure, const char *name); | |
736133f1 | 235 | |
5cec03e4 JG |
236 | /* Replace an existing field's type in a structure */ |
237 | BT_HIDDEN | |
238 | int bt_ctf_field_type_structure_set_field_index( | |
239 | struct bt_ctf_field_type *structure, | |
240 | struct bt_ctf_field_type *field, int index); | |
241 | ||
736133f1 JG |
242 | BT_HIDDEN |
243 | int bt_ctf_field_type_variant_get_field_name_index( | |
244 | struct bt_ctf_field_type *variant, const char *name); | |
aa4e271c JG |
245 | |
246 | BT_HIDDEN | |
247 | int bt_ctf_field_type_sequence_set_length_field_path( | |
248 | struct bt_ctf_field_type *type, | |
249 | struct bt_ctf_field_path *path); | |
4a1e8671 | 250 | |
32fe3f28 PP |
251 | BT_HIDDEN |
252 | struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path( | |
253 | struct bt_ctf_field_type *type); | |
254 | ||
4a1e8671 JG |
255 | BT_HIDDEN |
256 | int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, | |
257 | struct bt_ctf_field_path *path); | |
3f39933a | 258 | |
32fe3f28 PP |
259 | BT_HIDDEN |
260 | struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path( | |
261 | struct bt_ctf_field_type *type); | |
262 | ||
3f39933a JG |
263 | BT_HIDDEN |
264 | int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type, | |
265 | struct bt_ctf_field_type *tag); | |
266 | ||
5cec03e4 JG |
267 | /* Replace an existing field's type in a variant */ |
268 | BT_HIDDEN | |
269 | int bt_ctf_field_type_variant_set_field_index( | |
270 | struct bt_ctf_field_type *variant, | |
271 | struct bt_ctf_field_type *field, int index); | |
272 | ||
626e93aa PP |
273 | BT_HIDDEN |
274 | int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, | |
275 | struct bt_ctf_field_type *element_type); | |
276 | ||
277 | BT_HIDDEN | |
278 | int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, | |
279 | struct bt_ctf_field_type *element_type); | |
280 | ||
adc315b8 | 281 | #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */ |