1 #ifndef BABELTRACE_CTF_IR_EVENT_TYPES_H
2 #define BABELTRACE_CTF_IR_EVENT_TYPES_H
5 * BabelTrace - CTF IR: Event Types
7 * Copyright 2013 EfficiOS Inc.
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
33 #include <babeltrace/ctf/events.h>
40 struct bt_ctf_event_class
;
42 struct bt_ctf_field_type
;
44 enum bt_ctf_integer_base
{
45 BT_CTF_INTEGER_BASE_UNKNOWN
= -1,
46 BT_CTF_INTEGER_BASE_BINARY
= 2,
47 BT_CTF_INTEGER_BASE_OCTAL
= 8,
48 BT_CTF_INTEGER_BASE_DECIMAL
= 10,
49 BT_CTF_INTEGER_BASE_HEXADECIMAL
= 16,
52 enum bt_ctf_byte_order
{
53 BT_CTF_BYTE_ORDER_NATIVE
= 0,
54 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
,
55 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
56 BT_CTF_BYTE_ORDER_NETWORK
,
60 * bt_ctf_field_type_integer_create: create an integer field type.
62 * Allocate a new integer field type of the given size. The creation of a field
63 * type sets its reference count to 1.
65 * @param size Integer field type size/length in bits.
67 * Returns an allocated field type on success, NULL on error.
69 extern struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(
73 * bt_ctf_field_type_integer_set_signed: set an integer type's signedness.
75 * Set an integer type's signedness attribute.
77 * @param integer Integer type.
78 * @param is_signed Integer's signedness, defaults to FALSE.
80 * Returns 0 on success, a negative value on error.
82 extern int bt_ctf_field_type_integer_set_signed(
83 struct bt_ctf_field_type
*integer
, int is_signed
);
86 * bt_ctf_field_type_integer_set_base: set an integer type's base.
88 * Set an integer type's base used to pretty-print the resulting trace.
90 * @param integer Integer type.
91 * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL.
93 * Returns 0 on success, a negative value on error.
95 extern int bt_ctf_field_type_integer_set_base(
96 struct bt_ctf_field_type
*integer
,
97 enum bt_ctf_integer_base base
);
100 * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding.
102 * An integer encoding may be set to signal that the integer must be printed as
105 * @param integer Integer type.
106 * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE
108 * Returns 0 on success, a negative value on error.
110 extern int bt_ctf_field_type_integer_set_encoding(
111 struct bt_ctf_field_type
*integer
,
112 enum ctf_string_encoding encoding
);
115 * bt_ctf_field_type_enumeration_create: create an enumeration field type.
117 * Allocate a new enumeration field type with the given underlying type. The
118 * creation of a field type sets its reference count to 1.
119 * The resulting enumeration will share the integer_container_type's ownership
120 * by increasing its reference count.
122 * @param integer_container_type Underlying integer type of the enumeration
125 * Returns an allocated field type on success, NULL on error.
127 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
128 struct bt_ctf_field_type
*integer_container_type
);
131 * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping.
133 * Add a mapping to the enumeration. The range's values are inclusive.
135 * @param enumeration Enumeration type.
136 * @param string Enumeration mapping name (will be copied).
137 * @param range_start Enumeration mapping range start.
138 * @param range_end Enumeration mapping range end.
140 * Returns 0 on success, a negative value on error.
142 extern int bt_ctf_field_type_enumeration_add_mapping(
143 struct bt_ctf_field_type
*enumeration
, const char *string
,
144 int64_t range_start
, int64_t range_end
);
147 * bt_ctf_field_type_floating_point_create: create a floating point field type.
149 * Allocate a new floating point field type. The creation of a field type sets
150 * its reference count to 1.
152 * Returns an allocated field type on success, NULL on error.
154 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
157 * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit
160 * Set the number of exponent digits to use to store the floating point field.
161 * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG.
163 * @param floating_point Floating point type.
164 * @param exponent_digits Number of digits to allocate to the exponent (defaults
167 * Returns 0 on success, a negative value on error.
169 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
170 struct bt_ctf_field_type
*floating_point
,
171 unsigned int exponent_digits
);
174 * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit
177 * Set the number of mantissa digits to use to store the floating point field.
178 * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG.
180 * @param floating_point Floating point type.
181 * @param mantissa_digits Number of digits to allocate to the mantissa (defaults
184 * Returns 0 on success, a negative value on error.
186 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
187 struct bt_ctf_field_type
*floating_point
,
188 unsigned int mantissa_digits
);
191 * bt_ctf_field_type_structure_create: create a structure field type.
193 * Allocate a new structure field type. The creation of a field type sets
194 * its reference count to 1.
196 * Returns an allocated field type on success, NULL on error.
198 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
201 * bt_ctf_field_type_structure_add_field: add a field to a structure.
203 * Add a field of type "field_type" to the structure. The structure will share
204 * field_type's ownership by increasing its reference count.
206 * @param structure Structure type.
207 * @param field_type Type of the field to add to the structure type.
208 * @param field_name Name of the structure's new field (will be copied).
210 * Returns 0 on success, a negative value on error.
212 extern int bt_ctf_field_type_structure_add_field(
213 struct bt_ctf_field_type
*structure
,
214 struct bt_ctf_field_type
*field_type
,
215 const char *field_name
);
218 * bt_ctf_field_type_variant_create: create a variant field type.
220 * Allocate a new variant field type. The creation of a field type sets
221 * its reference count to 1. tag_name must be the name of an enumeration
222 * field declared in the same scope as this variant.
224 * @param enum_tag Type of the variant's tag/selector (must be an enumeration).
225 * @param tag_name Name of the variant's tag/selector field (will be copied).
227 * Returns an allocated field type on success, NULL on error.
229 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
230 struct bt_ctf_field_type
*enum_tag
,
231 const char *tag_name
);
234 * bt_ctf_field_type_variant_add_field: add a field to a variant.
236 * Add a field of type "field_type" to the variant.The variant will share
237 * field_type's ownership by increasing its reference count. The "field_name"
238 * will be copied. field_name must match a mapping in the tag/selector
241 * @param variant Variant type.
242 * @param field_type Type of the variant type's new field.
243 * @param field_name Name of the variant type's new field (will be copied).
245 * Returns 0 on success, a negative value on error.
247 extern int bt_ctf_field_type_variant_add_field(
248 struct bt_ctf_field_type
*variant
,
249 struct bt_ctf_field_type
*field_type
,
250 const char *field_name
);
253 * bt_ctf_field_type_array_create: create an array field type.
255 * Allocate a new array field type. The creation of a field type sets
256 * its reference count to 1.
258 * @param element_type Array's element type.
259 * @oaram length Array type's length.
261 * Returns an allocated field type on success, NULL on error.
263 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
264 struct bt_ctf_field_type
*element_type
,
265 unsigned int length
);
268 * bt_ctf_field_type_sequence_create: create a sequence field type.
270 * Allocate a new sequence field type. The creation of a field type sets
271 * its reference count to 1. "length_field_name" must match an integer field
272 * declared in the same scope.
274 * @param element_type Sequence's element type.
275 * @param length_field_name Name of the sequence's length field (will be
278 * Returns an allocated field type on success, NULL on error.
280 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
281 struct bt_ctf_field_type
*element_type
,
282 const char *length_field_name
);
285 * bt_ctf_field_type_string_create: create a string field type.
287 * Allocate a new string field type. The creation of a field type sets
288 * its reference count to 1.
290 * Returns an allocated field type on success, NULL on error.
292 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
295 * bt_ctf_field_type_string_set_encoding: set a string type's encoding.
297 * Set the string type's encoding.
299 * @param string String type.
300 * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII.
301 * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8.
303 * Returns 0 on success, a negative value on error.
305 extern int bt_ctf_field_type_string_set_encoding(
306 struct bt_ctf_field_type
*string
,
307 enum ctf_string_encoding encoding
);
310 * bt_ctf_field_type_set_alignment: set a field type's alignment.
312 * Set the field type's alignment.
314 * @param type Field type.
315 * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However,
316 * some types, such as structures and string, may impose other alignment
319 * Returns 0 on success, a negative value on error.
321 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
322 unsigned int alignment
);
325 * bt_ctf_field_type_set_byte_order: set a field type's byte order.
327 * Set the field type's byte order.
329 * @param type Field type.
330 * @param byte_order Field type's byte order. Defaults to
331 * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness.
333 * Returns 0 on success, a negative value on error.
335 extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
336 enum bt_ctf_byte_order byte_order
);
339 * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
340 * the field type's reference count.
342 * These functions ensure that the field type won't be destroyed while it
343 * is in use. The same number of get and put (plus one extra put to
344 * release the initial reference done at creation) have to be done to
345 * destroy a field type.
347 * When the field type's reference count is decremented to 0 by a
348 * bt_ctf_field_type_put, the field type is freed.
350 * @param type Field type.
352 extern void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
);
353 extern void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
);
359 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */