4 * Babeltrace CTF IR - Event Types
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "FIELD-TYPES"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/ctf-ir/field-types-internal.h>
33 #include <babeltrace/ctf-ir/field-path-internal.h>
34 #include <babeltrace/ctf-ir/utils.h>
35 #include <babeltrace/ref.h>
36 #include <babeltrace/ctf-ir/clock-class.h>
37 #include <babeltrace/ctf-ir/clock-class-internal.h>
38 #include <babeltrace/ctf-writer/writer-internal.h>
39 #include <babeltrace/object-internal.h>
40 #include <babeltrace/ref.h>
41 #include <babeltrace/compiler-internal.h>
42 #include <babeltrace/endian-internal.h>
43 #include <babeltrace/assert-internal.h>
48 struct range_overlap_query
{
63 void bt_field_type_destroy(struct bt_object
*);
65 void bt_field_type_integer_destroy(struct bt_field_type
*);
67 void bt_field_type_enumeration_destroy(struct bt_field_type
*);
69 void bt_field_type_floating_point_destroy(struct bt_field_type
*);
71 void bt_field_type_structure_destroy(struct bt_field_type
*);
73 void bt_field_type_variant_destroy(struct bt_field_type
*);
75 void bt_field_type_array_destroy(struct bt_field_type
*);
77 void bt_field_type_sequence_destroy(struct bt_field_type
*);
79 void bt_field_type_string_destroy(struct bt_field_type
*);
82 void (* const type_destroy_funcs
[])(struct bt_field_type
*) = {
83 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_type_integer_destroy
,
84 [BT_FIELD_TYPE_ID_ENUM
] =
85 bt_field_type_enumeration_destroy
,
86 [BT_FIELD_TYPE_ID_FLOAT
] =
87 bt_field_type_floating_point_destroy
,
88 [BT_FIELD_TYPE_ID_STRUCT
] = bt_field_type_structure_destroy
,
89 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_type_variant_destroy
,
90 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_type_array_destroy
,
91 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_type_sequence_destroy
,
92 [BT_FIELD_TYPE_ID_STRING
] = bt_field_type_string_destroy
,
96 void generic_field_type_freeze(struct bt_field_type
*);
98 void bt_field_type_integer_freeze(struct bt_field_type
*);
100 void bt_field_type_enumeration_freeze(struct bt_field_type
*);
102 void bt_field_type_structure_freeze(struct bt_field_type
*);
104 void bt_field_type_variant_freeze(struct bt_field_type
*);
106 void bt_field_type_array_freeze(struct bt_field_type
*);
108 void bt_field_type_sequence_freeze(struct bt_field_type
*);
111 type_freeze_func
const type_freeze_funcs
[] = {
112 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_type_integer_freeze
,
113 [BT_FIELD_TYPE_ID_ENUM
] = bt_field_type_enumeration_freeze
,
114 [BT_FIELD_TYPE_ID_FLOAT
] = generic_field_type_freeze
,
115 [BT_FIELD_TYPE_ID_STRUCT
] = bt_field_type_structure_freeze
,
116 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_type_variant_freeze
,
117 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_type_array_freeze
,
118 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_type_sequence_freeze
,
119 [BT_FIELD_TYPE_ID_STRING
] = generic_field_type_freeze
,
123 int bt_field_type_integer_serialize(struct bt_field_type
*,
124 struct metadata_context
*);
126 int bt_field_type_enumeration_serialize(struct bt_field_type
*,
127 struct metadata_context
*);
129 int bt_field_type_floating_point_serialize(
130 struct bt_field_type
*, struct metadata_context
*);
132 int bt_field_type_structure_serialize(struct bt_field_type
*,
133 struct metadata_context
*);
135 int bt_field_type_variant_serialize(struct bt_field_type
*,
136 struct metadata_context
*);
138 int bt_field_type_array_serialize(struct bt_field_type
*,
139 struct metadata_context
*);
141 int bt_field_type_sequence_serialize(struct bt_field_type
*,
142 struct metadata_context
*);
144 int bt_field_type_string_serialize(struct bt_field_type
*,
145 struct metadata_context
*);
148 type_serialize_func
const type_serialize_funcs
[] = {
149 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_type_integer_serialize
,
150 [BT_FIELD_TYPE_ID_ENUM
] =
151 bt_field_type_enumeration_serialize
,
152 [BT_FIELD_TYPE_ID_FLOAT
] =
153 bt_field_type_floating_point_serialize
,
154 [BT_FIELD_TYPE_ID_STRUCT
] =
155 bt_field_type_structure_serialize
,
156 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_type_variant_serialize
,
157 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_type_array_serialize
,
158 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_type_sequence_serialize
,
159 [BT_FIELD_TYPE_ID_STRING
] = bt_field_type_string_serialize
,
163 void bt_field_type_integer_set_byte_order(struct bt_field_type
*,
164 enum bt_byte_order byte_order
);
166 void bt_field_type_enumeration_set_byte_order(struct bt_field_type
*,
167 enum bt_byte_order byte_order
);
169 void bt_field_type_floating_point_set_byte_order(
170 struct bt_field_type
*, enum bt_byte_order byte_order
);
172 void bt_field_type_structure_set_byte_order(struct bt_field_type
*,
173 enum bt_byte_order byte_order
);
175 void bt_field_type_variant_set_byte_order(struct bt_field_type
*,
176 enum bt_byte_order byte_order
);
178 void bt_field_type_array_set_byte_order(struct bt_field_type
*,
179 enum bt_byte_order byte_order
);
181 void bt_field_type_sequence_set_byte_order(struct bt_field_type
*,
182 enum bt_byte_order byte_order
);
185 void (* const set_byte_order_funcs
[])(struct bt_field_type
*,
186 enum bt_byte_order
) = {
187 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_type_integer_set_byte_order
,
188 [BT_FIELD_TYPE_ID_ENUM
] =
189 bt_field_type_enumeration_set_byte_order
,
190 [BT_FIELD_TYPE_ID_FLOAT
] =
191 bt_field_type_floating_point_set_byte_order
,
192 [BT_FIELD_TYPE_ID_STRUCT
] =
193 bt_field_type_structure_set_byte_order
,
194 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_type_variant_set_byte_order
,
195 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_type_array_set_byte_order
,
196 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_type_sequence_set_byte_order
,
197 [BT_FIELD_TYPE_ID_STRING
] = NULL
,
201 struct bt_field_type
*bt_field_type_integer_copy(
202 struct bt_field_type
*);
204 struct bt_field_type
*bt_field_type_enumeration_copy(
205 struct bt_field_type
*);
207 struct bt_field_type
*bt_field_type_floating_point_copy(
208 struct bt_field_type
*);
210 struct bt_field_type
*bt_field_type_structure_copy(
211 struct bt_field_type
*);
213 struct bt_field_type
*bt_field_type_variant_copy(
214 struct bt_field_type
*);
216 struct bt_field_type
*bt_field_type_array_copy(
217 struct bt_field_type
*);
219 struct bt_field_type
*bt_field_type_sequence_copy(
220 struct bt_field_type
*);
222 struct bt_field_type
*bt_field_type_string_copy(
223 struct bt_field_type
*);
226 struct bt_field_type
*(* const type_copy_funcs
[])(
227 struct bt_field_type
*) = {
228 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_type_integer_copy
,
229 [BT_FIELD_TYPE_ID_ENUM
] = bt_field_type_enumeration_copy
,
230 [BT_FIELD_TYPE_ID_FLOAT
] = bt_field_type_floating_point_copy
,
231 [BT_FIELD_TYPE_ID_STRUCT
] = bt_field_type_structure_copy
,
232 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_type_variant_copy
,
233 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_type_array_copy
,
234 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_type_sequence_copy
,
235 [BT_FIELD_TYPE_ID_STRING
] = bt_field_type_string_copy
,
239 int bt_field_type_integer_compare(struct bt_field_type
*,
240 struct bt_field_type
*);
242 int bt_field_type_floating_point_compare(struct bt_field_type
*,
243 struct bt_field_type
*);
245 int bt_field_type_enumeration_compare(struct bt_field_type
*,
246 struct bt_field_type
*);
248 int bt_field_type_string_compare(struct bt_field_type
*,
249 struct bt_field_type
*);
251 int bt_field_type_structure_compare(struct bt_field_type
*,
252 struct bt_field_type
*);
254 int bt_field_type_variant_compare(struct bt_field_type
*,
255 struct bt_field_type
*);
257 int bt_field_type_array_compare(struct bt_field_type
*,
258 struct bt_field_type
*);
260 int bt_field_type_sequence_compare(struct bt_field_type
*,
261 struct bt_field_type
*);
264 int (* const type_compare_funcs
[])(struct bt_field_type
*,
265 struct bt_field_type
*) = {
266 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_type_integer_compare
,
267 [BT_FIELD_TYPE_ID_ENUM
] = bt_field_type_enumeration_compare
,
268 [BT_FIELD_TYPE_ID_FLOAT
] = bt_field_type_floating_point_compare
,
269 [BT_FIELD_TYPE_ID_STRUCT
] = bt_field_type_structure_compare
,
270 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_type_variant_compare
,
271 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_type_array_compare
,
272 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_type_sequence_compare
,
273 [BT_FIELD_TYPE_ID_STRING
] = bt_field_type_string_compare
,
277 int bt_field_type_integer_validate(struct bt_field_type
*);
279 int bt_field_type_enumeration_validate(struct bt_field_type
*);
281 int bt_field_type_structure_validate(struct bt_field_type
*);
283 int bt_field_type_variant_validate(struct bt_field_type
*);
285 int bt_field_type_array_validate(struct bt_field_type
*);
287 int bt_field_type_sequence_validate(struct bt_field_type
*);
290 int (* const type_validate_funcs
[])(struct bt_field_type
*) = {
291 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_type_integer_validate
,
292 [BT_FIELD_TYPE_ID_FLOAT
] = NULL
,
293 [BT_FIELD_TYPE_ID_STRING
] = NULL
,
294 [BT_FIELD_TYPE_ID_ENUM
] = bt_field_type_enumeration_validate
,
295 [BT_FIELD_TYPE_ID_STRUCT
] = bt_field_type_structure_validate
,
296 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_type_variant_validate
,
297 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_type_array_validate
,
298 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_type_sequence_validate
,
302 void destroy_enumeration_mapping(struct enumeration_mapping
*mapping
)
308 void destroy_structure_field(struct structure_field
*field
)
314 BT_LOGD("Destroying structure/variant field type's field object: "
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.");
323 void check_ranges_overlap(gpointer element
, gpointer query
)
325 struct enumeration_mapping
*mapping
= element
;
326 struct range_overlap_query
*overlap_query
= query
;
328 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
329 && overlap_query
->range_start
._signed
<=
330 mapping
->range_end
._signed
) {
331 overlap_query
->overlaps
= 1;
332 overlap_query
->mapping_name
= mapping
->string
;
335 overlap_query
->overlaps
|=
336 mapping
->string
== overlap_query
->mapping_name
;
338 if (overlap_query
->overlaps
) {
339 BT_LOGV("Overlapping enumeration field type mappings: "
340 "mapping-name=\"%s\", "
341 "mapping-a-range-start=%" PRId64
", "
342 "mapping-a-range-end=%" PRId64
", "
343 "mapping-b-range-start=%" PRId64
", "
344 "mapping-b-range-end=%" PRId64
,
345 g_quark_to_string(mapping
->string
),
346 mapping
->range_start
._signed
,
347 mapping
->range_end
._signed
,
348 overlap_query
->range_start
._signed
,
349 overlap_query
->range_end
._signed
);
354 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
356 struct enumeration_mapping
*mapping
= element
;
357 struct range_overlap_query
*overlap_query
= query
;
359 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
360 && overlap_query
->range_start
._unsigned
<=
361 mapping
->range_end
._unsigned
) {
362 overlap_query
->overlaps
= 1;
363 overlap_query
->mapping_name
= mapping
->string
;
366 overlap_query
->overlaps
|=
367 mapping
->string
== overlap_query
->mapping_name
;
369 if (overlap_query
->overlaps
) {
370 BT_LOGW("Overlapping enumeration field type mappings: "
371 "mapping-name=\"%s\", "
372 "mapping-a-range-start=%" PRIu64
", "
373 "mapping-a-range-end=%" PRIu64
", "
374 "mapping-b-range-start=%" PRIu64
", "
375 "mapping-b-range-end=%" PRIu64
,
376 g_quark_to_string(mapping
->string
),
377 mapping
->range_start
._unsigned
,
378 mapping
->range_end
._unsigned
,
379 overlap_query
->range_start
._unsigned
,
380 overlap_query
->range_end
._unsigned
);
385 gint
compare_enumeration_mappings_signed(struct enumeration_mapping
**a
,
386 struct enumeration_mapping
**b
)
388 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
392 gint
compare_enumeration_mappings_unsigned(struct enumeration_mapping
**a
,
393 struct enumeration_mapping
**b
)
395 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
399 void bt_field_type_init(struct bt_field_type
*type
, bt_bool init_bo
)
401 BT_ASSERT(type
&& (type
->id
> BT_FIELD_TYPE_ID_UNKNOWN
) &&
402 (type
->id
< BT_FIELD_TYPE_ID_NR
));
404 bt_object_init(type
, bt_field_type_destroy
);
405 type
->freeze
= type_freeze_funcs
[type
->id
];
406 type
->serialize
= type_serialize_funcs
[type
->id
];
410 const enum bt_byte_order bo
= BT_BYTE_ORDER_NATIVE
;
412 BT_LOGD("Setting initial field type's byte order: bo=%s",
413 bt_byte_order_string(bo
));
414 ret
= bt_field_type_set_byte_order(type
, bo
);
422 int add_structure_field(GPtrArray
*fields
,
423 GHashTable
*field_name_to_index
,
424 struct bt_field_type
*field_type
,
425 const char *field_name
)
428 GQuark name_quark
= g_quark_from_string(field_name
);
429 struct structure_field
*field
;
431 /* Make sure structure does not contain a field of the same name */
432 if (g_hash_table_lookup_extended(field_name_to_index
,
433 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
434 BT_LOGW("Structure or variant field type already contains a field type with this name: "
435 "field-name=\"%s\"", field_name
);
440 field
= g_new0(struct structure_field
, 1);
442 BT_LOGE_STR("Failed to allocate one structure/variant field type field.");
448 field
->name
= name_quark
;
449 field
->type
= field_type
;
450 g_hash_table_insert(field_name_to_index
,
451 GUINT_TO_POINTER(name_quark
),
452 GUINT_TO_POINTER(fields
->len
));
453 g_ptr_array_add(fields
, field
);
454 BT_LOGV("Added structure/variant field type field: field-ft-addr=%p, "
455 "field-name=\"%s\"", field_type
, field_name
);
461 void bt_field_type_destroy(struct bt_object
*obj
)
463 struct bt_field_type
*type
;
464 enum bt_field_type_id type_id
;
466 type
= container_of(obj
, struct bt_field_type
, base
);
468 BT_ASSERT(type_id
> BT_FIELD_TYPE_ID_UNKNOWN
&&
469 type_id
< BT_FIELD_TYPE_ID_NR
);
470 type_destroy_funcs
[type_id
](type
);
474 int bt_field_type_integer_validate(struct bt_field_type
*type
)
478 struct bt_field_type_integer
*integer
=
479 container_of(type
, struct bt_field_type_integer
,
482 if (integer
->mapped_clock
&& integer
->is_signed
) {
483 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
484 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
485 type
, integer
->mapped_clock
,
486 bt_clock_class_get_name(integer
->mapped_clock
));
496 struct enumeration_mapping
*get_enumeration_mapping(
497 struct bt_field_type
*type
, uint64_t index
)
499 struct enumeration_mapping
*mapping
= NULL
;
500 struct bt_field_type_enumeration
*enumeration
;
502 enumeration
= container_of(type
, struct bt_field_type_enumeration
,
504 if (index
>= enumeration
->entries
->len
) {
505 BT_LOGW("Invalid parameter: index is out of bounds: "
506 "addr=%p, index=%" PRIu64
", count=%u",
507 type
, index
, enumeration
->entries
->len
);
511 mapping
= g_ptr_array_index(enumeration
->entries
, index
);
517 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
518 * Only used when freezing an enumeration.
521 void set_enumeration_range_overlap(
522 struct bt_field_type
*type
)
525 struct bt_field_type
*container_type
;
526 struct bt_field_type_enumeration
*enumeration_type
;
529 BT_LOGV("Setting enumeration field type's overlap flag: addr=%p",
531 enumeration_type
= container_of(type
,
532 struct bt_field_type_enumeration
, parent
);
534 len
= enumeration_type
->entries
->len
;
535 container_type
= enumeration_type
->container
;
536 is_signed
= bt_field_type_integer_is_signed(container_type
);
538 for (i
= 0; i
< len
; i
++) {
539 for (j
= i
+ 1; j
< len
; j
++) {
540 struct enumeration_mapping
*mapping
[2];
542 mapping
[0] = get_enumeration_mapping(type
, i
);
543 mapping
[1] = get_enumeration_mapping(type
, j
);
545 if (mapping
[0]->range_start
._signed
546 <= mapping
[1]->range_end
._signed
547 && mapping
[0]->range_end
._signed
548 >= mapping
[1]->range_start
._signed
) {
549 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
553 if (mapping
[0]->range_start
._unsigned
554 <= mapping
[1]->range_end
._unsigned
555 && mapping
[0]->range_end
._unsigned
556 >= mapping
[1]->range_start
._unsigned
) {
557 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
565 if (enumeration_type
->has_overlapping_ranges
) {
566 BT_LOGV_STR("Enumeration field type has overlapping ranges.");
568 BT_LOGV_STR("Enumeration field type has no overlapping ranges.");
573 int bt_field_type_enumeration_validate(struct bt_field_type
*type
)
577 struct bt_field_type_enumeration
*enumeration
=
578 container_of(type
, struct bt_field_type_enumeration
,
580 struct bt_field_type
*container_type
=
581 bt_field_type_enumeration_get_container_type(type
);
583 BT_ASSERT(container_type
);
584 ret
= bt_field_type_validate(container_type
);
586 BT_LOGW("Invalid enumeration field type: container type is invalid: "
587 "enum-ft-addr=%p, int-ft-addr=%p",
588 type
, container_type
);
592 /* Ensure enum has entries */
593 if (enumeration
->entries
->len
== 0) {
594 BT_LOGW("Invalid enumeration field type: no entries: "
601 BT_PUT(container_type
);
606 int bt_field_type_sequence_validate(struct bt_field_type
*type
)
609 struct bt_field_type
*element_type
= NULL
;
610 struct bt_field_type_sequence
*sequence
=
611 container_of(type
, struct bt_field_type_sequence
,
614 /* Length field name should be set at this point */
615 if (sequence
->length_field_name
->len
== 0) {
616 BT_LOGW("Invalid sequence field type: no length field name: "
622 element_type
= bt_field_type_sequence_get_element_type(type
);
623 BT_ASSERT(element_type
);
624 ret
= bt_field_type_validate(element_type
);
626 BT_LOGW("Invalid sequence field type: invalid element field type: "
627 "seq-ft-addr=%p, element-ft-add=%p",
632 BT_PUT(element_type
);
638 int bt_field_type_array_validate(struct bt_field_type
*type
)
641 struct bt_field_type
*element_type
= NULL
;
643 element_type
= bt_field_type_array_get_element_type(type
);
644 BT_ASSERT(element_type
);
645 ret
= bt_field_type_validate(element_type
);
647 BT_LOGW("Invalid array field type: invalid element field type: "
648 "array-ft-addr=%p, element-ft-add=%p",
652 BT_PUT(element_type
);
657 int bt_field_type_structure_validate(struct bt_field_type
*type
)
660 struct bt_field_type
*child_type
= NULL
;
661 int64_t field_count
= bt_field_type_structure_get_field_count(type
);
664 BT_ASSERT(field_count
>= 0);
666 for (i
= 0; i
< field_count
; ++i
) {
667 const char *field_name
;
669 ret
= bt_field_type_structure_get_field_by_index(type
,
670 &field_name
, &child_type
, i
);
672 ret
= bt_field_type_validate(child_type
);
674 BT_LOGW("Invalid structure field type: "
675 "a contained field type is invalid: "
676 "struct-ft-addr=%p, field-ft-addr=%p, "
677 "field-name=\"%s\", field-index=%" PRId64
,
678 type
, child_type
, field_name
, i
);
692 bt_bool
bt_field_type_enumeration_has_overlapping_ranges(
693 struct bt_field_type_enumeration
*enumeration_type
)
695 if (!enumeration_type
->parent
.frozen
) {
696 set_enumeration_range_overlap(&enumeration_type
->parent
);
698 return enumeration_type
->has_overlapping_ranges
;
702 int bt_field_type_variant_validate(struct bt_field_type
*type
)
706 struct bt_field_type
*child_type
= NULL
;
707 struct bt_field_type_variant
*variant
=
708 container_of(type
, struct bt_field_type_variant
,
712 if (variant
->tag_name
->len
== 0) {
713 BT_LOGW("Invalid variant field type: no tag field name: "
720 BT_LOGW("Invalid variant field type: no tag field type: "
721 "addr=%p, tag-field-name=\"%s\"", type
,
722 variant
->tag_name
->str
);
727 if (bt_field_type_enumeration_has_overlapping_ranges(
729 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
730 "variant-ft-addr=%p, tag-field-name=\"%s\", "
731 "enum-ft-addr=%p", type
, variant
->tag_name
->str
,
738 * It is valid to have a variant field type which does not have
739 * the fields corresponding to each label in the associated
742 * It is also valid to have variant field type fields which
743 * cannot be selected because the variant field type tag has no
744 * mapping named as such. This scenario, while not ideal, cannot
747 * If a non-existing field happens to be selected by an
748 * enumeration while reading a variant field, an error will be
749 * generated at that point (while reading the stream).
751 field_count
= bt_field_type_variant_get_field_count(type
);
752 if (field_count
< 0) {
753 BT_LOGW("Invalid variant field type: no fields: "
754 "addr=%p, tag-field-name=\"%s\"",
755 type
, variant
->tag_name
->str
);
760 for (i
= 0; i
< field_count
; ++i
) {
761 const char *field_name
;
763 ret
= bt_field_type_variant_get_field_by_index(type
,
764 &field_name
, &child_type
, i
);
766 ret
= bt_field_type_validate(child_type
);
768 BT_LOGW("Invalid variant field type: "
769 "a contained field type is invalid: "
770 "variant-ft-addr=%p, tag-field-name=\"%s\", "
771 "field-ft-addr=%p, field-name=\"%s\", "
772 "field-index=%" PRId64
,
773 type
, variant
->tag_name
->str
, child_type
,
788 * This function validates a given field type without considering
789 * where this field type is located. It only validates the properties
790 * of the given field type and the properties of its children if
794 int bt_field_type_validate(struct bt_field_type
*type
)
797 enum bt_field_type_id id
= bt_field_type_get_type_id(type
);
802 /* Already marked as valid */
806 if (type_validate_funcs
[id
]) {
807 ret
= type_validate_funcs
[id
](type
);
810 if (!ret
&& type
->frozen
) {
811 /* Field type is valid */
812 BT_LOGV("Marking field type as valid: addr=%p", type
);
820 struct bt_field_type
*bt_field_type_integer_create(unsigned int size
)
822 struct bt_field_type_integer
*integer
=
823 g_new0(struct bt_field_type_integer
, 1);
825 BT_LOGD("Creating integer field type object: size=%u", size
);
828 BT_LOGE_STR("Failed to allocate one integer field type.");
832 if (size
== 0 || size
> 64) {
833 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
838 integer
->parent
.id
= BT_FIELD_TYPE_ID_INTEGER
;
839 integer
->size
= size
;
840 integer
->base
= BT_INTEGER_BASE_DECIMAL
;
841 integer
->encoding
= BT_STRING_ENCODING_NONE
;
842 bt_field_type_init(&integer
->parent
, TRUE
);
843 BT_LOGD("Created integer field type object: addr=%p, size=%u",
844 &integer
->parent
, size
);
845 return &integer
->parent
;
848 int bt_field_type_integer_get_size(struct bt_field_type
*type
)
851 struct bt_field_type_integer
*integer
;
854 BT_LOGW_STR("Invalid parameter: field type is NULL.");
859 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
860 BT_LOGW("Invalid parameter: field type is not an integer field type: "
861 "addr=%p, ft-id=%s", type
,
862 bt_field_type_id_string(type
->id
));
867 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
868 ret
= (int) integer
->size
;
873 int bt_ctf_field_type_integer_get_signed(struct bt_field_type
*type
)
876 struct bt_field_type_integer
*integer
;
879 BT_LOGW_STR("Invalid parameter: field type is NULL.");
884 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
885 BT_LOGW("Invalid parameter: field type is not an integer field type: "
886 "addr=%p, ft-id=%s", type
,
887 bt_field_type_id_string(type
->id
));
892 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
893 ret
= integer
->is_signed
;
898 bt_bool
bt_field_type_integer_is_signed(
899 struct bt_field_type
*int_field_type
)
901 return bt_ctf_field_type_integer_get_signed(int_field_type
) ?
905 int bt_field_type_integer_set_is_signed(struct bt_field_type
*type
,
909 struct bt_field_type_integer
*integer
;
912 BT_LOGW_STR("Invalid parameter: field type is NULL.");
918 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
924 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
925 BT_LOGW("Invalid parameter: field type is not an integer field type: "
926 "addr=%p, ft-id=%s", type
,
927 bt_field_type_id_string(type
->id
));
932 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
933 integer
->is_signed
= !!is_signed
;
934 BT_LOGV("Set integer field type's signedness: addr=%p, is-signed=%d",
940 int bt_field_type_integer_set_size(struct bt_field_type
*type
,
944 struct bt_field_type_integer
*integer
;
947 BT_LOGW_STR("Invalid parameter: field type is NULL.");
953 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
959 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
960 BT_LOGW("Invalid parameter: field type is not an integer field type: "
961 "addr=%p, ft-id=%s", type
,
962 bt_field_type_id_string(type
->id
));
967 if (size
== 0 || size
> 64) {
968 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
969 "addr=%p, size=%u", type
, size
);
974 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
975 integer
->size
= size
;
976 BT_LOGV("Set integer field type's size: addr=%p, size=%u",
982 enum bt_integer_base
bt_field_type_integer_get_base(
983 struct bt_field_type
*type
)
985 enum bt_integer_base ret
= BT_INTEGER_BASE_UNKNOWN
;
986 struct bt_field_type_integer
*integer
;
989 BT_LOGW_STR("Invalid parameter: field type is NULL.");
993 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
994 BT_LOGW("Invalid parameter: field type is not an integer field type: "
995 "addr=%p, ft-id=%s", type
,
996 bt_field_type_id_string(type
->id
));
1000 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
1001 ret
= integer
->base
;
1006 int bt_field_type_integer_set_base(struct bt_field_type
*type
,
1007 enum bt_integer_base base
)
1012 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1018 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1024 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1025 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1026 "addr=%p, ft-id=%s", type
,
1027 bt_field_type_id_string(type
->id
));
1033 case BT_INTEGER_BASE_UNSPECIFIED
:
1034 case BT_INTEGER_BASE_BINARY
:
1035 case BT_INTEGER_BASE_OCTAL
:
1036 case BT_INTEGER_BASE_DECIMAL
:
1037 case BT_INTEGER_BASE_HEXADECIMAL
:
1039 struct bt_field_type_integer
*integer
= container_of(type
,
1040 struct bt_field_type_integer
, parent
);
1041 integer
->base
= base
;
1045 BT_LOGW("Invalid parameter: unknown integer field type base: "
1046 "addr=%p, base=%d", type
, base
);
1050 BT_LOGV("Set integer field type's base: addr=%p, base=%s",
1051 type
, bt_integer_base_string(base
));
1057 enum bt_string_encoding
bt_field_type_integer_get_encoding(
1058 struct bt_field_type
*type
)
1060 enum bt_string_encoding ret
= BT_STRING_ENCODING_UNKNOWN
;
1061 struct bt_field_type_integer
*integer
;
1064 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1068 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1069 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1070 "addr=%p, ft-id=%s", type
,
1071 bt_field_type_id_string(type
->id
));
1075 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
1076 ret
= integer
->encoding
;
1081 int bt_field_type_integer_set_encoding(struct bt_field_type
*type
,
1082 enum bt_string_encoding encoding
)
1085 struct bt_field_type_integer
*integer
;
1088 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1094 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1100 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1101 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1102 "addr=%p, ft-id=%s", type
,
1103 bt_field_type_id_string(type
->id
));
1108 if (encoding
!= BT_STRING_ENCODING_UTF8
&&
1109 encoding
!= BT_STRING_ENCODING_ASCII
&&
1110 encoding
!= BT_STRING_ENCODING_NONE
) {
1111 BT_LOGW("Invalid parameter: unknown string encoding: "
1112 "addr=%p, encoding=%d", type
, encoding
);
1117 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
1118 integer
->encoding
= encoding
;
1119 BT_LOGV("Set integer field type's encoding: addr=%p, encoding=%s",
1120 type
, bt_string_encoding_string(encoding
));
1125 struct bt_clock_class
*bt_field_type_integer_get_mapped_clock_class(
1126 struct bt_field_type
*type
)
1128 struct bt_field_type_integer
*integer
;
1129 struct bt_clock_class
*clock_class
= NULL
;
1132 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1136 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
1137 clock_class
= integer
->mapped_clock
;
1138 bt_get(clock_class
);
1144 int bt_field_type_integer_set_mapped_clock_class_no_check(
1145 struct bt_field_type
*type
,
1146 struct bt_clock_class
*clock_class
)
1148 struct bt_field_type_integer
*integer
;
1152 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1158 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1163 if (type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1164 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1165 "addr=%p, ft-id=%s", type
,
1166 bt_field_type_id_string(type
->id
));
1170 if (!bt_clock_class_is_valid(clock_class
)) {
1171 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1172 "clock-class-addr=%p, clock-class-name=\"%s\"",
1174 bt_clock_class_get_name(clock_class
));
1179 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
1180 bt_put(integer
->mapped_clock
);
1181 integer
->mapped_clock
= bt_get(clock_class
);
1182 BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
1183 "clock-class-addr=%p, clock-class-name=\"%s\"",
1184 type
, clock_class
, bt_clock_class_get_name(clock_class
));
1189 int bt_field_type_integer_set_mapped_clock_class(
1190 struct bt_field_type
*type
,
1191 struct bt_clock_class
*clock_class
)
1196 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1202 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1208 ret
= bt_field_type_integer_set_mapped_clock_class_no_check(
1216 void bt_field_type_enum_iter_destroy(struct bt_object
*obj
)
1218 struct bt_field_type_enumeration_mapping_iterator
*iter
=
1220 struct bt_field_type_enumeration_mapping_iterator
,
1223 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
1225 BT_LOGD_STR("Putting parent enumeration field type.");
1226 bt_put(&iter
->enumeration_type
->parent
);
1231 struct bt_field_type_enumeration_mapping_iterator
*
1232 bt_field_type_enumeration_find_mappings_type(
1233 struct bt_field_type
*type
,
1234 enum bt_field_type_enumeration_mapping_iterator_type iterator_type
)
1236 struct bt_field_type_enumeration
*enumeration_type
;
1237 struct bt_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1240 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1244 if (type
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
1245 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1246 "addr=%p, ft-id=%s", type
,
1247 bt_field_type_id_string(type
->id
));
1251 enumeration_type
= container_of(type
,
1252 struct bt_field_type_enumeration
, parent
);
1253 iter
= g_new0(struct bt_field_type_enumeration_mapping_iterator
, 1);
1255 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
1259 bt_object_init(&iter
->base
, bt_field_type_enum_iter_destroy
);
1261 iter
->enumeration_type
= enumeration_type
;
1263 iter
->type
= iterator_type
;
1268 struct bt_field_type_enumeration_mapping_iterator
*
1269 bt_field_type_enumeration_find_mappings_by_name(
1270 struct bt_field_type
*type
, const char *name
)
1272 struct bt_field_type_enumeration_mapping_iterator
*iter
;
1274 iter
= bt_field_type_enumeration_find_mappings_type(
1275 type
, ITERATOR_BY_NAME
);
1277 BT_LOGW("Cannot create enumeration field type mapping iterator: "
1278 "ft-addr=%p, mapping-name=\"%s\"", type
, name
);
1282 iter
->u
.name_quark
= g_quark_try_string(name
);
1283 if (!iter
->u
.name_quark
) {
1285 * No results are possible, set the iterator's position at the
1288 iter
->index
= iter
->enumeration_type
->entries
->len
;
1296 int bt_field_type_enumeration_mapping_iterator_next(
1297 struct bt_field_type_enumeration_mapping_iterator
*iter
)
1299 struct bt_field_type_enumeration
*enumeration
;
1300 struct bt_field_type
*type
;
1301 int i
, ret
= 0, len
;
1304 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1309 enumeration
= iter
->enumeration_type
;
1310 type
= &enumeration
->parent
;
1311 len
= enumeration
->entries
->len
;
1312 for (i
= iter
->index
+ 1; i
< len
; i
++) {
1313 struct enumeration_mapping
*mapping
=
1314 get_enumeration_mapping(type
, i
);
1316 switch (iter
->type
) {
1317 case ITERATOR_BY_NAME
:
1318 if (mapping
->string
== iter
->u
.name_quark
) {
1323 case ITERATOR_BY_SIGNED_VALUE
:
1325 int64_t value
= iter
->u
.signed_value
;
1327 if (value
>= mapping
->range_start
._signed
&&
1328 value
<= mapping
->range_end
._signed
) {
1334 case ITERATOR_BY_UNSIGNED_VALUE
:
1336 uint64_t value
= iter
->u
.unsigned_value
;
1338 if (value
>= mapping
->range_start
._unsigned
&&
1339 value
<= mapping
->range_end
._unsigned
) {
1346 BT_LOGF("Invalid enumeration field type mapping iterator type: "
1347 "type=%d", iter
->type
);
1357 struct bt_field_type_enumeration_mapping_iterator
*
1358 bt_field_type_enumeration_find_mappings_by_signed_value(
1359 struct bt_field_type
*type
, int64_t value
)
1361 struct bt_field_type_enumeration_mapping_iterator
*iter
;
1363 iter
= bt_field_type_enumeration_find_mappings_type(
1364 type
, ITERATOR_BY_SIGNED_VALUE
);
1366 BT_LOGW("Cannot create enumeration field type mapping iterator: "
1367 "ft-addr=%p, value=%" PRId64
, type
, value
);
1371 if (bt_ctf_field_type_integer_get_signed(
1372 iter
->enumeration_type
->container
) != 1) {
1373 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
1374 "enum-ft-addr=%p, int-ft-addr=%p",
1375 type
, iter
->enumeration_type
->container
);
1379 iter
->u
.signed_value
= value
;
1386 struct bt_field_type_enumeration_mapping_iterator
*
1387 bt_field_type_enumeration_find_mappings_by_unsigned_value(
1388 struct bt_field_type
*type
, uint64_t value
)
1390 struct bt_field_type_enumeration_mapping_iterator
*iter
;
1392 iter
= bt_field_type_enumeration_find_mappings_type(
1393 type
, ITERATOR_BY_UNSIGNED_VALUE
);
1395 BT_LOGW("Cannot create enumeration field type mapping iterator: "
1396 "ft-addr=%p, value=%" PRIu64
, type
, value
);
1400 if (bt_ctf_field_type_integer_get_signed(
1401 iter
->enumeration_type
->container
) != 0) {
1402 BT_LOGW("Invalid parameter: enumeration field type is signed: "
1403 "enum-ft-addr=%p, int-ft-addr=%p",
1404 type
, iter
->enumeration_type
->container
);
1407 iter
->u
.unsigned_value
= value
;
1414 int bt_field_type_enumeration_mapping_iterator_get_signed(
1415 struct bt_field_type_enumeration_mapping_iterator
*iter
,
1416 const char **mapping_name
, int64_t *range_begin
,
1422 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1427 if (iter
->index
== -1) {
1428 BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
1433 ret
= bt_field_type_enumeration_get_mapping_signed(
1434 &iter
->enumeration_type
->parent
, iter
->index
,
1435 mapping_name
, range_begin
, range_end
);
1440 int bt_field_type_enumeration_mapping_iterator_get_unsigned(
1441 struct bt_field_type_enumeration_mapping_iterator
*iter
,
1442 const char **mapping_name
, uint64_t *range_begin
,
1443 uint64_t *range_end
)
1448 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1453 if (iter
->index
== -1) {
1454 BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
1459 ret
= bt_field_type_enumeration_get_mapping_unsigned(
1460 &iter
->enumeration_type
->parent
, iter
->index
,
1461 mapping_name
, range_begin
, range_end
);
1466 int bt_field_type_enumeration_get_mapping_signed(
1467 struct bt_field_type
*enum_field_type
,
1468 uint64_t index
, const char **mapping_name
, int64_t *range_begin
,
1472 struct enumeration_mapping
*mapping
;
1474 if (!enum_field_type
) {
1475 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1480 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1482 /* get_enumeration_mapping() reports any error */
1488 *mapping_name
= g_quark_to_string(mapping
->string
);
1489 BT_ASSERT(*mapping_name
);
1493 *range_begin
= mapping
->range_start
._signed
;
1497 *range_end
= mapping
->range_end
._signed
;
1503 int bt_field_type_enumeration_get_mapping_unsigned(
1504 struct bt_field_type
*enum_field_type
,
1506 const char **mapping_name
, uint64_t *range_begin
,
1507 uint64_t *range_end
)
1510 struct enumeration_mapping
*mapping
;
1512 if (!enum_field_type
) {
1513 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1518 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1520 /* get_enumeration_mapping() reports any error */
1526 *mapping_name
= g_quark_to_string(mapping
->string
);
1527 BT_ASSERT(*mapping_name
);
1531 *range_begin
= mapping
->range_start
._unsigned
;
1535 *range_end
= mapping
->range_end
._unsigned
;
1541 struct bt_field_type
*bt_field_type_enumeration_create(
1542 struct bt_field_type
*integer_container_type
)
1544 struct bt_field_type_enumeration
*enumeration
= NULL
;
1546 BT_LOGD("Creating enumeration field type object: int-ft-addr=%p",
1547 integer_container_type
);
1549 if (!integer_container_type
) {
1550 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1554 if (integer_container_type
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
1555 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
1556 "container-ft-addr=%p, container-ft-id=%s",
1557 integer_container_type
,
1558 bt_field_type_id_string(integer_container_type
->id
));
1562 enumeration
= g_new0(struct bt_field_type_enumeration
, 1);
1564 BT_LOGE_STR("Failed to allocate one enumeration field type.");
1568 enumeration
->parent
.id
= BT_FIELD_TYPE_ID_ENUM
;
1569 bt_get(integer_container_type
);
1570 enumeration
->container
= integer_container_type
;
1571 enumeration
->entries
= g_ptr_array_new_with_free_func(
1572 (GDestroyNotify
)destroy_enumeration_mapping
);
1573 bt_field_type_init(&enumeration
->parent
, FALSE
);
1574 BT_LOGD("Created enumeration field type object: addr=%p, "
1575 "int-ft-addr=%p, int-ft-size=%u",
1576 &enumeration
->parent
, integer_container_type
,
1577 bt_field_type_integer_get_size(integer_container_type
));
1578 return &enumeration
->parent
;
1580 g_free(enumeration
);
1584 struct bt_field_type
*bt_field_type_enumeration_get_container_type(
1585 struct bt_field_type
*type
)
1587 struct bt_field_type
*container_type
= NULL
;
1588 struct bt_field_type_enumeration
*enumeration_type
;
1591 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1595 if (type
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
1596 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1597 "addr=%p, ft-id=%s", type
,
1598 bt_field_type_id_string(type
->id
));
1602 enumeration_type
= container_of(type
,
1603 struct bt_field_type_enumeration
, parent
);
1604 container_type
= enumeration_type
->container
;
1605 bt_get(container_type
);
1607 return container_type
;
1610 int bt_field_type_enumeration_add_mapping_signed(
1611 struct bt_field_type
*type
, const char *string
,
1612 int64_t range_start
, int64_t range_end
)
1615 GQuark mapping_name
;
1616 struct enumeration_mapping
*mapping
;
1617 struct bt_field_type_enumeration
*enumeration
;
1618 char *escaped_string
;
1621 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1627 BT_LOGW_STR("Invalid parameter: string is NULL.");
1633 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1639 if (type
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
1640 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1641 "addr=%p, ft-id=%s", type
,
1642 bt_field_type_id_string(type
->id
));
1647 if (range_end
< range_start
) {
1648 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1649 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1650 type
, range_start
, range_end
);
1655 if (strlen(string
) == 0) {
1656 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1657 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1663 escaped_string
= g_strescape(string
, NULL
);
1664 if (!escaped_string
) {
1665 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1666 "mapping-name-addr=%p, mapping-name=\"%s\"",
1667 type
, string
, string
);
1672 mapping
= g_new(struct enumeration_mapping
, 1);
1674 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1678 mapping_name
= g_quark_from_string(escaped_string
);
1679 *mapping
= (struct enumeration_mapping
) {
1680 .range_start
._signed
= range_start
,
1681 .range_end
._signed
= range_end
,
1682 .string
= mapping_name
,
1684 enumeration
= container_of(type
, struct bt_field_type_enumeration
,
1686 g_ptr_array_add(enumeration
->entries
, mapping
);
1687 g_ptr_array_sort(enumeration
->entries
,
1688 (GCompareFunc
)compare_enumeration_mappings_signed
);
1689 BT_LOGV("Added mapping to signed enumeration field type: addr=%p, "
1690 "name=\"%s\", range-start=%" PRId64
", "
1691 "range-end=%" PRId64
,
1692 type
, string
, range_start
, range_end
);
1694 free(escaped_string
);
1699 int bt_field_type_enumeration_add_mapping_unsigned(
1700 struct bt_field_type
*type
, const char *string
,
1701 uint64_t range_start
, uint64_t range_end
)
1704 GQuark mapping_name
;
1705 struct enumeration_mapping
*mapping
;
1706 struct bt_field_type_enumeration
*enumeration
;
1707 char *escaped_string
;
1710 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1716 BT_LOGW_STR("Invalid parameter: string is NULL.");
1722 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1728 if (type
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
1729 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1730 "addr=%p, ft-id=%s", type
,
1731 bt_field_type_id_string(type
->id
));
1736 if (range_end
< range_start
) {
1737 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1738 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1739 type
, range_start
, range_end
);
1744 if (strlen(string
) == 0) {
1745 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1746 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1752 escaped_string
= g_strescape(string
, NULL
);
1753 if (!escaped_string
) {
1754 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1755 "mapping-name-addr=%p, mapping-name=\"%s\"",
1756 type
, string
, string
);
1761 mapping
= g_new(struct enumeration_mapping
, 1);
1763 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1767 mapping_name
= g_quark_from_string(escaped_string
);
1768 *mapping
= (struct enumeration_mapping
) {
1769 .range_start
._unsigned
= range_start
,
1770 .range_end
._unsigned
= range_end
,
1771 .string
= mapping_name
,
1773 enumeration
= container_of(type
, struct bt_field_type_enumeration
,
1775 g_ptr_array_add(enumeration
->entries
, mapping
);
1776 g_ptr_array_sort(enumeration
->entries
,
1777 (GCompareFunc
)compare_enumeration_mappings_unsigned
);
1778 BT_LOGV("Added mapping to unsigned enumeration field type: addr=%p, "
1779 "name=\"%s\", range-start=%" PRIu64
", "
1780 "range-end=%" PRIu64
,
1781 type
, string
, range_start
, range_end
);
1783 free(escaped_string
);
1788 int64_t bt_field_type_enumeration_get_mapping_count(
1789 struct bt_field_type
*type
)
1792 struct bt_field_type_enumeration
*enumeration
;
1795 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1800 if (type
->id
!= BT_FIELD_TYPE_ID_ENUM
) {
1801 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1802 "addr=%p, ft-id=%s", type
,
1803 bt_field_type_id_string(type
->id
));
1808 enumeration
= container_of(type
, struct bt_field_type_enumeration
,
1810 ret
= (int64_t) enumeration
->entries
->len
;
1815 struct bt_field_type
*bt_field_type_floating_point_create(void)
1817 struct bt_field_type_floating_point
*floating_point
=
1818 g_new0(struct bt_field_type_floating_point
, 1);
1820 BT_LOGD_STR("Creating floating point number field type object.");
1822 if (!floating_point
) {
1823 BT_LOGE_STR("Failed to allocate one floating point number field type.");
1827 floating_point
->parent
.id
= BT_FIELD_TYPE_ID_FLOAT
;
1828 floating_point
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
1829 floating_point
->mant_dig
= FLT_MANT_DIG
;
1830 bt_field_type_init(&floating_point
->parent
, TRUE
);
1831 BT_LOGD("Created floating point number field type object: addr=%p, "
1832 "exp-size=%u, mant-size=%u", &floating_point
->parent
,
1833 floating_point
->exp_dig
, floating_point
->mant_dig
);
1835 return floating_point
? &floating_point
->parent
: NULL
;
1838 int bt_field_type_floating_point_get_exponent_digits(
1839 struct bt_field_type
*type
)
1842 struct bt_field_type_floating_point
*floating_point
;
1845 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1850 if (type
->id
!= BT_FIELD_TYPE_ID_FLOAT
) {
1851 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1852 "addr=%p, ft-id=%s", type
,
1853 bt_field_type_id_string(type
->id
));
1858 floating_point
= container_of(type
,
1859 struct bt_field_type_floating_point
, parent
);
1860 ret
= (int) floating_point
->exp_dig
;
1865 int bt_field_type_floating_point_set_exponent_digits(
1866 struct bt_field_type
*type
,
1867 unsigned int exponent_digits
)
1870 struct bt_field_type_floating_point
*floating_point
;
1873 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1879 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1885 if (type
->id
!= BT_FIELD_TYPE_ID_FLOAT
) {
1886 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1887 "addr=%p, ft-id=%s", type
,
1888 bt_field_type_id_string(type
->id
));
1893 floating_point
= container_of(type
,
1894 struct bt_field_type_floating_point
, parent
);
1895 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1896 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1898 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1899 BT_LOGW("Invalid parameter: invalid exponent size: "
1900 "addr=%p, exp-size=%u", type
, exponent_digits
);
1905 floating_point
->exp_dig
= exponent_digits
;
1906 BT_LOGV("Set floating point number field type's exponent size: addr=%p, "
1907 "exp-size=%u", type
, exponent_digits
);
1912 int bt_field_type_floating_point_get_mantissa_digits(
1913 struct bt_field_type
*type
)
1916 struct bt_field_type_floating_point
*floating_point
;
1919 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1924 if (type
->id
!= BT_FIELD_TYPE_ID_FLOAT
) {
1925 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1926 "addr=%p, ft-id=%s", type
,
1927 bt_field_type_id_string(type
->id
));
1932 floating_point
= container_of(type
,
1933 struct bt_field_type_floating_point
, parent
);
1934 ret
= (int) floating_point
->mant_dig
;
1939 int bt_field_type_floating_point_set_mantissa_digits(
1940 struct bt_field_type
*type
,
1941 unsigned int mantissa_digits
)
1944 struct bt_field_type_floating_point
*floating_point
;
1947 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1953 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1959 if (type
->id
!= BT_FIELD_TYPE_ID_FLOAT
) {
1960 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1961 "addr=%p, ft-id=%s", type
,
1962 bt_field_type_id_string(type
->id
));
1967 floating_point
= container_of(type
,
1968 struct bt_field_type_floating_point
, parent
);
1970 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1971 (mantissa_digits
!= DBL_MANT_DIG
) &&
1972 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1973 BT_LOGW("Invalid parameter: invalid mantissa size: "
1974 "addr=%p, mant-size=%u", type
, mantissa_digits
);
1979 floating_point
->mant_dig
= mantissa_digits
;
1980 BT_LOGV("Set floating point number field type's mantissa size: addr=%p, "
1981 "mant-size=%u", type
, mantissa_digits
);
1986 struct bt_field_type
*bt_field_type_structure_create(void)
1988 struct bt_field_type_structure
*structure
=
1989 g_new0(struct bt_field_type_structure
, 1);
1991 BT_LOGD_STR("Creating structure field type object.");
1994 BT_LOGE_STR("Failed to allocate one structure field type.");
1998 structure
->parent
.id
= BT_FIELD_TYPE_ID_STRUCT
;
1999 structure
->fields
= g_ptr_array_new_with_free_func(
2000 (GDestroyNotify
)destroy_structure_field
);
2001 structure
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2002 bt_field_type_init(&structure
->parent
, TRUE
);
2003 BT_LOGD("Created structure field type object: addr=%p",
2004 &structure
->parent
);
2005 return &structure
->parent
;
2011 int bt_field_type_structure_replace_field(struct bt_field_type
*type
,
2012 const char *field_name
, struct bt_field_type
*field_type
)
2015 struct bt_field_type_structure
*structure
;
2020 BT_ASSERT(field_name
);
2021 BT_ASSERT(field_type
);
2022 BT_ASSERT(type
->id
== BT_FIELD_TYPE_ID_STRUCT
);
2023 structure
= container_of(type
, struct bt_field_type_structure
, parent
);
2024 name_quark
= g_quark_from_string(field_name
);
2026 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2027 struct structure_field
*field
= g_ptr_array_index(
2028 structure
->fields
, i
);
2030 if (field
->name
== name_quark
) {
2031 bt_put(field
->type
);
2032 field
->type
= bt_get(field_type
);
2039 int bt_field_type_structure_add_field(struct bt_field_type
*type
,
2040 struct bt_field_type
*field_type
,
2041 const char *field_name
)
2044 struct bt_field_type_structure
*structure
;
2047 * TODO: check that `field_type` does not contain `type`,
2051 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2057 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2063 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2069 if (type
->id
!= BT_FIELD_TYPE_ID_STRUCT
) {
2070 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2071 "addr=%p, ft-id=%s", type
,
2072 bt_field_type_id_string(type
->id
));
2077 if (type
== field_type
) {
2078 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
2084 structure
= container_of(type
,
2085 struct bt_field_type_structure
, parent
);
2086 if (add_structure_field(structure
->fields
,
2087 structure
->field_name_to_index
, field_type
, field_name
)) {
2088 BT_LOGW("Cannot add field to structure field type: "
2089 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2090 type
, field_type
, field_name
);
2095 BT_LOGV("Added structure field type field: struct-ft-addr=%p, "
2096 "field-ft-addr=%p, field-name=\"%s\"", type
,
2097 field_type
, field_name
);
2102 int64_t bt_field_type_structure_get_field_count(
2103 struct bt_field_type
*type
)
2106 struct bt_field_type_structure
*structure
;
2109 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2114 if (type
->id
!= BT_FIELD_TYPE_ID_STRUCT
) {
2115 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2116 "addr=%p, ft-id=%s", type
,
2117 bt_field_type_id_string(type
->id
));
2122 structure
= container_of(type
, struct bt_field_type_structure
,
2124 ret
= (int64_t) structure
->fields
->len
;
2129 int bt_field_type_structure_get_field_by_index(
2130 struct bt_field_type
*type
,
2131 const char **field_name
, struct bt_field_type
**field_type
,
2134 struct bt_field_type_structure
*structure
;
2135 struct structure_field
*field
;
2139 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2144 if (type
->id
!= BT_FIELD_TYPE_ID_STRUCT
) {
2145 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2146 "addr=%p, ft-id=%s", type
,
2147 bt_field_type_id_string(type
->id
));
2152 structure
= container_of(type
, struct bt_field_type_structure
,
2154 if (index
>= structure
->fields
->len
) {
2155 BT_LOGW("Invalid parameter: index is out of bounds: "
2156 "addr=%p, index=%" PRIu64
", count=%u",
2157 type
, index
, structure
->fields
->len
);
2162 field
= g_ptr_array_index(structure
->fields
, index
);
2164 *field_type
= field
->type
;
2165 bt_get(field
->type
);
2168 *field_name
= g_quark_to_string(field
->name
);
2169 BT_ASSERT(*field_name
);
2175 struct bt_field_type
*bt_field_type_structure_get_field_type_by_name(
2176 struct bt_field_type
*type
,
2181 struct structure_field
*field
;
2182 struct bt_field_type_structure
*structure
;
2183 struct bt_field_type
*field_type
= NULL
;
2186 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2191 BT_LOGW_STR("Invalid parameter: name is NULL.");
2195 name_quark
= g_quark_try_string(name
);
2197 BT_LOGV("No such structure field type field name: "
2198 "ft-addr=%p, field-name=\"%s\"",
2203 structure
= container_of(type
, struct bt_field_type_structure
,
2205 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
2206 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2207 BT_LOGV("No such structure field type field name: "
2208 "ft-addr=%p, field-name=\"%s\"",
2213 field
= structure
->fields
->pdata
[index
];
2214 field_type
= field
->type
;
2220 struct bt_field_type
*bt_field_type_variant_create(
2221 struct bt_field_type
*enum_tag
, const char *tag_name
)
2223 struct bt_field_type_variant
*variant
= NULL
;
2225 BT_LOGD("Creating variant field type object: "
2226 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2227 enum_tag
, tag_name
);
2229 if (tag_name
&& !bt_identifier_is_valid(tag_name
)) {
2230 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2231 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2232 enum_tag
, tag_name
);
2236 variant
= g_new0(struct bt_field_type_variant
, 1);
2238 BT_LOGE_STR("Failed to allocate one variant field type.");
2242 variant
->parent
.id
= BT_FIELD_TYPE_ID_VARIANT
;
2243 variant
->tag_name
= g_string_new(tag_name
);
2244 variant
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2245 variant
->fields
= g_ptr_array_new_with_free_func(
2246 (GDestroyNotify
) destroy_structure_field
);
2249 variant
->tag
= container_of(enum_tag
,
2250 struct bt_field_type_enumeration
, parent
);
2253 bt_field_type_init(&variant
->parent
, TRUE
);
2254 /* A variant's alignment is undefined */
2255 variant
->parent
.alignment
= 0;
2256 BT_LOGD("Created variant field type object: addr=%p, "
2257 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2258 &variant
->parent
, enum_tag
, tag_name
);
2259 return &variant
->parent
;
2264 struct bt_field_type
*bt_field_type_variant_get_tag_type(
2265 struct bt_field_type
*type
)
2267 struct bt_field_type_variant
*variant
;
2268 struct bt_field_type
*tag_type
= NULL
;
2271 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2275 if (type
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2276 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2277 "addr=%p, ft-id=%s", type
,
2278 bt_field_type_id_string(type
->id
));
2282 variant
= container_of(type
, struct bt_field_type_variant
, parent
);
2283 if (!variant
->tag
) {
2284 BT_LOGV("Variant field type has no tag field type: "
2289 tag_type
= &variant
->tag
->parent
;
2295 const char *bt_field_type_variant_get_tag_name(
2296 struct bt_field_type
*type
)
2298 struct bt_field_type_variant
*variant
;
2299 const char *tag_name
= NULL
;
2302 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2306 if (type
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2307 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2308 "addr=%p, ft-id=%s", type
,
2309 bt_field_type_id_string(type
->id
));
2313 variant
= container_of(type
, struct bt_field_type_variant
, parent
);
2314 if (variant
->tag_name
->len
== 0) {
2315 BT_LOGV("Variant field type has no tag field name: "
2320 tag_name
= variant
->tag_name
->str
;
2325 int bt_field_type_variant_set_tag_name(
2326 struct bt_field_type
*type
, const char *name
)
2329 struct bt_field_type_variant
*variant
;
2332 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2338 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2344 if (type
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2345 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2346 "addr=%p, ft-id=%s", type
,
2347 bt_field_type_id_string(type
->id
));
2352 if (!bt_identifier_is_valid(name
)) {
2353 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2354 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2360 variant
= container_of(type
, struct bt_field_type_variant
, parent
);
2361 g_string_assign(variant
->tag_name
, name
);
2362 BT_LOGV("Set variant field type's tag field name: addr=%p, "
2363 "tag-field-name=\"%s\"", type
, name
);
2368 int bt_field_type_variant_add_field(struct bt_field_type
*type
,
2369 struct bt_field_type
*field_type
,
2370 const char *field_name
)
2374 struct bt_field_type_variant
*variant
;
2375 GQuark field_name_quark
= g_quark_from_string(field_name
);
2378 * TODO: check that `field_type` does not contain `type`,
2382 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2388 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2394 if (type
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2395 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2396 "addr=%p, ft-id=%s", type
,
2397 bt_field_type_id_string(type
->id
));
2402 if (type
== field_type
) {
2403 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2409 variant
= container_of(type
, struct bt_field_type_variant
, parent
);
2411 /* The user has explicitly provided a tag; validate against it. */
2415 /* Make sure this name is present in the enum tag */
2416 for (i
= 0; i
< variant
->tag
->entries
->len
; i
++) {
2417 struct enumeration_mapping
*mapping
=
2418 g_ptr_array_index(variant
->tag
->entries
, i
);
2420 if (mapping
->string
== field_name_quark
) {
2427 /* Validation failed */
2428 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2429 "variant-ft-addr=%p, tag-ft-addr=%p, "
2430 "tag-field-name=\"%s\""
2431 "field-ft-addr=%p, field-name=\"%s\"",
2432 type
, variant
->tag
, variant
->tag_name
->str
,
2433 field_type
, field_name
);
2439 if (add_structure_field(variant
->fields
, variant
->field_name_to_index
,
2440 field_type
, field_name
)) {
2441 BT_LOGW("Cannot add field to variant field type: "
2442 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2443 type
, field_type
, field_name
);
2448 BT_LOGV("Added variant field type field: variant-ft-addr=%p, "
2449 "field-ft-addr=%p, field-name=\"%s\"", type
,
2450 field_type
, field_name
);
2456 struct bt_field_type
*bt_field_type_variant_get_field_type_by_name(
2457 struct bt_field_type
*type
,
2458 const char *field_name
)
2462 struct structure_field
*field
;
2463 struct bt_field_type_variant
*variant
;
2464 struct bt_field_type
*field_type
= NULL
;
2467 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2472 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2476 name_quark
= g_quark_try_string(field_name
);
2478 BT_LOGV("No such variant field type field name: "
2479 "ft-addr=%p, field-name=\"%s\"",
2484 variant
= container_of(type
, struct bt_field_type_variant
, parent
);
2485 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
2486 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2487 BT_LOGV("No such variant field type field name: "
2488 "ft-addr=%p, field-name=\"%s\"",
2493 field
= g_ptr_array_index(variant
->fields
, index
);
2494 field_type
= field
->type
;
2500 struct bt_field_type
*bt_field_type_variant_get_field_type_from_tag(
2501 struct bt_field_type
*type
,
2502 struct bt_field
*tag
)
2505 const char *enum_value
;
2506 struct bt_field_type
*field_type
= NULL
;
2507 struct bt_field_type_enumeration_mapping_iterator
*iter
= NULL
;
2510 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2515 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
2519 if (type
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2520 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2521 "addr=%p, ft-id=%s", type
,
2522 bt_field_type_id_string(type
->id
));
2526 iter
= bt_field_enumeration_get_mappings(tag
);
2527 ret
= bt_field_type_enumeration_mapping_iterator_next(iter
);
2529 BT_LOGW("Cannot get enumeration field type mapping iterator from enumeration field: "
2530 "enum-field-addr=%p", tag
);
2534 ret
= bt_field_type_enumeration_mapping_iterator_get_signed(iter
,
2535 &enum_value
, NULL
, NULL
);
2537 BT_LOGW("Cannot get enumeration field type mapping iterator's current mapping: "
2538 "iter-addr=%p", iter
);
2542 field_type
= bt_field_type_variant_get_field_type_by_name(
2549 int64_t bt_field_type_variant_get_field_count(struct bt_field_type
*type
)
2552 struct bt_field_type_variant
*variant
;
2555 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2560 if (type
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2561 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2562 "addr=%p, ft-id=%s", type
,
2563 bt_field_type_id_string(type
->id
));
2568 variant
= container_of(type
, struct bt_field_type_variant
,
2570 ret
= (int64_t) variant
->fields
->len
;
2576 int bt_field_type_variant_get_field_by_index(struct bt_field_type
*type
,
2577 const char **field_name
, struct bt_field_type
**field_type
,
2580 struct bt_field_type_variant
*variant
;
2581 struct structure_field
*field
;
2585 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2590 if (type
->id
!= BT_FIELD_TYPE_ID_VARIANT
) {
2591 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2592 "addr=%p, ft-id=%s", type
,
2593 bt_field_type_id_string(type
->id
));
2598 variant
= container_of(type
, struct bt_field_type_variant
,
2600 if (index
>= variant
->fields
->len
) {
2601 BT_LOGW("Invalid parameter: index is out of bounds: "
2602 "addr=%p, index=%" PRIu64
", count=%u",
2603 type
, index
, variant
->fields
->len
);
2608 field
= g_ptr_array_index(variant
->fields
, index
);
2610 *field_type
= field
->type
;
2611 bt_get(field
->type
);
2614 *field_name
= g_quark_to_string(field
->name
);
2615 BT_ASSERT(*field_name
);
2621 struct bt_field_type
*bt_field_type_array_create(
2622 struct bt_field_type
*element_type
,
2623 unsigned int length
)
2625 struct bt_field_type_array
*array
= NULL
;
2627 BT_LOGD("Creating array field type object: element-ft-addr=%p, "
2628 "length=%u", element_type
, length
);
2630 if (!element_type
) {
2631 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2636 BT_LOGW_STR("Invalid parameter: length is zero.");
2640 array
= g_new0(struct bt_field_type_array
, 1);
2642 BT_LOGE_STR("Failed to allocate one array field type.");
2646 array
->parent
.id
= BT_FIELD_TYPE_ID_ARRAY
;
2647 bt_get(element_type
);
2648 array
->element_type
= element_type
;
2649 array
->length
= length
;
2650 bt_field_type_init(&array
->parent
, FALSE
);
2651 BT_LOGD("Created array field type object: addr=%p, "
2652 "element-ft-addr=%p, length=%u",
2653 &array
->parent
, element_type
, length
);
2654 return &array
->parent
;
2659 struct bt_field_type
*bt_field_type_array_get_element_type(
2660 struct bt_field_type
*type
)
2662 struct bt_field_type
*ret
= NULL
;
2663 struct bt_field_type_array
*array
;
2666 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2670 if (type
->id
!= BT_FIELD_TYPE_ID_ARRAY
) {
2671 BT_LOGW("Invalid parameter: field type is not an array field type: "
2672 "addr=%p, ft-id=%s", type
,
2673 bt_field_type_id_string(type
->id
));
2677 array
= container_of(type
, struct bt_field_type_array
, parent
);
2678 ret
= array
->element_type
;
2685 int bt_field_type_array_set_element_type(struct bt_field_type
*type
,
2686 struct bt_field_type
*element_type
)
2689 struct bt_field_type_array
*array
;
2692 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2697 if (!element_type
) {
2698 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2703 if (type
->id
!= BT_FIELD_TYPE_ID_ARRAY
) {
2704 BT_LOGW("Invalid parameter: field type is not an array field type: "
2705 "addr=%p, ft-id=%s", type
,
2706 bt_field_type_id_string(type
->id
));
2711 array
= container_of(type
, struct bt_field_type_array
, parent
);
2713 if (array
->element_type
) {
2714 BT_PUT(array
->element_type
);
2717 array
->element_type
= element_type
;
2718 bt_get(array
->element_type
);
2719 BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
2720 "element-ft-addr=%p", type
, element_type
);
2726 int64_t bt_field_type_array_get_length(struct bt_field_type
*type
)
2729 struct bt_field_type_array
*array
;
2732 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2737 if (type
->id
!= BT_FIELD_TYPE_ID_ARRAY
) {
2738 BT_LOGW("Invalid parameter: field type is not an array field type: "
2739 "addr=%p, ft-id=%s", type
,
2740 bt_field_type_id_string(type
->id
));
2745 array
= container_of(type
, struct bt_field_type_array
, parent
);
2746 ret
= (int64_t) array
->length
;
2751 struct bt_field_type
*bt_field_type_sequence_create(
2752 struct bt_field_type
*element_type
,
2753 const char *length_field_name
)
2755 struct bt_field_type_sequence
*sequence
= NULL
;
2757 BT_LOGD("Creating sequence field type object: element-ft-addr=%p, "
2758 "length-field-name=\"%s\"", element_type
, length_field_name
);
2760 if (!element_type
) {
2761 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2765 if (!bt_identifier_is_valid(length_field_name
)) {
2766 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
2767 "length-field-name=\"%s\"", length_field_name
);
2771 sequence
= g_new0(struct bt_field_type_sequence
, 1);
2773 BT_LOGE_STR("Failed to allocate one sequence field type.");
2777 sequence
->parent
.id
= BT_FIELD_TYPE_ID_SEQUENCE
;
2778 bt_get(element_type
);
2779 sequence
->element_type
= element_type
;
2780 sequence
->length_field_name
= g_string_new(length_field_name
);
2781 bt_field_type_init(&sequence
->parent
, FALSE
);
2782 BT_LOGD("Created sequence field type object: addr=%p, "
2783 "element-ft-addr=%p, length-field-name=\"%s\"",
2784 &sequence
->parent
, element_type
, length_field_name
);
2785 return &sequence
->parent
;
2790 struct bt_field_type
*bt_field_type_sequence_get_element_type(
2791 struct bt_field_type
*type
)
2793 struct bt_field_type
*ret
= NULL
;
2794 struct bt_field_type_sequence
*sequence
;
2797 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2801 if (type
->id
!= BT_FIELD_TYPE_ID_SEQUENCE
) {
2802 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2803 "addr=%p, ft-id=%s", type
,
2804 bt_field_type_id_string(type
->id
));
2808 sequence
= container_of(type
, struct bt_field_type_sequence
,
2810 ret
= sequence
->element_type
;
2817 int bt_field_type_sequence_set_element_type(struct bt_field_type
*type
,
2818 struct bt_field_type
*element_type
)
2821 struct bt_field_type_sequence
*sequence
;
2824 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2829 if (!element_type
) {
2830 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2835 if (type
->id
!= BT_FIELD_TYPE_ID_SEQUENCE
) {
2836 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2837 "addr=%p, ft-id=%s", type
,
2838 bt_field_type_id_string(type
->id
));
2843 sequence
= container_of(type
, struct bt_field_type_sequence
, parent
);
2844 if (sequence
->element_type
) {
2845 BT_PUT(sequence
->element_type
);
2848 sequence
->element_type
= element_type
;
2849 bt_get(sequence
->element_type
);
2850 BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
2851 "element-ft-addr=%p", type
, element_type
);
2857 const char *bt_field_type_sequence_get_length_field_name(
2858 struct bt_field_type
*type
)
2860 const char *ret
= NULL
;
2861 struct bt_field_type_sequence
*sequence
;
2864 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2868 if (type
->id
!= BT_FIELD_TYPE_ID_SEQUENCE
) {
2869 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2870 "addr=%p, ft-id=%s", type
,
2871 bt_field_type_id_string(type
->id
));
2875 sequence
= container_of(type
, struct bt_field_type_sequence
,
2877 ret
= sequence
->length_field_name
->str
;
2882 struct bt_field_type
*bt_field_type_string_create(void)
2884 struct bt_field_type_string
*string
=
2885 g_new0(struct bt_field_type_string
, 1);
2887 BT_LOGD_STR("Creating string field type object.");
2890 BT_LOGE_STR("Failed to allocate one string field type.");
2894 string
->parent
.id
= BT_FIELD_TYPE_ID_STRING
;
2895 bt_field_type_init(&string
->parent
, TRUE
);
2896 string
->encoding
= BT_STRING_ENCODING_UTF8
;
2897 string
->parent
.alignment
= CHAR_BIT
;
2898 BT_LOGD("Created string field type object: addr=%p", &string
->parent
);
2899 return &string
->parent
;
2902 enum bt_string_encoding
bt_field_type_string_get_encoding(
2903 struct bt_field_type
*type
)
2905 struct bt_field_type_string
*string
;
2906 enum bt_string_encoding ret
= BT_STRING_ENCODING_UNKNOWN
;
2909 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2913 if (type
->id
!= BT_FIELD_TYPE_ID_STRING
) {
2914 BT_LOGW("Invalid parameter: field type is not a string field type: "
2915 "addr=%p, ft-id=%s", type
,
2916 bt_field_type_id_string(type
->id
));
2920 string
= container_of(type
, struct bt_field_type_string
,
2922 ret
= string
->encoding
;
2927 int bt_field_type_string_set_encoding(struct bt_field_type
*type
,
2928 enum bt_string_encoding encoding
)
2931 struct bt_field_type_string
*string
;
2934 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2939 if (type
->id
!= BT_FIELD_TYPE_ID_STRING
) {
2940 BT_LOGW("Invalid parameter: field type is not a string field type: "
2941 "addr=%p, ft-id=%s", type
,
2942 bt_field_type_id_string(type
->id
));
2947 if (encoding
!= BT_STRING_ENCODING_UTF8
&&
2948 encoding
!= BT_STRING_ENCODING_ASCII
) {
2949 BT_LOGW("Invalid parameter: unknown string encoding: "
2950 "addr=%p, encoding=%d", type
, encoding
);
2955 string
= container_of(type
, struct bt_field_type_string
, parent
);
2956 string
->encoding
= encoding
;
2957 BT_LOGV("Set string field type's encoding: addr=%p, encoding=%s",
2958 type
, bt_string_encoding_string(encoding
));
2963 int bt_field_type_get_alignment(struct bt_field_type
*type
)
2966 enum bt_field_type_id type_id
;
2969 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2975 ret
= (int) type
->alignment
;
2979 type_id
= bt_field_type_get_type_id(type
);
2981 case BT_FIELD_TYPE_ID_SEQUENCE
:
2983 struct bt_field_type
*element
=
2984 bt_field_type_sequence_get_element_type(type
);
2987 ret
= bt_field_type_get_alignment(element
);
2991 case BT_FIELD_TYPE_ID_ARRAY
:
2993 struct bt_field_type
*element
=
2994 bt_field_type_array_get_element_type(type
);
2997 ret
= bt_field_type_get_alignment(element
);
3001 case BT_FIELD_TYPE_ID_STRUCT
:
3003 int64_t i
, element_count
;
3005 element_count
= bt_field_type_structure_get_field_count(
3007 BT_ASSERT(element_count
>= 0);
3009 for (i
= 0; i
< element_count
; i
++) {
3010 struct bt_field_type
*field
= NULL
;
3011 int field_alignment
;
3013 ret
= bt_field_type_structure_get_field_by_index(
3014 type
, NULL
, &field
, i
);
3015 BT_ASSERT(ret
== 0);
3017 field_alignment
= bt_field_type_get_alignment(
3020 if (field_alignment
< 0) {
3021 ret
= field_alignment
;
3025 type
->alignment
= MAX(field_alignment
, type
->alignment
);
3027 ret
= (int) type
->alignment
;
3030 case BT_FIELD_TYPE_ID_ENUM
:
3032 struct bt_field_type
*container
=
3033 bt_field_type_enumeration_get_container_type(type
);
3035 ret
= bt_field_type_get_alignment(container
);
3039 case BT_FIELD_TYPE_ID_UNKNOWN
:
3040 BT_LOGW("Invalid parameter: unknown field type ID: "
3041 "addr=%p, ft-id=%d", type
, type_id
);
3045 ret
= (int) type
->alignment
;
3053 int is_power_of_two(unsigned int value
)
3055 return ((value
& (value
- 1)) == 0) && value
> 0;
3058 int bt_field_type_set_alignment(struct bt_field_type
*type
,
3059 unsigned int alignment
)
3062 enum bt_field_type_id type_id
;
3064 /* Alignment must be a power of two */
3066 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3072 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3078 if (!is_power_of_two(alignment
)) {
3079 BT_LOGW("Invalid parameter: alignment is not a power of two: "
3080 "addr=%p, align=%u", type
, alignment
);
3085 type_id
= bt_field_type_get_type_id(type
);
3086 if (type_id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
3087 BT_LOGW("Invalid parameter: unknown field type ID: "
3088 "addr=%p, ft-id=%d", type
, type_id
);
3093 if (type
->id
== BT_FIELD_TYPE_ID_STRING
&&
3094 alignment
!= CHAR_BIT
) {
3095 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
3096 "addr=%p, align=%u", CHAR_BIT
, type
, alignment
);
3101 if (type_id
== BT_FIELD_TYPE_ID_VARIANT
||
3102 type_id
== BT_FIELD_TYPE_ID_SEQUENCE
||
3103 type_id
== BT_FIELD_TYPE_ID_ARRAY
) {
3104 /* Setting an alignment on these types makes no sense */
3105 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
3106 "addr=%p, ft-id=%s", type
,
3107 bt_field_type_id_string(type
->id
));
3112 type
->alignment
= alignment
;
3114 BT_LOGV("Set field type's alignment: addr=%p, align=%u",
3120 enum bt_byte_order
bt_field_type_get_byte_order(
3121 struct bt_field_type
*type
)
3123 enum bt_byte_order ret
= BT_BYTE_ORDER_UNKNOWN
;
3126 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3131 case BT_FIELD_TYPE_ID_INTEGER
:
3133 struct bt_field_type_integer
*integer
= container_of(
3134 type
, struct bt_field_type_integer
, parent
);
3135 ret
= integer
->user_byte_order
;
3138 case BT_FIELD_TYPE_ID_ENUM
:
3140 struct bt_field_type_enumeration
*enum_ft
= container_of(
3141 type
, struct bt_field_type_enumeration
, parent
);
3142 ret
= bt_field_type_get_byte_order(enum_ft
->container
);
3145 case BT_FIELD_TYPE_ID_FLOAT
:
3147 struct bt_field_type_floating_point
*floating_point
=
3149 struct bt_field_type_floating_point
,
3151 ret
= floating_point
->user_byte_order
;
3155 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
3156 "addr=%p, ft-id=%s", type
,
3157 bt_field_type_id_string(type
->id
));
3161 BT_ASSERT(ret
== BT_BYTE_ORDER_NATIVE
||
3162 ret
== BT_BYTE_ORDER_LITTLE_ENDIAN
||
3163 ret
== BT_BYTE_ORDER_BIG_ENDIAN
||
3164 ret
== BT_BYTE_ORDER_NETWORK
);
3170 int bt_field_type_set_byte_order(struct bt_field_type
*type
,
3171 enum bt_byte_order byte_order
)
3176 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3182 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3188 if (byte_order
!= BT_BYTE_ORDER_NATIVE
&&
3189 byte_order
!= BT_BYTE_ORDER_LITTLE_ENDIAN
&&
3190 byte_order
!= BT_BYTE_ORDER_BIG_ENDIAN
&&
3191 byte_order
!= BT_BYTE_ORDER_NETWORK
) {
3192 BT_LOGW("Invalid parameter: invalid byte order: "
3193 "addr=%p, bo=%s", type
,
3194 bt_byte_order_string(byte_order
));
3199 if (set_byte_order_funcs
[type
->id
]) {
3200 set_byte_order_funcs
[type
->id
](type
, byte_order
);
3203 BT_LOGV("Set field type's byte order: addr=%p, bo=%s",
3204 type
, bt_byte_order_string(byte_order
));
3210 enum bt_field_type_id
bt_field_type_get_type_id(
3211 struct bt_field_type
*type
)
3214 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3215 return BT_FIELD_TYPE_ID_UNKNOWN
;
3221 int bt_field_type_is_integer(struct bt_field_type
*type
)
3223 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_INTEGER
;
3226 int bt_field_type_is_floating_point(struct bt_field_type
*type
)
3228 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_FLOAT
;
3231 int bt_field_type_is_enumeration(struct bt_field_type
*type
)
3233 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_ENUM
;
3236 int bt_field_type_is_string(struct bt_field_type
*type
)
3238 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_STRING
;
3241 int bt_field_type_is_structure(struct bt_field_type
*type
)
3243 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_STRUCT
;
3246 int bt_field_type_is_array(struct bt_field_type
*type
)
3248 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_ARRAY
;
3251 int bt_field_type_is_sequence(struct bt_field_type
*type
)
3253 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_SEQUENCE
;
3256 int bt_field_type_is_variant(struct bt_field_type
*type
)
3258 return bt_field_type_get_type_id(type
) == BT_FIELD_TYPE_ID_VARIANT
;
3261 /* Pre-2.0 CTF writer backward compatibility */
3262 void bt_ctf_field_type_get(struct bt_field_type
*type
)
3267 /* Pre-2.0 CTF writer backward compatibility */
3268 void bt_ctf_field_type_put(struct bt_field_type
*type
)
3274 void _bt_field_type_freeze(struct bt_field_type
*type
)
3276 if (!type
|| type
->frozen
) {
3284 struct bt_field_type
*bt_field_type_variant_get_field_type_signed(
3285 struct bt_field_type_variant
*variant
,
3288 struct bt_field_type
*type
= NULL
;
3289 GQuark field_name_quark
;
3291 struct structure_field
*field_entry
;
3292 struct range_overlap_query query
= {
3293 .range_start
._signed
= tag_value
,
3294 .range_end
._signed
= tag_value
,
3299 g_ptr_array_foreach(variant
->tag
->entries
, check_ranges_overlap
,
3301 if (!query
.overlaps
) {
3305 field_name_quark
= query
.mapping_name
;
3306 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3307 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3311 field_entry
= g_ptr_array_index(variant
->fields
, (size_t) index
);
3312 type
= field_entry
->type
;
3318 struct bt_field_type
*bt_field_type_variant_get_field_type_unsigned(
3319 struct bt_field_type_variant
*variant
,
3322 struct bt_field_type
*type
= NULL
;
3323 GQuark field_name_quark
;
3325 struct structure_field
*field_entry
;
3326 struct range_overlap_query query
= {
3327 .range_start
._unsigned
= tag_value
,
3328 .range_end
._unsigned
= tag_value
,
3333 g_ptr_array_foreach(variant
->tag
->entries
,
3334 check_ranges_overlap_unsigned
,
3336 if (!query
.overlaps
) {
3340 field_name_quark
= query
.mapping_name
;
3341 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3342 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3346 field_entry
= g_ptr_array_index(variant
->fields
, (size_t)index
);
3347 type
= field_entry
->type
;
3353 int bt_field_type_serialize(struct bt_field_type
*type
,
3354 struct metadata_context
*context
)
3361 /* Make sure field type is valid before serializing it */
3362 ret
= bt_field_type_validate(type
);
3364 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
3369 ret
= type
->serialize(type
, context
);
3374 struct bt_field_type
*bt_field_type_copy(struct bt_field_type
*type
)
3376 struct bt_field_type
*copy
= NULL
;
3379 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3383 copy
= type_copy_funcs
[type
->id
](type
);
3385 BT_LOGE_STR("Cannot copy field type.");
3389 copy
->alignment
= type
->alignment
;
3395 int bt_field_type_structure_get_field_name_index(
3396 struct bt_field_type
*type
, const char *name
)
3401 struct bt_field_type_structure
*structure
;
3404 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3410 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3415 if (bt_field_type_get_type_id(type
) != BT_FIELD_TYPE_ID_STRUCT
) {
3416 BT_LOGW("Invalid parameter: field type is not a structure field type: "
3417 "addr=%p, ft-id=%s", type
,
3418 bt_field_type_id_string(type
->id
));
3423 name_quark
= g_quark_try_string(name
);
3425 BT_LOGV("No such structure field type field name: "
3426 "ft-addr=%p, field-name=\"%s\"",
3432 structure
= container_of(type
, struct bt_field_type_structure
,
3434 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
3435 GUINT_TO_POINTER(name_quark
),
3436 NULL
, (gpointer
*)&index
)) {
3437 BT_LOGV("No such structure field type field name: "
3438 "ft-addr=%p, field-name=\"%s\"",
3449 int bt_field_type_variant_get_field_name_index(
3450 struct bt_field_type
*type
, const char *name
)
3455 struct bt_field_type_variant
*variant
;
3458 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3464 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3469 if (bt_field_type_get_type_id(type
) != BT_FIELD_TYPE_ID_VARIANT
) {
3470 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3471 "addr=%p, ft-id=%s", type
,
3472 bt_field_type_id_string(type
->id
));
3477 name_quark
= g_quark_try_string(name
);
3479 BT_LOGV("No such variant field type field name: "
3480 "ft-addr=%p, field-name=\"%s\"",
3486 variant
= container_of(type
, struct bt_field_type_variant
,
3488 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3489 GUINT_TO_POINTER(name_quark
),
3490 NULL
, (gpointer
*)&index
)) {
3491 BT_LOGV("No such variant field type field name: "
3492 "ft-addr=%p, field-name=\"%s\"",
3503 int bt_field_type_sequence_set_length_field_path(
3504 struct bt_field_type
*type
,
3505 struct bt_field_path
*path
)
3508 struct bt_field_type_sequence
*sequence
;
3511 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3516 if (bt_field_type_get_type_id(type
) != BT_FIELD_TYPE_ID_SEQUENCE
) {
3517 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
3518 "addr=%p, ft-id=%s", type
,
3519 bt_field_type_id_string(type
->id
));
3524 sequence
= container_of(type
, struct bt_field_type_sequence
,
3527 BT_MOVE(sequence
->length_field_path
, path
);
3528 BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
3529 "field-path-addr=%p", type
, path
);
3535 int bt_field_type_variant_set_tag_field_path(struct bt_field_type
*type
,
3536 struct bt_field_path
*path
)
3539 struct bt_field_type_variant
*variant
;
3542 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3547 if (bt_field_type_get_type_id(type
) != BT_FIELD_TYPE_ID_VARIANT
) {
3548 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3549 "addr=%p, ft-id=%s", type
,
3550 bt_field_type_id_string(type
->id
));
3555 variant
= container_of(type
, struct bt_field_type_variant
,
3558 BT_MOVE(variant
->tag_field_path
, path
);
3559 BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
3560 "field-path-addr=%p", type
, path
);
3566 int bt_field_type_variant_set_tag_field_type(struct bt_field_type
*type
,
3567 struct bt_field_type
*tag
)
3570 struct bt_field_type_variant
*variant
;
3573 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3579 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
3584 if (bt_field_type_get_type_id(tag
) != BT_FIELD_TYPE_ID_ENUM
) {
3585 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
3586 "addr=%p, ft-id=%s", type
,
3587 bt_field_type_id_string(type
->id
));
3592 variant
= container_of(type
, struct bt_field_type_variant
,
3596 bt_put(&variant
->tag
->parent
);
3598 variant
->tag
= container_of(tag
, struct bt_field_type_enumeration
,
3600 BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
3601 "tag-ft-addr=%p", type
, tag
);
3607 void bt_field_type_integer_destroy(struct bt_field_type
*type
)
3609 struct bt_field_type_integer
*integer
=
3610 (struct bt_field_type_integer
*) type
;
3616 BT_LOGD("Destroying integer field type object: addr=%p", type
);
3617 BT_LOGD_STR("Putting mapped clock class.");
3618 bt_put(integer
->mapped_clock
);
3623 void bt_field_type_enumeration_destroy(struct bt_field_type
*type
)
3625 struct bt_field_type_enumeration
*enumeration
=
3626 (struct bt_field_type_enumeration
*) type
;
3632 BT_LOGD("Destroying enumeration field type object: addr=%p", type
);
3633 g_ptr_array_free(enumeration
->entries
, TRUE
);
3634 BT_LOGD_STR("Putting container field type.");
3635 bt_put(enumeration
->container
);
3636 g_free(enumeration
);
3640 void bt_field_type_floating_point_destroy(struct bt_field_type
*type
)
3642 struct bt_field_type_floating_point
*floating_point
=
3643 (struct bt_field_type_floating_point
*) type
;
3649 BT_LOGD("Destroying floating point number field type object: addr=%p", type
);
3650 g_free(floating_point
);
3654 void bt_field_type_structure_destroy(struct bt_field_type
*type
)
3656 struct bt_field_type_structure
*structure
=
3657 (struct bt_field_type_structure
*) type
;
3663 BT_LOGD("Destroying structure field type object: addr=%p", type
);
3664 g_ptr_array_free(structure
->fields
, TRUE
);
3665 g_hash_table_destroy(structure
->field_name_to_index
);
3670 void bt_field_type_variant_destroy(struct bt_field_type
*type
)
3672 struct bt_field_type_variant
*variant
=
3673 (struct bt_field_type_variant
*) type
;
3679 BT_LOGD("Destroying variant field type object: addr=%p", type
);
3680 g_ptr_array_free(variant
->fields
, TRUE
);
3681 g_hash_table_destroy(variant
->field_name_to_index
);
3682 g_string_free(variant
->tag_name
, TRUE
);
3683 BT_LOGD_STR("Putting tag field type.");
3684 bt_put(&variant
->tag
->parent
);
3685 BT_PUT(variant
->tag_field_path
);
3690 void bt_field_type_array_destroy(struct bt_field_type
*type
)
3692 struct bt_field_type_array
*array
=
3693 (struct bt_field_type_array
*) type
;
3699 BT_LOGD("Destroying array field type object: addr=%p", type
);
3700 BT_LOGD_STR("Putting element field type.");
3701 bt_put(array
->element_type
);
3706 void bt_field_type_sequence_destroy(struct bt_field_type
*type
)
3708 struct bt_field_type_sequence
*sequence
=
3709 (struct bt_field_type_sequence
*) type
;
3715 BT_LOGD("Destroying sequence field type object: addr=%p", type
);
3716 BT_LOGD_STR("Putting element field type.");
3717 bt_put(sequence
->element_type
);
3718 g_string_free(sequence
->length_field_name
, TRUE
);
3719 BT_LOGD_STR("Putting length field path.");
3720 BT_PUT(sequence
->length_field_path
);
3725 void bt_field_type_string_destroy(struct bt_field_type
*type
)
3727 struct bt_field_type_string
*string
=
3728 (struct bt_field_type_string
*) type
;
3734 BT_LOGD("Destroying string field type object: addr=%p", type
);
3739 void generic_field_type_freeze(struct bt_field_type
*type
)
3745 void bt_field_type_integer_freeze(struct bt_field_type
*type
)
3747 struct bt_field_type_integer
*integer_type
= container_of(
3748 type
, struct bt_field_type_integer
, parent
);
3750 BT_LOGD("Freezing integer field type object: addr=%p", type
);
3752 if (integer_type
->mapped_clock
) {
3753 BT_LOGD_STR("Freezing integer field type's mapped clock class.");
3754 bt_clock_class_freeze(integer_type
->mapped_clock
);
3757 generic_field_type_freeze(type
);
3761 void bt_field_type_enumeration_freeze(struct bt_field_type
*type
)
3763 struct bt_field_type_enumeration
*enumeration_type
= container_of(
3764 type
, struct bt_field_type_enumeration
, parent
);
3766 BT_LOGD("Freezing enumeration field type object: addr=%p", type
);
3767 type
->alignment
= bt_field_type_get_alignment(type
);
3768 set_enumeration_range_overlap(type
);
3769 generic_field_type_freeze(type
);
3770 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3771 enumeration_type
->container
);
3772 bt_field_type_freeze(enumeration_type
->container
);
3776 void freeze_structure_field(struct structure_field
*field
)
3778 BT_LOGD("Freezing structure/variant field type field: field-addr=%p, "
3779 "field-ft-addr=%p, field-name=\"%s\"", field
,
3780 field
->type
, g_quark_to_string(field
->name
));
3781 bt_field_type_freeze(field
->type
);
3785 void bt_field_type_structure_freeze(struct bt_field_type
*type
)
3787 struct bt_field_type_structure
*structure_type
= container_of(
3788 type
, struct bt_field_type_structure
, parent
);
3790 /* Cache the alignment */
3791 BT_LOGD("Freezing structure field type object: addr=%p", type
);
3792 type
->alignment
= bt_field_type_get_alignment(type
);
3793 generic_field_type_freeze(type
);
3794 g_ptr_array_foreach(structure_type
->fields
,
3795 (GFunc
) freeze_structure_field
, NULL
);
3799 void bt_field_type_variant_freeze(struct bt_field_type
*type
)
3801 struct bt_field_type_variant
*variant_type
= container_of(
3802 type
, struct bt_field_type_variant
, parent
);
3804 BT_LOGD("Freezing variant field type object: addr=%p", type
);
3805 generic_field_type_freeze(type
);
3806 g_ptr_array_foreach(variant_type
->fields
,
3807 (GFunc
) freeze_structure_field
, NULL
);
3811 void bt_field_type_array_freeze(struct bt_field_type
*type
)
3813 struct bt_field_type_array
*array_type
= container_of(
3814 type
, struct bt_field_type_array
, parent
);
3816 /* Cache the alignment */
3817 BT_LOGD("Freezing array field type object: addr=%p", type
);
3818 type
->alignment
= bt_field_type_get_alignment(type
);
3819 generic_field_type_freeze(type
);
3820 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3821 array_type
->element_type
);
3822 bt_field_type_freeze(array_type
->element_type
);
3826 void bt_field_type_sequence_freeze(struct bt_field_type
*type
)
3828 struct bt_field_type_sequence
*sequence_type
= container_of(
3829 type
, struct bt_field_type_sequence
, parent
);
3831 /* Cache the alignment */
3832 BT_LOGD("Freezing sequence field type object: addr=%p", type
);
3833 type
->alignment
= bt_field_type_get_alignment(type
);
3834 generic_field_type_freeze(type
);
3835 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3836 sequence_type
->element_type
);
3837 bt_field_type_freeze(sequence_type
->element_type
);
3841 const char *get_encoding_string(enum bt_string_encoding encoding
)
3843 const char *encoding_string
;
3846 case BT_STRING_ENCODING_NONE
:
3847 encoding_string
= "none";
3849 case BT_STRING_ENCODING_ASCII
:
3850 encoding_string
= "ASCII";
3852 case BT_STRING_ENCODING_UTF8
:
3853 encoding_string
= "UTF8";
3856 encoding_string
= "unknown";
3860 return encoding_string
;
3864 const char *get_integer_base_string(enum bt_integer_base base
)
3866 const char *base_string
;
3869 case BT_INTEGER_BASE_DECIMAL
:
3870 case BT_INTEGER_BASE_UNSPECIFIED
:
3871 base_string
= "decimal";
3873 case BT_INTEGER_BASE_HEXADECIMAL
:
3874 base_string
= "hexadecimal";
3876 case BT_INTEGER_BASE_OCTAL
:
3877 base_string
= "octal";
3879 case BT_INTEGER_BASE_BINARY
:
3880 base_string
= "binary";
3883 base_string
= "unknown";
3891 void append_field_name(struct metadata_context
*context
,
3894 g_string_append_c(context
->string
, ' ');
3896 if (!bt_identifier_is_valid(name
) || *name
== '_') {
3897 g_string_append_c(context
->string
, '_');
3900 g_string_append(context
->string
, name
);
3904 int bt_field_type_integer_serialize(struct bt_field_type
*type
,
3905 struct metadata_context
*context
)
3907 struct bt_field_type_integer
*integer
= container_of(type
,
3908 struct bt_field_type_integer
, parent
);
3911 BT_LOGD("Serializing integer field type's metadata: "
3912 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3913 g_string_append_printf(context
->string
,
3914 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
3915 integer
->size
, type
->alignment
,
3916 (integer
->is_signed
? "true" : "false"),
3917 get_encoding_string(integer
->encoding
),
3918 get_integer_base_string(integer
->base
),
3919 get_byte_order_string(integer
->user_byte_order
));
3920 if (integer
->mapped_clock
) {
3921 const char *clock_name
= bt_clock_class_get_name(
3922 integer
->mapped_clock
);
3924 BT_ASSERT(clock_name
);
3925 g_string_append_printf(context
->string
,
3926 "; map = clock.%s.value", clock_name
);
3929 g_string_append(context
->string
, "; }");
3934 int bt_field_type_enumeration_serialize(struct bt_field_type
*type
,
3935 struct metadata_context
*context
)
3939 struct bt_field_type_enumeration
*enumeration
= container_of(type
,
3940 struct bt_field_type_enumeration
, parent
);
3941 struct bt_field_type
*container_type
;
3942 int container_signed
;
3944 BT_LOGD("Serializing enumeration field type's metadata: "
3945 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3946 container_type
= bt_field_type_enumeration_get_container_type(type
);
3947 BT_ASSERT(container_type
);
3948 container_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
3949 BT_ASSERT(container_signed
>= 0);
3950 g_string_append(context
->string
, "enum : ");
3951 BT_LOGD_STR("Serializing enumeration field type's container field type's metadata.");
3952 ret
= bt_field_type_serialize(enumeration
->container
, context
);
3954 BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
3955 "container-ft-addr=%p", enumeration
->container
);
3959 g_string_append(context
->string
, " { ");
3960 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
3961 struct enumeration_mapping
*mapping
=
3962 enumeration
->entries
->pdata
[entry
];
3963 const char *label
= g_quark_to_string(mapping
->string
);
3965 g_string_append(context
->string
, "\"");
3967 if (!bt_identifier_is_valid(label
) || label
[0] == '_') {
3968 g_string_append(context
->string
, "_");
3971 g_string_append_printf(context
->string
, "%s\" = ", label
);
3973 if (container_signed
) {
3974 if (mapping
->range_start
._signed
==
3975 mapping
->range_end
._signed
) {
3976 g_string_append_printf(context
->string
,
3978 mapping
->range_start
._signed
);
3980 g_string_append_printf(context
->string
,
3981 "%" PRId64
" ... %" PRId64
,
3982 mapping
->range_start
._signed
,
3983 mapping
->range_end
._signed
);
3986 if (mapping
->range_start
._unsigned
==
3987 mapping
->range_end
._unsigned
) {
3988 g_string_append_printf(context
->string
,
3990 mapping
->range_start
._unsigned
);
3992 g_string_append_printf(context
->string
,
3993 "%" PRIu64
" ... %" PRIu64
,
3994 mapping
->range_start
._unsigned
,
3995 mapping
->range_end
._unsigned
);
3999 g_string_append(context
->string
,
4000 ((entry
!= (enumeration
->entries
->len
- 1)) ?
4004 if (context
->field_name
->len
) {
4005 append_field_name(context
,
4006 context
->field_name
->str
);
4007 g_string_assign(context
->field_name
, "");
4010 bt_put(container_type
);
4015 int bt_field_type_floating_point_serialize(struct bt_field_type
*type
,
4016 struct metadata_context
*context
)
4018 struct bt_field_type_floating_point
*floating_point
= container_of(
4019 type
, struct bt_field_type_floating_point
, parent
);
4021 BT_LOGD("Serializing floating point number field type's metadata: "
4022 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4023 g_string_append_printf(context
->string
,
4024 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
4025 floating_point
->exp_dig
,
4026 floating_point
->mant_dig
,
4027 get_byte_order_string(floating_point
->user_byte_order
),
4033 int bt_field_type_structure_serialize(struct bt_field_type
*type
,
4034 struct metadata_context
*context
)
4037 unsigned int indent
;
4039 struct bt_field_type_structure
*structure
= container_of(type
,
4040 struct bt_field_type_structure
, parent
);
4041 GString
*structure_field_name
= context
->field_name
;
4043 BT_LOGD("Serializing structure field type's metadata: "
4044 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4045 context
->field_name
= g_string_new("");
4047 context
->current_indentation_level
++;
4048 g_string_append(context
->string
, "struct {\n");
4050 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4051 struct structure_field
*field
= structure
->fields
->pdata
[i
];
4053 BT_LOGD("Serializing structure field type's field metadata: "
4055 "field-ft-addr=%p, field-name=\"%s\"",
4056 i
, field
, g_quark_to_string(field
->name
));
4058 for (indent
= 0; indent
< context
->current_indentation_level
;
4060 g_string_append_c(context
->string
, '\t');
4063 g_string_assign(context
->field_name
,
4064 g_quark_to_string(field
->name
));
4065 ret
= bt_field_type_serialize(field
->type
, context
);
4067 BT_LOGW("Cannot serialize structure field type's field's metadata: "
4069 "field-ft-addr=%p, field-name=\"%s\"",
4071 g_quark_to_string(field
->name
));
4075 if (context
->field_name
->len
) {
4076 append_field_name(context
,
4077 context
->field_name
->str
);
4079 g_string_append(context
->string
, ";\n");
4082 context
->current_indentation_level
--;
4083 for (indent
= 0; indent
< context
->current_indentation_level
;
4085 g_string_append_c(context
->string
, '\t');
4088 g_string_append_printf(context
->string
, "} align(%u)",
4091 g_string_free(context
->field_name
, TRUE
);
4092 context
->field_name
= structure_field_name
;
4097 int bt_field_type_variant_serialize(struct bt_field_type
*type
,
4098 struct metadata_context
*context
)
4101 unsigned int indent
;
4103 struct bt_field_type_variant
*variant
= container_of(
4104 type
, struct bt_field_type_variant
, parent
);
4105 GString
*variant_field_name
= context
->field_name
;
4107 BT_LOGD("Serializing variant field type's metadata: "
4108 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4109 context
->field_name
= g_string_new("");
4110 if (variant
->tag_name
->len
> 0) {
4111 g_string_append(context
->string
, "variant <");
4112 append_field_name(context
, variant
->tag_name
->str
);
4113 g_string_append(context
->string
, "> {\n");
4115 g_string_append(context
->string
, "variant {\n");
4118 context
->current_indentation_level
++;
4119 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4120 struct structure_field
*field
= variant
->fields
->pdata
[i
];
4122 BT_LOGD("Serializing variant field type's field metadata: "
4124 "field-ft-addr=%p, field-name=\"%s\"",
4125 i
, field
, g_quark_to_string(field
->name
));
4127 g_string_assign(context
->field_name
,
4128 g_quark_to_string(field
->name
));
4129 for (indent
= 0; indent
< context
->current_indentation_level
;
4131 g_string_append_c(context
->string
, '\t');
4134 g_string_assign(context
->field_name
,
4135 g_quark_to_string(field
->name
));
4136 ret
= bt_field_type_serialize(field
->type
, context
);
4138 BT_LOGW("Cannot serialize variant field type's field's metadata: "
4140 "field-ft-addr=%p, field-name=\"%s\"",
4142 g_quark_to_string(field
->name
));
4146 if (context
->field_name
->len
) {
4147 append_field_name(context
,
4148 context
->field_name
->str
);
4149 g_string_append_c(context
->string
, ';');
4152 g_string_append_c(context
->string
, '\n');
4155 context
->current_indentation_level
--;
4156 for (indent
= 0; indent
< context
->current_indentation_level
;
4158 g_string_append_c(context
->string
, '\t');
4161 g_string_append(context
->string
, "}");
4163 g_string_free(context
->field_name
, TRUE
);
4164 context
->field_name
= variant_field_name
;
4169 int bt_field_type_array_serialize(struct bt_field_type
*type
,
4170 struct metadata_context
*context
)
4173 struct bt_field_type_array
*array
= container_of(type
,
4174 struct bt_field_type_array
, parent
);
4176 BT_LOGD("Serializing array field type's metadata: "
4177 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4178 BT_LOGD_STR("Serializing array field type's element field type's metadata.");
4179 ret
= bt_field_type_serialize(array
->element_type
, context
);
4181 BT_LOGW("Cannot serialize array field type's element field type's metadata: "
4182 "element-ft-addr=%p", array
->element_type
);
4186 if (context
->field_name
->len
) {
4187 append_field_name(context
,
4188 context
->field_name
->str
);
4190 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4191 g_string_assign(context
->field_name
, "");
4193 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4200 int bt_field_type_sequence_serialize(struct bt_field_type
*type
,
4201 struct metadata_context
*context
)
4204 struct bt_field_type_sequence
*sequence
= container_of(
4205 type
, struct bt_field_type_sequence
, parent
);
4207 BT_LOGD("Serializing sequence field type's metadata: "
4208 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4209 BT_LOGD_STR("Serializing sequence field type's element field type's metadata.");
4210 ret
= bt_field_type_serialize(sequence
->element_type
, context
);
4212 BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
4213 "element-ft-addr=%p", sequence
->element_type
);
4217 if (context
->field_name
->len
) {
4218 append_field_name(context
, context
->field_name
->str
);
4219 g_string_assign(context
->field_name
, "");
4221 g_string_append(context
->string
, "[");
4222 append_field_name(context
, sequence
->length_field_name
->str
);
4223 g_string_append(context
->string
, "]");
4229 int bt_field_type_string_serialize(struct bt_field_type
*type
,
4230 struct metadata_context
*context
)
4232 struct bt_field_type_string
*string
= container_of(
4233 type
, struct bt_field_type_string
, parent
);
4235 BT_LOGD("Serializing string field type's metadata: "
4236 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4237 g_string_append_printf(context
->string
,
4238 "string { encoding = %s; }",
4239 get_encoding_string(string
->encoding
));
4244 void bt_field_type_integer_set_byte_order(struct bt_field_type
*type
,
4245 enum bt_byte_order byte_order
)
4247 struct bt_field_type_integer
*integer_type
= container_of(type
,
4248 struct bt_field_type_integer
, parent
);
4250 integer_type
->user_byte_order
= byte_order
;
4254 void bt_field_type_enumeration_set_byte_order(
4255 struct bt_field_type
*type
, enum bt_byte_order byte_order
)
4257 struct bt_field_type_enumeration
*enum_type
= container_of(type
,
4258 struct bt_field_type_enumeration
, parent
);
4260 /* Safe to assume that container is an integer */
4261 bt_field_type_integer_set_byte_order(enum_type
->container
,
4266 void bt_field_type_floating_point_set_byte_order(
4267 struct bt_field_type
*type
, enum bt_byte_order byte_order
)
4269 struct bt_field_type_floating_point
*floating_point_type
=
4270 container_of(type
, struct bt_field_type_floating_point
,
4273 floating_point_type
->user_byte_order
= byte_order
;
4277 void bt_field_type_structure_set_byte_order(struct bt_field_type
*type
,
4278 enum bt_byte_order byte_order
)
4281 struct bt_field_type_structure
*structure_type
=
4282 container_of(type
, struct bt_field_type_structure
,
4285 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
4286 struct structure_field
*field
= g_ptr_array_index(
4287 structure_type
->fields
, i
);
4288 struct bt_field_type
*field_type
= field
->type
;
4290 if (set_byte_order_funcs
[field_type
->id
]) {
4291 set_byte_order_funcs
[field_type
->id
](
4292 field_type
, byte_order
);
4298 void bt_field_type_variant_set_byte_order(struct bt_field_type
*type
,
4299 enum bt_byte_order byte_order
)
4302 struct bt_field_type_variant
*variant_type
=
4303 container_of(type
, struct bt_field_type_variant
,
4306 for (i
= 0; i
< variant_type
->fields
->len
; i
++) {
4307 struct structure_field
*field
= g_ptr_array_index(
4308 variant_type
->fields
, i
);
4309 struct bt_field_type
*field_type
= field
->type
;
4311 if (set_byte_order_funcs
[field_type
->id
]) {
4312 set_byte_order_funcs
[field_type
->id
](
4313 field_type
, byte_order
);
4319 void bt_field_type_array_set_byte_order(struct bt_field_type
*type
,
4320 enum bt_byte_order byte_order
)
4322 struct bt_field_type_array
*array_type
=
4323 container_of(type
, struct bt_field_type_array
,
4326 if (set_byte_order_funcs
[array_type
->element_type
->id
]) {
4327 set_byte_order_funcs
[array_type
->element_type
->id
](
4328 array_type
->element_type
, byte_order
);
4333 void bt_field_type_sequence_set_byte_order(struct bt_field_type
*type
,
4334 enum bt_byte_order byte_order
)
4336 struct bt_field_type_sequence
*sequence_type
=
4337 container_of(type
, struct bt_field_type_sequence
,
4340 if (set_byte_order_funcs
[
4341 sequence_type
->element_type
->id
]) {
4342 set_byte_order_funcs
[
4343 sequence_type
->element_type
->id
](
4344 sequence_type
->element_type
, byte_order
);
4349 struct bt_field_type
*bt_field_type_integer_copy(
4350 struct bt_field_type
*type
)
4352 struct bt_field_type
*copy
;
4353 struct bt_field_type_integer
*integer
, *copy_integer
;
4355 BT_LOGD("Copying integer field type's: addr=%p", type
);
4356 integer
= container_of(type
, struct bt_field_type_integer
, parent
);
4357 copy
= bt_field_type_integer_create(integer
->size
);
4359 BT_LOGE_STR("Cannot create integer field type.");
4363 copy_integer
= container_of(copy
, struct bt_field_type_integer
,
4365 copy_integer
->mapped_clock
= bt_get(integer
->mapped_clock
);
4366 copy_integer
->user_byte_order
= integer
->user_byte_order
;
4367 copy_integer
->is_signed
= integer
->is_signed
;
4368 copy_integer
->size
= integer
->size
;
4369 copy_integer
->base
= integer
->base
;
4370 copy_integer
->encoding
= integer
->encoding
;
4371 BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4379 struct bt_field_type
*bt_field_type_enumeration_copy(
4380 struct bt_field_type
*type
)
4383 struct bt_field_type
*copy
= NULL
, *copy_container
;
4384 struct bt_field_type_enumeration
*enumeration
, *copy_enumeration
;
4386 BT_LOGD("Copying enumeration field type's: addr=%p", type
);
4387 enumeration
= container_of(type
, struct bt_field_type_enumeration
,
4390 /* Copy the source enumeration's container */
4391 BT_LOGD_STR("Copying enumeration field type's container field type.");
4392 copy_container
= bt_field_type_copy(enumeration
->container
);
4393 if (!copy_container
) {
4394 BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
4398 copy
= bt_field_type_enumeration_create(copy_container
);
4400 BT_LOGE_STR("Cannot create enumeration field type.");
4403 copy_enumeration
= container_of(copy
,
4404 struct bt_field_type_enumeration
, parent
);
4406 /* Copy all enumaration entries */
4407 for (i
= 0; i
< enumeration
->entries
->len
; i
++) {
4408 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4409 enumeration
->entries
, i
);
4410 struct enumeration_mapping
*copy_mapping
= g_new0(
4411 struct enumeration_mapping
, 1);
4413 if (!copy_mapping
) {
4414 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4418 *copy_mapping
= *mapping
;
4419 g_ptr_array_add(copy_enumeration
->entries
, copy_mapping
);
4422 BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4426 bt_put(copy_container
);
4429 bt_put(copy_container
);
4435 struct bt_field_type
*bt_field_type_floating_point_copy(
4436 struct bt_field_type
*type
)
4438 struct bt_field_type
*copy
;
4439 struct bt_field_type_floating_point
*floating_point
, *copy_float
;
4441 BT_LOGD("Copying floating point number field type's: addr=%p", type
);
4442 floating_point
= container_of(type
,
4443 struct bt_field_type_floating_point
, parent
);
4444 copy
= bt_field_type_floating_point_create();
4446 BT_LOGE_STR("Cannot create floating point number field type.");
4450 copy_float
= container_of(copy
,
4451 struct bt_field_type_floating_point
, parent
);
4452 copy_float
->user_byte_order
= floating_point
->user_byte_order
;
4453 copy_float
->exp_dig
= floating_point
->exp_dig
;
4454 copy_float
->mant_dig
= floating_point
->mant_dig
;
4455 BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4462 struct bt_field_type
*bt_field_type_structure_copy(
4463 struct bt_field_type
*type
)
4466 GHashTableIter iter
;
4467 gpointer key
, value
;
4468 struct bt_field_type
*copy
;
4469 struct bt_field_type_structure
*structure
, *copy_structure
;
4471 BT_LOGD("Copying structure field type's: addr=%p", type
);
4472 structure
= container_of(type
, struct bt_field_type_structure
,
4474 copy
= bt_field_type_structure_create();
4476 BT_LOGE_STR("Cannot create structure field type.");
4480 copy_structure
= container_of(copy
,
4481 struct bt_field_type_structure
, parent
);
4483 /* Copy field_name_to_index */
4484 g_hash_table_iter_init(&iter
, structure
->field_name_to_index
);
4485 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4486 g_hash_table_insert(copy_structure
->field_name_to_index
,
4490 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4491 struct structure_field
*entry
, *copy_entry
;
4492 struct bt_field_type
*copy_field
;
4494 entry
= g_ptr_array_index(structure
->fields
, i
);
4495 BT_LOGD("Copying structure field type's field: "
4496 "index=%" PRId64
", "
4497 "field-ft-addr=%p, field-name=\"%s\"",
4498 i
, entry
, g_quark_to_string(entry
->name
));
4499 copy_entry
= g_new0(struct structure_field
, 1);
4501 BT_LOGE_STR("Failed to allocate one structure field type field.");
4505 copy_field
= bt_field_type_copy(entry
->type
);
4507 BT_LOGE("Cannot copy structure field type's field: "
4508 "index=%" PRId64
", "
4509 "field-ft-addr=%p, field-name=\"%s\"",
4510 i
, entry
, g_quark_to_string(entry
->name
));
4515 copy_entry
->name
= entry
->name
;
4516 copy_entry
->type
= copy_field
;
4517 g_ptr_array_add(copy_structure
->fields
, copy_entry
);
4520 BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4531 struct bt_field_type
*bt_field_type_variant_copy(
4532 struct bt_field_type
*type
)
4535 GHashTableIter iter
;
4536 gpointer key
, value
;
4537 struct bt_field_type
*copy
= NULL
, *copy_tag
= NULL
;
4538 struct bt_field_type_variant
*variant
, *copy_variant
;
4540 BT_LOGD("Copying variant field type's: addr=%p", type
);
4541 variant
= container_of(type
, struct bt_field_type_variant
,
4544 BT_LOGD_STR("Copying variant field type's tag field type.");
4545 copy_tag
= bt_field_type_copy(&variant
->tag
->parent
);
4547 BT_LOGE_STR("Cannot copy variant field type's tag field type.");
4552 copy
= bt_field_type_variant_create(copy_tag
,
4553 variant
->tag_name
->len
? variant
->tag_name
->str
: NULL
);
4555 BT_LOGE_STR("Cannot create variant field type.");
4559 copy_variant
= container_of(copy
, struct bt_field_type_variant
,
4562 /* Copy field_name_to_index */
4563 g_hash_table_iter_init(&iter
, variant
->field_name_to_index
);
4564 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4565 g_hash_table_insert(copy_variant
->field_name_to_index
,
4569 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4570 struct structure_field
*entry
, *copy_entry
;
4571 struct bt_field_type
*copy_field
;
4573 entry
= g_ptr_array_index(variant
->fields
, i
);
4574 BT_LOGD("Copying variant field type's field: "
4575 "index=%" PRId64
", "
4576 "field-ft-addr=%p, field-name=\"%s\"",
4577 i
, entry
, g_quark_to_string(entry
->name
));
4578 copy_entry
= g_new0(struct structure_field
, 1);
4580 BT_LOGE_STR("Failed to allocate one variant field type field.");
4584 copy_field
= bt_field_type_copy(entry
->type
);
4586 BT_LOGE("Cannot copy variant field type's field: "
4587 "index=%" PRId64
", "
4588 "field-ft-addr=%p, field-name=\"%s\"",
4589 i
, entry
, g_quark_to_string(entry
->name
));
4594 copy_entry
->name
= entry
->name
;
4595 copy_entry
->type
= copy_field
;
4596 g_ptr_array_add(copy_variant
->fields
, copy_entry
);
4599 if (variant
->tag_field_path
) {
4600 BT_LOGD_STR("Copying variant field type's tag field path.");
4601 copy_variant
->tag_field_path
= bt_field_path_copy(
4602 variant
->tag_field_path
);
4603 if (!copy_variant
->tag_field_path
) {
4604 BT_LOGE_STR("Cannot copy variant field type's tag field path.");
4609 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4622 struct bt_field_type
*bt_field_type_array_copy(
4623 struct bt_field_type
*type
)
4625 struct bt_field_type
*copy
= NULL
, *copy_element
;
4626 struct bt_field_type_array
*array
;
4628 BT_LOGD("Copying array field type's: addr=%p", type
);
4629 array
= container_of(type
, struct bt_field_type_array
,
4631 BT_LOGD_STR("Copying array field type's element field type.");
4632 copy_element
= bt_field_type_copy(array
->element_type
);
4633 if (!copy_element
) {
4634 BT_LOGE_STR("Cannot copy array field type's element field type.");
4638 copy
= bt_field_type_array_create(copy_element
, array
->length
);
4640 BT_LOGE_STR("Cannot create array field type.");
4644 BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
4648 bt_put(copy_element
);
4653 struct bt_field_type
*bt_field_type_sequence_copy(
4654 struct bt_field_type
*type
)
4656 struct bt_field_type
*copy
= NULL
, *copy_element
;
4657 struct bt_field_type_sequence
*sequence
, *copy_sequence
;
4659 BT_LOGD("Copying sequence field type's: addr=%p", type
);
4660 sequence
= container_of(type
, struct bt_field_type_sequence
,
4662 BT_LOGD_STR("Copying sequence field type's element field type.");
4663 copy_element
= bt_field_type_copy(sequence
->element_type
);
4664 if (!copy_element
) {
4665 BT_LOGE_STR("Cannot copy sequence field type's element field type.");
4669 copy
= bt_field_type_sequence_create(copy_element
,
4670 sequence
->length_field_name
->len
?
4671 sequence
->length_field_name
->str
: NULL
);
4673 BT_LOGE_STR("Cannot create sequence field type.");
4677 copy_sequence
= container_of(copy
, struct bt_field_type_sequence
,
4679 if (sequence
->length_field_path
) {
4680 BT_LOGD_STR("Copying sequence field type's length field path.");
4681 copy_sequence
->length_field_path
= bt_field_path_copy(
4682 sequence
->length_field_path
);
4683 if (!copy_sequence
->length_field_path
) {
4684 BT_LOGE_STR("Cannot copy sequence field type's length field path.");
4689 BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4693 bt_put(copy_element
);
4701 struct bt_field_type
*bt_field_type_string_copy(
4702 struct bt_field_type
*type
)
4704 struct bt_field_type
*copy
;
4706 BT_LOGD("Copying string field type's: addr=%p", type
);
4707 copy
= bt_field_type_string_create();
4709 BT_LOGE_STR("Cannot create string field type.");
4713 BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
4720 int bt_field_type_integer_compare(struct bt_field_type
*type_a
,
4721 struct bt_field_type
*type_b
)
4724 struct bt_field_type_integer
*int_type_a
;
4725 struct bt_field_type_integer
*int_type_b
;
4727 int_type_a
= container_of(type_a
, struct bt_field_type_integer
,
4729 int_type_b
= container_of(type_b
, struct bt_field_type_integer
,
4733 if (int_type_a
->size
!= int_type_b
->size
) {
4734 BT_LOGV("Integer field types differ: different sizes: "
4735 "ft-a-size=%u, ft-b-size=%u",
4736 int_type_a
->size
, int_type_b
->size
);
4741 if (int_type_a
->user_byte_order
!= int_type_b
->user_byte_order
) {
4742 BT_LOGV("Integer field types differ: different byte orders: "
4743 "ft-a-bo=%s, ft-b-bo=%s",
4744 bt_byte_order_string(int_type_a
->user_byte_order
),
4745 bt_byte_order_string(int_type_b
->user_byte_order
));
4750 if (int_type_a
->is_signed
!= int_type_b
->is_signed
) {
4751 BT_LOGV("Integer field types differ: different signedness: "
4752 "ft-a-is-signed=%d, ft-b-is-signed=%d",
4753 int_type_a
->is_signed
,
4754 int_type_b
->is_signed
);
4759 if (int_type_a
->base
!= int_type_b
->base
) {
4760 BT_LOGV("Integer field types differ: different bases: "
4761 "ft-a-base=%s, ft-b-base=%s",
4762 bt_integer_base_string(int_type_a
->base
),
4763 bt_integer_base_string(int_type_b
->base
));
4768 if (int_type_a
->encoding
!= int_type_b
->encoding
) {
4769 BT_LOGV("Integer field types differ: different encodings: "
4770 "ft-a-encoding=%s, ft-b-encoding=%s",
4771 bt_string_encoding_string(int_type_a
->encoding
),
4772 bt_string_encoding_string(int_type_b
->encoding
));
4776 /* Mapped clock class */
4777 if (int_type_a
->mapped_clock
) {
4778 if (!int_type_b
->mapped_clock
) {
4779 BT_LOGV_STR("Integer field types differ: field type A "
4780 "has a mapped clock class, but field type B "
4785 if (bt_clock_class_compare(int_type_a
->mapped_clock
,
4786 int_type_b
->mapped_clock
) != 0) {
4787 BT_LOGV_STR("Integer field types differ: different "
4788 "mapped clock classes.");
4791 if (int_type_b
->mapped_clock
) {
4792 BT_LOGV_STR("Integer field types differ: field type A "
4793 "has no description, but field type B has one.");
4806 int bt_field_type_floating_point_compare(struct bt_field_type
*type_a
,
4807 struct bt_field_type
*type_b
)
4810 struct bt_field_type_floating_point
*float_a
;
4811 struct bt_field_type_floating_point
*float_b
;
4813 float_a
= container_of(type_a
,
4814 struct bt_field_type_floating_point
, parent
);
4815 float_b
= container_of(type_b
,
4816 struct bt_field_type_floating_point
, parent
);
4819 if (float_a
->user_byte_order
!= float_b
->user_byte_order
) {
4820 BT_LOGV("Floating point number field types differ: different byte orders: "
4821 "ft-a-bo=%s, ft-b-bo=%s",
4822 bt_byte_order_string(float_a
->user_byte_order
),
4823 bt_byte_order_string(float_b
->user_byte_order
));
4827 /* Exponent length */
4828 if (float_a
->exp_dig
!= float_b
->exp_dig
) {
4829 BT_LOGV("Floating point number field types differ: different exponent sizes: "
4830 "ft-a-exp-size=%u, ft-b-exp-size=%u",
4831 float_a
->exp_dig
, float_b
->exp_dig
);
4835 /* Mantissa length */
4836 if (float_a
->mant_dig
!= float_b
->mant_dig
) {
4837 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
4838 "ft-a-mant-size=%u, ft-b-mant-size=%u",
4839 float_a
->mant_dig
, float_b
->mant_dig
);
4851 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
4852 struct enumeration_mapping
*mapping_b
)
4857 if (mapping_a
->string
!= mapping_b
->string
) {
4858 BT_LOGV("Enumeration field type mappings differ: different names: "
4859 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
4860 g_quark_to_string(mapping_a
->string
),
4861 g_quark_to_string(mapping_b
->string
));
4866 if (mapping_a
->range_start
._unsigned
!=
4867 mapping_b
->range_start
._unsigned
) {
4868 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
4869 "mapping-a-range-start-unsigned=%" PRIu64
", "
4870 "mapping-b-range-start-unsigned=%" PRIu64
,
4871 mapping_a
->range_start
._unsigned
,
4872 mapping_b
->range_start
._unsigned
);
4877 if (mapping_a
->range_end
._unsigned
!=
4878 mapping_b
->range_end
._unsigned
) {
4879 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
4880 "mapping-a-range-end-unsigned=%" PRIu64
", "
4881 "mapping-b-range-end-unsigned=%" PRIu64
,
4882 mapping_a
->range_end
._unsigned
,
4883 mapping_b
->range_end
._unsigned
);
4895 int bt_field_type_enumeration_compare(struct bt_field_type
*type_a
,
4896 struct bt_field_type
*type_b
)
4900 struct bt_field_type_enumeration
*enum_a
;
4901 struct bt_field_type_enumeration
*enum_b
;
4903 enum_a
= container_of(type_a
,
4904 struct bt_field_type_enumeration
, parent
);
4905 enum_b
= container_of(type_b
,
4906 struct bt_field_type_enumeration
, parent
);
4908 /* Container field type */
4909 ret
= bt_field_type_compare(enum_a
->container
, enum_b
->container
);
4911 BT_LOGV("Enumeration field types differ: different container field types: "
4912 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
4913 enum_a
->container
, enum_b
->container
);
4920 if (enum_a
->entries
->len
!= enum_b
->entries
->len
) {
4924 for (i
= 0; i
< enum_a
->entries
->len
; ++i
) {
4925 struct enumeration_mapping
*mapping_a
=
4926 g_ptr_array_index(enum_a
->entries
, i
);
4927 struct enumeration_mapping
*mapping_b
=
4928 g_ptr_array_index(enum_b
->entries
, i
);
4930 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4931 BT_LOGV("Enumeration field types differ: different mappings: "
4932 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4933 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4934 mapping_a
, mapping_b
,
4935 g_quark_to_string(mapping_a
->string
),
4936 g_quark_to_string(mapping_b
->string
));
4949 int bt_field_type_string_compare(struct bt_field_type
*type_a
,
4950 struct bt_field_type
*type_b
)
4953 struct bt_field_type_string
*string_a
;
4954 struct bt_field_type_string
*string_b
;
4956 string_a
= container_of(type_a
,
4957 struct bt_field_type_string
, parent
);
4958 string_b
= container_of(type_b
,
4959 struct bt_field_type_string
, parent
);
4962 if (string_a
->encoding
!= string_b
->encoding
) {
4963 BT_LOGV("String field types differ: different encodings: "
4964 "ft-a-encoding=%s, ft-b-encoding=%s",
4965 bt_string_encoding_string(string_a
->encoding
),
4966 bt_string_encoding_string(string_b
->encoding
));
4978 int compare_structure_fields(struct structure_field
*field_a
,
4979 struct structure_field
*field_b
)
4984 if (field_a
->name
!= field_b
->name
) {
4985 BT_LOGV("Structure/variant field type fields differ: different names: "
4986 "field-a-name=%s, field-b-name=%s",
4987 g_quark_to_string(field_a
->name
),
4988 g_quark_to_string(field_b
->name
));
4993 ret
= bt_field_type_compare(field_a
->type
, field_b
->type
);
4995 BT_LOGV("Structure/variant field type fields differ: different field types: "
4996 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
4997 g_quark_to_string(field_a
->name
),
4998 field_a
->type
, field_b
->type
);
5006 int bt_field_type_structure_compare(struct bt_field_type
*type_a
,
5007 struct bt_field_type
*type_b
)
5011 struct bt_field_type_structure
*struct_a
;
5012 struct bt_field_type_structure
*struct_b
;
5014 struct_a
= container_of(type_a
,
5015 struct bt_field_type_structure
, parent
);
5016 struct_b
= container_of(type_b
,
5017 struct bt_field_type_structure
, parent
);
5020 if (bt_field_type_get_alignment(type_a
) !=
5021 bt_field_type_get_alignment(type_b
)) {
5022 BT_LOGV("Structure field types differ: different alignments: "
5023 "ft-a-align=%u, ft-b-align=%u",
5024 bt_field_type_get_alignment(type_a
),
5025 bt_field_type_get_alignment(type_b
));
5030 if (struct_a
->fields
->len
!= struct_b
->fields
->len
) {
5031 BT_LOGV("Structure field types differ: different field counts: "
5032 "ft-a-field-count=%u, ft-b-field-count=%u",
5033 struct_a
->fields
->len
, struct_b
->fields
->len
);
5037 for (i
= 0; i
< struct_a
->fields
->len
; ++i
) {
5038 struct structure_field
*field_a
=
5039 g_ptr_array_index(struct_a
->fields
, i
);
5040 struct structure_field
*field_b
=
5041 g_ptr_array_index(struct_b
->fields
, i
);
5043 ret
= compare_structure_fields(field_a
, field_b
);
5045 /* compare_structure_fields() logs what differs */
5046 BT_LOGV_STR("Structure field types differ: different fields.");
5059 int bt_field_type_variant_compare(struct bt_field_type
*type_a
,
5060 struct bt_field_type
*type_b
)
5064 struct bt_field_type_variant
*variant_a
;
5065 struct bt_field_type_variant
*variant_b
;
5067 variant_a
= container_of(type_a
,
5068 struct bt_field_type_variant
, parent
);
5069 variant_b
= container_of(type_b
,
5070 struct bt_field_type_variant
, parent
);
5073 if (strcmp(variant_a
->tag_name
->str
, variant_b
->tag_name
->str
)) {
5074 BT_LOGV("Variant field types differ: different tag field names: "
5075 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
5076 variant_a
->tag_name
->str
, variant_b
->tag_name
->str
);
5081 ret
= bt_field_type_compare(
5082 (struct bt_field_type
*) variant_a
->tag
,
5083 (struct bt_field_type
*) variant_b
->tag
);
5085 BT_LOGV("Variant field types differ: different tag field types: "
5086 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
5087 variant_a
->tag
, variant_b
->tag
);
5094 if (variant_a
->fields
->len
!= variant_b
->fields
->len
) {
5095 BT_LOGV("Structure field types differ: different field counts: "
5096 "ft-a-field-count=%u, ft-b-field-count=%u",
5097 variant_a
->fields
->len
, variant_b
->fields
->len
);
5101 for (i
= 0; i
< variant_a
->fields
->len
; ++i
) {
5102 struct structure_field
*field_a
=
5103 g_ptr_array_index(variant_a
->fields
, i
);
5104 struct structure_field
*field_b
=
5105 g_ptr_array_index(variant_b
->fields
, i
);
5107 ret
= compare_structure_fields(field_a
, field_b
);
5109 /* compare_structure_fields() logs what differs */
5110 BT_LOGV_STR("Variant field types differ: different fields.");
5123 int bt_field_type_array_compare(struct bt_field_type
*type_a
,
5124 struct bt_field_type
*type_b
)
5127 struct bt_field_type_array
*array_a
;
5128 struct bt_field_type_array
*array_b
;
5130 array_a
= container_of(type_a
,
5131 struct bt_field_type_array
, parent
);
5132 array_b
= container_of(type_b
,
5133 struct bt_field_type_array
, parent
);
5136 if (array_a
->length
!= array_b
->length
) {
5137 BT_LOGV("Structure field types differ: different lengths: "
5138 "ft-a-length=%u, ft-b-length=%u",
5139 array_a
->length
, array_b
->length
);
5144 ret
= bt_field_type_compare(array_a
->element_type
,
5145 array_b
->element_type
);
5147 BT_LOGV("Array field types differ: different element field types: "
5148 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5149 array_a
->element_type
, array_b
->element_type
);
5157 int bt_field_type_sequence_compare(struct bt_field_type
*type_a
,
5158 struct bt_field_type
*type_b
)
5161 struct bt_field_type_sequence
*sequence_a
;
5162 struct bt_field_type_sequence
*sequence_b
;
5164 sequence_a
= container_of(type_a
,
5165 struct bt_field_type_sequence
, parent
);
5166 sequence_b
= container_of(type_b
,
5167 struct bt_field_type_sequence
, parent
);
5170 if (strcmp(sequence_a
->length_field_name
->str
,
5171 sequence_b
->length_field_name
->str
)) {
5172 BT_LOGV("Sequence field types differ: different length field names: "
5173 "ft-a-length-field-name=\"%s\", "
5174 "ft-b-length-field-name=\"%s\"",
5175 sequence_a
->length_field_name
->str
,
5176 sequence_b
->length_field_name
->str
);
5181 ret
= bt_field_type_compare(sequence_a
->element_type
,
5182 sequence_b
->element_type
);
5184 BT_LOGV("Sequence field types differ: different element field types: "
5185 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5186 sequence_a
->element_type
, sequence_b
->element_type
);
5193 int bt_field_type_compare(struct bt_field_type
*type_a
,
5194 struct bt_field_type
*type_b
)
5198 if (type_a
== type_b
) {
5199 /* Same reference: equal (even if both are NULL) */
5205 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
5211 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
5216 if (type_a
->id
!= type_b
->id
) {
5217 /* Different type IDs */
5218 BT_LOGV("Field types differ: different IDs: "
5219 "ft-a-addr=%p, ft-b-addr=%p, "
5220 "ft-a-id=%s, ft-b-id=%s",
5222 bt_field_type_id_string(type_a
->id
),
5223 bt_field_type_id_string(type_b
->id
));
5227 if (type_a
->id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
5228 /* Both have unknown type IDs */
5229 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
5233 ret
= type_compare_funcs
[type_a
->id
](type_a
, type_b
);
5235 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
5244 int64_t bt_field_type_get_field_count(struct bt_field_type
*field_type
)
5246 int64_t field_count
= -1;
5247 enum bt_field_type_id type_id
= bt_field_type_get_type_id(field_type
);
5250 case CTF_TYPE_STRUCT
:
5252 bt_field_type_structure_get_field_count(field_type
);
5254 case CTF_TYPE_VARIANT
:
5256 bt_field_type_variant_get_field_count(field_type
);
5258 case CTF_TYPE_ARRAY
:
5259 case CTF_TYPE_SEQUENCE
:
5261 * Array and sequence types always contain a single member
5262 * (the element type).
5274 struct bt_field_type
*bt_field_type_get_field_at_index(
5275 struct bt_field_type
*field_type
, int index
)
5277 struct bt_field_type
*field
= NULL
;
5278 enum bt_field_type_id type_id
= bt_field_type_get_type_id(field_type
);
5281 case CTF_TYPE_STRUCT
:
5283 int ret
= bt_field_type_structure_get_field_by_index(
5284 field_type
, NULL
, &field
, index
);
5291 case CTF_TYPE_VARIANT
:
5293 int ret
= bt_field_type_variant_get_field_by_index(
5294 field_type
, NULL
, &field
, index
);
5301 case CTF_TYPE_ARRAY
:
5302 field
= bt_field_type_array_get_element_type(field_type
);
5304 case CTF_TYPE_SEQUENCE
:
5305 field
= bt_field_type_sequence_get_element_type(field_type
);
5315 int bt_field_type_get_field_index(struct bt_field_type
*field_type
,
5318 int field_index
= -1;
5319 enum bt_field_type_id type_id
= bt_field_type_get_type_id(field_type
);
5322 case CTF_TYPE_STRUCT
:
5323 field_index
= bt_field_type_structure_get_field_name_index(
5326 case CTF_TYPE_VARIANT
:
5327 field_index
= bt_field_type_variant_get_field_name_index(
5337 struct bt_field_path
*bt_field_type_variant_get_tag_field_path(
5338 struct bt_field_type
*type
)
5340 struct bt_field_path
*field_path
= NULL
;
5341 struct bt_field_type_variant
*variant
;
5344 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5348 if (!bt_field_type_is_variant(type
)) {
5349 BT_LOGW("Invalid parameter: field type is not a variant field type: "
5350 "addr=%p, ft-id=%s", type
,
5351 bt_field_type_id_string(type
->id
));
5355 variant
= container_of(type
, struct bt_field_type_variant
,
5357 field_path
= bt_get(variant
->tag_field_path
);
5362 struct bt_field_path
*bt_field_type_sequence_get_length_field_path(
5363 struct bt_field_type
*type
)
5365 struct bt_field_path
*field_path
= NULL
;
5366 struct bt_field_type_sequence
*sequence
;
5369 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5373 if (!bt_field_type_is_sequence(type
)) {
5374 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
5375 "addr=%p, ft-id=%s", type
,
5376 bt_field_type_id_string(type
->id
));
5380 sequence
= container_of(type
, struct bt_field_type_sequence
,
5382 field_path
= bt_get(sequence
->length_field_path
);