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
*);
167 struct bt_field
*create_static_array_field(struct bt_field_class
*);
170 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*);
173 struct bt_field
*create_option_field(struct bt_field_class
*);
176 struct bt_field
*create_variant_field(struct bt_field_class
*);
179 struct bt_field
*(* const field_create_funcs
[])(struct bt_field_class
*) = {
180 [BT_FIELD_CLASS_TYPE_BOOL
] = create_bool_field
,
181 [BT_FIELD_CLASS_TYPE_BIT_ARRAY
] = create_bit_array_field
,
182 [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
] = create_integer_field
,
183 [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
] = create_integer_field
,
184 [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
] = create_integer_field
,
185 [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
] = create_integer_field
,
186 [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
] = create_real_field
,
187 [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
] = create_real_field
,
188 [BT_FIELD_CLASS_TYPE_STRING
] = create_string_field
,
189 [BT_FIELD_CLASS_TYPE_STRUCTURE
] = create_structure_field
,
190 [BT_FIELD_CLASS_TYPE_STATIC_ARRAY
] = create_static_array_field
,
191 [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
] = create_dynamic_array_field
,
192 [BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR
] = create_option_field
,
193 [BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
] = create_option_field
,
194 [BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
] = create_option_field
,
195 [BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
] = create_option_field
,
196 [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
] = create_variant_field
,
197 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
] = create_variant_field
,
198 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
] = create_variant_field
,
202 void destroy_bool_field(struct bt_field
*field
);
205 void destroy_bit_array_field(struct bt_field
*field
);
208 void destroy_integer_field(struct bt_field
*field
);
211 void destroy_real_field(struct bt_field
*field
);
214 void destroy_string_field(struct bt_field
*field
);
217 void destroy_structure_field(struct bt_field
*field
);
220 void destroy_array_field(struct bt_field
*field
);
223 void destroy_option_field(struct bt_field
*field
);
226 void destroy_variant_field(struct bt_field
*field
);
229 void (* const field_destroy_funcs
[])(struct bt_field
*) = {
230 [BT_FIELD_CLASS_TYPE_BOOL
] = destroy_bool_field
,
231 [BT_FIELD_CLASS_TYPE_BIT_ARRAY
] = destroy_bit_array_field
,
232 [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
] = destroy_integer_field
,
233 [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
] = destroy_integer_field
,
234 [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
] = destroy_integer_field
,
235 [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
] = destroy_integer_field
,
236 [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
] = destroy_real_field
,
237 [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
] = destroy_real_field
,
238 [BT_FIELD_CLASS_TYPE_STRING
] = destroy_string_field
,
239 [BT_FIELD_CLASS_TYPE_STRUCTURE
] = destroy_structure_field
,
240 [BT_FIELD_CLASS_TYPE_STATIC_ARRAY
] = destroy_array_field
,
241 [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
] = destroy_array_field
,
242 [BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR
] = destroy_option_field
,
243 [BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
] = destroy_option_field
,
244 [BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
] = destroy_option_field
,
245 [BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
] = destroy_option_field
,
246 [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
] = destroy_variant_field
,
247 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
] = destroy_variant_field
,
248 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
] = destroy_variant_field
,
251 struct bt_field_class
*bt_field_borrow_class(struct bt_field
*field
)
253 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
257 const struct bt_field_class
*bt_field_borrow_class_const(
258 const struct bt_field
*field
)
260 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
264 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
266 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
267 return field
->class->type
;
271 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
273 struct bt_field
*field
= NULL
;
276 field
= field_create_funcs
[fc
->type
](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_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_OBJECT_PUT_REF_AND_RESET(string_field
);
400 g_array_index(string_field
->buf
, char, 0) = '\0';
401 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
404 return (void *) string_field
;
408 int create_fields_from_named_field_classes(
409 struct bt_field_class_named_field_class_container
*fc
,
415 *fields
= g_ptr_array_new_with_free_func(
416 (GDestroyNotify
) bt_field_destroy
);
418 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
423 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
425 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
426 struct bt_field
*field
;
427 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
429 field
= bt_field_create(named_fc
->fc
);
431 BT_LIB_LOGE_APPEND_CAUSE(
432 "Failed to create structure member or variant option field: "
433 "name=\"%s\", %![fc-]+F",
434 named_fc
->name
->str
, named_fc
->fc
);
439 g_ptr_array_index(*fields
, i
) = field
;
447 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
449 struct bt_field_structure
*struct_field
;
451 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
452 struct_field
= g_new0(struct bt_field_structure
, 1);
454 BT_LIB_LOGE_APPEND_CAUSE(
455 "Failed to allocate one structure field.");
459 init_field((void *) struct_field
, fc
, &structure_field_methods
);
461 if (create_fields_from_named_field_classes((void *) fc
,
462 &struct_field
->fields
)) {
463 BT_LIB_LOGE_APPEND_CAUSE(
464 "Cannot create structure member fields: %![fc-]+F", fc
);
465 BT_OBJECT_PUT_REF_AND_RESET(struct_field
);
469 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
472 return (void *) struct_field
;
476 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
478 struct bt_field_option
*opt_field
;
479 struct bt_field_class_option
*opt_fc
= (void *) fc
;
481 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
482 opt_field
= g_new0(struct bt_field_option
, 1);
484 BT_LIB_LOGE_APPEND_CAUSE(
485 "Failed to allocate one option field.");
489 init_field((void *) opt_field
, fc
, &option_field_methods
);
490 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
491 if (!opt_field
->content_field
) {
492 BT_LIB_LOGE_APPEND_CAUSE(
493 "Failed to create option field's content field: "
494 "%![opt-fc-]+F, %![content-fc-]+F",
495 opt_fc
, opt_fc
->content_fc
);
496 BT_OBJECT_PUT_REF_AND_RESET(opt_field
);
500 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
503 return (void *) opt_field
;
507 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
509 struct bt_field_variant
*var_field
;
511 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
512 var_field
= g_new0(struct bt_field_variant
, 1);
514 BT_LIB_LOGE_APPEND_CAUSE(
515 "Failed to allocate one variant field.");
519 init_field((void *) var_field
, fc
, &variant_field_methods
);
521 if (create_fields_from_named_field_classes((void *) fc
,
522 &var_field
->fields
)) {
523 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
525 BT_OBJECT_PUT_REF_AND_RESET(var_field
);
529 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
532 return (void *) var_field
;
536 int init_array_field_fields(struct bt_field_array
*array_field
)
540 struct bt_field_class_array
*array_fc
;
542 BT_ASSERT(array_field
);
543 array_fc
= (void *) array_field
->common
.class;
544 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
545 if (!array_field
->fields
) {
546 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
551 g_ptr_array_set_free_func(array_field
->fields
,
552 (GDestroyNotify
) bt_field_destroy
);
553 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
555 for (i
= 0; i
< array_field
->length
; i
++) {
556 array_field
->fields
->pdata
[i
] = bt_field_create(
557 array_fc
->element_fc
);
558 if (!array_field
->fields
->pdata
[i
]) {
559 BT_LIB_LOGE_APPEND_CAUSE(
560 "Cannot create array field's element field: "
561 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
572 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
574 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
575 struct bt_field_array
*array_field
;
577 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
578 array_field
= g_new0(struct bt_field_array
, 1);
580 BT_LIB_LOGE_APPEND_CAUSE(
581 "Failed to allocate one static array field.");
585 init_field((void *) array_field
, fc
, &array_field_methods
);
586 array_field
->length
= array_fc
->length
;
588 if (init_array_field_fields(array_field
)) {
589 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
591 BT_OBJECT_PUT_REF_AND_RESET(array_field
);
595 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
598 return (void *) array_field
;
602 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
604 struct bt_field_array
*array_field
;
606 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
607 array_field
= g_new0(struct bt_field_array
, 1);
609 BT_LIB_LOGE_APPEND_CAUSE(
610 "Failed to allocate one dynamic array field.");
614 init_field((void *) array_field
, fc
, &array_field_methods
);
616 if (init_array_field_fields(array_field
)) {
617 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
619 BT_OBJECT_PUT_REF_AND_RESET(array_field
);
623 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
626 return (void *) array_field
;
629 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
631 const struct bt_field_bool
*bool_field
= (const void *) field
;
633 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
634 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
635 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
637 return (bt_bool
) bool_field
->value
;
640 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
642 struct bt_field_bool
*bool_field
= (void *) field
;
644 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
645 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
647 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
648 bool_field
->value
= (bool) value
;
649 bt_field_set_single(field
, true);
652 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
654 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
656 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
657 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
658 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
659 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
660 return ba_field
->value_as_int
;
663 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
666 struct bt_field_bit_array
*ba_field
= (void *) field
;
667 struct bt_field_class_bit_array
*ba_fc
;
669 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
670 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
671 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
672 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
673 ba_fc
= (void *) field
->class;
674 ba_field
->value_as_int
= value
;
676 if (ba_fc
->length
< 64) {
678 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
681 bt_field_set_single(field
, true);
684 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
686 const struct bt_field_integer
*int_field
= (const void *) field
;
688 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
689 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
690 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
691 return int_field
->value
.i
;
694 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
696 struct bt_field_integer
*int_field
= (void *) field
;
698 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
699 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
700 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
701 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
702 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
703 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
704 "%![fc-]+F", value
, field
, field
->class);
705 int_field
->value
.i
= value
;
706 bt_field_set_single(field
, true);
709 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
711 const struct bt_field_integer
*int_field
= (const void *) field
;
713 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
714 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
715 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
716 return int_field
->value
.u
;
719 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
721 struct bt_field_integer
*int_field
= (void *) field
;
723 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
724 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
725 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
726 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
727 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
728 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
729 "%![fc-]+F", value
, field
, field
->class);
730 int_field
->value
.u
= value
;
731 bt_field_set_single(field
, true);
734 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
736 const struct bt_field_real
*real_field
= (const void *) field
;
738 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
739 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
740 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
741 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
742 return (float) real_field
->value
;
745 double bt_field_real_double_precision_get_value(const struct bt_field
*field
)
747 const struct bt_field_real
*real_field
= (const void *) field
;
749 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
750 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
751 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
752 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
754 return real_field
->value
;
757 void bt_field_real_single_precision_set_value(struct bt_field
*field
,
760 struct bt_field_real
*real_field
= (void *) field
;
762 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
763 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
764 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
765 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
767 real_field
->value
= (double) value
;
768 bt_field_set_single(field
, true);
771 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
774 struct bt_field_real
*real_field
= (void *) field
;
776 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
777 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
778 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
779 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
781 real_field
->value
= value
;
782 bt_field_set_single(field
, true);
785 enum bt_field_enumeration_get_mapping_labels_status
786 bt_field_enumeration_unsigned_get_mapping_labels(
787 const struct bt_field
*field
,
788 bt_field_class_enumeration_mapping_label_array
*label_array
,
791 const struct bt_field_integer
*int_field
= (const void *) field
;
793 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
794 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
795 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
796 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
797 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
798 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
800 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
801 field
->class, int_field
->value
.u
, label_array
, count
);
804 enum bt_field_enumeration_get_mapping_labels_status
805 bt_field_enumeration_signed_get_mapping_labels(
806 const struct bt_field
*field
,
807 bt_field_class_enumeration_mapping_label_array
*label_array
,
810 const struct bt_field_integer
*int_field
= (const void *) field
;
812 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
813 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
814 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
815 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
816 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
817 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
819 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
820 field
->class, int_field
->value
.i
, label_array
, count
);
823 const char *bt_field_string_get_value(const struct bt_field
*field
)
825 const struct bt_field_string
*string_field
= (const void *) field
;
827 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
828 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
829 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
831 return (const char *) string_field
->buf
->data
;
834 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
836 const struct bt_field_string
*string_field
= (const void *) field
;
838 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
839 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
840 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
842 return string_field
->length
;
846 void clear_string_field(struct bt_field
*field
)
848 struct bt_field_string
*string_field
= (void *) field
;
851 string_field
->length
= 0;
852 bt_field_set_single(field
, true);
855 enum bt_field_string_set_value_status
bt_field_string_set_value(
856 struct bt_field
*field
, const char *value
)
858 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
859 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
860 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
861 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
863 clear_string_field(field
);
864 return (int) bt_field_string_append_with_length(field
, value
,
865 (uint64_t) strlen(value
));
868 enum bt_field_string_append_status
bt_field_string_append(
869 struct bt_field
*field
, const char *value
)
871 return bt_field_string_append_with_length(field
,
872 value
, (uint64_t) strlen(value
));
875 enum bt_field_string_append_status
bt_field_string_append_with_length(
876 struct bt_field
*field
, const char *value
, uint64_t length
)
878 struct bt_field_string
*string_field
= (void *) field
;
882 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
883 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
884 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
885 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
886 BT_FIELD_CLASS_TYPE_STRING
, "Field");
888 /* Make sure no null bytes are appended */
889 BT_ASSERT_PRE_DEV(!memchr(value
, '\0', length
),
890 "String value to append contains a null character: "
891 "partial-value=\"%.32s\", length=%" PRIu64
, value
, length
);
893 new_length
= length
+ string_field
->length
;
895 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
896 g_array_set_size(string_field
->buf
, new_length
+ 1);
899 data
= string_field
->buf
->data
;
900 memcpy(data
+ string_field
->length
, value
, length
);
901 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
902 string_field
->length
= new_length
;
903 bt_field_set_single(field
, true);
904 return BT_FUNC_STATUS_OK
;
907 void bt_field_string_clear(struct bt_field
*field
)
909 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
910 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
911 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
912 BT_FIELD_CLASS_TYPE_STRING
, "Field");
913 clear_string_field(field
);
916 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
918 const struct bt_field_array
*array_field
= (const void *) field
;
920 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
921 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
922 return array_field
->length
;
925 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
926 struct bt_field
*field
, uint64_t length
)
928 int ret
= BT_FUNC_STATUS_OK
;
929 struct bt_field_array
*array_field
= (void *) field
;
931 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
932 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
933 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
, "Field");
934 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
936 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
938 struct bt_field_class_array
*array_fc
;
939 uint64_t cur_len
= array_field
->fields
->len
;
942 g_ptr_array_set_size(array_field
->fields
, length
);
943 array_fc
= (void *) field
->class;
945 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
946 struct bt_field
*elem_field
= bt_field_create(
947 array_fc
->element_fc
);
950 BT_LIB_LOGE_APPEND_CAUSE(
951 "Cannot create element field for "
952 "dynamic array field: "
953 "index=%" PRIu64
", "
954 "%![array-field-]+f", i
, field
);
955 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
959 BT_ASSERT(!array_field
->fields
->pdata
[i
]);
960 array_field
->fields
->pdata
[i
] = elem_field
;
964 array_field
->length
= length
;
971 struct bt_field
*borrow_array_field_element_field_by_index(
972 struct bt_field
*field
, uint64_t index
)
974 struct bt_field_array
*array_field
= (void *) field
;
976 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
977 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
978 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, array_field
->length
);
979 return array_field
->fields
->pdata
[index
];
982 struct bt_field
*bt_field_array_borrow_element_field_by_index(
983 struct bt_field
*field
, uint64_t index
)
985 return borrow_array_field_element_field_by_index(field
, index
);
988 const struct bt_field
*
989 bt_field_array_borrow_element_field_by_index_const(
990 const struct bt_field
*field
, uint64_t index
)
992 return borrow_array_field_element_field_by_index((void *) field
, index
);
996 struct bt_field
*borrow_structure_field_member_field_by_index(
997 struct bt_field
*field
, uint64_t index
)
999 struct bt_field_structure
*struct_field
= (void *) field
;
1001 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1002 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1003 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1004 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, struct_field
->fields
->len
);
1005 return struct_field
->fields
->pdata
[index
];
1008 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1009 struct bt_field
*field
, uint64_t index
)
1011 return borrow_structure_field_member_field_by_index(field
,
1015 const struct bt_field
*
1016 bt_field_structure_borrow_member_field_by_index_const(
1017 const struct bt_field
*field
, uint64_t index
)
1019 return borrow_structure_field_member_field_by_index(
1020 (void *) field
, index
);
1024 struct bt_field
*borrow_structure_field_member_field_by_name(
1025 struct bt_field
*field
, const char *name
)
1027 struct bt_field
*ret_field
= NULL
;
1028 struct bt_field_class_structure
*struct_fc
;
1029 struct bt_field_structure
*struct_field
= (void *) field
;
1033 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1034 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Field name");
1035 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1036 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1037 struct_fc
= (void *) field
->class;
1039 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1040 &orig_key
, &index
)) {
1044 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1045 BT_ASSERT(ret_field
);
1051 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1052 struct bt_field
*field
, const char *name
)
1054 return borrow_structure_field_member_field_by_name(field
, name
);
1057 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1058 const struct bt_field
*field
, const char *name
)
1060 return borrow_structure_field_member_field_by_name(
1061 (void *) field
, name
);
1064 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1066 struct bt_field_option
*opt_field
= (void *) field
;
1068 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1069 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "Field");
1070 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1073 opt_field
->selected_field
= opt_field
->content_field
;
1075 opt_field
->selected_field
= NULL
;
1079 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1081 struct bt_field_option
*opt_field
= (void *) field
;
1083 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1084 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "Field");
1085 return opt_field
->selected_field
;
1088 const struct bt_field
*bt_field_option_borrow_field_const(
1089 const struct bt_field
*field
)
1091 return (const void *) bt_field_option_borrow_field((void *) field
);
1095 struct bt_field
*borrow_variant_field_selected_option_field(
1096 struct bt_field
*field
)
1098 struct bt_field_variant
*var_field
= (void *) field
;
1100 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1101 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1102 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1103 "Variant field has no selected field: %!+f", field
);
1104 return var_field
->selected_field
;
1107 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1108 struct bt_field
*field
)
1110 return borrow_variant_field_selected_option_field(field
);
1113 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1114 const struct bt_field
*field
)
1116 return borrow_variant_field_selected_option_field((void *) field
);
1120 const struct bt_field_class_variant_option
*
1121 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1123 const struct bt_field_class_named_field_class_container
*container_fc
;
1124 const struct bt_field_variant
*var_field
= (const void *) field
;
1127 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1128 "Variant field has no selected field: %!+f", field
);
1129 container_fc
= (const void *) field
->class;
1130 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1133 const struct bt_field_class_variant_option
*
1134 bt_field_variant_borrow_selected_class_option_const(
1135 const struct bt_field
*field
)
1137 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1138 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1139 return borrow_variant_field_selected_class_option(field
);
1142 const struct bt_field_class_variant_with_selector_unsigned_option
*
1143 bt_field_variant_with_unsigned_selector_borrow_selected_class_option_const(
1144 const struct bt_field
*field
)
1146 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1147 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1148 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
, "Field");
1149 return (const void *) borrow_variant_field_selected_class_option(field
);
1152 const struct bt_field_class_variant_with_selector_signed_option
*
1153 bt_field_variant_with_signed_selector_borrow_selected_class_option_const(
1154 const struct bt_field
*field
)
1156 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1157 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1158 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
, "Field");
1159 return (const void *) borrow_variant_field_selected_class_option(field
);
1162 enum bt_field_variant_select_option_field_by_index_status
1163 bt_field_variant_select_option_field_by_index(
1164 struct bt_field
*field
, uint64_t index
)
1166 struct bt_field_variant
*var_field
= (void *) field
;
1168 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1169 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1170 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1171 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1172 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1173 var_field
->selected_index
= index
;
1174 return BT_FUNC_STATUS_OK
;
1177 uint64_t bt_field_variant_get_selected_option_field_index(
1178 const struct bt_field
*field
)
1180 const struct bt_field_variant
*var_field
= (const void *) field
;
1182 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1183 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1184 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1185 "Variant field has no selected field: %!+f", field
);
1186 return var_field
->selected_index
;
1190 void bt_field_finalize(struct bt_field
*field
)
1193 BT_LOGD_STR("Putting field's class.");
1194 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1198 void destroy_bool_field(struct bt_field
*field
)
1201 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1202 bt_field_finalize(field
);
1207 void destroy_bit_array_field(struct bt_field
*field
)
1210 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1211 bt_field_finalize(field
);
1216 void destroy_integer_field(struct bt_field
*field
)
1219 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1220 bt_field_finalize(field
);
1225 void destroy_real_field(struct bt_field
*field
)
1228 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1229 bt_field_finalize(field
);
1234 void destroy_structure_field(struct bt_field
*field
)
1236 struct bt_field_structure
*struct_field
= (void *) field
;
1239 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1240 bt_field_finalize(field
);
1242 if (struct_field
->fields
) {
1243 g_ptr_array_free(struct_field
->fields
, TRUE
);
1244 struct_field
->fields
= NULL
;
1251 void destroy_option_field(struct bt_field
*field
)
1253 struct bt_field_option
*opt_field
= (void *) field
;
1256 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1257 bt_field_finalize(field
);
1259 if (opt_field
->content_field
) {
1260 bt_field_destroy(opt_field
->content_field
);
1267 void destroy_variant_field(struct bt_field
*field
)
1269 struct bt_field_variant
*var_field
= (void *) field
;
1272 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1273 bt_field_finalize(field
);
1275 if (var_field
->fields
) {
1276 g_ptr_array_free(var_field
->fields
, TRUE
);
1277 var_field
->fields
= NULL
;
1284 void destroy_array_field(struct bt_field
*field
)
1286 struct bt_field_array
*array_field
= (void *) field
;
1289 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1290 bt_field_finalize(field
);
1292 if (array_field
->fields
) {
1293 g_ptr_array_free(array_field
->fields
, TRUE
);
1294 array_field
->fields
= NULL
;
1301 void destroy_string_field(struct bt_field
*field
)
1303 struct bt_field_string
*string_field
= (void *) field
;
1306 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1307 bt_field_finalize(field
);
1309 if (string_field
->buf
) {
1310 g_array_free(string_field
->buf
, TRUE
);
1311 string_field
->buf
= NULL
;
1318 void bt_field_destroy(struct bt_field
*field
)
1321 field_destroy_funcs
[field
->class->type
](field
);
1325 void reset_single_field(struct bt_field
*field
)
1328 field
->is_set
= false;
1332 void reset_structure_field(struct bt_field
*field
)
1335 struct bt_field_structure
*struct_field
= (void *) field
;
1339 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1340 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1345 void reset_option_field(struct bt_field
*field
)
1347 struct bt_field_option
*opt_field
= (void *) field
;
1349 BT_ASSERT(opt_field
);
1350 bt_field_reset(opt_field
->content_field
);
1351 opt_field
->selected_field
= NULL
;
1355 void reset_variant_field(struct bt_field
*field
)
1358 struct bt_field_variant
*var_field
= (void *) field
;
1362 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1363 bt_field_reset(var_field
->fields
->pdata
[i
]);
1368 void reset_array_field(struct bt_field
*field
)
1371 struct bt_field_array
*array_field
= (void *) field
;
1375 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1376 bt_field_reset(array_field
->fields
->pdata
[i
]);
1381 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1383 field
->frozen
= is_frozen
;
1387 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1390 struct bt_field_structure
*struct_field
= (void *) field
;
1392 BT_LIB_LOGD("Setting structure field's frozen state: "
1393 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1395 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1396 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1398 BT_LIB_LOGD("Setting structure field's member field's "
1399 "frozen state: %![field-]+f, index=%" PRIu64
,
1401 _bt_field_set_is_frozen(member_field
, is_frozen
);
1404 set_single_field_is_frozen(field
, is_frozen
);
1408 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1410 struct bt_field_option
*opt_field
= (void *) field
;
1412 BT_LIB_LOGD("Setting option field's frozen state: "
1413 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1414 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1415 set_single_field_is_frozen(field
, is_frozen
);
1419 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1422 struct bt_field_variant
*var_field
= (void *) field
;
1424 BT_LIB_LOGD("Setting variant field's frozen state: "
1425 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1427 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1428 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1430 BT_LIB_LOGD("Setting variant field's option field's "
1431 "frozen state: %![field-]+f, index=%" PRIu64
,
1433 _bt_field_set_is_frozen(option_field
, is_frozen
);
1436 set_single_field_is_frozen(field
, is_frozen
);
1440 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1443 struct bt_field_array
*array_field
= (void *) field
;
1445 BT_LIB_LOGD("Setting array field's frozen state: "
1446 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1448 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1449 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1451 BT_LIB_LOGD("Setting array field's element field's "
1452 "frozen state: %![field-]+f, index=%" PRIu64
,
1454 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1457 set_single_field_is_frozen(field
, is_frozen
);
1461 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1465 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1467 BT_ASSERT(field
->methods
->set_is_frozen
);
1468 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1472 bool single_field_is_set(const struct bt_field
*field
)
1475 return field
->is_set
;
1479 bool structure_field_is_set(const struct bt_field
*field
)
1483 const struct bt_field_structure
*struct_field
= (const void *) field
;
1487 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1488 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1499 bool option_field_is_set(const struct bt_field
*field
)
1501 const struct bt_field_option
*opt_field
= (const void *) field
;
1502 bool is_set
= false;
1506 if (opt_field
->selected_field
) {
1507 is_set
= bt_field_is_set(opt_field
->selected_field
);
1514 bool variant_field_is_set(const struct bt_field
*field
)
1516 const struct bt_field_variant
*var_field
= (const void *) field
;
1517 bool is_set
= false;
1521 if (var_field
->selected_field
) {
1522 is_set
= bt_field_is_set(var_field
->selected_field
);
1529 bool array_field_is_set(const struct bt_field
*field
)
1533 const struct bt_field_array
*array_field
= (const void *) field
;
1537 for (i
= 0; i
< array_field
->length
; i
++) {
1538 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);