| 1 | #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H |
| 2 | #define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace - CTF IR: Event field types internal |
| 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 | |
| 30 | #include <babeltrace/ctf-writer/event-types.h> |
| 31 | #include <babeltrace/ctf-writer/event-fields.h> |
| 32 | #include <babeltrace/ctf-writer/writer.h> |
| 33 | #include <babeltrace/ctf-ir/trace-internal.h> |
| 34 | #include <babeltrace/babeltrace-internal.h> |
| 35 | #include <babeltrace/object-internal.h> |
| 36 | #include <babeltrace/types.h> |
| 37 | #include <babeltrace/ctf/events.h> |
| 38 | #include <glib.h> |
| 39 | |
| 40 | typedef void (*type_freeze_func)(struct bt_ctf_field_type *); |
| 41 | typedef int (*type_serialize_func)(struct bt_ctf_field_type *, |
| 42 | struct metadata_context *); |
| 43 | |
| 44 | enum bt_ctf_type_id { |
| 45 | BT_CTF_TYPE_ID_UNKNOWN = CTF_TYPE_UNKNOWN, |
| 46 | BT_CTF_TYPE_ID_INTEGER = CTF_TYPE_INTEGER, |
| 47 | BT_CTF_TYPE_ID_FLOAT = CTF_TYPE_FLOAT, |
| 48 | BT_CTF_TYPE_ID_ENUM = CTF_TYPE_ENUM, |
| 49 | BT_CTF_TYPE_ID_STRING = CTF_TYPE_STRING, |
| 50 | BT_CTF_TYPE_ID_STRUCT = CTF_TYPE_STRUCT, |
| 51 | BT_CTF_TYPE_ID_UNTAGGED_VARIANT = CTF_TYPE_UNTAGGED_VARIANT, |
| 52 | BT_CTF_TYPE_ID_VARIANT = CTF_TYPE_VARIANT, |
| 53 | BT_CTF_TYPE_ID_ARRAY = CTF_TYPE_ARRAY, |
| 54 | BT_CTF_TYPE_ID_SEQUENCE = CTF_TYPE_SEQUENCE, |
| 55 | BT_CTF_NR_TYPE_IDS, |
| 56 | }; |
| 57 | |
| 58 | enum bt_ctf_ir_scope { |
| 59 | BT_CTF_SCOPE_UNKNOWN = -1, |
| 60 | BT_CTF_SCOPE_ENV = 0, |
| 61 | BT_CTF_SCOPE_TRACE_PACKET_HEADER = 1, |
| 62 | BT_CTF_SCOPE_STREAM_PACKET_CONTEXT = 2, |
| 63 | BT_CTF_SCOPE_STREAM_EVENT_HEADER = 3, |
| 64 | BT_CTF_SCOPE_STREAM_EVENT_CONTEXT = 4, |
| 65 | BT_CTF_SCOPE_EVENT_CONTEXT = 5, |
| 66 | BT_CTF_SCOPE_EVENT_FIELDS = 6, |
| 67 | }; |
| 68 | |
| 69 | struct bt_ctf_field_type { |
| 70 | struct bt_object base; |
| 71 | struct bt_declaration *declaration; |
| 72 | type_freeze_func freeze; |
| 73 | type_serialize_func serialize; |
| 74 | /* |
| 75 | * A type can't be modified once it is added to an event or after a |
| 76 | * a field has been instanciated from it. |
| 77 | */ |
| 78 | int frozen; |
| 79 | |
| 80 | /* |
| 81 | * This flag indicates if the field type is valid. A valid |
| 82 | * field type is _always_ frozen. All the nested field types of |
| 83 | * a valid field type are also valid (and thus frozen). |
| 84 | */ |
| 85 | int valid; |
| 86 | }; |
| 87 | |
| 88 | struct bt_ctf_field_type_integer { |
| 89 | struct bt_ctf_field_type parent; |
| 90 | struct declaration_integer declaration; |
| 91 | struct bt_ctf_clock *mapped_clock; |
| 92 | |
| 93 | /* |
| 94 | * This is what the user sets and is never modified by internal |
| 95 | * code. |
| 96 | * |
| 97 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. |
| 98 | */ |
| 99 | enum bt_ctf_byte_order user_byte_order; |
| 100 | }; |
| 101 | |
| 102 | struct enumeration_mapping { |
| 103 | union { |
| 104 | uint64_t _unsigned; |
| 105 | int64_t _signed; |
| 106 | } range_start; |
| 107 | |
| 108 | union { |
| 109 | uint64_t _unsigned; |
| 110 | int64_t _signed; |
| 111 | } range_end; |
| 112 | GQuark string; |
| 113 | }; |
| 114 | |
| 115 | struct bt_ctf_field_type_enumeration { |
| 116 | struct bt_ctf_field_type parent; |
| 117 | struct bt_ctf_field_type *container; |
| 118 | GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */ |
| 119 | struct declaration_enum declaration; |
| 120 | }; |
| 121 | |
| 122 | struct bt_ctf_field_type_floating_point { |
| 123 | struct bt_ctf_field_type parent; |
| 124 | struct declaration_float declaration; |
| 125 | |
| 126 | /* |
| 127 | * The `declaration` field above contains 3 pointers pointing |
| 128 | * to the fields below. This avoids unnecessary dynamic |
| 129 | * allocations. |
| 130 | */ |
| 131 | struct declaration_integer sign; |
| 132 | struct declaration_integer mantissa; |
| 133 | struct declaration_integer exp; |
| 134 | |
| 135 | /* |
| 136 | * This is what the user sets and is never modified by internal |
| 137 | * code. |
| 138 | * |
| 139 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. |
| 140 | */ |
| 141 | enum bt_ctf_byte_order user_byte_order; |
| 142 | }; |
| 143 | |
| 144 | struct structure_field { |
| 145 | GQuark name; |
| 146 | struct bt_ctf_field_type *type; |
| 147 | }; |
| 148 | |
| 149 | struct bt_ctf_field_type_structure { |
| 150 | struct bt_ctf_field_type parent; |
| 151 | GHashTable *field_name_to_index; |
| 152 | GPtrArray *fields; /* Array of pointers to struct structure_field */ |
| 153 | struct declaration_struct declaration; |
| 154 | }; |
| 155 | |
| 156 | struct bt_ctf_field_type_variant { |
| 157 | struct bt_ctf_field_type parent; |
| 158 | GString *tag_name; |
| 159 | struct bt_ctf_field_type_enumeration *tag; |
| 160 | struct bt_ctf_field_path *tag_field_path; |
| 161 | GHashTable *field_name_to_index; |
| 162 | GPtrArray *fields; /* Array of pointers to struct structure_field */ |
| 163 | struct declaration_variant declaration; |
| 164 | }; |
| 165 | |
| 166 | struct bt_ctf_field_type_array { |
| 167 | struct bt_ctf_field_type parent; |
| 168 | struct bt_ctf_field_type *element_type; |
| 169 | unsigned int length; /* Number of elements */ |
| 170 | struct declaration_array declaration; |
| 171 | }; |
| 172 | |
| 173 | struct bt_ctf_field_type_sequence { |
| 174 | struct bt_ctf_field_type parent; |
| 175 | struct bt_ctf_field_type *element_type; |
| 176 | GString *length_field_name; |
| 177 | struct bt_ctf_field_path *length_field_path; |
| 178 | struct declaration_sequence declaration; |
| 179 | }; |
| 180 | |
| 181 | struct bt_ctf_field_type_string { |
| 182 | struct bt_ctf_field_type parent; |
| 183 | struct declaration_string declaration; |
| 184 | }; |
| 185 | |
| 186 | BT_HIDDEN |
| 187 | void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); |
| 188 | |
| 189 | BT_HIDDEN |
| 190 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( |
| 191 | struct bt_ctf_field_type_variant *variant, int64_t tag_value); |
| 192 | |
| 193 | BT_HIDDEN |
| 194 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( |
| 195 | struct bt_ctf_field_type_variant *variant, uint64_t tag_value); |
| 196 | |
| 197 | BT_HIDDEN |
| 198 | int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, |
| 199 | struct metadata_context *context); |
| 200 | |
| 201 | BT_HIDDEN |
| 202 | int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); |
| 203 | |
| 204 | BT_HIDDEN |
| 205 | const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned( |
| 206 | struct bt_ctf_field_type_enumeration *enumeration_type, |
| 207 | uint64_t value); |
| 208 | |
| 209 | BT_HIDDEN |
| 210 | const char *bt_ctf_field_type_enumeration_get_mapping_name_signed( |
| 211 | struct bt_ctf_field_type_enumeration *enumeration_type, |
| 212 | int64_t value); |
| 213 | |
| 214 | /* Override field type's byte order only if it is set to "native" */ |
| 215 | BT_HIDDEN |
| 216 | void bt_ctf_field_type_set_native_byte_order( |
| 217 | struct bt_ctf_field_type *type, int byte_order); |
| 218 | |
| 219 | /* Deep copy a field type */ |
| 220 | BT_HIDDEN |
| 221 | struct bt_ctf_field_type *bt_ctf_field_type_copy( |
| 222 | struct bt_ctf_field_type *type); |
| 223 | |
| 224 | BT_HIDDEN |
| 225 | int bt_ctf_field_type_structure_get_field_name_index( |
| 226 | struct bt_ctf_field_type *structure, const char *name); |
| 227 | |
| 228 | /* Replace an existing field's type in a structure */ |
| 229 | BT_HIDDEN |
| 230 | int bt_ctf_field_type_structure_set_field_index( |
| 231 | struct bt_ctf_field_type *structure, |
| 232 | struct bt_ctf_field_type *field, int index); |
| 233 | |
| 234 | BT_HIDDEN |
| 235 | int bt_ctf_field_type_variant_get_field_name_index( |
| 236 | struct bt_ctf_field_type *variant, const char *name); |
| 237 | |
| 238 | BT_HIDDEN |
| 239 | int bt_ctf_field_type_sequence_set_length_field_path( |
| 240 | struct bt_ctf_field_type *type, |
| 241 | struct bt_ctf_field_path *path); |
| 242 | |
| 243 | BT_HIDDEN |
| 244 | int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, |
| 245 | struct bt_ctf_field_path *path); |
| 246 | |
| 247 | BT_HIDDEN |
| 248 | int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type, |
| 249 | struct bt_ctf_field_type *tag_type); |
| 250 | |
| 251 | /* Replace an existing field's type in a variant */ |
| 252 | BT_HIDDEN |
| 253 | int bt_ctf_field_type_variant_set_field_index( |
| 254 | struct bt_ctf_field_type *variant, |
| 255 | struct bt_ctf_field_type *field, int index); |
| 256 | |
| 257 | BT_HIDDEN |
| 258 | int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, |
| 259 | struct bt_ctf_field_type *element_type); |
| 260 | |
| 261 | BT_HIDDEN |
| 262 | int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, |
| 263 | struct bt_ctf_field_type *element_type); |
| 264 | |
| 265 | BT_HIDDEN |
| 266 | int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type); |
| 267 | |
| 268 | BT_HIDDEN |
| 269 | struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index( |
| 270 | struct bt_ctf_field_type *type, int index); |
| 271 | |
| 272 | BT_HIDDEN |
| 273 | int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type, |
| 274 | const char *name); |
| 275 | |
| 276 | /* |
| 277 | * bt_ctf_field_type_integer_get_size: get an integer type's size. |
| 278 | * |
| 279 | * Get an integer type's size. |
| 280 | * |
| 281 | * @param integer Integer type. |
| 282 | * |
| 283 | * Returns the integer type's size, a negative value on error. |
| 284 | */ |
| 285 | BT_HIDDEN |
| 286 | int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer); |
| 287 | |
| 288 | /* |
| 289 | * bt_ctf_field_type_integer_get_base: get an integer type's base. |
| 290 | * |
| 291 | * Get an integer type's base used to pretty-print the resulting trace. |
| 292 | * |
| 293 | * @param integer Integer type. |
| 294 | * |
| 295 | * Returns the integer type's base on success, BT_CTF_INTEGER_BASE_UNKNOWN on |
| 296 | * error. |
| 297 | */ |
| 298 | BT_HIDDEN |
| 299 | enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( |
| 300 | struct bt_ctf_field_type *integer); |
| 301 | |
| 302 | /* |
| 303 | * bt_ctf_field_type_integer_get_encoding: get an integer type's encoding. |
| 304 | * |
| 305 | * @param integer Integer type. |
| 306 | * |
| 307 | * Returns the string field's encoding on success, |
| 308 | * BT_CTF_STRING_ENCODING_UNKNOWN on error. |
| 309 | */ |
| 310 | BT_HIDDEN |
| 311 | enum bt_ctf_string_encoding bt_ctf_field_type_integer_get_encoding( |
| 312 | struct bt_ctf_field_type *integer); |
| 313 | |
| 314 | /** |
| 315 | * bt_ctf_field_type_integer_get_mapped_clock: get an integer type's mapped clock. |
| 316 | * |
| 317 | * @param integer Integer type. |
| 318 | * |
| 319 | * Returns the integer's mapped clock (if any), NULL on error. |
| 320 | */ |
| 321 | BT_HIDDEN |
| 322 | struct bt_ctf_clock *bt_ctf_field_type_integer_get_mapped_clock( |
| 323 | struct bt_ctf_field_type *integer); |
| 324 | |
| 325 | /** |
| 326 | * bt_ctf_field_type_integer_set_mapped_clock: set an integer type's mapped clock. |
| 327 | * |
| 328 | * @param integer Integer type. |
| 329 | * @param clock Clock to map. |
| 330 | * |
| 331 | * Returns 0 on success, a negative value on error. |
| 332 | */ |
| 333 | BT_HIDDEN |
| 334 | int bt_ctf_field_type_integer_set_mapped_clock( |
| 335 | struct bt_ctf_field_type *integer, |
| 336 | struct bt_ctf_clock *clock); |
| 337 | |
| 338 | /* |
| 339 | * bt_ctf_field_type_enumeration_get_container_type: get underlying container. |
| 340 | * |
| 341 | * Get the enumeration type's underlying integer container type. |
| 342 | * |
| 343 | * @param enumeration Enumeration type. |
| 344 | * |
| 345 | * Returns an allocated field type on success, NULL on error. |
| 346 | */ |
| 347 | BT_HIDDEN |
| 348 | struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type( |
| 349 | struct bt_ctf_field_type *enumeration); |
| 350 | |
| 351 | /* |
| 352 | * bt_ctf_field_type_enumeration_add_mapping_unsigned: add an enumeration |
| 353 | * mapping. |
| 354 | * |
| 355 | * Add a mapping to the enumeration. The range's values are inclusive. |
| 356 | * |
| 357 | * @param enumeration Enumeration type. |
| 358 | * @param name Enumeration mapping name (will be copied). |
| 359 | * @param range_start Enumeration mapping range start. |
| 360 | * @param range_end Enumeration mapping range end. |
| 361 | * |
| 362 | * Returns 0 on success, a negative value on error. |
| 363 | */ |
| 364 | BT_HIDDEN |
| 365 | int bt_ctf_field_type_enumeration_add_mapping_unsigned( |
| 366 | struct bt_ctf_field_type *enumeration, const char *name, |
| 367 | uint64_t range_start, uint64_t range_end); |
| 368 | |
| 369 | /* |
| 370 | * bt_ctf_field_type_enumeration_get_mapping_count: Get the number of mappings |
| 371 | * defined in the enumeration. |
| 372 | * |
| 373 | * @param enumeration Enumeration type. |
| 374 | * |
| 375 | * Returns the mapping count on success, a negative value on error. |
| 376 | */ |
| 377 | BT_HIDDEN |
| 378 | int bt_ctf_field_type_enumeration_get_mapping_count( |
| 379 | struct bt_ctf_field_type *enumeration); |
| 380 | |
| 381 | /* |
| 382 | * bt_ctf_field_type_enumeration_get_mapping: get an enumeration mapping. |
| 383 | * |
| 384 | * @param enumeration Enumeration type. |
| 385 | * @param index Index of mapping. |
| 386 | * @param name Pointer where the mapping's name will be returned (valid for |
| 387 | * the lifetime of the enumeration). |
| 388 | * @param range_start Pointer where the enumeration mapping's range start will |
| 389 | * be returned. |
| 390 | * @param range_end Pointer where the enumeration mapping's range end will |
| 391 | * be returned. |
| 392 | * |
| 393 | * Returns 0 on success, a negative value on error. |
| 394 | */ |
| 395 | BT_HIDDEN |
| 396 | int bt_ctf_field_type_enumeration_get_mapping( |
| 397 | struct bt_ctf_field_type *enumeration, int index, |
| 398 | const char **name, int64_t *range_start, int64_t *range_end); |
| 399 | |
| 400 | /* |
| 401 | * bt_ctf_field_type_enumeration_get_mapping_unsigned: get a mapping. |
| 402 | * |
| 403 | * @param enumeration Enumeration type. |
| 404 | * @param index Index of mapping. |
| 405 | * @param name Pointer where the mapping's name will be returned (valid for |
| 406 | * the lifetime of the enumeration). |
| 407 | * @param range_start Pointer where the enumeration mapping's range start will |
| 408 | * be returned. |
| 409 | * @param range_end Pointer where the enumeration mapping's range end will |
| 410 | * be returned. |
| 411 | * |
| 412 | * Returns 0 on success, a negative value on error. |
| 413 | */ |
| 414 | BT_HIDDEN |
| 415 | int bt_ctf_field_type_enumeration_get_mapping_unsigned( |
| 416 | struct bt_ctf_field_type *enumeration, int index, |
| 417 | const char **name, uint64_t *range_start, |
| 418 | uint64_t *range_end); |
| 419 | |
| 420 | /* |
| 421 | * bt_ctf_field_type_enumeration_get_mapping_index_by_name: get an enumerations' |
| 422 | * mapping index by name. |
| 423 | * |
| 424 | * @param enumeration Enumeration type. |
| 425 | * @param name Mapping name. |
| 426 | * |
| 427 | * Returns mapping index on success, a negative value on error. |
| 428 | */ |
| 429 | BT_HIDDEN |
| 430 | int bt_ctf_field_type_enumeration_get_mapping_index_by_name( |
| 431 | struct bt_ctf_field_type *enumeration, const char *name); |
| 432 | |
| 433 | /* |
| 434 | * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an |
| 435 | * enumerations' mapping index by value. |
| 436 | * |
| 437 | * @param enumeration Enumeration type. |
| 438 | * @param value Value. |
| 439 | * |
| 440 | * Returns mapping index on success, a negative value on error. |
| 441 | */ |
| 442 | BT_HIDDEN |
| 443 | int bt_ctf_field_type_enumeration_get_mapping_index_by_value( |
| 444 | struct bt_ctf_field_type *enumeration, int64_t value); |
| 445 | |
| 446 | /* |
| 447 | * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an |
| 448 | * enumerations' mapping index by value. |
| 449 | * |
| 450 | * @param enumeration Enumeration type. |
| 451 | * @param value Value. |
| 452 | * |
| 453 | * Returns 0 on success, a negative value on error. |
| 454 | */ |
| 455 | BT_HIDDEN |
| 456 | int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( |
| 457 | struct bt_ctf_field_type *enumeration, uint64_t value); |
| 458 | |
| 459 | /* |
| 460 | * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit |
| 461 | * count. |
| 462 | * |
| 463 | * @param floating_point Floating point type. |
| 464 | * |
| 465 | * Returns the exponent digit count on success, a negative value on error. |
| 466 | */ |
| 467 | BT_HIDDEN |
| 468 | int bt_ctf_field_type_floating_point_get_exponent_digits( |
| 469 | struct bt_ctf_field_type *floating_point); |
| 470 | |
| 471 | /* |
| 472 | * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit |
| 473 | * count. |
| 474 | * |
| 475 | * @param floating_point Floating point type. |
| 476 | * |
| 477 | * Returns the mantissa digit count on success, a negative value on error. |
| 478 | */ |
| 479 | BT_HIDDEN |
| 480 | int bt_ctf_field_type_floating_point_get_mantissa_digits( |
| 481 | struct bt_ctf_field_type *floating_point); |
| 482 | |
| 483 | /* |
| 484 | * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined |
| 485 | * in the structure. |
| 486 | * |
| 487 | * @param structure Structure type. |
| 488 | * |
| 489 | * Returns the field count on success, a negative value on error. |
| 490 | */ |
| 491 | BT_HIDDEN |
| 492 | int bt_ctf_field_type_structure_get_field_count( |
| 493 | struct bt_ctf_field_type *structure); |
| 494 | |
| 495 | /* |
| 496 | * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's |
| 497 | * type by name. |
| 498 | * |
| 499 | * @param structure Structure type. |
| 500 | * @param field_name Name of the structure's field. |
| 501 | * |
| 502 | * Returns a field type instance on success, NULL on error. |
| 503 | */ |
| 504 | BT_HIDDEN |
| 505 | struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( |
| 506 | struct bt_ctf_field_type *structure, const char *field_name); |
| 507 | |
| 508 | /* |
| 509 | * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type. |
| 510 | * |
| 511 | * @param variant Variant type. |
| 512 | * |
| 513 | * Returns a field type instance on success, NULL if unset. |
| 514 | */ |
| 515 | BT_HIDDEN |
| 516 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type( |
| 517 | struct bt_ctf_field_type *variant); |
| 518 | |
| 519 | /* |
| 520 | * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name. |
| 521 | * |
| 522 | * @param variant Variant type. |
| 523 | * |
| 524 | * Returns the tag field's name, NULL if unset. |
| 525 | */ |
| 526 | BT_HIDDEN |
| 527 | const char *bt_ctf_field_type_variant_get_tag_name( |
| 528 | struct bt_ctf_field_type *variant); |
| 529 | |
| 530 | /* |
| 531 | * bt_ctf_field_type_variant_set_tag_name: set a variant's tag name. |
| 532 | * |
| 533 | * @param variant Variant type. |
| 534 | * @param name Tag field name. |
| 535 | * |
| 536 | * Returns 0 on success, a negative value on error. |
| 537 | */ |
| 538 | BT_HIDDEN |
| 539 | int bt_ctf_field_type_variant_set_tag_name( |
| 540 | struct bt_ctf_field_type *variant, const char *name); |
| 541 | |
| 542 | /* |
| 543 | * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type. |
| 544 | * |
| 545 | * @param structure Variant type. |
| 546 | * @param field_name Name of the variant's field. |
| 547 | * |
| 548 | * Returns a field type instance on success, NULL on error. |
| 549 | */ |
| 550 | BT_HIDDEN |
| 551 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( |
| 552 | struct bt_ctf_field_type *variant, const char *field_name); |
| 553 | |
| 554 | /* |
| 555 | * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type. |
| 556 | * |
| 557 | * @param variant Variant type. |
| 558 | * @param tag Type tag (enum). |
| 559 | * |
| 560 | * Returns a field type instance on success, NULL on error. |
| 561 | */ |
| 562 | BT_HIDDEN |
| 563 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( |
| 564 | struct bt_ctf_field_type *variant, struct bt_ctf_field *tag); |
| 565 | |
| 566 | /* |
| 567 | * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined |
| 568 | * in the variant. |
| 569 | * |
| 570 | * @param variant Variant type. |
| 571 | * |
| 572 | * Returns the field count on success, a negative value on error. |
| 573 | */ |
| 574 | BT_HIDDEN |
| 575 | int bt_ctf_field_type_variant_get_field_count( |
| 576 | struct bt_ctf_field_type *variant); |
| 577 | |
| 578 | /* |
| 579 | * bt_ctf_field_type_variant_get_field: get a variant's field name and type. |
| 580 | * |
| 581 | * @param variant Variant type. |
| 582 | * @param field_type Pointer to a const char* where the field's name will |
| 583 | * be returned. |
| 584 | * @param field_type Pointer to a bt_ctf_field_type* where the field's type will |
| 585 | * be returned. |
| 586 | * @param index Index of field. |
| 587 | * |
| 588 | * Returns 0 on success, a negative value on error. |
| 589 | */ |
| 590 | BT_HIDDEN |
| 591 | int bt_ctf_field_type_variant_get_field( |
| 592 | struct bt_ctf_field_type *variant, const char **field_name, |
| 593 | struct bt_ctf_field_type **field_type, int index); |
| 594 | |
| 595 | /* |
| 596 | * bt_ctf_field_type_array_get_element_type: get an array's element type. |
| 597 | * |
| 598 | * @param array Array type. |
| 599 | * |
| 600 | * Returns a field type instance on success, NULL on error. |
| 601 | */ |
| 602 | BT_HIDDEN |
| 603 | struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type( |
| 604 | struct bt_ctf_field_type *array); |
| 605 | |
| 606 | /* |
| 607 | * bt_ctf_field_type_array_get_length: get an array's length. |
| 608 | * |
| 609 | * @param array Array type. |
| 610 | * |
| 611 | * Returns the array's length on success, a negative value on error. |
| 612 | */ |
| 613 | BT_HIDDEN |
| 614 | int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array); |
| 615 | |
| 616 | /* |
| 617 | * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type. |
| 618 | * |
| 619 | * @param sequence Sequence type. |
| 620 | * |
| 621 | * Returns a field type instance on success, NULL on error. |
| 622 | */ |
| 623 | BT_HIDDEN |
| 624 | struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type( |
| 625 | struct bt_ctf_field_type *sequence); |
| 626 | |
| 627 | /* |
| 628 | * bt_ctf_field_type_sequence_get_length_field_name: get length field name. |
| 629 | * |
| 630 | * @param sequence Sequence type. |
| 631 | * |
| 632 | * Returns the sequence's length field on success, NULL on error. |
| 633 | */ |
| 634 | BT_HIDDEN |
| 635 | const char *bt_ctf_field_type_sequence_get_length_field_name( |
| 636 | struct bt_ctf_field_type *sequence); |
| 637 | |
| 638 | /* |
| 639 | * bt_ctf_field_type_string_get_encoding: get a string type's encoding. |
| 640 | * |
| 641 | * Get the string type's encoding. |
| 642 | * |
| 643 | * @param string_type String type. |
| 644 | * |
| 645 | * Returns the string's encoding on success, a BT_CTF_STRING_ENCODING_UNKNOWN |
| 646 | * on error. |
| 647 | */ |
| 648 | BT_HIDDEN |
| 649 | enum bt_ctf_string_encoding bt_ctf_field_type_string_get_encoding( |
| 650 | struct bt_ctf_field_type *string_type); |
| 651 | |
| 652 | /* |
| 653 | * bt_ctf_field_type_get_alignment: get a field type's alignment. |
| 654 | * |
| 655 | * Get the field type's alignment. |
| 656 | * |
| 657 | * @param type Field type. |
| 658 | * |
| 659 | * Returns the field type's alignment on success, a negative value on error and |
| 660 | * 0 if the alignment is undefined (as in the case of a variant). |
| 661 | */ |
| 662 | BT_HIDDEN |
| 663 | int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type); |
| 664 | |
| 665 | /* |
| 666 | * bt_ctf_field_type_get_byte_order: get a field type's byte order. |
| 667 | * |
| 668 | * @param type Field type. |
| 669 | * |
| 670 | * Returns the field type's byte order on success, a negative value on error. |
| 671 | */ |
| 672 | BT_HIDDEN |
| 673 | enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order( |
| 674 | struct bt_ctf_field_type *type); |
| 675 | |
| 676 | |
| 677 | /* |
| 678 | * bt_ctf_field_type_variant_get_tag_field_path: get a variant's tag's field |
| 679 | * path. |
| 680 | * |
| 681 | * Get the variant's tag's field path. |
| 682 | * |
| 683 | * @param type Field type. |
| 684 | * |
| 685 | * Returns the field path on success, NULL on error or if no field path is set. |
| 686 | */ |
| 687 | BT_HIDDEN |
| 688 | struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path( |
| 689 | struct bt_ctf_field_type *type); |
| 690 | |
| 691 | /* |
| 692 | * bt_ctf_field_type_sequence_get_length_field_path: get a sequence's length's |
| 693 | * field path. |
| 694 | * |
| 695 | * Get the sequence's length's field path. |
| 696 | * |
| 697 | * @param type Field type. |
| 698 | * |
| 699 | * Returns the field path on success, NULL on error or if no field path is set. |
| 700 | */ |
| 701 | BT_HIDDEN |
| 702 | struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path( |
| 703 | struct bt_ctf_field_type *type); |
| 704 | |
| 705 | /* |
| 706 | * bt_ctf_field_type_compare: compare two field types recursively |
| 707 | * |
| 708 | * Compare two field types recursively. |
| 709 | * |
| 710 | * The registered tag field type of a variant field type is ignored: |
| 711 | * only the tag strings are compared. |
| 712 | * |
| 713 | * @param type_a Field type A. |
| 714 | * @param type_b Field type B. |
| 715 | * |
| 716 | * Returns 0 if both field types are semantically equivalent, a positive |
| 717 | * value if they are not equivalent, or a negative value on error. |
| 718 | */ |
| 719 | BT_HIDDEN |
| 720 | int bt_ctf_field_type_compare(struct bt_ctf_field_type *type_a, |
| 721 | struct bt_ctf_field_type *type_b); |
| 722 | |
| 723 | /* |
| 724 | * bt_ctf_field_type_get_type_id: get a field type's bt_ctf_type_id. |
| 725 | * |
| 726 | * @param type Field type. |
| 727 | * |
| 728 | * Returns the field type's bt_ctf_type_id, CTF_TYPE_UNKNOWN on error. |
| 729 | */ |
| 730 | BT_HIDDEN |
| 731 | enum bt_ctf_type_id bt_ctf_field_type_get_type_id( |
| 732 | struct bt_ctf_field_type *type); |
| 733 | |
| 734 | /* |
| 735 | * bt_ctf_field_type_is_integer: returns whether or not a given field |
| 736 | * type is an integer type. |
| 737 | * |
| 738 | * @param type Field type. |
| 739 | * |
| 740 | * Returns 1 if the field type is an integer type, 0 otherwise. |
| 741 | */ |
| 742 | BT_HIDDEN |
| 743 | int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *type); |
| 744 | |
| 745 | /* |
| 746 | * bt_ctf_field_type_is_floating_point: returns whether or not a given field |
| 747 | * type is a floating point number type. |
| 748 | * |
| 749 | * @param type Field type. |
| 750 | * |
| 751 | * Returns 1 if the field type is a floating point number type, 0 otherwise. |
| 752 | */ |
| 753 | BT_HIDDEN |
| 754 | int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *type); |
| 755 | |
| 756 | /* |
| 757 | * bt_ctf_field_type_is_enumeration: returns whether or not a given field |
| 758 | * type is an enumeration type. |
| 759 | * |
| 760 | * @param type Field type. |
| 761 | * |
| 762 | * Returns 1 if the field type is an enumeration type, 0 otherwise. |
| 763 | */ |
| 764 | BT_HIDDEN |
| 765 | int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *type); |
| 766 | |
| 767 | /* |
| 768 | * bt_ctf_field_type_is_string: returns whether or not a given field |
| 769 | * type is a string type. |
| 770 | * |
| 771 | * @param type Field type. |
| 772 | * |
| 773 | * Returns 1 if the field type is a string type, 0 otherwise. |
| 774 | */ |
| 775 | BT_HIDDEN |
| 776 | int bt_ctf_field_type_is_string(struct bt_ctf_field_type *type); |
| 777 | |
| 778 | /* |
| 779 | * bt_ctf_field_type_is_structure: returns whether or not a given field |
| 780 | * type is a structure type. |
| 781 | * |
| 782 | * @param type Field type. |
| 783 | * |
| 784 | * Returns 1 if the field type is a structure type, 0 otherwise. |
| 785 | */ |
| 786 | BT_HIDDEN |
| 787 | int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *type); |
| 788 | |
| 789 | /* |
| 790 | * bt_ctf_field_type_is_array: returns whether or not a given field |
| 791 | * type is an array type. |
| 792 | * |
| 793 | * @param type Field type. |
| 794 | * |
| 795 | * Returns 1 if the field type is an array type, 0 otherwise. |
| 796 | */ |
| 797 | BT_HIDDEN |
| 798 | int bt_ctf_field_type_is_array(struct bt_ctf_field_type *type); |
| 799 | |
| 800 | /* |
| 801 | * bt_ctf_field_type_is_sequence: returns whether or not a given field |
| 802 | * type is a sequence type. |
| 803 | * |
| 804 | * @param type Field type. |
| 805 | * |
| 806 | * Returns 1 if the field type is a sequence type, 0 otherwise. |
| 807 | */ |
| 808 | BT_HIDDEN |
| 809 | int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *type); |
| 810 | |
| 811 | /* |
| 812 | * bt_ctf_field_type_is_variant: returns whether or not a given field |
| 813 | * type is a variant type. |
| 814 | * |
| 815 | * @param type Field type. |
| 816 | * |
| 817 | * Returns 1 if the field type is a variant type, 0 otherwise. |
| 818 | */ |
| 819 | BT_HIDDEN |
| 820 | int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *type); |
| 821 | |
| 822 | #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */ |