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
);
441 BT_LOGV("Added structure/variant field type field: field-ft-addr=%p, "
442 "field-name=\"%s\"", field_type
, field_name
);
448 void bt_ctf_field_type_destroy(struct bt_object
*obj
)
450 struct bt_ctf_field_type
*type
;
451 enum bt_ctf_field_type_id type_id
;
453 BT_LOGD("Destroying field type object: addr=%p", obj
);
454 type
= container_of(obj
, struct bt_ctf_field_type
, base
);
456 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
||
457 type_id
>= BT_CTF_NR_TYPE_IDS
) {
458 BT_LOGW("Unknown field type ID: addr=%p, id=%d", obj
, type_id
);
462 type_destroy_funcs
[type_id
](type
);
466 int bt_ctf_field_type_integer_validate(struct bt_ctf_field_type
*type
)
470 struct bt_ctf_field_type_integer
*integer
=
471 container_of(type
, struct bt_ctf_field_type_integer
,
474 if (integer
->mapped_clock
&& integer
->is_signed
) {
475 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
476 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
477 type
, integer
->mapped_clock
,
478 bt_ctf_clock_class_get_name(integer
->mapped_clock
));
488 struct enumeration_mapping
*get_enumeration_mapping(
489 struct bt_ctf_field_type
*type
, uint64_t index
)
491 struct enumeration_mapping
*mapping
= NULL
;
492 struct bt_ctf_field_type_enumeration
*enumeration
;
494 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
496 if (index
>= enumeration
->entries
->len
) {
497 BT_LOGW("Invalid parameter: index is out of bounds: "
498 "addr=%p, index=%" PRIu64
", count=%u",
499 type
, index
, enumeration
->entries
->len
);
503 mapping
= g_ptr_array_index(enumeration
->entries
, index
);
509 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
510 * Only used when freezing an enumeration.
513 void set_enumeration_range_overlap(
514 struct bt_ctf_field_type
*type
)
517 struct bt_ctf_field_type
*container_type
;
518 struct bt_ctf_field_type_enumeration
*enumeration_type
;
521 BT_LOGV("Setting enumeration field type's overlap flag: addr=%p",
523 enumeration_type
= container_of(type
,
524 struct bt_ctf_field_type_enumeration
, parent
);
526 len
= enumeration_type
->entries
->len
;
527 container_type
= enumeration_type
->container
;
528 is_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
530 for (i
= 0; i
< len
; i
++) {
531 for (j
= i
+ 1; j
< len
; j
++) {
532 struct enumeration_mapping
*mapping
[2];
534 mapping
[0] = get_enumeration_mapping(type
, i
);
535 mapping
[1] = get_enumeration_mapping(type
, j
);
537 if (mapping
[0]->range_start
._signed
538 <= mapping
[1]->range_end
._signed
539 && mapping
[0]->range_end
._signed
540 >= mapping
[1]->range_start
._signed
) {
541 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
545 if (mapping
[0]->range_start
._unsigned
546 <= mapping
[1]->range_end
._unsigned
547 && mapping
[0]->range_end
._unsigned
548 >= mapping
[1]->range_start
._unsigned
) {
549 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
557 if (enumeration_type
->has_overlapping_ranges
) {
558 BT_LOGV_STR("Enumeration field type has overlapping ranges.");
560 BT_LOGV_STR("Enumeration field type has no overlapping ranges.");
565 int bt_ctf_field_type_enumeration_validate(struct bt_ctf_field_type
*type
)
569 struct bt_ctf_field_type_enumeration
*enumeration
=
570 container_of(type
, struct bt_ctf_field_type_enumeration
,
572 struct bt_ctf_field_type
*container_type
=
573 bt_ctf_field_type_enumeration_get_container_type(type
);
575 assert(container_type
);
576 ret
= bt_ctf_field_type_validate(container_type
);
578 BT_LOGW("Invalid enumeration field type: container type is invalid: "
579 "enum-ft-addr=%p, int-ft-addr=%p",
580 type
, container_type
);
584 /* Ensure enum has entries */
585 if (enumeration
->entries
->len
== 0) {
586 BT_LOGW("Invalid enumeration field type: no entries: "
593 BT_PUT(container_type
);
598 int bt_ctf_field_type_sequence_validate(struct bt_ctf_field_type
*type
)
601 struct bt_ctf_field_type
*element_type
= NULL
;
602 struct bt_ctf_field_type_sequence
*sequence
=
603 container_of(type
, struct bt_ctf_field_type_sequence
,
606 /* Length field name should be set at this point */
607 if (sequence
->length_field_name
->len
== 0) {
608 BT_LOGW("Invalid sequence field type: no length field name: "
614 element_type
= bt_ctf_field_type_sequence_get_element_type(type
);
615 assert(element_type
);
616 ret
= bt_ctf_field_type_validate(element_type
);
618 BT_LOGW("Invalid sequence field type: invalid element field type: "
619 "seq-ft-addr=%p, element-ft-add=%p",
624 BT_PUT(element_type
);
630 int bt_ctf_field_type_array_validate(struct bt_ctf_field_type
*type
)
633 struct bt_ctf_field_type
*element_type
= NULL
;
635 element_type
= bt_ctf_field_type_array_get_element_type(type
);
636 assert(element_type
);
637 ret
= bt_ctf_field_type_validate(element_type
);
639 BT_LOGW("Invalid array field type: invalid element field type: "
640 "array-ft-addr=%p, element-ft-add=%p",
644 BT_PUT(element_type
);
649 int bt_ctf_field_type_structure_validate(struct bt_ctf_field_type
*type
)
652 struct bt_ctf_field_type
*child_type
= NULL
;
653 int64_t field_count
= bt_ctf_field_type_structure_get_field_count(type
);
656 assert(field_count
>= 0);
658 for (i
= 0; i
< field_count
; ++i
) {
659 const char *field_name
;
661 ret
= bt_ctf_field_type_structure_get_field_by_index(type
,
662 &field_name
, &child_type
, i
);
664 ret
= bt_ctf_field_type_validate(child_type
);
666 BT_LOGW("Invalid structure field type: "
667 "a contained field type is invalid: "
668 "struct-ft-addr=%p, field-ft-addr=%p, "
669 "field-name=\"%s\", field-index=%" PRId64
,
670 type
, child_type
, field_name
, i
);
684 bt_bool
bt_ctf_field_type_enumeration_has_overlapping_ranges(
685 struct bt_ctf_field_type_enumeration
*enumeration_type
)
687 if (!enumeration_type
->parent
.frozen
) {
688 set_enumeration_range_overlap(&enumeration_type
->parent
);
690 return enumeration_type
->has_overlapping_ranges
;
694 int bt_ctf_field_type_enumeration_get_mapping_name(
695 struct bt_ctf_field_type
*enum_field_type
,
697 const char **mapping_name
)
700 struct enumeration_mapping
*mapping
;
702 assert(enum_field_type
);
703 mapping
= get_enumeration_mapping(enum_field_type
, index
);
706 *mapping_name
= g_quark_to_string(mapping
->string
);
713 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type
*type
)
717 struct bt_ctf_field_type
*child_type
= NULL
;
718 struct bt_ctf_field_type_variant
*variant
=
719 container_of(type
, struct bt_ctf_field_type_variant
,
722 int64_t tag_mappings_count
;
724 if (variant
->tag_name
->len
== 0) {
725 BT_LOGW("Invalid variant field type: no tag field name: "
732 BT_LOGW("Invalid variant field type: no tag field type: "
733 "addr=%p, tag-field-name=\"%s\"", type
,
734 variant
->tag_name
->str
);
739 if (bt_ctf_field_type_enumeration_has_overlapping_ranges(
741 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
742 "variant-ft-addr=%p, tag-field-name=\"%s\", "
743 "enum-ft-addr=%p", type
, variant
->tag_name
->str
,
750 bt_ctf_field_type_enumeration_get_mapping_count(
751 (struct bt_ctf_field_type
*) variant
->tag
);
754 * Validate that each mapping found in the tag has a name which
755 * is also the name of a field in this variant field type.
757 * The opposite is accepted: variant FT fields which cannot be
758 * selected because the variant FT tag has no mapping named as
759 * such. This scenario, while not ideal, cannot cause any error.
761 for (i
= 0; i
< tag_mappings_count
; ++i
) {
763 struct bt_ctf_field_type
*ft
;
765 ret
= bt_ctf_field_type_enumeration_get_mapping_name(
766 (struct bt_ctf_field_type
*) variant
->tag
,
770 ft
= bt_ctf_field_type_variant_get_field_type_by_name(
773 BT_LOGW("Invalid variant field type: "
774 "enumeration tag field type contains a mapping which does not name a variant field type field: "
775 "variant-ft-addr=%p, tag-field-name=\"%s\", "
776 "enum-ft-addr=%p, mapping-name=\"%s\"",
777 type
, variant
->tag_name
->str
, variant
->tag
,
786 field_count
= bt_ctf_field_type_variant_get_field_count(type
);
787 if (field_count
< 0) {
788 BT_LOGW("Invalid variant field type: no fields: "
789 "addr=%p, tag-field-name=\"%s\"",
790 type
, variant
->tag_name
->str
);
795 for (i
= 0; i
< field_count
; ++i
) {
796 const char *field_name
;
798 ret
= bt_ctf_field_type_variant_get_field_by_index(type
,
799 &field_name
, &child_type
, i
);
801 ret
= bt_ctf_field_type_validate(child_type
);
803 BT_LOGW("Invalid variant field type: "
804 "a contained field type is invalid: "
805 "variant-ft-addr=%p, tag-field-name=\"%s\", "
806 "field-ft-addr=%p, field-name=\"%s\", "
807 "field-index=%" PRId64
,
808 type
, variant
->tag_name
->str
, child_type
,
823 * This function validates a given field type without considering
824 * where this field type is located. It only validates the properties
825 * of the given field type and the properties of its children if
829 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
)
832 enum bt_ctf_field_type_id id
= bt_ctf_field_type_get_type_id(type
);
837 /* Already marked as valid */
841 if (type_validate_funcs
[id
]) {
842 ret
= type_validate_funcs
[id
](type
);
845 if (!ret
&& type
->frozen
) {
846 /* Field type is valid */
854 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
856 struct bt_ctf_field_type_integer
*integer
=
857 g_new0(struct bt_ctf_field_type_integer
, 1);
859 BT_LOGD("Creating integer field type object: size=%u", size
);
862 BT_LOGE_STR("Failed to allocate one integer field type.");
866 if (size
== 0 || size
> 64) {
867 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
872 integer
->parent
.id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
873 integer
->size
= size
;
874 integer
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
875 integer
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
876 bt_ctf_field_type_init(&integer
->parent
, TRUE
);
877 BT_LOGD("Created integer field type object: addr=%p, size=%u",
878 &integer
->parent
, size
);
879 return &integer
->parent
;
882 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*type
)
885 struct bt_ctf_field_type_integer
*integer
;
888 BT_LOGW_STR("Invalid parameter: field type is NULL.");
893 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
894 BT_LOGW("Invalid parameter: field type is not an integer field type: "
895 "addr=%p, ft-id=%s", type
,
896 bt_ctf_field_type_id_string(type
->id
));
901 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
902 ret
= (int) integer
->size
;
907 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type
*type
)
910 struct bt_ctf_field_type_integer
*integer
;
913 BT_LOGW_STR("Invalid parameter: field type is NULL.");
918 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
919 BT_LOGW("Invalid parameter: field type is not an integer field type: "
920 "addr=%p, ft-id=%s", type
,
921 bt_ctf_field_type_id_string(type
->id
));
926 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
927 ret
= integer
->is_signed
;
932 bt_bool
bt_ctf_field_type_integer_is_signed(
933 struct bt_ctf_field_type
*int_field_type
)
935 return bt_ctf_field_type_integer_get_signed(int_field_type
) ?
939 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type
*type
,
943 struct bt_ctf_field_type_integer
*integer
;
946 BT_LOGW_STR("Invalid parameter: field type is NULL.");
952 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
958 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
959 BT_LOGW("Invalid parameter: field type is not an integer field type: "
960 "addr=%p, ft-id=%s", type
,
961 bt_ctf_field_type_id_string(type
->id
));
966 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
967 integer
->is_signed
= !!is_signed
;
968 BT_LOGV("Set integer field type's signedness: addr=%p, is-signed=%d",
974 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*type
,
978 struct bt_ctf_field_type_integer
*integer
;
981 BT_LOGW_STR("Invalid parameter: field type is NULL.");
987 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
993 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
994 BT_LOGW("Invalid parameter: field type is not an integer field type: "
995 "addr=%p, ft-id=%s", type
,
996 bt_ctf_field_type_id_string(type
->id
));
1001 if (size
== 0 || size
> 64) {
1002 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
1003 "addr=%p, size=%u", type
, size
);
1008 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1009 integer
->size
= size
;
1010 BT_LOGV("Set integer field type's size: addr=%p, size=%u",
1016 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
1017 struct bt_ctf_field_type
*type
)
1019 enum bt_ctf_integer_base ret
= BT_CTF_INTEGER_BASE_UNKNOWN
;
1020 struct bt_ctf_field_type_integer
*integer
;
1023 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1027 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1028 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1029 "addr=%p, ft-id=%s", type
,
1030 bt_ctf_field_type_id_string(type
->id
));
1034 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1035 ret
= integer
->base
;
1040 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*type
,
1041 enum bt_ctf_integer_base base
)
1046 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1052 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1058 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1059 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1060 "addr=%p, ft-id=%s", type
,
1061 bt_ctf_field_type_id_string(type
->id
));
1067 case BT_CTF_INTEGER_BASE_BINARY
:
1068 case BT_CTF_INTEGER_BASE_OCTAL
:
1069 case BT_CTF_INTEGER_BASE_DECIMAL
:
1070 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1072 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
1073 struct bt_ctf_field_type_integer
, parent
);
1074 integer
->base
= base
;
1078 BT_LOGW("Invalid parameter: unknown integer field type base: "
1079 "addr=%p, base=%d", type
, base
);
1083 BT_LOGV("Set integer field type's base: addr=%p, base=%s",
1084 type
, bt_ctf_integer_base_string(base
));
1090 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
1091 struct bt_ctf_field_type
*type
)
1093 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
1094 struct bt_ctf_field_type_integer
*integer
;
1097 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1101 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1102 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1103 "addr=%p, ft-id=%s", type
,
1104 bt_ctf_field_type_id_string(type
->id
));
1108 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1109 ret
= integer
->encoding
;
1114 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*type
,
1115 enum bt_ctf_string_encoding encoding
)
1118 struct bt_ctf_field_type_integer
*integer
;
1121 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1127 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1133 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1134 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1135 "addr=%p, ft-id=%s", type
,
1136 bt_ctf_field_type_id_string(type
->id
));
1141 if (encoding
< BT_CTF_STRING_ENCODING_NONE
||
1142 encoding
>= BT_CTF_STRING_ENCODING_UNKNOWN
) {
1143 BT_LOGW("Invalid parameter: unknown string encoding: "
1144 "addr=%p, encoding=%d", type
, encoding
);
1149 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1150 integer
->encoding
= encoding
;
1151 BT_LOGV("Set integer field type's encoding: addr=%p, encoding=%s",
1152 type
, bt_ctf_string_encoding_string(encoding
));
1157 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
1158 struct bt_ctf_field_type
*type
)
1160 struct bt_ctf_field_type_integer
*integer
;
1161 struct bt_ctf_clock_class
*clock_class
= NULL
;
1164 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1168 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1169 clock_class
= integer
->mapped_clock
;
1170 bt_get(clock_class
);
1175 int bt_ctf_field_type_integer_set_mapped_clock_class(
1176 struct bt_ctf_field_type
*type
,
1177 struct bt_ctf_clock_class
*clock_class
)
1179 struct bt_ctf_field_type_integer
*integer
;
1183 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1189 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1195 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1201 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1202 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1203 "clock-class-addr=%p, clock-class-name=\"%s\"",
1205 bt_ctf_clock_class_get_name(clock_class
));
1210 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1211 bt_put(integer
->mapped_clock
);
1212 integer
->mapped_clock
= bt_get(clock_class
);
1213 BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
1214 "clock-class-addr=%p, clock-class-name=\"%s\"",
1215 type
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1221 void bt_ctf_field_type_enum_iter_destroy(struct bt_object
*obj
)
1223 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
1225 struct bt_ctf_field_type_enumeration_mapping_iterator
,
1228 bt_put(&iter
->enumeration_type
->parent
);
1233 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1234 bt_ctf_field_type_enumeration_find_mappings_type(
1235 struct bt_ctf_field_type
*type
,
1236 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
1238 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1239 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1242 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1246 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1247 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1248 "addr=%p, ft-id=%s", type
,
1249 bt_ctf_field_type_id_string(type
->id
));
1253 enumeration_type
= container_of(type
,
1254 struct bt_ctf_field_type_enumeration
, parent
);
1255 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
1257 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
1261 bt_object_init(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
1263 iter
->enumeration_type
= enumeration_type
;
1265 iter
->type
= iterator_type
;
1270 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1271 bt_ctf_field_type_enumeration_find_mappings_by_name(
1272 struct bt_ctf_field_type
*type
, const char *name
)
1274 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1276 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1277 type
, ITERATOR_BY_NAME
);
1279 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1280 "ft-addr=%p, mapping-name=\"%s\"", type
, name
);
1284 iter
->u
.name_quark
= g_quark_try_string(name
);
1285 if (!iter
->u
.name_quark
) {
1286 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
1290 /* Advance iterator to first entry, or leave index at -1. */
1291 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1292 /* No entry found. */
1302 int bt_ctf_field_type_enumeration_mapping_iterator_next(
1303 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
1305 struct bt_ctf_field_type_enumeration
*enumeration
;
1306 struct bt_ctf_field_type
*type
;
1307 int i
, ret
= 0, len
;
1310 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1315 enumeration
= iter
->enumeration_type
;
1316 type
= &enumeration
->parent
;
1317 len
= enumeration
->entries
->len
;
1318 for (i
= iter
->index
+ 1; i
< len
; i
++) {
1319 struct enumeration_mapping
*mapping
=
1320 get_enumeration_mapping(type
, i
);
1322 switch (iter
->type
) {
1323 case ITERATOR_BY_NAME
:
1324 if (mapping
->string
== iter
->u
.name_quark
) {
1329 case ITERATOR_BY_SIGNED_VALUE
:
1331 int64_t value
= iter
->u
.signed_value
;
1333 if (value
>= mapping
->range_start
._signed
&&
1334 value
<= mapping
->range_end
._signed
) {
1340 case ITERATOR_BY_UNSIGNED_VALUE
:
1342 uint64_t value
= iter
->u
.unsigned_value
;
1344 if (value
>= mapping
->range_start
._unsigned
&&
1345 value
<= mapping
->range_end
._unsigned
) {
1361 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1362 bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1363 struct bt_ctf_field_type
*type
, int64_t value
)
1365 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1367 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1368 type
, ITERATOR_BY_SIGNED_VALUE
);
1370 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1371 "ft-addr=%p, value=%" PRId64
, type
, value
);
1375 if (bt_ctf_field_type_integer_get_signed(
1376 iter
->enumeration_type
->container
) != 1) {
1377 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
1378 "enum-ft-addr=%p, int-ft-addr=%p",
1379 type
, iter
->enumeration_type
->container
);
1383 iter
->u
.signed_value
= value
;
1385 /* Advance iterator to first entry, or leave index at -1. */
1386 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1387 /* No entry found. */
1397 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1398 bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1399 struct bt_ctf_field_type
*type
, uint64_t value
)
1401 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1404 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1408 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1409 type
, ITERATOR_BY_UNSIGNED_VALUE
);
1411 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1412 "ft-addr=%p, value=%" PRIu64
, type
, value
);
1416 if (bt_ctf_field_type_integer_get_signed(
1417 iter
->enumeration_type
->container
) != 0) {
1418 BT_LOGW("Invalid parameter: enumeration field type is signed: "
1419 "enum-ft-addr=%p, int-ft-addr=%p",
1420 type
, iter
->enumeration_type
->container
);
1423 iter
->u
.unsigned_value
= value
;
1425 /* Advance iterator to first entry, or leave index at -1. */
1426 if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter
)) {
1427 /* No entry found. */
1437 int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
1438 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1439 const char **mapping_name
, int64_t *range_begin
,
1445 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1450 ret
= bt_ctf_field_type_enumeration_get_mapping_signed(
1451 &iter
->enumeration_type
->parent
, iter
->index
,
1452 mapping_name
, range_begin
, range_end
);
1457 int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
1458 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1459 const char **mapping_name
, uint64_t *range_begin
,
1460 uint64_t *range_end
)
1465 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1470 ret
= bt_ctf_field_type_enumeration_get_mapping_unsigned(
1471 &iter
->enumeration_type
->parent
, iter
->index
,
1472 mapping_name
, range_begin
, range_end
);
1477 int bt_ctf_field_type_enumeration_get_mapping_signed(
1478 struct bt_ctf_field_type
*enum_field_type
,
1479 uint64_t index
, const char **mapping_name
, int64_t *range_begin
,
1483 struct enumeration_mapping
*mapping
;
1485 if (!enum_field_type
) {
1486 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1491 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1493 /* get_enumeration_mapping() reports any error */
1499 *mapping_name
= g_quark_to_string(mapping
->string
);
1503 *range_begin
= mapping
->range_start
._signed
;
1507 *range_end
= mapping
->range_end
._signed
;
1513 int bt_ctf_field_type_enumeration_get_mapping_unsigned(
1514 struct bt_ctf_field_type
*enum_field_type
,
1516 const char **mapping_name
, uint64_t *range_begin
,
1517 uint64_t *range_end
)
1520 struct enumeration_mapping
*mapping
;
1522 if (!enum_field_type
) {
1523 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1528 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1530 /* get_enumeration_mapping() reports any error */
1536 *mapping_name
= g_quark_to_string(mapping
->string
);
1540 *range_begin
= mapping
->range_start
._unsigned
;
1544 *range_end
= mapping
->range_end
._unsigned
;
1550 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
1551 struct bt_ctf_field_type
*integer_container_type
)
1553 struct bt_ctf_field_type_enumeration
*enumeration
= NULL
;
1555 BT_LOGD("Creating enumeration field type object: int-ft-addr=%p",
1556 integer_container_type
);
1558 if (!integer_container_type
) {
1559 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1563 if (integer_container_type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1564 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
1565 "container-ft-addr=%p, container-ft-id=%s",
1566 integer_container_type
,
1567 bt_ctf_field_type_id_string(integer_container_type
->id
));
1571 enumeration
= g_new0(struct bt_ctf_field_type_enumeration
, 1);
1573 BT_LOGE_STR("Failed to allocate one enumeration field type.");
1577 enumeration
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
1578 bt_get(integer_container_type
);
1579 enumeration
->container
= integer_container_type
;
1580 enumeration
->entries
= g_ptr_array_new_with_free_func(
1581 (GDestroyNotify
)destroy_enumeration_mapping
);
1582 bt_ctf_field_type_init(&enumeration
->parent
, FALSE
);
1583 BT_LOGD("Created enumeration field type object: addr=%p, "
1584 "int-ft-addr=%p, int-ft-size=%u",
1585 &enumeration
->parent
, integer_container_type
,
1586 bt_ctf_field_type_integer_get_size(integer_container_type
));
1587 return &enumeration
->parent
;
1589 g_free(enumeration
);
1593 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_type(
1594 struct bt_ctf_field_type
*type
)
1596 struct bt_ctf_field_type
*container_type
= NULL
;
1597 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1600 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1604 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1605 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1606 "addr=%p, ft-id=%s", type
,
1607 bt_ctf_field_type_id_string(type
->id
));
1611 enumeration_type
= container_of(type
,
1612 struct bt_ctf_field_type_enumeration
, parent
);
1613 container_type
= enumeration_type
->container
;
1614 bt_get(container_type
);
1616 return container_type
;
1619 int bt_ctf_field_type_enumeration_add_mapping_signed(
1620 struct bt_ctf_field_type
*type
, const char *string
,
1621 int64_t range_start
, int64_t range_end
)
1624 GQuark mapping_name
;
1625 struct enumeration_mapping
*mapping
;
1626 struct bt_ctf_field_type_enumeration
*enumeration
;
1627 char *escaped_string
;
1630 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1636 BT_LOGW_STR("Invalid parameter: string is NULL.");
1642 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1648 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1649 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1650 "addr=%p, ft-id=%s", type
,
1651 bt_ctf_field_type_id_string(type
->id
));
1656 if (range_end
< range_start
) {
1657 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1658 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1659 type
, range_start
, range_end
);
1664 if (strlen(string
) == 0) {
1665 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1666 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1672 escaped_string
= g_strescape(string
, NULL
);
1673 if (!escaped_string
) {
1674 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1675 "mapping-name-addr=%p, mapping-name=\"%s\"",
1676 type
, string
, string
);
1681 mapping
= g_new(struct enumeration_mapping
, 1);
1683 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1687 mapping_name
= g_quark_from_string(escaped_string
);
1688 *mapping
= (struct enumeration_mapping
) {
1689 .range_start
._signed
= range_start
,
1690 .range_end
._signed
= range_end
,
1691 .string
= mapping_name
,
1693 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1695 g_ptr_array_add(enumeration
->entries
, mapping
);
1696 g_ptr_array_sort(enumeration
->entries
,
1697 (GCompareFunc
)compare_enumeration_mappings_signed
);
1698 BT_LOGV("Added mapping to signed enumeration field type: addr=%p, "
1699 "name=\"%s\", range-start=%" PRId64
", "
1700 "range-end=%" PRId64
,
1701 type
, string
, range_start
, range_end
);
1703 free(escaped_string
);
1708 int bt_ctf_field_type_enumeration_add_mapping_unsigned(
1709 struct bt_ctf_field_type
*type
, const char *string
,
1710 uint64_t range_start
, uint64_t range_end
)
1713 GQuark mapping_name
;
1714 struct enumeration_mapping
*mapping
;
1715 struct bt_ctf_field_type_enumeration
*enumeration
;
1716 char *escaped_string
;
1719 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1725 BT_LOGW_STR("Invalid parameter: string is NULL.");
1731 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1737 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1738 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1739 "addr=%p, ft-id=%s", type
,
1740 bt_ctf_field_type_id_string(type
->id
));
1745 if (range_end
< range_start
) {
1746 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1747 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1748 type
, range_start
, range_end
);
1753 if (strlen(string
) == 0) {
1754 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1755 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1761 escaped_string
= g_strescape(string
, NULL
);
1762 if (!escaped_string
) {
1763 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1764 "mapping-name-addr=%p, mapping-name=\"%s\"",
1765 type
, string
, string
);
1770 mapping
= g_new(struct enumeration_mapping
, 1);
1772 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1776 mapping_name
= g_quark_from_string(escaped_string
);
1777 *mapping
= (struct enumeration_mapping
) {
1778 .range_start
._unsigned
= range_start
,
1779 .range_end
._unsigned
= range_end
,
1780 .string
= mapping_name
,
1782 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1784 g_ptr_array_add(enumeration
->entries
, mapping
);
1785 g_ptr_array_sort(enumeration
->entries
,
1786 (GCompareFunc
)compare_enumeration_mappings_unsigned
);
1787 BT_LOGV("Added mapping to unsigned enumeration field type: addr=%p, "
1788 "name=\"%s\", range-start=%" PRIu64
", "
1789 "range-end=%" PRIu64
,
1790 type
, string
, range_start
, range_end
);
1792 free(escaped_string
);
1797 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
1798 struct bt_ctf_field_type
*type
)
1801 struct bt_ctf_field_type_enumeration
*enumeration
;
1804 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1809 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1810 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1811 "addr=%p, ft-id=%s", type
,
1812 bt_ctf_field_type_id_string(type
->id
));
1817 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1819 ret
= (int64_t) enumeration
->entries
->len
;
1824 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
1826 struct bt_ctf_field_type_floating_point
*floating_point
=
1827 g_new0(struct bt_ctf_field_type_floating_point
, 1);
1829 BT_LOGD_STR("Creating floating point number field type object.");
1831 if (!floating_point
) {
1832 BT_LOGE_STR("Failed to allocate one floating point number field type.");
1836 floating_point
->parent
.id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
1837 floating_point
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
1838 floating_point
->mant_dig
= FLT_MANT_DIG
;
1839 bt_ctf_field_type_init(&floating_point
->parent
, TRUE
);
1840 BT_LOGD("Created floating point number field type object: addr=%p, "
1841 "exp-size=%u, mant-size=%u", &floating_point
->parent
,
1842 floating_point
->exp_dig
, floating_point
->mant_dig
);
1844 return floating_point
? &floating_point
->parent
: NULL
;
1847 int bt_ctf_field_type_floating_point_get_exponent_digits(
1848 struct bt_ctf_field_type
*type
)
1851 struct bt_ctf_field_type_floating_point
*floating_point
;
1854 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1859 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1860 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1861 "addr=%p, ft-id=%s", type
,
1862 bt_ctf_field_type_id_string(type
->id
));
1867 floating_point
= container_of(type
,
1868 struct bt_ctf_field_type_floating_point
, parent
);
1869 ret
= (int) floating_point
->exp_dig
;
1874 int bt_ctf_field_type_floating_point_set_exponent_digits(
1875 struct bt_ctf_field_type
*type
,
1876 unsigned int exponent_digits
)
1879 struct bt_ctf_field_type_floating_point
*floating_point
;
1882 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1888 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1894 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1895 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1896 "addr=%p, ft-id=%s", type
,
1897 bt_ctf_field_type_id_string(type
->id
));
1902 floating_point
= container_of(type
,
1903 struct bt_ctf_field_type_floating_point
, parent
);
1904 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1905 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1907 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1908 BT_LOGW("Invalid parameter: invalid exponent size: "
1909 "addr=%p, exp-size=%u", type
, exponent_digits
);
1914 floating_point
->exp_dig
= exponent_digits
;
1915 BT_LOGV("Set floating point number field type's exponent size: addr=%p, "
1916 "exp-size=%u", type
, exponent_digits
);
1921 int bt_ctf_field_type_floating_point_get_mantissa_digits(
1922 struct bt_ctf_field_type
*type
)
1925 struct bt_ctf_field_type_floating_point
*floating_point
;
1928 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1933 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1934 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1935 "addr=%p, ft-id=%s", type
,
1936 bt_ctf_field_type_id_string(type
->id
));
1941 floating_point
= container_of(type
,
1942 struct bt_ctf_field_type_floating_point
, parent
);
1943 ret
= (int) floating_point
->mant_dig
;
1948 int bt_ctf_field_type_floating_point_set_mantissa_digits(
1949 struct bt_ctf_field_type
*type
,
1950 unsigned int mantissa_digits
)
1953 struct bt_ctf_field_type_floating_point
*floating_point
;
1956 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1962 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1968 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1969 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1970 "addr=%p, ft-id=%s", type
,
1971 bt_ctf_field_type_id_string(type
->id
));
1976 floating_point
= container_of(type
,
1977 struct bt_ctf_field_type_floating_point
, parent
);
1979 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1980 (mantissa_digits
!= DBL_MANT_DIG
) &&
1981 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1982 BT_LOGW("Invalid parameter: invalid mantissa size: "
1983 "addr=%p, mant-size=%u", type
, mantissa_digits
);
1988 floating_point
->mant_dig
= mantissa_digits
;
1989 BT_LOGV("Set floating point number field type's mantissa size: addr=%p, "
1990 "mant-size=%u", type
, mantissa_digits
);
1995 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
1997 struct bt_ctf_field_type_structure
*structure
=
1998 g_new0(struct bt_ctf_field_type_structure
, 1);
2000 BT_LOGD_STR("Creating structure field type object.");
2003 BT_LOGE_STR("Failed to allocate one structure field type.");
2007 structure
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
2008 structure
->fields
= g_ptr_array_new_with_free_func(
2009 (GDestroyNotify
)destroy_structure_field
);
2010 structure
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2011 bt_ctf_field_type_init(&structure
->parent
, TRUE
);
2012 BT_LOGD("Created structure field type object: addr=%p",
2013 &structure
->parent
);
2014 return &structure
->parent
;
2019 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*type
,
2020 struct bt_ctf_field_type
*field_type
,
2021 const char *field_name
)
2024 struct bt_ctf_field_type_structure
*structure
;
2027 * TODO: check that `field_type` does not contain `type`,
2031 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2037 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2043 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2049 if (bt_ctf_validate_identifier(field_name
)) {
2050 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2051 "struct-ft-addr=%p, field-name=\"%s\"",
2057 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2058 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2059 "addr=%p, ft-id=%s", type
,
2060 bt_ctf_field_type_id_string(type
->id
));
2065 if (type
== field_type
) {
2066 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
2072 structure
= container_of(type
,
2073 struct bt_ctf_field_type_structure
, parent
);
2074 if (add_structure_field(structure
->fields
,
2075 structure
->field_name_to_index
, field_type
, field_name
)) {
2076 BT_LOGW("Cannot add field to structure field type: "
2077 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2078 type
, field_type
, field_name
);
2083 BT_LOGV("Added structure field type field: struct-ft-addr=%p, "
2084 "field-ft-addr=%p, field-name=\"%s\"", type
,
2085 field_type
, field_name
);
2090 int64_t bt_ctf_field_type_structure_get_field_count(
2091 struct bt_ctf_field_type
*type
)
2094 struct bt_ctf_field_type_structure
*structure
;
2097 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2102 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2103 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2104 "addr=%p, ft-id=%s", type
,
2105 bt_ctf_field_type_id_string(type
->id
));
2110 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2112 ret
= (int64_t) structure
->fields
->len
;
2117 int bt_ctf_field_type_structure_get_field_by_index(
2118 struct bt_ctf_field_type
*type
,
2119 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2122 struct bt_ctf_field_type_structure
*structure
;
2123 struct structure_field
*field
;
2127 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2132 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2133 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2134 "addr=%p, ft-id=%s", type
,
2135 bt_ctf_field_type_id_string(type
->id
));
2140 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2142 if (index
>= structure
->fields
->len
) {
2143 BT_LOGW("Invalid parameter: index is out of bounds: "
2144 "addr=%p, index=%" PRIu64
", count=%u",
2145 type
, index
, structure
->fields
->len
);
2150 field
= g_ptr_array_index(structure
->fields
, index
);
2152 *field_type
= field
->type
;
2153 bt_get(field
->type
);
2156 *field_name
= g_quark_to_string(field
->name
);
2162 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
2163 struct bt_ctf_field_type
*type
,
2168 struct structure_field
*field
;
2169 struct bt_ctf_field_type_structure
*structure
;
2170 struct bt_ctf_field_type
*field_type
= NULL
;
2173 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2178 BT_LOGW_STR("Invalid parameter: name is NULL.");
2182 name_quark
= g_quark_try_string(name
);
2184 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
2188 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2190 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
2191 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2195 field
= structure
->fields
->pdata
[index
];
2196 field_type
= field
->type
;
2202 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
2203 struct bt_ctf_field_type
*enum_tag
, const char *tag_name
)
2205 struct bt_ctf_field_type_variant
*variant
= NULL
;
2207 BT_LOGD("Creating variant field type object: "
2208 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2209 enum_tag
, tag_name
);
2211 if (tag_name
&& bt_ctf_validate_identifier(tag_name
)) {
2212 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2213 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2214 enum_tag
, tag_name
);
2218 variant
= g_new0(struct bt_ctf_field_type_variant
, 1);
2220 BT_LOGE_STR("Failed to allocate one variant field type.");
2224 variant
->parent
.id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
2225 variant
->tag_name
= g_string_new(tag_name
);
2226 variant
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2227 variant
->fields
= g_ptr_array_new_with_free_func(
2228 (GDestroyNotify
) destroy_structure_field
);
2231 variant
->tag
= container_of(enum_tag
,
2232 struct bt_ctf_field_type_enumeration
, parent
);
2235 bt_ctf_field_type_init(&variant
->parent
, TRUE
);
2236 /* A variant's alignment is undefined */
2237 variant
->parent
.alignment
= 0;
2238 BT_LOGD("Created variant field type object: addr=%p, "
2239 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2240 &variant
->parent
, enum_tag
, tag_name
);
2241 return &variant
->parent
;
2246 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_type(
2247 struct bt_ctf_field_type
*type
)
2249 struct bt_ctf_field_type_variant
*variant
;
2250 struct bt_ctf_field_type
*tag_type
= NULL
;
2253 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2257 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2258 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2259 "addr=%p, ft-id=%s", type
,
2260 bt_ctf_field_type_id_string(type
->id
));
2264 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2265 if (!variant
->tag
) {
2266 BT_LOGV("Variant field type has no tag field type: "
2271 tag_type
= &variant
->tag
->parent
;
2277 const char *bt_ctf_field_type_variant_get_tag_name(
2278 struct bt_ctf_field_type
*type
)
2280 struct bt_ctf_field_type_variant
*variant
;
2281 const char *tag_name
= NULL
;
2284 BT_LOGW_STR("Invalid parameter: field type is NULL.");
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
));
2295 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2296 if (variant
->tag_name
->len
== 0) {
2297 BT_LOGV("Variant field type has no tag field name: "
2302 tag_name
= variant
->tag_name
->str
;
2307 int bt_ctf_field_type_variant_set_tag_name(
2308 struct bt_ctf_field_type
*type
, const char *name
)
2311 struct bt_ctf_field_type_variant
*variant
;
2314 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2320 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2326 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2327 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2328 "addr=%p, ft-id=%s", type
,
2329 bt_ctf_field_type_id_string(type
->id
));
2334 if (bt_ctf_validate_identifier(name
)) {
2335 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2336 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2342 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2343 g_string_assign(variant
->tag_name
, name
);
2344 BT_LOGV("Set variant field type's tag field name: addr=%p, "
2345 "tag-field-name=\"%s\"", type
, name
);
2350 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*type
,
2351 struct bt_ctf_field_type
*field_type
,
2352 const char *field_name
)
2356 struct bt_ctf_field_type_variant
*variant
;
2357 GQuark field_name_quark
= g_quark_from_string(field_name
);
2360 * TODO: check that `field_type` does not contain `type`,
2364 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2370 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2376 if (bt_ctf_validate_identifier(field_name
)) {
2377 BT_LOGW("Invalid parameter: field name is not a valid CTF identifier: "
2378 "variant-ft-addr=%p, field-name=\"%s\"",
2384 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2385 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2386 "addr=%p, ft-id=%s", type
,
2387 bt_ctf_field_type_id_string(type
->id
));
2392 if (type
== field_type
) {
2393 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2399 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2401 /* The user has explicitly provided a tag; validate against it. */
2405 /* Make sure this name is present in the enum tag */
2406 for (i
= 0; i
< variant
->tag
->entries
->len
; i
++) {
2407 struct enumeration_mapping
*mapping
=
2408 g_ptr_array_index(variant
->tag
->entries
, i
);
2410 if (mapping
->string
== field_name_quark
) {
2417 /* Validation failed */
2418 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2419 "variant-ft-addr=%p, tag-ft-addr=%p, "
2420 "tag-field-name=\"%s\""
2421 "field-ft-addr=%p, field-name=\"%s\"",
2422 type
, variant
->tag
, variant
->tag_name
->str
,
2423 field_type
, field_name
);
2429 if (add_structure_field(variant
->fields
, variant
->field_name_to_index
,
2430 field_type
, field_name
)) {
2431 BT_LOGW("Cannot add field to variant field type: "
2432 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2433 type
, field_type
, field_name
);
2438 BT_LOGV("Added variant field type field: variant-ft-addr=%p, "
2439 "field-ft-addr=%p, field-name=\"%s\"", type
,
2440 field_type
, field_name
);
2446 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
2447 struct bt_ctf_field_type
*type
,
2448 const char *field_name
)
2452 struct structure_field
*field
;
2453 struct bt_ctf_field_type_variant
*variant
;
2454 struct bt_ctf_field_type
*field_type
= NULL
;
2457 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2462 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2466 name_quark
= g_quark_try_string(field_name
);
2468 BT_LOGE("Cannot get GQuark: string=\"%s\"", field_name
);
2472 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2473 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
2474 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2478 field
= g_ptr_array_index(variant
->fields
, index
);
2479 field_type
= field
->type
;
2485 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
2486 struct bt_ctf_field_type
*type
,
2487 struct bt_ctf_field
*tag
)
2490 const char *enum_value
;
2491 struct bt_ctf_field_type
*field_type
= NULL
;
2492 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
2495 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2500 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
2504 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2505 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2506 "addr=%p, ft-id=%s", type
,
2507 bt_ctf_field_type_id_string(type
->id
));
2511 iter
= bt_ctf_field_enumeration_get_mappings(tag
);
2513 BT_LOGE("Cannot get enumeration field type mapping iterator from enumeration field: "
2514 "enum-field-addr=%p", tag
);
2518 ret
= bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter
,
2519 &enum_value
, NULL
, NULL
);
2521 BT_LOGW("Cannot get enumeration field type mapping iterator's current mapping: "
2522 "iter-addr=%p", iter
);
2526 field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
2533 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*type
)
2536 struct bt_ctf_field_type_variant
*variant
;
2539 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2544 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2545 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2546 "addr=%p, ft-id=%s", type
,
2547 bt_ctf_field_type_id_string(type
->id
));
2552 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2554 ret
= (int64_t) variant
->fields
->len
;
2560 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*type
,
2561 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2564 struct bt_ctf_field_type_variant
*variant
;
2565 struct structure_field
*field
;
2569 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2574 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2575 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2576 "addr=%p, ft-id=%s", type
,
2577 bt_ctf_field_type_id_string(type
->id
));
2582 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2584 if (index
>= variant
->fields
->len
) {
2585 BT_LOGW("Invalid parameter: index is out of bounds: "
2586 "addr=%p, index=%" PRIu64
", count=%u",
2587 type
, index
, variant
->fields
->len
);
2592 field
= g_ptr_array_index(variant
->fields
, index
);
2594 *field_type
= field
->type
;
2595 bt_get(field
->type
);
2598 *field_name
= g_quark_to_string(field
->name
);
2604 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
2605 struct bt_ctf_field_type
*element_type
,
2606 unsigned int length
)
2608 struct bt_ctf_field_type_array
*array
= NULL
;
2610 BT_LOGD("Creating array field type object: element-ft-addr=%p, "
2611 "length=%u", element_type
, length
);
2613 if (!element_type
) {
2614 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2619 BT_LOGW_STR("Invalid parameter: length is zero.");
2623 array
= g_new0(struct bt_ctf_field_type_array
, 1);
2625 BT_LOGE_STR("Failed to allocate one array field type.");
2629 array
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
2630 bt_get(element_type
);
2631 array
->element_type
= element_type
;
2632 array
->length
= length
;
2633 bt_ctf_field_type_init(&array
->parent
, FALSE
);
2634 BT_LOGD("Created array field type object: addr=%p, "
2635 "element-ft-addr=%p, length=%u",
2636 &array
->parent
, element_type
, length
);
2637 return &array
->parent
;
2642 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_type(
2643 struct bt_ctf_field_type
*type
)
2645 struct bt_ctf_field_type
*ret
= NULL
;
2646 struct bt_ctf_field_type_array
*array
;
2649 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2653 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2654 BT_LOGW("Invalid parameter: field type is not an array field type: "
2655 "addr=%p, ft-id=%s", type
,
2656 bt_ctf_field_type_id_string(type
->id
));
2660 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2661 ret
= array
->element_type
;
2668 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*type
,
2669 struct bt_ctf_field_type
*element_type
)
2672 struct bt_ctf_field_type_array
*array
;
2675 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2680 if (!element_type
) {
2681 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2686 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2687 BT_LOGW("Invalid parameter: field type is not an array field type: "
2688 "addr=%p, ft-id=%s", type
,
2689 bt_ctf_field_type_id_string(type
->id
));
2694 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2696 if (array
->element_type
) {
2697 BT_PUT(array
->element_type
);
2700 array
->element_type
= element_type
;
2701 bt_get(array
->element_type
);
2702 BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
2703 "element-ft-addr=%p", type
, element_type
);
2709 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*type
)
2712 struct bt_ctf_field_type_array
*array
;
2715 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2720 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2721 BT_LOGW("Invalid parameter: field type is not an array field type: "
2722 "addr=%p, ft-id=%s", type
,
2723 bt_ctf_field_type_id_string(type
->id
));
2728 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2729 ret
= (int64_t) array
->length
;
2734 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
2735 struct bt_ctf_field_type
*element_type
,
2736 const char *length_field_name
)
2738 struct bt_ctf_field_type_sequence
*sequence
= NULL
;
2740 BT_LOGD("Creating sequence field type object: element-ft-addr=%p, "
2741 "length-field-name=\"%s\"", element_type
, length_field_name
);
2743 if (!element_type
) {
2744 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2748 if (bt_ctf_validate_identifier(length_field_name
)) {
2749 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
2750 "length-field-name=\"%s\"", length_field_name
);
2754 sequence
= g_new0(struct bt_ctf_field_type_sequence
, 1);
2756 BT_LOGE_STR("Failed to allocate one sequence field type.");
2760 sequence
->parent
.id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
2761 bt_get(element_type
);
2762 sequence
->element_type
= element_type
;
2763 sequence
->length_field_name
= g_string_new(length_field_name
);
2764 bt_ctf_field_type_init(&sequence
->parent
, FALSE
);
2765 BT_LOGD("Created sequence field type object: addr=%p, "
2766 "element-ft-addr=%p, length-field-name=\"%s\"",
2767 &sequence
->parent
, element_type
, length_field_name
);
2768 return &sequence
->parent
;
2773 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_type(
2774 struct bt_ctf_field_type
*type
)
2776 struct bt_ctf_field_type
*ret
= NULL
;
2777 struct bt_ctf_field_type_sequence
*sequence
;
2780 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2784 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2785 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2786 "addr=%p, ft-id=%s", type
,
2787 bt_ctf_field_type_id_string(type
->id
));
2791 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2793 ret
= sequence
->element_type
;
2800 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*type
,
2801 struct bt_ctf_field_type
*element_type
)
2804 struct bt_ctf_field_type_sequence
*sequence
;
2807 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2812 if (!element_type
) {
2813 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2818 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2819 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2820 "addr=%p, ft-id=%s", type
,
2821 bt_ctf_field_type_id_string(type
->id
));
2826 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
, parent
);
2827 if (sequence
->element_type
) {
2828 BT_PUT(sequence
->element_type
);
2831 sequence
->element_type
= element_type
;
2832 bt_get(sequence
->element_type
);
2833 BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
2834 "element-ft-addr=%p", type
, element_type
);
2840 const char *bt_ctf_field_type_sequence_get_length_field_name(
2841 struct bt_ctf_field_type
*type
)
2843 const char *ret
= NULL
;
2844 struct bt_ctf_field_type_sequence
*sequence
;
2847 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2851 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2852 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2853 "addr=%p, ft-id=%s", type
,
2854 bt_ctf_field_type_id_string(type
->id
));
2858 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2860 ret
= sequence
->length_field_name
->str
;
2865 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
2867 struct bt_ctf_field_type_string
*string
=
2868 g_new0(struct bt_ctf_field_type_string
, 1);
2870 BT_LOGD_STR("Creating string field type object.");
2873 BT_LOGE_STR("Failed to allocate one string field type.");
2877 string
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRING
;
2878 bt_ctf_field_type_init(&string
->parent
, TRUE
);
2879 string
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2880 string
->parent
.alignment
= CHAR_BIT
;
2881 BT_LOGD("Created string field type object: addr=%p", &string
->parent
);
2882 return &string
->parent
;
2885 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
2886 struct bt_ctf_field_type
*type
)
2888 struct bt_ctf_field_type_string
*string
;
2889 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
2892 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2896 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2897 BT_LOGW("Invalid parameter: field type is not a string field type: "
2898 "addr=%p, ft-id=%s", type
,
2899 bt_ctf_field_type_id_string(type
->id
));
2903 string
= container_of(type
, struct bt_ctf_field_type_string
,
2905 ret
= string
->encoding
;
2910 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*type
,
2911 enum bt_ctf_string_encoding encoding
)
2914 struct bt_ctf_field_type_string
*string
;
2917 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2922 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2923 BT_LOGW("Invalid parameter: field type is not a string field type: "
2924 "addr=%p, ft-id=%s", type
,
2925 bt_ctf_field_type_id_string(type
->id
));
2930 if ((encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2931 encoding
!= BT_CTF_STRING_ENCODING_ASCII
)) {
2932 BT_LOGW("Invalid parameter: unknown string encoding: "
2933 "addr=%p, encoding=%d", type
, encoding
);
2938 string
= container_of(type
, struct bt_ctf_field_type_string
, parent
);
2939 string
->encoding
= encoding
;
2940 BT_LOGV("Set string field type's encoding: addr=%p, encoding=%s",
2941 type
, bt_ctf_string_encoding_string(encoding
));
2946 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*type
)
2949 enum bt_ctf_field_type_id type_id
;
2952 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2958 ret
= (int) type
->alignment
;
2962 type_id
= bt_ctf_field_type_get_type_id(type
);
2964 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2966 struct bt_ctf_field_type
*element
=
2967 bt_ctf_field_type_sequence_get_element_type(type
);
2970 ret
= bt_ctf_field_type_get_alignment(element
);
2974 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2976 struct bt_ctf_field_type
*element
=
2977 bt_ctf_field_type_array_get_element_type(type
);
2980 ret
= bt_ctf_field_type_get_alignment(element
);
2984 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2986 int64_t i
, element_count
;
2988 element_count
= bt_ctf_field_type_structure_get_field_count(
2990 assert(element_count
>= 0);
2992 for (i
= 0; i
< element_count
; i
++) {
2993 struct bt_ctf_field_type
*field
;
2994 int field_alignment
;
2996 ret
= bt_ctf_field_type_structure_get_field_by_index(
2997 type
, NULL
, &field
, i
);
3000 field_alignment
= bt_ctf_field_type_get_alignment(
3003 if (field_alignment
< 0) {
3004 ret
= field_alignment
;
3008 type
->alignment
= MAX(field_alignment
, type
->alignment
);
3010 ret
= (int) type
->alignment
;
3013 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
3014 BT_LOGW("Invalid parameter: unknown field type ID: "
3015 "addr=%p, ft-id=%d", type
, type_id
);
3019 ret
= (int) type
->alignment
;
3027 int is_power_of_two(unsigned int value
)
3029 return ((value
& (value
- 1)) == 0) && value
> 0;
3032 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
3033 unsigned int alignment
)
3036 enum bt_ctf_field_type_id type_id
;
3038 /* Alignment must be a power of two */
3040 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3046 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3052 if (!is_power_of_two(alignment
)) {
3053 BT_LOGW("Invalid parameter: alignment is not a power of two: "
3054 "addr=%p, align=%u", type
, alignment
);
3059 type_id
= bt_ctf_field_type_get_type_id(type
);
3060 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3061 BT_LOGW("Invalid parameter: unknown field type ID: "
3062 "addr=%p, ft-id=%d", type
, type_id
);
3067 if (type
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&&
3068 alignment
!= CHAR_BIT
) {
3069 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
3070 "addr=%p, align=%u", CHAR_BIT
, type
, alignment
);
3075 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
3076 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
3077 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
3078 /* Setting an alignment on these types makes no sense */
3079 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
3080 "addr=%p, ft-id=%s", type
,
3081 bt_ctf_field_type_id_string(type
->id
));
3086 type
->alignment
= alignment
;
3088 BT_LOGV("Set field type's alignment: addr=%p, align=%u",
3094 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
3095 struct bt_ctf_field_type
*type
)
3097 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
3100 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3105 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3107 struct bt_ctf_field_type_integer
*integer
= container_of(
3108 type
, struct bt_ctf_field_type_integer
, parent
);
3109 ret
= integer
->user_byte_order
;
3112 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3114 struct bt_ctf_field_type_enumeration
*enum_ft
= container_of(
3115 type
, struct bt_ctf_field_type_enumeration
, parent
);
3116 ret
= bt_ctf_field_type_get_byte_order(enum_ft
->container
);
3119 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
3121 struct bt_ctf_field_type_floating_point
*floating_point
=
3123 struct bt_ctf_field_type_floating_point
,
3125 ret
= floating_point
->user_byte_order
;
3129 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
3130 "addr=%p, ft-id=%s", type
,
3131 bt_ctf_field_type_id_string(type
->id
));
3135 assert(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
3136 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
3137 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
3138 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
3144 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
3145 enum bt_ctf_byte_order byte_order
)
3150 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3156 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3162 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
3163 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
3164 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
3165 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
3166 BT_LOGW("Invalid parameter: unknown byte order: "
3167 "addr=%p, bo=%s", type
,
3168 bt_ctf_byte_order_string(byte_order
));
3173 if (set_byte_order_funcs
[type
->id
]) {
3174 set_byte_order_funcs
[type
->id
](type
, byte_order
);
3177 BT_LOGV("Set field type's byte order: addr=%p, bo=%s",
3178 type
, bt_ctf_byte_order_string(byte_order
));
3184 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
3185 struct bt_ctf_field_type
*type
)
3188 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3189 return BT_CTF_FIELD_TYPE_ID_UNKNOWN
;
3195 int bt_ctf_field_type_is_integer(struct bt_ctf_field_type
*type
)
3197 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
;
3200 int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type
*type
)
3202 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_FLOAT
;
3205 int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type
*type
)
3207 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ENUM
;
3210 int bt_ctf_field_type_is_string(struct bt_ctf_field_type
*type
)
3212 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRING
;
3215 int bt_ctf_field_type_is_structure(struct bt_ctf_field_type
*type
)
3217 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
;
3220 int bt_ctf_field_type_is_array(struct bt_ctf_field_type
*type
)
3222 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ARRAY
;
3225 int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type
*type
)
3227 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
3230 int bt_ctf_field_type_is_variant(struct bt_ctf_field_type
*type
)
3232 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_VARIANT
;
3235 /* Pre-2.0 CTF writer backward compatibility */
3236 void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
)
3241 /* Pre-2.0 CTF writer backward compatibility */
3242 void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
)
3248 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
)
3250 if (!type
|| type
->frozen
) {
3254 BT_LOGD("Freezing field type: addr=%p", type
);
3259 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
3260 struct bt_ctf_field_type_variant
*variant
,
3263 struct bt_ctf_field_type
*type
= NULL
;
3264 GQuark field_name_quark
;
3266 struct structure_field
*field_entry
;
3267 struct range_overlap_query query
= {
3268 .range_start
._signed
= tag_value
,
3269 .range_end
._signed
= tag_value
,
3274 g_ptr_array_foreach(variant
->tag
->entries
, check_ranges_overlap
,
3276 if (!query
.overlaps
) {
3280 field_name_quark
= query
.mapping_name
;
3281 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3282 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3286 field_entry
= g_ptr_array_index(variant
->fields
, (size_t) index
);
3287 type
= field_entry
->type
;
3293 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
3294 struct bt_ctf_field_type_variant
*variant
,
3297 struct bt_ctf_field_type
*type
= NULL
;
3298 GQuark field_name_quark
;
3300 struct structure_field
*field_entry
;
3301 struct range_overlap_query query
= {
3302 .range_start
._unsigned
= tag_value
,
3303 .range_end
._unsigned
= tag_value
,
3308 g_ptr_array_foreach(variant
->tag
->entries
,
3309 check_ranges_overlap_unsigned
,
3311 if (!query
.overlaps
) {
3315 field_name_quark
= query
.mapping_name
;
3316 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3317 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3321 field_entry
= g_ptr_array_index(variant
->fields
, (size_t)index
);
3322 type
= field_entry
->type
;
3328 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
3329 struct metadata_context
*context
)
3336 BT_LOGD("Serializing field type's metadata: "
3337 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3339 /* Make sure field type is valid before serializing it */
3340 ret
= bt_ctf_field_type_validate(type
);
3342 BT_LOGW_STR("Cannot serialize field type's metadata: field type is invalid.");
3346 ret
= type
->serialize(type
, context
);
3351 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*type
)
3353 struct bt_ctf_field_type
*copy
= NULL
;
3355 BT_LOGD("Copying field type object: addr=%p", type
);
3358 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3362 copy
= type_copy_funcs
[type
->id
](type
);
3364 BT_LOGE_STR("Cannot copy field type.");
3368 copy
->alignment
= type
->alignment
;
3369 BT_LOGD("Copied field type object: copy-ft-addr=%p", copy
);
3375 int bt_ctf_field_type_structure_get_field_name_index(
3376 struct bt_ctf_field_type
*type
, const char *name
)
3381 struct bt_ctf_field_type_structure
*structure
;
3384 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3390 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3395 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
3396 BT_LOGW("Invalid parameter: field type is not a structure field type: "
3397 "addr=%p, ft-id=%s", type
,
3398 bt_ctf_field_type_id_string(type
->id
));
3403 name_quark
= g_quark_try_string(name
);
3405 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
3410 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
3412 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
3413 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
3423 int bt_ctf_field_type_variant_get_field_name_index(
3424 struct bt_ctf_field_type
*type
, const char *name
)
3429 struct bt_ctf_field_type_variant
*variant
;
3432 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3438 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3443 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3444 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3445 "addr=%p, ft-id=%s", type
,
3446 bt_ctf_field_type_id_string(type
->id
));
3451 name_quark
= g_quark_try_string(name
);
3453 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
3458 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3460 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3461 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
3471 int bt_ctf_field_type_sequence_set_length_field_path(
3472 struct bt_ctf_field_type
*type
,
3473 struct bt_ctf_field_path
*path
)
3476 struct bt_ctf_field_type_sequence
*sequence
;
3479 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3484 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
3485 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
3486 "addr=%p, ft-id=%s", type
,
3487 bt_ctf_field_type_id_string(type
->id
));
3492 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
3495 BT_MOVE(sequence
->length_field_path
, path
);
3496 BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
3497 "field-path-addr=%p", type
, path
);
3503 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
3504 struct bt_ctf_field_path
*path
)
3507 struct bt_ctf_field_type_variant
*variant
;
3510 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3515 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3516 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3517 "addr=%p, ft-id=%s", type
,
3518 bt_ctf_field_type_id_string(type
->id
));
3523 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3526 BT_MOVE(variant
->tag_field_path
, path
);
3527 BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
3528 "field-path-addr=%p", type
, path
);
3534 int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type
*type
,
3535 struct bt_ctf_field_type
*tag
)
3538 struct bt_ctf_field_type_variant
*variant
;
3541 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3547 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
3552 if (bt_ctf_field_type_get_type_id(tag
) != BT_CTF_FIELD_TYPE_ID_ENUM
) {
3553 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
3554 "addr=%p, ft-id=%s", type
,
3555 bt_ctf_field_type_id_string(type
->id
));
3560 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3564 bt_put(&variant
->tag
->parent
);
3566 variant
->tag
= container_of(tag
, struct bt_ctf_field_type_enumeration
,
3568 BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
3569 "tag-ft-addr=%p", type
, tag
);
3575 void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type
*type
)
3577 struct bt_ctf_field_type_integer
*integer
=
3578 (struct bt_ctf_field_type_integer
*) type
;
3584 BT_LOGD("Destroying integer field type object: addr=%p", type
);
3585 bt_put(integer
->mapped_clock
);
3590 void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type
*type
)
3592 struct bt_ctf_field_type_enumeration
*enumeration
=
3593 (struct bt_ctf_field_type_enumeration
*) type
;
3599 BT_LOGD("Destroying enumeration field type object: addr=%p", type
);
3600 g_ptr_array_free(enumeration
->entries
, TRUE
);
3601 bt_put(enumeration
->container
);
3602 g_free(enumeration
);
3606 void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type
*type
)
3608 struct bt_ctf_field_type_floating_point
*floating_point
=
3609 (struct bt_ctf_field_type_floating_point
*) type
;
3615 BT_LOGD("Destroying floating point number field type object: addr=%p", type
);
3616 g_free(floating_point
);
3620 void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type
*type
)
3622 struct bt_ctf_field_type_structure
*structure
=
3623 (struct bt_ctf_field_type_structure
*) type
;
3629 BT_LOGD("Destroying structure field type object: addr=%p", type
);
3630 g_ptr_array_free(structure
->fields
, TRUE
);
3631 g_hash_table_destroy(structure
->field_name_to_index
);
3636 void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type
*type
)
3638 struct bt_ctf_field_type_variant
*variant
=
3639 (struct bt_ctf_field_type_variant
*) type
;
3645 BT_LOGD("Destroying variant field type object: addr=%p", type
);
3646 g_ptr_array_free(variant
->fields
, TRUE
);
3647 g_hash_table_destroy(variant
->field_name_to_index
);
3648 g_string_free(variant
->tag_name
, TRUE
);
3649 bt_put(&variant
->tag
->parent
);
3650 BT_PUT(variant
->tag_field_path
);
3655 void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type
*type
)
3657 struct bt_ctf_field_type_array
*array
=
3658 (struct bt_ctf_field_type_array
*) type
;
3664 BT_LOGD("Destroying array field type object: addr=%p", type
);
3665 bt_put(array
->element_type
);
3670 void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type
*type
)
3672 struct bt_ctf_field_type_sequence
*sequence
=
3673 (struct bt_ctf_field_type_sequence
*) type
;
3679 BT_LOGD("Destroying sequence field type object: addr=%p", type
);
3680 bt_put(sequence
->element_type
);
3681 g_string_free(sequence
->length_field_name
, TRUE
);
3682 BT_PUT(sequence
->length_field_path
);
3687 void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type
*type
)
3689 struct bt_ctf_field_type_string
*string
=
3690 (struct bt_ctf_field_type_string
*) type
;
3696 BT_LOGD("Destroying string field type object: addr=%p", type
);
3701 void generic_field_type_freeze(struct bt_ctf_field_type
*type
)
3707 void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type
*type
)
3709 struct bt_ctf_field_type_integer
*integer_type
= container_of(
3710 type
, struct bt_ctf_field_type_integer
, parent
);
3712 BT_LOGD("Freezing integer field type object: addr=%p", type
);
3714 if (integer_type
->mapped_clock
) {
3715 bt_ctf_clock_class_freeze(integer_type
->mapped_clock
);
3718 generic_field_type_freeze(type
);
3722 void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type
*type
)
3724 struct bt_ctf_field_type_enumeration
*enumeration_type
= container_of(
3725 type
, struct bt_ctf_field_type_enumeration
, parent
);
3727 BT_LOGD("Freezing enumeration field type object: addr=%p", type
);
3728 set_enumeration_range_overlap(type
);
3729 generic_field_type_freeze(type
);
3730 bt_ctf_field_type_freeze(enumeration_type
->container
);
3734 void freeze_structure_field(struct structure_field
*field
)
3736 BT_LOGD("Freezing structure field type field: addr=%p", field
);
3737 bt_ctf_field_type_freeze(field
->type
);
3741 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*type
)
3743 struct bt_ctf_field_type_structure
*structure_type
= container_of(
3744 type
, struct bt_ctf_field_type_structure
, parent
);
3746 /* Cache the alignment */
3747 BT_LOGD("Freezing structure field type object: addr=%p", type
);
3748 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3749 generic_field_type_freeze(type
);
3750 g_ptr_array_foreach(structure_type
->fields
,
3751 (GFunc
) freeze_structure_field
, NULL
);
3755 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*type
)
3757 struct bt_ctf_field_type_variant
*variant_type
= container_of(
3758 type
, struct bt_ctf_field_type_variant
, parent
);
3760 BT_LOGD("Freezing variant field type object: addr=%p", type
);
3761 generic_field_type_freeze(type
);
3762 g_ptr_array_foreach(variant_type
->fields
,
3763 (GFunc
) freeze_structure_field
, NULL
);
3767 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*type
)
3769 struct bt_ctf_field_type_array
*array_type
= container_of(
3770 type
, struct bt_ctf_field_type_array
, parent
);
3772 /* Cache the alignment */
3773 BT_LOGD("Freezing array field type object: addr=%p", type
);
3774 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3775 generic_field_type_freeze(type
);
3776 bt_ctf_field_type_freeze(array_type
->element_type
);
3780 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*type
)
3782 struct bt_ctf_field_type_sequence
*sequence_type
= container_of(
3783 type
, struct bt_ctf_field_type_sequence
, parent
);
3785 /* Cache the alignment */
3786 BT_LOGD("Freezing sequence field type object: addr=%p", type
);
3787 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3788 generic_field_type_freeze(type
);
3789 bt_ctf_field_type_freeze(sequence_type
->element_type
);
3793 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
3795 const char *encoding_string
;
3798 case BT_CTF_STRING_ENCODING_NONE
:
3799 encoding_string
= "none";
3801 case BT_CTF_STRING_ENCODING_ASCII
:
3802 encoding_string
= "ASCII";
3804 case BT_CTF_STRING_ENCODING_UTF8
:
3805 encoding_string
= "UTF8";
3808 encoding_string
= "unknown";
3812 return encoding_string
;
3816 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
3818 const char *base_string
;
3821 case BT_CTF_INTEGER_BASE_DECIMAL
:
3822 base_string
= "decimal";
3824 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
3825 base_string
= "hexadecimal";
3827 case BT_CTF_INTEGER_BASE_OCTAL
:
3828 base_string
= "octal";
3830 case BT_CTF_INTEGER_BASE_BINARY
:
3831 base_string
= "binary";
3834 base_string
= "unknown";
3842 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*type
,
3843 struct metadata_context
*context
)
3845 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
3846 struct bt_ctf_field_type_integer
, parent
);
3849 BT_LOGD("Serializing integer field type's metadata: "
3850 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3851 g_string_append_printf(context
->string
,
3852 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
3853 integer
->size
, type
->alignment
,
3854 (integer
->is_signed
? "true" : "false"),
3855 get_encoding_string(integer
->encoding
),
3856 get_integer_base_string(integer
->base
),
3857 get_byte_order_string(integer
->user_byte_order
));
3858 if (integer
->mapped_clock
) {
3859 const char *clock_name
= bt_ctf_clock_class_get_name(
3860 integer
->mapped_clock
);
3863 g_string_append_printf(context
->string
,
3864 "; map = clock.%s.value", clock_name
);
3867 g_string_append(context
->string
, "; }");
3872 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*type
,
3873 struct metadata_context
*context
)
3877 struct bt_ctf_field_type_enumeration
*enumeration
= container_of(type
,
3878 struct bt_ctf_field_type_enumeration
, parent
);
3879 struct bt_ctf_field_type
*container_type
;
3880 int container_signed
;
3882 BT_LOGD("Serializing enumeration field type's metadata: "
3883 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3884 container_type
= bt_ctf_field_type_enumeration_get_container_type(type
);
3885 assert(container_type
);
3886 container_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
3887 assert(container_signed
>= 0);
3888 g_string_append(context
->string
, "enum : ");
3889 ret
= bt_ctf_field_type_serialize(enumeration
->container
, context
);
3891 BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
3892 "container-ft-addr=%p", enumeration
->container
);
3896 g_string_append(context
->string
, " { ");
3897 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
3898 struct enumeration_mapping
*mapping
=
3899 enumeration
->entries
->pdata
[entry
];
3901 if (container_signed
) {
3902 if (mapping
->range_start
._signed
==
3903 mapping
->range_end
._signed
) {
3904 g_string_append_printf(context
->string
,
3905 "\"%s\" = %" PRId64
,
3906 g_quark_to_string(mapping
->string
),
3907 mapping
->range_start
._signed
);
3909 g_string_append_printf(context
->string
,
3910 "\"%s\" = %" PRId64
" ... %" PRId64
,
3911 g_quark_to_string(mapping
->string
),
3912 mapping
->range_start
._signed
,
3913 mapping
->range_end
._signed
);
3916 if (mapping
->range_start
._unsigned
==
3917 mapping
->range_end
._unsigned
) {
3918 g_string_append_printf(context
->string
,
3919 "\"%s\" = %" PRIu64
,
3920 g_quark_to_string(mapping
->string
),
3921 mapping
->range_start
._unsigned
);
3923 g_string_append_printf(context
->string
,
3924 "\"%s\" = %" PRIu64
" ... %" PRIu64
,
3925 g_quark_to_string(mapping
->string
),
3926 mapping
->range_start
._unsigned
,
3927 mapping
->range_end
._unsigned
);
3931 g_string_append(context
->string
,
3932 ((entry
!= (enumeration
->entries
->len
- 1)) ?
3936 if (context
->field_name
->len
) {
3937 g_string_append_printf(context
->string
, " %s",
3938 context
->field_name
->str
);
3939 g_string_assign(context
->field_name
, "");
3942 bt_put(container_type
);
3947 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type
*type
,
3948 struct metadata_context
*context
)
3950 struct bt_ctf_field_type_floating_point
*floating_point
= container_of(
3951 type
, struct bt_ctf_field_type_floating_point
, parent
);
3953 BT_LOGD("Serializing floating point number field type's metadata: "
3954 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3955 g_string_append_printf(context
->string
,
3956 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
3957 floating_point
->exp_dig
,
3958 floating_point
->mant_dig
,
3959 get_byte_order_string(floating_point
->user_byte_order
),
3965 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*type
,
3966 struct metadata_context
*context
)
3969 unsigned int indent
;
3971 struct bt_ctf_field_type_structure
*structure
= container_of(type
,
3972 struct bt_ctf_field_type_structure
, parent
);
3973 GString
*structure_field_name
= context
->field_name
;
3975 BT_LOGD("Serializing structure field type's metadata: "
3976 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3977 context
->field_name
= g_string_new("");
3979 context
->current_indentation_level
++;
3980 g_string_append(context
->string
, "struct {\n");
3982 for (i
= 0; i
< structure
->fields
->len
; i
++) {
3983 struct structure_field
*field
= structure
->fields
->pdata
[i
];
3985 BT_LOGV("Serializing structure field type's field metadata: "
3986 "index=%" PRId64
", "
3987 "field-ft-addr=%p, field-name=\"%s\"",
3988 i
, field
, g_quark_to_string(field
->name
));
3990 for (indent
= 0; indent
< context
->current_indentation_level
;
3992 g_string_append_c(context
->string
, '\t');
3995 g_string_assign(context
->field_name
,
3996 g_quark_to_string(field
->name
));
3997 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
3999 BT_LOGW("Cannot serialize structure field type's field's metadata: "
4000 "index=%" PRId64
", "
4001 "field-ft-addr=%p, field-name=\"%s\"",
4003 g_quark_to_string(field
->name
));
4007 if (context
->field_name
->len
) {
4008 g_string_append_printf(context
->string
, " %s",
4009 context
->field_name
->str
);
4011 g_string_append(context
->string
, ";\n");
4014 context
->current_indentation_level
--;
4015 for (indent
= 0; indent
< context
->current_indentation_level
;
4017 g_string_append_c(context
->string
, '\t');
4020 g_string_append_printf(context
->string
, "} align(%u)",
4023 g_string_free(context
->field_name
, TRUE
);
4024 context
->field_name
= structure_field_name
;
4029 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*type
,
4030 struct metadata_context
*context
)
4033 unsigned int indent
;
4035 struct bt_ctf_field_type_variant
*variant
= container_of(
4036 type
, struct bt_ctf_field_type_variant
, parent
);
4037 GString
*variant_field_name
= context
->field_name
;
4039 BT_LOGD("Serializing variant field type's metadata: "
4040 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4041 context
->field_name
= g_string_new("");
4042 if (variant
->tag_name
->len
> 0) {
4043 g_string_append_printf(context
->string
,
4044 "variant <%s> {\n", variant
->tag_name
->str
);
4046 g_string_append(context
->string
, "variant {\n");
4049 context
->current_indentation_level
++;
4050 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4051 struct structure_field
*field
= variant
->fields
->pdata
[i
];
4053 BT_LOGV("Serializing variant field type's field metadata: "
4054 "index=%" PRId64
", "
4055 "field-ft-addr=%p, field-name=\"%s\"",
4056 i
, field
, g_quark_to_string(field
->name
));
4058 g_string_assign(context
->field_name
,
4059 g_quark_to_string(field
->name
));
4060 for (indent
= 0; indent
< context
->current_indentation_level
;
4062 g_string_append_c(context
->string
, '\t');
4065 g_string_assign(context
->field_name
,
4066 g_quark_to_string(field
->name
));
4067 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4069 BT_LOGW("Cannot serialize variant field type's field's metadata: "
4070 "index=%" PRId64
", "
4071 "field-ft-addr=%p, field-name=\"%s\"",
4073 g_quark_to_string(field
->name
));
4077 if (context
->field_name
->len
) {
4078 g_string_append_printf(context
->string
, " %s;",
4079 context
->field_name
->str
);
4082 g_string_append_c(context
->string
, '\n');
4085 context
->current_indentation_level
--;
4086 for (indent
= 0; indent
< context
->current_indentation_level
;
4088 g_string_append_c(context
->string
, '\t');
4091 g_string_append(context
->string
, "}");
4093 g_string_free(context
->field_name
, TRUE
);
4094 context
->field_name
= variant_field_name
;
4099 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*type
,
4100 struct metadata_context
*context
)
4103 struct bt_ctf_field_type_array
*array
= container_of(type
,
4104 struct bt_ctf_field_type_array
, parent
);
4106 BT_LOGD("Serializing array field type's metadata: "
4107 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4108 ret
= bt_ctf_field_type_serialize(array
->element_type
, context
);
4110 BT_LOGW("Cannot serialize array field type's element field type's metadata: "
4111 "element-ft-addr=%p", array
->element_type
);
4115 if (context
->field_name
->len
) {
4116 g_string_append_printf(context
->string
, " %s[%u]",
4117 context
->field_name
->str
, array
->length
);
4118 g_string_assign(context
->field_name
, "");
4120 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4127 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*type
,
4128 struct metadata_context
*context
)
4131 struct bt_ctf_field_type_sequence
*sequence
= container_of(
4132 type
, struct bt_ctf_field_type_sequence
, parent
);
4134 BT_LOGD("Serializing sequence field type's metadata: "
4135 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4136 ret
= bt_ctf_field_type_serialize(sequence
->element_type
, context
);
4138 BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
4139 "element-ft-addr=%p", sequence
->element_type
);
4143 if (context
->field_name
->len
) {
4144 g_string_append_printf(context
->string
, " %s[%s]",
4145 context
->field_name
->str
,
4146 sequence
->length_field_name
->str
);
4147 g_string_assign(context
->field_name
, "");
4149 g_string_append_printf(context
->string
, "[%s]",
4150 sequence
->length_field_name
->str
);
4157 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*type
,
4158 struct metadata_context
*context
)
4160 struct bt_ctf_field_type_string
*string
= container_of(
4161 type
, struct bt_ctf_field_type_string
, parent
);
4163 BT_LOGD("Serializing string field type's metadata: "
4164 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4165 g_string_append_printf(context
->string
,
4166 "string { encoding = %s; }",
4167 get_encoding_string(string
->encoding
));
4172 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*type
,
4173 enum bt_ctf_byte_order byte_order
)
4175 struct bt_ctf_field_type_integer
*integer_type
= container_of(type
,
4176 struct bt_ctf_field_type_integer
, parent
);
4178 integer_type
->user_byte_order
= byte_order
;
4182 void bt_ctf_field_type_enumeration_set_byte_order(
4183 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4185 struct bt_ctf_field_type_enumeration
*enum_type
= container_of(type
,
4186 struct bt_ctf_field_type_enumeration
, parent
);
4188 /* Safe to assume that container is an integer */
4189 bt_ctf_field_type_integer_set_byte_order(enum_type
->container
,
4194 void bt_ctf_field_type_floating_point_set_byte_order(
4195 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4197 struct bt_ctf_field_type_floating_point
*floating_point_type
=
4198 container_of(type
, struct bt_ctf_field_type_floating_point
,
4201 floating_point_type
->user_byte_order
= byte_order
;
4205 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*type
,
4206 enum bt_ctf_byte_order byte_order
)
4209 struct bt_ctf_field_type_structure
*structure_type
=
4210 container_of(type
, struct bt_ctf_field_type_structure
,
4213 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
4214 struct structure_field
*field
= g_ptr_array_index(
4215 structure_type
->fields
, i
);
4216 struct bt_ctf_field_type
*field_type
= field
->type
;
4218 if (set_byte_order_funcs
[field_type
->id
]) {
4219 set_byte_order_funcs
[field_type
->id
](
4220 field_type
, byte_order
);
4226 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*type
,
4227 enum bt_ctf_byte_order byte_order
)
4230 struct bt_ctf_field_type_variant
*variant_type
=
4231 container_of(type
, struct bt_ctf_field_type_variant
,
4234 for (i
= 0; i
< variant_type
->fields
->len
; i
++) {
4235 struct structure_field
*field
= g_ptr_array_index(
4236 variant_type
->fields
, i
);
4237 struct bt_ctf_field_type
*field_type
= field
->type
;
4239 if (set_byte_order_funcs
[field_type
->id
]) {
4240 set_byte_order_funcs
[field_type
->id
](
4241 field_type
, byte_order
);
4247 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*type
,
4248 enum bt_ctf_byte_order byte_order
)
4250 struct bt_ctf_field_type_array
*array_type
=
4251 container_of(type
, struct bt_ctf_field_type_array
,
4254 if (set_byte_order_funcs
[array_type
->element_type
->id
]) {
4255 set_byte_order_funcs
[array_type
->element_type
->id
](
4256 array_type
->element_type
, byte_order
);
4261 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*type
,
4262 enum bt_ctf_byte_order byte_order
)
4264 struct bt_ctf_field_type_sequence
*sequence_type
=
4265 container_of(type
, struct bt_ctf_field_type_sequence
,
4268 if (set_byte_order_funcs
[
4269 sequence_type
->element_type
->id
]) {
4270 set_byte_order_funcs
[
4271 sequence_type
->element_type
->id
](
4272 sequence_type
->element_type
, byte_order
);
4277 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4278 struct bt_ctf_field_type
*type
)
4280 struct bt_ctf_field_type
*copy
;
4281 struct bt_ctf_field_type_integer
*integer
, *copy_integer
;
4283 BT_LOGD("Copying integer field type's: addr=%p", type
);
4284 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
4285 copy
= bt_ctf_field_type_integer_create(integer
->size
);
4287 BT_LOGE_STR("Cannot create integer field type.");
4291 copy_integer
= container_of(copy
, struct bt_ctf_field_type_integer
,
4293 copy_integer
->mapped_clock
= bt_get(integer
->mapped_clock
);
4294 copy_integer
->user_byte_order
= integer
->user_byte_order
;
4295 copy_integer
->is_signed
= integer
->is_signed
;
4296 copy_integer
->size
= integer
->size
;
4297 copy_integer
->base
= integer
->base
;
4298 copy_integer
->encoding
= integer
->encoding
;
4299 BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4307 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
4308 struct bt_ctf_field_type
*type
)
4311 struct bt_ctf_field_type
*copy
= NULL
, *copy_container
;
4312 struct bt_ctf_field_type_enumeration
*enumeration
, *copy_enumeration
;
4314 BT_LOGD("Copying enumeration field type's: addr=%p", type
);
4315 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
4318 /* Copy the source enumeration's container */
4319 copy_container
= bt_ctf_field_type_copy(enumeration
->container
);
4320 if (!copy_container
) {
4321 BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
4325 copy
= bt_ctf_field_type_enumeration_create(copy_container
);
4327 BT_LOGE_STR("Cannot create enumeration field type.");
4330 copy_enumeration
= container_of(copy
,
4331 struct bt_ctf_field_type_enumeration
, parent
);
4333 /* Copy all enumaration entries */
4334 for (i
= 0; i
< enumeration
->entries
->len
; i
++) {
4335 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4336 enumeration
->entries
, i
);
4337 struct enumeration_mapping
*copy_mapping
= g_new0(
4338 struct enumeration_mapping
, 1);
4340 if (!copy_mapping
) {
4341 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4345 *copy_mapping
= *mapping
;
4346 g_ptr_array_add(copy_enumeration
->entries
, copy_mapping
);
4349 BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4353 bt_put(copy_container
);
4356 bt_put(copy_container
);
4362 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4363 struct bt_ctf_field_type
*type
)
4365 struct bt_ctf_field_type
*copy
;
4366 struct bt_ctf_field_type_floating_point
*floating_point
, *copy_float
;
4368 BT_LOGD("Copying floating point number field type's: addr=%p", type
);
4369 floating_point
= container_of(type
,
4370 struct bt_ctf_field_type_floating_point
, parent
);
4371 copy
= bt_ctf_field_type_floating_point_create();
4373 BT_LOGE_STR("Cannot create floating point number field type.");
4377 copy_float
= container_of(copy
,
4378 struct bt_ctf_field_type_floating_point
, parent
);
4379 copy_float
->user_byte_order
= floating_point
->user_byte_order
;
4380 copy_float
->exp_dig
= floating_point
->exp_dig
;
4381 copy_float
->mant_dig
= floating_point
->mant_dig
;
4382 BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4389 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
4390 struct bt_ctf_field_type
*type
)
4393 GHashTableIter iter
;
4394 gpointer key
, value
;
4395 struct bt_ctf_field_type
*copy
;
4396 struct bt_ctf_field_type_structure
*structure
, *copy_structure
;
4398 BT_LOGD("Copying structure field type's: addr=%p", type
);
4399 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
4401 copy
= bt_ctf_field_type_structure_create();
4403 BT_LOGE_STR("Cannot create structure field type.");
4407 copy_structure
= container_of(copy
,
4408 struct bt_ctf_field_type_structure
, parent
);
4410 /* Copy field_name_to_index */
4411 g_hash_table_iter_init(&iter
, structure
->field_name_to_index
);
4412 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4413 g_hash_table_insert(copy_structure
->field_name_to_index
,
4417 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4418 struct structure_field
*entry
, *copy_entry
;
4419 struct bt_ctf_field_type
*copy_field
;
4421 entry
= g_ptr_array_index(structure
->fields
, i
);
4422 BT_LOGV("Copying structure field type's field: "
4423 "index=%" PRId64
", "
4424 "field-ft-addr=%p, field-name=\"%s\"",
4425 i
, entry
, g_quark_to_string(entry
->name
));
4426 copy_entry
= g_new0(struct structure_field
, 1);
4428 BT_LOGE_STR("Failed to allocate one structure field type field.");
4432 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4434 BT_LOGE("Cannot copy structure field type's field: "
4435 "index=%" PRId64
", "
4436 "field-ft-addr=%p, field-name=\"%s\"",
4437 i
, entry
, g_quark_to_string(entry
->name
));
4442 copy_entry
->name
= entry
->name
;
4443 copy_entry
->type
= copy_field
;
4444 g_ptr_array_add(copy_structure
->fields
, copy_entry
);
4447 BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4458 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
4459 struct bt_ctf_field_type
*type
)
4462 GHashTableIter iter
;
4463 gpointer key
, value
;
4464 struct bt_ctf_field_type
*copy
= NULL
, *copy_tag
= NULL
;
4465 struct bt_ctf_field_type_variant
*variant
, *copy_variant
;
4467 BT_LOGD("Copying variant field type's: addr=%p", type
);
4468 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
4471 copy_tag
= bt_ctf_field_type_copy(&variant
->tag
->parent
);
4473 BT_LOGE_STR("Cannot copy variant field type's tag field type.");
4478 copy
= bt_ctf_field_type_variant_create(copy_tag
,
4479 variant
->tag_name
->len
? variant
->tag_name
->str
: NULL
);
4481 BT_LOGE_STR("Cannot create variant field type.");
4485 copy_variant
= container_of(copy
, struct bt_ctf_field_type_variant
,
4488 /* Copy field_name_to_index */
4489 g_hash_table_iter_init(&iter
, variant
->field_name_to_index
);
4490 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4491 g_hash_table_insert(copy_variant
->field_name_to_index
,
4495 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4496 struct structure_field
*entry
, *copy_entry
;
4497 struct bt_ctf_field_type
*copy_field
;
4499 entry
= g_ptr_array_index(variant
->fields
, i
);
4500 BT_LOGV("Copying variant field type's field: "
4501 "index=%" PRId64
", "
4502 "field-ft-addr=%p, field-name=\"%s\"",
4503 i
, entry
, g_quark_to_string(entry
->name
));
4504 copy_entry
= g_new0(struct structure_field
, 1);
4506 BT_LOGE_STR("Failed to allocate one variant field type field.");
4510 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4512 BT_LOGE("Cannot copy variant field type's field: "
4513 "index=%" PRId64
", "
4514 "field-ft-addr=%p, field-name=\"%s\"",
4515 i
, entry
, g_quark_to_string(entry
->name
));
4520 copy_entry
->name
= entry
->name
;
4521 copy_entry
->type
= copy_field
;
4522 g_ptr_array_add(copy_variant
->fields
, copy_entry
);
4525 if (variant
->tag_field_path
) {
4526 BT_LOGV_STR("Copying variant field type's tag field path.");
4527 copy_variant
->tag_field_path
= bt_ctf_field_path_copy(
4528 variant
->tag_field_path
);
4529 if (!copy_variant
->tag_field_path
) {
4530 BT_LOGE_STR("Cannot copy variant field type's tag field path.");
4535 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4548 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
4549 struct bt_ctf_field_type
*type
)
4551 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4552 struct bt_ctf_field_type_array
*array
;
4554 BT_LOGD("Copying array field type's: addr=%p", type
);
4555 array
= container_of(type
, struct bt_ctf_field_type_array
,
4557 copy_element
= bt_ctf_field_type_copy(array
->element_type
);
4558 if (!copy_element
) {
4559 BT_LOGE_STR("Cannot copy array field type's element field type.");
4563 copy
= bt_ctf_field_type_array_create(copy_element
, array
->length
);
4565 BT_LOGE_STR("Cannot create array field type.");
4569 BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
4573 bt_put(copy_element
);
4578 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
4579 struct bt_ctf_field_type
*type
)
4581 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4582 struct bt_ctf_field_type_sequence
*sequence
, *copy_sequence
;
4584 BT_LOGD("Copying sequence field type's: addr=%p", type
);
4585 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
4587 copy_element
= bt_ctf_field_type_copy(sequence
->element_type
);
4588 if (!copy_element
) {
4589 BT_LOGE_STR("Cannot copy sequence field type's element field type.");
4593 copy
= bt_ctf_field_type_sequence_create(copy_element
,
4594 sequence
->length_field_name
->len
?
4595 sequence
->length_field_name
->str
: NULL
);
4597 BT_LOGE_STR("Cannot create sequence field type.");
4601 copy_sequence
= container_of(copy
, struct bt_ctf_field_type_sequence
,
4603 if (sequence
->length_field_path
) {
4604 BT_LOGV_STR("Copying sequence field type's length field path.");
4605 copy_sequence
->length_field_path
= bt_ctf_field_path_copy(
4606 sequence
->length_field_path
);
4607 if (!copy_sequence
->length_field_path
) {
4608 BT_LOGE_STR("Cannot copy sequence field type's length field path.");
4613 BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4617 bt_put(copy_element
);
4625 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4626 struct bt_ctf_field_type
*type
)
4628 struct bt_ctf_field_type
*copy
;
4629 struct bt_ctf_field_type_string
*string
;
4631 BT_LOGD("Copying string field type's: addr=%p", type
);
4632 copy
= bt_ctf_field_type_string_create();
4634 BT_LOGE_STR("Cannot create string field type.");
4638 string
= container_of(type
, struct bt_ctf_field_type_string
,
4640 BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
4647 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*type_a
,
4648 struct bt_ctf_field_type
*type_b
)
4651 struct bt_ctf_field_type_integer
*int_type_a
;
4652 struct bt_ctf_field_type_integer
*int_type_b
;
4654 int_type_a
= container_of(type_a
, struct bt_ctf_field_type_integer
,
4656 int_type_b
= container_of(type_b
, struct bt_ctf_field_type_integer
,
4660 if (int_type_a
->size
!= int_type_b
->size
) {
4661 BT_LOGV("Integer field types differ: different sizes: "
4662 "ft-a-size=%u, ft-b-size=%u",
4663 int_type_a
->size
, int_type_b
->size
);
4668 if (int_type_a
->user_byte_order
!= int_type_b
->user_byte_order
) {
4669 BT_LOGV("Integer field types differ: different byte orders: "
4670 "ft-a-bo=%s, ft-b-bo=%s",
4671 bt_ctf_byte_order_string(int_type_a
->user_byte_order
),
4672 bt_ctf_byte_order_string(int_type_b
->user_byte_order
));
4677 if (int_type_a
->is_signed
!= int_type_b
->is_signed
) {
4678 BT_LOGV("Integer field types differ: different signedness: "
4679 "ft-a-is-signed=%d, ft-b-is-signed=%d",
4680 int_type_a
->is_signed
,
4681 int_type_b
->is_signed
);
4686 if (int_type_a
->base
!= int_type_b
->base
) {
4687 BT_LOGV("Integer field types differ: different bases: "
4688 "ft-a-base=%s, ft-b-base=%s",
4689 bt_ctf_integer_base_string(int_type_a
->base
),
4690 bt_ctf_integer_base_string(int_type_b
->base
));
4695 if (int_type_a
->encoding
!= int_type_b
->encoding
) {
4696 BT_LOGV("Integer field types differ: different encodings: "
4697 "ft-a-encoding=%s, ft-b-encoding=%s",
4698 bt_ctf_string_encoding_string(int_type_a
->encoding
),
4699 bt_ctf_string_encoding_string(int_type_b
->encoding
));
4704 if (int_type_a
->mapped_clock
!= int_type_b
->mapped_clock
) {
4705 BT_LOGV("Integer field types differ: different mapped clock classes: "
4706 "ft-a-mapped-clock-class-addr=%p, "
4707 "ft-b-mapped-clock-class-addr=%p, ",
4708 "ft-a-mapped-clock-class-name=\"%s\", ",
4709 "ft-b-mapped-clock-class-name=\"%s\"",
4710 int_type_a
->mapped_clock
, int_type_b
->mapped_clock
,
4711 int_type_a
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_a
->mapped_clock
) : "",
4712 int_type_b
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_b
->mapped_clock
) : "");
4724 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*type_a
,
4725 struct bt_ctf_field_type
*type_b
)
4728 struct bt_ctf_field_type_floating_point
*float_a
;
4729 struct bt_ctf_field_type_floating_point
*float_b
;
4731 float_a
= container_of(type_a
,
4732 struct bt_ctf_field_type_floating_point
, parent
);
4733 float_b
= container_of(type_b
,
4734 struct bt_ctf_field_type_floating_point
, parent
);
4737 if (float_a
->user_byte_order
!= float_b
->user_byte_order
) {
4738 BT_LOGV("Floating point number field types differ: different byte orders: "
4739 "ft-a-bo=%s, ft-b-bo=%s",
4740 bt_ctf_byte_order_string(float_a
->user_byte_order
),
4741 bt_ctf_byte_order_string(float_b
->user_byte_order
));
4745 /* Exponent length */
4746 if (float_a
->exp_dig
!= float_b
->exp_dig
) {
4747 BT_LOGV("Floating point number field types differ: different exponent sizes: "
4748 "ft-a-exp-size=%s, ft-b-exp-size=%s",
4749 float_a
->exp_dig
, float_b
->exp_dig
);
4753 /* Mantissa length */
4754 if (float_a
->mant_dig
!= float_b
->mant_dig
) {
4755 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
4756 "ft-a-mant-size=%s, ft-b-mant-size=%s",
4757 float_a
->mant_dig
, float_b
->mant_dig
);
4769 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
4770 struct enumeration_mapping
*mapping_b
)
4775 if (mapping_a
->string
!= mapping_b
->string
) {
4776 BT_LOGV("Enumeration field type mappings differ: different names: "
4777 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
4778 g_quark_to_string(mapping_a
->string
),
4779 g_quark_to_string(mapping_b
->string
));
4784 if (mapping_a
->range_start
._unsigned
!=
4785 mapping_b
->range_start
._unsigned
) {
4786 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
4787 "mapping-a-range-start-unsigned=%" PRIu64
", "
4788 "mapping-b-range-start-unsigned=%" PRIu64
,
4789 mapping_a
->range_start
._unsigned
,
4790 mapping_b
->range_start
._unsigned
);
4795 if (mapping_a
->range_end
._unsigned
!=
4796 mapping_b
->range_end
._unsigned
) {
4797 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
4798 "mapping-a-range-end-unsigned=%" PRIu64
", "
4799 "mapping-b-range-end-unsigned=%" PRIu64
,
4800 mapping_a
->range_end
._unsigned
,
4801 mapping_b
->range_end
._unsigned
);
4813 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*type_a
,
4814 struct bt_ctf_field_type
*type_b
)
4818 struct bt_ctf_field_type_enumeration
*enum_a
;
4819 struct bt_ctf_field_type_enumeration
*enum_b
;
4821 enum_a
= container_of(type_a
,
4822 struct bt_ctf_field_type_enumeration
, parent
);
4823 enum_b
= container_of(type_b
,
4824 struct bt_ctf_field_type_enumeration
, parent
);
4826 /* Container field type */
4827 ret
= bt_ctf_field_type_compare(enum_a
->container
, enum_b
->container
);
4829 BT_LOGV("Enumeration field types differ: different container field types: "
4830 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
4831 enum_a
->container
, enum_b
->container
);
4838 if (enum_a
->entries
->len
!= enum_b
->entries
->len
) {
4842 for (i
= 0; i
< enum_a
->entries
->len
; ++i
) {
4843 struct enumeration_mapping
*mapping_a
=
4844 g_ptr_array_index(enum_a
->entries
, i
);
4845 struct enumeration_mapping
*mapping_b
=
4846 g_ptr_array_index(enum_b
->entries
, i
);
4848 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4849 BT_LOGV("Enumeration field types differ: different mappings: "
4850 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4851 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4852 mapping_a
, mapping_b
,
4853 g_quark_to_string(mapping_a
->string
),
4854 g_quark_to_string(mapping_b
->string
));
4867 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*type_a
,
4868 struct bt_ctf_field_type
*type_b
)
4871 struct bt_ctf_field_type_string
*string_a
;
4872 struct bt_ctf_field_type_string
*string_b
;
4874 string_a
= container_of(type_a
,
4875 struct bt_ctf_field_type_string
, parent
);
4876 string_b
= container_of(type_b
,
4877 struct bt_ctf_field_type_string
, parent
);
4880 if (string_a
->encoding
!= string_b
->encoding
) {
4881 BT_LOGV("String field types differ: different encodings: "
4882 "ft-a-encoding=%s, ft-b-encoding=%s",
4883 bt_ctf_string_encoding_string(string_a
->encoding
),
4884 bt_ctf_string_encoding_string(string_b
->encoding
));
4896 int compare_structure_fields(struct structure_field
*field_a
,
4897 struct structure_field
*field_b
)
4902 if (field_a
->name
!= field_b
->name
) {
4903 BT_LOGV("Structure/variant field type fields differ: different names: "
4904 "field-a-name=%s, field-b-name=%s",
4905 g_quark_to_string(field_a
->name
),
4906 g_quark_to_string(field_b
->name
));
4911 ret
= bt_ctf_field_type_compare(field_a
->type
, field_b
->type
);
4913 BT_LOGV("Structure/variant field type fields differ: different field types: "
4914 "field-name=\"%s\", field-a-ft-addr=%s, field-b-ft-addr=%s",
4915 g_quark_to_string(field_a
->name
),
4916 field_a
->type
, field_b
->type
);
4924 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*type_a
,
4925 struct bt_ctf_field_type
*type_b
)
4929 struct bt_ctf_field_type_structure
*struct_a
;
4930 struct bt_ctf_field_type_structure
*struct_b
;
4932 struct_a
= container_of(type_a
,
4933 struct bt_ctf_field_type_structure
, parent
);
4934 struct_b
= container_of(type_b
,
4935 struct bt_ctf_field_type_structure
, parent
);
4938 if (bt_ctf_field_type_get_alignment(type_a
) !=
4939 bt_ctf_field_type_get_alignment(type_b
)) {
4940 BT_LOGV("Structure field types differ: different alignments: "
4941 "ft-a-align=%u, ft-b-align=%u",
4942 bt_ctf_field_type_get_alignment(type_a
),
4943 bt_ctf_field_type_get_alignment(type_b
));
4948 if (struct_a
->fields
->len
!= struct_b
->fields
->len
) {
4949 BT_LOGV("Structure field types differ: different field counts: "
4950 "ft-a-field-count=%u, ft-b-field-count=%u",
4951 struct_a
->fields
->len
, struct_b
->fields
->len
);
4955 for (i
= 0; i
< struct_a
->fields
->len
; ++i
) {
4956 struct structure_field
*field_a
=
4957 g_ptr_array_index(struct_a
->fields
, i
);
4958 struct structure_field
*field_b
=
4959 g_ptr_array_index(struct_b
->fields
, i
);
4961 ret
= compare_structure_fields(field_a
, field_b
);
4963 /* compare_structure_fields() logs what differs */
4964 BT_LOGV_STR("Structure field types differ: different fields.");
4977 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*type_a
,
4978 struct bt_ctf_field_type
*type_b
)
4982 struct bt_ctf_field_type_variant
*variant_a
;
4983 struct bt_ctf_field_type_variant
*variant_b
;
4985 variant_a
= container_of(type_a
,
4986 struct bt_ctf_field_type_variant
, parent
);
4987 variant_b
= container_of(type_b
,
4988 struct bt_ctf_field_type_variant
, parent
);
4991 if (strcmp(variant_a
->tag_name
->str
, variant_b
->tag_name
->str
)) {
4992 BT_LOGV("Variant field types differ: different tag field names: "
4993 "ft-a-tag-field-name=%u, ft-b-tag-field-name=%u",
4994 variant_a
->tag_name
->str
, variant_b
->tag_name
->str
);
4999 ret
= bt_ctf_field_type_compare(
5000 (struct bt_ctf_field_type
*) variant_a
->tag
,
5001 (struct bt_ctf_field_type
*) variant_b
->tag
);
5003 BT_LOGV("Variant field types differ: different tag field types: "
5004 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
5005 variant_a
->tag
, variant_b
->tag
);
5012 if (variant_a
->fields
->len
!= variant_b
->fields
->len
) {
5013 BT_LOGV("Structure field types differ: different field counts: "
5014 "ft-a-field-count=%u, ft-b-field-count=%u",
5015 variant_a
->fields
->len
, variant_b
->fields
->len
);
5019 for (i
= 0; i
< variant_a
->fields
->len
; ++i
) {
5020 struct structure_field
*field_a
=
5021 g_ptr_array_index(variant_a
->fields
, i
);
5022 struct structure_field
*field_b
=
5023 g_ptr_array_index(variant_b
->fields
, i
);
5025 ret
= compare_structure_fields(field_a
, field_b
);
5027 /* compare_structure_fields() logs what differs */
5028 BT_LOGV_STR("Variant field types differ: different fields.");
5041 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*type_a
,
5042 struct bt_ctf_field_type
*type_b
)
5045 struct bt_ctf_field_type_array
*array_a
;
5046 struct bt_ctf_field_type_array
*array_b
;
5048 array_a
= container_of(type_a
,
5049 struct bt_ctf_field_type_array
, parent
);
5050 array_b
= container_of(type_b
,
5051 struct bt_ctf_field_type_array
, parent
);
5054 if (array_a
->length
!= array_b
->length
) {
5055 BT_LOGV("Structure field types differ: different lengths: "
5056 "ft-a-length=%u, ft-b-length=%u",
5057 array_a
->length
, array_b
->length
);
5062 ret
= bt_ctf_field_type_compare(array_a
->element_type
,
5063 array_b
->element_type
);
5065 BT_LOGV("Array field types differ: different element field types: "
5066 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5067 array_a
->element_type
, array_b
->element_type
);
5075 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*type_a
,
5076 struct bt_ctf_field_type
*type_b
)
5079 struct bt_ctf_field_type_sequence
*sequence_a
;
5080 struct bt_ctf_field_type_sequence
*sequence_b
;
5082 sequence_a
= container_of(type_a
,
5083 struct bt_ctf_field_type_sequence
, parent
);
5084 sequence_b
= container_of(type_b
,
5085 struct bt_ctf_field_type_sequence
, parent
);
5088 if (strcmp(sequence_a
->length_field_name
->str
,
5089 sequence_b
->length_field_name
->str
)) {
5090 BT_LOGV("Sequence field types differ: different length field names: "
5091 "ft-a-length-field-name=%u, ft-b-length-field-name=%u",
5092 sequence_a
->length_field_name
->str
,
5093 sequence_b
->length_field_name
->str
);
5098 ret
= bt_ctf_field_type_compare(sequence_a
->element_type
,
5099 sequence_b
->element_type
);
5101 BT_LOGV("Sequence field types differ: different element field types: "
5102 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5103 sequence_a
->element_type
, sequence_b
->element_type
);
5110 int bt_ctf_field_type_compare(struct bt_ctf_field_type
*type_a
,
5111 struct bt_ctf_field_type
*type_b
)
5115 if (type_a
== type_b
) {
5116 /* Same reference: equal (even if both are NULL) */
5122 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
5128 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
5133 if (type_a
->id
!= type_b
->id
) {
5134 /* Different type IDs */
5135 BT_LOGV("Field types differ: different IDs: "
5136 "ft-a-addr=%p, ft-b-addr=%p, "
5137 "ft-a-id=%s, ft-b-id=%s",
5139 bt_ctf_field_type_id_string(type_a
->id
),
5140 bt_ctf_field_type_id_string(type_b
->id
));
5144 if (type_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
5145 /* Both have unknown type IDs */
5146 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
5150 ret
= type_compare_funcs
[type_a
->id
](type_a
, type_b
);
5152 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
5161 int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*field_type
)
5163 int64_t field_count
= -1;
5164 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5167 case CTF_TYPE_STRUCT
:
5169 bt_ctf_field_type_structure_get_field_count(field_type
);
5171 case CTF_TYPE_VARIANT
:
5173 bt_ctf_field_type_variant_get_field_count(field_type
);
5175 case CTF_TYPE_ARRAY
:
5176 case CTF_TYPE_SEQUENCE
:
5178 * Array and sequence types always contain a single member
5179 * (the element type).
5191 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
5192 struct bt_ctf_field_type
*field_type
, int index
)
5194 struct bt_ctf_field_type
*field
= NULL
;
5195 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5198 case CTF_TYPE_STRUCT
:
5199 bt_ctf_field_type_structure_get_field_by_index(field_type
,
5200 NULL
, &field
, index
);
5202 case CTF_TYPE_VARIANT
:
5204 int ret
= bt_ctf_field_type_variant_get_field_by_index(
5205 field_type
, NULL
, &field
, index
);
5212 case CTF_TYPE_ARRAY
:
5213 field
= bt_ctf_field_type_array_get_element_type(field_type
);
5215 case CTF_TYPE_SEQUENCE
:
5216 field
= bt_ctf_field_type_sequence_get_element_type(field_type
);
5226 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*field_type
,
5229 int field_index
= -1;
5230 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5233 case CTF_TYPE_STRUCT
:
5234 field_index
= bt_ctf_field_type_structure_get_field_name_index(
5237 case CTF_TYPE_VARIANT
:
5238 field_index
= bt_ctf_field_type_variant_get_field_name_index(
5248 struct bt_ctf_field_path
*bt_ctf_field_type_variant_get_tag_field_path(
5249 struct bt_ctf_field_type
*type
)
5251 struct bt_ctf_field_path
*field_path
= NULL
;
5252 struct bt_ctf_field_type_variant
*variant
;
5255 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5259 if (!bt_ctf_field_type_is_variant(type
)) {
5260 BT_LOGW("Invalid parameter: field type is not a variant field type: "
5261 "addr=%p, ft-id=%s", type
,
5262 bt_ctf_field_type_id_string(type
->id
));
5266 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
5268 field_path
= bt_get(variant
->tag_field_path
);
5273 struct bt_ctf_field_path
*bt_ctf_field_type_sequence_get_length_field_path(
5274 struct bt_ctf_field_type
*type
)
5276 struct bt_ctf_field_path
*field_path
= NULL
;
5277 struct bt_ctf_field_type_sequence
*sequence
;
5280 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5284 if (!bt_ctf_field_type_is_sequence(type
)) {
5285 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
5286 "addr=%p, ft-id=%s", type
,
5287 bt_ctf_field_type_id_string(type
->id
));
5291 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
5293 field_path
= bt_get(sequence
->length_field_path
);