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
] = create_option_field
,
193 [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
] = create_variant_field
,
194 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
] = create_variant_field
,
195 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
] = create_variant_field
,
199 void destroy_bool_field(struct bt_field
*field
);
202 void destroy_bit_array_field(struct bt_field
*field
);
205 void destroy_integer_field(struct bt_field
*field
);
208 void destroy_real_field(struct bt_field
*field
);
211 void destroy_string_field(struct bt_field
*field
);
214 void destroy_structure_field(struct bt_field
*field
);
217 void destroy_array_field(struct bt_field
*field
);
220 void destroy_option_field(struct bt_field
*field
);
223 void destroy_variant_field(struct bt_field
*field
);
226 void (* const field_destroy_funcs
[])(struct bt_field
*) = {
227 [BT_FIELD_CLASS_TYPE_BOOL
] = destroy_bool_field
,
228 [BT_FIELD_CLASS_TYPE_BIT_ARRAY
] = destroy_bit_array_field
,
229 [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
] = destroy_integer_field
,
230 [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
] = destroy_integer_field
,
231 [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
] = destroy_integer_field
,
232 [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
] = destroy_integer_field
,
233 [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
] = destroy_real_field
,
234 [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
] = destroy_real_field
,
235 [BT_FIELD_CLASS_TYPE_STRING
] = destroy_string_field
,
236 [BT_FIELD_CLASS_TYPE_STRUCTURE
] = destroy_structure_field
,
237 [BT_FIELD_CLASS_TYPE_STATIC_ARRAY
] = destroy_array_field
,
238 [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
] = destroy_array_field
,
239 [BT_FIELD_CLASS_TYPE_OPTION
] = destroy_option_field
,
240 [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
] = destroy_variant_field
,
241 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
] = destroy_variant_field
,
242 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
] = destroy_variant_field
,
245 struct bt_field_class
*bt_field_borrow_class(struct bt_field
*field
)
247 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
251 const struct bt_field_class
*bt_field_borrow_class_const(
252 const struct bt_field
*field
)
254 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
258 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
260 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
261 return field
->class->type
;
265 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
267 struct bt_field
*field
= NULL
;
270 field
= field_create_funcs
[fc
->type
](fc
);
272 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
282 void init_field(struct bt_field
*field
, struct bt_field_class
*fc
,
283 struct bt_field_methods
*methods
)
287 bt_object_init_unique(&field
->base
);
288 field
->methods
= methods
;
290 bt_object_get_no_null_check(fc
);
294 struct bt_field
*create_bool_field(struct bt_field_class
*fc
)
296 struct bt_field_bool
*bool_field
;
298 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc
);
299 bool_field
= g_new0(struct bt_field_bool
, 1);
301 BT_LIB_LOGE_APPEND_CAUSE(
302 "Failed to allocate one boolean field.");
306 init_field((void *) bool_field
, fc
, &bool_field_methods
);
307 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field
);
310 return (void *) bool_field
;
314 struct bt_field
*create_bit_array_field(struct bt_field_class
*fc
)
316 struct bt_field_bit_array
*ba_field
;
318 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc
);
319 ba_field
= g_new0(struct bt_field_bit_array
, 1);
321 BT_LIB_LOGE_APPEND_CAUSE(
322 "Failed to allocate one bit array field.");
326 init_field((void *) ba_field
, fc
, &bit_array_field_methods
);
327 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field
);
330 return (void *) ba_field
;
334 struct bt_field
*create_integer_field(struct bt_field_class
*fc
)
336 struct bt_field_integer
*int_field
;
338 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc
);
339 int_field
= g_new0(struct bt_field_integer
, 1);
341 BT_LIB_LOGE_APPEND_CAUSE(
342 "Failed to allocate one integer field.");
346 init_field((void *) int_field
, fc
, &integer_field_methods
);
347 BT_LIB_LOGD("Created integer field object: %!+f", int_field
);
350 return (void *) int_field
;
354 struct bt_field
*create_real_field(struct bt_field_class
*fc
)
356 struct bt_field_real
*real_field
;
358 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc
);
359 real_field
= g_new0(struct bt_field_real
, 1);
361 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
365 init_field((void *) real_field
, fc
, &real_field_methods
);
366 BT_LIB_LOGD("Created real field object: %!+f", real_field
);
369 return (void *) real_field
;
373 struct bt_field
*create_string_field(struct bt_field_class
*fc
)
375 struct bt_field_string
*string_field
;
377 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc
);
378 string_field
= g_new0(struct bt_field_string
, 1);
380 BT_LIB_LOGE_APPEND_CAUSE(
381 "Failed to allocate one string field.");
385 init_field((void *) string_field
, fc
, &string_field_methods
);
386 string_field
->buf
= g_array_sized_new(FALSE
, FALSE
,
388 if (!string_field
->buf
) {
389 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
390 BT_OBJECT_PUT_REF_AND_RESET(string_field
);
394 g_array_index(string_field
->buf
, char, 0) = '\0';
395 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
398 return (void *) string_field
;
402 int create_fields_from_named_field_classes(
403 struct bt_field_class_named_field_class_container
*fc
,
409 *fields
= g_ptr_array_new_with_free_func(
410 (GDestroyNotify
) bt_field_destroy
);
412 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
417 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
419 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
420 struct bt_field
*field
;
421 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
423 field
= bt_field_create(named_fc
->fc
);
425 BT_LIB_LOGE_APPEND_CAUSE(
426 "Failed to create structure member or variant option field: "
427 "name=\"%s\", %![fc-]+F",
428 named_fc
->name
->str
, named_fc
->fc
);
433 g_ptr_array_index(*fields
, i
) = field
;
441 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
443 struct bt_field_structure
*struct_field
;
445 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
446 struct_field
= g_new0(struct bt_field_structure
, 1);
448 BT_LIB_LOGE_APPEND_CAUSE(
449 "Failed to allocate one structure field.");
453 init_field((void *) struct_field
, fc
, &structure_field_methods
);
455 if (create_fields_from_named_field_classes((void *) fc
,
456 &struct_field
->fields
)) {
457 BT_LIB_LOGE_APPEND_CAUSE(
458 "Cannot create structure member fields: %![fc-]+F", fc
);
459 BT_OBJECT_PUT_REF_AND_RESET(struct_field
);
463 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
466 return (void *) struct_field
;
470 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
472 struct bt_field_option
*opt_field
;
473 struct bt_field_class_option
*opt_fc
= (void *) fc
;
475 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
476 opt_field
= g_new0(struct bt_field_option
, 1);
478 BT_LIB_LOGE_APPEND_CAUSE(
479 "Failed to allocate one option field.");
483 init_field((void *) opt_field
, fc
, &option_field_methods
);
484 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
485 if (!opt_field
->content_field
) {
486 BT_LIB_LOGE_APPEND_CAUSE(
487 "Failed to create option field's content field: "
488 "%![opt-fc-]+F, %![content-fc-]+F",
489 opt_fc
, opt_fc
->content_fc
);
490 BT_OBJECT_PUT_REF_AND_RESET(opt_field
);
494 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
497 return (void *) opt_field
;
501 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
503 struct bt_field_variant
*var_field
;
505 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
506 var_field
= g_new0(struct bt_field_variant
, 1);
508 BT_LIB_LOGE_APPEND_CAUSE(
509 "Failed to allocate one variant field.");
513 init_field((void *) var_field
, fc
, &variant_field_methods
);
515 if (create_fields_from_named_field_classes((void *) fc
,
516 &var_field
->fields
)) {
517 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
519 BT_OBJECT_PUT_REF_AND_RESET(var_field
);
523 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
526 return (void *) var_field
;
530 int init_array_field_fields(struct bt_field_array
*array_field
)
534 struct bt_field_class_array
*array_fc
;
536 BT_ASSERT(array_field
);
537 array_fc
= (void *) array_field
->common
.class;
538 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
539 if (!array_field
->fields
) {
540 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
545 g_ptr_array_set_free_func(array_field
->fields
,
546 (GDestroyNotify
) bt_field_destroy
);
547 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
549 for (i
= 0; i
< array_field
->length
; i
++) {
550 array_field
->fields
->pdata
[i
] = bt_field_create(
551 array_fc
->element_fc
);
552 if (!array_field
->fields
->pdata
[i
]) {
553 BT_LIB_LOGE_APPEND_CAUSE(
554 "Cannot create array field's element field: "
555 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
566 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
568 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
569 struct bt_field_array
*array_field
;
571 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
572 array_field
= g_new0(struct bt_field_array
, 1);
574 BT_LIB_LOGE_APPEND_CAUSE(
575 "Failed to allocate one static array field.");
579 init_field((void *) array_field
, fc
, &array_field_methods
);
580 array_field
->length
= array_fc
->length
;
582 if (init_array_field_fields(array_field
)) {
583 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
585 BT_OBJECT_PUT_REF_AND_RESET(array_field
);
589 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
592 return (void *) array_field
;
596 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
598 struct bt_field_array
*array_field
;
600 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
601 array_field
= g_new0(struct bt_field_array
, 1);
603 BT_LIB_LOGE_APPEND_CAUSE(
604 "Failed to allocate one dynamic array field.");
608 init_field((void *) array_field
, fc
, &array_field_methods
);
610 if (init_array_field_fields(array_field
)) {
611 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
613 BT_OBJECT_PUT_REF_AND_RESET(array_field
);
617 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
620 return (void *) array_field
;
623 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
625 const struct bt_field_bool
*bool_field
= (const void *) field
;
627 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
628 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
629 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
631 return (bt_bool
) bool_field
->value
;
634 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
636 struct bt_field_bool
*bool_field
= (void *) field
;
638 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
639 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
641 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
642 bool_field
->value
= (bool) value
;
643 bt_field_set_single(field
, true);
646 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
648 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
650 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
651 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
652 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
653 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
654 return ba_field
->value_as_int
;
657 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
660 struct bt_field_bit_array
*ba_field
= (void *) field
;
661 struct bt_field_class_bit_array
*ba_fc
;
663 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
664 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
665 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
666 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
667 ba_fc
= (void *) field
->class;
668 ba_field
->value_as_int
= value
;
670 if (ba_fc
->length
< 64) {
672 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
675 bt_field_set_single(field
, true);
678 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
680 const struct bt_field_integer
*int_field
= (const void *) field
;
682 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
683 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
684 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
685 return int_field
->value
.i
;
688 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
690 struct bt_field_integer
*int_field
= (void *) field
;
692 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
693 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
694 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
695 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
696 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
697 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
698 "%![fc-]+F", value
, field
, field
->class);
699 int_field
->value
.i
= value
;
700 bt_field_set_single(field
, true);
703 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
705 const struct bt_field_integer
*int_field
= (const void *) field
;
707 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
708 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
709 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
710 return int_field
->value
.u
;
713 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
715 struct bt_field_integer
*int_field
= (void *) field
;
717 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
718 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
719 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
720 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
721 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
722 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
723 "%![fc-]+F", value
, field
, field
->class);
724 int_field
->value
.u
= value
;
725 bt_field_set_single(field
, true);
728 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
730 const struct bt_field_real
*real_field
= (const void *) field
;
732 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
733 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
734 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
735 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
736 return (float) real_field
->value
;
739 double bt_field_real_double_precision_get_value(const struct bt_field
*field
)
741 const struct bt_field_real
*real_field
= (const void *) field
;
743 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
744 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
745 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
746 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
748 return real_field
->value
;
751 void bt_field_real_single_precision_set_value(struct bt_field
*field
,
754 struct bt_field_real
*real_field
= (void *) field
;
756 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
757 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
758 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
759 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
761 real_field
->value
= (double) value
;
762 bt_field_set_single(field
, true);
765 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
768 struct bt_field_real
*real_field
= (void *) field
;
770 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
771 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
772 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
773 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
775 real_field
->value
= value
;
776 bt_field_set_single(field
, true);
779 enum bt_field_enumeration_get_mapping_labels_status
780 bt_field_enumeration_unsigned_get_mapping_labels(
781 const struct bt_field
*field
,
782 bt_field_class_enumeration_mapping_label_array
*label_array
,
785 const struct bt_field_integer
*int_field
= (const void *) field
;
787 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
788 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
789 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
790 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
791 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
792 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
794 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
795 field
->class, int_field
->value
.u
, label_array
, count
);
798 enum bt_field_enumeration_get_mapping_labels_status
799 bt_field_enumeration_signed_get_mapping_labels(
800 const struct bt_field
*field
,
801 bt_field_class_enumeration_mapping_label_array
*label_array
,
804 const struct bt_field_integer
*int_field
= (const void *) field
;
806 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
807 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
808 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
809 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
810 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
811 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
813 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
814 field
->class, int_field
->value
.i
, label_array
, count
);
817 const char *bt_field_string_get_value(const struct bt_field
*field
)
819 const struct bt_field_string
*string_field
= (const void *) field
;
821 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
822 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
823 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
825 return (const char *) string_field
->buf
->data
;
828 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
830 const struct bt_field_string
*string_field
= (const void *) field
;
832 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
833 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
834 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
836 return string_field
->length
;
840 void clear_string_field(struct bt_field
*field
)
842 struct bt_field_string
*string_field
= (void *) field
;
845 string_field
->length
= 0;
846 bt_field_set_single(field
, true);
849 enum bt_field_string_set_value_status
bt_field_string_set_value(
850 struct bt_field
*field
, const char *value
)
852 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
853 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
854 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
855 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
857 clear_string_field(field
);
858 return (int) bt_field_string_append_with_length(field
, value
,
859 (uint64_t) strlen(value
));
862 enum bt_field_string_append_status
bt_field_string_append(
863 struct bt_field
*field
, const char *value
)
865 return bt_field_string_append_with_length(field
,
866 value
, (uint64_t) strlen(value
));
869 enum bt_field_string_append_status
bt_field_string_append_with_length(
870 struct bt_field
*field
, const char *value
, uint64_t length
)
872 struct bt_field_string
*string_field
= (void *) field
;
876 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
877 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
878 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
879 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
880 BT_FIELD_CLASS_TYPE_STRING
, "Field");
882 /* Make sure no null bytes are appended */
883 BT_ASSERT_PRE_DEV(!memchr(value
, '\0', length
),
884 "String value to append contains a null character: "
885 "partial-value=\"%.32s\", length=%" PRIu64
, value
, length
);
887 new_length
= length
+ string_field
->length
;
889 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
890 g_array_set_size(string_field
->buf
, new_length
+ 1);
893 data
= string_field
->buf
->data
;
894 memcpy(data
+ string_field
->length
, value
, length
);
895 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
896 string_field
->length
= new_length
;
897 bt_field_set_single(field
, true);
898 return BT_FUNC_STATUS_OK
;
901 void bt_field_string_clear(struct bt_field
*field
)
903 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
904 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
905 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
906 BT_FIELD_CLASS_TYPE_STRING
, "Field");
907 clear_string_field(field
);
910 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
912 const struct bt_field_array
*array_field
= (const void *) field
;
914 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
915 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
916 return array_field
->length
;
919 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
920 struct bt_field
*field
, uint64_t length
)
922 int ret
= BT_FUNC_STATUS_OK
;
923 struct bt_field_array
*array_field
= (void *) field
;
925 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
926 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
927 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
, "Field");
928 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
930 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
932 struct bt_field_class_array
*array_fc
;
933 uint64_t cur_len
= array_field
->fields
->len
;
936 g_ptr_array_set_size(array_field
->fields
, length
);
937 array_fc
= (void *) field
->class;
939 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
940 struct bt_field
*elem_field
= bt_field_create(
941 array_fc
->element_fc
);
944 BT_LIB_LOGE_APPEND_CAUSE(
945 "Cannot create element field for "
946 "dynamic array field: "
947 "index=%" PRIu64
", "
948 "%![array-field-]+f", i
, field
);
949 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
953 BT_ASSERT(!array_field
->fields
->pdata
[i
]);
954 array_field
->fields
->pdata
[i
] = elem_field
;
958 array_field
->length
= length
;
965 struct bt_field
*borrow_array_field_element_field_by_index(
966 struct bt_field
*field
, uint64_t index
)
968 struct bt_field_array
*array_field
= (void *) field
;
970 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
971 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
972 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, array_field
->length
);
973 return array_field
->fields
->pdata
[index
];
976 struct bt_field
*bt_field_array_borrow_element_field_by_index(
977 struct bt_field
*field
, uint64_t index
)
979 return borrow_array_field_element_field_by_index(field
, index
);
982 const struct bt_field
*
983 bt_field_array_borrow_element_field_by_index_const(
984 const struct bt_field
*field
, uint64_t index
)
986 return borrow_array_field_element_field_by_index((void *) field
, index
);
990 struct bt_field
*borrow_structure_field_member_field_by_index(
991 struct bt_field
*field
, uint64_t index
)
993 struct bt_field_structure
*struct_field
= (void *) field
;
995 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
996 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
997 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
998 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, struct_field
->fields
->len
);
999 return struct_field
->fields
->pdata
[index
];
1002 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1003 struct bt_field
*field
, uint64_t index
)
1005 return borrow_structure_field_member_field_by_index(field
,
1009 const struct bt_field
*
1010 bt_field_structure_borrow_member_field_by_index_const(
1011 const struct bt_field
*field
, uint64_t index
)
1013 return borrow_structure_field_member_field_by_index(
1014 (void *) field
, index
);
1018 struct bt_field
*borrow_structure_field_member_field_by_name(
1019 struct bt_field
*field
, const char *name
)
1021 struct bt_field
*ret_field
= NULL
;
1022 struct bt_field_class_structure
*struct_fc
;
1023 struct bt_field_structure
*struct_field
= (void *) field
;
1027 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1028 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Field name");
1029 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1030 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1031 struct_fc
= (void *) field
->class;
1033 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1034 &orig_key
, &index
)) {
1038 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1039 BT_ASSERT(ret_field
);
1045 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1046 struct bt_field
*field
, const char *name
)
1048 return borrow_structure_field_member_field_by_name(field
, name
);
1051 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1052 const struct bt_field
*field
, const char *name
)
1054 return borrow_structure_field_member_field_by_name(
1055 (void *) field
, name
);
1058 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1060 struct bt_field_option
*opt_field
= (void *) field
;
1062 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1063 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1064 BT_FIELD_CLASS_TYPE_OPTION
, "Field");
1065 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1068 opt_field
->selected_field
= opt_field
->content_field
;
1070 opt_field
->selected_field
= NULL
;
1074 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1076 struct bt_field_option
*opt_field
= (void *) field
;
1078 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1079 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1080 BT_FIELD_CLASS_TYPE_OPTION
, "Field");
1081 return opt_field
->selected_field
;
1084 const struct bt_field
*bt_field_option_borrow_field_const(
1085 const struct bt_field
*field
)
1087 return (const void *) bt_field_option_borrow_field((void *) field
);
1091 struct bt_field
*borrow_variant_field_selected_option_field(
1092 struct bt_field
*field
)
1094 struct bt_field_variant
*var_field
= (void *) field
;
1096 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1097 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1098 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1099 "Variant field has no selected field: %!+f", field
);
1100 return var_field
->selected_field
;
1103 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1104 struct bt_field
*field
)
1106 return borrow_variant_field_selected_option_field(field
);
1109 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1110 const struct bt_field
*field
)
1112 return borrow_variant_field_selected_option_field((void *) field
);
1116 const struct bt_field_class_variant_option
*
1117 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1119 const struct bt_field_class_named_field_class_container
*container_fc
;
1120 const struct bt_field_variant
*var_field
= (const void *) field
;
1123 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1124 "Variant field has no selected field: %!+f", field
);
1125 container_fc
= (const void *) field
->class;
1126 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1129 const struct bt_field_class_variant_option
*
1130 bt_field_variant_borrow_selected_class_option_const(
1131 const struct bt_field
*field
)
1133 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1134 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1135 return borrow_variant_field_selected_class_option(field
);
1138 const struct bt_field_class_variant_with_selector_unsigned_option
*
1139 bt_field_variant_with_unsigned_selector_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_HAS_CLASS_TYPE(field
,
1144 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
, "Field");
1145 return (const void *) borrow_variant_field_selected_class_option(field
);
1148 const struct bt_field_class_variant_with_selector_signed_option
*
1149 bt_field_variant_with_signed_selector_borrow_selected_class_option_const(
1150 const struct bt_field
*field
)
1152 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1153 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1154 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
, "Field");
1155 return (const void *) borrow_variant_field_selected_class_option(field
);
1158 enum bt_field_variant_select_option_field_by_index_status
1159 bt_field_variant_select_option_field_by_index(
1160 struct bt_field
*field
, uint64_t index
)
1162 struct bt_field_variant
*var_field
= (void *) field
;
1164 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1165 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1166 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1167 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1168 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1169 var_field
->selected_index
= index
;
1170 return BT_FUNC_STATUS_OK
;
1173 uint64_t bt_field_variant_get_selected_option_field_index(
1174 const struct bt_field
*field
)
1176 const struct bt_field_variant
*var_field
= (const void *) field
;
1178 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1179 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1180 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1181 "Variant field has no selected field: %!+f", field
);
1182 return var_field
->selected_index
;
1186 void bt_field_finalize(struct bt_field
*field
)
1189 BT_LOGD_STR("Putting field's class.");
1190 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1194 void destroy_bool_field(struct bt_field
*field
)
1197 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1198 bt_field_finalize(field
);
1203 void destroy_bit_array_field(struct bt_field
*field
)
1206 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1207 bt_field_finalize(field
);
1212 void destroy_integer_field(struct bt_field
*field
)
1215 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1216 bt_field_finalize(field
);
1221 void destroy_real_field(struct bt_field
*field
)
1224 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1225 bt_field_finalize(field
);
1230 void destroy_structure_field(struct bt_field
*field
)
1232 struct bt_field_structure
*struct_field
= (void *) field
;
1235 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1236 bt_field_finalize(field
);
1238 if (struct_field
->fields
) {
1239 g_ptr_array_free(struct_field
->fields
, TRUE
);
1240 struct_field
->fields
= NULL
;
1247 void destroy_option_field(struct bt_field
*field
)
1249 struct bt_field_option
*opt_field
= (void *) field
;
1252 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1253 bt_field_finalize(field
);
1255 if (opt_field
->content_field
) {
1256 bt_field_destroy(opt_field
->content_field
);
1263 void destroy_variant_field(struct bt_field
*field
)
1265 struct bt_field_variant
*var_field
= (void *) field
;
1268 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1269 bt_field_finalize(field
);
1271 if (var_field
->fields
) {
1272 g_ptr_array_free(var_field
->fields
, TRUE
);
1273 var_field
->fields
= NULL
;
1280 void destroy_array_field(struct bt_field
*field
)
1282 struct bt_field_array
*array_field
= (void *) field
;
1285 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1286 bt_field_finalize(field
);
1288 if (array_field
->fields
) {
1289 g_ptr_array_free(array_field
->fields
, TRUE
);
1290 array_field
->fields
= NULL
;
1297 void destroy_string_field(struct bt_field
*field
)
1299 struct bt_field_string
*string_field
= (void *) field
;
1302 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1303 bt_field_finalize(field
);
1305 if (string_field
->buf
) {
1306 g_array_free(string_field
->buf
, TRUE
);
1307 string_field
->buf
= NULL
;
1314 void bt_field_destroy(struct bt_field
*field
)
1317 field_destroy_funcs
[field
->class->type
](field
);
1321 void reset_single_field(struct bt_field
*field
)
1324 field
->is_set
= false;
1328 void reset_structure_field(struct bt_field
*field
)
1331 struct bt_field_structure
*struct_field
= (void *) field
;
1335 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1336 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1341 void reset_option_field(struct bt_field
*field
)
1343 struct bt_field_option
*opt_field
= (void *) field
;
1345 BT_ASSERT(opt_field
);
1346 bt_field_reset(opt_field
->content_field
);
1347 opt_field
->selected_field
= NULL
;
1351 void reset_variant_field(struct bt_field
*field
)
1354 struct bt_field_variant
*var_field
= (void *) field
;
1358 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1359 bt_field_reset(var_field
->fields
->pdata
[i
]);
1364 void reset_array_field(struct bt_field
*field
)
1367 struct bt_field_array
*array_field
= (void *) field
;
1371 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1372 bt_field_reset(array_field
->fields
->pdata
[i
]);
1377 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1379 field
->frozen
= is_frozen
;
1383 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1386 struct bt_field_structure
*struct_field
= (void *) field
;
1388 BT_LIB_LOGD("Setting structure field's frozen state: "
1389 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1391 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1392 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1394 BT_LIB_LOGD("Setting structure field's member field's "
1395 "frozen state: %![field-]+f, index=%" PRIu64
,
1397 _bt_field_set_is_frozen(member_field
, is_frozen
);
1400 set_single_field_is_frozen(field
, is_frozen
);
1404 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1406 struct bt_field_option
*opt_field
= (void *) field
;
1408 BT_LIB_LOGD("Setting option field's frozen state: "
1409 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1410 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1411 set_single_field_is_frozen(field
, is_frozen
);
1415 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1418 struct bt_field_variant
*var_field
= (void *) field
;
1420 BT_LIB_LOGD("Setting variant field's frozen state: "
1421 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1423 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1424 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1426 BT_LIB_LOGD("Setting variant field's option field's "
1427 "frozen state: %![field-]+f, index=%" PRIu64
,
1429 _bt_field_set_is_frozen(option_field
, is_frozen
);
1432 set_single_field_is_frozen(field
, is_frozen
);
1436 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1439 struct bt_field_array
*array_field
= (void *) field
;
1441 BT_LIB_LOGD("Setting array field's frozen state: "
1442 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1444 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1445 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1447 BT_LIB_LOGD("Setting array field's element field's "
1448 "frozen state: %![field-]+f, index=%" PRIu64
,
1450 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1453 set_single_field_is_frozen(field
, is_frozen
);
1457 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1461 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1463 BT_ASSERT(field
->methods
->set_is_frozen
);
1464 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1468 bool single_field_is_set(const struct bt_field
*field
)
1471 return field
->is_set
;
1475 bool structure_field_is_set(const struct bt_field
*field
)
1479 const struct bt_field_structure
*struct_field
= (const void *) field
;
1483 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1484 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1495 bool option_field_is_set(const struct bt_field
*field
)
1497 const struct bt_field_option
*opt_field
= (const void *) field
;
1498 bool is_set
= false;
1502 if (opt_field
->selected_field
) {
1503 is_set
= bt_field_is_set(opt_field
->selected_field
);
1510 bool variant_field_is_set(const struct bt_field
*field
)
1512 const struct bt_field_variant
*var_field
= (const void *) field
;
1513 bool is_set
= false;
1517 if (var_field
->selected_field
) {
1518 is_set
= bt_field_is_set(var_field
->selected_field
);
1525 bool array_field_is_set(const struct bt_field
*field
)
1529 const struct bt_field_array
*array_field
= (const void *) field
;
1533 for (i
= 0; i
< array_field
->length
; i
++) {
1534 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);