1 #ifndef BABELTRACE_CTF_WRITER_EVENT_TYPES_H
2 #define BABELTRACE_CTF_WRITER_EVENT_TYPES_H
5 * BabelTrace - CTF Writer: 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-writer/writer.h>
34 #include <babeltrace/ctf/events.h>
41 struct bt_ctf_event_class
;
43 struct bt_ctf_field_type
;
45 enum bt_ctf_integer_base
{
46 BT_CTF_INTEGER_BASE_UNKNOWN
= -1,
47 BT_CTF_INTEGER_BASE_BINARY
= 2,
48 BT_CTF_INTEGER_BASE_OCTAL
= 8,
49 BT_CTF_INTEGER_BASE_DECIMAL
= 10,
50 BT_CTF_INTEGER_BASE_HEXADECIMAL
= 16,
54 * bt_ctf_field_type_integer_create: create an integer field type.
56 * Allocate a new integer field type of the given size. The creation of a field
57 * type sets its reference count to 1.
59 * @param size Integer field type size/length in bits.
61 * Returns an allocated field type on success, NULL on error.
63 extern struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(
67 * bt_ctf_field_type_integer_set_signed: set an integer type's signedness.
69 * Set an integer type's signedness attribute.
71 * @param integer Integer type.
72 * @param is_signed Integer's signedness, defaults to FALSE.
74 * Returns 0 on success, a negative value on error.
76 extern int bt_ctf_field_type_integer_set_signed(
77 struct bt_ctf_field_type
*integer
, int is_signed
);
80 * bt_ctf_field_type_integer_set_base: set an integer type's base.
82 * Set an integer type's base used to pretty-print the resulting trace.
84 * @param integer Integer type.
85 * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL.
87 * Returns 0 on success, a negative value on error.
89 extern int bt_ctf_field_type_integer_set_base(
90 struct bt_ctf_field_type
*integer
,
91 enum bt_ctf_integer_base base
);
94 * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding.
96 * An integer encoding may be set to signal that the integer must be printed as
99 * @param integer Integer type.
100 * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE
102 * Returns 0 on success, a negative value on error.
104 extern int bt_ctf_field_type_integer_set_encoding(
105 struct bt_ctf_field_type
*integer
,
106 enum ctf_string_encoding encoding
);
109 * bt_ctf_field_type_enumeration_create: create an enumeration field type.
111 * Allocate a new enumeration field type with the given underlying type. The
112 * creation of a field type sets its reference count to 1.
113 * The resulting enumeration will share the integer_container_type's ownership
114 * by increasing its reference count.
116 * @param integer_container_type Underlying integer type of the enumeration
119 * Returns an allocated field type on success, NULL on error.
121 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
122 struct bt_ctf_field_type
*integer_container_type
);
125 * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping.
127 * Add a mapping to the enumeration. The range's values are inclusive.
129 * @param enumeration Enumeration type.
130 * @param string Enumeration mapping name (will be copied).
131 * @param range_start Enumeration mapping range start.
132 * @param range_end Enumeration mapping range end.
134 * Returns 0 on success, a negative value on error.
136 extern int bt_ctf_field_type_enumeration_add_mapping(
137 struct bt_ctf_field_type
*enumeration
, const char *string
,
138 int64_t range_start
, int64_t range_end
);
141 * bt_ctf_field_type_floating_point_create: create a floating point field type.
143 * Allocate a new floating point field type. The creation of a field type sets
144 * its reference count to 1.
146 * Returns an allocated field type on success, NULL on error.
148 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
151 * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit
154 * Set the number of exponent digits to use to store the floating point field.
155 * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG.
157 * @param floating_point Floating point type.
158 * @param exponent_digits Number of digits to allocate to the exponent (defaults
161 * Returns 0 on success, a negative value on error.
163 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
164 struct bt_ctf_field_type
*floating_point
,
165 unsigned int exponent_digits
);
168 * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit
171 * Set the number of mantissa digits to use to store the floating point field.
172 * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG.
174 * @param floating_point Floating point type.
175 * @param mantissa_digits Number of digits to allocate to the mantissa (defaults
178 * Returns 0 on success, a negative value on error.
180 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
181 struct bt_ctf_field_type
*floating_point
,
182 unsigned int mantissa_digits
);
185 * bt_ctf_field_type_structure_create: create a structure field type.
187 * Allocate a new structure field type. The creation of a field type sets
188 * its reference count to 1.
190 * Returns an allocated field type on success, NULL on error.
192 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
195 * bt_ctf_field_type_structure_add_field: add a field to a structure.
197 * Add a field of type "field_type" to the structure. The structure will share
198 * field_type's ownership by increasing its reference count.
200 * @param structure Structure type.
201 * @param field_type Type of the field to add to the structure type.
202 * @param field_name Name of the structure's new field (will be copied).
204 * Returns 0 on success, a negative value on error.
206 extern int bt_ctf_field_type_structure_add_field(
207 struct bt_ctf_field_type
*structure
,
208 struct bt_ctf_field_type
*field_type
,
209 const char *field_name
);
212 * bt_ctf_field_type_variant_create: create a variant field type.
214 * Allocate a new variant field type. The creation of a field type sets
215 * its reference count to 1. tag_name must be the name of an enumeration
216 * field declared in the same scope as this variant.
218 * @param enum_tag Type of the variant's tag/selector (must be an enumeration).
219 * @param tag_name Name of the variant's tag/selector field (will be copied).
221 * Returns an allocated field type on success, NULL on error.
223 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
224 struct bt_ctf_field_type
*enum_tag
,
225 const char *tag_name
);
228 * bt_ctf_field_type_variant_add_field: add a field to a variant.
230 * Add a field of type "field_type" to the variant.The variant will share
231 * field_type's ownership by increasing its reference count. The "field_name"
232 * will be copied. field_name must match a mapping in the tag/selector
235 * @param variant Variant type.
236 * @param field_type Type of the variant type's new field.
237 * @param field_name Name of the variant type's new field (will be copied).
239 * Returns 0 on success, a negative value on error.
241 extern int bt_ctf_field_type_variant_add_field(
242 struct bt_ctf_field_type
*variant
,
243 struct bt_ctf_field_type
*field_type
,
244 const char *field_name
);
247 * bt_ctf_field_type_array_create: create an array field type.
249 * Allocate a new array field type. The creation of a field type sets
250 * its reference count to 1.
252 * @param element_type Array's element type.
253 * @oaram length Array type's length.
255 * Returns an allocated field type on success, NULL on error.
257 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
258 struct bt_ctf_field_type
*element_type
,
259 unsigned int length
);
262 * bt_ctf_field_type_sequence_create: create a sequence field type.
264 * Allocate a new sequence field type. The creation of a field type sets
265 * its reference count to 1. "length_field_name" must match an integer field
266 * declared in the same scope.
268 * @param element_type Sequence's element type.
269 * @param length_field_name Name of the sequence's length field (will be
272 * Returns an allocated field type on success, NULL on error.
274 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
275 struct bt_ctf_field_type
*element_type
,
276 const char *length_field_name
);
279 * bt_ctf_field_type_string_create: create a string field type.
281 * Allocate a new string field type. The creation of a field type sets
282 * its reference count to 1.
284 * Returns an allocated field type on success, NULL on error.
286 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
289 * bt_ctf_field_type_string_set_encoding: set a string type's encoding.
291 * Set the string type's encoding.
293 * @param string String type.
294 * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII.
295 * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8.
297 * Returns 0 on success, a negative value on error.
299 extern int bt_ctf_field_type_string_set_encoding(
300 struct bt_ctf_field_type
*string
,
301 enum ctf_string_encoding encoding
);
304 * bt_ctf_field_type_set_alignment: set a field type's alignment.
306 * Set the field type's alignment.
308 * @param type Field type.
309 * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However,
310 * some types, such as structures and string, may impose other alignment
313 * Returns 0 on success, a negative value on error.
315 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
316 unsigned int alignment
);
319 * bt_ctf_field_type_set_byte_order: set a field type's byte order.
321 * Set the field type's byte order.
323 * @param type Field type.
324 * @param byte_order Field type's byte order. Defaults to
325 * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness.
327 * Returns 0 on success, a negative value on error.
329 extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
330 enum bt_ctf_byte_order byte_order
);
333 * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
334 * the field type's reference count.
336 * These functions ensure that the field type won't be destroyed while it
337 * is in use. The same number of get and put (plus one extra put to
338 * release the initial reference done at creation) have to be done to
339 * destroy a field type.
341 * When the field type's reference count is decremented to 0 by a
342 * bt_ctf_field_type_put, the field type is freed.
344 * @param type Field type.
346 extern void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
);
347 extern void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
);
353 #endif /* BABELTRACE_CTF_WRITER_EVENT_TYPES_H */