2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "LIB/FIELD"
25 #include "lib/logging.h"
27 #include "lib/assert-pre.h"
28 #include <babeltrace2/trace-ir/field.h>
29 #include <babeltrace2/trace-ir/field-const.h>
30 #include "lib/object.h"
31 #include "compat/compiler.h"
32 #include "compat/fcntl.h"
33 #include "common/align.h"
34 #include "common/assert.h"
38 #include "field-class.h"
39 #include "lib/func-status.h"
42 void reset_single_field(struct bt_field
*field
);
45 void reset_array_field(struct bt_field
*field
);
48 void reset_structure_field(struct bt_field
*field
);
51 void reset_option_field(struct bt_field
*field
);
54 void reset_variant_field(struct bt_field
*field
);
57 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
60 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
63 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
66 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
69 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
72 bool single_field_is_set(const struct bt_field
*field
);
75 bool array_field_is_set(const struct bt_field
*field
);
78 bool structure_field_is_set(const struct bt_field
*field
);
81 bool option_field_is_set(const struct bt_field
*field
);
84 bool variant_field_is_set(const struct bt_field
*field
);
87 struct bt_field_methods bool_field_methods
= {
88 .set_is_frozen
= set_single_field_is_frozen
,
89 .is_set
= single_field_is_set
,
90 .reset
= reset_single_field
,
94 struct bt_field_methods bit_array_field_methods
= {
95 .set_is_frozen
= set_single_field_is_frozen
,
96 .is_set
= single_field_is_set
,
97 .reset
= reset_single_field
,
101 struct bt_field_methods integer_field_methods
= {
102 .set_is_frozen
= set_single_field_is_frozen
,
103 .is_set
= single_field_is_set
,
104 .reset
= reset_single_field
,
108 struct bt_field_methods real_field_methods
= {
109 .set_is_frozen
= set_single_field_is_frozen
,
110 .is_set
= single_field_is_set
,
111 .reset
= reset_single_field
,
115 struct bt_field_methods string_field_methods
= {
116 .set_is_frozen
= set_single_field_is_frozen
,
117 .is_set
= single_field_is_set
,
118 .reset
= reset_single_field
,
122 struct bt_field_methods structure_field_methods
= {
123 .set_is_frozen
= set_structure_field_is_frozen
,
124 .is_set
= structure_field_is_set
,
125 .reset
= reset_structure_field
,
129 struct bt_field_methods array_field_methods
= {
130 .set_is_frozen
= set_array_field_is_frozen
,
131 .is_set
= array_field_is_set
,
132 .reset
= reset_array_field
,
136 struct bt_field_methods option_field_methods
= {
137 .set_is_frozen
= set_option_field_is_frozen
,
138 .is_set
= option_field_is_set
,
139 .reset
= reset_option_field
,
143 struct bt_field_methods variant_field_methods
= {
144 .set_is_frozen
= set_variant_field_is_frozen
,
145 .is_set
= variant_field_is_set
,
146 .reset
= reset_variant_field
,
150 struct bt_field
*create_bool_field(struct bt_field_class
*);
153 struct bt_field
*create_bit_array_field(struct bt_field_class
*);
156 struct bt_field
*create_integer_field(struct bt_field_class
*);
159 struct bt_field
*create_real_field(struct bt_field_class
*);
162 struct bt_field
*create_string_field(struct bt_field_class
*);
165 struct bt_field
*create_structure_field(struct bt_field_class
*);
168 struct bt_field
*create_static_array_field(struct bt_field_class
*);
171 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*);
174 struct bt_field
*create_option_field(struct bt_field_class
*);
177 struct bt_field
*create_variant_field(struct bt_field_class
*);
180 void destroy_bool_field(struct bt_field
*field
);
183 void destroy_bit_array_field(struct bt_field
*field
);
186 void destroy_integer_field(struct bt_field
*field
);
189 void destroy_real_field(struct bt_field
*field
);
192 void destroy_string_field(struct bt_field
*field
);
195 void destroy_structure_field(struct bt_field
*field
);
198 void destroy_array_field(struct bt_field
*field
);
201 void destroy_option_field(struct bt_field
*field
);
204 void destroy_variant_field(struct bt_field
*field
);
206 struct bt_field_class
*bt_field_borrow_class(struct bt_field
*field
)
208 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
212 const struct bt_field_class
*bt_field_borrow_class_const(
213 const struct bt_field
*field
)
215 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
219 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
221 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
222 return field
->class->type
;
226 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
228 struct bt_field
*field
= NULL
;
233 case BT_FIELD_CLASS_TYPE_BOOL
:
234 field
= create_bool_field(fc
);
236 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
237 field
= create_bit_array_field(fc
);
239 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
240 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
241 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
242 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
243 field
= create_integer_field(fc
);
245 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
246 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
247 field
= create_real_field(fc
);
249 case BT_FIELD_CLASS_TYPE_STRING
:
250 field
= create_string_field(fc
);
252 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
253 field
= create_structure_field(fc
);
255 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
256 field
= create_static_array_field(fc
);
258 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
259 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
260 field
= create_dynamic_array_field(fc
);
262 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
263 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
264 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
265 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
266 field
= create_option_field(fc
);
268 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
269 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
270 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
271 field
= create_variant_field(fc
);
278 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
288 void init_field(struct bt_field
*field
, struct bt_field_class
*fc
,
289 struct bt_field_methods
*methods
)
293 bt_object_init_unique(&field
->base
);
294 field
->methods
= methods
;
296 bt_object_get_ref_no_null_check(fc
);
300 struct bt_field
*create_bool_field(struct bt_field_class
*fc
)
302 struct bt_field_bool
*bool_field
;
304 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc
);
305 bool_field
= g_new0(struct bt_field_bool
, 1);
307 BT_LIB_LOGE_APPEND_CAUSE(
308 "Failed to allocate one boolean field.");
312 init_field((void *) bool_field
, fc
, &bool_field_methods
);
313 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field
);
316 return (void *) bool_field
;
320 struct bt_field
*create_bit_array_field(struct bt_field_class
*fc
)
322 struct bt_field_bit_array
*ba_field
;
324 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc
);
325 ba_field
= g_new0(struct bt_field_bit_array
, 1);
327 BT_LIB_LOGE_APPEND_CAUSE(
328 "Failed to allocate one bit array field.");
332 init_field((void *) ba_field
, fc
, &bit_array_field_methods
);
333 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field
);
336 return (void *) ba_field
;
340 struct bt_field
*create_integer_field(struct bt_field_class
*fc
)
342 struct bt_field_integer
*int_field
;
344 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc
);
345 int_field
= g_new0(struct bt_field_integer
, 1);
347 BT_LIB_LOGE_APPEND_CAUSE(
348 "Failed to allocate one integer field.");
352 init_field((void *) int_field
, fc
, &integer_field_methods
);
353 BT_LIB_LOGD("Created integer field object: %!+f", int_field
);
356 return (void *) int_field
;
360 struct bt_field
*create_real_field(struct bt_field_class
*fc
)
362 struct bt_field_real
*real_field
;
364 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc
);
365 real_field
= g_new0(struct bt_field_real
, 1);
367 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
371 init_field((void *) real_field
, fc
, &real_field_methods
);
372 BT_LIB_LOGD("Created real field object: %!+f", real_field
);
375 return (void *) real_field
;
379 struct bt_field
*create_string_field(struct bt_field_class
*fc
)
381 struct bt_field_string
*string_field
;
383 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc
);
384 string_field
= g_new0(struct bt_field_string
, 1);
386 BT_LIB_LOGE_APPEND_CAUSE(
387 "Failed to allocate one string field.");
391 init_field((void *) string_field
, fc
, &string_field_methods
);
392 string_field
->buf
= g_array_sized_new(FALSE
, FALSE
,
394 if (!string_field
->buf
) {
395 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
396 bt_field_destroy((void *) string_field
);
401 g_array_index(string_field
->buf
, char, 0) = '\0';
402 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
405 return (void *) string_field
;
409 int create_fields_from_named_field_classes(
410 struct bt_field_class_named_field_class_container
*fc
,
416 *fields
= g_ptr_array_new_with_free_func(
417 (GDestroyNotify
) bt_field_destroy
);
419 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
424 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
426 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
427 struct bt_field
*field
;
428 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
430 field
= bt_field_create(named_fc
->fc
);
432 BT_LIB_LOGE_APPEND_CAUSE(
433 "Failed to create structure member or variant option field: "
434 "name=\"%s\", %![fc-]+F",
435 named_fc
->name
->str
, named_fc
->fc
);
440 g_ptr_array_index(*fields
, i
) = field
;
448 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
450 struct bt_field_structure
*struct_field
;
452 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
453 struct_field
= g_new0(struct bt_field_structure
, 1);
455 BT_LIB_LOGE_APPEND_CAUSE(
456 "Failed to allocate one structure field.");
460 init_field((void *) struct_field
, fc
, &structure_field_methods
);
462 if (create_fields_from_named_field_classes((void *) fc
,
463 &struct_field
->fields
)) {
464 BT_LIB_LOGE_APPEND_CAUSE(
465 "Cannot create structure member fields: %![fc-]+F", fc
);
466 bt_field_destroy((void *) struct_field
);
471 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
474 return (void *) struct_field
;
478 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
480 struct bt_field_option
*opt_field
;
481 struct bt_field_class_option
*opt_fc
= (void *) fc
;
483 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
484 opt_field
= g_new0(struct bt_field_option
, 1);
486 BT_LIB_LOGE_APPEND_CAUSE(
487 "Failed to allocate one option field.");
491 init_field((void *) opt_field
, fc
, &option_field_methods
);
492 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
493 if (!opt_field
->content_field
) {
494 BT_LIB_LOGE_APPEND_CAUSE(
495 "Failed to create option field's content field: "
496 "%![opt-fc-]+F, %![content-fc-]+F",
497 opt_fc
, opt_fc
->content_fc
);
498 bt_field_destroy((void *) opt_field
);
503 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
506 return (void *) opt_field
;
510 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
512 struct bt_field_variant
*var_field
;
514 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
515 var_field
= g_new0(struct bt_field_variant
, 1);
517 BT_LIB_LOGE_APPEND_CAUSE(
518 "Failed to allocate one variant field.");
522 init_field((void *) var_field
, fc
, &variant_field_methods
);
524 if (create_fields_from_named_field_classes((void *) fc
,
525 &var_field
->fields
)) {
526 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
528 bt_field_destroy((void *) var_field
);
533 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
536 return (void *) var_field
;
540 int init_array_field_fields(struct bt_field_array
*array_field
)
544 struct bt_field_class_array
*array_fc
;
546 BT_ASSERT(array_field
);
547 array_fc
= (void *) array_field
->common
.class;
548 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
549 if (!array_field
->fields
) {
550 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
555 g_ptr_array_set_free_func(array_field
->fields
,
556 (GDestroyNotify
) bt_field_destroy
);
557 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
559 for (i
= 0; i
< array_field
->length
; i
++) {
560 array_field
->fields
->pdata
[i
] = bt_field_create(
561 array_fc
->element_fc
);
562 if (!array_field
->fields
->pdata
[i
]) {
563 BT_LIB_LOGE_APPEND_CAUSE(
564 "Cannot create array field's element field: "
565 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
576 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
578 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
579 struct bt_field_array
*array_field
;
581 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
582 array_field
= g_new0(struct bt_field_array
, 1);
584 BT_LIB_LOGE_APPEND_CAUSE(
585 "Failed to allocate one static array field.");
589 init_field((void *) array_field
, fc
, &array_field_methods
);
590 array_field
->length
= array_fc
->length
;
592 if (init_array_field_fields(array_field
)) {
593 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
595 bt_field_destroy((void *) array_field
);
600 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
603 return (void *) array_field
;
607 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
609 struct bt_field_array
*array_field
;
611 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
612 array_field
= g_new0(struct bt_field_array
, 1);
614 BT_LIB_LOGE_APPEND_CAUSE(
615 "Failed to allocate one dynamic array field.");
619 init_field((void *) array_field
, fc
, &array_field_methods
);
621 if (init_array_field_fields(array_field
)) {
622 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
624 bt_field_destroy((void *) array_field
);
629 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
632 return (void *) array_field
;
635 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
637 const struct bt_field_bool
*bool_field
= (const void *) field
;
639 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
640 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
641 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
643 return (bt_bool
) bool_field
->value
;
646 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
648 struct bt_field_bool
*bool_field
= (void *) field
;
650 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
651 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
653 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
654 bool_field
->value
= (bool) value
;
655 bt_field_set_single(field
, true);
658 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
660 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
662 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
663 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
664 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
665 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
666 return ba_field
->value_as_int
;
669 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
672 struct bt_field_bit_array
*ba_field
= (void *) field
;
673 struct bt_field_class_bit_array
*ba_fc
;
675 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
676 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
677 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
678 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
679 ba_fc
= (void *) field
->class;
680 ba_field
->value_as_int
= value
;
682 if (ba_fc
->length
< 64) {
684 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
687 bt_field_set_single(field
, true);
690 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
692 const struct bt_field_integer
*int_field
= (const void *) field
;
694 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
695 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
696 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
697 return int_field
->value
.i
;
700 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
702 struct bt_field_integer
*int_field
= (void *) field
;
704 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
705 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
706 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
707 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
708 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
709 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
710 "%![fc-]+F", value
, field
, field
->class);
711 int_field
->value
.i
= value
;
712 bt_field_set_single(field
, true);
715 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
717 const struct bt_field_integer
*int_field
= (const void *) field
;
719 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
720 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
721 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
722 return int_field
->value
.u
;
725 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
727 struct bt_field_integer
*int_field
= (void *) field
;
729 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
730 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
731 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
732 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
733 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
734 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
735 "%![fc-]+F", value
, field
, field
->class);
736 int_field
->value
.u
= value
;
737 bt_field_set_single(field
, true);
740 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
742 const struct bt_field_real
*real_field
= (const void *) field
;
744 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
745 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
746 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
747 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
748 return (float) real_field
->value
;
751 double bt_field_real_double_precision_get_value(const struct bt_field
*field
)
753 const struct bt_field_real
*real_field
= (const void *) field
;
755 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
756 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
757 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
758 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
760 return real_field
->value
;
763 void bt_field_real_single_precision_set_value(struct bt_field
*field
,
766 struct bt_field_real
*real_field
= (void *) field
;
768 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
769 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
770 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
771 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
773 real_field
->value
= (double) value
;
774 bt_field_set_single(field
, true);
777 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
780 struct bt_field_real
*real_field
= (void *) field
;
782 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
783 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
784 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
785 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
787 real_field
->value
= value
;
788 bt_field_set_single(field
, true);
791 enum bt_field_enumeration_get_mapping_labels_status
792 bt_field_enumeration_unsigned_get_mapping_labels(
793 const struct bt_field
*field
,
794 bt_field_class_enumeration_mapping_label_array
*label_array
,
797 const struct bt_field_integer
*int_field
= (const void *) field
;
799 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
800 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
801 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
802 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
803 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
804 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
806 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
807 field
->class, int_field
->value
.u
, label_array
, count
);
810 enum bt_field_enumeration_get_mapping_labels_status
811 bt_field_enumeration_signed_get_mapping_labels(
812 const struct bt_field
*field
,
813 bt_field_class_enumeration_mapping_label_array
*label_array
,
816 const struct bt_field_integer
*int_field
= (const void *) field
;
818 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
819 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
820 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
821 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
822 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
823 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
825 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
826 field
->class, int_field
->value
.i
, label_array
, count
);
829 const char *bt_field_string_get_value(const struct bt_field
*field
)
831 const struct bt_field_string
*string_field
= (const void *) field
;
833 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
834 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
835 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
837 return (const char *) string_field
->buf
->data
;
840 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
842 const struct bt_field_string
*string_field
= (const void *) field
;
844 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
845 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
846 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
848 return string_field
->length
;
852 void clear_string_field(struct bt_field
*field
)
854 struct bt_field_string
*string_field
= (void *) field
;
857 string_field
->length
= 0;
858 bt_field_set_single(field
, true);
861 enum bt_field_string_set_value_status
bt_field_string_set_value(
862 struct bt_field
*field
, const char *value
)
864 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
865 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
866 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
867 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
869 clear_string_field(field
);
870 return (int) bt_field_string_append_with_length(field
, value
,
871 (uint64_t) strlen(value
));
874 enum bt_field_string_append_status
bt_field_string_append(
875 struct bt_field
*field
, const char *value
)
877 return bt_field_string_append_with_length(field
,
878 value
, (uint64_t) strlen(value
));
881 enum bt_field_string_append_status
bt_field_string_append_with_length(
882 struct bt_field
*field
, const char *value
, uint64_t length
)
884 struct bt_field_string
*string_field
= (void *) field
;
888 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
889 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
890 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
891 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
892 BT_FIELD_CLASS_TYPE_STRING
, "Field");
894 /* Make sure no null bytes are appended */
895 BT_ASSERT_PRE_DEV(!memchr(value
, '\0', length
),
896 "String value to append contains a null character: "
897 "partial-value=\"%.32s\", length=%" PRIu64
, value
, length
);
899 new_length
= length
+ string_field
->length
;
901 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
902 g_array_set_size(string_field
->buf
, new_length
+ 1);
905 data
= string_field
->buf
->data
;
906 memcpy(data
+ string_field
->length
, value
, length
);
907 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
908 string_field
->length
= new_length
;
909 bt_field_set_single(field
, true);
910 return BT_FUNC_STATUS_OK
;
913 void bt_field_string_clear(struct bt_field
*field
)
915 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
916 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
917 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
918 BT_FIELD_CLASS_TYPE_STRING
, "Field");
919 clear_string_field(field
);
922 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
924 const struct bt_field_array
*array_field
= (const void *) field
;
926 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
927 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
928 return array_field
->length
;
931 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
932 struct bt_field
*field
, uint64_t length
)
934 int ret
= BT_FUNC_STATUS_OK
;
935 struct bt_field_array
*array_field
= (void *) field
;
937 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
938 BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(field
, "Field");
939 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
941 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
943 struct bt_field_class_array
*array_fc
;
944 uint64_t cur_len
= array_field
->fields
->len
;
947 g_ptr_array_set_size(array_field
->fields
, length
);
948 array_fc
= (void *) field
->class;
950 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
951 struct bt_field
*elem_field
= bt_field_create(
952 array_fc
->element_fc
);
955 BT_LIB_LOGE_APPEND_CAUSE(
956 "Cannot create element field for "
957 "dynamic array field: "
958 "index=%" PRIu64
", "
959 "%![array-field-]+f", i
, field
);
960 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
964 BT_ASSERT(!array_field
->fields
->pdata
[i
]);
965 array_field
->fields
->pdata
[i
] = elem_field
;
969 array_field
->length
= length
;
976 struct bt_field
*borrow_array_field_element_field_by_index(
977 struct bt_field
*field
, uint64_t index
)
979 struct bt_field_array
*array_field
= (void *) field
;
981 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
982 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
983 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, array_field
->length
);
984 return array_field
->fields
->pdata
[index
];
987 struct bt_field
*bt_field_array_borrow_element_field_by_index(
988 struct bt_field
*field
, uint64_t index
)
990 return borrow_array_field_element_field_by_index(field
, index
);
993 const struct bt_field
*
994 bt_field_array_borrow_element_field_by_index_const(
995 const struct bt_field
*field
, uint64_t index
)
997 return borrow_array_field_element_field_by_index((void *) field
, index
);
1001 struct bt_field
*borrow_structure_field_member_field_by_index(
1002 struct bt_field
*field
, uint64_t index
)
1004 struct bt_field_structure
*struct_field
= (void *) field
;
1006 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1007 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1008 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1009 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, struct_field
->fields
->len
);
1010 return struct_field
->fields
->pdata
[index
];
1013 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1014 struct bt_field
*field
, uint64_t index
)
1016 return borrow_structure_field_member_field_by_index(field
,
1020 const struct bt_field
*
1021 bt_field_structure_borrow_member_field_by_index_const(
1022 const struct bt_field
*field
, uint64_t index
)
1024 return borrow_structure_field_member_field_by_index(
1025 (void *) field
, index
);
1029 struct bt_field
*borrow_structure_field_member_field_by_name(
1030 struct bt_field
*field
, const char *name
)
1032 struct bt_field
*ret_field
= NULL
;
1033 struct bt_field_class_structure
*struct_fc
;
1034 struct bt_field_structure
*struct_field
= (void *) field
;
1038 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1039 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Field name");
1040 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1041 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1042 struct_fc
= (void *) field
->class;
1044 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1045 &orig_key
, &index
)) {
1049 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1050 BT_ASSERT(ret_field
);
1056 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1057 struct bt_field
*field
, const char *name
)
1059 return borrow_structure_field_member_field_by_name(field
, name
);
1062 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1063 const struct bt_field
*field
, const char *name
)
1065 return borrow_structure_field_member_field_by_name(
1066 (void *) field
, name
);
1069 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1071 struct bt_field_option
*opt_field
= (void *) field
;
1073 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1074 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "Field");
1075 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1078 opt_field
->selected_field
= opt_field
->content_field
;
1080 opt_field
->selected_field
= NULL
;
1084 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1086 struct bt_field_option
*opt_field
= (void *) field
;
1088 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1089 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "Field");
1090 return opt_field
->selected_field
;
1093 const struct bt_field
*bt_field_option_borrow_field_const(
1094 const struct bt_field
*field
)
1096 return (const void *) bt_field_option_borrow_field((void *) field
);
1100 struct bt_field
*borrow_variant_field_selected_option_field(
1101 struct bt_field
*field
)
1103 struct bt_field_variant
*var_field
= (void *) field
;
1105 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1106 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1107 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1108 "Variant field has no selected field: %!+f", field
);
1109 return var_field
->selected_field
;
1112 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1113 struct bt_field
*field
)
1115 return borrow_variant_field_selected_option_field(field
);
1118 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1119 const struct bt_field
*field
)
1121 return borrow_variant_field_selected_option_field((void *) field
);
1125 const struct bt_field_class_variant_option
*
1126 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1128 const struct bt_field_class_named_field_class_container
*container_fc
;
1129 const struct bt_field_variant
*var_field
= (const void *) field
;
1132 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1133 "Variant field has no selected field: %!+f", field
);
1134 container_fc
= (const void *) field
->class;
1135 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1138 const struct bt_field_class_variant_option
*
1139 bt_field_variant_borrow_selected_class_option_const(
1140 const struct bt_field
*field
)
1142 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1143 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1144 return borrow_variant_field_selected_class_option(field
);
1147 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1148 bt_field_variant_with_unsigned_integer_selector_borrow_selected_class_option_const(
1149 const struct bt_field
*field
)
1151 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1152 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1153 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
, "Field");
1154 return (const void *) borrow_variant_field_selected_class_option(field
);
1157 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1158 bt_field_variant_with_signed_integer_selector_borrow_selected_class_option_const(
1159 const struct bt_field
*field
)
1161 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1162 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1163 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
, "Field");
1164 return (const void *) borrow_variant_field_selected_class_option(field
);
1167 enum bt_field_variant_select_option_field_by_index_status
1168 bt_field_variant_select_option_field_by_index(
1169 struct bt_field
*field
, uint64_t index
)
1171 struct bt_field_variant
*var_field
= (void *) field
;
1173 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1174 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1175 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1176 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1177 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1178 var_field
->selected_index
= index
;
1179 return BT_FUNC_STATUS_OK
;
1182 uint64_t bt_field_variant_get_selected_option_field_index(
1183 const struct bt_field
*field
)
1185 const struct bt_field_variant
*var_field
= (const void *) field
;
1187 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1188 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1189 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1190 "Variant field has no selected field: %!+f", field
);
1191 return var_field
->selected_index
;
1195 void bt_field_finalize(struct bt_field
*field
)
1198 BT_LOGD_STR("Putting field's class.");
1199 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1203 void destroy_bool_field(struct bt_field
*field
)
1206 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1207 bt_field_finalize(field
);
1212 void destroy_bit_array_field(struct bt_field
*field
)
1215 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1216 bt_field_finalize(field
);
1221 void destroy_integer_field(struct bt_field
*field
)
1224 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1225 bt_field_finalize(field
);
1230 void destroy_real_field(struct bt_field
*field
)
1233 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1234 bt_field_finalize(field
);
1239 void destroy_structure_field(struct bt_field
*field
)
1241 struct bt_field_structure
*struct_field
= (void *) field
;
1244 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1245 bt_field_finalize(field
);
1247 if (struct_field
->fields
) {
1248 g_ptr_array_free(struct_field
->fields
, TRUE
);
1249 struct_field
->fields
= NULL
;
1256 void destroy_option_field(struct bt_field
*field
)
1258 struct bt_field_option
*opt_field
= (void *) field
;
1261 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1262 bt_field_finalize(field
);
1264 if (opt_field
->content_field
) {
1265 bt_field_destroy(opt_field
->content_field
);
1272 void destroy_variant_field(struct bt_field
*field
)
1274 struct bt_field_variant
*var_field
= (void *) field
;
1277 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1278 bt_field_finalize(field
);
1280 if (var_field
->fields
) {
1281 g_ptr_array_free(var_field
->fields
, TRUE
);
1282 var_field
->fields
= NULL
;
1289 void destroy_array_field(struct bt_field
*field
)
1291 struct bt_field_array
*array_field
= (void *) field
;
1294 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1295 bt_field_finalize(field
);
1297 if (array_field
->fields
) {
1298 g_ptr_array_free(array_field
->fields
, TRUE
);
1299 array_field
->fields
= NULL
;
1306 void destroy_string_field(struct bt_field
*field
)
1308 struct bt_field_string
*string_field
= (void *) field
;
1311 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1312 bt_field_finalize(field
);
1314 if (string_field
->buf
) {
1315 g_array_free(string_field
->buf
, TRUE
);
1316 string_field
->buf
= NULL
;
1323 void bt_field_destroy(struct bt_field
*field
)
1327 switch (field
->class->type
) {
1328 case BT_FIELD_CLASS_TYPE_BOOL
:
1329 destroy_bool_field(field
);
1331 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
1332 destroy_bit_array_field(field
);
1334 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1335 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1336 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1337 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1338 destroy_integer_field(field
);
1340 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
1341 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
1342 destroy_real_field(field
);
1344 case BT_FIELD_CLASS_TYPE_STRING
:
1345 destroy_string_field(field
);
1347 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1348 destroy_structure_field(field
);
1350 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1351 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
1352 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
1353 destroy_array_field(field
);
1355 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
1356 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
1357 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1358 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1359 destroy_option_field(field
);
1361 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
1362 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1363 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1364 destroy_variant_field(field
);
1372 void reset_single_field(struct bt_field
*field
)
1375 field
->is_set
= false;
1379 void reset_structure_field(struct bt_field
*field
)
1382 struct bt_field_structure
*struct_field
= (void *) field
;
1386 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1387 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1392 void reset_option_field(struct bt_field
*field
)
1394 struct bt_field_option
*opt_field
= (void *) field
;
1396 BT_ASSERT(opt_field
);
1397 bt_field_reset(opt_field
->content_field
);
1398 opt_field
->selected_field
= NULL
;
1402 void reset_variant_field(struct bt_field
*field
)
1405 struct bt_field_variant
*var_field
= (void *) field
;
1409 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1410 bt_field_reset(var_field
->fields
->pdata
[i
]);
1415 void reset_array_field(struct bt_field
*field
)
1418 struct bt_field_array
*array_field
= (void *) field
;
1422 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1423 bt_field_reset(array_field
->fields
->pdata
[i
]);
1428 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1430 field
->frozen
= is_frozen
;
1434 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1437 struct bt_field_structure
*struct_field
= (void *) field
;
1439 BT_LIB_LOGD("Setting structure field's frozen state: "
1440 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1442 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1443 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1445 BT_LIB_LOGD("Setting structure field's member field's "
1446 "frozen state: %![field-]+f, index=%" PRIu64
,
1448 _bt_field_set_is_frozen(member_field
, is_frozen
);
1451 set_single_field_is_frozen(field
, is_frozen
);
1455 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1457 struct bt_field_option
*opt_field
= (void *) field
;
1459 BT_LIB_LOGD("Setting option field's frozen state: "
1460 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1461 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1462 set_single_field_is_frozen(field
, is_frozen
);
1466 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1469 struct bt_field_variant
*var_field
= (void *) field
;
1471 BT_LIB_LOGD("Setting variant field's frozen state: "
1472 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1474 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1475 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1477 BT_LIB_LOGD("Setting variant field's option field's "
1478 "frozen state: %![field-]+f, index=%" PRIu64
,
1480 _bt_field_set_is_frozen(option_field
, is_frozen
);
1483 set_single_field_is_frozen(field
, is_frozen
);
1487 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1490 struct bt_field_array
*array_field
= (void *) field
;
1492 BT_LIB_LOGD("Setting array field's frozen state: "
1493 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1495 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1496 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1498 BT_LIB_LOGD("Setting array field's element field's "
1499 "frozen state: %![field-]+f, index=%" PRIu64
,
1501 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1504 set_single_field_is_frozen(field
, is_frozen
);
1508 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1512 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1514 BT_ASSERT(field
->methods
->set_is_frozen
);
1515 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1519 bool single_field_is_set(const struct bt_field
*field
)
1522 return field
->is_set
;
1526 bool structure_field_is_set(const struct bt_field
*field
)
1530 const struct bt_field_structure
*struct_field
= (const void *) field
;
1534 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1535 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1546 bool option_field_is_set(const struct bt_field
*field
)
1548 const struct bt_field_option
*opt_field
= (const void *) field
;
1549 bool is_set
= false;
1553 if (opt_field
->selected_field
) {
1554 is_set
= bt_field_is_set(opt_field
->selected_field
);
1561 bool variant_field_is_set(const struct bt_field
*field
)
1563 const struct bt_field_variant
*var_field
= (const void *) field
;
1564 bool is_set
= false;
1568 if (var_field
->selected_field
) {
1569 is_set
= bt_field_is_set(var_field
->selected_field
);
1576 bool array_field_is_set(const struct bt_field
*field
)
1580 const struct bt_field_array
*array_field
= (const void *) field
;
1584 for (i
= 0; i
< array_field
->length
; i
++) {
1585 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);