1 #ifndef BABELTRACE_CTF_WRITER_FIELD_TYPES_H
2 #define BABELTRACE_CTF_WRITER_FIELD_TYPES_H
5 * Babeltrace - CTF writer: Event Fields
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
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
36 #include <babeltrace/types.h>
37 #include <babeltrace/ctf-ir/field-types.h>
44 struct bt_ctf_field_type
;
46 enum bt_ctf_field_type_id
{
47 BT_CTF_FIELD_TYPE_ID_UNKNOWN
= BT_FIELD_TYPE_ID_UNKNOWN
,
48 BT_CTF_FIELD_TYPE_ID_INTEGER
= BT_FIELD_TYPE_ID_INTEGER
,
49 BT_CTF_FIELD_TYPE_ID_FLOAT
= BT_FIELD_TYPE_ID_FLOAT
,
50 BT_CTF_FIELD_TYPE_ID_ENUM
= BT_FIELD_TYPE_ID_ENUM
,
51 BT_CTF_FIELD_TYPE_ID_STRING
= BT_FIELD_TYPE_ID_STRING
,
52 BT_CTF_FIELD_TYPE_ID_STRUCT
= BT_FIELD_TYPE_ID_STRUCT
,
53 BT_CTF_FIELD_TYPE_ID_ARRAY
= BT_FIELD_TYPE_ID_ARRAY
,
54 BT_CTF_FIELD_TYPE_ID_SEQUENCE
= BT_FIELD_TYPE_ID_SEQUENCE
,
55 BT_CTF_FIELD_TYPE_ID_VARIANT
= BT_FIELD_TYPE_ID_VARIANT
,
56 BT_CTF_FIELD_TYPE_ID_NR
= BT_FIELD_TYPE_ID_NR
,
59 extern enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
60 struct bt_ctf_field_type
*field_type
);
62 enum bt_ctf_byte_order
{
63 BT_CTF_BYTE_ORDER_UNKNOWN
= BT_BYTE_ORDER_UNKNOWN
,
64 BT_CTF_BYTE_ORDER_NATIVE
= BT_BYTE_ORDER_NATIVE
,
65 BT_CTF_BYTE_ORDER_UNSPECIFIED
= BT_BYTE_ORDER_UNSPECIFIED
,
66 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
= BT_BYTE_ORDER_LITTLE_ENDIAN
,
67 BT_CTF_BYTE_ORDER_BIG_ENDIAN
= BT_BYTE_ORDER_BIG_ENDIAN
,
68 BT_CTF_BYTE_ORDER_NETWORK
= BT_BYTE_ORDER_NETWORK
,
71 enum bt_ctf_string_encoding
{
72 BT_CTF_STRING_ENCODING_UNKNOWN
= BT_STRING_ENCODING_UNKNOWN
,
73 BT_CTF_STRING_ENCODING_NONE
= BT_STRING_ENCODING_NONE
,
74 BT_CTF_STRING_ENCODING_UTF8
= BT_STRING_ENCODING_UTF8
,
75 BT_CTF_STRING_ENCODING_ASCII
= BT_STRING_ENCODING_ASCII
,
78 /* Pre-2.0 CTF writer compatibility */
79 #define ctf_string_encoding bt_ctf_string_encoding
81 extern int bt_ctf_field_type_get_alignment(
82 struct bt_ctf_field_type
*field_type
);
84 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*field_type
,
85 unsigned int alignment
);
87 extern enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
88 struct bt_ctf_field_type
*field_type
);
90 extern int bt_ctf_field_type_set_byte_order(
91 struct bt_ctf_field_type
*field_type
,
92 enum bt_ctf_byte_order byte_order
);
94 enum bt_ctf_integer_base
{
95 /// Unknown, used for errors.
96 BT_CTF_INTEGER_BASE_UNKNOWN
= -1,
98 /// Unspecified by the tracer.
99 BT_CTF_INTEGER_BASE_UNSPECIFIED
= 0,
102 BT_CTF_INTEGER_BASE_BINARY
= 2,
105 BT_CTF_INTEGER_BASE_OCTAL
= 8,
108 BT_CTF_INTEGER_BASE_DECIMAL
= 10,
111 BT_CTF_INTEGER_BASE_HEXADECIMAL
= 16,
114 extern struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(
117 extern int bt_ctf_field_type_integer_get_size(
118 struct bt_ctf_field_type
*int_field_type
);
120 extern int bt_ctf_field_type_integer_set_size(
121 struct bt_ctf_field_type
*int_field_type
, unsigned int size
);
123 extern bt_bool
bt_ctf_field_type_integer_is_signed(
124 struct bt_ctf_field_type
*int_field_type
);
126 /* Pre-2.0 CTF writer compatibility */
128 int bt_ctf_field_type_integer_get_signed(
129 struct bt_ctf_field_type
*int_field_type
)
131 return bt_ctf_field_type_integer_is_signed(int_field_type
) ? 1 : 0;
134 extern int bt_ctf_field_type_integer_set_is_signed(
135 struct bt_ctf_field_type
*int_field_type
, bt_bool is_signed
);
137 /* Pre-2.0 CTF writer compatibility */
139 int bt_ctf_field_type_integer_set_signed(
140 struct bt_ctf_field_type
*int_field_type
, int is_signed
)
142 return bt_ctf_field_type_integer_set_is_signed(int_field_type
,
143 is_signed
? BT_TRUE
: BT_FALSE
);
146 extern enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
147 struct bt_ctf_field_type
*int_field_type
);
149 extern int bt_ctf_field_type_integer_set_base(
150 struct bt_ctf_field_type
*int_field_type
,
151 enum bt_ctf_integer_base base
);
153 extern enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
154 struct bt_ctf_field_type
*int_field_type
);
156 extern int bt_ctf_field_type_integer_set_encoding(
157 struct bt_ctf_field_type
*int_field_type
,
158 enum bt_ctf_string_encoding encoding
);
160 extern struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
161 struct bt_ctf_field_type
*int_field_type
);
163 extern int bt_ctf_field_type_integer_set_mapped_clock_class(
164 struct bt_ctf_field_type
*int_field_type
,
165 struct bt_ctf_clock_class
*clock_class
);
167 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
169 extern int bt_ctf_field_type_floating_point_get_exponent_digits(
170 struct bt_ctf_field_type
*float_field_type
);
172 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
173 struct bt_ctf_field_type
*float_field_type
,
174 unsigned int exponent_size
);
176 extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
177 struct bt_ctf_field_type
*float_field_type
);
179 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
180 struct bt_ctf_field_type
*float_field_type
,
181 unsigned int mantissa_sign_size
);
183 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
184 struct bt_ctf_field_type
*int_field_type
);
187 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
188 struct bt_ctf_field_type
*enum_field_type
);
190 extern int64_t bt_ctf_field_type_enumeration_get_mapping_count(
191 struct bt_ctf_field_type
*enum_field_type
);
193 extern int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
194 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
195 const char **name
, int64_t *range_begin
, int64_t *range_end
);
197 extern int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
198 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
199 const char **name
, uint64_t *range_begin
,
200 uint64_t *range_end
);
202 extern int bt_ctf_field_type_enumeration_signed_add_mapping(
203 struct bt_ctf_field_type
*enum_field_type
,
204 const char *name
, int64_t range_begin
, int64_t range_end
);
206 extern int bt_ctf_field_type_enumeration_unsigned_add_mapping(
207 struct bt_ctf_field_type
*enum_field_type
,
208 const char *name
, uint64_t range_begin
, uint64_t range_end
);
210 /* Pre-2.0 CTF writer compatibility */
212 int bt_ctf_field_type_enumeration_add_mapping(
213 struct bt_ctf_field_type
*enumeration
, const char *name
,
214 int64_t range_start
, int64_t range_end
)
216 return bt_ctf_field_type_enumeration_signed_add_mapping(enumeration
,
217 name
, range_start
, range_end
);
220 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
222 extern enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
223 struct bt_ctf_field_type
*string_field_type
);
225 extern int bt_ctf_field_type_string_set_encoding(
226 struct bt_ctf_field_type
*string_field_type
,
227 enum bt_ctf_string_encoding encoding
);
229 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
231 extern int64_t bt_ctf_field_type_structure_get_field_count(
232 struct bt_ctf_field_type
*struct_field_type
);
234 extern int bt_ctf_field_type_structure_get_field_by_index(
235 struct bt_ctf_field_type
*struct_field_type
,
236 const char **field_name
, struct bt_ctf_field_type
**field_type
,
239 /* Pre-2.0 CTF writer compatibility */
241 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type
*structure
,
242 const char **field_name
, struct bt_ctf_field_type
**field_type
,
245 return bt_ctf_field_type_structure_get_field_by_index(structure
,
246 field_name
, field_type
, (uint64_t) index
);
250 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
251 struct bt_ctf_field_type
*struct_field_type
,
252 const char *field_name
);
254 extern int bt_ctf_field_type_structure_add_field(
255 struct bt_ctf_field_type
*struct_field_type
,
256 struct bt_ctf_field_type
*field_type
,
257 const char *field_name
);
259 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
260 struct bt_ctf_field_type
*element_field_type
,
261 unsigned int length
);
263 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
264 struct bt_ctf_field_type
*array_field_type
);
266 extern int64_t bt_ctf_field_type_array_get_length(
267 struct bt_ctf_field_type
*array_field_type
);
269 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
270 struct bt_ctf_field_type
*element_field_type
,
271 const char *length_name
);
273 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
274 struct bt_ctf_field_type
*sequence_field_type
);
276 extern const char *bt_ctf_field_type_sequence_get_length_field_name(
277 struct bt_ctf_field_type
*sequence_field_type
);
279 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
280 struct bt_ctf_field_type
*tag_field_type
,
281 const char *tag_name
);
283 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
284 struct bt_ctf_field_type
*variant_field_type
);
286 extern const char *bt_ctf_field_type_variant_get_tag_name(
287 struct bt_ctf_field_type
*variant_field_type
);
289 extern int bt_ctf_field_type_variant_set_tag_name(
290 struct bt_ctf_field_type
*variant_field_type
,
291 const char *tag_name
);
293 extern int64_t bt_ctf_field_type_variant_get_field_count(
294 struct bt_ctf_field_type
*variant_field_type
);
296 extern int bt_ctf_field_type_variant_get_field_by_index(
297 struct bt_ctf_field_type
*variant_field_type
,
298 const char **field_name
,
299 struct bt_ctf_field_type
**field_type
, uint64_t index
);
302 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
303 struct bt_ctf_field_type
*variant_field_type
,
304 const char *field_name
);
307 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
308 struct bt_ctf_field_type
*variant_field_type
,
309 struct bt_ctf_field
*tag_field
);
311 extern int bt_ctf_field_type_variant_add_field(
312 struct bt_ctf_field_type
*variant_field_type
,
313 struct bt_ctf_field_type
*field_type
,
314 const char *field_name
);
320 #endif /* BABELTRACE_CTF_WRITER_FIELD_TYPES_H */