1 #ifndef BABELTRACE_CTF_WRITER_FIELD_TYPES_H
2 #define BABELTRACE_CTF_WRITER_FIELD_TYPES_H
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * The Common Trace Format (CTF) Specification is available at
28 * http://www.efficios.com/ctf
33 #include <babeltrace2/ctf-writer/types.h>
40 struct bt_ctf_field_type
;
43 /// Unknown, used for errors.
44 BT_CTF_SCOPE_UNKNOWN
= -1,
46 /// Trace packet header.
47 BT_CTF_SCOPE_TRACE_PACKET_HEADER
= 1,
49 /// Stream packet context.
50 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT
= 2,
52 /// Stream event header.
53 BT_CTF_SCOPE_STREAM_EVENT_HEADER
= 3,
55 /// Stream event context.
56 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT
= 4,
59 BT_CTF_SCOPE_EVENT_CONTEXT
= 5,
62 BT_CTF_SCOPE_EVENT_PAYLOAD
= 6,
66 BT_CTF_SCOPE_EVENT_FIELDS
= 6,
70 enum bt_ctf_field_type_id
{
71 BT_CTF_FIELD_TYPE_ID_UNKNOWN
= -1,
72 BT_CTF_FIELD_TYPE_ID_INTEGER
= 0,
73 BT_CTF_FIELD_TYPE_ID_FLOAT
= 1,
74 BT_CTF_FIELD_TYPE_ID_ENUM
= 2,
75 BT_CTF_FIELD_TYPE_ID_STRING
= 3,
76 BT_CTF_FIELD_TYPE_ID_STRUCT
= 4,
77 BT_CTF_FIELD_TYPE_ID_ARRAY
= 5,
78 BT_CTF_FIELD_TYPE_ID_SEQUENCE
= 6,
79 BT_CTF_FIELD_TYPE_ID_VARIANT
= 7,
80 BT_CTF_FIELD_TYPE_ID_NR
,
83 extern enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
84 struct bt_ctf_field_type
*field_type
);
86 enum bt_ctf_byte_order
{
87 BT_CTF_BYTE_ORDER_UNKNOWN
= -1,
88 BT_CTF_BYTE_ORDER_NATIVE
= 0,
89 BT_CTF_BYTE_ORDER_UNSPECIFIED
,
90 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
,
91 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
92 BT_CTF_BYTE_ORDER_NETWORK
,
95 enum bt_ctf_string_encoding
{
96 BT_CTF_STRING_ENCODING_UNKNOWN
= -1,
97 BT_CTF_STRING_ENCODING_NONE
,
98 BT_CTF_STRING_ENCODING_UTF8
,
99 BT_CTF_STRING_ENCODING_ASCII
,
102 /* Pre-2.0 CTF writer compatibility */
103 #define ctf_string_encoding bt_ctf_string_encoding
105 extern int bt_ctf_field_type_get_alignment(
106 struct bt_ctf_field_type
*field_type
);
108 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*field_type
,
109 unsigned int alignment
);
111 extern enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
112 struct bt_ctf_field_type
*field_type
);
114 extern int bt_ctf_field_type_set_byte_order(
115 struct bt_ctf_field_type
*field_type
,
116 enum bt_ctf_byte_order byte_order
);
118 enum bt_ctf_integer_base
{
119 /// Unknown, used for errors.
120 BT_CTF_INTEGER_BASE_UNKNOWN
= -1,
122 /// Unspecified by the tracer.
123 BT_CTF_INTEGER_BASE_UNSPECIFIED
= 0,
126 BT_CTF_INTEGER_BASE_BINARY
= 2,
129 BT_CTF_INTEGER_BASE_OCTAL
= 8,
132 BT_CTF_INTEGER_BASE_DECIMAL
= 10,
135 BT_CTF_INTEGER_BASE_HEXADECIMAL
= 16,
138 extern struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(
141 extern int bt_ctf_field_type_integer_get_size(
142 struct bt_ctf_field_type
*int_field_type
);
144 extern int bt_ctf_field_type_integer_set_size(
145 struct bt_ctf_field_type
*int_field_type
, unsigned int size
);
147 extern bt_ctf_bool
bt_ctf_field_type_integer_is_signed(
148 struct bt_ctf_field_type
*int_field_type
);
150 /* Pre-2.0 CTF writer compatibility */
152 int bt_ctf_field_type_integer_get_signed(
153 struct bt_ctf_field_type
*int_field_type
)
155 return bt_ctf_field_type_integer_is_signed(int_field_type
) ? 1 : 0;
158 extern int bt_ctf_field_type_integer_set_is_signed(
159 struct bt_ctf_field_type
*int_field_type
, bt_ctf_bool is_signed
);
161 /* Pre-2.0 CTF writer compatibility */
163 int bt_ctf_field_type_integer_set_signed(
164 struct bt_ctf_field_type
*int_field_type
, int is_signed
)
166 return bt_ctf_field_type_integer_set_is_signed(int_field_type
,
167 is_signed
? BT_CTF_TRUE
: BT_CTF_FALSE
);
170 extern enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
171 struct bt_ctf_field_type
*int_field_type
);
173 extern int bt_ctf_field_type_integer_set_base(
174 struct bt_ctf_field_type
*int_field_type
,
175 enum bt_ctf_integer_base base
);
177 extern enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
178 struct bt_ctf_field_type
*int_field_type
);
180 extern int bt_ctf_field_type_integer_set_encoding(
181 struct bt_ctf_field_type
*int_field_type
,
182 enum bt_ctf_string_encoding encoding
);
184 extern struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
185 struct bt_ctf_field_type
*int_field_type
);
187 extern int bt_ctf_field_type_integer_set_mapped_clock_class(
188 struct bt_ctf_field_type
*int_field_type
,
189 struct bt_ctf_clock_class
*clock_class
);
191 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
193 extern int bt_ctf_field_type_floating_point_get_exponent_digits(
194 struct bt_ctf_field_type
*float_field_type
);
196 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
197 struct bt_ctf_field_type
*float_field_type
,
198 unsigned int exponent_size
);
200 extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
201 struct bt_ctf_field_type
*float_field_type
);
203 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
204 struct bt_ctf_field_type
*float_field_type
,
205 unsigned int mantissa_sign_size
);
207 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
208 struct bt_ctf_field_type
*int_field_type
);
211 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
212 struct bt_ctf_field_type
*enum_field_type
);
214 extern int64_t bt_ctf_field_type_enumeration_get_mapping_count(
215 struct bt_ctf_field_type
*enum_field_type
);
217 extern int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
218 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
219 const char **name
, int64_t *range_begin
, int64_t *range_end
);
221 extern int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
222 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
223 const char **name
, uint64_t *range_begin
,
224 uint64_t *range_end
);
226 extern int bt_ctf_field_type_enumeration_signed_add_mapping(
227 struct bt_ctf_field_type
*enum_field_type
,
228 const char *name
, int64_t range_begin
, int64_t range_end
);
230 extern int bt_ctf_field_type_enumeration_unsigned_add_mapping(
231 struct bt_ctf_field_type
*enum_field_type
,
232 const char *name
, uint64_t range_begin
, uint64_t range_end
);
234 /* Pre-2.0 CTF writer compatibility */
236 int bt_ctf_field_type_enumeration_add_mapping(
237 struct bt_ctf_field_type
*enumeration
, const char *name
,
238 int64_t range_start
, int64_t range_end
)
240 return bt_ctf_field_type_enumeration_signed_add_mapping(enumeration
,
241 name
, range_start
, range_end
);
244 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
246 extern enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
247 struct bt_ctf_field_type
*string_field_type
);
249 extern int bt_ctf_field_type_string_set_encoding(
250 struct bt_ctf_field_type
*string_field_type
,
251 enum bt_ctf_string_encoding encoding
);
253 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
255 extern int64_t bt_ctf_field_type_structure_get_field_count(
256 struct bt_ctf_field_type
*struct_field_type
);
258 extern int bt_ctf_field_type_structure_get_field_by_index(
259 struct bt_ctf_field_type
*struct_field_type
,
260 const char **field_name
, struct bt_ctf_field_type
**field_type
,
263 /* Pre-2.0 CTF writer compatibility */
265 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type
*structure
,
266 const char **field_name
, struct bt_ctf_field_type
**field_type
,
269 return bt_ctf_field_type_structure_get_field_by_index(structure
,
270 field_name
, field_type
, (uint64_t) index
);
274 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
275 struct bt_ctf_field_type
*struct_field_type
,
276 const char *field_name
);
278 extern int bt_ctf_field_type_structure_add_field(
279 struct bt_ctf_field_type
*struct_field_type
,
280 struct bt_ctf_field_type
*field_type
,
281 const char *field_name
);
283 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
284 struct bt_ctf_field_type
*element_field_type
,
285 unsigned int length
);
287 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
288 struct bt_ctf_field_type
*array_field_type
);
290 extern int64_t bt_ctf_field_type_array_get_length(
291 struct bt_ctf_field_type
*array_field_type
);
293 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
294 struct bt_ctf_field_type
*element_field_type
,
295 const char *length_name
);
297 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
298 struct bt_ctf_field_type
*sequence_field_type
);
300 extern const char *bt_ctf_field_type_sequence_get_length_field_name(
301 struct bt_ctf_field_type
*sequence_field_type
);
303 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
304 struct bt_ctf_field_type
*tag_field_type
,
305 const char *tag_name
);
307 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
308 struct bt_ctf_field_type
*variant_field_type
);
310 extern const char *bt_ctf_field_type_variant_get_tag_name(
311 struct bt_ctf_field_type
*variant_field_type
);
313 extern int bt_ctf_field_type_variant_set_tag_name(
314 struct bt_ctf_field_type
*variant_field_type
,
315 const char *tag_name
);
317 extern int64_t bt_ctf_field_type_variant_get_field_count(
318 struct bt_ctf_field_type
*variant_field_type
);
320 extern int bt_ctf_field_type_variant_get_field_by_index(
321 struct bt_ctf_field_type
*variant_field_type
,
322 const char **field_name
,
323 struct bt_ctf_field_type
**field_type
, uint64_t index
);
326 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
327 struct bt_ctf_field_type
*variant_field_type
,
328 const char *field_name
);
331 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
332 struct bt_ctf_field_type
*variant_field_type
,
333 struct bt_ctf_field
*tag_field
);
335 extern int bt_ctf_field_type_variant_add_field(
336 struct bt_ctf_field_type
*variant_field_type
,
337 struct bt_ctf_field_type
*field_type
,
338 const char *field_name
);
344 #endif /* BABELTRACE_CTF_WRITER_FIELD_TYPES_H */