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_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3731 enumeration_type
->container
);
3732 bt_ctf_field_type_freeze(enumeration_type
->container
);
3736 void freeze_structure_field(struct structure_field
*field
)
3738 BT_LOGD("Freezing structure/variant field type field: field-addr=%p, "
3739 "field-ft-addr=%p, field-name=\"%s\"", field
,
3740 field
->type
, g_quark_to_string(field
->name
));
3741 bt_ctf_field_type_freeze(field
->type
);
3745 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*type
)
3747 struct bt_ctf_field_type_structure
*structure_type
= container_of(
3748 type
, struct bt_ctf_field_type_structure
, parent
);
3750 /* Cache the alignment */
3751 BT_LOGD("Freezing structure field type object: addr=%p", type
);
3752 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3753 generic_field_type_freeze(type
);
3754 g_ptr_array_foreach(structure_type
->fields
,
3755 (GFunc
) freeze_structure_field
, NULL
);
3759 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*type
)
3761 struct bt_ctf_field_type_variant
*variant_type
= container_of(
3762 type
, struct bt_ctf_field_type_variant
, parent
);
3764 BT_LOGD("Freezing variant field type object: addr=%p", type
);
3765 generic_field_type_freeze(type
);
3766 g_ptr_array_foreach(variant_type
->fields
,
3767 (GFunc
) freeze_structure_field
, NULL
);
3771 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*type
)
3773 struct bt_ctf_field_type_array
*array_type
= container_of(
3774 type
, struct bt_ctf_field_type_array
, parent
);
3776 /* Cache the alignment */
3777 BT_LOGD("Freezing array field type object: addr=%p", type
);
3778 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3779 generic_field_type_freeze(type
);
3780 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3781 array_type
->element_type
);
3782 bt_ctf_field_type_freeze(array_type
->element_type
);
3786 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*type
)
3788 struct bt_ctf_field_type_sequence
*sequence_type
= container_of(
3789 type
, struct bt_ctf_field_type_sequence
, parent
);
3791 /* Cache the alignment */
3792 BT_LOGD("Freezing sequence field type object: addr=%p", type
);
3793 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3794 generic_field_type_freeze(type
);
3795 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3796 sequence_type
->element_type
);
3797 bt_ctf_field_type_freeze(sequence_type
->element_type
);
3801 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
3803 const char *encoding_string
;
3806 case BT_CTF_STRING_ENCODING_NONE
:
3807 encoding_string
= "none";
3809 case BT_CTF_STRING_ENCODING_ASCII
:
3810 encoding_string
= "ASCII";
3812 case BT_CTF_STRING_ENCODING_UTF8
:
3813 encoding_string
= "UTF8";
3816 encoding_string
= "unknown";
3820 return encoding_string
;
3824 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
3826 const char *base_string
;
3829 case BT_CTF_INTEGER_BASE_DECIMAL
:
3830 base_string
= "decimal";
3832 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
3833 base_string
= "hexadecimal";
3835 case BT_CTF_INTEGER_BASE_OCTAL
:
3836 base_string
= "octal";
3838 case BT_CTF_INTEGER_BASE_BINARY
:
3839 base_string
= "binary";
3842 base_string
= "unknown";
3850 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*type
,
3851 struct metadata_context
*context
)
3853 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
3854 struct bt_ctf_field_type_integer
, parent
);
3857 BT_LOGD("Serializing integer field type's metadata: "
3858 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3859 g_string_append_printf(context
->string
,
3860 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
3861 integer
->size
, type
->alignment
,
3862 (integer
->is_signed
? "true" : "false"),
3863 get_encoding_string(integer
->encoding
),
3864 get_integer_base_string(integer
->base
),
3865 get_byte_order_string(integer
->user_byte_order
));
3866 if (integer
->mapped_clock
) {
3867 const char *clock_name
= bt_ctf_clock_class_get_name(
3868 integer
->mapped_clock
);
3871 g_string_append_printf(context
->string
,
3872 "; map = clock.%s.value", clock_name
);
3875 g_string_append(context
->string
, "; }");
3880 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*type
,
3881 struct metadata_context
*context
)
3885 struct bt_ctf_field_type_enumeration
*enumeration
= container_of(type
,
3886 struct bt_ctf_field_type_enumeration
, parent
);
3887 struct bt_ctf_field_type
*container_type
;
3888 int container_signed
;
3890 BT_LOGD("Serializing enumeration field type's metadata: "
3891 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3892 container_type
= bt_ctf_field_type_enumeration_get_container_type(type
);
3893 assert(container_type
);
3894 container_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
3895 assert(container_signed
>= 0);
3896 g_string_append(context
->string
, "enum : ");
3897 ret
= bt_ctf_field_type_serialize(enumeration
->container
, context
);
3899 BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
3900 "container-ft-addr=%p", enumeration
->container
);
3904 g_string_append(context
->string
, " { ");
3905 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
3906 struct enumeration_mapping
*mapping
=
3907 enumeration
->entries
->pdata
[entry
];
3909 if (container_signed
) {
3910 if (mapping
->range_start
._signed
==
3911 mapping
->range_end
._signed
) {
3912 g_string_append_printf(context
->string
,
3913 "\"%s\" = %" PRId64
,
3914 g_quark_to_string(mapping
->string
),
3915 mapping
->range_start
._signed
);
3917 g_string_append_printf(context
->string
,
3918 "\"%s\" = %" PRId64
" ... %" PRId64
,
3919 g_quark_to_string(mapping
->string
),
3920 mapping
->range_start
._signed
,
3921 mapping
->range_end
._signed
);
3924 if (mapping
->range_start
._unsigned
==
3925 mapping
->range_end
._unsigned
) {
3926 g_string_append_printf(context
->string
,
3927 "\"%s\" = %" PRIu64
,
3928 g_quark_to_string(mapping
->string
),
3929 mapping
->range_start
._unsigned
);
3931 g_string_append_printf(context
->string
,
3932 "\"%s\" = %" PRIu64
" ... %" PRIu64
,
3933 g_quark_to_string(mapping
->string
),
3934 mapping
->range_start
._unsigned
,
3935 mapping
->range_end
._unsigned
);
3939 g_string_append(context
->string
,
3940 ((entry
!= (enumeration
->entries
->len
- 1)) ?
3944 if (context
->field_name
->len
) {
3945 g_string_append_printf(context
->string
, " %s",
3946 context
->field_name
->str
);
3947 g_string_assign(context
->field_name
, "");
3950 bt_put(container_type
);
3955 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type
*type
,
3956 struct metadata_context
*context
)
3958 struct bt_ctf_field_type_floating_point
*floating_point
= container_of(
3959 type
, struct bt_ctf_field_type_floating_point
, parent
);
3961 BT_LOGD("Serializing floating point number field type's metadata: "
3962 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3963 g_string_append_printf(context
->string
,
3964 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
3965 floating_point
->exp_dig
,
3966 floating_point
->mant_dig
,
3967 get_byte_order_string(floating_point
->user_byte_order
),
3973 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*type
,
3974 struct metadata_context
*context
)
3977 unsigned int indent
;
3979 struct bt_ctf_field_type_structure
*structure
= container_of(type
,
3980 struct bt_ctf_field_type_structure
, parent
);
3981 GString
*structure_field_name
= context
->field_name
;
3983 BT_LOGD("Serializing structure field type's metadata: "
3984 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3985 context
->field_name
= g_string_new("");
3987 context
->current_indentation_level
++;
3988 g_string_append(context
->string
, "struct {\n");
3990 for (i
= 0; i
< structure
->fields
->len
; i
++) {
3991 struct structure_field
*field
= structure
->fields
->pdata
[i
];
3993 BT_LOGV("Serializing structure field type's field metadata: "
3994 "index=%" PRId64
", "
3995 "field-ft-addr=%p, field-name=\"%s\"",
3996 i
, field
, g_quark_to_string(field
->name
));
3998 for (indent
= 0; indent
< context
->current_indentation_level
;
4000 g_string_append_c(context
->string
, '\t');
4003 g_string_assign(context
->field_name
,
4004 g_quark_to_string(field
->name
));
4005 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4007 BT_LOGW("Cannot serialize structure field type's field's metadata: "
4008 "index=%" PRId64
", "
4009 "field-ft-addr=%p, field-name=\"%s\"",
4011 g_quark_to_string(field
->name
));
4015 if (context
->field_name
->len
) {
4016 g_string_append_printf(context
->string
, " %s",
4017 context
->field_name
->str
);
4019 g_string_append(context
->string
, ";\n");
4022 context
->current_indentation_level
--;
4023 for (indent
= 0; indent
< context
->current_indentation_level
;
4025 g_string_append_c(context
->string
, '\t');
4028 g_string_append_printf(context
->string
, "} align(%u)",
4031 g_string_free(context
->field_name
, TRUE
);
4032 context
->field_name
= structure_field_name
;
4037 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*type
,
4038 struct metadata_context
*context
)
4041 unsigned int indent
;
4043 struct bt_ctf_field_type_variant
*variant
= container_of(
4044 type
, struct bt_ctf_field_type_variant
, parent
);
4045 GString
*variant_field_name
= context
->field_name
;
4047 BT_LOGD("Serializing variant field type's metadata: "
4048 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4049 context
->field_name
= g_string_new("");
4050 if (variant
->tag_name
->len
> 0) {
4051 g_string_append_printf(context
->string
,
4052 "variant <%s> {\n", variant
->tag_name
->str
);
4054 g_string_append(context
->string
, "variant {\n");
4057 context
->current_indentation_level
++;
4058 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4059 struct structure_field
*field
= variant
->fields
->pdata
[i
];
4061 BT_LOGV("Serializing variant field type's field metadata: "
4062 "index=%" PRId64
", "
4063 "field-ft-addr=%p, field-name=\"%s\"",
4064 i
, field
, g_quark_to_string(field
->name
));
4066 g_string_assign(context
->field_name
,
4067 g_quark_to_string(field
->name
));
4068 for (indent
= 0; indent
< context
->current_indentation_level
;
4070 g_string_append_c(context
->string
, '\t');
4073 g_string_assign(context
->field_name
,
4074 g_quark_to_string(field
->name
));
4075 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4077 BT_LOGW("Cannot serialize variant field type's field's metadata: "
4078 "index=%" PRId64
", "
4079 "field-ft-addr=%p, field-name=\"%s\"",
4081 g_quark_to_string(field
->name
));
4085 if (context
->field_name
->len
) {
4086 g_string_append_printf(context
->string
, " %s;",
4087 context
->field_name
->str
);
4090 g_string_append_c(context
->string
, '\n');
4093 context
->current_indentation_level
--;
4094 for (indent
= 0; indent
< context
->current_indentation_level
;
4096 g_string_append_c(context
->string
, '\t');
4099 g_string_append(context
->string
, "}");
4101 g_string_free(context
->field_name
, TRUE
);
4102 context
->field_name
= variant_field_name
;
4107 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*type
,
4108 struct metadata_context
*context
)
4111 struct bt_ctf_field_type_array
*array
= container_of(type
,
4112 struct bt_ctf_field_type_array
, parent
);
4114 BT_LOGD("Serializing array field type's metadata: "
4115 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4116 ret
= bt_ctf_field_type_serialize(array
->element_type
, context
);
4118 BT_LOGW("Cannot serialize array field type's element field type's metadata: "
4119 "element-ft-addr=%p", array
->element_type
);
4123 if (context
->field_name
->len
) {
4124 g_string_append_printf(context
->string
, " %s[%u]",
4125 context
->field_name
->str
, array
->length
);
4126 g_string_assign(context
->field_name
, "");
4128 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4135 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*type
,
4136 struct metadata_context
*context
)
4139 struct bt_ctf_field_type_sequence
*sequence
= container_of(
4140 type
, struct bt_ctf_field_type_sequence
, parent
);
4142 BT_LOGD("Serializing sequence field type's metadata: "
4143 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4144 ret
= bt_ctf_field_type_serialize(sequence
->element_type
, context
);
4146 BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
4147 "element-ft-addr=%p", sequence
->element_type
);
4151 if (context
->field_name
->len
) {
4152 g_string_append_printf(context
->string
, " %s[%s]",
4153 context
->field_name
->str
,
4154 sequence
->length_field_name
->str
);
4155 g_string_assign(context
->field_name
, "");
4157 g_string_append_printf(context
->string
, "[%s]",
4158 sequence
->length_field_name
->str
);
4165 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*type
,
4166 struct metadata_context
*context
)
4168 struct bt_ctf_field_type_string
*string
= container_of(
4169 type
, struct bt_ctf_field_type_string
, parent
);
4171 BT_LOGD("Serializing string field type's metadata: "
4172 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4173 g_string_append_printf(context
->string
,
4174 "string { encoding = %s; }",
4175 get_encoding_string(string
->encoding
));
4180 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*type
,
4181 enum bt_ctf_byte_order byte_order
)
4183 struct bt_ctf_field_type_integer
*integer_type
= container_of(type
,
4184 struct bt_ctf_field_type_integer
, parent
);
4186 integer_type
->user_byte_order
= byte_order
;
4190 void bt_ctf_field_type_enumeration_set_byte_order(
4191 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4193 struct bt_ctf_field_type_enumeration
*enum_type
= container_of(type
,
4194 struct bt_ctf_field_type_enumeration
, parent
);
4196 /* Safe to assume that container is an integer */
4197 bt_ctf_field_type_integer_set_byte_order(enum_type
->container
,
4202 void bt_ctf_field_type_floating_point_set_byte_order(
4203 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4205 struct bt_ctf_field_type_floating_point
*floating_point_type
=
4206 container_of(type
, struct bt_ctf_field_type_floating_point
,
4209 floating_point_type
->user_byte_order
= byte_order
;
4213 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*type
,
4214 enum bt_ctf_byte_order byte_order
)
4217 struct bt_ctf_field_type_structure
*structure_type
=
4218 container_of(type
, struct bt_ctf_field_type_structure
,
4221 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
4222 struct structure_field
*field
= g_ptr_array_index(
4223 structure_type
->fields
, i
);
4224 struct bt_ctf_field_type
*field_type
= field
->type
;
4226 if (set_byte_order_funcs
[field_type
->id
]) {
4227 set_byte_order_funcs
[field_type
->id
](
4228 field_type
, byte_order
);
4234 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*type
,
4235 enum bt_ctf_byte_order byte_order
)
4238 struct bt_ctf_field_type_variant
*variant_type
=
4239 container_of(type
, struct bt_ctf_field_type_variant
,
4242 for (i
= 0; i
< variant_type
->fields
->len
; i
++) {
4243 struct structure_field
*field
= g_ptr_array_index(
4244 variant_type
->fields
, i
);
4245 struct bt_ctf_field_type
*field_type
= field
->type
;
4247 if (set_byte_order_funcs
[field_type
->id
]) {
4248 set_byte_order_funcs
[field_type
->id
](
4249 field_type
, byte_order
);
4255 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*type
,
4256 enum bt_ctf_byte_order byte_order
)
4258 struct bt_ctf_field_type_array
*array_type
=
4259 container_of(type
, struct bt_ctf_field_type_array
,
4262 if (set_byte_order_funcs
[array_type
->element_type
->id
]) {
4263 set_byte_order_funcs
[array_type
->element_type
->id
](
4264 array_type
->element_type
, byte_order
);
4269 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*type
,
4270 enum bt_ctf_byte_order byte_order
)
4272 struct bt_ctf_field_type_sequence
*sequence_type
=
4273 container_of(type
, struct bt_ctf_field_type_sequence
,
4276 if (set_byte_order_funcs
[
4277 sequence_type
->element_type
->id
]) {
4278 set_byte_order_funcs
[
4279 sequence_type
->element_type
->id
](
4280 sequence_type
->element_type
, byte_order
);
4285 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4286 struct bt_ctf_field_type
*type
)
4288 struct bt_ctf_field_type
*copy
;
4289 struct bt_ctf_field_type_integer
*integer
, *copy_integer
;
4291 BT_LOGD("Copying integer field type's: addr=%p", type
);
4292 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
4293 copy
= bt_ctf_field_type_integer_create(integer
->size
);
4295 BT_LOGE_STR("Cannot create integer field type.");
4299 copy_integer
= container_of(copy
, struct bt_ctf_field_type_integer
,
4301 copy_integer
->mapped_clock
= bt_get(integer
->mapped_clock
);
4302 copy_integer
->user_byte_order
= integer
->user_byte_order
;
4303 copy_integer
->is_signed
= integer
->is_signed
;
4304 copy_integer
->size
= integer
->size
;
4305 copy_integer
->base
= integer
->base
;
4306 copy_integer
->encoding
= integer
->encoding
;
4307 BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4315 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
4316 struct bt_ctf_field_type
*type
)
4319 struct bt_ctf_field_type
*copy
= NULL
, *copy_container
;
4320 struct bt_ctf_field_type_enumeration
*enumeration
, *copy_enumeration
;
4322 BT_LOGD("Copying enumeration field type's: addr=%p", type
);
4323 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
4326 /* Copy the source enumeration's container */
4327 copy_container
= bt_ctf_field_type_copy(enumeration
->container
);
4328 if (!copy_container
) {
4329 BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
4333 copy
= bt_ctf_field_type_enumeration_create(copy_container
);
4335 BT_LOGE_STR("Cannot create enumeration field type.");
4338 copy_enumeration
= container_of(copy
,
4339 struct bt_ctf_field_type_enumeration
, parent
);
4341 /* Copy all enumaration entries */
4342 for (i
= 0; i
< enumeration
->entries
->len
; i
++) {
4343 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4344 enumeration
->entries
, i
);
4345 struct enumeration_mapping
*copy_mapping
= g_new0(
4346 struct enumeration_mapping
, 1);
4348 if (!copy_mapping
) {
4349 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4353 *copy_mapping
= *mapping
;
4354 g_ptr_array_add(copy_enumeration
->entries
, copy_mapping
);
4357 BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4361 bt_put(copy_container
);
4364 bt_put(copy_container
);
4370 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4371 struct bt_ctf_field_type
*type
)
4373 struct bt_ctf_field_type
*copy
;
4374 struct bt_ctf_field_type_floating_point
*floating_point
, *copy_float
;
4376 BT_LOGD("Copying floating point number field type's: addr=%p", type
);
4377 floating_point
= container_of(type
,
4378 struct bt_ctf_field_type_floating_point
, parent
);
4379 copy
= bt_ctf_field_type_floating_point_create();
4381 BT_LOGE_STR("Cannot create floating point number field type.");
4385 copy_float
= container_of(copy
,
4386 struct bt_ctf_field_type_floating_point
, parent
);
4387 copy_float
->user_byte_order
= floating_point
->user_byte_order
;
4388 copy_float
->exp_dig
= floating_point
->exp_dig
;
4389 copy_float
->mant_dig
= floating_point
->mant_dig
;
4390 BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4397 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
4398 struct bt_ctf_field_type
*type
)
4401 GHashTableIter iter
;
4402 gpointer key
, value
;
4403 struct bt_ctf_field_type
*copy
;
4404 struct bt_ctf_field_type_structure
*structure
, *copy_structure
;
4406 BT_LOGD("Copying structure field type's: addr=%p", type
);
4407 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
4409 copy
= bt_ctf_field_type_structure_create();
4411 BT_LOGE_STR("Cannot create structure field type.");
4415 copy_structure
= container_of(copy
,
4416 struct bt_ctf_field_type_structure
, parent
);
4418 /* Copy field_name_to_index */
4419 g_hash_table_iter_init(&iter
, structure
->field_name_to_index
);
4420 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4421 g_hash_table_insert(copy_structure
->field_name_to_index
,
4425 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4426 struct structure_field
*entry
, *copy_entry
;
4427 struct bt_ctf_field_type
*copy_field
;
4429 entry
= g_ptr_array_index(structure
->fields
, i
);
4430 BT_LOGV("Copying structure field type's field: "
4431 "index=%" PRId64
", "
4432 "field-ft-addr=%p, field-name=\"%s\"",
4433 i
, entry
, g_quark_to_string(entry
->name
));
4434 copy_entry
= g_new0(struct structure_field
, 1);
4436 BT_LOGE_STR("Failed to allocate one structure field type field.");
4440 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4442 BT_LOGE("Cannot copy structure field type's field: "
4443 "index=%" PRId64
", "
4444 "field-ft-addr=%p, field-name=\"%s\"",
4445 i
, entry
, g_quark_to_string(entry
->name
));
4450 copy_entry
->name
= entry
->name
;
4451 copy_entry
->type
= copy_field
;
4452 g_ptr_array_add(copy_structure
->fields
, copy_entry
);
4455 BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4466 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
4467 struct bt_ctf_field_type
*type
)
4470 GHashTableIter iter
;
4471 gpointer key
, value
;
4472 struct bt_ctf_field_type
*copy
= NULL
, *copy_tag
= NULL
;
4473 struct bt_ctf_field_type_variant
*variant
, *copy_variant
;
4475 BT_LOGD("Copying variant field type's: addr=%p", type
);
4476 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
4479 copy_tag
= bt_ctf_field_type_copy(&variant
->tag
->parent
);
4481 BT_LOGE_STR("Cannot copy variant field type's tag field type.");
4486 copy
= bt_ctf_field_type_variant_create(copy_tag
,
4487 variant
->tag_name
->len
? variant
->tag_name
->str
: NULL
);
4489 BT_LOGE_STR("Cannot create variant field type.");
4493 copy_variant
= container_of(copy
, struct bt_ctf_field_type_variant
,
4496 /* Copy field_name_to_index */
4497 g_hash_table_iter_init(&iter
, variant
->field_name_to_index
);
4498 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4499 g_hash_table_insert(copy_variant
->field_name_to_index
,
4503 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4504 struct structure_field
*entry
, *copy_entry
;
4505 struct bt_ctf_field_type
*copy_field
;
4507 entry
= g_ptr_array_index(variant
->fields
, i
);
4508 BT_LOGV("Copying variant field type's field: "
4509 "index=%" PRId64
", "
4510 "field-ft-addr=%p, field-name=\"%s\"",
4511 i
, entry
, g_quark_to_string(entry
->name
));
4512 copy_entry
= g_new0(struct structure_field
, 1);
4514 BT_LOGE_STR("Failed to allocate one variant field type field.");
4518 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4520 BT_LOGE("Cannot copy variant field type's field: "
4521 "index=%" PRId64
", "
4522 "field-ft-addr=%p, field-name=\"%s\"",
4523 i
, entry
, g_quark_to_string(entry
->name
));
4528 copy_entry
->name
= entry
->name
;
4529 copy_entry
->type
= copy_field
;
4530 g_ptr_array_add(copy_variant
->fields
, copy_entry
);
4533 if (variant
->tag_field_path
) {
4534 BT_LOGV_STR("Copying variant field type's tag field path.");
4535 copy_variant
->tag_field_path
= bt_ctf_field_path_copy(
4536 variant
->tag_field_path
);
4537 if (!copy_variant
->tag_field_path
) {
4538 BT_LOGE_STR("Cannot copy variant field type's tag field path.");
4543 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4556 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
4557 struct bt_ctf_field_type
*type
)
4559 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4560 struct bt_ctf_field_type_array
*array
;
4562 BT_LOGD("Copying array field type's: addr=%p", type
);
4563 array
= container_of(type
, struct bt_ctf_field_type_array
,
4565 copy_element
= bt_ctf_field_type_copy(array
->element_type
);
4566 if (!copy_element
) {
4567 BT_LOGE_STR("Cannot copy array field type's element field type.");
4571 copy
= bt_ctf_field_type_array_create(copy_element
, array
->length
);
4573 BT_LOGE_STR("Cannot create array field type.");
4577 BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
4581 bt_put(copy_element
);
4586 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
4587 struct bt_ctf_field_type
*type
)
4589 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4590 struct bt_ctf_field_type_sequence
*sequence
, *copy_sequence
;
4592 BT_LOGD("Copying sequence field type's: addr=%p", type
);
4593 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
4595 copy_element
= bt_ctf_field_type_copy(sequence
->element_type
);
4596 if (!copy_element
) {
4597 BT_LOGE_STR("Cannot copy sequence field type's element field type.");
4601 copy
= bt_ctf_field_type_sequence_create(copy_element
,
4602 sequence
->length_field_name
->len
?
4603 sequence
->length_field_name
->str
: NULL
);
4605 BT_LOGE_STR("Cannot create sequence field type.");
4609 copy_sequence
= container_of(copy
, struct bt_ctf_field_type_sequence
,
4611 if (sequence
->length_field_path
) {
4612 BT_LOGV_STR("Copying sequence field type's length field path.");
4613 copy_sequence
->length_field_path
= bt_ctf_field_path_copy(
4614 sequence
->length_field_path
);
4615 if (!copy_sequence
->length_field_path
) {
4616 BT_LOGE_STR("Cannot copy sequence field type's length field path.");
4621 BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4625 bt_put(copy_element
);
4633 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4634 struct bt_ctf_field_type
*type
)
4636 struct bt_ctf_field_type
*copy
;
4637 struct bt_ctf_field_type_string
*string
;
4639 BT_LOGD("Copying string field type's: addr=%p", type
);
4640 copy
= bt_ctf_field_type_string_create();
4642 BT_LOGE_STR("Cannot create string field type.");
4646 string
= container_of(type
, struct bt_ctf_field_type_string
,
4648 BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
4655 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*type_a
,
4656 struct bt_ctf_field_type
*type_b
)
4659 struct bt_ctf_field_type_integer
*int_type_a
;
4660 struct bt_ctf_field_type_integer
*int_type_b
;
4662 int_type_a
= container_of(type_a
, struct bt_ctf_field_type_integer
,
4664 int_type_b
= container_of(type_b
, struct bt_ctf_field_type_integer
,
4668 if (int_type_a
->size
!= int_type_b
->size
) {
4669 BT_LOGV("Integer field types differ: different sizes: "
4670 "ft-a-size=%u, ft-b-size=%u",
4671 int_type_a
->size
, int_type_b
->size
);
4676 if (int_type_a
->user_byte_order
!= int_type_b
->user_byte_order
) {
4677 BT_LOGV("Integer field types differ: different byte orders: "
4678 "ft-a-bo=%s, ft-b-bo=%s",
4679 bt_ctf_byte_order_string(int_type_a
->user_byte_order
),
4680 bt_ctf_byte_order_string(int_type_b
->user_byte_order
));
4685 if (int_type_a
->is_signed
!= int_type_b
->is_signed
) {
4686 BT_LOGV("Integer field types differ: different signedness: "
4687 "ft-a-is-signed=%d, ft-b-is-signed=%d",
4688 int_type_a
->is_signed
,
4689 int_type_b
->is_signed
);
4694 if (int_type_a
->base
!= int_type_b
->base
) {
4695 BT_LOGV("Integer field types differ: different bases: "
4696 "ft-a-base=%s, ft-b-base=%s",
4697 bt_ctf_integer_base_string(int_type_a
->base
),
4698 bt_ctf_integer_base_string(int_type_b
->base
));
4703 if (int_type_a
->encoding
!= int_type_b
->encoding
) {
4704 BT_LOGV("Integer field types differ: different encodings: "
4705 "ft-a-encoding=%s, ft-b-encoding=%s",
4706 bt_ctf_string_encoding_string(int_type_a
->encoding
),
4707 bt_ctf_string_encoding_string(int_type_b
->encoding
));
4712 if (int_type_a
->mapped_clock
!= int_type_b
->mapped_clock
) {
4713 BT_LOGV("Integer field types differ: different mapped clock classes: "
4714 "ft-a-mapped-clock-class-addr=%p, "
4715 "ft-b-mapped-clock-class-addr=%p, ",
4716 "ft-a-mapped-clock-class-name=\"%s\", ",
4717 "ft-b-mapped-clock-class-name=\"%s\"",
4718 int_type_a
->mapped_clock
, int_type_b
->mapped_clock
,
4719 int_type_a
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_a
->mapped_clock
) : "",
4720 int_type_b
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_b
->mapped_clock
) : "");
4732 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*type_a
,
4733 struct bt_ctf_field_type
*type_b
)
4736 struct bt_ctf_field_type_floating_point
*float_a
;
4737 struct bt_ctf_field_type_floating_point
*float_b
;
4739 float_a
= container_of(type_a
,
4740 struct bt_ctf_field_type_floating_point
, parent
);
4741 float_b
= container_of(type_b
,
4742 struct bt_ctf_field_type_floating_point
, parent
);
4745 if (float_a
->user_byte_order
!= float_b
->user_byte_order
) {
4746 BT_LOGV("Floating point number field types differ: different byte orders: "
4747 "ft-a-bo=%s, ft-b-bo=%s",
4748 bt_ctf_byte_order_string(float_a
->user_byte_order
),
4749 bt_ctf_byte_order_string(float_b
->user_byte_order
));
4753 /* Exponent length */
4754 if (float_a
->exp_dig
!= float_b
->exp_dig
) {
4755 BT_LOGV("Floating point number field types differ: different exponent sizes: "
4756 "ft-a-exp-size=%s, ft-b-exp-size=%s",
4757 float_a
->exp_dig
, float_b
->exp_dig
);
4761 /* Mantissa length */
4762 if (float_a
->mant_dig
!= float_b
->mant_dig
) {
4763 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
4764 "ft-a-mant-size=%s, ft-b-mant-size=%s",
4765 float_a
->mant_dig
, float_b
->mant_dig
);
4777 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
4778 struct enumeration_mapping
*mapping_b
)
4783 if (mapping_a
->string
!= mapping_b
->string
) {
4784 BT_LOGV("Enumeration field type mappings differ: different names: "
4785 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
4786 g_quark_to_string(mapping_a
->string
),
4787 g_quark_to_string(mapping_b
->string
));
4792 if (mapping_a
->range_start
._unsigned
!=
4793 mapping_b
->range_start
._unsigned
) {
4794 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
4795 "mapping-a-range-start-unsigned=%" PRIu64
", "
4796 "mapping-b-range-start-unsigned=%" PRIu64
,
4797 mapping_a
->range_start
._unsigned
,
4798 mapping_b
->range_start
._unsigned
);
4803 if (mapping_a
->range_end
._unsigned
!=
4804 mapping_b
->range_end
._unsigned
) {
4805 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
4806 "mapping-a-range-end-unsigned=%" PRIu64
", "
4807 "mapping-b-range-end-unsigned=%" PRIu64
,
4808 mapping_a
->range_end
._unsigned
,
4809 mapping_b
->range_end
._unsigned
);
4821 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*type_a
,
4822 struct bt_ctf_field_type
*type_b
)
4826 struct bt_ctf_field_type_enumeration
*enum_a
;
4827 struct bt_ctf_field_type_enumeration
*enum_b
;
4829 enum_a
= container_of(type_a
,
4830 struct bt_ctf_field_type_enumeration
, parent
);
4831 enum_b
= container_of(type_b
,
4832 struct bt_ctf_field_type_enumeration
, parent
);
4834 /* Container field type */
4835 ret
= bt_ctf_field_type_compare(enum_a
->container
, enum_b
->container
);
4837 BT_LOGV("Enumeration field types differ: different container field types: "
4838 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
4839 enum_a
->container
, enum_b
->container
);
4846 if (enum_a
->entries
->len
!= enum_b
->entries
->len
) {
4850 for (i
= 0; i
< enum_a
->entries
->len
; ++i
) {
4851 struct enumeration_mapping
*mapping_a
=
4852 g_ptr_array_index(enum_a
->entries
, i
);
4853 struct enumeration_mapping
*mapping_b
=
4854 g_ptr_array_index(enum_b
->entries
, i
);
4856 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4857 BT_LOGV("Enumeration field types differ: different mappings: "
4858 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4859 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4860 mapping_a
, mapping_b
,
4861 g_quark_to_string(mapping_a
->string
),
4862 g_quark_to_string(mapping_b
->string
));
4875 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*type_a
,
4876 struct bt_ctf_field_type
*type_b
)
4879 struct bt_ctf_field_type_string
*string_a
;
4880 struct bt_ctf_field_type_string
*string_b
;
4882 string_a
= container_of(type_a
,
4883 struct bt_ctf_field_type_string
, parent
);
4884 string_b
= container_of(type_b
,
4885 struct bt_ctf_field_type_string
, parent
);
4888 if (string_a
->encoding
!= string_b
->encoding
) {
4889 BT_LOGV("String field types differ: different encodings: "
4890 "ft-a-encoding=%s, ft-b-encoding=%s",
4891 bt_ctf_string_encoding_string(string_a
->encoding
),
4892 bt_ctf_string_encoding_string(string_b
->encoding
));
4904 int compare_structure_fields(struct structure_field
*field_a
,
4905 struct structure_field
*field_b
)
4910 if (field_a
->name
!= field_b
->name
) {
4911 BT_LOGV("Structure/variant field type fields differ: different names: "
4912 "field-a-name=%s, field-b-name=%s",
4913 g_quark_to_string(field_a
->name
),
4914 g_quark_to_string(field_b
->name
));
4919 ret
= bt_ctf_field_type_compare(field_a
->type
, field_b
->type
);
4921 BT_LOGV("Structure/variant field type fields differ: different field types: "
4922 "field-name=\"%s\", field-a-ft-addr=%s, field-b-ft-addr=%s",
4923 g_quark_to_string(field_a
->name
),
4924 field_a
->type
, field_b
->type
);
4932 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*type_a
,
4933 struct bt_ctf_field_type
*type_b
)
4937 struct bt_ctf_field_type_structure
*struct_a
;
4938 struct bt_ctf_field_type_structure
*struct_b
;
4940 struct_a
= container_of(type_a
,
4941 struct bt_ctf_field_type_structure
, parent
);
4942 struct_b
= container_of(type_b
,
4943 struct bt_ctf_field_type_structure
, parent
);
4946 if (bt_ctf_field_type_get_alignment(type_a
) !=
4947 bt_ctf_field_type_get_alignment(type_b
)) {
4948 BT_LOGV("Structure field types differ: different alignments: "
4949 "ft-a-align=%u, ft-b-align=%u",
4950 bt_ctf_field_type_get_alignment(type_a
),
4951 bt_ctf_field_type_get_alignment(type_b
));
4956 if (struct_a
->fields
->len
!= struct_b
->fields
->len
) {
4957 BT_LOGV("Structure field types differ: different field counts: "
4958 "ft-a-field-count=%u, ft-b-field-count=%u",
4959 struct_a
->fields
->len
, struct_b
->fields
->len
);
4963 for (i
= 0; i
< struct_a
->fields
->len
; ++i
) {
4964 struct structure_field
*field_a
=
4965 g_ptr_array_index(struct_a
->fields
, i
);
4966 struct structure_field
*field_b
=
4967 g_ptr_array_index(struct_b
->fields
, i
);
4969 ret
= compare_structure_fields(field_a
, field_b
);
4971 /* compare_structure_fields() logs what differs */
4972 BT_LOGV_STR("Structure field types differ: different fields.");
4985 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*type_a
,
4986 struct bt_ctf_field_type
*type_b
)
4990 struct bt_ctf_field_type_variant
*variant_a
;
4991 struct bt_ctf_field_type_variant
*variant_b
;
4993 variant_a
= container_of(type_a
,
4994 struct bt_ctf_field_type_variant
, parent
);
4995 variant_b
= container_of(type_b
,
4996 struct bt_ctf_field_type_variant
, parent
);
4999 if (strcmp(variant_a
->tag_name
->str
, variant_b
->tag_name
->str
)) {
5000 BT_LOGV("Variant field types differ: different tag field names: "
5001 "ft-a-tag-field-name=%u, ft-b-tag-field-name=%u",
5002 variant_a
->tag_name
->str
, variant_b
->tag_name
->str
);
5007 ret
= bt_ctf_field_type_compare(
5008 (struct bt_ctf_field_type
*) variant_a
->tag
,
5009 (struct bt_ctf_field_type
*) variant_b
->tag
);
5011 BT_LOGV("Variant field types differ: different tag field types: "
5012 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
5013 variant_a
->tag
, variant_b
->tag
);
5020 if (variant_a
->fields
->len
!= variant_b
->fields
->len
) {
5021 BT_LOGV("Structure field types differ: different field counts: "
5022 "ft-a-field-count=%u, ft-b-field-count=%u",
5023 variant_a
->fields
->len
, variant_b
->fields
->len
);
5027 for (i
= 0; i
< variant_a
->fields
->len
; ++i
) {
5028 struct structure_field
*field_a
=
5029 g_ptr_array_index(variant_a
->fields
, i
);
5030 struct structure_field
*field_b
=
5031 g_ptr_array_index(variant_b
->fields
, i
);
5033 ret
= compare_structure_fields(field_a
, field_b
);
5035 /* compare_structure_fields() logs what differs */
5036 BT_LOGV_STR("Variant field types differ: different fields.");
5049 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*type_a
,
5050 struct bt_ctf_field_type
*type_b
)
5053 struct bt_ctf_field_type_array
*array_a
;
5054 struct bt_ctf_field_type_array
*array_b
;
5056 array_a
= container_of(type_a
,
5057 struct bt_ctf_field_type_array
, parent
);
5058 array_b
= container_of(type_b
,
5059 struct bt_ctf_field_type_array
, parent
);
5062 if (array_a
->length
!= array_b
->length
) {
5063 BT_LOGV("Structure field types differ: different lengths: "
5064 "ft-a-length=%u, ft-b-length=%u",
5065 array_a
->length
, array_b
->length
);
5070 ret
= bt_ctf_field_type_compare(array_a
->element_type
,
5071 array_b
->element_type
);
5073 BT_LOGV("Array field types differ: different element field types: "
5074 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5075 array_a
->element_type
, array_b
->element_type
);
5083 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*type_a
,
5084 struct bt_ctf_field_type
*type_b
)
5087 struct bt_ctf_field_type_sequence
*sequence_a
;
5088 struct bt_ctf_field_type_sequence
*sequence_b
;
5090 sequence_a
= container_of(type_a
,
5091 struct bt_ctf_field_type_sequence
, parent
);
5092 sequence_b
= container_of(type_b
,
5093 struct bt_ctf_field_type_sequence
, parent
);
5096 if (strcmp(sequence_a
->length_field_name
->str
,
5097 sequence_b
->length_field_name
->str
)) {
5098 BT_LOGV("Sequence field types differ: different length field names: "
5099 "ft-a-length-field-name=%u, ft-b-length-field-name=%u",
5100 sequence_a
->length_field_name
->str
,
5101 sequence_b
->length_field_name
->str
);
5106 ret
= bt_ctf_field_type_compare(sequence_a
->element_type
,
5107 sequence_b
->element_type
);
5109 BT_LOGV("Sequence field types differ: different element field types: "
5110 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5111 sequence_a
->element_type
, sequence_b
->element_type
);
5118 int bt_ctf_field_type_compare(struct bt_ctf_field_type
*type_a
,
5119 struct bt_ctf_field_type
*type_b
)
5123 if (type_a
== type_b
) {
5124 /* Same reference: equal (even if both are NULL) */
5130 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
5136 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
5141 if (type_a
->id
!= type_b
->id
) {
5142 /* Different type IDs */
5143 BT_LOGV("Field types differ: different IDs: "
5144 "ft-a-addr=%p, ft-b-addr=%p, "
5145 "ft-a-id=%s, ft-b-id=%s",
5147 bt_ctf_field_type_id_string(type_a
->id
),
5148 bt_ctf_field_type_id_string(type_b
->id
));
5152 if (type_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
5153 /* Both have unknown type IDs */
5154 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
5158 ret
= type_compare_funcs
[type_a
->id
](type_a
, type_b
);
5160 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
5169 int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*field_type
)
5171 int64_t field_count
= -1;
5172 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5175 case CTF_TYPE_STRUCT
:
5177 bt_ctf_field_type_structure_get_field_count(field_type
);
5179 case CTF_TYPE_VARIANT
:
5181 bt_ctf_field_type_variant_get_field_count(field_type
);
5183 case CTF_TYPE_ARRAY
:
5184 case CTF_TYPE_SEQUENCE
:
5186 * Array and sequence types always contain a single member
5187 * (the element type).
5199 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
5200 struct bt_ctf_field_type
*field_type
, int index
)
5202 struct bt_ctf_field_type
*field
= NULL
;
5203 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5206 case CTF_TYPE_STRUCT
:
5207 bt_ctf_field_type_structure_get_field_by_index(field_type
,
5208 NULL
, &field
, index
);
5210 case CTF_TYPE_VARIANT
:
5212 int ret
= bt_ctf_field_type_variant_get_field_by_index(
5213 field_type
, NULL
, &field
, index
);
5220 case CTF_TYPE_ARRAY
:
5221 field
= bt_ctf_field_type_array_get_element_type(field_type
);
5223 case CTF_TYPE_SEQUENCE
:
5224 field
= bt_ctf_field_type_sequence_get_element_type(field_type
);
5234 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*field_type
,
5237 int field_index
= -1;
5238 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5241 case CTF_TYPE_STRUCT
:
5242 field_index
= bt_ctf_field_type_structure_get_field_name_index(
5245 case CTF_TYPE_VARIANT
:
5246 field_index
= bt_ctf_field_type_variant_get_field_name_index(
5256 struct bt_ctf_field_path
*bt_ctf_field_type_variant_get_tag_field_path(
5257 struct bt_ctf_field_type
*type
)
5259 struct bt_ctf_field_path
*field_path
= NULL
;
5260 struct bt_ctf_field_type_variant
*variant
;
5263 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5267 if (!bt_ctf_field_type_is_variant(type
)) {
5268 BT_LOGW("Invalid parameter: field type is not a variant field type: "
5269 "addr=%p, ft-id=%s", type
,
5270 bt_ctf_field_type_id_string(type
->id
));
5274 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
5276 field_path
= bt_get(variant
->tag_field_path
);
5281 struct bt_ctf_field_path
*bt_ctf_field_type_sequence_get_length_field_path(
5282 struct bt_ctf_field_type
*type
)
5284 struct bt_ctf_field_path
*field_path
= NULL
;
5285 struct bt_ctf_field_type_sequence
*sequence
;
5288 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5292 if (!bt_ctf_field_type_is_sequence(type
)) {
5293 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
5294 "addr=%p, ft-id=%s", type
,
5295 bt_ctf_field_type_id_string(type
->id
));
5299 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
5301 field_path
= bt_get(sequence
->length_field_path
);