Commit | Line | Data |
---|---|---|
adc315b8 JG |
1 | #ifndef BABELTRACE_CTF_IR_EVENT_TYPES_H |
2 | #define BABELTRACE_CTF_IR_EVENT_TYPES_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - CTF IR: Event Types | |
6 | * | |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
adc315b8 JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
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: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
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 | |
27 | * SOFTWARE. | |
28 | * | |
29 | * The Common Trace Format (CTF) Specification is available at | |
30 | * http://www.efficios.com/ctf | |
31 | */ | |
32 | ||
33 | #include <babeltrace/ctf/events.h> | |
34 | #include <stdint.h> | |
35 | ||
36 | #ifdef __cplusplus | |
37 | extern "C" { | |
38 | #endif | |
39 | ||
40 | struct bt_ctf_event_class; | |
41 | struct bt_ctf_event; | |
42 | struct bt_ctf_field_type; | |
43 | ||
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, | |
50 | }; | |
51 | ||
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, | |
57 | }; | |
58 | ||
59 | /* | |
60 | * bt_ctf_field_type_integer_create: create an integer field type. | |
61 | * | |
62 | * Allocate a new integer field type of the given size. The creation of a field | |
63 | * type sets its reference count to 1. | |
64 | * | |
65 | * @param size Integer field type size/length in bits. | |
66 | * | |
67 | * Returns an allocated field type on success, NULL on error. | |
68 | */ | |
69 | extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( | |
70 | unsigned int size); | |
71 | ||
72 | /* | |
73 | * bt_ctf_field_type_integer_set_signed: set an integer type's signedness. | |
74 | * | |
75 | * Set an integer type's signedness attribute. | |
76 | * | |
77 | * @param integer Integer type. | |
78 | * @param is_signed Integer's signedness, defaults to FALSE. | |
79 | * | |
80 | * Returns 0 on success, a negative value on error. | |
81 | */ | |
82 | extern int bt_ctf_field_type_integer_set_signed( | |
83 | struct bt_ctf_field_type *integer, int is_signed); | |
84 | ||
85 | /* | |
86 | * bt_ctf_field_type_integer_set_base: set an integer type's base. | |
87 | * | |
88 | * Set an integer type's base used to pretty-print the resulting trace. | |
89 | * | |
90 | * @param integer Integer type. | |
91 | * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL. | |
92 | * | |
93 | * Returns 0 on success, a negative value on error. | |
94 | */ | |
2c4a0758 | 95 | extern int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, |
adc315b8 JG |
96 | enum bt_ctf_integer_base base); |
97 | ||
98 | /* | |
99 | * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding. | |
100 | * | |
101 | * An integer encoding may be set to signal that the integer must be printed as | |
102 | * a text character. | |
103 | * | |
104 | * @param integer Integer type. | |
105 | * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE | |
106 | * | |
107 | * Returns 0 on success, a negative value on error. | |
108 | */ | |
109 | extern int bt_ctf_field_type_integer_set_encoding( | |
110 | struct bt_ctf_field_type *integer, | |
111 | enum ctf_string_encoding encoding); | |
112 | ||
113 | /* | |
114 | * bt_ctf_field_type_enumeration_create: create an enumeration field type. | |
115 | * | |
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. | |
120 | * | |
121 | * @param integer_container_type Underlying integer type of the enumeration | |
122 | * type. | |
123 | * | |
124 | * Returns an allocated field type on success, NULL on error. | |
125 | */ | |
126 | extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( | |
127 | struct bt_ctf_field_type *integer_container_type); | |
128 | ||
129 | /* | |
130 | * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping. | |
131 | * | |
132 | * Add a mapping to the enumeration. The range's values are inclusive. | |
133 | * | |
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. | |
138 | * | |
139 | * Returns 0 on success, a negative value on error. | |
140 | */ | |
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); | |
144 | ||
145 | /* | |
146 | * bt_ctf_field_type_floating_point_create: create a floating point field type. | |
147 | * | |
148 | * Allocate a new floating point field type. The creation of a field type sets | |
149 | * its reference count to 1. | |
150 | * | |
151 | * Returns an allocated field type on success, NULL on error. | |
152 | */ | |
153 | extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); | |
154 | ||
155 | /* | |
156 | * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit | |
157 | * count. | |
158 | * | |
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. | |
161 | * | |
162 | * @param floating_point Floating point type. | |
163 | * @param exponent_digits Number of digits to allocate to the exponent (defaults | |
164 | * to FLT_EXP_DIG). | |
165 | * | |
166 | * Returns 0 on success, a negative value on error. | |
167 | */ | |
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); | |
171 | ||
172 | /* | |
173 | * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit | |
174 | * count. | |
175 | * | |
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. | |
178 | * | |
179 | * @param floating_point Floating point type. | |
180 | * @param mantissa_digits Number of digits to allocate to the mantissa (defaults | |
181 | * to FLT_MANT_DIG). | |
182 | * | |
183 | * Returns 0 on success, a negative value on error. | |
184 | */ | |
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); | |
188 | ||
189 | /* | |
190 | * bt_ctf_field_type_structure_create: create a structure field type. | |
191 | * | |
192 | * Allocate a new structure field type. The creation of a field type sets | |
193 | * its reference count to 1. | |
194 | * | |
195 | * Returns an allocated field type on success, NULL on error. | |
196 | */ | |
197 | extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); | |
198 | ||
199 | /* | |
200 | * bt_ctf_field_type_structure_add_field: add a field to a structure. | |
201 | * | |
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. | |
204 | * | |
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). | |
208 | * | |
209 | * Returns 0 on success, a negative value on error. | |
210 | */ | |
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); | |
215 | ||
216 | /* | |
217 | * bt_ctf_field_type_variant_create: create a variant field type. | |
218 | * | |
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. | |
222 | * | |
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). | |
225 | * | |
226 | * Returns an allocated field type on success, NULL on error. | |
227 | */ | |
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); | |
231 | ||
232 | /* | |
233 | * bt_ctf_field_type_variant_add_field: add a field to a variant. | |
234 | * | |
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 | |
238 | * enumeration. | |
239 | * | |
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). | |
243 | * | |
244 | * Returns 0 on success, a negative value on error. | |
245 | */ | |
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); | |
250 | ||
251 | /* | |
252 | * bt_ctf_field_type_array_create: create an array field type. | |
253 | * | |
254 | * Allocate a new array field type. The creation of a field type sets | |
255 | * its reference count to 1. | |
256 | * | |
257 | * @param element_type Array's element type. | |
258 | * @oaram length Array type's length. | |
259 | * | |
260 | * Returns an allocated field type on success, NULL on error. | |
261 | */ | |
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); | |
265 | ||
266 | /* | |
267 | * bt_ctf_field_type_sequence_create: create a sequence field type. | |
268 | * | |
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. | |
272 | * | |
273 | * @param element_type Sequence's element type. | |
274 | * @param length_field_name Name of the sequence's length field (will be | |
275 | * copied). | |
276 | * | |
277 | * Returns an allocated field type on success, NULL on error. | |
278 | */ | |
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); | |
282 | ||
283 | /* | |
284 | * bt_ctf_field_type_string_create: create a string field type. | |
285 | * | |
286 | * Allocate a new string field type. The creation of a field type sets | |
287 | * its reference count to 1. | |
288 | * | |
289 | * Returns an allocated field type on success, NULL on error. | |
290 | */ | |
291 | extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); | |
292 | ||
293 | /* | |
294 | * bt_ctf_field_type_string_set_encoding: set a string type's encoding. | |
295 | * | |
296 | * Set the string type's encoding. | |
297 | * | |
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. | |
301 | * | |
302 | * Returns 0 on success, a negative value on error. | |
303 | */ | |
304 | extern int bt_ctf_field_type_string_set_encoding( | |
305 | struct bt_ctf_field_type *string, | |
306 | enum ctf_string_encoding encoding); | |
307 | ||
308 | /* | |
309 | * bt_ctf_field_type_set_alignment: set a field type's alignment. | |
310 | * | |
311 | * Set the field type's alignment. | |
312 | * | |
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 | |
316 | * constraints. | |
317 | * | |
318 | * Returns 0 on success, a negative value on error. | |
319 | */ | |
320 | extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, | |
321 | unsigned int alignment); | |
322 | ||
323 | /* | |
324 | * bt_ctf_field_type_set_byte_order: set a field type's byte order. | |
325 | * | |
326 | * Set the field type's byte order. | |
327 | * | |
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. | |
331 | * | |
332 | * Returns 0 on success, a negative value on error. | |
333 | */ | |
334 | extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, | |
335 | enum bt_ctf_byte_order byte_order); | |
336 | ||
337 | /* | |
338 | * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement | |
339 | * the field type's reference count. | |
340 | * | |
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. | |
345 | * | |
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. | |
348 | * | |
349 | * @param type Field type. | |
350 | */ | |
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); | |
353 | ||
354 | #ifdef __cplusplus | |
355 | } | |
356 | #endif | |
357 | ||
358 | #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */ |