2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #define BT_LOG_TAG "LIB/FIELD"
9 #include "lib/logging.h"
11 #include "lib/assert-pre.h"
12 #include <babeltrace2/trace-ir/field.h>
13 #include "lib/object.h"
14 #include "compat/compiler.h"
15 #include "compat/fcntl.h"
16 #include "common/align.h"
17 #include "common/assert.h"
22 #include "field-class.h"
23 #include "lib/func-status.h"
26 void reset_single_field(struct bt_field
*field
);
29 void reset_array_field(struct bt_field
*field
);
32 void reset_structure_field(struct bt_field
*field
);
35 void reset_option_field(struct bt_field
*field
);
38 void reset_variant_field(struct bt_field
*field
);
41 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
44 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
47 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
50 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
53 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
56 bool single_field_is_set(const struct bt_field
*field
);
59 bool array_field_is_set(const struct bt_field
*field
);
62 bool structure_field_is_set(const struct bt_field
*field
);
65 bool option_field_is_set(const struct bt_field
*field
);
68 bool variant_field_is_set(const struct bt_field
*field
);
71 struct bt_field_methods bool_field_methods
= {
72 .set_is_frozen
= set_single_field_is_frozen
,
73 .is_set
= single_field_is_set
,
74 .reset
= reset_single_field
,
78 struct bt_field_methods bit_array_field_methods
= {
79 .set_is_frozen
= set_single_field_is_frozen
,
80 .is_set
= single_field_is_set
,
81 .reset
= reset_single_field
,
85 struct bt_field_methods integer_field_methods
= {
86 .set_is_frozen
= set_single_field_is_frozen
,
87 .is_set
= single_field_is_set
,
88 .reset
= reset_single_field
,
92 struct bt_field_methods real_field_methods
= {
93 .set_is_frozen
= set_single_field_is_frozen
,
94 .is_set
= single_field_is_set
,
95 .reset
= reset_single_field
,
99 struct bt_field_methods string_field_methods
= {
100 .set_is_frozen
= set_single_field_is_frozen
,
101 .is_set
= single_field_is_set
,
102 .reset
= reset_single_field
,
106 struct bt_field_methods structure_field_methods
= {
107 .set_is_frozen
= set_structure_field_is_frozen
,
108 .is_set
= structure_field_is_set
,
109 .reset
= reset_structure_field
,
113 struct bt_field_methods array_field_methods
= {
114 .set_is_frozen
= set_array_field_is_frozen
,
115 .is_set
= array_field_is_set
,
116 .reset
= reset_array_field
,
120 struct bt_field_methods option_field_methods
= {
121 .set_is_frozen
= set_option_field_is_frozen
,
122 .is_set
= option_field_is_set
,
123 .reset
= reset_option_field
,
127 struct bt_field_methods variant_field_methods
= {
128 .set_is_frozen
= set_variant_field_is_frozen
,
129 .is_set
= variant_field_is_set
,
130 .reset
= reset_variant_field
,
134 struct bt_field
*create_bool_field(struct bt_field_class
*);
137 struct bt_field
*create_bit_array_field(struct bt_field_class
*);
140 struct bt_field
*create_integer_field(struct bt_field_class
*);
143 struct bt_field
*create_real_field(struct bt_field_class
*);
146 struct bt_field
*create_string_field(struct bt_field_class
*);
149 struct bt_field
*create_structure_field(struct bt_field_class
*);
152 struct bt_field
*create_static_array_field(struct bt_field_class
*);
155 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*);
158 struct bt_field
*create_option_field(struct bt_field_class
*);
161 struct bt_field
*create_variant_field(struct bt_field_class
*);
164 void destroy_bool_field(struct bt_field
*field
);
167 void destroy_bit_array_field(struct bt_field
*field
);
170 void destroy_integer_field(struct bt_field
*field
);
173 void destroy_real_field(struct bt_field
*field
);
176 void destroy_string_field(struct bt_field
*field
);
179 void destroy_structure_field(struct bt_field
*field
);
182 void destroy_array_field(struct bt_field
*field
);
185 void destroy_option_field(struct bt_field
*field
);
188 void destroy_variant_field(struct bt_field
*field
);
190 struct bt_field_class
*bt_field_borrow_class(struct bt_field
*field
)
192 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
196 const struct bt_field_class
*bt_field_borrow_class_const(
197 const struct bt_field
*field
)
199 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
203 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
205 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
206 return field
->class->type
;
210 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
212 struct bt_field
*field
= NULL
;
217 case BT_FIELD_CLASS_TYPE_BOOL
:
218 field
= create_bool_field(fc
);
220 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
221 field
= create_bit_array_field(fc
);
223 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
224 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
225 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
226 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
227 field
= create_integer_field(fc
);
229 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
230 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
231 field
= create_real_field(fc
);
233 case BT_FIELD_CLASS_TYPE_STRING
:
234 field
= create_string_field(fc
);
236 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
237 field
= create_structure_field(fc
);
239 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
240 field
= create_static_array_field(fc
);
242 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
243 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
244 field
= create_dynamic_array_field(fc
);
246 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
247 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
248 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
249 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
250 field
= create_option_field(fc
);
252 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
253 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
254 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
255 field
= create_variant_field(fc
);
262 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
272 void init_field(struct bt_field
*field
, struct bt_field_class
*fc
,
273 struct bt_field_methods
*methods
)
277 bt_object_init_unique(&field
->base
);
278 field
->methods
= methods
;
280 bt_object_get_ref_no_null_check(fc
);
284 struct bt_field
*create_bool_field(struct bt_field_class
*fc
)
286 struct bt_field_bool
*bool_field
;
288 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc
);
289 bool_field
= g_new0(struct bt_field_bool
, 1);
291 BT_LIB_LOGE_APPEND_CAUSE(
292 "Failed to allocate one boolean field.");
296 init_field((void *) bool_field
, fc
, &bool_field_methods
);
297 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field
);
300 return (void *) bool_field
;
304 struct bt_field
*create_bit_array_field(struct bt_field_class
*fc
)
306 struct bt_field_bit_array
*ba_field
;
308 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc
);
309 ba_field
= g_new0(struct bt_field_bit_array
, 1);
311 BT_LIB_LOGE_APPEND_CAUSE(
312 "Failed to allocate one bit array field.");
316 init_field((void *) ba_field
, fc
, &bit_array_field_methods
);
317 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field
);
320 return (void *) ba_field
;
324 struct bt_field
*create_integer_field(struct bt_field_class
*fc
)
326 struct bt_field_integer
*int_field
;
328 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc
);
329 int_field
= g_new0(struct bt_field_integer
, 1);
331 BT_LIB_LOGE_APPEND_CAUSE(
332 "Failed to allocate one integer field.");
336 init_field((void *) int_field
, fc
, &integer_field_methods
);
337 BT_LIB_LOGD("Created integer field object: %!+f", int_field
);
340 return (void *) int_field
;
344 struct bt_field
*create_real_field(struct bt_field_class
*fc
)
346 struct bt_field_real
*real_field
;
348 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc
);
349 real_field
= g_new0(struct bt_field_real
, 1);
351 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
355 init_field((void *) real_field
, fc
, &real_field_methods
);
356 BT_LIB_LOGD("Created real field object: %!+f", real_field
);
359 return (void *) real_field
;
363 struct bt_field
*create_string_field(struct bt_field_class
*fc
)
365 struct bt_field_string
*string_field
;
367 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc
);
368 string_field
= g_new0(struct bt_field_string
, 1);
370 BT_LIB_LOGE_APPEND_CAUSE(
371 "Failed to allocate one string field.");
375 init_field((void *) string_field
, fc
, &string_field_methods
);
376 string_field
->buf
= g_array_sized_new(FALSE
, FALSE
,
378 if (!string_field
->buf
) {
379 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
380 bt_field_destroy((void *) string_field
);
385 g_array_index(string_field
->buf
, char, 0) = '\0';
386 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
389 return (void *) string_field
;
393 int create_fields_from_named_field_classes(
394 struct bt_field_class_named_field_class_container
*fc
,
400 *fields
= g_ptr_array_new_with_free_func(
401 (GDestroyNotify
) bt_field_destroy
);
403 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
408 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
410 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
411 struct bt_field
*field
;
412 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
414 field
= bt_field_create(named_fc
->fc
);
416 BT_LIB_LOGE_APPEND_CAUSE(
417 "Failed to create structure member or variant option field: "
418 "name=\"%s\", %![fc-]+F",
419 named_fc
->name
->str
, named_fc
->fc
);
424 g_ptr_array_index(*fields
, i
) = field
;
432 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
434 struct bt_field_structure
*struct_field
;
436 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
437 struct_field
= g_new0(struct bt_field_structure
, 1);
439 BT_LIB_LOGE_APPEND_CAUSE(
440 "Failed to allocate one structure field.");
444 init_field((void *) struct_field
, fc
, &structure_field_methods
);
446 if (create_fields_from_named_field_classes((void *) fc
,
447 &struct_field
->fields
)) {
448 BT_LIB_LOGE_APPEND_CAUSE(
449 "Cannot create structure member fields: %![fc-]+F", fc
);
450 bt_field_destroy((void *) struct_field
);
455 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
458 return (void *) struct_field
;
462 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
464 struct bt_field_option
*opt_field
;
465 struct bt_field_class_option
*opt_fc
= (void *) fc
;
467 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
468 opt_field
= g_new0(struct bt_field_option
, 1);
470 BT_LIB_LOGE_APPEND_CAUSE(
471 "Failed to allocate one option field.");
475 init_field((void *) opt_field
, fc
, &option_field_methods
);
476 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
477 if (!opt_field
->content_field
) {
478 BT_LIB_LOGE_APPEND_CAUSE(
479 "Failed to create option field's content field: "
480 "%![opt-fc-]+F, %![content-fc-]+F",
481 opt_fc
, opt_fc
->content_fc
);
482 bt_field_destroy((void *) opt_field
);
487 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
490 return (void *) opt_field
;
494 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
496 struct bt_field_variant
*var_field
;
498 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
499 var_field
= g_new0(struct bt_field_variant
, 1);
501 BT_LIB_LOGE_APPEND_CAUSE(
502 "Failed to allocate one variant field.");
506 init_field((void *) var_field
, fc
, &variant_field_methods
);
508 if (create_fields_from_named_field_classes((void *) fc
,
509 &var_field
->fields
)) {
510 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
512 bt_field_destroy((void *) var_field
);
517 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
520 return (void *) var_field
;
524 int init_array_field_fields(struct bt_field_array
*array_field
)
528 struct bt_field_class_array
*array_fc
;
530 BT_ASSERT(array_field
);
531 array_fc
= (void *) array_field
->common
.class;
532 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
533 if (!array_field
->fields
) {
534 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
539 g_ptr_array_set_free_func(array_field
->fields
,
540 (GDestroyNotify
) bt_field_destroy
);
541 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
543 for (i
= 0; i
< array_field
->length
; i
++) {
544 array_field
->fields
->pdata
[i
] = bt_field_create(
545 array_fc
->element_fc
);
546 if (!array_field
->fields
->pdata
[i
]) {
547 BT_LIB_LOGE_APPEND_CAUSE(
548 "Cannot create array field's element field: "
549 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
560 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
562 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
563 struct bt_field_array
*array_field
;
565 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
566 array_field
= g_new0(struct bt_field_array
, 1);
568 BT_LIB_LOGE_APPEND_CAUSE(
569 "Failed to allocate one static array field.");
573 init_field((void *) array_field
, fc
, &array_field_methods
);
574 array_field
->length
= array_fc
->length
;
576 if (init_array_field_fields(array_field
)) {
577 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
579 bt_field_destroy((void *) array_field
);
584 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
587 return (void *) array_field
;
591 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
593 struct bt_field_array
*array_field
;
595 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
596 array_field
= g_new0(struct bt_field_array
, 1);
598 BT_LIB_LOGE_APPEND_CAUSE(
599 "Failed to allocate one dynamic array field.");
603 init_field((void *) array_field
, fc
, &array_field_methods
);
605 if (init_array_field_fields(array_field
)) {
606 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
608 bt_field_destroy((void *) array_field
);
613 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
616 return (void *) array_field
;
619 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
621 const struct bt_field_bool
*bool_field
= (const void *) field
;
623 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
624 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
625 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
627 return (bt_bool
) bool_field
->value
;
630 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
632 struct bt_field_bool
*bool_field
= (void *) field
;
634 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
635 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
637 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
638 bool_field
->value
= (bool) value
;
639 bt_field_set_single(field
, true);
642 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
644 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
646 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
647 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
648 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
649 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
650 return ba_field
->value_as_int
;
653 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
656 struct bt_field_bit_array
*ba_field
= (void *) field
;
657 struct bt_field_class_bit_array
*ba_fc
;
659 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
660 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
661 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
662 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
663 ba_fc
= (void *) field
->class;
664 ba_field
->value_as_int
= value
;
666 if (ba_fc
->length
< 64) {
668 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
671 bt_field_set_single(field
, true);
674 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
676 const struct bt_field_integer
*int_field
= (const void *) field
;
678 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
679 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
680 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
681 return int_field
->value
.i
;
684 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
686 struct bt_field_integer
*int_field
= (void *) field
;
688 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
689 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
690 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
691 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
692 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
693 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
694 "%![fc-]+F", value
, field
, field
->class);
695 int_field
->value
.i
= value
;
696 bt_field_set_single(field
, true);
699 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
701 const struct bt_field_integer
*int_field
= (const void *) field
;
703 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
704 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
705 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
706 return int_field
->value
.u
;
709 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
711 struct bt_field_integer
*int_field
= (void *) field
;
713 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
714 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
715 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
716 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
717 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
718 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
719 "%![fc-]+F", value
, field
, field
->class);
720 int_field
->value
.u
= value
;
721 bt_field_set_single(field
, true);
724 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
726 const struct bt_field_real
*real_field
= (const void *) field
;
728 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
729 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
730 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
731 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
732 return (float) real_field
->value
;
735 double bt_field_real_double_precision_get_value(const struct bt_field
*field
)
737 const struct bt_field_real
*real_field
= (const void *) field
;
739 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
740 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
741 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
742 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
744 return real_field
->value
;
747 void bt_field_real_single_precision_set_value(struct bt_field
*field
,
750 struct bt_field_real
*real_field
= (void *) field
;
752 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
753 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
754 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
755 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
757 real_field
->value
= (double) value
;
758 bt_field_set_single(field
, true);
761 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
764 struct bt_field_real
*real_field
= (void *) field
;
766 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
767 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
768 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
769 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
771 real_field
->value
= value
;
772 bt_field_set_single(field
, true);
775 enum bt_field_enumeration_get_mapping_labels_status
776 bt_field_enumeration_unsigned_get_mapping_labels(
777 const struct bt_field
*field
,
778 bt_field_class_enumeration_mapping_label_array
*label_array
,
781 const struct bt_field_integer
*int_field
= (const void *) field
;
783 BT_ASSERT_PRE_DEV_NO_ERROR();
784 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
785 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
786 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
787 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
788 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
789 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
791 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
792 field
->class, int_field
->value
.u
, label_array
, count
);
795 enum bt_field_enumeration_get_mapping_labels_status
796 bt_field_enumeration_signed_get_mapping_labels(
797 const struct bt_field
*field
,
798 bt_field_class_enumeration_mapping_label_array
*label_array
,
801 const struct bt_field_integer
*int_field
= (const void *) field
;
803 BT_ASSERT_PRE_DEV_NO_ERROR();
804 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
805 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
806 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
807 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
808 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
809 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
811 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
812 field
->class, int_field
->value
.i
, label_array
, count
);
815 const char *bt_field_string_get_value(const struct bt_field
*field
)
817 const struct bt_field_string
*string_field
= (const void *) field
;
819 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
820 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
821 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
823 return (const char *) string_field
->buf
->data
;
826 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
828 const struct bt_field_string
*string_field
= (const void *) field
;
830 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
831 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
832 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
834 return string_field
->length
;
838 void clear_string_field(struct bt_field
*field
)
840 struct bt_field_string
*string_field
= (void *) field
;
842 BT_ASSERT_DBG(field
);
843 string_field
->length
= 0;
844 bt_field_set_single(field
, true);
847 enum bt_field_string_set_value_status
bt_field_string_set_value(
848 struct bt_field
*field
, const char *value
)
850 BT_ASSERT_PRE_DEV_NO_ERROR();
851 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
852 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
853 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
854 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
856 clear_string_field(field
);
857 return (int) bt_field_string_append_with_length(field
, value
,
858 (uint64_t) strlen(value
));
861 enum bt_field_string_append_status
bt_field_string_append(
862 struct bt_field
*field
, const char *value
)
864 BT_ASSERT_PRE_DEV_NO_ERROR();
866 return bt_field_string_append_with_length(field
,
867 value
, (uint64_t) strlen(value
));
870 enum bt_field_string_append_status
bt_field_string_append_with_length(
871 struct bt_field
*field
, const char *value
, uint64_t length
)
873 struct bt_field_string
*string_field
= (void *) field
;
877 BT_ASSERT_PRE_DEV_NO_ERROR();
878 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
879 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
880 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
881 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
882 BT_FIELD_CLASS_TYPE_STRING
, "Field");
884 /* Make sure no null bytes are appended */
885 BT_ASSERT_PRE_DEV(!memchr(value
, '\0', length
),
886 "String value to append contains a null character: "
887 "partial-value=\"%.32s\", length=%" PRIu64
, value
, length
);
889 new_length
= length
+ string_field
->length
;
891 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
892 g_array_set_size(string_field
->buf
, new_length
+ 1);
895 data
= string_field
->buf
->data
;
896 memcpy(data
+ string_field
->length
, value
, length
);
897 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
898 string_field
->length
= new_length
;
899 bt_field_set_single(field
, true);
900 return BT_FUNC_STATUS_OK
;
903 void bt_field_string_clear(struct bt_field
*field
)
905 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
906 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
907 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
908 BT_FIELD_CLASS_TYPE_STRING
, "Field");
909 clear_string_field(field
);
912 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
914 const struct bt_field_array
*array_field
= (const void *) field
;
916 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
917 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
918 return array_field
->length
;
921 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
922 struct bt_field
*field
, uint64_t length
)
924 int ret
= BT_FUNC_STATUS_OK
;
925 struct bt_field_array
*array_field
= (void *) field
;
927 BT_ASSERT_PRE_DEV_NO_ERROR();
928 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
929 BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(field
, "Field");
930 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
932 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
934 struct bt_field_class_array
*array_fc
;
935 uint64_t cur_len
= array_field
->fields
->len
;
938 g_ptr_array_set_size(array_field
->fields
, length
);
939 array_fc
= (void *) field
->class;
941 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
942 struct bt_field
*elem_field
= bt_field_create(
943 array_fc
->element_fc
);
946 BT_LIB_LOGE_APPEND_CAUSE(
947 "Cannot create element field for "
948 "dynamic array field: "
949 "index=%" PRIu64
", "
950 "%![array-field-]+f", i
, field
);
951 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
955 BT_ASSERT_DBG(!array_field
->fields
->pdata
[i
]);
956 array_field
->fields
->pdata
[i
] = elem_field
;
960 array_field
->length
= length
;
967 struct bt_field
*borrow_array_field_element_field_by_index(
968 struct bt_field
*field
, uint64_t index
)
970 struct bt_field_array
*array_field
= (void *) field
;
972 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
973 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
974 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, array_field
->length
);
975 return array_field
->fields
->pdata
[index
];
978 struct bt_field
*bt_field_array_borrow_element_field_by_index(
979 struct bt_field
*field
, uint64_t index
)
981 return borrow_array_field_element_field_by_index(field
, index
);
984 const struct bt_field
*
985 bt_field_array_borrow_element_field_by_index_const(
986 const struct bt_field
*field
, uint64_t index
)
988 return borrow_array_field_element_field_by_index((void *) field
, index
);
992 struct bt_field
*borrow_structure_field_member_field_by_index(
993 struct bt_field
*field
, uint64_t index
)
995 struct bt_field_structure
*struct_field
= (void *) field
;
997 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
998 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
999 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1000 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, struct_field
->fields
->len
);
1001 return struct_field
->fields
->pdata
[index
];
1004 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1005 struct bt_field
*field
, uint64_t index
)
1007 return borrow_structure_field_member_field_by_index(field
,
1011 const struct bt_field
*
1012 bt_field_structure_borrow_member_field_by_index_const(
1013 const struct bt_field
*field
, uint64_t index
)
1015 return borrow_structure_field_member_field_by_index(
1016 (void *) field
, index
);
1020 struct bt_field
*borrow_structure_field_member_field_by_name(
1021 struct bt_field
*field
, const char *name
)
1023 struct bt_field
*ret_field
= NULL
;
1024 struct bt_field_class_structure
*struct_fc
;
1025 struct bt_field_structure
*struct_field
= (void *) field
;
1029 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1030 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Field name");
1031 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1032 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1033 struct_fc
= (void *) field
->class;
1035 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1036 &orig_key
, &index
)) {
1040 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1041 BT_ASSERT_DBG(ret_field
);
1047 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1048 struct bt_field
*field
, const char *name
)
1050 return borrow_structure_field_member_field_by_name(field
, name
);
1053 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1054 const struct bt_field
*field
, const char *name
)
1056 return borrow_structure_field_member_field_by_name(
1057 (void *) field
, name
);
1060 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1062 struct bt_field_option
*opt_field
= (void *) field
;
1064 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1065 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "Field");
1066 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1069 opt_field
->selected_field
= opt_field
->content_field
;
1071 opt_field
->selected_field
= NULL
;
1075 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1077 struct bt_field_option
*opt_field
= (void *) field
;
1079 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1080 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "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
;
1122 BT_ASSERT_DBG(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_option_class_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_field_integer_unsigned_option
*
1139 bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_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_INTEGER_SELECTOR_FIELD
, "Field");
1145 return (const void *) borrow_variant_field_selected_class_option(field
);
1148 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1149 bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_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_INTEGER_SELECTOR_FIELD
, "Field");
1155 return (const void *) borrow_variant_field_selected_class_option(field
);
1158 enum bt_field_variant_select_option_by_index_status
1159 bt_field_variant_select_option_by_index(
1160 struct bt_field
*field
, uint64_t index
)
1162 struct bt_field_variant
*var_field
= (void *) field
;
1164 BT_ASSERT_PRE_DEV_NO_ERROR();
1165 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1166 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1167 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1168 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1169 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1170 var_field
->selected_index
= index
;
1171 return BT_FUNC_STATUS_OK
;
1174 uint64_t bt_field_variant_get_selected_option_index(
1175 const struct bt_field
*field
)
1177 const struct bt_field_variant
*var_field
= (const void *) field
;
1179 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1180 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1181 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1182 "Variant field has no selected field: %!+f", field
);
1183 return var_field
->selected_index
;
1187 void bt_field_finalize(struct bt_field
*field
)
1190 BT_LOGD_STR("Putting field's class.");
1191 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1195 void destroy_bool_field(struct bt_field
*field
)
1198 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1199 bt_field_finalize(field
);
1204 void destroy_bit_array_field(struct bt_field
*field
)
1207 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1208 bt_field_finalize(field
);
1213 void destroy_integer_field(struct bt_field
*field
)
1216 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1217 bt_field_finalize(field
);
1222 void destroy_real_field(struct bt_field
*field
)
1225 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1226 bt_field_finalize(field
);
1231 void destroy_structure_field(struct bt_field
*field
)
1233 struct bt_field_structure
*struct_field
= (void *) field
;
1236 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1237 bt_field_finalize(field
);
1239 if (struct_field
->fields
) {
1240 g_ptr_array_free(struct_field
->fields
, TRUE
);
1241 struct_field
->fields
= NULL
;
1248 void destroy_option_field(struct bt_field
*field
)
1250 struct bt_field_option
*opt_field
= (void *) field
;
1253 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1254 bt_field_finalize(field
);
1256 if (opt_field
->content_field
) {
1257 bt_field_destroy(opt_field
->content_field
);
1264 void destroy_variant_field(struct bt_field
*field
)
1266 struct bt_field_variant
*var_field
= (void *) field
;
1269 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1270 bt_field_finalize(field
);
1272 if (var_field
->fields
) {
1273 g_ptr_array_free(var_field
->fields
, TRUE
);
1274 var_field
->fields
= NULL
;
1281 void destroy_array_field(struct bt_field
*field
)
1283 struct bt_field_array
*array_field
= (void *) field
;
1286 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1287 bt_field_finalize(field
);
1289 if (array_field
->fields
) {
1290 g_ptr_array_free(array_field
->fields
, TRUE
);
1291 array_field
->fields
= NULL
;
1298 void destroy_string_field(struct bt_field
*field
)
1300 struct bt_field_string
*string_field
= (void *) field
;
1303 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1304 bt_field_finalize(field
);
1306 if (string_field
->buf
) {
1307 g_array_free(string_field
->buf
, TRUE
);
1308 string_field
->buf
= NULL
;
1315 void bt_field_destroy(struct bt_field
*field
)
1319 switch (field
->class->type
) {
1320 case BT_FIELD_CLASS_TYPE_BOOL
:
1321 destroy_bool_field(field
);
1323 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
1324 destroy_bit_array_field(field
);
1326 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1327 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1328 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1329 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1330 destroy_integer_field(field
);
1332 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
1333 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
1334 destroy_real_field(field
);
1336 case BT_FIELD_CLASS_TYPE_STRING
:
1337 destroy_string_field(field
);
1339 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1340 destroy_structure_field(field
);
1342 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1343 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
1344 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
1345 destroy_array_field(field
);
1347 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
1348 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
1349 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1350 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1351 destroy_option_field(field
);
1353 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
1354 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1355 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1356 destroy_variant_field(field
);
1364 void reset_single_field(struct bt_field
*field
)
1366 BT_ASSERT_DBG(field
);
1367 field
->is_set
= false;
1371 void reset_structure_field(struct bt_field
*field
)
1374 struct bt_field_structure
*struct_field
= (void *) field
;
1376 BT_ASSERT_DBG(field
);
1378 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1379 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1384 void reset_option_field(struct bt_field
*field
)
1386 struct bt_field_option
*opt_field
= (void *) field
;
1388 BT_ASSERT_DBG(opt_field
);
1389 bt_field_reset(opt_field
->content_field
);
1390 opt_field
->selected_field
= NULL
;
1394 void reset_variant_field(struct bt_field
*field
)
1397 struct bt_field_variant
*var_field
= (void *) field
;
1399 BT_ASSERT_DBG(field
);
1401 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1402 bt_field_reset(var_field
->fields
->pdata
[i
]);
1407 void reset_array_field(struct bt_field
*field
)
1410 struct bt_field_array
*array_field
= (void *) field
;
1412 BT_ASSERT_DBG(field
);
1414 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1415 bt_field_reset(array_field
->fields
->pdata
[i
]);
1420 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1422 field
->frozen
= is_frozen
;
1426 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1429 struct bt_field_structure
*struct_field
= (void *) field
;
1431 BT_LIB_LOGD("Setting structure field's frozen state: "
1432 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1434 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1435 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1437 BT_LIB_LOGD("Setting structure field's member field's "
1438 "frozen state: %![field-]+f, index=%" PRIu64
,
1440 _bt_field_set_is_frozen(member_field
, is_frozen
);
1443 set_single_field_is_frozen(field
, is_frozen
);
1447 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1449 struct bt_field_option
*opt_field
= (void *) field
;
1451 BT_LIB_LOGD("Setting option field's frozen state: "
1452 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1453 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1454 set_single_field_is_frozen(field
, is_frozen
);
1458 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1461 struct bt_field_variant
*var_field
= (void *) field
;
1463 BT_LIB_LOGD("Setting variant field's frozen state: "
1464 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1466 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1467 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1469 BT_LIB_LOGD("Setting variant field's option field's "
1470 "frozen state: %![field-]+f, index=%" PRIu64
,
1472 _bt_field_set_is_frozen(option_field
, is_frozen
);
1475 set_single_field_is_frozen(field
, is_frozen
);
1479 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1482 struct bt_field_array
*array_field
= (void *) field
;
1484 BT_LIB_LOGD("Setting array field's frozen state: "
1485 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1487 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1488 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1490 BT_LIB_LOGD("Setting array field's element field's "
1491 "frozen state: %![field-]+f, index=%" PRIu64
,
1493 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1496 set_single_field_is_frozen(field
, is_frozen
);
1500 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1503 BT_ASSERT_DBG(field
);
1504 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1506 BT_ASSERT_DBG(field
->methods
->set_is_frozen
);
1507 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1511 bool single_field_is_set(const struct bt_field
*field
)
1513 BT_ASSERT_DBG(field
);
1514 return field
->is_set
;
1518 bool structure_field_is_set(const struct bt_field
*field
)
1522 const struct bt_field_structure
*struct_field
= (const void *) field
;
1524 BT_ASSERT_DBG(field
);
1526 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1527 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1538 bool option_field_is_set(const struct bt_field
*field
)
1540 const struct bt_field_option
*opt_field
= (const void *) field
;
1541 bool is_set
= false;
1543 BT_ASSERT_DBG(field
);
1545 if (opt_field
->selected_field
) {
1546 is_set
= bt_field_is_set(opt_field
->selected_field
);
1553 bool variant_field_is_set(const struct bt_field
*field
)
1555 const struct bt_field_variant
*var_field
= (const void *) field
;
1556 bool is_set
= false;
1558 BT_ASSERT_DBG(field
);
1560 if (var_field
->selected_field
) {
1561 is_set
= bt_field_is_set(var_field
->selected_field
);
1568 bool array_field_is_set(const struct bt_field
*field
)
1572 const struct bt_field_array
*array_field
= (const void *) field
;
1574 BT_ASSERT_DBG(field
);
1576 for (i
= 0; i
< array_field
->length
; i
++) {
1577 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);