4 * Babeltrace CTF IR - Event Types
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "FIELD-TYPES"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/ctf-ir/field-types-internal.h>
33 #include <babeltrace/ctf-ir/field-path-internal.h>
34 #include <babeltrace/ctf-ir/utils.h>
35 #include <babeltrace/ref.h>
36 #include <babeltrace/ctf-ir/clock-class.h>
37 #include <babeltrace/ctf-ir/clock-class-internal.h>
38 #include <babeltrace/ctf-writer/writer-internal.h>
39 #include <babeltrace/object-internal.h>
40 #include <babeltrace/ref.h>
41 #include <babeltrace/compiler-internal.h>
42 #include <babeltrace/endian-internal.h>
47 struct range_overlap_query
{
62 void bt_ctf_field_type_destroy(struct bt_object
*);
64 void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type
*);
66 void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type
*);
68 void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type
*);
70 void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type
*);
72 void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type
*);
74 void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type
*);
76 void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type
*);
78 void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type
*);
81 void (* const type_destroy_funcs
[])(struct bt_ctf_field_type
*) = {
82 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_destroy
,
83 [BT_CTF_FIELD_TYPE_ID_ENUM
] =
84 bt_ctf_field_type_enumeration_destroy
,
85 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
86 bt_ctf_field_type_floating_point_destroy
,
87 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_destroy
,
88 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_destroy
,
89 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_destroy
,
90 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_destroy
,
91 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_destroy
,
95 void generic_field_type_freeze(struct bt_ctf_field_type
*);
97 void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type
*);
99 void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type
*);
101 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*);
103 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*);
105 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*);
107 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*);
110 type_freeze_func
const type_freeze_funcs
[] = {
111 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_freeze
,
112 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_freeze
,
113 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = generic_field_type_freeze
,
114 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_freeze
,
115 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_freeze
,
116 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_freeze
,
117 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_freeze
,
118 [BT_CTF_FIELD_TYPE_ID_STRING
] = generic_field_type_freeze
,
122 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*,
123 struct metadata_context
*);
125 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*,
126 struct metadata_context
*);
128 int bt_ctf_field_type_floating_point_serialize(
129 struct bt_ctf_field_type
*, struct metadata_context
*);
131 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*,
132 struct metadata_context
*);
134 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*,
135 struct metadata_context
*);
137 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*,
138 struct metadata_context
*);
140 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*,
141 struct metadata_context
*);
143 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*,
144 struct metadata_context
*);
147 type_serialize_func
const type_serialize_funcs
[] = {
148 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_serialize
,
149 [BT_CTF_FIELD_TYPE_ID_ENUM
] =
150 bt_ctf_field_type_enumeration_serialize
,
151 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
152 bt_ctf_field_type_floating_point_serialize
,
153 [BT_CTF_FIELD_TYPE_ID_STRUCT
] =
154 bt_ctf_field_type_structure_serialize
,
155 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_serialize
,
156 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_serialize
,
157 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_serialize
,
158 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_serialize
,
162 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*,
163 enum bt_ctf_byte_order byte_order
);
165 void bt_ctf_field_type_enumeration_set_byte_order(struct bt_ctf_field_type
*,
166 enum bt_ctf_byte_order byte_order
);
168 void bt_ctf_field_type_floating_point_set_byte_order(
169 struct bt_ctf_field_type
*, enum bt_ctf_byte_order byte_order
);
171 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*,
172 enum bt_ctf_byte_order byte_order
);
174 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*,
175 enum bt_ctf_byte_order byte_order
);
177 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*,
178 enum bt_ctf_byte_order byte_order
);
180 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*,
181 enum bt_ctf_byte_order byte_order
);
184 void (* const set_byte_order_funcs
[])(struct bt_ctf_field_type
*,
185 enum bt_ctf_byte_order
) = {
186 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_set_byte_order
,
187 [BT_CTF_FIELD_TYPE_ID_ENUM
] =
188 bt_ctf_field_type_enumeration_set_byte_order
,
189 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
190 bt_ctf_field_type_floating_point_set_byte_order
,
191 [BT_CTF_FIELD_TYPE_ID_STRUCT
] =
192 bt_ctf_field_type_structure_set_byte_order
,
193 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_set_byte_order
,
194 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_set_byte_order
,
195 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_set_byte_order
,
196 [BT_CTF_FIELD_TYPE_ID_STRING
] = NULL
,
200 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
201 struct bt_ctf_field_type
*);
203 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
204 struct bt_ctf_field_type
*);
206 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
207 struct bt_ctf_field_type
*);
209 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
210 struct bt_ctf_field_type
*);
212 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
213 struct bt_ctf_field_type
*);
215 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
216 struct bt_ctf_field_type
*);
218 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
219 struct bt_ctf_field_type
*);
221 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
222 struct bt_ctf_field_type
*);
225 struct bt_ctf_field_type
*(* const type_copy_funcs
[])(
226 struct bt_ctf_field_type
*) = {
227 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_copy
,
228 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_copy
,
229 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_type_floating_point_copy
,
230 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_copy
,
231 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_copy
,
232 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_copy
,
233 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_copy
,
234 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_copy
,
238 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*,
239 struct bt_ctf_field_type
*);
241 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*,
242 struct bt_ctf_field_type
*);
244 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*,
245 struct bt_ctf_field_type
*);
247 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*,
248 struct bt_ctf_field_type
*);
250 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*,
251 struct bt_ctf_field_type
*);
253 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*,
254 struct bt_ctf_field_type
*);
256 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*,
257 struct bt_ctf_field_type
*);
259 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*,
260 struct bt_ctf_field_type
*);
263 int (* const type_compare_funcs
[])(struct bt_ctf_field_type
*,
264 struct bt_ctf_field_type
*) = {
265 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_compare
,
266 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_compare
,
267 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_type_floating_point_compare
,
268 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_compare
,
269 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_compare
,
270 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_compare
,
271 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_compare
,
272 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_type_string_compare
,
276 int bt_ctf_field_type_integer_validate(struct bt_ctf_field_type
*);
278 int bt_ctf_field_type_enumeration_validate(struct bt_ctf_field_type
*);
280 int bt_ctf_field_type_structure_validate(struct bt_ctf_field_type
*);
282 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type
*);
284 int bt_ctf_field_type_array_validate(struct bt_ctf_field_type
*);
286 int bt_ctf_field_type_sequence_validate(struct bt_ctf_field_type
*);
289 int (* const type_validate_funcs
[])(struct bt_ctf_field_type
*) = {
290 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_type_integer_validate
,
291 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = NULL
,
292 [BT_CTF_FIELD_TYPE_ID_STRING
] = NULL
,
293 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_type_enumeration_validate
,
294 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_type_structure_validate
,
295 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_type_variant_validate
,
296 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_type_array_validate
,
297 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_type_sequence_validate
,
301 void destroy_enumeration_mapping(struct enumeration_mapping
*mapping
)
307 void destroy_structure_field(struct structure_field
*field
)
313 BT_LOGD("Destroying structure/variant field type's field object: "
314 "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
315 field
, field
->type
, g_quark_to_string(field
->name
));
316 BT_LOGD_STR("Putting field type.");
322 void check_ranges_overlap(gpointer element
, gpointer query
)
324 struct enumeration_mapping
*mapping
= element
;
325 struct range_overlap_query
*overlap_query
= query
;
327 if (mapping
->range_start
._signed
<= overlap_query
->range_end
._signed
328 && overlap_query
->range_start
._signed
<=
329 mapping
->range_end
._signed
) {
330 overlap_query
->overlaps
= 1;
331 overlap_query
->mapping_name
= mapping
->string
;
334 overlap_query
->overlaps
|=
335 mapping
->string
== overlap_query
->mapping_name
;
337 if (overlap_query
->overlaps
) {
338 BT_LOGV("Overlapping enumeration field type mappings: "
339 "mapping-name=\"%s\", "
340 "mapping-a-range-start=%" PRId64
", "
341 "mapping-a-range-end=%" PRId64
", "
342 "mapping-b-range-start=%" PRId64
", "
343 "mapping-b-range-end=%" PRId64
,
344 g_quark_to_string(mapping
->string
),
345 mapping
->range_start
._signed
,
346 mapping
->range_end
._signed
,
347 overlap_query
->range_start
._signed
,
348 overlap_query
->range_end
._signed
);
353 void check_ranges_overlap_unsigned(gpointer element
, gpointer query
)
355 struct enumeration_mapping
*mapping
= element
;
356 struct range_overlap_query
*overlap_query
= query
;
358 if (mapping
->range_start
._unsigned
<= overlap_query
->range_end
._unsigned
359 && overlap_query
->range_start
._unsigned
<=
360 mapping
->range_end
._unsigned
) {
361 overlap_query
->overlaps
= 1;
362 overlap_query
->mapping_name
= mapping
->string
;
365 overlap_query
->overlaps
|=
366 mapping
->string
== overlap_query
->mapping_name
;
368 if (overlap_query
->overlaps
) {
369 BT_LOGW("Overlapping enumeration field type mappings: "
370 "mapping-name=\"%s\", "
371 "mapping-a-range-start=%" PRIu64
", "
372 "mapping-a-range-end=%" PRIu64
", "
373 "mapping-b-range-start=%" PRIu64
", "
374 "mapping-b-range-end=%" PRIu64
,
375 g_quark_to_string(mapping
->string
),
376 mapping
->range_start
._unsigned
,
377 mapping
->range_end
._unsigned
,
378 overlap_query
->range_start
._unsigned
,
379 overlap_query
->range_end
._unsigned
);
384 gint
compare_enumeration_mappings_signed(struct enumeration_mapping
**a
,
385 struct enumeration_mapping
**b
)
387 return ((*a
)->range_start
._signed
< (*b
)->range_start
._signed
) ? -1 : 1;
391 gint
compare_enumeration_mappings_unsigned(struct enumeration_mapping
**a
,
392 struct enumeration_mapping
**b
)
394 return ((*a
)->range_start
._unsigned
< (*b
)->range_start
._unsigned
) ? -1 : 1;
398 void bt_ctf_field_type_init(struct bt_ctf_field_type
*type
, bt_bool init_bo
)
400 assert(type
&& (type
->id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
) &&
401 (type
->id
< BT_CTF_NR_TYPE_IDS
));
403 bt_object_init(type
, bt_ctf_field_type_destroy
);
404 type
->freeze
= type_freeze_funcs
[type
->id
];
405 type
->serialize
= type_serialize_funcs
[type
->id
];
409 const enum bt_ctf_byte_order bo
= BT_CTF_BYTE_ORDER_NATIVE
;
411 BT_LOGD("Setting initial field type's byte order: bo=%s",
412 bt_ctf_byte_order_string(bo
));
413 ret
= bt_ctf_field_type_set_byte_order(type
, bo
);
421 int add_structure_field(GPtrArray
*fields
,
422 GHashTable
*field_name_to_index
,
423 struct bt_ctf_field_type
*field_type
,
424 const char *field_name
)
427 GQuark name_quark
= g_quark_from_string(field_name
);
428 GQuark underscore_name_quark
;
429 struct structure_field
*field
;
430 GString
*underscore_name
= g_string_new(NULL
);
432 if (!underscore_name
) {
433 BT_LOGE_STR("Failed to allocate a GString.");
438 g_string_assign(underscore_name
, "_");
439 g_string_append(underscore_name
, field_name
);
440 underscore_name_quark
= g_quark_from_string(underscore_name
->str
);
442 /* Make sure structure does not contain a field of the same name */
443 if (g_hash_table_lookup_extended(field_name_to_index
,
444 GUINT_TO_POINTER(name_quark
), NULL
, NULL
)) {
445 BT_LOGW("Structure or variant field type already contains a field type with this name: "
446 "field-name=\"%s\"", field_name
);
451 if (g_hash_table_lookup_extended(field_name_to_index
,
452 GUINT_TO_POINTER(underscore_name_quark
), NULL
, NULL
)) {
453 BT_LOGW("Structure or variant field type already contains a field type with this name: "
454 "field-name=\"%s\"", underscore_name
->str
);
459 field
= g_new0(struct structure_field
, 1);
461 BT_LOGE_STR("Failed to allocate one structure/variant field type field.");
467 field
->name
= name_quark
;
468 field
->type
= field_type
;
469 g_hash_table_insert(field_name_to_index
,
470 GUINT_TO_POINTER(name_quark
),
471 GUINT_TO_POINTER(fields
->len
));
472 g_hash_table_insert(field_name_to_index
,
473 GUINT_TO_POINTER(underscore_name_quark
),
474 GUINT_TO_POINTER(fields
->len
));
475 g_ptr_array_add(fields
, field
);
476 BT_LOGV("Added structure/variant field type field: field-ft-addr=%p, "
477 "field-name=\"%s\"", field_type
, field_name
);
479 g_string_free(underscore_name
, TRUE
);
484 void bt_ctf_field_type_destroy(struct bt_object
*obj
)
486 struct bt_ctf_field_type
*type
;
487 enum bt_ctf_field_type_id type_id
;
489 type
= container_of(obj
, struct bt_ctf_field_type
, base
);
491 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
492 type_id
< BT_CTF_NR_TYPE_IDS
);
493 type_destroy_funcs
[type_id
](type
);
497 int bt_ctf_field_type_integer_validate(struct bt_ctf_field_type
*type
)
501 struct bt_ctf_field_type_integer
*integer
=
502 container_of(type
, struct bt_ctf_field_type_integer
,
505 if (integer
->mapped_clock
&& integer
->is_signed
) {
506 BT_LOGW("Invalid integer field type: cannot be signed and have a mapped clock class: "
507 "ft-addr=%p, clock-class-addr=%p, clock-class-name=\"%s\"",
508 type
, integer
->mapped_clock
,
509 bt_ctf_clock_class_get_name(integer
->mapped_clock
));
519 struct enumeration_mapping
*get_enumeration_mapping(
520 struct bt_ctf_field_type
*type
, uint64_t index
)
522 struct enumeration_mapping
*mapping
= NULL
;
523 struct bt_ctf_field_type_enumeration
*enumeration
;
525 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
527 if (index
>= enumeration
->entries
->len
) {
528 BT_LOGW("Invalid parameter: index is out of bounds: "
529 "addr=%p, index=%" PRIu64
", count=%u",
530 type
, index
, enumeration
->entries
->len
);
534 mapping
= g_ptr_array_index(enumeration
->entries
, index
);
540 * Note: This algorithm is O(n^2) vs number of enumeration mappings.
541 * Only used when freezing an enumeration.
544 void set_enumeration_range_overlap(
545 struct bt_ctf_field_type
*type
)
548 struct bt_ctf_field_type
*container_type
;
549 struct bt_ctf_field_type_enumeration
*enumeration_type
;
552 BT_LOGV("Setting enumeration field type's overlap flag: addr=%p",
554 enumeration_type
= container_of(type
,
555 struct bt_ctf_field_type_enumeration
, parent
);
557 len
= enumeration_type
->entries
->len
;
558 container_type
= enumeration_type
->container
;
559 is_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
561 for (i
= 0; i
< len
; i
++) {
562 for (j
= i
+ 1; j
< len
; j
++) {
563 struct enumeration_mapping
*mapping
[2];
565 mapping
[0] = get_enumeration_mapping(type
, i
);
566 mapping
[1] = get_enumeration_mapping(type
, j
);
568 if (mapping
[0]->range_start
._signed
569 <= mapping
[1]->range_end
._signed
570 && mapping
[0]->range_end
._signed
571 >= mapping
[1]->range_start
._signed
) {
572 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
576 if (mapping
[0]->range_start
._unsigned
577 <= mapping
[1]->range_end
._unsigned
578 && mapping
[0]->range_end
._unsigned
579 >= mapping
[1]->range_start
._unsigned
) {
580 enumeration_type
->has_overlapping_ranges
= BT_TRUE
;
588 if (enumeration_type
->has_overlapping_ranges
) {
589 BT_LOGV_STR("Enumeration field type has overlapping ranges.");
591 BT_LOGV_STR("Enumeration field type has no overlapping ranges.");
596 int bt_ctf_field_type_enumeration_validate(struct bt_ctf_field_type
*type
)
600 struct bt_ctf_field_type_enumeration
*enumeration
=
601 container_of(type
, struct bt_ctf_field_type_enumeration
,
603 struct bt_ctf_field_type
*container_type
=
604 bt_ctf_field_type_enumeration_get_container_type(type
);
606 assert(container_type
);
607 ret
= bt_ctf_field_type_validate(container_type
);
609 BT_LOGW("Invalid enumeration field type: container type is invalid: "
610 "enum-ft-addr=%p, int-ft-addr=%p",
611 type
, container_type
);
615 /* Ensure enum has entries */
616 if (enumeration
->entries
->len
== 0) {
617 BT_LOGW("Invalid enumeration field type: no entries: "
624 BT_PUT(container_type
);
629 int bt_ctf_field_type_sequence_validate(struct bt_ctf_field_type
*type
)
632 struct bt_ctf_field_type
*element_type
= NULL
;
633 struct bt_ctf_field_type_sequence
*sequence
=
634 container_of(type
, struct bt_ctf_field_type_sequence
,
637 /* Length field name should be set at this point */
638 if (sequence
->length_field_name
->len
== 0) {
639 BT_LOGW("Invalid sequence field type: no length field name: "
645 element_type
= bt_ctf_field_type_sequence_get_element_type(type
);
646 assert(element_type
);
647 ret
= bt_ctf_field_type_validate(element_type
);
649 BT_LOGW("Invalid sequence field type: invalid element field type: "
650 "seq-ft-addr=%p, element-ft-add=%p",
655 BT_PUT(element_type
);
661 int bt_ctf_field_type_array_validate(struct bt_ctf_field_type
*type
)
664 struct bt_ctf_field_type
*element_type
= NULL
;
666 element_type
= bt_ctf_field_type_array_get_element_type(type
);
667 assert(element_type
);
668 ret
= bt_ctf_field_type_validate(element_type
);
670 BT_LOGW("Invalid array field type: invalid element field type: "
671 "array-ft-addr=%p, element-ft-add=%p",
675 BT_PUT(element_type
);
680 int bt_ctf_field_type_structure_validate(struct bt_ctf_field_type
*type
)
683 struct bt_ctf_field_type
*child_type
= NULL
;
684 int64_t field_count
= bt_ctf_field_type_structure_get_field_count(type
);
687 assert(field_count
>= 0);
689 for (i
= 0; i
< field_count
; ++i
) {
690 const char *field_name
;
692 ret
= bt_ctf_field_type_structure_get_field_by_index(type
,
693 &field_name
, &child_type
, i
);
695 ret
= bt_ctf_field_type_validate(child_type
);
697 BT_LOGW("Invalid structure field type: "
698 "a contained field type is invalid: "
699 "struct-ft-addr=%p, field-ft-addr=%p, "
700 "field-name=\"%s\", field-index=%" PRId64
,
701 type
, child_type
, field_name
, i
);
715 bt_bool
bt_ctf_field_type_enumeration_has_overlapping_ranges(
716 struct bt_ctf_field_type_enumeration
*enumeration_type
)
718 if (!enumeration_type
->parent
.frozen
) {
719 set_enumeration_range_overlap(&enumeration_type
->parent
);
721 return enumeration_type
->has_overlapping_ranges
;
725 int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type
*type
)
729 struct bt_ctf_field_type
*child_type
= NULL
;
730 struct bt_ctf_field_type_variant
*variant
=
731 container_of(type
, struct bt_ctf_field_type_variant
,
735 if (variant
->tag_name
->len
== 0) {
736 BT_LOGW("Invalid variant field type: no tag field name: "
743 BT_LOGW("Invalid variant field type: no tag field type: "
744 "addr=%p, tag-field-name=\"%s\"", type
,
745 variant
->tag_name
->str
);
750 if (bt_ctf_field_type_enumeration_has_overlapping_ranges(
752 BT_LOGW("Invalid variant field type: enumeration tag field type has overlapping ranges: "
753 "variant-ft-addr=%p, tag-field-name=\"%s\", "
754 "enum-ft-addr=%p", type
, variant
->tag_name
->str
,
761 * It is valid to have a variant field type which does not have
762 * the fields corresponding to each label in the associated
765 * It is also valid to have variant field type fields which
766 * cannot be selected because the variant field type tag has no
767 * mapping named as such. This scenario, while not ideal, cannot
770 * If a non-existing field happens to be selected by an
771 * enumeration while reading a variant field, an error will be
772 * generated at that point (while reading the stream).
774 field_count
= bt_ctf_field_type_variant_get_field_count(type
);
775 if (field_count
< 0) {
776 BT_LOGW("Invalid variant field type: no fields: "
777 "addr=%p, tag-field-name=\"%s\"",
778 type
, variant
->tag_name
->str
);
783 for (i
= 0; i
< field_count
; ++i
) {
784 const char *field_name
;
786 ret
= bt_ctf_field_type_variant_get_field_by_index(type
,
787 &field_name
, &child_type
, i
);
789 ret
= bt_ctf_field_type_validate(child_type
);
791 BT_LOGW("Invalid variant field type: "
792 "a contained field type is invalid: "
793 "variant-ft-addr=%p, tag-field-name=\"%s\", "
794 "field-ft-addr=%p, field-name=\"%s\", "
795 "field-index=%" PRId64
,
796 type
, variant
->tag_name
->str
, child_type
,
811 * This function validates a given field type without considering
812 * where this field type is located. It only validates the properties
813 * of the given field type and the properties of its children if
817 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
)
820 enum bt_ctf_field_type_id id
= bt_ctf_field_type_get_type_id(type
);
825 /* Already marked as valid */
829 if (type_validate_funcs
[id
]) {
830 ret
= type_validate_funcs
[id
](type
);
833 if (!ret
&& type
->frozen
) {
834 /* Field type is valid */
835 BT_LOGV("Marking field type as valid: addr=%p", type
);
843 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
845 struct bt_ctf_field_type_integer
*integer
=
846 g_new0(struct bt_ctf_field_type_integer
, 1);
848 BT_LOGD("Creating integer field type object: size=%u", size
);
851 BT_LOGE_STR("Failed to allocate one integer field type.");
855 if (size
== 0 || size
> 64) {
856 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
861 integer
->parent
.id
= BT_CTF_FIELD_TYPE_ID_INTEGER
;
862 integer
->size
= size
;
863 integer
->base
= BT_CTF_INTEGER_BASE_DECIMAL
;
864 integer
->encoding
= BT_CTF_STRING_ENCODING_NONE
;
865 bt_ctf_field_type_init(&integer
->parent
, TRUE
);
866 BT_LOGD("Created integer field type object: addr=%p, size=%u",
867 &integer
->parent
, size
);
868 return &integer
->parent
;
871 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*type
)
874 struct bt_ctf_field_type_integer
*integer
;
877 BT_LOGW_STR("Invalid parameter: field type is NULL.");
882 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
883 BT_LOGW("Invalid parameter: field type is not an integer field type: "
884 "addr=%p, ft-id=%s", type
,
885 bt_ctf_field_type_id_string(type
->id
));
890 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
891 ret
= (int) integer
->size
;
896 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type
*type
)
899 struct bt_ctf_field_type_integer
*integer
;
902 BT_LOGW_STR("Invalid parameter: field type is NULL.");
907 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
908 BT_LOGW("Invalid parameter: field type is not an integer field type: "
909 "addr=%p, ft-id=%s", type
,
910 bt_ctf_field_type_id_string(type
->id
));
915 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
916 ret
= integer
->is_signed
;
921 bt_bool
bt_ctf_field_type_integer_is_signed(
922 struct bt_ctf_field_type
*int_field_type
)
924 return bt_ctf_field_type_integer_get_signed(int_field_type
) ?
928 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type
*type
,
932 struct bt_ctf_field_type_integer
*integer
;
935 BT_LOGW_STR("Invalid parameter: field type is NULL.");
941 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
947 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
948 BT_LOGW("Invalid parameter: field type is not an integer field type: "
949 "addr=%p, ft-id=%s", type
,
950 bt_ctf_field_type_id_string(type
->id
));
955 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
956 integer
->is_signed
= !!is_signed
;
957 BT_LOGV("Set integer field type's signedness: addr=%p, is-signed=%d",
963 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*type
,
967 struct bt_ctf_field_type_integer
*integer
;
970 BT_LOGW_STR("Invalid parameter: field type is NULL.");
976 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
982 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
983 BT_LOGW("Invalid parameter: field type is not an integer field type: "
984 "addr=%p, ft-id=%s", type
,
985 bt_ctf_field_type_id_string(type
->id
));
990 if (size
== 0 || size
> 64) {
991 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
992 "addr=%p, size=%u", type
, size
);
997 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
998 integer
->size
= size
;
999 BT_LOGV("Set integer field type's size: addr=%p, size=%u",
1005 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
1006 struct bt_ctf_field_type
*type
)
1008 enum bt_ctf_integer_base ret
= BT_CTF_INTEGER_BASE_UNKNOWN
;
1009 struct bt_ctf_field_type_integer
*integer
;
1012 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1016 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1017 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1018 "addr=%p, ft-id=%s", type
,
1019 bt_ctf_field_type_id_string(type
->id
));
1023 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1024 ret
= integer
->base
;
1029 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*type
,
1030 enum bt_ctf_integer_base base
)
1035 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1041 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1047 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1048 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1049 "addr=%p, ft-id=%s", type
,
1050 bt_ctf_field_type_id_string(type
->id
));
1056 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
1057 case BT_CTF_INTEGER_BASE_BINARY
:
1058 case BT_CTF_INTEGER_BASE_OCTAL
:
1059 case BT_CTF_INTEGER_BASE_DECIMAL
:
1060 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
1062 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
1063 struct bt_ctf_field_type_integer
, parent
);
1064 integer
->base
= base
;
1068 BT_LOGW("Invalid parameter: unknown integer field type base: "
1069 "addr=%p, base=%d", type
, base
);
1073 BT_LOGV("Set integer field type's base: addr=%p, base=%s",
1074 type
, bt_ctf_integer_base_string(base
));
1080 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
1081 struct bt_ctf_field_type
*type
)
1083 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
1084 struct bt_ctf_field_type_integer
*integer
;
1087 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1091 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1092 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1093 "addr=%p, ft-id=%s", type
,
1094 bt_ctf_field_type_id_string(type
->id
));
1098 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1099 ret
= integer
->encoding
;
1104 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*type
,
1105 enum bt_ctf_string_encoding encoding
)
1108 struct bt_ctf_field_type_integer
*integer
;
1111 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1117 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1123 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1124 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1125 "addr=%p, ft-id=%s", type
,
1126 bt_ctf_field_type_id_string(type
->id
));
1131 if (encoding
< BT_CTF_STRING_ENCODING_NONE
||
1132 encoding
>= BT_CTF_STRING_ENCODING_UNKNOWN
) {
1133 BT_LOGW("Invalid parameter: unknown string encoding: "
1134 "addr=%p, encoding=%d", type
, encoding
);
1139 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1140 integer
->encoding
= encoding
;
1141 BT_LOGV("Set integer field type's encoding: addr=%p, encoding=%s",
1142 type
, bt_ctf_string_encoding_string(encoding
));
1147 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
1148 struct bt_ctf_field_type
*type
)
1150 struct bt_ctf_field_type_integer
*integer
;
1151 struct bt_ctf_clock_class
*clock_class
= NULL
;
1154 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1158 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1159 clock_class
= integer
->mapped_clock
;
1160 bt_get(clock_class
);
1166 int bt_ctf_field_type_integer_set_mapped_clock_class_no_check(
1167 struct bt_ctf_field_type
*type
,
1168 struct bt_ctf_clock_class
*clock_class
)
1170 struct bt_ctf_field_type_integer
*integer
;
1174 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1180 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
1185 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1186 BT_LOGW("Invalid parameter: field type is not an integer field type: "
1187 "addr=%p, ft-id=%s", type
,
1188 bt_ctf_field_type_id_string(type
->id
));
1192 if (!bt_ctf_clock_class_is_valid(clock_class
)) {
1193 BT_LOGW("Invalid parameter: clock class is invalid: ft-addr=%p"
1194 "clock-class-addr=%p, clock-class-name=\"%s\"",
1196 bt_ctf_clock_class_get_name(clock_class
));
1201 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
1202 bt_put(integer
->mapped_clock
);
1203 integer
->mapped_clock
= bt_get(clock_class
);
1204 BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
1205 "clock-class-addr=%p, clock-class-name=\"%s\"",
1206 type
, clock_class
, bt_ctf_clock_class_get_name(clock_class
));
1211 int bt_ctf_field_type_integer_set_mapped_clock_class(
1212 struct bt_ctf_field_type
*type
,
1213 struct bt_ctf_clock_class
*clock_class
)
1218 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1224 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1230 ret
= bt_ctf_field_type_integer_set_mapped_clock_class_no_check(
1238 void bt_ctf_field_type_enum_iter_destroy(struct bt_object
*obj
)
1240 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
=
1242 struct bt_ctf_field_type_enumeration_mapping_iterator
,
1245 BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
1247 BT_LOGD_STR("Putting parent enumeration field type.");
1248 bt_put(&iter
->enumeration_type
->parent
);
1253 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1254 bt_ctf_field_type_enumeration_find_mappings_type(
1255 struct bt_ctf_field_type
*type
,
1256 enum bt_ctf_field_type_enumeration_mapping_iterator_type iterator_type
)
1258 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1259 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1262 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1266 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1267 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1268 "addr=%p, ft-id=%s", type
,
1269 bt_ctf_field_type_id_string(type
->id
));
1273 enumeration_type
= container_of(type
,
1274 struct bt_ctf_field_type_enumeration
, parent
);
1275 iter
= g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator
, 1);
1277 BT_LOGE_STR("Failed to allocate one enumeration field type mapping.");
1281 bt_object_init(&iter
->base
, bt_ctf_field_type_enum_iter_destroy
);
1283 iter
->enumeration_type
= enumeration_type
;
1285 iter
->type
= iterator_type
;
1290 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1291 bt_ctf_field_type_enumeration_find_mappings_by_name(
1292 struct bt_ctf_field_type
*type
, const char *name
)
1294 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1296 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1297 type
, ITERATOR_BY_NAME
);
1299 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1300 "ft-addr=%p, mapping-name=\"%s\"", type
, name
);
1304 iter
->u
.name_quark
= g_quark_try_string(name
);
1305 if (!iter
->u
.name_quark
) {
1307 * No results are possible, set the iterator's position at the
1310 iter
->index
= iter
->enumeration_type
->entries
->len
;
1318 int bt_ctf_field_type_enumeration_mapping_iterator_next(
1319 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
)
1321 struct bt_ctf_field_type_enumeration
*enumeration
;
1322 struct bt_ctf_field_type
*type
;
1323 int i
, ret
= 0, len
;
1326 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1331 enumeration
= iter
->enumeration_type
;
1332 type
= &enumeration
->parent
;
1333 len
= enumeration
->entries
->len
;
1334 for (i
= iter
->index
+ 1; i
< len
; i
++) {
1335 struct enumeration_mapping
*mapping
=
1336 get_enumeration_mapping(type
, i
);
1338 switch (iter
->type
) {
1339 case ITERATOR_BY_NAME
:
1340 if (mapping
->string
== iter
->u
.name_quark
) {
1345 case ITERATOR_BY_SIGNED_VALUE
:
1347 int64_t value
= iter
->u
.signed_value
;
1349 if (value
>= mapping
->range_start
._signed
&&
1350 value
<= mapping
->range_end
._signed
) {
1356 case ITERATOR_BY_UNSIGNED_VALUE
:
1358 uint64_t value
= iter
->u
.unsigned_value
;
1360 if (value
>= mapping
->range_start
._unsigned
&&
1361 value
<= mapping
->range_end
._unsigned
) {
1368 BT_LOGF("Invalid enumeration field type mapping iterator type: "
1369 "type=%d", iter
->type
);
1379 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1380 bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1381 struct bt_ctf_field_type
*type
, int64_t value
)
1383 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1385 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1386 type
, ITERATOR_BY_SIGNED_VALUE
);
1388 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1389 "ft-addr=%p, value=%" PRId64
, type
, value
);
1393 if (bt_ctf_field_type_integer_get_signed(
1394 iter
->enumeration_type
->container
) != 1) {
1395 BT_LOGW("Invalid parameter: enumeration field type is unsigned: "
1396 "enum-ft-addr=%p, int-ft-addr=%p",
1397 type
, iter
->enumeration_type
->container
);
1401 iter
->u
.signed_value
= value
;
1408 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1409 bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1410 struct bt_ctf_field_type
*type
, uint64_t value
)
1412 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
;
1414 iter
= bt_ctf_field_type_enumeration_find_mappings_type(
1415 type
, ITERATOR_BY_UNSIGNED_VALUE
);
1417 BT_LOGE("Cannot create enumeration field type mapping iterator: "
1418 "ft-addr=%p, value=%" PRIu64
, type
, value
);
1422 if (bt_ctf_field_type_integer_get_signed(
1423 iter
->enumeration_type
->container
) != 0) {
1424 BT_LOGW("Invalid parameter: enumeration field type is signed: "
1425 "enum-ft-addr=%p, int-ft-addr=%p",
1426 type
, iter
->enumeration_type
->container
);
1429 iter
->u
.unsigned_value
= value
;
1436 int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
1437 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1438 const char **mapping_name
, int64_t *range_begin
,
1444 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1449 if (iter
->index
== -1) {
1450 BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
1455 ret
= bt_ctf_field_type_enumeration_get_mapping_signed(
1456 &iter
->enumeration_type
->parent
, iter
->index
,
1457 mapping_name
, range_begin
, range_end
);
1462 int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
1463 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
,
1464 const char **mapping_name
, uint64_t *range_begin
,
1465 uint64_t *range_end
)
1470 BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
1475 if (iter
->index
== -1) {
1476 BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
1481 ret
= bt_ctf_field_type_enumeration_get_mapping_unsigned(
1482 &iter
->enumeration_type
->parent
, iter
->index
,
1483 mapping_name
, range_begin
, range_end
);
1488 int bt_ctf_field_type_enumeration_get_mapping_signed(
1489 struct bt_ctf_field_type
*enum_field_type
,
1490 uint64_t index
, const char **mapping_name
, int64_t *range_begin
,
1494 struct enumeration_mapping
*mapping
;
1496 if (!enum_field_type
) {
1497 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1502 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1504 /* get_enumeration_mapping() reports any error */
1510 *mapping_name
= g_quark_to_string(mapping
->string
);
1511 assert(*mapping_name
);
1515 *range_begin
= mapping
->range_start
._signed
;
1519 *range_end
= mapping
->range_end
._signed
;
1525 int bt_ctf_field_type_enumeration_get_mapping_unsigned(
1526 struct bt_ctf_field_type
*enum_field_type
,
1528 const char **mapping_name
, uint64_t *range_begin
,
1529 uint64_t *range_end
)
1532 struct enumeration_mapping
*mapping
;
1534 if (!enum_field_type
) {
1535 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1540 mapping
= get_enumeration_mapping(enum_field_type
, index
);
1542 /* get_enumeration_mapping() reports any error */
1548 *mapping_name
= g_quark_to_string(mapping
->string
);
1549 assert(*mapping_name
);
1553 *range_begin
= mapping
->range_start
._unsigned
;
1557 *range_end
= mapping
->range_end
._unsigned
;
1563 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
1564 struct bt_ctf_field_type
*integer_container_type
)
1566 struct bt_ctf_field_type_enumeration
*enumeration
= NULL
;
1568 BT_LOGD("Creating enumeration field type object: int-ft-addr=%p",
1569 integer_container_type
);
1571 if (!integer_container_type
) {
1572 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1576 if (integer_container_type
->id
!= BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1577 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
1578 "container-ft-addr=%p, container-ft-id=%s",
1579 integer_container_type
,
1580 bt_ctf_field_type_id_string(integer_container_type
->id
));
1584 enumeration
= g_new0(struct bt_ctf_field_type_enumeration
, 1);
1586 BT_LOGE_STR("Failed to allocate one enumeration field type.");
1590 enumeration
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ENUM
;
1591 bt_get(integer_container_type
);
1592 enumeration
->container
= integer_container_type
;
1593 enumeration
->entries
= g_ptr_array_new_with_free_func(
1594 (GDestroyNotify
)destroy_enumeration_mapping
);
1595 bt_ctf_field_type_init(&enumeration
->parent
, FALSE
);
1596 BT_LOGD("Created enumeration field type object: addr=%p, "
1597 "int-ft-addr=%p, int-ft-size=%u",
1598 &enumeration
->parent
, integer_container_type
,
1599 bt_ctf_field_type_integer_get_size(integer_container_type
));
1600 return &enumeration
->parent
;
1602 g_free(enumeration
);
1606 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_type(
1607 struct bt_ctf_field_type
*type
)
1609 struct bt_ctf_field_type
*container_type
= NULL
;
1610 struct bt_ctf_field_type_enumeration
*enumeration_type
;
1613 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1617 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1618 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1619 "addr=%p, ft-id=%s", type
,
1620 bt_ctf_field_type_id_string(type
->id
));
1624 enumeration_type
= container_of(type
,
1625 struct bt_ctf_field_type_enumeration
, parent
);
1626 container_type
= enumeration_type
->container
;
1627 bt_get(container_type
);
1629 return container_type
;
1632 int bt_ctf_field_type_enumeration_add_mapping_signed(
1633 struct bt_ctf_field_type
*type
, const char *string
,
1634 int64_t range_start
, int64_t range_end
)
1637 GQuark mapping_name
;
1638 struct enumeration_mapping
*mapping
;
1639 struct bt_ctf_field_type_enumeration
*enumeration
;
1640 char *escaped_string
;
1643 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1649 BT_LOGW_STR("Invalid parameter: string is NULL.");
1655 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1661 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1662 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1663 "addr=%p, ft-id=%s", type
,
1664 bt_ctf_field_type_id_string(type
->id
));
1669 if (range_end
< range_start
) {
1670 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1671 "addr=%p, range-start=%" PRId64
", range-end=%" PRId64
,
1672 type
, range_start
, range_end
);
1677 if (strlen(string
) == 0) {
1678 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1679 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1685 escaped_string
= g_strescape(string
, NULL
);
1686 if (!escaped_string
) {
1687 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1688 "mapping-name-addr=%p, mapping-name=\"%s\"",
1689 type
, string
, string
);
1694 mapping
= g_new(struct enumeration_mapping
, 1);
1696 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1700 mapping_name
= g_quark_from_string(escaped_string
);
1701 *mapping
= (struct enumeration_mapping
) {
1702 .range_start
._signed
= range_start
,
1703 .range_end
._signed
= range_end
,
1704 .string
= mapping_name
,
1706 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1708 g_ptr_array_add(enumeration
->entries
, mapping
);
1709 g_ptr_array_sort(enumeration
->entries
,
1710 (GCompareFunc
)compare_enumeration_mappings_signed
);
1711 BT_LOGV("Added mapping to signed enumeration field type: addr=%p, "
1712 "name=\"%s\", range-start=%" PRId64
", "
1713 "range-end=%" PRId64
,
1714 type
, string
, range_start
, range_end
);
1716 free(escaped_string
);
1721 int bt_ctf_field_type_enumeration_add_mapping_unsigned(
1722 struct bt_ctf_field_type
*type
, const char *string
,
1723 uint64_t range_start
, uint64_t range_end
)
1726 GQuark mapping_name
;
1727 struct enumeration_mapping
*mapping
;
1728 struct bt_ctf_field_type_enumeration
*enumeration
;
1729 char *escaped_string
;
1732 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1738 BT_LOGW_STR("Invalid parameter: string is NULL.");
1744 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1750 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1751 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1752 "addr=%p, ft-id=%s", type
,
1753 bt_ctf_field_type_id_string(type
->id
));
1758 if (range_end
< range_start
) {
1759 BT_LOGW("Invalid parameter: range's end is lesser than range's start: "
1760 "addr=%p, range-start=%" PRIu64
", range-end=%" PRIu64
,
1761 type
, range_start
, range_end
);
1766 if (strlen(string
) == 0) {
1767 BT_LOGW("Invalid parameter: mapping name is an empty string: "
1768 "enum-ft-addr=%p, mapping-name-addr=%p", type
,
1774 escaped_string
= g_strescape(string
, NULL
);
1775 if (!escaped_string
) {
1776 BT_LOGE("Cannot escape mapping name: enum-ft-addr=%p, "
1777 "mapping-name-addr=%p, mapping-name=\"%s\"",
1778 type
, string
, string
);
1783 mapping
= g_new(struct enumeration_mapping
, 1);
1785 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1789 mapping_name
= g_quark_from_string(escaped_string
);
1790 *mapping
= (struct enumeration_mapping
) {
1791 .range_start
._unsigned
= range_start
,
1792 .range_end
._unsigned
= range_end
,
1793 .string
= mapping_name
,
1795 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1797 g_ptr_array_add(enumeration
->entries
, mapping
);
1798 g_ptr_array_sort(enumeration
->entries
,
1799 (GCompareFunc
)compare_enumeration_mappings_unsigned
);
1800 BT_LOGV("Added mapping to unsigned enumeration field type: addr=%p, "
1801 "name=\"%s\", range-start=%" PRIu64
", "
1802 "range-end=%" PRIu64
,
1803 type
, string
, range_start
, range_end
);
1805 free(escaped_string
);
1810 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
1811 struct bt_ctf_field_type
*type
)
1814 struct bt_ctf_field_type_enumeration
*enumeration
;
1817 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1822 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ENUM
) {
1823 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
1824 "addr=%p, ft-id=%s", type
,
1825 bt_ctf_field_type_id_string(type
->id
));
1830 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
1832 ret
= (int64_t) enumeration
->entries
->len
;
1837 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
1839 struct bt_ctf_field_type_floating_point
*floating_point
=
1840 g_new0(struct bt_ctf_field_type_floating_point
, 1);
1842 BT_LOGD_STR("Creating floating point number field type object.");
1844 if (!floating_point
) {
1845 BT_LOGE_STR("Failed to allocate one floating point number field type.");
1849 floating_point
->parent
.id
= BT_CTF_FIELD_TYPE_ID_FLOAT
;
1850 floating_point
->exp_dig
= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
;
1851 floating_point
->mant_dig
= FLT_MANT_DIG
;
1852 bt_ctf_field_type_init(&floating_point
->parent
, TRUE
);
1853 BT_LOGD("Created floating point number field type object: addr=%p, "
1854 "exp-size=%u, mant-size=%u", &floating_point
->parent
,
1855 floating_point
->exp_dig
, floating_point
->mant_dig
);
1857 return floating_point
? &floating_point
->parent
: NULL
;
1860 int bt_ctf_field_type_floating_point_get_exponent_digits(
1861 struct bt_ctf_field_type
*type
)
1864 struct bt_ctf_field_type_floating_point
*floating_point
;
1867 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1872 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1873 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1874 "addr=%p, ft-id=%s", type
,
1875 bt_ctf_field_type_id_string(type
->id
));
1880 floating_point
= container_of(type
,
1881 struct bt_ctf_field_type_floating_point
, parent
);
1882 ret
= (int) floating_point
->exp_dig
;
1887 int bt_ctf_field_type_floating_point_set_exponent_digits(
1888 struct bt_ctf_field_type
*type
,
1889 unsigned int exponent_digits
)
1892 struct bt_ctf_field_type_floating_point
*floating_point
;
1895 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1901 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1907 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1908 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1909 "addr=%p, ft-id=%s", type
,
1910 bt_ctf_field_type_id_string(type
->id
));
1915 floating_point
= container_of(type
,
1916 struct bt_ctf_field_type_floating_point
, parent
);
1917 if ((exponent_digits
!= sizeof(float) * CHAR_BIT
- FLT_MANT_DIG
) &&
1918 (exponent_digits
!= sizeof(double) * CHAR_BIT
- DBL_MANT_DIG
) &&
1920 sizeof(long double) * CHAR_BIT
- LDBL_MANT_DIG
)) {
1921 BT_LOGW("Invalid parameter: invalid exponent size: "
1922 "addr=%p, exp-size=%u", type
, exponent_digits
);
1927 floating_point
->exp_dig
= exponent_digits
;
1928 BT_LOGV("Set floating point number field type's exponent size: addr=%p, "
1929 "exp-size=%u", type
, exponent_digits
);
1934 int bt_ctf_field_type_floating_point_get_mantissa_digits(
1935 struct bt_ctf_field_type
*type
)
1938 struct bt_ctf_field_type_floating_point
*floating_point
;
1941 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1946 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1947 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1948 "addr=%p, ft-id=%s", type
,
1949 bt_ctf_field_type_id_string(type
->id
));
1954 floating_point
= container_of(type
,
1955 struct bt_ctf_field_type_floating_point
, parent
);
1956 ret
= (int) floating_point
->mant_dig
;
1961 int bt_ctf_field_type_floating_point_set_mantissa_digits(
1962 struct bt_ctf_field_type
*type
,
1963 unsigned int mantissa_digits
)
1966 struct bt_ctf_field_type_floating_point
*floating_point
;
1969 BT_LOGW_STR("Invalid parameter: field type is NULL.");
1975 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
1981 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1982 BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
1983 "addr=%p, ft-id=%s", type
,
1984 bt_ctf_field_type_id_string(type
->id
));
1989 floating_point
= container_of(type
,
1990 struct bt_ctf_field_type_floating_point
, parent
);
1992 if ((mantissa_digits
!= FLT_MANT_DIG
) &&
1993 (mantissa_digits
!= DBL_MANT_DIG
) &&
1994 (mantissa_digits
!= LDBL_MANT_DIG
)) {
1995 BT_LOGW("Invalid parameter: invalid mantissa size: "
1996 "addr=%p, mant-size=%u", type
, mantissa_digits
);
2001 floating_point
->mant_dig
= mantissa_digits
;
2002 BT_LOGV("Set floating point number field type's mantissa size: addr=%p, "
2003 "mant-size=%u", type
, mantissa_digits
);
2008 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
2010 struct bt_ctf_field_type_structure
*structure
=
2011 g_new0(struct bt_ctf_field_type_structure
, 1);
2013 BT_LOGD_STR("Creating structure field type object.");
2016 BT_LOGE_STR("Failed to allocate one structure field type.");
2020 structure
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRUCT
;
2021 structure
->fields
= g_ptr_array_new_with_free_func(
2022 (GDestroyNotify
)destroy_structure_field
);
2023 structure
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2024 bt_ctf_field_type_init(&structure
->parent
, TRUE
);
2025 BT_LOGD("Created structure field type object: addr=%p",
2026 &structure
->parent
);
2027 return &structure
->parent
;
2032 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*type
,
2033 struct bt_ctf_field_type
*field_type
,
2034 const char *field_name
)
2037 struct bt_ctf_field_type_structure
*structure
;
2040 * TODO: check that `field_type` does not contain `type`,
2044 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2050 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2056 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2062 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2063 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2064 "addr=%p, ft-id=%s", type
,
2065 bt_ctf_field_type_id_string(type
->id
));
2070 if (type
== field_type
) {
2071 BT_LOGW("Invalid parameter: structure field type and field type to add are the same: "
2077 structure
= container_of(type
,
2078 struct bt_ctf_field_type_structure
, parent
);
2079 if (add_structure_field(structure
->fields
,
2080 structure
->field_name_to_index
, field_type
, field_name
)) {
2081 BT_LOGW("Cannot add field to structure field type: "
2082 "struct-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2083 type
, field_type
, field_name
);
2088 BT_LOGV("Added structure field type field: struct-ft-addr=%p, "
2089 "field-ft-addr=%p, field-name=\"%s\"", type
,
2090 field_type
, field_name
);
2095 int64_t bt_ctf_field_type_structure_get_field_count(
2096 struct bt_ctf_field_type
*type
)
2099 struct bt_ctf_field_type_structure
*structure
;
2102 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2107 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2108 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2109 "addr=%p, ft-id=%s", type
,
2110 bt_ctf_field_type_id_string(type
->id
));
2115 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2117 ret
= (int64_t) structure
->fields
->len
;
2122 int bt_ctf_field_type_structure_get_field_by_index(
2123 struct bt_ctf_field_type
*type
,
2124 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2127 struct bt_ctf_field_type_structure
*structure
;
2128 struct structure_field
*field
;
2132 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2137 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRUCT
) {
2138 BT_LOGW("Invalid parameter: field type is not a structure field type: "
2139 "addr=%p, ft-id=%s", type
,
2140 bt_ctf_field_type_id_string(type
->id
));
2145 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2147 if (index
>= structure
->fields
->len
) {
2148 BT_LOGW("Invalid parameter: index is out of bounds: "
2149 "addr=%p, index=%" PRIu64
", count=%u",
2150 type
, index
, structure
->fields
->len
);
2155 field
= g_ptr_array_index(structure
->fields
, index
);
2157 *field_type
= field
->type
;
2158 bt_get(field
->type
);
2161 *field_name
= g_quark_to_string(field
->name
);
2162 assert(*field_name
);
2168 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
2169 struct bt_ctf_field_type
*type
,
2174 struct structure_field
*field
;
2175 struct bt_ctf_field_type_structure
*structure
;
2176 struct bt_ctf_field_type
*field_type
= NULL
;
2179 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2184 BT_LOGW_STR("Invalid parameter: name is NULL.");
2188 name_quark
= g_quark_try_string(name
);
2190 BT_LOGV("No such structure field type field name: "
2191 "ft-addr=%p, field-name=\"%s\"",
2196 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
2198 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
2199 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2200 BT_LOGV("No such structure field type field name: "
2201 "ft-addr=%p, field-name=\"%s\"",
2206 field
= structure
->fields
->pdata
[index
];
2207 field_type
= field
->type
;
2213 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
2214 struct bt_ctf_field_type
*enum_tag
, const char *tag_name
)
2216 struct bt_ctf_field_type_variant
*variant
= NULL
;
2218 BT_LOGD("Creating variant field type object: "
2219 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2220 enum_tag
, tag_name
);
2222 if (tag_name
&& bt_ctf_validate_identifier(tag_name
)) {
2223 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2224 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2225 enum_tag
, tag_name
);
2229 variant
= g_new0(struct bt_ctf_field_type_variant
, 1);
2231 BT_LOGE_STR("Failed to allocate one variant field type.");
2235 variant
->parent
.id
= BT_CTF_FIELD_TYPE_ID_VARIANT
;
2236 variant
->tag_name
= g_string_new(tag_name
);
2237 variant
->field_name_to_index
= g_hash_table_new(NULL
, NULL
);
2238 variant
->fields
= g_ptr_array_new_with_free_func(
2239 (GDestroyNotify
) destroy_structure_field
);
2242 variant
->tag
= container_of(enum_tag
,
2243 struct bt_ctf_field_type_enumeration
, parent
);
2246 bt_ctf_field_type_init(&variant
->parent
, TRUE
);
2247 /* A variant's alignment is undefined */
2248 variant
->parent
.alignment
= 0;
2249 BT_LOGD("Created variant field type object: addr=%p, "
2250 "tag-ft-addr=%p, tag-field-name=\"%s\"",
2251 &variant
->parent
, enum_tag
, tag_name
);
2252 return &variant
->parent
;
2257 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_type(
2258 struct bt_ctf_field_type
*type
)
2260 struct bt_ctf_field_type_variant
*variant
;
2261 struct bt_ctf_field_type
*tag_type
= NULL
;
2264 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2268 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2269 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2270 "addr=%p, ft-id=%s", type
,
2271 bt_ctf_field_type_id_string(type
->id
));
2275 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2276 if (!variant
->tag
) {
2277 BT_LOGV("Variant field type has no tag field type: "
2282 tag_type
= &variant
->tag
->parent
;
2288 const char *bt_ctf_field_type_variant_get_tag_name(
2289 struct bt_ctf_field_type
*type
)
2291 struct bt_ctf_field_type_variant
*variant
;
2292 const char *tag_name
= NULL
;
2295 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2299 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2300 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2301 "addr=%p, ft-id=%s", type
,
2302 bt_ctf_field_type_id_string(type
->id
));
2306 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2307 if (variant
->tag_name
->len
== 0) {
2308 BT_LOGV("Variant field type has no tag field name: "
2313 tag_name
= variant
->tag_name
->str
;
2318 int bt_ctf_field_type_variant_set_tag_name(
2319 struct bt_ctf_field_type
*type
, const char *name
)
2322 struct bt_ctf_field_type_variant
*variant
;
2325 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2331 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2337 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2338 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2339 "addr=%p, ft-id=%s", type
,
2340 bt_ctf_field_type_id_string(type
->id
));
2345 if (bt_ctf_validate_identifier(name
)) {
2346 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
2347 "variant-ft-addr=%p, tag-field-name=\"%s\"",
2353 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2354 g_string_assign(variant
->tag_name
, name
);
2355 BT_LOGV("Set variant field type's tag field name: addr=%p, "
2356 "tag-field-name=\"%s\"", type
, name
);
2361 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*type
,
2362 struct bt_ctf_field_type
*field_type
,
2363 const char *field_name
)
2367 struct bt_ctf_field_type_variant
*variant
;
2368 GQuark field_name_quark
= g_quark_from_string(field_name
);
2371 * TODO: check that `field_type` does not contain `type`,
2375 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2381 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
2387 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2388 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2389 "addr=%p, ft-id=%s", type
,
2390 bt_ctf_field_type_id_string(type
->id
));
2395 if (type
== field_type
) {
2396 BT_LOGW("Invalid parameter: variant field type and field type to add are the same: "
2402 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2404 /* The user has explicitly provided a tag; validate against it. */
2408 /* Make sure this name is present in the enum tag */
2409 for (i
= 0; i
< variant
->tag
->entries
->len
; i
++) {
2410 struct enumeration_mapping
*mapping
=
2411 g_ptr_array_index(variant
->tag
->entries
, i
);
2413 if (mapping
->string
== field_name_quark
) {
2420 /* Validation failed */
2421 BT_LOGW("Invalid parameter: field name does not name a tag field type's mapping: "
2422 "variant-ft-addr=%p, tag-ft-addr=%p, "
2423 "tag-field-name=\"%s\""
2424 "field-ft-addr=%p, field-name=\"%s\"",
2425 type
, variant
->tag
, variant
->tag_name
->str
,
2426 field_type
, field_name
);
2432 if (add_structure_field(variant
->fields
, variant
->field_name_to_index
,
2433 field_type
, field_name
)) {
2434 BT_LOGW("Cannot add field to variant field type: "
2435 "variant-ft-addr=%p, field-ft-addr=%p, field-name=\"%s\"",
2436 type
, field_type
, field_name
);
2441 BT_LOGV("Added variant field type field: variant-ft-addr=%p, "
2442 "field-ft-addr=%p, field-name=\"%s\"", type
,
2443 field_type
, field_name
);
2449 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
2450 struct bt_ctf_field_type
*type
,
2451 const char *field_name
)
2455 struct structure_field
*field
;
2456 struct bt_ctf_field_type_variant
*variant
;
2457 struct bt_ctf_field_type
*field_type
= NULL
;
2460 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2465 BT_LOGW_STR("Invalid parameter: field name is NULL.");
2469 name_quark
= g_quark_try_string(field_name
);
2471 BT_LOGV("No such variant field type field name: "
2472 "ft-addr=%p, field-name=\"%s\"",
2477 variant
= container_of(type
, struct bt_ctf_field_type_variant
, parent
);
2478 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
2479 GUINT_TO_POINTER(name_quark
), NULL
, (gpointer
*)&index
)) {
2480 BT_LOGV("No such variant field type field name: "
2481 "ft-addr=%p, field-name=\"%s\"",
2486 field
= g_ptr_array_index(variant
->fields
, index
);
2487 field_type
= field
->type
;
2493 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
2494 struct bt_ctf_field_type
*type
,
2495 struct bt_ctf_field
*tag
)
2498 const char *enum_value
;
2499 struct bt_ctf_field_type
*field_type
= NULL
;
2500 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
2503 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
2508 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
2512 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2513 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2514 "addr=%p, ft-id=%s", type
,
2515 bt_ctf_field_type_id_string(type
->id
));
2519 iter
= bt_ctf_field_enumeration_get_mappings(tag
);
2520 ret
= bt_ctf_field_type_enumeration_mapping_iterator_next(iter
);
2522 BT_LOGE("Cannot get enumeration field type mapping iterator from enumeration field: "
2523 "enum-field-addr=%p", tag
);
2527 ret
= bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter
,
2528 &enum_value
, NULL
, NULL
);
2530 BT_LOGW("Cannot get enumeration field type mapping iterator's current mapping: "
2531 "iter-addr=%p", iter
);
2535 field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
2542 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*type
)
2545 struct bt_ctf_field_type_variant
*variant
;
2548 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2553 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2554 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2555 "addr=%p, ft-id=%s", type
,
2556 bt_ctf_field_type_id_string(type
->id
));
2561 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2563 ret
= (int64_t) variant
->fields
->len
;
2569 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*type
,
2570 const char **field_name
, struct bt_ctf_field_type
**field_type
,
2573 struct bt_ctf_field_type_variant
*variant
;
2574 struct structure_field
*field
;
2578 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2583 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_VARIANT
) {
2584 BT_LOGW("Invalid parameter: field type is not a variant field type: "
2585 "addr=%p, ft-id=%s", type
,
2586 bt_ctf_field_type_id_string(type
->id
));
2591 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
2593 if (index
>= variant
->fields
->len
) {
2594 BT_LOGW("Invalid parameter: index is out of bounds: "
2595 "addr=%p, index=%" PRIu64
", count=%u",
2596 type
, index
, variant
->fields
->len
);
2601 field
= g_ptr_array_index(variant
->fields
, index
);
2603 *field_type
= field
->type
;
2604 bt_get(field
->type
);
2607 *field_name
= g_quark_to_string(field
->name
);
2608 assert(*field_name
);
2614 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
2615 struct bt_ctf_field_type
*element_type
,
2616 unsigned int length
)
2618 struct bt_ctf_field_type_array
*array
= NULL
;
2620 BT_LOGD("Creating array field type object: element-ft-addr=%p, "
2621 "length=%u", element_type
, length
);
2623 if (!element_type
) {
2624 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2629 BT_LOGW_STR("Invalid parameter: length is zero.");
2633 array
= g_new0(struct bt_ctf_field_type_array
, 1);
2635 BT_LOGE_STR("Failed to allocate one array field type.");
2639 array
->parent
.id
= BT_CTF_FIELD_TYPE_ID_ARRAY
;
2640 bt_get(element_type
);
2641 array
->element_type
= element_type
;
2642 array
->length
= length
;
2643 bt_ctf_field_type_init(&array
->parent
, FALSE
);
2644 BT_LOGD("Created array field type object: addr=%p, "
2645 "element-ft-addr=%p, length=%u",
2646 &array
->parent
, element_type
, length
);
2647 return &array
->parent
;
2652 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_type(
2653 struct bt_ctf_field_type
*type
)
2655 struct bt_ctf_field_type
*ret
= NULL
;
2656 struct bt_ctf_field_type_array
*array
;
2659 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2663 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2664 BT_LOGW("Invalid parameter: field type is not an array field type: "
2665 "addr=%p, ft-id=%s", type
,
2666 bt_ctf_field_type_id_string(type
->id
));
2670 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2671 ret
= array
->element_type
;
2678 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*type
,
2679 struct bt_ctf_field_type
*element_type
)
2682 struct bt_ctf_field_type_array
*array
;
2685 BT_LOGW_STR("Invalid parameter: array field type is NULL.");
2690 if (!element_type
) {
2691 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2696 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2697 BT_LOGW("Invalid parameter: field type is not an array field type: "
2698 "addr=%p, ft-id=%s", type
,
2699 bt_ctf_field_type_id_string(type
->id
));
2704 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2706 if (array
->element_type
) {
2707 BT_PUT(array
->element_type
);
2710 array
->element_type
= element_type
;
2711 bt_get(array
->element_type
);
2712 BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
2713 "element-ft-addr=%p", type
, element_type
);
2719 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*type
)
2722 struct bt_ctf_field_type_array
*array
;
2725 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2730 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_ARRAY
) {
2731 BT_LOGW("Invalid parameter: field type is not an array field type: "
2732 "addr=%p, ft-id=%s", type
,
2733 bt_ctf_field_type_id_string(type
->id
));
2738 array
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
2739 ret
= (int64_t) array
->length
;
2744 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
2745 struct bt_ctf_field_type
*element_type
,
2746 const char *length_field_name
)
2748 struct bt_ctf_field_type_sequence
*sequence
= NULL
;
2750 BT_LOGD("Creating sequence field type object: element-ft-addr=%p, "
2751 "length-field-name=\"%s\"", element_type
, length_field_name
);
2753 if (!element_type
) {
2754 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2758 if (bt_ctf_validate_identifier(length_field_name
)) {
2759 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
2760 "length-field-name=\"%s\"", length_field_name
);
2764 sequence
= g_new0(struct bt_ctf_field_type_sequence
, 1);
2766 BT_LOGE_STR("Failed to allocate one sequence field type.");
2770 sequence
->parent
.id
= BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
2771 bt_get(element_type
);
2772 sequence
->element_type
= element_type
;
2773 sequence
->length_field_name
= g_string_new(length_field_name
);
2774 bt_ctf_field_type_init(&sequence
->parent
, FALSE
);
2775 BT_LOGD("Created sequence field type object: addr=%p, "
2776 "element-ft-addr=%p, length-field-name=\"%s\"",
2777 &sequence
->parent
, element_type
, length_field_name
);
2778 return &sequence
->parent
;
2783 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_type(
2784 struct bt_ctf_field_type
*type
)
2786 struct bt_ctf_field_type
*ret
= NULL
;
2787 struct bt_ctf_field_type_sequence
*sequence
;
2790 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2794 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2795 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2796 "addr=%p, ft-id=%s", type
,
2797 bt_ctf_field_type_id_string(type
->id
));
2801 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2803 ret
= sequence
->element_type
;
2810 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*type
,
2811 struct bt_ctf_field_type
*element_type
)
2814 struct bt_ctf_field_type_sequence
*sequence
;
2817 BT_LOGW_STR("Invalid parameter: sequence field type is NULL.");
2822 if (!element_type
) {
2823 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
2828 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2829 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2830 "addr=%p, ft-id=%s", type
,
2831 bt_ctf_field_type_id_string(type
->id
));
2836 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
, parent
);
2837 if (sequence
->element_type
) {
2838 BT_PUT(sequence
->element_type
);
2841 sequence
->element_type
= element_type
;
2842 bt_get(sequence
->element_type
);
2843 BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
2844 "element-ft-addr=%p", type
, element_type
);
2850 const char *bt_ctf_field_type_sequence_get_length_field_name(
2851 struct bt_ctf_field_type
*type
)
2853 const char *ret
= NULL
;
2854 struct bt_ctf_field_type_sequence
*sequence
;
2857 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2861 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
2862 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
2863 "addr=%p, ft-id=%s", type
,
2864 bt_ctf_field_type_id_string(type
->id
));
2868 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
2870 ret
= sequence
->length_field_name
->str
;
2875 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
2877 struct bt_ctf_field_type_string
*string
=
2878 g_new0(struct bt_ctf_field_type_string
, 1);
2880 BT_LOGD_STR("Creating string field type object.");
2883 BT_LOGE_STR("Failed to allocate one string field type.");
2887 string
->parent
.id
= BT_CTF_FIELD_TYPE_ID_STRING
;
2888 bt_ctf_field_type_init(&string
->parent
, TRUE
);
2889 string
->encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2890 string
->parent
.alignment
= CHAR_BIT
;
2891 BT_LOGD("Created string field type object: addr=%p", &string
->parent
);
2892 return &string
->parent
;
2895 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
2896 struct bt_ctf_field_type
*type
)
2898 struct bt_ctf_field_type_string
*string
;
2899 enum bt_ctf_string_encoding ret
= BT_CTF_STRING_ENCODING_UNKNOWN
;
2902 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2906 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2907 BT_LOGW("Invalid parameter: field type is not a string field type: "
2908 "addr=%p, ft-id=%s", type
,
2909 bt_ctf_field_type_id_string(type
->id
));
2913 string
= container_of(type
, struct bt_ctf_field_type_string
,
2915 ret
= string
->encoding
;
2920 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*type
,
2921 enum bt_ctf_string_encoding encoding
)
2924 struct bt_ctf_field_type_string
*string
;
2927 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2932 if (type
->id
!= BT_CTF_FIELD_TYPE_ID_STRING
) {
2933 BT_LOGW("Invalid parameter: field type is not a string field type: "
2934 "addr=%p, ft-id=%s", type
,
2935 bt_ctf_field_type_id_string(type
->id
));
2940 if ((encoding
!= BT_CTF_STRING_ENCODING_UTF8
&&
2941 encoding
!= BT_CTF_STRING_ENCODING_ASCII
)) {
2942 BT_LOGW("Invalid parameter: unknown string encoding: "
2943 "addr=%p, encoding=%d", type
, encoding
);
2948 string
= container_of(type
, struct bt_ctf_field_type_string
, parent
);
2949 string
->encoding
= encoding
;
2950 BT_LOGV("Set string field type's encoding: addr=%p, encoding=%s",
2951 type
, bt_ctf_string_encoding_string(encoding
));
2956 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*type
)
2959 enum bt_ctf_field_type_id type_id
;
2962 BT_LOGW_STR("Invalid parameter: field type is NULL.");
2968 ret
= (int) type
->alignment
;
2972 type_id
= bt_ctf_field_type_get_type_id(type
);
2974 case BT_CTF_FIELD_TYPE_ID_SEQUENCE
:
2976 struct bt_ctf_field_type
*element
=
2977 bt_ctf_field_type_sequence_get_element_type(type
);
2980 ret
= bt_ctf_field_type_get_alignment(element
);
2984 case BT_CTF_FIELD_TYPE_ID_ARRAY
:
2986 struct bt_ctf_field_type
*element
=
2987 bt_ctf_field_type_array_get_element_type(type
);
2990 ret
= bt_ctf_field_type_get_alignment(element
);
2994 case BT_CTF_FIELD_TYPE_ID_STRUCT
:
2996 int64_t i
, element_count
;
2998 element_count
= bt_ctf_field_type_structure_get_field_count(
3000 assert(element_count
>= 0);
3002 for (i
= 0; i
< element_count
; i
++) {
3003 struct bt_ctf_field_type
*field
;
3004 int field_alignment
;
3006 ret
= bt_ctf_field_type_structure_get_field_by_index(
3007 type
, NULL
, &field
, i
);
3010 field_alignment
= bt_ctf_field_type_get_alignment(
3013 if (field_alignment
< 0) {
3014 ret
= field_alignment
;
3018 type
->alignment
= MAX(field_alignment
, type
->alignment
);
3020 ret
= (int) type
->alignment
;
3023 case BT_CTF_FIELD_TYPE_ID_UNKNOWN
:
3024 BT_LOGW("Invalid parameter: unknown field type ID: "
3025 "addr=%p, ft-id=%d", type
, type_id
);
3029 ret
= (int) type
->alignment
;
3037 int is_power_of_two(unsigned int value
)
3039 return ((value
& (value
- 1)) == 0) && value
> 0;
3042 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*type
,
3043 unsigned int alignment
)
3046 enum bt_ctf_field_type_id type_id
;
3048 /* Alignment must be a power of two */
3050 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3056 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3062 if (!is_power_of_two(alignment
)) {
3063 BT_LOGW("Invalid parameter: alignment is not a power of two: "
3064 "addr=%p, align=%u", type
, alignment
);
3069 type_id
= bt_ctf_field_type_get_type_id(type
);
3070 if (type_id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
3071 BT_LOGW("Invalid parameter: unknown field type ID: "
3072 "addr=%p, ft-id=%d", type
, type_id
);
3077 if (type
->id
== BT_CTF_FIELD_TYPE_ID_STRING
&&
3078 alignment
!= CHAR_BIT
) {
3079 BT_LOGW("Invalid parameter: alignment must be %u for a string field type: "
3080 "addr=%p, align=%u", CHAR_BIT
, type
, alignment
);
3085 if (type_id
== BT_CTF_FIELD_TYPE_ID_VARIANT
||
3086 type_id
== BT_CTF_FIELD_TYPE_ID_SEQUENCE
||
3087 type_id
== BT_CTF_FIELD_TYPE_ID_ARRAY
) {
3088 /* Setting an alignment on these types makes no sense */
3089 BT_LOGW("Invalid parameter: cannot set the alignment of this field type: "
3090 "addr=%p, ft-id=%s", type
,
3091 bt_ctf_field_type_id_string(type
->id
));
3096 type
->alignment
= alignment
;
3098 BT_LOGV("Set field type's alignment: addr=%p, align=%u",
3104 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
3105 struct bt_ctf_field_type
*type
)
3107 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
3110 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3115 case BT_CTF_FIELD_TYPE_ID_INTEGER
:
3117 struct bt_ctf_field_type_integer
*integer
= container_of(
3118 type
, struct bt_ctf_field_type_integer
, parent
);
3119 ret
= integer
->user_byte_order
;
3122 case BT_CTF_FIELD_TYPE_ID_ENUM
:
3124 struct bt_ctf_field_type_enumeration
*enum_ft
= container_of(
3125 type
, struct bt_ctf_field_type_enumeration
, parent
);
3126 ret
= bt_ctf_field_type_get_byte_order(enum_ft
->container
);
3129 case BT_CTF_FIELD_TYPE_ID_FLOAT
:
3131 struct bt_ctf_field_type_floating_point
*floating_point
=
3133 struct bt_ctf_field_type_floating_point
,
3135 ret
= floating_point
->user_byte_order
;
3139 BT_LOGW("Invalid parameter: cannot get the byte order of this field type: "
3140 "addr=%p, ft-id=%s", type
,
3141 bt_ctf_field_type_id_string(type
->id
));
3145 assert(ret
== BT_CTF_BYTE_ORDER_NATIVE
||
3146 ret
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
3147 ret
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
||
3148 ret
== BT_CTF_BYTE_ORDER_NETWORK
);
3154 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*type
,
3155 enum bt_ctf_byte_order byte_order
)
3160 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3166 BT_LOGW("Invalid parameter: field type is frozen: addr=%p",
3172 if (byte_order
!= BT_CTF_BYTE_ORDER_NATIVE
&&
3173 byte_order
!= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
&&
3174 byte_order
!= BT_CTF_BYTE_ORDER_BIG_ENDIAN
&&
3175 byte_order
!= BT_CTF_BYTE_ORDER_NETWORK
) {
3176 BT_LOGW("Invalid parameter: invalid byte order: "
3177 "addr=%p, bo=%s", type
,
3178 bt_ctf_byte_order_string(byte_order
));
3183 if (set_byte_order_funcs
[type
->id
]) {
3184 set_byte_order_funcs
[type
->id
](type
, byte_order
);
3187 BT_LOGV("Set field type's byte order: addr=%p, bo=%s",
3188 type
, bt_ctf_byte_order_string(byte_order
));
3194 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
3195 struct bt_ctf_field_type
*type
)
3198 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3199 return BT_CTF_FIELD_TYPE_ID_UNKNOWN
;
3205 int bt_ctf_field_type_is_integer(struct bt_ctf_field_type
*type
)
3207 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
;
3210 int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type
*type
)
3212 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_FLOAT
;
3215 int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type
*type
)
3217 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ENUM
;
3220 int bt_ctf_field_type_is_string(struct bt_ctf_field_type
*type
)
3222 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRING
;
3225 int bt_ctf_field_type_is_structure(struct bt_ctf_field_type
*type
)
3227 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
;
3230 int bt_ctf_field_type_is_array(struct bt_ctf_field_type
*type
)
3232 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_ARRAY
;
3235 int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type
*type
)
3237 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
3240 int bt_ctf_field_type_is_variant(struct bt_ctf_field_type
*type
)
3242 return bt_ctf_field_type_get_type_id(type
) == BT_CTF_FIELD_TYPE_ID_VARIANT
;
3245 /* Pre-2.0 CTF writer backward compatibility */
3246 void bt_ctf_field_type_get(struct bt_ctf_field_type
*type
)
3251 /* Pre-2.0 CTF writer backward compatibility */
3252 void bt_ctf_field_type_put(struct bt_ctf_field_type
*type
)
3258 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
)
3260 if (!type
|| type
->frozen
) {
3268 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
3269 struct bt_ctf_field_type_variant
*variant
,
3272 struct bt_ctf_field_type
*type
= NULL
;
3273 GQuark field_name_quark
;
3275 struct structure_field
*field_entry
;
3276 struct range_overlap_query query
= {
3277 .range_start
._signed
= tag_value
,
3278 .range_end
._signed
= tag_value
,
3283 g_ptr_array_foreach(variant
->tag
->entries
, check_ranges_overlap
,
3285 if (!query
.overlaps
) {
3289 field_name_quark
= query
.mapping_name
;
3290 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3291 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3295 field_entry
= g_ptr_array_index(variant
->fields
, (size_t) index
);
3296 type
= field_entry
->type
;
3302 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
3303 struct bt_ctf_field_type_variant
*variant
,
3306 struct bt_ctf_field_type
*type
= NULL
;
3307 GQuark field_name_quark
;
3309 struct structure_field
*field_entry
;
3310 struct range_overlap_query query
= {
3311 .range_start
._unsigned
= tag_value
,
3312 .range_end
._unsigned
= tag_value
,
3317 g_ptr_array_foreach(variant
->tag
->entries
,
3318 check_ranges_overlap_unsigned
,
3320 if (!query
.overlaps
) {
3324 field_name_quark
= query
.mapping_name
;
3325 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3326 GUINT_TO_POINTER(field_name_quark
), NULL
, &index
)) {
3330 field_entry
= g_ptr_array_index(variant
->fields
, (size_t)index
);
3331 type
= field_entry
->type
;
3337 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
3338 struct metadata_context
*context
)
3345 /* Make sure field type is valid before serializing it */
3346 ret
= bt_ctf_field_type_validate(type
);
3348 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
3353 ret
= type
->serialize(type
, context
);
3358 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*type
)
3360 struct bt_ctf_field_type
*copy
= NULL
;
3363 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3367 copy
= type_copy_funcs
[type
->id
](type
);
3369 BT_LOGE_STR("Cannot copy field type.");
3373 copy
->alignment
= type
->alignment
;
3379 int bt_ctf_field_type_structure_get_field_name_index(
3380 struct bt_ctf_field_type
*type
, const char *name
)
3385 struct bt_ctf_field_type_structure
*structure
;
3388 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3394 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3399 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
3400 BT_LOGW("Invalid parameter: field type is not a structure field type: "
3401 "addr=%p, ft-id=%s", type
,
3402 bt_ctf_field_type_id_string(type
->id
));
3407 name_quark
= g_quark_try_string(name
);
3409 BT_LOGV("No such structure field type field name: "
3410 "ft-addr=%p, field-name=\"%s\"",
3416 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
3418 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
3419 GUINT_TO_POINTER(name_quark
),
3420 NULL
, (gpointer
*)&index
)) {
3421 BT_LOGV("No such structure field type field name: "
3422 "ft-addr=%p, field-name=\"%s\"",
3433 int bt_ctf_field_type_variant_get_field_name_index(
3434 struct bt_ctf_field_type
*type
, const char *name
)
3439 struct bt_ctf_field_type_variant
*variant
;
3442 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3448 BT_LOGW_STR("Invalid parameter: field name is NULL.");
3453 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3454 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3455 "addr=%p, ft-id=%s", type
,
3456 bt_ctf_field_type_id_string(type
->id
));
3461 name_quark
= g_quark_try_string(name
);
3463 BT_LOGV("No such variant field type field name: "
3464 "ft-addr=%p, field-name=\"%s\"",
3470 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3472 if (!g_hash_table_lookup_extended(variant
->field_name_to_index
,
3473 GUINT_TO_POINTER(name_quark
),
3474 NULL
, (gpointer
*)&index
)) {
3475 BT_LOGV("No such variant field type field name: "
3476 "ft-addr=%p, field-name=\"%s\"",
3487 int bt_ctf_field_type_sequence_set_length_field_path(
3488 struct bt_ctf_field_type
*type
,
3489 struct bt_ctf_field_path
*path
)
3492 struct bt_ctf_field_type_sequence
*sequence
;
3495 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3500 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
3501 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
3502 "addr=%p, ft-id=%s", type
,
3503 bt_ctf_field_type_id_string(type
->id
));
3508 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
3511 BT_MOVE(sequence
->length_field_path
, path
);
3512 BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
3513 "field-path-addr=%p", type
, path
);
3519 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
3520 struct bt_ctf_field_path
*path
)
3523 struct bt_ctf_field_type_variant
*variant
;
3526 BT_LOGW_STR("Invalid parameter: field type is NULL.");
3531 if (bt_ctf_field_type_get_type_id(type
) != BT_CTF_FIELD_TYPE_ID_VARIANT
) {
3532 BT_LOGW("Invalid parameter: field type is not a variant field type: "
3533 "addr=%p, ft-id=%s", type
,
3534 bt_ctf_field_type_id_string(type
->id
));
3539 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3542 BT_MOVE(variant
->tag_field_path
, path
);
3543 BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
3544 "field-path-addr=%p", type
, path
);
3550 int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type
*type
,
3551 struct bt_ctf_field_type
*tag
)
3554 struct bt_ctf_field_type_variant
*variant
;
3557 BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
3563 BT_LOGW_STR("Invalid parameter: tag field type is NULL.");
3568 if (bt_ctf_field_type_get_type_id(tag
) != BT_CTF_FIELD_TYPE_ID_ENUM
) {
3569 BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
3570 "addr=%p, ft-id=%s", type
,
3571 bt_ctf_field_type_id_string(type
->id
));
3576 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
3580 bt_put(&variant
->tag
->parent
);
3582 variant
->tag
= container_of(tag
, struct bt_ctf_field_type_enumeration
,
3584 BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
3585 "tag-ft-addr=%p", type
, tag
);
3591 void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type
*type
)
3593 struct bt_ctf_field_type_integer
*integer
=
3594 (struct bt_ctf_field_type_integer
*) type
;
3600 BT_LOGD("Destroying integer field type object: addr=%p", type
);
3601 BT_LOGD_STR("Putting mapped clock class.");
3602 bt_put(integer
->mapped_clock
);
3607 void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type
*type
)
3609 struct bt_ctf_field_type_enumeration
*enumeration
=
3610 (struct bt_ctf_field_type_enumeration
*) type
;
3616 BT_LOGD("Destroying enumeration field type object: addr=%p", type
);
3617 g_ptr_array_free(enumeration
->entries
, TRUE
);
3618 BT_LOGD_STR("Putting container field type.");
3619 bt_put(enumeration
->container
);
3620 g_free(enumeration
);
3624 void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type
*type
)
3626 struct bt_ctf_field_type_floating_point
*floating_point
=
3627 (struct bt_ctf_field_type_floating_point
*) type
;
3633 BT_LOGD("Destroying floating point number field type object: addr=%p", type
);
3634 g_free(floating_point
);
3638 void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type
*type
)
3640 struct bt_ctf_field_type_structure
*structure
=
3641 (struct bt_ctf_field_type_structure
*) type
;
3647 BT_LOGD("Destroying structure field type object: addr=%p", type
);
3648 g_ptr_array_free(structure
->fields
, TRUE
);
3649 g_hash_table_destroy(structure
->field_name_to_index
);
3654 void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type
*type
)
3656 struct bt_ctf_field_type_variant
*variant
=
3657 (struct bt_ctf_field_type_variant
*) type
;
3663 BT_LOGD("Destroying variant field type object: addr=%p", type
);
3664 g_ptr_array_free(variant
->fields
, TRUE
);
3665 g_hash_table_destroy(variant
->field_name_to_index
);
3666 g_string_free(variant
->tag_name
, TRUE
);
3667 BT_LOGD_STR("Putting tag field type.");
3668 bt_put(&variant
->tag
->parent
);
3669 BT_PUT(variant
->tag_field_path
);
3674 void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type
*type
)
3676 struct bt_ctf_field_type_array
*array
=
3677 (struct bt_ctf_field_type_array
*) type
;
3683 BT_LOGD("Destroying array field type object: addr=%p", type
);
3684 BT_LOGD_STR("Putting element field type.");
3685 bt_put(array
->element_type
);
3690 void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type
*type
)
3692 struct bt_ctf_field_type_sequence
*sequence
=
3693 (struct bt_ctf_field_type_sequence
*) type
;
3699 BT_LOGD("Destroying sequence field type object: addr=%p", type
);
3700 BT_LOGD_STR("Putting element field type.");
3701 bt_put(sequence
->element_type
);
3702 g_string_free(sequence
->length_field_name
, TRUE
);
3703 BT_LOGD_STR("Putting length field path.");
3704 BT_PUT(sequence
->length_field_path
);
3709 void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type
*type
)
3711 struct bt_ctf_field_type_string
*string
=
3712 (struct bt_ctf_field_type_string
*) type
;
3718 BT_LOGD("Destroying string field type object: addr=%p", type
);
3723 void generic_field_type_freeze(struct bt_ctf_field_type
*type
)
3729 void bt_ctf_field_type_integer_freeze(struct bt_ctf_field_type
*type
)
3731 struct bt_ctf_field_type_integer
*integer_type
= container_of(
3732 type
, struct bt_ctf_field_type_integer
, parent
);
3734 BT_LOGD("Freezing integer field type object: addr=%p", type
);
3736 if (integer_type
->mapped_clock
) {
3737 BT_LOGD_STR("Freezing integer field type's mapped clock class.");
3738 bt_ctf_clock_class_freeze(integer_type
->mapped_clock
);
3741 generic_field_type_freeze(type
);
3745 void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type
*type
)
3747 struct bt_ctf_field_type_enumeration
*enumeration_type
= container_of(
3748 type
, struct bt_ctf_field_type_enumeration
, parent
);
3750 BT_LOGD("Freezing enumeration field type object: addr=%p", type
);
3751 set_enumeration_range_overlap(type
);
3752 generic_field_type_freeze(type
);
3753 BT_LOGD("Freezing enumeration field type object's container field type: int-ft-addr=%p",
3754 enumeration_type
->container
);
3755 bt_ctf_field_type_freeze(enumeration_type
->container
);
3759 void freeze_structure_field(struct structure_field
*field
)
3761 BT_LOGD("Freezing structure/variant field type field: field-addr=%p, "
3762 "field-ft-addr=%p, field-name=\"%s\"", field
,
3763 field
->type
, g_quark_to_string(field
->name
));
3764 bt_ctf_field_type_freeze(field
->type
);
3768 void bt_ctf_field_type_structure_freeze(struct bt_ctf_field_type
*type
)
3770 struct bt_ctf_field_type_structure
*structure_type
= container_of(
3771 type
, struct bt_ctf_field_type_structure
, parent
);
3773 /* Cache the alignment */
3774 BT_LOGD("Freezing structure field type object: addr=%p", type
);
3775 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3776 generic_field_type_freeze(type
);
3777 g_ptr_array_foreach(structure_type
->fields
,
3778 (GFunc
) freeze_structure_field
, NULL
);
3782 void bt_ctf_field_type_variant_freeze(struct bt_ctf_field_type
*type
)
3784 struct bt_ctf_field_type_variant
*variant_type
= container_of(
3785 type
, struct bt_ctf_field_type_variant
, parent
);
3787 BT_LOGD("Freezing variant field type object: addr=%p", type
);
3788 generic_field_type_freeze(type
);
3789 g_ptr_array_foreach(variant_type
->fields
,
3790 (GFunc
) freeze_structure_field
, NULL
);
3794 void bt_ctf_field_type_array_freeze(struct bt_ctf_field_type
*type
)
3796 struct bt_ctf_field_type_array
*array_type
= container_of(
3797 type
, struct bt_ctf_field_type_array
, parent
);
3799 /* Cache the alignment */
3800 BT_LOGD("Freezing array field type object: addr=%p", type
);
3801 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3802 generic_field_type_freeze(type
);
3803 BT_LOGD("Freezing array field type object's element field type: element-ft-addr=%p",
3804 array_type
->element_type
);
3805 bt_ctf_field_type_freeze(array_type
->element_type
);
3809 void bt_ctf_field_type_sequence_freeze(struct bt_ctf_field_type
*type
)
3811 struct bt_ctf_field_type_sequence
*sequence_type
= container_of(
3812 type
, struct bt_ctf_field_type_sequence
, parent
);
3814 /* Cache the alignment */
3815 BT_LOGD("Freezing sequence field type object: addr=%p", type
);
3816 type
->alignment
= bt_ctf_field_type_get_alignment(type
);
3817 generic_field_type_freeze(type
);
3818 BT_LOGD("Freezing sequence field type object's element field type: element-ft-addr=%p",
3819 sequence_type
->element_type
);
3820 bt_ctf_field_type_freeze(sequence_type
->element_type
);
3824 const char *get_encoding_string(enum bt_ctf_string_encoding encoding
)
3826 const char *encoding_string
;
3829 case BT_CTF_STRING_ENCODING_NONE
:
3830 encoding_string
= "none";
3832 case BT_CTF_STRING_ENCODING_ASCII
:
3833 encoding_string
= "ASCII";
3835 case BT_CTF_STRING_ENCODING_UTF8
:
3836 encoding_string
= "UTF8";
3839 encoding_string
= "unknown";
3843 return encoding_string
;
3847 const char *get_integer_base_string(enum bt_ctf_integer_base base
)
3849 const char *base_string
;
3852 case BT_CTF_INTEGER_BASE_DECIMAL
:
3853 case BT_CTF_INTEGER_BASE_UNSPECIFIED
:
3854 base_string
= "decimal";
3856 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
3857 base_string
= "hexadecimal";
3859 case BT_CTF_INTEGER_BASE_OCTAL
:
3860 base_string
= "octal";
3862 case BT_CTF_INTEGER_BASE_BINARY
:
3863 base_string
= "binary";
3866 base_string
= "unknown";
3874 void append_struct_variant_field_name(struct metadata_context
*context
,
3877 g_string_append_c(context
->string
, ' ');
3879 if (bt_ctf_validate_identifier(name
)) {
3880 g_string_append_c(context
->string
, '_');
3883 g_string_append(context
->string
, name
);
3887 int bt_ctf_field_type_integer_serialize(struct bt_ctf_field_type
*type
,
3888 struct metadata_context
*context
)
3890 struct bt_ctf_field_type_integer
*integer
= container_of(type
,
3891 struct bt_ctf_field_type_integer
, parent
);
3894 BT_LOGD("Serializing integer field type's metadata: "
3895 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3896 g_string_append_printf(context
->string
,
3897 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
3898 integer
->size
, type
->alignment
,
3899 (integer
->is_signed
? "true" : "false"),
3900 get_encoding_string(integer
->encoding
),
3901 get_integer_base_string(integer
->base
),
3902 get_byte_order_string(integer
->user_byte_order
));
3903 if (integer
->mapped_clock
) {
3904 const char *clock_name
= bt_ctf_clock_class_get_name(
3905 integer
->mapped_clock
);
3908 g_string_append_printf(context
->string
,
3909 "; map = clock.%s.value", clock_name
);
3912 g_string_append(context
->string
, "; }");
3917 int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type
*type
,
3918 struct metadata_context
*context
)
3922 struct bt_ctf_field_type_enumeration
*enumeration
= container_of(type
,
3923 struct bt_ctf_field_type_enumeration
, parent
);
3924 struct bt_ctf_field_type
*container_type
;
3925 int container_signed
;
3927 BT_LOGD("Serializing enumeration field type's metadata: "
3928 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
3929 container_type
= bt_ctf_field_type_enumeration_get_container_type(type
);
3930 assert(container_type
);
3931 container_signed
= bt_ctf_field_type_integer_get_signed(container_type
);
3932 assert(container_signed
>= 0);
3933 g_string_append(context
->string
, "enum : ");
3934 BT_LOGD_STR("Serializing enumeration field type's container field type's metadata.");
3935 ret
= bt_ctf_field_type_serialize(enumeration
->container
, context
);
3937 BT_LOGW("Cannot serialize enumeration field type's container field type's metadata: "
3938 "container-ft-addr=%p", enumeration
->container
);
3942 g_string_append(context
->string
, " { ");
3943 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
3944 struct enumeration_mapping
*mapping
=
3945 enumeration
->entries
->pdata
[entry
];
3947 if (container_signed
) {
3948 if (mapping
->range_start
._signed
==
3949 mapping
->range_end
._signed
) {
3950 g_string_append_printf(context
->string
,
3951 "\"%s\" = %" PRId64
,
3952 g_quark_to_string(mapping
->string
),
3953 mapping
->range_start
._signed
);
3955 g_string_append_printf(context
->string
,
3956 "\"%s\" = %" PRId64
" ... %" PRId64
,
3957 g_quark_to_string(mapping
->string
),
3958 mapping
->range_start
._signed
,
3959 mapping
->range_end
._signed
);
3962 if (mapping
->range_start
._unsigned
==
3963 mapping
->range_end
._unsigned
) {
3964 g_string_append_printf(context
->string
,
3965 "\"%s\" = %" PRIu64
,
3966 g_quark_to_string(mapping
->string
),
3967 mapping
->range_start
._unsigned
);
3969 g_string_append_printf(context
->string
,
3970 "\"%s\" = %" PRIu64
" ... %" PRIu64
,
3971 g_quark_to_string(mapping
->string
),
3972 mapping
->range_start
._unsigned
,
3973 mapping
->range_end
._unsigned
);
3977 g_string_append(context
->string
,
3978 ((entry
!= (enumeration
->entries
->len
- 1)) ?
3982 if (context
->field_name
->len
) {
3983 append_struct_variant_field_name(context
,
3984 context
->field_name
->str
);
3985 g_string_assign(context
->field_name
, "");
3988 bt_put(container_type
);
3993 int bt_ctf_field_type_floating_point_serialize(struct bt_ctf_field_type
*type
,
3994 struct metadata_context
*context
)
3996 struct bt_ctf_field_type_floating_point
*floating_point
= container_of(
3997 type
, struct bt_ctf_field_type_floating_point
, parent
);
3999 BT_LOGD("Serializing floating point number field type's metadata: "
4000 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4001 g_string_append_printf(context
->string
,
4002 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
4003 floating_point
->exp_dig
,
4004 floating_point
->mant_dig
,
4005 get_byte_order_string(floating_point
->user_byte_order
),
4011 int bt_ctf_field_type_structure_serialize(struct bt_ctf_field_type
*type
,
4012 struct metadata_context
*context
)
4015 unsigned int indent
;
4017 struct bt_ctf_field_type_structure
*structure
= container_of(type
,
4018 struct bt_ctf_field_type_structure
, parent
);
4019 GString
*structure_field_name
= context
->field_name
;
4021 BT_LOGD("Serializing structure field type's metadata: "
4022 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4023 context
->field_name
= g_string_new("");
4025 context
->current_indentation_level
++;
4026 g_string_append(context
->string
, "struct {\n");
4028 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4029 struct structure_field
*field
= structure
->fields
->pdata
[i
];
4031 BT_LOGD("Serializing structure field type's field metadata: "
4033 "field-ft-addr=%p, field-name=\"%s\"",
4034 i
, field
, g_quark_to_string(field
->name
));
4036 for (indent
= 0; indent
< context
->current_indentation_level
;
4038 g_string_append_c(context
->string
, '\t');
4041 g_string_assign(context
->field_name
,
4042 g_quark_to_string(field
->name
));
4043 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4045 BT_LOGW("Cannot serialize structure field type's field's metadata: "
4047 "field-ft-addr=%p, field-name=\"%s\"",
4049 g_quark_to_string(field
->name
));
4053 if (context
->field_name
->len
) {
4054 append_struct_variant_field_name(context
,
4055 context
->field_name
->str
);
4057 g_string_append(context
->string
, ";\n");
4060 context
->current_indentation_level
--;
4061 for (indent
= 0; indent
< context
->current_indentation_level
;
4063 g_string_append_c(context
->string
, '\t');
4066 g_string_append_printf(context
->string
, "} align(%u)",
4069 g_string_free(context
->field_name
, TRUE
);
4070 context
->field_name
= structure_field_name
;
4075 int bt_ctf_field_type_variant_serialize(struct bt_ctf_field_type
*type
,
4076 struct metadata_context
*context
)
4079 unsigned int indent
;
4081 struct bt_ctf_field_type_variant
*variant
= container_of(
4082 type
, struct bt_ctf_field_type_variant
, parent
);
4083 GString
*variant_field_name
= context
->field_name
;
4085 BT_LOGD("Serializing variant field type's metadata: "
4086 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4087 context
->field_name
= g_string_new("");
4088 if (variant
->tag_name
->len
> 0) {
4089 g_string_append_printf(context
->string
,
4090 "variant <%s> {\n", variant
->tag_name
->str
);
4092 g_string_append(context
->string
, "variant {\n");
4095 context
->current_indentation_level
++;
4096 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4097 struct structure_field
*field
= variant
->fields
->pdata
[i
];
4099 BT_LOGD("Serializing variant field type's field metadata: "
4101 "field-ft-addr=%p, field-name=\"%s\"",
4102 i
, field
, g_quark_to_string(field
->name
));
4104 g_string_assign(context
->field_name
,
4105 g_quark_to_string(field
->name
));
4106 for (indent
= 0; indent
< context
->current_indentation_level
;
4108 g_string_append_c(context
->string
, '\t');
4111 g_string_assign(context
->field_name
,
4112 g_quark_to_string(field
->name
));
4113 ret
= bt_ctf_field_type_serialize(field
->type
, context
);
4115 BT_LOGW("Cannot serialize variant field type's field's metadata: "
4117 "field-ft-addr=%p, field-name=\"%s\"",
4119 g_quark_to_string(field
->name
));
4123 if (context
->field_name
->len
) {
4124 append_struct_variant_field_name(context
,
4125 context
->field_name
->str
);
4126 g_string_append_c(context
->string
, ';');
4129 g_string_append_c(context
->string
, '\n');
4132 context
->current_indentation_level
--;
4133 for (indent
= 0; indent
< context
->current_indentation_level
;
4135 g_string_append_c(context
->string
, '\t');
4138 g_string_append(context
->string
, "}");
4140 g_string_free(context
->field_name
, TRUE
);
4141 context
->field_name
= variant_field_name
;
4146 int bt_ctf_field_type_array_serialize(struct bt_ctf_field_type
*type
,
4147 struct metadata_context
*context
)
4150 struct bt_ctf_field_type_array
*array
= container_of(type
,
4151 struct bt_ctf_field_type_array
, parent
);
4153 BT_LOGD("Serializing array field type's metadata: "
4154 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4155 BT_LOGD_STR("Serializing array field type's element field type's metadata.");
4156 ret
= bt_ctf_field_type_serialize(array
->element_type
, context
);
4158 BT_LOGW("Cannot serialize array field type's element field type's metadata: "
4159 "element-ft-addr=%p", array
->element_type
);
4163 if (context
->field_name
->len
) {
4164 append_struct_variant_field_name(context
,
4165 context
->field_name
->str
);
4167 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4168 g_string_assign(context
->field_name
, "");
4170 g_string_append_printf(context
->string
, "[%u]", array
->length
);
4177 int bt_ctf_field_type_sequence_serialize(struct bt_ctf_field_type
*type
,
4178 struct metadata_context
*context
)
4181 struct bt_ctf_field_type_sequence
*sequence
= container_of(
4182 type
, struct bt_ctf_field_type_sequence
, parent
);
4184 BT_LOGD("Serializing sequence field type's metadata: "
4185 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4186 BT_LOGD_STR("Serializing sequence field type's element field type's metadata.");
4187 ret
= bt_ctf_field_type_serialize(sequence
->element_type
, context
);
4189 BT_LOGW("Cannot serialize sequence field type's element field type's metadata: "
4190 "element-ft-addr=%p", sequence
->element_type
);
4194 if (context
->field_name
->len
) {
4195 append_struct_variant_field_name(context
,
4196 context
->field_name
->str
);
4198 g_string_append_printf(context
->string
, "[%s]",
4199 sequence
->length_field_name
->str
);
4200 g_string_assign(context
->field_name
, "");
4202 g_string_append_printf(context
->string
, "[%s]",
4203 sequence
->length_field_name
->str
);
4210 int bt_ctf_field_type_string_serialize(struct bt_ctf_field_type
*type
,
4211 struct metadata_context
*context
)
4213 struct bt_ctf_field_type_string
*string
= container_of(
4214 type
, struct bt_ctf_field_type_string
, parent
);
4216 BT_LOGD("Serializing string field type's metadata: "
4217 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
4218 g_string_append_printf(context
->string
,
4219 "string { encoding = %s; }",
4220 get_encoding_string(string
->encoding
));
4225 void bt_ctf_field_type_integer_set_byte_order(struct bt_ctf_field_type
*type
,
4226 enum bt_ctf_byte_order byte_order
)
4228 struct bt_ctf_field_type_integer
*integer_type
= container_of(type
,
4229 struct bt_ctf_field_type_integer
, parent
);
4231 integer_type
->user_byte_order
= byte_order
;
4235 void bt_ctf_field_type_enumeration_set_byte_order(
4236 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4238 struct bt_ctf_field_type_enumeration
*enum_type
= container_of(type
,
4239 struct bt_ctf_field_type_enumeration
, parent
);
4241 /* Safe to assume that container is an integer */
4242 bt_ctf_field_type_integer_set_byte_order(enum_type
->container
,
4247 void bt_ctf_field_type_floating_point_set_byte_order(
4248 struct bt_ctf_field_type
*type
, enum bt_ctf_byte_order byte_order
)
4250 struct bt_ctf_field_type_floating_point
*floating_point_type
=
4251 container_of(type
, struct bt_ctf_field_type_floating_point
,
4254 floating_point_type
->user_byte_order
= byte_order
;
4258 void bt_ctf_field_type_structure_set_byte_order(struct bt_ctf_field_type
*type
,
4259 enum bt_ctf_byte_order byte_order
)
4262 struct bt_ctf_field_type_structure
*structure_type
=
4263 container_of(type
, struct bt_ctf_field_type_structure
,
4266 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
4267 struct structure_field
*field
= g_ptr_array_index(
4268 structure_type
->fields
, i
);
4269 struct bt_ctf_field_type
*field_type
= field
->type
;
4271 if (set_byte_order_funcs
[field_type
->id
]) {
4272 set_byte_order_funcs
[field_type
->id
](
4273 field_type
, byte_order
);
4279 void bt_ctf_field_type_variant_set_byte_order(struct bt_ctf_field_type
*type
,
4280 enum bt_ctf_byte_order byte_order
)
4283 struct bt_ctf_field_type_variant
*variant_type
=
4284 container_of(type
, struct bt_ctf_field_type_variant
,
4287 for (i
= 0; i
< variant_type
->fields
->len
; i
++) {
4288 struct structure_field
*field
= g_ptr_array_index(
4289 variant_type
->fields
, i
);
4290 struct bt_ctf_field_type
*field_type
= field
->type
;
4292 if (set_byte_order_funcs
[field_type
->id
]) {
4293 set_byte_order_funcs
[field_type
->id
](
4294 field_type
, byte_order
);
4300 void bt_ctf_field_type_array_set_byte_order(struct bt_ctf_field_type
*type
,
4301 enum bt_ctf_byte_order byte_order
)
4303 struct bt_ctf_field_type_array
*array_type
=
4304 container_of(type
, struct bt_ctf_field_type_array
,
4307 if (set_byte_order_funcs
[array_type
->element_type
->id
]) {
4308 set_byte_order_funcs
[array_type
->element_type
->id
](
4309 array_type
->element_type
, byte_order
);
4314 void bt_ctf_field_type_sequence_set_byte_order(struct bt_ctf_field_type
*type
,
4315 enum bt_ctf_byte_order byte_order
)
4317 struct bt_ctf_field_type_sequence
*sequence_type
=
4318 container_of(type
, struct bt_ctf_field_type_sequence
,
4321 if (set_byte_order_funcs
[
4322 sequence_type
->element_type
->id
]) {
4323 set_byte_order_funcs
[
4324 sequence_type
->element_type
->id
](
4325 sequence_type
->element_type
, byte_order
);
4330 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
4331 struct bt_ctf_field_type
*type
)
4333 struct bt_ctf_field_type
*copy
;
4334 struct bt_ctf_field_type_integer
*integer
, *copy_integer
;
4336 BT_LOGD("Copying integer field type's: addr=%p", type
);
4337 integer
= container_of(type
, struct bt_ctf_field_type_integer
, parent
);
4338 copy
= bt_ctf_field_type_integer_create(integer
->size
);
4340 BT_LOGE_STR("Cannot create integer field type.");
4344 copy_integer
= container_of(copy
, struct bt_ctf_field_type_integer
,
4346 copy_integer
->mapped_clock
= bt_get(integer
->mapped_clock
);
4347 copy_integer
->user_byte_order
= integer
->user_byte_order
;
4348 copy_integer
->is_signed
= integer
->is_signed
;
4349 copy_integer
->size
= integer
->size
;
4350 copy_integer
->base
= integer
->base
;
4351 copy_integer
->encoding
= integer
->encoding
;
4352 BT_LOGD("Copied integer field type: original-ft-addr=%p, copy-ft-addr=%p",
4360 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy(
4361 struct bt_ctf_field_type
*type
)
4364 struct bt_ctf_field_type
*copy
= NULL
, *copy_container
;
4365 struct bt_ctf_field_type_enumeration
*enumeration
, *copy_enumeration
;
4367 BT_LOGD("Copying enumeration field type's: addr=%p", type
);
4368 enumeration
= container_of(type
, struct bt_ctf_field_type_enumeration
,
4371 /* Copy the source enumeration's container */
4372 BT_LOGD_STR("Copying enumeration field type's container field type.");
4373 copy_container
= bt_ctf_field_type_copy(enumeration
->container
);
4374 if (!copy_container
) {
4375 BT_LOGE_STR("Cannot copy enumeration field type's container field type.");
4379 copy
= bt_ctf_field_type_enumeration_create(copy_container
);
4381 BT_LOGE_STR("Cannot create enumeration field type.");
4384 copy_enumeration
= container_of(copy
,
4385 struct bt_ctf_field_type_enumeration
, parent
);
4387 /* Copy all enumaration entries */
4388 for (i
= 0; i
< enumeration
->entries
->len
; i
++) {
4389 struct enumeration_mapping
*mapping
= g_ptr_array_index(
4390 enumeration
->entries
, i
);
4391 struct enumeration_mapping
*copy_mapping
= g_new0(
4392 struct enumeration_mapping
, 1);
4394 if (!copy_mapping
) {
4395 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
4399 *copy_mapping
= *mapping
;
4400 g_ptr_array_add(copy_enumeration
->entries
, copy_mapping
);
4403 BT_LOGD("Copied enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
4407 bt_put(copy_container
);
4410 bt_put(copy_container
);
4416 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
4417 struct bt_ctf_field_type
*type
)
4419 struct bt_ctf_field_type
*copy
;
4420 struct bt_ctf_field_type_floating_point
*floating_point
, *copy_float
;
4422 BT_LOGD("Copying floating point number field type's: addr=%p", type
);
4423 floating_point
= container_of(type
,
4424 struct bt_ctf_field_type_floating_point
, parent
);
4425 copy
= bt_ctf_field_type_floating_point_create();
4427 BT_LOGE_STR("Cannot create floating point number field type.");
4431 copy_float
= container_of(copy
,
4432 struct bt_ctf_field_type_floating_point
, parent
);
4433 copy_float
->user_byte_order
= floating_point
->user_byte_order
;
4434 copy_float
->exp_dig
= floating_point
->exp_dig
;
4435 copy_float
->mant_dig
= floating_point
->mant_dig
;
4436 BT_LOGD("Copied floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
4443 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy(
4444 struct bt_ctf_field_type
*type
)
4447 GHashTableIter iter
;
4448 gpointer key
, value
;
4449 struct bt_ctf_field_type
*copy
;
4450 struct bt_ctf_field_type_structure
*structure
, *copy_structure
;
4452 BT_LOGD("Copying structure field type's: addr=%p", type
);
4453 structure
= container_of(type
, struct bt_ctf_field_type_structure
,
4455 copy
= bt_ctf_field_type_structure_create();
4457 BT_LOGE_STR("Cannot create structure field type.");
4461 copy_structure
= container_of(copy
,
4462 struct bt_ctf_field_type_structure
, parent
);
4464 /* Copy field_name_to_index */
4465 g_hash_table_iter_init(&iter
, structure
->field_name_to_index
);
4466 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4467 g_hash_table_insert(copy_structure
->field_name_to_index
,
4471 for (i
= 0; i
< structure
->fields
->len
; i
++) {
4472 struct structure_field
*entry
, *copy_entry
;
4473 struct bt_ctf_field_type
*copy_field
;
4475 entry
= g_ptr_array_index(structure
->fields
, i
);
4476 BT_LOGD("Copying structure field type's field: "
4477 "index=%" PRId64
", "
4478 "field-ft-addr=%p, field-name=\"%s\"",
4479 i
, entry
, g_quark_to_string(entry
->name
));
4480 copy_entry
= g_new0(struct structure_field
, 1);
4482 BT_LOGE_STR("Failed to allocate one structure field type field.");
4486 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4488 BT_LOGE("Cannot copy structure field type's field: "
4489 "index=%" PRId64
", "
4490 "field-ft-addr=%p, field-name=\"%s\"",
4491 i
, entry
, g_quark_to_string(entry
->name
));
4496 copy_entry
->name
= entry
->name
;
4497 copy_entry
->type
= copy_field
;
4498 g_ptr_array_add(copy_structure
->fields
, copy_entry
);
4501 BT_LOGD("Copied structure field type: original-ft-addr=%p, copy-ft-addr=%p",
4512 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy(
4513 struct bt_ctf_field_type
*type
)
4516 GHashTableIter iter
;
4517 gpointer key
, value
;
4518 struct bt_ctf_field_type
*copy
= NULL
, *copy_tag
= NULL
;
4519 struct bt_ctf_field_type_variant
*variant
, *copy_variant
;
4521 BT_LOGD("Copying variant field type's: addr=%p", type
);
4522 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
4525 BT_LOGD_STR("Copying variant field type's tag field type.");
4526 copy_tag
= bt_ctf_field_type_copy(&variant
->tag
->parent
);
4528 BT_LOGE_STR("Cannot copy variant field type's tag field type.");
4533 copy
= bt_ctf_field_type_variant_create(copy_tag
,
4534 variant
->tag_name
->len
? variant
->tag_name
->str
: NULL
);
4536 BT_LOGE_STR("Cannot create variant field type.");
4540 copy_variant
= container_of(copy
, struct bt_ctf_field_type_variant
,
4543 /* Copy field_name_to_index */
4544 g_hash_table_iter_init(&iter
, variant
->field_name_to_index
);
4545 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
4546 g_hash_table_insert(copy_variant
->field_name_to_index
,
4550 for (i
= 0; i
< variant
->fields
->len
; i
++) {
4551 struct structure_field
*entry
, *copy_entry
;
4552 struct bt_ctf_field_type
*copy_field
;
4554 entry
= g_ptr_array_index(variant
->fields
, i
);
4555 BT_LOGD("Copying variant field type's field: "
4556 "index=%" PRId64
", "
4557 "field-ft-addr=%p, field-name=\"%s\"",
4558 i
, entry
, g_quark_to_string(entry
->name
));
4559 copy_entry
= g_new0(struct structure_field
, 1);
4561 BT_LOGE_STR("Failed to allocate one variant field type field.");
4565 copy_field
= bt_ctf_field_type_copy(entry
->type
);
4567 BT_LOGE("Cannot copy variant field type's field: "
4568 "index=%" PRId64
", "
4569 "field-ft-addr=%p, field-name=\"%s\"",
4570 i
, entry
, g_quark_to_string(entry
->name
));
4575 copy_entry
->name
= entry
->name
;
4576 copy_entry
->type
= copy_field
;
4577 g_ptr_array_add(copy_variant
->fields
, copy_entry
);
4580 if (variant
->tag_field_path
) {
4581 BT_LOGD_STR("Copying variant field type's tag field path.");
4582 copy_variant
->tag_field_path
= bt_ctf_field_path_copy(
4583 variant
->tag_field_path
);
4584 if (!copy_variant
->tag_field_path
) {
4585 BT_LOGE_STR("Cannot copy variant field type's tag field path.");
4590 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
4603 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy(
4604 struct bt_ctf_field_type
*type
)
4606 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4607 struct bt_ctf_field_type_array
*array
;
4609 BT_LOGD("Copying array field type's: addr=%p", type
);
4610 array
= container_of(type
, struct bt_ctf_field_type_array
,
4612 BT_LOGD_STR("Copying array field type's element field type.");
4613 copy_element
= bt_ctf_field_type_copy(array
->element_type
);
4614 if (!copy_element
) {
4615 BT_LOGE_STR("Cannot copy array field type's element field type.");
4619 copy
= bt_ctf_field_type_array_create(copy_element
, array
->length
);
4621 BT_LOGE_STR("Cannot create array field type.");
4625 BT_LOGD("Copied array field type: original-ft-addr=%p, copy-ft-addr=%p",
4629 bt_put(copy_element
);
4634 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy(
4635 struct bt_ctf_field_type
*type
)
4637 struct bt_ctf_field_type
*copy
= NULL
, *copy_element
;
4638 struct bt_ctf_field_type_sequence
*sequence
, *copy_sequence
;
4640 BT_LOGD("Copying sequence field type's: addr=%p", type
);
4641 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
4643 BT_LOGD_STR("Copying sequence field type's element field type.");
4644 copy_element
= bt_ctf_field_type_copy(sequence
->element_type
);
4645 if (!copy_element
) {
4646 BT_LOGE_STR("Cannot copy sequence field type's element field type.");
4650 copy
= bt_ctf_field_type_sequence_create(copy_element
,
4651 sequence
->length_field_name
->len
?
4652 sequence
->length_field_name
->str
: NULL
);
4654 BT_LOGE_STR("Cannot create sequence field type.");
4658 copy_sequence
= container_of(copy
, struct bt_ctf_field_type_sequence
,
4660 if (sequence
->length_field_path
) {
4661 BT_LOGD_STR("Copying sequence field type's length field path.");
4662 copy_sequence
->length_field_path
= bt_ctf_field_path_copy(
4663 sequence
->length_field_path
);
4664 if (!copy_sequence
->length_field_path
) {
4665 BT_LOGE_STR("Cannot copy sequence field type's length field path.");
4670 BT_LOGD("Copied sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
4674 bt_put(copy_element
);
4682 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
4683 struct bt_ctf_field_type
*type
)
4685 struct bt_ctf_field_type
*copy
;
4687 BT_LOGD("Copying string field type's: addr=%p", type
);
4688 copy
= bt_ctf_field_type_string_create();
4690 BT_LOGE_STR("Cannot create string field type.");
4694 BT_LOGD("Copied string field type: original-ft-addr=%p, copy-ft-addr=%p",
4701 int bt_ctf_field_type_integer_compare(struct bt_ctf_field_type
*type_a
,
4702 struct bt_ctf_field_type
*type_b
)
4705 struct bt_ctf_field_type_integer
*int_type_a
;
4706 struct bt_ctf_field_type_integer
*int_type_b
;
4708 int_type_a
= container_of(type_a
, struct bt_ctf_field_type_integer
,
4710 int_type_b
= container_of(type_b
, struct bt_ctf_field_type_integer
,
4714 if (int_type_a
->size
!= int_type_b
->size
) {
4715 BT_LOGV("Integer field types differ: different sizes: "
4716 "ft-a-size=%u, ft-b-size=%u",
4717 int_type_a
->size
, int_type_b
->size
);
4722 if (int_type_a
->user_byte_order
!= int_type_b
->user_byte_order
) {
4723 BT_LOGV("Integer field types differ: different byte orders: "
4724 "ft-a-bo=%s, ft-b-bo=%s",
4725 bt_ctf_byte_order_string(int_type_a
->user_byte_order
),
4726 bt_ctf_byte_order_string(int_type_b
->user_byte_order
));
4731 if (int_type_a
->is_signed
!= int_type_b
->is_signed
) {
4732 BT_LOGV("Integer field types differ: different signedness: "
4733 "ft-a-is-signed=%d, ft-b-is-signed=%d",
4734 int_type_a
->is_signed
,
4735 int_type_b
->is_signed
);
4740 if (int_type_a
->base
!= int_type_b
->base
) {
4741 BT_LOGV("Integer field types differ: different bases: "
4742 "ft-a-base=%s, ft-b-base=%s",
4743 bt_ctf_integer_base_string(int_type_a
->base
),
4744 bt_ctf_integer_base_string(int_type_b
->base
));
4749 if (int_type_a
->encoding
!= int_type_b
->encoding
) {
4750 BT_LOGV("Integer field types differ: different encodings: "
4751 "ft-a-encoding=%s, ft-b-encoding=%s",
4752 bt_ctf_string_encoding_string(int_type_a
->encoding
),
4753 bt_ctf_string_encoding_string(int_type_b
->encoding
));
4758 if (int_type_a
->mapped_clock
!= int_type_b
->mapped_clock
) {
4759 BT_LOGV("Integer field types differ: different mapped clock classes: "
4760 "ft-a-mapped-clock-class-addr=%p, "
4761 "ft-b-mapped-clock-class-addr=%p, "
4762 "ft-a-mapped-clock-class-name=\"%s\", "
4763 "ft-b-mapped-clock-class-name=\"%s\"",
4764 int_type_a
->mapped_clock
, int_type_b
->mapped_clock
,
4765 int_type_a
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_a
->mapped_clock
) : "",
4766 int_type_b
->mapped_clock
? bt_ctf_clock_class_get_name(int_type_b
->mapped_clock
) : "");
4778 int bt_ctf_field_type_floating_point_compare(struct bt_ctf_field_type
*type_a
,
4779 struct bt_ctf_field_type
*type_b
)
4782 struct bt_ctf_field_type_floating_point
*float_a
;
4783 struct bt_ctf_field_type_floating_point
*float_b
;
4785 float_a
= container_of(type_a
,
4786 struct bt_ctf_field_type_floating_point
, parent
);
4787 float_b
= container_of(type_b
,
4788 struct bt_ctf_field_type_floating_point
, parent
);
4791 if (float_a
->user_byte_order
!= float_b
->user_byte_order
) {
4792 BT_LOGV("Floating point number field types differ: different byte orders: "
4793 "ft-a-bo=%s, ft-b-bo=%s",
4794 bt_ctf_byte_order_string(float_a
->user_byte_order
),
4795 bt_ctf_byte_order_string(float_b
->user_byte_order
));
4799 /* Exponent length */
4800 if (float_a
->exp_dig
!= float_b
->exp_dig
) {
4801 BT_LOGV("Floating point number field types differ: different exponent sizes: "
4802 "ft-a-exp-size=%u, ft-b-exp-size=%u",
4803 float_a
->exp_dig
, float_b
->exp_dig
);
4807 /* Mantissa length */
4808 if (float_a
->mant_dig
!= float_b
->mant_dig
) {
4809 BT_LOGV("Floating point number field types differ: different mantissa sizes: "
4810 "ft-a-mant-size=%u, ft-b-mant-size=%u",
4811 float_a
->mant_dig
, float_b
->mant_dig
);
4823 int compare_enumeration_mappings(struct enumeration_mapping
*mapping_a
,
4824 struct enumeration_mapping
*mapping_b
)
4829 if (mapping_a
->string
!= mapping_b
->string
) {
4830 BT_LOGV("Enumeration field type mappings differ: different names: "
4831 "mapping-a-name=\"%s\", mapping-b-name=\"%s\"",
4832 g_quark_to_string(mapping_a
->string
),
4833 g_quark_to_string(mapping_b
->string
));
4838 if (mapping_a
->range_start
._unsigned
!=
4839 mapping_b
->range_start
._unsigned
) {
4840 BT_LOGV("Enumeration field type mappings differ: different starts of range: "
4841 "mapping-a-range-start-unsigned=%" PRIu64
", "
4842 "mapping-b-range-start-unsigned=%" PRIu64
,
4843 mapping_a
->range_start
._unsigned
,
4844 mapping_b
->range_start
._unsigned
);
4849 if (mapping_a
->range_end
._unsigned
!=
4850 mapping_b
->range_end
._unsigned
) {
4851 BT_LOGV("Enumeration field type mappings differ: different ends of range: "
4852 "mapping-a-range-end-unsigned=%" PRIu64
", "
4853 "mapping-b-range-end-unsigned=%" PRIu64
,
4854 mapping_a
->range_end
._unsigned
,
4855 mapping_b
->range_end
._unsigned
);
4867 int bt_ctf_field_type_enumeration_compare(struct bt_ctf_field_type
*type_a
,
4868 struct bt_ctf_field_type
*type_b
)
4872 struct bt_ctf_field_type_enumeration
*enum_a
;
4873 struct bt_ctf_field_type_enumeration
*enum_b
;
4875 enum_a
= container_of(type_a
,
4876 struct bt_ctf_field_type_enumeration
, parent
);
4877 enum_b
= container_of(type_b
,
4878 struct bt_ctf_field_type_enumeration
, parent
);
4880 /* Container field type */
4881 ret
= bt_ctf_field_type_compare(enum_a
->container
, enum_b
->container
);
4883 BT_LOGV("Enumeration field types differ: different container field types: "
4884 "ft-a-container-ft-addr=%p, ft-b-container-ft-addr=%p",
4885 enum_a
->container
, enum_b
->container
);
4892 if (enum_a
->entries
->len
!= enum_b
->entries
->len
) {
4896 for (i
= 0; i
< enum_a
->entries
->len
; ++i
) {
4897 struct enumeration_mapping
*mapping_a
=
4898 g_ptr_array_index(enum_a
->entries
, i
);
4899 struct enumeration_mapping
*mapping_b
=
4900 g_ptr_array_index(enum_b
->entries
, i
);
4902 if (compare_enumeration_mappings(mapping_a
, mapping_b
)) {
4903 BT_LOGV("Enumeration field types differ: different mappings: "
4904 "ft-a-mapping-addr=%p, ft-b-mapping-addr=%p, "
4905 "ft-a-mapping-name=\"%s\", ft-b-mapping-name=\"%s\"",
4906 mapping_a
, mapping_b
,
4907 g_quark_to_string(mapping_a
->string
),
4908 g_quark_to_string(mapping_b
->string
));
4921 int bt_ctf_field_type_string_compare(struct bt_ctf_field_type
*type_a
,
4922 struct bt_ctf_field_type
*type_b
)
4925 struct bt_ctf_field_type_string
*string_a
;
4926 struct bt_ctf_field_type_string
*string_b
;
4928 string_a
= container_of(type_a
,
4929 struct bt_ctf_field_type_string
, parent
);
4930 string_b
= container_of(type_b
,
4931 struct bt_ctf_field_type_string
, parent
);
4934 if (string_a
->encoding
!= string_b
->encoding
) {
4935 BT_LOGV("String field types differ: different encodings: "
4936 "ft-a-encoding=%s, ft-b-encoding=%s",
4937 bt_ctf_string_encoding_string(string_a
->encoding
),
4938 bt_ctf_string_encoding_string(string_b
->encoding
));
4950 int compare_structure_fields(struct structure_field
*field_a
,
4951 struct structure_field
*field_b
)
4956 if (field_a
->name
!= field_b
->name
) {
4957 BT_LOGV("Structure/variant field type fields differ: different names: "
4958 "field-a-name=%s, field-b-name=%s",
4959 g_quark_to_string(field_a
->name
),
4960 g_quark_to_string(field_b
->name
));
4965 ret
= bt_ctf_field_type_compare(field_a
->type
, field_b
->type
);
4967 BT_LOGV("Structure/variant field type fields differ: different field types: "
4968 "field-name=\"%s\", field-a-ft-addr=%p, field-b-ft-addr=%p",
4969 g_quark_to_string(field_a
->name
),
4970 field_a
->type
, field_b
->type
);
4978 int bt_ctf_field_type_structure_compare(struct bt_ctf_field_type
*type_a
,
4979 struct bt_ctf_field_type
*type_b
)
4983 struct bt_ctf_field_type_structure
*struct_a
;
4984 struct bt_ctf_field_type_structure
*struct_b
;
4986 struct_a
= container_of(type_a
,
4987 struct bt_ctf_field_type_structure
, parent
);
4988 struct_b
= container_of(type_b
,
4989 struct bt_ctf_field_type_structure
, parent
);
4992 if (bt_ctf_field_type_get_alignment(type_a
) !=
4993 bt_ctf_field_type_get_alignment(type_b
)) {
4994 BT_LOGV("Structure field types differ: different alignments: "
4995 "ft-a-align=%u, ft-b-align=%u",
4996 bt_ctf_field_type_get_alignment(type_a
),
4997 bt_ctf_field_type_get_alignment(type_b
));
5002 if (struct_a
->fields
->len
!= struct_b
->fields
->len
) {
5003 BT_LOGV("Structure field types differ: different field counts: "
5004 "ft-a-field-count=%u, ft-b-field-count=%u",
5005 struct_a
->fields
->len
, struct_b
->fields
->len
);
5009 for (i
= 0; i
< struct_a
->fields
->len
; ++i
) {
5010 struct structure_field
*field_a
=
5011 g_ptr_array_index(struct_a
->fields
, i
);
5012 struct structure_field
*field_b
=
5013 g_ptr_array_index(struct_b
->fields
, i
);
5015 ret
= compare_structure_fields(field_a
, field_b
);
5017 /* compare_structure_fields() logs what differs */
5018 BT_LOGV_STR("Structure field types differ: different fields.");
5031 int bt_ctf_field_type_variant_compare(struct bt_ctf_field_type
*type_a
,
5032 struct bt_ctf_field_type
*type_b
)
5036 struct bt_ctf_field_type_variant
*variant_a
;
5037 struct bt_ctf_field_type_variant
*variant_b
;
5039 variant_a
= container_of(type_a
,
5040 struct bt_ctf_field_type_variant
, parent
);
5041 variant_b
= container_of(type_b
,
5042 struct bt_ctf_field_type_variant
, parent
);
5045 if (strcmp(variant_a
->tag_name
->str
, variant_b
->tag_name
->str
)) {
5046 BT_LOGV("Variant field types differ: different tag field names: "
5047 "ft-a-tag-field-name=\"%s\", ft-b-tag-field-name=\"%s\"",
5048 variant_a
->tag_name
->str
, variant_b
->tag_name
->str
);
5053 ret
= bt_ctf_field_type_compare(
5054 (struct bt_ctf_field_type
*) variant_a
->tag
,
5055 (struct bt_ctf_field_type
*) variant_b
->tag
);
5057 BT_LOGV("Variant field types differ: different tag field types: "
5058 "ft-a-tag-ft-addr=%p, ft-b-tag-ft-addr=%p",
5059 variant_a
->tag
, variant_b
->tag
);
5066 if (variant_a
->fields
->len
!= variant_b
->fields
->len
) {
5067 BT_LOGV("Structure field types differ: different field counts: "
5068 "ft-a-field-count=%u, ft-b-field-count=%u",
5069 variant_a
->fields
->len
, variant_b
->fields
->len
);
5073 for (i
= 0; i
< variant_a
->fields
->len
; ++i
) {
5074 struct structure_field
*field_a
=
5075 g_ptr_array_index(variant_a
->fields
, i
);
5076 struct structure_field
*field_b
=
5077 g_ptr_array_index(variant_b
->fields
, i
);
5079 ret
= compare_structure_fields(field_a
, field_b
);
5081 /* compare_structure_fields() logs what differs */
5082 BT_LOGV_STR("Variant field types differ: different fields.");
5095 int bt_ctf_field_type_array_compare(struct bt_ctf_field_type
*type_a
,
5096 struct bt_ctf_field_type
*type_b
)
5099 struct bt_ctf_field_type_array
*array_a
;
5100 struct bt_ctf_field_type_array
*array_b
;
5102 array_a
= container_of(type_a
,
5103 struct bt_ctf_field_type_array
, parent
);
5104 array_b
= container_of(type_b
,
5105 struct bt_ctf_field_type_array
, parent
);
5108 if (array_a
->length
!= array_b
->length
) {
5109 BT_LOGV("Structure field types differ: different lengths: "
5110 "ft-a-length=%u, ft-b-length=%u",
5111 array_a
->length
, array_b
->length
);
5116 ret
= bt_ctf_field_type_compare(array_a
->element_type
,
5117 array_b
->element_type
);
5119 BT_LOGV("Array field types differ: different element field types: "
5120 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5121 array_a
->element_type
, array_b
->element_type
);
5129 int bt_ctf_field_type_sequence_compare(struct bt_ctf_field_type
*type_a
,
5130 struct bt_ctf_field_type
*type_b
)
5133 struct bt_ctf_field_type_sequence
*sequence_a
;
5134 struct bt_ctf_field_type_sequence
*sequence_b
;
5136 sequence_a
= container_of(type_a
,
5137 struct bt_ctf_field_type_sequence
, parent
);
5138 sequence_b
= container_of(type_b
,
5139 struct bt_ctf_field_type_sequence
, parent
);
5142 if (strcmp(sequence_a
->length_field_name
->str
,
5143 sequence_b
->length_field_name
->str
)) {
5144 BT_LOGV("Sequence field types differ: different length field names: "
5145 "ft-a-length-field-name=\"%s\", "
5146 "ft-b-length-field-name=\"%s\"",
5147 sequence_a
->length_field_name
->str
,
5148 sequence_b
->length_field_name
->str
);
5153 ret
= bt_ctf_field_type_compare(sequence_a
->element_type
,
5154 sequence_b
->element_type
);
5156 BT_LOGV("Sequence field types differ: different element field types: "
5157 "ft-a-element-ft-addr=%p, ft-b-element-ft-addr=%p",
5158 sequence_a
->element_type
, sequence_b
->element_type
);
5165 int bt_ctf_field_type_compare(struct bt_ctf_field_type
*type_a
,
5166 struct bt_ctf_field_type
*type_b
)
5170 if (type_a
== type_b
) {
5171 /* Same reference: equal (even if both are NULL) */
5177 BT_LOGW_STR("Invalid parameter: field type A is NULL.");
5183 BT_LOGW_STR("Invalid parameter: field type B is NULL.");
5188 if (type_a
->id
!= type_b
->id
) {
5189 /* Different type IDs */
5190 BT_LOGV("Field types differ: different IDs: "
5191 "ft-a-addr=%p, ft-b-addr=%p, "
5192 "ft-a-id=%s, ft-b-id=%s",
5194 bt_ctf_field_type_id_string(type_a
->id
),
5195 bt_ctf_field_type_id_string(type_b
->id
));
5199 if (type_a
->id
== BT_CTF_FIELD_TYPE_ID_UNKNOWN
) {
5200 /* Both have unknown type IDs */
5201 BT_LOGW_STR("Invalid parameter: field type IDs are unknown.");
5205 ret
= type_compare_funcs
[type_a
->id
](type_a
, type_b
);
5207 BT_LOGV("Field types differ: ft-a-addr=%p, ft-b-addr=%p",
5216 int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*field_type
)
5218 int64_t field_count
= -1;
5219 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5222 case CTF_TYPE_STRUCT
:
5224 bt_ctf_field_type_structure_get_field_count(field_type
);
5226 case CTF_TYPE_VARIANT
:
5228 bt_ctf_field_type_variant_get_field_count(field_type
);
5230 case CTF_TYPE_ARRAY
:
5231 case CTF_TYPE_SEQUENCE
:
5233 * Array and sequence types always contain a single member
5234 * (the element type).
5246 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
5247 struct bt_ctf_field_type
*field_type
, int index
)
5249 struct bt_ctf_field_type
*field
= NULL
;
5250 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5253 case CTF_TYPE_STRUCT
:
5255 int ret
= bt_ctf_field_type_structure_get_field_by_index(
5256 field_type
, NULL
, &field
, index
);
5263 case CTF_TYPE_VARIANT
:
5265 int ret
= bt_ctf_field_type_variant_get_field_by_index(
5266 field_type
, NULL
, &field
, index
);
5273 case CTF_TYPE_ARRAY
:
5274 field
= bt_ctf_field_type_array_get_element_type(field_type
);
5276 case CTF_TYPE_SEQUENCE
:
5277 field
= bt_ctf_field_type_sequence_get_element_type(field_type
);
5287 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*field_type
,
5290 int field_index
= -1;
5291 enum bt_ctf_field_type_id type_id
= bt_ctf_field_type_get_type_id(field_type
);
5294 case CTF_TYPE_STRUCT
:
5295 field_index
= bt_ctf_field_type_structure_get_field_name_index(
5298 case CTF_TYPE_VARIANT
:
5299 field_index
= bt_ctf_field_type_variant_get_field_name_index(
5309 struct bt_ctf_field_path
*bt_ctf_field_type_variant_get_tag_field_path(
5310 struct bt_ctf_field_type
*type
)
5312 struct bt_ctf_field_path
*field_path
= NULL
;
5313 struct bt_ctf_field_type_variant
*variant
;
5316 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5320 if (!bt_ctf_field_type_is_variant(type
)) {
5321 BT_LOGW("Invalid parameter: field type is not a variant field type: "
5322 "addr=%p, ft-id=%s", type
,
5323 bt_ctf_field_type_id_string(type
->id
));
5327 variant
= container_of(type
, struct bt_ctf_field_type_variant
,
5329 field_path
= bt_get(variant
->tag_field_path
);
5334 struct bt_ctf_field_path
*bt_ctf_field_type_sequence_get_length_field_path(
5335 struct bt_ctf_field_type
*type
)
5337 struct bt_ctf_field_path
*field_path
= NULL
;
5338 struct bt_ctf_field_type_sequence
*sequence
;
5341 BT_LOGW_STR("Invalid parameter: field type is NULL.");
5345 if (!bt_ctf_field_type_is_sequence(type
)) {
5346 BT_LOGW("Invalid parameter: field type is not a sequence field type: "
5347 "addr=%p, ft-id=%s", type
,
5348 bt_ctf_field_type_id_string(type
->id
));
5352 sequence
= container_of(type
, struct bt_ctf_field_type_sequence
,
5354 field_path
= bt_get(sequence
->length_field_path
);