Commit | Line | Data |
---|---|---|
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 | ||
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> |
ac0c6bdd | 34 | #include <babeltrace/ctf-ir/clock-class.h> |
273b65be | 35 | #include <babeltrace/babeltrace-internal.h> |
83509119 | 36 | #include <babeltrace/object-internal.h> |
273b65be JG |
37 | #include <babeltrace/types.h> |
38 | #include <babeltrace/ctf/events.h> | |
39 | #include <glib.h> | |
40 | ||
b75277fb JG |
41 | typedef void (*type_freeze_func)(struct bt_ctf_field_type *); |
42 | typedef int (*type_serialize_func)(struct bt_ctf_field_type *, | |
273b65be JG |
43 | struct metadata_context *); |
44 | ||
45 | struct bt_ctf_field_type { | |
83509119 | 46 | struct bt_object base; |
273b65be JG |
47 | struct bt_declaration *declaration; |
48 | type_freeze_func freeze; | |
49 | type_serialize_func serialize; | |
50 | /* | |
51 | * A type can't be modified once it is added to an event or after a | |
52 | * a field has been instanciated from it. | |
53 | */ | |
54 | int frozen; | |
81e36fac PP |
55 | |
56 | /* | |
57 | * This flag indicates if the field type is valid. A valid | |
58 | * field type is _always_ frozen. All the nested field types of | |
59 | * a valid field type are also valid (and thus frozen). | |
60 | */ | |
61 | int valid; | |
273b65be JG |
62 | }; |
63 | ||
64 | struct bt_ctf_field_type_integer { | |
65 | struct bt_ctf_field_type parent; | |
66 | struct declaration_integer declaration; | |
ac0c6bdd | 67 | struct bt_ctf_clock_class *mapped_clock; |
445c3471 PP |
68 | |
69 | /* | |
70 | * This is what the user sets and is never modified by internal | |
71 | * code. | |
72 | * | |
73 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. | |
74 | */ | |
75 | enum bt_ctf_byte_order user_byte_order; | |
273b65be JG |
76 | }; |
77 | ||
78 | struct enumeration_mapping { | |
b92ddaaa JG |
79 | union { |
80 | uint64_t _unsigned; | |
81 | int64_t _signed; | |
82 | } range_start; | |
83 | ||
84 | union { | |
85 | uint64_t _unsigned; | |
86 | int64_t _signed; | |
87 | } range_end; | |
273b65be JG |
88 | GQuark string; |
89 | }; | |
90 | ||
91 | struct bt_ctf_field_type_enumeration { | |
92 | struct bt_ctf_field_type parent; | |
93 | struct bt_ctf_field_type *container; | |
db8ef253 | 94 | GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */ |
273b65be | 95 | struct declaration_enum declaration; |
d49e1284 | 96 | /* Only set during validation. */ |
96e8f959 MD |
97 | bool has_overlapping_ranges; |
98 | }; | |
99 | ||
d49e1284 | 100 | enum bt_ctf_field_type_enumeration_mapping_iterator_type { |
96e8f959 MD |
101 | ITERATOR_BY_NAME, |
102 | ITERATOR_BY_SIGNED_VALUE, | |
103 | ITERATOR_BY_UNSIGNED_VALUE, | |
104 | }; | |
105 | ||
106 | struct bt_ctf_field_type_enumeration_mapping_iterator { | |
107 | struct bt_object base; | |
108 | struct bt_ctf_field_type_enumeration *enumeration_type; | |
d49e1284 | 109 | enum bt_ctf_field_type_enumeration_mapping_iterator_type type; |
96e8f959 MD |
110 | int index; |
111 | union { | |
112 | GQuark name_quark; | |
113 | int64_t signed_value; | |
114 | uint64_t unsigned_value; | |
115 | } u; | |
273b65be JG |
116 | }; |
117 | ||
118 | struct bt_ctf_field_type_floating_point { | |
119 | struct bt_ctf_field_type parent; | |
120 | struct declaration_float declaration; | |
d480b699 PP |
121 | |
122 | /* | |
123 | * The `declaration` field above contains 3 pointers pointing | |
124 | * to the fields below. This avoids unnecessary dynamic | |
125 | * allocations. | |
126 | */ | |
273b65be JG |
127 | struct declaration_integer sign; |
128 | struct declaration_integer mantissa; | |
129 | struct declaration_integer exp; | |
445c3471 PP |
130 | |
131 | /* | |
132 | * This is what the user sets and is never modified by internal | |
133 | * code. | |
134 | * | |
135 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. | |
136 | */ | |
137 | enum bt_ctf_byte_order user_byte_order; | |
273b65be JG |
138 | }; |
139 | ||
140 | struct structure_field { | |
141 | GQuark name; | |
142 | struct bt_ctf_field_type *type; | |
143 | }; | |
144 | ||
145 | struct bt_ctf_field_type_structure { | |
146 | struct bt_ctf_field_type parent; | |
147 | GHashTable *field_name_to_index; | |
148 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
24724933 | 149 | struct declaration_struct declaration; |
273b65be JG |
150 | }; |
151 | ||
152 | struct bt_ctf_field_type_variant { | |
153 | struct bt_ctf_field_type parent; | |
154 | GString *tag_name; | |
155 | struct bt_ctf_field_type_enumeration *tag; | |
b011f6b0 | 156 | struct bt_ctf_field_path *tag_field_path; |
273b65be JG |
157 | GHashTable *field_name_to_index; |
158 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
159 | struct declaration_variant declaration; | |
160 | }; | |
161 | ||
162 | struct bt_ctf_field_type_array { | |
163 | struct bt_ctf_field_type parent; | |
164 | struct bt_ctf_field_type *element_type; | |
165 | unsigned int length; /* Number of elements */ | |
166 | struct declaration_array declaration; | |
167 | }; | |
168 | ||
169 | struct bt_ctf_field_type_sequence { | |
170 | struct bt_ctf_field_type parent; | |
171 | struct bt_ctf_field_type *element_type; | |
172 | GString *length_field_name; | |
aa4e271c | 173 | struct bt_ctf_field_path *length_field_path; |
273b65be JG |
174 | struct declaration_sequence declaration; |
175 | }; | |
176 | ||
177 | struct bt_ctf_field_type_string { | |
178 | struct bt_ctf_field_type parent; | |
179 | struct declaration_string declaration; | |
180 | }; | |
181 | ||
182 | BT_HIDDEN | |
183 | void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); | |
184 | ||
185 | BT_HIDDEN | |
b92ddaaa JG |
186 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( |
187 | struct bt_ctf_field_type_variant *variant, int64_t tag_value); | |
273b65be JG |
188 | |
189 | BT_HIDDEN | |
b92ddaaa JG |
190 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( |
191 | struct bt_ctf_field_type_variant *variant, uint64_t tag_value); | |
273b65be JG |
192 | |
193 | BT_HIDDEN | |
194 | int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, | |
195 | struct metadata_context *context); | |
196 | ||
9ce21c30 JG |
197 | BT_HIDDEN |
198 | int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); | |
199 | ||
c35a1669 JG |
200 | /* Override field type's byte order only if it is set to "native" */ |
201 | BT_HIDDEN | |
202 | void bt_ctf_field_type_set_native_byte_order( | |
203 | struct bt_ctf_field_type *type, int byte_order); | |
24724933 | 204 | |
39a5e0db JG |
205 | BT_HIDDEN |
206 | int bt_ctf_field_type_structure_get_field_name_index( | |
207 | struct bt_ctf_field_type *structure, const char *name); | |
736133f1 | 208 | |
5cec03e4 JG |
209 | /* Replace an existing field's type in a structure */ |
210 | BT_HIDDEN | |
211 | int bt_ctf_field_type_structure_set_field_index( | |
212 | struct bt_ctf_field_type *structure, | |
213 | struct bt_ctf_field_type *field, int index); | |
214 | ||
736133f1 JG |
215 | BT_HIDDEN |
216 | int bt_ctf_field_type_variant_get_field_name_index( | |
217 | struct bt_ctf_field_type *variant, const char *name); | |
aa4e271c JG |
218 | |
219 | BT_HIDDEN | |
220 | int bt_ctf_field_type_sequence_set_length_field_path( | |
221 | struct bt_ctf_field_type *type, | |
222 | struct bt_ctf_field_path *path); | |
4a1e8671 JG |
223 | |
224 | BT_HIDDEN | |
225 | int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, | |
226 | struct bt_ctf_field_path *path); | |
3f39933a JG |
227 | |
228 | BT_HIDDEN | |
4b5fcb78 PP |
229 | int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type, |
230 | struct bt_ctf_field_type *tag_type); | |
3f39933a | 231 | |
5cec03e4 JG |
232 | /* Replace an existing field's type in a variant */ |
233 | BT_HIDDEN | |
234 | int bt_ctf_field_type_variant_set_field_index( | |
235 | struct bt_ctf_field_type *variant, | |
236 | struct bt_ctf_field_type *field, int index); | |
237 | ||
626e93aa PP |
238 | BT_HIDDEN |
239 | int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, | |
240 | struct bt_ctf_field_type *element_type); | |
241 | ||
242 | BT_HIDDEN | |
243 | int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, | |
244 | struct bt_ctf_field_type *element_type); | |
245 | ||
09840de5 PP |
246 | BT_HIDDEN |
247 | int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type); | |
248 | ||
249 | BT_HIDDEN | |
250 | struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index( | |
251 | struct bt_ctf_field_type *type, int index); | |
252 | ||
253 | BT_HIDDEN | |
254 | int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type, | |
255 | const char *name); | |
256 | ||
2e33ac5a | 257 | #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */ |