2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
7 #define BT_LOG_TAG "LIB/VALUE"
8 #include "lib/logging.h"
14 #include <babeltrace2/babeltrace.h>
16 #include "compat/compiler.h"
17 #include "common/common.h"
18 #include "compat/glib.h"
19 #include "lib/assert-cond.h"
20 #include "lib/value.h"
21 #include "common/assert.h"
22 #include "func-status.h"
24 #define BT_ASSERT_PRE_DEV_VALUE_HOT(_value, _name) \
25 BT_ASSERT_PRE_DEV_HOT(((struct bt_value *) (_value)), (_name), \
28 #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
29 #define BT_VALUE_TO_INTEGER(_base) ((struct bt_value_integer *) (_base))
30 #define BT_VALUE_TO_REAL(_base) ((struct bt_value_real *) (_base))
31 #define BT_VALUE_TO_STRING(_base) ((struct bt_value_string *) (_base))
32 #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base))
33 #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
36 void bt_value_null_instance_release_func(struct bt_object
*obj
)
38 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
42 struct bt_value bt_value_null_instance
= {
46 .release_func
= bt_value_null_instance_release_func
,
47 .spec_release_func
= NULL
,
48 .parent_is_owner_listener_func
= NULL
,
51 .type
= BT_VALUE_TYPE_NULL
,
55 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
58 void bt_value_destroy(struct bt_object
*obj
);
61 void bt_value_string_destroy(struct bt_value
*object
)
63 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
64 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
68 void bt_value_array_destroy(struct bt_value
*object
)
71 * Pointer array's registered value destructor will take care
72 * of putting each contained object.
74 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
75 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
79 void bt_value_map_destroy(struct bt_value
*object
)
82 * Hash table's registered value destructor will take care of
83 * putting each contained object. Keys are GQuarks and cannot
84 * be destroyed anyway.
86 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
87 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
91 void (* const destroy_funcs
[])(struct bt_value
*) = {
92 [BT_VALUE_TYPE_NULL
] = NULL
,
93 [BT_VALUE_TYPE_BOOL
] = NULL
,
94 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
95 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
96 [BT_VALUE_TYPE_REAL
] = NULL
,
97 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
98 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
99 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
103 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
105 BT_ASSERT(null_obj
== bt_value_null
);
107 bt_object_get_ref_no_null_check(bt_value_null
);
108 return (void *) bt_value_null
;
112 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
114 return bt_value_bool_create_init(
115 BT_VALUE_TO_BOOL(bool_obj
)->value
);
119 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
123 struct bt_value
*bt_value_integer_copy(
124 const struct bt_value
*integer_obj
)
126 return bt_value_integer_create_init(integer_obj
->type
,
127 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
131 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
133 return bt_value_real_create_init(
134 BT_VALUE_TO_REAL(real_obj
)->value
);
138 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
140 return bt_value_string_create_init(
141 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
145 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
149 struct bt_value
*copy_obj
;
150 struct bt_value_array
*typed_array_obj
;
152 BT_LOGD("Copying array value: addr=%p", array_obj
);
153 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
154 copy_obj
= bt_value_array_create();
156 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
160 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
161 struct bt_value
*element_obj_copy
= NULL
;
162 const struct bt_value
*element_obj
=
163 bt_value_array_borrow_element_by_index_const(
166 BT_LOGD("Copying array value's element: element-addr=%p, "
167 "index=%d", element_obj
, i
);
168 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
170 BT_LIB_LOGE_APPEND_CAUSE(
171 "Cannot copy array value's element: "
172 "array-addr=%p, index=%d",
174 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
178 BT_ASSERT(element_obj_copy
);
179 ret
= bt_value_array_append_element(copy_obj
,
180 (void *) element_obj_copy
);
181 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
183 BT_LIB_LOGE_APPEND_CAUSE(
184 "Cannot append to array value: addr=%p",
186 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
191 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
192 array_obj
, copy_obj
);
199 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
203 gpointer key
, element_obj
;
204 struct bt_value
*copy_obj
;
205 struct bt_value
*element_obj_copy
= NULL
;
206 struct bt_value_map
*typed_map_obj
;
208 BT_LOGD("Copying map value: addr=%p", map_obj
);
209 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
210 copy_obj
= bt_value_map_create();
215 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
217 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
218 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
221 BT_LOGD("Copying map value's element: element-addr=%p, "
222 "key=\"%s\"", element_obj
, key_str
);
223 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
225 BT_LIB_LOGE_APPEND_CAUSE(
226 "Cannot copy map value's element: "
227 "map-addr=%p, key=\"%s\"",
229 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
233 BT_ASSERT(element_obj_copy
);
234 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
235 (void *) element_obj_copy
);
236 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
238 BT_LIB_LOGE_APPEND_CAUSE(
239 "Cannot insert into map value: addr=%p, key=\"%s\"",
241 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
246 BT_LOGD("Copied map value: addr=%p", map_obj
);
253 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
254 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
255 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
256 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
257 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
258 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
259 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
260 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
261 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
265 bt_bool
bt_value_null_is_equal(const struct bt_value
*object_a
,
266 const struct bt_value
*object_b
)
269 * Always BT_TRUE since bt_value_is_equal() already checks if both
270 * object_a and object_b have the same type, and in the case of
271 * null value objects, they're always the same if it is so.
277 bt_bool
bt_value_bool_is_equal(const struct bt_value
*object_a
,
278 const struct bt_value
*object_b
)
280 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
281 BT_VALUE_TO_BOOL(object_b
)->value
) {
282 BT_LOGT("Boolean value objects are different: "
283 "bool-a-val=%d, bool-b-val=%d",
284 BT_VALUE_TO_BOOL(object_a
)->value
,
285 BT_VALUE_TO_BOOL(object_b
)->value
);
293 bt_bool
bt_value_integer_is_equal(const struct bt_value
*object_a
,
294 const struct bt_value
*object_b
)
296 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
297 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
298 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
299 BT_LOGT("Unsigned integer value objects are different: "
300 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
301 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
302 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
304 BT_LOGT("Signed integer value objects are different: "
305 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
306 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
307 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
317 bt_bool
bt_value_real_is_equal(const struct bt_value
*object_a
,
318 const struct bt_value
*object_b
)
320 if (BT_VALUE_TO_REAL(object_a
)->value
!=
321 BT_VALUE_TO_REAL(object_b
)->value
) {
322 BT_LOGT("Real number value objects are different: "
323 "real-a-val=%f, real-b-val=%f",
324 BT_VALUE_TO_REAL(object_a
)->value
,
325 BT_VALUE_TO_REAL(object_b
)->value
);
333 bt_bool
bt_value_string_is_equal(const struct bt_value
*object_a
,
334 const struct bt_value
*object_b
)
336 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
337 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
338 BT_LOGT("String value objects are different: "
339 "string-a-val=\"%s\", string-b-val=\"%s\"",
340 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
341 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
349 bt_bool
bt_value_array_is_equal(const struct bt_value
*object_a
,
350 const struct bt_value
*object_b
)
353 bt_bool ret
= BT_TRUE
;
354 const struct bt_value_array
*array_obj_a
=
355 BT_VALUE_TO_ARRAY(object_a
);
357 if (bt_value_array_get_length(object_a
) !=
358 bt_value_array_get_length(object_b
)) {
359 BT_LOGT("Array values are different: size mismatch "
360 "value-a-addr=%p, value-b-addr=%p, "
361 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
363 bt_value_array_get_length(object_a
),
364 bt_value_array_get_length(object_b
));
369 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
370 const struct bt_value
*element_obj_a
;
371 const struct bt_value
*element_obj_b
;
373 element_obj_a
= bt_value_array_borrow_element_by_index_const(
375 element_obj_b
= bt_value_array_borrow_element_by_index_const(
378 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
379 BT_LOGT("Array values's elements are different: "
380 "value-a-addr=%p, value-b-addr=%p, index=%d",
381 element_obj_a
, element_obj_b
, i
);
392 bt_bool
bt_value_map_is_equal(const struct bt_value
*object_a
,
393 const struct bt_value
*object_b
)
395 bt_bool ret
= BT_TRUE
;
397 gpointer key
, element_obj_a
;
398 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
400 if (bt_value_map_get_size(object_a
) !=
401 bt_value_map_get_size(object_b
)) {
402 BT_LOGT("Map values are different: size mismatch "
403 "value-a-addr=%p, value-b-addr=%p, "
404 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
406 bt_value_map_get_size(object_a
),
407 bt_value_map_get_size(object_b
));
412 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
414 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
415 const struct bt_value
*element_obj_b
;
416 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
418 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
421 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
422 BT_LOGT("Map values's elements are different: "
423 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
424 element_obj_a
, element_obj_b
, key_str
);
435 bt_bool (* const is_equal_funcs
[])(const struct bt_value
*,
436 const struct bt_value
*) = {
437 [BT_VALUE_TYPE_NULL
] = bt_value_null_is_equal
,
438 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_is_equal
,
439 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_is_equal
,
440 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_is_equal
,
441 [BT_VALUE_TYPE_REAL
] = bt_value_real_is_equal
,
442 [BT_VALUE_TYPE_STRING
] = bt_value_string_is_equal
,
443 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_is_equal
,
444 [BT_VALUE_TYPE_MAP
] = bt_value_map_is_equal
,
448 void bt_value_null_freeze(struct bt_value
*object
)
453 void bt_value_generic_freeze(struct bt_value
*object
)
455 object
->frozen
= BT_TRUE
;
459 void bt_value_array_freeze(struct bt_value
*object
)
462 struct bt_value_array
*typed_array_obj
=
463 BT_VALUE_TO_ARRAY(object
);
465 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
466 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
469 bt_value_generic_freeze(object
);
473 void bt_value_map_freeze(struct bt_value
*object
)
476 gpointer key
, element_obj
;
477 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
479 g_hash_table_iter_init(&iter
, map_obj
->ght
);
481 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
482 bt_value_freeze(element_obj
);
485 bt_value_generic_freeze(object
);
489 void (* const freeze_funcs
[])(struct bt_value
*) = {
490 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
491 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
492 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
493 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
494 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
495 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
496 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
497 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
501 void bt_value_destroy(struct bt_object
*obj
)
503 struct bt_value
*value
;
505 value
= container_of(obj
, struct bt_value
, base
);
506 BT_LOGD("Destroying value: addr=%p", value
);
508 if (bt_value_is_null(value
)) {
509 BT_LOGD_STR("Not destroying the null value singleton.");
513 if (destroy_funcs
[value
->type
]) {
514 destroy_funcs
[value
->type
](value
);
521 void _bt_value_freeze(const struct bt_value
*c_object
)
523 const struct bt_value
*object
= (void *) c_object
;
527 if (object
->frozen
) {
531 BT_LOGD("Freezing value: addr=%p", object
);
532 freeze_funcs
[object
->type
]((void *) object
);
538 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
540 BT_ASSERT_PRE_DEV_NON_NULL(object
, "Value object");
545 struct bt_value
bt_value_create_base(enum bt_value_type type
)
547 struct bt_value value
;
550 value
.frozen
= BT_FALSE
;
551 bt_object_init_shared(&value
.base
, bt_value_destroy
);
555 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
557 struct bt_value_bool
*bool_obj
;
559 BT_ASSERT_PRE_NO_ERROR();
561 BT_LOGD("Creating boolean value object: val=%d", val
);
562 bool_obj
= g_new0(struct bt_value_bool
, 1);
564 BT_LIB_LOGE_APPEND_CAUSE(
565 "Failed to allocate one boolean value object.");
569 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
570 bool_obj
->value
= val
;
571 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
574 return (void *) bool_obj
;
577 struct bt_value
*bt_value_bool_create(void)
579 BT_ASSERT_PRE_NO_ERROR();
581 return bt_value_bool_create_init(BT_FALSE
);
585 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
588 struct bt_value_integer
*integer_obj
;
590 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
591 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
593 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
594 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
597 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
601 integer_obj
= g_new0(struct bt_value_integer
, 1);
603 BT_LIB_LOGE_APPEND_CAUSE(
604 "Failed to allocate one integer value object.");
608 integer_obj
->base
= bt_value_create_base(type
);
609 integer_obj
->value
.u
= uval
;
610 BT_LOGD("Created %ssigned integer value object: addr=%p",
611 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
615 return (void *) integer_obj
;
618 struct bt_value
*bt_value_integer_unsigned_create_init(uint64_t val
)
620 BT_ASSERT_PRE_NO_ERROR();
622 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
626 struct bt_value
*bt_value_integer_unsigned_create(void)
628 BT_ASSERT_PRE_NO_ERROR();
630 return bt_value_integer_unsigned_create_init(0);
633 struct bt_value
*bt_value_integer_signed_create_init(int64_t val
)
635 BT_ASSERT_PRE_NO_ERROR();
637 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
641 struct bt_value
*bt_value_integer_signed_create(void)
643 BT_ASSERT_PRE_NO_ERROR();
645 return bt_value_integer_signed_create_init(0);
648 struct bt_value
*bt_value_real_create_init(double val
)
650 struct bt_value_real
*real_obj
;
652 BT_ASSERT_PRE_NO_ERROR();
654 BT_LOGD("Creating real number value object: val=%f", val
);
655 real_obj
= g_new0(struct bt_value_real
, 1);
657 BT_LIB_LOGE_APPEND_CAUSE(
658 "Failed to allocate one real number value object.");
662 real_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_REAL
);
663 real_obj
->value
= val
;
664 BT_LOGD("Created real number value object: addr=%p",
668 return (void *) real_obj
;
671 struct bt_value
*bt_value_real_create(void)
673 BT_ASSERT_PRE_NO_ERROR();
675 return bt_value_real_create_init(0.);
678 struct bt_value
*bt_value_string_create_init(const char *val
)
680 struct bt_value_string
*string_obj
= NULL
;
682 BT_ASSERT_PRE_NO_ERROR();
683 BT_ASSERT_PRE_NON_NULL(val
, "Value");
685 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
686 string_obj
= g_new0(struct bt_value_string
, 1);
688 BT_LIB_LOGE_APPEND_CAUSE(
689 "Failed to allocate one string object.");
693 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
694 string_obj
->gstr
= g_string_new(val
);
695 if (!string_obj
->gstr
) {
696 BT_LIB_LOGE_APPEND_CAUSE(
697 "Failed to allocate a GString.");
703 BT_LOGD("Created string value object: addr=%p",
707 return (void *) string_obj
;
710 struct bt_value
*bt_value_string_create(void)
712 BT_ASSERT_PRE_NO_ERROR();
714 return bt_value_string_create_init("");
717 struct bt_value
*bt_value_array_create(void)
719 struct bt_value_array
*array_obj
;
721 BT_ASSERT_PRE_NO_ERROR();
723 BT_LOGD_STR("Creating empty array value object.");
724 array_obj
= g_new0(struct bt_value_array
, 1);
726 BT_LIB_LOGE_APPEND_CAUSE(
727 "Failed to allocate one array object.");
731 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
732 array_obj
->garray
= bt_g_ptr_array_new_full(0,
733 (GDestroyNotify
) bt_object_put_ref
);
734 if (!array_obj
->garray
) {
735 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
741 BT_LOGD("Created array value object: addr=%p",
745 return (void *) array_obj
;
748 struct bt_value
*bt_value_map_create(void)
750 struct bt_value_map
*map_obj
;
752 BT_ASSERT_PRE_NO_ERROR();
754 BT_LOGD_STR("Creating empty map value object.");
755 map_obj
= g_new0(struct bt_value_map
, 1);
757 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
761 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
762 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
763 NULL
, (GDestroyNotify
) bt_object_put_ref
);
765 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
771 BT_LOGD("Created map value object: addr=%p",
775 return (void *) map_obj
;
778 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
780 BT_ASSERT_PRE_DEV_NON_NULL(bool_obj
, "Value object");
781 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
782 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
785 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
787 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
788 BT_ASSERT_PRE_VALUE_HAS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
789 BT_ASSERT_PRE_DEV_VALUE_HOT(bool_obj
, "Value object");
790 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
791 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
795 uint64_t bt_value_integer_unsigned_get(const struct bt_value
*integer_obj
)
797 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
798 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(integer_obj
,
799 BT_VALUE_TYPE_UNSIGNED_INTEGER
);
800 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
803 int64_t bt_value_integer_signed_get(const struct bt_value
*integer_obj
)
805 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
806 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(integer_obj
,
807 BT_VALUE_TYPE_SIGNED_INTEGER
);
808 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
812 void bt_value_integer_set(struct bt_value
*integer_obj
,
813 enum bt_value_type expected_type
, uint64_t uval
)
815 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
816 BT_ASSERT_PRE_VALUE_HAS_TYPE(integer_obj
, expected_type
);
817 BT_ASSERT_PRE_DEV_VALUE_HOT(integer_obj
, "Value object");
818 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
821 void bt_value_integer_unsigned_set(struct bt_value
*integer_obj
,
824 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
);
825 BT_LOGT("Set unsigned integer value's raw value: "
826 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
829 void bt_value_integer_signed_set(struct bt_value
*integer_obj
,
832 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
834 BT_LOGT("Set signed integer value's raw value: "
835 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
838 double bt_value_real_get(const struct bt_value
*real_obj
)
840 BT_ASSERT_PRE_DEV_NON_NULL(real_obj
, "Value object");
841 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
842 return BT_VALUE_TO_REAL(real_obj
)->value
;
845 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
847 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
848 BT_ASSERT_PRE_VALUE_HAS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
849 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
, "Value object");
850 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
851 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
855 const char *bt_value_string_get(const struct bt_value
*string_obj
)
857 BT_ASSERT_PRE_DEV_NON_NULL(string_obj
, "Value object");
858 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
859 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
862 enum bt_value_string_set_status
bt_value_string_set(
863 struct bt_value
*string_obj
, const char *val
)
865 BT_ASSERT_PRE_NO_ERROR();
866 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
867 BT_ASSERT_PRE_VALUE_HAS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
868 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
, "Value object");
869 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
870 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
872 return BT_FUNC_STATUS_OK
;
875 uint64_t bt_value_array_get_length(const struct bt_value
*array_obj
)
877 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
878 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
879 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
882 struct bt_value
*bt_value_array_borrow_element_by_index(
883 struct bt_value
*array_obj
, uint64_t index
)
885 struct bt_value_array
*typed_array_obj
=
886 BT_VALUE_TO_ARRAY(array_obj
);
888 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
889 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
890 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
891 return g_ptr_array_index(typed_array_obj
->garray
, index
);
894 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
895 const struct bt_value
*array_obj
,
898 return bt_value_array_borrow_element_by_index(
899 (void *) array_obj
, index
);
902 enum bt_value_array_append_element_status
bt_value_array_append_element(
903 struct bt_value
*array_obj
,
904 struct bt_value
*element_obj
)
906 struct bt_value_array
*typed_array_obj
=
907 BT_VALUE_TO_ARRAY(array_obj
);
909 BT_ASSERT_PRE_NO_ERROR();
910 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
911 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
912 BT_ASSERT_PRE_VALUE_HAS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
913 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
914 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
915 bt_object_get_ref(element_obj
);
916 BT_LOGT("Appended element to array value: array-value-addr=%p, "
917 "element-value-addr=%p, new-size=%u",
918 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
919 return BT_FUNC_STATUS_OK
;
922 enum bt_value_array_append_element_status
923 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
925 enum bt_value_array_append_element_status ret
;
926 struct bt_value
*bool_obj
= NULL
;
928 BT_ASSERT_PRE_NO_ERROR();
930 bool_obj
= bt_value_bool_create_init(val
);
931 ret
= bt_value_array_append_element(array_obj
,
933 bt_object_put_ref(bool_obj
);
937 enum bt_value_array_append_element_status
938 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
941 enum bt_value_array_append_element_status ret
;
942 struct bt_value
*integer_obj
= NULL
;
944 BT_ASSERT_PRE_NO_ERROR();
946 integer_obj
= bt_value_integer_unsigned_create_init(val
);
947 ret
= bt_value_array_append_element(array_obj
,
948 (void *) integer_obj
);
949 bt_object_put_ref(integer_obj
);
953 enum bt_value_array_append_element_status
954 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
957 enum bt_value_array_append_element_status ret
;
958 struct bt_value
*integer_obj
= NULL
;
960 BT_ASSERT_PRE_NO_ERROR();
962 integer_obj
= bt_value_integer_signed_create_init(val
);
963 ret
= bt_value_array_append_element(array_obj
,
964 (void *) integer_obj
);
965 bt_object_put_ref(integer_obj
);
969 enum bt_value_array_append_element_status
970 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
972 enum bt_value_array_append_element_status ret
;
973 struct bt_value
*real_obj
= NULL
;
975 BT_ASSERT_PRE_NO_ERROR();
977 real_obj
= bt_value_real_create_init(val
);
978 ret
= bt_value_array_append_element(array_obj
,
980 bt_object_put_ref(real_obj
);
984 enum bt_value_array_append_element_status
985 bt_value_array_append_string_element(struct bt_value
*array_obj
,
988 enum bt_value_array_append_element_status ret
;
989 struct bt_value
*string_obj
= NULL
;
991 BT_ASSERT_PRE_NO_ERROR();
993 string_obj
= bt_value_string_create_init(val
);
994 ret
= bt_value_array_append_element(array_obj
,
995 (void *) string_obj
);
996 bt_object_put_ref(string_obj
);
1000 enum bt_value_array_append_element_status
1001 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
,
1002 struct bt_value
**element_obj
)
1004 enum bt_value_array_append_element_status ret
;
1005 struct bt_value
*empty_array_obj
= NULL
;
1007 BT_ASSERT_PRE_NO_ERROR();
1009 empty_array_obj
= bt_value_array_create();
1010 ret
= bt_value_array_append_element(array_obj
,
1011 (void *) empty_array_obj
);
1014 *element_obj
= empty_array_obj
;
1017 bt_object_put_ref(empty_array_obj
);
1021 enum bt_value_array_append_element_status
1022 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
,
1023 struct bt_value
**element_obj
)
1025 enum bt_value_array_append_element_status ret
;
1026 struct bt_value
*map_obj
= NULL
;
1028 BT_ASSERT_PRE_NO_ERROR();
1030 map_obj
= bt_value_map_create();
1031 ret
= bt_value_array_append_element(array_obj
,
1035 *element_obj
= map_obj
;
1038 bt_object_put_ref(map_obj
);
1042 enum bt_value_array_set_element_by_index_status
1043 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1044 struct bt_value
*element_obj
)
1046 struct bt_value_array
*typed_array_obj
=
1047 BT_VALUE_TO_ARRAY(array_obj
);
1049 BT_ASSERT_PRE_NO_ERROR();
1050 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1051 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1052 BT_ASSERT_PRE_VALUE_HAS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
1053 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
1054 BT_ASSERT_PRE_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
1055 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1056 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1057 bt_object_get_ref(element_obj
);
1058 BT_LOGT("Set array value's element: array-value-addr=%p, "
1059 "index=%" PRIu64
", element-value-addr=%p",
1060 array_obj
, index
, element_obj
);
1061 return BT_FUNC_STATUS_OK
;
1064 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1066 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1067 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1068 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1071 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1074 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1075 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1076 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1077 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1078 GUINT_TO_POINTER(g_quark_from_string(key
)));
1081 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1082 const struct bt_value
*map_obj
, const char *key
)
1084 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1087 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1089 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1090 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1091 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1092 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1093 GUINT_TO_POINTER(g_quark_from_string(key
)));
1096 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1097 struct bt_value
*map_obj
, const char *key
,
1098 struct bt_value
*element_obj
)
1100 BT_ASSERT_PRE_NO_ERROR();
1101 BT_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1102 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1103 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1104 BT_ASSERT_PRE_VALUE_HAS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1105 BT_ASSERT_PRE_DEV_VALUE_HOT(map_obj
, "Map value object");
1106 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1107 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1108 bt_object_get_ref(element_obj
);
1109 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1110 "key=\"%s\", element-value-addr=%p",
1111 map_obj
, key
, element_obj
);
1112 return BT_FUNC_STATUS_OK
;
1115 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1116 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1118 enum bt_value_map_insert_entry_status ret
;
1119 struct bt_value
*bool_obj
= NULL
;
1121 BT_ASSERT_PRE_NO_ERROR();
1123 bool_obj
= bt_value_bool_create_init(val
);
1124 ret
= bt_value_map_insert_entry(map_obj
, key
,
1126 bt_object_put_ref(bool_obj
);
1130 enum bt_value_map_insert_entry_status
1131 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1132 const char *key
, uint64_t val
)
1134 enum bt_value_map_insert_entry_status ret
;
1135 struct bt_value
*integer_obj
= NULL
;
1137 BT_ASSERT_PRE_NO_ERROR();
1139 integer_obj
= bt_value_integer_unsigned_create_init(val
);
1140 ret
= bt_value_map_insert_entry(map_obj
, key
,
1141 (void *) integer_obj
);
1142 bt_object_put_ref(integer_obj
);
1146 enum bt_value_map_insert_entry_status
1147 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1148 const char *key
, int64_t val
)
1150 enum bt_value_map_insert_entry_status ret
;
1151 struct bt_value
*integer_obj
= NULL
;
1153 BT_ASSERT_PRE_NO_ERROR();
1155 integer_obj
= bt_value_integer_signed_create_init(val
);
1156 ret
= bt_value_map_insert_entry(map_obj
, key
,
1157 (void *) integer_obj
);
1158 bt_object_put_ref(integer_obj
);
1162 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1163 struct bt_value
*map_obj
, const char *key
, double val
)
1165 enum bt_value_map_insert_entry_status ret
;
1166 struct bt_value
*real_obj
= NULL
;
1168 BT_ASSERT_PRE_NO_ERROR();
1170 real_obj
= bt_value_real_create_init(val
);
1171 ret
= bt_value_map_insert_entry(map_obj
, key
,
1173 bt_object_put_ref(real_obj
);
1177 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1178 struct bt_value
*map_obj
, const char *key
,
1181 enum bt_value_map_insert_entry_status ret
;
1182 struct bt_value
*string_obj
= NULL
;
1184 BT_ASSERT_PRE_NO_ERROR();
1186 string_obj
= bt_value_string_create_init(val
);
1187 ret
= bt_value_map_insert_entry(map_obj
, key
,
1188 (void *) string_obj
);
1189 bt_object_put_ref(string_obj
);
1193 enum bt_value_map_insert_entry_status
1194 bt_value_map_insert_empty_array_entry(
1195 struct bt_value
*map_obj
, const char *key
,
1196 bt_value
**entry_obj
)
1198 enum bt_value_map_insert_entry_status ret
;
1199 struct bt_value
*array_obj
= NULL
;
1201 BT_ASSERT_PRE_NO_ERROR();
1203 array_obj
= bt_value_array_create();
1204 ret
= bt_value_map_insert_entry(map_obj
, key
,
1205 (void *) array_obj
);
1208 *entry_obj
= array_obj
;
1211 bt_object_put_ref(array_obj
);
1215 enum bt_value_map_insert_entry_status
1216 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
,
1217 bt_value
**entry_obj
)
1219 enum bt_value_map_insert_entry_status ret
;
1220 struct bt_value
*empty_map_obj
= NULL
;
1222 BT_ASSERT_PRE_NO_ERROR();
1224 empty_map_obj
= bt_value_map_create();
1225 ret
= bt_value_map_insert_entry(map_obj
, key
,
1226 (void *) empty_map_obj
);
1229 *entry_obj
= empty_map_obj
;
1232 bt_object_put_ref(empty_map_obj
);
1236 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1237 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1240 int status
= BT_FUNC_STATUS_OK
;
1241 gpointer key
, element_obj
;
1242 GHashTableIter iter
;
1243 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1245 BT_ASSERT_PRE_NO_ERROR();
1247 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1248 BT_ASSERT_PRE_DEV_NON_NULL(func
, "Callback");
1249 BT_ASSERT_PRE_DEV_VALUE_HAS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1250 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1252 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1253 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1255 status
= func(key_str
, element_obj
, data
);
1256 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status
);
1257 if (status
!= BT_FUNC_STATUS_OK
) {
1259 BT_LIB_LOGE_APPEND_CAUSE(
1260 "User function failed while iterating "
1261 "map value entries: "
1262 "status=%s, key=\"%s\", "
1263 "value-addr=%p, data=%p",
1264 bt_common_func_status_string(status
),
1265 key_str
, element_obj
, data
);
1267 if (status
== BT_FUNC_STATUS_ERROR
) {
1269 * User function error becomes a
1270 * user error from this
1271 * function's caller's
1274 status
= BT_FUNC_STATUS_USER_ERROR
;
1277 BT_ASSERT(status
== BT_FUNC_STATUS_INTERRUPTED
);
1278 BT_LOGT("User interrupted the loop: status=%s, "
1279 "key=\"%s\", value-addr=%p, data=%p",
1280 bt_common_func_status_string(status
),
1281 key_str
, element_obj
, data
);
1291 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1292 const struct bt_value
*map_obj
,
1293 bt_value_map_foreach_entry_const_func func
, void *data
)
1295 BT_ASSERT_PRE_NO_ERROR();
1297 return (int) bt_value_map_foreach_entry((void *) map_obj
,
1298 (bt_value_map_foreach_entry_func
) func
, data
);
1301 struct extend_map_element_data
{
1302 struct bt_value
*base_obj
;
1306 bt_value_map_foreach_entry_const_func_status
extend_map_element(
1307 const char *key
, const struct bt_value
*extension_obj_elem
,
1311 struct extend_map_element_data
*extend_data
= data
;
1312 struct bt_value
*extension_obj_elem_copy
= NULL
;
1314 /* Copy object which is to replace the current one */
1315 status
= bt_value_copy(extension_obj_elem
, &extension_obj_elem_copy
);
1317 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1318 extension_obj_elem
);
1322 BT_ASSERT(extension_obj_elem_copy
);
1324 /* Replace in base map value. */
1325 status
= bt_value_map_insert_entry(extend_data
->base_obj
, key
,
1326 extension_obj_elem_copy
);
1328 BT_LIB_LOGE_APPEND_CAUSE(
1329 "Cannot replace value in base map value: key=\"%s\", "
1330 "%![base-map-value-]+v, %![element-value-]+v",
1331 key
, extend_data
->base_obj
, extension_obj_elem_copy
);
1338 BT_ASSERT(status
< 0);
1341 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1342 BT_ASSERT(status
== BT_FUNC_STATUS_OK
||
1343 status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1347 enum bt_value_map_extend_status
bt_value_map_extend(
1348 struct bt_value
*base_map_obj
,
1349 const struct bt_value
*extension_obj
)
1351 int status
= BT_FUNC_STATUS_OK
;
1352 struct extend_map_element_data extend_data
= {
1356 BT_ASSERT_PRE_NO_ERROR();
1357 BT_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1358 BT_ASSERT_PRE_DEV_VALUE_HOT(base_map_obj
, "Base value object");
1359 BT_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1360 BT_ASSERT_PRE_VALUE_HAS_TYPE(base_map_obj
, BT_VALUE_TYPE_MAP
);
1361 BT_ASSERT_PRE_VALUE_HAS_TYPE(extension_obj
, BT_VALUE_TYPE_MAP
);
1362 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1363 base_map_obj
, extension_obj
);
1366 * For each key in the extension map object, replace this key
1367 * in the base map object.
1369 extend_data
.base_obj
= base_map_obj
;
1370 status
= bt_value_map_foreach_entry_const(extension_obj
,
1371 extend_map_element
, &extend_data
);
1372 if (status
!= BT_FUNC_STATUS_OK
) {
1373 BT_ASSERT(status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1374 BT_LIB_LOGE_APPEND_CAUSE(
1375 "Cannot iterate on the extension object's elements: "
1376 "%![extension-value-]+v", extension_obj
);
1382 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1383 struct bt_value
**copy_obj
)
1385 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1387 BT_ASSERT_PRE_NO_ERROR();
1388 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
1389 BT_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1390 BT_LOGD("Copying value object: addr=%p", object
);
1391 *copy_obj
= copy_funcs
[object
->type
](object
);
1393 BT_LOGD("Copied value object: copy-value-addr=%p",
1396 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1398 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1404 bt_bool
bt_value_is_equal(const struct bt_value
*object_a
,
1405 const struct bt_value
*object_b
)
1407 bt_bool ret
= BT_FALSE
;
1409 BT_ASSERT_PRE_DEV_NON_NULL(object_a
, "Value object A");
1410 BT_ASSERT_PRE_DEV_NON_NULL(object_b
, "Value object B");
1412 if (object_a
->type
!= object_b
->type
) {
1413 BT_LOGT("Values are different: type mismatch: "
1414 "value-a-addr=%p, value-b-addr=%p, "
1415 "value-a-type=%s, value-b-type=%s",
1417 bt_common_value_type_string(object_a
->type
),
1418 bt_common_value_type_string(object_b
->type
));
1422 ret
= is_equal_funcs
[object_a
->type
](object_a
, object_b
);
1428 void bt_value_get_ref(const struct bt_value
*value
)
1430 bt_object_get_ref(value
);
1433 void bt_value_put_ref(const struct bt_value
*value
)
1435 bt_object_put_ref(value
);