2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "LIB/FIELD"
25 #include "lib/logging.h"
27 #include "lib/assert-pre.h"
28 #include <babeltrace2/trace-ir/field.h>
29 #include <babeltrace2/trace-ir/field-const.h>
30 #include "lib/object.h"
31 #include "compat/compiler.h"
32 #include "compat/fcntl.h"
33 #include "common/align.h"
34 #include "common/assert.h"
38 #include "field-class.h"
39 #include "lib/func-status.h"
42 void reset_single_field(struct bt_field
*field
);
45 void reset_array_field(struct bt_field
*field
);
48 void reset_structure_field(struct bt_field
*field
);
51 void reset_option_field(struct bt_field
*field
);
54 void reset_variant_field(struct bt_field
*field
);
57 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
60 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
63 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
66 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
69 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
72 bool single_field_is_set(const struct bt_field
*field
);
75 bool array_field_is_set(const struct bt_field
*field
);
78 bool structure_field_is_set(const struct bt_field
*field
);
81 bool option_field_is_set(const struct bt_field
*field
);
84 bool variant_field_is_set(const struct bt_field
*field
);
87 struct bt_field_methods bool_field_methods
= {
88 .set_is_frozen
= set_single_field_is_frozen
,
89 .is_set
= single_field_is_set
,
90 .reset
= reset_single_field
,
94 struct bt_field_methods bit_array_field_methods
= {
95 .set_is_frozen
= set_single_field_is_frozen
,
96 .is_set
= single_field_is_set
,
97 .reset
= reset_single_field
,
101 struct bt_field_methods integer_field_methods
= {
102 .set_is_frozen
= set_single_field_is_frozen
,
103 .is_set
= single_field_is_set
,
104 .reset
= reset_single_field
,
108 struct bt_field_methods real_field_methods
= {
109 .set_is_frozen
= set_single_field_is_frozen
,
110 .is_set
= single_field_is_set
,
111 .reset
= reset_single_field
,
115 struct bt_field_methods string_field_methods
= {
116 .set_is_frozen
= set_single_field_is_frozen
,
117 .is_set
= single_field_is_set
,
118 .reset
= reset_single_field
,
122 struct bt_field_methods structure_field_methods
= {
123 .set_is_frozen
= set_structure_field_is_frozen
,
124 .is_set
= structure_field_is_set
,
125 .reset
= reset_structure_field
,
129 struct bt_field_methods array_field_methods
= {
130 .set_is_frozen
= set_array_field_is_frozen
,
131 .is_set
= array_field_is_set
,
132 .reset
= reset_array_field
,
136 struct bt_field_methods option_field_methods
= {
137 .set_is_frozen
= set_option_field_is_frozen
,
138 .is_set
= option_field_is_set
,
139 .reset
= reset_option_field
,
143 struct bt_field_methods variant_field_methods
= {
144 .set_is_frozen
= set_variant_field_is_frozen
,
145 .is_set
= variant_field_is_set
,
146 .reset
= reset_variant_field
,
150 struct bt_field
*create_bool_field(struct bt_field_class
*);
153 struct bt_field
*create_bit_array_field(struct bt_field_class
*);
156 struct bt_field
*create_integer_field(struct bt_field_class
*);
159 struct bt_field
*create_real_field(struct bt_field_class
*);
162 struct bt_field
*create_string_field(struct bt_field_class
*);
165 struct bt_field
*create_structure_field(struct bt_field_class
*);
168 struct bt_field
*create_static_array_field(struct bt_field_class
*);
171 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*);
174 struct bt_field
*create_option_field(struct bt_field_class
*);
177 struct bt_field
*create_variant_field(struct bt_field_class
*);
180 struct bt_field
*(* const field_create_funcs
[])(struct bt_field_class
*) = {
181 [BT_FIELD_CLASS_TYPE_BOOL
] = create_bool_field
,
182 [BT_FIELD_CLASS_TYPE_BIT_ARRAY
] = create_bit_array_field
,
183 [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
] = create_integer_field
,
184 [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
] = create_integer_field
,
185 [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
] = create_integer_field
,
186 [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
] = create_integer_field
,
187 [BT_FIELD_CLASS_TYPE_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_REAL
] = destroy_real_field
,
234 [BT_FIELD_CLASS_TYPE_STRING
] = destroy_string_field
,
235 [BT_FIELD_CLASS_TYPE_STRUCTURE
] = destroy_structure_field
,
236 [BT_FIELD_CLASS_TYPE_STATIC_ARRAY
] = destroy_array_field
,
237 [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
] = destroy_array_field
,
238 [BT_FIELD_CLASS_TYPE_OPTION
] = destroy_option_field
,
239 [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
] = destroy_variant_field
,
240 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
] = destroy_variant_field
,
241 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
] = destroy_variant_field
,
244 struct bt_field_class
*bt_field_borrow_class(const struct bt_field
*field
)
246 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
250 const struct bt_field_class
*bt_field_borrow_class_const(
251 const struct bt_field
*field
)
253 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
257 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
259 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
260 return field
->class->type
;
264 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
266 struct bt_field
*field
= NULL
;
269 field
= field_create_funcs
[fc
->type
](fc
);
271 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
281 void init_field(struct bt_field
*field
, struct bt_field_class
*fc
,
282 struct bt_field_methods
*methods
)
286 bt_object_init_unique(&field
->base
);
287 field
->methods
= methods
;
289 bt_object_get_no_null_check(fc
);
293 struct bt_field
*create_bool_field(struct bt_field_class
*fc
)
295 struct bt_field_bool
*bool_field
;
297 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc
);
298 bool_field
= g_new0(struct bt_field_bool
, 1);
300 BT_LIB_LOGE_APPEND_CAUSE(
301 "Failed to allocate one boolean field.");
305 init_field((void *) bool_field
, fc
, &bool_field_methods
);
306 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field
);
309 return (void *) bool_field
;
313 struct bt_field
*create_bit_array_field(struct bt_field_class
*fc
)
315 struct bt_field_bit_array
*ba_field
;
317 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc
);
318 ba_field
= g_new0(struct bt_field_bit_array
, 1);
320 BT_LIB_LOGE_APPEND_CAUSE(
321 "Failed to allocate one bit array field.");
325 init_field((void *) ba_field
, fc
, &bit_array_field_methods
);
326 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field
);
329 return (void *) ba_field
;
333 struct bt_field
*create_integer_field(struct bt_field_class
*fc
)
335 struct bt_field_integer
*int_field
;
337 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc
);
338 int_field
= g_new0(struct bt_field_integer
, 1);
340 BT_LIB_LOGE_APPEND_CAUSE(
341 "Failed to allocate one integer field.");
345 init_field((void *) int_field
, fc
, &integer_field_methods
);
346 BT_LIB_LOGD("Created integer field object: %!+f", int_field
);
349 return (void *) int_field
;
353 struct bt_field
*create_real_field(struct bt_field_class
*fc
)
355 struct bt_field_real
*real_field
;
357 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc
);
358 real_field
= g_new0(struct bt_field_real
, 1);
360 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
364 init_field((void *) real_field
, fc
, &real_field_methods
);
365 BT_LIB_LOGD("Created real field object: %!+f", real_field
);
368 return (void *) real_field
;
372 struct bt_field
*create_string_field(struct bt_field_class
*fc
)
374 struct bt_field_string
*string_field
;
376 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc
);
377 string_field
= g_new0(struct bt_field_string
, 1);
379 BT_LIB_LOGE_APPEND_CAUSE(
380 "Failed to allocate one string field.");
384 init_field((void *) string_field
, fc
, &string_field_methods
);
385 string_field
->buf
= g_array_sized_new(FALSE
, FALSE
,
387 if (!string_field
->buf
) {
388 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
389 BT_OBJECT_PUT_REF_AND_RESET(string_field
);
393 g_array_index(string_field
->buf
, char, 0) = '\0';
394 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
397 return (void *) string_field
;
401 int create_fields_from_named_field_classes(
402 struct bt_field_class_named_field_class_container
*fc
,
408 *fields
= g_ptr_array_new_with_free_func(
409 (GDestroyNotify
) bt_field_destroy
);
411 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
416 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
418 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
419 struct bt_field
*field
;
420 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
422 field
= bt_field_create(named_fc
->fc
);
424 BT_LIB_LOGE_APPEND_CAUSE(
425 "Failed to create structure member or variant option field: "
426 "name=\"%s\", %![fc-]+F",
427 named_fc
->name
->str
, named_fc
->fc
);
432 g_ptr_array_index(*fields
, i
) = field
;
440 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
442 struct bt_field_structure
*struct_field
;
444 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
445 struct_field
= g_new0(struct bt_field_structure
, 1);
447 BT_LIB_LOGE_APPEND_CAUSE(
448 "Failed to allocate one structure field.");
452 init_field((void *) struct_field
, fc
, &structure_field_methods
);
454 if (create_fields_from_named_field_classes((void *) fc
,
455 &struct_field
->fields
)) {
456 BT_LIB_LOGE_APPEND_CAUSE(
457 "Cannot create structure member fields: %![fc-]+F", fc
);
458 BT_OBJECT_PUT_REF_AND_RESET(struct_field
);
462 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
465 return (void *) struct_field
;
469 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
471 struct bt_field_option
*opt_field
;
472 struct bt_field_class_option
*opt_fc
= (void *) fc
;
474 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
475 opt_field
= g_new0(struct bt_field_option
, 1);
477 BT_LIB_LOGE_APPEND_CAUSE(
478 "Failed to allocate one option field.");
482 init_field((void *) opt_field
, fc
, &option_field_methods
);
483 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
484 if (!opt_field
->content_field
) {
485 BT_LIB_LOGE_APPEND_CAUSE(
486 "Failed to create option field's content field: "
487 "%![opt-fc-]+F, %![content-fc-]+F",
488 opt_fc
, opt_fc
->content_fc
);
489 BT_OBJECT_PUT_REF_AND_RESET(opt_field
);
493 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
496 return (void *) opt_field
;
500 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
502 struct bt_field_variant
*var_field
;
504 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
505 var_field
= g_new0(struct bt_field_variant
, 1);
507 BT_LIB_LOGE_APPEND_CAUSE(
508 "Failed to allocate one variant field.");
512 init_field((void *) var_field
, fc
, &variant_field_methods
);
514 if (create_fields_from_named_field_classes((void *) fc
,
515 &var_field
->fields
)) {
516 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
518 BT_OBJECT_PUT_REF_AND_RESET(var_field
);
522 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
525 return (void *) var_field
;
529 int init_array_field_fields(struct bt_field_array
*array_field
)
533 struct bt_field_class_array
*array_fc
;
535 BT_ASSERT(array_field
);
536 array_fc
= (void *) array_field
->common
.class;
537 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
538 if (!array_field
->fields
) {
539 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
544 g_ptr_array_set_free_func(array_field
->fields
,
545 (GDestroyNotify
) bt_field_destroy
);
546 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
548 for (i
= 0; i
< array_field
->length
; i
++) {
549 array_field
->fields
->pdata
[i
] = bt_field_create(
550 array_fc
->element_fc
);
551 if (!array_field
->fields
->pdata
[i
]) {
552 BT_LIB_LOGE_APPEND_CAUSE(
553 "Cannot create array field's element field: "
554 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
565 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
567 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
568 struct bt_field_array
*array_field
;
570 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
571 array_field
= g_new0(struct bt_field_array
, 1);
573 BT_LIB_LOGE_APPEND_CAUSE(
574 "Failed to allocate one static array field.");
578 init_field((void *) array_field
, fc
, &array_field_methods
);
579 array_field
->length
= array_fc
->length
;
581 if (init_array_field_fields(array_field
)) {
582 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
584 BT_OBJECT_PUT_REF_AND_RESET(array_field
);
588 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
591 return (void *) array_field
;
595 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
597 struct bt_field_array
*array_field
;
599 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
600 array_field
= g_new0(struct bt_field_array
, 1);
602 BT_LIB_LOGE_APPEND_CAUSE(
603 "Failed to allocate one dynamic array field.");
607 init_field((void *) array_field
, fc
, &array_field_methods
);
609 if (init_array_field_fields(array_field
)) {
610 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
612 BT_OBJECT_PUT_REF_AND_RESET(array_field
);
616 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
619 return (void *) array_field
;
622 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
624 const struct bt_field_bool
*bool_field
= (const void *) field
;
626 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
627 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
628 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
630 return (bt_bool
) bool_field
->value
;
633 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
635 struct bt_field_bool
*bool_field
= (void *) field
;
637 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
638 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
640 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
641 bool_field
->value
= (bool) value
;
642 bt_field_set_single(field
, true);
645 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
647 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
649 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
650 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
651 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
652 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
653 return ba_field
->value_as_int
;
656 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
659 struct bt_field_bit_array
*ba_field
= (void *) field
;
660 struct bt_field_class_bit_array
*ba_fc
;
662 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
663 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
664 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
665 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
666 ba_fc
= (void *) field
->class;
667 ba_field
->value_as_int
= value
;
669 if (ba_fc
->length
< 64) {
671 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
674 bt_field_set_single(field
, true);
677 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
679 const struct bt_field_integer
*int_field
= (const void *) field
;
681 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
682 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
683 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
684 return int_field
->value
.i
;
687 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
689 struct bt_field_integer
*int_field
= (void *) field
;
691 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
692 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
693 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
694 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
695 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
696 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
697 "%![fc-]+F", value
, field
, field
->class);
698 int_field
->value
.i
= value
;
699 bt_field_set_single(field
, true);
702 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
704 const struct bt_field_integer
*int_field
= (const void *) field
;
706 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
707 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
708 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
709 return int_field
->value
.u
;
712 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
714 struct bt_field_integer
*int_field
= (void *) field
;
716 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
717 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
718 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
719 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
720 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
721 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
722 "%![fc-]+F", value
, field
, field
->class);
723 int_field
->value
.u
= value
;
724 bt_field_set_single(field
, true);
727 double bt_field_real_get_value(const struct bt_field
*field
)
729 const struct bt_field_real
*real_field
= (const void *) field
;
731 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
732 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
733 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_REAL
, "Field");
734 return real_field
->value
;
737 void bt_field_real_set_value(struct bt_field
*field
, double value
)
739 struct bt_field_real
*real_field
= (void *) field
;
741 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
742 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_REAL
, "Field");
743 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
745 !((struct bt_field_class_real
*) field
->class)->is_single_precision
||
746 (double) (float) value
== value
,
747 "Invalid value for a single-precision real number: value=%f, "
748 "%![fc-]+F", value
, field
->class);
749 real_field
->value
= value
;
750 bt_field_set_single(field
, true);
753 enum bt_field_enumeration_get_mapping_labels_status
754 bt_field_enumeration_unsigned_get_mapping_labels(
755 const struct bt_field
*field
,
756 bt_field_class_enumeration_mapping_label_array
*label_array
,
759 const struct bt_field_integer
*int_field
= (const void *) field
;
761 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
762 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
763 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
764 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
765 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
766 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
768 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
769 field
->class, int_field
->value
.u
, label_array
, count
);
772 enum bt_field_enumeration_get_mapping_labels_status
773 bt_field_enumeration_signed_get_mapping_labels(
774 const struct bt_field
*field
,
775 bt_field_class_enumeration_mapping_label_array
*label_array
,
778 const struct bt_field_integer
*int_field
= (const void *) field
;
780 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
781 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
782 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
783 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
784 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
785 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
787 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
788 field
->class, int_field
->value
.i
, label_array
, count
);
791 const char *bt_field_string_get_value(const struct bt_field
*field
)
793 const struct bt_field_string
*string_field
= (const void *) field
;
795 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
796 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
797 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
799 return (const char *) string_field
->buf
->data
;
802 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
804 const struct bt_field_string
*string_field
= (const void *) field
;
806 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
807 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
808 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
810 return string_field
->length
;
814 void clear_string_field(struct bt_field
*field
)
816 struct bt_field_string
*string_field
= (void *) field
;
819 string_field
->length
= 0;
820 bt_field_set_single(field
, true);
823 enum bt_field_string_set_value_status
bt_field_string_set_value(
824 struct bt_field
*field
, const char *value
)
826 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
827 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
828 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
829 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
831 clear_string_field(field
);
832 return (int) bt_field_string_append_with_length(field
, value
,
833 (uint64_t) strlen(value
));
836 enum bt_field_string_append_status
bt_field_string_append(
837 struct bt_field
*field
, const char *value
)
839 return bt_field_string_append_with_length(field
,
840 value
, (uint64_t) strlen(value
));
843 enum bt_field_string_append_status
bt_field_string_append_with_length(
844 struct bt_field
*field
, const char *value
, uint64_t length
)
846 struct bt_field_string
*string_field
= (void *) field
;
850 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
851 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
852 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
853 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
854 BT_FIELD_CLASS_TYPE_STRING
, "Field");
856 /* Make sure no null bytes are appended */
857 BT_ASSERT_PRE_DEV(!memchr(value
, '\0', length
),
858 "String value to append contains a null character: "
859 "partial-value=\"%.32s\", length=%" PRIu64
, value
, length
);
861 new_length
= length
+ string_field
->length
;
863 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
864 g_array_set_size(string_field
->buf
, new_length
+ 1);
867 data
= string_field
->buf
->data
;
868 memcpy(data
+ string_field
->length
, value
, length
);
869 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
870 string_field
->length
= new_length
;
871 bt_field_set_single(field
, true);
872 return BT_FUNC_STATUS_OK
;
875 void bt_field_string_clear(struct bt_field
*field
)
877 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
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");
881 clear_string_field(field
);
884 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
886 const struct bt_field_array
*array_field
= (const void *) field
;
888 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
889 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
890 return array_field
->length
;
893 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
894 struct bt_field
*field
, uint64_t length
)
896 int ret
= BT_FUNC_STATUS_OK
;
897 struct bt_field_array
*array_field
= (void *) field
;
899 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
900 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
901 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
, "Field");
902 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
904 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
906 struct bt_field_class_array
*array_fc
;
907 uint64_t cur_len
= array_field
->fields
->len
;
910 g_ptr_array_set_size(array_field
->fields
, length
);
911 array_fc
= (void *) field
->class;
913 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
914 struct bt_field
*elem_field
= bt_field_create(
915 array_fc
->element_fc
);
918 BT_LIB_LOGE_APPEND_CAUSE(
919 "Cannot create element field for "
920 "dynamic array field: "
921 "index=%" PRIu64
", "
922 "%![array-field-]+f", i
, field
);
923 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
927 BT_ASSERT(!array_field
->fields
->pdata
[i
]);
928 array_field
->fields
->pdata
[i
] = elem_field
;
932 array_field
->length
= length
;
939 struct bt_field
*borrow_array_field_element_field_by_index(
940 struct bt_field
*field
, uint64_t index
)
942 struct bt_field_array
*array_field
= (void *) field
;
944 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
945 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
946 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, array_field
->length
);
947 return array_field
->fields
->pdata
[index
];
950 struct bt_field
*bt_field_array_borrow_element_field_by_index(
951 struct bt_field
*field
, uint64_t index
)
953 return borrow_array_field_element_field_by_index(field
, index
);
956 const struct bt_field
*
957 bt_field_array_borrow_element_field_by_index_const(
958 const struct bt_field
*field
, uint64_t index
)
960 return borrow_array_field_element_field_by_index((void *) field
, index
);
964 struct bt_field
*borrow_structure_field_member_field_by_index(
965 struct bt_field
*field
, uint64_t index
)
967 struct bt_field_structure
*struct_field
= (void *) field
;
969 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
970 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
971 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
972 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, struct_field
->fields
->len
);
973 return struct_field
->fields
->pdata
[index
];
976 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
977 struct bt_field
*field
, uint64_t index
)
979 return borrow_structure_field_member_field_by_index(field
,
983 const struct bt_field
*
984 bt_field_structure_borrow_member_field_by_index_const(
985 const struct bt_field
*field
, uint64_t index
)
987 return borrow_structure_field_member_field_by_index(
988 (void *) field
, index
);
992 struct bt_field
*borrow_structure_field_member_field_by_name(
993 struct bt_field
*field
, const char *name
)
995 struct bt_field
*ret_field
= NULL
;
996 struct bt_field_class_structure
*struct_fc
;
997 struct bt_field_structure
*struct_field
= (void *) field
;
1001 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1002 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Field name");
1003 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1004 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1005 struct_fc
= (void *) field
->class;
1007 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1008 &orig_key
, &index
)) {
1012 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1013 BT_ASSERT(ret_field
);
1019 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1020 struct bt_field
*field
, const char *name
)
1022 return borrow_structure_field_member_field_by_name(field
, name
);
1025 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1026 const struct bt_field
*field
, const char *name
)
1028 return borrow_structure_field_member_field_by_name(
1029 (void *) field
, name
);
1032 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1034 struct bt_field_option
*opt_field
= (void *) field
;
1036 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1037 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1038 BT_FIELD_CLASS_TYPE_OPTION
, "Field");
1039 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1042 opt_field
->selected_field
= opt_field
->content_field
;
1044 opt_field
->selected_field
= NULL
;
1048 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1050 struct bt_field_option
*opt_field
= (void *) field
;
1052 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1053 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1054 BT_FIELD_CLASS_TYPE_OPTION
, "Field");
1055 return opt_field
->selected_field
;
1058 const struct bt_field
*bt_field_option_borrow_field_const(
1059 const struct bt_field
*field
)
1061 return (const void *) bt_field_option_borrow_field((void *) field
);
1065 struct bt_field
*borrow_variant_field_selected_option_field(
1066 struct bt_field
*field
)
1068 struct bt_field_variant
*var_field
= (void *) field
;
1070 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1071 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1072 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1073 "Variant field has no selected field: %!+f", field
);
1074 return var_field
->selected_field
;
1077 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1078 struct bt_field
*field
)
1080 return borrow_variant_field_selected_option_field(field
);
1083 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1084 const struct bt_field
*field
)
1086 return borrow_variant_field_selected_option_field((void *) field
);
1090 const struct bt_field_class_variant_option
*
1091 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1093 const struct bt_field_class_named_field_class_container
*container_fc
;
1094 const struct bt_field_variant
*var_field
= (const void *) field
;
1097 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1098 "Variant field has no selected field: %!+f", field
);
1099 container_fc
= (const void *) field
->class;
1100 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1103 const struct bt_field_class_variant_option
*
1104 bt_field_variant_borrow_selected_class_option_const(
1105 const struct bt_field
*field
)
1107 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1108 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1109 return borrow_variant_field_selected_class_option(field
);
1112 const struct bt_field_class_variant_with_selector_unsigned_option
*
1113 bt_field_variant_with_unsigned_selector_borrow_selected_class_option_const(
1114 const struct bt_field
*field
)
1116 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1117 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1118 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
, "Field");
1119 return (const void *) borrow_variant_field_selected_class_option(field
);
1122 const struct bt_field_class_variant_with_selector_signed_option
*
1123 bt_field_variant_with_signed_selector_borrow_selected_class_option_const(
1124 const struct bt_field
*field
)
1126 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1127 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1128 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
, "Field");
1129 return (const void *) borrow_variant_field_selected_class_option(field
);
1132 enum bt_field_variant_select_option_field_by_index_status
1133 bt_field_variant_select_option_field_by_index(
1134 struct bt_field
*field
, uint64_t index
)
1136 struct bt_field_variant
*var_field
= (void *) field
;
1138 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1139 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1140 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1141 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1142 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1143 var_field
->selected_index
= index
;
1144 return BT_FUNC_STATUS_OK
;
1147 uint64_t bt_field_variant_get_selected_option_field_index(
1148 const struct bt_field
*field
)
1150 const struct bt_field_variant
*var_field
= (const void *) field
;
1152 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1153 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1154 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1155 "Variant field has no selected field: %!+f", field
);
1156 return var_field
->selected_index
;
1160 void bt_field_finalize(struct bt_field
*field
)
1163 BT_LOGD_STR("Putting field's class.");
1164 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1168 void destroy_bool_field(struct bt_field
*field
)
1171 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1172 bt_field_finalize(field
);
1177 void destroy_bit_array_field(struct bt_field
*field
)
1180 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1181 bt_field_finalize(field
);
1186 void destroy_integer_field(struct bt_field
*field
)
1189 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1190 bt_field_finalize(field
);
1195 void destroy_real_field(struct bt_field
*field
)
1198 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1199 bt_field_finalize(field
);
1204 void destroy_structure_field(struct bt_field
*field
)
1206 struct bt_field_structure
*struct_field
= (void *) field
;
1209 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1210 bt_field_finalize(field
);
1212 if (struct_field
->fields
) {
1213 g_ptr_array_free(struct_field
->fields
, TRUE
);
1214 struct_field
->fields
= NULL
;
1221 void destroy_option_field(struct bt_field
*field
)
1223 struct bt_field_option
*opt_field
= (void *) field
;
1226 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1227 bt_field_finalize(field
);
1229 if (opt_field
->content_field
) {
1230 bt_field_destroy(opt_field
->content_field
);
1237 void destroy_variant_field(struct bt_field
*field
)
1239 struct bt_field_variant
*var_field
= (void *) field
;
1242 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1243 bt_field_finalize(field
);
1245 if (var_field
->fields
) {
1246 g_ptr_array_free(var_field
->fields
, TRUE
);
1247 var_field
->fields
= NULL
;
1254 void destroy_array_field(struct bt_field
*field
)
1256 struct bt_field_array
*array_field
= (void *) field
;
1259 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1260 bt_field_finalize(field
);
1262 if (array_field
->fields
) {
1263 g_ptr_array_free(array_field
->fields
, TRUE
);
1264 array_field
->fields
= NULL
;
1271 void destroy_string_field(struct bt_field
*field
)
1273 struct bt_field_string
*string_field
= (void *) field
;
1276 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1277 bt_field_finalize(field
);
1279 if (string_field
->buf
) {
1280 g_array_free(string_field
->buf
, TRUE
);
1281 string_field
->buf
= NULL
;
1288 void bt_field_destroy(struct bt_field
*field
)
1291 field_destroy_funcs
[field
->class->type
](field
);
1295 void reset_single_field(struct bt_field
*field
)
1298 field
->is_set
= false;
1302 void reset_structure_field(struct bt_field
*field
)
1305 struct bt_field_structure
*struct_field
= (void *) field
;
1309 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1310 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1315 void reset_option_field(struct bt_field
*field
)
1317 struct bt_field_option
*opt_field
= (void *) field
;
1319 BT_ASSERT(opt_field
);
1320 bt_field_reset(opt_field
->content_field
);
1321 opt_field
->selected_field
= NULL
;
1325 void reset_variant_field(struct bt_field
*field
)
1328 struct bt_field_variant
*var_field
= (void *) field
;
1332 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1333 bt_field_reset(var_field
->fields
->pdata
[i
]);
1338 void reset_array_field(struct bt_field
*field
)
1341 struct bt_field_array
*array_field
= (void *) field
;
1345 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1346 bt_field_reset(array_field
->fields
->pdata
[i
]);
1351 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1353 field
->frozen
= is_frozen
;
1357 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1360 struct bt_field_structure
*struct_field
= (void *) field
;
1362 BT_LIB_LOGD("Setting structure field's frozen state: "
1363 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1365 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1366 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1368 BT_LIB_LOGD("Setting structure field's member field's "
1369 "frozen state: %![field-]+f, index=%" PRIu64
,
1371 _bt_field_set_is_frozen(member_field
, is_frozen
);
1374 set_single_field_is_frozen(field
, is_frozen
);
1378 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1380 struct bt_field_option
*opt_field
= (void *) field
;
1382 BT_LIB_LOGD("Setting option field's frozen state: "
1383 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1384 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1385 set_single_field_is_frozen(field
, is_frozen
);
1389 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1392 struct bt_field_variant
*var_field
= (void *) field
;
1394 BT_LIB_LOGD("Setting variant field's frozen state: "
1395 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1397 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1398 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1400 BT_LIB_LOGD("Setting variant field's option field's "
1401 "frozen state: %![field-]+f, index=%" PRIu64
,
1403 _bt_field_set_is_frozen(option_field
, is_frozen
);
1406 set_single_field_is_frozen(field
, is_frozen
);
1410 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1413 struct bt_field_array
*array_field
= (void *) field
;
1415 BT_LIB_LOGD("Setting array field's frozen state: "
1416 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1418 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1419 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1421 BT_LIB_LOGD("Setting array field's element field's "
1422 "frozen state: %![field-]+f, index=%" PRIu64
,
1424 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1427 set_single_field_is_frozen(field
, is_frozen
);
1431 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1435 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1437 BT_ASSERT(field
->methods
->set_is_frozen
);
1438 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1442 bool single_field_is_set(const struct bt_field
*field
)
1445 return field
->is_set
;
1449 bool structure_field_is_set(const struct bt_field
*field
)
1453 const struct bt_field_structure
*struct_field
= (const void *) field
;
1457 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1458 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1469 bool option_field_is_set(const struct bt_field
*field
)
1471 const struct bt_field_option
*opt_field
= (const void *) field
;
1472 bool is_set
= false;
1476 if (opt_field
->selected_field
) {
1477 is_set
= bt_field_is_set(opt_field
->selected_field
);
1484 bool variant_field_is_set(const struct bt_field
*field
)
1486 const struct bt_field_variant
*var_field
= (const void *) field
;
1487 bool is_set
= false;
1491 if (var_field
->selected_field
) {
1492 is_set
= bt_field_is_set(var_field
->selected_field
);
1499 bool array_field_is_set(const struct bt_field
*field
)
1503 const struct bt_field_array
*array_field
= (const void *) field
;
1507 for (i
= 0; i
< array_field
->length
; i
++) {
1508 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);