| 1 | #ifndef BABELTRACE_CTF_WRITER_EVENT_TYPES_H |
| 2 | #define BABELTRACE_CTF_WRITER_EVENT_TYPES_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace - CTF Writer: Event Types |
| 6 | * |
| 7 | * Copyright 2013 EfficiOS Inc. |
| 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-writer/writer.h> |
| 34 | #include <babeltrace/ctf/events.h> |
| 35 | #include <stdint.h> |
| 36 | |
| 37 | #ifdef __cplusplus |
| 38 | extern "C" { |
| 39 | #endif |
| 40 | |
| 41 | struct bt_ctf_event_class; |
| 42 | struct bt_ctf_event; |
| 43 | struct bt_ctf_field_type; |
| 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 | /* |
| 54 | * bt_ctf_field_type_integer_create: create an integer field type. |
| 55 | * |
| 56 | * Allocate a new integer field type of the given size. The creation of a field |
| 57 | * type sets its reference count to 1. |
| 58 | * |
| 59 | * @param size Integer field type size/length in bits. |
| 60 | * |
| 61 | * Returns an allocated field type on success, NULL on error. |
| 62 | */ |
| 63 | extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( |
| 64 | unsigned int size); |
| 65 | |
| 66 | /* |
| 67 | * bt_ctf_field_type_integer_set_signed: set an integer type's signedness. |
| 68 | * |
| 69 | * Set an integer type's signedness attribute. |
| 70 | * |
| 71 | * @param integer Integer type. |
| 72 | * @param is_signed Integer's signedness, defaults to FALSE. |
| 73 | * |
| 74 | * Returns 0 on success, a negative value on error. |
| 75 | */ |
| 76 | extern int bt_ctf_field_type_integer_set_signed( |
| 77 | struct bt_ctf_field_type *integer, int is_signed); |
| 78 | |
| 79 | /* |
| 80 | * bt_ctf_field_type_integer_set_base: set an integer type's base. |
| 81 | * |
| 82 | * Set an integer type's base used to pretty-print the resulting trace. |
| 83 | * |
| 84 | * @param integer Integer type. |
| 85 | * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL. |
| 86 | * |
| 87 | * Returns 0 on success, a negative value on error. |
| 88 | */ |
| 89 | extern int bt_ctf_field_type_integer_set_base( |
| 90 | struct bt_ctf_field_type *integer, |
| 91 | enum bt_ctf_integer_base base); |
| 92 | |
| 93 | /* |
| 94 | * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding. |
| 95 | * |
| 96 | * An integer encoding may be set to signal that the integer must be printed as |
| 97 | * a text character. |
| 98 | * |
| 99 | * @param integer Integer type. |
| 100 | * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE |
| 101 | * |
| 102 | * Returns 0 on success, a negative value on error. |
| 103 | */ |
| 104 | extern int bt_ctf_field_type_integer_set_encoding( |
| 105 | struct bt_ctf_field_type *integer, |
| 106 | enum ctf_string_encoding encoding); |
| 107 | |
| 108 | /* |
| 109 | * bt_ctf_field_type_enumeration_create: create an enumeration field type. |
| 110 | * |
| 111 | * Allocate a new enumeration field type with the given underlying type. The |
| 112 | * creation of a field type sets its reference count to 1. |
| 113 | * The resulting enumeration will share the integer_container_type's ownership |
| 114 | * by increasing its reference count. |
| 115 | * |
| 116 | * @param integer_container_type Underlying integer type of the enumeration |
| 117 | * type. |
| 118 | * |
| 119 | * Returns an allocated field type on success, NULL on error. |
| 120 | */ |
| 121 | extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( |
| 122 | struct bt_ctf_field_type *integer_container_type); |
| 123 | |
| 124 | /* |
| 125 | * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping. |
| 126 | * |
| 127 | * Add a mapping to the enumeration. The range's values are inclusive. |
| 128 | * |
| 129 | * @param enumeration Enumeration type. |
| 130 | * @param string Enumeration mapping name (will be copied). |
| 131 | * @param range_start Enumeration mapping range start. |
| 132 | * @param range_end Enumeration mapping range end. |
| 133 | * |
| 134 | * Returns 0 on success, a negative value on error. |
| 135 | */ |
| 136 | extern int bt_ctf_field_type_enumeration_add_mapping( |
| 137 | struct bt_ctf_field_type *enumeration, const char *string, |
| 138 | int64_t range_start, int64_t range_end); |
| 139 | |
| 140 | /* |
| 141 | * bt_ctf_field_type_floating_point_create: create a floating point field type. |
| 142 | * |
| 143 | * Allocate a new floating point field type. The creation of a field type sets |
| 144 | * its reference count to 1. |
| 145 | * |
| 146 | * Returns an allocated field type on success, NULL on error. |
| 147 | */ |
| 148 | extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); |
| 149 | |
| 150 | /* |
| 151 | * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit |
| 152 | * count. |
| 153 | * |
| 154 | * Set the number of exponent digits to use to store the floating point field. |
| 155 | * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG. |
| 156 | * |
| 157 | * @param floating_point Floating point type. |
| 158 | * @param exponent_digits Number of digits to allocate to the exponent (defaults |
| 159 | * to FLT_EXP_DIG). |
| 160 | * |
| 161 | * Returns 0 on success, a negative value on error. |
| 162 | */ |
| 163 | extern int bt_ctf_field_type_floating_point_set_exponent_digits( |
| 164 | struct bt_ctf_field_type *floating_point, |
| 165 | unsigned int exponent_digits); |
| 166 | |
| 167 | /* |
| 168 | * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit |
| 169 | * count. |
| 170 | * |
| 171 | * Set the number of mantissa digits to use to store the floating point field. |
| 172 | * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG. |
| 173 | * |
| 174 | * @param floating_point Floating point type. |
| 175 | * @param mantissa_digits Number of digits to allocate to the mantissa (defaults |
| 176 | * to FLT_MANT_DIG). |
| 177 | * |
| 178 | * Returns 0 on success, a negative value on error. |
| 179 | */ |
| 180 | extern int bt_ctf_field_type_floating_point_set_mantissa_digits( |
| 181 | struct bt_ctf_field_type *floating_point, |
| 182 | unsigned int mantissa_digits); |
| 183 | |
| 184 | /* |
| 185 | * bt_ctf_field_type_structure_create: create a structure field type. |
| 186 | * |
| 187 | * Allocate a new structure field type. The creation of a field type sets |
| 188 | * its reference count to 1. |
| 189 | * |
| 190 | * Returns an allocated field type on success, NULL on error. |
| 191 | */ |
| 192 | extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); |
| 193 | |
| 194 | /* |
| 195 | * bt_ctf_field_type_structure_add_field: add a field to a structure. |
| 196 | * |
| 197 | * Add a field of type "field_type" to the structure. The structure will share |
| 198 | * field_type's ownership by increasing its reference count. |
| 199 | * |
| 200 | * @param structure Structure type. |
| 201 | * @param field_type Type of the field to add to the structure type. |
| 202 | * @param field_name Name of the structure's new field (will be copied). |
| 203 | * |
| 204 | * Returns 0 on success, a negative value on error. |
| 205 | */ |
| 206 | extern int bt_ctf_field_type_structure_add_field( |
| 207 | struct bt_ctf_field_type *structure, |
| 208 | struct bt_ctf_field_type *field_type, |
| 209 | const char *field_name); |
| 210 | |
| 211 | /* |
| 212 | * bt_ctf_field_type_variant_create: create a variant field type. |
| 213 | * |
| 214 | * Allocate a new variant field type. The creation of a field type sets |
| 215 | * its reference count to 1. tag_name must be the name of an enumeration |
| 216 | * field declared in the same scope as this variant. |
| 217 | * |
| 218 | * @param enum_tag Type of the variant's tag/selector (must be an enumeration). |
| 219 | * @param tag_name Name of the variant's tag/selector field (will be copied). |
| 220 | * |
| 221 | * Returns an allocated field type on success, NULL on error. |
| 222 | */ |
| 223 | extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create( |
| 224 | struct bt_ctf_field_type *enum_tag, |
| 225 | const char *tag_name); |
| 226 | |
| 227 | /* |
| 228 | * bt_ctf_field_type_variant_add_field: add a field to a variant. |
| 229 | * |
| 230 | * Add a field of type "field_type" to the variant.The variant will share |
| 231 | * field_type's ownership by increasing its reference count. The "field_name" |
| 232 | * will be copied. field_name must match a mapping in the tag/selector |
| 233 | * enumeration. |
| 234 | * |
| 235 | * @param variant Variant type. |
| 236 | * @param field_type Type of the variant type's new field. |
| 237 | * @param field_name Name of the variant type's new field (will be copied). |
| 238 | * |
| 239 | * Returns 0 on success, a negative value on error. |
| 240 | */ |
| 241 | extern int bt_ctf_field_type_variant_add_field( |
| 242 | struct bt_ctf_field_type *variant, |
| 243 | struct bt_ctf_field_type *field_type, |
| 244 | const char *field_name); |
| 245 | |
| 246 | /* |
| 247 | * bt_ctf_field_type_array_create: create an array field type. |
| 248 | * |
| 249 | * Allocate a new array field type. The creation of a field type sets |
| 250 | * its reference count to 1. |
| 251 | * |
| 252 | * @param element_type Array's element type. |
| 253 | * @oaram length Array type's length. |
| 254 | * |
| 255 | * Returns an allocated field type on success, NULL on error. |
| 256 | */ |
| 257 | extern struct bt_ctf_field_type *bt_ctf_field_type_array_create( |
| 258 | struct bt_ctf_field_type *element_type, |
| 259 | unsigned int length); |
| 260 | |
| 261 | /* |
| 262 | * bt_ctf_field_type_sequence_create: create a sequence field type. |
| 263 | * |
| 264 | * Allocate a new sequence field type. The creation of a field type sets |
| 265 | * its reference count to 1. "length_field_name" must match an integer field |
| 266 | * declared in the same scope. |
| 267 | * |
| 268 | * @param element_type Sequence's element type. |
| 269 | * @param length_field_name Name of the sequence's length field (will be |
| 270 | * copied). |
| 271 | * |
| 272 | * Returns an allocated field type on success, NULL on error. |
| 273 | */ |
| 274 | extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( |
| 275 | struct bt_ctf_field_type *element_type, |
| 276 | const char *length_field_name); |
| 277 | |
| 278 | /* |
| 279 | * bt_ctf_field_type_string_create: create a string field type. |
| 280 | * |
| 281 | * Allocate a new string field type. The creation of a field type sets |
| 282 | * its reference count to 1. |
| 283 | * |
| 284 | * Returns an allocated field type on success, NULL on error. |
| 285 | */ |
| 286 | extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); |
| 287 | |
| 288 | /* |
| 289 | * bt_ctf_field_type_string_set_encoding: set a string type's encoding. |
| 290 | * |
| 291 | * Set the string type's encoding. |
| 292 | * |
| 293 | * @param string String type. |
| 294 | * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII. |
| 295 | * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8. |
| 296 | * |
| 297 | * Returns 0 on success, a negative value on error. |
| 298 | */ |
| 299 | extern int bt_ctf_field_type_string_set_encoding( |
| 300 | struct bt_ctf_field_type *string, |
| 301 | enum ctf_string_encoding encoding); |
| 302 | |
| 303 | /* |
| 304 | * bt_ctf_field_type_set_alignment: set a field type's alignment. |
| 305 | * |
| 306 | * Set the field type's alignment. |
| 307 | * |
| 308 | * @param type Field type. |
| 309 | * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However, |
| 310 | * some types, such as structures and string, may impose other alignment |
| 311 | * constraints. |
| 312 | * |
| 313 | * Returns 0 on success, a negative value on error. |
| 314 | */ |
| 315 | extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, |
| 316 | unsigned int alignment); |
| 317 | |
| 318 | /* |
| 319 | * bt_ctf_field_type_set_byte_order: set a field type's byte order. |
| 320 | * |
| 321 | * Set the field type's byte order. |
| 322 | * |
| 323 | * @param type Field type. |
| 324 | * @param byte_order Field type's byte order. Defaults to |
| 325 | * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness. |
| 326 | * |
| 327 | * Returns 0 on success, a negative value on error. |
| 328 | */ |
| 329 | extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, |
| 330 | enum bt_ctf_byte_order byte_order); |
| 331 | |
| 332 | /* |
| 333 | * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement |
| 334 | * the field type's reference count. |
| 335 | * |
| 336 | * These functions ensure that the field type won't be destroyed while it |
| 337 | * is in use. The same number of get and put (plus one extra put to |
| 338 | * release the initial reference done at creation) have to be done to |
| 339 | * destroy a field type. |
| 340 | * |
| 341 | * When the field type's reference count is decremented to 0 by a |
| 342 | * bt_ctf_field_type_put, the field type is freed. |
| 343 | * |
| 344 | * @param type Field type. |
| 345 | */ |
| 346 | extern void bt_ctf_field_type_get(struct bt_ctf_field_type *type); |
| 347 | extern void bt_ctf_field_type_put(struct bt_ctf_field_type *type); |
| 348 | |
| 349 | #ifdef __cplusplus |
| 350 | } |
| 351 | #endif |
| 352 | |
| 353 | #endif /* BABELTRACE_CTF_WRITER_EVENT_TYPES_H */ |