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
;
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,
53 enum bt_ctf_byte_order
{
54 BT_CTF_BYTE_ORDER_UNKNOWN
= -1,
55 BT_CTF_BYTE_ORDER_NATIVE
= 0,
56 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
,
57 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
58 BT_CTF_BYTE_ORDER_NETWORK
,
62 * bt_ctf_field_type_integer_create: create an integer field type.
64 * Allocate a new integer field type of the given size. The creation of a field
65 * type sets its reference countto 1.
67 * @param size Integer field type size/length in bits.
69 * Returns an allocated field type on success, NULL on error.
71 extern struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(
75 * bt_ctf_field_type_integer_get_size: get an integer type's size.
77 * Get an integer type's size.
79 * @param integer Integer type.
81 * Returns the integer type's size, a negative value on error.
83 extern int bt_ctf_field_type_integer_get_size(
84 struct bt_ctf_field_type
*integer
);
87 * bt_ctf_field_type_integer_get_signed: get an integer type's signedness.
89 * Get an integer type's signedness attribute.
91 * @param integer Integer type.
93 * Returns the integer's signedness, a negative value on error.
95 extern int bt_ctf_field_type_integer_get_signed(
96 struct bt_ctf_field_type
*integer
);
99 * bt_ctf_field_type_integer_set_signed: set an integer type's signedness.
101 * Set an integer type's signedness attribute.
103 * @param integer Integer type.
104 * @param is_signed Integer's signedness, defaults to FALSE.
106 * Returns 0 on success, a negative value on error.
108 extern int bt_ctf_field_type_integer_set_signed(
109 struct bt_ctf_field_type
*integer
, int is_signed
);
112 * bt_ctf_field_type_integer_get_base: get an integer type's base.
114 * Get an integer type's base used to pretty-print the resulting trace.
116 * @param integer Integer type.
118 * Returns the integer type's base on success, BT_CTF_INTEGER_BASE_UNKNOWN on
121 extern enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
122 struct bt_ctf_field_type
*integer
);
125 * bt_ctf_field_type_integer_set_base: set an integer type's base.
127 * Set an integer type's base used to pretty-print the resulting trace.
129 * @param integer Integer type.
130 * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL.
132 * Returns 0 on success, a negative value on error.
134 extern int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*integer
,
135 enum bt_ctf_integer_base base
);
138 * bt_ctf_field_type_integer_get_encoding: get an integer type's encoding.
140 * @param integer Integer type.
142 * Returns the string field's encoding on success, CTF_STRING_UNKNOWN on error.
144 extern enum ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
145 struct bt_ctf_field_type
*integer
);
148 * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding.
150 * An integer encoding may be set to signal that the integer must be printed as
153 * @param integer Integer type.
154 * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE
156 * Returns 0 on success, a negative value on error.
158 extern int bt_ctf_field_type_integer_set_encoding(
159 struct bt_ctf_field_type
*integer
,
160 enum ctf_string_encoding encoding
);
163 * bt_ctf_field_type_enumeration_create: create an enumeration field type.
165 * Allocate a new enumeration field type with the given underlying type. The
166 * creation of a field type sets its reference count to 1.
167 * The resulting enumeration will share the integer_container_type's ownership
168 * by increasing its reference count.
170 * @param integer_container_type Underlying integer type of the enumeration
173 * Returns an allocated field type on success, NULL on error.
175 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
176 struct bt_ctf_field_type
*integer_container_type
);
179 * bt_ctf_field_type_enumeration_get_container_type: get underlying container.
181 * Get the enumeration type's underlying integer container type.
183 * @param enumeration Enumeration type.
185 * Returns an allocated field type on success, NULL on error.
188 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_type(
189 struct bt_ctf_field_type
*enumeration
);
192 * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping.
194 * Add a mapping to the enumeration. The range's values are inclusive.
196 * @param enumeration Enumeration type.
197 * @param name Enumeration mapping name (will be copied).
198 * @param range_start Enumeration mapping range start.
199 * @param range_end Enumeration mapping range end.
201 * Returns 0 on success, a negative value on error.
203 extern int bt_ctf_field_type_enumeration_add_mapping(
204 struct bt_ctf_field_type
*enumeration
, const char *name
,
205 int64_t range_start
, int64_t range_end
);
208 * bt_ctf_field_type_enumeration_add_mapping_unsigned: add an enumeration
211 * Add a mapping to the enumeration. The range's values are inclusive.
213 * @param enumeration Enumeration type.
214 * @param name Enumeration mapping name (will be copied).
215 * @param range_start Enumeration mapping range start.
216 * @param range_end Enumeration mapping range end.
218 * Returns 0 on success, a negative value on error.
220 extern int bt_ctf_field_type_enumeration_add_mapping_unsigned(
221 struct bt_ctf_field_type
*enumeration
, const char *name
,
222 uint64_t range_start
, uint64_t range_end
);
225 * bt_ctf_field_type_enumeration_get_mapping_count: Get the number of mappings
226 * defined in the enumeration.
228 * @param enumeration Enumeration type.
230 * Returns the mapping count on success, a negative value on error.
232 extern int64_t bt_ctf_field_type_enumeration_get_mapping_count(
233 struct bt_ctf_field_type
*enumeration
);
236 * bt_ctf_field_type_enumeration_get_mapping: get an enumeration mapping.
238 * @param enumeration Enumeration type.
239 * @param index Index of mapping.
240 * @param name Pointer where the mapping's name will be returned (valid for
241 * the lifetime of the enumeration).
242 * @param range_start Pointer where the enumeration mapping's range start will
244 * @param range_end Pointer where the enumeration mapping's range end will
247 * Returns 0 on success, a negative value on error.
249 extern int bt_ctf_field_type_enumeration_get_mapping(
250 struct bt_ctf_field_type
*enumeration
, size_t index
,
251 const char **name
, int64_t *range_start
, int64_t *range_end
);
254 * bt_ctf_field_type_enumeration_get_mapping_unsigned: get a mapping.
256 * @param enumeration Enumeration type.
257 * @param index Index of mapping.
258 * @param name Pointer where the mapping's name will be returned (valid for
259 * the lifetime of the enumeration).
260 * @param range_start Pointer where the enumeration mapping's range start will
262 * @param range_end Pointer where the enumeration mapping's range end will
265 * Returns 0 on success, a negative value on error.
267 extern int bt_ctf_field_type_enumeration_get_mapping_unsigned(
268 struct bt_ctf_field_type
*enumeration
, size_t index
,
269 const char **name
, uint64_t *range_start
,
270 uint64_t *range_end
);
273 * bt_ctf_field_type_enumeration_get_mapping_index_by_name: get an enumerations'
274 * mapping index by name.
276 * @param enumeration Enumeration type.
277 * @param name Mapping name.
278 * @param index Pointer where the enumeration's mapping index will be returned.
280 * Returns 0 on success, a negative value on error.
282 extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name(
283 struct bt_ctf_field_type
*enumeration
, const char *name
,
287 * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an
288 * enumerations' mapping index by value.
290 * @param enumeration Enumeration type.
291 * @param value Value.
292 * @param index Pointer where the enumeration's mapping index will be returned.
294 * Returns 0 on success, a negative value on error.
296 extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value(
297 struct bt_ctf_field_type
*enumeration
, int64_t value
,
301 * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an
302 * enumerations' mapping index by value.
304 * @param enumeration Enumeration type.
305 * @param value Value.
306 * @param index Pointer where the enumeration's mapping index will be returned.
308 * Returns 0 on success, a negative value on error.
310 extern int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
311 struct bt_ctf_field_type
*enumeration
, uint64_t value
,
315 * bt_ctf_field_type_floating_point_create: create a floating point field type.
317 * Allocate a new floating point field type. The creation of a field type sets
318 * its reference count to 1.
320 * Returns an allocated field type on success, NULL on error.
322 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
325 * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit
328 * @param floating_point Floating point type.
330 * Returns the exponent digit count on success, a negative value on error.
332 extern int bt_ctf_field_type_floating_point_get_exponent_digits(
333 struct bt_ctf_field_type
*floating_point
);
336 * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit
339 * Set the number of exponent digits to use to store the floating point field.
340 * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG.
342 * @param floating_point Floating point type.
343 * @param exponent_digits Number of digits to allocate to the exponent (defaults
346 * Returns 0 on success, a negative value on error.
348 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
349 struct bt_ctf_field_type
*floating_point
,
350 unsigned int exponent_digits
);
353 * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit
356 * @param floating_point Floating point type.
358 * Returns the mantissa digit count on success, a negative value on error.
360 extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
361 struct bt_ctf_field_type
*floating_point
);
364 * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit
367 * Set the number of mantissa digits to use to store the floating point field.
368 * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG.
370 * @param floating_point Floating point type.
371 * @param mantissa_digits Number of digits to allocate to the mantissa (defaults
374 * Returns 0 on success, a negative value on error.
376 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
377 struct bt_ctf_field_type
*floating_point
,
378 unsigned int mantissa_digits
);
381 * bt_ctf_field_type_structure_create: create a structure field type.
383 * Allocate a new structure field type. The creation of a field type sets
384 * its reference count to 1.
386 * Returns an allocated field type on success, NULL on error.
388 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
391 * bt_ctf_field_type_structure_add_field: add a field to a structure.
393 * Add a field of type "field_type" to the structure. The structure will share
394 * field_type's ownership by increasing its reference count.
396 * @param structure Structure type.
397 * @param field_type Type of the field to add to the structure type.
398 * @param field_name Name of the structure's new field (will be copied).
400 * Returns 0 on success, a negative value on error.
402 extern int bt_ctf_field_type_structure_add_field(
403 struct bt_ctf_field_type
*structure
,
404 struct bt_ctf_field_type
*field_type
,
405 const char *field_name
);
408 * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined
411 * @param structure Structure type.
413 * Returns the field count on success, a negative value on error.
415 extern int64_t bt_ctf_field_type_structure_get_field_count(
416 struct bt_ctf_field_type
*structure
);
419 * bt_ctf_field_type_structure_get_field: get a structure's field type and name.
421 * @param structure Structure type.
422 * @param field_type Pointer to a const char* where the field's name will
424 * @param field_type Pointer to a bt_ctf_field_type* where the field's type will
426 * @param index Index of field.
428 * Returns 0 on success, a negative value on error.
430 extern int bt_ctf_field_type_structure_get_field(
431 struct bt_ctf_field_type
*structure
,
432 const char **field_name
, struct bt_ctf_field_type
**field_type
,
436 * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's
439 * @param structure Structure type.
440 * @param field_name Name of the structure's field.
442 * Returns a field type instance on success, NULL on error.
445 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
446 struct bt_ctf_field_type
*structure
, const char *field_name
);
449 * bt_ctf_field_type_variant_create: create a variant field type.
451 * Allocate a new variant field type. The creation of a field type sets
452 * its reference count to 1. tag_name must be the name of an enumeration
453 * field declared in the same scope as this variant.
455 * @param enum_tag Type of the variant's tag/selector (must be an enumeration).
456 * @param tag_name Name of the variant's tag/selector field (will be copied).
458 * Returns an allocated field type on success, NULL on error.
460 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
461 struct bt_ctf_field_type
*enum_tag
, const char *tag_name
);
464 * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type.
466 * @param variant Variant type.
468 * Returns a field type instance on success, NULL on error.
470 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_type(
471 struct bt_ctf_field_type
*variant
);
474 * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name.
476 * @param variant Variant type.
478 * Returns the tag field's name, NULL on error.
480 extern const char *bt_ctf_field_type_variant_get_tag_name(
481 struct bt_ctf_field_type
*variant
);
484 * bt_ctf_field_type_variant_add_field: add a field to a variant.
486 * Add a field of type "field_type" to the variant. The variant will share
487 * field_type's ownership by increasing its reference count. The "field_name"
488 * will be copied. field_name must match a mapping in the tag/selector
491 * @param variant Variant type.
492 * @param field_type Type of the variant type's new field.
493 * @param field_name Name of the variant type's new field (will be copied).
495 * Returns 0 on success, a negative value on error.
497 extern int bt_ctf_field_type_variant_add_field(
498 struct bt_ctf_field_type
*variant
,
499 struct bt_ctf_field_type
*field_type
,
500 const char *field_name
);
503 * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type.
505 * @param structure Variant type.
506 * @param field_name Name of the variant's field.
508 * Returns a field type instance on success, NULL on error.
511 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
512 struct bt_ctf_field_type
*variant
, const char *field_name
);
515 * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type.
517 * @param variant Variant type.
518 * @param tag Type tag (enum).
520 * Returns a field type instance on success, NULL on error.
523 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
524 struct bt_ctf_field_type
*variant
, struct bt_ctf_field
*tag
);
527 * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined
530 * @param variant Variant type.
532 * Returns the field count on success, a negative value on error.
534 extern int64_t bt_ctf_field_type_variant_get_field_count(
535 struct bt_ctf_field_type
*variant
);
538 * bt_ctf_field_type_variant_get_field: get a variant's field name and type.
540 * @param variant Variant type.
541 * @param field_type Pointer to a const char* where the field's name will
543 * @param field_type Pointer to a bt_ctf_field_type* where the field's type will
545 * @param index Index of field.
547 * Returns 0 on success, a negative value on error.
549 extern int bt_ctf_field_type_variant_get_field(
550 struct bt_ctf_field_type
*variant
, const char **field_name
,
551 struct bt_ctf_field_type
**field_type
, size_t index
);
554 * bt_ctf_field_type_array_create: create an array field type.
556 * Allocate a new array field type. The creation of a field type sets
557 * its reference count to 1.
559 * @param element_type Array's element type.
560 * @oaram length Array type's length.
562 * Returns an allocated field type on success, NULL on error.
564 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
565 struct bt_ctf_field_type
*element_type
, unsigned int length
);
568 * bt_ctf_field_type_array_get_element_type: get an array's element type.
570 * @param array Array type.
572 * Returns a field type instance on success, NULL on error.
574 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_type(
575 struct bt_ctf_field_type
*array
);
578 * bt_ctf_field_type_array_get_length: get an array's length.
580 * @param array Array type.
582 * Returns the array's length on success, a negative value on error.
584 extern int64_t bt_ctf_field_type_array_get_length(
585 struct bt_ctf_field_type
*array
);
588 * bt_ctf_field_type_sequence_create: create a sequence field type.
590 * Allocate a new sequence field type. The creation of a field type sets
591 * its reference count to 1. "length_field_name" must match an integer field
592 * declared in the same scope.
594 * @param element_type Sequence's element type.
595 * @param length_field_name Name of the sequence's length field (will be
598 * Returns an allocated field type on success, NULL on error.
600 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
601 struct bt_ctf_field_type
*element_type
,
602 const char *length_field_name
);
605 * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type.
607 * @param sequence Sequence type.
609 * Returns a field type instance on success, NULL on error.
611 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_type(
612 struct bt_ctf_field_type
*sequence
);
615 * bt_ctf_field_type_sequence_get_length_field_name: get length field name.
617 * @param sequence Sequence type.
619 * Returns the sequence's length field on success, NULL on error.
621 extern const char *bt_ctf_field_type_sequence_get_length_field_name(
622 struct bt_ctf_field_type
*sequence
);
625 * bt_ctf_field_type_string_create: create a string field type.
627 * Allocate a new string field type. The creation of a field type sets
628 * its reference count to 1.
630 * Returns an allocated field type on success, NULL on error.
632 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
635 * bt_ctf_field_type_string_get_encoding: get a string type's encoding.
637 * Get the string type's encoding.
639 * @param string_type String type.
641 * Returns the string's encoding on success, a CTF_STRING_UNKNOWN on error.
643 extern enum ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
644 struct bt_ctf_field_type
*string_type
);
647 * bt_ctf_field_type_string_set_encoding: set a string type's encoding.
649 * Set the string type's encoding.
651 * @param string_type String type.
652 * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII.
653 * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8.
655 * Returns 0 on success, a negative value on error.
657 extern int bt_ctf_field_type_string_set_encoding(
658 struct bt_ctf_field_type
*string_type
,
659 enum ctf_string_encoding encoding
);
662 * bt_ctf_field_type_get_alignment: get a field type's alignment.
664 * Get the field type's alignment.
666 * @param type Field type.
668 * Returns the field type's alignment on success, a negative value on error.
670 extern int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*type
);
673 * bt_ctf_field_type_set_alignment: set a field type's alignment.
675 * Set the field type's alignment.
677 * @param type Field type.
678 * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However,
679 * some types, such as structures and string, may impose other alignment
682 * Returns 0 on success, a negative value on error.
684 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
685 unsigned int alignment
);
688 * bt_ctf_field_type_get_byte_order: get a field type's byte order.
690 * @param type Field type.
692 * Returns the field type's byte order on success, a negative value on error.
694 extern enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
695 struct bt_ctf_field_type
*type
);
698 * bt_ctf_field_type_set_byte_order: set a field type's byte order.
700 * Set the field type's byte order.
702 * @param type Field type.
703 * @param byte_order Field type's byte order. Defaults to
704 * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness.
706 * Returns 0 on success, a negative value on error.
708 extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
709 enum bt_ctf_byte_order byte_order
);
712 * bt_ctf_field_type_get_type_id: get a field type's ctf_type_id.
714 * @param type Field type.
716 * Returns the field type's ctf_type_id, CTF_TYPE_UNKNOWN on error.
718 extern enum ctf_type_id
bt_ctf_field_type_get_type_id(
719 struct bt_ctf_field_type
*type
);
722 * bt_ctf_field_type_get_alias_nameL get a field type's alias name
724 * A type's alias name is set if it was resolved from a typedef or
725 * typealias. Note that types that are resolved from a ypealias or
726 * typedef are distinct from the underlying type and can't be compared
729 * @param type Field type.
731 * Returns a field type's alias name, NULL on error.
733 extern const char *bt_ctf_field_type_get_alias_name(
734 struct bt_ctf_field_type
*type
);
737 * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
738 * the field type's reference count.
740 * These functions ensure that the field type won't be destroyed while it
741 * is in use. The same number of get and put (plus one extra put to
742 * release the initial reference done at creation) have to be done to
743 * destroy a field type.
745 * When the field type's reference count is decremented to 0 by a
746 * bt_ctf_field_type_put, the field type is freed.
748 * @param type Field type.
750 extern void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
);
751 extern void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
);
757 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */