1 #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
2 #define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
5 * BabelTrace - CTF IR: Event field types internal
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/ctf-ir/clock-class.h>
32 #include <babeltrace/ctf-ir/field-types.h>
33 #include <babeltrace/babeltrace-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/types.h>
39 #define BT_ASSERT_PRE_FT_HAS_ID(_ft, _type_id, _name) \
40 BT_ASSERT_PRE(((struct bt_field_type *) (_ft))->id == (_type_id), \
41 _name " has the wrong type ID: expected-type-id=%s, " \
42 "%![ft-]+F", bt_common_field_type_id_string(_type_id), (_ft))
44 #define BT_ASSERT_PRE_FT_HOT(_ft, _name) \
45 BT_ASSERT_PRE_HOT((_ft), (_name), ": %!+F", (_ft))
47 #define BT_FIELD_TYPE_STRUCTURE_FIELD_AT_INDEX(_ft, _index) \
48 (&g_array_index(((struct bt_field_type_structure *) (_ft))->fields, \
49 struct bt_field_type_structure_field, (_index)))
51 #define BT_FIELD_TYPE_VARIANT_CHOICE_AT_INDEX(_ft, _index) \
52 (&g_array_index(((struct bt_field_type_variant *) (_ft))->choices, \
53 struct bt_field_type_variant_choice, (_index)))
58 typedef void (*bt_field_type_method_freeze
)(
59 struct bt_field_type
*);
60 typedef int (*bt_field_type_method_validate
)(
61 struct bt_field_type
*);
62 typedef void (*bt_field_type_method_set_byte_order
)(
63 struct bt_field_type
*, enum bt_byte_order
);
64 typedef struct bt_field_type
*(*bt_field_type_method_copy
)(
65 struct bt_field_type
*);
66 typedef int (*bt_field_type_method_compare
)(
67 struct bt_field_type
*,
68 struct bt_field_type
*);
70 struct bt_field_type_methods
{
71 bt_field_type_method_freeze freeze
;
72 bt_field_type_method_validate validate
;
73 bt_field_type_method_set_byte_order set_byte_order
;
74 bt_field_type_method_copy copy
;
75 bt_field_type_method_compare compare
;
78 struct bt_field_type
{
79 struct bt_object base
;
80 enum bt_field_type_id id
;
81 unsigned int alignment
;
84 struct bt_field_type_methods
*methods
;
87 * A type can't be modified once it is added to an event or after a
88 * a field has been instanciated from it.
93 * This flag indicates if the field type is valid. A valid
94 * field type is _always_ frozen. All the nested field types of
95 * a valid field type are also valid (and thus frozen).
100 struct bt_field_type_integer
{
101 struct bt_field_type common
;
104 struct bt_clock_class
*mapped_clock_class
;
106 enum bt_byte_order user_byte_order
;
109 enum bt_integer_base base
;
110 enum bt_string_encoding encoding
;
113 struct enumeration_mapping
{
125 struct bt_field_type_enumeration
{
126 struct bt_field_type common
;
129 struct bt_field_type_integer
*container_ft
;
131 /* Array of `struct enumeration_mapping *`, owned by this */
134 /* Only set during validation */
135 bt_bool has_overlapping_ranges
;
138 enum bt_field_type_enumeration_mapping_iterator_type
{
140 ITERATOR_BY_SIGNED_VALUE
,
141 ITERATOR_BY_UNSIGNED_VALUE
,
144 struct bt_field_type_enumeration_mapping_iterator
{
145 struct bt_object base
;
148 struct bt_field_type_enumeration
*enumeration_ft
;
150 enum bt_field_type_enumeration_mapping_iterator_type type
;
154 int64_t signed_value
;
155 uint64_t unsigned_value
;
159 struct bt_field_type_floating_point
{
160 struct bt_field_type common
;
161 enum bt_byte_order user_byte_order
;
162 unsigned int exp_dig
;
163 unsigned int mant_dig
;
166 struct bt_field_type_structure_field
{
170 struct bt_field_type
*type
;
173 struct bt_field_type_structure
{
174 struct bt_field_type common
;
175 GHashTable
*field_name_to_index
;
178 * Array of `struct bt_field_type_structure_field`,
184 struct bt_field_type_variant_choice_range
{
195 struct bt_field_type_variant_choice
{
199 struct bt_field_type
*type
;
201 /* Array of `struct bt_field_type_variant_choice_range` */
205 struct bt_field_type_variant
{
206 struct bt_field_type common
;
208 bool choices_up_to_date
;
211 struct bt_field_type_enumeration
*tag_ft
;
214 struct bt_field_path
*tag_field_path
;
216 GHashTable
*choice_name_to_index
;
219 * Array of `struct bt_field_type_variant_choice`,
224 struct bt_field_type_array
{
225 struct bt_field_type common
;
228 struct bt_field_type
*element_ft
;
233 struct bt_field_type_sequence
{
234 struct bt_field_type common
;
237 struct bt_field_type
*element_ft
;
239 GString
*length_field_name
;
242 struct bt_field_path
*length_field_path
;
245 struct bt_field_type_string
{
246 struct bt_field_type common
;
247 enum bt_string_encoding encoding
;
250 typedef struct bt_field
*(* bt_field_create_func
)(
251 struct bt_field_type
*);
254 static inline bool bt_field_type_has_known_id(
255 struct bt_field_type
*ft
)
257 return (int) ft
->id
> BT_FIELD_TYPE_ID_UNKNOWN
||
258 (int) ft
->id
< BT_FIELD_TYPE_ID_NR
;
262 int bt_field_type_variant_update_choices(
263 struct bt_field_type
*ft
);
266 void bt_field_type_freeze(struct bt_field_type
*ft
);
269 int bt_field_type_validate(struct bt_field_type
*ft
);
272 int bt_field_type_sequence_set_length_field_path(
273 struct bt_field_type
*ft
, struct bt_field_path
*path
);
276 int bt_field_type_variant_set_tag_field_path(
277 struct bt_field_type
*ft
,
278 struct bt_field_path
*path
);
281 int bt_field_type_variant_set_tag_field_type(
282 struct bt_field_type
*ft
,
283 struct bt_field_type
*tag_ft
);
286 int64_t bt_field_type_get_field_count(struct bt_field_type
*ft
);
289 struct bt_field_type
*bt_field_type_borrow_field_at_index(
290 struct bt_field_type
*ft
, int index
);
293 int bt_field_type_get_field_index(struct bt_field_type
*ft
,
297 int bt_field_type_validate_single_clock_class(
298 struct bt_field_type
*ft
,
299 struct bt_clock_class
**expected_clock_class
);
302 int64_t bt_field_type_variant_find_choice_index(
303 struct bt_field_type
*ft
, uint64_t uval
,
306 #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */