4 * Babeltrace CTF IR - Event Fields
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 "FIELDS"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/assert-pre-internal.h>
33 #include <babeltrace/ctf-ir/fields.h>
34 #include <babeltrace/ctf-ir/fields-internal.h>
35 #include <babeltrace/ctf-ir/field-types-internal.h>
36 #include <babeltrace/object-internal.h>
37 #include <babeltrace/ref.h>
38 #include <babeltrace/compiler-internal.h>
39 #include <babeltrace/compat/fcntl-internal.h>
40 #include <babeltrace/align-internal.h>
41 #include <babeltrace/assert-internal.h>
44 #define BT_ASSERT_PRE_FIELD_IS_INT_OR_ENUM(_field, _name) \
45 BT_ASSERT_PRE((_field)->type->id == BT_FIELD_TYPE_ID_INTEGER || \
46 (_field)->type->id == BT_FIELD_TYPE_ID_ENUM, \
47 _name " is not an integer or an enumeration field: " \
51 int bt_field_generic_validate(struct bt_field
*field
);
54 int bt_field_structure_validate_recursive(struct bt_field
*field
);
57 int bt_field_variant_validate_recursive(struct bt_field
*field
);
60 int bt_field_array_validate_recursive(struct bt_field
*field
);
63 int bt_field_sequence_validate_recursive(struct bt_field
*field
);
66 void bt_field_generic_reset(struct bt_field
*field
);
69 void bt_field_structure_reset_recursive(struct bt_field
*field
);
72 void bt_field_variant_reset_recursive(struct bt_field
*field
);
75 void bt_field_array_reset_recursive(struct bt_field
*field
);
78 void bt_field_sequence_reset_recursive(struct bt_field
*field
);
81 void bt_field_generic_set_is_frozen(struct bt_field
*field
,
85 void bt_field_structure_set_is_frozen_recursive(
86 struct bt_field
*field
, bool is_frozen
);
89 void bt_field_variant_set_is_frozen_recursive(
90 struct bt_field
*field
, bool is_frozen
);
93 void bt_field_array_set_is_frozen_recursive(
94 struct bt_field
*field
, bool is_frozen
);
97 void bt_field_sequence_set_is_frozen_recursive(
98 struct bt_field
*field
, bool is_frozen
);
101 bt_bool
bt_field_generic_is_set(struct bt_field
*field
);
104 bt_bool
bt_field_structure_is_set_recursive(
105 struct bt_field
*field
);
108 bt_bool
bt_field_variant_is_set_recursive(struct bt_field
*field
);
111 bt_bool
bt_field_array_is_set_recursive(struct bt_field
*field
);
114 bt_bool
bt_field_sequence_is_set_recursive(struct bt_field
*field
);
116 static struct bt_field_methods bt_field_integer_methods
= {
117 .set_is_frozen
= bt_field_generic_set_is_frozen
,
118 .validate
= bt_field_generic_validate
,
119 .is_set
= bt_field_generic_is_set
,
120 .reset
= bt_field_generic_reset
,
123 static struct bt_field_methods bt_field_floating_point_methods
= {
124 .set_is_frozen
= bt_field_generic_set_is_frozen
,
125 .validate
= bt_field_generic_validate
,
126 .is_set
= bt_field_generic_is_set
,
127 .reset
= bt_field_generic_reset
,
130 static struct bt_field_methods bt_field_enumeration_methods
= {
131 .set_is_frozen
= bt_field_generic_set_is_frozen
,
132 .validate
= bt_field_generic_validate
,
133 .is_set
= bt_field_generic_is_set
,
134 .reset
= bt_field_generic_reset
,
137 static struct bt_field_methods bt_field_string_methods
= {
138 .set_is_frozen
= bt_field_generic_set_is_frozen
,
139 .validate
= bt_field_generic_validate
,
140 .is_set
= bt_field_generic_is_set
,
141 .reset
= bt_field_generic_reset
,
144 static struct bt_field_methods bt_field_structure_methods
= {
145 .set_is_frozen
= bt_field_structure_set_is_frozen_recursive
,
146 .validate
= bt_field_structure_validate_recursive
,
147 .is_set
= bt_field_structure_is_set_recursive
,
148 .reset
= bt_field_structure_reset_recursive
,
151 static struct bt_field_methods bt_field_sequence_methods
= {
152 .set_is_frozen
= bt_field_sequence_set_is_frozen_recursive
,
153 .validate
= bt_field_sequence_validate_recursive
,
154 .is_set
= bt_field_sequence_is_set_recursive
,
155 .reset
= bt_field_sequence_reset_recursive
,
158 static struct bt_field_methods bt_field_array_methods
= {
159 .set_is_frozen
= bt_field_array_set_is_frozen_recursive
,
160 .validate
= bt_field_array_validate_recursive
,
161 .is_set
= bt_field_array_is_set_recursive
,
162 .reset
= bt_field_array_reset_recursive
,
165 static struct bt_field_methods bt_field_variant_methods
= {
166 .set_is_frozen
= bt_field_variant_set_is_frozen_recursive
,
167 .validate
= bt_field_variant_validate_recursive
,
168 .is_set
= bt_field_variant_is_set_recursive
,
169 .reset
= bt_field_variant_reset_recursive
,
173 struct bt_field
*bt_field_integer_create(struct bt_field_type
*);
176 struct bt_field
*bt_field_enumeration_create(struct bt_field_type
*);
179 struct bt_field
*bt_field_floating_point_create(struct bt_field_type
*);
182 struct bt_field
*bt_field_structure_create(struct bt_field_type
*);
185 struct bt_field
*bt_field_variant_create(struct bt_field_type
*);
188 struct bt_field
*bt_field_array_create(struct bt_field_type
*);
191 struct bt_field
*bt_field_sequence_create(struct bt_field_type
*);
194 struct bt_field
*bt_field_string_create(struct bt_field_type
*);
197 struct bt_field
*(* const field_create_funcs
[])(struct bt_field_type
*) = {
198 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_integer_create
,
199 [BT_FIELD_TYPE_ID_ENUM
] = bt_field_enumeration_create
,
200 [BT_FIELD_TYPE_ID_FLOAT
] = bt_field_floating_point_create
,
201 [BT_FIELD_TYPE_ID_STRUCT
] = bt_field_structure_create
,
202 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_variant_create
,
203 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_array_create
,
204 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_sequence_create
,
205 [BT_FIELD_TYPE_ID_STRING
] = bt_field_string_create
,
209 void bt_field_integer_destroy(struct bt_field
*field
);
212 void bt_field_enumeration_destroy(struct bt_field
*field
);
215 void bt_field_floating_point_destroy(struct bt_field
*field
);
218 void bt_field_structure_destroy_recursive(struct bt_field
*field
);
221 void bt_field_variant_destroy_recursive(struct bt_field
*field
);
224 void bt_field_array_destroy_recursive(struct bt_field
*field
);
227 void bt_field_sequence_destroy_recursive(struct bt_field
*field
);
230 void bt_field_string_destroy(struct bt_field
*field
);
233 void (* const field_destroy_funcs
[])(struct bt_field
*) = {
234 [BT_FIELD_TYPE_ID_INTEGER
] = bt_field_integer_destroy
,
235 [BT_FIELD_TYPE_ID_ENUM
] = bt_field_enumeration_destroy
,
236 [BT_FIELD_TYPE_ID_FLOAT
] = bt_field_floating_point_destroy
,
237 [BT_FIELD_TYPE_ID_STRUCT
] = bt_field_structure_destroy_recursive
,
238 [BT_FIELD_TYPE_ID_VARIANT
] = bt_field_variant_destroy_recursive
,
239 [BT_FIELD_TYPE_ID_ARRAY
] = bt_field_array_destroy_recursive
,
240 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_field_sequence_destroy_recursive
,
241 [BT_FIELD_TYPE_ID_STRING
] = bt_field_string_destroy
,
245 static inline bool value_is_in_range_signed(unsigned int size
, int64_t value
)
248 int64_t min_value
, max_value
;
250 min_value
= -(1ULL << (size
- 1));
251 max_value
= (1ULL << (size
- 1)) - 1;
252 if (value
< min_value
|| value
> max_value
) {
253 BT_LOGF("Value is out of bounds: value=%" PRId64
", "
254 "min-value=%" PRId64
", max-value=%" PRId64
,
255 value
, min_value
, max_value
);
263 static inline bool value_is_in_range_unsigned(unsigned int size
, uint64_t value
)
268 max_value
= (size
== 64) ? UINT64_MAX
: ((uint64_t) 1 << size
) - 1;
269 if (value
> max_value
) {
270 BT_LOGF("Value is out of bounds: value=%" PRIu64
", "
271 "max-value=%" PRIu64
,
280 struct bt_field
*bt_field_create_recursive(struct bt_field_type
*type
)
282 struct bt_field
*field
= NULL
;
283 enum bt_field_type_id type_id
;
285 BT_ASSERT_PRE_NON_NULL(type
, "Field type");
286 BT_ASSERT(bt_field_type_has_known_id((void *) type
));
287 BT_ASSERT_PRE(bt_field_type_validate((void *) type
) == 0,
288 "Field type is invalid: %!+F", type
);
289 type_id
= bt_field_type_get_type_id(type
);
290 field
= field_create_funcs
[type_id
](type
);
295 bt_field_type_freeze(type
);
301 struct bt_field_type
*bt_field_borrow_type(struct bt_field
*field
)
303 struct bt_field_type
*ret
= NULL
;
305 BT_ASSERT_PRE_NON_NULL(field
, "Field");
310 enum bt_field_type_id
bt_field_get_type_id(struct bt_field
*field
)
312 BT_ASSERT_PRE_NON_NULL(field
, "Field");
313 return field
->type
->id
;
316 int64_t bt_field_sequence_get_length(struct bt_field
*field
)
318 struct bt_field_sequence
*sequence
= (void *) field
;
320 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
321 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_SEQUENCE
,
323 return (int64_t) sequence
->length
;
326 int bt_field_sequence_set_length(struct bt_field
*field
, uint64_t length
)
329 struct bt_field_sequence
*sequence
= (void *) field
;
331 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
332 BT_ASSERT_PRE(((int64_t) length
) >= 0,
333 "Invalid sequence length (too large): length=%" PRId64
,
335 BT_ASSERT_PRE_FIELD_HOT(field
, "Sequence field");
337 if (unlikely(length
> sequence
->elements
->len
)) {
339 struct bt_field_type_sequence
*sequence_ft
;
340 uint64_t cur_len
= sequence
->elements
->len
;
343 g_ptr_array_set_size(sequence
->elements
, length
);
344 sequence_ft
= (void *) sequence
->common
.type
;
346 for (i
= cur_len
; i
< sequence
->elements
->len
; i
++) {
347 struct bt_field
*elem_field
=
348 bt_field_create_recursive(
349 sequence_ft
->element_ft
);
356 BT_ASSERT(!sequence
->elements
->pdata
[i
]);
357 sequence
->elements
->pdata
[i
] = elem_field
;
361 sequence
->length
= length
;
367 struct bt_field
*bt_field_structure_borrow_field_by_index(
368 struct bt_field
*field
, uint64_t index
)
370 struct bt_field_structure
*structure
= (void *) field
;
372 BT_ASSERT_PRE_NON_NULL(field
, "Structure field");
373 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
374 BT_FIELD_TYPE_ID_STRUCT
, "Field");
375 BT_ASSERT_PRE(index
< structure
->fields
->len
,
376 "Index is out of bound: %![struct-field-]+f, "
377 "index=%" PRIu64
", count=%u", field
, index
,
378 structure
->fields
->len
);
379 return structure
->fields
->pdata
[index
];
382 struct bt_field
*bt_field_structure_borrow_field_by_name(
383 struct bt_field
*field
, const char *name
)
385 struct bt_field
*ret
= NULL
;
387 struct bt_field_type_structure
*structure_ft
;
388 struct bt_field_structure
*structure
= (void *) field
;
390 GHashTable
*field_name_to_index
;
392 BT_ASSERT_PRE_NON_NULL(field
, "Structure field");
393 BT_ASSERT_PRE_NON_NULL(name
, "Field name");
394 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
395 BT_FIELD_TYPE_ID_STRUCT
, "Field");
396 structure_ft
= (void *) field
->type
;
397 field_name_to_index
= structure_ft
->field_name_to_index
;
398 field_quark
= g_quark_from_string(name
);
399 if (!g_hash_table_lookup_extended(field_name_to_index
,
400 GUINT_TO_POINTER(field_quark
),
401 NULL
, (gpointer
*) &index
)) {
402 BT_LOGV("Invalid parameter: no such field in structure field's type: "
403 "struct-field-addr=%p, struct-ft-addr=%p, name=\"%s\"",
404 field
, field
->type
, name
);
408 ret
= structure
->fields
->pdata
[index
];
415 struct bt_field
*bt_field_array_borrow_field(
416 struct bt_field
*field
, uint64_t index
)
418 struct bt_field_array
*array
= (void *) field
;
420 BT_ASSERT_PRE_NON_NULL(field
, "Array field");
421 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_ARRAY
,
423 BT_ASSERT_PRE(index
< array
->elements
->len
,
424 "Index is out of bound: %![array-field-]+f, "
425 "index=%" PRIu64
", count=%u", field
,
426 index
, array
->elements
->len
);
427 return array
->elements
->pdata
[(size_t) index
];
430 struct bt_field
*bt_field_sequence_borrow_field(
431 struct bt_field
*field
, uint64_t index
)
433 struct bt_field_sequence
*sequence
= (void *) field
;
435 BT_ASSERT_PRE_NON_NULL(field
, "Sequence field");
436 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
, BT_FIELD_TYPE_ID_SEQUENCE
,
438 BT_ASSERT_PRE(index
< sequence
->length
,
439 "Index is out of bound: %![seq-field-]+f, "
440 "index=%" PRIu64
", count=%u", field
, index
,
441 sequence
->elements
->len
);
442 return sequence
->elements
->pdata
[(size_t) index
];
445 struct bt_field
*bt_field_variant_borrow_current_field(
446 struct bt_field
*field
)
448 struct bt_field_variant
*variant
= (void *) field
;
450 BT_ASSERT_PRE_NON_NULL(field
, "Variant field");
451 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
452 BT_FIELD_TYPE_ID_VARIANT
, "Field");
453 BT_ASSERT_PRE(variant
->current_field
,
454 "Variant field has no current field: %!+f", field
);
455 return variant
->current_field
;
459 int bt_field_variant_set_tag(struct bt_field
*field
,
460 uint64_t tag_uval
, bool is_signed
)
463 int64_t choice_index
;
464 struct bt_field_variant
*variant
= (void *) field
;
466 BT_ASSERT_PRE_NON_NULL(field
, "Variant field");
467 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
468 BT_FIELD_TYPE_ID_VARIANT
, "Field");
470 /* Find matching index in variant field's type */
471 choice_index
= bt_field_type_variant_find_choice_index(
472 field
->type
, tag_uval
, is_signed
);
473 if (choice_index
< 0) {
478 /* Select corresponding field */
479 BT_ASSERT(choice_index
< variant
->fields
->len
);
480 variant
->current_field
= variant
->fields
->pdata
[choice_index
];
481 variant
->tag_value
.u
= tag_uval
;
487 int bt_field_variant_set_tag_signed(struct bt_field
*variant_field
,
490 return bt_field_variant_set_tag((void *) variant_field
,
491 (uint64_t) tag
, true);
494 int bt_field_variant_set_tag_unsigned(struct bt_field
*variant_field
,
497 return bt_field_variant_set_tag((void *) variant_field
,
498 (uint64_t) tag
, false);
501 int bt_field_variant_get_tag_signed(struct bt_field
*field
,
504 struct bt_field_variant
*variant
= (void *) field
;
506 BT_ASSERT_PRE_NON_NULL(field
, "Variant field");
507 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
508 BT_FIELD_TYPE_ID_VARIANT
, "Field");
509 BT_ASSERT_PRE(variant
->current_field
,
510 "Variant field has no current field: %!+f", field
);
511 *tag
= variant
->tag_value
.i
;
515 int bt_field_variant_get_tag_unsigned(struct bt_field
*field
,
518 struct bt_field_variant
*variant
= (void *) field
;
520 BT_ASSERT_PRE_NON_NULL(field
, "Variant field");
521 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
522 BT_FIELD_TYPE_ID_VARIANT
, "Field");
523 BT_ASSERT_PRE(variant
->current_field
,
524 "Variant field has no current field: %!+f", field
);
525 *tag
= variant
->tag_value
.u
;
529 struct bt_field_type_enumeration_mapping_iterator
*
530 bt_field_enumeration_get_mappings(struct bt_field
*field
)
532 struct bt_field_enumeration
*enum_field
= (void *) field
;
533 struct bt_field_type_enumeration
*enum_type
= NULL
;
534 struct bt_field_type_integer
*integer_type
= NULL
;
535 struct bt_field_type_enumeration_mapping_iterator
*iter
= NULL
;
538 BT_ASSERT(field
->type
->id
== BT_FIELD_TYPE_ID_ENUM
);
539 BT_ASSERT(field
->payload_set
);
540 BT_ASSERT_PRE_NON_NULL(field
, "Enumeration field");
541 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID((struct bt_field
*) field
,
542 BT_FIELD_TYPE_ID_ENUM
, "Field");
543 BT_ASSERT_PRE_FIELD_IS_SET((struct bt_field
*) field
,
544 "Enumeration field");
545 enum_type
= (void *) field
->type
;
546 integer_type
= enum_type
->container_ft
;
548 if (!integer_type
->is_signed
) {
549 iter
= bt_field_type_enumeration_unsigned_find_mappings_by_value(
551 enum_field
->common
.payload
.unsignd
);
553 iter
= bt_field_type_enumeration_signed_find_mappings_by_value(
555 enum_field
->common
.payload
.signd
);
563 struct bt_field_type_integer
*get_int_enum_int_ft(
564 struct bt_field
*field
)
566 struct bt_field_integer
*int_field
= (void *) field
;
567 struct bt_field_type_integer
*int_ft
= NULL
;
569 if (int_field
->common
.type
->id
== BT_FIELD_TYPE_ID_INTEGER
) {
570 int_ft
= (void *) int_field
->common
.type
;
571 } else if (int_field
->common
.type
->id
== BT_FIELD_TYPE_ID_ENUM
) {
572 struct bt_field_type_enumeration
*enum_ft
=
573 (void *) int_field
->common
.type
;
574 int_ft
= enum_ft
->container_ft
;
583 int bt_field_integer_signed_get_value(struct bt_field
*field
, int64_t *value
)
585 struct bt_field_integer
*integer
= (void *) field
;
587 BT_ASSERT_PRE_NON_NULL(field
, "Integer/enumeration field");
588 BT_ASSERT_PRE_NON_NULL(value
, "Value");
589 BT_ASSERT_PRE_FIELD_IS_SET(field
,
590 "Integer/enumeration field");
591 BT_ASSERT_PRE_FIELD_IS_INT_OR_ENUM(field
, "Field");
592 BT_ASSERT_PRE(bt_field_type_integer_is_signed(
593 (void *) get_int_enum_int_ft(field
)),
594 "Field's type is unsigned: %!+f", field
);
595 *value
= integer
->payload
.signd
;
599 int bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
602 struct bt_field_integer
*integer
= (void *) field
;
604 BT_ASSERT_PRE_NON_NULL(field
, "Integer field");
605 BT_ASSERT_PRE_FIELD_HOT(field
, "Integer field");
606 BT_ASSERT_PRE_FIELD_IS_INT_OR_ENUM(field
, "Field");
607 BT_ASSERT_PRE(bt_field_type_integer_is_signed(
608 (void *) get_int_enum_int_ft(field
)),
609 "Field's type is unsigned: %!+f", field
);
610 BT_ASSERT_PRE(value_is_in_range_signed(
611 get_int_enum_int_ft(field
)->size
, value
),
612 "Value is out of bounds: value=%" PRId64
", %![field-]+f",
614 integer
->payload
.signd
= value
;
615 bt_field_set(field
, true);
619 int bt_field_integer_unsigned_get_value(struct bt_field
*field
, uint64_t *value
)
621 struct bt_field_integer
*integer
= (void *) field
;
623 BT_ASSERT_PRE_NON_NULL(field
, "Integer field");
624 BT_ASSERT_PRE_NON_NULL(value
, "Value");
625 BT_ASSERT_PRE_FIELD_IS_SET(field
, "Integer field");
626 BT_ASSERT_PRE_FIELD_IS_INT_OR_ENUM(field
, "Field");
627 BT_ASSERT_PRE(!bt_field_type_integer_is_signed(
628 (void *) get_int_enum_int_ft(field
)),
629 "Field's type is signed: %!+f", field
);
630 *value
= integer
->payload
.unsignd
;
634 int bt_field_integer_unsigned_set_value(struct bt_field
*field
,
637 struct bt_field_integer
*integer
= (void *) field
;
639 BT_ASSERT_PRE_NON_NULL(field
, "Integer field");
640 BT_ASSERT_PRE_FIELD_HOT(field
, "Integer field");
641 BT_ASSERT_PRE_FIELD_IS_INT_OR_ENUM(field
, "Field");
642 BT_ASSERT_PRE(!bt_field_type_integer_is_signed(
643 (void *) get_int_enum_int_ft(field
)),
644 "Field's type is signed: %!+f", field
);
645 BT_ASSERT_PRE(value_is_in_range_unsigned(
646 get_int_enum_int_ft(field
)->size
, value
),
647 "Value is out of bounds: value=%" PRIu64
", %![field-]+f",
649 integer
->payload
.unsignd
= value
;
650 bt_field_set(field
, true);
654 int bt_field_floating_point_get_value(struct bt_field
*field
,
657 struct bt_field_floating_point
*floating_point
= (void *) field
;
659 BT_ASSERT_PRE_NON_NULL(field
, "Floating point number field");
660 BT_ASSERT_PRE_NON_NULL(value
, "Value");
661 BT_ASSERT_PRE_FIELD_IS_SET(field
, "Floating point number field");
662 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
663 BT_FIELD_TYPE_ID_FLOAT
, "Field");
664 *value
= floating_point
->payload
;
668 int bt_field_floating_point_set_value(struct bt_field
*field
,
671 struct bt_field_floating_point
*floating_point
= (void *) field
;
673 BT_ASSERT_PRE_NON_NULL(field
, "Floating point number field");
674 BT_ASSERT_PRE_FIELD_HOT(field
, "Floating point number field");
675 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
676 BT_FIELD_TYPE_ID_FLOAT
, "Field");
677 floating_point
->payload
= value
;
678 bt_field_set(field
, true);
682 const char *bt_field_string_get_value(struct bt_field
*field
)
684 struct bt_field_string
*string
= (void *) field
;
686 BT_ASSERT_PRE_NON_NULL(field
, "String field");
687 BT_ASSERT_PRE_FIELD_IS_SET(field
, "String field");
688 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
689 BT_FIELD_TYPE_ID_STRING
, "Field");
690 return (const char *) string
->buf
->data
;
693 int bt_field_string_set_value(struct bt_field
*field
, const char *value
)
695 BT_ASSERT_PRE_NON_NULL(field
, "String field");
696 BT_ASSERT_PRE_NON_NULL(value
, "Value");
697 BT_ASSERT_PRE_FIELD_HOT(field
, "String field");
698 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
699 BT_FIELD_TYPE_ID_STRING
, "Field");
700 bt_field_string_clear(field
);
701 return bt_field_string_append_len(field
,
702 value
, strlen(value
));
705 int bt_field_string_append(struct bt_field
*field
, const char *value
)
707 BT_ASSERT_PRE_NON_NULL(value
, "Value");
708 return bt_field_string_append_len(field
, value
,
712 int bt_field_string_append_len(struct bt_field
*field
,
713 const char *value
, unsigned int length
)
715 struct bt_field_string
*string_field
= (void *) field
;
719 BT_ASSERT_PRE_NON_NULL(field
, "String field");
720 BT_ASSERT_PRE_NON_NULL(value
, "Value");
721 BT_ASSERT_PRE_FIELD_HOT(field
, "String field");
722 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
723 BT_FIELD_TYPE_ID_STRING
, "Field");
725 /* Make sure no null bytes are appended */
726 BT_ASSERT_PRE(memchr(value
, '\0', length
) == NULL
,
727 "String value to append contains a null character: "
728 "partial-value=\"%.32s\", length=%u", value
, length
);
730 new_size
= string_field
->size
+ length
;
732 if (unlikely(new_size
+ 1 > string_field
->buf
->len
)) {
733 g_array_set_size(string_field
->buf
, new_size
+ 1);
736 data
= string_field
->buf
->data
;
737 memcpy(data
+ string_field
->size
, value
, length
);
738 ((char *) string_field
->buf
->data
)[new_size
] = '\0';
739 string_field
->size
= new_size
;
740 bt_field_set(field
, true);
744 int bt_field_string_clear(struct bt_field
*field
)
746 struct bt_field_string
*string_field
= (void *) field
;
748 BT_ASSERT_PRE_NON_NULL(field
, "String field");
749 BT_ASSERT_PRE_FIELD_HOT(field
, "String field");
750 BT_ASSERT_PRE_FIELD_HAS_TYPE_ID(field
,
751 BT_FIELD_TYPE_ID_STRING
, "Field");
752 string_field
->size
= 0;
753 bt_field_set(field
, true);
758 void bt_field_finalize(struct bt_field
*field
)
761 BT_LOGD_STR("Putting field's type.");
766 void bt_field_integer_destroy(struct bt_field
*field
)
769 BT_LOGD("Destroying integer field object: addr=%p", field
);
770 bt_field_finalize(field
);
775 void bt_field_floating_point_destroy(struct bt_field
*field
)
778 BT_LOGD("Destroying floating point field object: addr=%p", field
);
779 bt_field_finalize(field
);
784 void bt_field_enumeration_destroy(struct bt_field
*field
)
786 BT_LOGD("Destroying enumeration field object: addr=%p", field
);
787 bt_field_finalize((void *) field
);
792 void bt_field_structure_destroy_recursive(struct bt_field
*field
)
794 struct bt_field_structure
*structure
= (void *) field
;
797 BT_LOGD("Destroying structure field object: addr=%p", field
);
798 bt_field_finalize(field
);
800 if (structure
->fields
) {
801 g_ptr_array_free(structure
->fields
, TRUE
);
808 void bt_field_variant_destroy_recursive(struct bt_field
*field
)
810 struct bt_field_variant
*variant
= (void *) field
;
813 BT_LOGD("Destroying variant field object: addr=%p", field
);
814 bt_field_finalize(field
);
816 if (variant
->fields
) {
817 g_ptr_array_free(variant
->fields
, TRUE
);
824 void bt_field_array_destroy_recursive(struct bt_field
*field
)
826 struct bt_field_array
*array
= (void *) field
;
829 BT_LOGD("Destroying array field object: addr=%p", field
);
830 bt_field_finalize(field
);
832 if (array
->elements
) {
833 g_ptr_array_free(array
->elements
, TRUE
);
840 void bt_field_sequence_destroy_recursive(struct bt_field
*field
)
842 struct bt_field_sequence
*sequence
= (void *) field
;
845 BT_LOGD("Destroying sequence field object: addr=%p", field
);
846 bt_field_finalize(field
);
848 if (sequence
->elements
) {
849 g_ptr_array_free(sequence
->elements
, TRUE
);
855 void bt_field_string_destroy(struct bt_field
*field
)
857 struct bt_field_string
*string
= (void *) field
;
859 BT_LOGD("Destroying string field object: addr=%p", field
);
861 bt_field_finalize(field
);
864 g_array_free(string
->buf
, TRUE
);
871 void bt_field_destroy_recursive(struct bt_field
*field
)
877 BT_ASSERT(bt_field_type_has_known_id((void *) field
->type
));
878 field_destroy_funcs
[field
->type
->id
](field
);
882 void bt_field_initialize(struct bt_field
*field
,
883 struct bt_field_type
*ft
,
884 struct bt_field_methods
*methods
)
888 bt_object_init_unique(&field
->base
);
889 field
->methods
= methods
;
890 field
->type
= bt_get(ft
);
894 struct bt_field
*bt_field_integer_create(struct bt_field_type
*type
)
896 struct bt_field_integer
*integer
=
897 g_new0(struct bt_field_integer
, 1);
899 BT_LOGD("Creating integer field object: ft-addr=%p", type
);
902 bt_field_initialize((void *) integer
, (void *) type
,
903 &bt_field_integer_methods
);
904 BT_LOGD("Created integer field object: addr=%p, ft-addr=%p",
907 BT_LOGE_STR("Failed to allocate one integer field.");
910 return (void *) integer
;
914 struct bt_field
*bt_field_enumeration_create(struct bt_field_type
*type
)
916 struct bt_field_enumeration
*enumeration
= g_new0(
917 struct bt_field_enumeration
, 1);
919 BT_LOGD("Creating enumeration field object: ft-addr=%p", type
);
922 bt_field_initialize((void *) enumeration
,
923 (void *) type
, &bt_field_enumeration_methods
);
924 BT_LOGD("Created enumeration field object: addr=%p, ft-addr=%p",
927 BT_LOGE_STR("Failed to allocate one enumeration field.");
930 return (void *) enumeration
;
934 struct bt_field
*bt_field_floating_point_create(struct bt_field_type
*type
)
936 struct bt_field_floating_point
*floating_point
;
938 BT_LOGD("Creating floating point number field object: ft-addr=%p", type
);
939 floating_point
= g_new0(struct bt_field_floating_point
, 1);
941 if (floating_point
) {
942 bt_field_initialize((void *) floating_point
,
943 (void *) type
, &bt_field_floating_point_methods
);
944 BT_LOGD("Created floating point number field object: addr=%p, ft-addr=%p",
945 floating_point
, type
);
947 BT_LOGE_STR("Failed to allocate one floating point number field.");
950 return (void *) floating_point
;
954 int bt_field_structure_initialize(struct bt_field
*field
,
955 struct bt_field_type
*type
,
956 struct bt_field_methods
*methods
,
957 bt_field_create_func field_create_func
,
958 GDestroyNotify field_release_func
)
961 struct bt_field_type_structure
*structure_type
= (void *) type
;
962 struct bt_field_structure
*structure
= (void *) field
;
965 BT_LOGD("Initializing structure field object: ft-addr=%p", type
);
966 bt_field_initialize(field
, type
, methods
);
967 structure
->fields
= g_ptr_array_new_with_free_func(field_release_func
);
968 g_ptr_array_set_size(structure
->fields
, structure_type
->fields
->len
);
970 /* Create all fields contained in the structure field. */
971 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
972 struct bt_field
*field
;
973 struct bt_field_type_structure_field
*struct_field
=
974 BT_FIELD_TYPE_STRUCTURE_FIELD_AT_INDEX(
976 field
= field_create_func(struct_field
->type
);
978 BT_LOGE("Failed to create structure field's member: name=\"%s\", index=%zu",
979 g_quark_to_string(struct_field
->name
), i
);
984 g_ptr_array_index(structure
->fields
, i
) = field
;
987 BT_LOGD("Initialized structure field object: addr=%p, ft-addr=%p",
995 struct bt_field
*bt_field_structure_create(struct bt_field_type
*type
)
997 struct bt_field_structure
*structure
= g_new0(
998 struct bt_field_structure
, 1);
1001 BT_LOGD("Creating structure field object: ft-addr=%p", type
);
1004 BT_LOGE_STR("Failed to allocate one structure field.");
1008 iret
= bt_field_structure_initialize((void *) structure
,
1009 (void *) type
, &bt_field_structure_methods
,
1010 (bt_field_create_func
) bt_field_create_recursive
,
1011 (GDestroyNotify
) bt_field_destroy_recursive
);
1017 BT_LOGD("Created structure field object: addr=%p, ft-addr=%p",
1021 return (void *) structure
;
1025 int bt_field_variant_initialize(struct bt_field
*field
,
1026 struct bt_field_type
*type
,
1027 struct bt_field_methods
*methods
,
1028 bt_field_create_func field_create_func
,
1029 GDestroyNotify field_release_func
)
1032 struct bt_field_type_variant
*variant_type
= (void *) type
;
1033 struct bt_field_variant
*variant
= (void *) field
;
1036 BT_LOGD("Initializing variant field object: ft-addr=%p", type
);
1037 bt_field_initialize(field
, type
, methods
);
1038 ret
= bt_field_type_variant_update_choices(type
);
1040 BT_LOGE("Cannot update variant field type choices: "
1045 variant
->fields
= g_ptr_array_new_with_free_func(field_release_func
);
1046 g_ptr_array_set_size(variant
->fields
, variant_type
->choices
->len
);
1048 /* Create all fields contained in the variant field. */
1049 for (i
= 0; i
< variant_type
->choices
->len
; i
++) {
1050 struct bt_field
*field
;
1051 struct bt_field_type_variant_choice
*var_choice
=
1052 BT_FIELD_TYPE_VARIANT_CHOICE_AT_INDEX(
1055 field
= field_create_func(var_choice
->type
);
1057 BT_LOGE("Failed to create variant field's member: name=\"%s\", index=%zu",
1058 g_quark_to_string(var_choice
->name
), i
);
1063 g_ptr_array_index(variant
->fields
, i
) = field
;
1066 BT_LOGD("Initialized variant field object: addr=%p, ft-addr=%p",
1074 int bt_field_string_initialize(struct bt_field
*field
,
1075 struct bt_field_type
*type
,
1076 struct bt_field_methods
*methods
)
1079 struct bt_field_string
*string
= (void *) field
;
1081 BT_LOGD("Initializing string field object: ft-addr=%p", type
);
1082 bt_field_initialize(field
, type
, methods
);
1083 string
->buf
= g_array_sized_new(FALSE
, FALSE
, sizeof(char), 1);
1089 g_array_index(string
->buf
, char, 0) = '\0';
1090 BT_LOGD("Initialized string field object: addr=%p, ft-addr=%p",
1098 struct bt_field
*bt_field_variant_create(struct bt_field_type
*type
)
1100 struct bt_field_variant
*variant
= g_new0(
1101 struct bt_field_variant
, 1);
1104 BT_LOGD("Creating variant field object: ft-addr=%p", type
);
1107 BT_LOGE_STR("Failed to allocate one variant field.");
1111 iret
= bt_field_variant_initialize((void *) variant
,
1112 (void *) type
, &bt_field_variant_methods
,
1113 (bt_field_create_func
) bt_field_create_recursive
,
1114 (GDestroyNotify
) bt_field_destroy_recursive
);
1120 BT_LOGD("Created variant field object: addr=%p, ft-addr=%p",
1124 return (void *) variant
;
1128 int bt_field_array_initialize(struct bt_field
*field
,
1129 struct bt_field_type
*type
,
1130 struct bt_field_methods
*methods
,
1131 bt_field_create_func field_create_func
,
1132 GDestroyNotify field_destroy_func
)
1134 struct bt_field_type_array
*array_type
= (void *) type
;
1135 struct bt_field_array
*array
= (void *) field
;
1136 unsigned int array_length
;
1140 BT_LOGD("Initializing array field object: ft-addr=%p", type
);
1142 bt_field_initialize(field
, type
, methods
);
1143 array_length
= array_type
->length
;
1144 array
->elements
= g_ptr_array_sized_new(array_length
);
1145 if (!array
->elements
) {
1150 g_ptr_array_set_free_func(array
->elements
, field_destroy_func
);
1151 g_ptr_array_set_size(array
->elements
, array_length
);
1153 for (i
= 0; i
< array_length
; i
++) {
1154 array
->elements
->pdata
[i
] = field_create_func(
1155 array_type
->element_ft
);
1156 if (!array
->elements
->pdata
[i
]) {
1162 BT_LOGD("Initialized array field object: addr=%p, ft-addr=%p",
1170 struct bt_field
*bt_field_array_create(struct bt_field_type
*type
)
1172 struct bt_field_array
*array
=
1173 g_new0(struct bt_field_array
, 1);
1176 BT_LOGD("Creating array field object: ft-addr=%p", type
);
1180 BT_LOGE_STR("Failed to allocate one array field.");
1184 ret
= bt_field_array_initialize((void *) array
,
1185 (void *) type
, &bt_field_array_methods
,
1186 (bt_field_create_func
) bt_field_create_recursive
,
1187 (GDestroyNotify
) bt_field_destroy_recursive
);
1193 BT_LOGD("Created array field object: addr=%p, ft-addr=%p",
1197 return (void *) array
;
1201 int bt_field_sequence_initialize(struct bt_field
*field
,
1202 struct bt_field_type
*type
,
1203 struct bt_field_methods
*methods
,
1204 GDestroyNotify field_destroy_func
)
1206 struct bt_field_sequence
*sequence
= (void *) field
;
1209 BT_LOGD("Initializing sequence field object: ft-addr=%p", type
);
1211 bt_field_initialize(field
, type
, methods
);
1212 sequence
->elements
= g_ptr_array_new();
1213 if (!sequence
->elements
) {
1218 g_ptr_array_set_free_func(sequence
->elements
, field_destroy_func
);
1219 BT_LOGD("Initialized sequence field object: addr=%p, ft-addr=%p",
1227 struct bt_field
*bt_field_sequence_create(struct bt_field_type
*type
)
1229 struct bt_field_sequence
*sequence
=
1230 g_new0(struct bt_field_sequence
, 1);
1233 BT_LOGD("Creating sequence field object: ft-addr=%p", type
);
1237 BT_LOGE_STR("Failed to allocate one sequence field.");
1241 ret
= bt_field_sequence_initialize((void *) sequence
,
1242 (void *) type
, &bt_field_sequence_methods
,
1243 (GDestroyNotify
) bt_field_destroy_recursive
);
1249 BT_LOGD("Created sequence field object: addr=%p, ft-addr=%p",
1253 return (void *) sequence
;
1257 struct bt_field
*bt_field_string_create(struct bt_field_type
*type
)
1259 struct bt_field_string
*string
= g_new0(
1260 struct bt_field_string
, 1);
1262 BT_LOGD("Creating string field object: ft-addr=%p", type
);
1265 bt_field_string_initialize((void *) string
,
1266 (void *) type
, &bt_field_string_methods
);
1267 BT_LOGD("Created string field object: addr=%p, ft-addr=%p",
1270 BT_LOGE_STR("Failed to allocate one string field.");
1273 return (void *) string
;
1277 int bt_field_generic_validate(struct bt_field
*field
)
1279 return (field
&& field
->payload_set
) ? 0 : -1;
1283 int bt_field_structure_validate_recursive(struct bt_field
*field
)
1287 struct bt_field_structure
*structure
= (void *) field
;
1291 for (i
= 0; i
< structure
->fields
->len
; i
++) {
1292 ret
= bt_field_validate_recursive(
1293 (void *) structure
->fields
->pdata
[i
]);
1299 this_ret
= bt_field_type_structure_borrow_field_by_index(
1300 field
->type
, &name
, NULL
, i
);
1301 BT_ASSERT(this_ret
== 0);
1302 BT_ASSERT_PRE_MSG("Invalid structure field's field: "
1303 "%![struct-field-]+f, field-name=\"%s\", "
1304 "index=%" PRId64
", %![field-]+f",
1305 field
, name
, i
, structure
->fields
->pdata
[i
]);
1315 int bt_field_variant_validate_recursive(struct bt_field
*field
)
1318 struct bt_field_variant
*variant
= (void *) field
;
1322 if (!variant
->current_field
) {
1327 ret
= bt_field_validate_recursive(variant
->current_field
);
1334 int bt_field_array_validate_recursive(struct bt_field
*field
)
1338 struct bt_field_array
*array
= (void *) field
;
1342 for (i
= 0; i
< array
->elements
->len
; i
++) {
1343 ret
= bt_field_validate_recursive((void *) array
->elements
->pdata
[i
]);
1345 BT_ASSERT_PRE_MSG("Invalid array field's element field: "
1346 "%![array-field-]+f, " PRId64
", "
1347 "%![elem-field-]+f",
1348 field
, i
, array
->elements
->pdata
[i
]);
1358 int bt_field_sequence_validate_recursive(struct bt_field
*field
)
1362 struct bt_field_sequence
*sequence
= (void *) field
;
1366 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
1367 ret
= bt_field_validate_recursive(
1368 (void *) sequence
->elements
->pdata
[i
]);
1370 BT_ASSERT_PRE_MSG("Invalid sequence field's element field: "
1371 "%![seq-field-]+f, " PRId64
", "
1372 "%![elem-field-]+f",
1373 field
, i
, sequence
->elements
->pdata
[i
]);
1382 void bt_field_generic_reset(struct bt_field
*field
)
1385 field
->payload_set
= false;
1389 void bt_field_structure_reset_recursive(struct bt_field
*field
)
1392 struct bt_field_structure
*structure
= (void *) field
;
1396 for (i
= 0; i
< structure
->fields
->len
; i
++) {
1397 struct bt_field
*member
= structure
->fields
->pdata
[i
];
1401 * Structure members are lazily initialized;
1402 * skip if this member has not been allocated
1408 bt_field_reset_recursive(member
);
1413 void bt_field_variant_reset_recursive(struct bt_field
*field
)
1415 struct bt_field_variant
*variant
= (void *) field
;
1418 variant
->current_field
= NULL
;
1422 void bt_field_array_reset_recursive(struct bt_field
*field
)
1425 struct bt_field_array
*array
= (void *) field
;
1429 for (i
= 0; i
< array
->elements
->len
; i
++) {
1430 struct bt_field
*member
= array
->elements
->pdata
[i
];
1434 * Array elements are lazily initialized; skip
1435 * if this member has not been allocated yet.
1440 bt_field_reset_recursive(member
);
1445 void bt_field_sequence_reset_recursive(struct bt_field
*field
)
1447 struct bt_field_sequence
*sequence
= (void *) field
;
1452 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
1453 if (sequence
->elements
->pdata
[i
]) {
1454 bt_field_reset_recursive(
1455 sequence
->elements
->pdata
[i
]);
1459 sequence
->length
= 0;
1463 void bt_field_generic_set_is_frozen(struct bt_field
*field
,
1466 field
->frozen
= is_frozen
;
1470 void bt_field_structure_set_is_frozen_recursive(
1471 struct bt_field
*field
, bool is_frozen
)
1474 struct bt_field_structure
*structure_field
= (void *) field
;
1476 BT_LOGD("Freezing structure field object: addr=%p", field
);
1478 for (i
= 0; i
< structure_field
->fields
->len
; i
++) {
1479 struct bt_field
*struct_field
=
1480 g_ptr_array_index(structure_field
->fields
, i
);
1482 BT_LOGD("Freezing structure field's field: field-addr=%p, index=%" PRId64
,
1484 bt_field_set_is_frozen_recursive(struct_field
,
1488 bt_field_generic_set_is_frozen(field
, is_frozen
);
1492 void bt_field_variant_set_is_frozen_recursive(
1493 struct bt_field
*field
, bool is_frozen
)
1496 struct bt_field_variant
*variant_field
= (void *) field
;
1498 BT_LOGD("Freezing variant field object: addr=%p", field
);
1500 for (i
= 0; i
< variant_field
->fields
->len
; i
++) {
1501 struct bt_field
*var_field
=
1502 g_ptr_array_index(variant_field
->fields
, i
);
1504 BT_LOGD("Freezing variant field's field: field-addr=%p, index=%" PRId64
,
1506 bt_field_set_is_frozen_recursive(var_field
, is_frozen
);
1509 bt_field_generic_set_is_frozen(field
, is_frozen
);
1513 void bt_field_array_set_is_frozen_recursive(
1514 struct bt_field
*field
, bool is_frozen
)
1517 struct bt_field_array
*array_field
= (void *) field
;
1519 BT_LOGD("Freezing array field object: addr=%p", field
);
1521 for (i
= 0; i
< array_field
->elements
->len
; i
++) {
1522 struct bt_field
*elem_field
=
1523 g_ptr_array_index(array_field
->elements
, i
);
1525 BT_LOGD("Freezing array field object's element field: "
1526 "element-field-addr=%p, index=%" PRId64
,
1528 bt_field_set_is_frozen_recursive(elem_field
, is_frozen
);
1531 bt_field_generic_set_is_frozen(field
, is_frozen
);
1535 void bt_field_sequence_set_is_frozen_recursive(
1536 struct bt_field
*field
, bool is_frozen
)
1539 struct bt_field_sequence
*sequence_field
= (void *) field
;
1541 BT_LOGD("Freezing sequence field object: addr=%p", field
);
1543 for (i
= 0; i
< sequence_field
->length
; i
++) {
1544 struct bt_field
*elem_field
=
1545 g_ptr_array_index(sequence_field
->elements
, i
);
1547 BT_LOGD("Freezing sequence field object's element field: "
1548 "element-field-addr=%p, index=%" PRId64
,
1550 bt_field_set_is_frozen_recursive(elem_field
, is_frozen
);
1553 bt_field_generic_set_is_frozen(field
, is_frozen
);
1557 void _bt_field_set_is_frozen_recursive(struct bt_field
*field
,
1564 BT_LOGD("Setting field object's frozen state: addr=%p, is-frozen=%d",
1566 BT_ASSERT(bt_field_type_has_known_id(field
->type
));
1567 BT_ASSERT(field
->methods
->set_is_frozen
);
1568 field
->methods
->set_is_frozen(field
, is_frozen
);
1575 bt_bool
bt_field_generic_is_set(struct bt_field
*field
)
1577 return field
&& field
->payload_set
;
1581 bt_bool
bt_field_structure_is_set_recursive(
1582 struct bt_field
*field
)
1584 bt_bool is_set
= BT_FALSE
;
1586 struct bt_field_structure
*structure
= (void *) field
;
1590 for (i
= 0; i
< structure
->fields
->len
; i
++) {
1591 is_set
= bt_field_is_set_recursive(
1592 structure
->fields
->pdata
[i
]);
1603 bt_bool
bt_field_variant_is_set_recursive(struct bt_field
*field
)
1605 struct bt_field_variant
*variant
= (void *) field
;
1606 bt_bool is_set
= BT_FALSE
;
1610 if (variant
->current_field
) {
1611 is_set
= bt_field_is_set_recursive(
1612 variant
->current_field
);
1619 bt_bool
bt_field_array_is_set_recursive(struct bt_field
*field
)
1622 bt_bool is_set
= BT_FALSE
;
1623 struct bt_field_array
*array
= (void *) field
;
1627 for (i
= 0; i
< array
->elements
->len
; i
++) {
1628 is_set
= bt_field_is_set_recursive(array
->elements
->pdata
[i
]);
1639 bt_bool
bt_field_sequence_is_set_recursive(struct bt_field
*field
)
1642 bt_bool is_set
= BT_FALSE
;
1643 struct bt_field_sequence
*sequence
= (void *) field
;
1647 if (!sequence
->elements
) {
1651 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
1652 is_set
= bt_field_is_set_recursive(
1653 sequence
->elements
->pdata
[i
]);