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 count to 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 int 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
, int 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
, int 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.
279 * Returns mapping index on success, a negative value on error.
281 extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name(
282 struct bt_ctf_field_type
*enumeration
, const char *name
);
285 * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an
286 * enumerations' mapping index by value.
288 * @param enumeration Enumeration type.
289 * @param value Value.
291 * Returns mapping index on success, a negative value on error.
293 extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value(
294 struct bt_ctf_field_type
*enumeration
, int64_t value
);
297 * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an
298 * enumerations' mapping index by value.
300 * @param enumeration Enumeration type.
301 * @param value Value.
303 * Returns 0 on success, a negative value on error.
305 extern int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
306 struct bt_ctf_field_type
*enumeration
, uint64_t value
);
309 * bt_ctf_field_type_floating_point_create: create a floating point field type.
311 * Allocate a new floating point field type. The creation of a field type sets
312 * its reference count to 1.
314 * Returns an allocated field type on success, NULL on error.
316 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
319 * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit
322 * @param floating_point Floating point type.
324 * Returns the exponent digit count on success, a negative value on error.
326 extern int bt_ctf_field_type_floating_point_get_exponent_digits(
327 struct bt_ctf_field_type
*floating_point
);
330 * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit
333 * Set the number of exponent digits to use to store the floating point field.
334 * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG.
336 * @param floating_point Floating point type.
337 * @param exponent_digits Number of digits to allocate to the exponent (defaults
340 * Returns 0 on success, a negative value on error.
342 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
343 struct bt_ctf_field_type
*floating_point
,
344 unsigned int exponent_digits
);
347 * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit
350 * @param floating_point Floating point type.
352 * Returns the mantissa digit count on success, a negative value on error.
354 extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
355 struct bt_ctf_field_type
*floating_point
);
358 * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit
361 * Set the number of mantissa digits to use to store the floating point field.
362 * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG.
364 * @param floating_point Floating point type.
365 * @param mantissa_digits Number of digits to allocate to the mantissa (defaults
368 * Returns 0 on success, a negative value on error.
370 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
371 struct bt_ctf_field_type
*floating_point
,
372 unsigned int mantissa_digits
);
375 * bt_ctf_field_type_structure_create: create a structure field type.
377 * Allocate a new structure field type. The creation of a field type sets
378 * its reference count to 1.
380 * Returns an allocated field type on success, NULL on error.
382 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
385 * bt_ctf_field_type_structure_add_field: add a field to a structure.
387 * Add a field of type "field_type" to the structure. The structure will share
388 * field_type's ownership by increasing its reference count.
390 * @param structure Structure type.
391 * @param field_type Type of the field to add to the structure type.
392 * @param field_name Name of the structure's new field (will be copied).
394 * Returns 0 on success, a negative value on error.
396 extern int bt_ctf_field_type_structure_add_field(
397 struct bt_ctf_field_type
*structure
,
398 struct bt_ctf_field_type
*field_type
,
399 const char *field_name
);
402 * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined
405 * @param structure Structure type.
407 * Returns the field count on success, a negative value on error.
409 extern int bt_ctf_field_type_structure_get_field_count(
410 struct bt_ctf_field_type
*structure
);
413 * bt_ctf_field_type_structure_get_field: get a structure's field type and name.
415 * @param structure Structure type.
416 * @param field_type Pointer to a const char* where the field's name will
418 * @param field_type Pointer to a bt_ctf_field_type* where the field's type will
420 * @param index Index of field.
422 * Returns 0 on success, a negative value on error.
424 extern int bt_ctf_field_type_structure_get_field(
425 struct bt_ctf_field_type
*structure
,
426 const char **field_name
, struct bt_ctf_field_type
**field_type
,
430 * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's
433 * @param structure Structure type.
434 * @param field_name Name of the structure's field.
436 * Returns a field type instance on success, NULL on error.
439 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
440 struct bt_ctf_field_type
*structure
, const char *field_name
);
443 * bt_ctf_field_type_variant_create: create a variant field type.
445 * Allocate a new variant field type. The creation of a field type sets
446 * its reference count to 1. tag_name must be the name of an enumeration
447 * field declared in the same scope as this variant.
449 * @param enum_tag Type of the variant's tag/selector (must be an enumeration).
450 * @param tag_name Name of the variant's tag/selector field (will be copied).
452 * Returns an allocated field type on success, NULL on error.
454 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
455 struct bt_ctf_field_type
*enum_tag
, const char *tag_name
);
458 * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type.
460 * @param variant Variant type.
462 * Returns a field type instance on success, NULL on error.
464 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_type(
465 struct bt_ctf_field_type
*variant
);
468 * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name.
470 * @param variant Variant type.
472 * Returns the tag field's name, NULL on error.
474 extern const char *bt_ctf_field_type_variant_get_tag_name(
475 struct bt_ctf_field_type
*variant
);
478 * bt_ctf_field_type_variant_add_field: add a field to a variant.
480 * Add a field of type "field_type" to the variant. The variant will share
481 * field_type's ownership by increasing its reference count. The "field_name"
482 * will be copied. field_name must match a mapping in the tag/selector
485 * @param variant Variant type.
486 * @param field_type Type of the variant type's new field.
487 * @param field_name Name of the variant type's new field (will be copied).
489 * Returns 0 on success, a negative value on error.
491 extern int bt_ctf_field_type_variant_add_field(
492 struct bt_ctf_field_type
*variant
,
493 struct bt_ctf_field_type
*field_type
,
494 const char *field_name
);
497 * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type.
499 * @param structure Variant type.
500 * @param field_name Name of the variant's field.
502 * Returns a field type instance on success, NULL on error.
505 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
506 struct bt_ctf_field_type
*variant
, const char *field_name
);
509 * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type.
511 * @param variant Variant type.
512 * @param tag Type tag (enum).
514 * Returns a field type instance on success, NULL on error.
517 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
518 struct bt_ctf_field_type
*variant
, struct bt_ctf_field
*tag
);
521 * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined
524 * @param variant Variant type.
526 * Returns the field count on success, a negative value on error.
528 extern int bt_ctf_field_type_variant_get_field_count(
529 struct bt_ctf_field_type
*variant
);
532 * bt_ctf_field_type_variant_get_field: get a variant's field name and type.
534 * @param variant Variant type.
535 * @param field_type Pointer to a const char* where the field's name will
537 * @param field_type Pointer to a bt_ctf_field_type* where the field's type will
539 * @param index Index of field.
541 * Returns 0 on success, a negative value on error.
543 extern int bt_ctf_field_type_variant_get_field(
544 struct bt_ctf_field_type
*variant
, const char **field_name
,
545 struct bt_ctf_field_type
**field_type
, int index
);
548 * bt_ctf_field_type_array_create: create an array field type.
550 * Allocate a new array field type. The creation of a field type sets
551 * its reference count to 1.
553 * @param element_type Array's element type.
554 * @oaram length Array type's length.
556 * Returns an allocated field type on success, NULL on error.
558 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
559 struct bt_ctf_field_type
*element_type
, unsigned int length
);
562 * bt_ctf_field_type_array_get_element_type: get an array's element type.
564 * @param array Array type.
566 * Returns a field type instance on success, NULL on error.
568 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_type(
569 struct bt_ctf_field_type
*array
);
572 * bt_ctf_field_type_array_get_length: get an array's length.
574 * @param array Array type.
576 * Returns the array's length on success, a negative value on error.
578 extern int64_t bt_ctf_field_type_array_get_length(
579 struct bt_ctf_field_type
*array
);
582 * bt_ctf_field_type_sequence_create: create a sequence field type.
584 * Allocate a new sequence field type. The creation of a field type sets
585 * its reference count to 1. "length_field_name" must match an integer field
586 * declared in the same scope.
588 * @param element_type Sequence's element type.
589 * @param length_field_name Name of the sequence's length field (will be
592 * Returns an allocated field type on success, NULL on error.
594 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
595 struct bt_ctf_field_type
*element_type
,
596 const char *length_field_name
);
599 * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type.
601 * @param sequence Sequence type.
603 * Returns a field type instance on success, NULL on error.
605 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_type(
606 struct bt_ctf_field_type
*sequence
);
609 * bt_ctf_field_type_sequence_get_length_field_name: get length field name.
611 * @param sequence Sequence type.
613 * Returns the sequence's length field on success, NULL on error.
615 extern const char *bt_ctf_field_type_sequence_get_length_field_name(
616 struct bt_ctf_field_type
*sequence
);
619 * bt_ctf_field_type_string_create: create a string field type.
621 * Allocate a new string field type. The creation of a field type sets
622 * its reference count to 1.
624 * Returns an allocated field type on success, NULL on error.
626 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
629 * bt_ctf_field_type_string_get_encoding: get a string type's encoding.
631 * Get the string type's encoding.
633 * @param string_type String type.
635 * Returns the string's encoding on success, a CTF_STRING_UNKNOWN on error.
637 extern enum ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
638 struct bt_ctf_field_type
*string_type
);
641 * bt_ctf_field_type_string_set_encoding: set a string type's encoding.
643 * Set the string type's encoding.
645 * @param string_type String type.
646 * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII.
647 * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8.
649 * Returns 0 on success, a negative value on error.
651 extern int bt_ctf_field_type_string_set_encoding(
652 struct bt_ctf_field_type
*string_type
,
653 enum ctf_string_encoding encoding
);
656 * bt_ctf_field_type_get_alignment: get a field type's alignment.
658 * Get the field type's alignment.
660 * @param type Field type.
662 * Returns the field type's alignment on success, a negative value on error.
664 extern int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*type
);
667 * bt_ctf_field_type_set_alignment: set a field type's alignment.
669 * Set the field type's alignment.
671 * @param type Field type.
672 * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However,
673 * some types, such as structures and string, may impose other alignment
676 * Returns 0 on success, a negative value on error.
678 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
679 unsigned int alignment
);
682 * bt_ctf_field_type_get_byte_order: get a field type's byte order.
684 * @param type Field type.
686 * Returns the field type's byte order on success, a negative value on error.
688 extern enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
689 struct bt_ctf_field_type
*type
);
692 * bt_ctf_field_type_set_byte_order: set a field type's byte order.
694 * Set the field type's byte order.
696 * @param type Field type.
697 * @param byte_order Field type's byte order. Defaults to
698 * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness.
700 * Returns 0 on success, a negative value on error.
702 extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
703 enum bt_ctf_byte_order byte_order
);
706 * bt_ctf_field_type_get_type_id: get a field type's ctf_type_id.
708 * @param type Field type.
710 * Returns the field type's ctf_type_id, CTF_TYPE_UNKNOWN on error.
712 extern enum ctf_type_id
bt_ctf_field_type_get_type_id(
713 struct bt_ctf_field_type
*type
);
716 * bt_ctf_field_type_get_alias_nameL get a field type's alias name
718 * A type's alias name is set if it was resolved from a typedef or
719 * typealias. Note that types that are resolved from a ypealias or
720 * typedef are distinct from the underlying type and can't be compared
723 * @param type Field type.
725 * Returns a field type's alias name, NULL on error.
727 extern const char *bt_ctf_field_type_get_alias_name(
728 struct bt_ctf_field_type
*type
);
731 * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
732 * the field type's reference count.
734 * These functions ensure that the field type won't be destroyed while it
735 * is in use. The same number of get and put (plus one extra put to
736 * release the initial reference done at creation) have to be done to
737 * destroy a field type.
739 * When the field type's reference count is decremented to 0 by a
740 * bt_ctf_field_type_put, the field type is freed.
742 * @param type Field type.
744 extern void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
);
745 extern void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
);
751 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */