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-cond.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/assert.h"
21 #include "field-class.h"
22 #include "lib/func-status.h"
25 #define BT_ASSERT_PRE_DEV_FIELD_HOT(_field) \
26 BT_ASSERT_PRE_DEV_HOT("field", \
27 (const struct bt_field *) (_field), "Field", ": %!+f", (_field))
30 void reset_single_field(struct bt_field
*field
);
33 void reset_array_field(struct bt_field
*field
);
36 void reset_structure_field(struct bt_field
*field
);
39 void reset_option_field(struct bt_field
*field
);
42 void reset_variant_field(struct bt_field
*field
);
45 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
48 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
51 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
54 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
57 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
);
60 bool single_field_is_set(const struct bt_field
*field
);
63 bool array_field_is_set(const struct bt_field
*field
);
66 bool structure_field_is_set(const struct bt_field
*field
);
69 bool option_field_is_set(const struct bt_field
*field
);
72 bool variant_field_is_set(const struct bt_field
*field
);
75 struct bt_field_methods bool_field_methods
= {
76 .set_is_frozen
= set_single_field_is_frozen
,
77 .is_set
= single_field_is_set
,
78 .reset
= reset_single_field
,
82 struct bt_field_methods bit_array_field_methods
= {
83 .set_is_frozen
= set_single_field_is_frozen
,
84 .is_set
= single_field_is_set
,
85 .reset
= reset_single_field
,
89 struct bt_field_methods integer_field_methods
= {
90 .set_is_frozen
= set_single_field_is_frozen
,
91 .is_set
= single_field_is_set
,
92 .reset
= reset_single_field
,
96 struct bt_field_methods real_field_methods
= {
97 .set_is_frozen
= set_single_field_is_frozen
,
98 .is_set
= single_field_is_set
,
99 .reset
= reset_single_field
,
103 struct bt_field_methods string_field_methods
= {
104 .set_is_frozen
= set_single_field_is_frozen
,
105 .is_set
= single_field_is_set
,
106 .reset
= reset_single_field
,
110 struct bt_field_methods structure_field_methods
= {
111 .set_is_frozen
= set_structure_field_is_frozen
,
112 .is_set
= structure_field_is_set
,
113 .reset
= reset_structure_field
,
117 struct bt_field_methods array_field_methods
= {
118 .set_is_frozen
= set_array_field_is_frozen
,
119 .is_set
= array_field_is_set
,
120 .reset
= reset_array_field
,
124 struct bt_field_methods option_field_methods
= {
125 .set_is_frozen
= set_option_field_is_frozen
,
126 .is_set
= option_field_is_set
,
127 .reset
= reset_option_field
,
131 struct bt_field_methods variant_field_methods
= {
132 .set_is_frozen
= set_variant_field_is_frozen
,
133 .is_set
= variant_field_is_set
,
134 .reset
= reset_variant_field
,
138 struct bt_field
*create_bool_field(struct bt_field_class
*);
141 struct bt_field
*create_bit_array_field(struct bt_field_class
*);
144 struct bt_field
*create_integer_field(struct bt_field_class
*);
147 struct bt_field
*create_real_field(struct bt_field_class
*);
150 struct bt_field
*create_string_field(struct bt_field_class
*);
153 struct bt_field
*create_structure_field(struct bt_field_class
*);
156 struct bt_field
*create_static_array_field(struct bt_field_class
*);
159 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*);
162 struct bt_field
*create_option_field(struct bt_field_class
*);
165 struct bt_field
*create_variant_field(struct bt_field_class
*);
168 void destroy_bool_field(struct bt_field
*field
);
171 void destroy_bit_array_field(struct bt_field
*field
);
174 void destroy_integer_field(struct bt_field
*field
);
177 void destroy_real_field(struct bt_field
*field
);
180 void destroy_string_field(struct bt_field
*field
);
183 void destroy_structure_field(struct bt_field
*field
);
186 void destroy_array_field(struct bt_field
*field
);
189 void destroy_option_field(struct bt_field
*field
);
192 void destroy_variant_field(struct bt_field
*field
);
195 struct bt_field_class
*bt_field_borrow_class(struct bt_field
*field
)
197 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
202 const struct bt_field_class
*bt_field_borrow_class_const(
203 const struct bt_field
*field
)
205 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
210 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
212 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
213 return field
->class->type
;
216 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
218 struct bt_field
*field
= NULL
;
223 case BT_FIELD_CLASS_TYPE_BOOL
:
224 field
= create_bool_field(fc
);
226 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
227 field
= create_bit_array_field(fc
);
229 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
230 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
231 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
232 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
233 field
= create_integer_field(fc
);
235 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
236 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
237 field
= create_real_field(fc
);
239 case BT_FIELD_CLASS_TYPE_STRING
:
240 field
= create_string_field(fc
);
242 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
243 field
= create_structure_field(fc
);
245 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
246 field
= create_static_array_field(fc
);
248 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
249 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
250 field
= create_dynamic_array_field(fc
);
252 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
253 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
254 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
255 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
256 field
= create_option_field(fc
);
258 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
259 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
260 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
261 field
= create_variant_field(fc
);
268 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
278 void init_field(struct bt_field
*field
, struct bt_field_class
*fc
,
279 struct bt_field_methods
*methods
)
283 bt_object_init_unique(&field
->base
);
284 field
->methods
= methods
;
286 bt_object_get_ref_no_null_check(fc
);
290 struct bt_field
*create_bool_field(struct bt_field_class
*fc
)
292 struct bt_field_bool
*bool_field
;
294 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc
);
295 bool_field
= g_new0(struct bt_field_bool
, 1);
297 BT_LIB_LOGE_APPEND_CAUSE(
298 "Failed to allocate one boolean field.");
302 init_field((void *) bool_field
, fc
, &bool_field_methods
);
303 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field
);
306 return (void *) bool_field
;
310 struct bt_field
*create_bit_array_field(struct bt_field_class
*fc
)
312 struct bt_field_bit_array
*ba_field
;
314 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc
);
315 ba_field
= g_new0(struct bt_field_bit_array
, 1);
317 BT_LIB_LOGE_APPEND_CAUSE(
318 "Failed to allocate one bit array field.");
322 init_field((void *) ba_field
, fc
, &bit_array_field_methods
);
323 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field
);
326 return (void *) ba_field
;
330 struct bt_field
*create_integer_field(struct bt_field_class
*fc
)
332 struct bt_field_integer
*int_field
;
334 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc
);
335 int_field
= g_new0(struct bt_field_integer
, 1);
337 BT_LIB_LOGE_APPEND_CAUSE(
338 "Failed to allocate one integer field.");
342 init_field((void *) int_field
, fc
, &integer_field_methods
);
343 BT_LIB_LOGD("Created integer field object: %!+f", int_field
);
346 return (void *) int_field
;
350 struct bt_field
*create_real_field(struct bt_field_class
*fc
)
352 struct bt_field_real
*real_field
;
354 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc
);
355 real_field
= g_new0(struct bt_field_real
, 1);
357 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
361 init_field((void *) real_field
, fc
, &real_field_methods
);
362 BT_LIB_LOGD("Created real field object: %!+f", real_field
);
365 return (void *) real_field
;
369 struct bt_field
*create_string_field(struct bt_field_class
*fc
)
371 struct bt_field_string
*string_field
;
373 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc
);
374 string_field
= g_new0(struct bt_field_string
, 1);
376 BT_LIB_LOGE_APPEND_CAUSE(
377 "Failed to allocate one string field.");
381 init_field((void *) string_field
, fc
, &string_field_methods
);
382 string_field
->buf
= g_array_sized_new(FALSE
, FALSE
,
384 if (!string_field
->buf
) {
385 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
386 bt_field_destroy((void *) string_field
);
391 g_array_set_size(string_field
->buf
, 1);
392 bt_g_array_index(string_field
->buf
, char, 0) = '\0';
393 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
396 return (void *) string_field
;
400 int create_fields_from_named_field_classes(
401 struct bt_field_class_named_field_class_container
*fc
,
407 *fields
= g_ptr_array_new_with_free_func(
408 (GDestroyNotify
) bt_field_destroy
);
410 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
415 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
417 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
418 struct bt_field
*field
;
419 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
421 field
= bt_field_create(named_fc
->fc
);
423 BT_LIB_LOGE_APPEND_CAUSE(
424 "Failed to create structure member or variant option field: "
425 "name=\"%s\", %![fc-]+F",
426 named_fc
->name
->str
, named_fc
->fc
);
431 g_ptr_array_index(*fields
, i
) = field
;
439 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
441 struct bt_field_structure
*struct_field
;
443 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
444 struct_field
= g_new0(struct bt_field_structure
, 1);
446 BT_LIB_LOGE_APPEND_CAUSE(
447 "Failed to allocate one structure field.");
451 init_field((void *) struct_field
, fc
, &structure_field_methods
);
453 if (create_fields_from_named_field_classes((void *) fc
,
454 &struct_field
->fields
)) {
455 BT_LIB_LOGE_APPEND_CAUSE(
456 "Cannot create structure member fields: %![fc-]+F", fc
);
457 bt_field_destroy((void *) 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_field_destroy((void *) opt_field
);
494 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
497 return (void *) opt_field
;
501 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
503 struct bt_field_variant
*var_field
;
505 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
506 var_field
= g_new0(struct bt_field_variant
, 1);
508 BT_LIB_LOGE_APPEND_CAUSE(
509 "Failed to allocate one variant field.");
513 init_field((void *) var_field
, fc
, &variant_field_methods
);
515 if (create_fields_from_named_field_classes((void *) fc
,
516 &var_field
->fields
)) {
517 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
519 bt_field_destroy((void *) var_field
);
524 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
527 return (void *) var_field
;
531 int init_array_field_fields(struct bt_field_array
*array_field
)
535 struct bt_field_class_array
*array_fc
;
537 BT_ASSERT(array_field
);
538 array_fc
= (void *) array_field
->common
.class;
539 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
540 if (!array_field
->fields
) {
541 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
546 g_ptr_array_set_free_func(array_field
->fields
,
547 (GDestroyNotify
) bt_field_destroy
);
548 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
550 for (i
= 0; i
< array_field
->length
; i
++) {
551 array_field
->fields
->pdata
[i
] = bt_field_create(
552 array_fc
->element_fc
);
553 if (!array_field
->fields
->pdata
[i
]) {
554 BT_LIB_LOGE_APPEND_CAUSE(
555 "Cannot create array field's element field: "
556 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
567 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
569 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
570 struct bt_field_array
*array_field
;
572 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
573 array_field
= g_new0(struct bt_field_array
, 1);
575 BT_LIB_LOGE_APPEND_CAUSE(
576 "Failed to allocate one static array field.");
580 init_field((void *) array_field
, fc
, &array_field_methods
);
581 array_field
->length
= array_fc
->length
;
583 if (init_array_field_fields(array_field
)) {
584 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
586 bt_field_destroy((void *) array_field
);
591 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
594 return (void *) array_field
;
598 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
600 struct bt_field_array
*array_field
;
602 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
603 array_field
= g_new0(struct bt_field_array
, 1);
605 BT_LIB_LOGE_APPEND_CAUSE(
606 "Failed to allocate one dynamic array field.");
610 init_field((void *) array_field
, fc
, &array_field_methods
);
612 if (init_array_field_fields(array_field
)) {
613 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
615 bt_field_destroy((void *) array_field
);
620 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
623 return (void *) array_field
;
627 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
629 const struct bt_field_bool
*bool_field
= (const void *) field
;
631 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
632 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
633 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
634 "boolean-field", BT_FIELD_CLASS_TYPE_BOOL
, "Field");
635 return (bt_bool
) bool_field
->value
;
639 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
641 struct bt_field_bool
*bool_field
= (void *) field
;
643 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
644 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
645 "boolean-field", BT_FIELD_CLASS_TYPE_BOOL
, "Field");
646 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
647 bool_field
->value
= (bool) value
;
648 bt_field_set_single(field
, true);
652 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
654 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
656 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
657 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
658 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
659 "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
660 return ba_field
->value_as_int
;
664 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
667 struct bt_field_bit_array
*ba_field
= (void *) field
;
668 struct bt_field_class_bit_array
*ba_fc
;
670 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
671 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
672 "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
673 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
674 ba_fc
= (void *) field
->class;
675 ba_field
->value_as_int
= value
;
677 if (ba_fc
->length
< 64) {
679 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
682 bt_field_set_single(field
, true);
686 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
688 const struct bt_field_integer
*int_field
= (const void *) field
;
690 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
691 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
692 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field
, "Field");
693 return int_field
->value
.i
;
697 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
699 struct bt_field_integer
*int_field
= (void *) field
;
701 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
702 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field
, "Field");
703 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
704 BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
705 bt_util_value_is_in_range_signed(
706 ((struct bt_field_class_integer
*) field
->class)->range
,
708 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
709 "%![fc-]+F", value
, field
, field
->class);
710 int_field
->value
.i
= value
;
711 bt_field_set_single(field
, true);
715 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
717 const struct bt_field_integer
*int_field
= (const void *) field
;
719 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
720 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
721 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field
, "Field");
722 return int_field
->value
.u
;
726 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
728 struct bt_field_integer
*int_field
= (void *) field
;
730 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
731 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field
, "Field");
732 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
733 BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
734 bt_util_value_is_in_range_unsigned(
735 ((struct bt_field_class_integer
*) field
->class)->range
,
737 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
738 "%![fc-]+F", value
, field
, field
->class);
739 int_field
->value
.u
= value
;
740 bt_field_set_single(field
, true);
744 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
746 const struct bt_field_real
*real_field
= (const void *) field
;
748 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
749 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
750 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
751 "single-precision-real-field",
752 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
753 return (float) real_field
->value
;
757 double bt_field_real_double_precision_get_value(const struct bt_field
*field
)
759 const struct bt_field_real
*real_field
= (const void *) field
;
761 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
762 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
763 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
764 "double-precision-real-field",
765 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
766 return real_field
->value
;
770 void bt_field_real_single_precision_set_value(struct bt_field
*field
,
773 struct bt_field_real
*real_field
= (void *) field
;
775 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
776 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
777 "single-precision-real-field",
778 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
779 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
781 real_field
->value
= (double) value
;
782 bt_field_set_single(field
, true);
786 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
789 struct bt_field_real
*real_field
= (void *) field
;
791 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
792 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
793 "double-precision-real-field",
794 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
795 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
797 real_field
->value
= value
;
798 bt_field_set_single(field
, true);
802 enum bt_field_enumeration_get_mapping_labels_status
803 bt_field_enumeration_unsigned_get_mapping_labels(
804 const struct bt_field
*field
,
805 bt_field_class_enumeration_mapping_label_array
*label_array
,
808 const struct bt_field_integer
*int_field
= (const void *) field
;
810 BT_ASSERT_PRE_DEV_NO_ERROR();
811 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
812 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
813 "Label array (output)");
814 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
815 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
816 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
817 "unsigned-enumeration-field",
818 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
820 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
821 field
->class, int_field
->value
.u
, label_array
, count
);
825 enum bt_field_enumeration_get_mapping_labels_status
826 bt_field_enumeration_signed_get_mapping_labels(
827 const struct bt_field
*field
,
828 bt_field_class_enumeration_mapping_label_array
*label_array
,
831 const struct bt_field_integer
*int_field
= (const void *) field
;
833 BT_ASSERT_PRE_DEV_NO_ERROR();
834 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
835 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
836 "Label array (output)");
837 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
838 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
839 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
840 "signed-enumeration-field",
841 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
843 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
844 field
->class, int_field
->value
.i
, label_array
, count
);
848 const char *bt_field_string_get_value(const struct bt_field
*field
)
850 const struct bt_field_string
*string_field
= (const void *) field
;
852 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
853 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
854 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
855 BT_FIELD_CLASS_TYPE_STRING
, "Field");
856 return (const char *) string_field
->buf
->data
;
860 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
862 const struct bt_field_string
*string_field
= (const void *) field
;
864 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
865 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
866 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
867 BT_FIELD_CLASS_TYPE_STRING
, "Field");
868 return string_field
->length
;
872 void clear_string_field(struct bt_field
*field
)
874 struct bt_field_string
*string_field
= (void *) field
;
876 BT_ASSERT_DBG(field
);
877 string_field
->length
= 0;
878 bt_g_array_index(string_field
->buf
, char, 0) = '\0';
879 bt_field_set_single(field
, true);
883 enum bt_field_string_set_value_status
bt_field_string_set_value(
884 struct bt_field
*field
, const char *value
)
886 BT_ASSERT_PRE_DEV_NO_ERROR();
887 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
888 BT_ASSERT_PRE_DEV_NON_NULL("value", value
, "Value");
889 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
890 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
891 BT_FIELD_CLASS_TYPE_STRING
, "Field");
892 clear_string_field(field
);
893 return (int) bt_field_string_append_with_length(field
, value
,
894 (uint64_t) strlen(value
));
897 #define BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(_field, _value, _length) \
899 BT_ASSERT_PRE_DEV_NO_ERROR(); \
900 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field); \
901 BT_ASSERT_PRE_DEV_NON_NULL("value", (_value), "Value"); \
902 BT_ASSERT_PRE_DEV_FIELD_HOT(_field); \
903 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", \
904 (_field), "string-field", \
905 BT_FIELD_CLASS_TYPE_STRING, "Field"); \
906 BT_ASSERT_PRE_DEV("value-has-no-null-byte", \
907 !memchr((_value), '\0', (_length)), \
908 "String value to append contains a null character: " \
909 "partial-value=\"%.32s\", length=%" PRIu64, \
910 (_value), (_length)); \
914 enum bt_field_string_append_status
append_to_string_field_with_length(
915 struct bt_field
*field
, const char *value
, uint64_t length
)
917 struct bt_field_string
*string_field
= (void *) field
;
921 BT_ASSERT_DBG(field
);
922 BT_ASSERT_DBG(value
);
923 new_length
= length
+ string_field
->length
;
925 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
926 g_array_set_size(string_field
->buf
, new_length
+ 1);
929 data
= string_field
->buf
->data
;
930 memcpy(data
+ string_field
->length
, value
, length
);
931 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
932 string_field
->length
= new_length
;
933 bt_field_set_single(field
, true);
934 return BT_FUNC_STATUS_OK
;
938 enum bt_field_string_append_status
bt_field_string_append_with_length(
939 struct bt_field
*field
, const char *value
, uint64_t length
)
941 BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field
, value
,
943 return append_to_string_field_with_length(field
, value
, length
);
947 enum bt_field_string_append_status
bt_field_string_append(
948 struct bt_field
*field
, const char *value
)
950 uint64_t length
= (uint64_t) strlen(value
);
952 BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field
, value
,
954 return append_to_string_field_with_length(field
, value
, length
);
958 void bt_field_string_clear(struct bt_field
*field
)
960 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
961 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
962 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
963 BT_FIELD_CLASS_TYPE_STRING
, "Field");
964 clear_string_field(field
);
968 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
970 const struct bt_field_array
*array_field
= (const void *) field
;
972 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
973 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY("field", field
, "Field");
974 return array_field
->length
;
978 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
979 struct bt_field
*field
, uint64_t length
)
981 int ret
= BT_FUNC_STATUS_OK
;
982 struct bt_field_array
*array_field
= (void *) field
;
984 BT_ASSERT_PRE_DEV_NO_ERROR();
985 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
986 BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY("field", field
, "Field");
987 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
989 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
991 struct bt_field_class_array
*array_fc
;
992 uint64_t cur_len
= array_field
->fields
->len
;
995 g_ptr_array_set_size(array_field
->fields
, length
);
996 array_fc
= (void *) field
->class;
998 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
999 struct bt_field
*elem_field
= bt_field_create(
1000 array_fc
->element_fc
);
1003 BT_LIB_LOGE_APPEND_CAUSE(
1004 "Cannot create element field for "
1005 "dynamic array field: "
1006 "index=%" PRIu64
", "
1007 "%![array-field-]+f", i
, field
);
1008 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
1012 BT_ASSERT_DBG(!array_field
->fields
->pdata
[i
]);
1013 array_field
->fields
->pdata
[i
] = elem_field
;
1017 array_field
->length
= length
;
1024 struct bt_field
*borrow_array_field_element_field_by_index(
1025 struct bt_field
*field
, uint64_t index
, const char *api_func
)
1027 struct bt_field_array
*array_field
= (void *) field
;
1029 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1030 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY_FROM_FUNC(api_func
, "field", field
,
1032 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1033 array_field
->length
);
1034 return array_field
->fields
->pdata
[index
];
1038 struct bt_field
*bt_field_array_borrow_element_field_by_index(
1039 struct bt_field
*field
, uint64_t index
)
1041 return borrow_array_field_element_field_by_index(field
, index
,
1046 const struct bt_field
*
1047 bt_field_array_borrow_element_field_by_index_const(
1048 const struct bt_field
*field
, uint64_t index
)
1050 return borrow_array_field_element_field_by_index((void *) field
, index
,
1055 struct bt_field
*borrow_structure_field_member_field_by_index(
1056 struct bt_field
*field
, uint64_t index
, const char *api_func
)
1058 struct bt_field_structure
*struct_field
= (void *) field
;
1060 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1061 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func
, "field",
1062 field
, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE
,
1064 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1065 struct_field
->fields
->len
);
1066 return struct_field
->fields
->pdata
[index
];
1070 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1071 struct bt_field
*field
, uint64_t index
)
1073 return borrow_structure_field_member_field_by_index(field
,
1078 const struct bt_field
*
1079 bt_field_structure_borrow_member_field_by_index_const(
1080 const struct bt_field
*field
, uint64_t index
)
1082 return borrow_structure_field_member_field_by_index(
1083 (void *) field
, index
, __func__
);
1087 struct bt_field
*borrow_structure_field_member_field_by_name(
1088 struct bt_field
*field
, const char *name
, const char *api_func
)
1090 struct bt_field
*ret_field
= NULL
;
1091 struct bt_field_class_structure
*struct_fc
;
1092 struct bt_field_structure
*struct_field
= (void *) field
;
1096 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1097 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "member-name", name
,
1099 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func
, "field",
1100 field
, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE
,
1102 struct_fc
= (void *) field
->class;
1104 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1105 &orig_key
, &index
)) {
1109 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1110 BT_ASSERT_DBG(ret_field
);
1117 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1118 struct bt_field
*field
, const char *name
)
1120 return borrow_structure_field_member_field_by_name(field
, name
,
1125 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1126 const struct bt_field
*field
, const char *name
)
1128 return borrow_structure_field_member_field_by_name(
1129 (void *) field
, name
, __func__
);
1133 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1135 struct bt_field_option
*opt_field
= (void *) field
;
1137 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1138 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field
, "Field");
1139 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
1142 opt_field
->selected_field
= opt_field
->content_field
;
1144 opt_field
->selected_field
= NULL
;
1149 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1151 struct bt_field_option
*opt_field
= (void *) field
;
1153 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1154 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field
, "Field");
1155 return opt_field
->selected_field
;
1159 const struct bt_field
*bt_field_option_borrow_field_const(
1160 const struct bt_field
*field
)
1162 return (const void *) bt_field_option_borrow_field((void *) field
);
1165 #define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(_field) \
1167 struct bt_field_variant *_var_field = (void *) field; \
1168 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field); \
1169 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", (_field), \
1171 BT_ASSERT_PRE_DEV("has-selected-field", \
1172 _var_field->selected_field, \
1173 "Variant field has no selected field: %!+f", \
1178 struct bt_field
*borrow_variant_field_selected_option_field(
1179 struct bt_field
*field
)
1181 struct bt_field_variant
*var_field
= (void *) field
;
1183 BT_ASSERT_DBG(field
);
1184 return var_field
->selected_field
;
1188 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1189 struct bt_field
*field
)
1191 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field
);
1192 return borrow_variant_field_selected_option_field(field
);
1196 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1197 const struct bt_field
*field
)
1199 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field
);
1200 return borrow_variant_field_selected_option_field((void *) field
);
1203 #define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(_field) \
1205 struct bt_field_variant *_var_field = (void *) field; \
1206 BT_ASSERT_PRE_DEV("has-selected-field", \
1207 _var_field->selected_field, \
1208 "Variant field has no selected field: %!+f", \
1213 const struct bt_field_class_variant_option
*
1214 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1216 const struct bt_field_class_named_field_class_container
*container_fc
;
1217 const struct bt_field_variant
*var_field
= (const void *) field
;
1219 BT_ASSERT_DBG(field
);
1220 container_fc
= (const void *) field
->class;
1221 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1225 const struct bt_field_class_variant_option
*
1226 bt_field_variant_borrow_selected_option_class_const(
1227 const struct bt_field
*field
)
1229 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1230 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1231 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1232 return borrow_variant_field_selected_class_option(field
);
1236 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1237 bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_const(
1238 const struct bt_field
*field
)
1240 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1241 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
1242 "variant-field-with-unsigned-selector-field",
1243 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1245 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1246 return (const void *) borrow_variant_field_selected_class_option(field
);
1250 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1251 bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_const(
1252 const struct bt_field
*field
)
1254 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1255 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
1256 "variant-field-with-signed-selector-field",
1257 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1259 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1260 return (const void *) borrow_variant_field_selected_class_option(field
);
1264 enum bt_field_variant_select_option_by_index_status
1265 bt_field_variant_select_option_by_index(
1266 struct bt_field
*field
, uint64_t index
)
1268 struct bt_field_variant
*var_field
= (void *) field
;
1270 BT_ASSERT_PRE_DEV_NO_ERROR();
1271 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1272 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1273 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
1274 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1275 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1276 var_field
->selected_index
= index
;
1277 return BT_FUNC_STATUS_OK
;
1281 uint64_t bt_field_variant_get_selected_option_index(
1282 const struct bt_field
*field
)
1284 const struct bt_field_variant
*var_field
= (const void *) field
;
1286 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1287 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1288 BT_ASSERT_PRE_DEV("has-selected-field", var_field
->selected_field
,
1289 "Variant field has no selected field: %!+f", field
);
1290 return var_field
->selected_index
;
1294 void bt_field_finalize(struct bt_field
*field
)
1297 BT_LOGD_STR("Putting field's class.");
1298 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1302 void destroy_bool_field(struct bt_field
*field
)
1305 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1306 bt_field_finalize(field
);
1311 void destroy_bit_array_field(struct bt_field
*field
)
1314 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1315 bt_field_finalize(field
);
1320 void destroy_integer_field(struct bt_field
*field
)
1323 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1324 bt_field_finalize(field
);
1329 void destroy_real_field(struct bt_field
*field
)
1332 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1333 bt_field_finalize(field
);
1338 void destroy_structure_field(struct bt_field
*field
)
1340 struct bt_field_structure
*struct_field
= (void *) field
;
1343 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1344 bt_field_finalize(field
);
1346 if (struct_field
->fields
) {
1347 g_ptr_array_free(struct_field
->fields
, TRUE
);
1348 struct_field
->fields
= NULL
;
1355 void destroy_option_field(struct bt_field
*field
)
1357 struct bt_field_option
*opt_field
= (void *) field
;
1360 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1361 bt_field_finalize(field
);
1363 if (opt_field
->content_field
) {
1364 bt_field_destroy(opt_field
->content_field
);
1371 void destroy_variant_field(struct bt_field
*field
)
1373 struct bt_field_variant
*var_field
= (void *) field
;
1376 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1377 bt_field_finalize(field
);
1379 if (var_field
->fields
) {
1380 g_ptr_array_free(var_field
->fields
, TRUE
);
1381 var_field
->fields
= NULL
;
1388 void destroy_array_field(struct bt_field
*field
)
1390 struct bt_field_array
*array_field
= (void *) field
;
1393 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1394 bt_field_finalize(field
);
1396 if (array_field
->fields
) {
1397 g_ptr_array_free(array_field
->fields
, TRUE
);
1398 array_field
->fields
= NULL
;
1405 void destroy_string_field(struct bt_field
*field
)
1407 struct bt_field_string
*string_field
= (void *) field
;
1410 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1411 bt_field_finalize(field
);
1413 if (string_field
->buf
) {
1414 g_array_free(string_field
->buf
, TRUE
);
1415 string_field
->buf
= NULL
;
1421 void bt_field_destroy(struct bt_field
*field
)
1425 switch (field
->class->type
) {
1426 case BT_FIELD_CLASS_TYPE_BOOL
:
1427 destroy_bool_field(field
);
1429 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
1430 destroy_bit_array_field(field
);
1432 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1433 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1434 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1435 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1436 destroy_integer_field(field
);
1438 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
1439 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
1440 destroy_real_field(field
);
1442 case BT_FIELD_CLASS_TYPE_STRING
:
1443 destroy_string_field(field
);
1445 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1446 destroy_structure_field(field
);
1448 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1449 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
1450 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
1451 destroy_array_field(field
);
1453 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
1454 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
1455 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1456 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1457 destroy_option_field(field
);
1459 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
1460 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1461 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1462 destroy_variant_field(field
);
1470 void reset_single_field(struct bt_field
*field
)
1472 BT_ASSERT_DBG(field
);
1473 field
->is_set
= false;
1477 void reset_structure_field(struct bt_field
*field
)
1480 struct bt_field_structure
*struct_field
= (void *) field
;
1482 BT_ASSERT_DBG(field
);
1484 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1485 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1490 void reset_option_field(struct bt_field
*field
)
1492 struct bt_field_option
*opt_field
= (void *) field
;
1494 BT_ASSERT_DBG(opt_field
);
1495 bt_field_reset(opt_field
->content_field
);
1496 opt_field
->selected_field
= NULL
;
1500 void reset_variant_field(struct bt_field
*field
)
1503 struct bt_field_variant
*var_field
= (void *) field
;
1505 BT_ASSERT_DBG(field
);
1507 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1508 bt_field_reset(var_field
->fields
->pdata
[i
]);
1513 void reset_array_field(struct bt_field
*field
)
1516 struct bt_field_array
*array_field
= (void *) field
;
1518 BT_ASSERT_DBG(field
);
1520 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1521 bt_field_reset(array_field
->fields
->pdata
[i
]);
1526 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1528 field
->frozen
= is_frozen
;
1532 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1535 struct bt_field_structure
*struct_field
= (void *) field
;
1537 BT_LIB_LOGD("Setting structure field's frozen state: "
1538 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1540 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1541 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1543 BT_LIB_LOGD("Setting structure field's member field's "
1544 "frozen state: %![field-]+f, index=%" PRIu64
,
1546 _bt_field_set_is_frozen(member_field
, is_frozen
);
1549 set_single_field_is_frozen(field
, is_frozen
);
1553 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1555 struct bt_field_option
*opt_field
= (void *) field
;
1557 BT_LIB_LOGD("Setting option field's frozen state: "
1558 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1559 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1560 set_single_field_is_frozen(field
, is_frozen
);
1564 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1567 struct bt_field_variant
*var_field
= (void *) field
;
1569 BT_LIB_LOGD("Setting variant field's frozen state: "
1570 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1572 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1573 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1575 BT_LIB_LOGD("Setting variant field's option field's "
1576 "frozen state: %![field-]+f, index=%" PRIu64
,
1578 _bt_field_set_is_frozen(option_field
, is_frozen
);
1581 set_single_field_is_frozen(field
, is_frozen
);
1585 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1588 struct bt_field_array
*array_field
= (void *) field
;
1590 BT_LIB_LOGD("Setting array field's frozen state: "
1591 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1593 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1594 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1596 BT_LIB_LOGD("Setting array field's element field's "
1597 "frozen state: %![field-]+f, index=%" PRIu64
,
1599 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1602 set_single_field_is_frozen(field
, is_frozen
);
1605 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1608 BT_ASSERT_DBG(field
);
1609 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1611 BT_ASSERT_DBG(field
->methods
->set_is_frozen
);
1612 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1616 bool single_field_is_set(const struct bt_field
*field
)
1618 BT_ASSERT_DBG(field
);
1619 return field
->is_set
;
1623 bool structure_field_is_set(const struct bt_field
*field
)
1627 const struct bt_field_structure
*struct_field
= (const void *) field
;
1629 BT_ASSERT_DBG(field
);
1631 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1632 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1643 bool option_field_is_set(const struct bt_field
*field
)
1645 const struct bt_field_option
*opt_field
= (const void *) field
;
1646 bool is_set
= false;
1648 BT_ASSERT_DBG(field
);
1650 if (opt_field
->selected_field
) {
1651 is_set
= bt_field_is_set(opt_field
->selected_field
);
1658 bool variant_field_is_set(const struct bt_field
*field
)
1660 const struct bt_field_variant
*var_field
= (const void *) field
;
1661 bool is_set
= false;
1663 BT_ASSERT_DBG(field
);
1665 if (var_field
->selected_field
) {
1666 is_set
= bt_field_is_set(var_field
->selected_field
);
1673 bool array_field_is_set(const struct bt_field
*field
)
1677 const struct bt_field_array
*array_field
= (const void *) field
;
1679 BT_ASSERT_DBG(field
);
1681 for (i
= 0; i
< array_field
->length
; i
++) {
1682 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);