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"
32 #include <babeltrace2-ctf-writer/fields.h>
33 #include <babeltrace2-ctf-writer/field-types.h>
34 #include <babeltrace2-ctf-writer/object.h>
35 #include <babeltrace2-ctf-writer/utils.h>
37 #include "common/assert.h"
38 #include "compat/compiler.h"
39 #include "compat/endian.h"
41 #include "assert-pre.h"
42 #include "clock-class.h"
44 #include "field-path.h"
46 #include "field-types.h"
51 void destroy_enumeration_mapping(struct bt_ctf_enumeration_mapping
*mapping
)
57 void bt_ctf_field_type_common_initialize(struct bt_ctf_field_type_common
*ft
,
58 bool init_bo
, bt_ctf_object_release_func release_func
,
59 struct bt_ctf_field_type_common_methods
*methods
)
61 BT_ASSERT(ft
&& (ft
->id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
) &&
62 (ft
->id
< BT_CTF_FIELD_TYPE_ID_NR
));
64 bt_ctf_object_init_shared(&ft
->base
, release_func
);
65 ft
->methods
= methods
;
69 const enum bt_ctf_byte_order bo
= BT_CTF_BYTE_ORDER_NATIVE
;
71 BT_LOGD("Setting initial field type's byte order: bo=%s",
72 bt_ctf_byte_order_string(bo
));
73 ret
= bt_ctf_field_type_common_set_byte_order(ft
, bo
);
81 void bt_ctf_field_type_common_integer_initialize(
82 struct bt_ctf_field_type_common
*ft
,
83 unsigned int size
, bt_ctf_object_release_func release_func
,
84 struct bt_ctf_field_type_common_methods
*methods
)
86 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
89 BT_LOGD("Initializing common integer field type object: size=%u",
91 ft
->id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
93 int_ft
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
94 int_ft
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
95 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
96 BT_LOGD("Initialized common integer field type object: addr=%p, size=%u",
101 void bt_ctf_field_type_common_floating_point_initialize(
102 struct bt_ctf_field_type_common
*ft
,
103 bt_ctf_object_release_func release_func
,
104 struct bt_ctf_field_type_common_methods
*methods
)
106 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
108 BT_LOGD_STR("Initializing common floating point number field type object.");
109 ft
->id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
110 flt_ft
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
111 flt_ft
->mant_dig
= FLT_MANT_DIG
;
112 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
113 BT_LOGD("Initialized common floating point number field type object: addr=%p, "
114 "exp-size=%u, mant-size=%u", ft
, flt_ft
->exp_dig
,
119 void bt_ctf_field_type_common_enumeration_initialize(
120 struct bt_ctf_field_type_common
*ft
,
121 struct bt_ctf_field_type_common
*container_ft
,
122 bt_ctf_object_release_func release_func
,
123 struct bt_ctf_field_type_common_methods
*methods
)
125 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
127 BT_ASSERT(container_ft
);
128 BT_LOGD("Initializing common enumeration field type object: int-ft-addr=%p",
130 ft
->id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
131 enum_ft
->container_ft
= bt_ctf_object_get_ref(container_ft
);
132 enum_ft
->entries
= g_ptr_array_new_with_free_func(
133 (GDestroyNotify
) destroy_enumeration_mapping
);
134 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
135 BT_LOGD("Initialized common enumeration field type object: addr=%p, "
136 "int-ft-addr=%p, int-ft-size=%u", ft
, container_ft
,
137 bt_ctf_field_type_common_integer_get_size(container_ft
));
141 void bt_ctf_field_type_common_string_initialize(
142 struct bt_ctf_field_type_common
*ft
,
143 bt_ctf_object_release_func release_func
,
144 struct bt_ctf_field_type_common_methods
*methods
)
146 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
148 BT_LOGD_STR("Initializing common string field type object.");
149 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRING
;
150 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
151 string_ft
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
152 ft
->alignment
= CHAR_BIT
;
153 BT_LOGD("Initialized common string field type object: addr=%p", ft
);
157 void bt_ctf_field_type_common_structure_initialize(
158 struct bt_ctf_field_type_common
*ft
,
159 bt_ctf_object_release_func release_func
,
160 struct bt_ctf_field_type_common_methods
*methods
)
162 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
164 BT_LOGD_STR("Initializing common structure field type object.");
165 ft
->id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
166 struct_ft
->fields
= g_array_new(FALSE
, TRUE
,
167 sizeof(struct bt_ctf_field_type_common_structure_field
));
168 struct_ft
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
169 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
170 BT_LOGD("Initialized common structure field type object: addr=%p", ft
);
174 void bt_ctf_field_type_common_array_initialize(
175 struct bt_ctf_field_type_common
*ft
,
176 struct bt_ctf_field_type_common
*element_ft
,
177 unsigned int length
, bt_ctf_object_release_func release_func
,
178 struct bt_ctf_field_type_common_methods
*methods
)
180 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
182 BT_ASSERT(element_ft
);
183 BT_LOGD("Initializing common array field type object: element-ft-addr=%p, "
184 "length=%u", element_ft
, length
);
185 ft
->id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
186 array_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
187 array_ft
->length
= length
;
188 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
189 BT_LOGD("Initialized common array field type object: addr=%p, "
190 "element-ft-addr=%p, length=%u", ft
, element_ft
, length
);
194 void bt_ctf_field_type_common_sequence_initialize(
195 struct bt_ctf_field_type_common
*ft
,
196 struct bt_ctf_field_type_common
*element_ft
,
197 const char *length_field_name
,
198 bt_ctf_object_release_func release_func
,
199 struct bt_ctf_field_type_common_methods
*methods
)
201 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
203 BT_ASSERT(element_ft
);
204 BT_ASSERT(length_field_name
);
205 BT_ASSERT(bt_ctf_identifier_is_valid(length_field_name
));
206 BT_LOGD("Initializing common sequence field type object: element-ft-addr=%p, "
207 "length-field-name=\"%s\"", element_ft
, length_field_name
);
208 ft
->id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
209 seq_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
210 seq_ft
->length_field_name
= g_string_new(length_field_name
);
211 bt_ctf_field_type_common_initialize(ft
, false, release_func
, methods
);
212 BT_LOGD("Initialized common sequence field type object: addr=%p, "
213 "element-ft-addr=%p, length-field-name=\"%s\"",
214 ft
, element_ft
, length_field_name
);
218 void bt_ctf_field_type_common_variant_initialize(
219 struct bt_ctf_field_type_common
*ft
,
220 struct bt_ctf_field_type_common
*tag_ft
,
221 const char *tag_name
,
222 bt_ctf_object_release_func release_func
,
223 struct bt_ctf_field_type_common_methods
*methods
)
225 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
227 BT_ASSERT(!tag_name
|| bt_ctf_identifier_is_valid(tag_name
));
228 BT_LOGD("Initializing common variant field type object: "
229 "tag-ft-addr=%p, tag-field-name=\"%s\"",
231 ft
->id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
232 var_ft
->tag_name
= g_string_new(tag_name
);
233 var_ft
->choice_name_to_index
= g_hash_table_new(NULL
, NULL
);
234 var_ft
->choices
= g_array_new(FALSE
, TRUE
,
235 sizeof(struct bt_ctf_field_type_common_variant_choice
));
238 var_ft
->tag_ft
= bt_ctf_object_get_ref(tag_ft
);
241 bt_ctf_field_type_common_initialize(ft
, true, release_func
, methods
);
242 /* A variant's alignment is undefined */
244 BT_LOGD("Initialized common variant field type object: addr=%p, "
245 "tag-ft-addr=%p, tag-field-name=\"%s\"",
246 ft
, tag_ft
, tag_name
);
250 void bt_ctf_field_type_common_integer_destroy(struct bt_ctf_object
*obj
)
252 struct bt_ctf_field_type_common_integer
*ft
= (void *) obj
;
258 BT_LOGD("Destroying integer field type object: addr=%p", ft
);
259 BT_LOGD_STR("Putting mapped clock class.");
260 bt_ctf_object_put_ref(ft
->mapped_clock_class
);
265 void bt_ctf_field_type_common_floating_point_destroy(struct bt_ctf_object
*obj
)
267 struct bt_ctf_field_type_common_floating_point
*ft
= (void *) obj
;
273 BT_LOGD("Destroying floating point number field type object: addr=%p", ft
);
278 void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_ctf_object
*obj
)
280 struct bt_ctf_field_type_common_enumeration
*ft
= (void *) obj
;
286 BT_LOGD("Destroying enumeration field type object: addr=%p", ft
);
287 g_ptr_array_free(ft
->entries
, TRUE
);
288 BT_LOGD_STR("Putting container field type.");
289 bt_ctf_object_put_ref(ft
->container_ft
);
294 void bt_ctf_field_type_common_string_destroy(struct bt_ctf_object
*obj
)
296 struct bt_ctf_field_type_common_string
*ft
= (void *) obj
;
302 BT_LOGD("Destroying string field type object: addr=%p", ft
);
307 void bt_ctf_field_type_common_structure_field_finalize(
308 struct bt_ctf_field_type_common_structure_field
*field
)
314 BT_LOGD("Finalizing structure field type's field: "
315 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
316 field
, field
->type
, g_quark_to_string(field
->name
));
317 BT_LOGD_STR("Putting field type.");
318 bt_ctf_object_put_ref(field
->type
);
322 void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_ctf_object
*obj
)
324 struct bt_ctf_field_type_common_structure
*ft
= (void *) obj
;
331 BT_LOGD("Destroying structure field type object: addr=%p", ft
);
334 for (i
= 0; i
< ft
->fields
->len
; i
++) {
335 bt_ctf_field_type_common_structure_field_finalize(
336 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
340 g_array_free(ft
->fields
, TRUE
);
343 if (ft
->field_name_to_index
) {
344 g_hash_table_destroy(ft
->field_name_to_index
);
351 void bt_ctf_field_type_common_array_destroy_recursive(struct bt_ctf_object
*obj
)
353 struct bt_ctf_field_type_common_array
*ft
= (void *) obj
;
359 BT_LOGD("Destroying array field type object: addr=%p", ft
);
360 BT_LOGD_STR("Putting element field type.");
361 bt_ctf_object_put_ref(ft
->element_ft
);
366 void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_ctf_object
*obj
)
368 struct bt_ctf_field_type_common_sequence
*ft
= (void *) obj
;
374 BT_LOGD("Destroying sequence field type object: addr=%p", ft
);
375 BT_LOGD_STR("Putting element field type.");
376 bt_ctf_object_put_ref(ft
->element_ft
);
377 g_string_free(ft
->length_field_name
, TRUE
);
378 BT_LOGD_STR("Putting length field path.");
379 bt_ctf_object_put_ref(ft
->length_field_path
);
384 void bt_ctf_field_type_common_variant_choice_finalize(
385 struct bt_ctf_field_type_common_variant_choice
*choice
)
391 BT_LOGD("Finalizing variant field type's choice: "
392 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
393 choice
, choice
->type
, g_quark_to_string(choice
->name
));
394 BT_LOGD_STR("Putting field type.");
395 bt_ctf_object_put_ref(choice
->type
);
397 if (choice
->ranges
) {
398 g_array_free(choice
->ranges
, TRUE
);
403 void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_ctf_object
*obj
)
405 struct bt_ctf_field_type_common_variant
*ft
= (void *) obj
;
412 BT_LOGD("Destroying variant field type object: addr=%p", ft
);
415 for (i
= 0; i
< ft
->choices
->len
; i
++) {
416 bt_ctf_field_type_common_variant_choice_finalize(
417 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
421 g_array_free(ft
->choices
, TRUE
);
424 if (ft
->choice_name_to_index
) {
425 g_hash_table_destroy(ft
->choice_name_to_index
);
429 g_string_free(ft
->tag_name
, TRUE
);
432 BT_LOGD_STR("Putting tag field type.");
433 bt_ctf_object_put_ref(ft
->tag_ft
);
434 BT_LOGD_STR("Putting tag field path.");
435 bt_ctf_object_put_ref(ft
->tag_field_path
);
439 struct range_overlap_query
{
454 void check_ranges_overlap(gpointer element
, gpointer query
)
456 struct bt_ctf_enumeration_mapping
*mapping
= element
;
457 struct range_overlap_query
*overlap_query
= query
;
459 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
460 && overlap_query
->range_start
._signed
<=
461 mapping
->range_end
._signed
) {
462 overlap_query
->overlaps
= 1;
463 overlap_query
->mapping_name
= mapping
->string
;
466 overlap_query
->overlaps
|=
467 mapping
->string
== overlap_query
->mapping_name
;
469 if (overlap_query
->overlaps
) {
470 BT_LOGT("Overlapping enumeration field type mappings: "
471 "mapping-name=\"%s\", "
472 "mapping-a-range-start=%" PRId64
", "
473 "mapping-a-range-end=%" PRId64
", "
474 "mapping-b-range-start=%" PRId64
", "
475 "mapping-b-range-end=%" PRId64
,
476 g_quark_to_string(mapping
->string
),
477 mapping
->range_start
._signed
,
478 mapping
->range_end
._signed
,
479 overlap_query
->range_start
._signed
,
480 overlap_query
->range_end
._signed
);
485 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
487 struct bt_ctf_enumeration_mapping
*mapping
= element
;
488 struct range_overlap_query
*overlap_query
= query
;
490 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
491 && overlap_query
->range_start
._unsigned
<=
492 mapping
->range_end
._unsigned
) {
493 overlap_query
->overlaps
= 1;
494 overlap_query
->mapping_name
= mapping
->string
;
497 overlap_query
->overlaps
|=
498 mapping
->string
== overlap_query
->mapping_name
;
500 if (overlap_query
->overlaps
) {
501 BT_LOGW("Overlapping enumeration field type mappings: "
502 "mapping-name=\"%s\", "
503 "mapping-a-range-start=%" PRIu64
", "
504 "mapping-a-range-end=%" PRIu64
", "
505 "mapping-b-range-start=%" PRIu64
", "
506 "mapping-b-range-end=%" PRIu64
,
507 g_quark_to_string(mapping
->string
),
508 mapping
->range_start
._unsigned
,
509 mapping
->range_end
._unsigned
,
510 overlap_query
->range_start
._unsigned
,
511 overlap_query
->range_end
._unsigned
);
516 gint
compare_enumeration_mappings_signed(struct bt_ctf_enumeration_mapping
**a
,
517 struct bt_ctf_enumeration_mapping
**b
)
519 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
523 gint
compare_enumeration_mappings_unsigned(struct bt_ctf_enumeration_mapping
**a
,
524 struct bt_ctf_enumeration_mapping
**b
)
526 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
530 int add_structure_variant_member(GArray
*members
,
531 GHashTable
*field_name_to_index
,
532 struct bt_ctf_field_type_common
*field_type
, const char *field_name
,
536 GQuark name_quark
= g_quark_from_string(field_name
);
537 struct bt_ctf_field_type_common
**member_ft
;
540 /* Make sure structure does not contain a field of the same name */
541 if (g_hash_table_lookup_extended(field_name_to_index
,
542 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
543 BT_LOGW("Structure or variant field type already contains a field type with this name: "
544 "field-name=\"%s\"", field_name
);
549 g_array_set_size(members
, members
->len
+ 1);
552 struct bt_ctf_field_type_common_variant_choice
*choice
=
553 &g_array_index(members
,
554 struct bt_ctf_field_type_common_variant_choice
,
557 member_ft
= &choice
->type
;
558 member_name
= &choice
->name
;
559 BT_ASSERT(!choice
->ranges
);
560 choice
->ranges
= g_array_new(FALSE
, TRUE
,
561 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
562 BT_ASSERT(choice
->ranges
);
564 struct bt_ctf_field_type_common_structure_field
*field
=
565 &g_array_index(members
,
566 struct bt_ctf_field_type_common_structure_field
,
569 member_ft
= &field
->type
;
570 member_name
= &field
->name
;
573 *member_name
= name_quark
;
574 *member_ft
= bt_ctf_object_get_ref(field_type
);
575 g_hash_table_insert(field_name_to_index
,
576 GUINT_TO_POINTER(name_quark
),
577 GUINT_TO_POINTER(members
->len
- 1));
578 BT_LOGT("Added structure/variant field type member: member-ft-addr=%p, "
579 "member-name=\"%s\"", field_type
, field_name
);
586 int bt_ctf_field_type_common_integer_validate(struct bt_ctf_field_type_common
*ft
)
589 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
591 if (int_ft
->mapped_clock_class
&& int_ft
->is_signed
) {
592 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
593 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
594 ft
, int_ft
->mapped_clock_class
,
595 bt_ctf_clock_class_get_name(int_ft
->mapped_clock_class
));
605 void bt_ctf_field_type_enum_iter_destroy(struct bt_ctf_object
*obj
)
607 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
609 struct bt_ctf_field_type_enumeration_mapping_iterator
,
612 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
614 BT_LOGD_STR("Putting parent enumeration field type.");
615 bt_ctf_object_put_ref(iter
->enumeration_ft
);
620 struct bt_ctf_field_type_enumeration_mapping_iterator
*
621 bt_ctf_field_type_common_enumeration_find_mappings_type(
622 struct bt_ctf_field_type_common
*ft
,
623 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
625 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
627 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
628 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
,
630 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
632 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
636 bt_ctf_object_init_shared(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
637 iter
->enumeration_ft
= bt_ctf_object_get_ref(ft
);
639 iter
->type
= iterator_type
;
646 struct bt_ctf_field_type_enumeration_mapping_iterator
*
647 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
648 struct bt_ctf_field_type_common
*ft
, const char *name
)
650 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
652 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
653 ft
, CTF_ITERATOR_BY_NAME
);
655 BT_LOGW("Cannot create enumeration field type mapping iterator: "
656 "ft-addr=%p, mapping-name=\"%s\"", ft
, name
);
660 iter
->u
.name_quark
= g_quark_try_string(name
);
661 if (!iter
->u
.name_quark
) {
663 * No results are possible, set the iterator's position at the
666 iter
->index
= iter
->enumeration_ft
->entries
->len
;
672 bt_ctf_object_put_ref(iter
);
677 struct bt_ctf_enumeration_mapping
*bt_ctf_field_type_common_enumeration_get_mapping_by_index(
678 struct bt_ctf_field_type_common
*ft
, uint64_t index
)
680 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
681 struct bt_ctf_enumeration_mapping
*mapping
= NULL
;
683 if (index
>= enum_ft
->entries
->len
) {
684 BT_LOGW("Invalid parameter: index is out of bounds: "
685 "addr=%p, index=%" PRIu64
", count=%u",
686 ft
, index
, enum_ft
->entries
->len
);
690 mapping
= g_ptr_array_index(enum_ft
->entries
, index
);
697 int bt_ctf_field_type_enumeration_mapping_iterator_next(
698 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
700 struct bt_ctf_field_type_common_enumeration
*enum_ft
= iter
->enumeration_ft
;
703 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
704 len
= enum_ft
->entries
->len
;
705 for (i
= iter
->index
+ 1; i
< len
; i
++) {
706 struct bt_ctf_enumeration_mapping
*mapping
=
707 bt_ctf_field_type_common_enumeration_get_mapping_by_index(
708 BT_CTF_TO_COMMON(enum_ft
), i
);
710 switch (iter
->type
) {
711 case CTF_ITERATOR_BY_NAME
:
712 if (mapping
->string
== iter
->u
.name_quark
) {
717 case CTF_ITERATOR_BY_SIGNED_VALUE
:
719 int64_t value
= iter
->u
.signed_value
;
721 if (value
>= mapping
->range_start
._signed
&&
722 value
<= mapping
->range_end
._signed
) {
728 case CTF_ITERATOR_BY_UNSIGNED_VALUE
:
730 uint64_t value
= iter
->u
.unsigned_value
;
732 if (value
>= mapping
->range_start
._unsigned
&&
733 value
<= mapping
->range_end
._unsigned
) {
740 BT_LOGF("Invalid enumeration field type mapping iterator type: "
741 "type=%d", iter
->type
);
753 struct bt_ctf_field_type_enumeration_mapping_iterator
*
754 bt_ctf_field_type_common_enumeration_signed_find_mappings_by_value(
755 struct bt_ctf_field_type_common
*ft
, int64_t value
)
757 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
759 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
760 ft
, CTF_ITERATOR_BY_SIGNED_VALUE
);
762 BT_LOGW("Cannot create enumeration field type mapping iterator: "
763 "ft-addr=%p, value=%" PRId64
, ft
, value
);
767 if (bt_ctf_field_type_common_integer_is_signed(
768 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 1) {
769 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
770 "enum-ft-addr=%p, int-ft-addr=%p",
771 ft
, iter
->enumeration_ft
->container_ft
);
775 iter
->u
.signed_value
= value
;
779 bt_ctf_object_put_ref(iter
);
784 struct bt_ctf_field_type_enumeration_mapping_iterator
*
785 bt_ctf_field_type_common_enumeration_unsigned_find_mappings_by_value(
786 struct bt_ctf_field_type_common
*ft
, uint64_t value
)
788 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
790 iter
= bt_ctf_field_type_common_enumeration_find_mappings_type(
791 ft
, CTF_ITERATOR_BY_UNSIGNED_VALUE
);
793 BT_LOGW("Cannot create enumeration field type mapping iterator: "
794 "ft-addr=%p, value=%" PRIu64
, ft
, value
);
798 if (bt_ctf_field_type_common_integer_is_signed(
799 BT_CTF_TO_COMMON(iter
->enumeration_ft
->container_ft
)) != 0) {
800 BT_LOGW("Invalid parameter: enumeration field type is signed: "
801 "enum-ft-addr=%p, int-ft-addr=%p",
802 ft
, iter
->enumeration_ft
->container_ft
);
806 iter
->u
.unsigned_value
= value
;
810 bt_ctf_object_put_ref(iter
);
815 int bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
816 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
817 const char **mapping_name
, int64_t *range_begin
,
820 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
821 BT_CTF_ASSERT_PRE(iter
->index
!= -1,
822 "Invalid enumeration field type mapping iterator access: "
823 "addr=%p, position=-1", iter
);
824 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
825 (void *) iter
->enumeration_ft
, iter
->index
,
826 mapping_name
, range_begin
, range_end
);
830 int bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
831 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
832 const char **mapping_name
, uint64_t *range_begin
,
835 BT_CTF_ASSERT_PRE_NON_NULL(iter
, "Enumeration field type mapping iterator");
836 BT_CTF_ASSERT_PRE(iter
->index
!= -1,
837 "Invalid enumeration field type mapping iterator access: "
838 "addr=%p, position=-1", iter
);
839 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
840 (void *) iter
->enumeration_ft
, iter
->index
,
841 mapping_name
, range_begin
, range_end
);
845 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
846 * Only used when freezing an enumeration.
849 void bt_ctf_field_type_common_enumeration_set_range_overlap(
850 struct bt_ctf_field_type_common_enumeration
*ft
)
855 BT_LOGT("Setting enumeration field type's overlap flag: addr=%p",
857 len
= ft
->entries
->len
;
858 is_signed
= bt_ctf_field_type_common_integer_is_signed(
859 BT_CTF_TO_COMMON(ft
->container_ft
));
861 for (i
= 0; i
< len
; i
++) {
862 for (j
= i
+ 1; j
< len
; j
++) {
863 struct bt_ctf_enumeration_mapping
*mapping
[2];
865 mapping
[0] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
866 BT_CTF_TO_COMMON(ft
), i
);
867 mapping
[1] = bt_ctf_field_type_common_enumeration_get_mapping_by_index(
868 BT_CTF_TO_COMMON(ft
), j
);
870 if (mapping
[0]->range_start
._signed
871 <= mapping
[1]->range_end
._signed
872 && mapping
[0]->range_end
._signed
873 >= mapping
[1]->range_start
._signed
) {
874 ft
->has_overlapping_ranges
= BT_CTF_TRUE
;
878 if (mapping
[0]->range_start
._unsigned
879 <= mapping
[1]->range_end
._unsigned
880 && mapping
[0]->range_end
._unsigned
881 >= mapping
[1]->range_start
._unsigned
) {
882 ft
->has_overlapping_ranges
= BT_CTF_TRUE
;
890 if (ft
->has_overlapping_ranges
) {
891 BT_LOGT_STR("Enumeration field type has overlapping ranges.");
893 BT_LOGT_STR("Enumeration field type has no overlapping ranges.");
898 int bt_ctf_field_type_common_enumeration_validate_recursive(
899 struct bt_ctf_field_type_common
*ft
)
902 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
904 ret
= bt_ctf_field_type_common_integer_validate(
905 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
907 BT_LOGW("Invalid enumeration field type: container type is invalid: "
908 "enum-ft-addr=%p, int-ft-addr=%p",
909 ft
, enum_ft
->container_ft
);
913 /* Ensure enum has entries */
914 if (enum_ft
->entries
->len
== 0) {
915 BT_LOGW("Invalid enumeration field type: no entries: "
926 int bt_ctf_field_type_common_sequence_validate_recursive(
927 struct bt_ctf_field_type_common
*ft
)
930 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
932 /* Length field name should be set at this point */
933 if (seq_ft
->length_field_name
->len
== 0) {
934 BT_LOGW("Invalid sequence field type: no length field name: "
940 ret
= bt_ctf_field_type_common_validate(seq_ft
->element_ft
);
942 BT_LOGW("Invalid sequence field type: invalid element field type: "
943 "seq-ft-addr=%p, element-ft-add=%p",
944 ft
, seq_ft
->element_ft
);
952 int bt_ctf_field_type_common_array_validate_recursive(
953 struct bt_ctf_field_type_common
*ft
)
956 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
958 ret
= bt_ctf_field_type_common_validate(array_ft
->element_ft
);
960 BT_LOGW("Invalid array field type: invalid element field type: "
961 "array-ft-addr=%p, element-ft-add=%p",
962 ft
, array_ft
->element_ft
);
969 int bt_ctf_field_type_common_structure_validate_recursive(
970 struct bt_ctf_field_type_common
*ft
)
973 struct bt_ctf_field_type_common
*child_ft
= NULL
;
974 int64_t field_count
=
975 bt_ctf_field_type_common_structure_get_field_count(ft
);
978 BT_ASSERT(field_count
>= 0);
980 for (i
= 0; i
< field_count
; ++i
) {
981 const char *field_name
;
983 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(ft
,
984 &field_name
, &child_ft
, i
);
986 ret
= bt_ctf_field_type_common_validate(child_ft
);
988 BT_LOGW("Invalid structure field type: "
989 "a contained field type is invalid: "
990 "struct-ft-addr=%p, field-ft-addr=%p, "
991 "field-name=\"%s\", field-index=%" PRId64
,
992 ft
, child_ft
, field_name
, i
);
1002 bt_ctf_bool
bt_ctf_field_type_common_enumeration_has_overlapping_ranges(
1003 struct bt_ctf_field_type_common_enumeration
*enum_ft
)
1005 if (!enum_ft
->common
.frozen
) {
1006 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
1009 return enum_ft
->has_overlapping_ranges
;
1013 int bt_ctf_field_type_common_variant_validate_recursive(
1014 struct bt_ctf_field_type_common
*ft
)
1017 int64_t field_count
;
1018 struct bt_ctf_field_type_common
*child_ft
= NULL
;
1019 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1022 if (var_ft
->tag_name
->len
== 0) {
1023 BT_LOGW("Invalid variant field type: no tag field name: "
1029 if (!var_ft
->tag_ft
) {
1030 BT_LOGW("Invalid variant field type: no tag field type: "
1031 "addr=%p, tag-field-name=\"%s\"", var_ft
,
1032 var_ft
->tag_name
->str
);
1037 if (bt_ctf_field_type_common_enumeration_has_overlapping_ranges(var_ft
->tag_ft
)) {
1038 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
1039 "variant-ft-addr=%p, tag-field-name=\"%s\", "
1040 "enum-ft-addr=%p", ft
, var_ft
->tag_name
->str
,
1047 * It is valid to have a variant field type which does not have
1048 * the fields corresponding to each label in the associated
1051 * It is also valid to have variant field type fields which
1052 * cannot be selected because the variant field type tag has no
1053 * mapping named as such. This scenario, while not ideal, cannot
1056 * If a non-existing field happens to be selected by an
1057 * enumeration while reading a variant field, an error will be
1058 * generated at that point (while reading the stream).
1060 field_count
= bt_ctf_field_type_common_variant_get_field_count(ft
);
1061 if (field_count
< 0) {
1062 BT_LOGW("Invalid variant field type: no fields: "
1063 "addr=%p, tag-field-name=\"%s\"",
1064 ft
, var_ft
->tag_name
->str
);
1069 for (i
= 0; i
< field_count
; ++i
) {
1070 const char *field_name
;
1072 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(ft
,
1073 &field_name
, &child_ft
, i
);
1074 BT_ASSERT(ret
== 0);
1075 ret
= bt_ctf_field_type_common_validate(child_ft
);
1077 BT_LOGW("Invalid variant field type: "
1078 "a contained field type is invalid: "
1079 "variant-ft-addr=%p, tag-field-name=\"%s\", "
1080 "field-ft-addr=%p, field-name=\"%s\", "
1081 "field-index=%" PRId64
,
1082 ft
, var_ft
->tag_name
->str
, child_ft
,
1093 * This function validates a given field type without considering
1094 * where this field type is located. It only validates the properties
1095 * of the given field type and the properties of its children if
1099 int bt_ctf_field_type_common_validate(struct bt_ctf_field_type_common
*ft
)
1106 /* Already marked as valid */
1110 if (ft
->methods
->validate
) {
1111 ret
= ft
->methods
->validate(ft
);
1114 if (ret
== 0 && ft
->frozen
) {
1115 /* Field type is valid */
1116 BT_LOGT("Marking field type as valid: addr=%p", ft
);
1125 int bt_ctf_field_type_common_integer_get_size(struct bt_ctf_field_type_common
*ft
)
1127 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1129 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1130 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1132 return (int) int_ft
->size
;
1136 bt_ctf_bool
bt_ctf_field_type_common_integer_is_signed(struct bt_ctf_field_type_common
*ft
)
1138 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1140 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1141 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1143 return int_ft
->is_signed
;
1147 int bt_ctf_field_type_common_integer_set_is_signed(struct bt_ctf_field_type_common
*ft
,
1148 bt_ctf_bool is_signed
)
1151 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1154 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1160 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1166 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1167 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1168 "addr=%p, ft-id=%s", ft
,
1169 bt_ctf_field_type_id_string(ft
->id
));
1174 int_ft
->is_signed
= !!is_signed
;
1175 BT_LOGT("Set integer field type's signedness: addr=%p, is-signed=%d",
1183 int bt_ctf_field_type_common_integer_set_size(struct bt_ctf_field_type_common
*ft
,
1187 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1190 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1196 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1202 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1203 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1204 "addr=%p, ft-id=%s", ft
,
1205 bt_ctf_field_type_id_string(ft
->id
));
1210 if (size
== 0 || size
> 64) {
1211 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
1212 "addr=%p, size=%u", ft
, size
);
1217 int_ft
->size
= size
;
1218 BT_LOGT("Set integer field type's size: addr=%p, size=%u",
1226 enum bt_ctf_integer_base
bt_ctf_field_type_common_integer_get_base(
1227 struct bt_ctf_field_type_common
*ft
)
1229 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1231 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1232 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1234 return int_ft
->base
;
1238 int bt_ctf_field_type_common_integer_set_base(struct bt_ctf_field_type_common
*ft
,
1239 enum bt_ctf_integer_base base
)
1242 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1245 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1251 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1257 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1258 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1259 "addr=%p, ft-id=%s", ft
,
1260 bt_ctf_field_type_id_string(ft
->id
));
1266 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
1267 case BT_CTF_INTEGER_BASE_BINARY
:
1268 case BT_CTF_INTEGER_BASE_OCTAL
:
1269 case BT_CTF_INTEGER_BASE_DECIMAL
:
1270 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1272 int_ft
->base
= base
;
1276 BT_LOGW("Invalid parameter: unknown integer field type base: "
1277 "addr=%p, base=%d", ft
, base
);
1281 BT_LOGT("Set integer field type's base: addr=%p, base=%s",
1282 ft
, bt_ctf_integer_base_string(base
));
1289 enum bt_ctf_string_encoding
bt_ctf_field_type_common_integer_get_encoding(
1290 struct bt_ctf_field_type_common
*ft
)
1292 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1294 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1295 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1297 return int_ft
->encoding
;
1301 int bt_ctf_field_type_common_integer_set_encoding(struct bt_ctf_field_type_common
*ft
,
1302 enum bt_ctf_string_encoding encoding
)
1305 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1308 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1314 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1320 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1321 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1322 "addr=%p, ft-id=%s", ft
,
1323 bt_ctf_field_type_id_string(ft
->id
));
1328 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
1329 encoding
!= BT_CTF_STRING_ENCODING_ASCII
&&
1330 encoding
!= BT_CTF_STRING_ENCODING_NONE
) {
1331 BT_LOGW("Invalid parameter: unknown string encoding: "
1332 "addr=%p, encoding=%d", ft
, encoding
);
1337 int_ft
->encoding
= encoding
;
1338 BT_LOGT("Set integer field type's encoding: addr=%p, encoding=%s",
1339 ft
, bt_ctf_string_encoding_string(encoding
));
1346 struct bt_ctf_clock_class
*bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
1347 struct bt_ctf_field_type_common
*ft
)
1349 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1351 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1352 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_INTEGER
,
1354 return int_ft
->mapped_clock_class
;
1358 int bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1359 struct bt_ctf_field_type_common
*ft
,
1360 struct bt_ctf_clock_class
*clock_class
)
1362 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
1366 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1371 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1372 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1373 "addr=%p, ft-id=%s", ft
,
1374 bt_ctf_field_type_id_string(ft
->id
));
1378 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1379 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1380 "clock-class-addr=%p, clock-class-name=\"%s\"",
1382 bt_ctf_clock_class_get_name(clock_class
));
1387 bt_ctf_object_put_ref(int_ft
->mapped_clock_class
);
1388 int_ft
->mapped_clock_class
= bt_ctf_object_get_ref(clock_class
);
1389 BT_LOGT("Set integer field type's mapped clock class: ft-addr=%p, "
1390 "clock-class-addr=%p, clock-class-name=\"%s\"",
1391 ft
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1398 int bt_ctf_field_type_common_integer_set_mapped_clock_class(
1399 struct bt_ctf_field_type_common
*ft
,
1400 struct bt_ctf_clock_class
*clock_class
)
1405 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1411 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1417 ret
= bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
1425 int bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
1426 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1427 const char **mapping_name
, int64_t *range_begin
,
1431 struct bt_ctf_enumeration_mapping
*mapping
;
1433 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1434 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
,
1435 BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1436 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(ft
,
1439 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() logs errors */
1445 *mapping_name
= g_quark_to_string(mapping
->string
);
1446 BT_ASSERT(*mapping_name
);
1450 *range_begin
= mapping
->range_start
._signed
;
1454 *range_end
= mapping
->range_end
._signed
;
1462 int bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
1463 struct bt_ctf_field_type_common
*ft
, uint64_t index
,
1464 const char **mapping_name
, uint64_t *range_begin
,
1465 uint64_t *range_end
)
1468 struct bt_ctf_enumeration_mapping
*mapping
;
1470 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1471 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1472 mapping
= bt_ctf_field_type_common_enumeration_get_mapping_by_index(
1475 /* bt_ctf_field_type_common_enumeration_get_mapping_by_index() reports any error */
1481 *mapping_name
= g_quark_to_string(mapping
->string
);
1482 BT_ASSERT(*mapping_name
);
1486 *range_begin
= mapping
->range_start
._unsigned
;
1490 *range_end
= mapping
->range_end
._unsigned
;
1498 struct bt_ctf_field_type_common
*
1499 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
1500 struct bt_ctf_field_type_common
*ft
)
1502 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1504 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1505 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1506 return BT_CTF_TO_COMMON(enum_ft
->container_ft
);
1510 int bt_ctf_field_type_common_enumeration_signed_add_mapping(
1511 struct bt_ctf_field_type_common
*ft
, const char *string
,
1512 int64_t range_start
, int64_t range_end
)
1515 GQuark mapping_name
;
1516 struct bt_ctf_enumeration_mapping
*mapping
;
1517 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1518 char *escaped_string
;
1521 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1527 BT_LOGW_STR("Invalid parameter: string is NULL.");
1533 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1539 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1540 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1541 "addr=%p, ft-id=%s", ft
,
1542 bt_ctf_field_type_id_string(ft
->id
));
1547 if (range_end
< range_start
) {
1548 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1549 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1550 ft
, range_start
, range_end
);
1555 if (strlen(string
) == 0) {
1556 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1557 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1563 escaped_string
= g_strescape(string
, NULL
);
1564 if (!escaped_string
) {
1565 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1566 "mapping-name-addr=%p, mapping-name=\"%s\"",
1567 ft
, string
, string
);
1572 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1574 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1578 mapping_name
= g_quark_from_string(escaped_string
);
1579 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1580 .range_start
._signed
= range_start
,
1581 .range_end
._signed
= range_end
,
1582 .string
= mapping_name
,
1584 g_ptr_array_add(enum_ft
->entries
, mapping
);
1585 g_ptr_array_sort(enum_ft
->entries
,
1586 (GCompareFunc
) compare_enumeration_mappings_signed
);
1587 BT_LOGT("Added mapping to signed enumeration field type: addr=%p, "
1588 "name=\"%s\", range-start=%" PRId64
", "
1589 "range-end=%" PRId64
,
1590 ft
, string
, range_start
, range_end
);
1593 free(escaped_string
);
1600 int bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
1601 struct bt_ctf_field_type_common
*ft
, const char *string
,
1602 uint64_t range_start
, uint64_t range_end
)
1605 GQuark mapping_name
;
1606 struct bt_ctf_enumeration_mapping
*mapping
;
1607 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1608 char *escaped_string
;
1611 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1617 BT_LOGW_STR("Invalid parameter: string is NULL.");
1623 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1629 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1630 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1631 "addr=%p, ft-id=%s", ft
,
1632 bt_ctf_field_type_id_string(ft
->id
));
1637 if (range_end
< range_start
) {
1638 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1639 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1640 ft
, range_start
, range_end
);
1645 if (strlen(string
) == 0) {
1646 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1647 "enum-ft-addr=%p, mapping-name-addr=%p", ft
,
1653 escaped_string
= g_strescape(string
, NULL
);
1654 if (!escaped_string
) {
1655 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1656 "mapping-name-addr=%p, mapping-name=\"%s\"",
1657 ft
, string
, string
);
1662 mapping
= g_new(struct bt_ctf_enumeration_mapping
, 1);
1664 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1668 mapping_name
= g_quark_from_string(escaped_string
);
1669 *mapping
= (struct bt_ctf_enumeration_mapping
) {
1670 .range_start
._unsigned
= range_start
,
1671 .range_end
._unsigned
= range_end
,
1672 .string
= mapping_name
,
1674 g_ptr_array_add(enum_ft
->entries
, mapping
);
1675 g_ptr_array_sort(enum_ft
->entries
,
1676 (GCompareFunc
) compare_enumeration_mappings_unsigned
);
1677 BT_LOGT("Added mapping to unsigned enumeration field type: addr=%p, "
1678 "name=\"%s\", range-start=%" PRIu64
", "
1679 "range-end=%" PRIu64
,
1680 ft
, string
, range_start
, range_end
);
1683 free(escaped_string
);
1690 int64_t bt_ctf_field_type_common_enumeration_get_mapping_count(
1691 struct bt_ctf_field_type_common
*ft
)
1693 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
1695 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1696 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ENUM
, "Field type");
1697 return (int64_t) enum_ft
->entries
->len
;
1701 int bt_ctf_field_type_common_floating_point_get_exponent_digits(
1702 struct bt_ctf_field_type_common
*ft
)
1704 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1706 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1707 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1709 return (int) flt_ft
->exp_dig
;
1713 int bt_ctf_field_type_common_floating_point_set_exponent_digits(
1714 struct bt_ctf_field_type_common
*ft
,
1715 unsigned int exponent_digits
)
1718 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1721 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1727 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1733 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1734 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1735 "addr=%p, ft-id=%s", ft
,
1736 bt_ctf_field_type_id_string(ft
->id
));
1741 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1742 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1744 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1745 BT_LOGW("Invalid parameter: invalid exponent size: "
1746 "addr=%p, exp-size=%u", ft
, exponent_digits
);
1751 flt_ft
->exp_dig
= exponent_digits
;
1752 BT_LOGT("Set floating point number field type's exponent size: addr=%p, "
1753 "exp-size=%u", ft
, exponent_digits
);
1760 int bt_ctf_field_type_common_floating_point_get_mantissa_digits(
1761 struct bt_ctf_field_type_common
*ft
)
1763 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1765 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1766 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_FLOAT
,
1768 return (int) flt_ft
->mant_dig
;
1772 int bt_ctf_field_type_common_floating_point_set_mantissa_digits(
1773 struct bt_ctf_field_type_common
*ft
, unsigned int mantissa_digits
)
1776 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
1779 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1785 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1791 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1792 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1793 "addr=%p, ft-id=%s", ft
,
1794 bt_ctf_field_type_id_string(ft
->id
));
1799 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1800 (mantissa_digits
!= DBL_MANT_DIG
) &&
1801 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1802 BT_LOGW("Invalid parameter: invalid mantissa size: "
1803 "addr=%p, mant-size=%u", ft
, mantissa_digits
);
1808 flt_ft
->mant_dig
= mantissa_digits
;
1809 BT_LOGT("Set floating point number field type's mantissa size: addr=%p, "
1810 "mant-size=%u", ft
, mantissa_digits
);
1817 int bt_ctf_field_type_common_structure_replace_field(
1818 struct bt_ctf_field_type_common
*ft
,
1819 const char *field_name
,
1820 struct bt_ctf_field_type_common
*field_type
)
1823 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1828 BT_ASSERT(field_name
);
1829 BT_ASSERT(field_type
);
1830 BT_ASSERT(ft
->id
== BT_CTF_FIELD_TYPE_ID_STRUCT
);
1831 name_quark
= g_quark_from_string(field_name
);
1833 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
1834 struct bt_ctf_field_type_common_structure_field
*field
=
1835 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
1837 if (field
->name
== name_quark
) {
1838 bt_ctf_object_put_ref(field
->type
);
1839 field
->type
= bt_ctf_object_get_ref(field_type
);
1847 int bt_ctf_field_type_common_structure_add_field(struct bt_ctf_field_type_common
*ft
,
1848 struct bt_ctf_field_type_common
*field_type
,
1849 const char *field_name
)
1852 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1855 * TODO: check that `field_type` does not contain `type`,
1859 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1865 BT_LOGW_STR("Invalid parameter: field name is NULL.");
1871 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1877 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
1878 BT_LOGW("Invalid parameter: field type is not a structure field type: "
1879 "addr=%p, ft-id=%s", ft
,
1880 bt_ctf_field_type_id_string(ft
->id
));
1885 if (ft
== field_type
) {
1886 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
1892 if (add_structure_variant_member(struct_ft
->fields
,
1893 struct_ft
->field_name_to_index
, field_type
, field_name
,
1895 BT_LOGW("Cannot add field to structure field type: "
1896 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
1897 ft
, field_type
, field_name
);
1902 BT_LOGT("Added structure field type field: struct-ft-addr=%p, "
1903 "field-ft-addr=%p, field-name=\"%s\"", ft
,
1904 field_type
, field_name
);
1911 int64_t bt_ctf_field_type_common_structure_get_field_count(
1912 struct bt_ctf_field_type_common
*ft
)
1914 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1916 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1917 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1919 return (int64_t) struct_ft
->fields
->len
;
1923 int bt_ctf_field_type_common_structure_borrow_field_by_index(
1924 struct bt_ctf_field_type_common
*ft
,
1925 const char **field_name
,
1926 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
1928 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1929 struct bt_ctf_field_type_common_structure_field
*field
;
1931 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1932 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1934 BT_CTF_ASSERT_PRE(index
< struct_ft
->fields
->len
,
1935 "Index is out of bounds: index=%" PRIu64
", "
1936 "count=%u, ft-addr=%p",
1937 index
, struct_ft
->fields
->len
, ft
);
1938 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(struct_ft
, index
);
1941 *field_type
= field
->type
;
1945 *field_name
= g_quark_to_string(field
->name
);
1946 BT_ASSERT(*field_name
);
1953 struct bt_ctf_field_type_common
*
1954 bt_ctf_field_type_common_structure_borrow_field_type_by_name(
1955 struct bt_ctf_field_type_common
*ft
, const char *name
)
1959 struct bt_ctf_field_type_common_structure_field
*field
;
1960 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
1961 struct bt_ctf_field_type_common
*field_type
= NULL
;
1963 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1964 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
1965 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
1967 name_quark
= g_quark_try_string(name
);
1969 BT_LOGT("No such structure field type field name: "
1970 "ft-addr=%p, field-name=\"%s\"",
1975 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
1976 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
1977 BT_LOGT("No such structure field type field name: "
1978 "ft-addr=%p, field-name=\"%s\"",
1983 field
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, index
);
1984 field_type
= field
->type
;
1991 struct bt_ctf_field_type_common
*
1992 bt_ctf_field_type_common_variant_borrow_tag_field_type(
1993 struct bt_ctf_field_type_common
*ft
)
1995 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
1996 struct bt_ctf_field_type_common
*tag_ft
= NULL
;
1998 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
1999 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2002 if (!var_ft
->tag_ft
) {
2003 BT_LOGT("Variant field type has no tag field type: "
2008 tag_ft
= BT_CTF_TO_COMMON(var_ft
->tag_ft
);
2015 const char *bt_ctf_field_type_common_variant_get_tag_name(
2016 struct bt_ctf_field_type_common
*ft
)
2018 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2019 const char *tag_name
= NULL
;
2021 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2022 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2025 if (var_ft
->tag_name
->len
== 0) {
2026 BT_LOGT("Variant field type has no tag field name: "
2031 tag_name
= var_ft
->tag_name
->str
;
2038 int bt_ctf_field_type_common_variant_set_tag_name(
2039 struct bt_ctf_field_type_common
*ft
, const char *name
)
2042 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2045 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2051 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2057 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2058 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2059 "addr=%p, ft-id=%s", ft
, bt_ctf_field_type_id_string(ft
->id
));
2064 if (!bt_ctf_identifier_is_valid(name
)) {
2065 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2066 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2072 g_string_assign(var_ft
->tag_name
, name
);
2073 BT_LOGT("Set variant field type's tag field name: addr=%p, "
2074 "tag-field-name=\"%s\"", ft
, name
);
2081 int bt_ctf_field_type_common_variant_add_field(struct bt_ctf_field_type_common
*ft
,
2082 struct bt_ctf_field_type_common
*field_type
,
2083 const char *field_name
)
2087 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2088 GQuark field_name_quark
= g_quark_from_string(field_name
);
2091 * TODO: check that `field_type` does not contain `type`,
2095 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2101 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2107 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2108 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2109 "addr=%p, ft-id=%s", ft
,
2110 bt_ctf_field_type_id_string(ft
->id
));
2115 if (ft
== field_type
) {
2116 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2122 /* The user has explicitly provided a tag; validate against it. */
2123 if (var_ft
->tag_ft
) {
2126 /* Make sure this name is present in the enum tag */
2127 for (i
= 0; i
< var_ft
->tag_ft
->entries
->len
; i
++) {
2128 struct bt_ctf_enumeration_mapping
*mapping
=
2129 g_ptr_array_index(var_ft
->tag_ft
->entries
, i
);
2131 if (mapping
->string
== field_name_quark
) {
2138 /* Validation failed */
2139 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2140 "variant-ft-addr=%p, tag-ft-addr=%p, "
2141 "tag-field-name=\"%s\""
2142 "field-ft-addr=%p, field-name=\"%s\"",
2143 ft
, var_ft
->tag_ft
, var_ft
->tag_name
->str
,
2144 field_type
, field_name
);
2150 if (add_structure_variant_member(var_ft
->choices
,
2151 var_ft
->choice_name_to_index
, field_type
,
2152 field_name
, true)) {
2153 BT_LOGW("Cannot add field to variant field type: "
2154 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2155 ft
, field_type
, field_name
);
2160 BT_LOGT("Added variant field type field: variant-ft-addr=%p, "
2161 "field-ft-addr=%p, field-name=\"%s\"", ft
,
2162 field_type
, field_name
);
2169 struct bt_ctf_field_type_common
*
2170 bt_ctf_field_type_common_variant_borrow_field_type_by_name(
2171 struct bt_ctf_field_type_common
*ft
,
2172 const char *field_name
)
2176 struct bt_ctf_field_type_common_variant_choice
*choice
;
2177 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2178 struct bt_ctf_field_type_common
*field_type
= NULL
;
2180 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2181 BT_CTF_ASSERT_PRE_NON_NULL(field_name
, "Name");
2182 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2184 name_quark
= g_quark_try_string(field_name
);
2186 BT_LOGT("No such variant field type field name: "
2187 "ft-addr=%p, field-name=\"%s\"",
2192 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2193 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*) &index
)) {
2194 BT_LOGT("No such variant field type field name: "
2195 "ft-addr=%p, field-name=\"%s\"",
2200 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2201 field_type
= choice
->type
;
2208 int64_t bt_ctf_field_type_common_variant_get_field_count(
2209 struct bt_ctf_field_type_common
*ft
)
2211 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2213 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Variant field type");
2214 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2216 return (int64_t) var_ft
->choices
->len
;
2220 int bt_ctf_field_type_common_variant_borrow_field_by_index(
2221 struct bt_ctf_field_type_common
*ft
,
2222 const char **field_name
,
2223 struct bt_ctf_field_type_common
**field_type
, uint64_t index
)
2225 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2226 struct bt_ctf_field_type_common_variant_choice
*choice
;
2228 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2229 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2231 BT_CTF_ASSERT_PRE(index
< var_ft
->choices
->len
,
2232 "Index is out of bounds: index=%" PRIu64
", "
2233 "count=%u, ft-addr=%p",
2234 index
, var_ft
->choices
->len
, ft
);
2235 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, index
);
2238 *field_type
= choice
->type
;
2242 *field_name
= g_quark_to_string(choice
->name
);
2243 BT_ASSERT(*field_name
);
2250 int64_t bt_ctf_field_type_common_variant_find_choice_index(
2251 struct bt_ctf_field_type_common
*ft
, uint64_t uval
,
2256 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2259 BT_ASSERT(ft
->id
== BT_CTF_FIELD_TYPE_ID_VARIANT
);
2261 if (bt_ctf_field_type_common_variant_update_choices(ft
)) {
2266 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
2268 struct bt_ctf_field_type_common_variant_choice
*choice
=
2269 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
2272 for (range_i
= 0; range_i
< choice
->ranges
->len
; range_i
++) {
2273 struct bt_ctf_field_type_common_variant_choice_range
*range
=
2276 struct bt_ctf_field_type_common_variant_choice_range
,
2280 int64_t tag_ival
= (int64_t) uval
;
2282 if (tag_ival
>= range
->lower
.i
&&
2283 tag_ival
<= range
->upper
.i
) {
2287 if (uval
>= range
->lower
.u
&&
2288 uval
<= range
->upper
.u
) {
2295 /* Range not found */
2307 struct bt_ctf_field_type_common
*
2308 bt_ctf_field_type_common_array_borrow_element_field_type(
2309 struct bt_ctf_field_type_common
*ft
)
2311 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2313 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2314 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2316 BT_ASSERT(array_ft
&& array_ft
->element_ft
);
2317 return array_ft
->element_ft
;
2321 int bt_ctf_field_type_common_array_set_element_field_type(
2322 struct bt_ctf_field_type_common
*ft
,
2323 struct bt_ctf_field_type_common
*element_ft
)
2326 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2329 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2335 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2340 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2341 BT_LOGW("Invalid parameter: field type is not an array field type: "
2342 "addr=%p, ft-id=%s", ft
,
2343 bt_ctf_field_type_id_string(ft
->id
));
2348 if (array_ft
->element_ft
) {
2349 BT_CTF_OBJECT_PUT_REF_AND_RESET(array_ft
->element_ft
);
2352 array_ft
->element_ft
= bt_ctf_object_get_ref(element_ft
);
2353 BT_LOGT("Set array field type's element field type: array-ft-addr=%p, "
2354 "element-ft-addr=%p", ft
, element_ft
);
2361 int64_t bt_ctf_field_type_common_array_get_length(struct bt_ctf_field_type_common
*ft
)
2363 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
2365 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2366 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_ARRAY
,
2368 return (int64_t) array_ft
->length
;
2372 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_sequence_borrow_element_field_type(
2373 struct bt_ctf_field_type_common
*ft
)
2375 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2377 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2378 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2380 return seq_ft
->element_ft
;
2384 int bt_ctf_field_type_common_sequence_set_element_field_type(
2385 struct bt_ctf_field_type_common
*ft
,
2386 struct bt_ctf_field_type_common
*element_ft
)
2389 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2392 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2398 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2403 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2404 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2405 "addr=%p, ft-id=%s", ft
,
2406 bt_ctf_field_type_id_string(ft
->id
));
2411 if (seq_ft
->element_ft
) {
2412 BT_CTF_OBJECT_PUT_REF_AND_RESET(seq_ft
->element_ft
);
2415 seq_ft
->element_ft
= element_ft
;
2416 bt_ctf_object_get_ref(seq_ft
->element_ft
);
2417 BT_LOGT("Set sequence field type's element field type: sequence-ft-addr=%p, "
2418 "element-ft-addr=%p", ft
, element_ft
);
2425 const char *bt_ctf_field_type_common_sequence_get_length_field_name(
2426 struct bt_ctf_field_type_common
*ft
)
2428 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2430 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2431 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
2433 return seq_ft
->length_field_name
?
2434 seq_ft
->length_field_name
->str
: NULL
;
2438 enum bt_ctf_string_encoding
bt_ctf_field_type_common_string_get_encoding(
2439 struct bt_ctf_field_type_common
*ft
)
2441 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2443 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2444 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRING
,
2446 return string_ft
->encoding
;
2450 int bt_ctf_field_type_common_string_set_encoding(struct bt_ctf_field_type_common
*ft
,
2451 enum bt_ctf_string_encoding encoding
)
2454 struct bt_ctf_field_type_common_string
*string_ft
= BT_CTF_FROM_COMMON(ft
);
2457 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2462 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2463 BT_LOGW("Invalid parameter: field type is not a string field type: "
2464 "addr=%p, ft-id=%s", ft
,
2465 bt_ctf_field_type_id_string(ft
->id
));
2470 if (encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2471 encoding
!= BT_CTF_STRING_ENCODING_ASCII
) {
2472 BT_LOGW("Invalid parameter: unknown string encoding: "
2473 "addr=%p, encoding=%d", ft
, encoding
);
2478 string_ft
->encoding
= encoding
;
2479 BT_LOGT("Set string field type's encoding: addr=%p, encoding=%s",
2480 ft
, bt_ctf_string_encoding_string(encoding
));
2487 int bt_ctf_field_type_common_get_alignment(struct bt_ctf_field_type_common
*ft
)
2490 enum bt_ctf_field_type_id type_id
;
2492 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2495 ret
= (int) ft
->alignment
;
2499 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2501 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2503 struct bt_ctf_field_type_common
*element_ft
=
2504 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
2506 BT_ASSERT(element_ft
);
2507 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2510 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2512 struct bt_ctf_field_type_common
*element_ft
=
2513 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
2515 BT_ASSERT(element_ft
);
2516 ret
= bt_ctf_field_type_common_get_alignment(element_ft
);
2519 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2521 int64_t i
, element_count
;
2523 element_count
= bt_ctf_field_type_common_structure_get_field_count(
2525 BT_ASSERT(element_count
>= 0);
2527 for (i
= 0; i
< element_count
; i
++) {
2528 struct bt_ctf_field_type_common
*field
= NULL
;
2529 int field_alignment
;
2531 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
2532 ft
, NULL
, &field
, i
);
2533 BT_ASSERT(ret
== 0);
2535 field_alignment
= bt_ctf_field_type_common_get_alignment(
2537 if (field_alignment
< 0) {
2538 ret
= field_alignment
;
2542 ft
->alignment
= MAX(field_alignment
, ft
->alignment
);
2544 ret
= (int) ft
->alignment
;
2547 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
2548 BT_LOGW("Invalid parameter: unknown field type ID: "
2549 "addr=%p, ft-id=%d", ft
, type_id
);
2553 ret
= (int) ft
->alignment
;
2562 int is_power_of_two(unsigned int value
)
2564 return ((value
& (value
- 1)) == 0) && value
> 0;
2568 int bt_ctf_field_type_common_set_alignment(struct bt_ctf_field_type_common
*ft
,
2569 unsigned int alignment
)
2572 enum bt_ctf_field_type_id type_id
;
2574 /* Alignment must be a power of two */
2576 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2582 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2588 if (!is_power_of_two(alignment
)) {
2589 BT_LOGW("Invalid parameter: alignment is not a power of two: "
2590 "addr=%p, align=%u", ft
, alignment
);
2595 type_id
= bt_ctf_field_type_common_get_type_id(ft
);
2596 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
2597 BT_LOGW("Invalid parameter: unknown field type ID: "
2598 "addr=%p, ft-id=%d", ft
, type_id
);
2603 if (ft
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&& alignment
!= CHAR_BIT
) {
2604 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
2605 "addr=%p, align=%u", CHAR_BIT
, ft
, alignment
);
2610 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
2611 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
2612 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2613 /* Setting an alignment on these types makes no sense */
2614 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
2615 "addr=%p, ft-id=%s", ft
,
2616 bt_ctf_field_type_id_string(ft
->id
));
2621 ft
->alignment
= alignment
;
2623 BT_LOGT("Set field type's alignment: addr=%p, align=%u",
2631 enum bt_ctf_byte_order
bt_ctf_field_type_common_get_byte_order(
2632 struct bt_ctf_field_type_common
*ft
)
2634 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
2636 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2639 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
2641 struct bt_ctf_field_type_common_integer
*integer
=
2642 BT_CTF_FROM_COMMON(ft
);
2644 ret
= integer
->user_byte_order
;
2647 case BT_CTF_FIELD_TYPE_ID_ENUM
:
2649 struct bt_ctf_field_type_common_enumeration
*enum_ft
=
2650 BT_CTF_FROM_COMMON(ft
);
2652 ret
= bt_ctf_field_type_common_get_byte_order(
2653 BT_CTF_TO_COMMON(enum_ft
->container_ft
));
2656 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
2658 struct bt_ctf_field_type_common_floating_point
*floating_point
=
2659 BT_CTF_FROM_COMMON(ft
);
2660 ret
= floating_point
->user_byte_order
;
2664 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
2665 "addr=%p, ft-id=%s", ft
,
2666 bt_ctf_field_type_id_string(ft
->id
));
2670 BT_ASSERT(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
2671 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
2672 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
2673 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
2680 int bt_ctf_field_type_common_set_byte_order(struct bt_ctf_field_type_common
*ft
,
2681 enum bt_ctf_byte_order byte_order
)
2686 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2692 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2698 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
2699 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
2700 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
2701 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
2702 BT_LOGW("Invalid parameter: invalid byte order: "
2703 "addr=%p, bo=%s", ft
,
2704 bt_ctf_byte_order_string(byte_order
));
2709 if (ft
->methods
->set_byte_order
) {
2710 ft
->methods
->set_byte_order(ft
, byte_order
);
2713 BT_LOGT("Set field type's byte order: addr=%p, bo=%s",
2714 ft
, bt_ctf_byte_order_string(byte_order
));
2721 enum bt_ctf_field_type_id
bt_ctf_field_type_common_get_type_id(
2722 struct bt_ctf_field_type_common
*ft
)
2724 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2729 void bt_ctf_field_type_common_freeze(struct bt_ctf_field_type_common
*ft
)
2731 if (!ft
|| ft
->frozen
) {
2735 BT_ASSERT(ft
->methods
->freeze
);
2736 ft
->methods
->freeze(ft
);
2740 struct bt_ctf_field_type_common
*
2741 bt_ctf_field_type_common_variant_borrow_field_type_signed(
2742 struct bt_ctf_field_type_common_variant
*var_ft
,
2745 struct bt_ctf_field_type_common
*field_type
= NULL
;
2746 GQuark field_name_quark
;
2748 struct bt_ctf_field_type_common_variant_choice
*choice
;
2749 struct range_overlap_query query
= {
2750 .range_start
._signed
= tag_value
,
2751 .range_end
._signed
= tag_value
,
2756 g_ptr_array_foreach(var_ft
->tag_ft
->entries
, check_ranges_overlap
,
2758 if (!query
.overlaps
) {
2762 field_name_quark
= query
.mapping_name
;
2763 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2764 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2768 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2770 field_type
= choice
->type
;
2777 struct bt_ctf_field_type_common
*
2778 bt_ctf_field_type_common_variant_borrow_field_type_unsigned(
2779 struct bt_ctf_field_type_common_variant
*var_ft
,
2782 struct bt_ctf_field_type_common
*field_type
= NULL
;
2783 GQuark field_name_quark
;
2785 struct bt_ctf_field_type_common_variant_choice
*choice
;
2786 struct range_overlap_query query
= {
2787 .range_start
._unsigned
= tag_value
,
2788 .range_end
._unsigned
= tag_value
,
2793 g_ptr_array_foreach(var_ft
->tag_ft
->entries
,
2794 check_ranges_overlap_unsigned
, &query
);
2795 if (!query
.overlaps
) {
2799 field_name_quark
= query
.mapping_name
;
2800 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2801 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
2805 choice
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
,
2807 field_type
= choice
->type
;
2814 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_copy(
2815 struct bt_ctf_field_type_common
*ft
)
2817 struct bt_ctf_field_type_common
*ft_copy
= NULL
;
2819 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2820 BT_ASSERT(ft
->methods
->copy
);
2821 ft_copy
= ft
->methods
->copy(ft
);
2823 BT_LOGE_STR("Cannot copy field type.");
2827 ft_copy
->alignment
= ft
->alignment
;
2834 int bt_ctf_field_type_common_structure_get_field_name_index(
2835 struct bt_ctf_field_type_common
*ft
, const char *name
)
2840 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
2842 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2843 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
2844 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_STRUCT
,
2847 name_quark
= g_quark_try_string(name
);
2849 BT_LOGT("No such structure field type field name: "
2850 "ft-addr=%p, field-name=\"%s\"",
2856 if (!g_hash_table_lookup_extended(struct_ft
->field_name_to_index
,
2857 GUINT_TO_POINTER(name_quark
),
2858 NULL
, (gpointer
*) &index
)) {
2859 BT_LOGT("No such structure field type field name: "
2860 "ft-addr=%p, field-name=\"%s\"",
2873 int bt_ctf_field_type_common_variant_get_field_name_index(
2874 struct bt_ctf_field_type_common
*ft
, const char *name
)
2879 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2881 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
2882 BT_CTF_ASSERT_PRE_NON_NULL(name
, "Name");
2883 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
2885 name_quark
= g_quark_try_string(name
);
2887 BT_LOGT("No such variant field type field name: "
2888 "ft-addr=%p, field-name=\"%s\"",
2894 if (!g_hash_table_lookup_extended(var_ft
->choice_name_to_index
,
2895 GUINT_TO_POINTER(name_quark
),
2896 NULL
, (gpointer
*) &index
)) {
2897 BT_LOGT("No such variant field type field name: "
2898 "ft-addr=%p, field-name=\"%s\"",
2911 int bt_ctf_field_type_common_sequence_set_length_field_path(
2912 struct bt_ctf_field_type_common
*ft
, struct bt_ctf_field_path
*path
)
2915 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
2918 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2923 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2924 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2925 "addr=%p, ft-id=%s", ft
,
2926 bt_ctf_field_type_id_string(ft
->id
));
2931 bt_ctf_object_get_ref(path
);
2932 BT_CTF_OBJECT_MOVE_REF(seq_ft
->length_field_path
, path
);
2933 BT_LOGT("Set sequence field type's length field path: ft-addr=%p, "
2934 "field-path-addr=%p", ft
, path
);
2941 int bt_ctf_field_type_common_variant_set_tag_field_path(
2942 struct bt_ctf_field_type_common
*ft
,
2943 struct bt_ctf_field_path
*path
)
2946 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2949 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2954 if (ft
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2955 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2956 "addr=%p, ft-id=%s", ft
,
2957 bt_ctf_field_type_id_string(ft
->id
));
2962 bt_ctf_object_get_ref(path
);
2963 BT_CTF_OBJECT_MOVE_REF(var_ft
->tag_field_path
, path
);
2964 BT_LOGT("Set variant field type's tag field path: ft-addr=%p, "
2965 "field-path-addr=%p", ft
, path
);
2972 int bt_ctf_field_type_common_variant_set_tag_field_type(
2973 struct bt_ctf_field_type_common
*ft
,
2974 struct bt_ctf_field_type_common
*tag_ft
)
2977 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
2980 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2986 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
2991 if (tag_ft
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
2992 BT_LOGW("Invalid parameter: tag field type is not an enumeration field type: "
2993 "addr=%p, ft-id=%s", tag_ft
,
2994 bt_ctf_field_type_id_string(tag_ft
->id
));
2999 bt_ctf_object_put_ref(var_ft
->tag_ft
);
3000 var_ft
->tag_ft
= bt_ctf_object_get_ref(tag_ft
);
3001 BT_LOGT("Set variant field type's tag field type: variant-ft-addr=%p, "
3002 "tag-ft-addr=%p", ft
, tag_ft
);
3009 void bt_ctf_field_type_common_generic_freeze(struct bt_ctf_field_type_common
*ft
)
3015 void bt_ctf_field_type_common_enumeration_freeze_recursive(
3016 struct bt_ctf_field_type_common
*ft
)
3018 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
3020 BT_LOGD("Freezing enumeration field type object: addr=%p", ft
);
3021 bt_ctf_field_type_common_enumeration_set_range_overlap(enum_ft
);
3022 bt_ctf_field_type_common_generic_freeze(ft
);
3023 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3024 enum_ft
->container_ft
);
3025 bt_ctf_field_type_common_freeze(BT_CTF_TO_COMMON(enum_ft
->container_ft
));
3029 void bt_ctf_field_type_common_structure_freeze_recursive(
3030 struct bt_ctf_field_type_common
*ft
)
3032 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
3035 /* Cache the alignment */
3036 BT_LOGD("Freezing structure field type object: addr=%p", ft
);
3037 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3038 bt_ctf_field_type_common_generic_freeze(ft
);
3040 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3041 struct bt_ctf_field_type_common_structure_field
*field
=
3042 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft
, i
);
3044 BT_LOGD("Freezing structure field type field: "
3045 "ft-addr=%p, name=\"%s\"",
3046 field
->type
, g_quark_to_string(field
->name
));
3047 bt_ctf_field_type_common_freeze(field
->type
);
3052 int bt_ctf_field_type_common_variant_update_choices(struct bt_ctf_field_type_common
*ft
)
3054 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3059 if (ft
->frozen
&& var_ft
->choices_up_to_date
) {
3063 BT_ASSERT(var_ft
->tag_ft
);
3064 is_signed
= !!var_ft
->tag_ft
->container_ft
->is_signed
;
3066 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3067 struct bt_ctf_field_type_common_variant_choice
*choice
=
3068 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
3069 const char *choice_name
= g_quark_to_string(choice
->name
);
3070 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
3071 bt_ctf_field_type_common_enumeration_find_mappings_by_name(
3072 BT_CTF_TO_COMMON(var_ft
->tag_ft
), choice_name
);
3079 BT_ASSERT(choice
->ranges
);
3080 g_array_set_size(choice
->ranges
, 0);
3082 while (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
) == 0) {
3083 struct bt_ctf_field_type_common_variant_choice_range range
;
3086 ret
= bt_ctf_field_type_enumeration_mapping_iterator_signed_get(
3088 &range
.lower
.i
, &range
.upper
.i
);
3090 ret
= bt_ctf_field_type_enumeration_mapping_iterator_unsigned_get(
3092 &range
.lower
.u
, &range
.upper
.u
);
3095 BT_ASSERT(ret
== 0);
3096 g_array_append_val(choice
->ranges
, range
);
3099 bt_ctf_object_put_ref(iter
);
3102 var_ft
->choices_up_to_date
= true;
3109 void bt_ctf_field_type_common_variant_freeze_recursive(
3110 struct bt_ctf_field_type_common
*ft
)
3112 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3115 BT_LOGD("Freezing variant field type object: addr=%p", ft
);
3116 bt_ctf_field_type_common_generic_freeze(ft
);
3118 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3119 struct bt_ctf_field_type_common_variant_choice
*choice
=
3120 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(ft
, i
);
3122 BT_LOGD("Freezing variant field type member: "
3123 "ft-addr=%p, name=\"%s\"",
3124 choice
->type
, g_quark_to_string(choice
->name
));
3125 bt_ctf_field_type_common_freeze(choice
->type
);
3130 void bt_ctf_field_type_common_array_freeze_recursive(
3131 struct bt_ctf_field_type_common
*ft
)
3133 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3135 /* Cache the alignment */
3136 BT_LOGD("Freezing array field type object: addr=%p", ft
);
3137 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3138 bt_ctf_field_type_common_generic_freeze(ft
);
3139 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3140 array_ft
->element_ft
);
3141 bt_ctf_field_type_common_freeze(array_ft
->element_ft
);
3145 void bt_ctf_field_type_common_sequence_freeze_recursive(
3146 struct bt_ctf_field_type_common
*ft
)
3148 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3150 /* Cache the alignment */
3151 BT_LOGD("Freezing sequence field type object: addr=%p", ft
);
3152 ft
->alignment
= bt_ctf_field_type_common_get_alignment(ft
);
3153 bt_ctf_field_type_common_generic_freeze(ft
);
3154 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3155 seq_ft
->element_ft
);
3156 bt_ctf_field_type_common_freeze(seq_ft
->element_ft
);
3160 void bt_ctf_field_type_common_integer_set_byte_order(
3161 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3163 struct bt_ctf_field_type_common_integer
*int_ft
= BT_CTF_FROM_COMMON(ft
);
3165 int_ft
->user_byte_order
= byte_order
;
3169 void bt_ctf_field_type_common_enumeration_set_byte_order_recursive(
3170 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3172 struct bt_ctf_field_type_common_enumeration
*enum_ft
= BT_CTF_FROM_COMMON(ft
);
3174 bt_ctf_field_type_common_set_byte_order(BT_CTF_TO_COMMON(enum_ft
->container_ft
),
3179 void bt_ctf_field_type_common_floating_point_set_byte_order(
3180 struct bt_ctf_field_type_common
*ft
, enum bt_ctf_byte_order byte_order
)
3182 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
3184 flt_ft
->user_byte_order
= byte_order
;
3188 void bt_ctf_field_type_common_structure_set_byte_order_recursive(
3189 struct bt_ctf_field_type_common
*ft
,
3190 enum bt_ctf_byte_order byte_order
)
3193 struct bt_ctf_field_type_common_structure
*struct_ft
= BT_CTF_FROM_COMMON(ft
);
3195 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
3196 struct bt_ctf_field_type_common_structure_field
*field
=
3197 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3199 struct bt_ctf_field_type_common
*field_type
= field
->type
;
3201 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3206 void bt_ctf_field_type_common_variant_set_byte_order_recursive(
3207 struct bt_ctf_field_type_common
*ft
,
3208 enum bt_ctf_byte_order byte_order
)
3211 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3213 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
3214 struct bt_ctf_field_type_common_variant_choice
*choice
=
3215 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3217 struct bt_ctf_field_type_common
*field_type
= choice
->type
;
3219 bt_ctf_field_type_common_set_byte_order(field_type
, byte_order
);
3224 void bt_ctf_field_type_common_array_set_byte_order_recursive(
3225 struct bt_ctf_field_type_common
*ft
,
3226 enum bt_ctf_byte_order byte_order
)
3228 struct bt_ctf_field_type_common_array
*array_ft
= BT_CTF_FROM_COMMON(ft
);
3230 bt_ctf_field_type_common_set_byte_order(array_ft
->element_ft
, byte_order
);
3234 void bt_ctf_field_type_common_sequence_set_byte_order_recursive(
3235 struct bt_ctf_field_type_common
*ft
,
3236 enum bt_ctf_byte_order byte_order
)
3238 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3240 bt_ctf_field_type_common_set_byte_order(seq_ft
->element_ft
, byte_order
);
3245 int bt_ctf_field_type_common_integer_compare(struct bt_ctf_field_type_common
*ft_a
,
3246 struct bt_ctf_field_type_common
*ft_b
)
3249 struct bt_ctf_field_type_common_integer
*int_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3250 struct bt_ctf_field_type_common_integer
*int_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3253 if (int_ft_a
->size
!= int_ft_b
->size
) {
3254 BT_LOGT("Integer field types differ: different sizes: "
3255 "ft-a-size=%u, ft-b-size=%u",
3256 int_ft_a
->size
, int_ft_b
->size
);
3261 if (int_ft_a
->user_byte_order
!= int_ft_b
->user_byte_order
) {
3262 BT_LOGT("Integer field types differ: different byte orders: "
3263 "ft-a-bo=%s, ft-b-bo=%s",
3264 bt_ctf_byte_order_string(int_ft_a
->user_byte_order
),
3265 bt_ctf_byte_order_string(int_ft_b
->user_byte_order
));
3270 if (int_ft_a
->is_signed
!= int_ft_b
->is_signed
) {
3271 BT_LOGT("Integer field types differ: different signedness: "
3272 "ft-a-is-signed=%d, ft-b-is-signed=%d",
3273 int_ft_a
->is_signed
,
3274 int_ft_b
->is_signed
);
3279 if (int_ft_a
->base
!= int_ft_b
->base
) {
3280 BT_LOGT("Integer field types differ: different bases: "
3281 "ft-a-base=%s, ft-b-base=%s",
3282 bt_ctf_integer_base_string(int_ft_a
->base
),
3283 bt_ctf_integer_base_string(int_ft_b
->base
));
3288 if (int_ft_a
->encoding
!= int_ft_b
->encoding
) {
3289 BT_LOGT("Integer field types differ: different encodings: "
3290 "ft-a-encoding=%s, ft-b-encoding=%s",
3291 bt_ctf_string_encoding_string(int_ft_a
->encoding
),
3292 bt_ctf_string_encoding_string(int_ft_b
->encoding
));
3296 /* Mapped clock class */
3297 if (int_ft_a
->mapped_clock_class
) {
3298 if (!int_ft_b
->mapped_clock_class
) {
3299 BT_LOGT_STR("Integer field types differ: field type A "
3300 "has a mapped clock class, but field type B "
3305 if (bt_ctf_clock_class_compare(int_ft_a
->mapped_clock_class
,
3306 int_ft_b
->mapped_clock_class
) != 0) {
3307 BT_LOGT_STR("Integer field types differ: different "
3308 "mapped clock classes.");
3311 if (int_ft_b
->mapped_clock_class
) {
3312 BT_LOGT_STR("Integer field types differ: field type A "
3313 "has no description, but field type B has one.");
3326 int bt_ctf_field_type_common_floating_point_compare(
3327 struct bt_ctf_field_type_common
*ft_a
,
3328 struct bt_ctf_field_type_common
*ft_b
)
3331 struct bt_ctf_field_type_common_floating_point
*flt_ft_a
=
3332 BT_CTF_FROM_COMMON(ft_a
);
3333 struct bt_ctf_field_type_common_floating_point
*flt_ft_b
=
3334 BT_CTF_FROM_COMMON(ft_b
);
3337 if (flt_ft_a
->user_byte_order
!= flt_ft_b
->user_byte_order
) {
3338 BT_LOGT("Floating point number field types differ: different byte orders: "
3339 "ft-a-bo=%s, ft-b-bo=%s",
3340 bt_ctf_byte_order_string(flt_ft_a
->user_byte_order
),
3341 bt_ctf_byte_order_string(flt_ft_b
->user_byte_order
));
3345 /* Exponent length */
3346 if (flt_ft_a
->exp_dig
!= flt_ft_b
->exp_dig
) {
3347 BT_LOGT("Floating point number field types differ: different exponent sizes: "
3348 "ft-a-exp-size=%u, ft-b-exp-size=%u",
3349 flt_ft_a
->exp_dig
, flt_ft_b
->exp_dig
);
3353 /* Mantissa length */
3354 if (flt_ft_a
->mant_dig
!= flt_ft_b
->mant_dig
) {
3355 BT_LOGT("Floating point number field types differ: different mantissa sizes: "
3356 "ft-a-mant-size=%u, ft-b-mant-size=%u",
3357 flt_ft_a
->mant_dig
, flt_ft_b
->mant_dig
);
3369 int compare_enumeration_mappings(struct bt_ctf_enumeration_mapping
*mapping_a
,
3370 struct bt_ctf_enumeration_mapping
*mapping_b
)
3375 if (mapping_a
->string
!= mapping_b
->string
) {
3376 BT_LOGT("Enumeration field type mappings differ: different names: "
3377 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
3378 g_quark_to_string(mapping_a
->string
),
3379 g_quark_to_string(mapping_b
->string
));
3384 if (mapping_a
->range_start
._unsigned
!=
3385 mapping_b
->range_start
._unsigned
) {
3386 BT_LOGT("Enumeration field type mappings differ: different starts of range: "
3387 "mapping-a-range-start-unsigned=%" PRIu64
", "
3388 "mapping-b-range-start-unsigned=%" PRIu64
,
3389 mapping_a
->range_start
._unsigned
,
3390 mapping_b
->range_start
._unsigned
);
3395 if (mapping_a
->range_end
._unsigned
!=
3396 mapping_b
->range_end
._unsigned
) {
3397 BT_LOGT("Enumeration field type mappings differ: different ends of range: "
3398 "mapping-a-range-end-unsigned=%" PRIu64
", "
3399 "mapping-b-range-end-unsigned=%" PRIu64
,
3400 mapping_a
->range_end
._unsigned
,
3401 mapping_b
->range_end
._unsigned
);
3413 int bt_ctf_field_type_common_enumeration_compare_recursive(
3414 struct bt_ctf_field_type_common
*ft_a
,
3415 struct bt_ctf_field_type_common
*ft_b
)
3419 struct bt_ctf_field_type_common_enumeration
*enum_ft_a
=
3420 BT_CTF_FROM_COMMON(ft_a
);
3421 struct bt_ctf_field_type_common_enumeration
*enum_ft_b
=
3422 BT_CTF_FROM_COMMON(ft_b
);
3424 /* Container field type */
3425 ret
= bt_ctf_field_type_common_compare(
3426 BT_CTF_TO_COMMON(enum_ft_a
->container_ft
),
3427 BT_CTF_TO_COMMON(enum_ft_b
->container_ft
));
3429 BT_LOGT("Enumeration field types differ: different container field types: "
3430 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
3431 enum_ft_a
->container_ft
, enum_ft_b
->container_ft
);
3438 if (enum_ft_a
->entries
->len
!= enum_ft_b
->entries
->len
) {
3442 for (i
= 0; i
< enum_ft_a
->entries
->len
; ++i
) {
3443 struct bt_ctf_enumeration_mapping
*mapping_a
=
3444 g_ptr_array_index(enum_ft_a
->entries
, i
);
3445 struct bt_ctf_enumeration_mapping
*mapping_b
=
3446 g_ptr_array_index(enum_ft_b
->entries
, i
);
3448 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
3449 BT_LOGT("Enumeration field types differ: different mappings: "
3450 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
3451 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
3452 mapping_a
, mapping_b
,
3453 g_quark_to_string(mapping_a
->string
),
3454 g_quark_to_string(mapping_b
->string
));
3467 int bt_ctf_field_type_common_string_compare(struct bt_ctf_field_type_common
*ft_a
,
3468 struct bt_ctf_field_type_common
*ft_b
)
3471 struct bt_ctf_field_type_common_string
*string_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3472 struct bt_ctf_field_type_common_string
*string_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3475 if (string_ft_a
->encoding
!= string_ft_b
->encoding
) {
3476 BT_LOGT("String field types differ: different encodings: "
3477 "ft-a-encoding=%s, ft-b-encoding=%s",
3478 bt_ctf_string_encoding_string(string_ft_a
->encoding
),
3479 bt_ctf_string_encoding_string(string_ft_b
->encoding
));
3491 int compare_structure_variant_members(
3492 struct bt_ctf_field_type_common
*member_a_ft
,
3493 struct bt_ctf_field_type_common
*member_b_ft
,
3494 GQuark member_a_name
, GQuark member_b_name
)
3499 if (member_a_name
!= member_b_name
) {
3500 BT_LOGT("Structure/variant field type fields differ: different names: "
3501 "field-a-name=%s, field-b-name=%s",
3502 g_quark_to_string(member_a_name
),
3503 g_quark_to_string(member_b_name
));
3508 ret
= bt_ctf_field_type_common_compare(member_a_ft
, member_b_ft
);
3510 BT_LOGT("Structure/variant field type fields differ: different field types: "
3511 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
3512 g_quark_to_string(member_a_name
),
3513 member_a_ft
, member_b_ft
);
3521 int bt_ctf_field_type_common_structure_compare_recursive(
3522 struct bt_ctf_field_type_common
*ft_a
,
3523 struct bt_ctf_field_type_common
*ft_b
)
3527 struct bt_ctf_field_type_common_structure
*struct_ft_a
=
3528 BT_CTF_FROM_COMMON(ft_a
);
3529 struct bt_ctf_field_type_common_structure
*struct_ft_b
=
3530 BT_CTF_FROM_COMMON(ft_b
);
3533 if (bt_ctf_field_type_common_get_alignment(ft_a
) !=
3534 bt_ctf_field_type_common_get_alignment(ft_b
)) {
3535 BT_LOGT("Structure field types differ: different alignments: "
3536 "ft-a-align=%u, ft-b-align=%u",
3537 bt_ctf_field_type_common_get_alignment(ft_a
),
3538 bt_ctf_field_type_common_get_alignment(ft_b
));
3543 if (struct_ft_a
->fields
->len
!= struct_ft_b
->fields
->len
) {
3544 BT_LOGT("Structure field types differ: different field counts: "
3545 "ft-a-field-count=%u, ft-b-field-count=%u",
3546 struct_ft_a
->fields
->len
, struct_ft_b
->fields
->len
);
3550 for (i
= 0; i
< struct_ft_a
->fields
->len
; ++i
) {
3551 struct bt_ctf_field_type_common_structure_field
*field_a
=
3552 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3554 struct bt_ctf_field_type_common_structure_field
*field_b
=
3555 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
3558 ret
= compare_structure_variant_members(field_a
->type
,
3559 field_b
->type
, field_a
->name
, field_b
->name
);
3561 /* compare_structure_variant_members() logs what differs */
3562 BT_LOGT_STR("Structure field types differ: different fields.");
3575 int bt_ctf_field_type_common_variant_compare_recursive(
3576 struct bt_ctf_field_type_common
*ft_a
,
3577 struct bt_ctf_field_type_common
*ft_b
)
3581 struct bt_ctf_field_type_common_variant
*var_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3582 struct bt_ctf_field_type_common_variant
*var_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3585 if (strcmp(var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
)) {
3586 BT_LOGT("Variant field types differ: different tag field names: "
3587 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
3588 var_ft_a
->tag_name
->str
, var_ft_b
->tag_name
->str
);
3593 ret
= bt_ctf_field_type_common_compare(BT_CTF_TO_COMMON(var_ft_a
->tag_ft
),
3594 BT_CTF_TO_COMMON(var_ft_b
->tag_ft
));
3596 BT_LOGT("Variant field types differ: different tag field types: "
3597 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
3598 var_ft_a
->tag_ft
, var_ft_b
->tag_ft
);
3605 if (var_ft_a
->choices
->len
!= var_ft_b
->choices
->len
) {
3606 BT_LOGT("Variant field types differ: different field counts: "
3607 "ft-a-field-count=%u, ft-b-field-count=%u",
3608 var_ft_a
->choices
->len
, var_ft_b
->choices
->len
);
3612 for (i
= 0; i
< var_ft_a
->choices
->len
; ++i
) {
3613 struct bt_ctf_field_type_common_variant_choice
*choice_a
=
3614 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3616 struct bt_ctf_field_type_common_variant_choice
*choice_b
=
3617 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
3620 ret
= compare_structure_variant_members(choice_a
->type
,
3621 choice_b
->type
, choice_a
->name
, choice_b
->name
);
3623 /* compare_structure_variant_members() logs what differs */
3624 BT_LOGT_STR("Variant field types differ: different fields.");
3637 int bt_ctf_field_type_common_array_compare_recursive(
3638 struct bt_ctf_field_type_common
*ft_a
,
3639 struct bt_ctf_field_type_common
*ft_b
)
3642 struct bt_ctf_field_type_common_array
*array_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3643 struct bt_ctf_field_type_common_array
*array_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3646 if (array_ft_a
->length
!= array_ft_b
->length
) {
3647 BT_LOGT("Structure field types differ: different lengths: "
3648 "ft-a-length=%u, ft-b-length=%u",
3649 array_ft_a
->length
, array_ft_b
->length
);
3654 ret
= bt_ctf_field_type_common_compare(array_ft_a
->element_ft
,
3655 array_ft_b
->element_ft
);
3657 BT_LOGT("Array field types differ: different element field types: "
3658 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3659 array_ft_a
->element_ft
, array_ft_b
->element_ft
);
3667 int bt_ctf_field_type_common_sequence_compare_recursive(
3668 struct bt_ctf_field_type_common
*ft_a
,
3669 struct bt_ctf_field_type_common
*ft_b
)
3672 struct bt_ctf_field_type_common_sequence
*seq_ft_a
= BT_CTF_FROM_COMMON(ft_a
);
3673 struct bt_ctf_field_type_common_sequence
*seq_ft_b
= BT_CTF_FROM_COMMON(ft_b
);
3676 if (strcmp(seq_ft_a
->length_field_name
->str
,
3677 seq_ft_b
->length_field_name
->str
)) {
3678 BT_LOGT("Sequence field types differ: different length field names: "
3679 "ft-a-length-field-name=\"%s\", "
3680 "ft-b-length-field-name=\"%s\"",
3681 seq_ft_a
->length_field_name
->str
,
3682 seq_ft_b
->length_field_name
->str
);
3687 ret
= bt_ctf_field_type_common_compare(seq_ft_a
->element_ft
,
3688 seq_ft_b
->element_ft
);
3690 BT_LOGT("Sequence field types differ: different element field types: "
3691 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
3692 seq_ft_a
->element_ft
, seq_ft_b
->element_ft
);
3700 int bt_ctf_field_type_common_compare(struct bt_ctf_field_type_common
*ft_a
,
3701 struct bt_ctf_field_type_common
*ft_b
)
3705 BT_CTF_ASSERT_PRE_NON_NULL(ft_a
, "Field type A");
3706 BT_CTF_ASSERT_PRE_NON_NULL(ft_b
, "Field type B");
3709 /* Same reference: equal (even if both are NULL) */
3715 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
3721 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
3726 if (ft_a
->id
!= ft_b
->id
) {
3727 /* Different type IDs */
3728 BT_LOGT("Field types differ: different IDs: "
3729 "ft-a-addr=%p, ft-b-addr=%p, "
3730 "ft-a-id=%s, ft-b-id=%s",
3732 bt_ctf_field_type_id_string(ft_a
->id
),
3733 bt_ctf_field_type_id_string(ft_b
->id
));
3737 if (ft_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3738 /* Both have unknown type IDs */
3739 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
3743 BT_ASSERT(ft_a
->methods
->compare
);
3744 ret
= ft_a
->methods
->compare(ft_a
, ft_b
);
3746 BT_LOGT("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
3755 int64_t bt_ctf_field_type_common_get_field_count(struct bt_ctf_field_type_common
*ft
)
3757 int64_t field_count
= -1;
3760 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3762 bt_ctf_field_type_common_structure_get_field_count(ft
);
3764 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3766 bt_ctf_field_type_common_variant_get_field_count(ft
);
3768 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3769 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3771 * Array and sequence types always contain a single member
3772 * (the element type).
3784 struct bt_ctf_field_type_common
*bt_ctf_field_type_common_borrow_field_at_index(
3785 struct bt_ctf_field_type_common
*ft
, int index
)
3787 struct bt_ctf_field_type_common
*field_type
= NULL
;
3790 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3792 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3793 ft
, NULL
, &field_type
, index
);
3800 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3802 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3803 ft
, NULL
, &field_type
, index
);
3810 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3812 bt_ctf_field_type_common_array_borrow_element_field_type(ft
);
3814 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3816 bt_ctf_field_type_common_sequence_borrow_element_field_type(ft
);
3827 int bt_ctf_field_type_common_get_field_index(struct bt_ctf_field_type_common
*ft
,
3830 int field_index
= -1;
3833 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3834 field_index
= bt_ctf_field_type_common_structure_get_field_name_index(
3837 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3838 field_index
= bt_ctf_field_type_common_variant_get_field_name_index(
3849 struct bt_ctf_field_path
*bt_ctf_field_type_common_variant_borrow_tag_field_path(
3850 struct bt_ctf_field_type_common
*ft
)
3852 struct bt_ctf_field_type_common_variant
*var_ft
= BT_CTF_FROM_COMMON(ft
);
3854 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
3855 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
3857 return var_ft
->tag_field_path
;
3861 struct bt_ctf_field_path
*bt_ctf_field_type_common_sequence_borrow_length_field_path(
3862 struct bt_ctf_field_type_common
*ft
)
3864 struct bt_ctf_field_type_common_sequence
*seq_ft
= BT_CTF_FROM_COMMON(ft
);
3866 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
3867 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
3869 return seq_ft
->length_field_path
;
3873 int bt_ctf_field_type_common_validate_single_clock_class(
3874 struct bt_ctf_field_type_common
*ft
,
3875 struct bt_ctf_clock_class
**expected_clock_class
)
3883 BT_ASSERT(expected_clock_class
);
3886 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3888 struct bt_ctf_clock_class
*mapped_clock_class
=
3889 bt_ctf_field_type_common_integer_borrow_mapped_clock_class(ft
);
3891 if (!mapped_clock_class
) {
3895 if (!*expected_clock_class
) {
3896 /* Move reference to output parameter */
3897 *expected_clock_class
= bt_ctf_object_get_ref(mapped_clock_class
);
3898 mapped_clock_class
= NULL
;
3899 BT_LOGT("Setting expected clock class: "
3900 "expected-clock-class-addr=%p",
3901 *expected_clock_class
);
3903 if (mapped_clock_class
!= *expected_clock_class
) {
3904 BT_LOGW("Integer field type is not mapped to "
3905 "the expected clock class: "
3906 "mapped-clock-class-addr=%p, "
3907 "mapped-clock-class-name=\"%s\", "
3908 "expected-clock-class-addr=%p, "
3909 "expected-clock-class-name=\"%s\"",
3911 bt_ctf_clock_class_get_name(mapped_clock_class
),
3912 *expected_clock_class
,
3913 bt_ctf_clock_class_get_name(*expected_clock_class
));
3914 bt_ctf_object_put_ref(mapped_clock_class
);
3922 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3923 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3924 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3926 struct bt_ctf_field_type_common
*sub_ft
= NULL
;
3929 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3930 sub_ft
= bt_ctf_field_type_common_enumeration_borrow_container_field_type(
3933 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3934 sub_ft
= bt_ctf_field_type_common_array_borrow_element_field_type(
3937 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3938 sub_ft
= bt_ctf_field_type_common_sequence_borrow_element_field_type(
3942 BT_LOGF("Unexpected field type ID: id=%d", ft
->id
);
3947 ret
= bt_ctf_field_type_common_validate_single_clock_class(sub_ft
,
3948 expected_clock_class
);
3951 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3954 int64_t count
= bt_ctf_field_type_common_structure_get_field_count(
3957 for (i
= 0; i
< count
; i
++) {
3959 struct bt_ctf_field_type_common
*member_type
;
3961 ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
3962 ft
, &name
, &member_type
, i
);
3963 BT_ASSERT(ret
== 0);
3964 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3965 member_type
, expected_clock_class
);
3967 BT_LOGW("Structure field type's field's type "
3968 "is not recursively mapped to the "
3969 "expected clock class: "
3970 "field-ft-addr=%p, field-name=\"%s\"",
3977 case BT_CTF_FIELD_TYPE_ID_VARIANT
:
3980 int64_t count
= bt_ctf_field_type_common_variant_get_field_count(
3983 for (i
= 0; i
< count
; i
++) {
3985 struct bt_ctf_field_type_common
*member_type
;
3987 ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
3988 ft
, &name
, &member_type
, i
);
3989 BT_ASSERT(ret
== 0);
3990 ret
= bt_ctf_field_type_common_validate_single_clock_class(
3991 member_type
, expected_clock_class
);
3993 BT_LOGW("Variant field type's field's type "
3994 "is not recursively mapped to the "
3995 "expected clock class: "
3996 "field-ft-addr=%p, field-name=\"%s\"",
4012 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4013 struct bt_ctf_field_type
*ft
);
4016 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
4017 struct bt_ctf_field_type
*ft
);
4020 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4021 struct bt_ctf_field_type
*ft
);
4024 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
4025 struct bt_ctf_field_type
*ft
);
4028 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
4029 struct bt_ctf_field_type
*ft
);
4032 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
4033 struct bt_ctf_field_type
*ft
);
4036 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
4037 struct bt_ctf_field_type
*type
);
4040 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4041 struct bt_ctf_field_type
*type
);
4043 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_integer_methods
= {
4044 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4045 .validate
= bt_ctf_field_type_common_integer_validate
,
4046 .set_byte_order
= bt_ctf_field_type_common_integer_set_byte_order
,
4047 .copy
= (bt_ctf_field_type_common_method_copy
)
4048 bt_ctf_field_type_integer_copy
,
4049 .compare
= bt_ctf_field_type_common_integer_compare
,
4052 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_floating_point_methods
= {
4053 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4055 .set_byte_order
= bt_ctf_field_type_common_floating_point_set_byte_order
,
4056 .copy
= (bt_ctf_field_type_common_method_copy
)
4057 bt_ctf_field_type_floating_point_copy
,
4058 .compare
= bt_ctf_field_type_common_floating_point_compare
,
4061 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_enumeration_methods
= {
4062 .freeze
= bt_ctf_field_type_common_enumeration_freeze_recursive
,
4063 .validate
= bt_ctf_field_type_common_enumeration_validate_recursive
,
4064 .set_byte_order
= bt_ctf_field_type_common_enumeration_set_byte_order_recursive
,
4065 .copy
= (bt_ctf_field_type_common_method_copy
)
4066 bt_ctf_field_type_enumeration_copy_recursive
,
4067 .compare
= bt_ctf_field_type_common_enumeration_compare_recursive
,
4070 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_string_methods
= {
4071 .freeze
= bt_ctf_field_type_common_generic_freeze
,
4073 .set_byte_order
= NULL
,
4074 .copy
= (bt_ctf_field_type_common_method_copy
)
4075 bt_ctf_field_type_string_copy
,
4076 .compare
= bt_ctf_field_type_common_string_compare
,
4079 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_array_methods
= {
4080 .freeze
= bt_ctf_field_type_common_array_freeze_recursive
,
4081 .validate
= bt_ctf_field_type_common_array_validate_recursive
,
4082 .set_byte_order
= bt_ctf_field_type_common_array_set_byte_order_recursive
,
4083 .copy
= (bt_ctf_field_type_common_method_copy
)
4084 bt_ctf_field_type_array_copy_recursive
,
4085 .compare
= bt_ctf_field_type_common_array_compare_recursive
,
4088 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_sequence_methods
= {
4089 .freeze
= bt_ctf_field_type_common_sequence_freeze_recursive
,
4090 .validate
= bt_ctf_field_type_common_sequence_validate_recursive
,
4091 .set_byte_order
= bt_ctf_field_type_common_sequence_set_byte_order_recursive
,
4092 .copy
= (bt_ctf_field_type_common_method_copy
)
4093 bt_ctf_field_type_sequence_copy_recursive
,
4094 .compare
= bt_ctf_field_type_common_sequence_compare_recursive
,
4097 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_structure_methods
= {
4098 .freeze
= bt_ctf_field_type_common_structure_freeze_recursive
,
4099 .validate
= bt_ctf_field_type_common_structure_validate_recursive
,
4100 .set_byte_order
= bt_ctf_field_type_common_structure_set_byte_order_recursive
,
4101 .copy
= (bt_ctf_field_type_common_method_copy
)
4102 bt_ctf_field_type_structure_copy_recursive
,
4103 .compare
= bt_ctf_field_type_common_structure_compare_recursive
,
4106 static struct bt_ctf_field_type_common_methods bt_ctf_field_type_variant_methods
= {
4107 .freeze
= bt_ctf_field_type_common_variant_freeze_recursive
,
4108 .validate
= bt_ctf_field_type_common_variant_validate_recursive
,
4109 .set_byte_order
= bt_ctf_field_type_common_variant_set_byte_order_recursive
,
4110 .copy
= (bt_ctf_field_type_common_method_copy
)
4111 bt_ctf_field_type_variant_copy_recursive
,
4112 .compare
= bt_ctf_field_type_common_variant_compare_recursive
,
4115 typedef int (*bt_ctf_field_type_serialize_func
)(struct bt_ctf_field_type_common
*,
4116 struct metadata_context
*);
4119 int bt_ctf_field_type_serialize_recursive(struct bt_ctf_field_type
*type
,
4120 struct metadata_context
*context
)
4123 struct bt_ctf_field_type_common
*type_common
= (void *) type
;
4124 bt_ctf_field_type_serialize_func serialize_func
;
4129 /* Make sure field type is valid before serializing it */
4130 ret
= bt_ctf_field_type_common_validate((void *) type
);
4132 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
4137 serialize_func
= type_common
->spec
.writer
.serialize_func
;
4138 ret
= serialize_func((void *) type
, context
);
4145 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
4147 const char *encoding_string
;
4150 case BT_CTF_STRING_ENCODING_NONE
:
4151 encoding_string
= "none";
4153 case BT_CTF_STRING_ENCODING_ASCII
:
4154 encoding_string
= "ASCII";
4156 case BT_CTF_STRING_ENCODING_UTF8
:
4157 encoding_string
= "UTF8";
4160 encoding_string
= "unknown";
4164 return encoding_string
;
4168 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
4170 const char *base_string
;
4173 case BT_CTF_INTEGER_BASE_DECIMAL
:
4174 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
4175 base_string
= "decimal";
4177 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
4178 base_string
= "hexadecimal";
4180 case BT_CTF_INTEGER_BASE_OCTAL
:
4181 base_string
= "octal";
4183 case BT_CTF_INTEGER_BASE_BINARY
:
4184 base_string
= "binary";
4187 base_string
= "unknown";
4195 void append_field_name(struct metadata_context
*context
,
4198 g_string_append_c(context
->string
, ' ');
4200 if (!bt_ctf_identifier_is_valid(name
) || *name
== '_') {
4201 g_string_append_c(context
->string
, '_');
4204 g_string_append(context
->string
, name
);
4208 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type_common
*type
,
4209 struct metadata_context
*context
)
4211 struct bt_ctf_field_type_common_integer
*integer
= BT_CTF_FROM_COMMON(type
);
4214 BT_LOGD("Serializing CTF writer integer field type's metadata: "
4215 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4216 g_string_append_printf(context
->string
,
4217 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
4218 integer
->size
, type
->alignment
,
4219 (integer
->is_signed
? "true" : "false"),
4220 get_encoding_string(integer
->encoding
),
4221 get_integer_base_string(integer
->base
),
4222 bt_ctf_get_byte_order_string(integer
->user_byte_order
));
4223 if (integer
->mapped_clock_class
) {
4224 const char *clock_name
= bt_ctf_clock_class_get_name(
4225 integer
->mapped_clock_class
);
4227 BT_ASSERT(clock_name
);
4228 g_string_append_printf(context
->string
,
4229 "; map = clock.%s.value", clock_name
);
4232 g_string_append(context
->string
, "; }");
4237 int bt_ctf_field_type_enumeration_serialize_recursive(
4238 struct bt_ctf_field_type_common
*type
,
4239 struct metadata_context
*context
)
4243 struct bt_ctf_field_type_common_enumeration
*enumeration
=
4244 BT_CTF_FROM_COMMON(type
);
4245 struct bt_ctf_field_type_common
*container_type
;
4246 int container_signed
;
4248 BT_LOGD("Serializing CTF writer enumeration field type's metadata: "
4249 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4251 bt_ctf_field_type_common_enumeration_borrow_container_field_type(type
);
4252 BT_ASSERT(container_type
);
4253 container_signed
= bt_ctf_field_type_common_integer_is_signed(
4255 BT_ASSERT(container_signed
>= 0);
4256 g_string_append(context
->string
, "enum : ");
4257 BT_LOGD_STR("Serializing CTF writer enumeration field type's container field type's metadata.");
4258 ret
= bt_ctf_field_type_serialize_recursive(
4259 (void *) enumeration
->container_ft
, context
);
4261 BT_LOGW("Cannot serialize CTF writer enumeration field type's container field type's metadata: "
4262 "container-ft-addr=%p", enumeration
->container_ft
);
4266 g_string_append(context
->string
, " { ");
4267 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
4268 struct bt_ctf_enumeration_mapping
*mapping
=
4269 enumeration
->entries
->pdata
[entry
];
4270 const char *label
= g_quark_to_string(mapping
->string
);
4272 g_string_append(context
->string
, "\"");
4274 if (!bt_ctf_identifier_is_valid(label
) || label
[0] == '_') {
4275 g_string_append(context
->string
, "_");
4278 g_string_append_printf(context
->string
, "%s\" = ", label
);
4280 if (container_signed
) {
4281 if (mapping
->range_start
._signed
==
4282 mapping
->range_end
._signed
) {
4283 g_string_append_printf(context
->string
,
4285 mapping
->range_start
._signed
);
4287 g_string_append_printf(context
->string
,
4288 "%" PRId64
" ... %" PRId64
,
4289 mapping
->range_start
._signed
,
4290 mapping
->range_end
._signed
);
4293 if (mapping
->range_start
._unsigned
==
4294 mapping
->range_end
._unsigned
) {
4295 g_string_append_printf(context
->string
,
4297 mapping
->range_start
._unsigned
);
4299 g_string_append_printf(context
->string
,
4300 "%" PRIu64
" ... %" PRIu64
,
4301 mapping
->range_start
._unsigned
,
4302 mapping
->range_end
._unsigned
);
4306 g_string_append(context
->string
,
4307 ((entry
!= (enumeration
->entries
->len
- 1)) ?
4311 if (context
->field_name
->len
) {
4312 append_field_name(context
,
4313 context
->field_name
->str
);
4314 g_string_assign(context
->field_name
, "");
4322 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type_common
*type
,
4323 struct metadata_context
*context
)
4325 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4326 BT_CTF_FROM_COMMON(type
);
4328 BT_LOGD("Serializing CTF writer floating point number field type's metadata: "
4329 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4330 g_string_append_printf(context
->string
,
4331 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
4332 floating_point
->exp_dig
,
4333 floating_point
->mant_dig
,
4334 bt_ctf_get_byte_order_string(floating_point
->user_byte_order
),
4340 int bt_ctf_field_type_structure_serialize_recursive(
4341 struct bt_ctf_field_type_common
*type
,
4342 struct metadata_context
*context
)
4345 unsigned int indent
;
4347 struct bt_ctf_field_type_common_structure
*structure
= BT_CTF_FROM_COMMON(type
);
4348 GString
*structure_field_name
= context
->field_name
;
4350 BT_LOGD("Serializing CTF writer structure field type's metadata: "
4351 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4352 context
->field_name
= g_string_new("");
4354 context
->current_indentation_level
++;
4355 g_string_append(context
->string
, "struct {\n");
4357 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4358 struct bt_ctf_field_type_common_structure_field
*field
=
4359 BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
4362 BT_LOGD("Serializing CTF writer structure field type's field metadata: "
4364 "field-ft-addr=%p, field-name=\"%s\"",
4365 i
, field
, g_quark_to_string(field
->name
));
4367 for (indent
= 0; indent
< context
->current_indentation_level
;
4369 g_string_append_c(context
->string
, '\t');
4372 g_string_assign(context
->field_name
,
4373 g_quark_to_string(field
->name
));
4374 ret
= bt_ctf_field_type_serialize_recursive(
4375 (void *) field
->type
, context
);
4377 BT_LOGW("Cannot serialize CTF writer structure field type's field's metadata: "
4379 "field-ft-addr=%p, field-name=\"%s\"",
4381 g_quark_to_string(field
->name
));
4385 if (context
->field_name
->len
) {
4386 append_field_name(context
,
4387 context
->field_name
->str
);
4389 g_string_append(context
->string
, ";\n");
4392 context
->current_indentation_level
--;
4393 for (indent
= 0; indent
< context
->current_indentation_level
;
4395 g_string_append_c(context
->string
, '\t');
4398 g_string_append_printf(context
->string
, "} align(%u)",
4402 g_string_free(context
->field_name
, TRUE
);
4403 context
->field_name
= structure_field_name
;
4408 int bt_ctf_field_type_variant_serialize_recursive(
4409 struct bt_ctf_field_type_common
*type
,
4410 struct metadata_context
*context
)
4413 unsigned int indent
;
4415 struct bt_ctf_field_type_common_variant
*variant
= BT_CTF_FROM_COMMON(type
);
4416 GString
*variant_field_name
= context
->field_name
;
4418 BT_LOGD("Serializing CTF writer variant field type's metadata: "
4419 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4420 context
->field_name
= g_string_new("");
4421 if (variant
->tag_name
->len
> 0) {
4422 g_string_append(context
->string
, "variant <");
4423 append_field_name(context
, variant
->tag_name
->str
);
4424 g_string_append(context
->string
, "> {\n");
4426 g_string_append(context
->string
, "variant {\n");
4429 context
->current_indentation_level
++;
4430 for (i
= 0; i
< variant
->choices
->len
; i
++) {
4431 struct bt_ctf_field_type_common_variant_choice
*field
=
4432 BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
4435 BT_LOGD("Serializing CTF writer variant field type's field metadata: "
4437 "field-ft-addr=%p, field-name=\"%s\"",
4438 i
, field
, g_quark_to_string(field
->name
));
4440 g_string_assign(context
->field_name
,
4441 g_quark_to_string(field
->name
));
4442 for (indent
= 0; indent
< context
->current_indentation_level
;
4444 g_string_append_c(context
->string
, '\t');
4447 g_string_assign(context
->field_name
,
4448 g_quark_to_string(field
->name
));
4449 ret
= bt_ctf_field_type_serialize_recursive(
4450 (void *) field
->type
, context
);
4452 BT_LOGW("Cannot serialize CTF writer variant field type's field's metadata: "
4454 "field-ft-addr=%p, field-name=\"%s\"",
4456 g_quark_to_string(field
->name
));
4460 if (context
->field_name
->len
) {
4461 append_field_name(context
,
4462 context
->field_name
->str
);
4463 g_string_append_c(context
->string
, ';');
4466 g_string_append_c(context
->string
, '\n');
4469 context
->current_indentation_level
--;
4470 for (indent
= 0; indent
< context
->current_indentation_level
;
4472 g_string_append_c(context
->string
, '\t');
4475 g_string_append(context
->string
, "}");
4478 g_string_free(context
->field_name
, TRUE
);
4479 context
->field_name
= variant_field_name
;
4484 int bt_ctf_field_type_array_serialize_recursive(
4485 struct bt_ctf_field_type_common
*type
,
4486 struct metadata_context
*context
)
4489 struct bt_ctf_field_type_common_array
*array
= BT_CTF_FROM_COMMON(type
);
4491 BT_LOGD("Serializing CTF writer array field type's metadata: "
4492 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4493 BT_LOGD_STR("Serializing CTF writer array field type's element field type's metadata.");
4494 ret
= bt_ctf_field_type_serialize_recursive(
4495 (void *) array
->element_ft
, context
);
4497 BT_LOGW("Cannot serialize CTF writer array field type's element field type's metadata: "
4498 "element-ft-addr=%p", array
->element_ft
);
4502 if (context
->field_name
->len
) {
4503 append_field_name(context
,
4504 context
->field_name
->str
);
4506 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4507 g_string_assign(context
->field_name
, "");
4509 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4517 int bt_ctf_field_type_sequence_serialize_recursive(
4518 struct bt_ctf_field_type_common
*type
,
4519 struct metadata_context
*context
)
4522 struct bt_ctf_field_type_common_sequence
*sequence
= BT_CTF_FROM_COMMON(type
);
4524 BT_LOGD("Serializing CTF writer sequence field type's metadata: "
4525 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4526 BT_LOGD_STR("Serializing CTF writer sequence field type's element field type's metadata.");
4527 ret
= bt_ctf_field_type_serialize_recursive(
4528 (void *) sequence
->element_ft
, context
);
4530 BT_LOGW("Cannot serialize CTF writer sequence field type's element field type's metadata: "
4531 "element-ft-addr=%p", sequence
->element_ft
);
4535 if (context
->field_name
->len
) {
4536 append_field_name(context
, context
->field_name
->str
);
4537 g_string_assign(context
->field_name
, "");
4539 g_string_append(context
->string
, "[");
4540 append_field_name(context
, sequence
->length_field_name
->str
);
4541 g_string_append(context
->string
, "]");
4548 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type_common
*type
,
4549 struct metadata_context
*context
)
4551 struct bt_ctf_field_type_common_string
*string
= BT_CTF_FROM_COMMON(type
);
4553 BT_LOGD("Serializing CTF writer string field type's metadata: "
4554 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4555 g_string_append_printf(context
->string
,
4556 "string { encoding = %s; }",
4557 get_encoding_string(string
->encoding
));
4561 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
4563 struct bt_ctf_field_type_common_integer
*integer
= NULL
;
4565 BT_LOGD("Creating CTF writer integer field type object: size=%u", size
);
4567 if (size
== 0 || size
> 64) {
4568 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
4573 integer
= g_new0(struct bt_ctf_field_type_common_integer
, 1);
4575 BT_LOGE_STR("Failed to allocate one integer field type.");
4579 bt_ctf_field_type_common_integer_initialize(BT_CTF_TO_COMMON(integer
),
4580 size
, bt_ctf_field_type_common_integer_destroy
,
4581 &bt_ctf_field_type_integer_methods
);
4582 integer
->common
.spec
.writer
.serialize_func
=
4583 bt_ctf_field_type_integer_serialize
;
4584 BT_LOGD("Created CTF writer integer field type object: addr=%p, size=%u",
4589 BT_CTF_OBJECT_PUT_REF_AND_RESET(integer
);
4592 return (void *) integer
;
4595 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*ft
)
4597 return bt_ctf_field_type_common_integer_get_size((void *) ft
);
4600 bt_ctf_bool
bt_ctf_field_type_integer_is_signed(struct bt_ctf_field_type
*ft
)
4602 return bt_ctf_field_type_common_integer_is_signed((void *) ft
);
4605 int bt_ctf_field_type_integer_set_is_signed(struct bt_ctf_field_type
*ft
,
4606 bt_ctf_bool is_signed
)
4608 return bt_ctf_field_type_common_integer_set_is_signed((void *) ft
,
4612 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*ft
,
4615 return bt_ctf_field_type_common_integer_set_size((void *) ft
, size
);
4618 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
4619 struct bt_ctf_field_type
*ft
)
4621 return (int) bt_ctf_field_type_common_integer_get_base((void *) ft
);
4624 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*ft
,
4625 enum bt_ctf_integer_base base
)
4627 return bt_ctf_field_type_common_integer_set_base((void *) ft
,
4631 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
4632 struct bt_ctf_field_type
*ft
)
4634 return (int) bt_ctf_field_type_common_integer_get_encoding((void *) ft
);
4637 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*ft
,
4638 enum bt_ctf_string_encoding encoding
)
4640 return bt_ctf_field_type_common_integer_set_encoding((void *) ft
,
4644 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
4645 struct bt_ctf_field_type
*ft
)
4647 return bt_ctf_object_get_ref(bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
4651 int bt_ctf_field_type_integer_set_mapped_clock_class(
4652 struct bt_ctf_field_type
*ft
,
4653 struct bt_ctf_clock_class
*clock_class
)
4655 return bt_ctf_field_type_common_integer_set_mapped_clock_class((void *) ft
,
4659 int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
4660 struct bt_ctf_field_type
*ft
, uint64_t index
,
4661 const char **mapping_name
, int64_t *range_begin
,
4664 return bt_ctf_field_type_common_enumeration_signed_get_mapping_by_index(
4665 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4668 int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
4669 struct bt_ctf_field_type
*ft
, uint64_t index
,
4670 const char **mapping_name
, uint64_t *range_begin
,
4671 uint64_t *range_end
)
4673 return bt_ctf_field_type_common_enumeration_unsigned_get_mapping_by_index(
4674 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
4677 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
4678 struct bt_ctf_field_type
*container_ft
)
4680 struct bt_ctf_field_type_common_enumeration
*enumeration
= NULL
;
4681 struct bt_ctf_field_type_common
*int_ft
= (void *) container_ft
;
4683 BT_LOGD("Creating CTF writer enumeration field type object: int-ft-addr=%p",
4686 if (!container_ft
) {
4687 BT_LOGW_STR("Invalid parameter: field type is NULL.");
4691 if (int_ft
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
4692 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
4693 "container-ft-addr=%p, container-ft-id=%s",
4694 container_ft
, bt_ctf_field_type_id_string(int_ft
->id
));
4698 enumeration
= g_new0(struct bt_ctf_field_type_common_enumeration
, 1);
4700 BT_LOGE_STR("Failed to allocate one enumeration field type.");
4704 bt_ctf_field_type_common_enumeration_initialize(BT_CTF_TO_COMMON(enumeration
),
4705 int_ft
, bt_ctf_field_type_common_enumeration_destroy_recursive
,
4706 &bt_ctf_field_type_enumeration_methods
);
4707 enumeration
->common
.spec
.writer
.serialize_func
=
4708 bt_ctf_field_type_enumeration_serialize_recursive
;
4709 BT_LOGD("Created CTF writer enumeration field type object: addr=%p, "
4710 "int-ft-addr=%p, int-ft-size=%u",
4711 enumeration
, container_ft
,
4712 bt_ctf_field_type_integer_get_size(container_ft
));
4716 BT_CTF_OBJECT_PUT_REF_AND_RESET(enumeration
);
4719 return (void *) enumeration
;
4722 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
4723 struct bt_ctf_field_type
*ft
)
4725 return bt_ctf_object_get_ref(
4726 bt_ctf_field_type_common_enumeration_borrow_container_field_type(
4730 int bt_ctf_field_type_enumeration_signed_add_mapping(
4731 struct bt_ctf_field_type
*ft
, const char *string
,
4732 int64_t range_start
, int64_t range_end
)
4734 return bt_ctf_field_type_common_enumeration_signed_add_mapping(
4735 (void *) ft
, string
, range_start
, range_end
);
4738 int bt_ctf_field_type_enumeration_unsigned_add_mapping(
4739 struct bt_ctf_field_type
*ft
, const char *string
,
4740 uint64_t range_start
, uint64_t range_end
)
4742 return bt_ctf_field_type_common_enumeration_unsigned_add_mapping(
4743 (void *) ft
, string
, range_start
, range_end
);
4746 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
4747 struct bt_ctf_field_type
*ft
)
4749 return bt_ctf_field_type_common_enumeration_get_mapping_count((void *) ft
);
4752 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
4754 struct bt_ctf_field_type_common_floating_point
*floating_point
=
4755 g_new0(struct bt_ctf_field_type_common_floating_point
, 1);
4757 BT_LOGD_STR("Creating CTF writer floating point number field type object.");
4759 if (!floating_point
) {
4760 BT_LOGE_STR("Failed to allocate one floating point number field type.");
4764 bt_ctf_field_type_common_floating_point_initialize(
4765 BT_CTF_TO_COMMON(floating_point
),
4766 bt_ctf_field_type_common_floating_point_destroy
,
4767 &bt_ctf_field_type_floating_point_methods
);
4768 floating_point
->common
.spec
.writer
.serialize_func
=
4769 bt_ctf_field_type_floating_point_serialize
;
4770 BT_LOGD("Created CTF writer floating point number field type object: addr=%p, "
4771 "exp-size=%u, mant-size=%u", floating_point
,
4772 floating_point
->exp_dig
, floating_point
->mant_dig
);
4775 return (void *) floating_point
;
4778 int bt_ctf_field_type_floating_point_get_exponent_digits(
4779 struct bt_ctf_field_type
*ft
)
4781 return bt_ctf_field_type_common_floating_point_get_exponent_digits(
4785 int bt_ctf_field_type_floating_point_set_exponent_digits(
4786 struct bt_ctf_field_type
*ft
, unsigned int exponent_digits
)
4788 return bt_ctf_field_type_common_floating_point_set_exponent_digits(
4789 (void *) ft
, exponent_digits
);
4792 int bt_ctf_field_type_floating_point_get_mantissa_digits(
4793 struct bt_ctf_field_type
*ft
)
4795 return bt_ctf_field_type_common_floating_point_get_mantissa_digits(
4799 int bt_ctf_field_type_floating_point_set_mantissa_digits(
4800 struct bt_ctf_field_type
*ft
, unsigned int mantissa_digits
)
4802 return bt_ctf_field_type_common_floating_point_set_mantissa_digits(
4803 (void *) ft
, mantissa_digits
);
4806 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
4808 struct bt_ctf_field_type_common_structure
*structure
=
4809 g_new0(struct bt_ctf_field_type_common_structure
, 1);
4811 BT_LOGD_STR("Creating CTF writer structure field type object.");
4814 BT_LOGE_STR("Failed to allocate one structure field type.");
4818 bt_ctf_field_type_common_structure_initialize(BT_CTF_TO_COMMON(structure
),
4819 bt_ctf_field_type_common_structure_destroy_recursive
,
4820 &bt_ctf_field_type_structure_methods
);
4821 structure
->common
.spec
.writer
.serialize_func
=
4822 bt_ctf_field_type_structure_serialize_recursive
;
4823 BT_LOGD("Created CTF writer structure field type object: addr=%p",
4828 BT_CTF_OBJECT_PUT_REF_AND_RESET(structure
);
4831 return (void *) structure
;
4834 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*ft
,
4835 struct bt_ctf_field_type
*field_type
,
4836 const char *field_name
)
4838 return bt_ctf_field_type_common_structure_add_field((void *) ft
,
4839 (void *) field_type
, field_name
);
4842 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type
*ft
)
4844 return bt_ctf_field_type_common_structure_get_field_count((void *) ft
);
4847 int bt_ctf_field_type_structure_get_field_by_index(
4848 struct bt_ctf_field_type
*ft
,
4849 const char **field_name
,
4850 struct bt_ctf_field_type
**field_type
, uint64_t index
)
4852 int ret
= bt_ctf_field_type_common_structure_borrow_field_by_index(
4853 (void *) ft
, field_name
, (void *) field_type
, index
);
4855 if (ret
== 0 && field_type
) {
4856 bt_ctf_object_get_ref(*field_type
);
4862 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
4863 struct bt_ctf_field_type
*ft
, const char *name
)
4865 return bt_ctf_object_get_ref(bt_ctf_field_type_common_structure_borrow_field_type_by_name(
4866 (void *) ft
, name
));
4869 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
4870 struct bt_ctf_field_type
*tag_ft
, const char *tag_name
)
4872 struct bt_ctf_field_type_common_variant
*var_ft
= NULL
;
4874 BT_LOGD("Creating CTF writer variant field type object: "
4875 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4878 if (tag_name
&& !bt_ctf_identifier_is_valid(tag_name
)) {
4879 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
4880 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4885 var_ft
= g_new0(struct bt_ctf_field_type_common_variant
, 1);
4887 BT_LOGE_STR("Failed to allocate one variant field type.");
4891 bt_ctf_field_type_common_variant_initialize(BT_CTF_TO_COMMON(var_ft
),
4892 (void *) tag_ft
, tag_name
,
4893 bt_ctf_field_type_common_variant_destroy_recursive
,
4894 &bt_ctf_field_type_variant_methods
);
4895 var_ft
->common
.spec
.writer
.serialize_func
=
4896 bt_ctf_field_type_variant_serialize_recursive
;
4897 BT_LOGD("Created CTF writer variant field type object: addr=%p, "
4898 "tag-ft-addr=%p, tag-field-name=\"%s\"",
4899 var_ft
, tag_ft
, tag_name
);
4903 BT_CTF_OBJECT_PUT_REF_AND_RESET(var_ft
);
4906 return (void *) var_ft
;
4909 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
4910 struct bt_ctf_field_type
*ft
)
4912 return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_tag_field_type(
4916 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type
*ft
)
4918 return bt_ctf_field_type_common_variant_get_tag_name((void *) ft
);
4921 int bt_ctf_field_type_variant_set_tag_name(
4922 struct bt_ctf_field_type
*ft
, const char *name
)
4924 return bt_ctf_field_type_common_variant_set_tag_name((void *) ft
, name
);
4927 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*ft
,
4928 struct bt_ctf_field_type
*field_type
,
4929 const char *field_name
)
4931 return bt_ctf_field_type_common_variant_add_field((void *) ft
,
4932 (void *) field_type
, field_name
);
4935 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
4936 struct bt_ctf_field_type
*ft
,
4937 const char *field_name
)
4939 return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_field_type_by_name(
4940 (void *) ft
, field_name
));
4943 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
4944 struct bt_ctf_field_type
*ft
,
4945 struct bt_ctf_field
*tag_field
)
4948 int64_t choice_index
;
4949 struct bt_ctf_field
*container
;
4950 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
4951 struct bt_ctf_field_type
*ret_ft
= NULL
;
4953 BT_CTF_ASSERT_PRE_NON_NULL(ft
, "Field type");
4954 BT_CTF_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(ft
, BT_CTF_FIELD_TYPE_ID_VARIANT
,
4956 BT_CTF_ASSERT_PRE_NON_NULL(tag_field
, "Tag field");
4957 BT_CTF_ASSERT_PRE_CTF_FIELD_COMMON_HAS_TYPE_ID(
4958 (struct bt_ctf_field_common
*) tag_field
,
4959 BT_CTF_FIELD_TYPE_ID_ENUM
, "Tag field");
4960 BT_CTF_ASSERT_PRE_CTF_FIELD_COMMON_IS_SET((struct bt_ctf_field_common
*) tag_field
,
4963 container
= bt_ctf_field_enumeration_borrow_container(tag_field
);
4964 BT_ASSERT(container
);
4966 if (var_ft
->tag_ft
->container_ft
->is_signed
) {
4969 ret
= bt_ctf_field_integer_signed_get_value(container
,
4971 BT_ASSERT(ret
== 0);
4972 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4973 (void *) ft
, (uint64_t) val
, true);
4977 ret
= bt_ctf_field_integer_unsigned_get_value(container
,
4979 BT_ASSERT(ret
== 0);
4980 choice_index
= bt_ctf_field_type_common_variant_find_choice_index(
4981 (void *) ft
, val
, false);
4984 if (choice_index
< 0) {
4985 BT_LOGW("Cannot find variant field type's field: "
4986 "var-ft-addr=%p, tag-field-addr=%p", ft
, tag_field
);
4990 ret
= bt_ctf_field_type_variant_get_field_by_index(ft
, NULL
,
4991 &ret_ft
, choice_index
);
4992 BT_ASSERT(ret
== 0);
4998 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*ft
)
5000 return bt_ctf_field_type_common_variant_get_field_count((void *) ft
);
5003 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*ft
,
5004 const char **field_name
, struct bt_ctf_field_type
**field_type
,
5007 int ret
= bt_ctf_field_type_common_variant_borrow_field_by_index(
5008 (void *) ft
, field_name
, (void *) field_type
, index
);
5010 if (ret
== 0 && field_type
) {
5011 bt_ctf_object_get_ref(*field_type
);
5017 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
5018 struct bt_ctf_field_type
*element_ft
, unsigned int length
)
5020 struct bt_ctf_field_type_common_array
*array
= NULL
;
5022 BT_LOGD("Creating CTF writer array field type object: element-ft-addr=%p, "
5023 "length=%u", element_ft
, length
);
5026 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
5031 BT_LOGW_STR("Invalid parameter: length is zero.");
5035 array
= g_new0(struct bt_ctf_field_type_common_array
, 1);
5037 BT_LOGE_STR("Failed to allocate one array field type.");
5041 bt_ctf_field_type_common_array_initialize(BT_CTF_TO_COMMON(array
),
5042 (void *) element_ft
, length
,
5043 bt_ctf_field_type_common_array_destroy_recursive
,
5044 &bt_ctf_field_type_array_methods
);
5045 array
->common
.spec
.writer
.serialize_func
=
5046 bt_ctf_field_type_array_serialize_recursive
;
5047 BT_LOGD("Created CTF writer array field type object: addr=%p, "
5048 "element-ft-addr=%p, length=%u",
5049 array
, element_ft
, length
);
5053 BT_CTF_OBJECT_PUT_REF_AND_RESET(array
);
5056 return (void *) array
;
5059 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
5060 struct bt_ctf_field_type
*ft
)
5062 return bt_ctf_object_get_ref(bt_ctf_field_type_common_array_borrow_element_field_type(
5066 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*ft
)
5068 return bt_ctf_field_type_common_array_get_length((void *) ft
);
5071 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
5072 struct bt_ctf_field_type
*element_ft
,
5073 const char *length_field_name
)
5075 struct bt_ctf_field_type_common_sequence
*sequence
= NULL
;
5077 BT_LOGD("Creating CTF writer sequence field type object: element-ft-addr=%p, "
5078 "length-field-name=\"%s\"", element_ft
, length_field_name
);
5081 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
5085 if (!bt_ctf_identifier_is_valid(length_field_name
)) {
5086 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
5087 "length-field-name=\"%s\"", length_field_name
);
5091 sequence
= g_new0(struct bt_ctf_field_type_common_sequence
, 1);
5093 BT_LOGE_STR("Failed to allocate one sequence field type.");
5097 bt_ctf_field_type_common_sequence_initialize(BT_CTF_TO_COMMON(sequence
),
5098 (void *) element_ft
, length_field_name
,
5099 bt_ctf_field_type_common_sequence_destroy_recursive
,
5100 &bt_ctf_field_type_sequence_methods
);
5101 sequence
->common
.spec
.writer
.serialize_func
=
5102 bt_ctf_field_type_sequence_serialize_recursive
;
5103 BT_LOGD("Created CTF writer sequence field type object: addr=%p, "
5104 "element-ft-addr=%p, length-field-name=\"%s\"",
5105 sequence
, element_ft
, length_field_name
);
5109 BT_CTF_OBJECT_PUT_REF_AND_RESET(sequence
);
5112 return (void *) sequence
;
5115 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
5116 struct bt_ctf_field_type
*ft
)
5118 return bt_ctf_object_get_ref(bt_ctf_field_type_common_sequence_borrow_element_field_type(
5122 const char *bt_ctf_field_type_sequence_get_length_field_name(
5123 struct bt_ctf_field_type
*ft
)
5125 return bt_ctf_field_type_common_sequence_get_length_field_name((void *) ft
);
5128 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
5130 struct bt_ctf_field_type_common_string
*string
=
5131 g_new0(struct bt_ctf_field_type_common_string
, 1);
5133 BT_LOGD_STR("Creating CTF writer string field type object.");
5136 BT_LOGE_STR("Failed to allocate one string field type.");
5140 bt_ctf_field_type_common_string_initialize(BT_CTF_TO_COMMON(string
),
5141 bt_ctf_field_type_common_string_destroy
,
5142 &bt_ctf_field_type_string_methods
);
5143 string
->common
.spec
.writer
.serialize_func
=
5144 bt_ctf_field_type_string_serialize
;
5145 BT_LOGD("Created CTF writer string field type object: addr=%p", string
);
5146 return (void *) string
;
5149 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
5150 struct bt_ctf_field_type
*ft
)
5152 return (int) bt_ctf_field_type_common_string_get_encoding((void *) ft
);
5155 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*ft
,
5156 enum bt_ctf_string_encoding encoding
)
5158 return bt_ctf_field_type_common_string_set_encoding((void *) ft
,
5162 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*ft
)
5164 return bt_ctf_field_type_common_get_alignment((void *) ft
);
5167 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*ft
,
5168 unsigned int alignment
)
5170 return bt_ctf_field_type_common_set_alignment((void *) ft
, alignment
);
5173 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
5174 struct bt_ctf_field_type
*ft
)
5176 return (int) bt_ctf_field_type_common_get_byte_order((void *) ft
);
5179 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*ft
,
5180 enum bt_ctf_byte_order byte_order
)
5182 return bt_ctf_field_type_common_set_byte_order((void *) ft
,
5186 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
5187 struct bt_ctf_field_type
*ft
)
5189 return (int) bt_ctf_field_type_common_get_type_id((void *) ft
);
5193 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*ft
)
5195 return (void *) bt_ctf_field_type_common_copy((void *) ft
);
5199 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
5200 struct bt_ctf_field_type
*ft
)
5202 struct bt_ctf_field_type_common_integer
*int_ft
= (void *) ft
;
5203 struct bt_ctf_field_type_common_integer
*copy_ft
;
5205 BT_LOGD("Copying CTF writer integer field type's: addr=%p", ft
);
5206 copy_ft
= (void *) bt_ctf_field_type_integer_create(int_ft
->size
);
5208 BT_LOGE_STR("Cannot create CTF writer integer field type.");
5212 copy_ft
->mapped_clock_class
= bt_ctf_object_get_ref(int_ft
->mapped_clock_class
);
5213 copy_ft
->user_byte_order
= int_ft
->user_byte_order
;
5214 copy_ft
->is_signed
= int_ft
->is_signed
;
5215 copy_ft
->size
= int_ft
->size
;
5216 copy_ft
->base
= int_ft
->base
;
5217 copy_ft
->encoding
= int_ft
->encoding
;
5218 BT_LOGD("Copied CTF writer integer field type: original-ft-addr=%p, copy-ft-addr=%p",
5222 return (void *) copy_ft
;
5226 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
5227 struct bt_ctf_field_type
*ft
)
5230 struct bt_ctf_field_type_common_enumeration
*enum_ft
= (void *) ft
;
5231 struct bt_ctf_field_type_common_enumeration
*copy_ft
= NULL
;
5232 struct bt_ctf_field_type_common_enumeration
*container_copy_ft
;
5234 BT_LOGD("Copying CTF writer enumeration field type's: addr=%p", ft
);
5236 /* Copy the source enumeration's container */
5237 BT_LOGD_STR("Copying CTF writer enumeration field type's container field type.");
5238 container_copy_ft
= BT_CTF_FROM_COMMON(bt_ctf_field_type_common_copy(
5239 BT_CTF_TO_COMMON(enum_ft
->container_ft
)));
5240 if (!container_copy_ft
) {
5241 BT_LOGE_STR("Cannot copy CTF writer enumeration field type's container field type.");
5245 copy_ft
= (void *) bt_ctf_field_type_enumeration_create(
5246 (void *) container_copy_ft
);
5248 BT_LOGE_STR("Cannot create CTF writer enumeration field type.");
5252 /* Copy all enumaration entries */
5253 for (i
= 0; i
< enum_ft
->entries
->len
; i
++) {
5254 struct bt_ctf_enumeration_mapping
*mapping
= g_ptr_array_index(
5255 enum_ft
->entries
, i
);
5256 struct bt_ctf_enumeration_mapping
*copy_mapping
= g_new0(
5257 struct bt_ctf_enumeration_mapping
, 1);
5259 if (!copy_mapping
) {
5260 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
5264 *copy_mapping
= *mapping
;
5265 g_ptr_array_add(copy_ft
->entries
, copy_mapping
);
5268 BT_LOGD("Copied CTF writer enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
5272 bt_ctf_object_put_ref(container_copy_ft
);
5273 return (void *) copy_ft
;
5276 bt_ctf_object_put_ref(container_copy_ft
);
5277 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5278 return (void *) copy_ft
;
5282 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
5283 struct bt_ctf_field_type
*ft
)
5285 struct bt_ctf_field_type_common_floating_point
*flt_ft
= BT_CTF_FROM_COMMON(ft
);
5286 struct bt_ctf_field_type_common_floating_point
*copy_ft
;
5288 BT_LOGD("Copying CTF writer floating point number field type's: addr=%p", ft
);
5289 copy_ft
= (void *) bt_ctf_field_type_floating_point_create();
5291 BT_LOGE_STR("Cannot create CTF writer floating point number field type.");
5295 copy_ft
->user_byte_order
= flt_ft
->user_byte_order
;
5296 copy_ft
->exp_dig
= flt_ft
->exp_dig
;
5297 copy_ft
->mant_dig
= flt_ft
->mant_dig
;
5298 BT_LOGD("Copied CTF writer floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
5302 return (void *) copy_ft
;
5306 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
5307 struct bt_ctf_field_type
*ft
)
5310 GHashTableIter iter
;
5311 gpointer key
, value
;
5312 struct bt_ctf_field_type_common_structure
*struct_ft
= (void *) ft
;
5313 struct bt_ctf_field_type_common_structure
*copy_ft
;
5315 BT_LOGD("Copying CTF writer structure field type's: addr=%p", ft
);
5316 copy_ft
= (void *) bt_ctf_field_type_structure_create();
5318 BT_LOGE_STR("Cannot create CTF writer structure field type.");
5322 /* Copy field_name_to_index */
5323 g_hash_table_iter_init(&iter
, struct_ft
->field_name_to_index
);
5324 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5325 g_hash_table_insert(copy_ft
->field_name_to_index
,
5329 g_array_set_size(copy_ft
->fields
, struct_ft
->fields
->len
);
5331 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
5332 struct bt_ctf_field_type_common_structure_field
*entry
, *copy_entry
;
5333 struct bt_ctf_field_type_common
*field_ft_copy
;
5335 entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5337 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(
5339 BT_LOGD("Copying CTF writer structure field type's field: "
5340 "index=%" PRId64
", "
5341 "field-ft-addr=%p, field-name=\"%s\"",
5342 i
, entry
, g_quark_to_string(entry
->name
));
5344 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5345 (void *) entry
->type
);
5346 if (!field_ft_copy
) {
5347 BT_LOGE("Cannot copy CTF writer structure field type's field: "
5348 "index=%" PRId64
", "
5349 "field-ft-addr=%p, field-name=\"%s\"",
5350 i
, entry
, g_quark_to_string(entry
->name
));
5354 copy_entry
->name
= entry
->name
;
5355 copy_entry
->type
= field_ft_copy
;
5358 BT_LOGD("Copied CTF writer structure field type: original-ft-addr=%p, copy-ft-addr=%p",
5362 return (void *) copy_ft
;
5365 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5370 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
5371 struct bt_ctf_field_type
*ft
)
5374 GHashTableIter iter
;
5375 gpointer key
, value
;
5376 struct bt_ctf_field_type_common
*tag_ft_copy
= NULL
;
5377 struct bt_ctf_field_type_common_variant
*var_ft
= (void *) ft
;
5378 struct bt_ctf_field_type_common_variant
*copy_ft
= NULL
;
5380 BT_LOGD("Copying CTF writer variant field type's: addr=%p", ft
);
5381 if (var_ft
->tag_ft
) {
5382 BT_LOGD_STR("Copying CTF writer variant field type's tag field type.");
5383 tag_ft_copy
= bt_ctf_field_type_common_copy(
5384 BT_CTF_TO_COMMON(var_ft
->tag_ft
));
5386 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field type.");
5391 copy_ft
= (void *) bt_ctf_field_type_variant_create(
5392 (void *) tag_ft_copy
,
5393 var_ft
->tag_name
->len
? var_ft
->tag_name
->str
: NULL
);
5395 BT_LOGE_STR("Cannot create CTF writer variant field type.");
5399 /* Copy field_name_to_index */
5400 g_hash_table_iter_init(&iter
, var_ft
->choice_name_to_index
);
5401 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
5402 g_hash_table_insert(copy_ft
->choice_name_to_index
,
5406 g_array_set_size(copy_ft
->choices
, var_ft
->choices
->len
);
5408 for (i
= 0; i
< var_ft
->choices
->len
; i
++) {
5409 struct bt_ctf_field_type_common_variant_choice
*entry
, *copy_entry
;
5410 struct bt_ctf_field_type_common
*field_ft_copy
;
5413 entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(var_ft
, i
);
5414 copy_entry
= BT_CTF_FIELD_TYPE_COMMON_VARIANT_CHOICE_AT_INDEX(
5416 BT_LOGD("Copying CTF writer variant field type's field: "
5417 "index=%" PRId64
", "
5418 "field-ft-addr=%p, field-name=\"%s\"",
5419 i
, entry
, g_quark_to_string(entry
->name
));
5421 field_ft_copy
= (void *) bt_ctf_field_type_copy(
5422 (void *) entry
->type
);
5423 if (!field_ft_copy
) {
5424 BT_LOGE("Cannot copy CTF writer variant field type's field: "
5425 "index=%" PRId64
", "
5426 "field-ft-addr=%p, field-name=\"%s\"",
5427 i
, entry
, g_quark_to_string(entry
->name
));
5432 copy_entry
->name
= entry
->name
;
5433 copy_entry
->type
= field_ft_copy
;
5436 copy_entry
->ranges
= g_array_new(FALSE
, TRUE
,
5437 sizeof(struct bt_ctf_field_type_common_variant_choice_range
));
5438 BT_ASSERT(copy_entry
->ranges
);
5439 g_array_set_size(copy_entry
->ranges
, entry
->ranges
->len
);
5441 for (range_i
= 0; range_i
< entry
->ranges
->len
; range_i
++) {
5442 copy_entry
->ranges
[range_i
] = entry
->ranges
[range_i
];
5446 if (var_ft
->tag_field_path
) {
5447 BT_LOGD_STR("Copying CTF writer variant field type's tag field path.");
5448 copy_ft
->tag_field_path
= bt_ctf_field_path_copy(
5449 var_ft
->tag_field_path
);
5450 if (!copy_ft
->tag_field_path
) {
5451 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field path.");
5456 copy_ft
->choices_up_to_date
= var_ft
->choices_up_to_date
;
5457 BT_LOGD("Copied CTF writer variant field type: original-ft-addr=%p, copy-ft-addr=%p",
5461 bt_ctf_object_put_ref(tag_ft_copy
);
5462 return (void *) copy_ft
;
5465 bt_ctf_object_put_ref(tag_ft_copy
);
5466 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5471 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
5472 struct bt_ctf_field_type
*ft
)
5474 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5475 struct bt_ctf_field_type_common_array
*array_ft
= (void *) ft
;
5476 struct bt_ctf_field_type_common_array
*copy_ft
= NULL
;
5478 BT_LOGD("Copying CTF writer array field type's: addr=%p", ft
);
5479 BT_LOGD_STR("Copying CTF writer array field type's element field type.");
5480 container_ft_copy
= bt_ctf_field_type_common_copy(array_ft
->element_ft
);
5481 if (!container_ft_copy
) {
5482 BT_LOGE_STR("Cannot copy CTF writer array field type's element field type.");
5486 copy_ft
= (void *) bt_ctf_field_type_array_create(
5487 (void *) container_ft_copy
, array_ft
->length
);
5489 BT_LOGE_STR("Cannot create CTF writer array field type.");
5493 BT_LOGD("Copied CTF writer array field type: original-ft-addr=%p, copy-ft-addr=%p",
5497 bt_ctf_object_put_ref(container_ft_copy
);
5498 return (void *) copy_ft
;
5502 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
5503 struct bt_ctf_field_type
*ft
)
5505 struct bt_ctf_field_type_common
*container_ft_copy
= NULL
;
5506 struct bt_ctf_field_type_common_sequence
*seq_ft
= (void *) ft
;
5507 struct bt_ctf_field_type_common_sequence
*copy_ft
= NULL
;
5509 BT_LOGD("Copying CTF writer sequence field type's: addr=%p", ft
);
5510 BT_LOGD_STR("Copying CTF writer sequence field type's element field type.");
5511 container_ft_copy
= bt_ctf_field_type_common_copy(seq_ft
->element_ft
);
5512 if (!container_ft_copy
) {
5513 BT_LOGE_STR("Cannot copy CTF writer sequence field type's element field type.");
5517 copy_ft
= (void *) bt_ctf_field_type_sequence_create(
5518 (void *) container_ft_copy
,
5519 seq_ft
->length_field_name
->len
?
5520 seq_ft
->length_field_name
->str
: NULL
);
5522 BT_LOGE_STR("Cannot create CTF writer sequence field type.");
5526 if (seq_ft
->length_field_path
) {
5527 BT_LOGD_STR("Copying CTF writer sequence field type's length field path.");
5528 copy_ft
->length_field_path
= bt_ctf_field_path_copy(
5529 seq_ft
->length_field_path
);
5530 if (!copy_ft
->length_field_path
) {
5531 BT_LOGE_STR("Cannot copy CTF writer sequence field type's length field path.");
5536 BT_LOGD("Copied CTF writer sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
5540 bt_ctf_object_put_ref(container_ft_copy
);
5541 return (void *) copy_ft
;
5543 bt_ctf_object_put_ref(container_ft_copy
);
5544 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft
);
5549 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(struct bt_ctf_field_type
*ft
)
5551 struct bt_ctf_field_type_common_string
*string_ft
= (void *) ft
;
5552 struct bt_ctf_field_type_common_string
*copy_ft
= NULL
;
5554 BT_LOGD("Copying CTF writer string field type's: addr=%p", ft
);
5555 copy_ft
= (void *) bt_ctf_field_type_string_create();
5557 BT_LOGE_STR("Cannot create CTF writer string field type.");
5561 copy_ft
->encoding
= string_ft
->encoding
;
5562 BT_LOGD("Copied CTF writer string field type: original-ft-addr=%p, copy-ft-addr=%p",
5566 return (void *) copy_ft
;