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_variant_validate(struct bt_ctf_field_type
*type
)
705 struct bt_ctf_field_type
*child_type
= NULL
;
706 struct bt_ctf_field_type_variant
*variant
=
707 container_of(type
, struct bt_ctf_field_type_variant
,
711 if (variant
->tag_name
->len
== 0) {
712 BT_LOGW("Invalid variant field type: no tag field name: "
719 BT_LOGW("Invalid variant field type: no tag field type: "
720 "addr=%p, tag-field-name=\"%s\"", type
,
721 variant
->tag_name
->str
);
726 if (bt_ctf_field_type_enumeration_has_overlapping_ranges(
728 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
729 "variant-ft-addr=%p, tag-field-name=\"%s\", "
730 "enum-ft-addr=%p", type
, variant
->tag_name
->str
,
737 * It is valid to have a variant field type which does not have
738 * the fields corresponding to each label in the associated
741 * It is also valid to have variant field type fields which
742 * cannot be selected because the variant field type tag has no
743 * mapping named as such. This scenario, while not ideal, cannot
746 * If a non-existing field happens to be selected by an
747 * enumeration while reading a variant field, an error will be
748 * generated at that point (while reading the stream).
750 field_count
= bt_ctf_field_type_variant_get_field_count(type
);
751 if (field_count
< 0) {
752 BT_LOGW("Invalid variant field type: no fields: "
753 "addr=%p, tag-field-name=\"%s\"",
754 type
, variant
->tag_name
->str
);
759 for (i
= 0; i
< field_count
; ++i
) {
760 const char *field_name
;
762 ret
= bt_ctf_field_type_variant_get_field_by_index(type
,
763 &field_name
, &child_type
, i
);
765 ret
= bt_ctf_field_type_validate(child_type
);
767 BT_LOGW("Invalid variant field type: "
768 "a contained field type is invalid: "
769 "variant-ft-addr=%p, tag-field-name=\"%s\", "
770 "field-ft-addr=%p, field-name=\"%s\", "
771 "field-index=%" PRId64
,
772 type
, variant
->tag_name
->str
, child_type
,
787 * This function validates a given field type without considering
788 * where this field type is located. It only validates the properties
789 * of the given field type and the properties of its children if
793 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
)
796 enum bt_ctf_field_type_id id
= bt_ctf_field_type_get_type_id(type
);
801 /* Already marked as valid */
805 if (type_validate_funcs
[id
]) {
806 ret
= type_validate_funcs
[id
](type
);
809 if (!ret
&& type
->frozen
) {
810 /* Field type is valid */
811 BT_LOGV("Marking field type as valid: addr=%p", type
);
819 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
821 struct bt_ctf_field_type_integer
*integer
=
822 g_new0(struct bt_ctf_field_type_integer
, 1);
824 BT_LOGD("Creating integer field type object: size=%u", size
);
827 BT_LOGE_STR("Failed to allocate one integer field type.");
831 if (size
== 0 || size
> 64) {
832 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
837 integer
->parent
.id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
838 integer
->size
= size
;
839 integer
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
840 integer
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
841 bt_ctf_field_type_init(&integer
->parent
, TRUE
);
842 BT_LOGD("Created integer field type object: addr=%p, size=%u",
843 &integer
->parent
, size
);
844 return &integer
->parent
;
847 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*type
)
850 struct bt_ctf_field_type_integer
*integer
;
853 BT_LOGW_STR("Invalid parameter: field type is NULL.");
858 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
859 BT_LOGW("Invalid parameter: field type is not an integer field type: "
860 "addr=%p, ft-id=%s", type
,
861 bt_ctf_field_type_id_string(type
->id
));
866 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
867 ret
= (int) integer
->size
;
872 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type
*type
)
875 struct bt_ctf_field_type_integer
*integer
;
878 BT_LOGW_STR("Invalid parameter: field type is NULL.");
883 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
884 BT_LOGW("Invalid parameter: field type is not an integer field type: "
885 "addr=%p, ft-id=%s", type
,
886 bt_ctf_field_type_id_string(type
->id
));
891 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
892 ret
= integer
->is_signed
;
897 bt_bool
bt_ctf_field_type_integer_is_signed(
898 struct bt_ctf_field_type
*int_field_type
)
900 return bt_ctf_field_type_integer_get_signed(int_field_type
) ?
904 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type
*type
,
908 struct bt_ctf_field_type_integer
*integer
;
911 BT_LOGW_STR("Invalid parameter: field type is NULL.");
917 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
923 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
924 BT_LOGW("Invalid parameter: field type is not an integer field type: "
925 "addr=%p, ft-id=%s", type
,
926 bt_ctf_field_type_id_string(type
->id
));
931 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
932 integer
->is_signed
= !!is_signed
;
933 BT_LOGV("Set integer field type's signedness: addr=%p, is-signed=%d",
939 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*type
,
943 struct bt_ctf_field_type_integer
*integer
;
946 BT_LOGW_STR("Invalid parameter: field type is NULL.");
952 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
958 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
959 BT_LOGW("Invalid parameter: field type is not an integer field type: "
960 "addr=%p, ft-id=%s", type
,
961 bt_ctf_field_type_id_string(type
->id
));
966 if (size
== 0 || size
> 64) {
967 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
968 "addr=%p, size=%u", type
, size
);
973 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
974 integer
->size
= size
;
975 BT_LOGV("Set integer field type's size: addr=%p, size=%u",
981 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
982 struct bt_ctf_field_type
*type
)
984 enum bt_ctf_integer_base ret
= BT_CTF_INTEGER_BASE_UNKNOWN
;
985 struct bt_ctf_field_type_integer
*integer
;
988 BT_LOGW_STR("Invalid parameter: field type is NULL.");
992 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
993 BT_LOGW("Invalid parameter: field type is not an integer field type: "
994 "addr=%p, ft-id=%s", type
,
995 bt_ctf_field_type_id_string(type
->id
));
999 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1000 ret
= integer
->base
;
1005 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*type
,
1006 enum bt_ctf_integer_base base
)
1011 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1017 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1023 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1024 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1025 "addr=%p, ft-id=%s", type
,
1026 bt_ctf_field_type_id_string(type
->id
));
1032 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
1033 case BT_CTF_INTEGER_BASE_BINARY
:
1034 case BT_CTF_INTEGER_BASE_OCTAL
:
1035 case BT_CTF_INTEGER_BASE_DECIMAL
:
1036 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1038 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
1039 struct bt_ctf_field_type_integer
, parent
);
1040 integer
->base
= base
;
1044 BT_LOGW("Invalid parameter: unknown integer field type base: "
1045 "addr=%p, base=%d", type
, base
);
1049 BT_LOGV("Set integer field type's base: addr=%p, base=%s",
1050 type
, bt_ctf_integer_base_string(base
));
1056 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
1057 struct bt_ctf_field_type
*type
)
1059 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
1060 struct bt_ctf_field_type_integer
*integer
;
1063 BT_LOGW_STR("Invalid parameter: field type is NULL.");
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
));
1074 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1075 ret
= integer
->encoding
;
1080 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*type
,
1081 enum bt_ctf_string_encoding encoding
)
1084 struct bt_ctf_field_type_integer
*integer
;
1087 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1093 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1099 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1100 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1101 "addr=%p, ft-id=%s", type
,
1102 bt_ctf_field_type_id_string(type
->id
));
1107 if (encoding
< BT_CTF_STRING_ENCODING_NONE
||
1108 encoding
>= BT_CTF_STRING_ENCODING_UNKNOWN
) {
1109 BT_LOGW("Invalid parameter: unknown string encoding: "
1110 "addr=%p, encoding=%d", type
, encoding
);
1115 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1116 integer
->encoding
= encoding
;
1117 BT_LOGV("Set integer field type's encoding: addr=%p, encoding=%s",
1118 type
, bt_ctf_string_encoding_string(encoding
));
1123 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
1124 struct bt_ctf_field_type
*type
)
1126 struct bt_ctf_field_type_integer
*integer
;
1127 struct bt_ctf_clock_class
*clock_class
= NULL
;
1130 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1134 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1135 clock_class
= integer
->mapped_clock
;
1136 bt_get(clock_class
);
1142 int bt_ctf_field_type_integer_set_mapped_clock_class_no_check(
1143 struct bt_ctf_field_type
*type
,
1144 struct bt_ctf_clock_class
*clock_class
)
1146 struct bt_ctf_field_type_integer
*integer
;
1150 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1156 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1161 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1162 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1163 "addr=%p, ft-id=%s", type
,
1164 bt_ctf_field_type_id_string(type
->id
));
1168 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1169 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1170 "clock-class-addr=%p, clock-class-name=\"%s\"",
1172 bt_ctf_clock_class_get_name(clock_class
));
1177 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1178 bt_put(integer
->mapped_clock
);
1179 integer
->mapped_clock
= bt_get(clock_class
);
1180 BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
1181 "clock-class-addr=%p, clock-class-name=\"%s\"",
1182 type
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1187 int bt_ctf_field_type_integer_set_mapped_clock_class(
1188 struct bt_ctf_field_type
*type
,
1189 struct bt_ctf_clock_class
*clock_class
)
1194 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1200 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1206 ret
= bt_ctf_field_type_integer_set_mapped_clock_class_no_check(
1214 void bt_ctf_field_type_enum_iter_destroy(struct bt_object
*obj
)
1216 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
1218 struct bt_ctf_field_type_enumeration_mapping_iterator
,
1221 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
1223 BT_LOGD_STR("Putting parent enumeration field type.");
1224 bt_put(&iter
->enumeration_type
->parent
);
1229 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1230 bt_ctf_field_type_enumeration_find_mappings_type(
1231 struct bt_ctf_field_type
*type
,
1232 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
1234 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1235 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1238 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1242 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1243 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1244 "addr=%p, ft-id=%s", type
,
1245 bt_ctf_field_type_id_string(type
->id
));
1249 enumeration_type
= container_of(type
,
1250 struct bt_ctf_field_type_enumeration
, parent
);
1251 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
1253 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
1257 bt_object_init(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
1259 iter
->enumeration_type
= enumeration_type
;
1261 iter
->type
= iterator_type
;
1266 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1267 bt_ctf_field_type_enumeration_find_mappings_by_name(
1268 struct bt_ctf_field_type
*type
, const char *name
)
1270 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1272 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1273 type
, ITERATOR_BY_NAME
);
1275 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1276 "ft-addr=%p, mapping-name=\"%s\"", type
, name
);
1280 iter
->u
.name_quark
= g_quark_try_string(name
);
1281 if (!iter
->u
.name_quark
) {
1283 * No results are possible, set the iterator's position at the
1286 iter
->index
= iter
->enumeration_type
->entries
->len
;
1294 int bt_ctf_field_type_enumeration_mapping_iterator_next(
1295 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
1297 struct bt_ctf_field_type_enumeration
*enumeration
;
1298 struct bt_ctf_field_type
*type
;
1299 int i
, ret
= 0, len
;
1302 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1307 enumeration
= iter
->enumeration_type
;
1308 type
= &enumeration
->parent
;
1309 len
= enumeration
->entries
->len
;
1310 for (i
= iter
->index
+ 1; i
< len
; i
++) {
1311 struct enumeration_mapping
*mapping
=
1312 get_enumeration_mapping(type
, i
);
1314 switch (iter
->type
) {
1315 case ITERATOR_BY_NAME
:
1316 if (mapping
->string
== iter
->u
.name_quark
) {
1321 case ITERATOR_BY_SIGNED_VALUE
:
1323 int64_t value
= iter
->u
.signed_value
;
1325 if (value
>= mapping
->range_start
._signed
&&
1326 value
<= mapping
->range_end
._signed
) {
1332 case ITERATOR_BY_UNSIGNED_VALUE
:
1334 uint64_t value
= iter
->u
.unsigned_value
;
1336 if (value
>= mapping
->range_start
._unsigned
&&
1337 value
<= mapping
->range_end
._unsigned
) {
1344 BT_LOGF("Invalid enumeration field type mapping iterator type: "
1345 "type=%d", iter
->type
);
1355 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1356 bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1357 struct bt_ctf_field_type
*type
, int64_t value
)
1359 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1361 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1362 type
, ITERATOR_BY_SIGNED_VALUE
);
1364 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1365 "ft-addr=%p, value=%" PRId64
, type
, value
);
1369 if (bt_ctf_field_type_integer_get_signed(
1370 iter
->enumeration_type
->container
) != 1) {
1371 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
1372 "enum-ft-addr=%p, int-ft-addr=%p",
1373 type
, iter
->enumeration_type
->container
);
1377 iter
->u
.signed_value
= value
;
1384 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1385 bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1386 struct bt_ctf_field_type
*type
, uint64_t value
)
1388 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1390 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1391 type
, ITERATOR_BY_UNSIGNED_VALUE
);
1393 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1394 "ft-addr=%p, value=%" PRIu64
, type
, value
);
1398 if (bt_ctf_field_type_integer_get_signed(
1399 iter
->enumeration_type
->container
) != 0) {
1400 BT_LOGW("Invalid parameter: enumeration field type is signed: "
1401 "enum-ft-addr=%p, int-ft-addr=%p",
1402 type
, iter
->enumeration_type
->container
);
1405 iter
->u
.unsigned_value
= value
;
1412 int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
1413 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1414 const char **mapping_name
, int64_t *range_begin
,
1420 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1425 if (iter
->index
== -1) {
1426 BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
1431 ret
= bt_ctf_field_type_enumeration_get_mapping_signed(
1432 &iter
->enumeration_type
->parent
, iter
->index
,
1433 mapping_name
, range_begin
, range_end
);
1438 int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
1439 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1440 const char **mapping_name
, uint64_t *range_begin
,
1441 uint64_t *range_end
)
1446 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1451 if (iter
->index
== -1) {
1452 BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
1457 ret
= bt_ctf_field_type_enumeration_get_mapping_unsigned(
1458 &iter
->enumeration_type
->parent
, iter
->index
,
1459 mapping_name
, range_begin
, range_end
);
1464 int bt_ctf_field_type_enumeration_get_mapping_signed(
1465 struct bt_ctf_field_type
*enum_field_type
,
1466 uint64_t index
, const char **mapping_name
, int64_t *range_begin
,
1470 struct enumeration_mapping
*mapping
;
1472 if (!enum_field_type
) {
1473 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1478 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1480 /* get_enumeration_mapping() reports any error */
1486 *mapping_name
= g_quark_to_string(mapping
->string
);
1487 assert(*mapping_name
);
1491 *range_begin
= mapping
->range_start
._signed
;
1495 *range_end
= mapping
->range_end
._signed
;
1501 int bt_ctf_field_type_enumeration_get_mapping_unsigned(
1502 struct bt_ctf_field_type
*enum_field_type
,
1504 const char **mapping_name
, uint64_t *range_begin
,
1505 uint64_t *range_end
)
1508 struct enumeration_mapping
*mapping
;
1510 if (!enum_field_type
) {
1511 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1516 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1518 /* get_enumeration_mapping() reports any error */
1524 *mapping_name
= g_quark_to_string(mapping
->string
);
1525 assert(*mapping_name
);
1529 *range_begin
= mapping
->range_start
._unsigned
;
1533 *range_end
= mapping
->range_end
._unsigned
;
1539 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
1540 struct bt_ctf_field_type
*integer_container_type
)
1542 struct bt_ctf_field_type_enumeration
*enumeration
= NULL
;
1544 BT_LOGD("Creating enumeration field type object: int-ft-addr=%p",
1545 integer_container_type
);
1547 if (!integer_container_type
) {
1548 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1552 if (integer_container_type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1553 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
1554 "container-ft-addr=%p, container-ft-id=%s",
1555 integer_container_type
,
1556 bt_ctf_field_type_id_string(integer_container_type
->id
));
1560 enumeration
= g_new0(struct bt_ctf_field_type_enumeration
, 1);
1562 BT_LOGE_STR("Failed to allocate one enumeration field type.");
1566 enumeration
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
1567 bt_get(integer_container_type
);
1568 enumeration
->container
= integer_container_type
;
1569 enumeration
->entries
= g_ptr_array_new_with_free_func(
1570 (GDestroyNotify
)destroy_enumeration_mapping
);
1571 bt_ctf_field_type_init(&enumeration
->parent
, FALSE
);
1572 BT_LOGD("Created enumeration field type object: addr=%p, "
1573 "int-ft-addr=%p, int-ft-size=%u",
1574 &enumeration
->parent
, integer_container_type
,
1575 bt_ctf_field_type_integer_get_size(integer_container_type
));
1576 return &enumeration
->parent
;
1578 g_free(enumeration
);
1582 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_type(
1583 struct bt_ctf_field_type
*type
)
1585 struct bt_ctf_field_type
*container_type
= NULL
;
1586 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1589 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1593 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1594 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1595 "addr=%p, ft-id=%s", type
,
1596 bt_ctf_field_type_id_string(type
->id
));
1600 enumeration_type
= container_of(type
,
1601 struct bt_ctf_field_type_enumeration
, parent
);
1602 container_type
= enumeration_type
->container
;
1603 bt_get(container_type
);
1605 return container_type
;
1608 int bt_ctf_field_type_enumeration_add_mapping_signed(
1609 struct bt_ctf_field_type
*type
, const char *string
,
1610 int64_t range_start
, int64_t range_end
)
1613 GQuark mapping_name
;
1614 struct enumeration_mapping
*mapping
;
1615 struct bt_ctf_field_type_enumeration
*enumeration
;
1616 char *escaped_string
;
1619 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1625 BT_LOGW_STR("Invalid parameter: string is NULL.");
1631 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1637 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1638 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1639 "addr=%p, ft-id=%s", type
,
1640 bt_ctf_field_type_id_string(type
->id
));
1645 if (range_end
< range_start
) {
1646 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1647 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1648 type
, range_start
, range_end
);
1653 if (strlen(string
) == 0) {
1654 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1655 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1661 escaped_string
= g_strescape(string
, NULL
);
1662 if (!escaped_string
) {
1663 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1664 "mapping-name-addr=%p, mapping-name=\"%s\"",
1665 type
, string
, string
);
1670 mapping
= g_new(struct enumeration_mapping
, 1);
1672 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1676 mapping_name
= g_quark_from_string(escaped_string
);
1677 *mapping
= (struct enumeration_mapping
) {
1678 .range_start
._signed
= range_start
,
1679 .range_end
._signed
= range_end
,
1680 .string
= mapping_name
,
1682 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1684 g_ptr_array_add(enumeration
->entries
, mapping
);
1685 g_ptr_array_sort(enumeration
->entries
,
1686 (GCompareFunc
)compare_enumeration_mappings_signed
);
1687 BT_LOGV("Added mapping to signed enumeration field type: addr=%p, "
1688 "name=\"%s\", range-start=%" PRId64
", "
1689 "range-end=%" PRId64
,
1690 type
, string
, range_start
, range_end
);
1692 free(escaped_string
);
1697 int bt_ctf_field_type_enumeration_add_mapping_unsigned(
1698 struct bt_ctf_field_type
*type
, const char *string
,
1699 uint64_t range_start
, uint64_t range_end
)
1702 GQuark mapping_name
;
1703 struct enumeration_mapping
*mapping
;
1704 struct bt_ctf_field_type_enumeration
*enumeration
;
1705 char *escaped_string
;
1708 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1714 BT_LOGW_STR("Invalid parameter: string is NULL.");
1720 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1726 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1727 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1728 "addr=%p, ft-id=%s", type
,
1729 bt_ctf_field_type_id_string(type
->id
));
1734 if (range_end
< range_start
) {
1735 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1736 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1737 type
, range_start
, range_end
);
1742 if (strlen(string
) == 0) {
1743 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1744 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1750 escaped_string
= g_strescape(string
, NULL
);
1751 if (!escaped_string
) {
1752 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1753 "mapping-name-addr=%p, mapping-name=\"%s\"",
1754 type
, string
, string
);
1759 mapping
= g_new(struct enumeration_mapping
, 1);
1761 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1765 mapping_name
= g_quark_from_string(escaped_string
);
1766 *mapping
= (struct enumeration_mapping
) {
1767 .range_start
._unsigned
= range_start
,
1768 .range_end
._unsigned
= range_end
,
1769 .string
= mapping_name
,
1771 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1773 g_ptr_array_add(enumeration
->entries
, mapping
);
1774 g_ptr_array_sort(enumeration
->entries
,
1775 (GCompareFunc
)compare_enumeration_mappings_unsigned
);
1776 BT_LOGV("Added mapping to unsigned enumeration field type: addr=%p, "
1777 "name=\"%s\", range-start=%" PRIu64
", "
1778 "range-end=%" PRIu64
,
1779 type
, string
, range_start
, range_end
);
1781 free(escaped_string
);
1786 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
1787 struct bt_ctf_field_type
*type
)
1790 struct bt_ctf_field_type_enumeration
*enumeration
;
1793 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1798 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1799 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1800 "addr=%p, ft-id=%s", type
,
1801 bt_ctf_field_type_id_string(type
->id
));
1806 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1808 ret
= (int64_t) enumeration
->entries
->len
;
1813 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
1815 struct bt_ctf_field_type_floating_point
*floating_point
=
1816 g_new0(struct bt_ctf_field_type_floating_point
, 1);
1818 BT_LOGD_STR("Creating floating point number field type object.");
1820 if (!floating_point
) {
1821 BT_LOGE_STR("Failed to allocate one floating point number field type.");
1825 floating_point
->parent
.id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
1826 floating_point
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
1827 floating_point
->mant_dig
= FLT_MANT_DIG
;
1828 bt_ctf_field_type_init(&floating_point
->parent
, TRUE
);
1829 BT_LOGD("Created floating point number field type object: addr=%p, "
1830 "exp-size=%u, mant-size=%u", &floating_point
->parent
,
1831 floating_point
->exp_dig
, floating_point
->mant_dig
);
1833 return floating_point
? &floating_point
->parent
: NULL
;
1836 int bt_ctf_field_type_floating_point_get_exponent_digits(
1837 struct bt_ctf_field_type
*type
)
1840 struct bt_ctf_field_type_floating_point
*floating_point
;
1843 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1848 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1849 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1850 "addr=%p, ft-id=%s", type
,
1851 bt_ctf_field_type_id_string(type
->id
));
1856 floating_point
= container_of(type
,
1857 struct bt_ctf_field_type_floating_point
, parent
);
1858 ret
= (int) floating_point
->exp_dig
;
1863 int bt_ctf_field_type_floating_point_set_exponent_digits(
1864 struct bt_ctf_field_type
*type
,
1865 unsigned int exponent_digits
)
1868 struct bt_ctf_field_type_floating_point
*floating_point
;
1871 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1877 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1883 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1884 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1885 "addr=%p, ft-id=%s", type
,
1886 bt_ctf_field_type_id_string(type
->id
));
1891 floating_point
= container_of(type
,
1892 struct bt_ctf_field_type_floating_point
, parent
);
1893 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1894 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1896 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1897 BT_LOGW("Invalid parameter: invalid exponent size: "
1898 "addr=%p, exp-size=%u", type
, exponent_digits
);
1903 floating_point
->exp_dig
= exponent_digits
;
1904 BT_LOGV("Set floating point number field type's exponent size: addr=%p, "
1905 "exp-size=%u", type
, exponent_digits
);
1910 int bt_ctf_field_type_floating_point_get_mantissa_digits(
1911 struct bt_ctf_field_type
*type
)
1914 struct bt_ctf_field_type_floating_point
*floating_point
;
1917 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1922 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1923 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1924 "addr=%p, ft-id=%s", type
,
1925 bt_ctf_field_type_id_string(type
->id
));
1930 floating_point
= container_of(type
,
1931 struct bt_ctf_field_type_floating_point
, parent
);
1932 ret
= (int) floating_point
->mant_dig
;
1937 int bt_ctf_field_type_floating_point_set_mantissa_digits(
1938 struct bt_ctf_field_type
*type
,
1939 unsigned int mantissa_digits
)
1942 struct bt_ctf_field_type_floating_point
*floating_point
;
1945 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1951 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1957 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1958 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1959 "addr=%p, ft-id=%s", type
,
1960 bt_ctf_field_type_id_string(type
->id
));
1965 floating_point
= container_of(type
,
1966 struct bt_ctf_field_type_floating_point
, parent
);
1968 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1969 (mantissa_digits
!= DBL_MANT_DIG
) &&
1970 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1971 BT_LOGW("Invalid parameter: invalid mantissa size: "
1972 "addr=%p, mant-size=%u", type
, mantissa_digits
);
1977 floating_point
->mant_dig
= mantissa_digits
;
1978 BT_LOGV("Set floating point number field type's mantissa size: addr=%p, "
1979 "mant-size=%u", type
, mantissa_digits
);
1984 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
1986 struct bt_ctf_field_type_structure
*structure
=
1987 g_new0(struct bt_ctf_field_type_structure
, 1);
1989 BT_LOGD_STR("Creating structure field type object.");
1992 BT_LOGE_STR("Failed to allocate one structure field type.");
1996 structure
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
1997 structure
->fields
= g_ptr_array_new_with_free_func(
1998 (GDestroyNotify
)destroy_structure_field
);
1999 structure
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2000 bt_ctf_field_type_init(&structure
->parent
, TRUE
);
2001 BT_LOGD("Created structure field type object: addr=%p",
2002 &structure
->parent
);
2003 return &structure
->parent
;
2008 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*type
,
2009 struct bt_ctf_field_type
*field_type
,
2010 const char *field_name
)
2013 struct bt_ctf_field_type_structure
*structure
;
2016 * TODO: check that `field_type` does not contain `type`,
2020 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2026 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2032 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2038 if (bt_ctf_validate_identifier(field_name
)) {
2039 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2040 "struct-ft-addr=%p, field-name=\"%s\"",
2046 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2047 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2048 "addr=%p, ft-id=%s", type
,
2049 bt_ctf_field_type_id_string(type
->id
));
2054 if (type
== field_type
) {
2055 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
2061 structure
= container_of(type
,
2062 struct bt_ctf_field_type_structure
, parent
);
2063 if (add_structure_field(structure
->fields
,
2064 structure
->field_name_to_index
, field_type
, field_name
)) {
2065 BT_LOGW("Cannot add field to structure field type: "
2066 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2067 type
, field_type
, field_name
);
2072 BT_LOGV("Added structure field type field: struct-ft-addr=%p, "
2073 "field-ft-addr=%p, field-name=\"%s\"", type
,
2074 field_type
, field_name
);
2079 int64_t bt_ctf_field_type_structure_get_field_count(
2080 struct bt_ctf_field_type
*type
)
2083 struct bt_ctf_field_type_structure
*structure
;
2086 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2091 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2092 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2093 "addr=%p, ft-id=%s", type
,
2094 bt_ctf_field_type_id_string(type
->id
));
2099 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2101 ret
= (int64_t) structure
->fields
->len
;
2106 int bt_ctf_field_type_structure_get_field_by_index(
2107 struct bt_ctf_field_type
*type
,
2108 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2111 struct bt_ctf_field_type_structure
*structure
;
2112 struct structure_field
*field
;
2116 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2121 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2122 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2123 "addr=%p, ft-id=%s", type
,
2124 bt_ctf_field_type_id_string(type
->id
));
2129 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2131 if (index
>= structure
->fields
->len
) {
2132 BT_LOGW("Invalid parameter: index is out of bounds: "
2133 "addr=%p, index=%" PRIu64
", count=%u",
2134 type
, index
, structure
->fields
->len
);
2139 field
= g_ptr_array_index(structure
->fields
, index
);
2141 *field_type
= field
->type
;
2142 bt_get(field
->type
);
2145 *field_name
= g_quark_to_string(field
->name
);
2146 assert(*field_name
);
2152 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
2153 struct bt_ctf_field_type
*type
,
2158 struct structure_field
*field
;
2159 struct bt_ctf_field_type_structure
*structure
;
2160 struct bt_ctf_field_type
*field_type
= NULL
;
2163 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2168 BT_LOGW_STR("Invalid parameter: name is NULL.");
2172 name_quark
= g_quark_try_string(name
);
2174 BT_LOGV("No such structure field type field name: "
2175 "ft-addr=%p, field-name=\"%s\"",
2180 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2182 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
2183 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2184 BT_LOGV("No such structure field type field name: "
2185 "ft-addr=%p, field-name=\"%s\"",
2190 field
= structure
->fields
->pdata
[index
];
2191 field_type
= field
->type
;
2197 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
2198 struct bt_ctf_field_type
*enum_tag
, const char *tag_name
)
2200 struct bt_ctf_field_type_variant
*variant
= NULL
;
2202 BT_LOGD("Creating variant field type object: "
2203 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2204 enum_tag
, tag_name
);
2206 if (tag_name
&& bt_ctf_validate_identifier(tag_name
)) {
2207 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2208 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2209 enum_tag
, tag_name
);
2213 variant
= g_new0(struct bt_ctf_field_type_variant
, 1);
2215 BT_LOGE_STR("Failed to allocate one variant field type.");
2219 variant
->parent
.id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
2220 variant
->tag_name
= g_string_new(tag_name
);
2221 variant
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2222 variant
->fields
= g_ptr_array_new_with_free_func(
2223 (GDestroyNotify
) destroy_structure_field
);
2226 variant
->tag
= container_of(enum_tag
,
2227 struct bt_ctf_field_type_enumeration
, parent
);
2230 bt_ctf_field_type_init(&variant
->parent
, TRUE
);
2231 /* A variant's alignment is undefined */
2232 variant
->parent
.alignment
= 0;
2233 BT_LOGD("Created variant field type object: addr=%p, "
2234 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2235 &variant
->parent
, enum_tag
, tag_name
);
2236 return &variant
->parent
;
2241 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_type(
2242 struct bt_ctf_field_type
*type
)
2244 struct bt_ctf_field_type_variant
*variant
;
2245 struct bt_ctf_field_type
*tag_type
= NULL
;
2248 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2252 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2253 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2254 "addr=%p, ft-id=%s", type
,
2255 bt_ctf_field_type_id_string(type
->id
));
2259 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2260 if (!variant
->tag
) {
2261 BT_LOGV("Variant field type has no tag field type: "
2266 tag_type
= &variant
->tag
->parent
;
2272 const char *bt_ctf_field_type_variant_get_tag_name(
2273 struct bt_ctf_field_type
*type
)
2275 struct bt_ctf_field_type_variant
*variant
;
2276 const char *tag_name
= NULL
;
2279 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2283 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2284 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2285 "addr=%p, ft-id=%s", type
,
2286 bt_ctf_field_type_id_string(type
->id
));
2290 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2291 if (variant
->tag_name
->len
== 0) {
2292 BT_LOGV("Variant field type has no tag field name: "
2297 tag_name
= variant
->tag_name
->str
;
2302 int bt_ctf_field_type_variant_set_tag_name(
2303 struct bt_ctf_field_type
*type
, const char *name
)
2306 struct bt_ctf_field_type_variant
*variant
;
2309 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2315 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2321 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2322 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2323 "addr=%p, ft-id=%s", type
,
2324 bt_ctf_field_type_id_string(type
->id
));
2329 if (bt_ctf_validate_identifier(name
)) {
2330 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2331 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2337 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2338 g_string_assign(variant
->tag_name
, name
);
2339 BT_LOGV("Set variant field type's tag field name: addr=%p, "
2340 "tag-field-name=\"%s\"", type
, name
);
2345 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*type
,
2346 struct bt_ctf_field_type
*field_type
,
2347 const char *field_name
)
2351 struct bt_ctf_field_type_variant
*variant
;
2352 GQuark field_name_quark
= g_quark_from_string(field_name
);
2355 * TODO: check that `field_type` does not contain `type`,
2359 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2365 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2371 if (bt_ctf_validate_identifier(field_name
)) {
2372 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2373 "variant-ft-addr=%p, field-name=\"%s\"",
2379 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2380 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2381 "addr=%p, ft-id=%s", type
,
2382 bt_ctf_field_type_id_string(type
->id
));
2387 if (type
== field_type
) {
2388 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2394 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2396 /* The user has explicitly provided a tag; validate against it. */
2400 /* Make sure this name is present in the enum tag */
2401 for (i
= 0; i
< variant
->tag
->entries
->len
; i
++) {
2402 struct enumeration_mapping
*mapping
=
2403 g_ptr_array_index(variant
->tag
->entries
, i
);
2405 if (mapping
->string
== field_name_quark
) {
2412 /* Validation failed */
2413 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2414 "variant-ft-addr=%p, tag-ft-addr=%p, "
2415 "tag-field-name=\"%s\""
2416 "field-ft-addr=%p, field-name=\"%s\"",
2417 type
, variant
->tag
, variant
->tag_name
->str
,
2418 field_type
, field_name
);
2424 if (add_structure_field(variant
->fields
, variant
->field_name_to_index
,
2425 field_type
, field_name
)) {
2426 BT_LOGW("Cannot add field to variant field type: "
2427 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2428 type
, field_type
, field_name
);
2433 BT_LOGV("Added variant field type field: variant-ft-addr=%p, "
2434 "field-ft-addr=%p, field-name=\"%s\"", type
,
2435 field_type
, field_name
);
2441 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
2442 struct bt_ctf_field_type
*type
,
2443 const char *field_name
)
2447 struct structure_field
*field
;
2448 struct bt_ctf_field_type_variant
*variant
;
2449 struct bt_ctf_field_type
*field_type
= NULL
;
2452 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2457 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2461 name_quark
= g_quark_try_string(field_name
);
2463 BT_LOGV("No such variant field type field name: "
2464 "ft-addr=%p, field-name=\"%s\"",
2469 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2470 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
2471 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2472 BT_LOGV("No such variant field type field name: "
2473 "ft-addr=%p, field-name=\"%s\"",
2478 field
= g_ptr_array_index(variant
->fields
, index
);
2479 field_type
= field
->type
;
2485 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
2486 struct bt_ctf_field_type
*type
,
2487 struct bt_ctf_field
*tag
)
2490 const char *enum_value
;
2491 struct bt_ctf_field_type
*field_type
= NULL
;
2492 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
2495 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2500 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
2504 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2505 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2506 "addr=%p, ft-id=%s", type
,
2507 bt_ctf_field_type_id_string(type
->id
));
2511 iter
= bt_ctf_field_enumeration_get_mappings(tag
);
2512 ret
= bt_ctf_field_type_enumeration_mapping_iterator_next(iter
);
2514 BT_LOGE("Cannot get enumeration field type mapping iterator from enumeration field: "
2515 "enum-field-addr=%p", tag
);
2519 ret
= bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter
,
2520 &enum_value
, NULL
, NULL
);
2522 BT_LOGW("Cannot get enumeration field type mapping iterator's current mapping: "
2523 "iter-addr=%p", iter
);
2527 field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
2534 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*type
)
2537 struct bt_ctf_field_type_variant
*variant
;
2540 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2545 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2546 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2547 "addr=%p, ft-id=%s", type
,
2548 bt_ctf_field_type_id_string(type
->id
));
2553 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2555 ret
= (int64_t) variant
->fields
->len
;
2561 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*type
,
2562 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2565 struct bt_ctf_field_type_variant
*variant
;
2566 struct structure_field
*field
;
2570 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2575 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2576 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2577 "addr=%p, ft-id=%s", type
,
2578 bt_ctf_field_type_id_string(type
->id
));
2583 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2585 if (index
>= variant
->fields
->len
) {
2586 BT_LOGW("Invalid parameter: index is out of bounds: "
2587 "addr=%p, index=%" PRIu64
", count=%u",
2588 type
, index
, variant
->fields
->len
);
2593 field
= g_ptr_array_index(variant
->fields
, index
);
2595 *field_type
= field
->type
;
2596 bt_get(field
->type
);
2599 *field_name
= g_quark_to_string(field
->name
);
2600 assert(*field_name
);
2606 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
2607 struct bt_ctf_field_type
*element_type
,
2608 unsigned int length
)
2610 struct bt_ctf_field_type_array
*array
= NULL
;
2612 BT_LOGD("Creating array field type object: element-ft-addr=%p, "
2613 "length=%u", element_type
, length
);
2615 if (!element_type
) {
2616 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2621 BT_LOGW_STR("Invalid parameter: length is zero.");
2625 array
= g_new0(struct bt_ctf_field_type_array
, 1);
2627 BT_LOGE_STR("Failed to allocate one array field type.");
2631 array
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
2632 bt_get(element_type
);
2633 array
->element_type
= element_type
;
2634 array
->length
= length
;
2635 bt_ctf_field_type_init(&array
->parent
, FALSE
);
2636 BT_LOGD("Created array field type object: addr=%p, "
2637 "element-ft-addr=%p, length=%u",
2638 &array
->parent
, element_type
, length
);
2639 return &array
->parent
;
2644 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_type(
2645 struct bt_ctf_field_type
*type
)
2647 struct bt_ctf_field_type
*ret
= NULL
;
2648 struct bt_ctf_field_type_array
*array
;
2651 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2655 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2656 BT_LOGW("Invalid parameter: field type is not an array field type: "
2657 "addr=%p, ft-id=%s", type
,
2658 bt_ctf_field_type_id_string(type
->id
));
2662 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2663 ret
= array
->element_type
;
2670 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*type
,
2671 struct bt_ctf_field_type
*element_type
)
2674 struct bt_ctf_field_type_array
*array
;
2677 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2682 if (!element_type
) {
2683 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2688 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2689 BT_LOGW("Invalid parameter: field type is not an array field type: "
2690 "addr=%p, ft-id=%s", type
,
2691 bt_ctf_field_type_id_string(type
->id
));
2696 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2698 if (array
->element_type
) {
2699 BT_PUT(array
->element_type
);
2702 array
->element_type
= element_type
;
2703 bt_get(array
->element_type
);
2704 BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
2705 "element-ft-addr=%p", type
, element_type
);
2711 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*type
)
2714 struct bt_ctf_field_type_array
*array
;
2717 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2722 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2723 BT_LOGW("Invalid parameter: field type is not an array field type: "
2724 "addr=%p, ft-id=%s", type
,
2725 bt_ctf_field_type_id_string(type
->id
));
2730 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2731 ret
= (int64_t) array
->length
;
2736 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
2737 struct bt_ctf_field_type
*element_type
,
2738 const char *length_field_name
)
2740 struct bt_ctf_field_type_sequence
*sequence
= NULL
;
2742 BT_LOGD("Creating sequence field type object: element-ft-addr=%p, "
2743 "length-field-name=\"%s\"", element_type
, length_field_name
);
2745 if (!element_type
) {
2746 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2750 if (bt_ctf_validate_identifier(length_field_name
)) {
2751 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
2752 "length-field-name=\"%s\"", length_field_name
);
2756 sequence
= g_new0(struct bt_ctf_field_type_sequence
, 1);
2758 BT_LOGE_STR("Failed to allocate one sequence field type.");
2762 sequence
->parent
.id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
2763 bt_get(element_type
);
2764 sequence
->element_type
= element_type
;
2765 sequence
->length_field_name
= g_string_new(length_field_name
);
2766 bt_ctf_field_type_init(&sequence
->parent
, FALSE
);
2767 BT_LOGD("Created sequence field type object: addr=%p, "
2768 "element-ft-addr=%p, length-field-name=\"%s\"",
2769 &sequence
->parent
, element_type
, length_field_name
);
2770 return &sequence
->parent
;
2775 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_type(
2776 struct bt_ctf_field_type
*type
)
2778 struct bt_ctf_field_type
*ret
= NULL
;
2779 struct bt_ctf_field_type_sequence
*sequence
;
2782 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2786 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2787 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2788 "addr=%p, ft-id=%s", type
,
2789 bt_ctf_field_type_id_string(type
->id
));
2793 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2795 ret
= sequence
->element_type
;
2802 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*type
,
2803 struct bt_ctf_field_type
*element_type
)
2806 struct bt_ctf_field_type_sequence
*sequence
;
2809 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2814 if (!element_type
) {
2815 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2820 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2821 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2822 "addr=%p, ft-id=%s", type
,
2823 bt_ctf_field_type_id_string(type
->id
));
2828 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
, parent
);
2829 if (sequence
->element_type
) {
2830 BT_PUT(sequence
->element_type
);
2833 sequence
->element_type
= element_type
;
2834 bt_get(sequence
->element_type
);
2835 BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
2836 "element-ft-addr=%p", type
, element_type
);
2842 const char *bt_ctf_field_type_sequence_get_length_field_name(
2843 struct bt_ctf_field_type
*type
)
2845 const char *ret
= NULL
;
2846 struct bt_ctf_field_type_sequence
*sequence
;
2849 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2853 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2854 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2855 "addr=%p, ft-id=%s", type
,
2856 bt_ctf_field_type_id_string(type
->id
));
2860 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2862 ret
= sequence
->length_field_name
->str
;
2867 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
2869 struct bt_ctf_field_type_string
*string
=
2870 g_new0(struct bt_ctf_field_type_string
, 1);
2872 BT_LOGD_STR("Creating string field type object.");
2875 BT_LOGE_STR("Failed to allocate one string field type.");
2879 string
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRING
;
2880 bt_ctf_field_type_init(&string
->parent
, TRUE
);
2881 string
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2882 string
->parent
.alignment
= CHAR_BIT
;
2883 BT_LOGD("Created string field type object: addr=%p", &string
->parent
);
2884 return &string
->parent
;
2887 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
2888 struct bt_ctf_field_type
*type
)
2890 struct bt_ctf_field_type_string
*string
;
2891 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
2894 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2898 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2899 BT_LOGW("Invalid parameter: field type is not a string field type: "
2900 "addr=%p, ft-id=%s", type
,
2901 bt_ctf_field_type_id_string(type
->id
));
2905 string
= container_of(type
, struct bt_ctf_field_type_string
,
2907 ret
= string
->encoding
;
2912 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*type
,
2913 enum bt_ctf_string_encoding encoding
)
2916 struct bt_ctf_field_type_string
*string
;
2919 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2924 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2925 BT_LOGW("Invalid parameter: field type is not a string field type: "
2926 "addr=%p, ft-id=%s", type
,
2927 bt_ctf_field_type_id_string(type
->id
));
2932 if ((encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2933 encoding
!= BT_CTF_STRING_ENCODING_ASCII
)) {
2934 BT_LOGW("Invalid parameter: unknown string encoding: "
2935 "addr=%p, encoding=%d", type
, encoding
);
2940 string
= container_of(type
, struct bt_ctf_field_type_string
, parent
);
2941 string
->encoding
= encoding
;
2942 BT_LOGV("Set string field type's encoding: addr=%p, encoding=%s",
2943 type
, bt_ctf_string_encoding_string(encoding
));
2948 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*type
)
2951 enum bt_ctf_field_type_id type_id
;
2954 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2960 ret
= (int) type
->alignment
;
2964 type_id
= bt_ctf_field_type_get_type_id(type
);
2966 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2968 struct bt_ctf_field_type
*element
=
2969 bt_ctf_field_type_sequence_get_element_type(type
);
2972 ret
= bt_ctf_field_type_get_alignment(element
);
2976 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2978 struct bt_ctf_field_type
*element
=
2979 bt_ctf_field_type_array_get_element_type(type
);
2982 ret
= bt_ctf_field_type_get_alignment(element
);
2986 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2988 int64_t i
, element_count
;
2990 element_count
= bt_ctf_field_type_structure_get_field_count(
2992 assert(element_count
>= 0);
2994 for (i
= 0; i
< element_count
; i
++) {
2995 struct bt_ctf_field_type
*field
;
2996 int field_alignment
;
2998 ret
= bt_ctf_field_type_structure_get_field_by_index(
2999 type
, NULL
, &field
, i
);
3002 field_alignment
= bt_ctf_field_type_get_alignment(
3005 if (field_alignment
< 0) {
3006 ret
= field_alignment
;
3010 type
->alignment
= MAX(field_alignment
, type
->alignment
);
3012 ret
= (int) type
->alignment
;
3015 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
3016 BT_LOGW("Invalid parameter: unknown field type ID: "
3017 "addr=%p, ft-id=%d", type
, type_id
);
3021 ret
= (int) type
->alignment
;
3029 int is_power_of_two(unsigned int value
)
3031 return ((value
& (value
- 1)) == 0) && value
> 0;
3034 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
3035 unsigned int alignment
)
3038 enum bt_ctf_field_type_id type_id
;
3040 /* Alignment must be a power of two */
3042 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3048 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3054 if (!is_power_of_two(alignment
)) {
3055 BT_LOGW("Invalid parameter: alignment is not a power of two: "
3056 "addr=%p, align=%u", type
, alignment
);
3061 type_id
= bt_ctf_field_type_get_type_id(type
);
3062 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3063 BT_LOGW("Invalid parameter: unknown field type ID: "
3064 "addr=%p, ft-id=%d", type
, type_id
);
3069 if (type
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&&
3070 alignment
!= CHAR_BIT
) {
3071 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
3072 "addr=%p, align=%u", CHAR_BIT
, type
, alignment
);
3077 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
3078 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
3079 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
3080 /* Setting an alignment on these types makes no sense */
3081 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
3082 "addr=%p, ft-id=%s", type
,
3083 bt_ctf_field_type_id_string(type
->id
));
3088 type
->alignment
= alignment
;
3090 BT_LOGV("Set field type's alignment: addr=%p, align=%u",
3096 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
3097 struct bt_ctf_field_type
*type
)
3099 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
3102 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3107 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3109 struct bt_ctf_field_type_integer
*integer
= container_of(
3110 type
, struct bt_ctf_field_type_integer
, parent
);
3111 ret
= integer
->user_byte_order
;
3114 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3116 struct bt_ctf_field_type_enumeration
*enum_ft
= container_of(
3117 type
, struct bt_ctf_field_type_enumeration
, parent
);
3118 ret
= bt_ctf_field_type_get_byte_order(enum_ft
->container
);
3121 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
3123 struct bt_ctf_field_type_floating_point
*floating_point
=
3125 struct bt_ctf_field_type_floating_point
,
3127 ret
= floating_point
->user_byte_order
;
3131 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
3132 "addr=%p, ft-id=%s", type
,
3133 bt_ctf_field_type_id_string(type
->id
));
3137 assert(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
3138 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
3139 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
3140 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
3146 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
3147 enum bt_ctf_byte_order byte_order
)
3152 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3158 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3164 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
3165 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
3166 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
3167 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
3168 BT_LOGW("Invalid parameter: invalid byte order: "
3169 "addr=%p, bo=%s", type
,
3170 bt_ctf_byte_order_string(byte_order
));
3175 if (set_byte_order_funcs
[type
->id
]) {
3176 set_byte_order_funcs
[type
->id
](type
, byte_order
);
3179 BT_LOGV("Set field type's byte order: addr=%p, bo=%s",
3180 type
, bt_ctf_byte_order_string(byte_order
));
3186 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
3187 struct bt_ctf_field_type
*type
)
3190 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3191 return BT_CTF_FIELD_TYPE_ID_UNKNOWN
;
3197 int bt_ctf_field_type_is_integer(struct bt_ctf_field_type
*type
)
3199 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
;
3202 int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type
*type
)
3204 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_FLOAT
;
3207 int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type
*type
)
3209 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ENUM
;
3212 int bt_ctf_field_type_is_string(struct bt_ctf_field_type
*type
)
3214 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRING
;
3217 int bt_ctf_field_type_is_structure(struct bt_ctf_field_type
*type
)
3219 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
;
3222 int bt_ctf_field_type_is_array(struct bt_ctf_field_type
*type
)
3224 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ARRAY
;
3227 int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type
*type
)
3229 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
3232 int bt_ctf_field_type_is_variant(struct bt_ctf_field_type
*type
)
3234 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_VARIANT
;
3237 /* Pre-2.0 CTF writer backward compatibility */
3238 void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
)
3243 /* Pre-2.0 CTF writer backward compatibility */
3244 void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
)
3250 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
)
3252 if (!type
|| type
->frozen
) {
3260 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
3261 struct bt_ctf_field_type_variant
*variant
,
3264 struct bt_ctf_field_type
*type
= NULL
;
3265 GQuark field_name_quark
;
3267 struct structure_field
*field_entry
;
3268 struct range_overlap_query query
= {
3269 .range_start
._signed
= tag_value
,
3270 .range_end
._signed
= tag_value
,
3275 g_ptr_array_foreach(variant
->tag
->entries
, check_ranges_overlap
,
3277 if (!query
.overlaps
) {
3281 field_name_quark
= query
.mapping_name
;
3282 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3283 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3287 field_entry
= g_ptr_array_index(variant
->fields
, (size_t) index
);
3288 type
= field_entry
->type
;
3294 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
3295 struct bt_ctf_field_type_variant
*variant
,
3298 struct bt_ctf_field_type
*type
= NULL
;
3299 GQuark field_name_quark
;
3301 struct structure_field
*field_entry
;
3302 struct range_overlap_query query
= {
3303 .range_start
._unsigned
= tag_value
,
3304 .range_end
._unsigned
= tag_value
,
3309 g_ptr_array_foreach(variant
->tag
->entries
,
3310 check_ranges_overlap_unsigned
,
3312 if (!query
.overlaps
) {
3316 field_name_quark
= query
.mapping_name
;
3317 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3318 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3322 field_entry
= g_ptr_array_index(variant
->fields
, (size_t)index
);
3323 type
= field_entry
->type
;
3329 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
3330 struct metadata_context
*context
)
3337 /* Make sure field type is valid before serializing it */
3338 ret
= bt_ctf_field_type_validate(type
);
3340 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
3345 ret
= type
->serialize(type
, context
);
3350 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*type
)
3352 struct bt_ctf_field_type
*copy
= NULL
;
3355 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3359 copy
= type_copy_funcs
[type
->id
](type
);
3361 BT_LOGE_STR("Cannot copy field type.");
3365 copy
->alignment
= type
->alignment
;
3371 int bt_ctf_field_type_structure_get_field_name_index(
3372 struct bt_ctf_field_type
*type
, const char *name
)
3377 struct bt_ctf_field_type_structure
*structure
;
3380 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3386 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3391 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
3392 BT_LOGW("Invalid parameter: field type is not a structure field type: "
3393 "addr=%p, ft-id=%s", type
,
3394 bt_ctf_field_type_id_string(type
->id
));
3399 name_quark
= g_quark_try_string(name
);
3401 BT_LOGV("No such structure field type field name: "
3402 "ft-addr=%p, field-name=\"%s\"",
3408 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
3410 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
3411 GUINT_TO_POINTER(name_quark
),
3412 NULL
, (gpointer
*)&index
)) {
3413 BT_LOGV("No such structure field type field name: "
3414 "ft-addr=%p, field-name=\"%s\"",
3425 int bt_ctf_field_type_variant_get_field_name_index(
3426 struct bt_ctf_field_type
*type
, const char *name
)
3431 struct bt_ctf_field_type_variant
*variant
;
3434 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3440 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3445 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3446 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3447 "addr=%p, ft-id=%s", type
,
3448 bt_ctf_field_type_id_string(type
->id
));
3453 name_quark
= g_quark_try_string(name
);
3455 BT_LOGV("No such variant field type field name: "
3456 "ft-addr=%p, field-name=\"%s\"",
3462 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3464 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3465 GUINT_TO_POINTER(name_quark
),
3466 NULL
, (gpointer
*)&index
)) {
3467 BT_LOGV("No such variant field type field name: "
3468 "ft-addr=%p, field-name=\"%s\"",
3479 int bt_ctf_field_type_sequence_set_length_field_path(
3480 struct bt_ctf_field_type
*type
,
3481 struct bt_ctf_field_path
*path
)
3484 struct bt_ctf_field_type_sequence
*sequence
;
3487 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3492 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
3493 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
3494 "addr=%p, ft-id=%s", type
,
3495 bt_ctf_field_type_id_string(type
->id
));
3500 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
3503 BT_MOVE(sequence
->length_field_path
, path
);
3504 BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
3505 "field-path-addr=%p", type
, path
);
3511 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
3512 struct bt_ctf_field_path
*path
)
3515 struct bt_ctf_field_type_variant
*variant
;
3518 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3523 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3524 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3525 "addr=%p, ft-id=%s", type
,
3526 bt_ctf_field_type_id_string(type
->id
));
3531 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3534 BT_MOVE(variant
->tag_field_path
, path
);
3535 BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
3536 "field-path-addr=%p", type
, path
);
3542 int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type
*type
,
3543 struct bt_ctf_field_type
*tag
)
3546 struct bt_ctf_field_type_variant
*variant
;
3549 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3555 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
3560 if (bt_ctf_field_type_get_type_id(tag
) != BT_CTF_FIELD_TYPE_ID_ENUM
) {
3561 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
3562 "addr=%p, ft-id=%s", type
,
3563 bt_ctf_field_type_id_string(type
->id
));
3568 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3572 bt_put(&variant
->tag
->parent
);
3574 variant
->tag
= container_of(tag
, struct bt_ctf_field_type_enumeration
,
3576 BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
3577 "tag-ft-addr=%p", type
, tag
);
3583 void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type
*type
)
3585 struct bt_ctf_field_type_integer
*integer
=
3586 (struct bt_ctf_field_type_integer
*) type
;
3592 BT_LOGD("Destroying integer field type object: addr=%p", type
);
3593 BT_LOGD_STR("Putting mapped clock class.");
3594 bt_put(integer
->mapped_clock
);
3599 void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type
*type
)
3601 struct bt_ctf_field_type_enumeration
*enumeration
=
3602 (struct bt_ctf_field_type_enumeration
*) type
;
3608 BT_LOGD("Destroying enumeration field type object: addr=%p", type
);
3609 g_ptr_array_free(enumeration
->entries
, TRUE
);
3610 BT_LOGD_STR("Putting container field type.");
3611 bt_put(enumeration
->container
);
3612 g_free(enumeration
);
3616 void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type
*type
)
3618 struct bt_ctf_field_type_floating_point
*floating_point
=
3619 (struct bt_ctf_field_type_floating_point
*) type
;
3625 BT_LOGD("Destroying floating point number field type object: addr=%p", type
);
3626 g_free(floating_point
);
3630 void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type
*type
)
3632 struct bt_ctf_field_type_structure
*structure
=
3633 (struct bt_ctf_field_type_structure
*) type
;
3639 BT_LOGD("Destroying structure field type object: addr=%p", type
);
3640 g_ptr_array_free(structure
->fields
, TRUE
);
3641 g_hash_table_destroy(structure
->field_name_to_index
);
3646 void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type
*type
)
3648 struct bt_ctf_field_type_variant
*variant
=
3649 (struct bt_ctf_field_type_variant
*) type
;
3655 BT_LOGD("Destroying variant field type object: addr=%p", type
);
3656 g_ptr_array_free(variant
->fields
, TRUE
);
3657 g_hash_table_destroy(variant
->field_name_to_index
);
3658 g_string_free(variant
->tag_name
, TRUE
);
3659 BT_LOGD_STR("Putting tag field type.");
3660 bt_put(&variant
->tag
->parent
);
3661 BT_PUT(variant
->tag_field_path
);
3666 void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type
*type
)
3668 struct bt_ctf_field_type_array
*array
=
3669 (struct bt_ctf_field_type_array
*) type
;
3675 BT_LOGD("Destroying array field type object: addr=%p", type
);
3676 BT_LOGD_STR("Putting element field type.");
3677 bt_put(array
->element_type
);
3682 void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type
*type
)
3684 struct bt_ctf_field_type_sequence
*sequence
=
3685 (struct bt_ctf_field_type_sequence
*) type
;
3691 BT_LOGD("Destroying sequence field type object: addr=%p", type
);
3692 BT_LOGD_STR("Putting element field type.");
3693 bt_put(sequence
->element_type
);
3694 g_string_free(sequence
->length_field_name
, TRUE
);
3695 BT_LOGD_STR("Putting length field path.");
3696 BT_PUT(sequence
->length_field_path
);
3701 void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type
*type
)
3703 struct bt_ctf_field_type_string
*string
=
3704 (struct bt_ctf_field_type_string
*) type
;
3710 BT_LOGD("Destroying string field type object: addr=%p", type
);
3715 void generic_field_type_freeze(struct bt_ctf_field_type
*type
)
3721 void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type
*type
)
3723 struct bt_ctf_field_type_integer
*integer_type
= container_of(
3724 type
, struct bt_ctf_field_type_integer
, parent
);
3726 BT_LOGD("Freezing integer field type object: addr=%p", type
);
3728 if (integer_type
->mapped_clock
) {
3729 BT_LOGD_STR("Freezing integer field type's mapped clock class.");
3730 bt_ctf_clock_class_freeze(integer_type
->mapped_clock
);
3733 generic_field_type_freeze(type
);
3737 void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type
*type
)
3739 struct bt_ctf_field_type_enumeration
*enumeration_type
= container_of(
3740 type
, struct bt_ctf_field_type_enumeration
, parent
);
3742 BT_LOGD("Freezing enumeration field type object: addr=%p", type
);
3743 set_enumeration_range_overlap(type
);
3744 generic_field_type_freeze(type
);
3745 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3746 enumeration_type
->container
);
3747 bt_ctf_field_type_freeze(enumeration_type
->container
);
3751 void freeze_structure_field(struct structure_field
*field
)
3753 BT_LOGD("Freezing structure/variant field type field: field-addr=%p, "
3754 "field-ft-addr=%p, field-name=\"%s\"", field
,
3755 field
->type
, g_quark_to_string(field
->name
));
3756 bt_ctf_field_type_freeze(field
->type
);
3760 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*type
)
3762 struct bt_ctf_field_type_structure
*structure_type
= container_of(
3763 type
, struct bt_ctf_field_type_structure
, parent
);
3765 /* Cache the alignment */
3766 BT_LOGD("Freezing structure field type object: addr=%p", type
);
3767 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3768 generic_field_type_freeze(type
);
3769 g_ptr_array_foreach(structure_type
->fields
,
3770 (GFunc
) freeze_structure_field
, NULL
);
3774 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*type
)
3776 struct bt_ctf_field_type_variant
*variant_type
= container_of(
3777 type
, struct bt_ctf_field_type_variant
, parent
);
3779 BT_LOGD("Freezing variant field type object: addr=%p", type
);
3780 generic_field_type_freeze(type
);
3781 g_ptr_array_foreach(variant_type
->fields
,
3782 (GFunc
) freeze_structure_field
, NULL
);
3786 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*type
)
3788 struct bt_ctf_field_type_array
*array_type
= container_of(
3789 type
, struct bt_ctf_field_type_array
, parent
);
3791 /* Cache the alignment */
3792 BT_LOGD("Freezing array field type object: addr=%p", type
);
3793 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3794 generic_field_type_freeze(type
);
3795 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3796 array_type
->element_type
);
3797 bt_ctf_field_type_freeze(array_type
->element_type
);
3801 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*type
)
3803 struct bt_ctf_field_type_sequence
*sequence_type
= container_of(
3804 type
, struct bt_ctf_field_type_sequence
, parent
);
3806 /* Cache the alignment */
3807 BT_LOGD("Freezing sequence field type object: addr=%p", type
);
3808 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3809 generic_field_type_freeze(type
);
3810 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3811 sequence_type
->element_type
);
3812 bt_ctf_field_type_freeze(sequence_type
->element_type
);
3816 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
3818 const char *encoding_string
;
3821 case BT_CTF_STRING_ENCODING_NONE
:
3822 encoding_string
= "none";
3824 case BT_CTF_STRING_ENCODING_ASCII
:
3825 encoding_string
= "ASCII";
3827 case BT_CTF_STRING_ENCODING_UTF8
:
3828 encoding_string
= "UTF8";
3831 encoding_string
= "unknown";
3835 return encoding_string
;
3839 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
3841 const char *base_string
;
3844 case BT_CTF_INTEGER_BASE_DECIMAL
:
3845 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
3846 base_string
= "decimal";
3848 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
3849 base_string
= "hexadecimal";
3851 case BT_CTF_INTEGER_BASE_OCTAL
:
3852 base_string
= "octal";
3854 case BT_CTF_INTEGER_BASE_BINARY
:
3855 base_string
= "binary";
3858 base_string
= "unknown";
3866 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*type
,
3867 struct metadata_context
*context
)
3869 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
3870 struct bt_ctf_field_type_integer
, parent
);
3873 BT_LOGD("Serializing integer field type's metadata: "
3874 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3875 g_string_append_printf(context
->string
,
3876 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
3877 integer
->size
, type
->alignment
,
3878 (integer
->is_signed
? "true" : "false"),
3879 get_encoding_string(integer
->encoding
),
3880 get_integer_base_string(integer
->base
),
3881 get_byte_order_string(integer
->user_byte_order
));
3882 if (integer
->mapped_clock
) {
3883 const char *clock_name
= bt_ctf_clock_class_get_name(
3884 integer
->mapped_clock
);
3887 g_string_append_printf(context
->string
,
3888 "; map = clock.%s.value", clock_name
);
3891 g_string_append(context
->string
, "; }");
3896 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*type
,
3897 struct metadata_context
*context
)
3901 struct bt_ctf_field_type_enumeration
*enumeration
= container_of(type
,
3902 struct bt_ctf_field_type_enumeration
, parent
);
3903 struct bt_ctf_field_type
*container_type
;
3904 int container_signed
;
3906 BT_LOGD("Serializing enumeration field type's metadata: "
3907 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3908 container_type
= bt_ctf_field_type_enumeration_get_container_type(type
);
3909 assert(container_type
);
3910 container_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
3911 assert(container_signed
>= 0);
3912 g_string_append(context
->string
, "enum : ");
3913 BT_LOGD_STR("Serializing enumeration field type's container field type's metadata.");
3914 ret
= bt_ctf_field_type_serialize(enumeration
->container
, context
);
3916 BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
3917 "container-ft-addr=%p", enumeration
->container
);
3921 g_string_append(context
->string
, " { ");
3922 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
3923 struct enumeration_mapping
*mapping
=
3924 enumeration
->entries
->pdata
[entry
];
3926 if (container_signed
) {
3927 if (mapping
->range_start
._signed
==
3928 mapping
->range_end
._signed
) {
3929 g_string_append_printf(context
->string
,
3930 "\"%s\" = %" PRId64
,
3931 g_quark_to_string(mapping
->string
),
3932 mapping
->range_start
._signed
);
3934 g_string_append_printf(context
->string
,
3935 "\"%s\" = %" PRId64
" ... %" PRId64
,
3936 g_quark_to_string(mapping
->string
),
3937 mapping
->range_start
._signed
,
3938 mapping
->range_end
._signed
);
3941 if (mapping
->range_start
._unsigned
==
3942 mapping
->range_end
._unsigned
) {
3943 g_string_append_printf(context
->string
,
3944 "\"%s\" = %" PRIu64
,
3945 g_quark_to_string(mapping
->string
),
3946 mapping
->range_start
._unsigned
);
3948 g_string_append_printf(context
->string
,
3949 "\"%s\" = %" PRIu64
" ... %" PRIu64
,
3950 g_quark_to_string(mapping
->string
),
3951 mapping
->range_start
._unsigned
,
3952 mapping
->range_end
._unsigned
);
3956 g_string_append(context
->string
,
3957 ((entry
!= (enumeration
->entries
->len
- 1)) ?
3961 if (context
->field_name
->len
) {
3962 g_string_append_printf(context
->string
, " %s",
3963 context
->field_name
->str
);
3964 g_string_assign(context
->field_name
, "");
3967 bt_put(container_type
);
3972 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type
*type
,
3973 struct metadata_context
*context
)
3975 struct bt_ctf_field_type_floating_point
*floating_point
= container_of(
3976 type
, struct bt_ctf_field_type_floating_point
, parent
);
3978 BT_LOGD("Serializing floating point number field type's metadata: "
3979 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3980 g_string_append_printf(context
->string
,
3981 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
3982 floating_point
->exp_dig
,
3983 floating_point
->mant_dig
,
3984 get_byte_order_string(floating_point
->user_byte_order
),
3990 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*type
,
3991 struct metadata_context
*context
)
3994 unsigned int indent
;
3996 struct bt_ctf_field_type_structure
*structure
= container_of(type
,
3997 struct bt_ctf_field_type_structure
, parent
);
3998 GString
*structure_field_name
= context
->field_name
;
4000 BT_LOGD("Serializing structure field type's metadata: "
4001 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4002 context
->field_name
= g_string_new("");
4004 context
->current_indentation_level
++;
4005 g_string_append(context
->string
, "struct {\n");
4007 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4008 struct structure_field
*field
= structure
->fields
->pdata
[i
];
4010 BT_LOGD("Serializing structure field type's field metadata: "
4012 "field-ft-addr=%p, field-name=\"%s\"",
4013 i
, field
, g_quark_to_string(field
->name
));
4015 for (indent
= 0; indent
< context
->current_indentation_level
;
4017 g_string_append_c(context
->string
, '\t');
4020 g_string_assign(context
->field_name
,
4021 g_quark_to_string(field
->name
));
4022 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4024 BT_LOGW("Cannot serialize structure field type's field's metadata: "
4026 "field-ft-addr=%p, field-name=\"%s\"",
4028 g_quark_to_string(field
->name
));
4032 if (context
->field_name
->len
) {
4033 g_string_append_printf(context
->string
, " %s",
4034 context
->field_name
->str
);
4036 g_string_append(context
->string
, ";\n");
4039 context
->current_indentation_level
--;
4040 for (indent
= 0; indent
< context
->current_indentation_level
;
4042 g_string_append_c(context
->string
, '\t');
4045 g_string_append_printf(context
->string
, "} align(%u)",
4048 g_string_free(context
->field_name
, TRUE
);
4049 context
->field_name
= structure_field_name
;
4054 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*type
,
4055 struct metadata_context
*context
)
4058 unsigned int indent
;
4060 struct bt_ctf_field_type_variant
*variant
= container_of(
4061 type
, struct bt_ctf_field_type_variant
, parent
);
4062 GString
*variant_field_name
= context
->field_name
;
4064 BT_LOGD("Serializing variant field type's metadata: "
4065 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4066 context
->field_name
= g_string_new("");
4067 if (variant
->tag_name
->len
> 0) {
4068 g_string_append_printf(context
->string
,
4069 "variant <%s> {\n", variant
->tag_name
->str
);
4071 g_string_append(context
->string
, "variant {\n");
4074 context
->current_indentation_level
++;
4075 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4076 struct structure_field
*field
= variant
->fields
->pdata
[i
];
4078 BT_LOGD("Serializing variant field type's field metadata: "
4080 "field-ft-addr=%p, field-name=\"%s\"",
4081 i
, field
, g_quark_to_string(field
->name
));
4083 g_string_assign(context
->field_name
,
4084 g_quark_to_string(field
->name
));
4085 for (indent
= 0; indent
< context
->current_indentation_level
;
4087 g_string_append_c(context
->string
, '\t');
4090 g_string_assign(context
->field_name
,
4091 g_quark_to_string(field
->name
));
4092 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4094 BT_LOGW("Cannot serialize variant field type's field's metadata: "
4096 "field-ft-addr=%p, field-name=\"%s\"",
4098 g_quark_to_string(field
->name
));
4102 if (context
->field_name
->len
) {
4103 g_string_append_printf(context
->string
, " %s;",
4104 context
->field_name
->str
);
4107 g_string_append_c(context
->string
, '\n');
4110 context
->current_indentation_level
--;
4111 for (indent
= 0; indent
< context
->current_indentation_level
;
4113 g_string_append_c(context
->string
, '\t');
4116 g_string_append(context
->string
, "}");
4118 g_string_free(context
->field_name
, TRUE
);
4119 context
->field_name
= variant_field_name
;
4124 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*type
,
4125 struct metadata_context
*context
)
4128 struct bt_ctf_field_type_array
*array
= container_of(type
,
4129 struct bt_ctf_field_type_array
, parent
);
4131 BT_LOGD("Serializing array field type's metadata: "
4132 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4133 BT_LOGD_STR("Serializing array field type's element field type's metadata.");
4134 ret
= bt_ctf_field_type_serialize(array
->element_type
, context
);
4136 BT_LOGW("Cannot serialize array field type's element field type's metadata: "
4137 "element-ft-addr=%p", array
->element_type
);
4141 if (context
->field_name
->len
) {
4142 g_string_append_printf(context
->string
, " %s[%u]",
4143 context
->field_name
->str
, array
->length
);
4144 g_string_assign(context
->field_name
, "");
4146 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4153 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*type
,
4154 struct metadata_context
*context
)
4157 struct bt_ctf_field_type_sequence
*sequence
= container_of(
4158 type
, struct bt_ctf_field_type_sequence
, parent
);
4160 BT_LOGD("Serializing sequence field type's metadata: "
4161 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4162 BT_LOGD_STR("Serializing sequence field type's element field type's metadata.");
4163 ret
= bt_ctf_field_type_serialize(sequence
->element_type
, context
);
4165 BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
4166 "element-ft-addr=%p", sequence
->element_type
);
4170 if (context
->field_name
->len
) {
4171 g_string_append_printf(context
->string
, " %s[%s]",
4172 context
->field_name
->str
,
4173 sequence
->length_field_name
->str
);
4174 g_string_assign(context
->field_name
, "");
4176 g_string_append_printf(context
->string
, "[%s]",
4177 sequence
->length_field_name
->str
);
4184 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*type
,
4185 struct metadata_context
*context
)
4187 struct bt_ctf_field_type_string
*string
= container_of(
4188 type
, struct bt_ctf_field_type_string
, parent
);
4190 BT_LOGD("Serializing string field type's metadata: "
4191 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4192 g_string_append_printf(context
->string
,
4193 "string { encoding = %s; }",
4194 get_encoding_string(string
->encoding
));
4199 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*type
,
4200 enum bt_ctf_byte_order byte_order
)
4202 struct bt_ctf_field_type_integer
*integer_type
= container_of(type
,
4203 struct bt_ctf_field_type_integer
, parent
);
4205 integer_type
->user_byte_order
= byte_order
;
4209 void bt_ctf_field_type_enumeration_set_byte_order(
4210 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4212 struct bt_ctf_field_type_enumeration
*enum_type
= container_of(type
,
4213 struct bt_ctf_field_type_enumeration
, parent
);
4215 /* Safe to assume that container is an integer */
4216 bt_ctf_field_type_integer_set_byte_order(enum_type
->container
,
4221 void bt_ctf_field_type_floating_point_set_byte_order(
4222 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4224 struct bt_ctf_field_type_floating_point
*floating_point_type
=
4225 container_of(type
, struct bt_ctf_field_type_floating_point
,
4228 floating_point_type
->user_byte_order
= byte_order
;
4232 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*type
,
4233 enum bt_ctf_byte_order byte_order
)
4236 struct bt_ctf_field_type_structure
*structure_type
=
4237 container_of(type
, struct bt_ctf_field_type_structure
,
4240 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
4241 struct structure_field
*field
= g_ptr_array_index(
4242 structure_type
->fields
, i
);
4243 struct bt_ctf_field_type
*field_type
= field
->type
;
4245 if (set_byte_order_funcs
[field_type
->id
]) {
4246 set_byte_order_funcs
[field_type
->id
](
4247 field_type
, byte_order
);
4253 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*type
,
4254 enum bt_ctf_byte_order byte_order
)
4257 struct bt_ctf_field_type_variant
*variant_type
=
4258 container_of(type
, struct bt_ctf_field_type_variant
,
4261 for (i
= 0; i
< variant_type
->fields
->len
; i
++) {
4262 struct structure_field
*field
= g_ptr_array_index(
4263 variant_type
->fields
, i
);
4264 struct bt_ctf_field_type
*field_type
= field
->type
;
4266 if (set_byte_order_funcs
[field_type
->id
]) {
4267 set_byte_order_funcs
[field_type
->id
](
4268 field_type
, byte_order
);
4274 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*type
,
4275 enum bt_ctf_byte_order byte_order
)
4277 struct bt_ctf_field_type_array
*array_type
=
4278 container_of(type
, struct bt_ctf_field_type_array
,
4281 if (set_byte_order_funcs
[array_type
->element_type
->id
]) {
4282 set_byte_order_funcs
[array_type
->element_type
->id
](
4283 array_type
->element_type
, byte_order
);
4288 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*type
,
4289 enum bt_ctf_byte_order byte_order
)
4291 struct bt_ctf_field_type_sequence
*sequence_type
=
4292 container_of(type
, struct bt_ctf_field_type_sequence
,
4295 if (set_byte_order_funcs
[
4296 sequence_type
->element_type
->id
]) {
4297 set_byte_order_funcs
[
4298 sequence_type
->element_type
->id
](
4299 sequence_type
->element_type
, byte_order
);
4304 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4305 struct bt_ctf_field_type
*type
)
4307 struct bt_ctf_field_type
*copy
;
4308 struct bt_ctf_field_type_integer
*integer
, *copy_integer
;
4310 BT_LOGD("Copying integer field type's: addr=%p", type
);
4311 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
4312 copy
= bt_ctf_field_type_integer_create(integer
->size
);
4314 BT_LOGE_STR("Cannot create integer field type.");
4318 copy_integer
= container_of(copy
, struct bt_ctf_field_type_integer
,
4320 copy_integer
->mapped_clock
= bt_get(integer
->mapped_clock
);
4321 copy_integer
->user_byte_order
= integer
->user_byte_order
;
4322 copy_integer
->is_signed
= integer
->is_signed
;
4323 copy_integer
->size
= integer
->size
;
4324 copy_integer
->base
= integer
->base
;
4325 copy_integer
->encoding
= integer
->encoding
;
4326 BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4334 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
4335 struct bt_ctf_field_type
*type
)
4338 struct bt_ctf_field_type
*copy
= NULL
, *copy_container
;
4339 struct bt_ctf_field_type_enumeration
*enumeration
, *copy_enumeration
;
4341 BT_LOGD("Copying enumeration field type's: addr=%p", type
);
4342 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
4345 /* Copy the source enumeration's container */
4346 BT_LOGD_STR("Copying enumeration field type's container field type.");
4347 copy_container
= bt_ctf_field_type_copy(enumeration
->container
);
4348 if (!copy_container
) {
4349 BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
4353 copy
= bt_ctf_field_type_enumeration_create(copy_container
);
4355 BT_LOGE_STR("Cannot create enumeration field type.");
4358 copy_enumeration
= container_of(copy
,
4359 struct bt_ctf_field_type_enumeration
, parent
);
4361 /* Copy all enumaration entries */
4362 for (i
= 0; i
< enumeration
->entries
->len
; i
++) {
4363 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4364 enumeration
->entries
, i
);
4365 struct enumeration_mapping
*copy_mapping
= g_new0(
4366 struct enumeration_mapping
, 1);
4368 if (!copy_mapping
) {
4369 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4373 *copy_mapping
= *mapping
;
4374 g_ptr_array_add(copy_enumeration
->entries
, copy_mapping
);
4377 BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4381 bt_put(copy_container
);
4384 bt_put(copy_container
);
4390 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4391 struct bt_ctf_field_type
*type
)
4393 struct bt_ctf_field_type
*copy
;
4394 struct bt_ctf_field_type_floating_point
*floating_point
, *copy_float
;
4396 BT_LOGD("Copying floating point number field type's: addr=%p", type
);
4397 floating_point
= container_of(type
,
4398 struct bt_ctf_field_type_floating_point
, parent
);
4399 copy
= bt_ctf_field_type_floating_point_create();
4401 BT_LOGE_STR("Cannot create floating point number field type.");
4405 copy_float
= container_of(copy
,
4406 struct bt_ctf_field_type_floating_point
, parent
);
4407 copy_float
->user_byte_order
= floating_point
->user_byte_order
;
4408 copy_float
->exp_dig
= floating_point
->exp_dig
;
4409 copy_float
->mant_dig
= floating_point
->mant_dig
;
4410 BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4417 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
4418 struct bt_ctf_field_type
*type
)
4421 GHashTableIter iter
;
4422 gpointer key
, value
;
4423 struct bt_ctf_field_type
*copy
;
4424 struct bt_ctf_field_type_structure
*structure
, *copy_structure
;
4426 BT_LOGD("Copying structure field type's: addr=%p", type
);
4427 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
4429 copy
= bt_ctf_field_type_structure_create();
4431 BT_LOGE_STR("Cannot create structure field type.");
4435 copy_structure
= container_of(copy
,
4436 struct bt_ctf_field_type_structure
, parent
);
4438 /* Copy field_name_to_index */
4439 g_hash_table_iter_init(&iter
, structure
->field_name_to_index
);
4440 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4441 g_hash_table_insert(copy_structure
->field_name_to_index
,
4445 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4446 struct structure_field
*entry
, *copy_entry
;
4447 struct bt_ctf_field_type
*copy_field
;
4449 entry
= g_ptr_array_index(structure
->fields
, i
);
4450 BT_LOGD("Copying structure field type's field: "
4451 "index=%" PRId64
", "
4452 "field-ft-addr=%p, field-name=\"%s\"",
4453 i
, entry
, g_quark_to_string(entry
->name
));
4454 copy_entry
= g_new0(struct structure_field
, 1);
4456 BT_LOGE_STR("Failed to allocate one structure field type field.");
4460 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4462 BT_LOGE("Cannot copy structure field type's field: "
4463 "index=%" PRId64
", "
4464 "field-ft-addr=%p, field-name=\"%s\"",
4465 i
, entry
, g_quark_to_string(entry
->name
));
4470 copy_entry
->name
= entry
->name
;
4471 copy_entry
->type
= copy_field
;
4472 g_ptr_array_add(copy_structure
->fields
, copy_entry
);
4475 BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4486 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
4487 struct bt_ctf_field_type
*type
)
4490 GHashTableIter iter
;
4491 gpointer key
, value
;
4492 struct bt_ctf_field_type
*copy
= NULL
, *copy_tag
= NULL
;
4493 struct bt_ctf_field_type_variant
*variant
, *copy_variant
;
4495 BT_LOGD("Copying variant field type's: addr=%p", type
);
4496 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
4499 BT_LOGD_STR("Copying variant field type's tag field type.");
4500 copy_tag
= bt_ctf_field_type_copy(&variant
->tag
->parent
);
4502 BT_LOGE_STR("Cannot copy variant field type's tag field type.");
4507 copy
= bt_ctf_field_type_variant_create(copy_tag
,
4508 variant
->tag_name
->len
? variant
->tag_name
->str
: NULL
);
4510 BT_LOGE_STR("Cannot create variant field type.");
4514 copy_variant
= container_of(copy
, struct bt_ctf_field_type_variant
,
4517 /* Copy field_name_to_index */
4518 g_hash_table_iter_init(&iter
, variant
->field_name_to_index
);
4519 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4520 g_hash_table_insert(copy_variant
->field_name_to_index
,
4524 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4525 struct structure_field
*entry
, *copy_entry
;
4526 struct bt_ctf_field_type
*copy_field
;
4528 entry
= g_ptr_array_index(variant
->fields
, i
);
4529 BT_LOGD("Copying variant field type's field: "
4530 "index=%" PRId64
", "
4531 "field-ft-addr=%p, field-name=\"%s\"",
4532 i
, entry
, g_quark_to_string(entry
->name
));
4533 copy_entry
= g_new0(struct structure_field
, 1);
4535 BT_LOGE_STR("Failed to allocate one variant field type field.");
4539 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4541 BT_LOGE("Cannot copy variant field type's field: "
4542 "index=%" PRId64
", "
4543 "field-ft-addr=%p, field-name=\"%s\"",
4544 i
, entry
, g_quark_to_string(entry
->name
));
4549 copy_entry
->name
= entry
->name
;
4550 copy_entry
->type
= copy_field
;
4551 g_ptr_array_add(copy_variant
->fields
, copy_entry
);
4554 if (variant
->tag_field_path
) {
4555 BT_LOGD_STR("Copying variant field type's tag field path.");
4556 copy_variant
->tag_field_path
= bt_ctf_field_path_copy(
4557 variant
->tag_field_path
);
4558 if (!copy_variant
->tag_field_path
) {
4559 BT_LOGE_STR("Cannot copy variant field type's tag field path.");
4564 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4577 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
4578 struct bt_ctf_field_type
*type
)
4580 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4581 struct bt_ctf_field_type_array
*array
;
4583 BT_LOGD("Copying array field type's: addr=%p", type
);
4584 array
= container_of(type
, struct bt_ctf_field_type_array
,
4586 BT_LOGD_STR("Copying array field type's element field type.");
4587 copy_element
= bt_ctf_field_type_copy(array
->element_type
);
4588 if (!copy_element
) {
4589 BT_LOGE_STR("Cannot copy array field type's element field type.");
4593 copy
= bt_ctf_field_type_array_create(copy_element
, array
->length
);
4595 BT_LOGE_STR("Cannot create array field type.");
4599 BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
4603 bt_put(copy_element
);
4608 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
4609 struct bt_ctf_field_type
*type
)
4611 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4612 struct bt_ctf_field_type_sequence
*sequence
, *copy_sequence
;
4614 BT_LOGD("Copying sequence field type's: addr=%p", type
);
4615 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
4617 BT_LOGD_STR("Copying sequence field type's element field type.");
4618 copy_element
= bt_ctf_field_type_copy(sequence
->element_type
);
4619 if (!copy_element
) {
4620 BT_LOGE_STR("Cannot copy sequence field type's element field type.");
4624 copy
= bt_ctf_field_type_sequence_create(copy_element
,
4625 sequence
->length_field_name
->len
?
4626 sequence
->length_field_name
->str
: NULL
);
4628 BT_LOGE_STR("Cannot create sequence field type.");
4632 copy_sequence
= container_of(copy
, struct bt_ctf_field_type_sequence
,
4634 if (sequence
->length_field_path
) {
4635 BT_LOGD_STR("Copying sequence field type's length field path.");
4636 copy_sequence
->length_field_path
= bt_ctf_field_path_copy(
4637 sequence
->length_field_path
);
4638 if (!copy_sequence
->length_field_path
) {
4639 BT_LOGE_STR("Cannot copy sequence field type's length field path.");
4644 BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4648 bt_put(copy_element
);
4656 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4657 struct bt_ctf_field_type
*type
)
4659 struct bt_ctf_field_type
*copy
;
4661 BT_LOGD("Copying string field type's: addr=%p", type
);
4662 copy
= bt_ctf_field_type_string_create();
4664 BT_LOGE_STR("Cannot create string field type.");
4668 BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
4675 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*type_a
,
4676 struct bt_ctf_field_type
*type_b
)
4679 struct bt_ctf_field_type_integer
*int_type_a
;
4680 struct bt_ctf_field_type_integer
*int_type_b
;
4682 int_type_a
= container_of(type_a
, struct bt_ctf_field_type_integer
,
4684 int_type_b
= container_of(type_b
, struct bt_ctf_field_type_integer
,
4688 if (int_type_a
->size
!= int_type_b
->size
) {
4689 BT_LOGV("Integer field types differ: different sizes: "
4690 "ft-a-size=%u, ft-b-size=%u",
4691 int_type_a
->size
, int_type_b
->size
);
4696 if (int_type_a
->user_byte_order
!= int_type_b
->user_byte_order
) {
4697 BT_LOGV("Integer field types differ: different byte orders: "
4698 "ft-a-bo=%s, ft-b-bo=%s",
4699 bt_ctf_byte_order_string(int_type_a
->user_byte_order
),
4700 bt_ctf_byte_order_string(int_type_b
->user_byte_order
));
4705 if (int_type_a
->is_signed
!= int_type_b
->is_signed
) {
4706 BT_LOGV("Integer field types differ: different signedness: "
4707 "ft-a-is-signed=%d, ft-b-is-signed=%d",
4708 int_type_a
->is_signed
,
4709 int_type_b
->is_signed
);
4714 if (int_type_a
->base
!= int_type_b
->base
) {
4715 BT_LOGV("Integer field types differ: different bases: "
4716 "ft-a-base=%s, ft-b-base=%s",
4717 bt_ctf_integer_base_string(int_type_a
->base
),
4718 bt_ctf_integer_base_string(int_type_b
->base
));
4723 if (int_type_a
->encoding
!= int_type_b
->encoding
) {
4724 BT_LOGV("Integer field types differ: different encodings: "
4725 "ft-a-encoding=%s, ft-b-encoding=%s",
4726 bt_ctf_string_encoding_string(int_type_a
->encoding
),
4727 bt_ctf_string_encoding_string(int_type_b
->encoding
));
4732 if (int_type_a
->mapped_clock
!= int_type_b
->mapped_clock
) {
4733 BT_LOGV("Integer field types differ: different mapped clock classes: "
4734 "ft-a-mapped-clock-class-addr=%p, "
4735 "ft-b-mapped-clock-class-addr=%p, "
4736 "ft-a-mapped-clock-class-name=\"%s\", "
4737 "ft-b-mapped-clock-class-name=\"%s\"",
4738 int_type_a
->mapped_clock
, int_type_b
->mapped_clock
,
4739 int_type_a
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_a
->mapped_clock
) : "",
4740 int_type_b
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_b
->mapped_clock
) : "");
4752 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*type_a
,
4753 struct bt_ctf_field_type
*type_b
)
4756 struct bt_ctf_field_type_floating_point
*float_a
;
4757 struct bt_ctf_field_type_floating_point
*float_b
;
4759 float_a
= container_of(type_a
,
4760 struct bt_ctf_field_type_floating_point
, parent
);
4761 float_b
= container_of(type_b
,
4762 struct bt_ctf_field_type_floating_point
, parent
);
4765 if (float_a
->user_byte_order
!= float_b
->user_byte_order
) {
4766 BT_LOGV("Floating point number field types differ: different byte orders: "
4767 "ft-a-bo=%s, ft-b-bo=%s",
4768 bt_ctf_byte_order_string(float_a
->user_byte_order
),
4769 bt_ctf_byte_order_string(float_b
->user_byte_order
));
4773 /* Exponent length */
4774 if (float_a
->exp_dig
!= float_b
->exp_dig
) {
4775 BT_LOGV("Floating point number field types differ: different exponent sizes: "
4776 "ft-a-exp-size=%u, ft-b-exp-size=%u",
4777 float_a
->exp_dig
, float_b
->exp_dig
);
4781 /* Mantissa length */
4782 if (float_a
->mant_dig
!= float_b
->mant_dig
) {
4783 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
4784 "ft-a-mant-size=%u, ft-b-mant-size=%u",
4785 float_a
->mant_dig
, float_b
->mant_dig
);
4797 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
4798 struct enumeration_mapping
*mapping_b
)
4803 if (mapping_a
->string
!= mapping_b
->string
) {
4804 BT_LOGV("Enumeration field type mappings differ: different names: "
4805 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
4806 g_quark_to_string(mapping_a
->string
),
4807 g_quark_to_string(mapping_b
->string
));
4812 if (mapping_a
->range_start
._unsigned
!=
4813 mapping_b
->range_start
._unsigned
) {
4814 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
4815 "mapping-a-range-start-unsigned=%" PRIu64
", "
4816 "mapping-b-range-start-unsigned=%" PRIu64
,
4817 mapping_a
->range_start
._unsigned
,
4818 mapping_b
->range_start
._unsigned
);
4823 if (mapping_a
->range_end
._unsigned
!=
4824 mapping_b
->range_end
._unsigned
) {
4825 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
4826 "mapping-a-range-end-unsigned=%" PRIu64
", "
4827 "mapping-b-range-end-unsigned=%" PRIu64
,
4828 mapping_a
->range_end
._unsigned
,
4829 mapping_b
->range_end
._unsigned
);
4841 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*type_a
,
4842 struct bt_ctf_field_type
*type_b
)
4846 struct bt_ctf_field_type_enumeration
*enum_a
;
4847 struct bt_ctf_field_type_enumeration
*enum_b
;
4849 enum_a
= container_of(type_a
,
4850 struct bt_ctf_field_type_enumeration
, parent
);
4851 enum_b
= container_of(type_b
,
4852 struct bt_ctf_field_type_enumeration
, parent
);
4854 /* Container field type */
4855 ret
= bt_ctf_field_type_compare(enum_a
->container
, enum_b
->container
);
4857 BT_LOGV("Enumeration field types differ: different container field types: "
4858 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
4859 enum_a
->container
, enum_b
->container
);
4866 if (enum_a
->entries
->len
!= enum_b
->entries
->len
) {
4870 for (i
= 0; i
< enum_a
->entries
->len
; ++i
) {
4871 struct enumeration_mapping
*mapping_a
=
4872 g_ptr_array_index(enum_a
->entries
, i
);
4873 struct enumeration_mapping
*mapping_b
=
4874 g_ptr_array_index(enum_b
->entries
, i
);
4876 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4877 BT_LOGV("Enumeration field types differ: different mappings: "
4878 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4879 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4880 mapping_a
, mapping_b
,
4881 g_quark_to_string(mapping_a
->string
),
4882 g_quark_to_string(mapping_b
->string
));
4895 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*type_a
,
4896 struct bt_ctf_field_type
*type_b
)
4899 struct bt_ctf_field_type_string
*string_a
;
4900 struct bt_ctf_field_type_string
*string_b
;
4902 string_a
= container_of(type_a
,
4903 struct bt_ctf_field_type_string
, parent
);
4904 string_b
= container_of(type_b
,
4905 struct bt_ctf_field_type_string
, parent
);
4908 if (string_a
->encoding
!= string_b
->encoding
) {
4909 BT_LOGV("String field types differ: different encodings: "
4910 "ft-a-encoding=%s, ft-b-encoding=%s",
4911 bt_ctf_string_encoding_string(string_a
->encoding
),
4912 bt_ctf_string_encoding_string(string_b
->encoding
));
4924 int compare_structure_fields(struct structure_field
*field_a
,
4925 struct structure_field
*field_b
)
4930 if (field_a
->name
!= field_b
->name
) {
4931 BT_LOGV("Structure/variant field type fields differ: different names: "
4932 "field-a-name=%s, field-b-name=%s",
4933 g_quark_to_string(field_a
->name
),
4934 g_quark_to_string(field_b
->name
));
4939 ret
= bt_ctf_field_type_compare(field_a
->type
, field_b
->type
);
4941 BT_LOGV("Structure/variant field type fields differ: different field types: "
4942 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
4943 g_quark_to_string(field_a
->name
),
4944 field_a
->type
, field_b
->type
);
4952 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*type_a
,
4953 struct bt_ctf_field_type
*type_b
)
4957 struct bt_ctf_field_type_structure
*struct_a
;
4958 struct bt_ctf_field_type_structure
*struct_b
;
4960 struct_a
= container_of(type_a
,
4961 struct bt_ctf_field_type_structure
, parent
);
4962 struct_b
= container_of(type_b
,
4963 struct bt_ctf_field_type_structure
, parent
);
4966 if (bt_ctf_field_type_get_alignment(type_a
) !=
4967 bt_ctf_field_type_get_alignment(type_b
)) {
4968 BT_LOGV("Structure field types differ: different alignments: "
4969 "ft-a-align=%u, ft-b-align=%u",
4970 bt_ctf_field_type_get_alignment(type_a
),
4971 bt_ctf_field_type_get_alignment(type_b
));
4976 if (struct_a
->fields
->len
!= struct_b
->fields
->len
) {
4977 BT_LOGV("Structure field types differ: different field counts: "
4978 "ft-a-field-count=%u, ft-b-field-count=%u",
4979 struct_a
->fields
->len
, struct_b
->fields
->len
);
4983 for (i
= 0; i
< struct_a
->fields
->len
; ++i
) {
4984 struct structure_field
*field_a
=
4985 g_ptr_array_index(struct_a
->fields
, i
);
4986 struct structure_field
*field_b
=
4987 g_ptr_array_index(struct_b
->fields
, i
);
4989 ret
= compare_structure_fields(field_a
, field_b
);
4991 /* compare_structure_fields() logs what differs */
4992 BT_LOGV_STR("Structure field types differ: different fields.");
5005 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*type_a
,
5006 struct bt_ctf_field_type
*type_b
)
5010 struct bt_ctf_field_type_variant
*variant_a
;
5011 struct bt_ctf_field_type_variant
*variant_b
;
5013 variant_a
= container_of(type_a
,
5014 struct bt_ctf_field_type_variant
, parent
);
5015 variant_b
= container_of(type_b
,
5016 struct bt_ctf_field_type_variant
, parent
);
5019 if (strcmp(variant_a
->tag_name
->str
, variant_b
->tag_name
->str
)) {
5020 BT_LOGV("Variant field types differ: different tag field names: "
5021 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
5022 variant_a
->tag_name
->str
, variant_b
->tag_name
->str
);
5027 ret
= bt_ctf_field_type_compare(
5028 (struct bt_ctf_field_type
*) variant_a
->tag
,
5029 (struct bt_ctf_field_type
*) variant_b
->tag
);
5031 BT_LOGV("Variant field types differ: different tag field types: "
5032 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
5033 variant_a
->tag
, variant_b
->tag
);
5040 if (variant_a
->fields
->len
!= variant_b
->fields
->len
) {
5041 BT_LOGV("Structure field types differ: different field counts: "
5042 "ft-a-field-count=%u, ft-b-field-count=%u",
5043 variant_a
->fields
->len
, variant_b
->fields
->len
);
5047 for (i
= 0; i
< variant_a
->fields
->len
; ++i
) {
5048 struct structure_field
*field_a
=
5049 g_ptr_array_index(variant_a
->fields
, i
);
5050 struct structure_field
*field_b
=
5051 g_ptr_array_index(variant_b
->fields
, i
);
5053 ret
= compare_structure_fields(field_a
, field_b
);
5055 /* compare_structure_fields() logs what differs */
5056 BT_LOGV_STR("Variant field types differ: different fields.");
5069 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*type_a
,
5070 struct bt_ctf_field_type
*type_b
)
5073 struct bt_ctf_field_type_array
*array_a
;
5074 struct bt_ctf_field_type_array
*array_b
;
5076 array_a
= container_of(type_a
,
5077 struct bt_ctf_field_type_array
, parent
);
5078 array_b
= container_of(type_b
,
5079 struct bt_ctf_field_type_array
, parent
);
5082 if (array_a
->length
!= array_b
->length
) {
5083 BT_LOGV("Structure field types differ: different lengths: "
5084 "ft-a-length=%u, ft-b-length=%u",
5085 array_a
->length
, array_b
->length
);
5090 ret
= bt_ctf_field_type_compare(array_a
->element_type
,
5091 array_b
->element_type
);
5093 BT_LOGV("Array field types differ: different element field types: "
5094 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5095 array_a
->element_type
, array_b
->element_type
);
5103 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*type_a
,
5104 struct bt_ctf_field_type
*type_b
)
5107 struct bt_ctf_field_type_sequence
*sequence_a
;
5108 struct bt_ctf_field_type_sequence
*sequence_b
;
5110 sequence_a
= container_of(type_a
,
5111 struct bt_ctf_field_type_sequence
, parent
);
5112 sequence_b
= container_of(type_b
,
5113 struct bt_ctf_field_type_sequence
, parent
);
5116 if (strcmp(sequence_a
->length_field_name
->str
,
5117 sequence_b
->length_field_name
->str
)) {
5118 BT_LOGV("Sequence field types differ: different length field names: "
5119 "ft-a-length-field-name=\"%s\", "
5120 "ft-b-length-field-name=\"%s\"",
5121 sequence_a
->length_field_name
->str
,
5122 sequence_b
->length_field_name
->str
);
5127 ret
= bt_ctf_field_type_compare(sequence_a
->element_type
,
5128 sequence_b
->element_type
);
5130 BT_LOGV("Sequence field types differ: different element field types: "
5131 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5132 sequence_a
->element_type
, sequence_b
->element_type
);
5139 int bt_ctf_field_type_compare(struct bt_ctf_field_type
*type_a
,
5140 struct bt_ctf_field_type
*type_b
)
5144 if (type_a
== type_b
) {
5145 /* Same reference: equal (even if both are NULL) */
5151 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
5157 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
5162 if (type_a
->id
!= type_b
->id
) {
5163 /* Different type IDs */
5164 BT_LOGV("Field types differ: different IDs: "
5165 "ft-a-addr=%p, ft-b-addr=%p, "
5166 "ft-a-id=%s, ft-b-id=%s",
5168 bt_ctf_field_type_id_string(type_a
->id
),
5169 bt_ctf_field_type_id_string(type_b
->id
));
5173 if (type_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
5174 /* Both have unknown type IDs */
5175 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
5179 ret
= type_compare_funcs
[type_a
->id
](type_a
, type_b
);
5181 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
5190 int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*field_type
)
5192 int64_t field_count
= -1;
5193 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5196 case CTF_TYPE_STRUCT
:
5198 bt_ctf_field_type_structure_get_field_count(field_type
);
5200 case CTF_TYPE_VARIANT
:
5202 bt_ctf_field_type_variant_get_field_count(field_type
);
5204 case CTF_TYPE_ARRAY
:
5205 case CTF_TYPE_SEQUENCE
:
5207 * Array and sequence types always contain a single member
5208 * (the element type).
5220 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
5221 struct bt_ctf_field_type
*field_type
, int index
)
5223 struct bt_ctf_field_type
*field
= NULL
;
5224 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5227 case CTF_TYPE_STRUCT
:
5229 int ret
= bt_ctf_field_type_structure_get_field_by_index(
5230 field_type
, NULL
, &field
, index
);
5237 case CTF_TYPE_VARIANT
:
5239 int ret
= bt_ctf_field_type_variant_get_field_by_index(
5240 field_type
, NULL
, &field
, index
);
5247 case CTF_TYPE_ARRAY
:
5248 field
= bt_ctf_field_type_array_get_element_type(field_type
);
5250 case CTF_TYPE_SEQUENCE
:
5251 field
= bt_ctf_field_type_sequence_get_element_type(field_type
);
5261 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*field_type
,
5264 int field_index
= -1;
5265 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5268 case CTF_TYPE_STRUCT
:
5269 field_index
= bt_ctf_field_type_structure_get_field_name_index(
5272 case CTF_TYPE_VARIANT
:
5273 field_index
= bt_ctf_field_type_variant_get_field_name_index(
5283 struct bt_ctf_field_path
*bt_ctf_field_type_variant_get_tag_field_path(
5284 struct bt_ctf_field_type
*type
)
5286 struct bt_ctf_field_path
*field_path
= NULL
;
5287 struct bt_ctf_field_type_variant
*variant
;
5290 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5294 if (!bt_ctf_field_type_is_variant(type
)) {
5295 BT_LOGW("Invalid parameter: field type is not a variant field type: "
5296 "addr=%p, ft-id=%s", type
,
5297 bt_ctf_field_type_id_string(type
->id
));
5301 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
5303 field_path
= bt_get(variant
->tag_field_path
);
5308 struct bt_ctf_field_path
*bt_ctf_field_type_sequence_get_length_field_path(
5309 struct bt_ctf_field_type
*type
)
5311 struct bt_ctf_field_path
*field_path
= NULL
;
5312 struct bt_ctf_field_type_sequence
*sequence
;
5315 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5319 if (!bt_ctf_field_type_is_sequence(type
)) {
5320 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
5321 "addr=%p, ft-id=%s", type
,
5322 bt_ctf_field_type_id_string(type
->id
));
5326 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
5328 field_path
= bt_get(sequence
->length_field_path
);