Make API CTF-agnostic
[babeltrace.git] / include / babeltrace / ctf-ir / field-types-internal.h
1 #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
2 #define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
3
4 /*
5 * BabelTrace - CTF IR: Event field types internal
6 *
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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/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>
36 #include <stdint.h>
37 #include <glib.h>
38
39 #define BT_ASSERT_PRE_FT_IS_INT(_ft, _name) \
40 BT_ASSERT_PRE( \
41 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_INTEGER || \
42 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_INTEGER || \
43 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION || \
44 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_ENUMERATION, \
45 _name " is not an integer field type: %![ft-]+F", (_ft))
46
47 #define BT_ASSERT_PRE_FT_IS_UNSIGNED_INT(_ft, _name) \
48 BT_ASSERT_PRE( \
49 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_INTEGER || \
50 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION, \
51 _name " is not an unsigned integer field type: %![ft-]+F", (_ft))
52
53 #define BT_ASSERT_PRE_FT_IS_ENUM(_ft, _name) \
54 BT_ASSERT_PRE( \
55 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION || \
56 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_ENUMERATION, \
57 _name " is not an enumeration field type: %![ft-]+F", (_ft))
58
59 #define BT_ASSERT_PRE_FT_IS_ARRAY(_ft, _name) \
60 BT_ASSERT_PRE( \
61 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_STATIC_ARRAY || \
62 ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_DYNAMIC_ARRAY, \
63 _name " is not an array field type: %![ft-]+F", (_ft))
64
65 #define BT_ASSERT_PRE_FT_HAS_ID(_ft, _id, _name) \
66 BT_ASSERT_PRE(((struct bt_field_type *) (_ft))->id == (_id), \
67 _name " has the wrong ID: expected-id=%s, " \
68 "%![ft-]+F", bt_common_field_type_id_string(_id), (_ft))
69
70 #define BT_ASSERT_PRE_FT_HOT(_ft, _name) \
71 BT_ASSERT_PRE_HOT((struct bt_field_type *) (_ft), \
72 (_name), ": %!+F", (_ft))
73
74 #define BT_FIELD_TYPE_NAMED_FT_AT_INDEX(_ft, _index) \
75 (&g_array_index(((struct bt_field_type_named_field_types_container *) (_ft))->named_fts, \
76 struct bt_named_field_type, (_index)))
77
78 #define BT_FIELD_TYPE_ENUM_MAPPING_AT_INDEX(_ft, _index) \
79 (&g_array_index(((struct bt_field_type_enumeration *) (_ft))->mappings, \
80 struct bt_field_type_enumeration_mapping, (_index)))
81
82 #define BT_FIELD_TYPE_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
83 (&g_array_index((_mapping)->ranges, \
84 struct bt_field_type_enumeration_mapping_range, (_index)))
85
86 struct bt_field;
87 struct bt_field_type;
88
89 struct bt_field_type {
90 struct bt_object base;
91 enum bt_field_type_id id;
92 bool frozen;
93
94 /*
95 * Only used in developer mode, this flag indicates whether or
96 * not this field type is part of a trace.
97 */
98 bool part_of_trace;
99 };
100
101 struct bt_field_type_integer {
102 struct bt_field_type common;
103
104 /*
105 * Value range of fields built from this integer field type:
106 * this is an equivalent integer size in bits. More formally,
107 * `range` is `n` in:
108 *
109 * Unsigned range: [0, 2^n - 1]
110 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
111 */
112 uint64_t range;
113
114 enum bt_field_type_integer_preferred_display_base base;
115 };
116
117 struct bt_field_type_enumeration_mapping_range {
118 union {
119 uint64_t u;
120 int64_t i;
121 } lower;
122
123 union {
124 uint64_t u;
125 int64_t i;
126 } upper;
127 };
128
129 struct bt_field_type_enumeration_mapping {
130 GString *label;
131
132 /* Array of `struct bt_field_type_enumeration_mapping_range` */
133 GArray *ranges;
134 };
135
136 struct bt_field_type_enumeration {
137 struct bt_field_type_integer common;
138
139 /* Array of `struct bt_field_type_enumeration_mapping *` */
140 GArray *mappings;
141
142 /*
143 * This is an array of `const char *` which acts as a temporary
144 * (potentially growing) buffer for
145 * bt_field_type_unsigned_enumeration_get_mapping_labels_by_value()
146 * and
147 * bt_field_type_signed_enumeration_get_mapping_labels_by_value().
148 *
149 * The actual strings are owned by the mappings above.
150 */
151 GPtrArray *label_buf;
152 };
153
154 struct bt_field_type_real {
155 struct bt_field_type common;
156 bool is_single_precision;
157 };
158
159 struct bt_field_type_string {
160 struct bt_field_type common;
161 };
162
163 /* A named field type is a (name, field type) pair */
164 struct bt_named_field_type {
165 GString *name;
166
167 /* Owned by this */
168 struct bt_field_type *ft;
169 };
170
171 /*
172 * This is the base field type for a container of named field types.
173 * Structure and variant field types inherit this.
174 */
175 struct bt_field_type_named_field_types_container {
176 struct bt_field_type common;
177
178 /*
179 * Key: `const char *`, not owned by this (owned by named field
180 * type objects contained in `named_fts` below).
181 */
182 GHashTable *name_to_index;
183
184 /* Array of `struct bt_named_field_type` */
185 GArray *named_fts;
186 };
187
188 struct bt_field_type_structure {
189 struct bt_field_type_named_field_types_container common;
190 };
191
192 struct bt_field_type_array {
193 struct bt_field_type common;
194
195 /* Owned by this */
196 struct bt_field_type *element_ft;
197 };
198
199 struct bt_field_type_static_array {
200 struct bt_field_type_array common;
201 uint64_t length;
202 };
203
204 struct bt_field_type_dynamic_array {
205 struct bt_field_type_array common;
206
207 /* Weak: never dereferenced, only use to find it elsewhere */
208 struct bt_field_type *length_ft;
209
210 /* Owned by this */
211 struct bt_field_path *length_field_path;
212 };
213
214 struct bt_field_type_variant {
215 struct bt_field_type_named_field_types_container common;
216
217 /* Weak: never dereferenced, only use to find it elsewhere */
218 struct bt_field_type *selector_ft;
219
220 /* Owned by this */
221 struct bt_field_path *selector_field_path;
222 };
223
224 static inline
225 bool bt_field_type_has_known_id(struct bt_field_type *ft)
226 {
227 return ft->id >= BT_FIELD_TYPE_ID_UNSIGNED_INTEGER &&
228 ft->id <= BT_FIELD_TYPE_ID_VARIANT;
229 }
230
231 BT_HIDDEN
232 void _bt_field_type_freeze(struct bt_field_type *field_type);
233
234 #ifdef BT_DEV_MODE
235 # define bt_field_type_freeze _bt_field_type_freeze
236 #else
237 # define bt_field_type_freeze(_ft)
238 #endif
239
240 /*
241 * This function recursively marks `field_type` and its children as
242 * being part of a trace. This is used to validate that all field types
243 * are used at a single location within trace objects even if they are
244 * shared objects for other purposes.
245 */
246 BT_HIDDEN
247 void _bt_field_type_make_part_of_trace(struct bt_field_type *field_type);
248
249 #ifdef BT_DEV_MODE
250 # define bt_field_type_make_part_of_trace _bt_field_type_make_part_of_trace
251 #else
252 # define bt_field_type_make_part_of_trace(_ft) ((void) _ft)
253 #endif
254
255 #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */
This page took 0.034653 seconds and 4 git commands to generate.