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
);
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_index(string_field
->buf
, char, 0) = '\0';
392 BT_LIB_LOGD("Created string field object: %!+f", string_field
);
395 return (void *) string_field
;
399 int create_fields_from_named_field_classes(
400 struct bt_field_class_named_field_class_container
*fc
,
406 *fields
= g_ptr_array_new_with_free_func(
407 (GDestroyNotify
) bt_field_destroy
);
409 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
414 g_ptr_array_set_size(*fields
, fc
->named_fcs
->len
);
416 for (i
= 0; i
< fc
->named_fcs
->len
; i
++) {
417 struct bt_field
*field
;
418 struct bt_named_field_class
*named_fc
= fc
->named_fcs
->pdata
[i
];
420 field
= bt_field_create(named_fc
->fc
);
422 BT_LIB_LOGE_APPEND_CAUSE(
423 "Failed to create structure member or variant option field: "
424 "name=\"%s\", %![fc-]+F",
425 named_fc
->name
->str
, named_fc
->fc
);
430 g_ptr_array_index(*fields
, i
) = field
;
438 struct bt_field
*create_structure_field(struct bt_field_class
*fc
)
440 struct bt_field_structure
*struct_field
;
442 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc
);
443 struct_field
= g_new0(struct bt_field_structure
, 1);
445 BT_LIB_LOGE_APPEND_CAUSE(
446 "Failed to allocate one structure field.");
450 init_field((void *) struct_field
, fc
, &structure_field_methods
);
452 if (create_fields_from_named_field_classes((void *) fc
,
453 &struct_field
->fields
)) {
454 BT_LIB_LOGE_APPEND_CAUSE(
455 "Cannot create structure member fields: %![fc-]+F", fc
);
456 bt_field_destroy((void *) struct_field
);
461 BT_LIB_LOGD("Created structure field object: %!+f", struct_field
);
464 return (void *) struct_field
;
468 struct bt_field
*create_option_field(struct bt_field_class
*fc
)
470 struct bt_field_option
*opt_field
;
471 struct bt_field_class_option
*opt_fc
= (void *) fc
;
473 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc
);
474 opt_field
= g_new0(struct bt_field_option
, 1);
476 BT_LIB_LOGE_APPEND_CAUSE(
477 "Failed to allocate one option field.");
481 init_field((void *) opt_field
, fc
, &option_field_methods
);
482 opt_field
->content_field
= bt_field_create(opt_fc
->content_fc
);
483 if (!opt_field
->content_field
) {
484 BT_LIB_LOGE_APPEND_CAUSE(
485 "Failed to create option field's content field: "
486 "%![opt-fc-]+F, %![content-fc-]+F",
487 opt_fc
, opt_fc
->content_fc
);
488 bt_field_destroy((void *) opt_field
);
493 BT_LIB_LOGD("Created option field object: %!+f", opt_field
);
496 return (void *) opt_field
;
500 struct bt_field
*create_variant_field(struct bt_field_class
*fc
)
502 struct bt_field_variant
*var_field
;
504 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc
);
505 var_field
= g_new0(struct bt_field_variant
, 1);
507 BT_LIB_LOGE_APPEND_CAUSE(
508 "Failed to allocate one variant field.");
512 init_field((void *) var_field
, fc
, &variant_field_methods
);
514 if (create_fields_from_named_field_classes((void *) fc
,
515 &var_field
->fields
)) {
516 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
518 bt_field_destroy((void *) var_field
);
523 BT_LIB_LOGD("Created variant field object: %!+f", var_field
);
526 return (void *) var_field
;
530 int init_array_field_fields(struct bt_field_array
*array_field
)
534 struct bt_field_class_array
*array_fc
;
536 BT_ASSERT(array_field
);
537 array_fc
= (void *) array_field
->common
.class;
538 array_field
->fields
= g_ptr_array_sized_new(array_field
->length
);
539 if (!array_field
->fields
) {
540 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
545 g_ptr_array_set_free_func(array_field
->fields
,
546 (GDestroyNotify
) bt_field_destroy
);
547 g_ptr_array_set_size(array_field
->fields
, array_field
->length
);
549 for (i
= 0; i
< array_field
->length
; i
++) {
550 array_field
->fields
->pdata
[i
] = bt_field_create(
551 array_fc
->element_fc
);
552 if (!array_field
->fields
->pdata
[i
]) {
553 BT_LIB_LOGE_APPEND_CAUSE(
554 "Cannot create array field's element field: "
555 "index=%" PRIu64
", %![fc-]+F", i
, array_fc
);
566 struct bt_field
*create_static_array_field(struct bt_field_class
*fc
)
568 struct bt_field_class_array_static
*array_fc
= (void *) fc
;
569 struct bt_field_array
*array_field
;
571 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc
);
572 array_field
= g_new0(struct bt_field_array
, 1);
574 BT_LIB_LOGE_APPEND_CAUSE(
575 "Failed to allocate one static array field.");
579 init_field((void *) array_field
, fc
, &array_field_methods
);
580 array_field
->length
= array_fc
->length
;
582 if (init_array_field_fields(array_field
)) {
583 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
585 bt_field_destroy((void *) array_field
);
590 BT_LIB_LOGD("Created static array field object: %!+f", array_field
);
593 return (void *) array_field
;
597 struct bt_field
*create_dynamic_array_field(struct bt_field_class
*fc
)
599 struct bt_field_array
*array_field
;
601 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc
);
602 array_field
= g_new0(struct bt_field_array
, 1);
604 BT_LIB_LOGE_APPEND_CAUSE(
605 "Failed to allocate one dynamic array field.");
609 init_field((void *) array_field
, fc
, &array_field_methods
);
611 if (init_array_field_fields(array_field
)) {
612 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
614 bt_field_destroy((void *) array_field
);
619 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field
);
622 return (void *) array_field
;
626 bt_bool
bt_field_bool_get_value(const struct bt_field
*field
)
628 const struct bt_field_bool
*bool_field
= (const void *) field
;
630 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
631 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
632 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
633 "boolean-field", BT_FIELD_CLASS_TYPE_BOOL
, "Field");
634 return (bt_bool
) bool_field
->value
;
638 void bt_field_bool_set_value(struct bt_field
*field
, bt_bool value
)
640 struct bt_field_bool
*bool_field
= (void *) field
;
642 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
643 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
644 "boolean-field", BT_FIELD_CLASS_TYPE_BOOL
, "Field");
645 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
646 bool_field
->value
= (bool) value
;
647 bt_field_set_single(field
, true);
651 uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field
*field
)
653 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
655 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
656 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
657 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
658 "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
659 return ba_field
->value_as_int
;
663 void bt_field_bit_array_set_value_as_integer(struct bt_field
*field
,
666 struct bt_field_bit_array
*ba_field
= (void *) field
;
667 struct bt_field_class_bit_array
*ba_fc
;
669 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
670 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
671 "bit-array-field", BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field");
672 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
673 ba_fc
= (void *) field
->class;
674 ba_field
->value_as_int
= value
;
676 if (ba_fc
->length
< 64) {
678 ba_field
->value_as_int
&= ((UINT64_C(1) << ba_fc
->length
) - 1);
681 bt_field_set_single(field
, true);
685 int64_t bt_field_integer_signed_get_value(const struct bt_field
*field
)
687 const struct bt_field_integer
*int_field
= (const void *) field
;
689 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
690 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
691 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field
, "Field");
692 return int_field
->value
.i
;
696 void bt_field_integer_signed_set_value(struct bt_field
*field
, int64_t value
)
698 struct bt_field_integer
*int_field
= (void *) field
;
700 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
701 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT("field", field
, "Field");
702 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
703 BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
704 bt_util_value_is_in_range_signed(
705 ((struct bt_field_class_integer
*) field
->class)->range
,
707 "Value is out of bounds: value=%" PRId64
", %![field-]+f, "
708 "%![fc-]+F", value
, field
, field
->class);
709 int_field
->value
.i
= value
;
710 bt_field_set_single(field
, true);
714 uint64_t bt_field_integer_unsigned_get_value(const struct bt_field
*field
)
716 const struct bt_field_integer
*int_field
= (const void *) field
;
718 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
719 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
720 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field
, "Field");
721 return int_field
->value
.u
;
725 void bt_field_integer_unsigned_set_value(struct bt_field
*field
, uint64_t value
)
727 struct bt_field_integer
*int_field
= (void *) field
;
729 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
730 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT("field", field
, "Field");
731 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
732 BT_ASSERT_PRE_DEV("valid-value-for-field-class-field-value-range",
733 bt_util_value_is_in_range_unsigned(
734 ((struct bt_field_class_integer
*) field
->class)->range
,
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);
743 float bt_field_real_single_precision_get_value(const struct bt_field
*field
)
745 const struct bt_field_real
*real_field
= (const void *) field
;
747 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
748 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
749 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
750 "single-precision-real-field",
751 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
752 return (float) real_field
->value
;
756 double bt_field_real_double_precision_get_value(const struct bt_field
*field
)
758 const struct bt_field_real
*real_field
= (const void *) field
;
760 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
761 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
762 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
763 "double-precision-real-field",
764 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
765 return real_field
->value
;
769 void bt_field_real_single_precision_set_value(struct bt_field
*field
,
772 struct bt_field_real
*real_field
= (void *) field
;
774 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
775 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
776 "single-precision-real-field",
777 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
, "Field");
778 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
780 real_field
->value
= (double) value
;
781 bt_field_set_single(field
, true);
785 void bt_field_real_double_precision_set_value(struct bt_field
*field
,
788 struct bt_field_real
*real_field
= (void *) field
;
790 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
791 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
792 "double-precision-real-field",
793 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
, "Field");
794 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
796 real_field
->value
= value
;
797 bt_field_set_single(field
, true);
801 enum bt_field_enumeration_get_mapping_labels_status
802 bt_field_enumeration_unsigned_get_mapping_labels(
803 const struct bt_field
*field
,
804 bt_field_class_enumeration_mapping_label_array
*label_array
,
807 const struct bt_field_integer
*int_field
= (const void *) field
;
809 BT_ASSERT_PRE_DEV_NO_ERROR();
810 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
811 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
812 "Label array (output)");
813 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
814 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
815 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
816 "unsigned-enumeration-field",
817 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field");
819 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
820 field
->class, int_field
->value
.u
, label_array
, count
);
824 enum bt_field_enumeration_get_mapping_labels_status
825 bt_field_enumeration_signed_get_mapping_labels(
826 const struct bt_field
*field
,
827 bt_field_class_enumeration_mapping_label_array
*label_array
,
830 const struct bt_field_integer
*int_field
= (const void *) field
;
832 BT_ASSERT_PRE_DEV_NO_ERROR();
833 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
834 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
835 "Label array (output)");
836 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
837 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
838 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
839 "signed-enumeration-field",
840 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field");
842 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
843 field
->class, int_field
->value
.i
, label_array
, count
);
847 const char *bt_field_string_get_value(const struct bt_field
*field
)
849 const struct bt_field_string
*string_field
= (const void *) field
;
851 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
852 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
853 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
854 BT_FIELD_CLASS_TYPE_STRING
, "Field");
855 return (const char *) string_field
->buf
->data
;
859 uint64_t bt_field_string_get_length(const struct bt_field
*field
)
861 const struct bt_field_string
*string_field
= (const void *) field
;
863 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
864 BT_ASSERT_PRE_DEV_FIELD_IS_SET("field", field
);
865 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
866 BT_FIELD_CLASS_TYPE_STRING
, "Field");
867 return string_field
->length
;
871 void clear_string_field(struct bt_field
*field
)
873 struct bt_field_string
*string_field
= (void *) field
;
875 BT_ASSERT_DBG(field
);
876 string_field
->length
= 0;
877 g_array_index(string_field
->buf
, char, 0) = '\0';
878 bt_field_set_single(field
, true);
882 enum bt_field_string_set_value_status
bt_field_string_set_value(
883 struct bt_field
*field
, const char *value
)
885 BT_ASSERT_PRE_DEV_NO_ERROR();
886 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
887 BT_ASSERT_PRE_DEV_NON_NULL("value", value
, "Value");
888 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
889 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
890 BT_FIELD_CLASS_TYPE_STRING
, "Field");
891 clear_string_field(field
);
892 return (int) bt_field_string_append_with_length(field
, value
,
893 (uint64_t) strlen(value
));
896 #define BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(_field, _value, _length) \
898 BT_ASSERT_PRE_DEV_NO_ERROR(); \
899 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field); \
900 BT_ASSERT_PRE_DEV_NON_NULL("value", (_value), "Value"); \
901 BT_ASSERT_PRE_DEV_FIELD_HOT(_field); \
902 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", \
903 (_field), "string-field", \
904 BT_FIELD_CLASS_TYPE_STRING, "Field"); \
905 BT_ASSERT_PRE_DEV("value-has-no-null-byte", \
906 !memchr((_value), '\0', (_length)), \
907 "String value to append contains a null character: " \
908 "partial-value=\"%.32s\", length=%" PRIu64, \
909 (_value), (_length)); \
913 enum bt_field_string_append_status
append_to_string_field_with_length(
914 struct bt_field
*field
, const char *value
, uint64_t length
)
916 struct bt_field_string
*string_field
= (void *) field
;
920 BT_ASSERT_DBG(field
);
921 BT_ASSERT_DBG(value
);
922 new_length
= length
+ string_field
->length
;
924 if (G_UNLIKELY(new_length
+ 1 > string_field
->buf
->len
)) {
925 g_array_set_size(string_field
->buf
, new_length
+ 1);
928 data
= string_field
->buf
->data
;
929 memcpy(data
+ string_field
->length
, value
, length
);
930 ((char *) string_field
->buf
->data
)[new_length
] = '\0';
931 string_field
->length
= new_length
;
932 bt_field_set_single(field
, true);
933 return BT_FUNC_STATUS_OK
;
937 enum bt_field_string_append_status
bt_field_string_append_with_length(
938 struct bt_field
*field
, const char *value
, uint64_t length
)
940 BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field
, value
,
942 return append_to_string_field_with_length(field
, value
, length
);
946 enum bt_field_string_append_status
bt_field_string_append(
947 struct bt_field
*field
, const char *value
)
949 uint64_t length
= (uint64_t) strlen(value
);
951 BT_ASSERT_PRE_DEV_FOR_APPEND_TO_STRING_FIELD_WITH_LENGTH(field
, value
,
953 return append_to_string_field_with_length(field
, value
, length
);
957 void bt_field_string_clear(struct bt_field
*field
)
959 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
960 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
961 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
, "string-field",
962 BT_FIELD_CLASS_TYPE_STRING
, "Field");
963 clear_string_field(field
);
967 uint64_t bt_field_array_get_length(const struct bt_field
*field
)
969 const struct bt_field_array
*array_field
= (const void *) field
;
971 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
972 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY("field", field
, "Field");
973 return array_field
->length
;
977 enum bt_field_array_dynamic_set_length_status
bt_field_array_dynamic_set_length(
978 struct bt_field
*field
, uint64_t length
)
980 int ret
= BT_FUNC_STATUS_OK
;
981 struct bt_field_array
*array_field
= (void *) field
;
983 BT_ASSERT_PRE_DEV_NO_ERROR();
984 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
985 BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY("field", field
, "Field");
986 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
988 if (G_UNLIKELY(length
> array_field
->fields
->len
)) {
990 struct bt_field_class_array
*array_fc
;
991 uint64_t cur_len
= array_field
->fields
->len
;
994 g_ptr_array_set_size(array_field
->fields
, length
);
995 array_fc
= (void *) field
->class;
997 for (i
= cur_len
; i
< array_field
->fields
->len
; i
++) {
998 struct bt_field
*elem_field
= bt_field_create(
999 array_fc
->element_fc
);
1002 BT_LIB_LOGE_APPEND_CAUSE(
1003 "Cannot create element field for "
1004 "dynamic array field: "
1005 "index=%" PRIu64
", "
1006 "%![array-field-]+f", i
, field
);
1007 ret
= BT_FUNC_STATUS_MEMORY_ERROR
;
1011 BT_ASSERT_DBG(!array_field
->fields
->pdata
[i
]);
1012 array_field
->fields
->pdata
[i
] = elem_field
;
1016 array_field
->length
= length
;
1023 struct bt_field
*borrow_array_field_element_field_by_index(
1024 struct bt_field
*field
, uint64_t index
, const char *api_func
)
1026 struct bt_field_array
*array_field
= (void *) field
;
1028 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1029 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY_FROM_FUNC(api_func
, "field", field
,
1031 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1032 array_field
->length
);
1033 return array_field
->fields
->pdata
[index
];
1037 struct bt_field
*bt_field_array_borrow_element_field_by_index(
1038 struct bt_field
*field
, uint64_t index
)
1040 return borrow_array_field_element_field_by_index(field
, index
,
1045 const struct bt_field
*
1046 bt_field_array_borrow_element_field_by_index_const(
1047 const struct bt_field
*field
, uint64_t index
)
1049 return borrow_array_field_element_field_by_index((void *) field
, index
,
1054 struct bt_field
*borrow_structure_field_member_field_by_index(
1055 struct bt_field
*field
, uint64_t index
, const char *api_func
)
1057 struct bt_field_structure
*struct_field
= (void *) field
;
1059 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1060 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func
, "field",
1061 field
, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE
,
1063 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1064 struct_field
->fields
->len
);
1065 return struct_field
->fields
->pdata
[index
];
1069 struct bt_field
*bt_field_structure_borrow_member_field_by_index(
1070 struct bt_field
*field
, uint64_t index
)
1072 return borrow_structure_field_member_field_by_index(field
,
1077 const struct bt_field
*
1078 bt_field_structure_borrow_member_field_by_index_const(
1079 const struct bt_field
*field
, uint64_t index
)
1081 return borrow_structure_field_member_field_by_index(
1082 (void *) field
, index
, __func__
);
1086 struct bt_field
*borrow_structure_field_member_field_by_name(
1087 struct bt_field
*field
, const char *name
, const char *api_func
)
1089 struct bt_field
*ret_field
= NULL
;
1090 struct bt_field_class_structure
*struct_fc
;
1091 struct bt_field_structure
*struct_field
= (void *) field
;
1095 BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(api_func
, field
);
1096 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "member-name", name
,
1098 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(api_func
, "field",
1099 field
, "structure-field", BT_FIELD_CLASS_TYPE_STRUCTURE
,
1101 struct_fc
= (void *) field
->class;
1103 if (!g_hash_table_lookup_extended(struct_fc
->common
.name_to_index
, name
,
1104 &orig_key
, &index
)) {
1108 ret_field
= struct_field
->fields
->pdata
[GPOINTER_TO_UINT(index
)];
1109 BT_ASSERT_DBG(ret_field
);
1116 struct bt_field
*bt_field_structure_borrow_member_field_by_name(
1117 struct bt_field
*field
, const char *name
)
1119 return borrow_structure_field_member_field_by_name(field
, name
,
1124 const struct bt_field
*bt_field_structure_borrow_member_field_by_name_const(
1125 const struct bt_field
*field
, const char *name
)
1127 return borrow_structure_field_member_field_by_name(
1128 (void *) field
, name
, __func__
);
1132 void bt_field_option_set_has_field(struct bt_field
*field
, bt_bool has_field
)
1134 struct bt_field_option
*opt_field
= (void *) field
;
1136 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1137 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field
, "Field");
1138 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
1141 opt_field
->selected_field
= opt_field
->content_field
;
1143 opt_field
->selected_field
= NULL
;
1148 struct bt_field
*bt_field_option_borrow_field(struct bt_field
*field
)
1150 struct bt_field_option
*opt_field
= (void *) field
;
1152 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1153 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION("field", field
, "Field");
1154 return opt_field
->selected_field
;
1158 const struct bt_field
*bt_field_option_borrow_field_const(
1159 const struct bt_field
*field
)
1161 return (const void *) bt_field_option_borrow_field((void *) field
);
1164 #define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(_field) \
1166 struct bt_field_variant *_var_field = (void *) field; \
1167 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field); \
1168 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", (_field), \
1170 BT_ASSERT_PRE_DEV("has-selected-field", \
1171 _var_field->selected_field, \
1172 "Variant field has no selected field: %!+f", \
1177 struct bt_field
*borrow_variant_field_selected_option_field(
1178 struct bt_field
*field
)
1180 struct bt_field_variant
*var_field
= (void *) field
;
1182 BT_ASSERT_DBG(field
);
1183 return var_field
->selected_field
;
1187 struct bt_field
*bt_field_variant_borrow_selected_option_field(
1188 struct bt_field
*field
)
1190 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field
);
1191 return borrow_variant_field_selected_option_field(field
);
1195 const struct bt_field
*bt_field_variant_borrow_selected_option_field_const(
1196 const struct bt_field
*field
)
1198 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_OPT_FIELD(field
);
1199 return borrow_variant_field_selected_option_field((void *) field
);
1202 #define BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(_field) \
1204 struct bt_field_variant *_var_field = (void *) field; \
1205 BT_ASSERT_PRE_DEV("has-selected-field", \
1206 _var_field->selected_field, \
1207 "Variant field has no selected field: %!+f", \
1212 const struct bt_field_class_variant_option
*
1213 borrow_variant_field_selected_class_option(const struct bt_field
*field
)
1215 const struct bt_field_class_named_field_class_container
*container_fc
;
1216 const struct bt_field_variant
*var_field
= (const void *) field
;
1218 BT_ASSERT_DBG(field
);
1219 container_fc
= (const void *) field
->class;
1220 return container_fc
->named_fcs
->pdata
[var_field
->selected_index
];
1224 const struct bt_field_class_variant_option
*
1225 bt_field_variant_borrow_selected_option_class_const(
1226 const struct bt_field
*field
)
1228 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1229 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1230 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1231 return borrow_variant_field_selected_class_option(field
);
1235 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1236 bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_const(
1237 const struct bt_field
*field
)
1239 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1240 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
1241 "variant-field-with-unsigned-selector-field",
1242 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1244 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1245 return (const void *) borrow_variant_field_selected_class_option(field
);
1249 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1250 bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_const(
1251 const struct bt_field
*field
)
1253 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1254 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE("field", field
,
1255 "variant-field-with-signed-selector-field",
1256 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1258 BT_ASSERT_PRE_DEV_FOR_BORROW_VAR_FIELD_SEL_CLASS_OPT(field
);
1259 return (const void *) borrow_variant_field_selected_class_option(field
);
1263 enum bt_field_variant_select_option_by_index_status
1264 bt_field_variant_select_option_by_index(
1265 struct bt_field
*field
, uint64_t index
)
1267 struct bt_field_variant
*var_field
= (void *) field
;
1269 BT_ASSERT_PRE_DEV_NO_ERROR();
1270 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1271 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1272 BT_ASSERT_PRE_DEV_FIELD_HOT(field
);
1273 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, var_field
->fields
->len
);
1274 var_field
->selected_field
= var_field
->fields
->pdata
[index
];
1275 var_field
->selected_index
= index
;
1276 return BT_FUNC_STATUS_OK
;
1280 uint64_t bt_field_variant_get_selected_option_index(
1281 const struct bt_field
*field
)
1283 const struct bt_field_variant
*var_field
= (const void *) field
;
1285 BT_ASSERT_PRE_DEV_FIELD_NON_NULL(field
);
1286 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT("field", field
, "Field");
1287 BT_ASSERT_PRE_DEV("has-selected-field", var_field
->selected_field
,
1288 "Variant field has no selected field: %!+f", field
);
1289 return var_field
->selected_index
;
1293 void bt_field_finalize(struct bt_field
*field
)
1296 BT_LOGD_STR("Putting field's class.");
1297 BT_OBJECT_PUT_REF_AND_RESET(field
->class);
1301 void destroy_bool_field(struct bt_field
*field
)
1304 BT_LIB_LOGD("Destroying boolean field object: %!+f", field
);
1305 bt_field_finalize(field
);
1310 void destroy_bit_array_field(struct bt_field
*field
)
1313 BT_LIB_LOGD("Destroying bit array field object: %!+f", field
);
1314 bt_field_finalize(field
);
1319 void destroy_integer_field(struct bt_field
*field
)
1322 BT_LIB_LOGD("Destroying integer field object: %!+f", field
);
1323 bt_field_finalize(field
);
1328 void destroy_real_field(struct bt_field
*field
)
1331 BT_LIB_LOGD("Destroying real field object: %!+f", field
);
1332 bt_field_finalize(field
);
1337 void destroy_structure_field(struct bt_field
*field
)
1339 struct bt_field_structure
*struct_field
= (void *) field
;
1342 BT_LIB_LOGD("Destroying structure field object: %!+f", field
);
1343 bt_field_finalize(field
);
1345 if (struct_field
->fields
) {
1346 g_ptr_array_free(struct_field
->fields
, TRUE
);
1347 struct_field
->fields
= NULL
;
1354 void destroy_option_field(struct bt_field
*field
)
1356 struct bt_field_option
*opt_field
= (void *) field
;
1359 BT_LIB_LOGD("Destroying option field object: %!+f", field
);
1360 bt_field_finalize(field
);
1362 if (opt_field
->content_field
) {
1363 bt_field_destroy(opt_field
->content_field
);
1370 void destroy_variant_field(struct bt_field
*field
)
1372 struct bt_field_variant
*var_field
= (void *) field
;
1375 BT_LIB_LOGD("Destroying variant field object: %!+f", field
);
1376 bt_field_finalize(field
);
1378 if (var_field
->fields
) {
1379 g_ptr_array_free(var_field
->fields
, TRUE
);
1380 var_field
->fields
= NULL
;
1387 void destroy_array_field(struct bt_field
*field
)
1389 struct bt_field_array
*array_field
= (void *) field
;
1392 BT_LIB_LOGD("Destroying array field object: %!+f", field
);
1393 bt_field_finalize(field
);
1395 if (array_field
->fields
) {
1396 g_ptr_array_free(array_field
->fields
, TRUE
);
1397 array_field
->fields
= NULL
;
1404 void destroy_string_field(struct bt_field
*field
)
1406 struct bt_field_string
*string_field
= (void *) field
;
1409 BT_LIB_LOGD("Destroying string field object: %!+f", field
);
1410 bt_field_finalize(field
);
1412 if (string_field
->buf
) {
1413 g_array_free(string_field
->buf
, TRUE
);
1414 string_field
->buf
= NULL
;
1420 void bt_field_destroy(struct bt_field
*field
)
1424 switch (field
->class->type
) {
1425 case BT_FIELD_CLASS_TYPE_BOOL
:
1426 destroy_bool_field(field
);
1428 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
1429 destroy_bit_array_field(field
);
1431 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1432 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1433 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1434 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1435 destroy_integer_field(field
);
1437 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
1438 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
1439 destroy_real_field(field
);
1441 case BT_FIELD_CLASS_TYPE_STRING
:
1442 destroy_string_field(field
);
1444 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1445 destroy_structure_field(field
);
1447 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1448 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
1449 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
1450 destroy_array_field(field
);
1452 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
1453 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
1454 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1455 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1456 destroy_option_field(field
);
1458 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
1459 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
1460 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
1461 destroy_variant_field(field
);
1469 void reset_single_field(struct bt_field
*field
)
1471 BT_ASSERT_DBG(field
);
1472 field
->is_set
= false;
1476 void reset_structure_field(struct bt_field
*field
)
1479 struct bt_field_structure
*struct_field
= (void *) field
;
1481 BT_ASSERT_DBG(field
);
1483 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1484 bt_field_reset(struct_field
->fields
->pdata
[i
]);
1489 void reset_option_field(struct bt_field
*field
)
1491 struct bt_field_option
*opt_field
= (void *) field
;
1493 BT_ASSERT_DBG(opt_field
);
1494 bt_field_reset(opt_field
->content_field
);
1495 opt_field
->selected_field
= NULL
;
1499 void reset_variant_field(struct bt_field
*field
)
1502 struct bt_field_variant
*var_field
= (void *) field
;
1504 BT_ASSERT_DBG(field
);
1506 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1507 bt_field_reset(var_field
->fields
->pdata
[i
]);
1512 void reset_array_field(struct bt_field
*field
)
1515 struct bt_field_array
*array_field
= (void *) field
;
1517 BT_ASSERT_DBG(field
);
1519 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1520 bt_field_reset(array_field
->fields
->pdata
[i
]);
1525 void set_single_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1527 field
->frozen
= is_frozen
;
1531 void set_structure_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1534 struct bt_field_structure
*struct_field
= (void *) field
;
1536 BT_LIB_LOGD("Setting structure field's frozen state: "
1537 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1539 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1540 struct bt_field
*member_field
= struct_field
->fields
->pdata
[i
];
1542 BT_LIB_LOGD("Setting structure field's member field's "
1543 "frozen state: %![field-]+f, index=%" PRIu64
,
1545 _bt_field_set_is_frozen(member_field
, is_frozen
);
1548 set_single_field_is_frozen(field
, is_frozen
);
1552 void set_option_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1554 struct bt_field_option
*opt_field
= (void *) field
;
1556 BT_LIB_LOGD("Setting option field's frozen state: "
1557 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1558 _bt_field_set_is_frozen(opt_field
->content_field
, is_frozen
);
1559 set_single_field_is_frozen(field
, is_frozen
);
1563 void set_variant_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1566 struct bt_field_variant
*var_field
= (void *) field
;
1568 BT_LIB_LOGD("Setting variant field's frozen state: "
1569 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1571 for (i
= 0; i
< var_field
->fields
->len
; i
++) {
1572 struct bt_field
*option_field
= var_field
->fields
->pdata
[i
];
1574 BT_LIB_LOGD("Setting variant field's option field's "
1575 "frozen state: %![field-]+f, index=%" PRIu64
,
1577 _bt_field_set_is_frozen(option_field
, is_frozen
);
1580 set_single_field_is_frozen(field
, is_frozen
);
1584 void set_array_field_is_frozen(struct bt_field
*field
, bool is_frozen
)
1587 struct bt_field_array
*array_field
= (void *) field
;
1589 BT_LIB_LOGD("Setting array field's frozen state: "
1590 "%![field-]+f, is-frozen=%d", field
, is_frozen
);
1592 for (i
= 0; i
< array_field
->fields
->len
; i
++) {
1593 struct bt_field
*elem_field
= array_field
->fields
->pdata
[i
];
1595 BT_LIB_LOGD("Setting array field's element field's "
1596 "frozen state: %![field-]+f, index=%" PRIu64
,
1598 _bt_field_set_is_frozen(elem_field
, is_frozen
);
1601 set_single_field_is_frozen(field
, is_frozen
);
1604 void _bt_field_set_is_frozen(const struct bt_field
*field
,
1607 BT_ASSERT_DBG(field
);
1608 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
1610 BT_ASSERT_DBG(field
->methods
->set_is_frozen
);
1611 field
->methods
->set_is_frozen((void *) field
, is_frozen
);
1615 bool single_field_is_set(const struct bt_field
*field
)
1617 BT_ASSERT_DBG(field
);
1618 return field
->is_set
;
1622 bool structure_field_is_set(const struct bt_field
*field
)
1626 const struct bt_field_structure
*struct_field
= (const void *) field
;
1628 BT_ASSERT_DBG(field
);
1630 for (i
= 0; i
< struct_field
->fields
->len
; i
++) {
1631 is_set
= bt_field_is_set(struct_field
->fields
->pdata
[i
]);
1642 bool option_field_is_set(const struct bt_field
*field
)
1644 const struct bt_field_option
*opt_field
= (const void *) field
;
1645 bool is_set
= false;
1647 BT_ASSERT_DBG(field
);
1649 if (opt_field
->selected_field
) {
1650 is_set
= bt_field_is_set(opt_field
->selected_field
);
1657 bool variant_field_is_set(const struct bt_field
*field
)
1659 const struct bt_field_variant
*var_field
= (const void *) field
;
1660 bool is_set
= false;
1662 BT_ASSERT_DBG(field
);
1664 if (var_field
->selected_field
) {
1665 is_set
= bt_field_is_set(var_field
->selected_field
);
1672 bool array_field_is_set(const struct bt_field
*field
)
1676 const struct bt_field_array
*array_field
= (const void *) field
;
1678 BT_ASSERT_DBG(field
);
1680 for (i
= 0; i
< array_field
->length
; i
++) {
1681 is_set
= bt_field_is_set(array_field
->fields
->pdata
[i
]);