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