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 | ||
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> |
273b65be | 36 | #include <babeltrace/babeltrace-internal.h> |
83509119 | 37 | #include <babeltrace/object-internal.h> |
273b65be JG |
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; |
1487a16a | 46 | enum bt_ctf_field_type_id id; |
dc3fffef | 47 | unsigned int alignment; |
273b65be JG |
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; | |
ac0c6bdd | 66 | struct bt_ctf_clock_class *mapped_clock; |
445c3471 | 67 | enum bt_ctf_byte_order user_byte_order; |
dc3fffef PP |
68 | bool is_signed; |
69 | unsigned int size; | |
70 | enum bt_ctf_integer_base base; | |
71 | enum bt_ctf_string_encoding encoding; | |
273b65be JG |
72 | }; |
73 | ||
74 | struct enumeration_mapping { | |
b92ddaaa JG |
75 | union { |
76 | uint64_t _unsigned; | |
77 | int64_t _signed; | |
78 | } range_start; | |
79 | ||
80 | union { | |
81 | uint64_t _unsigned; | |
82 | int64_t _signed; | |
83 | } range_end; | |
273b65be JG |
84 | GQuark string; |
85 | }; | |
86 | ||
87 | struct bt_ctf_field_type_enumeration { | |
88 | struct bt_ctf_field_type parent; | |
89 | struct bt_ctf_field_type *container; | |
db8ef253 | 90 | GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */ |
d49e1284 | 91 | /* Only set during validation. */ |
96e8f959 MD |
92 | bool has_overlapping_ranges; |
93 | }; | |
94 | ||
d49e1284 | 95 | enum bt_ctf_field_type_enumeration_mapping_iterator_type { |
96e8f959 MD |
96 | ITERATOR_BY_NAME, |
97 | ITERATOR_BY_SIGNED_VALUE, | |
98 | ITERATOR_BY_UNSIGNED_VALUE, | |
99 | }; | |
100 | ||
101 | struct bt_ctf_field_type_enumeration_mapping_iterator { | |
102 | struct bt_object base; | |
103 | struct bt_ctf_field_type_enumeration *enumeration_type; | |
d49e1284 | 104 | enum bt_ctf_field_type_enumeration_mapping_iterator_type type; |
96e8f959 MD |
105 | int index; |
106 | union { | |
107 | GQuark name_quark; | |
108 | int64_t signed_value; | |
109 | uint64_t unsigned_value; | |
110 | } u; | |
273b65be JG |
111 | }; |
112 | ||
113 | struct bt_ctf_field_type_floating_point { | |
114 | struct bt_ctf_field_type parent; | |
445c3471 | 115 | enum bt_ctf_byte_order user_byte_order; |
dc3fffef PP |
116 | unsigned int exp_dig; |
117 | unsigned int mant_dig; | |
273b65be JG |
118 | }; |
119 | ||
120 | struct structure_field { | |
121 | GQuark name; | |
122 | struct bt_ctf_field_type *type; | |
123 | }; | |
124 | ||
125 | struct bt_ctf_field_type_structure { | |
126 | struct bt_ctf_field_type parent; | |
127 | GHashTable *field_name_to_index; | |
128 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
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 */ | |
273b65be JG |
138 | }; |
139 | ||
140 | struct bt_ctf_field_type_array { | |
141 | struct bt_ctf_field_type parent; | |
142 | struct bt_ctf_field_type *element_type; | |
143 | unsigned int length; /* Number of elements */ | |
273b65be JG |
144 | }; |
145 | ||
146 | struct bt_ctf_field_type_sequence { | |
147 | struct bt_ctf_field_type parent; | |
148 | struct bt_ctf_field_type *element_type; | |
149 | GString *length_field_name; | |
aa4e271c | 150 | struct bt_ctf_field_path *length_field_path; |
273b65be JG |
151 | }; |
152 | ||
153 | struct bt_ctf_field_type_string { | |
154 | struct bt_ctf_field_type parent; | |
dc3fffef | 155 | enum bt_ctf_string_encoding encoding; |
273b65be JG |
156 | }; |
157 | ||
158 | BT_HIDDEN | |
159 | void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); | |
160 | ||
161 | BT_HIDDEN | |
b92ddaaa JG |
162 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( |
163 | struct bt_ctf_field_type_variant *variant, int64_t tag_value); | |
273b65be JG |
164 | |
165 | BT_HIDDEN | |
b92ddaaa JG |
166 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( |
167 | struct bt_ctf_field_type_variant *variant, uint64_t tag_value); | |
273b65be JG |
168 | |
169 | BT_HIDDEN | |
170 | int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, | |
171 | struct metadata_context *context); | |
172 | ||
9ce21c30 JG |
173 | BT_HIDDEN |
174 | int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); | |
175 | ||
39a5e0db JG |
176 | BT_HIDDEN |
177 | int bt_ctf_field_type_structure_get_field_name_index( | |
178 | struct bt_ctf_field_type *structure, const char *name); | |
736133f1 | 179 | |
5cec03e4 JG |
180 | /* Replace an existing field's type in a structure */ |
181 | BT_HIDDEN | |
182 | int bt_ctf_field_type_structure_set_field_index( | |
183 | struct bt_ctf_field_type *structure, | |
184 | struct bt_ctf_field_type *field, int index); | |
185 | ||
736133f1 JG |
186 | BT_HIDDEN |
187 | int bt_ctf_field_type_variant_get_field_name_index( | |
188 | struct bt_ctf_field_type *variant, const char *name); | |
aa4e271c JG |
189 | |
190 | BT_HIDDEN | |
191 | int bt_ctf_field_type_sequence_set_length_field_path( | |
192 | struct bt_ctf_field_type *type, | |
193 | struct bt_ctf_field_path *path); | |
4a1e8671 JG |
194 | |
195 | BT_HIDDEN | |
196 | int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, | |
197 | struct bt_ctf_field_path *path); | |
3f39933a JG |
198 | |
199 | BT_HIDDEN | |
4b5fcb78 PP |
200 | int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type, |
201 | struct bt_ctf_field_type *tag_type); | |
3f39933a | 202 | |
5cec03e4 JG |
203 | /* Replace an existing field's type in a variant */ |
204 | BT_HIDDEN | |
205 | int bt_ctf_field_type_variant_set_field_index( | |
206 | struct bt_ctf_field_type *variant, | |
207 | struct bt_ctf_field_type *field, int index); | |
208 | ||
626e93aa PP |
209 | BT_HIDDEN |
210 | int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, | |
211 | struct bt_ctf_field_type *element_type); | |
212 | ||
213 | BT_HIDDEN | |
214 | int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, | |
215 | struct bt_ctf_field_type *element_type); | |
216 | ||
09840de5 | 217 | BT_HIDDEN |
544d0515 | 218 | int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type); |
09840de5 PP |
219 | |
220 | BT_HIDDEN | |
221 | struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index( | |
222 | struct bt_ctf_field_type *type, int index); | |
223 | ||
224 | BT_HIDDEN | |
225 | int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type, | |
226 | const char *name); | |
227 | ||
2e33ac5a | 228 | #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */ |