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, 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
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(struct bt_ctf_field_type
*integer
,
96 enum bt_ctf_integer_base base
);
99 * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding.
101 * An integer encoding may be set to signal that the integer must be printed as
104 * @param integer Integer type.
105 * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE
107 * Returns 0 on success, a negative value on error.
109 extern int bt_ctf_field_type_integer_set_encoding(
110 struct bt_ctf_field_type
*integer
,
111 enum ctf_string_encoding encoding
);
114 * bt_ctf_field_type_enumeration_create: create an enumeration field type.
116 * Allocate a new enumeration field type with the given underlying type. The
117 * creation of a field type sets its reference count to 1.
118 * The resulting enumeration will share the integer_container_type's ownership
119 * by increasing its reference count.
121 * @param integer_container_type Underlying integer type of the enumeration
124 * Returns an allocated field type on success, NULL on error.
126 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
127 struct bt_ctf_field_type
*integer_container_type
);
130 * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping.
132 * Add a mapping to the enumeration. The range's values are inclusive.
134 * @param enumeration Enumeration type.
135 * @param string Enumeration mapping name (will be copied).
136 * @param range_start Enumeration mapping range start.
137 * @param range_end Enumeration mapping range end.
139 * Returns 0 on success, a negative value on error.
141 extern int bt_ctf_field_type_enumeration_add_mapping(
142 struct bt_ctf_field_type
*enumeration
, const char *string
,
143 int64_t range_start
, int64_t range_end
);
146 * bt_ctf_field_type_floating_point_create: create a floating point field type.
148 * Allocate a new floating point field type. The creation of a field type sets
149 * its reference count to 1.
151 * Returns an allocated field type on success, NULL on error.
153 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
156 * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit
159 * Set the number of exponent digits to use to store the floating point field.
160 * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG.
162 * @param floating_point Floating point type.
163 * @param exponent_digits Number of digits to allocate to the exponent (defaults
166 * Returns 0 on success, a negative value on error.
168 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
169 struct bt_ctf_field_type
*floating_point
,
170 unsigned int exponent_digits
);
173 * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit
176 * Set the number of mantissa digits to use to store the floating point field.
177 * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG.
179 * @param floating_point Floating point type.
180 * @param mantissa_digits Number of digits to allocate to the mantissa (defaults
183 * Returns 0 on success, a negative value on error.
185 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
186 struct bt_ctf_field_type
*floating_point
,
187 unsigned int mantissa_digits
);
190 * bt_ctf_field_type_structure_create: create a structure field type.
192 * Allocate a new structure field type. The creation of a field type sets
193 * its reference count to 1.
195 * Returns an allocated field type on success, NULL on error.
197 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
200 * bt_ctf_field_type_structure_add_field: add a field to a structure.
202 * Add a field of type "field_type" to the structure. The structure will share
203 * field_type's ownership by increasing its reference count.
205 * @param structure Structure type.
206 * @param field_type Type of the field to add to the structure type.
207 * @param field_name Name of the structure's new field (will be copied).
209 * Returns 0 on success, a negative value on error.
211 extern int bt_ctf_field_type_structure_add_field(
212 struct bt_ctf_field_type
*structure
,
213 struct bt_ctf_field_type
*field_type
,
214 const char *field_name
);
217 * bt_ctf_field_type_variant_create: create a variant field type.
219 * Allocate a new variant field type. The creation of a field type sets
220 * its reference count to 1. tag_name must be the name of an enumeration
221 * field declared in the same scope as this variant.
223 * @param enum_tag Type of the variant's tag/selector (must be an enumeration).
224 * @param tag_name Name of the variant's tag/selector field (will be copied).
226 * Returns an allocated field type on success, NULL on error.
228 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
229 struct bt_ctf_field_type
*enum_tag
,
230 const char *tag_name
);
233 * bt_ctf_field_type_variant_add_field: add a field to a variant.
235 * Add a field of type "field_type" to the variant.The variant will share
236 * field_type's ownership by increasing its reference count. The "field_name"
237 * will be copied. field_name must match a mapping in the tag/selector
240 * @param variant Variant type.
241 * @param field_type Type of the variant type's new field.
242 * @param field_name Name of the variant type's new field (will be copied).
244 * Returns 0 on success, a negative value on error.
246 extern int bt_ctf_field_type_variant_add_field(
247 struct bt_ctf_field_type
*variant
,
248 struct bt_ctf_field_type
*field_type
,
249 const char *field_name
);
252 * bt_ctf_field_type_array_create: create an array field type.
254 * Allocate a new array field type. The creation of a field type sets
255 * its reference count to 1.
257 * @param element_type Array's element type.
258 * @oaram length Array type's length.
260 * Returns an allocated field type on success, NULL on error.
262 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
263 struct bt_ctf_field_type
*element_type
,
264 unsigned int length
);
267 * bt_ctf_field_type_sequence_create: create a sequence field type.
269 * Allocate a new sequence field type. The creation of a field type sets
270 * its reference count to 1. "length_field_name" must match an integer field
271 * declared in the same scope.
273 * @param element_type Sequence's element type.
274 * @param length_field_name Name of the sequence's length field (will be
277 * Returns an allocated field type on success, NULL on error.
279 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
280 struct bt_ctf_field_type
*element_type
,
281 const char *length_field_name
);
284 * bt_ctf_field_type_string_create: create a string field type.
286 * Allocate a new string field type. The creation of a field type sets
287 * its reference count to 1.
289 * Returns an allocated field type on success, NULL on error.
291 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
294 * bt_ctf_field_type_string_set_encoding: set a string type's encoding.
296 * Set the string type's encoding.
298 * @param string String type.
299 * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII.
300 * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8.
302 * Returns 0 on success, a negative value on error.
304 extern int bt_ctf_field_type_string_set_encoding(
305 struct bt_ctf_field_type
*string
,
306 enum ctf_string_encoding encoding
);
309 * bt_ctf_field_type_set_alignment: set a field type's alignment.
311 * Set the field type's alignment.
313 * @param type Field type.
314 * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However,
315 * some types, such as structures and string, may impose other alignment
318 * Returns 0 on success, a negative value on error.
320 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
321 unsigned int alignment
);
324 * bt_ctf_field_type_set_byte_order: set a field type's byte order.
326 * Set the field type's byte order.
328 * @param type Field type.
329 * @param byte_order Field type's byte order. Defaults to
330 * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness.
332 * Returns 0 on success, a negative value on error.
334 extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
335 enum bt_ctf_byte_order byte_order
);
338 * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
339 * the field type's reference count.
341 * These functions ensure that the field type won't be destroyed while it
342 * is in use. The same number of get and put (plus one extra put to
343 * release the initial reference done at creation) have to be done to
344 * destroy a field type.
346 * When the field type's reference count is decremented to 0 by a
347 * bt_ctf_field_type_put, the field type is freed.
349 * @param type Field type.
351 extern void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
);
352 extern void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
);
358 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */