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/align.h"
17 #include "common/assert.h"
22 #include "field-class.h"
23 #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
);
194 struct bt_field_class
*bt_field_borrow_class(struct bt_field
*field
)
196 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
200 const struct bt_field_class
*bt_field_borrow_class_const(
201 const struct bt_field
*field
)
203 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
207 enum bt_field_class_type
bt_field_get_class_type(const struct bt_field
*field
)
209 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
210 return field
->class->type
;
214 struct bt_field
*bt_field_create(struct bt_field_class
*fc
)
216 struct bt_field
*field
= NULL
;
221 case BT_FIELD_CLASS_TYPE_BOOL
:
222 field
= create_bool_field(fc
);
224 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
225 field
= create_bit_array_field(fc
);
227 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
228 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
229 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
230 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
231 field
= create_integer_field(fc
);
233 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
234 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
235 field
= create_real_field(fc
);
237 case BT_FIELD_CLASS_TYPE_STRING
:
238 field
= create_string_field(fc
);
240 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
241 field
= create_structure_field(fc
);
243 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
244 field
= create_static_array_field(fc
);
246 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
247 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
248 field
= create_dynamic_array_field(fc
);
250 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
251 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
252 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
253 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
254 field
= create_option_field(fc
);
256 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
257 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
258 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
259 field
= create_variant_field(fc
);
266 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
276 void init_field(struct bt_field
*field
, struct bt_field_class
*fc
,
277 struct bt_field_methods
*methods
)
281 bt_object_init_unique(&field
->base
);
282 field
->methods
= methods
;
284 bt_object_get_ref_no_null_check(fc
);
288 struct bt_field
*create_bool_field(struct bt_field_class
*fc
)
290 struct bt_field_bool
*bool_field
;
292 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc
);
293 bool_field
= g_new0(struct bt_field_bool
, 1);
295 BT_LIB_LOGE_APPEND_CAUSE(
296 "Failed to allocate one boolean field.");
300 init_field((void *) bool_field
, fc
, &bool_field_methods
);
301 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field
);
304 return (void *) bool_field
;
308 struct bt_field
*create_bit_array_field(struct bt_field_class
*fc
)
310 struct bt_field_bit_array
*ba_field
;
312 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc
);
313 ba_field
= g_new0(struct bt_field_bit_array
, 1);
315 BT_LIB_LOGE_APPEND_CAUSE(
316 "Failed to allocate one bit array field.");
320 init_field((void *) ba_field
, fc
, &bit_array_field_methods
);
321 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field
);
324 return (void *) ba_field
;
328 struct bt_field
*create_integer_field(struct bt_field_class
*fc
)
330 struct bt_field_integer
*int_field
;
332 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc
);
333 int_field
= g_new0(struct bt_field_integer
, 1);
335 BT_LIB_LOGE_APPEND_CAUSE(
336 "Failed to allocate one integer field.");
340 init_field((void *) int_field
, fc
, &integer_field_methods
);
341 BT_LIB_LOGD("Created integer field object: %!+f", int_field
);
344 return (void *) int_field
;
348 struct bt_field
*create_real_field(struct bt_field_class
*fc
)
350 struct bt_field_real
*real_field
;
352 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc
);
353 real_field
= g_new0(struct bt_field_real
, 1);
355 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
359 init_field((void *) real_field
, fc
, &real_field_methods
);
360 BT_LIB_LOGD("Created real field object: %!+f", real_field
);
363 return (void *) real_field
;
367 struct bt_field
*create_string_field(struct bt_field_class
*fc
)
369 struct bt_field_string
*string_field
;
371 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc
);
372 string_field
= g_new0(struct bt_field_string
, 1);
374 BT_LIB_LOGE_APPEND_CAUSE(
375 "Failed to allocate one string field.");
379 init_field((void *) string_field
, fc
, &string_field_methods
);
380 string_field
->buf
= g_array_sized_new(FALSE
, FALSE
,
382 if (!string_field
->buf
) {
383 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
384 bt_field_destroy((void *) string_field
);
389 g_array_index(string_field
->buf
, char, 0) = '\0';
390 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
393 return (void *) string_field
;
397 int create_fields_from_named_field_classes(
398 struct bt_field_class_named_field_class_container
*fc
,
404 *fields
= g_ptr_array_new_with_free_func(
405 (GDestroyNotify
) bt_field_destroy
);
407 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
412 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
414 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
415 struct bt_field
*field
;
416 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
418 field
= bt_field_create(named_fc
->fc
);
420 BT_LIB_LOGE_APPEND_CAUSE(
421 "Failed to create structure member or variant option field: "
422 "name=\"%s\", %![fc-]+F",
423 named_fc
->name
->str
, named_fc
->fc
);
428 g_ptr_array_index(*fields
, i
) = field
;
436 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
438 struct bt_field_structure
*struct_field
;
440 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
441 struct_field
= g_new0(struct bt_field_structure
, 1);
443 BT_LIB_LOGE_APPEND_CAUSE(
444 "Failed to allocate one structure field.");
448 init_field((void *) struct_field
, fc
, &structure_field_methods
);
450 if (create_fields_from_named_field_classes((void *) fc
,
451 &struct_field
->fields
)) {
452 BT_LIB_LOGE_APPEND_CAUSE(
453 "Cannot create structure member fields: %![fc-]+F", fc
);
454 bt_field_destroy((void *) struct_field
);
459 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
462 return (void *) struct_field
;
466 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
468 struct bt_field_option
*opt_field
;
469 struct bt_field_class_option
*opt_fc
= (void *) fc
;
471 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
472 opt_field
= g_new0(struct bt_field_option
, 1);
474 BT_LIB_LOGE_APPEND_CAUSE(
475 "Failed to allocate one option field.");
479 init_field((void *) opt_field
, fc
, &option_field_methods
);
480 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
481 if (!opt_field
->content_field
) {
482 BT_LIB_LOGE_APPEND_CAUSE(
483 "Failed to create option field's content field: "
484 "%![opt-fc-]+F, %![content-fc-]+F",
485 opt_fc
, opt_fc
->content_fc
);
486 bt_field_destroy((void *) opt_field
);
491 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
494 return (void *) opt_field
;
498 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
500 struct bt_field_variant
*var_field
;
502 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
503 var_field
= g_new0(struct bt_field_variant
, 1);
505 BT_LIB_LOGE_APPEND_CAUSE(
506 "Failed to allocate one variant field.");
510 init_field((void *) var_field
, fc
, &variant_field_methods
);
512 if (create_fields_from_named_field_classes((void *) fc
,
513 &var_field
->fields
)) {
514 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
516 bt_field_destroy((void *) var_field
);
521 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
524 return (void *) var_field
;
528 int init_array_field_fields(struct bt_field_array
*array_field
)
532 struct bt_field_class_array
*array_fc
;
534 BT_ASSERT(array_field
);
535 array_fc
= (void *) array_field
->common
.class;
536 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
537 if (!array_field
->fields
) {
538 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
543 g_ptr_array_set_free_func(array_field
->fields
,
544 (GDestroyNotify
) bt_field_destroy
);
545 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
547 for (i
= 0; i
< array_field
->length
; i
++) {
548 array_field
->fields
->pdata
[i
] = bt_field_create(
549 array_fc
->element_fc
);
550 if (!array_field
->fields
->pdata
[i
]) {
551 BT_LIB_LOGE_APPEND_CAUSE(
552 "Cannot create array field's element field: "
553 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
564 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
566 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
567 struct bt_field_array
*array_field
;
569 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
570 array_field
= g_new0(struct bt_field_array
, 1);
572 BT_LIB_LOGE_APPEND_CAUSE(
573 "Failed to allocate one static array field.");
577 init_field((void *) array_field
, fc
, &array_field_methods
);
578 array_field
->length
= array_fc
->length
;
580 if (init_array_field_fields(array_field
)) {
581 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
583 bt_field_destroy((void *) 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_field_destroy((void *) array_field
);
617 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
620 return (void *) array_field
;
623 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
625 const struct bt_field_bool
*bool_field
= (const void *) field
;
627 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
628 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
629 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
630 "boolean-field", BT_FIELD_CLASS_TYPE_BOOL
, "Field");
631 return (bt_bool
) bool_field
->value
;
634 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
636 struct bt_field_bool
*bool_field
= (void *) field
;
638 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
639 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
640 "boolean-field", BT_FIELD_CLASS_TYPE_BOOL
, "Field");
641 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
642 bool_field
->value
= (bool) value
;
643 bt_field_set_single(field
, true);
646 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
648 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
650 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
651 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
652 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
653 "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
654 return ba_field
->value_as_int
;
657 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
660 struct bt_field_bit_array
*ba_field
= (void *) field
;
661 struct bt_field_class_bit_array
*ba_fc
;
663 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
664 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
665 "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
666 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
667 ba_fc
= (void *) field
->class;
668 ba_field
->value_as_int
= value
;
670 if (ba_fc
->length
< 64) {
672 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
675 bt_field_set_single(field
, true);
678 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
680 const struct bt_field_integer
*int_field
= (const void *) field
;
682 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
683 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
684 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field
, "Field");
685 return int_field
->value
.i
;
688 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
690 struct bt_field_integer
*int_field
= (void *) field
;
692 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
693 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field
, "Field");
694 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
695 BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
696 bt_util_value_is_in_range_signed(
697 ((struct bt_field_class_integer
*) field
->class)->range
,
699 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
700 "%![fc-]+F", value
, field
, field
->class);
701 int_field
->value
.i
= value
;
702 bt_field_set_single(field
, true);
705 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
707 const struct bt_field_integer
*int_field
= (const void *) field
;
709 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
710 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
711 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field
, "Field");
712 return int_field
->value
.u
;
715 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
717 struct bt_field_integer
*int_field
= (void *) field
;
719 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
720 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field
, "Field");
721 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
722 BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
723 bt_util_value_is_in_range_unsigned(
724 ((struct bt_field_class_integer
*) field
->class)->range
,
726 "Value is out of bounds: value=%" PRIu64
", %![field-]+f, "
727 "%![fc-]+F", value
, field
, field
->class);
728 int_field
->value
.u
= value
;
729 bt_field_set_single(field
, true);
732 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
734 const struct bt_field_real
*real_field
= (const void *) field
;
736 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
737 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
738 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
739 "single-precision-real-field",
740 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
741 return (float) real_field
->value
;
744 double bt_field_real_double_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 "double-precision-real-field",
752 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
753 return real_field
->value
;
756 void bt_field_real_single_precision_set_value(struct bt_field
*field
,
759 struct bt_field_real
*real_field
= (void *) field
;
761 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
762 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
763 "single-precision-real-field",
764 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
765 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
767 real_field
->value
= (double) value
;
768 bt_field_set_single(field
, true);
771 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
774 struct bt_field_real
*real_field
= (void *) field
;
776 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
777 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
778 "double-precision-real-field",
779 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
780 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
782 real_field
->value
= value
;
783 bt_field_set_single(field
, true);
786 enum bt_field_enumeration_get_mapping_labels_status
787 bt_field_enumeration_unsigned_get_mapping_labels(
788 const struct bt_field
*field
,
789 bt_field_class_enumeration_mapping_label_array
*label_array
,
792 const struct bt_field_integer
*int_field
= (const void *) field
;
794 BT_ASSERT_PRE_DEV_NO_ERROR();
795 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
796 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
797 "Label array (output)");
798 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
799 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
800 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
801 "unsigned-enumeration-field",
802 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
804 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
805 field
->class, int_field
->value
.u
, label_array
, count
);
808 enum bt_field_enumeration_get_mapping_labels_status
809 bt_field_enumeration_signed_get_mapping_labels(
810 const struct bt_field
*field
,
811 bt_field_class_enumeration_mapping_label_array
*label_array
,
814 const struct bt_field_integer
*int_field
= (const void *) field
;
816 BT_ASSERT_PRE_DEV_NO_ERROR();
817 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
818 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
819 "Label array (output)");
820 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
821 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
822 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
823 "signed-enumeration-field",
824 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
826 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
827 field
->class, int_field
->value
.i
, label_array
, count
);
830 const char *bt_field_string_get_value(const struct bt_field
*field
)
832 const struct bt_field_string
*string_field
= (const void *) field
;
834 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
835 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
836 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
837 BT_FIELD_CLASS_TYPE_STRING
, "Field");
838 return (const char *) string_field
->buf
->data
;
841 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
843 const struct bt_field_string
*string_field
= (const void *) field
;
845 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
846 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
847 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
848 BT_FIELD_CLASS_TYPE_STRING
, "Field");
849 return string_field
->length
;
853 void clear_string_field(struct bt_field
*field
)
855 struct bt_field_string
*string_field
= (void *) field
;
857 BT_ASSERT_DBG(field
);
858 string_field
->length
= 0;
859 g_array_index(string_field
->buf
, char, 0) = '\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_NO_ERROR();
867 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
868 BT_ASSERT_PRE_DEV_NON_NULL("value", value
, "Value");
869 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
870 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
871 BT_FIELD_CLASS_TYPE_STRING
, "Field");
872 clear_string_field(field
);
873 return (int) bt_field_string_append_with_length(field
, value
,
874 (uint64_t) strlen(value
));
877 #define BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(_field, _value, _length) \
879 BT_ASSERT_PRE_DEV_NO_ERROR(); \
880 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field); \
881 BT_ASSERT_PRE_DEV_NON_NULL("value", (_value), "Value"); \
882 BT_ASSERT_PRE_DEV_FIELD_HOT(_field); \
883 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", \
884 (_field), "string-field", \
885 BT_FIELD_CLASS_TYPE_STRING, "Field"); \
886 BT_ASSERT_PRE_DEV("value-has-no-null-byte", \
887 !memchr((_value), '\0', (_length)), \
888 "String value to append contains a null character: " \
889 "partial-value=\"%.32s\", length=%" PRIu64, \
890 (_value), (_length)); \
894 enum bt_field_string_append_status
append_to_string_field_with_length(
895 struct bt_field
*field
, const char *value
, uint64_t length
)
897 struct bt_field_string
*string_field
= (void *) field
;
901 BT_ASSERT_DBG(field
);
902 BT_ASSERT_DBG(value
);
903 new_length
= length
+ string_field
->length
;
905 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
906 g_array_set_size(string_field
->buf
, new_length
+ 1);
909 data
= string_field
->buf
->data
;
910 memcpy(data
+ string_field
->length
, value
, length
);
911 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
912 string_field
->length
= new_length
;
913 bt_field_set_single(field
, true);
914 return BT_FUNC_STATUS_OK
;
917 enum bt_field_string_append_status
bt_field_string_append_with_length(
918 struct bt_field
*field
, const char *value
, uint64_t length
)
920 BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field
, value
,
922 return append_to_string_field_with_length(field
, value
, length
);
925 enum bt_field_string_append_status
bt_field_string_append(
926 struct bt_field
*field
, const char *value
)
928 uint64_t length
= (uint64_t) strlen(value
);
930 BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field
, value
,
932 return append_to_string_field_with_length(field
, value
, length
);
935 void bt_field_string_clear(struct bt_field
*field
)
937 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
938 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
939 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
940 BT_FIELD_CLASS_TYPE_STRING
, "Field");
941 clear_string_field(field
);
944 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
946 const struct bt_field_array
*array_field
= (const void *) field
;
948 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
949 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY("field", field
, "Field");
950 return array_field
->length
;
953 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
954 struct bt_field
*field
, uint64_t length
)
956 int ret
= BT_FUNC_STATUS_OK
;
957 struct bt_field_array
*array_field
= (void *) field
;
959 BT_ASSERT_PRE_DEV_NO_ERROR();
960 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
961 BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY("field", field
, "Field");
962 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
964 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
966 struct bt_field_class_array
*array_fc
;
967 uint64_t cur_len
= array_field
->fields
->len
;
970 g_ptr_array_set_size(array_field
->fields
, length
);
971 array_fc
= (void *) field
->class;
973 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
974 struct bt_field
*elem_field
= bt_field_create(
975 array_fc
->element_fc
);
978 BT_LIB_LOGE_APPEND_CAUSE(
979 "Cannot create element field for "
980 "dynamic array field: "
981 "index=%" PRIu64
", "
982 "%![array-field-]+f", i
, field
);
983 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
987 BT_ASSERT_DBG(!array_field
->fields
->pdata
[i
]);
988 array_field
->fields
->pdata
[i
] = elem_field
;
992 array_field
->length
= length
;
999 struct bt_field
*borrow_array_field_element_field_by_index(
1000 struct bt_field
*field
, uint64_t index
, const char *api_func
)
1002 struct bt_field_array
*array_field
= (void *) field
;
1004 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1005 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY_FROM_FUNC(api_func
, "field", field
,
1007 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1008 array_field
->length
);
1009 return array_field
->fields
->pdata
[index
];
1012 struct bt_field
*bt_field_array_borrow_element_field_by_index(
1013 struct bt_field
*field
, uint64_t index
)
1015 return borrow_array_field_element_field_by_index(field
, index
,
1019 const struct bt_field
*
1020 bt_field_array_borrow_element_field_by_index_const(
1021 const struct bt_field
*field
, uint64_t index
)
1023 return borrow_array_field_element_field_by_index((void *) field
, index
,
1028 struct bt_field
*borrow_structure_field_member_field_by_index(
1029 struct bt_field
*field
, uint64_t index
, const char *api_func
)
1031 struct bt_field_structure
*struct_field
= (void *) field
;
1033 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1034 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func
, "field",
1035 field
, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE
,
1037 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1038 struct_field
->fields
->len
);
1039 return struct_field
->fields
->pdata
[index
];
1042 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1043 struct bt_field
*field
, uint64_t index
)
1045 return borrow_structure_field_member_field_by_index(field
,
1049 const struct bt_field
*
1050 bt_field_structure_borrow_member_field_by_index_const(
1051 const struct bt_field
*field
, uint64_t index
)
1053 return borrow_structure_field_member_field_by_index(
1054 (void *) field
, index
, __func__
);
1058 struct bt_field
*borrow_structure_field_member_field_by_name(
1059 struct bt_field
*field
, const char *name
, const char *api_func
)
1061 struct bt_field
*ret_field
= NULL
;
1062 struct bt_field_class_structure
*struct_fc
;
1063 struct bt_field_structure
*struct_field
= (void *) field
;
1067 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1068 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "member-name", name
,
1070 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func
, "field",
1071 field
, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE
,
1073 struct_fc
= (void *) field
->class;
1075 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1076 &orig_key
, &index
)) {
1080 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1081 BT_ASSERT_DBG(ret_field
);
1087 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1088 struct bt_field
*field
, const char *name
)
1090 return borrow_structure_field_member_field_by_name(field
, name
,
1094 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1095 const struct bt_field
*field
, const char *name
)
1097 return borrow_structure_field_member_field_by_name(
1098 (void *) field
, name
, __func__
);
1101 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1103 struct bt_field_option
*opt_field
= (void *) field
;
1105 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1106 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field
, "Field");
1107 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
1110 opt_field
->selected_field
= opt_field
->content_field
;
1112 opt_field
->selected_field
= NULL
;
1116 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1118 struct bt_field_option
*opt_field
= (void *) field
;
1120 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1121 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field
, "Field");
1122 return opt_field
->selected_field
;
1125 const struct bt_field
*bt_field_option_borrow_field_const(
1126 const struct bt_field
*field
)
1128 return (const void *) bt_field_option_borrow_field((void *) field
);
1131 #define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(_field) \
1133 struct bt_field_variant *_var_field = (void *) field; \
1134 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field); \
1135 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", (_field), \
1137 BT_ASSERT_PRE_DEV("has-selected-field", \
1138 _var_field->selected_field, \
1139 "Variant field has no selected field: %!+f", \
1144 struct bt_field
*borrow_variant_field_selected_option_field(
1145 struct bt_field
*field
)
1147 struct bt_field_variant
*var_field
= (void *) field
;
1149 BT_ASSERT_DBG(field
);
1150 return var_field
->selected_field
;
1153 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1154 struct bt_field
*field
)
1156 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field
);
1157 return borrow_variant_field_selected_option_field(field
);
1160 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1161 const struct bt_field
*field
)
1163 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field
);
1164 return borrow_variant_field_selected_option_field((void *) field
);
1167 #define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(_field) \
1169 struct bt_field_variant *_var_field = (void *) field; \
1170 BT_ASSERT_PRE_DEV("has-selected-field", \
1171 _var_field->selected_field, \
1172 "Variant field has no selected field: %!+f", \
1177 const struct bt_field_class_variant_option
*
1178 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1180 const struct bt_field_class_named_field_class_container
*container_fc
;
1181 const struct bt_field_variant
*var_field
= (const void *) field
;
1183 BT_ASSERT_DBG(field
);
1184 container_fc
= (const void *) field
->class;
1185 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1188 const struct bt_field_class_variant_option
*
1189 bt_field_variant_borrow_selected_option_class_const(
1190 const struct bt_field
*field
)
1192 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1193 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1194 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1195 return borrow_variant_field_selected_class_option(field
);
1198 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1199 bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_const(
1200 const struct bt_field
*field
)
1202 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1203 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
1204 "variant-field-with-unsigned-selector-field",
1205 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1207 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1208 return (const void *) borrow_variant_field_selected_class_option(field
);
1211 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1212 bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_const(
1213 const struct bt_field
*field
)
1215 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1216 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
1217 "variant-field-with-signed-selector-field",
1218 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1220 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1221 return (const void *) borrow_variant_field_selected_class_option(field
);
1224 enum bt_field_variant_select_option_by_index_status
1225 bt_field_variant_select_option_by_index(
1226 struct bt_field
*field
, uint64_t index
)
1228 struct bt_field_variant
*var_field
= (void *) field
;
1230 BT_ASSERT_PRE_DEV_NO_ERROR();
1231 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1232 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1233 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
1234 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1235 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1236 var_field
->selected_index
= index
;
1237 return BT_FUNC_STATUS_OK
;
1240 uint64_t bt_field_variant_get_selected_option_index(
1241 const struct bt_field
*field
)
1243 const struct bt_field_variant
*var_field
= (const void *) field
;
1245 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1246 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1247 BT_ASSERT_PRE_DEV("has-selected-field", var_field
->selected_field
,
1248 "Variant field has no selected field: %!+f", field
);
1249 return var_field
->selected_index
;
1253 void bt_field_finalize(struct bt_field
*field
)
1256 BT_LOGD_STR("Putting field's class.");
1257 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1261 void destroy_bool_field(struct bt_field
*field
)
1264 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1265 bt_field_finalize(field
);
1270 void destroy_bit_array_field(struct bt_field
*field
)
1273 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1274 bt_field_finalize(field
);
1279 void destroy_integer_field(struct bt_field
*field
)
1282 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1283 bt_field_finalize(field
);
1288 void destroy_real_field(struct bt_field
*field
)
1291 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1292 bt_field_finalize(field
);
1297 void destroy_structure_field(struct bt_field
*field
)
1299 struct bt_field_structure
*struct_field
= (void *) field
;
1302 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1303 bt_field_finalize(field
);
1305 if (struct_field
->fields
) {
1306 g_ptr_array_free(struct_field
->fields
, TRUE
);
1307 struct_field
->fields
= NULL
;
1314 void destroy_option_field(struct bt_field
*field
)
1316 struct bt_field_option
*opt_field
= (void *) field
;
1319 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1320 bt_field_finalize(field
);
1322 if (opt_field
->content_field
) {
1323 bt_field_destroy(opt_field
->content_field
);
1330 void destroy_variant_field(struct bt_field
*field
)
1332 struct bt_field_variant
*var_field
= (void *) field
;
1335 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1336 bt_field_finalize(field
);
1338 if (var_field
->fields
) {
1339 g_ptr_array_free(var_field
->fields
, TRUE
);
1340 var_field
->fields
= NULL
;
1347 void destroy_array_field(struct bt_field
*field
)
1349 struct bt_field_array
*array_field
= (void *) field
;
1352 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1353 bt_field_finalize(field
);
1355 if (array_field
->fields
) {
1356 g_ptr_array_free(array_field
->fields
, TRUE
);
1357 array_field
->fields
= NULL
;
1364 void destroy_string_field(struct bt_field
*field
)
1366 struct bt_field_string
*string_field
= (void *) field
;
1369 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1370 bt_field_finalize(field
);
1372 if (string_field
->buf
) {
1373 g_array_free(string_field
->buf
, TRUE
);
1374 string_field
->buf
= NULL
;
1381 void bt_field_destroy(struct bt_field
*field
)
1385 switch (field
->class->type
) {
1386 case BT_FIELD_CLASS_TYPE_BOOL
:
1387 destroy_bool_field(field
);
1389 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
1390 destroy_bit_array_field(field
);
1392 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1393 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1394 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1395 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1396 destroy_integer_field(field
);
1398 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
1399 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
1400 destroy_real_field(field
);
1402 case BT_FIELD_CLASS_TYPE_STRING
:
1403 destroy_string_field(field
);
1405 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1406 destroy_structure_field(field
);
1408 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1409 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
1410 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
1411 destroy_array_field(field
);
1413 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
1414 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
1415 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1416 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1417 destroy_option_field(field
);
1419 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
1420 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1421 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1422 destroy_variant_field(field
);
1430 void reset_single_field(struct bt_field
*field
)
1432 BT_ASSERT_DBG(field
);
1433 field
->is_set
= false;
1437 void reset_structure_field(struct bt_field
*field
)
1440 struct bt_field_structure
*struct_field
= (void *) field
;
1442 BT_ASSERT_DBG(field
);
1444 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1445 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1450 void reset_option_field(struct bt_field
*field
)
1452 struct bt_field_option
*opt_field
= (void *) field
;
1454 BT_ASSERT_DBG(opt_field
);
1455 bt_field_reset(opt_field
->content_field
);
1456 opt_field
->selected_field
= NULL
;
1460 void reset_variant_field(struct bt_field
*field
)
1463 struct bt_field_variant
*var_field
= (void *) field
;
1465 BT_ASSERT_DBG(field
);
1467 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1468 bt_field_reset(var_field
->fields
->pdata
[i
]);
1473 void reset_array_field(struct bt_field
*field
)
1476 struct bt_field_array
*array_field
= (void *) field
;
1478 BT_ASSERT_DBG(field
);
1480 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1481 bt_field_reset(array_field
->fields
->pdata
[i
]);
1486 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1488 field
->frozen
= is_frozen
;
1492 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1495 struct bt_field_structure
*struct_field
= (void *) field
;
1497 BT_LIB_LOGD("Setting structure field's frozen state: "
1498 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1500 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1501 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1503 BT_LIB_LOGD("Setting structure field's member field's "
1504 "frozen state: %![field-]+f, index=%" PRIu64
,
1506 _bt_field_set_is_frozen(member_field
, is_frozen
);
1509 set_single_field_is_frozen(field
, is_frozen
);
1513 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1515 struct bt_field_option
*opt_field
= (void *) field
;
1517 BT_LIB_LOGD("Setting option field's frozen state: "
1518 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1519 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1520 set_single_field_is_frozen(field
, is_frozen
);
1524 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1527 struct bt_field_variant
*var_field
= (void *) field
;
1529 BT_LIB_LOGD("Setting variant field's frozen state: "
1530 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1532 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1533 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1535 BT_LIB_LOGD("Setting variant field's option field's "
1536 "frozen state: %![field-]+f, index=%" PRIu64
,
1538 _bt_field_set_is_frozen(option_field
, is_frozen
);
1541 set_single_field_is_frozen(field
, is_frozen
);
1545 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1548 struct bt_field_array
*array_field
= (void *) field
;
1550 BT_LIB_LOGD("Setting array field's frozen state: "
1551 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1553 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1554 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1556 BT_LIB_LOGD("Setting array field's element field's "
1557 "frozen state: %![field-]+f, index=%" PRIu64
,
1559 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1562 set_single_field_is_frozen(field
, is_frozen
);
1566 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1569 BT_ASSERT_DBG(field
);
1570 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1572 BT_ASSERT_DBG(field
->methods
->set_is_frozen
);
1573 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1577 bool single_field_is_set(const struct bt_field
*field
)
1579 BT_ASSERT_DBG(field
);
1580 return field
->is_set
;
1584 bool structure_field_is_set(const struct bt_field
*field
)
1588 const struct bt_field_structure
*struct_field
= (const void *) field
;
1590 BT_ASSERT_DBG(field
);
1592 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1593 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1604 bool option_field_is_set(const struct bt_field
*field
)
1606 const struct bt_field_option
*opt_field
= (const void *) field
;
1607 bool is_set
= false;
1609 BT_ASSERT_DBG(field
);
1611 if (opt_field
->selected_field
) {
1612 is_set
= bt_field_is_set(opt_field
->selected_field
);
1619 bool variant_field_is_set(const struct bt_field
*field
)
1621 const struct bt_field_variant
*var_field
= (const void *) field
;
1622 bool is_set
= false;
1624 BT_ASSERT_DBG(field
);
1626 if (var_field
->selected_field
) {
1627 is_set
= bt_field_is_set(var_field
->selected_field
);
1634 bool array_field_is_set(const struct bt_field
*field
)
1638 const struct bt_field_array
*array_field
= (const void *) field
;
1640 BT_ASSERT_DBG(field
);
1642 for (i
= 0; i
< array_field
->length
; i
++) {
1643 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);