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
)
314 void check_ranges_overlap(gpointer element
, gpointer query
)
316 struct enumeration_mapping
*mapping
= element
;
317 struct range_overlap_query
*overlap_query
= query
;
319 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
320 && overlap_query
->range_start
._signed
<=
321 mapping
->range_end
._signed
) {
322 overlap_query
->overlaps
= 1;
323 overlap_query
->mapping_name
= mapping
->string
;
326 overlap_query
->overlaps
|=
327 mapping
->string
== overlap_query
->mapping_name
;
329 if (overlap_query
->overlaps
) {
330 BT_LOGV("Overlapping enumeration field type mappings: "
331 "mapping-name=\"%s\", "
332 "mapping-a-range-start=%" PRId64
", "
333 "mapping-a-range-end=%" PRId64
", "
334 "mapping-b-range-start=%" PRId64
", "
335 "mapping-b-range-end=%" PRId64
,
336 g_quark_to_string(mapping
->string
),
337 mapping
->range_start
._signed
,
338 mapping
->range_end
._signed
,
339 overlap_query
->range_start
._signed
,
340 overlap_query
->range_end
._signed
);
345 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
347 struct enumeration_mapping
*mapping
= element
;
348 struct range_overlap_query
*overlap_query
= query
;
350 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
351 && overlap_query
->range_start
._unsigned
<=
352 mapping
->range_end
._unsigned
) {
353 overlap_query
->overlaps
= 1;
354 overlap_query
->mapping_name
= mapping
->string
;
357 overlap_query
->overlaps
|=
358 mapping
->string
== overlap_query
->mapping_name
;
360 if (overlap_query
->overlaps
) {
361 BT_LOGW("Overlapping enumeration field type mappings: "
362 "mapping-name=\"%s\", "
363 "mapping-a-range-start=%" PRIu64
", "
364 "mapping-a-range-end=%" PRIu64
", "
365 "mapping-b-range-start=%" PRIu64
", "
366 "mapping-b-range-end=%" PRIu64
,
367 g_quark_to_string(mapping
->string
),
368 mapping
->range_start
._unsigned
,
369 mapping
->range_end
._unsigned
,
370 overlap_query
->range_start
._unsigned
,
371 overlap_query
->range_end
._unsigned
);
376 gint
compare_enumeration_mappings_signed(struct enumeration_mapping
**a
,
377 struct enumeration_mapping
**b
)
379 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
383 gint
compare_enumeration_mappings_unsigned(struct enumeration_mapping
**a
,
384 struct enumeration_mapping
**b
)
386 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
390 void bt_ctf_field_type_init(struct bt_ctf_field_type
*type
, bt_bool init_bo
)
392 assert(type
&& (type
->id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
) &&
393 (type
->id
< BT_CTF_NR_TYPE_IDS
));
395 bt_object_init(type
, bt_ctf_field_type_destroy
);
396 type
->freeze
= type_freeze_funcs
[type
->id
];
397 type
->serialize
= type_serialize_funcs
[type
->id
];
400 int ret
= bt_ctf_field_type_set_byte_order(type
,
401 BT_CTF_BYTE_ORDER_NATIVE
);
409 int add_structure_field(GPtrArray
*fields
,
410 GHashTable
*field_name_to_index
,
411 struct bt_ctf_field_type
*field_type
,
412 const char *field_name
)
415 GQuark name_quark
= g_quark_from_string(field_name
);
416 struct structure_field
*field
;
418 /* Make sure structure does not contain a field of the same name */
419 if (g_hash_table_lookup_extended(field_name_to_index
,
420 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
421 BT_LOGW("Structure or variant field type already contains a field type with this name: "
422 "field-name=\"%s\"", field_name
);
427 field
= g_new0(struct structure_field
, 1);
429 BT_LOGE_STR("Failed to allocate one structure/variant field type field.");
435 field
->name
= name_quark
;
436 field
->type
= field_type
;
437 g_hash_table_insert(field_name_to_index
,
438 GUINT_TO_POINTER(name_quark
),
439 GUINT_TO_POINTER(fields
->len
));
440 g_ptr_array_add(fields
, field
);
446 void bt_ctf_field_type_destroy(struct bt_object
*obj
)
448 struct bt_ctf_field_type
*type
;
449 enum bt_ctf_field_type_id type_id
;
451 BT_LOGD("Destroying field type object: addr=%p", obj
);
452 type
= container_of(obj
, struct bt_ctf_field_type
, base
);
454 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
||
455 type_id
>= BT_CTF_NR_TYPE_IDS
) {
456 BT_LOGW("Unknown field type ID: addr=%p, id=%d", obj
, type_id
);
460 type_destroy_funcs
[type_id
](type
);
464 int bt_ctf_field_type_integer_validate(struct bt_ctf_field_type
*type
)
468 struct bt_ctf_field_type_integer
*integer
=
469 container_of(type
, struct bt_ctf_field_type_integer
,
472 if (integer
->mapped_clock
&& integer
->is_signed
) {
473 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
474 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
475 type
, integer
->mapped_clock
,
476 bt_ctf_clock_class_get_name(integer
->mapped_clock
));
486 struct enumeration_mapping
*get_enumeration_mapping(
487 struct bt_ctf_field_type
*type
, uint64_t index
)
489 struct enumeration_mapping
*mapping
= NULL
;
490 struct bt_ctf_field_type_enumeration
*enumeration
;
492 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
494 if (index
>= enumeration
->entries
->len
) {
495 BT_LOGW("Invalid parameter: index is out of bounds: "
496 "addr=%p, index=%" PRIu64
", count=%u",
497 type
, index
, enumeration
->entries
->len
);
501 mapping
= g_ptr_array_index(enumeration
->entries
, index
);
507 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
508 * Only used when freezing an enumeration.
511 void set_enumeration_range_overlap(
512 struct bt_ctf_field_type
*type
)
515 struct bt_ctf_field_type
*container_type
;
516 struct bt_ctf_field_type_enumeration
*enumeration_type
;
519 BT_LOGV("Setting enumeration field type's overlap flag: addr=%p",
521 enumeration_type
= container_of(type
,
522 struct bt_ctf_field_type_enumeration
, parent
);
524 len
= enumeration_type
->entries
->len
;
525 container_type
= enumeration_type
->container
;
526 is_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
528 for (i
= 0; i
< len
; i
++) {
529 for (j
= i
+ 1; j
< len
; j
++) {
530 struct enumeration_mapping
*mapping
[2];
532 mapping
[0] = get_enumeration_mapping(type
, i
);
533 mapping
[1] = get_enumeration_mapping(type
, j
);
535 if (mapping
[0]->range_start
._signed
536 <= mapping
[1]->range_end
._signed
537 && mapping
[0]->range_end
._signed
538 >= mapping
[1]->range_start
._signed
) {
539 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
543 if (mapping
[0]->range_start
._unsigned
544 <= mapping
[1]->range_end
._unsigned
545 && mapping
[0]->range_end
._unsigned
546 >= mapping
[1]->range_start
._unsigned
) {
547 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
556 int bt_ctf_field_type_enumeration_validate(struct bt_ctf_field_type
*type
)
560 struct bt_ctf_field_type_enumeration
*enumeration
=
561 container_of(type
, struct bt_ctf_field_type_enumeration
,
563 struct bt_ctf_field_type
*container_type
=
564 bt_ctf_field_type_enumeration_get_container_type(type
);
566 assert(container_type
);
567 ret
= bt_ctf_field_type_validate(container_type
);
569 BT_LOGW("Invalid enumeration field type: container type is invalid: "
570 "enum-ft-addr=%p, int-ft-addr=%p",
571 type
, container_type
);
575 /* Ensure enum has entries */
576 if (enumeration
->entries
->len
== 0) {
577 BT_LOGW("Invalid enumeration field type: no entries: "
584 BT_PUT(container_type
);
589 int bt_ctf_field_type_sequence_validate(struct bt_ctf_field_type
*type
)
592 struct bt_ctf_field_type
*element_type
= NULL
;
593 struct bt_ctf_field_type_sequence
*sequence
=
594 container_of(type
, struct bt_ctf_field_type_sequence
,
597 /* Length field name should be set at this point */
598 if (sequence
->length_field_name
->len
== 0) {
599 BT_LOGW("Invalid sequence field type: no length field name: "
605 element_type
= bt_ctf_field_type_sequence_get_element_type(type
);
606 assert(element_type
);
607 ret
= bt_ctf_field_type_validate(element_type
);
609 BT_LOGW("Invalid sequence field type: invalid element field type: "
610 "seq-ft-addr=%p, element-ft-add=%p",
615 BT_PUT(element_type
);
621 int bt_ctf_field_type_array_validate(struct bt_ctf_field_type
*type
)
624 struct bt_ctf_field_type
*element_type
= NULL
;
626 element_type
= bt_ctf_field_type_array_get_element_type(type
);
627 assert(element_type
);
628 ret
= bt_ctf_field_type_validate(element_type
);
630 BT_LOGW("Invalid array field type: invalid element field type: "
631 "array-ft-addr=%p, element-ft-add=%p",
635 BT_PUT(element_type
);
640 int bt_ctf_field_type_structure_validate(struct bt_ctf_field_type
*type
)
643 struct bt_ctf_field_type
*child_type
= NULL
;
644 int64_t field_count
= bt_ctf_field_type_structure_get_field_count(type
);
647 assert(field_count
>= 0);
649 for (i
= 0; i
< field_count
; ++i
) {
650 const char *field_name
;
652 ret
= bt_ctf_field_type_structure_get_field_by_index(type
,
653 &field_name
, &child_type
, i
);
655 ret
= bt_ctf_field_type_validate(child_type
);
657 BT_LOGW("Invalid structure field type: "
658 "a contained field type is invalid: "
659 "struct-ft-addr=%p, field-ft-addr=%p, "
660 "field-name=\"%s\", field-index=%" PRId64
,
661 type
, child_type
, field_name
, i
);
675 bt_bool
bt_ctf_field_type_enumeration_has_overlapping_ranges(
676 struct bt_ctf_field_type_enumeration
*enumeration_type
)
678 if (!enumeration_type
->parent
.frozen
) {
679 set_enumeration_range_overlap(&enumeration_type
->parent
);
681 return enumeration_type
->has_overlapping_ranges
;
685 int bt_ctf_field_type_enumeration_get_mapping_name(
686 struct bt_ctf_field_type
*enum_field_type
,
688 const char **mapping_name
)
691 struct enumeration_mapping
*mapping
;
693 assert(enum_field_type
);
694 mapping
= get_enumeration_mapping(enum_field_type
, index
);
697 *mapping_name
= g_quark_to_string(mapping
->string
);
704 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type
*type
)
708 struct bt_ctf_field_type
*child_type
= NULL
;
709 struct bt_ctf_field_type_variant
*variant
=
710 container_of(type
, struct bt_ctf_field_type_variant
,
713 int64_t tag_mappings_count
;
715 if (variant
->tag_name
->len
== 0) {
716 BT_LOGW("Invalid variant field type: no tag field name: "
723 BT_LOGW("Invalid variant field type: no tag field type: "
724 "addr=%p, tag-field-name=\"%s\"", type
,
725 variant
->tag_name
->str
);
730 if (bt_ctf_field_type_enumeration_has_overlapping_ranges(
732 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
733 "variant-ft-addr=%p, tag-field-name=\"%s\", "
734 "enum-ft-addr=%p", type
, variant
->tag_name
->str
,
741 bt_ctf_field_type_enumeration_get_mapping_count(
742 (struct bt_ctf_field_type
*) variant
->tag
);
745 * Validate that each mapping found in the tag has a name which
746 * is also the name of a field in this variant field type.
748 * The opposite is accepted: variant FT fields which cannot be
749 * selected because the variant FT tag has no mapping named as
750 * such. This scenario, while not ideal, cannot cause any error.
752 for (i
= 0; i
< tag_mappings_count
; ++i
) {
754 struct bt_ctf_field_type
*ft
;
756 ret
= bt_ctf_field_type_enumeration_get_mapping_name(
757 (struct bt_ctf_field_type
*) variant
->tag
,
761 ft
= bt_ctf_field_type_variant_get_field_type_by_name(
764 BT_LOGW("Invalid variant field type: "
765 "enumeration tag field type contains a mapping which does not name a variant field type field: "
766 "variant-ft-addr=%p, tag-field-name=\"%s\", "
767 "enum-ft-addr=%p, mapping-name=\"%s\"",
768 type
, variant
->tag_name
->str
, variant
->tag
,
777 field_count
= bt_ctf_field_type_variant_get_field_count(type
);
778 if (field_count
< 0) {
779 BT_LOGW("Invalid variant field type: no fields: "
780 "addr=%p, tag-field-name=\"%s\"",
781 type
, variant
->tag_name
->str
);
786 for (i
= 0; i
< field_count
; ++i
) {
787 const char *field_name
;
789 ret
= bt_ctf_field_type_variant_get_field_by_index(type
,
790 &field_name
, &child_type
, i
);
792 ret
= bt_ctf_field_type_validate(child_type
);
794 BT_LOGW("Invalid variant field type: "
795 "a contained field type is invalid: "
796 "variant-ft-addr=%p, tag-field-name=\"%s\", "
797 "field-ft-addr=%p, field-name=\"%s\", "
798 "field-index=%" PRId64
,
799 type
, variant
->tag_name
->str
, child_type
,
814 * This function validates a given field type without considering
815 * where this field type is located. It only validates the properties
816 * of the given field type and the properties of its children if
820 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
)
823 enum bt_ctf_field_type_id id
= bt_ctf_field_type_get_type_id(type
);
828 /* Already marked as valid */
832 if (type_validate_funcs
[id
]) {
833 ret
= type_validate_funcs
[id
](type
);
836 if (!ret
&& type
->frozen
) {
837 /* Field type is valid */
845 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
847 struct bt_ctf_field_type_integer
*integer
=
848 g_new0(struct bt_ctf_field_type_integer
, 1);
850 BT_LOGD("Creating integer field type object: size=%u", size
);
853 BT_LOGE_STR("Failed to allocate one integer field type.");
857 if (size
== 0 || size
> 64) {
858 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
863 integer
->parent
.id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
864 integer
->size
= size
;
865 integer
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
866 integer
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
867 bt_ctf_field_type_init(&integer
->parent
, TRUE
);
868 BT_LOGD("Created integer field type object: addr=%p, size=%u",
869 &integer
->parent
, size
);
870 return &integer
->parent
;
873 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*type
)
876 struct bt_ctf_field_type_integer
*integer
;
879 BT_LOGW_STR("Invalid parameter: field type is NULL.");
884 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
885 BT_LOGW("Invalid parameter: field type is not an integer field type: "
886 "addr=%p, ft-id=%s", type
,
887 bt_ctf_field_type_id_string(type
->id
));
892 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
893 ret
= (int) integer
->size
;
898 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type
*type
)
901 struct bt_ctf_field_type_integer
*integer
;
904 BT_LOGW_STR("Invalid parameter: field type is NULL.");
909 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
910 BT_LOGW("Invalid parameter: field type is not an integer field type: "
911 "addr=%p, ft-id=%s", type
,
912 bt_ctf_field_type_id_string(type
->id
));
917 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
918 ret
= integer
->is_signed
;
923 bt_bool
bt_ctf_field_type_integer_is_signed(
924 struct bt_ctf_field_type
*int_field_type
)
926 return bt_ctf_field_type_integer_get_signed(int_field_type
) ?
930 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type
*type
,
934 struct bt_ctf_field_type_integer
*integer
;
937 BT_LOGW_STR("Invalid parameter: field type is NULL.");
943 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
949 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
950 BT_LOGW("Invalid parameter: field type is not an integer field type: "
951 "addr=%p, ft-id=%s", type
,
952 bt_ctf_field_type_id_string(type
->id
));
957 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
958 integer
->is_signed
= !!is_signed
;
963 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*type
,
967 struct bt_ctf_field_type_integer
*integer
;
970 BT_LOGW_STR("Invalid parameter: field type is NULL.");
976 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
982 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
983 BT_LOGW("Invalid parameter: field type is not an integer field type: "
984 "addr=%p, ft-id=%s", type
,
985 bt_ctf_field_type_id_string(type
->id
));
990 if (size
== 0 || size
> 64) {
991 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
992 "addr=%p, size=%u", type
, size
);
997 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
998 integer
->size
= size
;
1003 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
1004 struct bt_ctf_field_type
*type
)
1006 enum bt_ctf_integer_base ret
= BT_CTF_INTEGER_BASE_UNKNOWN
;
1007 struct bt_ctf_field_type_integer
*integer
;
1010 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1014 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1015 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1016 "addr=%p, ft-id=%s", type
,
1017 bt_ctf_field_type_id_string(type
->id
));
1021 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1022 ret
= integer
->base
;
1027 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*type
,
1028 enum bt_ctf_integer_base base
)
1033 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1039 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1045 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1046 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1047 "addr=%p, ft-id=%s", type
,
1048 bt_ctf_field_type_id_string(type
->id
));
1054 case BT_CTF_INTEGER_BASE_BINARY
:
1055 case BT_CTF_INTEGER_BASE_OCTAL
:
1056 case BT_CTF_INTEGER_BASE_DECIMAL
:
1057 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1059 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
1060 struct bt_ctf_field_type_integer
, parent
);
1061 integer
->base
= base
;
1065 BT_LOGW("Invalid parameter: unknown integer field type base: "
1066 "addr=%p, base=%d", type
, base
);
1073 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
1074 struct bt_ctf_field_type
*type
)
1076 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
1077 struct bt_ctf_field_type_integer
*integer
;
1080 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1084 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1085 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1086 "addr=%p, ft-id=%s", type
,
1087 bt_ctf_field_type_id_string(type
->id
));
1091 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1092 ret
= integer
->encoding
;
1097 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*type
,
1098 enum bt_ctf_string_encoding encoding
)
1101 struct bt_ctf_field_type_integer
*integer
;
1104 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1110 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1116 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1117 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1118 "addr=%p, ft-id=%s", type
,
1119 bt_ctf_field_type_id_string(type
->id
));
1124 if (encoding
< BT_CTF_STRING_ENCODING_NONE
||
1125 encoding
>= BT_CTF_STRING_ENCODING_UNKNOWN
) {
1126 BT_LOGW("Invalid parameter: unknown string encoding: "
1127 "addr=%p, encoding=%d", type
, encoding
);
1132 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1133 integer
->encoding
= encoding
;
1138 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
1139 struct bt_ctf_field_type
*type
)
1141 struct bt_ctf_field_type_integer
*integer
;
1142 struct bt_ctf_clock_class
*clock_class
= NULL
;
1145 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1149 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1150 clock_class
= integer
->mapped_clock
;
1151 bt_get(clock_class
);
1156 int bt_ctf_field_type_integer_set_mapped_clock_class(
1157 struct bt_ctf_field_type
*type
,
1158 struct bt_ctf_clock_class
*clock_class
)
1160 struct bt_ctf_field_type_integer
*integer
;
1164 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1170 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1176 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1182 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1183 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1184 "clock-class-addr=%p, clock-class-name=\"%s\"",
1186 bt_ctf_clock_class_get_name(clock_class
));
1191 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1192 bt_put(integer
->mapped_clock
);
1193 integer
->mapped_clock
= bt_get(clock_class
);
1199 void bt_ctf_field_type_enum_iter_destroy(struct bt_object
*obj
)
1201 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
1203 struct bt_ctf_field_type_enumeration_mapping_iterator
,
1206 bt_put(&iter
->enumeration_type
->parent
);
1211 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1212 bt_ctf_field_type_enumeration_find_mappings_type(
1213 struct bt_ctf_field_type
*type
,
1214 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
1216 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1217 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1220 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1224 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1225 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1226 "addr=%p, ft-id=%s", type
,
1227 bt_ctf_field_type_id_string(type
->id
));
1231 enumeration_type
= container_of(type
,
1232 struct bt_ctf_field_type_enumeration
, parent
);
1233 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
1235 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
1239 bt_object_init(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
1241 iter
->enumeration_type
= enumeration_type
;
1243 iter
->type
= iterator_type
;
1248 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1249 bt_ctf_field_type_enumeration_find_mappings_by_name(
1250 struct bt_ctf_field_type
*type
, const char *name
)
1252 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1254 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1255 type
, ITERATOR_BY_NAME
);
1257 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1258 "ft-addr=%p, mapping-name=\"%s\"", type
, name
);
1262 iter
->u
.name_quark
= g_quark_try_string(name
);
1263 if (!iter
->u
.name_quark
) {
1264 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
1268 /* Advance iterator to first entry, or leave index at -1. */
1269 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1270 /* No entry found. */
1280 int bt_ctf_field_type_enumeration_mapping_iterator_next(
1281 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
1283 struct bt_ctf_field_type_enumeration
*enumeration
;
1284 struct bt_ctf_field_type
*type
;
1285 int i
, ret
= 0, len
;
1288 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1293 enumeration
= iter
->enumeration_type
;
1294 type
= &enumeration
->parent
;
1295 len
= enumeration
->entries
->len
;
1296 for (i
= iter
->index
+ 1; i
< len
; i
++) {
1297 struct enumeration_mapping
*mapping
=
1298 get_enumeration_mapping(type
, i
);
1300 switch (iter
->type
) {
1301 case ITERATOR_BY_NAME
:
1302 if (mapping
->string
== iter
->u
.name_quark
) {
1307 case ITERATOR_BY_SIGNED_VALUE
:
1309 int64_t value
= iter
->u
.signed_value
;
1311 if (value
>= mapping
->range_start
._signed
&&
1312 value
<= mapping
->range_end
._signed
) {
1318 case ITERATOR_BY_UNSIGNED_VALUE
:
1320 uint64_t value
= iter
->u
.unsigned_value
;
1322 if (value
>= mapping
->range_start
._unsigned
&&
1323 value
<= mapping
->range_end
._unsigned
) {
1339 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1340 bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1341 struct bt_ctf_field_type
*type
, int64_t value
)
1343 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1345 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1346 type
, ITERATOR_BY_SIGNED_VALUE
);
1348 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1349 "ft-addr=%p, value=%" PRId64
, type
, value
);
1353 if (bt_ctf_field_type_integer_get_signed(
1354 iter
->enumeration_type
->container
) != 1) {
1355 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
1356 "enum-ft-addr=%p, int-ft-addr=%p",
1357 type
, iter
->enumeration_type
->container
);
1361 iter
->u
.signed_value
= value
;
1363 /* Advance iterator to first entry, or leave index at -1. */
1364 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1365 /* No entry found. */
1375 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1376 bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1377 struct bt_ctf_field_type
*type
, uint64_t value
)
1379 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1382 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1386 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1387 type
, ITERATOR_BY_UNSIGNED_VALUE
);
1389 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1390 "ft-addr=%p, value=%" PRIu64
, type
, value
);
1394 if (bt_ctf_field_type_integer_get_signed(
1395 iter
->enumeration_type
->container
) != 0) {
1396 BT_LOGW("Invalid parameter: enumeration field type is signed: "
1397 "enum-ft-addr=%p, int-ft-addr=%p",
1398 type
, iter
->enumeration_type
->container
);
1401 iter
->u
.unsigned_value
= value
;
1403 /* Advance iterator to first entry, or leave index at -1. */
1404 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1405 /* No entry found. */
1415 int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
1416 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1417 const char **mapping_name
, int64_t *range_begin
,
1423 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1428 ret
= bt_ctf_field_type_enumeration_get_mapping_signed(
1429 &iter
->enumeration_type
->parent
, iter
->index
,
1430 mapping_name
, range_begin
, range_end
);
1435 int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
1436 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1437 const char **mapping_name
, uint64_t *range_begin
,
1438 uint64_t *range_end
)
1443 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1448 ret
= bt_ctf_field_type_enumeration_get_mapping_unsigned(
1449 &iter
->enumeration_type
->parent
, iter
->index
,
1450 mapping_name
, range_begin
, range_end
);
1455 int bt_ctf_field_type_enumeration_get_mapping_signed(
1456 struct bt_ctf_field_type
*enum_field_type
,
1457 uint64_t index
, const char **mapping_name
, int64_t *range_begin
,
1461 struct enumeration_mapping
*mapping
;
1463 if (!enum_field_type
) {
1464 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1469 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1471 /* get_enumeration_mapping() reports any error */
1477 *mapping_name
= g_quark_to_string(mapping
->string
);
1481 *range_begin
= mapping
->range_start
._signed
;
1485 *range_end
= mapping
->range_end
._signed
;
1491 int bt_ctf_field_type_enumeration_get_mapping_unsigned(
1492 struct bt_ctf_field_type
*enum_field_type
,
1494 const char **mapping_name
, uint64_t *range_begin
,
1495 uint64_t *range_end
)
1498 struct enumeration_mapping
*mapping
;
1500 if (!enum_field_type
) {
1501 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1506 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1508 /* get_enumeration_mapping() reports any error */
1514 *mapping_name
= g_quark_to_string(mapping
->string
);
1518 *range_begin
= mapping
->range_start
._unsigned
;
1522 *range_end
= mapping
->range_end
._unsigned
;
1528 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
1529 struct bt_ctf_field_type
*integer_container_type
)
1531 struct bt_ctf_field_type_enumeration
*enumeration
= NULL
;
1533 BT_LOGD("Creating enumeration field type object: int-ft-addr=%p",
1534 integer_container_type
);
1536 if (!integer_container_type
) {
1537 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1541 if (integer_container_type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1542 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
1543 "container-ft-addr=%p, container-ft-id=%s",
1544 integer_container_type
,
1545 bt_ctf_field_type_id_string(integer_container_type
->id
));
1549 enumeration
= g_new0(struct bt_ctf_field_type_enumeration
, 1);
1551 BT_LOGE_STR("Failed to allocate one enumeration field type.");
1555 enumeration
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
1556 bt_get(integer_container_type
);
1557 enumeration
->container
= integer_container_type
;
1558 enumeration
->entries
= g_ptr_array_new_with_free_func(
1559 (GDestroyNotify
)destroy_enumeration_mapping
);
1560 bt_ctf_field_type_init(&enumeration
->parent
, FALSE
);
1561 BT_LOGD("Created enumeration field type object: addr=%p, "
1562 "int-ft-addr=%p, int-ft-size=%u",
1563 &enumeration
->parent
, integer_container_type
,
1564 bt_ctf_field_type_integer_get_size(integer_container_type
));
1565 return &enumeration
->parent
;
1567 g_free(enumeration
);
1571 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_type(
1572 struct bt_ctf_field_type
*type
)
1574 struct bt_ctf_field_type
*container_type
= NULL
;
1575 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1578 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1582 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1583 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1584 "addr=%p, ft-id=%s", type
,
1585 bt_ctf_field_type_id_string(type
->id
));
1589 enumeration_type
= container_of(type
,
1590 struct bt_ctf_field_type_enumeration
, parent
);
1591 container_type
= enumeration_type
->container
;
1592 bt_get(container_type
);
1594 return container_type
;
1597 int bt_ctf_field_type_enumeration_add_mapping(
1598 struct bt_ctf_field_type
*type
, const char *string
,
1599 int64_t range_start
, int64_t range_end
)
1602 GQuark mapping_name
;
1603 struct enumeration_mapping
*mapping
;
1604 struct bt_ctf_field_type_enumeration
*enumeration
;
1605 char *escaped_string
;
1608 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1614 BT_LOGW_STR("Invalid parameter: string is NULL.");
1620 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1626 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1627 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1628 "addr=%p, ft-id=%s", type
,
1629 bt_ctf_field_type_id_string(type
->id
));
1634 if (range_end
< range_start
) {
1635 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1636 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1637 type
, range_start
, range_end
);
1642 if (strlen(string
) == 0) {
1643 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1644 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1650 escaped_string
= g_strescape(string
, NULL
);
1651 if (!escaped_string
) {
1652 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1653 "mapping-name-addr=%p, mapping-name=\"%s\"",
1654 type
, string
, string
);
1659 mapping
= g_new(struct enumeration_mapping
, 1);
1661 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1665 mapping_name
= g_quark_from_string(escaped_string
);
1666 *mapping
= (struct enumeration_mapping
) {
1667 .range_start
._signed
= range_start
,
1668 .range_end
._signed
= range_end
,
1669 .string
= mapping_name
,
1671 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1673 g_ptr_array_add(enumeration
->entries
, mapping
);
1674 g_ptr_array_sort(enumeration
->entries
,
1675 (GCompareFunc
)compare_enumeration_mappings_signed
);
1677 free(escaped_string
);
1682 int bt_ctf_field_type_enumeration_add_mapping_unsigned(
1683 struct bt_ctf_field_type
*type
, const char *string
,
1684 uint64_t range_start
, uint64_t range_end
)
1687 GQuark mapping_name
;
1688 struct enumeration_mapping
*mapping
;
1689 struct bt_ctf_field_type_enumeration
*enumeration
;
1690 char *escaped_string
;
1693 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1699 BT_LOGW_STR("Invalid parameter: string is NULL.");
1705 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1711 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1712 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1713 "addr=%p, ft-id=%s", type
,
1714 bt_ctf_field_type_id_string(type
->id
));
1719 if (range_end
< range_start
) {
1720 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1721 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1722 type
, range_start
, range_end
);
1727 if (strlen(string
) == 0) {
1728 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1729 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1735 escaped_string
= g_strescape(string
, NULL
);
1736 if (!escaped_string
) {
1737 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1738 "mapping-name-addr=%p, mapping-name=\"%s\"",
1739 type
, string
, string
);
1744 mapping
= g_new(struct enumeration_mapping
, 1);
1746 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1750 mapping_name
= g_quark_from_string(escaped_string
);
1751 *mapping
= (struct enumeration_mapping
) {
1752 .range_start
._unsigned
= range_start
,
1753 .range_end
._unsigned
= range_end
,
1754 .string
= mapping_name
,
1756 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1758 g_ptr_array_add(enumeration
->entries
, mapping
);
1759 g_ptr_array_sort(enumeration
->entries
,
1760 (GCompareFunc
)compare_enumeration_mappings_unsigned
);
1762 free(escaped_string
);
1767 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
1768 struct bt_ctf_field_type
*type
)
1771 struct bt_ctf_field_type_enumeration
*enumeration
;
1774 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1779 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1780 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1781 "addr=%p, ft-id=%s", type
,
1782 bt_ctf_field_type_id_string(type
->id
));
1787 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1789 ret
= (int64_t) enumeration
->entries
->len
;
1794 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
1796 struct bt_ctf_field_type_floating_point
*floating_point
=
1797 g_new0(struct bt_ctf_field_type_floating_point
, 1);
1799 BT_LOGD_STR("Creating floating point number field type object.");
1801 if (!floating_point
) {
1802 BT_LOGE_STR("Failed to allocate one floating point number field type.");
1806 floating_point
->parent
.id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
1807 floating_point
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
1808 floating_point
->mant_dig
= FLT_MANT_DIG
;
1809 bt_ctf_field_type_init(&floating_point
->parent
, TRUE
);
1810 BT_LOGD("Created floating point number field type object: addr=%p, "
1811 "exp-size=%u, mant-size=%u", &floating_point
->parent
,
1812 floating_point
->exp_dig
, floating_point
->mant_dig
);
1814 return floating_point
? &floating_point
->parent
: NULL
;
1817 int bt_ctf_field_type_floating_point_get_exponent_digits(
1818 struct bt_ctf_field_type
*type
)
1821 struct bt_ctf_field_type_floating_point
*floating_point
;
1824 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1829 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1830 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1831 "addr=%p, ft-id=%s", type
,
1832 bt_ctf_field_type_id_string(type
->id
));
1837 floating_point
= container_of(type
,
1838 struct bt_ctf_field_type_floating_point
, parent
);
1839 ret
= (int) floating_point
->exp_dig
;
1844 int bt_ctf_field_type_floating_point_set_exponent_digits(
1845 struct bt_ctf_field_type
*type
,
1846 unsigned int exponent_digits
)
1849 struct bt_ctf_field_type_floating_point
*floating_point
;
1852 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1858 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1864 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1865 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1866 "addr=%p, ft-id=%s", type
,
1867 bt_ctf_field_type_id_string(type
->id
));
1872 floating_point
= container_of(type
,
1873 struct bt_ctf_field_type_floating_point
, parent
);
1874 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1875 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1877 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1878 BT_LOGW("Invalid parameter: invalid exponent size: "
1879 "addr=%p, exp-size=%u", type
, exponent_digits
);
1884 floating_point
->exp_dig
= exponent_digits
;
1889 int bt_ctf_field_type_floating_point_get_mantissa_digits(
1890 struct bt_ctf_field_type
*type
)
1893 struct bt_ctf_field_type_floating_point
*floating_point
;
1896 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1901 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1902 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1903 "addr=%p, ft-id=%s", type
,
1904 bt_ctf_field_type_id_string(type
->id
));
1909 floating_point
= container_of(type
,
1910 struct bt_ctf_field_type_floating_point
, parent
);
1911 ret
= (int) floating_point
->mant_dig
;
1916 int bt_ctf_field_type_floating_point_set_mantissa_digits(
1917 struct bt_ctf_field_type
*type
,
1918 unsigned int mantissa_digits
)
1921 struct bt_ctf_field_type_floating_point
*floating_point
;
1924 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1930 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1936 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1937 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1938 "addr=%p, ft-id=%s", type
,
1939 bt_ctf_field_type_id_string(type
->id
));
1944 floating_point
= container_of(type
,
1945 struct bt_ctf_field_type_floating_point
, parent
);
1947 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1948 (mantissa_digits
!= DBL_MANT_DIG
) &&
1949 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1950 BT_LOGW("Invalid parameter: invalid mantissa size: "
1951 "addr=%p, mant-size=%u", type
, mantissa_digits
);
1956 floating_point
->mant_dig
= mantissa_digits
;
1961 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
1963 struct bt_ctf_field_type_structure
*structure
=
1964 g_new0(struct bt_ctf_field_type_structure
, 1);
1966 BT_LOGD_STR("Creating structure field type object.");
1969 BT_LOGE_STR("Failed to allocate one structure field type.");
1973 structure
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
1974 structure
->fields
= g_ptr_array_new_with_free_func(
1975 (GDestroyNotify
)destroy_structure_field
);
1976 structure
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
1977 bt_ctf_field_type_init(&structure
->parent
, TRUE
);
1978 BT_LOGD("Created structure field type object: addr=%p",
1979 &structure
->parent
);
1980 return &structure
->parent
;
1985 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*type
,
1986 struct bt_ctf_field_type
*field_type
,
1987 const char *field_name
)
1990 struct bt_ctf_field_type_structure
*structure
;
1993 * TODO: check that `field_type` does not contain `type`,
1997 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2003 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2009 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2015 if (bt_ctf_validate_identifier(field_name
)) {
2016 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2017 "struct-ft-addr=%p, field-name=\"%s\"",
2023 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2024 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2025 "addr=%p, ft-id=%s", type
,
2026 bt_ctf_field_type_id_string(type
->id
));
2031 if (type
== field_type
) {
2032 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
2038 structure
= container_of(type
,
2039 struct bt_ctf_field_type_structure
, parent
);
2040 if (add_structure_field(structure
->fields
,
2041 structure
->field_name_to_index
, field_type
, field_name
)) {
2042 BT_LOGW("Cannot add field to structure field type: "
2043 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2044 type
, field_type
, field_name
);
2052 int64_t bt_ctf_field_type_structure_get_field_count(
2053 struct bt_ctf_field_type
*type
)
2056 struct bt_ctf_field_type_structure
*structure
;
2059 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2064 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2065 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2066 "addr=%p, ft-id=%s", type
,
2067 bt_ctf_field_type_id_string(type
->id
));
2072 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2074 ret
= (int64_t) structure
->fields
->len
;
2079 int bt_ctf_field_type_structure_get_field_by_index(
2080 struct bt_ctf_field_type
*type
,
2081 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2084 struct bt_ctf_field_type_structure
*structure
;
2085 struct structure_field
*field
;
2089 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2094 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2095 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2096 "addr=%p, ft-id=%s", type
,
2097 bt_ctf_field_type_id_string(type
->id
));
2102 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2104 if (index
>= structure
->fields
->len
) {
2105 BT_LOGW("Invalid parameter: index is out of bounds: "
2106 "addr=%p, index=%" PRIu64
", count=%u",
2107 type
, index
, structure
->fields
->len
);
2112 field
= g_ptr_array_index(structure
->fields
, index
);
2114 *field_type
= field
->type
;
2115 bt_get(field
->type
);
2118 *field_name
= g_quark_to_string(field
->name
);
2124 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
2125 struct bt_ctf_field_type
*type
,
2130 struct structure_field
*field
;
2131 struct bt_ctf_field_type_structure
*structure
;
2132 struct bt_ctf_field_type
*field_type
= NULL
;
2135 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2140 BT_LOGW_STR("Invalid parameter: name is NULL.");
2144 name_quark
= g_quark_try_string(name
);
2146 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
2150 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2152 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
2153 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2157 field
= structure
->fields
->pdata
[index
];
2158 field_type
= field
->type
;
2164 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
2165 struct bt_ctf_field_type
*enum_tag
, const char *tag_name
)
2167 struct bt_ctf_field_type_variant
*variant
= NULL
;
2169 BT_LOGD("Creating variant field type object: "
2170 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2171 enum_tag
, tag_name
);
2173 if (tag_name
&& bt_ctf_validate_identifier(tag_name
)) {
2174 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2175 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2176 enum_tag
, tag_name
);
2180 variant
= g_new0(struct bt_ctf_field_type_variant
, 1);
2182 BT_LOGE_STR("Failed to allocate one variant field type.");
2186 variant
->parent
.id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
2187 variant
->tag_name
= g_string_new(tag_name
);
2188 variant
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2189 variant
->fields
= g_ptr_array_new_with_free_func(
2190 (GDestroyNotify
) destroy_structure_field
);
2193 variant
->tag
= container_of(enum_tag
,
2194 struct bt_ctf_field_type_enumeration
, parent
);
2197 bt_ctf_field_type_init(&variant
->parent
, TRUE
);
2198 /* A variant's alignment is undefined */
2199 variant
->parent
.alignment
= 0;
2200 BT_LOGD("Created variant field type object: addr=%p, "
2201 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2202 &variant
->parent
, enum_tag
, tag_name
);
2203 return &variant
->parent
;
2208 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_type(
2209 struct bt_ctf_field_type
*type
)
2211 struct bt_ctf_field_type_variant
*variant
;
2212 struct bt_ctf_field_type
*tag_type
= NULL
;
2215 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2219 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2220 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2221 "addr=%p, ft-id=%s", type
,
2222 bt_ctf_field_type_id_string(type
->id
));
2226 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2227 if (!variant
->tag
) {
2228 BT_LOGV("Variant field type has no tag field type: "
2233 tag_type
= &variant
->tag
->parent
;
2239 const char *bt_ctf_field_type_variant_get_tag_name(
2240 struct bt_ctf_field_type
*type
)
2242 struct bt_ctf_field_type_variant
*variant
;
2243 const char *tag_name
= NULL
;
2246 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2250 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2251 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2252 "addr=%p, ft-id=%s", type
,
2253 bt_ctf_field_type_id_string(type
->id
));
2257 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2258 if (variant
->tag_name
->len
== 0) {
2259 BT_LOGV("Variant field type has no tag field name: "
2264 tag_name
= variant
->tag_name
->str
;
2269 int bt_ctf_field_type_variant_set_tag_name(
2270 struct bt_ctf_field_type
*type
, const char *name
)
2273 struct bt_ctf_field_type_variant
*variant
;
2276 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2282 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2288 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2289 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2290 "addr=%p, ft-id=%s", type
,
2291 bt_ctf_field_type_id_string(type
->id
));
2296 if (bt_ctf_validate_identifier(name
)) {
2297 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2298 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2304 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2305 g_string_assign(variant
->tag_name
, name
);
2310 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*type
,
2311 struct bt_ctf_field_type
*field_type
,
2312 const char *field_name
)
2316 struct bt_ctf_field_type_variant
*variant
;
2317 GQuark field_name_quark
= g_quark_from_string(field_name
);
2320 * TODO: check that `field_type` does not contain `type`,
2324 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2330 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2336 if (bt_ctf_validate_identifier(field_name
)) {
2337 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2338 "variant-ft-addr=%p, field-name=\"%s\"",
2344 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2345 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2346 "addr=%p, ft-id=%s", type
,
2347 bt_ctf_field_type_id_string(type
->id
));
2352 if (type
== field_type
) {
2353 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2359 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2361 /* The user has explicitly provided a tag; validate against it. */
2365 /* Make sure this name is present in the enum tag */
2366 for (i
= 0; i
< variant
->tag
->entries
->len
; i
++) {
2367 struct enumeration_mapping
*mapping
=
2368 g_ptr_array_index(variant
->tag
->entries
, i
);
2370 if (mapping
->string
== field_name_quark
) {
2377 /* Validation failed */
2378 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2379 "variant-ft-addr=%p, tag-ft-addr=%p, "
2380 "tag-field-name=\"%s\""
2381 "field-ft-addr=%p, field-name=\"%s\"",
2382 type
, variant
->tag
, variant
->tag_name
->str
,
2383 field_type
, field_name
);
2389 if (add_structure_field(variant
->fields
, variant
->field_name_to_index
,
2390 field_type
, field_name
)) {
2391 BT_LOGW("Cannot add field to variant field type: "
2392 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2393 type
, field_type
, field_name
);
2401 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
2402 struct bt_ctf_field_type
*type
,
2403 const char *field_name
)
2407 struct structure_field
*field
;
2408 struct bt_ctf_field_type_variant
*variant
;
2409 struct bt_ctf_field_type
*field_type
= NULL
;
2412 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2417 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2421 name_quark
= g_quark_try_string(field_name
);
2423 BT_LOGE("Cannot get GQuark: string=\"%s\"", field_name
);
2427 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2428 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
2429 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2433 field
= g_ptr_array_index(variant
->fields
, index
);
2434 field_type
= field
->type
;
2440 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
2441 struct bt_ctf_field_type
*type
,
2442 struct bt_ctf_field
*tag
)
2445 const char *enum_value
;
2446 struct bt_ctf_field_type
*field_type
= NULL
;
2447 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
2450 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2455 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
2459 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2460 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2461 "addr=%p, ft-id=%s", type
,
2462 bt_ctf_field_type_id_string(type
->id
));
2466 iter
= bt_ctf_field_enumeration_get_mappings(tag
);
2468 BT_LOGE("Cannot get enumeration field type mapping iterator from enumeration field: "
2469 "enum-field-addr=%p", tag
);
2473 ret
= bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter
,
2474 &enum_value
, NULL
, NULL
);
2476 BT_LOGW("Cannot get enumeration field type mapping iterator's current mapping: "
2477 "iter-addr=%p", iter
);
2481 field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
2488 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*type
)
2491 struct bt_ctf_field_type_variant
*variant
;
2494 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2499 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2500 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2501 "addr=%p, ft-id=%s", type
,
2502 bt_ctf_field_type_id_string(type
->id
));
2507 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2509 ret
= (int64_t) variant
->fields
->len
;
2515 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*type
,
2516 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2519 struct bt_ctf_field_type_variant
*variant
;
2520 struct structure_field
*field
;
2524 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2529 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2530 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2531 "addr=%p, ft-id=%s", type
,
2532 bt_ctf_field_type_id_string(type
->id
));
2537 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2539 if (index
>= variant
->fields
->len
) {
2540 BT_LOGW("Invalid parameter: index is out of bounds: "
2541 "addr=%p, index=%" PRIu64
", count=%u",
2542 type
, index
, variant
->fields
->len
);
2547 field
= g_ptr_array_index(variant
->fields
, index
);
2549 *field_type
= field
->type
;
2550 bt_get(field
->type
);
2553 *field_name
= g_quark_to_string(field
->name
);
2559 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
2560 struct bt_ctf_field_type
*element_type
,
2561 unsigned int length
)
2563 struct bt_ctf_field_type_array
*array
= NULL
;
2565 BT_LOGD("Creating array field type object: element-ft-addr=%p, "
2566 "length=%u", element_type
, length
);
2568 if (!element_type
) {
2569 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2574 BT_LOGW_STR("Invalid parameter: length is zero.");
2578 array
= g_new0(struct bt_ctf_field_type_array
, 1);
2580 BT_LOGE_STR("Failed to allocate one array field type.");
2584 array
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
2585 bt_get(element_type
);
2586 array
->element_type
= element_type
;
2587 array
->length
= length
;
2588 bt_ctf_field_type_init(&array
->parent
, FALSE
);
2589 BT_LOGD("Created array field type object: addr=%p, "
2590 "element-ft-addr=%p, length=%u",
2591 &array
->parent
, element_type
, length
);
2592 return &array
->parent
;
2597 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_type(
2598 struct bt_ctf_field_type
*type
)
2600 struct bt_ctf_field_type
*ret
= NULL
;
2601 struct bt_ctf_field_type_array
*array
;
2604 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2608 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2609 BT_LOGW("Invalid parameter: field type is not an array field type: "
2610 "addr=%p, ft-id=%s", type
,
2611 bt_ctf_field_type_id_string(type
->id
));
2615 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2616 ret
= array
->element_type
;
2623 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*type
,
2624 struct bt_ctf_field_type
*element_type
)
2627 struct bt_ctf_field_type_array
*array
;
2630 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2635 if (!element_type
) {
2636 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2641 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2642 BT_LOGW("Invalid parameter: field type is not an array field type: "
2643 "addr=%p, ft-id=%s", type
,
2644 bt_ctf_field_type_id_string(type
->id
));
2649 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2651 if (array
->element_type
) {
2652 BT_PUT(array
->element_type
);
2655 array
->element_type
= element_type
;
2656 bt_get(array
->element_type
);
2662 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*type
)
2665 struct bt_ctf_field_type_array
*array
;
2668 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2673 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2674 BT_LOGW("Invalid parameter: field type is not an array field type: "
2675 "addr=%p, ft-id=%s", type
,
2676 bt_ctf_field_type_id_string(type
->id
));
2681 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2682 ret
= (int64_t) array
->length
;
2687 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
2688 struct bt_ctf_field_type
*element_type
,
2689 const char *length_field_name
)
2691 struct bt_ctf_field_type_sequence
*sequence
= NULL
;
2693 BT_LOGD("Creating sequence field type object: element-ft-addr=%p, "
2694 "length-field-name=\"%s\"", element_type
, length_field_name
);
2696 if (!element_type
) {
2697 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2701 if (bt_ctf_validate_identifier(length_field_name
)) {
2702 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
2703 "length-field-name=\"%s\"", length_field_name
);
2707 sequence
= g_new0(struct bt_ctf_field_type_sequence
, 1);
2709 BT_LOGE_STR("Failed to allocate one sequence field type.");
2713 sequence
->parent
.id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
2714 bt_get(element_type
);
2715 sequence
->element_type
= element_type
;
2716 sequence
->length_field_name
= g_string_new(length_field_name
);
2717 bt_ctf_field_type_init(&sequence
->parent
, FALSE
);
2718 BT_LOGD("Created sequence field type object: addr=%p, "
2719 "element-ft-addr=%p, length-field-name=\"%s\"",
2720 &sequence
->parent
, element_type
, length_field_name
);
2721 return &sequence
->parent
;
2726 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_type(
2727 struct bt_ctf_field_type
*type
)
2729 struct bt_ctf_field_type
*ret
= NULL
;
2730 struct bt_ctf_field_type_sequence
*sequence
;
2733 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2737 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2738 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2739 "addr=%p, ft-id=%s", type
,
2740 bt_ctf_field_type_id_string(type
->id
));
2744 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2746 ret
= sequence
->element_type
;
2753 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*type
,
2754 struct bt_ctf_field_type
*element_type
)
2757 struct bt_ctf_field_type_sequence
*sequence
;
2760 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2765 if (!element_type
) {
2766 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2771 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2772 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2773 "addr=%p, ft-id=%s", type
,
2774 bt_ctf_field_type_id_string(type
->id
));
2779 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
, parent
);
2780 if (sequence
->element_type
) {
2781 BT_PUT(sequence
->element_type
);
2784 sequence
->element_type
= element_type
;
2785 bt_get(sequence
->element_type
);
2791 const char *bt_ctf_field_type_sequence_get_length_field_name(
2792 struct bt_ctf_field_type
*type
)
2794 const char *ret
= NULL
;
2795 struct bt_ctf_field_type_sequence
*sequence
;
2798 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2802 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2803 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2804 "addr=%p, ft-id=%s", type
,
2805 bt_ctf_field_type_id_string(type
->id
));
2809 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2811 ret
= sequence
->length_field_name
->str
;
2816 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
2818 struct bt_ctf_field_type_string
*string
=
2819 g_new0(struct bt_ctf_field_type_string
, 1);
2821 BT_LOGD_STR("Creating string field type object.");
2824 BT_LOGE_STR("Failed to allocate one string field type.");
2828 string
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRING
;
2829 bt_ctf_field_type_init(&string
->parent
, TRUE
);
2830 string
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2831 string
->parent
.alignment
= CHAR_BIT
;
2832 BT_LOGD("Created string field type object: addr=%p", &string
->parent
);
2833 return &string
->parent
;
2836 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
2837 struct bt_ctf_field_type
*type
)
2839 struct bt_ctf_field_type_string
*string
;
2840 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
2843 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2847 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2848 BT_LOGW("Invalid parameter: field type is not a string field type: "
2849 "addr=%p, ft-id=%s", type
,
2850 bt_ctf_field_type_id_string(type
->id
));
2854 string
= container_of(type
, struct bt_ctf_field_type_string
,
2856 ret
= string
->encoding
;
2861 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*type
,
2862 enum bt_ctf_string_encoding encoding
)
2865 struct bt_ctf_field_type_string
*string
;
2868 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2873 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2874 BT_LOGW("Invalid parameter: field type is not a string field type: "
2875 "addr=%p, ft-id=%s", type
,
2876 bt_ctf_field_type_id_string(type
->id
));
2881 if ((encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2882 encoding
!= BT_CTF_STRING_ENCODING_ASCII
)) {
2883 BT_LOGW("Invalid parameter: unknown string encoding: "
2884 "addr=%p, encoding=%d", type
, encoding
);
2889 string
= container_of(type
, struct bt_ctf_field_type_string
, parent
);
2890 string
->encoding
= encoding
;
2895 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*type
)
2898 enum bt_ctf_field_type_id type_id
;
2901 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2907 ret
= (int) type
->alignment
;
2911 type_id
= bt_ctf_field_type_get_type_id(type
);
2913 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2915 struct bt_ctf_field_type
*element
=
2916 bt_ctf_field_type_sequence_get_element_type(type
);
2919 ret
= bt_ctf_field_type_get_alignment(element
);
2923 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2925 struct bt_ctf_field_type
*element
=
2926 bt_ctf_field_type_array_get_element_type(type
);
2929 ret
= bt_ctf_field_type_get_alignment(element
);
2933 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2935 int64_t i
, element_count
;
2937 element_count
= bt_ctf_field_type_structure_get_field_count(
2939 assert(element_count
>= 0);
2941 for (i
= 0; i
< element_count
; i
++) {
2942 struct bt_ctf_field_type
*field
;
2943 int field_alignment
;
2945 ret
= bt_ctf_field_type_structure_get_field_by_index(
2946 type
, NULL
, &field
, i
);
2949 field_alignment
= bt_ctf_field_type_get_alignment(
2952 if (field_alignment
< 0) {
2953 ret
= field_alignment
;
2957 type
->alignment
= MAX(field_alignment
, type
->alignment
);
2959 ret
= (int) type
->alignment
;
2962 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
2963 BT_LOGW("Invalid parameter: unknown field type ID: "
2964 "addr=%p, ft-id=%d", type
, type_id
);
2968 ret
= (int) type
->alignment
;
2976 int is_power_of_two(unsigned int value
)
2978 return ((value
& (value
- 1)) == 0) && value
> 0;
2981 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
2982 unsigned int alignment
)
2985 enum bt_ctf_field_type_id type_id
;
2987 /* Alignment must be a power of two */
2989 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2995 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3001 if (!is_power_of_two(alignment
)) {
3002 BT_LOGW("Invalid parameter: alignment is not a power of two: "
3003 "addr=%p, align=%u", type
, alignment
);
3008 type_id
= bt_ctf_field_type_get_type_id(type
);
3009 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3010 BT_LOGW("Invalid parameter: unknown field type ID: "
3011 "addr=%p, ft-id=%d", type
, type_id
);
3016 if (type
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&&
3017 alignment
!= CHAR_BIT
) {
3018 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
3019 "addr=%p, align=%u", CHAR_BIT
, type
, alignment
);
3024 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
3025 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
3026 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
3027 /* Setting an alignment on these types makes no sense */
3028 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
3029 "addr=%p, ft-id=%s", type
,
3030 bt_ctf_field_type_id_string(type
->id
));
3035 type
->alignment
= alignment
;
3041 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
3042 struct bt_ctf_field_type
*type
)
3044 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
3047 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3052 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3054 struct bt_ctf_field_type_integer
*integer
= container_of(
3055 type
, struct bt_ctf_field_type_integer
, parent
);
3056 ret
= integer
->user_byte_order
;
3059 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3061 struct bt_ctf_field_type_enumeration
*enum_ft
= container_of(
3062 type
, struct bt_ctf_field_type_enumeration
, parent
);
3063 ret
= bt_ctf_field_type_get_byte_order(enum_ft
->container
);
3066 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
3068 struct bt_ctf_field_type_floating_point
*floating_point
=
3070 struct bt_ctf_field_type_floating_point
,
3072 ret
= floating_point
->user_byte_order
;
3076 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
3077 "addr=%p, ft-id=%s", type
,
3078 bt_ctf_field_type_id_string(type
->id
));
3082 assert(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
3083 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
3084 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
3085 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
3091 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
3092 enum bt_ctf_byte_order byte_order
)
3097 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3103 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3109 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
3110 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
3111 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
3112 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
3113 BT_LOGW("Invalid parameter: unknown byte order: "
3114 "addr=%p, bo=%s", type
,
3115 bt_ctf_byte_order_string(byte_order
));
3120 if (set_byte_order_funcs
[type
->id
]) {
3121 set_byte_order_funcs
[type
->id
](type
, byte_order
);
3127 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
3128 struct bt_ctf_field_type
*type
)
3131 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3132 return BT_CTF_FIELD_TYPE_ID_UNKNOWN
;
3138 int bt_ctf_field_type_is_integer(struct bt_ctf_field_type
*type
)
3140 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
;
3143 int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type
*type
)
3145 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_FLOAT
;
3148 int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type
*type
)
3150 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ENUM
;
3153 int bt_ctf_field_type_is_string(struct bt_ctf_field_type
*type
)
3155 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRING
;
3158 int bt_ctf_field_type_is_structure(struct bt_ctf_field_type
*type
)
3160 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
;
3163 int bt_ctf_field_type_is_array(struct bt_ctf_field_type
*type
)
3165 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ARRAY
;
3168 int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type
*type
)
3170 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
3173 int bt_ctf_field_type_is_variant(struct bt_ctf_field_type
*type
)
3175 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_VARIANT
;
3178 /* Pre-2.0 CTF writer backward compatibility */
3179 void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
)
3184 /* Pre-2.0 CTF writer backward compatibility */
3185 void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
)
3191 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
)
3193 if (!type
|| type
->frozen
) {
3197 BT_LOGD("Freezing field type: addr=%p", type
);
3202 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
3203 struct bt_ctf_field_type_variant
*variant
,
3206 struct bt_ctf_field_type
*type
= NULL
;
3207 GQuark field_name_quark
;
3209 struct structure_field
*field_entry
;
3210 struct range_overlap_query query
= {
3211 .range_start
._signed
= tag_value
,
3212 .range_end
._signed
= tag_value
,
3217 g_ptr_array_foreach(variant
->tag
->entries
, check_ranges_overlap
,
3219 if (!query
.overlaps
) {
3223 field_name_quark
= query
.mapping_name
;
3224 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3225 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3229 field_entry
= g_ptr_array_index(variant
->fields
, (size_t) index
);
3230 type
= field_entry
->type
;
3236 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
3237 struct bt_ctf_field_type_variant
*variant
,
3240 struct bt_ctf_field_type
*type
= NULL
;
3241 GQuark field_name_quark
;
3243 struct structure_field
*field_entry
;
3244 struct range_overlap_query query
= {
3245 .range_start
._unsigned
= tag_value
,
3246 .range_end
._unsigned
= tag_value
,
3251 g_ptr_array_foreach(variant
->tag
->entries
,
3252 check_ranges_overlap_unsigned
,
3254 if (!query
.overlaps
) {
3258 field_name_quark
= query
.mapping_name
;
3259 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3260 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3264 field_entry
= g_ptr_array_index(variant
->fields
, (size_t)index
);
3265 type
= field_entry
->type
;
3271 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
3272 struct metadata_context
*context
)
3279 BT_LOGD("Serializing field type's metadata: "
3280 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3282 /* Make sure field type is valid before serializing it */
3283 ret
= bt_ctf_field_type_validate(type
);
3285 BT_LOGW_STR("Cannot serialize field type's metadata: field type is invalid.");
3289 ret
= type
->serialize(type
, context
);
3294 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*type
)
3296 struct bt_ctf_field_type
*copy
= NULL
;
3298 BT_LOGD("Copying field type object: addr=%p", type
);
3301 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3305 copy
= type_copy_funcs
[type
->id
](type
);
3307 BT_LOGE_STR("Cannot copy field type.");
3311 copy
->alignment
= type
->alignment
;
3312 BT_LOGD("Copied field type object: copy-ft-addr=%p", copy
);
3318 int bt_ctf_field_type_structure_get_field_name_index(
3319 struct bt_ctf_field_type
*type
, const char *name
)
3324 struct bt_ctf_field_type_structure
*structure
;
3327 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3333 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3338 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
3339 BT_LOGW("Invalid parameter: field type is not a structure field type: "
3340 "addr=%p, ft-id=%s", type
,
3341 bt_ctf_field_type_id_string(type
->id
));
3346 name_quark
= g_quark_try_string(name
);
3348 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
3353 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
3355 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
3356 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
3366 int bt_ctf_field_type_structure_set_field_index(struct bt_ctf_field_type
*type
,
3367 struct bt_ctf_field_type
*field
, int index
)
3370 struct bt_ctf_field_type_structure
*structure
;
3373 BT_LOGW_STR("Invalid parameter: structure field type is NULL.");
3379 BT_LOGW_STR("Invalid parameter: field's field type is NULL.");
3384 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
3385 BT_LOGW("Invalid parameter: field type is not a structure field type: "
3386 "addr=%p, ft-id=%s", type
,
3387 bt_ctf_field_type_id_string(type
->id
));
3392 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
3394 if (index
< 0 || index
>= structure
->fields
->len
) {
3395 BT_LOGW("Invalid parameter: index is out of bounds: "
3396 "addr=%p, index=%" PRIu64
", count=%u",
3397 type
, index
, structure
->fields
->len
);
3403 bt_put(((struct structure_field
*)
3404 g_ptr_array_index(structure
->fields
, index
))->type
);
3405 ((struct structure_field
*) structure
->fields
->pdata
[index
])->type
=
3412 int bt_ctf_field_type_variant_get_field_name_index(
3413 struct bt_ctf_field_type
*type
, const char *name
)
3418 struct bt_ctf_field_type_variant
*variant
;
3421 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3427 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3432 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3433 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3434 "addr=%p, ft-id=%s", type
,
3435 bt_ctf_field_type_id_string(type
->id
));
3440 name_quark
= g_quark_try_string(name
);
3442 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
3447 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3449 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3450 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
3460 int bt_ctf_field_type_sequence_set_length_field_path(
3461 struct bt_ctf_field_type
*type
,
3462 struct bt_ctf_field_path
*path
)
3465 struct bt_ctf_field_type_sequence
*sequence
;
3468 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3473 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
3474 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
3475 "addr=%p, ft-id=%s", type
,
3476 bt_ctf_field_type_id_string(type
->id
));
3481 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
3484 BT_MOVE(sequence
->length_field_path
, path
);
3490 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
3491 struct bt_ctf_field_path
*path
)
3494 struct bt_ctf_field_type_variant
*variant
;
3497 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3502 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3503 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3504 "addr=%p, ft-id=%s", type
,
3505 bt_ctf_field_type_id_string(type
->id
));
3510 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3513 BT_MOVE(variant
->tag_field_path
, path
);
3519 int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type
*type
,
3520 struct bt_ctf_field_type
*tag
)
3523 struct bt_ctf_field_type_variant
*variant
;
3526 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3532 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
3537 if (bt_ctf_field_type_get_type_id(tag
) != BT_CTF_FIELD_TYPE_ID_ENUM
) {
3538 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
3539 "addr=%p, ft-id=%s", type
,
3540 bt_ctf_field_type_id_string(type
->id
));
3545 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3549 bt_put(&variant
->tag
->parent
);
3551 variant
->tag
= container_of(tag
, struct bt_ctf_field_type_enumeration
,
3558 void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type
*type
)
3560 struct bt_ctf_field_type_integer
*integer
=
3561 (struct bt_ctf_field_type_integer
*) type
;
3567 BT_LOGD("Destroying integer field type object: addr=%p", type
);
3568 bt_put(integer
->mapped_clock
);
3573 void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type
*type
)
3575 struct bt_ctf_field_type_enumeration
*enumeration
=
3576 (struct bt_ctf_field_type_enumeration
*) type
;
3582 BT_LOGD("Destroying enumeration field type object: addr=%p", type
);
3583 g_ptr_array_free(enumeration
->entries
, TRUE
);
3584 bt_put(enumeration
->container
);
3585 g_free(enumeration
);
3589 void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type
*type
)
3591 struct bt_ctf_field_type_floating_point
*floating_point
=
3592 (struct bt_ctf_field_type_floating_point
*) type
;
3598 BT_LOGD("Destroying floating point number field type object: addr=%p", type
);
3599 g_free(floating_point
);
3603 void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type
*type
)
3605 struct bt_ctf_field_type_structure
*structure
=
3606 (struct bt_ctf_field_type_structure
*) type
;
3612 BT_LOGD("Destroying structure field type object: addr=%p", type
);
3613 g_ptr_array_free(structure
->fields
, TRUE
);
3614 g_hash_table_destroy(structure
->field_name_to_index
);
3619 void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type
*type
)
3621 struct bt_ctf_field_type_variant
*variant
=
3622 (struct bt_ctf_field_type_variant
*) type
;
3628 BT_LOGD("Destroying variant field type object: addr=%p", type
);
3629 g_ptr_array_free(variant
->fields
, TRUE
);
3630 g_hash_table_destroy(variant
->field_name_to_index
);
3631 g_string_free(variant
->tag_name
, TRUE
);
3632 bt_put(&variant
->tag
->parent
);
3633 BT_PUT(variant
->tag_field_path
);
3638 void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type
*type
)
3640 struct bt_ctf_field_type_array
*array
=
3641 (struct bt_ctf_field_type_array
*) type
;
3647 BT_LOGD("Destroying array field type object: addr=%p", type
);
3648 bt_put(array
->element_type
);
3653 void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type
*type
)
3655 struct bt_ctf_field_type_sequence
*sequence
=
3656 (struct bt_ctf_field_type_sequence
*) type
;
3662 BT_LOGD("Destroying sequence field type object: addr=%p", type
);
3663 bt_put(sequence
->element_type
);
3664 g_string_free(sequence
->length_field_name
, TRUE
);
3665 BT_PUT(sequence
->length_field_path
);
3670 void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type
*type
)
3672 struct bt_ctf_field_type_string
*string
=
3673 (struct bt_ctf_field_type_string
*) type
;
3679 BT_LOGD("Destroying string field type object: addr=%p", type
);
3684 void generic_field_type_freeze(struct bt_ctf_field_type
*type
)
3690 void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type
*type
)
3692 struct bt_ctf_field_type_integer
*integer_type
= container_of(
3693 type
, struct bt_ctf_field_type_integer
, parent
);
3695 BT_LOGD("Freezing integer field type object: addr=%p", type
);
3697 if (integer_type
->mapped_clock
) {
3698 bt_ctf_clock_class_freeze(integer_type
->mapped_clock
);
3701 generic_field_type_freeze(type
);
3705 void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type
*type
)
3707 struct bt_ctf_field_type_enumeration
*enumeration_type
= container_of(
3708 type
, struct bt_ctf_field_type_enumeration
, parent
);
3710 BT_LOGD("Freezing enumeration field type object: addr=%p", type
);
3711 set_enumeration_range_overlap(type
);
3712 generic_field_type_freeze(type
);
3713 bt_ctf_field_type_freeze(enumeration_type
->container
);
3717 void freeze_structure_field(struct structure_field
*field
)
3719 BT_LOGD("Freezing structure field type field: addr=%p", field
);
3720 bt_ctf_field_type_freeze(field
->type
);
3724 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*type
)
3726 struct bt_ctf_field_type_structure
*structure_type
= container_of(
3727 type
, struct bt_ctf_field_type_structure
, parent
);
3729 /* Cache the alignment */
3730 BT_LOGD("Freezing structure field type object: addr=%p", type
);
3731 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3732 generic_field_type_freeze(type
);
3733 g_ptr_array_foreach(structure_type
->fields
,
3734 (GFunc
) freeze_structure_field
, NULL
);
3738 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*type
)
3740 struct bt_ctf_field_type_variant
*variant_type
= container_of(
3741 type
, struct bt_ctf_field_type_variant
, parent
);
3743 BT_LOGD("Freezing variant field type object: addr=%p", type
);
3744 generic_field_type_freeze(type
);
3745 g_ptr_array_foreach(variant_type
->fields
,
3746 (GFunc
) freeze_structure_field
, NULL
);
3750 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*type
)
3752 struct bt_ctf_field_type_array
*array_type
= container_of(
3753 type
, struct bt_ctf_field_type_array
, parent
);
3755 /* Cache the alignment */
3756 BT_LOGD("Freezing array field type object: addr=%p", type
);
3757 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3758 generic_field_type_freeze(type
);
3759 bt_ctf_field_type_freeze(array_type
->element_type
);
3763 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*type
)
3765 struct bt_ctf_field_type_sequence
*sequence_type
= container_of(
3766 type
, struct bt_ctf_field_type_sequence
, parent
);
3768 /* Cache the alignment */
3769 BT_LOGD("Freezing sequence field type object: addr=%p", type
);
3770 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3771 generic_field_type_freeze(type
);
3772 bt_ctf_field_type_freeze(sequence_type
->element_type
);
3776 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
3778 const char *encoding_string
;
3781 case BT_CTF_STRING_ENCODING_NONE
:
3782 encoding_string
= "none";
3784 case BT_CTF_STRING_ENCODING_ASCII
:
3785 encoding_string
= "ASCII";
3787 case BT_CTF_STRING_ENCODING_UTF8
:
3788 encoding_string
= "UTF8";
3791 encoding_string
= "unknown";
3795 return encoding_string
;
3799 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
3801 const char *base_string
;
3804 case BT_CTF_INTEGER_BASE_DECIMAL
:
3805 base_string
= "decimal";
3807 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
3808 base_string
= "hexadecimal";
3810 case BT_CTF_INTEGER_BASE_OCTAL
:
3811 base_string
= "octal";
3813 case BT_CTF_INTEGER_BASE_BINARY
:
3814 base_string
= "binary";
3817 base_string
= "unknown";
3825 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*type
,
3826 struct metadata_context
*context
)
3828 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
3829 struct bt_ctf_field_type_integer
, parent
);
3832 BT_LOGD("Serializing integer field type's metadata: "
3833 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3834 g_string_append_printf(context
->string
,
3835 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
3836 integer
->size
, type
->alignment
,
3837 (integer
->is_signed
? "true" : "false"),
3838 get_encoding_string(integer
->encoding
),
3839 get_integer_base_string(integer
->base
),
3840 get_byte_order_string(integer
->user_byte_order
));
3841 if (integer
->mapped_clock
) {
3842 const char *clock_name
= bt_ctf_clock_class_get_name(
3843 integer
->mapped_clock
);
3846 g_string_append_printf(context
->string
,
3847 "; map = clock.%s.value", clock_name
);
3850 g_string_append(context
->string
, "; }");
3855 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*type
,
3856 struct metadata_context
*context
)
3860 struct bt_ctf_field_type_enumeration
*enumeration
= container_of(type
,
3861 struct bt_ctf_field_type_enumeration
, parent
);
3862 struct bt_ctf_field_type
*container_type
;
3863 int container_signed
;
3865 BT_LOGD("Serializing enumeration field type's metadata: "
3866 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3867 container_type
= bt_ctf_field_type_enumeration_get_container_type(type
);
3868 assert(container_type
);
3869 container_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
3870 assert(container_signed
>= 0);
3871 g_string_append(context
->string
, "enum : ");
3872 ret
= bt_ctf_field_type_serialize(enumeration
->container
, context
);
3874 BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
3875 "container-ft-addr=%p", enumeration
->container
);
3879 g_string_append(context
->string
, " { ");
3880 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
3881 struct enumeration_mapping
*mapping
=
3882 enumeration
->entries
->pdata
[entry
];
3884 if (container_signed
) {
3885 if (mapping
->range_start
._signed
==
3886 mapping
->range_end
._signed
) {
3887 g_string_append_printf(context
->string
,
3888 "\"%s\" = %" PRId64
,
3889 g_quark_to_string(mapping
->string
),
3890 mapping
->range_start
._signed
);
3892 g_string_append_printf(context
->string
,
3893 "\"%s\" = %" PRId64
" ... %" PRId64
,
3894 g_quark_to_string(mapping
->string
),
3895 mapping
->range_start
._signed
,
3896 mapping
->range_end
._signed
);
3899 if (mapping
->range_start
._unsigned
==
3900 mapping
->range_end
._unsigned
) {
3901 g_string_append_printf(context
->string
,
3902 "\"%s\" = %" PRIu64
,
3903 g_quark_to_string(mapping
->string
),
3904 mapping
->range_start
._unsigned
);
3906 g_string_append_printf(context
->string
,
3907 "\"%s\" = %" PRIu64
" ... %" PRIu64
,
3908 g_quark_to_string(mapping
->string
),
3909 mapping
->range_start
._unsigned
,
3910 mapping
->range_end
._unsigned
);
3914 g_string_append(context
->string
,
3915 ((entry
!= (enumeration
->entries
->len
- 1)) ?
3919 if (context
->field_name
->len
) {
3920 g_string_append_printf(context
->string
, " %s",
3921 context
->field_name
->str
);
3922 g_string_assign(context
->field_name
, "");
3925 bt_put(container_type
);
3930 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type
*type
,
3931 struct metadata_context
*context
)
3933 struct bt_ctf_field_type_floating_point
*floating_point
= container_of(
3934 type
, struct bt_ctf_field_type_floating_point
, parent
);
3936 BT_LOGD("Serializing floating point number field type's metadata: "
3937 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3938 g_string_append_printf(context
->string
,
3939 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
3940 floating_point
->exp_dig
,
3941 floating_point
->mant_dig
,
3942 get_byte_order_string(floating_point
->user_byte_order
),
3948 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*type
,
3949 struct metadata_context
*context
)
3952 unsigned int indent
;
3954 struct bt_ctf_field_type_structure
*structure
= container_of(type
,
3955 struct bt_ctf_field_type_structure
, parent
);
3956 GString
*structure_field_name
= context
->field_name
;
3958 BT_LOGD("Serializing structure field type's metadata: "
3959 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3960 context
->field_name
= g_string_new("");
3962 context
->current_indentation_level
++;
3963 g_string_append(context
->string
, "struct {\n");
3965 for (i
= 0; i
< structure
->fields
->len
; i
++) {
3966 struct structure_field
*field
;
3968 for (indent
= 0; indent
< context
->current_indentation_level
;
3970 g_string_append_c(context
->string
, '\t');
3973 field
= structure
->fields
->pdata
[i
];
3974 g_string_assign(context
->field_name
,
3975 g_quark_to_string(field
->name
));
3976 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
3978 BT_LOGW("Cannot serialize structure field type's field's metadata: "
3979 "index=%" PRId64
", "
3980 "field-ft-addr=%p, field-name=\"%s\"",
3982 g_quark_to_string(field
->name
));
3986 if (context
->field_name
->len
) {
3987 g_string_append_printf(context
->string
, " %s",
3988 context
->field_name
->str
);
3990 g_string_append(context
->string
, ";\n");
3993 context
->current_indentation_level
--;
3994 for (indent
= 0; indent
< context
->current_indentation_level
;
3996 g_string_append_c(context
->string
, '\t');
3999 g_string_append_printf(context
->string
, "} align(%u)",
4002 g_string_free(context
->field_name
, TRUE
);
4003 context
->field_name
= structure_field_name
;
4008 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*type
,
4009 struct metadata_context
*context
)
4012 unsigned int indent
;
4014 struct bt_ctf_field_type_variant
*variant
= container_of(
4015 type
, struct bt_ctf_field_type_variant
, parent
);
4016 GString
*variant_field_name
= context
->field_name
;
4018 BT_LOGD("Serializing variant field type's metadata: "
4019 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4020 context
->field_name
= g_string_new("");
4021 if (variant
->tag_name
->len
> 0) {
4022 g_string_append_printf(context
->string
,
4023 "variant <%s> {\n", variant
->tag_name
->str
);
4025 g_string_append(context
->string
, "variant {\n");
4028 context
->current_indentation_level
++;
4029 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4030 struct structure_field
*field
= variant
->fields
->pdata
[i
];
4032 g_string_assign(context
->field_name
,
4033 g_quark_to_string(field
->name
));
4034 for (indent
= 0; indent
< context
->current_indentation_level
;
4036 g_string_append_c(context
->string
, '\t');
4039 g_string_assign(context
->field_name
,
4040 g_quark_to_string(field
->name
));
4041 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4043 BT_LOGW("Cannot serialize variant field type's field's metadata: "
4044 "index=%" PRId64
", "
4045 "field-ft-addr=%p, field-name=\"%s\"",
4047 g_quark_to_string(field
->name
));
4051 if (context
->field_name
->len
) {
4052 g_string_append_printf(context
->string
, " %s;",
4053 context
->field_name
->str
);
4056 g_string_append_c(context
->string
, '\n');
4059 context
->current_indentation_level
--;
4060 for (indent
= 0; indent
< context
->current_indentation_level
;
4062 g_string_append_c(context
->string
, '\t');
4065 g_string_append(context
->string
, "}");
4067 g_string_free(context
->field_name
, TRUE
);
4068 context
->field_name
= variant_field_name
;
4073 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*type
,
4074 struct metadata_context
*context
)
4077 struct bt_ctf_field_type_array
*array
= container_of(type
,
4078 struct bt_ctf_field_type_array
, parent
);
4080 BT_LOGD("Serializing array field type's metadata: "
4081 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4082 ret
= bt_ctf_field_type_serialize(array
->element_type
, context
);
4084 BT_LOGW("Cannot serialize array field type's element field type's metadata: "
4085 "element-ft-addr=%p", array
->element_type
);
4089 if (context
->field_name
->len
) {
4090 g_string_append_printf(context
->string
, " %s[%u]",
4091 context
->field_name
->str
, array
->length
);
4092 g_string_assign(context
->field_name
, "");
4094 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4101 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*type
,
4102 struct metadata_context
*context
)
4105 struct bt_ctf_field_type_sequence
*sequence
= container_of(
4106 type
, struct bt_ctf_field_type_sequence
, parent
);
4108 BT_LOGD("Serializing sequence field type's metadata: "
4109 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4110 ret
= bt_ctf_field_type_serialize(sequence
->element_type
, context
);
4112 BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
4113 "element-ft-addr=%p", sequence
->element_type
);
4117 if (context
->field_name
->len
) {
4118 g_string_append_printf(context
->string
, " %s[%s]",
4119 context
->field_name
->str
,
4120 sequence
->length_field_name
->str
);
4121 g_string_assign(context
->field_name
, "");
4123 g_string_append_printf(context
->string
, "[%s]",
4124 sequence
->length_field_name
->str
);
4131 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*type
,
4132 struct metadata_context
*context
)
4134 struct bt_ctf_field_type_string
*string
= container_of(
4135 type
, struct bt_ctf_field_type_string
, parent
);
4137 BT_LOGD("Serializing string field type's metadata: "
4138 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4139 g_string_append_printf(context
->string
,
4140 "string { encoding = %s; }",
4141 get_encoding_string(string
->encoding
));
4146 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*type
,
4147 enum bt_ctf_byte_order byte_order
)
4149 struct bt_ctf_field_type_integer
*integer_type
= container_of(type
,
4150 struct bt_ctf_field_type_integer
, parent
);
4152 integer_type
->user_byte_order
= byte_order
;
4156 void bt_ctf_field_type_enumeration_set_byte_order(
4157 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4159 struct bt_ctf_field_type_enumeration
*enum_type
= container_of(type
,
4160 struct bt_ctf_field_type_enumeration
, parent
);
4162 /* Safe to assume that container is an integer */
4163 bt_ctf_field_type_integer_set_byte_order(enum_type
->container
,
4168 void bt_ctf_field_type_floating_point_set_byte_order(
4169 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4171 struct bt_ctf_field_type_floating_point
*floating_point_type
=
4172 container_of(type
, struct bt_ctf_field_type_floating_point
,
4175 floating_point_type
->user_byte_order
= byte_order
;
4179 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*type
,
4180 enum bt_ctf_byte_order byte_order
)
4183 struct bt_ctf_field_type_structure
*structure_type
=
4184 container_of(type
, struct bt_ctf_field_type_structure
,
4187 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
4188 struct structure_field
*field
= g_ptr_array_index(
4189 structure_type
->fields
, i
);
4190 struct bt_ctf_field_type
*field_type
= field
->type
;
4192 if (set_byte_order_funcs
[field_type
->id
]) {
4193 set_byte_order_funcs
[field_type
->id
](
4194 field_type
, byte_order
);
4200 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*type
,
4201 enum bt_ctf_byte_order byte_order
)
4204 struct bt_ctf_field_type_variant
*variant_type
=
4205 container_of(type
, struct bt_ctf_field_type_variant
,
4208 for (i
= 0; i
< variant_type
->fields
->len
; i
++) {
4209 struct structure_field
*field
= g_ptr_array_index(
4210 variant_type
->fields
, i
);
4211 struct bt_ctf_field_type
*field_type
= field
->type
;
4213 if (set_byte_order_funcs
[field_type
->id
]) {
4214 set_byte_order_funcs
[field_type
->id
](
4215 field_type
, byte_order
);
4221 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*type
,
4222 enum bt_ctf_byte_order byte_order
)
4224 struct bt_ctf_field_type_array
*array_type
=
4225 container_of(type
, struct bt_ctf_field_type_array
,
4228 if (set_byte_order_funcs
[array_type
->element_type
->id
]) {
4229 set_byte_order_funcs
[array_type
->element_type
->id
](
4230 array_type
->element_type
, byte_order
);
4235 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*type
,
4236 enum bt_ctf_byte_order byte_order
)
4238 struct bt_ctf_field_type_sequence
*sequence_type
=
4239 container_of(type
, struct bt_ctf_field_type_sequence
,
4242 if (set_byte_order_funcs
[
4243 sequence_type
->element_type
->id
]) {
4244 set_byte_order_funcs
[
4245 sequence_type
->element_type
->id
](
4246 sequence_type
->element_type
, byte_order
);
4251 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4252 struct bt_ctf_field_type
*type
)
4254 struct bt_ctf_field_type
*copy
;
4255 struct bt_ctf_field_type_integer
*integer
, *copy_integer
;
4257 BT_LOGD("Copying integer field type's: addr=%p", type
);
4258 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
4259 copy
= bt_ctf_field_type_integer_create(integer
->size
);
4261 BT_LOGE_STR("Cannot create integer field type.");
4265 copy_integer
= container_of(copy
, struct bt_ctf_field_type_integer
,
4267 copy_integer
->mapped_clock
= bt_get(integer
->mapped_clock
);
4268 copy_integer
->user_byte_order
= integer
->user_byte_order
;
4269 copy_integer
->is_signed
= integer
->is_signed
;
4270 copy_integer
->size
= integer
->size
;
4271 copy_integer
->base
= integer
->base
;
4272 copy_integer
->encoding
= integer
->encoding
;
4273 BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4281 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
4282 struct bt_ctf_field_type
*type
)
4285 struct bt_ctf_field_type
*copy
= NULL
, *copy_container
;
4286 struct bt_ctf_field_type_enumeration
*enumeration
, *copy_enumeration
;
4288 BT_LOGD("Copying enumeration field type's: addr=%p", type
);
4289 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
4292 /* Copy the source enumeration's container */
4293 copy_container
= bt_ctf_field_type_copy(enumeration
->container
);
4294 if (!copy_container
) {
4295 BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
4299 copy
= bt_ctf_field_type_enumeration_create(copy_container
);
4301 BT_LOGE_STR("Cannot create enumeration field type.");
4304 copy_enumeration
= container_of(copy
,
4305 struct bt_ctf_field_type_enumeration
, parent
);
4307 /* Copy all enumaration entries */
4308 for (i
= 0; i
< enumeration
->entries
->len
; i
++) {
4309 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4310 enumeration
->entries
, i
);
4311 struct enumeration_mapping
*copy_mapping
= g_new0(
4312 struct enumeration_mapping
, 1);
4314 if (!copy_mapping
) {
4315 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4319 *copy_mapping
= *mapping
;
4320 g_ptr_array_add(copy_enumeration
->entries
, copy_mapping
);
4323 BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4327 bt_put(copy_container
);
4330 bt_put(copy_container
);
4336 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4337 struct bt_ctf_field_type
*type
)
4339 struct bt_ctf_field_type
*copy
;
4340 struct bt_ctf_field_type_floating_point
*floating_point
, *copy_float
;
4342 BT_LOGD("Copying floating point number field type's: addr=%p", type
);
4343 floating_point
= container_of(type
,
4344 struct bt_ctf_field_type_floating_point
, parent
);
4345 copy
= bt_ctf_field_type_floating_point_create();
4347 BT_LOGE_STR("Cannot create floating point number field type.");
4351 copy_float
= container_of(copy
,
4352 struct bt_ctf_field_type_floating_point
, parent
);
4353 copy_float
->user_byte_order
= floating_point
->user_byte_order
;
4354 copy_float
->exp_dig
= floating_point
->exp_dig
;
4355 copy_float
->mant_dig
= floating_point
->mant_dig
;
4356 BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4363 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
4364 struct bt_ctf_field_type
*type
)
4367 GHashTableIter iter
;
4368 gpointer key
, value
;
4369 struct bt_ctf_field_type
*copy
;
4370 struct bt_ctf_field_type_structure
*structure
, *copy_structure
;
4372 BT_LOGD("Copying structure field type's: addr=%p", type
);
4373 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
4375 copy
= bt_ctf_field_type_structure_create();
4377 BT_LOGE_STR("Cannot create structure field type.");
4381 copy_structure
= container_of(copy
,
4382 struct bt_ctf_field_type_structure
, parent
);
4384 /* Copy field_name_to_index */
4385 g_hash_table_iter_init(&iter
, structure
->field_name_to_index
);
4386 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4387 g_hash_table_insert(copy_structure
->field_name_to_index
,
4391 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4392 struct structure_field
*entry
, *copy_entry
;
4393 struct bt_ctf_field_type
*copy_field
;
4395 copy_entry
= g_new0(struct structure_field
, 1);
4397 BT_LOGE_STR("Failed to allocate one structure field type field.");
4401 entry
= g_ptr_array_index(structure
->fields
, i
);
4402 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4404 BT_LOGE("Cannot copy structure field type's field: "
4405 "index=%" PRId64
", "
4406 "field-ft-addr=%p, field-name=\"%s\"",
4407 i
, entry
, g_quark_to_string(entry
->name
));
4412 copy_entry
->name
= entry
->name
;
4413 copy_entry
->type
= copy_field
;
4414 g_ptr_array_add(copy_structure
->fields
, copy_entry
);
4417 BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4428 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
4429 struct bt_ctf_field_type
*type
)
4432 GHashTableIter iter
;
4433 gpointer key
, value
;
4434 struct bt_ctf_field_type
*copy
= NULL
, *copy_tag
= NULL
;
4435 struct bt_ctf_field_type_variant
*variant
, *copy_variant
;
4437 BT_LOGD("Copying variant field type's: addr=%p", type
);
4438 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
4441 copy_tag
= bt_ctf_field_type_copy(&variant
->tag
->parent
);
4443 BT_LOGE_STR("Cannot copy variant field type's tag field type.");
4448 copy
= bt_ctf_field_type_variant_create(copy_tag
,
4449 variant
->tag_name
->len
? variant
->tag_name
->str
: NULL
);
4451 BT_LOGE_STR("Cannot create variant field type.");
4455 copy_variant
= container_of(copy
, struct bt_ctf_field_type_variant
,
4458 /* Copy field_name_to_index */
4459 g_hash_table_iter_init(&iter
, variant
->field_name_to_index
);
4460 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4461 g_hash_table_insert(copy_variant
->field_name_to_index
,
4465 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4466 struct structure_field
*entry
, *copy_entry
;
4467 struct bt_ctf_field_type
*copy_field
;
4469 copy_entry
= g_new0(struct structure_field
, 1);
4471 BT_LOGE_STR("Failed to allocate one variant field type field.");
4475 entry
= g_ptr_array_index(variant
->fields
, i
);
4476 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4478 BT_LOGE("Cannot copy variant field type's field: "
4479 "index=%" PRId64
", "
4480 "field-ft-addr=%p, field-name=\"%s\"",
4481 i
, entry
, g_quark_to_string(entry
->name
));
4486 copy_entry
->name
= entry
->name
;
4487 copy_entry
->type
= copy_field
;
4488 g_ptr_array_add(copy_variant
->fields
, copy_entry
);
4491 if (variant
->tag_field_path
) {
4492 copy_variant
->tag_field_path
= bt_ctf_field_path_copy(
4493 variant
->tag_field_path
);
4494 if (!copy_variant
->tag_field_path
) {
4495 BT_LOGE_STR("Cannot copy variant field type's tag field path.");
4500 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4513 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
4514 struct bt_ctf_field_type
*type
)
4516 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4517 struct bt_ctf_field_type_array
*array
;
4519 BT_LOGD("Copying array field type's: addr=%p", type
);
4520 array
= container_of(type
, struct bt_ctf_field_type_array
,
4522 copy_element
= bt_ctf_field_type_copy(array
->element_type
);
4523 if (!copy_element
) {
4524 BT_LOGE_STR("Cannot copy array field type's element field type.");
4528 copy
= bt_ctf_field_type_array_create(copy_element
, array
->length
);
4530 BT_LOGE_STR("Cannot create array field type.");
4534 BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
4538 bt_put(copy_element
);
4543 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
4544 struct bt_ctf_field_type
*type
)
4546 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4547 struct bt_ctf_field_type_sequence
*sequence
, *copy_sequence
;
4549 BT_LOGD("Copying sequence field type's: addr=%p", type
);
4550 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
4552 copy_element
= bt_ctf_field_type_copy(sequence
->element_type
);
4553 if (!copy_element
) {
4554 BT_LOGE_STR("Cannot copy sequence field type's element field type.");
4558 copy
= bt_ctf_field_type_sequence_create(copy_element
,
4559 sequence
->length_field_name
->len
?
4560 sequence
->length_field_name
->str
: NULL
);
4562 BT_LOGE_STR("Cannot create sequence field type.");
4566 copy_sequence
= container_of(copy
, struct bt_ctf_field_type_sequence
,
4568 if (sequence
->length_field_path
) {
4569 copy_sequence
->length_field_path
= bt_ctf_field_path_copy(
4570 sequence
->length_field_path
);
4571 if (!copy_sequence
->length_field_path
) {
4572 BT_LOGE_STR("Cannot copy sequence field type's length field path.");
4577 BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4581 bt_put(copy_element
);
4589 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4590 struct bt_ctf_field_type
*type
)
4592 struct bt_ctf_field_type
*copy
;
4593 struct bt_ctf_field_type_string
*string
;
4595 BT_LOGD("Copying string field type's: addr=%p", type
);
4596 copy
= bt_ctf_field_type_string_create();
4598 BT_LOGE_STR("Cannot create string field type.");
4602 string
= container_of(type
, struct bt_ctf_field_type_string
,
4604 BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
4611 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*type_a
,
4612 struct bt_ctf_field_type
*type_b
)
4615 struct bt_ctf_field_type_integer
*int_type_a
;
4616 struct bt_ctf_field_type_integer
*int_type_b
;
4618 int_type_a
= container_of(type_a
, struct bt_ctf_field_type_integer
,
4620 int_type_b
= container_of(type_b
, struct bt_ctf_field_type_integer
,
4624 if (int_type_a
->size
!= int_type_b
->size
) {
4625 BT_LOGV("Integer field types differ: different sizes: "
4626 "ft-a-size=%u, ft-b-size=%u",
4627 int_type_a
->size
, int_type_b
->size
);
4632 if (int_type_a
->user_byte_order
!= int_type_b
->user_byte_order
) {
4633 BT_LOGV("Integer field types differ: different byte orders: "
4634 "ft-a-bo=%s, ft-b-bo=%s",
4635 bt_ctf_byte_order_string(int_type_a
->user_byte_order
),
4636 bt_ctf_byte_order_string(int_type_b
->user_byte_order
));
4641 if (int_type_a
->is_signed
!= int_type_b
->is_signed
) {
4642 BT_LOGV("Integer field types differ: different signedness: "
4643 "ft-a-is-signed=%d, ft-b-is-signed=%d",
4644 int_type_a
->is_signed
,
4645 int_type_b
->is_signed
);
4650 if (int_type_a
->base
!= int_type_b
->base
) {
4651 BT_LOGV("Integer field types differ: different bases: "
4652 "ft-a-base=%s, ft-b-base=%s",
4653 bt_ctf_integer_base_string(int_type_a
->base
),
4654 bt_ctf_integer_base_string(int_type_b
->base
));
4659 if (int_type_a
->encoding
!= int_type_b
->encoding
) {
4660 BT_LOGV("Integer field types differ: different encodings: "
4661 "ft-a-encoding=%s, ft-b-encoding=%s",
4662 bt_ctf_string_encoding_string(int_type_a
->encoding
),
4663 bt_ctf_string_encoding_string(int_type_b
->encoding
));
4668 if (int_type_a
->mapped_clock
!= int_type_b
->mapped_clock
) {
4669 BT_LOGV("Integer field types differ: different mapped clock classes: "
4670 "ft-a-mapped-clock-class-addr=%p, "
4671 "ft-b-mapped-clock-class-addr=%p, ",
4672 "ft-a-mapped-clock-class-name=\"%s\", ",
4673 "ft-b-mapped-clock-class-name=\"%s\"",
4674 int_type_a
->mapped_clock
, int_type_b
->mapped_clock
,
4675 int_type_a
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_a
->mapped_clock
) : "",
4676 int_type_b
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_b
->mapped_clock
) : "");
4688 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*type_a
,
4689 struct bt_ctf_field_type
*type_b
)
4692 struct bt_ctf_field_type_floating_point
*float_a
;
4693 struct bt_ctf_field_type_floating_point
*float_b
;
4695 float_a
= container_of(type_a
,
4696 struct bt_ctf_field_type_floating_point
, parent
);
4697 float_b
= container_of(type_b
,
4698 struct bt_ctf_field_type_floating_point
, parent
);
4701 if (float_a
->user_byte_order
!= float_b
->user_byte_order
) {
4702 BT_LOGV("Floating point number field types differ: different byte orders: "
4703 "ft-a-bo=%s, ft-b-bo=%s",
4704 bt_ctf_byte_order_string(float_a
->user_byte_order
),
4705 bt_ctf_byte_order_string(float_b
->user_byte_order
));
4709 /* Exponent length */
4710 if (float_a
->exp_dig
!= float_b
->exp_dig
) {
4711 BT_LOGV("Floating point number field types differ: different exponent sizes: "
4712 "ft-a-exp-size=%s, ft-b-exp-size=%s",
4713 float_a
->exp_dig
, float_b
->exp_dig
);
4717 /* Mantissa length */
4718 if (float_a
->mant_dig
!= float_b
->mant_dig
) {
4719 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
4720 "ft-a-mant-size=%s, ft-b-mant-size=%s",
4721 float_a
->mant_dig
, float_b
->mant_dig
);
4733 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
4734 struct enumeration_mapping
*mapping_b
)
4739 if (mapping_a
->string
!= mapping_b
->string
) {
4740 BT_LOGV("Enumeration field type mappings differ: different names: "
4741 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
4742 g_quark_to_string(mapping_a
->string
),
4743 g_quark_to_string(mapping_b
->string
));
4748 if (mapping_a
->range_start
._unsigned
!=
4749 mapping_b
->range_start
._unsigned
) {
4750 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
4751 "mapping-a-range-start-unsigned=%" PRIu64
", "
4752 "mapping-b-range-start-unsigned=%" PRIu64
,
4753 mapping_a
->range_start
._unsigned
,
4754 mapping_b
->range_start
._unsigned
);
4759 if (mapping_a
->range_end
._unsigned
!=
4760 mapping_b
->range_end
._unsigned
) {
4761 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
4762 "mapping-a-range-end-unsigned=%" PRIu64
", "
4763 "mapping-b-range-end-unsigned=%" PRIu64
,
4764 mapping_a
->range_end
._unsigned
,
4765 mapping_b
->range_end
._unsigned
);
4777 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*type_a
,
4778 struct bt_ctf_field_type
*type_b
)
4782 struct bt_ctf_field_type_enumeration
*enum_a
;
4783 struct bt_ctf_field_type_enumeration
*enum_b
;
4785 enum_a
= container_of(type_a
,
4786 struct bt_ctf_field_type_enumeration
, parent
);
4787 enum_b
= container_of(type_b
,
4788 struct bt_ctf_field_type_enumeration
, parent
);
4790 /* Container field type */
4791 ret
= bt_ctf_field_type_compare(enum_a
->container
, enum_b
->container
);
4793 BT_LOGV("Enumeration field types differ: different container field types: "
4794 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
4795 enum_a
->container
, enum_b
->container
);
4802 if (enum_a
->entries
->len
!= enum_b
->entries
->len
) {
4806 for (i
= 0; i
< enum_a
->entries
->len
; ++i
) {
4807 struct enumeration_mapping
*mapping_a
=
4808 g_ptr_array_index(enum_a
->entries
, i
);
4809 struct enumeration_mapping
*mapping_b
=
4810 g_ptr_array_index(enum_b
->entries
, i
);
4812 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4813 BT_LOGV("Enumeration field types differ: different mappings: "
4814 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4815 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4816 mapping_a
, mapping_b
,
4817 g_quark_to_string(mapping_a
->string
),
4818 g_quark_to_string(mapping_b
->string
));
4831 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*type_a
,
4832 struct bt_ctf_field_type
*type_b
)
4835 struct bt_ctf_field_type_string
*string_a
;
4836 struct bt_ctf_field_type_string
*string_b
;
4838 string_a
= container_of(type_a
,
4839 struct bt_ctf_field_type_string
, parent
);
4840 string_b
= container_of(type_b
,
4841 struct bt_ctf_field_type_string
, parent
);
4844 if (string_a
->encoding
!= string_b
->encoding
) {
4845 BT_LOGV("String field types differ: different encodings: "
4846 "ft-a-encoding=%s, ft-b-encoding=%s",
4847 bt_ctf_string_encoding_string(string_a
->encoding
),
4848 bt_ctf_string_encoding_string(string_b
->encoding
));
4860 int compare_structure_fields(struct structure_field
*field_a
,
4861 struct structure_field
*field_b
)
4866 if (field_a
->name
!= field_b
->name
) {
4867 BT_LOGV("Structure/variant field type fields differ: different names: "
4868 "field-a-name=%s, field-b-name=%s",
4869 g_quark_to_string(field_a
->name
),
4870 g_quark_to_string(field_b
->name
));
4875 ret
= bt_ctf_field_type_compare(field_a
->type
, field_b
->type
);
4877 BT_LOGV("Structure/variant field type fields differ: different field types: "
4878 "field-name=\"%s\", field-a-ft-addr=%s, field-b-ft-addr=%s",
4879 g_quark_to_string(field_a
->name
),
4880 field_a
->type
, field_b
->type
);
4888 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*type_a
,
4889 struct bt_ctf_field_type
*type_b
)
4893 struct bt_ctf_field_type_structure
*struct_a
;
4894 struct bt_ctf_field_type_structure
*struct_b
;
4896 struct_a
= container_of(type_a
,
4897 struct bt_ctf_field_type_structure
, parent
);
4898 struct_b
= container_of(type_b
,
4899 struct bt_ctf_field_type_structure
, parent
);
4902 if (bt_ctf_field_type_get_alignment(type_a
) !=
4903 bt_ctf_field_type_get_alignment(type_b
)) {
4904 BT_LOGV("Structure field types differ: different alignments: "
4905 "ft-a-align=%u, ft-b-align=%u",
4906 bt_ctf_field_type_get_alignment(type_a
),
4907 bt_ctf_field_type_get_alignment(type_b
));
4912 if (struct_a
->fields
->len
!= struct_b
->fields
->len
) {
4913 BT_LOGV("Structure field types differ: different field counts: "
4914 "ft-a-field-count=%u, ft-b-field-count=%u",
4915 struct_a
->fields
->len
, struct_b
->fields
->len
);
4919 for (i
= 0; i
< struct_a
->fields
->len
; ++i
) {
4920 struct structure_field
*field_a
=
4921 g_ptr_array_index(struct_a
->fields
, i
);
4922 struct structure_field
*field_b
=
4923 g_ptr_array_index(struct_b
->fields
, i
);
4925 ret
= compare_structure_fields(field_a
, field_b
);
4927 /* compare_structure_fields() logs what differs */
4928 BT_LOGV_STR("Structure field types differ: different fields.");
4941 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*type_a
,
4942 struct bt_ctf_field_type
*type_b
)
4946 struct bt_ctf_field_type_variant
*variant_a
;
4947 struct bt_ctf_field_type_variant
*variant_b
;
4949 variant_a
= container_of(type_a
,
4950 struct bt_ctf_field_type_variant
, parent
);
4951 variant_b
= container_of(type_b
,
4952 struct bt_ctf_field_type_variant
, parent
);
4955 if (strcmp(variant_a
->tag_name
->str
, variant_b
->tag_name
->str
)) {
4956 BT_LOGV("Variant field types differ: different tag field names: "
4957 "ft-a-tag-field-name=%u, ft-b-tag-field-name=%u",
4958 variant_a
->tag_name
->str
, variant_b
->tag_name
->str
);
4963 ret
= bt_ctf_field_type_compare(
4964 (struct bt_ctf_field_type
*) variant_a
->tag
,
4965 (struct bt_ctf_field_type
*) variant_b
->tag
);
4967 BT_LOGV("Variant field types differ: different tag field types: "
4968 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
4969 variant_a
->tag
, variant_b
->tag
);
4976 if (variant_a
->fields
->len
!= variant_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 variant_a
->fields
->len
, variant_b
->fields
->len
);
4983 for (i
= 0; i
< variant_a
->fields
->len
; ++i
) {
4984 struct structure_field
*field_a
=
4985 g_ptr_array_index(variant_a
->fields
, i
);
4986 struct structure_field
*field_b
=
4987 g_ptr_array_index(variant_b
->fields
, i
);
4989 ret
= compare_structure_fields(field_a
, field_b
);
4991 /* compare_structure_fields() logs what differs */
4992 BT_LOGV_STR("Variant field types differ: different fields.");
5005 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*type_a
,
5006 struct bt_ctf_field_type
*type_b
)
5009 struct bt_ctf_field_type_array
*array_a
;
5010 struct bt_ctf_field_type_array
*array_b
;
5012 array_a
= container_of(type_a
,
5013 struct bt_ctf_field_type_array
, parent
);
5014 array_b
= container_of(type_b
,
5015 struct bt_ctf_field_type_array
, parent
);
5018 if (array_a
->length
!= array_b
->length
) {
5019 BT_LOGV("Structure field types differ: different lengths: "
5020 "ft-a-length=%u, ft-b-length=%u",
5021 array_a
->length
, array_b
->length
);
5026 ret
= bt_ctf_field_type_compare(array_a
->element_type
,
5027 array_b
->element_type
);
5029 BT_LOGV("Array field types differ: different element field types: "
5030 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5031 array_a
->element_type
, array_b
->element_type
);
5039 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*type_a
,
5040 struct bt_ctf_field_type
*type_b
)
5043 struct bt_ctf_field_type_sequence
*sequence_a
;
5044 struct bt_ctf_field_type_sequence
*sequence_b
;
5046 sequence_a
= container_of(type_a
,
5047 struct bt_ctf_field_type_sequence
, parent
);
5048 sequence_b
= container_of(type_b
,
5049 struct bt_ctf_field_type_sequence
, parent
);
5052 if (strcmp(sequence_a
->length_field_name
->str
,
5053 sequence_b
->length_field_name
->str
)) {
5054 BT_LOGV("Sequence field types differ: different length field names: "
5055 "ft-a-length-field-name=%u, ft-b-length-field-name=%u",
5056 sequence_a
->length_field_name
->str
,
5057 sequence_b
->length_field_name
->str
);
5062 ret
= bt_ctf_field_type_compare(sequence_a
->element_type
,
5063 sequence_b
->element_type
);
5065 BT_LOGV("Sequence field types differ: different element field types: "
5066 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5067 sequence_a
->element_type
, sequence_b
->element_type
);
5074 int bt_ctf_field_type_compare(struct bt_ctf_field_type
*type_a
,
5075 struct bt_ctf_field_type
*type_b
)
5079 if (type_a
== type_b
) {
5080 /* Same reference: equal (even if both are NULL) */
5086 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
5092 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
5097 if (type_a
->id
!= type_b
->id
) {
5098 /* Different type IDs */
5099 BT_LOGV("Field types differ: different IDs: "
5100 "ft-a-addr=%p, ft-b-addr=%p, "
5101 "ft-a-id=%s, ft-b-id=%s",
5103 bt_ctf_field_type_id_string(type_a
->id
),
5104 bt_ctf_field_type_id_string(type_b
->id
));
5108 if (type_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
5109 /* Both have unknown type IDs */
5110 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
5114 ret
= type_compare_funcs
[type_a
->id
](type_a
, type_b
);
5116 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
5125 int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*field_type
)
5127 int64_t field_count
= -1;
5128 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5131 case CTF_TYPE_STRUCT
:
5133 bt_ctf_field_type_structure_get_field_count(field_type
);
5135 case CTF_TYPE_VARIANT
:
5137 bt_ctf_field_type_variant_get_field_count(field_type
);
5139 case CTF_TYPE_ARRAY
:
5140 case CTF_TYPE_SEQUENCE
:
5142 * Array and sequence types always contain a single member
5143 * (the element type).
5155 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
5156 struct bt_ctf_field_type
*field_type
, int index
)
5158 struct bt_ctf_field_type
*field
= NULL
;
5159 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5162 case CTF_TYPE_STRUCT
:
5163 bt_ctf_field_type_structure_get_field_by_index(field_type
,
5164 NULL
, &field
, index
);
5166 case CTF_TYPE_VARIANT
:
5168 int ret
= bt_ctf_field_type_variant_get_field_by_index(
5169 field_type
, NULL
, &field
, index
);
5176 case CTF_TYPE_ARRAY
:
5177 field
= bt_ctf_field_type_array_get_element_type(field_type
);
5179 case CTF_TYPE_SEQUENCE
:
5180 field
= bt_ctf_field_type_sequence_get_element_type(field_type
);
5190 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*field_type
,
5193 int field_index
= -1;
5194 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5197 case CTF_TYPE_STRUCT
:
5198 field_index
= bt_ctf_field_type_structure_get_field_name_index(
5201 case CTF_TYPE_VARIANT
:
5202 field_index
= bt_ctf_field_type_variant_get_field_name_index(
5212 struct bt_ctf_field_path
*bt_ctf_field_type_variant_get_tag_field_path(
5213 struct bt_ctf_field_type
*type
)
5215 struct bt_ctf_field_path
*field_path
= NULL
;
5216 struct bt_ctf_field_type_variant
*variant
;
5219 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5223 if (!bt_ctf_field_type_is_variant(type
)) {
5224 BT_LOGW("Invalid parameter: field type is not a variant field type: "
5225 "addr=%p, ft-id=%s", type
,
5226 bt_ctf_field_type_id_string(type
->id
));
5230 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
5232 field_path
= bt_get(variant
->tag_field_path
);
5237 struct bt_ctf_field_path
*bt_ctf_field_type_sequence_get_length_field_path(
5238 struct bt_ctf_field_type
*type
)
5240 struct bt_ctf_field_path
*field_path
= NULL
;
5241 struct bt_ctf_field_type_sequence
*sequence
;
5244 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5248 if (!bt_ctf_field_type_is_sequence(type
)) {
5249 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
5250 "addr=%p, ft-id=%s", type
,
5251 bt_ctf_field_type_id_string(type
->id
));
5255 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
5257 field_path
= bt_get(sequence
->length_field_path
);