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_FROM_FUNC(_func, _value) \
25 BT_ASSERT_PRE_DEV_HOT_FROM_FUNC(_func, "value-object", \
26 ((struct bt_value *) (_value)), "Value object", \
29 #define BT_ASSERT_PRE_DEV_VALUE_HOT(_value) \
30 BT_ASSERT_PRE_DEV_VALUE_HOT_FROM_FUNC(__func__, (_value))
32 #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
33 #define BT_VALUE_TO_INTEGER(_base) ((struct bt_value_integer *) (_base))
34 #define BT_VALUE_TO_REAL(_base) ((struct bt_value_real *) (_base))
35 #define BT_VALUE_TO_STRING(_base) ((struct bt_value_string *) (_base))
36 #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base))
37 #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
40 void bt_value_null_instance_release_func(struct bt_object
*obj
)
42 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
46 struct bt_value bt_value_null_instance
= {
50 .release_func
= bt_value_null_instance_release_func
,
51 .spec_release_func
= NULL
,
52 .parent_is_owner_listener_func
= NULL
,
55 .type
= BT_VALUE_TYPE_NULL
,
60 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
63 void bt_value_destroy(struct bt_object
*obj
);
66 void bt_value_string_destroy(struct bt_value
*object
)
68 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
69 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
73 void bt_value_array_destroy(struct bt_value
*object
)
76 * Pointer array's registered value destructor will take care
77 * of putting each contained object.
79 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
80 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
84 void bt_value_map_destroy(struct bt_value
*object
)
87 * Hash table's registered value destructor will take care of
88 * putting each contained object. Keys are GQuarks and cannot
89 * be destroyed anyway.
91 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
92 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
96 void (* const destroy_funcs
[])(struct bt_value
*) = {
97 [BT_VALUE_TYPE_NULL
] = NULL
,
98 [BT_VALUE_TYPE_BOOL
] = NULL
,
99 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
100 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
101 [BT_VALUE_TYPE_REAL
] = NULL
,
102 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
103 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
104 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
108 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
110 BT_ASSERT(null_obj
== bt_value_null
);
112 bt_object_get_ref_no_null_check(bt_value_null
);
113 return (void *) bt_value_null
;
117 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
119 return bt_value_bool_create_init(
120 BT_VALUE_TO_BOOL(bool_obj
)->value
);
124 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
128 struct bt_value
*bt_value_integer_copy(
129 const struct bt_value
*integer_obj
)
131 return bt_value_integer_create_init(integer_obj
->type
,
132 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
136 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
138 return bt_value_real_create_init(
139 BT_VALUE_TO_REAL(real_obj
)->value
);
143 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
145 return bt_value_string_create_init(
146 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
150 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
154 struct bt_value
*copy_obj
;
155 struct bt_value_array
*typed_array_obj
;
157 BT_LOGD("Copying array value: addr=%p", array_obj
);
158 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
159 copy_obj
= bt_value_array_create();
161 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
165 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
166 struct bt_value
*element_obj_copy
= NULL
;
167 const struct bt_value
*element_obj
=
168 bt_value_array_borrow_element_by_index_const(
171 BT_LOGD("Copying array value's element: element-addr=%p, "
172 "index=%d", element_obj
, i
);
173 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
175 BT_LIB_LOGE_APPEND_CAUSE(
176 "Cannot copy array value's element: "
177 "array-addr=%p, index=%d",
179 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
183 BT_ASSERT(element_obj_copy
);
184 ret
= bt_value_array_append_element(copy_obj
,
185 (void *) element_obj_copy
);
186 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
188 BT_LIB_LOGE_APPEND_CAUSE(
189 "Cannot append to array value: addr=%p",
191 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
196 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
197 array_obj
, copy_obj
);
204 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
208 gpointer key
, element_obj
;
209 struct bt_value
*copy_obj
;
210 struct bt_value
*element_obj_copy
= NULL
;
211 struct bt_value_map
*typed_map_obj
;
213 BT_LOGD("Copying map value: addr=%p", map_obj
);
214 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
215 copy_obj
= bt_value_map_create();
220 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
222 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
223 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
226 BT_LOGD("Copying map value's element: element-addr=%p, "
227 "key=\"%s\"", element_obj
, key_str
);
228 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
230 BT_LIB_LOGE_APPEND_CAUSE(
231 "Cannot copy map value's element: "
232 "map-addr=%p, key=\"%s\"",
234 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
238 BT_ASSERT(element_obj_copy
);
239 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
240 (void *) element_obj_copy
);
241 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
243 BT_LIB_LOGE_APPEND_CAUSE(
244 "Cannot insert into map value: addr=%p, key=\"%s\"",
246 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
251 BT_LOGD("Copied map value: addr=%p", map_obj
);
258 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
259 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
260 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
261 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
262 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
263 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
264 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
265 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
266 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
270 bt_bool
bt_value_null_is_equal(
271 const struct bt_value
*object_a
__attribute__((unused
)),
272 const struct bt_value
*object_b
__attribute__((unused
)))
275 * Always BT_TRUE since bt_value_is_equal() already checks if both
276 * object_a and object_b have the same type, and in the case of
277 * null value objects, they're always the same if it is so.
283 bt_bool
bt_value_bool_is_equal(const struct bt_value
*object_a
,
284 const struct bt_value
*object_b
)
286 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
287 BT_VALUE_TO_BOOL(object_b
)->value
) {
288 BT_LOGT("Boolean value objects are different: "
289 "bool-a-val=%d, bool-b-val=%d",
290 BT_VALUE_TO_BOOL(object_a
)->value
,
291 BT_VALUE_TO_BOOL(object_b
)->value
);
299 bt_bool
bt_value_integer_is_equal(const struct bt_value
*object_a
,
300 const struct bt_value
*object_b
)
302 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
303 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
304 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
305 BT_LOGT("Unsigned integer value objects are different: "
306 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
307 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
308 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
310 BT_LOGT("Signed integer value objects are different: "
311 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
312 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
313 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
323 bt_bool
bt_value_real_is_equal(const struct bt_value
*object_a
,
324 const struct bt_value
*object_b
)
326 if (BT_VALUE_TO_REAL(object_a
)->value
!=
327 BT_VALUE_TO_REAL(object_b
)->value
) {
328 BT_LOGT("Real number value objects are different: "
329 "real-a-val=%f, real-b-val=%f",
330 BT_VALUE_TO_REAL(object_a
)->value
,
331 BT_VALUE_TO_REAL(object_b
)->value
);
339 bt_bool
bt_value_string_is_equal(const struct bt_value
*object_a
,
340 const struct bt_value
*object_b
)
342 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
343 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
344 BT_LOGT("String value objects are different: "
345 "string-a-val=\"%s\", string-b-val=\"%s\"",
346 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
347 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
355 bt_bool
bt_value_array_is_equal(const struct bt_value
*object_a
,
356 const struct bt_value
*object_b
)
359 bt_bool ret
= BT_TRUE
;
360 const struct bt_value_array
*array_obj_a
=
361 BT_VALUE_TO_ARRAY(object_a
);
363 if (bt_value_array_get_length(object_a
) !=
364 bt_value_array_get_length(object_b
)) {
365 BT_LOGT("Array values are different: size mismatch "
366 "value-a-addr=%p, value-b-addr=%p, "
367 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
369 bt_value_array_get_length(object_a
),
370 bt_value_array_get_length(object_b
));
375 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
376 const struct bt_value
*element_obj_a
;
377 const struct bt_value
*element_obj_b
;
379 element_obj_a
= bt_value_array_borrow_element_by_index_const(
381 element_obj_b
= bt_value_array_borrow_element_by_index_const(
384 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
385 BT_LOGT("Array values's elements are different: "
386 "value-a-addr=%p, value-b-addr=%p, index=%d",
387 element_obj_a
, element_obj_b
, i
);
398 bt_bool
bt_value_map_is_equal(const struct bt_value
*object_a
,
399 const struct bt_value
*object_b
)
401 bt_bool ret
= BT_TRUE
;
403 gpointer key
, element_obj_a
;
404 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
406 if (bt_value_map_get_size(object_a
) !=
407 bt_value_map_get_size(object_b
)) {
408 BT_LOGT("Map values are different: size mismatch "
409 "value-a-addr=%p, value-b-addr=%p, "
410 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
412 bt_value_map_get_size(object_a
),
413 bt_value_map_get_size(object_b
));
418 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
420 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
421 const struct bt_value
*element_obj_b
;
422 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
424 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
427 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
428 BT_LOGT("Map values's elements are different: "
429 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
430 element_obj_a
, element_obj_b
, key_str
);
441 bt_bool (* const is_equal_funcs
[])(const struct bt_value
*,
442 const struct bt_value
*) = {
443 [BT_VALUE_TYPE_NULL
] = bt_value_null_is_equal
,
444 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_is_equal
,
445 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_is_equal
,
446 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_is_equal
,
447 [BT_VALUE_TYPE_REAL
] = bt_value_real_is_equal
,
448 [BT_VALUE_TYPE_STRING
] = bt_value_string_is_equal
,
449 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_is_equal
,
450 [BT_VALUE_TYPE_MAP
] = bt_value_map_is_equal
,
454 void bt_value_null_freeze(struct bt_value
*object
__attribute__((unused
)))
459 void bt_value_generic_freeze(struct bt_value
*object
)
461 object
->frozen
= BT_TRUE
;
465 void bt_value_array_freeze(struct bt_value
*object
)
468 struct bt_value_array
*typed_array_obj
=
469 BT_VALUE_TO_ARRAY(object
);
471 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
472 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
475 bt_value_generic_freeze(object
);
479 void bt_value_map_freeze(struct bt_value
*object
)
482 gpointer key
, element_obj
;
483 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
485 g_hash_table_iter_init(&iter
, map_obj
->ght
);
487 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
488 bt_value_freeze(element_obj
);
491 bt_value_generic_freeze(object
);
495 void (* const freeze_funcs
[])(struct bt_value
*) = {
496 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
497 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
498 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
499 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
500 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
501 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
502 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
503 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
507 void bt_value_destroy(struct bt_object
*obj
)
509 struct bt_value
*value
;
511 value
= container_of(obj
, struct bt_value
, base
);
512 BT_LOGD("Destroying value: addr=%p", value
);
514 if (bt_value_is_null(value
)) {
515 BT_LOGD_STR("Not destroying the null value singleton.");
519 if (destroy_funcs
[value
->type
]) {
520 destroy_funcs
[value
->type
](value
);
526 void _bt_value_freeze(const struct bt_value
*c_object
)
528 const struct bt_value
*object
= (void *) c_object
;
532 if (object
->frozen
) {
536 BT_LOGD("Freezing value: addr=%p", object
);
537 freeze_funcs
[object
->type
]((void *) object
);
544 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
546 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(object
);
551 struct bt_value
bt_value_create_base(enum bt_value_type type
)
553 struct bt_value value
;
556 value
.frozen
= BT_FALSE
;
557 bt_object_init_shared(&value
.base
, bt_value_destroy
);
562 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
564 struct bt_value_bool
*bool_obj
;
566 BT_ASSERT_PRE_NO_ERROR();
568 BT_LOGD("Creating boolean value object: val=%d", val
);
569 bool_obj
= g_new0(struct bt_value_bool
, 1);
571 BT_LIB_LOGE_APPEND_CAUSE(
572 "Failed to allocate one boolean value object.");
576 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
577 bool_obj
->value
= val
;
578 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
581 return (void *) bool_obj
;
585 struct bt_value
*bt_value_bool_create(void)
587 BT_ASSERT_PRE_NO_ERROR();
589 return bt_value_bool_create_init(BT_FALSE
);
593 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
596 struct bt_value_integer
*integer_obj
;
598 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
599 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
601 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
602 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
605 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
609 integer_obj
= g_new0(struct bt_value_integer
, 1);
611 BT_LIB_LOGE_APPEND_CAUSE(
612 "Failed to allocate one integer value object.");
616 integer_obj
->base
= bt_value_create_base(type
);
617 integer_obj
->value
.u
= uval
;
618 BT_LOGD("Created %ssigned integer value object: addr=%p",
619 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
623 return (void *) integer_obj
;
627 struct bt_value
*bt_value_integer_unsigned_create_init(uint64_t val
)
629 BT_ASSERT_PRE_NO_ERROR();
631 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
636 struct bt_value
*bt_value_integer_unsigned_create(void)
638 BT_ASSERT_PRE_NO_ERROR();
640 return bt_value_integer_unsigned_create_init(0);
644 struct bt_value
*bt_value_integer_signed_create_init(int64_t val
)
646 BT_ASSERT_PRE_NO_ERROR();
648 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
653 struct bt_value
*bt_value_integer_signed_create(void)
655 BT_ASSERT_PRE_NO_ERROR();
657 return bt_value_integer_signed_create_init(0);
661 struct bt_value
*bt_value_real_create_init(double val
)
663 struct bt_value_real
*real_obj
;
665 BT_ASSERT_PRE_NO_ERROR();
667 BT_LOGD("Creating real number value object: val=%f", val
);
668 real_obj
= g_new0(struct bt_value_real
, 1);
670 BT_LIB_LOGE_APPEND_CAUSE(
671 "Failed to allocate one real number value object.");
675 real_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_REAL
);
676 real_obj
->value
= val
;
677 BT_LOGD("Created real number value object: addr=%p",
681 return (void *) real_obj
;
685 struct bt_value
*bt_value_real_create(void)
687 BT_ASSERT_PRE_NO_ERROR();
689 return bt_value_real_create_init(0.);
693 struct bt_value
*bt_value_string_create_init(const char *val
)
695 struct bt_value_string
*string_obj
= NULL
;
697 BT_ASSERT_PRE_NO_ERROR();
698 BT_ASSERT_PRE_NON_NULL("raw-value", val
, "Raw value");
700 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
701 string_obj
= g_new0(struct bt_value_string
, 1);
703 BT_LIB_LOGE_APPEND_CAUSE(
704 "Failed to allocate one string object.");
708 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
709 string_obj
->gstr
= g_string_new(val
);
710 if (!string_obj
->gstr
) {
711 BT_LIB_LOGE_APPEND_CAUSE(
712 "Failed to allocate a GString.");
718 BT_LOGD("Created string value object: addr=%p",
722 return (void *) string_obj
;
726 struct bt_value
*bt_value_string_create(void)
728 BT_ASSERT_PRE_NO_ERROR();
730 return bt_value_string_create_init("");
734 struct bt_value
*bt_value_array_create(void)
736 struct bt_value_array
*array_obj
;
738 BT_ASSERT_PRE_NO_ERROR();
740 BT_LOGD_STR("Creating empty array value object.");
741 array_obj
= g_new0(struct bt_value_array
, 1);
743 BT_LIB_LOGE_APPEND_CAUSE(
744 "Failed to allocate one array object.");
748 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
749 array_obj
->garray
= bt_g_ptr_array_new_full(0,
750 (GDestroyNotify
) bt_object_put_ref
);
751 if (!array_obj
->garray
) {
752 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
758 BT_LOGD("Created array value object: addr=%p",
762 return (void *) array_obj
;
766 struct bt_value
*bt_value_map_create(void)
768 struct bt_value_map
*map_obj
;
770 BT_ASSERT_PRE_NO_ERROR();
772 BT_LOGD_STR("Creating empty map value object.");
773 map_obj
= g_new0(struct bt_value_map
, 1);
775 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
779 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
780 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
781 NULL
, (GDestroyNotify
) bt_object_put_ref
);
783 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
789 BT_LOGD("Created map value object: addr=%p",
793 return (void *) map_obj
;
797 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
799 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(bool_obj
);
800 BT_ASSERT_PRE_DEV_VALUE_IS_BOOL(bool_obj
);
801 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
805 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
807 BT_ASSERT_PRE_VALUE_NON_NULL(bool_obj
);
808 BT_ASSERT_PRE_VALUE_IS_BOOL(bool_obj
);
809 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
810 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
815 uint64_t bt_value_integer_unsigned_get(const struct bt_value
*integer_obj
)
817 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(integer_obj
);
818 BT_ASSERT_PRE_DEV_VALUE_IS_UNSIGNED_INT(integer_obj
);
819 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
823 int64_t bt_value_integer_signed_get(const struct bt_value
*integer_obj
)
825 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(integer_obj
);
826 BT_ASSERT_PRE_DEV_VALUE_IS_SIGNED_INT(integer_obj
);
827 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
831 void set_integer_value(struct bt_value
*integer_obj
,
832 enum bt_value_type expected_type
__attribute__((unused
)),
834 const char *api_func
)
836 BT_ASSERT_PRE_DEV_VALUE_HOT_FROM_FUNC(api_func
, integer_obj
);
837 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
841 void bt_value_integer_unsigned_set(struct bt_value
*integer_obj
,
844 BT_ASSERT_PRE_VALUE_NON_NULL(integer_obj
);
845 BT_ASSERT_PRE_VALUE_IS_UNSIGNED_INT(integer_obj
);
846 set_integer_value(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
,
848 BT_LOGT("Set unsigned integer value's raw value: "
849 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
853 void bt_value_integer_signed_set(struct bt_value
*integer_obj
,
856 BT_ASSERT_PRE_VALUE_NON_NULL(integer_obj
);
857 BT_ASSERT_PRE_VALUE_IS_SIGNED_INT(integer_obj
);
858 set_integer_value(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
859 (uint64_t) val
, __func__
);
860 BT_LOGT("Set signed integer value's raw value: "
861 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
865 double bt_value_real_get(const struct bt_value
*real_obj
)
867 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(real_obj
);
868 BT_ASSERT_PRE_DEV_VALUE_IS_REAL(real_obj
);
869 return BT_VALUE_TO_REAL(real_obj
)->value
;
873 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
875 BT_ASSERT_PRE_VALUE_NON_NULL(real_obj
);
876 BT_ASSERT_PRE_VALUE_IS_REAL(real_obj
);
877 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
);
878 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
879 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
884 const char *bt_value_string_get(const struct bt_value
*string_obj
)
886 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(string_obj
);
887 BT_ASSERT_PRE_DEV_VALUE_IS_STRING(string_obj
);
888 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
892 enum bt_value_string_set_status
bt_value_string_set(
893 struct bt_value
*string_obj
, const char *val
)
895 BT_ASSERT_PRE_NO_ERROR();
896 BT_ASSERT_PRE_VALUE_NON_NULL(string_obj
);
897 BT_ASSERT_PRE_VALUE_IS_STRING(string_obj
);
898 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
);
899 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
900 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
902 return BT_FUNC_STATUS_OK
;
906 uint64_t bt_value_array_get_length(const struct bt_value
*array_obj
)
908 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(array_obj
);
909 BT_ASSERT_PRE_DEV_VALUE_IS_ARRAY(array_obj
);
910 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
914 struct bt_value
*bt_value_array_borrow_element_by_index(
915 struct bt_value
*array_obj
, uint64_t index
)
917 struct bt_value_array
*typed_array_obj
=
918 BT_VALUE_TO_ARRAY(array_obj
);
920 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(array_obj
);
921 BT_ASSERT_PRE_DEV_VALUE_IS_ARRAY(array_obj
);
922 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
923 return g_ptr_array_index(typed_array_obj
->garray
, index
);
927 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
928 const struct bt_value
*array_obj
,
931 return bt_value_array_borrow_element_by_index(
932 (void *) array_obj
, index
);
936 enum bt_value_array_append_element_status
append_array_element(
937 struct bt_value
*array_obj
,
938 struct bt_value
*element_obj
, const char *api_func
)
940 struct bt_value_array
*typed_array_obj
=
941 BT_VALUE_TO_ARRAY(array_obj
);
943 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
944 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "array-value-object",
945 array_obj
, "Array value object");
946 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "element-value-object",
947 element_obj
, "Element value object");
948 BT_ASSERT_PRE_VALUE_HAS_TYPE_FROM_FUNC(api_func
, "value-object",
949 array_obj
, "array", BT_VALUE_TYPE_ARRAY
);
950 BT_ASSERT_PRE_DEV_VALUE_HOT_FROM_FUNC(api_func
, array_obj
);
951 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
952 bt_object_get_ref(element_obj
);
953 BT_LOGT("Appended element to array value: array-value-addr=%p, "
954 "element-value-addr=%p, new-size=%u",
955 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
956 return BT_FUNC_STATUS_OK
;
960 enum bt_value_array_append_element_status
bt_value_array_append_element(
961 struct bt_value
*array_obj
,
962 struct bt_value
*element_obj
)
964 return append_array_element(array_obj
, element_obj
, __func__
);
968 enum bt_value_array_append_element_status
969 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
971 enum bt_value_array_append_element_status ret
;
972 struct bt_value
*bool_obj
= NULL
;
974 BT_ASSERT_PRE_NO_ERROR();
976 bool_obj
= bt_value_bool_create_init(val
);
977 ret
= append_array_element(array_obj
,
978 (void *) bool_obj
, __func__
);
979 bt_object_put_ref(bool_obj
);
984 enum bt_value_array_append_element_status
985 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
988 enum bt_value_array_append_element_status ret
;
989 struct bt_value
*integer_obj
= NULL
;
991 BT_ASSERT_PRE_NO_ERROR();
993 integer_obj
= bt_value_integer_unsigned_create_init(val
);
994 ret
= append_array_element(array_obj
,
995 (void *) integer_obj
, __func__
);
996 bt_object_put_ref(integer_obj
);
1001 enum bt_value_array_append_element_status
1002 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
1005 enum bt_value_array_append_element_status ret
;
1006 struct bt_value
*integer_obj
= NULL
;
1008 BT_ASSERT_PRE_NO_ERROR();
1010 integer_obj
= bt_value_integer_signed_create_init(val
);
1011 ret
= append_array_element(array_obj
,
1012 (void *) integer_obj
, __func__
);
1013 bt_object_put_ref(integer_obj
);
1018 enum bt_value_array_append_element_status
1019 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
1021 enum bt_value_array_append_element_status ret
;
1022 struct bt_value
*real_obj
= NULL
;
1024 BT_ASSERT_PRE_NO_ERROR();
1026 real_obj
= bt_value_real_create_init(val
);
1027 ret
= append_array_element(array_obj
,
1028 (void *) real_obj
, __func__
);
1029 bt_object_put_ref(real_obj
);
1034 enum bt_value_array_append_element_status
1035 bt_value_array_append_string_element(struct bt_value
*array_obj
,
1038 enum bt_value_array_append_element_status ret
;
1039 struct bt_value
*string_obj
= NULL
;
1041 BT_ASSERT_PRE_NO_ERROR();
1043 string_obj
= bt_value_string_create_init(val
);
1044 ret
= append_array_element(array_obj
,
1045 (void *) string_obj
, __func__
);
1046 bt_object_put_ref(string_obj
);
1051 enum bt_value_array_append_element_status
1052 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
,
1053 struct bt_value
**element_obj
)
1055 enum bt_value_array_append_element_status ret
;
1056 struct bt_value
*empty_array_obj
= NULL
;
1058 BT_ASSERT_PRE_NO_ERROR();
1060 empty_array_obj
= bt_value_array_create();
1061 ret
= append_array_element(array_obj
,
1062 (void *) empty_array_obj
, __func__
);
1065 *element_obj
= empty_array_obj
;
1068 bt_object_put_ref(empty_array_obj
);
1073 enum bt_value_array_append_element_status
1074 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
,
1075 struct bt_value
**element_obj
)
1077 enum bt_value_array_append_element_status ret
;
1078 struct bt_value
*map_obj
= NULL
;
1080 BT_ASSERT_PRE_NO_ERROR();
1082 map_obj
= bt_value_map_create();
1083 ret
= append_array_element(array_obj
,
1084 (void *) map_obj
, __func__
);
1087 *element_obj
= map_obj
;
1090 bt_object_put_ref(map_obj
);
1095 enum bt_value_array_set_element_by_index_status
1096 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1097 struct bt_value
*element_obj
)
1099 struct bt_value_array
*typed_array_obj
=
1100 BT_VALUE_TO_ARRAY(array_obj
);
1102 BT_ASSERT_PRE_NO_ERROR();
1103 BT_ASSERT_PRE_NON_NULL("array-value-object", array_obj
,
1104 "Array value object");
1105 BT_ASSERT_PRE_NON_NULL("element-value-object", element_obj
,
1106 "Element value object");
1107 BT_ASSERT_PRE_VALUE_IS_ARRAY(array_obj
);
1108 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
);
1109 BT_ASSERT_PRE_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
1110 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1111 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1112 bt_object_get_ref(element_obj
);
1113 BT_LOGT("Set array value's element: array-value-addr=%p, "
1114 "index=%" PRIu64
", element-value-addr=%p",
1115 array_obj
, index
, element_obj
);
1116 return BT_FUNC_STATUS_OK
;
1120 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1122 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(map_obj
);
1123 BT_ASSERT_PRE_DEV_VALUE_IS_MAP(map_obj
);
1124 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1128 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1131 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(map_obj
);
1132 BT_ASSERT_PRE_DEV_KEY_NON_NULL(key
);
1133 BT_ASSERT_PRE_DEV_VALUE_IS_MAP(map_obj
);
1134 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1135 GUINT_TO_POINTER(g_quark_from_string(key
)));
1139 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1140 const struct bt_value
*map_obj
, const char *key
)
1142 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1146 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1148 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(map_obj
);
1149 BT_ASSERT_PRE_DEV_KEY_NON_NULL(key
);
1150 BT_ASSERT_PRE_DEV_VALUE_IS_MAP(map_obj
);
1151 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1152 GUINT_TO_POINTER(g_quark_from_string(key
)));
1156 enum bt_value_map_insert_entry_status
insert_map_value_entry(
1157 struct bt_value
*map_obj
, const char *key
,
1158 struct bt_value
*element_obj
, const char *api_func
)
1160 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
1161 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "map-value-object",
1162 map_obj
, "Map value object");
1163 BT_ASSERT_PRE_KEY_NON_NULL_FROM_FUNC(api_func
, key
);
1164 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
,
1165 "element-value-object", element_obj
, "Element value object");
1166 BT_ASSERT_PRE_VALUE_HAS_TYPE_FROM_FUNC(api_func
, "value-object",
1167 map_obj
, "map", BT_VALUE_TYPE_MAP
);
1168 BT_ASSERT_PRE_DEV_VALUE_HOT_FROM_FUNC(api_func
, map_obj
);
1169 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1170 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1171 bt_object_get_ref(element_obj
);
1172 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1173 "key=\"%s\", element-value-addr=%p",
1174 map_obj
, key
, element_obj
);
1175 return BT_FUNC_STATUS_OK
;
1179 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1180 struct bt_value
*map_obj
, const char *key
,
1181 struct bt_value
*element_obj
)
1183 return insert_map_value_entry(map_obj
, key
, element_obj
, __func__
);
1187 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1188 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1190 enum bt_value_map_insert_entry_status ret
;
1191 struct bt_value
*bool_obj
= NULL
;
1193 BT_ASSERT_PRE_NO_ERROR();
1195 bool_obj
= bt_value_bool_create_init(val
);
1196 ret
= insert_map_value_entry(map_obj
, key
,
1197 (void *) bool_obj
, __func__
);
1198 bt_object_put_ref(bool_obj
);
1203 enum bt_value_map_insert_entry_status
1204 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1205 const char *key
, uint64_t val
)
1207 enum bt_value_map_insert_entry_status ret
;
1208 struct bt_value
*integer_obj
= NULL
;
1210 BT_ASSERT_PRE_NO_ERROR();
1212 integer_obj
= bt_value_integer_unsigned_create_init(val
);
1213 ret
= insert_map_value_entry(map_obj
, key
,
1214 (void *) integer_obj
, __func__
);
1215 bt_object_put_ref(integer_obj
);
1220 enum bt_value_map_insert_entry_status
1221 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1222 const char *key
, int64_t val
)
1224 enum bt_value_map_insert_entry_status ret
;
1225 struct bt_value
*integer_obj
= NULL
;
1227 BT_ASSERT_PRE_NO_ERROR();
1229 integer_obj
= bt_value_integer_signed_create_init(val
);
1230 ret
= insert_map_value_entry(map_obj
, key
,
1231 (void *) integer_obj
, __func__
);
1232 bt_object_put_ref(integer_obj
);
1237 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1238 struct bt_value
*map_obj
, const char *key
, double val
)
1240 enum bt_value_map_insert_entry_status ret
;
1241 struct bt_value
*real_obj
= NULL
;
1243 BT_ASSERT_PRE_NO_ERROR();
1245 real_obj
= bt_value_real_create_init(val
);
1246 ret
= insert_map_value_entry(map_obj
, key
,
1247 (void *) real_obj
, __func__
);
1248 bt_object_put_ref(real_obj
);
1253 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1254 struct bt_value
*map_obj
, const char *key
,
1257 enum bt_value_map_insert_entry_status ret
;
1258 struct bt_value
*string_obj
= NULL
;
1260 BT_ASSERT_PRE_NO_ERROR();
1262 string_obj
= bt_value_string_create_init(val
);
1263 ret
= insert_map_value_entry(map_obj
, key
,
1264 (void *) string_obj
, __func__
);
1265 bt_object_put_ref(string_obj
);
1270 enum bt_value_map_insert_entry_status
1271 bt_value_map_insert_empty_array_entry(
1272 struct bt_value
*map_obj
, const char *key
,
1273 bt_value
**entry_obj
)
1275 enum bt_value_map_insert_entry_status ret
;
1276 struct bt_value
*array_obj
= NULL
;
1278 BT_ASSERT_PRE_NO_ERROR();
1280 array_obj
= bt_value_array_create();
1281 ret
= insert_map_value_entry(map_obj
, key
,
1282 (void *) array_obj
, __func__
);
1285 *entry_obj
= array_obj
;
1288 bt_object_put_ref(array_obj
);
1293 enum bt_value_map_insert_entry_status
1294 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
,
1295 bt_value
**entry_obj
)
1297 enum bt_value_map_insert_entry_status ret
;
1298 struct bt_value
*empty_map_obj
= NULL
;
1300 BT_ASSERT_PRE_NO_ERROR();
1302 empty_map_obj
= bt_value_map_create();
1303 ret
= insert_map_value_entry(map_obj
, key
,
1304 (void *) empty_map_obj
, __func__
);
1307 *entry_obj
= empty_map_obj
;
1310 bt_object_put_ref(empty_map_obj
);
1315 enum bt_value_map_foreach_entry_status
foreach_map_entry(
1316 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1317 void *data
, const char *api_func
,
1318 const char *user_func_name
)
1320 int status
= BT_FUNC_STATUS_OK
;
1321 gpointer key
, element_obj
;
1322 GHashTableIter iter
;
1323 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1325 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
1326 BT_ASSERT_PRE_DEV_VALUE_NON_NULL_FROM_FUNC(api_func
, map_obj
);
1327 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "user-function",
1328 func
, "User function");
1329 BT_ASSERT_PRE_VALUE_HAS_TYPE_FROM_FUNC(api_func
, "value-object",
1330 map_obj
, "map", BT_VALUE_TYPE_MAP
);
1331 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1333 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1334 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1336 status
= func(key_str
, element_obj
, data
);
1337 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(user_func_name
,
1339 if (status
!= BT_FUNC_STATUS_OK
) {
1341 BT_LIB_LOGE_APPEND_CAUSE(
1342 "User function failed while iterating "
1343 "map value entries: "
1344 "status=%s, key=\"%s\", "
1345 "value-addr=%p, data=%p",
1346 bt_common_func_status_string(status
),
1347 key_str
, element_obj
, data
);
1349 if (status
== BT_FUNC_STATUS_ERROR
) {
1351 * User function error becomes a
1352 * user error from this
1353 * function's caller's
1356 status
= BT_FUNC_STATUS_USER_ERROR
;
1359 BT_ASSERT(status
== BT_FUNC_STATUS_INTERRUPTED
);
1360 BT_LOGT("User interrupted the loop: status=%s, "
1361 "key=\"%s\", value-addr=%p, data=%p",
1362 bt_common_func_status_string(status
),
1363 key_str
, element_obj
, data
);
1374 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1375 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1378 return foreach_map_entry(map_obj
, func
, data
, __func__
,
1379 "bt_value_map_foreach_entry_func");
1383 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1384 const struct bt_value
*map_obj
,
1385 bt_value_map_foreach_entry_const_func func
, void *data
)
1387 return (int) foreach_map_entry((void *) map_obj
,
1388 (bt_value_map_foreach_entry_func
) func
, data
, __func__
,
1389 "bt_value_map_foreach_entry_const_func");
1392 struct extend_map_element_data
{
1393 struct bt_value
*base_obj
;
1397 bt_value_map_foreach_entry_const_func_status
extend_map_element(
1398 const char *key
, const struct bt_value
*extension_obj_elem
,
1402 struct extend_map_element_data
*extend_data
= data
;
1403 struct bt_value
*extension_obj_elem_copy
= NULL
;
1405 /* Copy object which is to replace the current one */
1406 status
= bt_value_copy(extension_obj_elem
, &extension_obj_elem_copy
);
1408 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1409 extension_obj_elem
);
1413 BT_ASSERT(extension_obj_elem_copy
);
1415 /* Replace in base map value. */
1416 status
= bt_value_map_insert_entry(extend_data
->base_obj
, key
,
1417 extension_obj_elem_copy
);
1419 BT_LIB_LOGE_APPEND_CAUSE(
1420 "Cannot replace value in base map value: key=\"%s\", "
1421 "%![base-map-value-]+v, %![element-value-]+v",
1422 key
, extend_data
->base_obj
, extension_obj_elem_copy
);
1429 BT_ASSERT(status
< 0);
1432 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1433 BT_ASSERT(status
== BT_FUNC_STATUS_OK
||
1434 status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1439 enum bt_value_map_extend_status
bt_value_map_extend(
1440 struct bt_value
*base_map_obj
,
1441 const struct bt_value
*extension_obj
)
1443 int status
= BT_FUNC_STATUS_OK
;
1444 struct extend_map_element_data extend_data
= {
1448 BT_ASSERT_PRE_NO_ERROR();
1449 BT_ASSERT_PRE_NON_NULL("base-value-object", base_map_obj
,
1450 "Base value object");
1451 BT_ASSERT_PRE_DEV_VALUE_HOT(base_map_obj
);
1452 BT_ASSERT_PRE_NON_NULL("extension-value-object", extension_obj
,
1453 "Extension value object");
1454 BT_ASSERT_PRE_VALUE_HAS_TYPE("base-value-object", base_map_obj
,
1455 "map", BT_VALUE_TYPE_MAP
);
1456 BT_ASSERT_PRE_VALUE_HAS_TYPE("extension-value-object", extension_obj
,
1457 "map", BT_VALUE_TYPE_MAP
);
1458 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1459 base_map_obj
, extension_obj
);
1462 * For each key in the extension map object, replace this key
1463 * in the base map object.
1465 extend_data
.base_obj
= base_map_obj
;
1466 status
= bt_value_map_foreach_entry_const(extension_obj
,
1467 extend_map_element
, &extend_data
);
1468 if (status
!= BT_FUNC_STATUS_OK
) {
1469 BT_ASSERT(status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1470 BT_LIB_LOGE_APPEND_CAUSE(
1471 "Cannot iterate on the extension object's elements: "
1472 "%![extension-value-]+v", extension_obj
);
1479 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1480 struct bt_value
**copy_obj
)
1482 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1484 BT_ASSERT_PRE_NO_ERROR();
1485 BT_ASSERT_PRE_VALUE_NON_NULL(object
);
1486 BT_ASSERT_PRE_NON_NULL("value-object-copy-output", copy_obj
,
1487 "Value object copy (output)");
1488 BT_LOGD("Copying value object: addr=%p", object
);
1489 *copy_obj
= copy_funcs
[object
->type
](object
);
1491 BT_LOGD("Copied value object: copy-value-addr=%p",
1494 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1496 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1503 bt_bool
bt_value_is_equal(const struct bt_value
*object_a
,
1504 const struct bt_value
*object_b
)
1506 bt_bool ret
= BT_FALSE
;
1508 BT_ASSERT_PRE_DEV_NON_NULL("value-object-a", object_a
,
1510 BT_ASSERT_PRE_DEV_NON_NULL("value-object-b", object_b
,
1513 if (object_a
->type
!= object_b
->type
) {
1514 BT_LOGT("Values are different: type mismatch: "
1515 "value-a-addr=%p, value-b-addr=%p, "
1516 "value-a-type=%s, value-b-type=%s",
1518 bt_common_value_type_string(object_a
->type
),
1519 bt_common_value_type_string(object_b
->type
));
1523 ret
= is_equal_funcs
[object_a
->type
](object_a
, object_b
);
1530 void bt_value_get_ref(const struct bt_value
*value
)
1532 bt_object_get_ref(value
);
1536 void bt_value_put_ref(const struct bt_value
*value
)
1538 bt_object_put_ref(value
);