1 #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
2 #define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
5 * BabelTrace - CTF IR: Event field types internal
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
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/ctf-ir/clock-class.h>
32 #include <babeltrace/ctf-ir/field-types.h>
33 #include <babeltrace/babeltrace-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/types.h>
39 #define BT_ASSERT_PRE_FT_COMMON_HAS_ID(_ft, _type_id, _name) \
40 BT_ASSERT_PRE(((struct bt_field_type_common *) (_ft))->id == (_type_id), \
41 _name " has the wrong type ID: expected-type-id=%s, " \
42 "%![ft-]+_F", bt_common_field_type_id_string(_type_id), (_ft))
44 #define BT_ASSERT_PRE_FT_HOT(_ft, _name) \
45 BT_ASSERT_PRE_HOT((_ft), (_name), ": +%!+_F", (_ft))
47 struct bt_field_common
;
48 struct bt_field_type_common
;
51 typedef void (*bt_field_type_common_method_freeze
)(
52 struct bt_field_type_common
*);
53 typedef int (*bt_field_type_common_method_validate
)(
54 struct bt_field_type_common
*);
55 typedef void (*bt_field_type_common_method_set_byte_order
)(
56 struct bt_field_type_common
*, enum bt_byte_order
);
57 typedef struct bt_field_type_common
*(*bt_field_type_common_method_copy
)(
58 struct bt_field_type_common
*);
59 typedef int (*bt_field_type_common_method_compare
)(
60 struct bt_field_type_common
*,
61 struct bt_field_type_common
*);
63 struct bt_field_type_common_methods
{
64 bt_field_type_common_method_freeze freeze
;
65 bt_field_type_common_method_validate validate
;
66 bt_field_type_common_method_set_byte_order set_byte_order
;
67 bt_field_type_common_method_copy copy
;
68 bt_field_type_common_method_compare compare
;
71 struct bt_field_type_common
{
72 struct bt_object base
;
73 enum bt_field_type_id id
;
74 unsigned int alignment
;
77 struct bt_field_type_common_methods
*methods
;
80 * A type can't be modified once it is added to an event or after a
81 * a field has been instanciated from it.
86 * This flag indicates if the field type is valid. A valid
87 * field type is _always_ frozen. All the nested field types of
88 * a valid field type are also valid (and thus frozen).
93 * Specialized data for either CTF IR or CTF writer APIs.
94 * Having this here ensures that:
96 * * The type-specific common data is always found at the same
97 * offset when the common API has a `struct
98 * bt_field_type_common *` so that you can cast it to `struct
99 * bt_field_type_common_integer *` for example and access the
100 * common integer field type fields.
102 * * The specific CTF IR and CTF writer APIs can access their
103 * specific field type fields in this union at an offset known
104 * at build time. This avoids a pointer to specific data so
105 * that all the fields, common or specific, of a CTF IR
106 * integer field type or of a CTF writer integer field type,
107 * for example, are contained within the same contiguous block
114 void *serialize_func
;
119 struct bt_field_type_common_integer
{
120 struct bt_field_type_common common
;
121 struct bt_clock_class
*mapped_clock_class
;
122 enum bt_byte_order user_byte_order
;
125 enum bt_integer_base base
;
126 enum bt_string_encoding encoding
;
129 struct enumeration_mapping
{
142 struct bt_field_type_common_enumeration
{
143 struct bt_field_type_common common
;
144 struct bt_field_type_common_integer
*container_ft
;
145 GPtrArray
*entries
; /* Array of ptrs to struct enumeration_mapping */
146 /* Only set during validation. */
147 bt_bool has_overlapping_ranges
;
150 enum bt_field_type_enumeration_mapping_iterator_type
{
152 ITERATOR_BY_SIGNED_VALUE
,
153 ITERATOR_BY_UNSIGNED_VALUE
,
156 struct bt_field_type_enumeration_mapping_iterator
{
157 struct bt_object base
;
158 struct bt_field_type_common_enumeration
*enumeration_ft
;
159 enum bt_field_type_enumeration_mapping_iterator_type type
;
163 int64_t signed_value
;
164 uint64_t unsigned_value
;
168 struct bt_field_type_common_floating_point
{
169 struct bt_field_type_common common
;
170 enum bt_byte_order user_byte_order
;
171 unsigned int exp_dig
;
172 unsigned int mant_dig
;
175 struct structure_field_common
{
176 struct bt_field_type_common common
;
178 struct bt_field_type_common
*type
;
181 struct bt_field_type_common_structure
{
182 struct bt_field_type_common common
;
183 GHashTable
*field_name_to_index
;
184 GPtrArray
*fields
; /* Array of pointers to struct structure_field_common */
187 struct bt_field_type_common_variant
{
188 struct bt_field_type_common common
;
190 struct bt_field_type_common_enumeration
*tag_ft
;
191 struct bt_field_path
*tag_field_path
;
192 GHashTable
*field_name_to_index
;
193 GPtrArray
*fields
; /* Array of pointers to struct structure_field_common */
196 struct bt_field_type_common_array
{
197 struct bt_field_type_common common
;
198 struct bt_field_type_common
*element_ft
;
199 unsigned int length
; /* Number of elements */
202 struct bt_field_type_common_sequence
{
203 struct bt_field_type_common common
;
204 struct bt_field_type_common
*element_ft
;
205 GString
*length_field_name
;
206 struct bt_field_path
*length_field_path
;
209 struct bt_field_type_common_string
{
210 struct bt_field_type_common common
;
211 enum bt_string_encoding encoding
;
215 # define bt_field_type_freeze _bt_field_type_freeze
216 # define bt_field_type_common_freeze _bt_field_type_common_freeze
218 # define bt_field_type_freeze(_ft)
219 # define bt_field_type_common_freeze(_ft)
222 typedef struct bt_field_common
*(* bt_field_common_create_func
)(
223 struct bt_field_type_common
*);
226 void bt_field_type_common_initialize(struct bt_field_type_common
*ft
,
227 bool init_bo
, bt_object_release_func release_func
,
228 struct bt_field_type_common_methods
*methods
);
231 void bt_field_type_common_integer_initialize(
232 struct bt_field_type_common
*ft
,
233 unsigned int size
, bt_object_release_func release_func
,
234 struct bt_field_type_common_methods
*methods
);
237 void bt_field_type_common_floating_point_initialize(
238 struct bt_field_type_common
*ft
,
239 bt_object_release_func release_func
,
240 struct bt_field_type_common_methods
*methods
);
243 void bt_field_type_common_enumeration_initialize(
244 struct bt_field_type_common
*ft
,
245 struct bt_field_type_common
*container_ft
,
246 bt_object_release_func release_func
,
247 struct bt_field_type_common_methods
*methods
);
250 void bt_field_type_common_string_initialize(
251 struct bt_field_type_common
*ft
,
252 bt_object_release_func release_func
,
253 struct bt_field_type_common_methods
*methods
);
256 void bt_field_type_common_structure_initialize(
257 struct bt_field_type_common
*ft
,
258 bt_object_release_func release_func
,
259 struct bt_field_type_common_methods
*methods
);
262 void bt_field_type_common_array_initialize(
263 struct bt_field_type_common
*ft
,
264 struct bt_field_type_common
*element_ft
,
265 unsigned int length
, bt_object_release_func release_func
,
266 struct bt_field_type_common_methods
*methods
);
269 void bt_field_type_common_sequence_initialize(
270 struct bt_field_type_common
*ft
,
271 struct bt_field_type_common
*element_ft
,
272 const char *length_field_name
,
273 bt_object_release_func release_func
,
274 struct bt_field_type_common_methods
*methods
);
277 void bt_field_type_common_variant_initialize(
278 struct bt_field_type_common
*ft
,
279 struct bt_field_type_common
*tag_ft
,
280 const char *tag_name
,
281 bt_object_release_func release_func
,
282 struct bt_field_type_common_methods
*methods
);
285 void bt_field_type_common_integer_destroy(struct bt_object
*obj
);
288 void bt_field_type_common_floating_point_destroy(struct bt_object
*obj
);
291 void bt_field_type_common_enumeration_destroy_recursive(struct bt_object
*obj
);
294 void bt_field_type_common_string_destroy(struct bt_object
*obj
);
297 void bt_field_type_common_structure_destroy_recursive(struct bt_object
*obj
);
300 void bt_field_type_common_array_destroy_recursive(struct bt_object
*obj
);
303 void bt_field_type_common_sequence_destroy_recursive(struct bt_object
*obj
);
306 void bt_field_type_common_variant_destroy_recursive(struct bt_object
*obj
);
309 int bt_field_type_common_integer_validate(struct bt_field_type_common
*ft
);
312 int bt_field_type_common_enumeration_validate_recursive(
313 struct bt_field_type_common
*ft
);
316 int bt_field_type_common_sequence_validate_recursive(
317 struct bt_field_type_common
*ft
);
320 int bt_field_type_common_array_validate_recursive(
321 struct bt_field_type_common
*ft
);
324 int bt_field_type_common_structure_validate_recursive(
325 struct bt_field_type_common
*ft
);
328 int bt_field_type_common_variant_validate_recursive(
329 struct bt_field_type_common
*type
);
332 int bt_field_type_common_validate(struct bt_field_type_common
*ft
);
335 int bt_field_type_common_integer_get_size(struct bt_field_type_common
*ft
);
338 bt_bool
bt_field_type_common_integer_is_signed(struct bt_field_type_common
*ft
);
341 int bt_field_type_common_integer_set_is_signed(struct bt_field_type_common
*ft
,
345 int bt_field_type_common_integer_set_size(struct bt_field_type_common
*ft
,
349 enum bt_integer_base
bt_field_type_common_integer_get_base(
350 struct bt_field_type_common
*ft
);
353 int bt_field_type_common_integer_set_base(struct bt_field_type_common
*ft
,
354 enum bt_integer_base base
);
357 enum bt_string_encoding
bt_field_type_common_integer_get_encoding(
358 struct bt_field_type_common
*ft
);
361 int bt_field_type_common_integer_set_encoding(struct bt_field_type_common
*ft
,
362 enum bt_string_encoding encoding
);
365 struct bt_clock_class
*bt_field_type_common_integer_get_mapped_clock_class(
366 struct bt_field_type_common
*ft
);
369 int bt_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
370 struct bt_field_type_common
*ft
,
371 struct bt_clock_class
*clock_class
);
374 int bt_field_type_common_integer_set_mapped_clock_class(
375 struct bt_field_type_common
*ft
,
376 struct bt_clock_class
*clock_class
);
379 struct bt_field_type_enumeration_mapping_iterator
*
380 bt_field_type_common_enumeration_find_mappings_by_name(
381 struct bt_field_type_common
*ft
, const char *name
);
384 struct bt_field_type_enumeration_mapping_iterator
*
385 bt_field_type_common_enumeration_signed_find_mappings_by_value(
386 struct bt_field_type_common
*ft
, int64_t value
);
389 struct bt_field_type_enumeration_mapping_iterator
*
390 bt_field_type_common_enumeration_unsigned_find_mappings_by_value(
391 struct bt_field_type_common
*ft
, uint64_t value
);
394 int bt_field_type_common_enumeration_signed_get_mapping_by_index(
395 struct bt_field_type_common
*ft
, uint64_t index
,
396 const char **mapping_name
, int64_t *range_begin
,
400 int bt_field_type_common_enumeration_unsigned_get_mapping_by_index(
401 struct bt_field_type_common
*ft
, uint64_t index
,
402 const char **mapping_name
, uint64_t *range_begin
,
403 uint64_t *range_end
);
406 struct bt_field_type_common
*bt_field_type_common_enumeration_get_container_field_type(
407 struct bt_field_type_common
*ft
);
410 int bt_field_type_common_enumeration_signed_add_mapping(
411 struct bt_field_type_common
*ft
, const char *string
,
412 int64_t range_start
, int64_t range_end
);
415 int bt_field_type_common_enumeration_unsigned_add_mapping(
416 struct bt_field_type_common
*ft
, const char *string
,
417 uint64_t range_start
, uint64_t range_end
);
420 int64_t bt_field_type_common_enumeration_get_mapping_count(
421 struct bt_field_type_common
*ft
);
424 int bt_field_type_common_floating_point_get_exponent_digits(
425 struct bt_field_type_common
*ft
);
428 int bt_field_type_common_floating_point_set_exponent_digits(
429 struct bt_field_type_common
*ft
,
430 unsigned int exponent_digits
);
433 int bt_field_type_common_floating_point_get_mantissa_digits(
434 struct bt_field_type_common
*type
);
437 int bt_field_type_common_floating_point_set_mantissa_digits(
438 struct bt_field_type_common
*ft
, unsigned int mantissa_digits
);
441 int bt_field_type_common_structure_replace_field(
442 struct bt_field_type_common
*ft
,
443 const char *field_name
,
444 struct bt_field_type_common
*field_type
);
447 int bt_field_type_common_structure_add_field(struct bt_field_type_common
*ft
,
448 struct bt_field_type_common
*field_type
,
449 const char *field_name
);
452 int64_t bt_field_type_common_structure_get_field_count(
453 struct bt_field_type_common
*ft
);
456 int bt_field_type_common_structure_get_field_by_index(
457 struct bt_field_type_common
*ft
,
458 const char **field_name
,
459 struct bt_field_type_common
**field_type
, uint64_t index
);
462 struct bt_field_type_common
*bt_field_type_common_structure_get_field_type_by_name(
463 struct bt_field_type_common
*ft
, const char *name
);
466 struct bt_field_type_common
*bt_field_type_common_variant_get_tag_field_type(
467 struct bt_field_type_common
*ft
);
470 const char *bt_field_type_common_variant_get_tag_name(
471 struct bt_field_type_common
*ft
);
474 int bt_field_type_common_variant_set_tag_name(
475 struct bt_field_type_common
*ft
, const char *name
);
478 int bt_field_type_common_variant_add_field(struct bt_field_type_common
*ft
,
479 struct bt_field_type_common
*field_type
,
480 const char *field_name
);
483 struct bt_field_type_common
*bt_field_type_common_variant_get_field_type_by_name(
484 struct bt_field_type_common
*ft
,
485 const char *field_name
);
488 struct bt_field_type_common
*bt_field_type_common_variant_get_field_type_from_tag(
489 struct bt_field_type_common
*ft
,
490 struct bt_field_common
*tag_field
,
491 bt_field_common_create_func field_create_func
);
494 int64_t bt_field_type_common_variant_get_field_count(
495 struct bt_field_type_common
*ft
);
498 int bt_field_type_common_variant_get_field_by_index(
499 struct bt_field_type_common
*ft
,
500 const char **field_name
,
501 struct bt_field_type_common
**field_type
, uint64_t index
);
504 struct bt_field_type_common
*bt_field_type_common_array_get_element_field_type(
505 struct bt_field_type_common
*ft
);
508 int bt_field_type_common_array_set_element_field_type(
509 struct bt_field_type_common
*ft
,
510 struct bt_field_type_common
*element_ft
);
513 int64_t bt_field_type_common_array_get_length(struct bt_field_type_common
*ft
);
516 struct bt_field_type_common
*bt_field_type_common_sequence_get_element_field_type(
517 struct bt_field_type_common
*ft
);
520 int bt_field_type_common_sequence_set_element_field_type(
521 struct bt_field_type_common
*ft
,
522 struct bt_field_type_common
*element_ft
);
525 const char *bt_field_type_common_sequence_get_length_field_name(
526 struct bt_field_type_common
*ft
);
529 enum bt_string_encoding
bt_field_type_common_string_get_encoding(
530 struct bt_field_type_common
*ft
);
533 int bt_field_type_common_string_set_encoding(struct bt_field_type_common
*ft
,
534 enum bt_string_encoding encoding
);
537 int bt_field_type_common_get_alignment(struct bt_field_type_common
*type
);
540 int bt_field_type_common_set_alignment(struct bt_field_type_common
*ft
,
541 unsigned int alignment
);
544 enum bt_byte_order
bt_field_type_common_get_byte_order(
545 struct bt_field_type_common
*ft
);
548 int bt_field_type_common_set_byte_order(struct bt_field_type_common
*ft
,
549 enum bt_byte_order byte_order
);
552 enum bt_field_type_id
bt_field_type_common_get_type_id(
553 struct bt_field_type_common
*ft
);
556 void _bt_field_type_common_freeze(struct bt_field_type_common
*ft
);
559 void _bt_field_type_freeze(struct bt_field_type
*ft
);
562 struct bt_field_type_common
*bt_field_type_common_variant_get_field_type_signed(
563 struct bt_field_type_common_variant
*var_ft
,
567 struct bt_field_type_common
*bt_field_type_common_variant_get_field_type_unsigned(
568 struct bt_field_type_common_variant
*var_ft
,
572 struct bt_field_type_common
*bt_field_type_common_copy(
573 struct bt_field_type_common
*ft
);
576 int bt_field_type_common_structure_get_field_name_index(
577 struct bt_field_type_common
*ft
, const char *name
);
580 int bt_field_type_common_variant_get_field_name_index(
581 struct bt_field_type_common
*ft
, const char *name
);
584 int bt_field_type_common_sequence_set_length_field_path(
585 struct bt_field_type_common
*ft
, struct bt_field_path
*path
);
588 int bt_field_type_common_variant_set_tag_field_path(
589 struct bt_field_type_common
*ft
,
590 struct bt_field_path
*path
);
593 int bt_field_type_common_variant_set_tag_field_type(
594 struct bt_field_type_common
*ft
,
595 struct bt_field_type_common
*tag_ft
);
598 void bt_field_type_common_generic_freeze(struct bt_field_type_common
*ft
);
601 void bt_field_type_common_enumeration_freeze_recursive(
602 struct bt_field_type_common
*ft
);
605 void bt_field_type_common_structure_freeze_recursive(
606 struct bt_field_type_common
*ft
);
609 void bt_field_type_common_variant_freeze_recursive(
610 struct bt_field_type_common
*ft
);
613 void bt_field_type_common_array_freeze_recursive(
614 struct bt_field_type_common
*ft
);
617 void bt_field_type_common_sequence_freeze_recursive(
618 struct bt_field_type_common
*type
);
621 void bt_field_type_common_integer_set_byte_order(
622 struct bt_field_type_common
*ft
, enum bt_byte_order byte_order
);
625 void bt_field_type_common_enumeration_set_byte_order_recursive(
626 struct bt_field_type_common
*ft
, enum bt_byte_order byte_order
);
629 void bt_field_type_common_floating_point_set_byte_order(
630 struct bt_field_type_common
*ft
, enum bt_byte_order byte_order
);
633 void bt_field_type_common_structure_set_byte_order_recursive(
634 struct bt_field_type_common
*ft
,
635 enum bt_byte_order byte_order
);
638 void bt_field_type_common_variant_set_byte_order_recursive(
639 struct bt_field_type_common
*ft
,
640 enum bt_byte_order byte_order
);
643 void bt_field_type_common_array_set_byte_order_recursive(
644 struct bt_field_type_common
*ft
,
645 enum bt_byte_order byte_order
);
648 void bt_field_type_common_sequence_set_byte_order_recursive(
649 struct bt_field_type_common
*ft
,
650 enum bt_byte_order byte_order
);
653 int bt_field_type_common_integer_compare(struct bt_field_type_common
*ft_a
,
654 struct bt_field_type_common
*ft_b
);
657 int bt_field_type_common_floating_point_compare(
658 struct bt_field_type_common
*ft_a
,
659 struct bt_field_type_common
*ft_b
);
662 int bt_field_type_common_enumeration_compare_recursive(
663 struct bt_field_type_common
*ft_a
,
664 struct bt_field_type_common
*ft_b
);
667 int bt_field_type_common_string_compare(struct bt_field_type_common
*ft_a
,
668 struct bt_field_type_common
*ft_b
);
671 int bt_field_type_common_structure_compare_recursive(
672 struct bt_field_type_common
*ft_a
,
673 struct bt_field_type_common
*ft_b
);
676 int bt_field_type_common_variant_compare_recursive(
677 struct bt_field_type_common
*ft_a
,
678 struct bt_field_type_common
*ft_b
);
681 int bt_field_type_common_array_compare_recursive(
682 struct bt_field_type_common
*ft_a
,
683 struct bt_field_type_common
*ft_b
);
686 int bt_field_type_common_sequence_compare_recursive(
687 struct bt_field_type_common
*ft_a
,
688 struct bt_field_type_common
*ft_b
);
691 int bt_field_type_common_compare(struct bt_field_type_common
*ft_a
,
692 struct bt_field_type_common
*ft_b
);
695 int64_t bt_field_type_common_get_field_count(struct bt_field_type_common
*ft
);
698 struct bt_field_type_common
*bt_field_type_common_get_field_at_index(
699 struct bt_field_type_common
*ft
, int index
);
702 int bt_field_type_common_get_field_index(struct bt_field_type_common
*ft
,
706 struct bt_field_path
*bt_field_type_common_variant_get_tag_field_path(
707 struct bt_field_type_common
*ft
);
710 struct bt_field_path
*bt_field_type_common_sequence_get_length_field_path(
711 struct bt_field_type_common
*ft
);
714 int bt_field_type_common_validate_single_clock_class(
715 struct bt_field_type_common
*ft
,
716 struct bt_clock_class
**expected_clock_class
);
718 #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */