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; | |
b92ddaaa | 43 | struct bt_ctf_field; |
adc315b8 JG |
44 | |
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, | |
51 | }; | |
52 | ||
53 | enum bt_ctf_byte_order { | |
b92ddaaa | 54 | BT_CTF_BYTE_ORDER_UNKNOWN = -1, |
c35a1669 JG |
55 | /* |
56 | * Note that native, in the context of the CTF specification, is defined as | |
57 | * "the byte order described in the trace" and does not mean that the host's | |
58 | * endianness will be used. | |
59 | */ | |
adc315b8 JG |
60 | BT_CTF_BYTE_ORDER_NATIVE = 0, |
61 | BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, | |
62 | BT_CTF_BYTE_ORDER_BIG_ENDIAN, | |
63 | BT_CTF_BYTE_ORDER_NETWORK, | |
64 | }; | |
65 | ||
66 | /* | |
67 | * bt_ctf_field_type_integer_create: create an integer field type. | |
68 | * | |
69 | * Allocate a new integer field type of the given size. The creation of a field | |
0ce5791b | 70 | * type sets its reference count to 1. |
adc315b8 JG |
71 | * |
72 | * @param size Integer field type size/length in bits. | |
73 | * | |
74 | * Returns an allocated field type on success, NULL on error. | |
75 | */ | |
76 | extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( | |
77 | unsigned int size); | |
78 | ||
b92ddaaa JG |
79 | /* |
80 | * bt_ctf_field_type_integer_get_size: get an integer type's size. | |
81 | * | |
82 | * Get an integer type's size. | |
83 | * | |
84 | * @param integer Integer type. | |
85 | * | |
86 | * Returns the integer type's size, a negative value on error. | |
87 | */ | |
88 | extern int bt_ctf_field_type_integer_get_size( | |
89 | struct bt_ctf_field_type *integer); | |
90 | ||
91 | /* | |
92 | * bt_ctf_field_type_integer_get_signed: get an integer type's signedness. | |
93 | * | |
94 | * Get an integer type's signedness attribute. | |
95 | * | |
96 | * @param integer Integer type. | |
97 | * | |
98 | * Returns the integer's signedness, a negative value on error. | |
99 | */ | |
100 | extern int bt_ctf_field_type_integer_get_signed( | |
101 | struct bt_ctf_field_type *integer); | |
102 | ||
adc315b8 JG |
103 | /* |
104 | * bt_ctf_field_type_integer_set_signed: set an integer type's signedness. | |
105 | * | |
106 | * Set an integer type's signedness attribute. | |
107 | * | |
108 | * @param integer Integer type. | |
109 | * @param is_signed Integer's signedness, defaults to FALSE. | |
110 | * | |
111 | * Returns 0 on success, a negative value on error. | |
112 | */ | |
113 | extern int bt_ctf_field_type_integer_set_signed( | |
114 | struct bt_ctf_field_type *integer, int is_signed); | |
115 | ||
b92ddaaa JG |
116 | /* |
117 | * bt_ctf_field_type_integer_get_base: get an integer type's base. | |
118 | * | |
119 | * Get an integer type's base used to pretty-print the resulting trace. | |
120 | * | |
121 | * @param integer Integer type. | |
122 | * | |
123 | * Returns the integer type's base on success, BT_CTF_INTEGER_BASE_UNKNOWN on | |
124 | * error. | |
125 | */ | |
126 | extern enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( | |
127 | struct bt_ctf_field_type *integer); | |
128 | ||
adc315b8 JG |
129 | /* |
130 | * bt_ctf_field_type_integer_set_base: set an integer type's base. | |
131 | * | |
132 | * Set an integer type's base used to pretty-print the resulting trace. | |
133 | * | |
134 | * @param integer Integer type. | |
135 | * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL. | |
136 | * | |
137 | * Returns 0 on success, a negative value on error. | |
138 | */ | |
2c4a0758 | 139 | extern int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, |
adc315b8 JG |
140 | enum bt_ctf_integer_base base); |
141 | ||
b92ddaaa JG |
142 | /* |
143 | * bt_ctf_field_type_integer_get_encoding: get an integer type's encoding. | |
144 | * | |
145 | * @param integer Integer type. | |
146 | * | |
147 | * Returns the string field's encoding on success, CTF_STRING_UNKNOWN on error. | |
148 | */ | |
149 | extern enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding( | |
150 | struct bt_ctf_field_type *integer); | |
151 | ||
adc315b8 JG |
152 | /* |
153 | * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding. | |
154 | * | |
155 | * An integer encoding may be set to signal that the integer must be printed as | |
156 | * a text character. | |
157 | * | |
158 | * @param integer Integer type. | |
159 | * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE | |
160 | * | |
161 | * Returns 0 on success, a negative value on error. | |
162 | */ | |
163 | extern int bt_ctf_field_type_integer_set_encoding( | |
164 | struct bt_ctf_field_type *integer, | |
165 | enum ctf_string_encoding encoding); | |
166 | ||
6cfb906f JG |
167 | /** |
168 | * bt_ctf_field_type_integer_get_mapped_clock: get an integer type's mapped clock. | |
169 | * | |
170 | * @param integer Integer type. | |
171 | * | |
172 | * Returns the integer's mapped clock (if any), NULL on error. | |
173 | */ | |
174 | extern struct bt_ctf_clock *bt_ctf_field_type_integer_get_mapped_clock( | |
175 | struct bt_ctf_field_type *integer); | |
176 | ||
177 | /** | |
178 | * bt_ctf_field_type_integer_set_mapped_clock: set an integer type's mapped clock. | |
179 | * | |
180 | * @param integer Integer type. | |
181 | * @param clock Clock to map. | |
182 | * | |
183 | * Returns 0 on success, a negative value on error. | |
184 | */ | |
185 | extern int bt_ctf_field_type_integer_set_mapped_clock( | |
186 | struct bt_ctf_field_type *integer, | |
187 | struct bt_ctf_clock *clock); | |
188 | ||
adc315b8 JG |
189 | /* |
190 | * bt_ctf_field_type_enumeration_create: create an enumeration field type. | |
191 | * | |
192 | * Allocate a new enumeration field type with the given underlying type. The | |
193 | * creation of a field type sets its reference count to 1. | |
194 | * The resulting enumeration will share the integer_container_type's ownership | |
195 | * by increasing its reference count. | |
196 | * | |
197 | * @param integer_container_type Underlying integer type of the enumeration | |
198 | * type. | |
199 | * | |
200 | * Returns an allocated field type on success, NULL on error. | |
201 | */ | |
202 | extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( | |
203 | struct bt_ctf_field_type *integer_container_type); | |
204 | ||
b92ddaaa JG |
205 | /* |
206 | * bt_ctf_field_type_enumeration_get_container_type: get underlying container. | |
207 | * | |
208 | * Get the enumeration type's underlying integer container type. | |
209 | * | |
210 | * @param enumeration Enumeration type. | |
211 | * | |
212 | * Returns an allocated field type on success, NULL on error. | |
213 | */ | |
214 | extern | |
215 | struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type( | |
216 | struct bt_ctf_field_type *enumeration); | |
217 | ||
adc315b8 JG |
218 | /* |
219 | * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping. | |
220 | * | |
221 | * Add a mapping to the enumeration. The range's values are inclusive. | |
222 | * | |
223 | * @param enumeration Enumeration type. | |
b92ddaaa | 224 | * @param name Enumeration mapping name (will be copied). |
adc315b8 JG |
225 | * @param range_start Enumeration mapping range start. |
226 | * @param range_end Enumeration mapping range end. | |
227 | * | |
228 | * Returns 0 on success, a negative value on error. | |
229 | */ | |
230 | extern int bt_ctf_field_type_enumeration_add_mapping( | |
b92ddaaa | 231 | struct bt_ctf_field_type *enumeration, const char *name, |
adc315b8 JG |
232 | int64_t range_start, int64_t range_end); |
233 | ||
b92ddaaa JG |
234 | /* |
235 | * bt_ctf_field_type_enumeration_add_mapping_unsigned: add an enumeration | |
236 | * mapping. | |
237 | * | |
238 | * Add a mapping to the enumeration. The range's values are inclusive. | |
239 | * | |
240 | * @param enumeration Enumeration type. | |
241 | * @param name Enumeration mapping name (will be copied). | |
242 | * @param range_start Enumeration mapping range start. | |
243 | * @param range_end Enumeration mapping range end. | |
244 | * | |
245 | * Returns 0 on success, a negative value on error. | |
246 | */ | |
247 | extern int bt_ctf_field_type_enumeration_add_mapping_unsigned( | |
248 | struct bt_ctf_field_type *enumeration, const char *name, | |
249 | uint64_t range_start, uint64_t range_end); | |
250 | ||
251 | /* | |
252 | * bt_ctf_field_type_enumeration_get_mapping_count: Get the number of mappings | |
253 | * defined in the enumeration. | |
254 | * | |
255 | * @param enumeration Enumeration type. | |
256 | * | |
257 | * Returns the mapping count on success, a negative value on error. | |
258 | */ | |
074ee56d | 259 | extern int bt_ctf_field_type_enumeration_get_mapping_count( |
b92ddaaa JG |
260 | struct bt_ctf_field_type *enumeration); |
261 | ||
262 | /* | |
263 | * bt_ctf_field_type_enumeration_get_mapping: get an enumeration mapping. | |
264 | * | |
265 | * @param enumeration Enumeration type. | |
266 | * @param index Index of mapping. | |
267 | * @param name Pointer where the mapping's name will be returned (valid for | |
268 | * the lifetime of the enumeration). | |
269 | * @param range_start Pointer where the enumeration mapping's range start will | |
270 | * be returned. | |
271 | * @param range_end Pointer where the enumeration mapping's range end will | |
272 | * be returned. | |
273 | * | |
274 | * Returns 0 on success, a negative value on error. | |
275 | */ | |
276 | extern int bt_ctf_field_type_enumeration_get_mapping( | |
074ee56d | 277 | struct bt_ctf_field_type *enumeration, int index, |
b92ddaaa JG |
278 | const char **name, int64_t *range_start, int64_t *range_end); |
279 | ||
280 | /* | |
281 | * bt_ctf_field_type_enumeration_get_mapping_unsigned: get a mapping. | |
282 | * | |
283 | * @param enumeration Enumeration type. | |
284 | * @param index Index of mapping. | |
285 | * @param name Pointer where the mapping's name will be returned (valid for | |
286 | * the lifetime of the enumeration). | |
287 | * @param range_start Pointer where the enumeration mapping's range start will | |
288 | * be returned. | |
289 | * @param range_end Pointer where the enumeration mapping's range end will | |
290 | * be returned. | |
291 | * | |
292 | * Returns 0 on success, a negative value on error. | |
293 | */ | |
294 | extern int bt_ctf_field_type_enumeration_get_mapping_unsigned( | |
074ee56d | 295 | struct bt_ctf_field_type *enumeration, int index, |
b92ddaaa JG |
296 | const char **name, uint64_t *range_start, |
297 | uint64_t *range_end); | |
298 | ||
299 | /* | |
300 | * bt_ctf_field_type_enumeration_get_mapping_index_by_name: get an enumerations' | |
301 | * mapping index by name. | |
302 | * | |
303 | * @param enumeration Enumeration type. | |
304 | * @param name Mapping name. | |
b92ddaaa | 305 | * |
074ee56d | 306 | * Returns mapping index on success, a negative value on error. |
b92ddaaa JG |
307 | */ |
308 | extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name( | |
074ee56d | 309 | struct bt_ctf_field_type *enumeration, const char *name); |
b92ddaaa JG |
310 | |
311 | /* | |
312 | * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an | |
313 | * enumerations' mapping index by value. | |
314 | * | |
315 | * @param enumeration Enumeration type. | |
316 | * @param value Value. | |
b92ddaaa | 317 | * |
074ee56d | 318 | * Returns mapping index on success, a negative value on error. |
b92ddaaa JG |
319 | */ |
320 | extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value( | |
074ee56d | 321 | struct bt_ctf_field_type *enumeration, int64_t value); |
b92ddaaa JG |
322 | |
323 | /* | |
324 | * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an | |
325 | * enumerations' mapping index by value. | |
326 | * | |
327 | * @param enumeration Enumeration type. | |
328 | * @param value Value. | |
b92ddaaa JG |
329 | * |
330 | * Returns 0 on success, a negative value on error. | |
331 | */ | |
332 | extern int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( | |
074ee56d | 333 | struct bt_ctf_field_type *enumeration, uint64_t value); |
b92ddaaa | 334 | |
adc315b8 JG |
335 | /* |
336 | * bt_ctf_field_type_floating_point_create: create a floating point field type. | |
337 | * | |
338 | * Allocate a new floating point field type. The creation of a field type sets | |
339 | * its reference count to 1. | |
340 | * | |
341 | * Returns an allocated field type on success, NULL on error. | |
342 | */ | |
343 | extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); | |
344 | ||
b92ddaaa JG |
345 | /* |
346 | * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit | |
347 | * count. | |
348 | * | |
349 | * @param floating_point Floating point type. | |
350 | * | |
351 | * Returns the exponent digit count on success, a negative value on error. | |
352 | */ | |
353 | extern int bt_ctf_field_type_floating_point_get_exponent_digits( | |
354 | struct bt_ctf_field_type *floating_point); | |
355 | ||
adc315b8 JG |
356 | /* |
357 | * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit | |
b92ddaaa | 358 | * count. |
adc315b8 JG |
359 | * |
360 | * Set the number of exponent digits to use to store the floating point field. | |
361 | * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG. | |
362 | * | |
363 | * @param floating_point Floating point type. | |
364 | * @param exponent_digits Number of digits to allocate to the exponent (defaults | |
365 | * to FLT_EXP_DIG). | |
366 | * | |
367 | * Returns 0 on success, a negative value on error. | |
368 | */ | |
369 | extern int bt_ctf_field_type_floating_point_set_exponent_digits( | |
370 | struct bt_ctf_field_type *floating_point, | |
371 | unsigned int exponent_digits); | |
372 | ||
373 | /* | |
b92ddaaa | 374 | * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit |
adc315b8 JG |
375 | * count. |
376 | * | |
b92ddaaa JG |
377 | * @param floating_point Floating point type. |
378 | * | |
379 | * Returns the mantissa digit count on success, a negative value on error. | |
380 | */ | |
381 | extern int bt_ctf_field_type_floating_point_get_mantissa_digits( | |
382 | struct bt_ctf_field_type *floating_point); | |
383 | ||
384 | /* | |
385 | * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit | |
386 | * count. | |
387 | * | |
adc315b8 JG |
388 | * Set the number of mantissa digits to use to store the floating point field. |
389 | * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG. | |
390 | * | |
391 | * @param floating_point Floating point type. | |
392 | * @param mantissa_digits Number of digits to allocate to the mantissa (defaults | |
393 | * to FLT_MANT_DIG). | |
394 | * | |
395 | * Returns 0 on success, a negative value on error. | |
396 | */ | |
397 | extern int bt_ctf_field_type_floating_point_set_mantissa_digits( | |
398 | struct bt_ctf_field_type *floating_point, | |
399 | unsigned int mantissa_digits); | |
400 | ||
401 | /* | |
402 | * bt_ctf_field_type_structure_create: create a structure field type. | |
403 | * | |
404 | * Allocate a new structure field type. The creation of a field type sets | |
405 | * its reference count to 1. | |
406 | * | |
407 | * Returns an allocated field type on success, NULL on error. | |
408 | */ | |
409 | extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); | |
410 | ||
411 | /* | |
412 | * bt_ctf_field_type_structure_add_field: add a field to a structure. | |
413 | * | |
414 | * Add a field of type "field_type" to the structure. The structure will share | |
415 | * field_type's ownership by increasing its reference count. | |
416 | * | |
417 | * @param structure Structure type. | |
418 | * @param field_type Type of the field to add to the structure type. | |
419 | * @param field_name Name of the structure's new field (will be copied). | |
420 | * | |
421 | * Returns 0 on success, a negative value on error. | |
422 | */ | |
423 | extern int bt_ctf_field_type_structure_add_field( | |
424 | struct bt_ctf_field_type *structure, | |
425 | struct bt_ctf_field_type *field_type, | |
426 | const char *field_name); | |
427 | ||
b92ddaaa JG |
428 | /* |
429 | * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined | |
430 | * in the structure. | |
431 | * | |
432 | * @param structure Structure type. | |
433 | * | |
434 | * Returns the field count on success, a negative value on error. | |
435 | */ | |
074ee56d | 436 | extern int bt_ctf_field_type_structure_get_field_count( |
b92ddaaa JG |
437 | struct bt_ctf_field_type *structure); |
438 | ||
439 | /* | |
440 | * bt_ctf_field_type_structure_get_field: get a structure's field type and name. | |
441 | * | |
442 | * @param structure Structure type. | |
443 | * @param field_type Pointer to a const char* where the field's name will | |
444 | * be returned. | |
445 | * @param field_type Pointer to a bt_ctf_field_type* where the field's type will | |
446 | * be returned. | |
447 | * @param index Index of field. | |
448 | * | |
449 | * Returns 0 on success, a negative value on error. | |
450 | */ | |
451 | extern int bt_ctf_field_type_structure_get_field( | |
452 | struct bt_ctf_field_type *structure, | |
453 | const char **field_name, struct bt_ctf_field_type **field_type, | |
074ee56d | 454 | int index); |
b92ddaaa JG |
455 | |
456 | /* | |
457 | * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's | |
458 | * type by name. | |
459 | * | |
460 | * @param structure Structure type. | |
461 | * @param field_name Name of the structure's field. | |
462 | * | |
463 | * Returns a field type instance on success, NULL on error. | |
464 | */ | |
465 | extern | |
466 | struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( | |
467 | struct bt_ctf_field_type *structure, const char *field_name); | |
468 | ||
adc315b8 JG |
469 | /* |
470 | * bt_ctf_field_type_variant_create: create a variant field type. | |
471 | * | |
472 | * Allocate a new variant field type. The creation of a field type sets | |
473 | * its reference count to 1. tag_name must be the name of an enumeration | |
474 | * field declared in the same scope as this variant. | |
475 | * | |
476 | * @param enum_tag Type of the variant's tag/selector (must be an enumeration). | |
477 | * @param tag_name Name of the variant's tag/selector field (will be copied). | |
478 | * | |
479 | * Returns an allocated field type on success, NULL on error. | |
480 | */ | |
481 | extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create( | |
b92ddaaa JG |
482 | struct bt_ctf_field_type *enum_tag, const char *tag_name); |
483 | ||
484 | /* | |
485 | * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type. | |
486 | * | |
487 | * @param variant Variant type. | |
488 | * | |
6964b7fd | 489 | * Returns a field type instance on success, NULL if unset. |
b92ddaaa JG |
490 | */ |
491 | extern struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type( | |
492 | struct bt_ctf_field_type *variant); | |
493 | ||
494 | /* | |
495 | * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name. | |
496 | * | |
497 | * @param variant Variant type. | |
498 | * | |
6964b7fd | 499 | * Returns the tag field's name, NULL if unset. |
b92ddaaa JG |
500 | */ |
501 | extern const char *bt_ctf_field_type_variant_get_tag_name( | |
502 | struct bt_ctf_field_type *variant); | |
adc315b8 | 503 | |
d9b1ab6d JG |
504 | /* |
505 | * bt_ctf_field_type_variant_set_tag_name: set a variant's tag name. | |
506 | * | |
507 | * @param variant Variant type. | |
508 | * @param name Tag field name. | |
509 | * | |
510 | * Returns 0 on success, a negative value on error. | |
511 | */ | |
512 | extern int bt_ctf_field_type_variant_set_tag_name( | |
513 | struct bt_ctf_field_type *variant, const char *name); | |
514 | ||
adc315b8 JG |
515 | /* |
516 | * bt_ctf_field_type_variant_add_field: add a field to a variant. | |
517 | * | |
b92ddaaa | 518 | * Add a field of type "field_type" to the variant. The variant will share |
adc315b8 JG |
519 | * field_type's ownership by increasing its reference count. The "field_name" |
520 | * will be copied. field_name must match a mapping in the tag/selector | |
521 | * enumeration. | |
522 | * | |
523 | * @param variant Variant type. | |
524 | * @param field_type Type of the variant type's new field. | |
525 | * @param field_name Name of the variant type's new field (will be copied). | |
526 | * | |
527 | * Returns 0 on success, a negative value on error. | |
528 | */ | |
529 | extern int bt_ctf_field_type_variant_add_field( | |
530 | struct bt_ctf_field_type *variant, | |
531 | struct bt_ctf_field_type *field_type, | |
532 | const char *field_name); | |
533 | ||
b92ddaaa JG |
534 | /* |
535 | * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type. | |
536 | * | |
537 | * @param structure Variant type. | |
538 | * @param field_name Name of the variant's field. | |
539 | * | |
540 | * Returns a field type instance on success, NULL on error. | |
541 | */ | |
542 | extern | |
543 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( | |
544 | struct bt_ctf_field_type *variant, const char *field_name); | |
545 | ||
546 | /* | |
547 | * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type. | |
548 | * | |
549 | * @param variant Variant type. | |
550 | * @param tag Type tag (enum). | |
551 | * | |
552 | * Returns a field type instance on success, NULL on error. | |
553 | */ | |
554 | extern | |
555 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( | |
556 | struct bt_ctf_field_type *variant, struct bt_ctf_field *tag); | |
557 | ||
558 | /* | |
559 | * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined | |
560 | * in the variant. | |
561 | * | |
562 | * @param variant Variant type. | |
563 | * | |
564 | * Returns the field count on success, a negative value on error. | |
565 | */ | |
074ee56d | 566 | extern int bt_ctf_field_type_variant_get_field_count( |
b92ddaaa JG |
567 | struct bt_ctf_field_type *variant); |
568 | ||
569 | /* | |
570 | * bt_ctf_field_type_variant_get_field: get a variant's field name and type. | |
571 | * | |
572 | * @param variant Variant type. | |
573 | * @param field_type Pointer to a const char* where the field's name will | |
574 | * be returned. | |
575 | * @param field_type Pointer to a bt_ctf_field_type* where the field's type will | |
576 | * be returned. | |
577 | * @param index Index of field. | |
578 | * | |
579 | * Returns 0 on success, a negative value on error. | |
580 | */ | |
581 | extern int bt_ctf_field_type_variant_get_field( | |
582 | struct bt_ctf_field_type *variant, const char **field_name, | |
074ee56d | 583 | struct bt_ctf_field_type **field_type, int index); |
b92ddaaa | 584 | |
adc315b8 JG |
585 | /* |
586 | * bt_ctf_field_type_array_create: create an array field type. | |
587 | * | |
588 | * Allocate a new array field type. The creation of a field type sets | |
589 | * its reference count to 1. | |
590 | * | |
591 | * @param element_type Array's element type. | |
592 | * @oaram length Array type's length. | |
593 | * | |
594 | * Returns an allocated field type on success, NULL on error. | |
595 | */ | |
596 | extern struct bt_ctf_field_type *bt_ctf_field_type_array_create( | |
b92ddaaa JG |
597 | struct bt_ctf_field_type *element_type, unsigned int length); |
598 | ||
599 | /* | |
600 | * bt_ctf_field_type_array_get_element_type: get an array's element type. | |
601 | * | |
602 | * @param array Array type. | |
603 | * | |
604 | * Returns a field type instance on success, NULL on error. | |
605 | */ | |
606 | extern struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type( | |
607 | struct bt_ctf_field_type *array); | |
608 | ||
609 | /* | |
610 | * bt_ctf_field_type_array_get_length: get an array's length. | |
611 | * | |
612 | * @param array Array type. | |
613 | * | |
614 | * Returns the array's length on success, a negative value on error. | |
615 | */ | |
616 | extern int64_t bt_ctf_field_type_array_get_length( | |
617 | struct bt_ctf_field_type *array); | |
adc315b8 JG |
618 | |
619 | /* | |
620 | * bt_ctf_field_type_sequence_create: create a sequence field type. | |
621 | * | |
622 | * Allocate a new sequence field type. The creation of a field type sets | |
623 | * its reference count to 1. "length_field_name" must match an integer field | |
624 | * declared in the same scope. | |
625 | * | |
626 | * @param element_type Sequence's element type. | |
627 | * @param length_field_name Name of the sequence's length field (will be | |
628 | * copied). | |
629 | * | |
630 | * Returns an allocated field type on success, NULL on error. | |
631 | */ | |
632 | extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( | |
633 | struct bt_ctf_field_type *element_type, | |
634 | const char *length_field_name); | |
635 | ||
b92ddaaa JG |
636 | /* |
637 | * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type. | |
638 | * | |
639 | * @param sequence Sequence type. | |
640 | * | |
641 | * Returns a field type instance on success, NULL on error. | |
642 | */ | |
643 | extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type( | |
644 | struct bt_ctf_field_type *sequence); | |
645 | ||
646 | /* | |
647 | * bt_ctf_field_type_sequence_get_length_field_name: get length field name. | |
648 | * | |
649 | * @param sequence Sequence type. | |
650 | * | |
651 | * Returns the sequence's length field on success, NULL on error. | |
652 | */ | |
653 | extern const char *bt_ctf_field_type_sequence_get_length_field_name( | |
654 | struct bt_ctf_field_type *sequence); | |
655 | ||
adc315b8 JG |
656 | /* |
657 | * bt_ctf_field_type_string_create: create a string field type. | |
658 | * | |
659 | * Allocate a new string field type. The creation of a field type sets | |
660 | * its reference count to 1. | |
661 | * | |
662 | * Returns an allocated field type on success, NULL on error. | |
663 | */ | |
664 | extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); | |
665 | ||
b92ddaaa JG |
666 | /* |
667 | * bt_ctf_field_type_string_get_encoding: get a string type's encoding. | |
668 | * | |
669 | * Get the string type's encoding. | |
670 | * | |
671 | * @param string_type String type. | |
672 | * | |
673 | * Returns the string's encoding on success, a CTF_STRING_UNKNOWN on error. | |
674 | */ | |
675 | extern enum ctf_string_encoding bt_ctf_field_type_string_get_encoding( | |
676 | struct bt_ctf_field_type *string_type); | |
677 | ||
adc315b8 JG |
678 | /* |
679 | * bt_ctf_field_type_string_set_encoding: set a string type's encoding. | |
680 | * | |
681 | * Set the string type's encoding. | |
682 | * | |
b92ddaaa | 683 | * @param string_type String type. |
adc315b8 JG |
684 | * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII. |
685 | * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8. | |
686 | * | |
687 | * Returns 0 on success, a negative value on error. | |
688 | */ | |
689 | extern int bt_ctf_field_type_string_set_encoding( | |
b92ddaaa | 690 | struct bt_ctf_field_type *string_type, |
adc315b8 JG |
691 | enum ctf_string_encoding encoding); |
692 | ||
b92ddaaa JG |
693 | /* |
694 | * bt_ctf_field_type_get_alignment: get a field type's alignment. | |
695 | * | |
696 | * Get the field type's alignment. | |
697 | * | |
698 | * @param type Field type. | |
699 | * | |
46caf2cb JG |
700 | * Returns the field type's alignment on success, a negative value on error and |
701 | * 0 if the alignment is undefined (as in the case of a variant). | |
b92ddaaa JG |
702 | */ |
703 | extern int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type); | |
704 | ||
adc315b8 JG |
705 | /* |
706 | * bt_ctf_field_type_set_alignment: set a field type's alignment. | |
707 | * | |
708 | * Set the field type's alignment. | |
709 | * | |
710 | * @param type Field type. | |
711 | * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However, | |
712 | * some types, such as structures and string, may impose other alignment | |
713 | * constraints. | |
714 | * | |
715 | * Returns 0 on success, a negative value on error. | |
716 | */ | |
717 | extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, | |
718 | unsigned int alignment); | |
719 | ||
b92ddaaa JG |
720 | /* |
721 | * bt_ctf_field_type_get_byte_order: get a field type's byte order. | |
722 | * | |
723 | * @param type Field type. | |
724 | * | |
725 | * Returns the field type's byte order on success, a negative value on error. | |
726 | */ | |
727 | extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order( | |
728 | struct bt_ctf_field_type *type); | |
729 | ||
adc315b8 JG |
730 | /* |
731 | * bt_ctf_field_type_set_byte_order: set a field type's byte order. | |
732 | * | |
733 | * Set the field type's byte order. | |
734 | * | |
735 | * @param type Field type. | |
736 | * @param byte_order Field type's byte order. Defaults to | |
c35a1669 | 737 | * BT_CTF_BYTE_ORDER_NATIVE; the trace's endianness. |
adc315b8 JG |
738 | * |
739 | * Returns 0 on success, a negative value on error. | |
740 | */ | |
741 | extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, | |
742 | enum bt_ctf_byte_order byte_order); | |
743 | ||
b92ddaaa JG |
744 | /* |
745 | * bt_ctf_field_type_get_type_id: get a field type's ctf_type_id. | |
746 | * | |
747 | * @param type Field type. | |
748 | * | |
749 | * Returns the field type's ctf_type_id, CTF_TYPE_UNKNOWN on error. | |
750 | */ | |
751 | extern enum ctf_type_id bt_ctf_field_type_get_type_id( | |
752 | struct bt_ctf_field_type *type); | |
753 | ||
56db8d7a PP |
754 | /* |
755 | * bt_ctf_field_type_is_integer: returns whether or not a given field | |
756 | * type is an integer type. | |
757 | * | |
758 | * @param type Field type. | |
759 | * | |
760 | * Returns 1 if the field type is an integer type, 0 otherwise. | |
761 | */ | |
762 | extern int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *type); | |
763 | ||
764 | /* | |
765 | * bt_ctf_field_type_is_floating_point: returns whether or not a given field | |
766 | * type is a floating point number type. | |
767 | * | |
768 | * @param type Field type. | |
769 | * | |
770 | * Returns 1 if the field type is a floating point number type, 0 otherwise. | |
771 | */ | |
772 | extern int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *type); | |
773 | ||
774 | /* | |
775 | * bt_ctf_field_type_is_enumeration: returns whether or not a given field | |
776 | * type is an enumeration type. | |
777 | * | |
778 | * @param type Field type. | |
779 | * | |
780 | * Returns 1 if the field type is an enumeration type, 0 otherwise. | |
781 | */ | |
782 | extern int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *type); | |
783 | ||
784 | /* | |
785 | * bt_ctf_field_type_is_string: returns whether or not a given field | |
786 | * type is a string type. | |
787 | * | |
788 | * @param type Field type. | |
789 | * | |
790 | * Returns 1 if the field type is a string type, 0 otherwise. | |
791 | */ | |
792 | extern int bt_ctf_field_type_is_string(struct bt_ctf_field_type *type); | |
793 | ||
794 | /* | |
795 | * bt_ctf_field_type_is_structure: returns whether or not a given field | |
796 | * type is a structure type. | |
797 | * | |
798 | * @param type Field type. | |
799 | * | |
800 | * Returns 1 if the field type is a structure type, 0 otherwise. | |
801 | */ | |
802 | extern int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *type); | |
803 | ||
804 | /* | |
805 | * bt_ctf_field_type_is_array: returns whether or not a given field | |
806 | * type is an array type. | |
807 | * | |
808 | * @param type Field type. | |
809 | * | |
810 | * Returns 1 if the field type is an array type, 0 otherwise. | |
811 | */ | |
812 | extern int bt_ctf_field_type_is_array(struct bt_ctf_field_type *type); | |
813 | ||
814 | /* | |
815 | * bt_ctf_field_type_is_sequence: returns whether or not a given field | |
816 | * type is a sequence type. | |
817 | * | |
818 | * @param type Field type. | |
819 | * | |
820 | * Returns 1 if the field type is a sequence type, 0 otherwise. | |
821 | */ | |
822 | extern int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *type); | |
823 | ||
824 | /* | |
825 | * bt_ctf_field_type_is_variant: returns whether or not a given field | |
826 | * type is a variant type. | |
827 | * | |
828 | * @param type Field type. | |
829 | * | |
830 | * Returns 1 if the field type is a variant type, 0 otherwise. | |
831 | */ | |
832 | extern int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *type); | |
833 | ||
adc315b8 JG |
834 | /* |
835 | * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement | |
836 | * the field type's reference count. | |
837 | * | |
de3dd40e PP |
838 | * You may also use bt_ctf_get() and bt_ctf_put() with field type objects. |
839 | * | |
adc315b8 JG |
840 | * These functions ensure that the field type won't be destroyed while it |
841 | * is in use. The same number of get and put (plus one extra put to | |
842 | * release the initial reference done at creation) have to be done to | |
843 | * destroy a field type. | |
844 | * | |
845 | * When the field type's reference count is decremented to 0 by a | |
846 | * bt_ctf_field_type_put, the field type is freed. | |
847 | * | |
848 | * @param type Field type. | |
849 | */ | |
850 | extern void bt_ctf_field_type_get(struct bt_ctf_field_type *type); | |
851 | extern void bt_ctf_field_type_put(struct bt_ctf_field_type *type); | |
852 | ||
853 | #ifdef __cplusplus | |
854 | } | |
855 | #endif | |
856 | ||
857 | #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */ |