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>
47 struct range_overlap_query
{
62 void bt_ctf_field_type_destroy(struct bt_object
*);
64 void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type
*);
66 void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type
*);
68 void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type
*);
70 void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type
*);
72 void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type
*);
74 void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type
*);
76 void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type
*);
78 void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type
*);
81 void (* const type_destroy_funcs
[])(struct bt_ctf_field_type
*) = {
82 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_destroy
,
83 [BT_CTF_FIELD_TYPE_ID_ENUM
] =
84 bt_ctf_field_type_enumeration_destroy
,
85 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
86 bt_ctf_field_type_floating_point_destroy
,
87 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_destroy
,
88 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_destroy
,
89 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_destroy
,
90 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_destroy
,
91 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_destroy
,
95 void generic_field_type_freeze(struct bt_ctf_field_type
*);
97 void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type
*);
99 void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type
*);
101 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*);
103 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*);
105 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*);
107 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*);
110 type_freeze_func
const type_freeze_funcs
[] = {
111 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_freeze
,
112 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_freeze
,
113 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = generic_field_type_freeze
,
114 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_freeze
,
115 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_freeze
,
116 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_freeze
,
117 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_freeze
,
118 [BT_CTF_FIELD_TYPE_ID_STRING
] = generic_field_type_freeze
,
122 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*,
123 struct metadata_context
*);
125 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*,
126 struct metadata_context
*);
128 int bt_ctf_field_type_floating_point_serialize(
129 struct bt_ctf_field_type
*, struct metadata_context
*);
131 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*,
132 struct metadata_context
*);
134 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*,
135 struct metadata_context
*);
137 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*,
138 struct metadata_context
*);
140 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*,
141 struct metadata_context
*);
143 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*,
144 struct metadata_context
*);
147 type_serialize_func
const type_serialize_funcs
[] = {
148 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_serialize
,
149 [BT_CTF_FIELD_TYPE_ID_ENUM
] =
150 bt_ctf_field_type_enumeration_serialize
,
151 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
152 bt_ctf_field_type_floating_point_serialize
,
153 [BT_CTF_FIELD_TYPE_ID_STRUCT
] =
154 bt_ctf_field_type_structure_serialize
,
155 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_serialize
,
156 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_serialize
,
157 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_serialize
,
158 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_serialize
,
162 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*,
163 enum bt_ctf_byte_order byte_order
);
165 void bt_ctf_field_type_enumeration_set_byte_order(struct bt_ctf_field_type
*,
166 enum bt_ctf_byte_order byte_order
);
168 void bt_ctf_field_type_floating_point_set_byte_order(
169 struct bt_ctf_field_type
*, enum bt_ctf_byte_order byte_order
);
171 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*,
172 enum bt_ctf_byte_order byte_order
);
174 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*,
175 enum bt_ctf_byte_order byte_order
);
177 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*,
178 enum bt_ctf_byte_order byte_order
);
180 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*,
181 enum bt_ctf_byte_order byte_order
);
184 void (* const set_byte_order_funcs
[])(struct bt_ctf_field_type
*,
185 enum bt_ctf_byte_order
) = {
186 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_set_byte_order
,
187 [BT_CTF_FIELD_TYPE_ID_ENUM
] =
188 bt_ctf_field_type_enumeration_set_byte_order
,
189 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
190 bt_ctf_field_type_floating_point_set_byte_order
,
191 [BT_CTF_FIELD_TYPE_ID_STRUCT
] =
192 bt_ctf_field_type_structure_set_byte_order
,
193 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_set_byte_order
,
194 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_set_byte_order
,
195 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_set_byte_order
,
196 [BT_CTF_FIELD_TYPE_ID_STRING
] = NULL
,
200 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
201 struct bt_ctf_field_type
*);
203 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
204 struct bt_ctf_field_type
*);
206 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
207 struct bt_ctf_field_type
*);
209 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
210 struct bt_ctf_field_type
*);
212 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
213 struct bt_ctf_field_type
*);
215 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
216 struct bt_ctf_field_type
*);
218 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
219 struct bt_ctf_field_type
*);
221 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
222 struct bt_ctf_field_type
*);
225 struct bt_ctf_field_type
*(* const type_copy_funcs
[])(
226 struct bt_ctf_field_type
*) = {
227 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_copy
,
228 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_copy
,
229 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_type_floating_point_copy
,
230 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_copy
,
231 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_copy
,
232 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_copy
,
233 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_copy
,
234 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_copy
,
238 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*,
239 struct bt_ctf_field_type
*);
241 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*,
242 struct bt_ctf_field_type
*);
244 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*,
245 struct bt_ctf_field_type
*);
247 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*,
248 struct bt_ctf_field_type
*);
250 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*,
251 struct bt_ctf_field_type
*);
253 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*,
254 struct bt_ctf_field_type
*);
256 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*,
257 struct bt_ctf_field_type
*);
259 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*,
260 struct bt_ctf_field_type
*);
263 int (* const type_compare_funcs
[])(struct bt_ctf_field_type
*,
264 struct bt_ctf_field_type
*) = {
265 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_compare
,
266 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_compare
,
267 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_type_floating_point_compare
,
268 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_compare
,
269 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_compare
,
270 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_compare
,
271 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_compare
,
272 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_compare
,
276 int bt_ctf_field_type_integer_validate(struct bt_ctf_field_type
*);
278 int bt_ctf_field_type_enumeration_validate(struct bt_ctf_field_type
*);
280 int bt_ctf_field_type_structure_validate(struct bt_ctf_field_type
*);
282 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type
*);
284 int bt_ctf_field_type_array_validate(struct bt_ctf_field_type
*);
286 int bt_ctf_field_type_sequence_validate(struct bt_ctf_field_type
*);
289 int (* const type_validate_funcs
[])(struct bt_ctf_field_type
*) = {
290 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_validate
,
291 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = NULL
,
292 [BT_CTF_FIELD_TYPE_ID_STRING
] = NULL
,
293 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_validate
,
294 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_validate
,
295 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_validate
,
296 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_validate
,
297 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_validate
,
301 void destroy_enumeration_mapping(struct enumeration_mapping
*mapping
)
307 void destroy_structure_field(struct structure_field
*field
)
313 BT_LOGD("Destroying structure/variant field type's field object: "
314 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
315 field
, field
->type
, g_quark_to_string(field
->name
));
316 BT_LOGD_STR("Putting field type.");
322 void check_ranges_overlap(gpointer element
, gpointer query
)
324 struct enumeration_mapping
*mapping
= element
;
325 struct range_overlap_query
*overlap_query
= query
;
327 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
328 && overlap_query
->range_start
._signed
<=
329 mapping
->range_end
._signed
) {
330 overlap_query
->overlaps
= 1;
331 overlap_query
->mapping_name
= mapping
->string
;
334 overlap_query
->overlaps
|=
335 mapping
->string
== overlap_query
->mapping_name
;
337 if (overlap_query
->overlaps
) {
338 BT_LOGV("Overlapping enumeration field type mappings: "
339 "mapping-name=\"%s\", "
340 "mapping-a-range-start=%" PRId64
", "
341 "mapping-a-range-end=%" PRId64
", "
342 "mapping-b-range-start=%" PRId64
", "
343 "mapping-b-range-end=%" PRId64
,
344 g_quark_to_string(mapping
->string
),
345 mapping
->range_start
._signed
,
346 mapping
->range_end
._signed
,
347 overlap_query
->range_start
._signed
,
348 overlap_query
->range_end
._signed
);
353 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
355 struct enumeration_mapping
*mapping
= element
;
356 struct range_overlap_query
*overlap_query
= query
;
358 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
359 && overlap_query
->range_start
._unsigned
<=
360 mapping
->range_end
._unsigned
) {
361 overlap_query
->overlaps
= 1;
362 overlap_query
->mapping_name
= mapping
->string
;
365 overlap_query
->overlaps
|=
366 mapping
->string
== overlap_query
->mapping_name
;
368 if (overlap_query
->overlaps
) {
369 BT_LOGW("Overlapping enumeration field type mappings: "
370 "mapping-name=\"%s\", "
371 "mapping-a-range-start=%" PRIu64
", "
372 "mapping-a-range-end=%" PRIu64
", "
373 "mapping-b-range-start=%" PRIu64
", "
374 "mapping-b-range-end=%" PRIu64
,
375 g_quark_to_string(mapping
->string
),
376 mapping
->range_start
._unsigned
,
377 mapping
->range_end
._unsigned
,
378 overlap_query
->range_start
._unsigned
,
379 overlap_query
->range_end
._unsigned
);
384 gint
compare_enumeration_mappings_signed(struct enumeration_mapping
**a
,
385 struct enumeration_mapping
**b
)
387 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
391 gint
compare_enumeration_mappings_unsigned(struct enumeration_mapping
**a
,
392 struct enumeration_mapping
**b
)
394 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
398 void bt_ctf_field_type_init(struct bt_ctf_field_type
*type
, bt_bool init_bo
)
400 assert(type
&& (type
->id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
) &&
401 (type
->id
< BT_CTF_NR_TYPE_IDS
));
403 bt_object_init(type
, bt_ctf_field_type_destroy
);
404 type
->freeze
= type_freeze_funcs
[type
->id
];
405 type
->serialize
= type_serialize_funcs
[type
->id
];
409 const enum bt_ctf_byte_order bo
= BT_CTF_BYTE_ORDER_NATIVE
;
411 BT_LOGD("Setting initial field type's byte order: bo=%s",
412 bt_ctf_byte_order_string(bo
));
413 ret
= bt_ctf_field_type_set_byte_order(type
, bo
);
421 int add_structure_field(GPtrArray
*fields
,
422 GHashTable
*field_name_to_index
,
423 struct bt_ctf_field_type
*field_type
,
424 const char *field_name
)
427 GQuark name_quark
= g_quark_from_string(field_name
);
428 struct structure_field
*field
;
430 /* Make sure structure does not contain a field of the same name */
431 if (g_hash_table_lookup_extended(field_name_to_index
,
432 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
433 BT_LOGW("Structure or variant field type already contains a field type with this name: "
434 "field-name=\"%s\"", field_name
);
439 field
= g_new0(struct structure_field
, 1);
441 BT_LOGE_STR("Failed to allocate one structure/variant field type field.");
447 field
->name
= name_quark
;
448 field
->type
= field_type
;
449 g_hash_table_insert(field_name_to_index
,
450 GUINT_TO_POINTER(name_quark
),
451 GUINT_TO_POINTER(fields
->len
));
452 g_ptr_array_add(fields
, field
);
453 BT_LOGV("Added structure/variant field type field: field-ft-addr=%p, "
454 "field-name=\"%s\"", field_type
, field_name
);
460 void bt_ctf_field_type_destroy(struct bt_object
*obj
)
462 struct bt_ctf_field_type
*type
;
463 enum bt_ctf_field_type_id type_id
;
465 type
= container_of(obj
, struct bt_ctf_field_type
, base
);
467 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
468 type_id
< BT_CTF_NR_TYPE_IDS
);
469 type_destroy_funcs
[type_id
](type
);
473 int bt_ctf_field_type_integer_validate(struct bt_ctf_field_type
*type
)
477 struct bt_ctf_field_type_integer
*integer
=
478 container_of(type
, struct bt_ctf_field_type_integer
,
481 if (integer
->mapped_clock
&& integer
->is_signed
) {
482 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
483 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
484 type
, integer
->mapped_clock
,
485 bt_ctf_clock_class_get_name(integer
->mapped_clock
));
495 struct enumeration_mapping
*get_enumeration_mapping(
496 struct bt_ctf_field_type
*type
, uint64_t index
)
498 struct enumeration_mapping
*mapping
= NULL
;
499 struct bt_ctf_field_type_enumeration
*enumeration
;
501 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
503 if (index
>= enumeration
->entries
->len
) {
504 BT_LOGW("Invalid parameter: index is out of bounds: "
505 "addr=%p, index=%" PRIu64
", count=%u",
506 type
, index
, enumeration
->entries
->len
);
510 mapping
= g_ptr_array_index(enumeration
->entries
, index
);
516 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
517 * Only used when freezing an enumeration.
520 void set_enumeration_range_overlap(
521 struct bt_ctf_field_type
*type
)
524 struct bt_ctf_field_type
*container_type
;
525 struct bt_ctf_field_type_enumeration
*enumeration_type
;
528 BT_LOGV("Setting enumeration field type's overlap flag: addr=%p",
530 enumeration_type
= container_of(type
,
531 struct bt_ctf_field_type_enumeration
, parent
);
533 len
= enumeration_type
->entries
->len
;
534 container_type
= enumeration_type
->container
;
535 is_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
537 for (i
= 0; i
< len
; i
++) {
538 for (j
= i
+ 1; j
< len
; j
++) {
539 struct enumeration_mapping
*mapping
[2];
541 mapping
[0] = get_enumeration_mapping(type
, i
);
542 mapping
[1] = get_enumeration_mapping(type
, j
);
544 if (mapping
[0]->range_start
._signed
545 <= mapping
[1]->range_end
._signed
546 && mapping
[0]->range_end
._signed
547 >= mapping
[1]->range_start
._signed
) {
548 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
552 if (mapping
[0]->range_start
._unsigned
553 <= mapping
[1]->range_end
._unsigned
554 && mapping
[0]->range_end
._unsigned
555 >= mapping
[1]->range_start
._unsigned
) {
556 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
564 if (enumeration_type
->has_overlapping_ranges
) {
565 BT_LOGV_STR("Enumeration field type has overlapping ranges.");
567 BT_LOGV_STR("Enumeration field type has no overlapping ranges.");
572 int bt_ctf_field_type_enumeration_validate(struct bt_ctf_field_type
*type
)
576 struct bt_ctf_field_type_enumeration
*enumeration
=
577 container_of(type
, struct bt_ctf_field_type_enumeration
,
579 struct bt_ctf_field_type
*container_type
=
580 bt_ctf_field_type_enumeration_get_container_type(type
);
582 assert(container_type
);
583 ret
= bt_ctf_field_type_validate(container_type
);
585 BT_LOGW("Invalid enumeration field type: container type is invalid: "
586 "enum-ft-addr=%p, int-ft-addr=%p",
587 type
, container_type
);
591 /* Ensure enum has entries */
592 if (enumeration
->entries
->len
== 0) {
593 BT_LOGW("Invalid enumeration field type: no entries: "
600 BT_PUT(container_type
);
605 int bt_ctf_field_type_sequence_validate(struct bt_ctf_field_type
*type
)
608 struct bt_ctf_field_type
*element_type
= NULL
;
609 struct bt_ctf_field_type_sequence
*sequence
=
610 container_of(type
, struct bt_ctf_field_type_sequence
,
613 /* Length field name should be set at this point */
614 if (sequence
->length_field_name
->len
== 0) {
615 BT_LOGW("Invalid sequence field type: no length field name: "
621 element_type
= bt_ctf_field_type_sequence_get_element_type(type
);
622 assert(element_type
);
623 ret
= bt_ctf_field_type_validate(element_type
);
625 BT_LOGW("Invalid sequence field type: invalid element field type: "
626 "seq-ft-addr=%p, element-ft-add=%p",
631 BT_PUT(element_type
);
637 int bt_ctf_field_type_array_validate(struct bt_ctf_field_type
*type
)
640 struct bt_ctf_field_type
*element_type
= NULL
;
642 element_type
= bt_ctf_field_type_array_get_element_type(type
);
643 assert(element_type
);
644 ret
= bt_ctf_field_type_validate(element_type
);
646 BT_LOGW("Invalid array field type: invalid element field type: "
647 "array-ft-addr=%p, element-ft-add=%p",
651 BT_PUT(element_type
);
656 int bt_ctf_field_type_structure_validate(struct bt_ctf_field_type
*type
)
659 struct bt_ctf_field_type
*child_type
= NULL
;
660 int64_t field_count
= bt_ctf_field_type_structure_get_field_count(type
);
663 assert(field_count
>= 0);
665 for (i
= 0; i
< field_count
; ++i
) {
666 const char *field_name
;
668 ret
= bt_ctf_field_type_structure_get_field_by_index(type
,
669 &field_name
, &child_type
, i
);
671 ret
= bt_ctf_field_type_validate(child_type
);
673 BT_LOGW("Invalid structure field type: "
674 "a contained field type is invalid: "
675 "struct-ft-addr=%p, field-ft-addr=%p, "
676 "field-name=\"%s\", field-index=%" PRId64
,
677 type
, child_type
, field_name
, i
);
691 bt_bool
bt_ctf_field_type_enumeration_has_overlapping_ranges(
692 struct bt_ctf_field_type_enumeration
*enumeration_type
)
694 if (!enumeration_type
->parent
.frozen
) {
695 set_enumeration_range_overlap(&enumeration_type
->parent
);
697 return enumeration_type
->has_overlapping_ranges
;
701 int bt_ctf_field_type_enumeration_get_mapping_name(
702 struct bt_ctf_field_type
*enum_field_type
,
704 const char **mapping_name
)
707 struct enumeration_mapping
*mapping
;
709 assert(enum_field_type
);
710 mapping
= get_enumeration_mapping(enum_field_type
, index
);
713 *mapping_name
= g_quark_to_string(mapping
->string
);
720 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type
*type
)
724 struct bt_ctf_field_type
*child_type
= NULL
;
725 struct bt_ctf_field_type_variant
*variant
=
726 container_of(type
, struct bt_ctf_field_type_variant
,
729 int64_t tag_mappings_count
;
731 if (variant
->tag_name
->len
== 0) {
732 BT_LOGW("Invalid variant field type: no tag field name: "
739 BT_LOGW("Invalid variant field type: no tag field type: "
740 "addr=%p, tag-field-name=\"%s\"", type
,
741 variant
->tag_name
->str
);
746 if (bt_ctf_field_type_enumeration_has_overlapping_ranges(
748 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
749 "variant-ft-addr=%p, tag-field-name=\"%s\", "
750 "enum-ft-addr=%p", type
, variant
->tag_name
->str
,
757 bt_ctf_field_type_enumeration_get_mapping_count(
758 (struct bt_ctf_field_type
*) variant
->tag
);
759 assert(tag_mappings_count
>= 0);
762 * Validate that each mapping found in the tag has a name which
763 * is also the name of a field in this variant field type.
765 * The opposite is accepted: variant FT fields which cannot be
766 * selected because the variant FT tag has no mapping named as
767 * such. This scenario, while not ideal, cannot cause any error.
769 for (i
= 0; i
< tag_mappings_count
; ++i
) {
771 struct bt_ctf_field_type
*ft
;
773 ret
= bt_ctf_field_type_enumeration_get_mapping_name(
774 (struct bt_ctf_field_type
*) variant
->tag
,
778 ft
= bt_ctf_field_type_variant_get_field_type_by_name(
781 BT_LOGW("Invalid variant field type: "
782 "enumeration tag field type contains a mapping which does not name a variant field type field: "
783 "variant-ft-addr=%p, tag-field-name=\"%s\", "
784 "enum-ft-addr=%p, mapping-name=\"%s\"",
785 type
, variant
->tag_name
->str
, variant
->tag
,
794 field_count
= bt_ctf_field_type_variant_get_field_count(type
);
795 if (field_count
< 0) {
796 BT_LOGW("Invalid variant field type: no fields: "
797 "addr=%p, tag-field-name=\"%s\"",
798 type
, variant
->tag_name
->str
);
803 for (i
= 0; i
< field_count
; ++i
) {
804 const char *field_name
;
806 ret
= bt_ctf_field_type_variant_get_field_by_index(type
,
807 &field_name
, &child_type
, i
);
809 ret
= bt_ctf_field_type_validate(child_type
);
811 BT_LOGW("Invalid variant field type: "
812 "a contained field type is invalid: "
813 "variant-ft-addr=%p, tag-field-name=\"%s\", "
814 "field-ft-addr=%p, field-name=\"%s\", "
815 "field-index=%" PRId64
,
816 type
, variant
->tag_name
->str
, child_type
,
831 * This function validates a given field type without considering
832 * where this field type is located. It only validates the properties
833 * of the given field type and the properties of its children if
837 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
)
840 enum bt_ctf_field_type_id id
= bt_ctf_field_type_get_type_id(type
);
845 /* Already marked as valid */
849 if (type_validate_funcs
[id
]) {
850 ret
= type_validate_funcs
[id
](type
);
853 if (!ret
&& type
->frozen
) {
854 /* Field type is valid */
855 BT_LOGV("Marking field type as valid: addr=%p", type
);
863 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
865 struct bt_ctf_field_type_integer
*integer
=
866 g_new0(struct bt_ctf_field_type_integer
, 1);
868 BT_LOGD("Creating integer field type object: size=%u", size
);
871 BT_LOGE_STR("Failed to allocate one integer field type.");
875 if (size
== 0 || size
> 64) {
876 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
881 integer
->parent
.id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
882 integer
->size
= size
;
883 integer
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
884 integer
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
885 bt_ctf_field_type_init(&integer
->parent
, TRUE
);
886 BT_LOGD("Created integer field type object: addr=%p, size=%u",
887 &integer
->parent
, size
);
888 return &integer
->parent
;
891 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*type
)
894 struct bt_ctf_field_type_integer
*integer
;
897 BT_LOGW_STR("Invalid parameter: field type is NULL.");
902 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
903 BT_LOGW("Invalid parameter: field type is not an integer field type: "
904 "addr=%p, ft-id=%s", type
,
905 bt_ctf_field_type_id_string(type
->id
));
910 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
911 ret
= (int) integer
->size
;
916 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type
*type
)
919 struct bt_ctf_field_type_integer
*integer
;
922 BT_LOGW_STR("Invalid parameter: field type is NULL.");
927 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
928 BT_LOGW("Invalid parameter: field type is not an integer field type: "
929 "addr=%p, ft-id=%s", type
,
930 bt_ctf_field_type_id_string(type
->id
));
935 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
936 ret
= integer
->is_signed
;
941 bt_bool
bt_ctf_field_type_integer_is_signed(
942 struct bt_ctf_field_type
*int_field_type
)
944 return bt_ctf_field_type_integer_get_signed(int_field_type
) ?
948 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type
*type
,
952 struct bt_ctf_field_type_integer
*integer
;
955 BT_LOGW_STR("Invalid parameter: field type is NULL.");
961 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
967 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
968 BT_LOGW("Invalid parameter: field type is not an integer field type: "
969 "addr=%p, ft-id=%s", type
,
970 bt_ctf_field_type_id_string(type
->id
));
975 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
976 integer
->is_signed
= !!is_signed
;
977 BT_LOGV("Set integer field type's signedness: addr=%p, is-signed=%d",
983 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*type
,
987 struct bt_ctf_field_type_integer
*integer
;
990 BT_LOGW_STR("Invalid parameter: field type is NULL.");
996 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1002 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1003 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1004 "addr=%p, ft-id=%s", type
,
1005 bt_ctf_field_type_id_string(type
->id
));
1010 if (size
== 0 || size
> 64) {
1011 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
1012 "addr=%p, size=%u", type
, size
);
1017 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1018 integer
->size
= size
;
1019 BT_LOGV("Set integer field type's size: addr=%p, size=%u",
1025 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
1026 struct bt_ctf_field_type
*type
)
1028 enum bt_ctf_integer_base ret
= BT_CTF_INTEGER_BASE_UNKNOWN
;
1029 struct bt_ctf_field_type_integer
*integer
;
1032 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1036 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1037 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1038 "addr=%p, ft-id=%s", type
,
1039 bt_ctf_field_type_id_string(type
->id
));
1043 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1044 ret
= integer
->base
;
1049 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*type
,
1050 enum bt_ctf_integer_base base
)
1055 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1061 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1067 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1068 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1069 "addr=%p, ft-id=%s", type
,
1070 bt_ctf_field_type_id_string(type
->id
));
1076 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
1077 case BT_CTF_INTEGER_BASE_BINARY
:
1078 case BT_CTF_INTEGER_BASE_OCTAL
:
1079 case BT_CTF_INTEGER_BASE_DECIMAL
:
1080 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1082 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
1083 struct bt_ctf_field_type_integer
, parent
);
1084 integer
->base
= base
;
1088 BT_LOGW("Invalid parameter: unknown integer field type base: "
1089 "addr=%p, base=%d", type
, base
);
1093 BT_LOGV("Set integer field type's base: addr=%p, base=%s",
1094 type
, bt_ctf_integer_base_string(base
));
1100 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
1101 struct bt_ctf_field_type
*type
)
1103 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
1104 struct bt_ctf_field_type_integer
*integer
;
1107 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1111 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1112 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1113 "addr=%p, ft-id=%s", type
,
1114 bt_ctf_field_type_id_string(type
->id
));
1118 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1119 ret
= integer
->encoding
;
1124 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*type
,
1125 enum bt_ctf_string_encoding encoding
)
1128 struct bt_ctf_field_type_integer
*integer
;
1131 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1137 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1143 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1144 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1145 "addr=%p, ft-id=%s", type
,
1146 bt_ctf_field_type_id_string(type
->id
));
1151 if (encoding
< BT_CTF_STRING_ENCODING_NONE
||
1152 encoding
>= BT_CTF_STRING_ENCODING_UNKNOWN
) {
1153 BT_LOGW("Invalid parameter: unknown string encoding: "
1154 "addr=%p, encoding=%d", type
, encoding
);
1159 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1160 integer
->encoding
= encoding
;
1161 BT_LOGV("Set integer field type's encoding: addr=%p, encoding=%s",
1162 type
, bt_ctf_string_encoding_string(encoding
));
1167 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
1168 struct bt_ctf_field_type
*type
)
1170 struct bt_ctf_field_type_integer
*integer
;
1171 struct bt_ctf_clock_class
*clock_class
= NULL
;
1174 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1178 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1179 clock_class
= integer
->mapped_clock
;
1180 bt_get(clock_class
);
1186 int bt_ctf_field_type_integer_set_mapped_clock_class_no_check(
1187 struct bt_ctf_field_type
*type
,
1188 struct bt_ctf_clock_class
*clock_class
)
1190 struct bt_ctf_field_type_integer
*integer
;
1194 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1200 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1205 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1206 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1207 "addr=%p, ft-id=%s", type
,
1208 bt_ctf_field_type_id_string(type
->id
));
1212 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1213 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1214 "clock-class-addr=%p, clock-class-name=\"%s\"",
1216 bt_ctf_clock_class_get_name(clock_class
));
1221 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1222 bt_put(integer
->mapped_clock
);
1223 integer
->mapped_clock
= bt_get(clock_class
);
1224 BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
1225 "clock-class-addr=%p, clock-class-name=\"%s\"",
1226 type
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1231 int bt_ctf_field_type_integer_set_mapped_clock_class(
1232 struct bt_ctf_field_type
*type
,
1233 struct bt_ctf_clock_class
*clock_class
)
1238 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1244 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1250 ret
= bt_ctf_field_type_integer_set_mapped_clock_class_no_check(
1258 void bt_ctf_field_type_enum_iter_destroy(struct bt_object
*obj
)
1260 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
1262 struct bt_ctf_field_type_enumeration_mapping_iterator
,
1265 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
1267 BT_LOGD_STR("Putting parent enumeration field type.");
1268 bt_put(&iter
->enumeration_type
->parent
);
1273 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1274 bt_ctf_field_type_enumeration_find_mappings_type(
1275 struct bt_ctf_field_type
*type
,
1276 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
1278 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1279 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1282 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1286 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1287 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1288 "addr=%p, ft-id=%s", type
,
1289 bt_ctf_field_type_id_string(type
->id
));
1293 enumeration_type
= container_of(type
,
1294 struct bt_ctf_field_type_enumeration
, parent
);
1295 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
1297 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
1301 bt_object_init(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
1303 iter
->enumeration_type
= enumeration_type
;
1305 iter
->type
= iterator_type
;
1310 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1311 bt_ctf_field_type_enumeration_find_mappings_by_name(
1312 struct bt_ctf_field_type
*type
, const char *name
)
1314 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1316 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1317 type
, ITERATOR_BY_NAME
);
1319 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1320 "ft-addr=%p, mapping-name=\"%s\"", type
, name
);
1324 iter
->u
.name_quark
= g_quark_try_string(name
);
1325 if (!iter
->u
.name_quark
) {
1326 BT_LOGV("No such enumeration field type mapping name: "
1327 "ft-addr=%p, mapping-name=\"%s\"",
1332 /* Advance iterator to first entry, or leave index at -1. */
1333 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1334 /* No entry found. */
1335 BT_LOGV("No such enumeration field type mapping name: "
1336 "ft-addr=%p, mapping-name=\"%s\"",
1347 int bt_ctf_field_type_enumeration_mapping_iterator_next(
1348 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
1350 struct bt_ctf_field_type_enumeration
*enumeration
;
1351 struct bt_ctf_field_type
*type
;
1352 int i
, ret
= 0, len
;
1355 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1360 enumeration
= iter
->enumeration_type
;
1361 type
= &enumeration
->parent
;
1362 len
= enumeration
->entries
->len
;
1363 for (i
= iter
->index
+ 1; i
< len
; i
++) {
1364 struct enumeration_mapping
*mapping
=
1365 get_enumeration_mapping(type
, i
);
1367 switch (iter
->type
) {
1368 case ITERATOR_BY_NAME
:
1369 if (mapping
->string
== iter
->u
.name_quark
) {
1374 case ITERATOR_BY_SIGNED_VALUE
:
1376 int64_t value
= iter
->u
.signed_value
;
1378 if (value
>= mapping
->range_start
._signed
&&
1379 value
<= mapping
->range_end
._signed
) {
1385 case ITERATOR_BY_UNSIGNED_VALUE
:
1387 uint64_t value
= iter
->u
.unsigned_value
;
1389 if (value
>= mapping
->range_start
._unsigned
&&
1390 value
<= mapping
->range_end
._unsigned
) {
1397 BT_LOGF("Invalid enumeration field type mapping iterator type: "
1398 "type=%d", iter
->type
);
1408 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1409 bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1410 struct bt_ctf_field_type
*type
, int64_t value
)
1412 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1414 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1415 type
, ITERATOR_BY_SIGNED_VALUE
);
1417 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1418 "ft-addr=%p, value=%" PRId64
, type
, value
);
1422 if (bt_ctf_field_type_integer_get_signed(
1423 iter
->enumeration_type
->container
) != 1) {
1424 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
1425 "enum-ft-addr=%p, int-ft-addr=%p",
1426 type
, iter
->enumeration_type
->container
);
1430 iter
->u
.signed_value
= value
;
1432 /* Advance iterator to first entry, or leave index at -1. */
1433 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1434 /* No entry found. */
1444 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1445 bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1446 struct bt_ctf_field_type
*type
, uint64_t value
)
1448 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1451 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1455 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1456 type
, ITERATOR_BY_UNSIGNED_VALUE
);
1458 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1459 "ft-addr=%p, value=%" PRIu64
, type
, value
);
1463 if (bt_ctf_field_type_integer_get_signed(
1464 iter
->enumeration_type
->container
) != 0) {
1465 BT_LOGW("Invalid parameter: enumeration field type is signed: "
1466 "enum-ft-addr=%p, int-ft-addr=%p",
1467 type
, iter
->enumeration_type
->container
);
1470 iter
->u
.unsigned_value
= value
;
1472 /* Advance iterator to first entry, or leave index at -1. */
1473 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1474 /* No entry found. */
1484 int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
1485 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1486 const char **mapping_name
, int64_t *range_begin
,
1492 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1497 ret
= bt_ctf_field_type_enumeration_get_mapping_signed(
1498 &iter
->enumeration_type
->parent
, iter
->index
,
1499 mapping_name
, range_begin
, range_end
);
1504 int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
1505 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1506 const char **mapping_name
, uint64_t *range_begin
,
1507 uint64_t *range_end
)
1512 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1517 ret
= bt_ctf_field_type_enumeration_get_mapping_unsigned(
1518 &iter
->enumeration_type
->parent
, iter
->index
,
1519 mapping_name
, range_begin
, range_end
);
1524 int bt_ctf_field_type_enumeration_get_mapping_signed(
1525 struct bt_ctf_field_type
*enum_field_type
,
1526 uint64_t index
, const char **mapping_name
, int64_t *range_begin
,
1530 struct enumeration_mapping
*mapping
;
1532 if (!enum_field_type
) {
1533 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1538 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1540 /* get_enumeration_mapping() reports any error */
1546 *mapping_name
= g_quark_to_string(mapping
->string
);
1547 assert(*mapping_name
);
1551 *range_begin
= mapping
->range_start
._signed
;
1555 *range_end
= mapping
->range_end
._signed
;
1561 int bt_ctf_field_type_enumeration_get_mapping_unsigned(
1562 struct bt_ctf_field_type
*enum_field_type
,
1564 const char **mapping_name
, uint64_t *range_begin
,
1565 uint64_t *range_end
)
1568 struct enumeration_mapping
*mapping
;
1570 if (!enum_field_type
) {
1571 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1576 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1578 /* get_enumeration_mapping() reports any error */
1584 *mapping_name
= g_quark_to_string(mapping
->string
);
1585 assert(*mapping_name
);
1589 *range_begin
= mapping
->range_start
._unsigned
;
1593 *range_end
= mapping
->range_end
._unsigned
;
1599 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
1600 struct bt_ctf_field_type
*integer_container_type
)
1602 struct bt_ctf_field_type_enumeration
*enumeration
= NULL
;
1604 BT_LOGD("Creating enumeration field type object: int-ft-addr=%p",
1605 integer_container_type
);
1607 if (!integer_container_type
) {
1608 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1612 if (integer_container_type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1613 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
1614 "container-ft-addr=%p, container-ft-id=%s",
1615 integer_container_type
,
1616 bt_ctf_field_type_id_string(integer_container_type
->id
));
1620 enumeration
= g_new0(struct bt_ctf_field_type_enumeration
, 1);
1622 BT_LOGE_STR("Failed to allocate one enumeration field type.");
1626 enumeration
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
1627 bt_get(integer_container_type
);
1628 enumeration
->container
= integer_container_type
;
1629 enumeration
->entries
= g_ptr_array_new_with_free_func(
1630 (GDestroyNotify
)destroy_enumeration_mapping
);
1631 bt_ctf_field_type_init(&enumeration
->parent
, FALSE
);
1632 BT_LOGD("Created enumeration field type object: addr=%p, "
1633 "int-ft-addr=%p, int-ft-size=%u",
1634 &enumeration
->parent
, integer_container_type
,
1635 bt_ctf_field_type_integer_get_size(integer_container_type
));
1636 return &enumeration
->parent
;
1638 g_free(enumeration
);
1642 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_type(
1643 struct bt_ctf_field_type
*type
)
1645 struct bt_ctf_field_type
*container_type
= NULL
;
1646 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1649 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1653 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1654 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1655 "addr=%p, ft-id=%s", type
,
1656 bt_ctf_field_type_id_string(type
->id
));
1660 enumeration_type
= container_of(type
,
1661 struct bt_ctf_field_type_enumeration
, parent
);
1662 container_type
= enumeration_type
->container
;
1663 bt_get(container_type
);
1665 return container_type
;
1668 int bt_ctf_field_type_enumeration_add_mapping_signed(
1669 struct bt_ctf_field_type
*type
, const char *string
,
1670 int64_t range_start
, int64_t range_end
)
1673 GQuark mapping_name
;
1674 struct enumeration_mapping
*mapping
;
1675 struct bt_ctf_field_type_enumeration
*enumeration
;
1676 char *escaped_string
;
1679 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1685 BT_LOGW_STR("Invalid parameter: string is NULL.");
1691 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1697 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1698 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1699 "addr=%p, ft-id=%s", type
,
1700 bt_ctf_field_type_id_string(type
->id
));
1705 if (range_end
< range_start
) {
1706 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1707 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1708 type
, range_start
, range_end
);
1713 if (strlen(string
) == 0) {
1714 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1715 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1721 escaped_string
= g_strescape(string
, NULL
);
1722 if (!escaped_string
) {
1723 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1724 "mapping-name-addr=%p, mapping-name=\"%s\"",
1725 type
, string
, string
);
1730 mapping
= g_new(struct enumeration_mapping
, 1);
1732 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1736 mapping_name
= g_quark_from_string(escaped_string
);
1737 *mapping
= (struct enumeration_mapping
) {
1738 .range_start
._signed
= range_start
,
1739 .range_end
._signed
= range_end
,
1740 .string
= mapping_name
,
1742 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1744 g_ptr_array_add(enumeration
->entries
, mapping
);
1745 g_ptr_array_sort(enumeration
->entries
,
1746 (GCompareFunc
)compare_enumeration_mappings_signed
);
1747 BT_LOGV("Added mapping to signed enumeration field type: addr=%p, "
1748 "name=\"%s\", range-start=%" PRId64
", "
1749 "range-end=%" PRId64
,
1750 type
, string
, range_start
, range_end
);
1752 free(escaped_string
);
1757 int bt_ctf_field_type_enumeration_add_mapping_unsigned(
1758 struct bt_ctf_field_type
*type
, const char *string
,
1759 uint64_t range_start
, uint64_t range_end
)
1762 GQuark mapping_name
;
1763 struct enumeration_mapping
*mapping
;
1764 struct bt_ctf_field_type_enumeration
*enumeration
;
1765 char *escaped_string
;
1768 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1774 BT_LOGW_STR("Invalid parameter: string is NULL.");
1780 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1786 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1787 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1788 "addr=%p, ft-id=%s", type
,
1789 bt_ctf_field_type_id_string(type
->id
));
1794 if (range_end
< range_start
) {
1795 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1796 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1797 type
, range_start
, range_end
);
1802 if (strlen(string
) == 0) {
1803 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1804 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1810 escaped_string
= g_strescape(string
, NULL
);
1811 if (!escaped_string
) {
1812 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1813 "mapping-name-addr=%p, mapping-name=\"%s\"",
1814 type
, string
, string
);
1819 mapping
= g_new(struct enumeration_mapping
, 1);
1821 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1825 mapping_name
= g_quark_from_string(escaped_string
);
1826 *mapping
= (struct enumeration_mapping
) {
1827 .range_start
._unsigned
= range_start
,
1828 .range_end
._unsigned
= range_end
,
1829 .string
= mapping_name
,
1831 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1833 g_ptr_array_add(enumeration
->entries
, mapping
);
1834 g_ptr_array_sort(enumeration
->entries
,
1835 (GCompareFunc
)compare_enumeration_mappings_unsigned
);
1836 BT_LOGV("Added mapping to unsigned enumeration field type: addr=%p, "
1837 "name=\"%s\", range-start=%" PRIu64
", "
1838 "range-end=%" PRIu64
,
1839 type
, string
, range_start
, range_end
);
1841 free(escaped_string
);
1846 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
1847 struct bt_ctf_field_type
*type
)
1850 struct bt_ctf_field_type_enumeration
*enumeration
;
1853 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1858 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1859 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1860 "addr=%p, ft-id=%s", type
,
1861 bt_ctf_field_type_id_string(type
->id
));
1866 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1868 ret
= (int64_t) enumeration
->entries
->len
;
1873 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
1875 struct bt_ctf_field_type_floating_point
*floating_point
=
1876 g_new0(struct bt_ctf_field_type_floating_point
, 1);
1878 BT_LOGD_STR("Creating floating point number field type object.");
1880 if (!floating_point
) {
1881 BT_LOGE_STR("Failed to allocate one floating point number field type.");
1885 floating_point
->parent
.id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
1886 floating_point
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
1887 floating_point
->mant_dig
= FLT_MANT_DIG
;
1888 bt_ctf_field_type_init(&floating_point
->parent
, TRUE
);
1889 BT_LOGD("Created floating point number field type object: addr=%p, "
1890 "exp-size=%u, mant-size=%u", &floating_point
->parent
,
1891 floating_point
->exp_dig
, floating_point
->mant_dig
);
1893 return floating_point
? &floating_point
->parent
: NULL
;
1896 int bt_ctf_field_type_floating_point_get_exponent_digits(
1897 struct bt_ctf_field_type
*type
)
1900 struct bt_ctf_field_type_floating_point
*floating_point
;
1903 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1908 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1909 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1910 "addr=%p, ft-id=%s", type
,
1911 bt_ctf_field_type_id_string(type
->id
));
1916 floating_point
= container_of(type
,
1917 struct bt_ctf_field_type_floating_point
, parent
);
1918 ret
= (int) floating_point
->exp_dig
;
1923 int bt_ctf_field_type_floating_point_set_exponent_digits(
1924 struct bt_ctf_field_type
*type
,
1925 unsigned int exponent_digits
)
1928 struct bt_ctf_field_type_floating_point
*floating_point
;
1931 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1937 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1943 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1944 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1945 "addr=%p, ft-id=%s", type
,
1946 bt_ctf_field_type_id_string(type
->id
));
1951 floating_point
= container_of(type
,
1952 struct bt_ctf_field_type_floating_point
, parent
);
1953 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1954 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1956 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1957 BT_LOGW("Invalid parameter: invalid exponent size: "
1958 "addr=%p, exp-size=%u", type
, exponent_digits
);
1963 floating_point
->exp_dig
= exponent_digits
;
1964 BT_LOGV("Set floating point number field type's exponent size: addr=%p, "
1965 "exp-size=%u", type
, exponent_digits
);
1970 int bt_ctf_field_type_floating_point_get_mantissa_digits(
1971 struct bt_ctf_field_type
*type
)
1974 struct bt_ctf_field_type_floating_point
*floating_point
;
1977 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1982 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1983 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1984 "addr=%p, ft-id=%s", type
,
1985 bt_ctf_field_type_id_string(type
->id
));
1990 floating_point
= container_of(type
,
1991 struct bt_ctf_field_type_floating_point
, parent
);
1992 ret
= (int) floating_point
->mant_dig
;
1997 int bt_ctf_field_type_floating_point_set_mantissa_digits(
1998 struct bt_ctf_field_type
*type
,
1999 unsigned int mantissa_digits
)
2002 struct bt_ctf_field_type_floating_point
*floating_point
;
2005 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2011 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2017 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
2018 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
2019 "addr=%p, ft-id=%s", type
,
2020 bt_ctf_field_type_id_string(type
->id
));
2025 floating_point
= container_of(type
,
2026 struct bt_ctf_field_type_floating_point
, parent
);
2028 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
2029 (mantissa_digits
!= DBL_MANT_DIG
) &&
2030 (mantissa_digits
!= LDBL_MANT_DIG
)) {
2031 BT_LOGW("Invalid parameter: invalid mantissa size: "
2032 "addr=%p, mant-size=%u", type
, mantissa_digits
);
2037 floating_point
->mant_dig
= mantissa_digits
;
2038 BT_LOGV("Set floating point number field type's mantissa size: addr=%p, "
2039 "mant-size=%u", type
, mantissa_digits
);
2044 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
2046 struct bt_ctf_field_type_structure
*structure
=
2047 g_new0(struct bt_ctf_field_type_structure
, 1);
2049 BT_LOGD_STR("Creating structure field type object.");
2052 BT_LOGE_STR("Failed to allocate one structure field type.");
2056 structure
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
2057 structure
->fields
= g_ptr_array_new_with_free_func(
2058 (GDestroyNotify
)destroy_structure_field
);
2059 structure
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2060 bt_ctf_field_type_init(&structure
->parent
, TRUE
);
2061 BT_LOGD("Created structure field type object: addr=%p",
2062 &structure
->parent
);
2063 return &structure
->parent
;
2068 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*type
,
2069 struct bt_ctf_field_type
*field_type
,
2070 const char *field_name
)
2073 struct bt_ctf_field_type_structure
*structure
;
2076 * TODO: check that `field_type` does not contain `type`,
2080 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2086 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2092 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2098 if (bt_ctf_validate_identifier(field_name
)) {
2099 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2100 "struct-ft-addr=%p, field-name=\"%s\"",
2106 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2107 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2108 "addr=%p, ft-id=%s", type
,
2109 bt_ctf_field_type_id_string(type
->id
));
2114 if (type
== field_type
) {
2115 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
2121 structure
= container_of(type
,
2122 struct bt_ctf_field_type_structure
, parent
);
2123 if (add_structure_field(structure
->fields
,
2124 structure
->field_name_to_index
, field_type
, field_name
)) {
2125 BT_LOGW("Cannot add field to structure field type: "
2126 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2127 type
, field_type
, field_name
);
2132 BT_LOGV("Added structure field type field: struct-ft-addr=%p, "
2133 "field-ft-addr=%p, field-name=\"%s\"", type
,
2134 field_type
, field_name
);
2139 int64_t bt_ctf_field_type_structure_get_field_count(
2140 struct bt_ctf_field_type
*type
)
2143 struct bt_ctf_field_type_structure
*structure
;
2146 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2151 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2152 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2153 "addr=%p, ft-id=%s", type
,
2154 bt_ctf_field_type_id_string(type
->id
));
2159 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2161 ret
= (int64_t) structure
->fields
->len
;
2166 int bt_ctf_field_type_structure_get_field_by_index(
2167 struct bt_ctf_field_type
*type
,
2168 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2171 struct bt_ctf_field_type_structure
*structure
;
2172 struct structure_field
*field
;
2176 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2181 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2182 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2183 "addr=%p, ft-id=%s", type
,
2184 bt_ctf_field_type_id_string(type
->id
));
2189 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2191 if (index
>= structure
->fields
->len
) {
2192 BT_LOGW("Invalid parameter: index is out of bounds: "
2193 "addr=%p, index=%" PRIu64
", count=%u",
2194 type
, index
, structure
->fields
->len
);
2199 field
= g_ptr_array_index(structure
->fields
, index
);
2201 *field_type
= field
->type
;
2202 bt_get(field
->type
);
2205 *field_name
= g_quark_to_string(field
->name
);
2206 assert(*field_name
);
2212 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
2213 struct bt_ctf_field_type
*type
,
2218 struct structure_field
*field
;
2219 struct bt_ctf_field_type_structure
*structure
;
2220 struct bt_ctf_field_type
*field_type
= NULL
;
2223 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2228 BT_LOGW_STR("Invalid parameter: name is NULL.");
2232 name_quark
= g_quark_try_string(name
);
2234 BT_LOGV("No such structure field type field name: "
2235 "ft-addr=%p, field-name=\"%s\"",
2240 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2242 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
2243 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2244 BT_LOGV("No such structure field type field name: "
2245 "ft-addr=%p, field-name=\"%s\"",
2250 field
= structure
->fields
->pdata
[index
];
2251 field_type
= field
->type
;
2257 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
2258 struct bt_ctf_field_type
*enum_tag
, const char *tag_name
)
2260 struct bt_ctf_field_type_variant
*variant
= NULL
;
2262 BT_LOGD("Creating variant field type object: "
2263 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2264 enum_tag
, tag_name
);
2266 if (tag_name
&& bt_ctf_validate_identifier(tag_name
)) {
2267 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2268 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2269 enum_tag
, tag_name
);
2273 variant
= g_new0(struct bt_ctf_field_type_variant
, 1);
2275 BT_LOGE_STR("Failed to allocate one variant field type.");
2279 variant
->parent
.id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
2280 variant
->tag_name
= g_string_new(tag_name
);
2281 variant
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2282 variant
->fields
= g_ptr_array_new_with_free_func(
2283 (GDestroyNotify
) destroy_structure_field
);
2286 variant
->tag
= container_of(enum_tag
,
2287 struct bt_ctf_field_type_enumeration
, parent
);
2290 bt_ctf_field_type_init(&variant
->parent
, TRUE
);
2291 /* A variant's alignment is undefined */
2292 variant
->parent
.alignment
= 0;
2293 BT_LOGD("Created variant field type object: addr=%p, "
2294 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2295 &variant
->parent
, enum_tag
, tag_name
);
2296 return &variant
->parent
;
2301 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_type(
2302 struct bt_ctf_field_type
*type
)
2304 struct bt_ctf_field_type_variant
*variant
;
2305 struct bt_ctf_field_type
*tag_type
= NULL
;
2308 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2312 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2313 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2314 "addr=%p, ft-id=%s", type
,
2315 bt_ctf_field_type_id_string(type
->id
));
2319 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2320 if (!variant
->tag
) {
2321 BT_LOGV("Variant field type has no tag field type: "
2326 tag_type
= &variant
->tag
->parent
;
2332 const char *bt_ctf_field_type_variant_get_tag_name(
2333 struct bt_ctf_field_type
*type
)
2335 struct bt_ctf_field_type_variant
*variant
;
2336 const char *tag_name
= NULL
;
2339 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2343 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2344 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2345 "addr=%p, ft-id=%s", type
,
2346 bt_ctf_field_type_id_string(type
->id
));
2350 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2351 if (variant
->tag_name
->len
== 0) {
2352 BT_LOGV("Variant field type has no tag field name: "
2357 tag_name
= variant
->tag_name
->str
;
2362 int bt_ctf_field_type_variant_set_tag_name(
2363 struct bt_ctf_field_type
*type
, const char *name
)
2366 struct bt_ctf_field_type_variant
*variant
;
2369 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2375 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2381 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2382 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2383 "addr=%p, ft-id=%s", type
,
2384 bt_ctf_field_type_id_string(type
->id
));
2389 if (bt_ctf_validate_identifier(name
)) {
2390 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2391 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2397 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2398 g_string_assign(variant
->tag_name
, name
);
2399 BT_LOGV("Set variant field type's tag field name: addr=%p, "
2400 "tag-field-name=\"%s\"", type
, name
);
2405 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*type
,
2406 struct bt_ctf_field_type
*field_type
,
2407 const char *field_name
)
2411 struct bt_ctf_field_type_variant
*variant
;
2412 GQuark field_name_quark
= g_quark_from_string(field_name
);
2415 * TODO: check that `field_type` does not contain `type`,
2419 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2425 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2431 if (bt_ctf_validate_identifier(field_name
)) {
2432 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2433 "variant-ft-addr=%p, field-name=\"%s\"",
2439 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2440 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2441 "addr=%p, ft-id=%s", type
,
2442 bt_ctf_field_type_id_string(type
->id
));
2447 if (type
== field_type
) {
2448 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2454 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2456 /* The user has explicitly provided a tag; validate against it. */
2460 /* Make sure this name is present in the enum tag */
2461 for (i
= 0; i
< variant
->tag
->entries
->len
; i
++) {
2462 struct enumeration_mapping
*mapping
=
2463 g_ptr_array_index(variant
->tag
->entries
, i
);
2465 if (mapping
->string
== field_name_quark
) {
2472 /* Validation failed */
2473 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2474 "variant-ft-addr=%p, tag-ft-addr=%p, "
2475 "tag-field-name=\"%s\""
2476 "field-ft-addr=%p, field-name=\"%s\"",
2477 type
, variant
->tag
, variant
->tag_name
->str
,
2478 field_type
, field_name
);
2484 if (add_structure_field(variant
->fields
, variant
->field_name_to_index
,
2485 field_type
, field_name
)) {
2486 BT_LOGW("Cannot add field to variant field type: "
2487 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2488 type
, field_type
, field_name
);
2493 BT_LOGV("Added variant field type field: variant-ft-addr=%p, "
2494 "field-ft-addr=%p, field-name=\"%s\"", type
,
2495 field_type
, field_name
);
2501 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
2502 struct bt_ctf_field_type
*type
,
2503 const char *field_name
)
2507 struct structure_field
*field
;
2508 struct bt_ctf_field_type_variant
*variant
;
2509 struct bt_ctf_field_type
*field_type
= NULL
;
2512 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2517 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2521 name_quark
= g_quark_try_string(field_name
);
2523 BT_LOGV("No such variant field type field name: "
2524 "ft-addr=%p, field-name=\"%s\"",
2529 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2530 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
2531 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2532 BT_LOGV("No such variant field type field name: "
2533 "ft-addr=%p, field-name=\"%s\"",
2538 field
= g_ptr_array_index(variant
->fields
, index
);
2539 field_type
= field
->type
;
2545 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
2546 struct bt_ctf_field_type
*type
,
2547 struct bt_ctf_field
*tag
)
2550 const char *enum_value
;
2551 struct bt_ctf_field_type
*field_type
= NULL
;
2552 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
2555 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2560 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
2564 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2565 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2566 "addr=%p, ft-id=%s", type
,
2567 bt_ctf_field_type_id_string(type
->id
));
2571 iter
= bt_ctf_field_enumeration_get_mappings(tag
);
2573 BT_LOGE("Cannot get enumeration field type mapping iterator from enumeration field: "
2574 "enum-field-addr=%p", tag
);
2578 ret
= bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter
,
2579 &enum_value
, NULL
, NULL
);
2581 BT_LOGW("Cannot get enumeration field type mapping iterator's current mapping: "
2582 "iter-addr=%p", iter
);
2586 field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
2593 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*type
)
2596 struct bt_ctf_field_type_variant
*variant
;
2599 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2604 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2605 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2606 "addr=%p, ft-id=%s", type
,
2607 bt_ctf_field_type_id_string(type
->id
));
2612 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2614 ret
= (int64_t) variant
->fields
->len
;
2620 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*type
,
2621 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2624 struct bt_ctf_field_type_variant
*variant
;
2625 struct structure_field
*field
;
2629 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2634 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2635 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2636 "addr=%p, ft-id=%s", type
,
2637 bt_ctf_field_type_id_string(type
->id
));
2642 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2644 if (index
>= variant
->fields
->len
) {
2645 BT_LOGW("Invalid parameter: index is out of bounds: "
2646 "addr=%p, index=%" PRIu64
", count=%u",
2647 type
, index
, variant
->fields
->len
);
2652 field
= g_ptr_array_index(variant
->fields
, index
);
2654 *field_type
= field
->type
;
2655 bt_get(field
->type
);
2658 *field_name
= g_quark_to_string(field
->name
);
2659 assert(*field_name
);
2665 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
2666 struct bt_ctf_field_type
*element_type
,
2667 unsigned int length
)
2669 struct bt_ctf_field_type_array
*array
= NULL
;
2671 BT_LOGD("Creating array field type object: element-ft-addr=%p, "
2672 "length=%u", element_type
, length
);
2674 if (!element_type
) {
2675 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2680 BT_LOGW_STR("Invalid parameter: length is zero.");
2684 array
= g_new0(struct bt_ctf_field_type_array
, 1);
2686 BT_LOGE_STR("Failed to allocate one array field type.");
2690 array
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
2691 bt_get(element_type
);
2692 array
->element_type
= element_type
;
2693 array
->length
= length
;
2694 bt_ctf_field_type_init(&array
->parent
, FALSE
);
2695 BT_LOGD("Created array field type object: addr=%p, "
2696 "element-ft-addr=%p, length=%u",
2697 &array
->parent
, element_type
, length
);
2698 return &array
->parent
;
2703 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_type(
2704 struct bt_ctf_field_type
*type
)
2706 struct bt_ctf_field_type
*ret
= NULL
;
2707 struct bt_ctf_field_type_array
*array
;
2710 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2714 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2715 BT_LOGW("Invalid parameter: field type is not an array field type: "
2716 "addr=%p, ft-id=%s", type
,
2717 bt_ctf_field_type_id_string(type
->id
));
2721 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2722 ret
= array
->element_type
;
2729 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*type
,
2730 struct bt_ctf_field_type
*element_type
)
2733 struct bt_ctf_field_type_array
*array
;
2736 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2741 if (!element_type
) {
2742 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2747 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2748 BT_LOGW("Invalid parameter: field type is not an array field type: "
2749 "addr=%p, ft-id=%s", type
,
2750 bt_ctf_field_type_id_string(type
->id
));
2755 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2757 if (array
->element_type
) {
2758 BT_PUT(array
->element_type
);
2761 array
->element_type
= element_type
;
2762 bt_get(array
->element_type
);
2763 BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
2764 "element-ft-addr=%p", type
, element_type
);
2770 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*type
)
2773 struct bt_ctf_field_type_array
*array
;
2776 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2781 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2782 BT_LOGW("Invalid parameter: field type is not an array field type: "
2783 "addr=%p, ft-id=%s", type
,
2784 bt_ctf_field_type_id_string(type
->id
));
2789 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2790 ret
= (int64_t) array
->length
;
2795 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
2796 struct bt_ctf_field_type
*element_type
,
2797 const char *length_field_name
)
2799 struct bt_ctf_field_type_sequence
*sequence
= NULL
;
2801 BT_LOGD("Creating sequence field type object: element-ft-addr=%p, "
2802 "length-field-name=\"%s\"", element_type
, length_field_name
);
2804 if (!element_type
) {
2805 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2809 if (bt_ctf_validate_identifier(length_field_name
)) {
2810 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
2811 "length-field-name=\"%s\"", length_field_name
);
2815 sequence
= g_new0(struct bt_ctf_field_type_sequence
, 1);
2817 BT_LOGE_STR("Failed to allocate one sequence field type.");
2821 sequence
->parent
.id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
2822 bt_get(element_type
);
2823 sequence
->element_type
= element_type
;
2824 sequence
->length_field_name
= g_string_new(length_field_name
);
2825 bt_ctf_field_type_init(&sequence
->parent
, FALSE
);
2826 BT_LOGD("Created sequence field type object: addr=%p, "
2827 "element-ft-addr=%p, length-field-name=\"%s\"",
2828 &sequence
->parent
, element_type
, length_field_name
);
2829 return &sequence
->parent
;
2834 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_type(
2835 struct bt_ctf_field_type
*type
)
2837 struct bt_ctf_field_type
*ret
= NULL
;
2838 struct bt_ctf_field_type_sequence
*sequence
;
2841 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2845 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2846 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2847 "addr=%p, ft-id=%s", type
,
2848 bt_ctf_field_type_id_string(type
->id
));
2852 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2854 ret
= sequence
->element_type
;
2861 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*type
,
2862 struct bt_ctf_field_type
*element_type
)
2865 struct bt_ctf_field_type_sequence
*sequence
;
2868 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2873 if (!element_type
) {
2874 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2879 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2880 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2881 "addr=%p, ft-id=%s", type
,
2882 bt_ctf_field_type_id_string(type
->id
));
2887 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
, parent
);
2888 if (sequence
->element_type
) {
2889 BT_PUT(sequence
->element_type
);
2892 sequence
->element_type
= element_type
;
2893 bt_get(sequence
->element_type
);
2894 BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
2895 "element-ft-addr=%p", type
, element_type
);
2901 const char *bt_ctf_field_type_sequence_get_length_field_name(
2902 struct bt_ctf_field_type
*type
)
2904 const char *ret
= NULL
;
2905 struct bt_ctf_field_type_sequence
*sequence
;
2908 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2912 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2913 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2914 "addr=%p, ft-id=%s", type
,
2915 bt_ctf_field_type_id_string(type
->id
));
2919 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2921 ret
= sequence
->length_field_name
->str
;
2926 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
2928 struct bt_ctf_field_type_string
*string
=
2929 g_new0(struct bt_ctf_field_type_string
, 1);
2931 BT_LOGD_STR("Creating string field type object.");
2934 BT_LOGE_STR("Failed to allocate one string field type.");
2938 string
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRING
;
2939 bt_ctf_field_type_init(&string
->parent
, TRUE
);
2940 string
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2941 string
->parent
.alignment
= CHAR_BIT
;
2942 BT_LOGD("Created string field type object: addr=%p", &string
->parent
);
2943 return &string
->parent
;
2946 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
2947 struct bt_ctf_field_type
*type
)
2949 struct bt_ctf_field_type_string
*string
;
2950 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
2953 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2957 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2958 BT_LOGW("Invalid parameter: field type is not a string field type: "
2959 "addr=%p, ft-id=%s", type
,
2960 bt_ctf_field_type_id_string(type
->id
));
2964 string
= container_of(type
, struct bt_ctf_field_type_string
,
2966 ret
= string
->encoding
;
2971 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*type
,
2972 enum bt_ctf_string_encoding encoding
)
2975 struct bt_ctf_field_type_string
*string
;
2978 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2983 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2984 BT_LOGW("Invalid parameter: field type is not a string field type: "
2985 "addr=%p, ft-id=%s", type
,
2986 bt_ctf_field_type_id_string(type
->id
));
2991 if ((encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2992 encoding
!= BT_CTF_STRING_ENCODING_ASCII
)) {
2993 BT_LOGW("Invalid parameter: unknown string encoding: "
2994 "addr=%p, encoding=%d", type
, encoding
);
2999 string
= container_of(type
, struct bt_ctf_field_type_string
, parent
);
3000 string
->encoding
= encoding
;
3001 BT_LOGV("Set string field type's encoding: addr=%p, encoding=%s",
3002 type
, bt_ctf_string_encoding_string(encoding
));
3007 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*type
)
3010 enum bt_ctf_field_type_id type_id
;
3013 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3019 ret
= (int) type
->alignment
;
3023 type_id
= bt_ctf_field_type_get_type_id(type
);
3025 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
3027 struct bt_ctf_field_type
*element
=
3028 bt_ctf_field_type_sequence_get_element_type(type
);
3031 ret
= bt_ctf_field_type_get_alignment(element
);
3035 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
3037 struct bt_ctf_field_type
*element
=
3038 bt_ctf_field_type_array_get_element_type(type
);
3041 ret
= bt_ctf_field_type_get_alignment(element
);
3045 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
3047 int64_t i
, element_count
;
3049 element_count
= bt_ctf_field_type_structure_get_field_count(
3051 assert(element_count
>= 0);
3053 for (i
= 0; i
< element_count
; i
++) {
3054 struct bt_ctf_field_type
*field
;
3055 int field_alignment
;
3057 ret
= bt_ctf_field_type_structure_get_field_by_index(
3058 type
, NULL
, &field
, i
);
3061 field_alignment
= bt_ctf_field_type_get_alignment(
3064 if (field_alignment
< 0) {
3065 ret
= field_alignment
;
3069 type
->alignment
= MAX(field_alignment
, type
->alignment
);
3071 ret
= (int) type
->alignment
;
3074 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
3075 BT_LOGW("Invalid parameter: unknown field type ID: "
3076 "addr=%p, ft-id=%d", type
, type_id
);
3080 ret
= (int) type
->alignment
;
3088 int is_power_of_two(unsigned int value
)
3090 return ((value
& (value
- 1)) == 0) && value
> 0;
3093 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
3094 unsigned int alignment
)
3097 enum bt_ctf_field_type_id type_id
;
3099 /* Alignment must be a power of two */
3101 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3107 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3113 if (!is_power_of_two(alignment
)) {
3114 BT_LOGW("Invalid parameter: alignment is not a power of two: "
3115 "addr=%p, align=%u", type
, alignment
);
3120 type_id
= bt_ctf_field_type_get_type_id(type
);
3121 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3122 BT_LOGW("Invalid parameter: unknown field type ID: "
3123 "addr=%p, ft-id=%d", type
, type_id
);
3128 if (type
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&&
3129 alignment
!= CHAR_BIT
) {
3130 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
3131 "addr=%p, align=%u", CHAR_BIT
, type
, alignment
);
3136 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
3137 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
3138 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
3139 /* Setting an alignment on these types makes no sense */
3140 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
3141 "addr=%p, ft-id=%s", type
,
3142 bt_ctf_field_type_id_string(type
->id
));
3147 type
->alignment
= alignment
;
3149 BT_LOGV("Set field type's alignment: addr=%p, align=%u",
3155 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
3156 struct bt_ctf_field_type
*type
)
3158 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
3161 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3166 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3168 struct bt_ctf_field_type_integer
*integer
= container_of(
3169 type
, struct bt_ctf_field_type_integer
, parent
);
3170 ret
= integer
->user_byte_order
;
3173 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3175 struct bt_ctf_field_type_enumeration
*enum_ft
= container_of(
3176 type
, struct bt_ctf_field_type_enumeration
, parent
);
3177 ret
= bt_ctf_field_type_get_byte_order(enum_ft
->container
);
3180 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
3182 struct bt_ctf_field_type_floating_point
*floating_point
=
3184 struct bt_ctf_field_type_floating_point
,
3186 ret
= floating_point
->user_byte_order
;
3190 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
3191 "addr=%p, ft-id=%s", type
,
3192 bt_ctf_field_type_id_string(type
->id
));
3196 assert(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
3197 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
3198 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
3199 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
3205 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
3206 enum bt_ctf_byte_order byte_order
)
3211 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3217 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3223 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
3224 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
3225 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
3226 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
3227 BT_LOGW("Invalid parameter: invalid byte order: "
3228 "addr=%p, bo=%s", type
,
3229 bt_ctf_byte_order_string(byte_order
));
3234 if (set_byte_order_funcs
[type
->id
]) {
3235 set_byte_order_funcs
[type
->id
](type
, byte_order
);
3238 BT_LOGV("Set field type's byte order: addr=%p, bo=%s",
3239 type
, bt_ctf_byte_order_string(byte_order
));
3245 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
3246 struct bt_ctf_field_type
*type
)
3249 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3250 return BT_CTF_FIELD_TYPE_ID_UNKNOWN
;
3256 int bt_ctf_field_type_is_integer(struct bt_ctf_field_type
*type
)
3258 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
;
3261 int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type
*type
)
3263 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_FLOAT
;
3266 int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type
*type
)
3268 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ENUM
;
3271 int bt_ctf_field_type_is_string(struct bt_ctf_field_type
*type
)
3273 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRING
;
3276 int bt_ctf_field_type_is_structure(struct bt_ctf_field_type
*type
)
3278 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
;
3281 int bt_ctf_field_type_is_array(struct bt_ctf_field_type
*type
)
3283 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ARRAY
;
3286 int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type
*type
)
3288 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
3291 int bt_ctf_field_type_is_variant(struct bt_ctf_field_type
*type
)
3293 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_VARIANT
;
3296 /* Pre-2.0 CTF writer backward compatibility */
3297 void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
)
3302 /* Pre-2.0 CTF writer backward compatibility */
3303 void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
)
3309 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
)
3311 if (!type
|| type
->frozen
) {
3319 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
3320 struct bt_ctf_field_type_variant
*variant
,
3323 struct bt_ctf_field_type
*type
= NULL
;
3324 GQuark field_name_quark
;
3326 struct structure_field
*field_entry
;
3327 struct range_overlap_query query
= {
3328 .range_start
._signed
= tag_value
,
3329 .range_end
._signed
= tag_value
,
3334 g_ptr_array_foreach(variant
->tag
->entries
, check_ranges_overlap
,
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 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
3354 struct bt_ctf_field_type_variant
*variant
,
3357 struct bt_ctf_field_type
*type
= NULL
;
3358 GQuark field_name_quark
;
3360 struct structure_field
*field_entry
;
3361 struct range_overlap_query query
= {
3362 .range_start
._unsigned
= tag_value
,
3363 .range_end
._unsigned
= tag_value
,
3368 g_ptr_array_foreach(variant
->tag
->entries
,
3369 check_ranges_overlap_unsigned
,
3371 if (!query
.overlaps
) {
3375 field_name_quark
= query
.mapping_name
;
3376 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3377 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3381 field_entry
= g_ptr_array_index(variant
->fields
, (size_t)index
);
3382 type
= field_entry
->type
;
3388 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
3389 struct metadata_context
*context
)
3396 /* Make sure field type is valid before serializing it */
3397 ret
= bt_ctf_field_type_validate(type
);
3399 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
3404 ret
= type
->serialize(type
, context
);
3409 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*type
)
3411 struct bt_ctf_field_type
*copy
= NULL
;
3414 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3418 copy
= type_copy_funcs
[type
->id
](type
);
3420 BT_LOGE_STR("Cannot copy field type.");
3424 copy
->alignment
= type
->alignment
;
3430 int bt_ctf_field_type_structure_get_field_name_index(
3431 struct bt_ctf_field_type
*type
, const char *name
)
3436 struct bt_ctf_field_type_structure
*structure
;
3439 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3445 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3450 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
3451 BT_LOGW("Invalid parameter: field type is not a structure field type: "
3452 "addr=%p, ft-id=%s", type
,
3453 bt_ctf_field_type_id_string(type
->id
));
3458 name_quark
= g_quark_try_string(name
);
3460 BT_LOGV("No such structure field type field name: "
3461 "ft-addr=%p, field-name=\"%s\"",
3467 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
3469 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
3470 GUINT_TO_POINTER(name_quark
),
3471 NULL
, (gpointer
*)&index
)) {
3472 BT_LOGV("No such structure field type field name: "
3473 "ft-addr=%p, field-name=\"%s\"",
3484 int bt_ctf_field_type_variant_get_field_name_index(
3485 struct bt_ctf_field_type
*type
, const char *name
)
3490 struct bt_ctf_field_type_variant
*variant
;
3493 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3499 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3504 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3505 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3506 "addr=%p, ft-id=%s", type
,
3507 bt_ctf_field_type_id_string(type
->id
));
3512 name_quark
= g_quark_try_string(name
);
3514 BT_LOGV("No such variant field type field name: "
3515 "ft-addr=%p, field-name=\"%s\"",
3521 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3523 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3524 GUINT_TO_POINTER(name_quark
),
3525 NULL
, (gpointer
*)&index
)) {
3526 BT_LOGV("No such variant field type field name: "
3527 "ft-addr=%p, field-name=\"%s\"",
3538 int bt_ctf_field_type_sequence_set_length_field_path(
3539 struct bt_ctf_field_type
*type
,
3540 struct bt_ctf_field_path
*path
)
3543 struct bt_ctf_field_type_sequence
*sequence
;
3546 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3551 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
3552 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
3553 "addr=%p, ft-id=%s", type
,
3554 bt_ctf_field_type_id_string(type
->id
));
3559 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
3562 BT_MOVE(sequence
->length_field_path
, path
);
3563 BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
3564 "field-path-addr=%p", type
, path
);
3570 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
3571 struct bt_ctf_field_path
*path
)
3574 struct bt_ctf_field_type_variant
*variant
;
3577 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3582 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3583 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3584 "addr=%p, ft-id=%s", type
,
3585 bt_ctf_field_type_id_string(type
->id
));
3590 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3593 BT_MOVE(variant
->tag_field_path
, path
);
3594 BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
3595 "field-path-addr=%p", type
, path
);
3601 int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type
*type
,
3602 struct bt_ctf_field_type
*tag
)
3605 struct bt_ctf_field_type_variant
*variant
;
3608 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3614 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
3619 if (bt_ctf_field_type_get_type_id(tag
) != BT_CTF_FIELD_TYPE_ID_ENUM
) {
3620 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
3621 "addr=%p, ft-id=%s", type
,
3622 bt_ctf_field_type_id_string(type
->id
));
3627 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3631 bt_put(&variant
->tag
->parent
);
3633 variant
->tag
= container_of(tag
, struct bt_ctf_field_type_enumeration
,
3635 BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
3636 "tag-ft-addr=%p", type
, tag
);
3642 void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type
*type
)
3644 struct bt_ctf_field_type_integer
*integer
=
3645 (struct bt_ctf_field_type_integer
*) type
;
3651 BT_LOGD("Destroying integer field type object: addr=%p", type
);
3652 BT_LOGD_STR("Putting mapped clock class.");
3653 bt_put(integer
->mapped_clock
);
3658 void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type
*type
)
3660 struct bt_ctf_field_type_enumeration
*enumeration
=
3661 (struct bt_ctf_field_type_enumeration
*) type
;
3667 BT_LOGD("Destroying enumeration field type object: addr=%p", type
);
3668 g_ptr_array_free(enumeration
->entries
, TRUE
);
3669 BT_LOGD_STR("Putting container field type.");
3670 bt_put(enumeration
->container
);
3671 g_free(enumeration
);
3675 void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type
*type
)
3677 struct bt_ctf_field_type_floating_point
*floating_point
=
3678 (struct bt_ctf_field_type_floating_point
*) type
;
3684 BT_LOGD("Destroying floating point number field type object: addr=%p", type
);
3685 g_free(floating_point
);
3689 void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type
*type
)
3691 struct bt_ctf_field_type_structure
*structure
=
3692 (struct bt_ctf_field_type_structure
*) type
;
3698 BT_LOGD("Destroying structure field type object: addr=%p", type
);
3699 g_ptr_array_free(structure
->fields
, TRUE
);
3700 g_hash_table_destroy(structure
->field_name_to_index
);
3705 void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type
*type
)
3707 struct bt_ctf_field_type_variant
*variant
=
3708 (struct bt_ctf_field_type_variant
*) type
;
3714 BT_LOGD("Destroying variant field type object: addr=%p", type
);
3715 g_ptr_array_free(variant
->fields
, TRUE
);
3716 g_hash_table_destroy(variant
->field_name_to_index
);
3717 g_string_free(variant
->tag_name
, TRUE
);
3718 BT_LOGD_STR("Putting tag field type.");
3719 bt_put(&variant
->tag
->parent
);
3720 BT_PUT(variant
->tag_field_path
);
3725 void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type
*type
)
3727 struct bt_ctf_field_type_array
*array
=
3728 (struct bt_ctf_field_type_array
*) type
;
3734 BT_LOGD("Destroying array field type object: addr=%p", type
);
3735 BT_LOGD_STR("Putting element field type.");
3736 bt_put(array
->element_type
);
3741 void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type
*type
)
3743 struct bt_ctf_field_type_sequence
*sequence
=
3744 (struct bt_ctf_field_type_sequence
*) type
;
3750 BT_LOGD("Destroying sequence field type object: addr=%p", type
);
3751 BT_LOGD_STR("Putting element field type.");
3752 bt_put(sequence
->element_type
);
3753 g_string_free(sequence
->length_field_name
, TRUE
);
3754 BT_LOGD_STR("Putting length field path.");
3755 BT_PUT(sequence
->length_field_path
);
3760 void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type
*type
)
3762 struct bt_ctf_field_type_string
*string
=
3763 (struct bt_ctf_field_type_string
*) type
;
3769 BT_LOGD("Destroying string field type object: addr=%p", type
);
3774 void generic_field_type_freeze(struct bt_ctf_field_type
*type
)
3780 void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type
*type
)
3782 struct bt_ctf_field_type_integer
*integer_type
= container_of(
3783 type
, struct bt_ctf_field_type_integer
, parent
);
3785 BT_LOGD("Freezing integer field type object: addr=%p", type
);
3787 if (integer_type
->mapped_clock
) {
3788 BT_LOGD_STR("Freezing integer field type's mapped clock class.");
3789 bt_ctf_clock_class_freeze(integer_type
->mapped_clock
);
3792 generic_field_type_freeze(type
);
3796 void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type
*type
)
3798 struct bt_ctf_field_type_enumeration
*enumeration_type
= container_of(
3799 type
, struct bt_ctf_field_type_enumeration
, parent
);
3801 BT_LOGD("Freezing enumeration field type object: addr=%p", type
);
3802 set_enumeration_range_overlap(type
);
3803 generic_field_type_freeze(type
);
3804 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3805 enumeration_type
->container
);
3806 bt_ctf_field_type_freeze(enumeration_type
->container
);
3810 void freeze_structure_field(struct structure_field
*field
)
3812 BT_LOGD("Freezing structure/variant field type field: field-addr=%p, "
3813 "field-ft-addr=%p, field-name=\"%s\"", field
,
3814 field
->type
, g_quark_to_string(field
->name
));
3815 bt_ctf_field_type_freeze(field
->type
);
3819 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*type
)
3821 struct bt_ctf_field_type_structure
*structure_type
= container_of(
3822 type
, struct bt_ctf_field_type_structure
, parent
);
3824 /* Cache the alignment */
3825 BT_LOGD("Freezing structure field type object: addr=%p", type
);
3826 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3827 generic_field_type_freeze(type
);
3828 g_ptr_array_foreach(structure_type
->fields
,
3829 (GFunc
) freeze_structure_field
, NULL
);
3833 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*type
)
3835 struct bt_ctf_field_type_variant
*variant_type
= container_of(
3836 type
, struct bt_ctf_field_type_variant
, parent
);
3838 BT_LOGD("Freezing variant field type object: addr=%p", type
);
3839 generic_field_type_freeze(type
);
3840 g_ptr_array_foreach(variant_type
->fields
,
3841 (GFunc
) freeze_structure_field
, NULL
);
3845 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*type
)
3847 struct bt_ctf_field_type_array
*array_type
= container_of(
3848 type
, struct bt_ctf_field_type_array
, parent
);
3850 /* Cache the alignment */
3851 BT_LOGD("Freezing array field type object: addr=%p", type
);
3852 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3853 generic_field_type_freeze(type
);
3854 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3855 array_type
->element_type
);
3856 bt_ctf_field_type_freeze(array_type
->element_type
);
3860 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*type
)
3862 struct bt_ctf_field_type_sequence
*sequence_type
= container_of(
3863 type
, struct bt_ctf_field_type_sequence
, parent
);
3865 /* Cache the alignment */
3866 BT_LOGD("Freezing sequence field type object: addr=%p", type
);
3867 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3868 generic_field_type_freeze(type
);
3869 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3870 sequence_type
->element_type
);
3871 bt_ctf_field_type_freeze(sequence_type
->element_type
);
3875 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
3877 const char *encoding_string
;
3880 case BT_CTF_STRING_ENCODING_NONE
:
3881 encoding_string
= "none";
3883 case BT_CTF_STRING_ENCODING_ASCII
:
3884 encoding_string
= "ASCII";
3886 case BT_CTF_STRING_ENCODING_UTF8
:
3887 encoding_string
= "UTF8";
3890 encoding_string
= "unknown";
3894 return encoding_string
;
3898 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
3900 const char *base_string
;
3903 case BT_CTF_INTEGER_BASE_DECIMAL
:
3904 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
3905 base_string
= "decimal";
3907 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
3908 base_string
= "hexadecimal";
3910 case BT_CTF_INTEGER_BASE_OCTAL
:
3911 base_string
= "octal";
3913 case BT_CTF_INTEGER_BASE_BINARY
:
3914 base_string
= "binary";
3917 base_string
= "unknown";
3925 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*type
,
3926 struct metadata_context
*context
)
3928 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
3929 struct bt_ctf_field_type_integer
, parent
);
3932 BT_LOGD("Serializing integer field type's metadata: "
3933 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3934 g_string_append_printf(context
->string
,
3935 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
3936 integer
->size
, type
->alignment
,
3937 (integer
->is_signed
? "true" : "false"),
3938 get_encoding_string(integer
->encoding
),
3939 get_integer_base_string(integer
->base
),
3940 get_byte_order_string(integer
->user_byte_order
));
3941 if (integer
->mapped_clock
) {
3942 const char *clock_name
= bt_ctf_clock_class_get_name(
3943 integer
->mapped_clock
);
3946 g_string_append_printf(context
->string
,
3947 "; map = clock.%s.value", clock_name
);
3950 g_string_append(context
->string
, "; }");
3955 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*type
,
3956 struct metadata_context
*context
)
3960 struct bt_ctf_field_type_enumeration
*enumeration
= container_of(type
,
3961 struct bt_ctf_field_type_enumeration
, parent
);
3962 struct bt_ctf_field_type
*container_type
;
3963 int container_signed
;
3965 BT_LOGD("Serializing enumeration field type's metadata: "
3966 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3967 container_type
= bt_ctf_field_type_enumeration_get_container_type(type
);
3968 assert(container_type
);
3969 container_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
3970 assert(container_signed
>= 0);
3971 g_string_append(context
->string
, "enum : ");
3972 BT_LOGD_STR("Serializing enumeration field type's container field type's metadata.");
3973 ret
= bt_ctf_field_type_serialize(enumeration
->container
, context
);
3975 BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
3976 "container-ft-addr=%p", enumeration
->container
);
3980 g_string_append(context
->string
, " { ");
3981 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
3982 struct enumeration_mapping
*mapping
=
3983 enumeration
->entries
->pdata
[entry
];
3985 if (container_signed
) {
3986 if (mapping
->range_start
._signed
==
3987 mapping
->range_end
._signed
) {
3988 g_string_append_printf(context
->string
,
3989 "\"%s\" = %" PRId64
,
3990 g_quark_to_string(mapping
->string
),
3991 mapping
->range_start
._signed
);
3993 g_string_append_printf(context
->string
,
3994 "\"%s\" = %" PRId64
" ... %" PRId64
,
3995 g_quark_to_string(mapping
->string
),
3996 mapping
->range_start
._signed
,
3997 mapping
->range_end
._signed
);
4000 if (mapping
->range_start
._unsigned
==
4001 mapping
->range_end
._unsigned
) {
4002 g_string_append_printf(context
->string
,
4003 "\"%s\" = %" PRIu64
,
4004 g_quark_to_string(mapping
->string
),
4005 mapping
->range_start
._unsigned
);
4007 g_string_append_printf(context
->string
,
4008 "\"%s\" = %" PRIu64
" ... %" PRIu64
,
4009 g_quark_to_string(mapping
->string
),
4010 mapping
->range_start
._unsigned
,
4011 mapping
->range_end
._unsigned
);
4015 g_string_append(context
->string
,
4016 ((entry
!= (enumeration
->entries
->len
- 1)) ?
4020 if (context
->field_name
->len
) {
4021 g_string_append_printf(context
->string
, " %s",
4022 context
->field_name
->str
);
4023 g_string_assign(context
->field_name
, "");
4026 bt_put(container_type
);
4031 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type
*type
,
4032 struct metadata_context
*context
)
4034 struct bt_ctf_field_type_floating_point
*floating_point
= container_of(
4035 type
, struct bt_ctf_field_type_floating_point
, parent
);
4037 BT_LOGD("Serializing floating point number field type's metadata: "
4038 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4039 g_string_append_printf(context
->string
,
4040 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
4041 floating_point
->exp_dig
,
4042 floating_point
->mant_dig
,
4043 get_byte_order_string(floating_point
->user_byte_order
),
4049 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*type
,
4050 struct metadata_context
*context
)
4053 unsigned int indent
;
4055 struct bt_ctf_field_type_structure
*structure
= container_of(type
,
4056 struct bt_ctf_field_type_structure
, parent
);
4057 GString
*structure_field_name
= context
->field_name
;
4059 BT_LOGD("Serializing structure field type's metadata: "
4060 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4061 context
->field_name
= g_string_new("");
4063 context
->current_indentation_level
++;
4064 g_string_append(context
->string
, "struct {\n");
4066 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4067 struct structure_field
*field
= structure
->fields
->pdata
[i
];
4069 BT_LOGD("Serializing structure field type's field metadata: "
4070 "index=%" PRId64
", "
4071 "field-ft-addr=%p, field-name=\"%s\"",
4072 i
, field
, g_quark_to_string(field
->name
));
4074 for (indent
= 0; indent
< context
->current_indentation_level
;
4076 g_string_append_c(context
->string
, '\t');
4079 g_string_assign(context
->field_name
,
4080 g_quark_to_string(field
->name
));
4081 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4083 BT_LOGW("Cannot serialize structure field type's field's metadata: "
4084 "index=%" PRId64
", "
4085 "field-ft-addr=%p, field-name=\"%s\"",
4087 g_quark_to_string(field
->name
));
4091 if (context
->field_name
->len
) {
4092 g_string_append_printf(context
->string
, " %s",
4093 context
->field_name
->str
);
4095 g_string_append(context
->string
, ";\n");
4098 context
->current_indentation_level
--;
4099 for (indent
= 0; indent
< context
->current_indentation_level
;
4101 g_string_append_c(context
->string
, '\t');
4104 g_string_append_printf(context
->string
, "} align(%u)",
4107 g_string_free(context
->field_name
, TRUE
);
4108 context
->field_name
= structure_field_name
;
4113 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*type
,
4114 struct metadata_context
*context
)
4117 unsigned int indent
;
4119 struct bt_ctf_field_type_variant
*variant
= container_of(
4120 type
, struct bt_ctf_field_type_variant
, parent
);
4121 GString
*variant_field_name
= context
->field_name
;
4123 BT_LOGD("Serializing variant field type's metadata: "
4124 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4125 context
->field_name
= g_string_new("");
4126 if (variant
->tag_name
->len
> 0) {
4127 g_string_append_printf(context
->string
,
4128 "variant <%s> {\n", variant
->tag_name
->str
);
4130 g_string_append(context
->string
, "variant {\n");
4133 context
->current_indentation_level
++;
4134 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4135 struct structure_field
*field
= variant
->fields
->pdata
[i
];
4137 BT_LOGD("Serializing variant field type's field metadata: "
4138 "index=%" PRId64
", "
4139 "field-ft-addr=%p, field-name=\"%s\"",
4140 i
, field
, g_quark_to_string(field
->name
));
4142 g_string_assign(context
->field_name
,
4143 g_quark_to_string(field
->name
));
4144 for (indent
= 0; indent
< context
->current_indentation_level
;
4146 g_string_append_c(context
->string
, '\t');
4149 g_string_assign(context
->field_name
,
4150 g_quark_to_string(field
->name
));
4151 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4153 BT_LOGW("Cannot serialize variant field type's field's metadata: "
4154 "index=%" PRId64
", "
4155 "field-ft-addr=%p, field-name=\"%s\"",
4157 g_quark_to_string(field
->name
));
4161 if (context
->field_name
->len
) {
4162 g_string_append_printf(context
->string
, " %s;",
4163 context
->field_name
->str
);
4166 g_string_append_c(context
->string
, '\n');
4169 context
->current_indentation_level
--;
4170 for (indent
= 0; indent
< context
->current_indentation_level
;
4172 g_string_append_c(context
->string
, '\t');
4175 g_string_append(context
->string
, "}");
4177 g_string_free(context
->field_name
, TRUE
);
4178 context
->field_name
= variant_field_name
;
4183 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*type
,
4184 struct metadata_context
*context
)
4187 struct bt_ctf_field_type_array
*array
= container_of(type
,
4188 struct bt_ctf_field_type_array
, parent
);
4190 BT_LOGD("Serializing array field type's metadata: "
4191 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4192 BT_LOGD_STR("Serializing array field type's element field type's metadata.");
4193 ret
= bt_ctf_field_type_serialize(array
->element_type
, context
);
4195 BT_LOGW("Cannot serialize array field type's element field type's metadata: "
4196 "element-ft-addr=%p", array
->element_type
);
4200 if (context
->field_name
->len
) {
4201 g_string_append_printf(context
->string
, " %s[%u]",
4202 context
->field_name
->str
, array
->length
);
4203 g_string_assign(context
->field_name
, "");
4205 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4212 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*type
,
4213 struct metadata_context
*context
)
4216 struct bt_ctf_field_type_sequence
*sequence
= container_of(
4217 type
, struct bt_ctf_field_type_sequence
, parent
);
4219 BT_LOGD("Serializing sequence field type's metadata: "
4220 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4221 BT_LOGD_STR("Serializing sequence field type's element field type's metadata.");
4222 ret
= bt_ctf_field_type_serialize(sequence
->element_type
, context
);
4224 BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
4225 "element-ft-addr=%p", sequence
->element_type
);
4229 if (context
->field_name
->len
) {
4230 g_string_append_printf(context
->string
, " %s[%s]",
4231 context
->field_name
->str
,
4232 sequence
->length_field_name
->str
);
4233 g_string_assign(context
->field_name
, "");
4235 g_string_append_printf(context
->string
, "[%s]",
4236 sequence
->length_field_name
->str
);
4243 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*type
,
4244 struct metadata_context
*context
)
4246 struct bt_ctf_field_type_string
*string
= container_of(
4247 type
, struct bt_ctf_field_type_string
, parent
);
4249 BT_LOGD("Serializing string field type's metadata: "
4250 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4251 g_string_append_printf(context
->string
,
4252 "string { encoding = %s; }",
4253 get_encoding_string(string
->encoding
));
4258 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*type
,
4259 enum bt_ctf_byte_order byte_order
)
4261 struct bt_ctf_field_type_integer
*integer_type
= container_of(type
,
4262 struct bt_ctf_field_type_integer
, parent
);
4264 integer_type
->user_byte_order
= byte_order
;
4268 void bt_ctf_field_type_enumeration_set_byte_order(
4269 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4271 struct bt_ctf_field_type_enumeration
*enum_type
= container_of(type
,
4272 struct bt_ctf_field_type_enumeration
, parent
);
4274 /* Safe to assume that container is an integer */
4275 bt_ctf_field_type_integer_set_byte_order(enum_type
->container
,
4280 void bt_ctf_field_type_floating_point_set_byte_order(
4281 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4283 struct bt_ctf_field_type_floating_point
*floating_point_type
=
4284 container_of(type
, struct bt_ctf_field_type_floating_point
,
4287 floating_point_type
->user_byte_order
= byte_order
;
4291 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*type
,
4292 enum bt_ctf_byte_order byte_order
)
4295 struct bt_ctf_field_type_structure
*structure_type
=
4296 container_of(type
, struct bt_ctf_field_type_structure
,
4299 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
4300 struct structure_field
*field
= g_ptr_array_index(
4301 structure_type
->fields
, i
);
4302 struct bt_ctf_field_type
*field_type
= field
->type
;
4304 if (set_byte_order_funcs
[field_type
->id
]) {
4305 set_byte_order_funcs
[field_type
->id
](
4306 field_type
, byte_order
);
4312 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*type
,
4313 enum bt_ctf_byte_order byte_order
)
4316 struct bt_ctf_field_type_variant
*variant_type
=
4317 container_of(type
, struct bt_ctf_field_type_variant
,
4320 for (i
= 0; i
< variant_type
->fields
->len
; i
++) {
4321 struct structure_field
*field
= g_ptr_array_index(
4322 variant_type
->fields
, i
);
4323 struct bt_ctf_field_type
*field_type
= field
->type
;
4325 if (set_byte_order_funcs
[field_type
->id
]) {
4326 set_byte_order_funcs
[field_type
->id
](
4327 field_type
, byte_order
);
4333 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*type
,
4334 enum bt_ctf_byte_order byte_order
)
4336 struct bt_ctf_field_type_array
*array_type
=
4337 container_of(type
, struct bt_ctf_field_type_array
,
4340 if (set_byte_order_funcs
[array_type
->element_type
->id
]) {
4341 set_byte_order_funcs
[array_type
->element_type
->id
](
4342 array_type
->element_type
, byte_order
);
4347 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*type
,
4348 enum bt_ctf_byte_order byte_order
)
4350 struct bt_ctf_field_type_sequence
*sequence_type
=
4351 container_of(type
, struct bt_ctf_field_type_sequence
,
4354 if (set_byte_order_funcs
[
4355 sequence_type
->element_type
->id
]) {
4356 set_byte_order_funcs
[
4357 sequence_type
->element_type
->id
](
4358 sequence_type
->element_type
, byte_order
);
4363 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4364 struct bt_ctf_field_type
*type
)
4366 struct bt_ctf_field_type
*copy
;
4367 struct bt_ctf_field_type_integer
*integer
, *copy_integer
;
4369 BT_LOGD("Copying integer field type's: addr=%p", type
);
4370 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
4371 copy
= bt_ctf_field_type_integer_create(integer
->size
);
4373 BT_LOGE_STR("Cannot create integer field type.");
4377 copy_integer
= container_of(copy
, struct bt_ctf_field_type_integer
,
4379 copy_integer
->mapped_clock
= bt_get(integer
->mapped_clock
);
4380 copy_integer
->user_byte_order
= integer
->user_byte_order
;
4381 copy_integer
->is_signed
= integer
->is_signed
;
4382 copy_integer
->size
= integer
->size
;
4383 copy_integer
->base
= integer
->base
;
4384 copy_integer
->encoding
= integer
->encoding
;
4385 BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4393 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
4394 struct bt_ctf_field_type
*type
)
4397 struct bt_ctf_field_type
*copy
= NULL
, *copy_container
;
4398 struct bt_ctf_field_type_enumeration
*enumeration
, *copy_enumeration
;
4400 BT_LOGD("Copying enumeration field type's: addr=%p", type
);
4401 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
4404 /* Copy the source enumeration's container */
4405 BT_LOGD_STR("Copying enumeration field type's container field type.");
4406 copy_container
= bt_ctf_field_type_copy(enumeration
->container
);
4407 if (!copy_container
) {
4408 BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
4412 copy
= bt_ctf_field_type_enumeration_create(copy_container
);
4414 BT_LOGE_STR("Cannot create enumeration field type.");
4417 copy_enumeration
= container_of(copy
,
4418 struct bt_ctf_field_type_enumeration
, parent
);
4420 /* Copy all enumaration entries */
4421 for (i
= 0; i
< enumeration
->entries
->len
; i
++) {
4422 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4423 enumeration
->entries
, i
);
4424 struct enumeration_mapping
*copy_mapping
= g_new0(
4425 struct enumeration_mapping
, 1);
4427 if (!copy_mapping
) {
4428 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4432 *copy_mapping
= *mapping
;
4433 g_ptr_array_add(copy_enumeration
->entries
, copy_mapping
);
4436 BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4440 bt_put(copy_container
);
4443 bt_put(copy_container
);
4449 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4450 struct bt_ctf_field_type
*type
)
4452 struct bt_ctf_field_type
*copy
;
4453 struct bt_ctf_field_type_floating_point
*floating_point
, *copy_float
;
4455 BT_LOGD("Copying floating point number field type's: addr=%p", type
);
4456 floating_point
= container_of(type
,
4457 struct bt_ctf_field_type_floating_point
, parent
);
4458 copy
= bt_ctf_field_type_floating_point_create();
4460 BT_LOGE_STR("Cannot create floating point number field type.");
4464 copy_float
= container_of(copy
,
4465 struct bt_ctf_field_type_floating_point
, parent
);
4466 copy_float
->user_byte_order
= floating_point
->user_byte_order
;
4467 copy_float
->exp_dig
= floating_point
->exp_dig
;
4468 copy_float
->mant_dig
= floating_point
->mant_dig
;
4469 BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4476 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
4477 struct bt_ctf_field_type
*type
)
4480 GHashTableIter iter
;
4481 gpointer key
, value
;
4482 struct bt_ctf_field_type
*copy
;
4483 struct bt_ctf_field_type_structure
*structure
, *copy_structure
;
4485 BT_LOGD("Copying structure field type's: addr=%p", type
);
4486 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
4488 copy
= bt_ctf_field_type_structure_create();
4490 BT_LOGE_STR("Cannot create structure field type.");
4494 copy_structure
= container_of(copy
,
4495 struct bt_ctf_field_type_structure
, parent
);
4497 /* Copy field_name_to_index */
4498 g_hash_table_iter_init(&iter
, structure
->field_name_to_index
);
4499 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4500 g_hash_table_insert(copy_structure
->field_name_to_index
,
4504 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4505 struct structure_field
*entry
, *copy_entry
;
4506 struct bt_ctf_field_type
*copy_field
;
4508 entry
= g_ptr_array_index(structure
->fields
, i
);
4509 BT_LOGD("Copying structure field type's field: "
4510 "index=%" PRId64
", "
4511 "field-ft-addr=%p, field-name=\"%s\"",
4512 i
, entry
, g_quark_to_string(entry
->name
));
4513 copy_entry
= g_new0(struct structure_field
, 1);
4515 BT_LOGE_STR("Failed to allocate one structure field type field.");
4519 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4521 BT_LOGE("Cannot copy structure field type's field: "
4522 "index=%" PRId64
", "
4523 "field-ft-addr=%p, field-name=\"%s\"",
4524 i
, entry
, g_quark_to_string(entry
->name
));
4529 copy_entry
->name
= entry
->name
;
4530 copy_entry
->type
= copy_field
;
4531 g_ptr_array_add(copy_structure
->fields
, copy_entry
);
4534 BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4545 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
4546 struct bt_ctf_field_type
*type
)
4549 GHashTableIter iter
;
4550 gpointer key
, value
;
4551 struct bt_ctf_field_type
*copy
= NULL
, *copy_tag
= NULL
;
4552 struct bt_ctf_field_type_variant
*variant
, *copy_variant
;
4554 BT_LOGD("Copying variant field type's: addr=%p", type
);
4555 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
4558 BT_LOGD_STR("Copying variant field type's tag field type.");
4559 copy_tag
= bt_ctf_field_type_copy(&variant
->tag
->parent
);
4561 BT_LOGE_STR("Cannot copy variant field type's tag field type.");
4566 copy
= bt_ctf_field_type_variant_create(copy_tag
,
4567 variant
->tag_name
->len
? variant
->tag_name
->str
: NULL
);
4569 BT_LOGE_STR("Cannot create variant field type.");
4573 copy_variant
= container_of(copy
, struct bt_ctf_field_type_variant
,
4576 /* Copy field_name_to_index */
4577 g_hash_table_iter_init(&iter
, variant
->field_name_to_index
);
4578 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4579 g_hash_table_insert(copy_variant
->field_name_to_index
,
4583 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4584 struct structure_field
*entry
, *copy_entry
;
4585 struct bt_ctf_field_type
*copy_field
;
4587 entry
= g_ptr_array_index(variant
->fields
, i
);
4588 BT_LOGD("Copying variant field type's field: "
4589 "index=%" PRId64
", "
4590 "field-ft-addr=%p, field-name=\"%s\"",
4591 i
, entry
, g_quark_to_string(entry
->name
));
4592 copy_entry
= g_new0(struct structure_field
, 1);
4594 BT_LOGE_STR("Failed to allocate one variant field type field.");
4598 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4600 BT_LOGE("Cannot copy variant field type's field: "
4601 "index=%" PRId64
", "
4602 "field-ft-addr=%p, field-name=\"%s\"",
4603 i
, entry
, g_quark_to_string(entry
->name
));
4608 copy_entry
->name
= entry
->name
;
4609 copy_entry
->type
= copy_field
;
4610 g_ptr_array_add(copy_variant
->fields
, copy_entry
);
4613 if (variant
->tag_field_path
) {
4614 BT_LOGD_STR("Copying variant field type's tag field path.");
4615 copy_variant
->tag_field_path
= bt_ctf_field_path_copy(
4616 variant
->tag_field_path
);
4617 if (!copy_variant
->tag_field_path
) {
4618 BT_LOGE_STR("Cannot copy variant field type's tag field path.");
4623 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4636 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
4637 struct bt_ctf_field_type
*type
)
4639 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4640 struct bt_ctf_field_type_array
*array
;
4642 BT_LOGD("Copying array field type's: addr=%p", type
);
4643 array
= container_of(type
, struct bt_ctf_field_type_array
,
4645 BT_LOGD_STR("Copying array field type's element field type.");
4646 copy_element
= bt_ctf_field_type_copy(array
->element_type
);
4647 if (!copy_element
) {
4648 BT_LOGE_STR("Cannot copy array field type's element field type.");
4652 copy
= bt_ctf_field_type_array_create(copy_element
, array
->length
);
4654 BT_LOGE_STR("Cannot create array field type.");
4658 BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
4662 bt_put(copy_element
);
4667 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
4668 struct bt_ctf_field_type
*type
)
4670 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4671 struct bt_ctf_field_type_sequence
*sequence
, *copy_sequence
;
4673 BT_LOGD("Copying sequence field type's: addr=%p", type
);
4674 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
4676 BT_LOGD_STR("Copying sequence field type's element field type.");
4677 copy_element
= bt_ctf_field_type_copy(sequence
->element_type
);
4678 if (!copy_element
) {
4679 BT_LOGE_STR("Cannot copy sequence field type's element field type.");
4683 copy
= bt_ctf_field_type_sequence_create(copy_element
,
4684 sequence
->length_field_name
->len
?
4685 sequence
->length_field_name
->str
: NULL
);
4687 BT_LOGE_STR("Cannot create sequence field type.");
4691 copy_sequence
= container_of(copy
, struct bt_ctf_field_type_sequence
,
4693 if (sequence
->length_field_path
) {
4694 BT_LOGD_STR("Copying sequence field type's length field path.");
4695 copy_sequence
->length_field_path
= bt_ctf_field_path_copy(
4696 sequence
->length_field_path
);
4697 if (!copy_sequence
->length_field_path
) {
4698 BT_LOGE_STR("Cannot copy sequence field type's length field path.");
4703 BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4707 bt_put(copy_element
);
4715 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4716 struct bt_ctf_field_type
*type
)
4718 struct bt_ctf_field_type
*copy
;
4720 BT_LOGD("Copying string field type's: addr=%p", type
);
4721 copy
= bt_ctf_field_type_string_create();
4723 BT_LOGE_STR("Cannot create string field type.");
4727 BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
4734 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*type_a
,
4735 struct bt_ctf_field_type
*type_b
)
4738 struct bt_ctf_field_type_integer
*int_type_a
;
4739 struct bt_ctf_field_type_integer
*int_type_b
;
4741 int_type_a
= container_of(type_a
, struct bt_ctf_field_type_integer
,
4743 int_type_b
= container_of(type_b
, struct bt_ctf_field_type_integer
,
4747 if (int_type_a
->size
!= int_type_b
->size
) {
4748 BT_LOGV("Integer field types differ: different sizes: "
4749 "ft-a-size=%u, ft-b-size=%u",
4750 int_type_a
->size
, int_type_b
->size
);
4755 if (int_type_a
->user_byte_order
!= int_type_b
->user_byte_order
) {
4756 BT_LOGV("Integer field types differ: different byte orders: "
4757 "ft-a-bo=%s, ft-b-bo=%s",
4758 bt_ctf_byte_order_string(int_type_a
->user_byte_order
),
4759 bt_ctf_byte_order_string(int_type_b
->user_byte_order
));
4764 if (int_type_a
->is_signed
!= int_type_b
->is_signed
) {
4765 BT_LOGV("Integer field types differ: different signedness: "
4766 "ft-a-is-signed=%d, ft-b-is-signed=%d",
4767 int_type_a
->is_signed
,
4768 int_type_b
->is_signed
);
4773 if (int_type_a
->base
!= int_type_b
->base
) {
4774 BT_LOGV("Integer field types differ: different bases: "
4775 "ft-a-base=%s, ft-b-base=%s",
4776 bt_ctf_integer_base_string(int_type_a
->base
),
4777 bt_ctf_integer_base_string(int_type_b
->base
));
4782 if (int_type_a
->encoding
!= int_type_b
->encoding
) {
4783 BT_LOGV("Integer field types differ: different encodings: "
4784 "ft-a-encoding=%s, ft-b-encoding=%s",
4785 bt_ctf_string_encoding_string(int_type_a
->encoding
),
4786 bt_ctf_string_encoding_string(int_type_b
->encoding
));
4791 if (int_type_a
->mapped_clock
!= int_type_b
->mapped_clock
) {
4792 BT_LOGV("Integer field types differ: different mapped clock classes: "
4793 "ft-a-mapped-clock-class-addr=%p, "
4794 "ft-b-mapped-clock-class-addr=%p, "
4795 "ft-a-mapped-clock-class-name=\"%s\", "
4796 "ft-b-mapped-clock-class-name=\"%s\"",
4797 int_type_a
->mapped_clock
, int_type_b
->mapped_clock
,
4798 int_type_a
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_a
->mapped_clock
) : "",
4799 int_type_b
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_b
->mapped_clock
) : "");
4811 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*type_a
,
4812 struct bt_ctf_field_type
*type_b
)
4815 struct bt_ctf_field_type_floating_point
*float_a
;
4816 struct bt_ctf_field_type_floating_point
*float_b
;
4818 float_a
= container_of(type_a
,
4819 struct bt_ctf_field_type_floating_point
, parent
);
4820 float_b
= container_of(type_b
,
4821 struct bt_ctf_field_type_floating_point
, parent
);
4824 if (float_a
->user_byte_order
!= float_b
->user_byte_order
) {
4825 BT_LOGV("Floating point number field types differ: different byte orders: "
4826 "ft-a-bo=%s, ft-b-bo=%s",
4827 bt_ctf_byte_order_string(float_a
->user_byte_order
),
4828 bt_ctf_byte_order_string(float_b
->user_byte_order
));
4832 /* Exponent length */
4833 if (float_a
->exp_dig
!= float_b
->exp_dig
) {
4834 BT_LOGV("Floating point number field types differ: different exponent sizes: "
4835 "ft-a-exp-size=%u, ft-b-exp-size=%u",
4836 float_a
->exp_dig
, float_b
->exp_dig
);
4840 /* Mantissa length */
4841 if (float_a
->mant_dig
!= float_b
->mant_dig
) {
4842 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
4843 "ft-a-mant-size=%u, ft-b-mant-size=%u",
4844 float_a
->mant_dig
, float_b
->mant_dig
);
4856 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
4857 struct enumeration_mapping
*mapping_b
)
4862 if (mapping_a
->string
!= mapping_b
->string
) {
4863 BT_LOGV("Enumeration field type mappings differ: different names: "
4864 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
4865 g_quark_to_string(mapping_a
->string
),
4866 g_quark_to_string(mapping_b
->string
));
4871 if (mapping_a
->range_start
._unsigned
!=
4872 mapping_b
->range_start
._unsigned
) {
4873 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
4874 "mapping-a-range-start-unsigned=%" PRIu64
", "
4875 "mapping-b-range-start-unsigned=%" PRIu64
,
4876 mapping_a
->range_start
._unsigned
,
4877 mapping_b
->range_start
._unsigned
);
4882 if (mapping_a
->range_end
._unsigned
!=
4883 mapping_b
->range_end
._unsigned
) {
4884 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
4885 "mapping-a-range-end-unsigned=%" PRIu64
", "
4886 "mapping-b-range-end-unsigned=%" PRIu64
,
4887 mapping_a
->range_end
._unsigned
,
4888 mapping_b
->range_end
._unsigned
);
4900 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*type_a
,
4901 struct bt_ctf_field_type
*type_b
)
4905 struct bt_ctf_field_type_enumeration
*enum_a
;
4906 struct bt_ctf_field_type_enumeration
*enum_b
;
4908 enum_a
= container_of(type_a
,
4909 struct bt_ctf_field_type_enumeration
, parent
);
4910 enum_b
= container_of(type_b
,
4911 struct bt_ctf_field_type_enumeration
, parent
);
4913 /* Container field type */
4914 ret
= bt_ctf_field_type_compare(enum_a
->container
, enum_b
->container
);
4916 BT_LOGV("Enumeration field types differ: different container field types: "
4917 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
4918 enum_a
->container
, enum_b
->container
);
4925 if (enum_a
->entries
->len
!= enum_b
->entries
->len
) {
4929 for (i
= 0; i
< enum_a
->entries
->len
; ++i
) {
4930 struct enumeration_mapping
*mapping_a
=
4931 g_ptr_array_index(enum_a
->entries
, i
);
4932 struct enumeration_mapping
*mapping_b
=
4933 g_ptr_array_index(enum_b
->entries
, i
);
4935 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4936 BT_LOGV("Enumeration field types differ: different mappings: "
4937 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4938 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4939 mapping_a
, mapping_b
,
4940 g_quark_to_string(mapping_a
->string
),
4941 g_quark_to_string(mapping_b
->string
));
4954 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*type_a
,
4955 struct bt_ctf_field_type
*type_b
)
4958 struct bt_ctf_field_type_string
*string_a
;
4959 struct bt_ctf_field_type_string
*string_b
;
4961 string_a
= container_of(type_a
,
4962 struct bt_ctf_field_type_string
, parent
);
4963 string_b
= container_of(type_b
,
4964 struct bt_ctf_field_type_string
, parent
);
4967 if (string_a
->encoding
!= string_b
->encoding
) {
4968 BT_LOGV("String field types differ: different encodings: "
4969 "ft-a-encoding=%s, ft-b-encoding=%s",
4970 bt_ctf_string_encoding_string(string_a
->encoding
),
4971 bt_ctf_string_encoding_string(string_b
->encoding
));
4983 int compare_structure_fields(struct structure_field
*field_a
,
4984 struct structure_field
*field_b
)
4989 if (field_a
->name
!= field_b
->name
) {
4990 BT_LOGV("Structure/variant field type fields differ: different names: "
4991 "field-a-name=%s, field-b-name=%s",
4992 g_quark_to_string(field_a
->name
),
4993 g_quark_to_string(field_b
->name
));
4998 ret
= bt_ctf_field_type_compare(field_a
->type
, field_b
->type
);
5000 BT_LOGV("Structure/variant field type fields differ: different field types: "
5001 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
5002 g_quark_to_string(field_a
->name
),
5003 field_a
->type
, field_b
->type
);
5011 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*type_a
,
5012 struct bt_ctf_field_type
*type_b
)
5016 struct bt_ctf_field_type_structure
*struct_a
;
5017 struct bt_ctf_field_type_structure
*struct_b
;
5019 struct_a
= container_of(type_a
,
5020 struct bt_ctf_field_type_structure
, parent
);
5021 struct_b
= container_of(type_b
,
5022 struct bt_ctf_field_type_structure
, parent
);
5025 if (bt_ctf_field_type_get_alignment(type_a
) !=
5026 bt_ctf_field_type_get_alignment(type_b
)) {
5027 BT_LOGV("Structure field types differ: different alignments: "
5028 "ft-a-align=%u, ft-b-align=%u",
5029 bt_ctf_field_type_get_alignment(type_a
),
5030 bt_ctf_field_type_get_alignment(type_b
));
5035 if (struct_a
->fields
->len
!= struct_b
->fields
->len
) {
5036 BT_LOGV("Structure field types differ: different field counts: "
5037 "ft-a-field-count=%u, ft-b-field-count=%u",
5038 struct_a
->fields
->len
, struct_b
->fields
->len
);
5042 for (i
= 0; i
< struct_a
->fields
->len
; ++i
) {
5043 struct structure_field
*field_a
=
5044 g_ptr_array_index(struct_a
->fields
, i
);
5045 struct structure_field
*field_b
=
5046 g_ptr_array_index(struct_b
->fields
, i
);
5048 ret
= compare_structure_fields(field_a
, field_b
);
5050 /* compare_structure_fields() logs what differs */
5051 BT_LOGV_STR("Structure field types differ: different fields.");
5064 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*type_a
,
5065 struct bt_ctf_field_type
*type_b
)
5069 struct bt_ctf_field_type_variant
*variant_a
;
5070 struct bt_ctf_field_type_variant
*variant_b
;
5072 variant_a
= container_of(type_a
,
5073 struct bt_ctf_field_type_variant
, parent
);
5074 variant_b
= container_of(type_b
,
5075 struct bt_ctf_field_type_variant
, parent
);
5078 if (strcmp(variant_a
->tag_name
->str
, variant_b
->tag_name
->str
)) {
5079 BT_LOGV("Variant field types differ: different tag field names: "
5080 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
5081 variant_a
->tag_name
->str
, variant_b
->tag_name
->str
);
5086 ret
= bt_ctf_field_type_compare(
5087 (struct bt_ctf_field_type
*) variant_a
->tag
,
5088 (struct bt_ctf_field_type
*) variant_b
->tag
);
5090 BT_LOGV("Variant field types differ: different tag field types: "
5091 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
5092 variant_a
->tag
, variant_b
->tag
);
5099 if (variant_a
->fields
->len
!= variant_b
->fields
->len
) {
5100 BT_LOGV("Structure field types differ: different field counts: "
5101 "ft-a-field-count=%u, ft-b-field-count=%u",
5102 variant_a
->fields
->len
, variant_b
->fields
->len
);
5106 for (i
= 0; i
< variant_a
->fields
->len
; ++i
) {
5107 struct structure_field
*field_a
=
5108 g_ptr_array_index(variant_a
->fields
, i
);
5109 struct structure_field
*field_b
=
5110 g_ptr_array_index(variant_b
->fields
, i
);
5112 ret
= compare_structure_fields(field_a
, field_b
);
5114 /* compare_structure_fields() logs what differs */
5115 BT_LOGV_STR("Variant field types differ: different fields.");
5128 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*type_a
,
5129 struct bt_ctf_field_type
*type_b
)
5132 struct bt_ctf_field_type_array
*array_a
;
5133 struct bt_ctf_field_type_array
*array_b
;
5135 array_a
= container_of(type_a
,
5136 struct bt_ctf_field_type_array
, parent
);
5137 array_b
= container_of(type_b
,
5138 struct bt_ctf_field_type_array
, parent
);
5141 if (array_a
->length
!= array_b
->length
) {
5142 BT_LOGV("Structure field types differ: different lengths: "
5143 "ft-a-length=%u, ft-b-length=%u",
5144 array_a
->length
, array_b
->length
);
5149 ret
= bt_ctf_field_type_compare(array_a
->element_type
,
5150 array_b
->element_type
);
5152 BT_LOGV("Array field types differ: different element field types: "
5153 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5154 array_a
->element_type
, array_b
->element_type
);
5162 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*type_a
,
5163 struct bt_ctf_field_type
*type_b
)
5166 struct bt_ctf_field_type_sequence
*sequence_a
;
5167 struct bt_ctf_field_type_sequence
*sequence_b
;
5169 sequence_a
= container_of(type_a
,
5170 struct bt_ctf_field_type_sequence
, parent
);
5171 sequence_b
= container_of(type_b
,
5172 struct bt_ctf_field_type_sequence
, parent
);
5175 if (strcmp(sequence_a
->length_field_name
->str
,
5176 sequence_b
->length_field_name
->str
)) {
5177 BT_LOGV("Sequence field types differ: different length field names: "
5178 "ft-a-length-field-name=\"%s\", "
5179 "ft-b-length-field-name=\"%s\"",
5180 sequence_a
->length_field_name
->str
,
5181 sequence_b
->length_field_name
->str
);
5186 ret
= bt_ctf_field_type_compare(sequence_a
->element_type
,
5187 sequence_b
->element_type
);
5189 BT_LOGV("Sequence field types differ: different element field types: "
5190 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5191 sequence_a
->element_type
, sequence_b
->element_type
);
5198 int bt_ctf_field_type_compare(struct bt_ctf_field_type
*type_a
,
5199 struct bt_ctf_field_type
*type_b
)
5203 if (type_a
== type_b
) {
5204 /* Same reference: equal (even if both are NULL) */
5210 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
5216 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
5221 if (type_a
->id
!= type_b
->id
) {
5222 /* Different type IDs */
5223 BT_LOGV("Field types differ: different IDs: "
5224 "ft-a-addr=%p, ft-b-addr=%p, "
5225 "ft-a-id=%s, ft-b-id=%s",
5227 bt_ctf_field_type_id_string(type_a
->id
),
5228 bt_ctf_field_type_id_string(type_b
->id
));
5232 if (type_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
5233 /* Both have unknown type IDs */
5234 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
5238 ret
= type_compare_funcs
[type_a
->id
](type_a
, type_b
);
5240 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
5249 int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*field_type
)
5251 int64_t field_count
= -1;
5252 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5255 case CTF_TYPE_STRUCT
:
5257 bt_ctf_field_type_structure_get_field_count(field_type
);
5259 case CTF_TYPE_VARIANT
:
5261 bt_ctf_field_type_variant_get_field_count(field_type
);
5263 case CTF_TYPE_ARRAY
:
5264 case CTF_TYPE_SEQUENCE
:
5266 * Array and sequence types always contain a single member
5267 * (the element type).
5279 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
5280 struct bt_ctf_field_type
*field_type
, int index
)
5282 struct bt_ctf_field_type
*field
= NULL
;
5283 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5286 case CTF_TYPE_STRUCT
:
5287 bt_ctf_field_type_structure_get_field_by_index(field_type
,
5288 NULL
, &field
, index
);
5290 case CTF_TYPE_VARIANT
:
5292 int ret
= bt_ctf_field_type_variant_get_field_by_index(
5293 field_type
, NULL
, &field
, index
);
5300 case CTF_TYPE_ARRAY
:
5301 field
= bt_ctf_field_type_array_get_element_type(field_type
);
5303 case CTF_TYPE_SEQUENCE
:
5304 field
= bt_ctf_field_type_sequence_get_element_type(field_type
);
5314 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*field_type
,
5317 int field_index
= -1;
5318 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5321 case CTF_TYPE_STRUCT
:
5322 field_index
= bt_ctf_field_type_structure_get_field_name_index(
5325 case CTF_TYPE_VARIANT
:
5326 field_index
= bt_ctf_field_type_variant_get_field_name_index(
5336 struct bt_ctf_field_path
*bt_ctf_field_type_variant_get_tag_field_path(
5337 struct bt_ctf_field_type
*type
)
5339 struct bt_ctf_field_path
*field_path
= NULL
;
5340 struct bt_ctf_field_type_variant
*variant
;
5343 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5347 if (!bt_ctf_field_type_is_variant(type
)) {
5348 BT_LOGW("Invalid parameter: field type is not a variant field type: "
5349 "addr=%p, ft-id=%s", type
,
5350 bt_ctf_field_type_id_string(type
->id
));
5354 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
5356 field_path
= bt_get(variant
->tag_field_path
);
5361 struct bt_ctf_field_path
*bt_ctf_field_type_sequence_get_length_field_path(
5362 struct bt_ctf_field_type
*type
)
5364 struct bt_ctf_field_path
*field_path
= NULL
;
5365 struct bt_ctf_field_type_sequence
*sequence
;
5368 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5372 if (!bt_ctf_field_type_is_sequence(type
)) {
5373 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
5374 "addr=%p, ft-id=%s", type
,
5375 bt_ctf_field_type_id_string(type
->id
));
5379 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
5381 field_path
= bt_get(sequence
->length_field_path
);