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