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_WITHOUT_LENGTH_FIELD
] = create_dynamic_array_field
,
192 [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
] = create_dynamic_array_field
,
193 [BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR
] = create_option_field
,
194 [BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
] = create_option_field
,
195 [BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
] = create_option_field
,
196 [BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
] = create_option_field
,
197 [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
] = create_variant_field
,
198 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
] = create_variant_field
,
199 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
] = create_variant_field
,
203 void destroy_bool_field(struct bt_field
*field
);
206 void destroy_bit_array_field(struct bt_field
*field
);
209 void destroy_integer_field(struct bt_field
*field
);
212 void destroy_real_field(struct bt_field
*field
);
215 void destroy_string_field(struct bt_field
*field
);
218 void destroy_structure_field(struct bt_field
*field
);
221 void destroy_array_field(struct bt_field
*field
);
224 void destroy_option_field(struct bt_field
*field
);
227 void destroy_variant_field(struct bt_field
*field
);
230 void (* const field_destroy_funcs
[])(struct bt_field
*) = {
231 [BT_FIELD_CLASS_TYPE_BOOL
] = destroy_bool_field
,
232 [BT_FIELD_CLASS_TYPE_BIT_ARRAY
] = destroy_bit_array_field
,
233 [BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
] = destroy_integer_field
,
234 [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
] = destroy_integer_field
,
235 [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
] = destroy_integer_field
,
236 [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
] = destroy_integer_field
,
237 [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
] = destroy_real_field
,
238 [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
] = destroy_real_field
,
239 [BT_FIELD_CLASS_TYPE_STRING
] = destroy_string_field
,
240 [BT_FIELD_CLASS_TYPE_STRUCTURE
] = destroy_structure_field
,
241 [BT_FIELD_CLASS_TYPE_STATIC_ARRAY
] = destroy_array_field
,
242 [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
] = destroy_array_field
,
243 [BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
] = destroy_array_field
,
244 [BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR
] = destroy_option_field
,
245 [BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
] = destroy_option_field
,
246 [BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
] = destroy_option_field
,
247 [BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
] = destroy_option_field
,
248 [BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
] = destroy_variant_field
,
249 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
] = destroy_variant_field
,
250 [BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
] = destroy_variant_field
,
253 struct bt_field_class
*bt_field_borrow_class(struct bt_field
*field
)
255 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
259 const struct bt_field_class
*bt_field_borrow_class_const(
260 const struct bt_field
*field
)
262 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
266 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
268 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
269 return field
->class->type
;
273 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
275 struct bt_field
*field
= NULL
;
278 field
= field_create_funcs
[fc
->type
](fc
);
280 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
290 void init_field(struct bt_field
*field
, struct bt_field_class
*fc
,
291 struct bt_field_methods
*methods
)
295 bt_object_init_unique(&field
->base
);
296 field
->methods
= methods
;
298 bt_object_get_ref_no_null_check(fc
);
302 struct bt_field
*create_bool_field(struct bt_field_class
*fc
)
304 struct bt_field_bool
*bool_field
;
306 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc
);
307 bool_field
= g_new0(struct bt_field_bool
, 1);
309 BT_LIB_LOGE_APPEND_CAUSE(
310 "Failed to allocate one boolean field.");
314 init_field((void *) bool_field
, fc
, &bool_field_methods
);
315 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field
);
318 return (void *) bool_field
;
322 struct bt_field
*create_bit_array_field(struct bt_field_class
*fc
)
324 struct bt_field_bit_array
*ba_field
;
326 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc
);
327 ba_field
= g_new0(struct bt_field_bit_array
, 1);
329 BT_LIB_LOGE_APPEND_CAUSE(
330 "Failed to allocate one bit array field.");
334 init_field((void *) ba_field
, fc
, &bit_array_field_methods
);
335 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field
);
338 return (void *) ba_field
;
342 struct bt_field
*create_integer_field(struct bt_field_class
*fc
)
344 struct bt_field_integer
*int_field
;
346 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc
);
347 int_field
= g_new0(struct bt_field_integer
, 1);
349 BT_LIB_LOGE_APPEND_CAUSE(
350 "Failed to allocate one integer field.");
354 init_field((void *) int_field
, fc
, &integer_field_methods
);
355 BT_LIB_LOGD("Created integer field object: %!+f", int_field
);
358 return (void *) int_field
;
362 struct bt_field
*create_real_field(struct bt_field_class
*fc
)
364 struct bt_field_real
*real_field
;
366 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc
);
367 real_field
= g_new0(struct bt_field_real
, 1);
369 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
373 init_field((void *) real_field
, fc
, &real_field_methods
);
374 BT_LIB_LOGD("Created real field object: %!+f", real_field
);
377 return (void *) real_field
;
381 struct bt_field
*create_string_field(struct bt_field_class
*fc
)
383 struct bt_field_string
*string_field
;
385 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc
);
386 string_field
= g_new0(struct bt_field_string
, 1);
388 BT_LIB_LOGE_APPEND_CAUSE(
389 "Failed to allocate one string field.");
393 init_field((void *) string_field
, fc
, &string_field_methods
);
394 string_field
->buf
= g_array_sized_new(FALSE
, FALSE
,
396 if (!string_field
->buf
) {
397 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
398 bt_field_destroy((void *) string_field
);
403 g_array_index(string_field
->buf
, char, 0) = '\0';
404 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
407 return (void *) string_field
;
411 int create_fields_from_named_field_classes(
412 struct bt_field_class_named_field_class_container
*fc
,
418 *fields
= g_ptr_array_new_with_free_func(
419 (GDestroyNotify
) bt_field_destroy
);
421 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
426 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
428 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
429 struct bt_field
*field
;
430 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
432 field
= bt_field_create(named_fc
->fc
);
434 BT_LIB_LOGE_APPEND_CAUSE(
435 "Failed to create structure member or variant option field: "
436 "name=\"%s\", %![fc-]+F",
437 named_fc
->name
->str
, named_fc
->fc
);
442 g_ptr_array_index(*fields
, i
) = field
;
450 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
452 struct bt_field_structure
*struct_field
;
454 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
455 struct_field
= g_new0(struct bt_field_structure
, 1);
457 BT_LIB_LOGE_APPEND_CAUSE(
458 "Failed to allocate one structure field.");
462 init_field((void *) struct_field
, fc
, &structure_field_methods
);
464 if (create_fields_from_named_field_classes((void *) fc
,
465 &struct_field
->fields
)) {
466 BT_LIB_LOGE_APPEND_CAUSE(
467 "Cannot create structure member fields: %![fc-]+F", fc
);
468 bt_field_destroy((void *) struct_field
);
473 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
476 return (void *) struct_field
;
480 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
482 struct bt_field_option
*opt_field
;
483 struct bt_field_class_option
*opt_fc
= (void *) fc
;
485 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
486 opt_field
= g_new0(struct bt_field_option
, 1);
488 BT_LIB_LOGE_APPEND_CAUSE(
489 "Failed to allocate one option field.");
493 init_field((void *) opt_field
, fc
, &option_field_methods
);
494 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
495 if (!opt_field
->content_field
) {
496 BT_LIB_LOGE_APPEND_CAUSE(
497 "Failed to create option field's content field: "
498 "%![opt-fc-]+F, %![content-fc-]+F",
499 opt_fc
, opt_fc
->content_fc
);
500 bt_field_destroy((void *) opt_field
);
505 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
508 return (void *) opt_field
;
512 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
514 struct bt_field_variant
*var_field
;
516 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
517 var_field
= g_new0(struct bt_field_variant
, 1);
519 BT_LIB_LOGE_APPEND_CAUSE(
520 "Failed to allocate one variant field.");
524 init_field((void *) var_field
, fc
, &variant_field_methods
);
526 if (create_fields_from_named_field_classes((void *) fc
,
527 &var_field
->fields
)) {
528 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
530 bt_field_destroy((void *) var_field
);
535 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
538 return (void *) var_field
;
542 int init_array_field_fields(struct bt_field_array
*array_field
)
546 struct bt_field_class_array
*array_fc
;
548 BT_ASSERT(array_field
);
549 array_fc
= (void *) array_field
->common
.class;
550 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
551 if (!array_field
->fields
) {
552 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
557 g_ptr_array_set_free_func(array_field
->fields
,
558 (GDestroyNotify
) bt_field_destroy
);
559 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
561 for (i
= 0; i
< array_field
->length
; i
++) {
562 array_field
->fields
->pdata
[i
] = bt_field_create(
563 array_fc
->element_fc
);
564 if (!array_field
->fields
->pdata
[i
]) {
565 BT_LIB_LOGE_APPEND_CAUSE(
566 "Cannot create array field's element field: "
567 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
578 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
580 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
581 struct bt_field_array
*array_field
;
583 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
584 array_field
= g_new0(struct bt_field_array
, 1);
586 BT_LIB_LOGE_APPEND_CAUSE(
587 "Failed to allocate one static array field.");
591 init_field((void *) array_field
, fc
, &array_field_methods
);
592 array_field
->length
= array_fc
->length
;
594 if (init_array_field_fields(array_field
)) {
595 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
597 bt_field_destroy((void *) array_field
);
602 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
605 return (void *) array_field
;
609 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
611 struct bt_field_array
*array_field
;
613 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
614 array_field
= g_new0(struct bt_field_array
, 1);
616 BT_LIB_LOGE_APPEND_CAUSE(
617 "Failed to allocate one dynamic array field.");
621 init_field((void *) array_field
, fc
, &array_field_methods
);
623 if (init_array_field_fields(array_field
)) {
624 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
626 bt_field_destroy((void *) array_field
);
631 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
634 return (void *) array_field
;
637 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
639 const struct bt_field_bool
*bool_field
= (const void *) field
;
641 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
642 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
643 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
645 return (bt_bool
) bool_field
->value
;
648 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
650 struct bt_field_bool
*bool_field
= (void *) field
;
652 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
653 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_BOOL
,
655 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
656 bool_field
->value
= (bool) value
;
657 bt_field_set_single(field
, true);
660 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
662 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
664 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
665 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
666 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
667 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
668 return ba_field
->value_as_int
;
671 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
674 struct bt_field_bit_array
*ba_field
= (void *) field
;
675 struct bt_field_class_bit_array
*ba_fc
;
677 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
678 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
679 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
680 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
681 ba_fc
= (void *) field
->class;
682 ba_field
->value_as_int
= value
;
684 if (ba_fc
->length
< 64) {
686 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
689 bt_field_set_single(field
, true);
692 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
694 const struct bt_field_integer
*int_field
= (const void *) field
;
696 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
697 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
698 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
699 return int_field
->value
.i
;
702 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
704 struct bt_field_integer
*int_field
= (void *) field
;
706 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
707 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field
, "Field");
708 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
709 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
710 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
711 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
712 "%![fc-]+F", value
, field
, field
->class);
713 int_field
->value
.i
= value
;
714 bt_field_set_single(field
, true);
717 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
719 const struct bt_field_integer
*int_field
= (const void *) field
;
721 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
722 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
723 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
724 return int_field
->value
.u
;
727 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
729 struct bt_field_integer
*int_field
= (void *) field
;
731 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
732 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field
, "Field");
733 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
734 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
735 ((struct bt_field_class_integer
*) field
->class)->range
, value
),
736 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
737 "%![fc-]+F", value
, field
, field
->class);
738 int_field
->value
.u
= value
;
739 bt_field_set_single(field
, true);
742 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
744 const struct bt_field_real
*real_field
= (const void *) field
;
746 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
747 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
748 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
749 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
750 return (float) real_field
->value
;
753 double bt_field_real_double_precision_get_value(const struct bt_field
*field
)
755 const struct bt_field_real
*real_field
= (const void *) field
;
757 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
758 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
759 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
760 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
762 return real_field
->value
;
765 void bt_field_real_single_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_SINGLE_PRECISION_REAL
, "Field");
773 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
775 real_field
->value
= (double) value
;
776 bt_field_set_single(field
, true);
779 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
782 struct bt_field_real
*real_field
= (void *) field
;
784 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
785 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
786 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
787 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
789 real_field
->value
= value
;
790 bt_field_set_single(field
, true);
793 enum bt_field_enumeration_get_mapping_labels_status
794 bt_field_enumeration_unsigned_get_mapping_labels(
795 const struct bt_field
*field
,
796 bt_field_class_enumeration_mapping_label_array
*label_array
,
799 const struct bt_field_integer
*int_field
= (const void *) field
;
801 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
802 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
803 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
804 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
805 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
806 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
808 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
809 field
->class, int_field
->value
.u
, label_array
, count
);
812 enum bt_field_enumeration_get_mapping_labels_status
813 bt_field_enumeration_signed_get_mapping_labels(
814 const struct bt_field
*field
,
815 bt_field_class_enumeration_mapping_label_array
*label_array
,
818 const struct bt_field_integer
*int_field
= (const void *) field
;
820 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
821 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
822 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Count (output)");
823 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
824 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
825 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
827 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
828 field
->class, int_field
->value
.i
, label_array
, count
);
831 const char *bt_field_string_get_value(const struct bt_field
*field
)
833 const struct bt_field_string
*string_field
= (const void *) field
;
835 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
836 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
837 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
839 return (const char *) string_field
->buf
->data
;
842 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
844 const struct bt_field_string
*string_field
= (const void *) field
;
846 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
847 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field
, "Field");
848 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
850 return string_field
->length
;
854 void clear_string_field(struct bt_field
*field
)
856 struct bt_field_string
*string_field
= (void *) field
;
859 string_field
->length
= 0;
860 bt_field_set_single(field
, true);
863 enum bt_field_string_set_value_status
bt_field_string_set_value(
864 struct bt_field
*field
, const char *value
)
866 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
867 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
868 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
869 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
, BT_FIELD_CLASS_TYPE_STRING
,
871 clear_string_field(field
);
872 return (int) bt_field_string_append_with_length(field
, value
,
873 (uint64_t) strlen(value
));
876 enum bt_field_string_append_status
bt_field_string_append(
877 struct bt_field
*field
, const char *value
)
879 return bt_field_string_append_with_length(field
,
880 value
, (uint64_t) strlen(value
));
883 enum bt_field_string_append_status
bt_field_string_append_with_length(
884 struct bt_field
*field
, const char *value
, uint64_t length
)
886 struct bt_field_string
*string_field
= (void *) field
;
890 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
891 BT_ASSERT_PRE_DEV_NON_NULL(value
, "Value");
892 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
893 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
894 BT_FIELD_CLASS_TYPE_STRING
, "Field");
896 /* Make sure no null bytes are appended */
897 BT_ASSERT_PRE_DEV(!memchr(value
, '\0', length
),
898 "String value to append contains a null character: "
899 "partial-value=\"%.32s\", length=%" PRIu64
, value
, length
);
901 new_length
= length
+ string_field
->length
;
903 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
904 g_array_set_size(string_field
->buf
, new_length
+ 1);
907 data
= string_field
->buf
->data
;
908 memcpy(data
+ string_field
->length
, value
, length
);
909 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
910 string_field
->length
= new_length
;
911 bt_field_set_single(field
, true);
912 return BT_FUNC_STATUS_OK
;
915 void bt_field_string_clear(struct bt_field
*field
)
917 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
918 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
919 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
920 BT_FIELD_CLASS_TYPE_STRING
, "Field");
921 clear_string_field(field
);
924 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
926 const struct bt_field_array
*array_field
= (const void *) field
;
928 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
929 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
930 return array_field
->length
;
933 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
934 struct bt_field
*field
, uint64_t length
)
936 int ret
= BT_FUNC_STATUS_OK
;
937 struct bt_field_array
*array_field
= (void *) field
;
939 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
940 BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(field
, "Field");
941 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
943 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
945 struct bt_field_class_array
*array_fc
;
946 uint64_t cur_len
= array_field
->fields
->len
;
949 g_ptr_array_set_size(array_field
->fields
, length
);
950 array_fc
= (void *) field
->class;
952 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
953 struct bt_field
*elem_field
= bt_field_create(
954 array_fc
->element_fc
);
957 BT_LIB_LOGE_APPEND_CAUSE(
958 "Cannot create element field for "
959 "dynamic array field: "
960 "index=%" PRIu64
", "
961 "%![array-field-]+f", i
, field
);
962 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
966 BT_ASSERT(!array_field
->fields
->pdata
[i
]);
967 array_field
->fields
->pdata
[i
] = elem_field
;
971 array_field
->length
= length
;
978 struct bt_field
*borrow_array_field_element_field_by_index(
979 struct bt_field
*field
, uint64_t index
)
981 struct bt_field_array
*array_field
= (void *) field
;
983 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
984 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field
, "Field");
985 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, array_field
->length
);
986 return array_field
->fields
->pdata
[index
];
989 struct bt_field
*bt_field_array_borrow_element_field_by_index(
990 struct bt_field
*field
, uint64_t index
)
992 return borrow_array_field_element_field_by_index(field
, index
);
995 const struct bt_field
*
996 bt_field_array_borrow_element_field_by_index_const(
997 const struct bt_field
*field
, uint64_t index
)
999 return borrow_array_field_element_field_by_index((void *) field
, index
);
1003 struct bt_field
*borrow_structure_field_member_field_by_index(
1004 struct bt_field
*field
, uint64_t index
)
1006 struct bt_field_structure
*struct_field
= (void *) field
;
1008 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1009 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1010 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1011 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, struct_field
->fields
->len
);
1012 return struct_field
->fields
->pdata
[index
];
1015 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1016 struct bt_field
*field
, uint64_t index
)
1018 return borrow_structure_field_member_field_by_index(field
,
1022 const struct bt_field
*
1023 bt_field_structure_borrow_member_field_by_index_const(
1024 const struct bt_field
*field
, uint64_t index
)
1026 return borrow_structure_field_member_field_by_index(
1027 (void *) field
, index
);
1031 struct bt_field
*borrow_structure_field_member_field_by_name(
1032 struct bt_field
*field
, const char *name
)
1034 struct bt_field
*ret_field
= NULL
;
1035 struct bt_field_class_structure
*struct_fc
;
1036 struct bt_field_structure
*struct_field
= (void *) field
;
1040 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1041 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Field name");
1042 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1043 BT_FIELD_CLASS_TYPE_STRUCTURE
, "Field");
1044 struct_fc
= (void *) field
->class;
1046 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1047 &orig_key
, &index
)) {
1051 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1052 BT_ASSERT(ret_field
);
1058 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1059 struct bt_field
*field
, const char *name
)
1061 return borrow_structure_field_member_field_by_name(field
, name
);
1064 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1065 const struct bt_field
*field
, const char *name
)
1067 return borrow_structure_field_member_field_by_name(
1068 (void *) field
, name
);
1071 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1073 struct bt_field_option
*opt_field
= (void *) field
;
1075 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1076 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "Field");
1077 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1080 opt_field
->selected_field
= opt_field
->content_field
;
1082 opt_field
->selected_field
= NULL
;
1086 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1088 struct bt_field_option
*opt_field
= (void *) field
;
1090 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1091 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field
, "Field");
1092 return opt_field
->selected_field
;
1095 const struct bt_field
*bt_field_option_borrow_field_const(
1096 const struct bt_field
*field
)
1098 return (const void *) bt_field_option_borrow_field((void *) field
);
1102 struct bt_field
*borrow_variant_field_selected_option_field(
1103 struct bt_field
*field
)
1105 struct bt_field_variant
*var_field
= (void *) field
;
1107 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1108 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1109 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1110 "Variant field has no selected field: %!+f", field
);
1111 return var_field
->selected_field
;
1114 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1115 struct bt_field
*field
)
1117 return borrow_variant_field_selected_option_field(field
);
1120 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1121 const struct bt_field
*field
)
1123 return borrow_variant_field_selected_option_field((void *) field
);
1127 const struct bt_field_class_variant_option
*
1128 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1130 const struct bt_field_class_named_field_class_container
*container_fc
;
1131 const struct bt_field_variant
*var_field
= (const void *) field
;
1134 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1135 "Variant field has no selected field: %!+f", field
);
1136 container_fc
= (const void *) field
->class;
1137 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1140 const struct bt_field_class_variant_option
*
1141 bt_field_variant_borrow_selected_class_option_const(
1142 const struct bt_field
*field
)
1144 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1145 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1146 return borrow_variant_field_selected_class_option(field
);
1149 const struct bt_field_class_variant_with_selector_integer_unsigned_option
*
1150 bt_field_variant_with_unsigned_integer_selector_borrow_selected_class_option_const(
1151 const struct bt_field
*field
)
1153 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1154 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1155 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
, "Field");
1156 return (const void *) borrow_variant_field_selected_class_option(field
);
1159 const struct bt_field_class_variant_with_selector_integer_signed_option
*
1160 bt_field_variant_with_signed_integer_selector_borrow_selected_class_option_const(
1161 const struct bt_field
*field
)
1163 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1164 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field
,
1165 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
, "Field");
1166 return (const void *) borrow_variant_field_selected_class_option(field
);
1169 enum bt_field_variant_select_option_field_by_index_status
1170 bt_field_variant_select_option_field_by_index(
1171 struct bt_field
*field
, uint64_t index
)
1173 struct bt_field_variant
*var_field
= (void *) field
;
1175 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1176 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1177 BT_ASSERT_PRE_DEV_FIELD_HOT(field
, "Field");
1178 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1179 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1180 var_field
->selected_index
= index
;
1181 return BT_FUNC_STATUS_OK
;
1184 uint64_t bt_field_variant_get_selected_option_field_index(
1185 const struct bt_field
*field
)
1187 const struct bt_field_variant
*var_field
= (const void *) field
;
1189 BT_ASSERT_PRE_DEV_NON_NULL(field
, "Field");
1190 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field
, "Field");
1191 BT_ASSERT_PRE_DEV(var_field
->selected_field
,
1192 "Variant field has no selected field: %!+f", field
);
1193 return var_field
->selected_index
;
1197 void bt_field_finalize(struct bt_field
*field
)
1200 BT_LOGD_STR("Putting field's class.");
1201 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1205 void destroy_bool_field(struct bt_field
*field
)
1208 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1209 bt_field_finalize(field
);
1214 void destroy_bit_array_field(struct bt_field
*field
)
1217 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1218 bt_field_finalize(field
);
1223 void destroy_integer_field(struct bt_field
*field
)
1226 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1227 bt_field_finalize(field
);
1232 void destroy_real_field(struct bt_field
*field
)
1235 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1236 bt_field_finalize(field
);
1241 void destroy_structure_field(struct bt_field
*field
)
1243 struct bt_field_structure
*struct_field
= (void *) field
;
1246 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1247 bt_field_finalize(field
);
1249 if (struct_field
->fields
) {
1250 g_ptr_array_free(struct_field
->fields
, TRUE
);
1251 struct_field
->fields
= NULL
;
1258 void destroy_option_field(struct bt_field
*field
)
1260 struct bt_field_option
*opt_field
= (void *) field
;
1263 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1264 bt_field_finalize(field
);
1266 if (opt_field
->content_field
) {
1267 bt_field_destroy(opt_field
->content_field
);
1274 void destroy_variant_field(struct bt_field
*field
)
1276 struct bt_field_variant
*var_field
= (void *) field
;
1279 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1280 bt_field_finalize(field
);
1282 if (var_field
->fields
) {
1283 g_ptr_array_free(var_field
->fields
, TRUE
);
1284 var_field
->fields
= NULL
;
1291 void destroy_array_field(struct bt_field
*field
)
1293 struct bt_field_array
*array_field
= (void *) field
;
1296 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1297 bt_field_finalize(field
);
1299 if (array_field
->fields
) {
1300 g_ptr_array_free(array_field
->fields
, TRUE
);
1301 array_field
->fields
= NULL
;
1308 void destroy_string_field(struct bt_field
*field
)
1310 struct bt_field_string
*string_field
= (void *) field
;
1313 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1314 bt_field_finalize(field
);
1316 if (string_field
->buf
) {
1317 g_array_free(string_field
->buf
, TRUE
);
1318 string_field
->buf
= NULL
;
1325 void bt_field_destroy(struct bt_field
*field
)
1328 field_destroy_funcs
[field
->class->type
](field
);
1332 void reset_single_field(struct bt_field
*field
)
1335 field
->is_set
= false;
1339 void reset_structure_field(struct bt_field
*field
)
1342 struct bt_field_structure
*struct_field
= (void *) field
;
1346 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1347 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1352 void reset_option_field(struct bt_field
*field
)
1354 struct bt_field_option
*opt_field
= (void *) field
;
1356 BT_ASSERT(opt_field
);
1357 bt_field_reset(opt_field
->content_field
);
1358 opt_field
->selected_field
= NULL
;
1362 void reset_variant_field(struct bt_field
*field
)
1365 struct bt_field_variant
*var_field
= (void *) field
;
1369 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1370 bt_field_reset(var_field
->fields
->pdata
[i
]);
1375 void reset_array_field(struct bt_field
*field
)
1378 struct bt_field_array
*array_field
= (void *) field
;
1382 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1383 bt_field_reset(array_field
->fields
->pdata
[i
]);
1388 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1390 field
->frozen
= is_frozen
;
1394 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1397 struct bt_field_structure
*struct_field
= (void *) field
;
1399 BT_LIB_LOGD("Setting structure field's frozen state: "
1400 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1402 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1403 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1405 BT_LIB_LOGD("Setting structure field's member field's "
1406 "frozen state: %![field-]+f, index=%" PRIu64
,
1408 _bt_field_set_is_frozen(member_field
, is_frozen
);
1411 set_single_field_is_frozen(field
, is_frozen
);
1415 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1417 struct bt_field_option
*opt_field
= (void *) field
;
1419 BT_LIB_LOGD("Setting option field's frozen state: "
1420 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1421 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1422 set_single_field_is_frozen(field
, is_frozen
);
1426 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1429 struct bt_field_variant
*var_field
= (void *) field
;
1431 BT_LIB_LOGD("Setting variant field's frozen state: "
1432 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1434 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1435 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1437 BT_LIB_LOGD("Setting variant field's option field's "
1438 "frozen state: %![field-]+f, index=%" PRIu64
,
1440 _bt_field_set_is_frozen(option_field
, is_frozen
);
1443 set_single_field_is_frozen(field
, is_frozen
);
1447 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1450 struct bt_field_array
*array_field
= (void *) field
;
1452 BT_LIB_LOGD("Setting array field's frozen state: "
1453 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1455 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1456 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1458 BT_LIB_LOGD("Setting array field's element field's "
1459 "frozen state: %![field-]+f, index=%" PRIu64
,
1461 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1464 set_single_field_is_frozen(field
, is_frozen
);
1468 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1472 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1474 BT_ASSERT(field
->methods
->set_is_frozen
);
1475 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1479 bool single_field_is_set(const struct bt_field
*field
)
1482 return field
->is_set
;
1486 bool structure_field_is_set(const struct bt_field
*field
)
1490 const struct bt_field_structure
*struct_field
= (const void *) field
;
1494 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1495 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1506 bool option_field_is_set(const struct bt_field
*field
)
1508 const struct bt_field_option
*opt_field
= (const void *) field
;
1509 bool is_set
= false;
1513 if (opt_field
->selected_field
) {
1514 is_set
= bt_field_is_set(opt_field
->selected_field
);
1521 bool variant_field_is_set(const struct bt_field
*field
)
1523 const struct bt_field_variant
*var_field
= (const void *) field
;
1524 bool is_set
= false;
1528 if (var_field
->selected_field
) {
1529 is_set
= bt_field_is_set(var_field
->selected_field
);
1536 bool array_field_is_set(const struct bt_field
*field
)
1540 const struct bt_field_array
*array_field
= (const void *) field
;
1544 for (i
= 0; i
< array_field
->length
; i
++) {
1545 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);