2 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #define BT_LOG_TAG "CTF-WRITER-FIELD-TYPES"
26 #include <babeltrace/lib-logging-internal.h>
28 #include <babeltrace/assert-pre-internal.h>
29 #include <babeltrace/assert-internal.h>
30 #include <babeltrace/compiler-internal.h>
31 #include <babeltrace/ctf-writer/clock-class-internal.h>
32 #include <babeltrace/ctf-writer/clock-internal.h>
33 #include <babeltrace/ctf-writer/field-path-internal.h>
34 #include <babeltrace/ctf-writer/field-types-internal.h>
35 #include <babeltrace/ctf-writer/field-types.h>
36 #include <babeltrace/ctf-writer/fields-internal.h>
37 #include <babeltrace/ctf-writer/fields.h>
38 #include <babeltrace/ctf-writer/utils-internal.h>
39 #include <babeltrace/ctf-writer/utils.h>
40 #include <babeltrace/endian-internal.h>
41 #include <babeltrace/object-internal.h>
42 #include <babeltrace/object.h>
48 void destroy_enumeration_mapping(struct bt_ctf_enumeration_mapping
*mapping
)
54 void bt_ctf_field_type_common_initialize(struct bt_ctf_field_type_common
*ft
,
55 bool init_bo
, bt_object_release_func release_func
,
56 struct bt_ctf_field_type_common_methods
*methods
)
58 BT_ASSERT(ft
&& (ft
->id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
) &&
59 (ft
->id
< BT_CTF_FIELD_TYPE_ID_NR
));
61 bt_object_init_shared(&ft
->base
, release_func
);
62 ft
->methods
= methods
;
66 const enum bt_ctf_byte_order bo
= BT_CTF_BYTE_ORDER_NATIVE
;
68 BT_LOGD("Setting initial field type's byte order: bo=%s",
69 bt_ctf_byte_order_string(bo
));
70 ret
= bt_ctf_field_type_common_set_byte_order(ft
, bo
);
78 void bt_ctf_field_type_common_integer_initialize(
79 struct bt_ctf_field_type_common
*ft
,
80 unsigned int size
, bt_object_release_func release_func
,
81 struct bt_ctf_field_type_common_methods
*methods
)
83 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
86 BT_LOGD("Initializing common integer field type object: size=%u",
88 ft
->id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
90 int_ft
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
91 int_ft
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
92 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
93 BT_LOGD("Initialized common integer field type object: addr=%p, size=%u",
98 void bt_ctf_field_type_common_floating_point_initialize(
99 struct bt_ctf_field_type_common
*ft
,
100 bt_object_release_func release_func
,
101 struct bt_ctf_field_type_common_methods
*methods
)
103 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
105 BT_LOGD_STR("Initializing common floating point number field type object.");
106 ft
->id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
107 flt_ft
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
108 flt_ft
->mant_dig
= FLT_MANT_DIG
;
109 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
110 BT_LOGD("Initialized common floating point number field type object: addr=%p, "
111 "exp-size=%u, mant-size=%u", ft
, flt_ft
->exp_dig
,
116 void bt_ctf_field_type_common_enumeration_initialize(
117 struct bt_ctf_field_type_common
*ft
,
118 struct bt_ctf_field_type_common
*container_ft
,
119 bt_object_release_func release_func
,
120 struct bt_ctf_field_type_common_methods
*methods
)
122 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
124 BT_ASSERT(container_ft
);
125 BT_LOGD("Initializing common enumeration field type object: int-ft-addr=%p",
127 ft
->id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
128 enum_ft
->container_ft
= bt_object_get_ref(container_ft
);
129 enum_ft
->entries
= g_ptr_array_new_with_free_func(
130 (GDestroyNotify
) destroy_enumeration_mapping
);
131 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
132 BT_LOGD("Initialized common enumeration field type object: addr=%p, "
133 "int-ft-addr=%p, int-ft-size=%u", ft
, container_ft
,
134 bt_ctf_field_type_common_integer_get_size(container_ft
));
138 void bt_ctf_field_type_common_string_initialize(
139 struct bt_ctf_field_type_common
*ft
,
140 bt_object_release_func release_func
,
141 struct bt_ctf_field_type_common_methods
*methods
)
143 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
145 BT_LOGD_STR("Initializing common string field type object.");
146 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRING
;
147 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
148 string_ft
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
149 ft
->alignment
= CHAR_BIT
;
150 BT_LOGD("Initialized common string field type object: addr=%p", ft
);
154 void bt_ctf_field_type_common_structure_initialize(
155 struct bt_ctf_field_type_common
*ft
,
156 bt_object_release_func release_func
,
157 struct bt_ctf_field_type_common_methods
*methods
)
159 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
161 BT_LOGD_STR("Initializing common structure field type object.");
162 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
163 struct_ft
->fields
= g_array_new(FALSE
, TRUE
,
164 sizeof(struct bt_ctf_field_type_common_structure_field
));
165 struct_ft
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
166 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
167 BT_LOGD("Initialized common structure field type object: addr=%p", ft
);
171 void bt_ctf_field_type_common_array_initialize(
172 struct bt_ctf_field_type_common
*ft
,
173 struct bt_ctf_field_type_common
*element_ft
,
174 unsigned int length
, bt_object_release_func release_func
,
175 struct bt_ctf_field_type_common_methods
*methods
)
177 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
179 BT_ASSERT(element_ft
);
180 BT_LOGD("Initializing common array field type object: element-ft-addr=%p, "
181 "length=%u", element_ft
, length
);
182 ft
->id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
183 array_ft
->element_ft
= bt_object_get_ref(element_ft
);
184 array_ft
->length
= length
;
185 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
186 BT_LOGD("Initialized common array field type object: addr=%p, "
187 "element-ft-addr=%p, length=%u", ft
, element_ft
, length
);
191 void bt_ctf_field_type_common_sequence_initialize(
192 struct bt_ctf_field_type_common
*ft
,
193 struct bt_ctf_field_type_common
*element_ft
,
194 const char *length_field_name
,
195 bt_object_release_func release_func
,
196 struct bt_ctf_field_type_common_methods
*methods
)
198 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
200 BT_ASSERT(element_ft
);
201 BT_ASSERT(length_field_name
);
202 BT_ASSERT(bt_ctf_identifier_is_valid(length_field_name
));
203 BT_LOGD("Initializing common sequence field type object: element-ft-addr=%p, "
204 "length-field-name=\"%s\"", element_ft
, length_field_name
);
205 ft
->id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
206 seq_ft
->element_ft
= bt_object_get_ref(element_ft
);
207 seq_ft
->length_field_name
= g_string_new(length_field_name
);
208 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
209 BT_LOGD("Initialized common sequence field type object: addr=%p, "
210 "element-ft-addr=%p, length-field-name=\"%s\"",
211 ft
, element_ft
, length_field_name
);
215 void bt_ctf_field_type_common_variant_initialize(
216 struct bt_ctf_field_type_common
*ft
,
217 struct bt_ctf_field_type_common
*tag_ft
,
218 const char *tag_name
,
219 bt_object_release_func release_func
,
220 struct bt_ctf_field_type_common_methods
*methods
)
222 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
224 BT_ASSERT(!tag_name
|| bt_ctf_identifier_is_valid(tag_name
));
225 BT_LOGD("Initializing common variant field type object: "
226 "tag-ft-addr=%p, tag-field-name=\"%s\"",
228 ft
->id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
229 var_ft
->tag_name
= g_string_new(tag_name
);
230 var_ft
->choice_name_to_index
= g_hash_table_new(NULL
, NULL
);
231 var_ft
->choices
= g_array_new(FALSE
, TRUE
,
232 sizeof(struct bt_ctf_field_type_common_variant_choice
));
235 var_ft
->tag_ft
= bt_object_get_ref(tag_ft
);
238 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
239 /* A variant's alignment is undefined */
241 BT_LOGD("Initialized common variant field type object: addr=%p, "
242 "tag-ft-addr=%p, tag-field-name=\"%s\"",
243 ft
, tag_ft
, tag_name
);
247 void bt_ctf_field_type_common_integer_destroy(struct bt_object
*obj
)
249 struct bt_ctf_field_type_common_integer
*ft
= (void *) obj
;
255 BT_LOGD("Destroying integer field type object: addr=%p", ft
);
256 BT_LOGD_STR("Putting mapped clock class.");
257 bt_object_put_ref(ft
->mapped_clock_class
);
262 void bt_ctf_field_type_common_floating_point_destroy(struct bt_object
*obj
)
264 struct bt_ctf_field_type_common_floating_point
*ft
= (void *) obj
;
270 BT_LOGD("Destroying floating point number field type object: addr=%p", ft
);
275 void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_object
*obj
)
277 struct bt_ctf_field_type_common_enumeration
*ft
= (void *) obj
;
283 BT_LOGD("Destroying enumeration field type object: addr=%p", ft
);
284 g_ptr_array_free(ft
->entries
, TRUE
);
285 BT_LOGD_STR("Putting container field type.");
286 bt_object_put_ref(ft
->container_ft
);
291 void bt_ctf_field_type_common_string_destroy(struct bt_object
*obj
)
293 struct bt_ctf_field_type_common_string
*ft
= (void *) obj
;
299 BT_LOGD("Destroying string field type object: addr=%p", ft
);
304 void bt_ctf_field_type_common_structure_field_finalize(
305 struct bt_ctf_field_type_common_structure_field
*field
)
311 BT_LOGD("Finalizing structure field type's field: "
312 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
313 field
, field
->type
, g_quark_to_string(field
->name
));
314 BT_LOGD_STR("Putting field type.");
315 bt_object_put_ref(field
->type
);
319 void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_object
*obj
)
321 struct bt_ctf_field_type_common_structure
*ft
= (void *) obj
;
328 BT_LOGD("Destroying structure field type object: addr=%p", ft
);
331 for (i
= 0; i
< ft
->fields
->len
; i
++) {
332 bt_ctf_field_type_common_structure_field_finalize(
333 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
337 g_array_free(ft
->fields
, TRUE
);
340 if (ft
->field_name_to_index
) {
341 g_hash_table_destroy(ft
->field_name_to_index
);
348 void bt_ctf_field_type_common_array_destroy_recursive(struct bt_object
*obj
)
350 struct bt_ctf_field_type_common_array
*ft
= (void *) obj
;
356 BT_LOGD("Destroying array field type object: addr=%p", ft
);
357 BT_LOGD_STR("Putting element field type.");
358 bt_object_put_ref(ft
->element_ft
);
363 void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_object
*obj
)
365 struct bt_ctf_field_type_common_sequence
*ft
= (void *) obj
;
371 BT_LOGD("Destroying sequence field type object: addr=%p", ft
);
372 BT_LOGD_STR("Putting element field type.");
373 bt_object_put_ref(ft
->element_ft
);
374 g_string_free(ft
->length_field_name
, TRUE
);
375 BT_LOGD_STR("Putting length field path.");
376 bt_object_put_ref(ft
->length_field_path
);
381 void bt_ctf_field_type_common_variant_choice_finalize(
382 struct bt_ctf_field_type_common_variant_choice
*choice
)
388 BT_LOGD("Finalizing variant field type's choice: "
389 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
390 choice
, choice
->type
, g_quark_to_string(choice
->name
));
391 BT_LOGD_STR("Putting field type.");
392 bt_object_put_ref(choice
->type
);
394 if (choice
->ranges
) {
395 g_array_free(choice
->ranges
, TRUE
);
400 void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_object
*obj
)
402 struct bt_ctf_field_type_common_variant
*ft
= (void *) obj
;
409 BT_LOGD("Destroying variant field type object: addr=%p", ft
);
412 for (i
= 0; i
< ft
->choices
->len
; i
++) {
413 bt_ctf_field_type_common_variant_choice_finalize(
414 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
418 g_array_free(ft
->choices
, TRUE
);
421 if (ft
->choice_name_to_index
) {
422 g_hash_table_destroy(ft
->choice_name_to_index
);
426 g_string_free(ft
->tag_name
, TRUE
);
429 BT_LOGD_STR("Putting tag field type.");
430 bt_object_put_ref(ft
->tag_ft
);
431 BT_LOGD_STR("Putting tag field path.");
432 bt_object_put_ref(ft
->tag_field_path
);
436 struct range_overlap_query
{
451 void check_ranges_overlap(gpointer element
, gpointer query
)
453 struct bt_ctf_enumeration_mapping
*mapping
= element
;
454 struct range_overlap_query
*overlap_query
= query
;
456 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
457 && overlap_query
->range_start
._signed
<=
458 mapping
->range_end
._signed
) {
459 overlap_query
->overlaps
= 1;
460 overlap_query
->mapping_name
= mapping
->string
;
463 overlap_query
->overlaps
|=
464 mapping
->string
== overlap_query
->mapping_name
;
466 if (overlap_query
->overlaps
) {
467 BT_LOGV("Overlapping enumeration field type mappings: "
468 "mapping-name=\"%s\", "
469 "mapping-a-range-start=%" PRId64
", "
470 "mapping-a-range-end=%" PRId64
", "
471 "mapping-b-range-start=%" PRId64
", "
472 "mapping-b-range-end=%" PRId64
,
473 g_quark_to_string(mapping
->string
),
474 mapping
->range_start
._signed
,
475 mapping
->range_end
._signed
,
476 overlap_query
->range_start
._signed
,
477 overlap_query
->range_end
._signed
);
482 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
484 struct bt_ctf_enumeration_mapping
*mapping
= element
;
485 struct range_overlap_query
*overlap_query
= query
;
487 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
488 && overlap_query
->range_start
._unsigned
<=
489 mapping
->range_end
._unsigned
) {
490 overlap_query
->overlaps
= 1;
491 overlap_query
->mapping_name
= mapping
->string
;
494 overlap_query
->overlaps
|=
495 mapping
->string
== overlap_query
->mapping_name
;
497 if (overlap_query
->overlaps
) {
498 BT_LOGW("Overlapping enumeration field type mappings: "
499 "mapping-name=\"%s\", "
500 "mapping-a-range-start=%" PRIu64
", "
501 "mapping-a-range-end=%" PRIu64
", "
502 "mapping-b-range-start=%" PRIu64
", "
503 "mapping-b-range-end=%" PRIu64
,
504 g_quark_to_string(mapping
->string
),
505 mapping
->range_start
._unsigned
,
506 mapping
->range_end
._unsigned
,
507 overlap_query
->range_start
._unsigned
,
508 overlap_query
->range_end
._unsigned
);
513 gint
compare_enumeration_mappings_signed(struct bt_ctf_enumeration_mapping
**a
,
514 struct bt_ctf_enumeration_mapping
**b
)
516 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
520 gint
compare_enumeration_mappings_unsigned(struct bt_ctf_enumeration_mapping
**a
,
521 struct bt_ctf_enumeration_mapping
**b
)
523 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
527 int add_structure_variant_member(GArray
*members
,
528 GHashTable
*field_name_to_index
,
529 struct bt_ctf_field_type_common
*field_type
, const char *field_name
,
533 GQuark name_quark
= g_quark_from_string(field_name
);
534 struct bt_ctf_field_type_common
**member_ft
;
537 /* Make sure structure does not contain a field of the same name */
538 if (g_hash_table_lookup_extended(field_name_to_index
,
539 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
540 BT_LOGW("Structure or variant field type already contains a field type with this name: "
541 "field-name=\"%s\"", field_name
);
546 g_array_set_size(members
, members
->len
+ 1);
549 struct bt_ctf_field_type_common_variant_choice
*choice
=
550 &g_array_index(members
,
551 struct bt_ctf_field_type_common_variant_choice
,
554 member_ft
= &choice
->type
;
555 member_name
= &choice
->name
;
556 BT_ASSERT(!choice
->ranges
);
557 choice
->ranges
= g_array_new(FALSE
, TRUE
,
558 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
559 BT_ASSERT(choice
->ranges
);
561 struct bt_ctf_field_type_common_structure_field
*field
=
562 &g_array_index(members
,
563 struct bt_ctf_field_type_common_structure_field
,
566 member_ft
= &field
->type
;
567 member_name
= &field
->name
;
570 *member_name
= name_quark
;
571 *member_ft
= bt_object_get_ref(field_type
);
572 g_hash_table_insert(field_name_to_index
,
573 GUINT_TO_POINTER(name_quark
),
574 GUINT_TO_POINTER(members
->len
- 1));
575 BT_LOGV("Added structure/variant field type member: member-ft-addr=%p, "
576 "member-name=\"%s\"", field_type
, field_name
);
583 int bt_ctf_field_type_common_integer_validate(struct bt_ctf_field_type_common
*ft
)
586 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
588 if (int_ft
->mapped_clock_class
&& int_ft
->is_signed
) {
589 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
590 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
591 ft
, int_ft
->mapped_clock_class
,
592 bt_ctf_clock_class_get_name(int_ft
->mapped_clock_class
));
602 void bt_ctf_field_type_enum_iter_destroy(struct bt_object
*obj
)
604 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
606 struct bt_ctf_field_type_enumeration_mapping_iterator
,
609 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
611 BT_LOGD_STR("Putting parent enumeration field type.");
612 bt_object_put_ref(iter
->enumeration_ft
);
617 struct bt_ctf_field_type_enumeration_mapping_iterator
*
618 bt_ctf_field_type_common_enumeration_find_mappings_type(
619 struct bt_ctf_field_type_common
*ft
,
620 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
622 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
624 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
625 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
,
627 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
629 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
633 bt_object_init_shared(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
634 iter
->enumeration_ft
= bt_object_get_ref(ft
);
636 iter
->type
= iterator_type
;
643 struct bt_ctf_field_type_enumeration_mapping_iterator
*
644 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
645 struct bt_ctf_field_type_common
*ft
, const char *name
)
647 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
649 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
650 ft
, CTF_ITERATOR_BY_NAME
);
652 BT_LOGW("Cannot create enumeration field type mapping iterator: "
653 "ft-addr=%p, mapping-name=\"%s\"", ft
, name
);
657 iter
->u
.name_quark
= g_quark_try_string(name
);
658 if (!iter
->u
.name_quark
) {
660 * No results are possible, set the iterator's position at the
663 iter
->index
= iter
->enumeration_ft
->entries
->len
;
669 bt_object_put_ref(iter
);
674 struct bt_ctf_enumeration_mapping
*bt_ctf_field_type_common_enumeration_get_mapping_by_index(
675 struct bt_ctf_field_type_common
*ft
, uint64_t index
)
677 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
678 struct bt_ctf_enumeration_mapping
*mapping
= NULL
;
680 if (index
>= enum_ft
->entries
->len
) {
681 BT_LOGW("Invalid parameter: index is out of bounds: "
682 "addr=%p, index=%" PRIu64
", count=%u",
683 ft
, index
, enum_ft
->entries
->len
);
687 mapping
= g_ptr_array_index(enum_ft
->entries
, index
);
694 int bt_ctf_field_type_enumeration_mapping_iterator_next(
695 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
697 struct bt_ctf_field_type_common_enumeration
*enum_ft
= iter
->enumeration_ft
;
700 BT_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
701 len
= enum_ft
->entries
->len
;
702 for (i
= iter
->index
+ 1; i
< len
; i
++) {
703 struct bt_ctf_enumeration_mapping
*mapping
=
704 bt_ctf_field_type_common_enumeration_get_mapping_by_index(
705 BT_CTF_TO_COMMON(enum_ft
), i
);
707 switch (iter
->type
) {
708 case CTF_ITERATOR_BY_NAME
:
709 if (mapping
->string
== iter
->u
.name_quark
) {
714 case CTF_ITERATOR_BY_SIGNED_VALUE
:
716 int64_t value
= iter
->u
.signed_value
;
718 if (value
>= mapping
->range_start
._signed
&&
719 value
<= mapping
->range_end
._signed
) {
725 case CTF_ITERATOR_BY_UNSIGNED_VALUE
:
727 uint64_t value
= iter
->u
.unsigned_value
;
729 if (value
>= mapping
->range_start
._unsigned
&&
730 value
<= mapping
->range_end
._unsigned
) {
737 BT_LOGF("Invalid enumeration field type mapping iterator type: "
738 "type=%d", iter
->type
);
750 struct bt_ctf_field_type_enumeration_mapping_iterator
*
751 bt_ctf_field_type_common_enumeration_signed_find_mappings_by_value(
752 struct bt_ctf_field_type_common
*ft
, int64_t value
)
754 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
756 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
757 ft
, CTF_ITERATOR_BY_SIGNED_VALUE
);
759 BT_LOGW("Cannot create enumeration field type mapping iterator: "
760 "ft-addr=%p, value=%" PRId64
, ft
, value
);
764 if (bt_ctf_field_type_common_integer_is_signed(
765 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 1) {
766 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
767 "enum-ft-addr=%p, int-ft-addr=%p",
768 ft
, iter
->enumeration_ft
->container_ft
);
772 iter
->u
.signed_value
= value
;
776 bt_object_put_ref(iter
);
781 struct bt_ctf_field_type_enumeration_mapping_iterator
*
782 bt_ctf_field_type_common_enumeration_unsigned_find_mappings_by_value(
783 struct bt_ctf_field_type_common
*ft
, uint64_t value
)
785 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
787 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
788 ft
, CTF_ITERATOR_BY_UNSIGNED_VALUE
);
790 BT_LOGW("Cannot create enumeration field type mapping iterator: "
791 "ft-addr=%p, value=%" PRIu64
, ft
, value
);
795 if (bt_ctf_field_type_common_integer_is_signed(
796 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 0) {
797 BT_LOGW("Invalid parameter: enumeration field type is signed: "
798 "enum-ft-addr=%p, int-ft-addr=%p",
799 ft
, iter
->enumeration_ft
->container_ft
);
803 iter
->u
.unsigned_value
= value
;
807 bt_object_put_ref(iter
);
812 int bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
813 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
814 const char **mapping_name
, int64_t *range_begin
,
817 BT_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
818 BT_ASSERT_PRE(iter
->index
!= -1,
819 "Invalid enumeration field type mapping iterator access: "
820 "addr=%p, position=-1", iter
);
821 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
822 (void *) iter
->enumeration_ft
, iter
->index
,
823 mapping_name
, range_begin
, range_end
);
827 int bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
828 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
829 const char **mapping_name
, uint64_t *range_begin
,
832 BT_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
833 BT_ASSERT_PRE(iter
->index
!= -1,
834 "Invalid enumeration field type mapping iterator access: "
835 "addr=%p, position=-1", iter
);
836 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
837 (void *) iter
->enumeration_ft
, iter
->index
,
838 mapping_name
, range_begin
, range_end
);
842 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
843 * Only used when freezing an enumeration.
846 void bt_ctf_field_type_common_enumeration_set_range_overlap(
847 struct bt_ctf_field_type_common_enumeration
*ft
)
852 BT_LOGV("Setting enumeration field type's overlap flag: addr=%p",
854 len
= ft
->entries
->len
;
855 is_signed
= bt_ctf_field_type_common_integer_is_signed(
856 BT_CTF_TO_COMMON(ft
->container_ft
));
858 for (i
= 0; i
< len
; i
++) {
859 for (j
= i
+ 1; j
< len
; j
++) {
860 struct bt_ctf_enumeration_mapping
*mapping
[2];
862 mapping
[0] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
863 BT_CTF_TO_COMMON(ft
), i
);
864 mapping
[1] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
865 BT_CTF_TO_COMMON(ft
), j
);
867 if (mapping
[0]->range_start
._signed
868 <= mapping
[1]->range_end
._signed
869 && mapping
[0]->range_end
._signed
870 >= mapping
[1]->range_start
._signed
) {
871 ft
->has_overlapping_ranges
= BT_TRUE
;
875 if (mapping
[0]->range_start
._unsigned
876 <= mapping
[1]->range_end
._unsigned
877 && mapping
[0]->range_end
._unsigned
878 >= mapping
[1]->range_start
._unsigned
) {
879 ft
->has_overlapping_ranges
= BT_TRUE
;
887 if (ft
->has_overlapping_ranges
) {
888 BT_LOGV_STR("Enumeration field type has overlapping ranges.");
890 BT_LOGV_STR("Enumeration field type has no overlapping ranges.");
895 int bt_ctf_field_type_common_enumeration_validate_recursive(
896 struct bt_ctf_field_type_common
*ft
)
899 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
901 ret
= bt_ctf_field_type_common_integer_validate(
902 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
904 BT_LOGW("Invalid enumeration field type: container type is invalid: "
905 "enum-ft-addr=%p, int-ft-addr=%p",
906 ft
, enum_ft
->container_ft
);
910 /* Ensure enum has entries */
911 if (enum_ft
->entries
->len
== 0) {
912 BT_LOGW("Invalid enumeration field type: no entries: "
923 int bt_ctf_field_type_common_sequence_validate_recursive(
924 struct bt_ctf_field_type_common
*ft
)
927 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
929 /* Length field name should be set at this point */
930 if (seq_ft
->length_field_name
->len
== 0) {
931 BT_LOGW("Invalid sequence field type: no length field name: "
937 ret
= bt_ctf_field_type_common_validate(seq_ft
->element_ft
);
939 BT_LOGW("Invalid sequence field type: invalid element field type: "
940 "seq-ft-addr=%p, element-ft-add=%p",
941 ft
, seq_ft
->element_ft
);
949 int bt_ctf_field_type_common_array_validate_recursive(
950 struct bt_ctf_field_type_common
*ft
)
953 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
955 ret
= bt_ctf_field_type_common_validate(array_ft
->element_ft
);
957 BT_LOGW("Invalid array field type: invalid element field type: "
958 "array-ft-addr=%p, element-ft-add=%p",
959 ft
, array_ft
->element_ft
);
966 int bt_ctf_field_type_common_structure_validate_recursive(
967 struct bt_ctf_field_type_common
*ft
)
970 struct bt_ctf_field_type_common
*child_ft
= NULL
;
971 int64_t field_count
=
972 bt_ctf_field_type_common_structure_get_field_count(ft
);
975 BT_ASSERT(field_count
>= 0);
977 for (i
= 0; i
< field_count
; ++i
) {
978 const char *field_name
;
980 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(ft
,
981 &field_name
, &child_ft
, i
);
983 ret
= bt_ctf_field_type_common_validate(child_ft
);
985 BT_LOGW("Invalid structure field type: "
986 "a contained field type is invalid: "
987 "struct-ft-addr=%p, field-ft-addr=%p, "
988 "field-name=\"%s\", field-index=%" PRId64
,
989 ft
, child_ft
, field_name
, i
);
999 bt_bool
bt_ctf_field_type_common_enumeration_has_overlapping_ranges(
1000 struct bt_ctf_field_type_common_enumeration
*enum_ft
)
1002 if (!enum_ft
->common
.frozen
) {
1003 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
1006 return enum_ft
->has_overlapping_ranges
;
1010 int bt_ctf_field_type_common_variant_validate_recursive(
1011 struct bt_ctf_field_type_common
*ft
)
1014 int64_t field_count
;
1015 struct bt_ctf_field_type_common
*child_ft
= NULL
;
1016 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1019 if (var_ft
->tag_name
->len
== 0) {
1020 BT_LOGW("Invalid variant field type: no tag field name: "
1026 if (!var_ft
->tag_ft
) {
1027 BT_LOGW("Invalid variant field type: no tag field type: "
1028 "addr=%p, tag-field-name=\"%s\"", var_ft
,
1029 var_ft
->tag_name
->str
);
1034 if (bt_ctf_field_type_common_enumeration_has_overlapping_ranges(var_ft
->tag_ft
)) {
1035 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
1036 "variant-ft-addr=%p, tag-field-name=\"%s\", "
1037 "enum-ft-addr=%p", ft
, var_ft
->tag_name
->str
,
1044 * It is valid to have a variant field type which does not have
1045 * the fields corresponding to each label in the associated
1048 * It is also valid to have variant field type fields which
1049 * cannot be selected because the variant field type tag has no
1050 * mapping named as such. This scenario, while not ideal, cannot
1053 * If a non-existing field happens to be selected by an
1054 * enumeration while reading a variant field, an error will be
1055 * generated at that point (while reading the stream).
1057 field_count
= bt_ctf_field_type_common_variant_get_field_count(ft
);
1058 if (field_count
< 0) {
1059 BT_LOGW("Invalid variant field type: no fields: "
1060 "addr=%p, tag-field-name=\"%s\"",
1061 ft
, var_ft
->tag_name
->str
);
1066 for (i
= 0; i
< field_count
; ++i
) {
1067 const char *field_name
;
1069 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(ft
,
1070 &field_name
, &child_ft
, i
);
1071 BT_ASSERT(ret
== 0);
1072 ret
= bt_ctf_field_type_common_validate(child_ft
);
1074 BT_LOGW("Invalid variant field type: "
1075 "a contained field type is invalid: "
1076 "variant-ft-addr=%p, tag-field-name=\"%s\", "
1077 "field-ft-addr=%p, field-name=\"%s\", "
1078 "field-index=%" PRId64
,
1079 ft
, var_ft
->tag_name
->str
, child_ft
,
1090 * This function validates a given field type without considering
1091 * where this field type is located. It only validates the properties
1092 * of the given field type and the properties of its children if
1096 int bt_ctf_field_type_common_validate(struct bt_ctf_field_type_common
*ft
)
1103 /* Already marked as valid */
1107 if (ft
->methods
->validate
) {
1108 ret
= ft
->methods
->validate(ft
);
1111 if (ret
== 0 && ft
->frozen
) {
1112 /* Field type is valid */
1113 BT_LOGV("Marking field type as valid: addr=%p", ft
);
1122 int bt_ctf_field_type_common_integer_get_size(struct bt_ctf_field_type_common
*ft
)
1124 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1126 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1127 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1129 return (int) int_ft
->size
;
1133 bt_bool
bt_ctf_field_type_common_integer_is_signed(struct bt_ctf_field_type_common
*ft
)
1135 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1137 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1138 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1140 return int_ft
->is_signed
;
1144 int bt_ctf_field_type_common_integer_set_is_signed(struct bt_ctf_field_type_common
*ft
,
1148 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1151 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1157 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1163 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1164 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1165 "addr=%p, ft-id=%s", ft
,
1166 bt_ctf_field_type_id_string(ft
->id
));
1171 int_ft
->is_signed
= !!is_signed
;
1172 BT_LOGV("Set integer field type's signedness: addr=%p, is-signed=%d",
1180 int bt_ctf_field_type_common_integer_set_size(struct bt_ctf_field_type_common
*ft
,
1184 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1187 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1193 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1199 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1200 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1201 "addr=%p, ft-id=%s", ft
,
1202 bt_ctf_field_type_id_string(ft
->id
));
1207 if (size
== 0 || size
> 64) {
1208 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
1209 "addr=%p, size=%u", ft
, size
);
1214 int_ft
->size
= size
;
1215 BT_LOGV("Set integer field type's size: addr=%p, size=%u",
1223 enum bt_ctf_integer_base
bt_ctf_field_type_common_integer_get_base(
1224 struct bt_ctf_field_type_common
*ft
)
1226 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1228 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1229 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1231 return int_ft
->base
;
1235 int bt_ctf_field_type_common_integer_set_base(struct bt_ctf_field_type_common
*ft
,
1236 enum bt_ctf_integer_base base
)
1239 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1242 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1248 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1254 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1255 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1256 "addr=%p, ft-id=%s", ft
,
1257 bt_ctf_field_type_id_string(ft
->id
));
1263 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
1264 case BT_CTF_INTEGER_BASE_BINARY
:
1265 case BT_CTF_INTEGER_BASE_OCTAL
:
1266 case BT_CTF_INTEGER_BASE_DECIMAL
:
1267 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1269 int_ft
->base
= base
;
1273 BT_LOGW("Invalid parameter: unknown integer field type base: "
1274 "addr=%p, base=%d", ft
, base
);
1278 BT_LOGV("Set integer field type's base: addr=%p, base=%s",
1279 ft
, bt_ctf_integer_base_string(base
));
1286 enum bt_ctf_string_encoding
bt_ctf_field_type_common_integer_get_encoding(
1287 struct bt_ctf_field_type_common
*ft
)
1289 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1291 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1292 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1294 return int_ft
->encoding
;
1298 int bt_ctf_field_type_common_integer_set_encoding(struct bt_ctf_field_type_common
*ft
,
1299 enum bt_ctf_string_encoding encoding
)
1302 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1305 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1311 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1317 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1318 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1319 "addr=%p, ft-id=%s", ft
,
1320 bt_ctf_field_type_id_string(ft
->id
));
1325 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
1326 encoding
!= BT_CTF_STRING_ENCODING_ASCII
&&
1327 encoding
!= BT_CTF_STRING_ENCODING_NONE
) {
1328 BT_LOGW("Invalid parameter: unknown string encoding: "
1329 "addr=%p, encoding=%d", ft
, encoding
);
1334 int_ft
->encoding
= encoding
;
1335 BT_LOGV("Set integer field type's encoding: addr=%p, encoding=%s",
1336 ft
, bt_ctf_string_encoding_string(encoding
));
1343 struct bt_ctf_clock_class
*bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
1344 struct bt_ctf_field_type_common
*ft
)
1346 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1348 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1349 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1351 return int_ft
->mapped_clock_class
;
1355 int bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1356 struct bt_ctf_field_type_common
*ft
,
1357 struct bt_ctf_clock_class
*clock_class
)
1359 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1363 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1368 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1369 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1370 "addr=%p, ft-id=%s", ft
,
1371 bt_ctf_field_type_id_string(ft
->id
));
1375 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1376 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1377 "clock-class-addr=%p, clock-class-name=\"%s\"",
1379 bt_ctf_clock_class_get_name(clock_class
));
1384 bt_object_put_ref(int_ft
->mapped_clock_class
);
1385 int_ft
->mapped_clock_class
= bt_object_get_ref(clock_class
);
1386 BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
1387 "clock-class-addr=%p, clock-class-name=\"%s\"",
1388 ft
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1395 int bt_ctf_field_type_common_integer_set_mapped_clock_class(
1396 struct bt_ctf_field_type_common
*ft
,
1397 struct bt_ctf_clock_class
*clock_class
)
1402 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1408 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1414 ret
= bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1422 int bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
1423 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1424 const char **mapping_name
, int64_t *range_begin
,
1428 struct bt_ctf_enumeration_mapping
*mapping
;
1430 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1431 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
,
1432 BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1433 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(ft
,
1436 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() logs errors */
1442 *mapping_name
= g_quark_to_string(mapping
->string
);
1443 BT_ASSERT(*mapping_name
);
1447 *range_begin
= mapping
->range_start
._signed
;
1451 *range_end
= mapping
->range_end
._signed
;
1459 int bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
1460 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1461 const char **mapping_name
, uint64_t *range_begin
,
1462 uint64_t *range_end
)
1465 struct bt_ctf_enumeration_mapping
*mapping
;
1467 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1468 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1469 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(
1472 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() reports any error */
1478 *mapping_name
= g_quark_to_string(mapping
->string
);
1479 BT_ASSERT(*mapping_name
);
1483 *range_begin
= mapping
->range_start
._unsigned
;
1487 *range_end
= mapping
->range_end
._unsigned
;
1495 struct bt_ctf_field_type_common
*
1496 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
1497 struct bt_ctf_field_type_common
*ft
)
1499 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1501 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1502 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1503 return BT_CTF_TO_COMMON(enum_ft
->container_ft
);
1507 int bt_ctf_field_type_common_enumeration_signed_add_mapping(
1508 struct bt_ctf_field_type_common
*ft
, const char *string
,
1509 int64_t range_start
, int64_t range_end
)
1512 GQuark mapping_name
;
1513 struct bt_ctf_enumeration_mapping
*mapping
;
1514 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1515 char *escaped_string
;
1518 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1524 BT_LOGW_STR("Invalid parameter: string is NULL.");
1530 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1536 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1537 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1538 "addr=%p, ft-id=%s", ft
,
1539 bt_ctf_field_type_id_string(ft
->id
));
1544 if (range_end
< range_start
) {
1545 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1546 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1547 ft
, range_start
, range_end
);
1552 if (strlen(string
) == 0) {
1553 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1554 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1560 escaped_string
= g_strescape(string
, NULL
);
1561 if (!escaped_string
) {
1562 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1563 "mapping-name-addr=%p, mapping-name=\"%s\"",
1564 ft
, string
, string
);
1569 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1571 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1575 mapping_name
= g_quark_from_string(escaped_string
);
1576 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1577 .range_start
._signed
= range_start
,
1578 .range_end
._signed
= range_end
,
1579 .string
= mapping_name
,
1581 g_ptr_array_add(enum_ft
->entries
, mapping
);
1582 g_ptr_array_sort(enum_ft
->entries
,
1583 (GCompareFunc
) compare_enumeration_mappings_signed
);
1584 BT_LOGV("Added mapping to signed enumeration field type: addr=%p, "
1585 "name=\"%s\", range-start=%" PRId64
", "
1586 "range-end=%" PRId64
,
1587 ft
, string
, range_start
, range_end
);
1590 free(escaped_string
);
1597 int bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
1598 struct bt_ctf_field_type_common
*ft
, const char *string
,
1599 uint64_t range_start
, uint64_t range_end
)
1602 GQuark mapping_name
;
1603 struct bt_ctf_enumeration_mapping
*mapping
;
1604 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1605 char *escaped_string
;
1608 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1614 BT_LOGW_STR("Invalid parameter: string is NULL.");
1620 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1626 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1627 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1628 "addr=%p, ft-id=%s", ft
,
1629 bt_ctf_field_type_id_string(ft
->id
));
1634 if (range_end
< range_start
) {
1635 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1636 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1637 ft
, range_start
, range_end
);
1642 if (strlen(string
) == 0) {
1643 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1644 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1650 escaped_string
= g_strescape(string
, NULL
);
1651 if (!escaped_string
) {
1652 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1653 "mapping-name-addr=%p, mapping-name=\"%s\"",
1654 ft
, string
, string
);
1659 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1661 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1665 mapping_name
= g_quark_from_string(escaped_string
);
1666 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1667 .range_start
._unsigned
= range_start
,
1668 .range_end
._unsigned
= range_end
,
1669 .string
= mapping_name
,
1671 g_ptr_array_add(enum_ft
->entries
, mapping
);
1672 g_ptr_array_sort(enum_ft
->entries
,
1673 (GCompareFunc
) compare_enumeration_mappings_unsigned
);
1674 BT_LOGV("Added mapping to unsigned enumeration field type: addr=%p, "
1675 "name=\"%s\", range-start=%" PRIu64
", "
1676 "range-end=%" PRIu64
,
1677 ft
, string
, range_start
, range_end
);
1680 free(escaped_string
);
1687 int64_t bt_ctf_field_type_common_enumeration_get_mapping_count(
1688 struct bt_ctf_field_type_common
*ft
)
1690 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1692 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1693 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1694 return (int64_t) enum_ft
->entries
->len
;
1698 int bt_ctf_field_type_common_floating_point_get_exponent_digits(
1699 struct bt_ctf_field_type_common
*ft
)
1701 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1703 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1704 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1706 return (int) flt_ft
->exp_dig
;
1710 int bt_ctf_field_type_common_floating_point_set_exponent_digits(
1711 struct bt_ctf_field_type_common
*ft
,
1712 unsigned int exponent_digits
)
1715 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1718 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1724 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1730 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1731 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1732 "addr=%p, ft-id=%s", ft
,
1733 bt_ctf_field_type_id_string(ft
->id
));
1738 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1739 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1741 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1742 BT_LOGW("Invalid parameter: invalid exponent size: "
1743 "addr=%p, exp-size=%u", ft
, exponent_digits
);
1748 flt_ft
->exp_dig
= exponent_digits
;
1749 BT_LOGV("Set floating point number field type's exponent size: addr=%p, "
1750 "exp-size=%u", ft
, exponent_digits
);
1757 int bt_ctf_field_type_common_floating_point_get_mantissa_digits(
1758 struct bt_ctf_field_type_common
*ft
)
1760 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1762 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1763 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1765 return (int) flt_ft
->mant_dig
;
1769 int bt_ctf_field_type_common_floating_point_set_mantissa_digits(
1770 struct bt_ctf_field_type_common
*ft
, unsigned int mantissa_digits
)
1773 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1776 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1782 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1788 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1789 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1790 "addr=%p, ft-id=%s", ft
,
1791 bt_ctf_field_type_id_string(ft
->id
));
1796 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1797 (mantissa_digits
!= DBL_MANT_DIG
) &&
1798 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1799 BT_LOGW("Invalid parameter: invalid mantissa size: "
1800 "addr=%p, mant-size=%u", ft
, mantissa_digits
);
1805 flt_ft
->mant_dig
= mantissa_digits
;
1806 BT_LOGV("Set floating point number field type's mantissa size: addr=%p, "
1807 "mant-size=%u", ft
, mantissa_digits
);
1814 int bt_ctf_field_type_common_structure_replace_field(
1815 struct bt_ctf_field_type_common
*ft
,
1816 const char *field_name
,
1817 struct bt_ctf_field_type_common
*field_type
)
1820 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1825 BT_ASSERT(field_name
);
1826 BT_ASSERT(field_type
);
1827 BT_ASSERT(ft
->id
== BT_CTF_FIELD_TYPE_ID_STRUCT
);
1828 name_quark
= g_quark_from_string(field_name
);
1830 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
1831 struct bt_ctf_field_type_common_structure_field
*field
=
1832 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
1834 if (field
->name
== name_quark
) {
1835 bt_object_put_ref(field
->type
);
1836 field
->type
= bt_object_get_ref(field_type
);
1844 int bt_ctf_field_type_common_structure_add_field(struct bt_ctf_field_type_common
*ft
,
1845 struct bt_ctf_field_type_common
*field_type
,
1846 const char *field_name
)
1849 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1852 * TODO: check that `field_type` does not contain `type`,
1856 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1862 BT_LOGW_STR("Invalid parameter: field name is NULL.");
1868 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1874 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
1875 BT_LOGW("Invalid parameter: field type is not a structure field type: "
1876 "addr=%p, ft-id=%s", ft
,
1877 bt_ctf_field_type_id_string(ft
->id
));
1882 if (ft
== field_type
) {
1883 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
1889 if (add_structure_variant_member(struct_ft
->fields
,
1890 struct_ft
->field_name_to_index
, field_type
, field_name
,
1892 BT_LOGW("Cannot add field to structure field type: "
1893 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
1894 ft
, field_type
, field_name
);
1899 BT_LOGV("Added structure field type field: struct-ft-addr=%p, "
1900 "field-ft-addr=%p, field-name=\"%s\"", ft
,
1901 field_type
, field_name
);
1908 int64_t bt_ctf_field_type_common_structure_get_field_count(
1909 struct bt_ctf_field_type_common
*ft
)
1911 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1913 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1914 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1916 return (int64_t) struct_ft
->fields
->len
;
1920 int bt_ctf_field_type_common_structure_borrow_field_by_index(
1921 struct bt_ctf_field_type_common
*ft
,
1922 const char **field_name
,
1923 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
1925 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1926 struct bt_ctf_field_type_common_structure_field
*field
;
1928 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1929 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1931 BT_ASSERT_PRE(index
< struct_ft
->fields
->len
,
1932 "Index is out of bounds: index=%" PRIu64
", "
1933 "count=%u, ft-addr=%p",
1934 index
, struct_ft
->fields
->len
, ft
);
1935 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(struct_ft
, index
);
1938 *field_type
= field
->type
;
1942 *field_name
= g_quark_to_string(field
->name
);
1943 BT_ASSERT(*field_name
);
1950 struct bt_ctf_field_type_common
*
1951 bt_ctf_field_type_common_structure_borrow_field_type_by_name(
1952 struct bt_ctf_field_type_common
*ft
, const char *name
)
1956 struct bt_ctf_field_type_common_structure_field
*field
;
1957 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1958 struct bt_ctf_field_type_common
*field_type
= NULL
;
1960 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1961 BT_ASSERT_PRE_NON_NULL(name
, "Name");
1962 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1964 name_quark
= g_quark_try_string(name
);
1966 BT_LOGV("No such structure field type field name: "
1967 "ft-addr=%p, field-name=\"%s\"",
1972 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
1973 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
1974 BT_LOGV("No such structure field type field name: "
1975 "ft-addr=%p, field-name=\"%s\"",
1980 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, index
);
1981 field_type
= field
->type
;
1988 struct bt_ctf_field_type_common
*
1989 bt_ctf_field_type_common_variant_borrow_tag_field_type(
1990 struct bt_ctf_field_type_common
*ft
)
1992 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1993 struct bt_ctf_field_type_common
*tag_ft
= NULL
;
1995 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
1996 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
1999 if (!var_ft
->tag_ft
) {
2000 BT_LOGV("Variant field type has no tag field type: "
2005 tag_ft
= BT_CTF_TO_COMMON(var_ft
->tag_ft
);
2012 const char *bt_ctf_field_type_common_variant_get_tag_name(
2013 struct bt_ctf_field_type_common
*ft
)
2015 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2016 const char *tag_name
= NULL
;
2018 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2019 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2022 if (var_ft
->tag_name
->len
== 0) {
2023 BT_LOGV("Variant field type has no tag field name: "
2028 tag_name
= var_ft
->tag_name
->str
;
2035 int bt_ctf_field_type_common_variant_set_tag_name(
2036 struct bt_ctf_field_type_common
*ft
, const char *name
)
2039 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2042 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2048 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2054 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2055 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2056 "addr=%p, ft-id=%s", ft
, bt_ctf_field_type_id_string(ft
->id
));
2061 if (!bt_ctf_identifier_is_valid(name
)) {
2062 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2063 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2069 g_string_assign(var_ft
->tag_name
, name
);
2070 BT_LOGV("Set variant field type's tag field name: addr=%p, "
2071 "tag-field-name=\"%s\"", ft
, name
);
2078 int bt_ctf_field_type_common_variant_add_field(struct bt_ctf_field_type_common
*ft
,
2079 struct bt_ctf_field_type_common
*field_type
,
2080 const char *field_name
)
2084 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2085 GQuark field_name_quark
= g_quark_from_string(field_name
);
2088 * TODO: check that `field_type` does not contain `type`,
2092 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2098 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2104 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2105 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2106 "addr=%p, ft-id=%s", ft
,
2107 bt_ctf_field_type_id_string(ft
->id
));
2112 if (ft
== field_type
) {
2113 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2119 /* The user has explicitly provided a tag; validate against it. */
2120 if (var_ft
->tag_ft
) {
2123 /* Make sure this name is present in the enum tag */
2124 for (i
= 0; i
< var_ft
->tag_ft
->entries
->len
; i
++) {
2125 struct bt_ctf_enumeration_mapping
*mapping
=
2126 g_ptr_array_index(var_ft
->tag_ft
->entries
, i
);
2128 if (mapping
->string
== field_name_quark
) {
2135 /* Validation failed */
2136 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2137 "variant-ft-addr=%p, tag-ft-addr=%p, "
2138 "tag-field-name=\"%s\""
2139 "field-ft-addr=%p, field-name=\"%s\"",
2140 ft
, var_ft
->tag_ft
, var_ft
->tag_name
->str
,
2141 field_type
, field_name
);
2147 if (add_structure_variant_member(var_ft
->choices
,
2148 var_ft
->choice_name_to_index
, field_type
,
2149 field_name
, true)) {
2150 BT_LOGW("Cannot add field to variant field type: "
2151 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2152 ft
, field_type
, field_name
);
2157 BT_LOGV("Added variant field type field: variant-ft-addr=%p, "
2158 "field-ft-addr=%p, field-name=\"%s\"", ft
,
2159 field_type
, field_name
);
2166 struct bt_ctf_field_type_common
*
2167 bt_ctf_field_type_common_variant_borrow_field_type_by_name(
2168 struct bt_ctf_field_type_common
*ft
,
2169 const char *field_name
)
2173 struct bt_ctf_field_type_common_variant_choice
*choice
;
2174 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2175 struct bt_ctf_field_type_common
*field_type
= NULL
;
2177 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2178 BT_ASSERT_PRE_NON_NULL(field_name
, "Name");
2179 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2181 name_quark
= g_quark_try_string(field_name
);
2183 BT_LOGV("No such variant field type field name: "
2184 "ft-addr=%p, field-name=\"%s\"",
2189 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2190 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
2191 BT_LOGV("No such variant field type field name: "
2192 "ft-addr=%p, field-name=\"%s\"",
2197 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2198 field_type
= choice
->type
;
2205 int64_t bt_ctf_field_type_common_variant_get_field_count(
2206 struct bt_ctf_field_type_common
*ft
)
2208 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2210 BT_ASSERT_PRE_NON_NULL(ft
, "Variant field type");
2211 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2213 return (int64_t) var_ft
->choices
->len
;
2217 int bt_ctf_field_type_common_variant_borrow_field_by_index(
2218 struct bt_ctf_field_type_common
*ft
,
2219 const char **field_name
,
2220 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
2222 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2223 struct bt_ctf_field_type_common_variant_choice
*choice
;
2225 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2226 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2228 BT_ASSERT_PRE(index
< var_ft
->choices
->len
,
2229 "Index is out of bounds: index=%" PRIu64
", "
2230 "count=%u, ft-addr=%p",
2231 index
, var_ft
->choices
->len
, ft
);
2232 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2235 *field_type
= choice
->type
;
2239 *field_name
= g_quark_to_string(choice
->name
);
2240 BT_ASSERT(*field_name
);
2247 int64_t bt_ctf_field_type_common_variant_find_choice_index(
2248 struct bt_ctf_field_type_common
*ft
, uint64_t uval
,
2253 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2256 BT_ASSERT(ft
->id
== BT_CTF_FIELD_TYPE_ID_VARIANT
);
2258 if (bt_ctf_field_type_common_variant_update_choices(ft
)) {
2263 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
2265 struct bt_ctf_field_type_common_variant_choice
*choice
=
2266 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
2269 for (range_i
= 0; range_i
< choice
->ranges
->len
; range_i
++) {
2270 struct bt_ctf_field_type_common_variant_choice_range
*range
=
2273 struct bt_ctf_field_type_common_variant_choice_range
,
2277 int64_t tag_ival
= (int64_t) uval
;
2279 if (tag_ival
>= range
->lower
.i
&&
2280 tag_ival
<= range
->upper
.i
) {
2284 if (uval
>= range
->lower
.u
&&
2285 uval
<= range
->upper
.u
) {
2292 /* Range not found */
2304 struct bt_ctf_field_type_common
*
2305 bt_ctf_field_type_common_array_borrow_element_field_type(
2306 struct bt_ctf_field_type_common
*ft
)
2308 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2310 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2311 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2313 BT_ASSERT(array_ft
&& array_ft
->element_ft
);
2314 return array_ft
->element_ft
;
2318 int bt_ctf_field_type_common_array_set_element_field_type(
2319 struct bt_ctf_field_type_common
*ft
,
2320 struct bt_ctf_field_type_common
*element_ft
)
2323 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2326 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2332 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2337 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2338 BT_LOGW("Invalid parameter: field type is not an array field type: "
2339 "addr=%p, ft-id=%s", ft
,
2340 bt_ctf_field_type_id_string(ft
->id
));
2345 if (array_ft
->element_ft
) {
2346 BT_OBJECT_PUT_REF_AND_RESET(array_ft
->element_ft
);
2349 array_ft
->element_ft
= bt_object_get_ref(element_ft
);
2350 BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
2351 "element-ft-addr=%p", ft
, element_ft
);
2358 int64_t bt_ctf_field_type_common_array_get_length(struct bt_ctf_field_type_common
*ft
)
2360 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2362 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2363 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2365 return (int64_t) array_ft
->length
;
2369 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_sequence_borrow_element_field_type(
2370 struct bt_ctf_field_type_common
*ft
)
2372 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2374 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2375 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2377 return seq_ft
->element_ft
;
2381 int bt_ctf_field_type_common_sequence_set_element_field_type(
2382 struct bt_ctf_field_type_common
*ft
,
2383 struct bt_ctf_field_type_common
*element_ft
)
2386 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2389 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2395 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2400 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2401 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2402 "addr=%p, ft-id=%s", ft
,
2403 bt_ctf_field_type_id_string(ft
->id
));
2408 if (seq_ft
->element_ft
) {
2409 BT_OBJECT_PUT_REF_AND_RESET(seq_ft
->element_ft
);
2412 seq_ft
->element_ft
= element_ft
;
2413 bt_object_get_ref(seq_ft
->element_ft
);
2414 BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
2415 "element-ft-addr=%p", ft
, element_ft
);
2422 const char *bt_ctf_field_type_common_sequence_get_length_field_name(
2423 struct bt_ctf_field_type_common
*ft
)
2425 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2427 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2428 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2430 return seq_ft
->length_field_name
?
2431 seq_ft
->length_field_name
->str
: NULL
;
2435 enum bt_ctf_string_encoding
bt_ctf_field_type_common_string_get_encoding(
2436 struct bt_ctf_field_type_common
*ft
)
2438 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2440 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2441 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRING
,
2443 return string_ft
->encoding
;
2447 int bt_ctf_field_type_common_string_set_encoding(struct bt_ctf_field_type_common
*ft
,
2448 enum bt_ctf_string_encoding encoding
)
2451 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2454 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2459 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2460 BT_LOGW("Invalid parameter: field type is not a string field type: "
2461 "addr=%p, ft-id=%s", ft
,
2462 bt_ctf_field_type_id_string(ft
->id
));
2467 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2468 encoding
!= BT_CTF_STRING_ENCODING_ASCII
) {
2469 BT_LOGW("Invalid parameter: unknown string encoding: "
2470 "addr=%p, encoding=%d", ft
, encoding
);
2475 string_ft
->encoding
= encoding
;
2476 BT_LOGV("Set string field type's encoding: addr=%p, encoding=%s",
2477 ft
, bt_ctf_string_encoding_string(encoding
));
2484 int bt_ctf_field_type_common_get_alignment(struct bt_ctf_field_type_common
*ft
)
2487 enum bt_ctf_field_type_id type_id
;
2489 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2492 ret
= (int) ft
->alignment
;
2496 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2498 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2500 struct bt_ctf_field_type_common
*element_ft
=
2501 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
2503 BT_ASSERT(element_ft
);
2504 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2507 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2509 struct bt_ctf_field_type_common
*element_ft
=
2510 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
2512 BT_ASSERT(element_ft
);
2513 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2516 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2518 int64_t i
, element_count
;
2520 element_count
= bt_ctf_field_type_common_structure_get_field_count(
2522 BT_ASSERT(element_count
>= 0);
2524 for (i
= 0; i
< element_count
; i
++) {
2525 struct bt_ctf_field_type_common
*field
= NULL
;
2526 int field_alignment
;
2528 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
2529 ft
, NULL
, &field
, i
);
2530 BT_ASSERT(ret
== 0);
2532 field_alignment
= bt_ctf_field_type_common_get_alignment(
2534 if (field_alignment
< 0) {
2535 ret
= field_alignment
;
2539 ft
->alignment
= MAX(field_alignment
, ft
->alignment
);
2541 ret
= (int) ft
->alignment
;
2544 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
2545 BT_LOGW("Invalid parameter: unknown field type ID: "
2546 "addr=%p, ft-id=%d", ft
, type_id
);
2550 ret
= (int) ft
->alignment
;
2559 int is_power_of_two(unsigned int value
)
2561 return ((value
& (value
- 1)) == 0) && value
> 0;
2565 int bt_ctf_field_type_common_set_alignment(struct bt_ctf_field_type_common
*ft
,
2566 unsigned int alignment
)
2569 enum bt_ctf_field_type_id type_id
;
2571 /* Alignment must be a power of two */
2573 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2579 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2585 if (!is_power_of_two(alignment
)) {
2586 BT_LOGW("Invalid parameter: alignment is not a power of two: "
2587 "addr=%p, align=%u", ft
, alignment
);
2592 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2593 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
2594 BT_LOGW("Invalid parameter: unknown field type ID: "
2595 "addr=%p, ft-id=%d", ft
, type_id
);
2600 if (ft
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&& alignment
!= CHAR_BIT
) {
2601 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
2602 "addr=%p, align=%u", CHAR_BIT
, ft
, alignment
);
2607 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
2608 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
2609 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2610 /* Setting an alignment on these types makes no sense */
2611 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
2612 "addr=%p, ft-id=%s", ft
,
2613 bt_ctf_field_type_id_string(ft
->id
));
2618 ft
->alignment
= alignment
;
2620 BT_LOGV("Set field type's alignment: addr=%p, align=%u",
2628 enum bt_ctf_byte_order
bt_ctf_field_type_common_get_byte_order(
2629 struct bt_ctf_field_type_common
*ft
)
2631 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
2633 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2636 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
2638 struct bt_ctf_field_type_common_integer
*integer
=
2639 BT_CTF_FROM_COMMON(ft
);
2641 ret
= integer
->user_byte_order
;
2644 case BT_CTF_FIELD_TYPE_ID_ENUM
:
2646 struct bt_ctf_field_type_common_enumeration
*enum_ft
=
2647 BT_CTF_FROM_COMMON(ft
);
2649 ret
= bt_ctf_field_type_common_get_byte_order(
2650 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
2653 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
2655 struct bt_ctf_field_type_common_floating_point
*floating_point
=
2656 BT_CTF_FROM_COMMON(ft
);
2657 ret
= floating_point
->user_byte_order
;
2661 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
2662 "addr=%p, ft-id=%s", ft
,
2663 bt_ctf_field_type_id_string(ft
->id
));
2667 BT_ASSERT(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
2668 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
2669 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
2670 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
2677 int bt_ctf_field_type_common_set_byte_order(struct bt_ctf_field_type_common
*ft
,
2678 enum bt_ctf_byte_order byte_order
)
2683 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2689 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2695 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
2696 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
2697 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
2698 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
2699 BT_LOGW("Invalid parameter: invalid byte order: "
2700 "addr=%p, bo=%s", ft
,
2701 bt_ctf_byte_order_string(byte_order
));
2706 if (ft
->methods
->set_byte_order
) {
2707 ft
->methods
->set_byte_order(ft
, byte_order
);
2710 BT_LOGV("Set field type's byte order: addr=%p, bo=%s",
2711 ft
, bt_ctf_byte_order_string(byte_order
));
2718 enum bt_ctf_field_type_id
bt_ctf_field_type_common_get_type_id(
2719 struct bt_ctf_field_type_common
*ft
)
2721 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2726 void bt_ctf_field_type_common_freeze(struct bt_ctf_field_type_common
*ft
)
2728 if (!ft
|| ft
->frozen
) {
2732 BT_ASSERT(ft
->methods
->freeze
);
2733 ft
->methods
->freeze(ft
);
2737 struct bt_ctf_field_type_common
*
2738 bt_ctf_field_type_common_variant_borrow_field_type_signed(
2739 struct bt_ctf_field_type_common_variant
*var_ft
,
2742 struct bt_ctf_field_type_common
*field_type
= NULL
;
2743 GQuark field_name_quark
;
2745 struct bt_ctf_field_type_common_variant_choice
*choice
;
2746 struct range_overlap_query query
= {
2747 .range_start
._signed
= tag_value
,
2748 .range_end
._signed
= tag_value
,
2753 g_ptr_array_foreach(var_ft
->tag_ft
->entries
, check_ranges_overlap
,
2755 if (!query
.overlaps
) {
2759 field_name_quark
= query
.mapping_name
;
2760 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2761 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2765 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2767 field_type
= choice
->type
;
2774 struct bt_ctf_field_type_common
*
2775 bt_ctf_field_type_common_variant_borrow_field_type_unsigned(
2776 struct bt_ctf_field_type_common_variant
*var_ft
,
2779 struct bt_ctf_field_type_common
*field_type
= NULL
;
2780 GQuark field_name_quark
;
2782 struct bt_ctf_field_type_common_variant_choice
*choice
;
2783 struct range_overlap_query query
= {
2784 .range_start
._unsigned
= tag_value
,
2785 .range_end
._unsigned
= tag_value
,
2790 g_ptr_array_foreach(var_ft
->tag_ft
->entries
,
2791 check_ranges_overlap_unsigned
, &query
);
2792 if (!query
.overlaps
) {
2796 field_name_quark
= query
.mapping_name
;
2797 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2798 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2802 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2804 field_type
= choice
->type
;
2811 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_copy(
2812 struct bt_ctf_field_type_common
*ft
)
2814 struct bt_ctf_field_type_common
*ft_copy
= NULL
;
2816 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2817 BT_ASSERT(ft
->methods
->copy
);
2818 ft_copy
= ft
->methods
->copy(ft
);
2820 BT_LOGE_STR("Cannot copy field type.");
2824 ft_copy
->alignment
= ft
->alignment
;
2831 int bt_ctf_field_type_common_structure_get_field_name_index(
2832 struct bt_ctf_field_type_common
*ft
, const char *name
)
2837 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
2839 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2840 BT_ASSERT_PRE_NON_NULL(name
, "Name");
2841 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
2844 name_quark
= g_quark_try_string(name
);
2846 BT_LOGV("No such structure field type field name: "
2847 "ft-addr=%p, field-name=\"%s\"",
2853 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
2854 GUINT_TO_POINTER(name_quark
),
2855 NULL
, (gpointer
*) &index
)) {
2856 BT_LOGV("No such structure field type field name: "
2857 "ft-addr=%p, field-name=\"%s\"",
2870 int bt_ctf_field_type_common_variant_get_field_name_index(
2871 struct bt_ctf_field_type_common
*ft
, const char *name
)
2876 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2878 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
2879 BT_ASSERT_PRE_NON_NULL(name
, "Name");
2880 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2882 name_quark
= g_quark_try_string(name
);
2884 BT_LOGV("No such variant field type field name: "
2885 "ft-addr=%p, field-name=\"%s\"",
2891 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2892 GUINT_TO_POINTER(name_quark
),
2893 NULL
, (gpointer
*) &index
)) {
2894 BT_LOGV("No such variant field type field name: "
2895 "ft-addr=%p, field-name=\"%s\"",
2908 int bt_ctf_field_type_common_sequence_set_length_field_path(
2909 struct bt_ctf_field_type_common
*ft
, struct bt_ctf_field_path
*path
)
2912 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2915 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2920 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2921 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2922 "addr=%p, ft-id=%s", ft
,
2923 bt_ctf_field_type_id_string(ft
->id
));
2928 bt_object_get_ref(path
);
2929 BT_OBJECT_MOVE_REF(seq_ft
->length_field_path
, path
);
2930 BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
2931 "field-path-addr=%p", ft
, path
);
2938 int bt_ctf_field_type_common_variant_set_tag_field_path(
2939 struct bt_ctf_field_type_common
*ft
,
2940 struct bt_ctf_field_path
*path
)
2943 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2946 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2951 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2952 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2953 "addr=%p, ft-id=%s", ft
,
2954 bt_ctf_field_type_id_string(ft
->id
));
2959 bt_object_get_ref(path
);
2960 BT_OBJECT_MOVE_REF(var_ft
->tag_field_path
, path
);
2961 BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
2962 "field-path-addr=%p", ft
, path
);
2969 int bt_ctf_field_type_common_variant_set_tag_field_type(
2970 struct bt_ctf_field_type_common
*ft
,
2971 struct bt_ctf_field_type_common
*tag_ft
)
2974 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2977 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2983 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
2988 if (tag_ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
2989 BT_LOGW("Invalid parameter: tag field type is not an enumeration field type: "
2990 "addr=%p, ft-id=%s", tag_ft
,
2991 bt_ctf_field_type_id_string(tag_ft
->id
));
2996 bt_object_put_ref(var_ft
->tag_ft
);
2997 var_ft
->tag_ft
= bt_object_get_ref(tag_ft
);
2998 BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
2999 "tag-ft-addr=%p", ft
, tag_ft
);
3006 void bt_ctf_field_type_common_generic_freeze(struct bt_ctf_field_type_common
*ft
)
3012 void bt_ctf_field_type_common_enumeration_freeze_recursive(
3013 struct bt_ctf_field_type_common
*ft
)
3015 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
3017 BT_LOGD("Freezing enumeration field type object: addr=%p", ft
);
3018 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
3019 bt_ctf_field_type_common_generic_freeze(ft
);
3020 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3021 enum_ft
->container_ft
);
3022 bt_ctf_field_type_common_freeze(BT_CTF_TO_COMMON(enum_ft
->container_ft
));
3026 void bt_ctf_field_type_common_structure_freeze_recursive(
3027 struct bt_ctf_field_type_common
*ft
)
3029 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
3032 /* Cache the alignment */
3033 BT_LOGD("Freezing structure field type object: addr=%p", ft
);
3034 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3035 bt_ctf_field_type_common_generic_freeze(ft
);
3037 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3038 struct bt_ctf_field_type_common_structure_field
*field
=
3039 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
3041 BT_LOGD("Freezing structure field type field: "
3042 "ft-addr=%p, name=\"%s\"",
3043 field
->type
, g_quark_to_string(field
->name
));
3044 bt_ctf_field_type_common_freeze(field
->type
);
3049 int bt_ctf_field_type_common_variant_update_choices(struct bt_ctf_field_type_common
*ft
)
3051 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3056 if (ft
->frozen
&& var_ft
->choices_up_to_date
) {
3060 BT_ASSERT(var_ft
->tag_ft
);
3061 is_signed
= !!var_ft
->tag_ft
->container_ft
->is_signed
;
3063 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3064 struct bt_ctf_field_type_common_variant_choice
*choice
=
3065 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
3066 const char *choice_name
= g_quark_to_string(choice
->name
);
3067 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
3068 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
3069 BT_CTF_TO_COMMON(var_ft
->tag_ft
), choice_name
);
3076 BT_ASSERT(choice
->ranges
);
3077 g_array_set_size(choice
->ranges
, 0);
3079 while (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
) == 0) {
3080 struct bt_ctf_field_type_common_variant_choice_range range
;
3083 ret
= bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
3085 &range
.lower
.i
, &range
.upper
.i
);
3087 ret
= bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
3089 &range
.lower
.u
, &range
.upper
.u
);
3092 BT_ASSERT(ret
== 0);
3093 g_array_append_val(choice
->ranges
, range
);
3096 bt_object_put_ref(iter
);
3099 var_ft
->choices_up_to_date
= true;
3106 void bt_ctf_field_type_common_variant_freeze_recursive(
3107 struct bt_ctf_field_type_common
*ft
)
3109 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3112 BT_LOGD("Freezing variant field type object: addr=%p", ft
);
3113 bt_ctf_field_type_common_generic_freeze(ft
);
3115 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3116 struct bt_ctf_field_type_common_variant_choice
*choice
=
3117 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
3119 BT_LOGD("Freezing variant field type member: "
3120 "ft-addr=%p, name=\"%s\"",
3121 choice
->type
, g_quark_to_string(choice
->name
));
3122 bt_ctf_field_type_common_freeze(choice
->type
);
3127 void bt_ctf_field_type_common_array_freeze_recursive(
3128 struct bt_ctf_field_type_common
*ft
)
3130 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3132 /* Cache the alignment */
3133 BT_LOGD("Freezing array field type object: addr=%p", ft
);
3134 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3135 bt_ctf_field_type_common_generic_freeze(ft
);
3136 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3137 array_ft
->element_ft
);
3138 bt_ctf_field_type_common_freeze(array_ft
->element_ft
);
3142 void bt_ctf_field_type_common_sequence_freeze_recursive(
3143 struct bt_ctf_field_type_common
*ft
)
3145 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3147 /* Cache the alignment */
3148 BT_LOGD("Freezing sequence field type object: addr=%p", ft
);
3149 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3150 bt_ctf_field_type_common_generic_freeze(ft
);
3151 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3152 seq_ft
->element_ft
);
3153 bt_ctf_field_type_common_freeze(seq_ft
->element_ft
);
3157 void bt_ctf_field_type_common_integer_set_byte_order(
3158 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3160 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
3162 int_ft
->user_byte_order
= byte_order
;
3166 void bt_ctf_field_type_common_enumeration_set_byte_order_recursive(
3167 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3169 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
3171 bt_ctf_field_type_common_set_byte_order(BT_CTF_TO_COMMON(enum_ft
->container_ft
),
3176 void bt_ctf_field_type_common_floating_point_set_byte_order(
3177 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3179 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
3181 flt_ft
->user_byte_order
= byte_order
;
3185 void bt_ctf_field_type_common_structure_set_byte_order_recursive(
3186 struct bt_ctf_field_type_common
*ft
,
3187 enum bt_ctf_byte_order byte_order
)
3190 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
3192 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3193 struct bt_ctf_field_type_common_structure_field
*field
=
3194 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3196 struct bt_ctf_field_type_common
*field_type
= field
->type
;
3198 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3203 void bt_ctf_field_type_common_variant_set_byte_order_recursive(
3204 struct bt_ctf_field_type_common
*ft
,
3205 enum bt_ctf_byte_order byte_order
)
3208 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3210 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3211 struct bt_ctf_field_type_common_variant_choice
*choice
=
3212 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3214 struct bt_ctf_field_type_common
*field_type
= choice
->type
;
3216 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3221 void bt_ctf_field_type_common_array_set_byte_order_recursive(
3222 struct bt_ctf_field_type_common
*ft
,
3223 enum bt_ctf_byte_order byte_order
)
3225 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3227 bt_ctf_field_type_common_set_byte_order(array_ft
->element_ft
, byte_order
);
3231 void bt_ctf_field_type_common_sequence_set_byte_order_recursive(
3232 struct bt_ctf_field_type_common
*ft
,
3233 enum bt_ctf_byte_order byte_order
)
3235 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3237 bt_ctf_field_type_common_set_byte_order(seq_ft
->element_ft
, byte_order
);
3242 int bt_ctf_field_type_common_integer_compare(struct bt_ctf_field_type_common
*ft_a
,
3243 struct bt_ctf_field_type_common
*ft_b
)
3246 struct bt_ctf_field_type_common_integer
*int_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3247 struct bt_ctf_field_type_common_integer
*int_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3250 if (int_ft_a
->size
!= int_ft_b
->size
) {
3251 BT_LOGV("Integer field types differ: different sizes: "
3252 "ft-a-size=%u, ft-b-size=%u",
3253 int_ft_a
->size
, int_ft_b
->size
);
3258 if (int_ft_a
->user_byte_order
!= int_ft_b
->user_byte_order
) {
3259 BT_LOGV("Integer field types differ: different byte orders: "
3260 "ft-a-bo=%s, ft-b-bo=%s",
3261 bt_ctf_byte_order_string(int_ft_a
->user_byte_order
),
3262 bt_ctf_byte_order_string(int_ft_b
->user_byte_order
));
3267 if (int_ft_a
->is_signed
!= int_ft_b
->is_signed
) {
3268 BT_LOGV("Integer field types differ: different signedness: "
3269 "ft-a-is-signed=%d, ft-b-is-signed=%d",
3270 int_ft_a
->is_signed
,
3271 int_ft_b
->is_signed
);
3276 if (int_ft_a
->base
!= int_ft_b
->base
) {
3277 BT_LOGV("Integer field types differ: different bases: "
3278 "ft-a-base=%s, ft-b-base=%s",
3279 bt_ctf_integer_base_string(int_ft_a
->base
),
3280 bt_ctf_integer_base_string(int_ft_b
->base
));
3285 if (int_ft_a
->encoding
!= int_ft_b
->encoding
) {
3286 BT_LOGV("Integer field types differ: different encodings: "
3287 "ft-a-encoding=%s, ft-b-encoding=%s",
3288 bt_ctf_string_encoding_string(int_ft_a
->encoding
),
3289 bt_ctf_string_encoding_string(int_ft_b
->encoding
));
3293 /* Mapped clock class */
3294 if (int_ft_a
->mapped_clock_class
) {
3295 if (!int_ft_b
->mapped_clock_class
) {
3296 BT_LOGV_STR("Integer field types differ: field type A "
3297 "has a mapped clock class, but field type B "
3302 if (bt_ctf_clock_class_compare(int_ft_a
->mapped_clock_class
,
3303 int_ft_b
->mapped_clock_class
) != 0) {
3304 BT_LOGV_STR("Integer field types differ: different "
3305 "mapped clock classes.");
3308 if (int_ft_b
->mapped_clock_class
) {
3309 BT_LOGV_STR("Integer field types differ: field type A "
3310 "has no description, but field type B has one.");
3323 int bt_ctf_field_type_common_floating_point_compare(
3324 struct bt_ctf_field_type_common
*ft_a
,
3325 struct bt_ctf_field_type_common
*ft_b
)
3328 struct bt_ctf_field_type_common_floating_point
*flt_ft_a
=
3329 BT_CTF_FROM_COMMON(ft_a
);
3330 struct bt_ctf_field_type_common_floating_point
*flt_ft_b
=
3331 BT_CTF_FROM_COMMON(ft_b
);
3334 if (flt_ft_a
->user_byte_order
!= flt_ft_b
->user_byte_order
) {
3335 BT_LOGV("Floating point number field types differ: different byte orders: "
3336 "ft-a-bo=%s, ft-b-bo=%s",
3337 bt_ctf_byte_order_string(flt_ft_a
->user_byte_order
),
3338 bt_ctf_byte_order_string(flt_ft_b
->user_byte_order
));
3342 /* Exponent length */
3343 if (flt_ft_a
->exp_dig
!= flt_ft_b
->exp_dig
) {
3344 BT_LOGV("Floating point number field types differ: different exponent sizes: "
3345 "ft-a-exp-size=%u, ft-b-exp-size=%u",
3346 flt_ft_a
->exp_dig
, flt_ft_b
->exp_dig
);
3350 /* Mantissa length */
3351 if (flt_ft_a
->mant_dig
!= flt_ft_b
->mant_dig
) {
3352 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
3353 "ft-a-mant-size=%u, ft-b-mant-size=%u",
3354 flt_ft_a
->mant_dig
, flt_ft_b
->mant_dig
);
3366 int compare_enumeration_mappings(struct bt_ctf_enumeration_mapping
*mapping_a
,
3367 struct bt_ctf_enumeration_mapping
*mapping_b
)
3372 if (mapping_a
->string
!= mapping_b
->string
) {
3373 BT_LOGV("Enumeration field type mappings differ: different names: "
3374 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
3375 g_quark_to_string(mapping_a
->string
),
3376 g_quark_to_string(mapping_b
->string
));
3381 if (mapping_a
->range_start
._unsigned
!=
3382 mapping_b
->range_start
._unsigned
) {
3383 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
3384 "mapping-a-range-start-unsigned=%" PRIu64
", "
3385 "mapping-b-range-start-unsigned=%" PRIu64
,
3386 mapping_a
->range_start
._unsigned
,
3387 mapping_b
->range_start
._unsigned
);
3392 if (mapping_a
->range_end
._unsigned
!=
3393 mapping_b
->range_end
._unsigned
) {
3394 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
3395 "mapping-a-range-end-unsigned=%" PRIu64
", "
3396 "mapping-b-range-end-unsigned=%" PRIu64
,
3397 mapping_a
->range_end
._unsigned
,
3398 mapping_b
->range_end
._unsigned
);
3410 int bt_ctf_field_type_common_enumeration_compare_recursive(
3411 struct bt_ctf_field_type_common
*ft_a
,
3412 struct bt_ctf_field_type_common
*ft_b
)
3416 struct bt_ctf_field_type_common_enumeration
*enum_ft_a
=
3417 BT_CTF_FROM_COMMON(ft_a
);
3418 struct bt_ctf_field_type_common_enumeration
*enum_ft_b
=
3419 BT_CTF_FROM_COMMON(ft_b
);
3421 /* Container field type */
3422 ret
= bt_ctf_field_type_common_compare(
3423 BT_CTF_TO_COMMON(enum_ft_a
->container_ft
),
3424 BT_CTF_TO_COMMON(enum_ft_b
->container_ft
));
3426 BT_LOGV("Enumeration field types differ: different container field types: "
3427 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
3428 enum_ft_a
->container_ft
, enum_ft_b
->container_ft
);
3435 if (enum_ft_a
->entries
->len
!= enum_ft_b
->entries
->len
) {
3439 for (i
= 0; i
< enum_ft_a
->entries
->len
; ++i
) {
3440 struct bt_ctf_enumeration_mapping
*mapping_a
=
3441 g_ptr_array_index(enum_ft_a
->entries
, i
);
3442 struct bt_ctf_enumeration_mapping
*mapping_b
=
3443 g_ptr_array_index(enum_ft_b
->entries
, i
);
3445 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
3446 BT_LOGV("Enumeration field types differ: different mappings: "
3447 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
3448 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
3449 mapping_a
, mapping_b
,
3450 g_quark_to_string(mapping_a
->string
),
3451 g_quark_to_string(mapping_b
->string
));
3464 int bt_ctf_field_type_common_string_compare(struct bt_ctf_field_type_common
*ft_a
,
3465 struct bt_ctf_field_type_common
*ft_b
)
3468 struct bt_ctf_field_type_common_string
*string_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3469 struct bt_ctf_field_type_common_string
*string_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3472 if (string_ft_a
->encoding
!= string_ft_b
->encoding
) {
3473 BT_LOGV("String field types differ: different encodings: "
3474 "ft-a-encoding=%s, ft-b-encoding=%s",
3475 bt_ctf_string_encoding_string(string_ft_a
->encoding
),
3476 bt_ctf_string_encoding_string(string_ft_b
->encoding
));
3488 int compare_structure_variant_members(
3489 struct bt_ctf_field_type_common
*member_a_ft
,
3490 struct bt_ctf_field_type_common
*member_b_ft
,
3491 GQuark member_a_name
, GQuark member_b_name
)
3496 if (member_a_name
!= member_b_name
) {
3497 BT_LOGV("Structure/variant field type fields differ: different names: "
3498 "field-a-name=%s, field-b-name=%s",
3499 g_quark_to_string(member_a_name
),
3500 g_quark_to_string(member_b_name
));
3505 ret
= bt_ctf_field_type_common_compare(member_a_ft
, member_b_ft
);
3507 BT_LOGV("Structure/variant field type fields differ: different field types: "
3508 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
3509 g_quark_to_string(member_a_name
),
3510 member_a_ft
, member_b_ft
);
3518 int bt_ctf_field_type_common_structure_compare_recursive(
3519 struct bt_ctf_field_type_common
*ft_a
,
3520 struct bt_ctf_field_type_common
*ft_b
)
3524 struct bt_ctf_field_type_common_structure
*struct_ft_a
=
3525 BT_CTF_FROM_COMMON(ft_a
);
3526 struct bt_ctf_field_type_common_structure
*struct_ft_b
=
3527 BT_CTF_FROM_COMMON(ft_b
);
3530 if (bt_ctf_field_type_common_get_alignment(ft_a
) !=
3531 bt_ctf_field_type_common_get_alignment(ft_b
)) {
3532 BT_LOGV("Structure field types differ: different alignments: "
3533 "ft-a-align=%u, ft-b-align=%u",
3534 bt_ctf_field_type_common_get_alignment(ft_a
),
3535 bt_ctf_field_type_common_get_alignment(ft_b
));
3540 if (struct_ft_a
->fields
->len
!= struct_ft_b
->fields
->len
) {
3541 BT_LOGV("Structure field types differ: different field counts: "
3542 "ft-a-field-count=%u, ft-b-field-count=%u",
3543 struct_ft_a
->fields
->len
, struct_ft_b
->fields
->len
);
3547 for (i
= 0; i
< struct_ft_a
->fields
->len
; ++i
) {
3548 struct bt_ctf_field_type_common_structure_field
*field_a
=
3549 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3551 struct bt_ctf_field_type_common_structure_field
*field_b
=
3552 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3555 ret
= compare_structure_variant_members(field_a
->type
,
3556 field_b
->type
, field_a
->name
, field_b
->name
);
3558 /* compare_structure_variant_members() logs what differs */
3559 BT_LOGV_STR("Structure field types differ: different fields.");
3572 int bt_ctf_field_type_common_variant_compare_recursive(
3573 struct bt_ctf_field_type_common
*ft_a
,
3574 struct bt_ctf_field_type_common
*ft_b
)
3578 struct bt_ctf_field_type_common_variant
*var_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3579 struct bt_ctf_field_type_common_variant
*var_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3582 if (strcmp(var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
)) {
3583 BT_LOGV("Variant field types differ: different tag field names: "
3584 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
3585 var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
);
3590 ret
= bt_ctf_field_type_common_compare(BT_CTF_TO_COMMON(var_ft_a
->tag_ft
),
3591 BT_CTF_TO_COMMON(var_ft_b
->tag_ft
));
3593 BT_LOGV("Variant field types differ: different tag field types: "
3594 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
3595 var_ft_a
->tag_ft
, var_ft_b
->tag_ft
);
3602 if (var_ft_a
->choices
->len
!= var_ft_b
->choices
->len
) {
3603 BT_LOGV("Variant field types differ: different field counts: "
3604 "ft-a-field-count=%u, ft-b-field-count=%u",
3605 var_ft_a
->choices
->len
, var_ft_b
->choices
->len
);
3609 for (i
= 0; i
< var_ft_a
->choices
->len
; ++i
) {
3610 struct bt_ctf_field_type_common_variant_choice
*choice_a
=
3611 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3613 struct bt_ctf_field_type_common_variant_choice
*choice_b
=
3614 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3617 ret
= compare_structure_variant_members(choice_a
->type
,
3618 choice_b
->type
, choice_a
->name
, choice_b
->name
);
3620 /* compare_structure_variant_members() logs what differs */
3621 BT_LOGV_STR("Variant field types differ: different fields.");
3634 int bt_ctf_field_type_common_array_compare_recursive(
3635 struct bt_ctf_field_type_common
*ft_a
,
3636 struct bt_ctf_field_type_common
*ft_b
)
3639 struct bt_ctf_field_type_common_array
*array_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3640 struct bt_ctf_field_type_common_array
*array_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3643 if (array_ft_a
->length
!= array_ft_b
->length
) {
3644 BT_LOGV("Structure field types differ: different lengths: "
3645 "ft-a-length=%u, ft-b-length=%u",
3646 array_ft_a
->length
, array_ft_b
->length
);
3651 ret
= bt_ctf_field_type_common_compare(array_ft_a
->element_ft
,
3652 array_ft_b
->element_ft
);
3654 BT_LOGV("Array field types differ: different element field types: "
3655 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3656 array_ft_a
->element_ft
, array_ft_b
->element_ft
);
3664 int bt_ctf_field_type_common_sequence_compare_recursive(
3665 struct bt_ctf_field_type_common
*ft_a
,
3666 struct bt_ctf_field_type_common
*ft_b
)
3669 struct bt_ctf_field_type_common_sequence
*seq_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3670 struct bt_ctf_field_type_common_sequence
*seq_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3673 if (strcmp(seq_ft_a
->length_field_name
->str
,
3674 seq_ft_b
->length_field_name
->str
)) {
3675 BT_LOGV("Sequence field types differ: different length field names: "
3676 "ft-a-length-field-name=\"%s\", "
3677 "ft-b-length-field-name=\"%s\"",
3678 seq_ft_a
->length_field_name
->str
,
3679 seq_ft_b
->length_field_name
->str
);
3684 ret
= bt_ctf_field_type_common_compare(seq_ft_a
->element_ft
,
3685 seq_ft_b
->element_ft
);
3687 BT_LOGV("Sequence field types differ: different element field types: "
3688 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3689 seq_ft_a
->element_ft
, seq_ft_b
->element_ft
);
3697 int bt_ctf_field_type_common_compare(struct bt_ctf_field_type_common
*ft_a
,
3698 struct bt_ctf_field_type_common
*ft_b
)
3702 BT_ASSERT_PRE_NON_NULL(ft_a
, "Field type A");
3703 BT_ASSERT_PRE_NON_NULL(ft_b
, "Field type B");
3706 /* Same reference: equal (even if both are NULL) */
3712 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
3718 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
3723 if (ft_a
->id
!= ft_b
->id
) {
3724 /* Different type IDs */
3725 BT_LOGV("Field types differ: different IDs: "
3726 "ft-a-addr=%p, ft-b-addr=%p, "
3727 "ft-a-id=%s, ft-b-id=%s",
3729 bt_ctf_field_type_id_string(ft_a
->id
),
3730 bt_ctf_field_type_id_string(ft_b
->id
));
3734 if (ft_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3735 /* Both have unknown type IDs */
3736 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
3740 BT_ASSERT(ft_a
->methods
->compare
);
3741 ret
= ft_a
->methods
->compare(ft_a
, ft_b
);
3743 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
3752 int64_t bt_ctf_field_type_common_get_field_count(struct bt_ctf_field_type_common
*ft
)
3754 int64_t field_count
= -1;
3757 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3759 bt_ctf_field_type_common_structure_get_field_count(ft
);
3761 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3763 bt_ctf_field_type_common_variant_get_field_count(ft
);
3765 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3766 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3768 * Array and sequence types always contain a single member
3769 * (the element type).
3781 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_borrow_field_at_index(
3782 struct bt_ctf_field_type_common
*ft
, int index
)
3784 struct bt_ctf_field_type_common
*field_type
= NULL
;
3787 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3789 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3790 ft
, NULL
, &field_type
, index
);
3797 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3799 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3800 ft
, NULL
, &field_type
, index
);
3807 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3809 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
3811 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3813 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
3824 int bt_ctf_field_type_common_get_field_index(struct bt_ctf_field_type_common
*ft
,
3827 int field_index
= -1;
3830 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3831 field_index
= bt_ctf_field_type_common_structure_get_field_name_index(
3834 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3835 field_index
= bt_ctf_field_type_common_variant_get_field_name_index(
3846 struct bt_ctf_field_path
*bt_ctf_field_type_common_variant_borrow_tag_field_path(
3847 struct bt_ctf_field_type_common
*ft
)
3849 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3851 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3852 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
3854 return var_ft
->tag_field_path
;
3858 struct bt_ctf_field_path
*bt_ctf_field_type_common_sequence_borrow_length_field_path(
3859 struct bt_ctf_field_type_common
*ft
)
3861 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3863 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
3864 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
3866 return seq_ft
->length_field_path
;
3870 int bt_ctf_field_type_common_validate_single_clock_class(
3871 struct bt_ctf_field_type_common
*ft
,
3872 struct bt_ctf_clock_class
**expected_clock_class
)
3880 BT_ASSERT(expected_clock_class
);
3883 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3885 struct bt_ctf_clock_class
*mapped_clock_class
=
3886 bt_ctf_field_type_common_integer_borrow_mapped_clock_class(ft
);
3888 if (!mapped_clock_class
) {
3892 if (!*expected_clock_class
) {
3893 /* Move reference to output parameter */
3894 *expected_clock_class
= bt_object_get_ref(mapped_clock_class
);
3895 mapped_clock_class
= NULL
;
3896 BT_LOGV("Setting expected clock class: "
3897 "expected-clock-class-addr=%p",
3898 *expected_clock_class
);
3900 if (mapped_clock_class
!= *expected_clock_class
) {
3901 BT_LOGW("Integer field type is not mapped to "
3902 "the expected clock class: "
3903 "mapped-clock-class-addr=%p, "
3904 "mapped-clock-class-name=\"%s\", "
3905 "expected-clock-class-addr=%p, "
3906 "expected-clock-class-name=\"%s\"",
3908 bt_ctf_clock_class_get_name(mapped_clock_class
),
3909 *expected_clock_class
,
3910 bt_ctf_clock_class_get_name(*expected_clock_class
));
3911 bt_object_put_ref(mapped_clock_class
);
3919 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3920 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3921 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3923 struct bt_ctf_field_type_common
*sub_ft
= NULL
;
3926 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3927 sub_ft
= bt_ctf_field_type_common_enumeration_borrow_container_field_type(
3930 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3931 sub_ft
= bt_ctf_field_type_common_array_borrow_element_field_type(
3934 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3935 sub_ft
= bt_ctf_field_type_common_sequence_borrow_element_field_type(
3939 BT_LOGF("Unexpected field type ID: id=%d", ft
->id
);
3944 ret
= bt_ctf_field_type_common_validate_single_clock_class(sub_ft
,
3945 expected_clock_class
);
3948 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3951 int64_t count
= bt_ctf_field_type_common_structure_get_field_count(
3954 for (i
= 0; i
< count
; i
++) {
3956 struct bt_ctf_field_type_common
*member_type
;
3958 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3959 ft
, &name
, &member_type
, i
);
3960 BT_ASSERT(ret
== 0);
3961 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3962 member_type
, expected_clock_class
);
3964 BT_LOGW("Structure field type's field's type "
3965 "is not recursively mapped to the "
3966 "expected clock class: "
3967 "field-ft-addr=%p, field-name=\"%s\"",
3974 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3977 int64_t count
= bt_ctf_field_type_common_variant_get_field_count(
3980 for (i
= 0; i
< count
; i
++) {
3982 struct bt_ctf_field_type_common
*member_type
;
3984 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3985 ft
, &name
, &member_type
, i
);
3986 BT_ASSERT(ret
== 0);
3987 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3988 member_type
, expected_clock_class
);
3990 BT_LOGW("Variant field type's field's type "
3991 "is not recursively mapped to the "
3992 "expected clock class: "
3993 "field-ft-addr=%p, field-name=\"%s\"",
4009 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4010 struct bt_ctf_field_type
*ft
);
4013 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
4014 struct bt_ctf_field_type
*ft
);
4017 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4018 struct bt_ctf_field_type
*ft
);
4021 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
4022 struct bt_ctf_field_type
*ft
);
4025 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
4026 struct bt_ctf_field_type
*ft
);
4029 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
4030 struct bt_ctf_field_type
*ft
);
4033 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
4034 struct bt_ctf_field_type
*type
);
4037 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4038 struct bt_ctf_field_type
*type
);
4040 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_integer_methods
= {
4041 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4042 .validate
= bt_ctf_field_type_common_integer_validate
,
4043 .set_byte_order
= bt_ctf_field_type_common_integer_set_byte_order
,
4044 .copy
= (bt_ctf_field_type_common_method_copy
)
4045 bt_ctf_field_type_integer_copy
,
4046 .compare
= bt_ctf_field_type_common_integer_compare
,
4049 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_floating_point_methods
= {
4050 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4052 .set_byte_order
= bt_ctf_field_type_common_floating_point_set_byte_order
,
4053 .copy
= (bt_ctf_field_type_common_method_copy
)
4054 bt_ctf_field_type_floating_point_copy
,
4055 .compare
= bt_ctf_field_type_common_floating_point_compare
,
4058 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_enumeration_methods
= {
4059 .freeze
= bt_ctf_field_type_common_enumeration_freeze_recursive
,
4060 .validate
= bt_ctf_field_type_common_enumeration_validate_recursive
,
4061 .set_byte_order
= bt_ctf_field_type_common_enumeration_set_byte_order_recursive
,
4062 .copy
= (bt_ctf_field_type_common_method_copy
)
4063 bt_ctf_field_type_enumeration_copy_recursive
,
4064 .compare
= bt_ctf_field_type_common_enumeration_compare_recursive
,
4067 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_string_methods
= {
4068 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4070 .set_byte_order
= NULL
,
4071 .copy
= (bt_ctf_field_type_common_method_copy
)
4072 bt_ctf_field_type_string_copy
,
4073 .compare
= bt_ctf_field_type_common_string_compare
,
4076 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_array_methods
= {
4077 .freeze
= bt_ctf_field_type_common_array_freeze_recursive
,
4078 .validate
= bt_ctf_field_type_common_array_validate_recursive
,
4079 .set_byte_order
= bt_ctf_field_type_common_array_set_byte_order_recursive
,
4080 .copy
= (bt_ctf_field_type_common_method_copy
)
4081 bt_ctf_field_type_array_copy_recursive
,
4082 .compare
= bt_ctf_field_type_common_array_compare_recursive
,
4085 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_sequence_methods
= {
4086 .freeze
= bt_ctf_field_type_common_sequence_freeze_recursive
,
4087 .validate
= bt_ctf_field_type_common_sequence_validate_recursive
,
4088 .set_byte_order
= bt_ctf_field_type_common_sequence_set_byte_order_recursive
,
4089 .copy
= (bt_ctf_field_type_common_method_copy
)
4090 bt_ctf_field_type_sequence_copy_recursive
,
4091 .compare
= bt_ctf_field_type_common_sequence_compare_recursive
,
4094 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_structure_methods
= {
4095 .freeze
= bt_ctf_field_type_common_structure_freeze_recursive
,
4096 .validate
= bt_ctf_field_type_common_structure_validate_recursive
,
4097 .set_byte_order
= bt_ctf_field_type_common_structure_set_byte_order_recursive
,
4098 .copy
= (bt_ctf_field_type_common_method_copy
)
4099 bt_ctf_field_type_structure_copy_recursive
,
4100 .compare
= bt_ctf_field_type_common_structure_compare_recursive
,
4103 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_variant_methods
= {
4104 .freeze
= bt_ctf_field_type_common_variant_freeze_recursive
,
4105 .validate
= bt_ctf_field_type_common_variant_validate_recursive
,
4106 .set_byte_order
= bt_ctf_field_type_common_variant_set_byte_order_recursive
,
4107 .copy
= (bt_ctf_field_type_common_method_copy
)
4108 bt_ctf_field_type_variant_copy_recursive
,
4109 .compare
= bt_ctf_field_type_common_variant_compare_recursive
,
4112 typedef int (*bt_ctf_field_type_serialize_func
)(struct bt_ctf_field_type_common
*,
4113 struct metadata_context
*);
4116 int bt_ctf_field_type_serialize_recursive(struct bt_ctf_field_type
*type
,
4117 struct metadata_context
*context
)
4120 struct bt_ctf_field_type_common
*type_common
= (void *) type
;
4121 bt_ctf_field_type_serialize_func serialize_func
;
4126 /* Make sure field type is valid before serializing it */
4127 ret
= bt_ctf_field_type_common_validate((void *) type
);
4129 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
4134 serialize_func
= type_common
->spec
.writer
.serialize_func
;
4135 ret
= serialize_func((void *) type
, context
);
4142 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
4144 const char *encoding_string
;
4147 case BT_CTF_STRING_ENCODING_NONE
:
4148 encoding_string
= "none";
4150 case BT_CTF_STRING_ENCODING_ASCII
:
4151 encoding_string
= "ASCII";
4153 case BT_CTF_STRING_ENCODING_UTF8
:
4154 encoding_string
= "UTF8";
4157 encoding_string
= "unknown";
4161 return encoding_string
;
4165 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
4167 const char *base_string
;
4170 case BT_CTF_INTEGER_BASE_DECIMAL
:
4171 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
4172 base_string
= "decimal";
4174 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
4175 base_string
= "hexadecimal";
4177 case BT_CTF_INTEGER_BASE_OCTAL
:
4178 base_string
= "octal";
4180 case BT_CTF_INTEGER_BASE_BINARY
:
4181 base_string
= "binary";
4184 base_string
= "unknown";
4192 void append_field_name(struct metadata_context
*context
,
4195 g_string_append_c(context
->string
, ' ');
4197 if (!bt_ctf_identifier_is_valid(name
) || *name
== '_') {
4198 g_string_append_c(context
->string
, '_');
4201 g_string_append(context
->string
, name
);
4205 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type_common
*type
,
4206 struct metadata_context
*context
)
4208 struct bt_ctf_field_type_common_integer
*integer
= BT_CTF_FROM_COMMON(type
);
4211 BT_LOGD("Serializing CTF writer integer field type's metadata: "
4212 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4213 g_string_append_printf(context
->string
,
4214 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
4215 integer
->size
, type
->alignment
,
4216 (integer
->is_signed
? "true" : "false"),
4217 get_encoding_string(integer
->encoding
),
4218 get_integer_base_string(integer
->base
),
4219 bt_ctf_get_byte_order_string(integer
->user_byte_order
));
4220 if (integer
->mapped_clock_class
) {
4221 const char *clock_name
= bt_ctf_clock_class_get_name(
4222 integer
->mapped_clock_class
);
4224 BT_ASSERT(clock_name
);
4225 g_string_append_printf(context
->string
,
4226 "; map = clock.%s.value", clock_name
);
4229 g_string_append(context
->string
, "; }");
4234 int bt_ctf_field_type_enumeration_serialize_recursive(
4235 struct bt_ctf_field_type_common
*type
,
4236 struct metadata_context
*context
)
4240 struct bt_ctf_field_type_common_enumeration
*enumeration
=
4241 BT_CTF_FROM_COMMON(type
);
4242 struct bt_ctf_field_type_common
*container_type
;
4243 int container_signed
;
4245 BT_LOGD("Serializing CTF writer enumeration field type's metadata: "
4246 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4248 bt_ctf_field_type_common_enumeration_borrow_container_field_type(type
);
4249 BT_ASSERT(container_type
);
4250 container_signed
= bt_ctf_field_type_common_integer_is_signed(
4252 BT_ASSERT(container_signed
>= 0);
4253 g_string_append(context
->string
, "enum : ");
4254 BT_LOGD_STR("Serializing CTF writer enumeration field type's container field type's metadata.");
4255 ret
= bt_ctf_field_type_serialize_recursive(
4256 (void *) enumeration
->container_ft
, context
);
4258 BT_LOGW("Cannot serialize CTF writer enumeration field type's container field type's metadata: "
4259 "container-ft-addr=%p", enumeration
->container_ft
);
4263 g_string_append(context
->string
, " { ");
4264 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
4265 struct bt_ctf_enumeration_mapping
*mapping
=
4266 enumeration
->entries
->pdata
[entry
];
4267 const char *label
= g_quark_to_string(mapping
->string
);
4269 g_string_append(context
->string
, "\"");
4271 if (!bt_ctf_identifier_is_valid(label
) || label
[0] == '_') {
4272 g_string_append(context
->string
, "_");
4275 g_string_append_printf(context
->string
, "%s\" = ", label
);
4277 if (container_signed
) {
4278 if (mapping
->range_start
._signed
==
4279 mapping
->range_end
._signed
) {
4280 g_string_append_printf(context
->string
,
4282 mapping
->range_start
._signed
);
4284 g_string_append_printf(context
->string
,
4285 "%" PRId64
" ... %" PRId64
,
4286 mapping
->range_start
._signed
,
4287 mapping
->range_end
._signed
);
4290 if (mapping
->range_start
._unsigned
==
4291 mapping
->range_end
._unsigned
) {
4292 g_string_append_printf(context
->string
,
4294 mapping
->range_start
._unsigned
);
4296 g_string_append_printf(context
->string
,
4297 "%" PRIu64
" ... %" PRIu64
,
4298 mapping
->range_start
._unsigned
,
4299 mapping
->range_end
._unsigned
);
4303 g_string_append(context
->string
,
4304 ((entry
!= (enumeration
->entries
->len
- 1)) ?
4308 if (context
->field_name
->len
) {
4309 append_field_name(context
,
4310 context
->field_name
->str
);
4311 g_string_assign(context
->field_name
, "");
4319 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type_common
*type
,
4320 struct metadata_context
*context
)
4322 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4323 BT_CTF_FROM_COMMON(type
);
4325 BT_LOGD("Serializing CTF writer floating point number field type's metadata: "
4326 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4327 g_string_append_printf(context
->string
,
4328 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
4329 floating_point
->exp_dig
,
4330 floating_point
->mant_dig
,
4331 bt_ctf_get_byte_order_string(floating_point
->user_byte_order
),
4337 int bt_ctf_field_type_structure_serialize_recursive(
4338 struct bt_ctf_field_type_common
*type
,
4339 struct metadata_context
*context
)
4342 unsigned int indent
;
4344 struct bt_ctf_field_type_common_structure
*structure
= BT_CTF_FROM_COMMON(type
);
4345 GString
*structure_field_name
= context
->field_name
;
4347 BT_LOGD("Serializing CTF writer structure field type's metadata: "
4348 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4349 context
->field_name
= g_string_new("");
4351 context
->current_indentation_level
++;
4352 g_string_append(context
->string
, "struct {\n");
4354 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4355 struct bt_ctf_field_type_common_structure_field
*field
=
4356 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
4359 BT_LOGD("Serializing CTF writer structure field type's field metadata: "
4361 "field-ft-addr=%p, field-name=\"%s\"",
4362 i
, field
, g_quark_to_string(field
->name
));
4364 for (indent
= 0; indent
< context
->current_indentation_level
;
4366 g_string_append_c(context
->string
, '\t');
4369 g_string_assign(context
->field_name
,
4370 g_quark_to_string(field
->name
));
4371 ret
= bt_ctf_field_type_serialize_recursive(
4372 (void *) field
->type
, context
);
4374 BT_LOGW("Cannot serialize CTF writer structure field type's field's metadata: "
4376 "field-ft-addr=%p, field-name=\"%s\"",
4378 g_quark_to_string(field
->name
));
4382 if (context
->field_name
->len
) {
4383 append_field_name(context
,
4384 context
->field_name
->str
);
4386 g_string_append(context
->string
, ";\n");
4389 context
->current_indentation_level
--;
4390 for (indent
= 0; indent
< context
->current_indentation_level
;
4392 g_string_append_c(context
->string
, '\t');
4395 g_string_append_printf(context
->string
, "} align(%u)",
4399 g_string_free(context
->field_name
, TRUE
);
4400 context
->field_name
= structure_field_name
;
4405 int bt_ctf_field_type_variant_serialize_recursive(
4406 struct bt_ctf_field_type_common
*type
,
4407 struct metadata_context
*context
)
4410 unsigned int indent
;
4412 struct bt_ctf_field_type_common_variant
*variant
= BT_CTF_FROM_COMMON(type
);
4413 GString
*variant_field_name
= context
->field_name
;
4415 BT_LOGD("Serializing CTF writer variant field type's metadata: "
4416 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4417 context
->field_name
= g_string_new("");
4418 if (variant
->tag_name
->len
> 0) {
4419 g_string_append(context
->string
, "variant <");
4420 append_field_name(context
, variant
->tag_name
->str
);
4421 g_string_append(context
->string
, "> {\n");
4423 g_string_append(context
->string
, "variant {\n");
4426 context
->current_indentation_level
++;
4427 for (i
= 0; i
< variant
->choices
->len
; i
++) {
4428 struct bt_ctf_field_type_common_variant_choice
*field
=
4429 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
4432 BT_LOGD("Serializing CTF writer variant field type's field metadata: "
4434 "field-ft-addr=%p, field-name=\"%s\"",
4435 i
, field
, g_quark_to_string(field
->name
));
4437 g_string_assign(context
->field_name
,
4438 g_quark_to_string(field
->name
));
4439 for (indent
= 0; indent
< context
->current_indentation_level
;
4441 g_string_append_c(context
->string
, '\t');
4444 g_string_assign(context
->field_name
,
4445 g_quark_to_string(field
->name
));
4446 ret
= bt_ctf_field_type_serialize_recursive(
4447 (void *) field
->type
, context
);
4449 BT_LOGW("Cannot serialize CTF writer variant field type's field's metadata: "
4451 "field-ft-addr=%p, field-name=\"%s\"",
4453 g_quark_to_string(field
->name
));
4457 if (context
->field_name
->len
) {
4458 append_field_name(context
,
4459 context
->field_name
->str
);
4460 g_string_append_c(context
->string
, ';');
4463 g_string_append_c(context
->string
, '\n');
4466 context
->current_indentation_level
--;
4467 for (indent
= 0; indent
< context
->current_indentation_level
;
4469 g_string_append_c(context
->string
, '\t');
4472 g_string_append(context
->string
, "}");
4475 g_string_free(context
->field_name
, TRUE
);
4476 context
->field_name
= variant_field_name
;
4481 int bt_ctf_field_type_array_serialize_recursive(
4482 struct bt_ctf_field_type_common
*type
,
4483 struct metadata_context
*context
)
4486 struct bt_ctf_field_type_common_array
*array
= BT_CTF_FROM_COMMON(type
);
4488 BT_LOGD("Serializing CTF writer array field type's metadata: "
4489 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4490 BT_LOGD_STR("Serializing CTF writer array field type's element field type's metadata.");
4491 ret
= bt_ctf_field_type_serialize_recursive(
4492 (void *) array
->element_ft
, context
);
4494 BT_LOGW("Cannot serialize CTF writer array field type's element field type's metadata: "
4495 "element-ft-addr=%p", array
->element_ft
);
4499 if (context
->field_name
->len
) {
4500 append_field_name(context
,
4501 context
->field_name
->str
);
4503 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4504 g_string_assign(context
->field_name
, "");
4506 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4514 int bt_ctf_field_type_sequence_serialize_recursive(
4515 struct bt_ctf_field_type_common
*type
,
4516 struct metadata_context
*context
)
4519 struct bt_ctf_field_type_common_sequence
*sequence
= BT_CTF_FROM_COMMON(type
);
4521 BT_LOGD("Serializing CTF writer sequence field type's metadata: "
4522 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4523 BT_LOGD_STR("Serializing CTF writer sequence field type's element field type's metadata.");
4524 ret
= bt_ctf_field_type_serialize_recursive(
4525 (void *) sequence
->element_ft
, context
);
4527 BT_LOGW("Cannot serialize CTF writer sequence field type's element field type's metadata: "
4528 "element-ft-addr=%p", sequence
->element_ft
);
4532 if (context
->field_name
->len
) {
4533 append_field_name(context
, context
->field_name
->str
);
4534 g_string_assign(context
->field_name
, "");
4536 g_string_append(context
->string
, "[");
4537 append_field_name(context
, sequence
->length_field_name
->str
);
4538 g_string_append(context
->string
, "]");
4545 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type_common
*type
,
4546 struct metadata_context
*context
)
4548 struct bt_ctf_field_type_common_string
*string
= BT_CTF_FROM_COMMON(type
);
4550 BT_LOGD("Serializing CTF writer string field type's metadata: "
4551 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4552 g_string_append_printf(context
->string
,
4553 "string { encoding = %s; }",
4554 get_encoding_string(string
->encoding
));
4558 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
4560 struct bt_ctf_field_type_common_integer
*integer
= NULL
;
4562 BT_LOGD("Creating CTF writer integer field type object: size=%u", size
);
4564 if (size
== 0 || size
> 64) {
4565 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
4570 integer
= g_new0(struct bt_ctf_field_type_common_integer
, 1);
4572 BT_LOGE_STR("Failed to allocate one integer field type.");
4576 bt_ctf_field_type_common_integer_initialize(BT_CTF_TO_COMMON(integer
),
4577 size
, bt_ctf_field_type_common_integer_destroy
,
4578 &bt_ctf_field_type_integer_methods
);
4579 integer
->common
.spec
.writer
.serialize_func
=
4580 bt_ctf_field_type_integer_serialize
;
4581 BT_LOGD("Created CTF writer integer field type object: addr=%p, size=%u",
4586 BT_OBJECT_PUT_REF_AND_RESET(integer
);
4589 return (void *) integer
;
4592 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*ft
)
4594 return bt_ctf_field_type_common_integer_get_size((void *) ft
);
4597 bt_bool
bt_ctf_field_type_integer_is_signed(struct bt_ctf_field_type
*ft
)
4599 return bt_ctf_field_type_common_integer_is_signed((void *) ft
);
4602 int bt_ctf_field_type_integer_set_is_signed(struct bt_ctf_field_type
*ft
,
4605 return bt_ctf_field_type_common_integer_set_is_signed((void *) ft
,
4609 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*ft
,
4612 return bt_ctf_field_type_common_integer_set_size((void *) ft
, size
);
4615 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
4616 struct bt_ctf_field_type
*ft
)
4618 return (int) bt_ctf_field_type_common_integer_get_base((void *) ft
);
4621 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*ft
,
4622 enum bt_ctf_integer_base base
)
4624 return bt_ctf_field_type_common_integer_set_base((void *) ft
,
4628 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
4629 struct bt_ctf_field_type
*ft
)
4631 return (int) bt_ctf_field_type_common_integer_get_encoding((void *) ft
);
4634 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*ft
,
4635 enum bt_ctf_string_encoding encoding
)
4637 return bt_ctf_field_type_common_integer_set_encoding((void *) ft
,
4641 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
4642 struct bt_ctf_field_type
*ft
)
4644 return bt_object_get_ref(bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
4648 int bt_ctf_field_type_integer_set_mapped_clock_class(
4649 struct bt_ctf_field_type
*ft
,
4650 struct bt_ctf_clock_class
*clock_class
)
4652 return bt_ctf_field_type_common_integer_set_mapped_clock_class((void *) ft
,
4656 int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
4657 struct bt_ctf_field_type
*ft
, uint64_t index
,
4658 const char **mapping_name
, int64_t *range_begin
,
4661 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
4662 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4665 int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
4666 struct bt_ctf_field_type
*ft
, uint64_t index
,
4667 const char **mapping_name
, uint64_t *range_begin
,
4668 uint64_t *range_end
)
4670 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
4671 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4674 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
4675 struct bt_ctf_field_type
*container_ft
)
4677 struct bt_ctf_field_type_common_enumeration
*enumeration
= NULL
;
4678 struct bt_ctf_field_type_common
*int_ft
= (void *) container_ft
;
4680 BT_LOGD("Creating CTF writer enumeration field type object: int-ft-addr=%p",
4683 if (!container_ft
) {
4684 BT_LOGW_STR("Invalid parameter: field type is NULL.");
4688 if (int_ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
4689 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
4690 "container-ft-addr=%p, container-ft-id=%s",
4691 container_ft
, bt_ctf_field_type_id_string(int_ft
->id
));
4695 enumeration
= g_new0(struct bt_ctf_field_type_common_enumeration
, 1);
4697 BT_LOGE_STR("Failed to allocate one enumeration field type.");
4701 bt_ctf_field_type_common_enumeration_initialize(BT_CTF_TO_COMMON(enumeration
),
4702 int_ft
, bt_ctf_field_type_common_enumeration_destroy_recursive
,
4703 &bt_ctf_field_type_enumeration_methods
);
4704 enumeration
->common
.spec
.writer
.serialize_func
=
4705 bt_ctf_field_type_enumeration_serialize_recursive
;
4706 BT_LOGD("Created CTF writer enumeration field type object: addr=%p, "
4707 "int-ft-addr=%p, int-ft-size=%u",
4708 enumeration
, container_ft
,
4709 bt_ctf_field_type_integer_get_size(container_ft
));
4713 BT_OBJECT_PUT_REF_AND_RESET(enumeration
);
4716 return (void *) enumeration
;
4719 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
4720 struct bt_ctf_field_type
*ft
)
4722 return bt_object_get_ref(
4723 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
4727 int bt_ctf_field_type_enumeration_signed_add_mapping(
4728 struct bt_ctf_field_type
*ft
, const char *string
,
4729 int64_t range_start
, int64_t range_end
)
4731 return bt_ctf_field_type_common_enumeration_signed_add_mapping(
4732 (void *) ft
, string
, range_start
, range_end
);
4735 int bt_ctf_field_type_enumeration_unsigned_add_mapping(
4736 struct bt_ctf_field_type
*ft
, const char *string
,
4737 uint64_t range_start
, uint64_t range_end
)
4739 return bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
4740 (void *) ft
, string
, range_start
, range_end
);
4743 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
4744 struct bt_ctf_field_type
*ft
)
4746 return bt_ctf_field_type_common_enumeration_get_mapping_count((void *) ft
);
4749 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
4751 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4752 g_new0(struct bt_ctf_field_type_common_floating_point
, 1);
4754 BT_LOGD_STR("Creating CTF writer floating point number field type object.");
4756 if (!floating_point
) {
4757 BT_LOGE_STR("Failed to allocate one floating point number field type.");
4761 bt_ctf_field_type_common_floating_point_initialize(
4762 BT_CTF_TO_COMMON(floating_point
),
4763 bt_ctf_field_type_common_floating_point_destroy
,
4764 &bt_ctf_field_type_floating_point_methods
);
4765 floating_point
->common
.spec
.writer
.serialize_func
=
4766 bt_ctf_field_type_floating_point_serialize
;
4767 BT_LOGD("Created CTF writer floating point number field type object: addr=%p, "
4768 "exp-size=%u, mant-size=%u", floating_point
,
4769 floating_point
->exp_dig
, floating_point
->mant_dig
);
4772 return (void *) floating_point
;
4775 int bt_ctf_field_type_floating_point_get_exponent_digits(
4776 struct bt_ctf_field_type
*ft
)
4778 return bt_ctf_field_type_common_floating_point_get_exponent_digits(
4782 int bt_ctf_field_type_floating_point_set_exponent_digits(
4783 struct bt_ctf_field_type
*ft
, unsigned int exponent_digits
)
4785 return bt_ctf_field_type_common_floating_point_set_exponent_digits(
4786 (void *) ft
, exponent_digits
);
4789 int bt_ctf_field_type_floating_point_get_mantissa_digits(
4790 struct bt_ctf_field_type
*ft
)
4792 return bt_ctf_field_type_common_floating_point_get_mantissa_digits(
4796 int bt_ctf_field_type_floating_point_set_mantissa_digits(
4797 struct bt_ctf_field_type
*ft
, unsigned int mantissa_digits
)
4799 return bt_ctf_field_type_common_floating_point_set_mantissa_digits(
4800 (void *) ft
, mantissa_digits
);
4803 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
4805 struct bt_ctf_field_type_common_structure
*structure
=
4806 g_new0(struct bt_ctf_field_type_common_structure
, 1);
4808 BT_LOGD_STR("Creating CTF writer structure field type object.");
4811 BT_LOGE_STR("Failed to allocate one structure field type.");
4815 bt_ctf_field_type_common_structure_initialize(BT_CTF_TO_COMMON(structure
),
4816 bt_ctf_field_type_common_structure_destroy_recursive
,
4817 &bt_ctf_field_type_structure_methods
);
4818 structure
->common
.spec
.writer
.serialize_func
=
4819 bt_ctf_field_type_structure_serialize_recursive
;
4820 BT_LOGD("Created CTF writer structure field type object: addr=%p",
4825 BT_OBJECT_PUT_REF_AND_RESET(structure
);
4828 return (void *) structure
;
4831 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*ft
,
4832 struct bt_ctf_field_type
*field_type
,
4833 const char *field_name
)
4835 return bt_ctf_field_type_common_structure_add_field((void *) ft
,
4836 (void *) field_type
, field_name
);
4839 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type
*ft
)
4841 return bt_ctf_field_type_common_structure_get_field_count((void *) ft
);
4844 int bt_ctf_field_type_structure_get_field_by_index(
4845 struct bt_ctf_field_type
*ft
,
4846 const char **field_name
,
4847 struct bt_ctf_field_type
**field_type
, uint64_t index
)
4849 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
4850 (void *) ft
, field_name
, (void *) field_type
, index
);
4852 if (ret
== 0 && field_type
) {
4853 bt_object_get_ref(*field_type
);
4859 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
4860 struct bt_ctf_field_type
*ft
, const char *name
)
4862 return bt_object_get_ref(bt_ctf_field_type_common_structure_borrow_field_type_by_name(
4863 (void *) ft
, name
));
4866 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
4867 struct bt_ctf_field_type
*tag_ft
, const char *tag_name
)
4869 struct bt_ctf_field_type_common_variant
*var_ft
= NULL
;
4871 BT_LOGD("Creating CTF writer variant field type object: "
4872 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4875 if (tag_name
&& !bt_ctf_identifier_is_valid(tag_name
)) {
4876 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
4877 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4882 var_ft
= g_new0(struct bt_ctf_field_type_common_variant
, 1);
4884 BT_LOGE_STR("Failed to allocate one variant field type.");
4888 bt_ctf_field_type_common_variant_initialize(BT_CTF_TO_COMMON(var_ft
),
4889 (void *) tag_ft
, tag_name
,
4890 bt_ctf_field_type_common_variant_destroy_recursive
,
4891 &bt_ctf_field_type_variant_methods
);
4892 var_ft
->common
.spec
.writer
.serialize_func
=
4893 bt_ctf_field_type_variant_serialize_recursive
;
4894 BT_LOGD("Created CTF writer variant field type object: addr=%p, "
4895 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4896 var_ft
, tag_ft
, tag_name
);
4900 BT_OBJECT_PUT_REF_AND_RESET(var_ft
);
4903 return (void *) var_ft
;
4906 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
4907 struct bt_ctf_field_type
*ft
)
4909 return bt_object_get_ref(bt_ctf_field_type_common_variant_borrow_tag_field_type(
4913 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type
*ft
)
4915 return bt_ctf_field_type_common_variant_get_tag_name((void *) ft
);
4918 int bt_ctf_field_type_variant_set_tag_name(
4919 struct bt_ctf_field_type
*ft
, const char *name
)
4921 return bt_ctf_field_type_common_variant_set_tag_name((void *) ft
, name
);
4924 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*ft
,
4925 struct bt_ctf_field_type
*field_type
,
4926 const char *field_name
)
4928 return bt_ctf_field_type_common_variant_add_field((void *) ft
,
4929 (void *) field_type
, field_name
);
4932 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
4933 struct bt_ctf_field_type
*ft
,
4934 const char *field_name
)
4936 return bt_object_get_ref(bt_ctf_field_type_common_variant_borrow_field_type_by_name(
4937 (void *) ft
, field_name
));
4940 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
4941 struct bt_ctf_field_type
*ft
,
4942 struct bt_ctf_field
*tag_field
)
4945 int64_t choice_index
;
4946 struct bt_ctf_field
*container
;
4947 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
4948 struct bt_ctf_field_type
*ret_ft
= NULL
;
4950 BT_ASSERT_PRE_NON_NULL(ft
, "Field type");
4951 BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
4953 BT_ASSERT_PRE_NON_NULL(tag_field
, "Tag field");
4954 BT_ASSERT_PRE_CTF_FIELD_COMMON_HAS_TYPE_ID(
4955 (struct bt_ctf_field_common
*) tag_field
,
4956 BT_CTF_FIELD_TYPE_ID_ENUM
, "Tag field");
4957 BT_ASSERT_PRE_CTF_FIELD_COMMON_IS_SET((struct bt_ctf_field_common
*) tag_field
,
4960 container
= bt_ctf_field_enumeration_borrow_container(tag_field
);
4961 BT_ASSERT(container
);
4963 if (var_ft
->tag_ft
->container_ft
->is_signed
) {
4966 ret
= bt_ctf_field_integer_signed_get_value(container
,
4968 BT_ASSERT(ret
== 0);
4969 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4970 (void *) ft
, (uint64_t) val
, true);
4974 ret
= bt_ctf_field_integer_unsigned_get_value(container
,
4976 BT_ASSERT(ret
== 0);
4977 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4978 (void *) ft
, val
, false);
4981 if (choice_index
< 0) {
4982 BT_LIB_LOGW("Cannot find variant field type's field: "
4983 "var-ft-addr=%p, tag-field-addr=%p", ft
, tag_field
);
4987 ret
= bt_ctf_field_type_variant_get_field_by_index(ft
, NULL
,
4988 &ret_ft
, choice_index
);
4989 BT_ASSERT(ret
== 0);
4995 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*ft
)
4997 return bt_ctf_field_type_common_variant_get_field_count((void *) ft
);
5000 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*ft
,
5001 const char **field_name
, struct bt_ctf_field_type
**field_type
,
5004 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
5005 (void *) ft
, field_name
, (void *) field_type
, index
);
5007 if (ret
== 0 && field_type
) {
5008 bt_object_get_ref(*field_type
);
5014 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
5015 struct bt_ctf_field_type
*element_ft
, unsigned int length
)
5017 struct bt_ctf_field_type_common_array
*array
= NULL
;
5019 BT_LOGD("Creating CTF writer array field type object: element-ft-addr=%p, "
5020 "length=%u", element_ft
, length
);
5023 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
5028 BT_LOGW_STR("Invalid parameter: length is zero.");
5032 array
= g_new0(struct bt_ctf_field_type_common_array
, 1);
5034 BT_LOGE_STR("Failed to allocate one array field type.");
5038 bt_ctf_field_type_common_array_initialize(BT_CTF_TO_COMMON(array
),
5039 (void *) element_ft
, length
,
5040 bt_ctf_field_type_common_array_destroy_recursive
,
5041 &bt_ctf_field_type_array_methods
);
5042 array
->common
.spec
.writer
.serialize_func
=
5043 bt_ctf_field_type_array_serialize_recursive
;
5044 BT_LOGD("Created CTF writer array field type object: addr=%p, "
5045 "element-ft-addr=%p, length=%u",
5046 array
, element_ft
, length
);
5050 BT_OBJECT_PUT_REF_AND_RESET(array
);
5053 return (void *) array
;
5056 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
5057 struct bt_ctf_field_type
*ft
)
5059 return bt_object_get_ref(bt_ctf_field_type_common_array_borrow_element_field_type(
5063 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*ft
)
5065 return bt_ctf_field_type_common_array_get_length((void *) ft
);
5068 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
5069 struct bt_ctf_field_type
*element_ft
,
5070 const char *length_field_name
)
5072 struct bt_ctf_field_type_common_sequence
*sequence
= NULL
;
5074 BT_LOGD("Creating CTF writer sequence field type object: element-ft-addr=%p, "
5075 "length-field-name=\"%s\"", element_ft
, length_field_name
);
5078 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
5082 if (!bt_ctf_identifier_is_valid(length_field_name
)) {
5083 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
5084 "length-field-name=\"%s\"", length_field_name
);
5088 sequence
= g_new0(struct bt_ctf_field_type_common_sequence
, 1);
5090 BT_LOGE_STR("Failed to allocate one sequence field type.");
5094 bt_ctf_field_type_common_sequence_initialize(BT_CTF_TO_COMMON(sequence
),
5095 (void *) element_ft
, length_field_name
,
5096 bt_ctf_field_type_common_sequence_destroy_recursive
,
5097 &bt_ctf_field_type_sequence_methods
);
5098 sequence
->common
.spec
.writer
.serialize_func
=
5099 bt_ctf_field_type_sequence_serialize_recursive
;
5100 BT_LOGD("Created CTF writer sequence field type object: addr=%p, "
5101 "element-ft-addr=%p, length-field-name=\"%s\"",
5102 sequence
, element_ft
, length_field_name
);
5106 BT_OBJECT_PUT_REF_AND_RESET(sequence
);
5109 return (void *) sequence
;
5112 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
5113 struct bt_ctf_field_type
*ft
)
5115 return bt_object_get_ref(bt_ctf_field_type_common_sequence_borrow_element_field_type(
5119 const char *bt_ctf_field_type_sequence_get_length_field_name(
5120 struct bt_ctf_field_type
*ft
)
5122 return bt_ctf_field_type_common_sequence_get_length_field_name((void *) ft
);
5125 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
5127 struct bt_ctf_field_type_common_string
*string
=
5128 g_new0(struct bt_ctf_field_type_common_string
, 1);
5130 BT_LOGD_STR("Creating CTF writer string field type object.");
5133 BT_LOGE_STR("Failed to allocate one string field type.");
5137 bt_ctf_field_type_common_string_initialize(BT_CTF_TO_COMMON(string
),
5138 bt_ctf_field_type_common_string_destroy
,
5139 &bt_ctf_field_type_string_methods
);
5140 string
->common
.spec
.writer
.serialize_func
=
5141 bt_ctf_field_type_string_serialize
;
5142 BT_LOGD("Created CTF writer string field type object: addr=%p", string
);
5143 return (void *) string
;
5146 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
5147 struct bt_ctf_field_type
*ft
)
5149 return (int) bt_ctf_field_type_common_string_get_encoding((void *) ft
);
5152 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*ft
,
5153 enum bt_ctf_string_encoding encoding
)
5155 return bt_ctf_field_type_common_string_set_encoding((void *) ft
,
5159 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*ft
)
5161 return bt_ctf_field_type_common_get_alignment((void *) ft
);
5164 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*ft
,
5165 unsigned int alignment
)
5167 return bt_ctf_field_type_common_set_alignment((void *) ft
, alignment
);
5170 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
5171 struct bt_ctf_field_type
*ft
)
5173 return (int) bt_ctf_field_type_common_get_byte_order((void *) ft
);
5176 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*ft
,
5177 enum bt_ctf_byte_order byte_order
)
5179 return bt_ctf_field_type_common_set_byte_order((void *) ft
,
5183 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
5184 struct bt_ctf_field_type
*ft
)
5186 return (int) bt_ctf_field_type_common_get_type_id((void *) ft
);
5190 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*ft
)
5192 return (void *) bt_ctf_field_type_common_copy((void *) ft
);
5196 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
5197 struct bt_ctf_field_type
*ft
)
5199 struct bt_ctf_field_type_common_integer
*int_ft
= (void *) ft
;
5200 struct bt_ctf_field_type_common_integer
*copy_ft
;
5202 BT_LOGD("Copying CTF writer integer field type's: addr=%p", ft
);
5203 copy_ft
= (void *) bt_ctf_field_type_integer_create(int_ft
->size
);
5205 BT_LOGE_STR("Cannot create CTF writer integer field type.");
5209 copy_ft
->mapped_clock_class
= bt_object_get_ref(int_ft
->mapped_clock_class
);
5210 copy_ft
->user_byte_order
= int_ft
->user_byte_order
;
5211 copy_ft
->is_signed
= int_ft
->is_signed
;
5212 copy_ft
->size
= int_ft
->size
;
5213 copy_ft
->base
= int_ft
->base
;
5214 copy_ft
->encoding
= int_ft
->encoding
;
5215 BT_LOGD("Copied CTF writer integer field type: original-ft-addr=%p, copy-ft-addr=%p",
5219 return (void *) copy_ft
;
5223 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
5224 struct bt_ctf_field_type
*ft
)
5227 struct bt_ctf_field_type_common_enumeration
*enum_ft
= (void *) ft
;
5228 struct bt_ctf_field_type_common_enumeration
*copy_ft
= NULL
;
5229 struct bt_ctf_field_type_common_enumeration
*container_copy_ft
;
5231 BT_LOGD("Copying CTF writer enumeration field type's: addr=%p", ft
);
5233 /* Copy the source enumeration's container */
5234 BT_LOGD_STR("Copying CTF writer enumeration field type's container field type.");
5235 container_copy_ft
= BT_CTF_FROM_COMMON(bt_ctf_field_type_common_copy(
5236 BT_CTF_TO_COMMON(enum_ft
->container_ft
)));
5237 if (!container_copy_ft
) {
5238 BT_LOGE_STR("Cannot copy CTF writer enumeration field type's container field type.");
5242 copy_ft
= (void *) bt_ctf_field_type_enumeration_create(
5243 (void *) container_copy_ft
);
5245 BT_LOGE_STR("Cannot create CTF writer enumeration field type.");
5249 /* Copy all enumaration entries */
5250 for (i
= 0; i
< enum_ft
->entries
->len
; i
++) {
5251 struct bt_ctf_enumeration_mapping
*mapping
= g_ptr_array_index(
5252 enum_ft
->entries
, i
);
5253 struct bt_ctf_enumeration_mapping
*copy_mapping
= g_new0(
5254 struct bt_ctf_enumeration_mapping
, 1);
5256 if (!copy_mapping
) {
5257 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
5261 *copy_mapping
= *mapping
;
5262 g_ptr_array_add(copy_ft
->entries
, copy_mapping
);
5265 BT_LOGD("Copied CTF writer enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
5269 bt_object_put_ref(container_copy_ft
);
5270 return (void *) copy_ft
;
5273 bt_object_put_ref(container_copy_ft
);
5274 BT_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5275 return (void *) copy_ft
;
5279 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
5280 struct bt_ctf_field_type
*ft
)
5282 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
5283 struct bt_ctf_field_type_common_floating_point
*copy_ft
;
5285 BT_LOGD("Copying CTF writer floating point number field type's: addr=%p", ft
);
5286 copy_ft
= (void *) bt_ctf_field_type_floating_point_create();
5288 BT_LOGE_STR("Cannot create CTF writer floating point number field type.");
5292 copy_ft
->user_byte_order
= flt_ft
->user_byte_order
;
5293 copy_ft
->exp_dig
= flt_ft
->exp_dig
;
5294 copy_ft
->mant_dig
= flt_ft
->mant_dig
;
5295 BT_LOGD("Copied CTF writer floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
5299 return (void *) copy_ft
;
5303 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
5304 struct bt_ctf_field_type
*ft
)
5307 GHashTableIter iter
;
5308 gpointer key
, value
;
5309 struct bt_ctf_field_type_common_structure
*struct_ft
= (void *) ft
;
5310 struct bt_ctf_field_type_common_structure
*copy_ft
;
5312 BT_LOGD("Copying CTF writer structure field type's: addr=%p", ft
);
5313 copy_ft
= (void *) bt_ctf_field_type_structure_create();
5315 BT_LOGE_STR("Cannot create CTF writer structure field type.");
5319 /* Copy field_name_to_index */
5320 g_hash_table_iter_init(&iter
, struct_ft
->field_name_to_index
);
5321 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5322 g_hash_table_insert(copy_ft
->field_name_to_index
,
5326 g_array_set_size(copy_ft
->fields
, struct_ft
->fields
->len
);
5328 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
5329 struct bt_ctf_field_type_common_structure_field
*entry
, *copy_entry
;
5330 struct bt_ctf_field_type_common
*field_ft_copy
;
5332 entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5334 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5336 BT_LOGD("Copying CTF writer structure field type's field: "
5337 "index=%" PRId64
", "
5338 "field-ft-addr=%p, field-name=\"%s\"",
5339 i
, entry
, g_quark_to_string(entry
->name
));
5341 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5342 (void *) entry
->type
);
5343 if (!field_ft_copy
) {
5344 BT_LOGE("Cannot copy CTF writer structure field type's field: "
5345 "index=%" PRId64
", "
5346 "field-ft-addr=%p, field-name=\"%s\"",
5347 i
, entry
, g_quark_to_string(entry
->name
));
5351 copy_entry
->name
= entry
->name
;
5352 copy_entry
->type
= field_ft_copy
;
5355 BT_LOGD("Copied CTF writer structure field type: original-ft-addr=%p, copy-ft-addr=%p",
5359 return (void *) copy_ft
;
5362 BT_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5367 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
5368 struct bt_ctf_field_type
*ft
)
5371 GHashTableIter iter
;
5372 gpointer key
, value
;
5373 struct bt_ctf_field_type_common
*tag_ft_copy
= NULL
;
5374 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
5375 struct bt_ctf_field_type_common_variant
*copy_ft
= NULL
;
5377 BT_LOGD("Copying CTF writer variant field type's: addr=%p", ft
);
5378 if (var_ft
->tag_ft
) {
5379 BT_LOGD_STR("Copying CTF writer variant field type's tag field type.");
5380 tag_ft_copy
= bt_ctf_field_type_common_copy(
5381 BT_CTF_TO_COMMON(var_ft
->tag_ft
));
5383 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field type.");
5388 copy_ft
= (void *) bt_ctf_field_type_variant_create(
5389 (void *) tag_ft_copy
,
5390 var_ft
->tag_name
->len
? var_ft
->tag_name
->str
: NULL
);
5392 BT_LOGE_STR("Cannot create CTF writer variant field type.");
5396 /* Copy field_name_to_index */
5397 g_hash_table_iter_init(&iter
, var_ft
->choice_name_to_index
);
5398 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5399 g_hash_table_insert(copy_ft
->choice_name_to_index
,
5403 g_array_set_size(copy_ft
->choices
, var_ft
->choices
->len
);
5405 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
5406 struct bt_ctf_field_type_common_variant_choice
*entry
, *copy_entry
;
5407 struct bt_ctf_field_type_common
*field_ft_copy
;
5410 entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
, i
);
5411 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
5413 BT_LOGD("Copying CTF writer variant field type's field: "
5414 "index=%" PRId64
", "
5415 "field-ft-addr=%p, field-name=\"%s\"",
5416 i
, entry
, g_quark_to_string(entry
->name
));
5418 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5419 (void *) entry
->type
);
5420 if (!field_ft_copy
) {
5421 BT_LOGE("Cannot copy CTF writer variant field type's field: "
5422 "index=%" PRId64
", "
5423 "field-ft-addr=%p, field-name=\"%s\"",
5424 i
, entry
, g_quark_to_string(entry
->name
));
5429 copy_entry
->name
= entry
->name
;
5430 copy_entry
->type
= field_ft_copy
;
5433 copy_entry
->ranges
= g_array_new(FALSE
, TRUE
,
5434 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
5435 BT_ASSERT(copy_entry
->ranges
);
5436 g_array_set_size(copy_entry
->ranges
, entry
->ranges
->len
);
5438 for (range_i
= 0; range_i
< entry
->ranges
->len
; range_i
++) {
5439 copy_entry
->ranges
[range_i
] = entry
->ranges
[range_i
];
5443 if (var_ft
->tag_field_path
) {
5444 BT_LOGD_STR("Copying CTF writer variant field type's tag field path.");
5445 copy_ft
->tag_field_path
= bt_ctf_field_path_copy(
5446 var_ft
->tag_field_path
);
5447 if (!copy_ft
->tag_field_path
) {
5448 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field path.");
5453 copy_ft
->choices_up_to_date
= var_ft
->choices_up_to_date
;
5454 BT_LOGD("Copied CTF writer variant field type: original-ft-addr=%p, copy-ft-addr=%p",
5458 bt_object_put_ref(tag_ft_copy
);
5459 return (void *) copy_ft
;
5462 bt_object_put_ref(tag_ft_copy
);
5463 BT_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5468 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
5469 struct bt_ctf_field_type
*ft
)
5471 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5472 struct bt_ctf_field_type_common_array
*array_ft
= (void *) ft
;
5473 struct bt_ctf_field_type_common_array
*copy_ft
= NULL
;
5475 BT_LOGD("Copying CTF writer array field type's: addr=%p", ft
);
5476 BT_LOGD_STR("Copying CTF writer array field type's element field type.");
5477 container_ft_copy
= bt_ctf_field_type_common_copy(array_ft
->element_ft
);
5478 if (!container_ft_copy
) {
5479 BT_LOGE_STR("Cannot copy CTF writer array field type's element field type.");
5483 copy_ft
= (void *) bt_ctf_field_type_array_create(
5484 (void *) container_ft_copy
, array_ft
->length
);
5486 BT_LOGE_STR("Cannot create CTF writer array field type.");
5490 BT_LOGD("Copied CTF writer array field type: original-ft-addr=%p, copy-ft-addr=%p",
5494 bt_object_put_ref(container_ft_copy
);
5495 return (void *) copy_ft
;
5499 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
5500 struct bt_ctf_field_type
*ft
)
5502 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5503 struct bt_ctf_field_type_common_sequence
*seq_ft
= (void *) ft
;
5504 struct bt_ctf_field_type_common_sequence
*copy_ft
= NULL
;
5506 BT_LOGD("Copying CTF writer sequence field type's: addr=%p", ft
);
5507 BT_LOGD_STR("Copying CTF writer sequence field type's element field type.");
5508 container_ft_copy
= bt_ctf_field_type_common_copy(seq_ft
->element_ft
);
5509 if (!container_ft_copy
) {
5510 BT_LOGE_STR("Cannot copy CTF writer sequence field type's element field type.");
5514 copy_ft
= (void *) bt_ctf_field_type_sequence_create(
5515 (void *) container_ft_copy
,
5516 seq_ft
->length_field_name
->len
?
5517 seq_ft
->length_field_name
->str
: NULL
);
5519 BT_LOGE_STR("Cannot create CTF writer sequence field type.");
5523 if (seq_ft
->length_field_path
) {
5524 BT_LOGD_STR("Copying CTF writer sequence field type's length field path.");
5525 copy_ft
->length_field_path
= bt_ctf_field_path_copy(
5526 seq_ft
->length_field_path
);
5527 if (!copy_ft
->length_field_path
) {
5528 BT_LOGE_STR("Cannot copy CTF writer sequence field type's length field path.");
5533 BT_LOGD("Copied CTF writer sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
5537 bt_object_put_ref(container_ft_copy
);
5538 return (void *) copy_ft
;
5540 bt_object_put_ref(container_ft_copy
);
5541 BT_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5546 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(struct bt_ctf_field_type
*ft
)
5548 struct bt_ctf_field_type_common_string
*string_ft
= (void *) ft
;
5549 struct bt_ctf_field_type_common_string
*copy_ft
= NULL
;
5551 BT_LOGD("Copying CTF writer string field type's: addr=%p", ft
);
5552 copy_ft
= (void *) bt_ctf_field_type_string_create();
5554 BT_LOGE_STR("Cannot create CTF writer string field type.");
5558 copy_ft
->encoding
= string_ft
->encoding
;
5559 BT_LOGD("Copied CTF writer string field type: original-ft-addr=%p, copy-ft-addr=%p",
5563 return (void *) copy_ft
;