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
,
59 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
62 void bt_value_destroy(struct bt_object
*obj
);
65 void bt_value_string_destroy(struct bt_value
*object
)
67 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
68 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
72 void bt_value_array_destroy(struct bt_value
*object
)
75 * Pointer array's registered value destructor will take care
76 * of putting each contained object.
78 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
79 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
83 void bt_value_map_destroy(struct bt_value
*object
)
86 * Hash table's registered value destructor will take care of
87 * putting each contained object. Keys are GQuarks and cannot
88 * be destroyed anyway.
90 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
91 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
95 void (* const destroy_funcs
[])(struct bt_value
*) = {
96 [BT_VALUE_TYPE_NULL
] = NULL
,
97 [BT_VALUE_TYPE_BOOL
] = NULL
,
98 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
99 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
100 [BT_VALUE_TYPE_REAL
] = NULL
,
101 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
102 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
103 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
107 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
109 BT_ASSERT(null_obj
== bt_value_null
);
111 bt_object_get_ref_no_null_check(bt_value_null
);
112 return (void *) bt_value_null
;
116 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
118 return bt_value_bool_create_init(
119 BT_VALUE_TO_BOOL(bool_obj
)->value
);
123 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
127 struct bt_value
*bt_value_integer_copy(
128 const struct bt_value
*integer_obj
)
130 return bt_value_integer_create_init(integer_obj
->type
,
131 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
135 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
137 return bt_value_real_create_init(
138 BT_VALUE_TO_REAL(real_obj
)->value
);
142 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
144 return bt_value_string_create_init(
145 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
149 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
153 struct bt_value
*copy_obj
;
154 struct bt_value_array
*typed_array_obj
;
156 BT_LOGD("Copying array value: addr=%p", array_obj
);
157 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
158 copy_obj
= bt_value_array_create();
160 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
164 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
165 struct bt_value
*element_obj_copy
= NULL
;
166 const struct bt_value
*element_obj
=
167 bt_value_array_borrow_element_by_index_const(
170 BT_LOGD("Copying array value's element: element-addr=%p, "
171 "index=%d", element_obj
, i
);
172 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
174 BT_LIB_LOGE_APPEND_CAUSE(
175 "Cannot copy array value's element: "
176 "array-addr=%p, index=%d",
178 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
182 BT_ASSERT(element_obj_copy
);
183 ret
= bt_value_array_append_element(copy_obj
,
184 (void *) element_obj_copy
);
185 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
187 BT_LIB_LOGE_APPEND_CAUSE(
188 "Cannot append to array value: addr=%p",
190 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
195 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
196 array_obj
, copy_obj
);
203 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
207 gpointer key
, element_obj
;
208 struct bt_value
*copy_obj
;
209 struct bt_value
*element_obj_copy
= NULL
;
210 struct bt_value_map
*typed_map_obj
;
212 BT_LOGD("Copying map value: addr=%p", map_obj
);
213 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
214 copy_obj
= bt_value_map_create();
219 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
221 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
222 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
225 BT_LOGD("Copying map value's element: element-addr=%p, "
226 "key=\"%s\"", element_obj
, key_str
);
227 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
229 BT_LIB_LOGE_APPEND_CAUSE(
230 "Cannot copy map value's element: "
231 "map-addr=%p, key=\"%s\"",
233 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
237 BT_ASSERT(element_obj_copy
);
238 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
239 (void *) element_obj_copy
);
240 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
242 BT_LIB_LOGE_APPEND_CAUSE(
243 "Cannot insert into map value: addr=%p, key=\"%s\"",
245 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
250 BT_LOGD("Copied map value: addr=%p", map_obj
);
257 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
258 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
259 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
260 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
261 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
262 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
263 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
264 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
265 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
269 bt_bool
bt_value_null_is_equal(const struct bt_value
*object_a
,
270 const struct bt_value
*object_b
)
273 * Always BT_TRUE since bt_value_is_equal() already checks if both
274 * object_a and object_b have the same type, and in the case of
275 * null value objects, they're always the same if it is so.
281 bt_bool
bt_value_bool_is_equal(const struct bt_value
*object_a
,
282 const struct bt_value
*object_b
)
284 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
285 BT_VALUE_TO_BOOL(object_b
)->value
) {
286 BT_LOGT("Boolean value objects are different: "
287 "bool-a-val=%d, bool-b-val=%d",
288 BT_VALUE_TO_BOOL(object_a
)->value
,
289 BT_VALUE_TO_BOOL(object_b
)->value
);
297 bt_bool
bt_value_integer_is_equal(const struct bt_value
*object_a
,
298 const struct bt_value
*object_b
)
300 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
301 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
302 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
303 BT_LOGT("Unsigned integer value objects are different: "
304 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
305 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
306 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
308 BT_LOGT("Signed integer value objects are different: "
309 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
310 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
311 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
321 bt_bool
bt_value_real_is_equal(const struct bt_value
*object_a
,
322 const struct bt_value
*object_b
)
324 if (BT_VALUE_TO_REAL(object_a
)->value
!=
325 BT_VALUE_TO_REAL(object_b
)->value
) {
326 BT_LOGT("Real number value objects are different: "
327 "real-a-val=%f, real-b-val=%f",
328 BT_VALUE_TO_REAL(object_a
)->value
,
329 BT_VALUE_TO_REAL(object_b
)->value
);
337 bt_bool
bt_value_string_is_equal(const struct bt_value
*object_a
,
338 const struct bt_value
*object_b
)
340 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
341 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
342 BT_LOGT("String value objects are different: "
343 "string-a-val=\"%s\", string-b-val=\"%s\"",
344 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
345 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
353 bt_bool
bt_value_array_is_equal(const struct bt_value
*object_a
,
354 const struct bt_value
*object_b
)
357 bt_bool ret
= BT_TRUE
;
358 const struct bt_value_array
*array_obj_a
=
359 BT_VALUE_TO_ARRAY(object_a
);
361 if (bt_value_array_get_length(object_a
) !=
362 bt_value_array_get_length(object_b
)) {
363 BT_LOGT("Array values are different: size mismatch "
364 "value-a-addr=%p, value-b-addr=%p, "
365 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
367 bt_value_array_get_length(object_a
),
368 bt_value_array_get_length(object_b
));
373 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
374 const struct bt_value
*element_obj_a
;
375 const struct bt_value
*element_obj_b
;
377 element_obj_a
= bt_value_array_borrow_element_by_index_const(
379 element_obj_b
= bt_value_array_borrow_element_by_index_const(
382 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
383 BT_LOGT("Array values's elements are different: "
384 "value-a-addr=%p, value-b-addr=%p, index=%d",
385 element_obj_a
, element_obj_b
, i
);
396 bt_bool
bt_value_map_is_equal(const struct bt_value
*object_a
,
397 const struct bt_value
*object_b
)
399 bt_bool ret
= BT_TRUE
;
401 gpointer key
, element_obj_a
;
402 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
404 if (bt_value_map_get_size(object_a
) !=
405 bt_value_map_get_size(object_b
)) {
406 BT_LOGT("Map values are different: size mismatch "
407 "value-a-addr=%p, value-b-addr=%p, "
408 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
410 bt_value_map_get_size(object_a
),
411 bt_value_map_get_size(object_b
));
416 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
418 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
419 const struct bt_value
*element_obj_b
;
420 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
422 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
425 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
426 BT_LOGT("Map values's elements are different: "
427 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
428 element_obj_a
, element_obj_b
, key_str
);
439 bt_bool (* const is_equal_funcs
[])(const struct bt_value
*,
440 const struct bt_value
*) = {
441 [BT_VALUE_TYPE_NULL
] = bt_value_null_is_equal
,
442 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_is_equal
,
443 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_is_equal
,
444 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_is_equal
,
445 [BT_VALUE_TYPE_REAL
] = bt_value_real_is_equal
,
446 [BT_VALUE_TYPE_STRING
] = bt_value_string_is_equal
,
447 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_is_equal
,
448 [BT_VALUE_TYPE_MAP
] = bt_value_map_is_equal
,
452 void bt_value_null_freeze(struct bt_value
*object
)
457 void bt_value_generic_freeze(struct bt_value
*object
)
459 object
->frozen
= BT_TRUE
;
463 void bt_value_array_freeze(struct bt_value
*object
)
466 struct bt_value_array
*typed_array_obj
=
467 BT_VALUE_TO_ARRAY(object
);
469 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
470 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
473 bt_value_generic_freeze(object
);
477 void bt_value_map_freeze(struct bt_value
*object
)
480 gpointer key
, element_obj
;
481 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
483 g_hash_table_iter_init(&iter
, map_obj
->ght
);
485 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
486 bt_value_freeze(element_obj
);
489 bt_value_generic_freeze(object
);
493 void (* const freeze_funcs
[])(struct bt_value
*) = {
494 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
495 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
496 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
497 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
498 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
499 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
500 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
501 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
505 void bt_value_destroy(struct bt_object
*obj
)
507 struct bt_value
*value
;
509 value
= container_of(obj
, struct bt_value
, base
);
510 BT_LOGD("Destroying value: addr=%p", value
);
512 if (bt_value_is_null(value
)) {
513 BT_LOGD_STR("Not destroying the null value singleton.");
517 if (destroy_funcs
[value
->type
]) {
518 destroy_funcs
[value
->type
](value
);
525 void _bt_value_freeze(const struct bt_value
*c_object
)
527 const struct bt_value
*object
= (void *) c_object
;
531 if (object
->frozen
) {
535 BT_LOGD("Freezing value: addr=%p", object
);
536 freeze_funcs
[object
->type
]((void *) object
);
542 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
544 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(object
);
549 struct bt_value
bt_value_create_base(enum bt_value_type type
)
551 struct bt_value value
;
554 value
.frozen
= BT_FALSE
;
555 bt_object_init_shared(&value
.base
, bt_value_destroy
);
559 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
561 struct bt_value_bool
*bool_obj
;
563 BT_ASSERT_PRE_NO_ERROR();
565 BT_LOGD("Creating boolean value object: val=%d", val
);
566 bool_obj
= g_new0(struct bt_value_bool
, 1);
568 BT_LIB_LOGE_APPEND_CAUSE(
569 "Failed to allocate one boolean value object.");
573 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
574 bool_obj
->value
= val
;
575 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
578 return (void *) bool_obj
;
581 struct bt_value
*bt_value_bool_create(void)
583 BT_ASSERT_PRE_NO_ERROR();
585 return bt_value_bool_create_init(BT_FALSE
);
589 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
592 struct bt_value_integer
*integer_obj
;
594 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
595 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
597 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
598 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
601 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
605 integer_obj
= g_new0(struct bt_value_integer
, 1);
607 BT_LIB_LOGE_APPEND_CAUSE(
608 "Failed to allocate one integer value object.");
612 integer_obj
->base
= bt_value_create_base(type
);
613 integer_obj
->value
.u
= uval
;
614 BT_LOGD("Created %ssigned integer value object: addr=%p",
615 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
619 return (void *) integer_obj
;
622 struct bt_value
*bt_value_integer_unsigned_create_init(uint64_t val
)
624 BT_ASSERT_PRE_NO_ERROR();
626 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
630 struct bt_value
*bt_value_integer_unsigned_create(void)
632 BT_ASSERT_PRE_NO_ERROR();
634 return bt_value_integer_unsigned_create_init(0);
637 struct bt_value
*bt_value_integer_signed_create_init(int64_t val
)
639 BT_ASSERT_PRE_NO_ERROR();
641 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
645 struct bt_value
*bt_value_integer_signed_create(void)
647 BT_ASSERT_PRE_NO_ERROR();
649 return bt_value_integer_signed_create_init(0);
652 struct bt_value
*bt_value_real_create_init(double val
)
654 struct bt_value_real
*real_obj
;
656 BT_ASSERT_PRE_NO_ERROR();
658 BT_LOGD("Creating real number value object: val=%f", val
);
659 real_obj
= g_new0(struct bt_value_real
, 1);
661 BT_LIB_LOGE_APPEND_CAUSE(
662 "Failed to allocate one real number value object.");
666 real_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_REAL
);
667 real_obj
->value
= val
;
668 BT_LOGD("Created real number value object: addr=%p",
672 return (void *) real_obj
;
675 struct bt_value
*bt_value_real_create(void)
677 BT_ASSERT_PRE_NO_ERROR();
679 return bt_value_real_create_init(0.);
682 struct bt_value
*bt_value_string_create_init(const char *val
)
684 struct bt_value_string
*string_obj
= NULL
;
686 BT_ASSERT_PRE_NO_ERROR();
687 BT_ASSERT_PRE_NON_NULL("raw-value", val
, "Raw value");
689 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
690 string_obj
= g_new0(struct bt_value_string
, 1);
692 BT_LIB_LOGE_APPEND_CAUSE(
693 "Failed to allocate one string object.");
697 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
698 string_obj
->gstr
= g_string_new(val
);
699 if (!string_obj
->gstr
) {
700 BT_LIB_LOGE_APPEND_CAUSE(
701 "Failed to allocate a GString.");
707 BT_LOGD("Created string value object: addr=%p",
711 return (void *) string_obj
;
714 struct bt_value
*bt_value_string_create(void)
716 BT_ASSERT_PRE_NO_ERROR();
718 return bt_value_string_create_init("");
721 struct bt_value
*bt_value_array_create(void)
723 struct bt_value_array
*array_obj
;
725 BT_ASSERT_PRE_NO_ERROR();
727 BT_LOGD_STR("Creating empty array value object.");
728 array_obj
= g_new0(struct bt_value_array
, 1);
730 BT_LIB_LOGE_APPEND_CAUSE(
731 "Failed to allocate one array object.");
735 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
736 array_obj
->garray
= bt_g_ptr_array_new_full(0,
737 (GDestroyNotify
) bt_object_put_ref
);
738 if (!array_obj
->garray
) {
739 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
745 BT_LOGD("Created array value object: addr=%p",
749 return (void *) array_obj
;
752 struct bt_value
*bt_value_map_create(void)
754 struct bt_value_map
*map_obj
;
756 BT_ASSERT_PRE_NO_ERROR();
758 BT_LOGD_STR("Creating empty map value object.");
759 map_obj
= g_new0(struct bt_value_map
, 1);
761 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
765 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
766 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
767 NULL
, (GDestroyNotify
) bt_object_put_ref
);
769 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
775 BT_LOGD("Created map value object: addr=%p",
779 return (void *) map_obj
;
782 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
784 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(bool_obj
);
785 BT_ASSERT_PRE_DEV_VALUE_IS_BOOL(bool_obj
);
786 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
789 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
791 BT_ASSERT_PRE_VALUE_NON_NULL(bool_obj
);
792 BT_ASSERT_PRE_VALUE_IS_BOOL(bool_obj
);
793 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
794 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
798 uint64_t bt_value_integer_unsigned_get(const struct bt_value
*integer_obj
)
800 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(integer_obj
);
801 BT_ASSERT_PRE_DEV_VALUE_IS_UNSIGNED_INT(integer_obj
);
802 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
805 int64_t bt_value_integer_signed_get(const struct bt_value
*integer_obj
)
807 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(integer_obj
);
808 BT_ASSERT_PRE_DEV_VALUE_IS_SIGNED_INT(integer_obj
);
809 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
813 void set_integer_value(struct bt_value
*integer_obj
,
814 enum bt_value_type expected_type
, uint64_t uval
,
815 const char *api_func
)
817 BT_ASSERT_PRE_DEV_VALUE_HOT_FROM_FUNC(api_func
, integer_obj
);
818 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
821 void bt_value_integer_unsigned_set(struct bt_value
*integer_obj
,
824 BT_ASSERT_PRE_VALUE_NON_NULL(integer_obj
);
825 BT_ASSERT_PRE_VALUE_IS_UNSIGNED_INT(integer_obj
);
826 set_integer_value(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
,
828 BT_LOGT("Set unsigned integer value's raw value: "
829 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
832 void bt_value_integer_signed_set(struct bt_value
*integer_obj
,
835 BT_ASSERT_PRE_VALUE_NON_NULL(integer_obj
);
836 BT_ASSERT_PRE_VALUE_IS_SIGNED_INT(integer_obj
);
837 set_integer_value(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
838 (uint64_t) val
, __func__
);
839 BT_LOGT("Set signed integer value's raw value: "
840 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
843 double bt_value_real_get(const struct bt_value
*real_obj
)
845 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(real_obj
);
846 BT_ASSERT_PRE_DEV_VALUE_IS_REAL(real_obj
);
847 return BT_VALUE_TO_REAL(real_obj
)->value
;
850 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
852 BT_ASSERT_PRE_VALUE_NON_NULL(real_obj
);
853 BT_ASSERT_PRE_VALUE_IS_REAL(real_obj
);
854 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
);
855 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
856 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
860 const char *bt_value_string_get(const struct bt_value
*string_obj
)
862 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(string_obj
);
863 BT_ASSERT_PRE_DEV_VALUE_IS_STRING(string_obj
);
864 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
867 enum bt_value_string_set_status
bt_value_string_set(
868 struct bt_value
*string_obj
, const char *val
)
870 BT_ASSERT_PRE_NO_ERROR();
871 BT_ASSERT_PRE_VALUE_NON_NULL(string_obj
);
872 BT_ASSERT_PRE_VALUE_IS_STRING(string_obj
);
873 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
);
874 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
875 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
877 return BT_FUNC_STATUS_OK
;
880 uint64_t bt_value_array_get_length(const struct bt_value
*array_obj
)
882 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(array_obj
);
883 BT_ASSERT_PRE_DEV_VALUE_IS_ARRAY(array_obj
);
884 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
887 struct bt_value
*bt_value_array_borrow_element_by_index(
888 struct bt_value
*array_obj
, uint64_t index
)
890 struct bt_value_array
*typed_array_obj
=
891 BT_VALUE_TO_ARRAY(array_obj
);
893 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(array_obj
);
894 BT_ASSERT_PRE_DEV_VALUE_IS_ARRAY(array_obj
);
895 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
896 return g_ptr_array_index(typed_array_obj
->garray
, index
);
899 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
900 const struct bt_value
*array_obj
,
903 return bt_value_array_borrow_element_by_index(
904 (void *) array_obj
, index
);
908 enum bt_value_array_append_element_status
append_array_element(
909 struct bt_value
*array_obj
,
910 struct bt_value
*element_obj
, const char *api_func
)
912 struct bt_value_array
*typed_array_obj
=
913 BT_VALUE_TO_ARRAY(array_obj
);
915 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
916 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "array-value-object",
917 array_obj
, "Array value object");
918 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "element-value-object",
919 element_obj
, "Element value object");
920 BT_ASSERT_PRE_VALUE_HAS_TYPE_FROM_FUNC(api_func
, "value-object",
921 array_obj
, "array", BT_VALUE_TYPE_ARRAY
);
922 BT_ASSERT_PRE_DEV_VALUE_HOT_FROM_FUNC(api_func
, array_obj
);
923 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
924 bt_object_get_ref(element_obj
);
925 BT_LOGT("Appended element to array value: array-value-addr=%p, "
926 "element-value-addr=%p, new-size=%u",
927 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
928 return BT_FUNC_STATUS_OK
;
931 enum bt_value_array_append_element_status
bt_value_array_append_element(
932 struct bt_value
*array_obj
,
933 struct bt_value
*element_obj
)
935 return append_array_element(array_obj
, element_obj
, __func__
);
938 enum bt_value_array_append_element_status
939 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
941 enum bt_value_array_append_element_status ret
;
942 struct bt_value
*bool_obj
= NULL
;
944 BT_ASSERT_PRE_NO_ERROR();
946 bool_obj
= bt_value_bool_create_init(val
);
947 ret
= append_array_element(array_obj
,
948 (void *) bool_obj
, __func__
);
949 bt_object_put_ref(bool_obj
);
953 enum bt_value_array_append_element_status
954 bt_value_array_append_unsigned_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_unsigned_create_init(val
);
963 ret
= append_array_element(array_obj
,
964 (void *) integer_obj
, __func__
);
965 bt_object_put_ref(integer_obj
);
969 enum bt_value_array_append_element_status
970 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
973 enum bt_value_array_append_element_status ret
;
974 struct bt_value
*integer_obj
= NULL
;
976 BT_ASSERT_PRE_NO_ERROR();
978 integer_obj
= bt_value_integer_signed_create_init(val
);
979 ret
= append_array_element(array_obj
,
980 (void *) integer_obj
, __func__
);
981 bt_object_put_ref(integer_obj
);
985 enum bt_value_array_append_element_status
986 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
988 enum bt_value_array_append_element_status ret
;
989 struct bt_value
*real_obj
= NULL
;
991 BT_ASSERT_PRE_NO_ERROR();
993 real_obj
= bt_value_real_create_init(val
);
994 ret
= append_array_element(array_obj
,
995 (void *) real_obj
, __func__
);
996 bt_object_put_ref(real_obj
);
1000 enum bt_value_array_append_element_status
1001 bt_value_array_append_string_element(struct bt_value
*array_obj
,
1004 enum bt_value_array_append_element_status ret
;
1005 struct bt_value
*string_obj
= NULL
;
1007 BT_ASSERT_PRE_NO_ERROR();
1009 string_obj
= bt_value_string_create_init(val
);
1010 ret
= append_array_element(array_obj
,
1011 (void *) string_obj
, __func__
);
1012 bt_object_put_ref(string_obj
);
1016 enum bt_value_array_append_element_status
1017 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
,
1018 struct bt_value
**element_obj
)
1020 enum bt_value_array_append_element_status ret
;
1021 struct bt_value
*empty_array_obj
= NULL
;
1023 BT_ASSERT_PRE_NO_ERROR();
1025 empty_array_obj
= bt_value_array_create();
1026 ret
= append_array_element(array_obj
,
1027 (void *) empty_array_obj
, __func__
);
1030 *element_obj
= empty_array_obj
;
1033 bt_object_put_ref(empty_array_obj
);
1037 enum bt_value_array_append_element_status
1038 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
,
1039 struct bt_value
**element_obj
)
1041 enum bt_value_array_append_element_status ret
;
1042 struct bt_value
*map_obj
= NULL
;
1044 BT_ASSERT_PRE_NO_ERROR();
1046 map_obj
= bt_value_map_create();
1047 ret
= append_array_element(array_obj
,
1048 (void *) map_obj
, __func__
);
1051 *element_obj
= map_obj
;
1054 bt_object_put_ref(map_obj
);
1058 enum bt_value_array_set_element_by_index_status
1059 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1060 struct bt_value
*element_obj
)
1062 struct bt_value_array
*typed_array_obj
=
1063 BT_VALUE_TO_ARRAY(array_obj
);
1065 BT_ASSERT_PRE_NO_ERROR();
1066 BT_ASSERT_PRE_NON_NULL("array-value-object", array_obj
,
1067 "Array value object");
1068 BT_ASSERT_PRE_NON_NULL("element-value-object", element_obj
,
1069 "Element value object");
1070 BT_ASSERT_PRE_VALUE_IS_ARRAY(array_obj
);
1071 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
);
1072 BT_ASSERT_PRE_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
1073 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1074 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1075 bt_object_get_ref(element_obj
);
1076 BT_LOGT("Set array value's element: array-value-addr=%p, "
1077 "index=%" PRIu64
", element-value-addr=%p",
1078 array_obj
, index
, element_obj
);
1079 return BT_FUNC_STATUS_OK
;
1082 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1084 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(map_obj
);
1085 BT_ASSERT_PRE_DEV_VALUE_IS_MAP(map_obj
);
1086 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1089 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1092 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(map_obj
);
1093 BT_ASSERT_PRE_DEV_KEY_NON_NULL(key
);
1094 BT_ASSERT_PRE_DEV_VALUE_IS_MAP(map_obj
);
1095 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1096 GUINT_TO_POINTER(g_quark_from_string(key
)));
1099 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1100 const struct bt_value
*map_obj
, const char *key
)
1102 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1105 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1107 BT_ASSERT_PRE_DEV_VALUE_NON_NULL(map_obj
);
1108 BT_ASSERT_PRE_DEV_KEY_NON_NULL(key
);
1109 BT_ASSERT_PRE_DEV_VALUE_IS_MAP(map_obj
);
1110 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1111 GUINT_TO_POINTER(g_quark_from_string(key
)));
1115 enum bt_value_map_insert_entry_status
insert_map_value_entry(
1116 struct bt_value
*map_obj
, const char *key
,
1117 struct bt_value
*element_obj
, const char *api_func
)
1119 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
1120 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "map-value-object",
1121 map_obj
, "Map value object");
1122 BT_ASSERT_PRE_KEY_NON_NULL_FROM_FUNC(api_func
, key
);
1123 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
,
1124 "element-value-object", element_obj
, "Element value object");
1125 BT_ASSERT_PRE_VALUE_HAS_TYPE_FROM_FUNC(api_func
, "value-object",
1126 map_obj
, "map", BT_VALUE_TYPE_MAP
);
1127 BT_ASSERT_PRE_DEV_VALUE_HOT_FROM_FUNC(api_func
, map_obj
);
1128 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1129 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1130 bt_object_get_ref(element_obj
);
1131 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1132 "key=\"%s\", element-value-addr=%p",
1133 map_obj
, key
, element_obj
);
1134 return BT_FUNC_STATUS_OK
;
1137 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1138 struct bt_value
*map_obj
, const char *key
,
1139 struct bt_value
*element_obj
)
1141 return insert_map_value_entry(map_obj
, key
, element_obj
, __func__
);
1144 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1145 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1147 enum bt_value_map_insert_entry_status ret
;
1148 struct bt_value
*bool_obj
= NULL
;
1150 BT_ASSERT_PRE_NO_ERROR();
1152 bool_obj
= bt_value_bool_create_init(val
);
1153 ret
= insert_map_value_entry(map_obj
, key
,
1154 (void *) bool_obj
, __func__
);
1155 bt_object_put_ref(bool_obj
);
1159 enum bt_value_map_insert_entry_status
1160 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1161 const char *key
, uint64_t val
)
1163 enum bt_value_map_insert_entry_status ret
;
1164 struct bt_value
*integer_obj
= NULL
;
1166 BT_ASSERT_PRE_NO_ERROR();
1168 integer_obj
= bt_value_integer_unsigned_create_init(val
);
1169 ret
= insert_map_value_entry(map_obj
, key
,
1170 (void *) integer_obj
, __func__
);
1171 bt_object_put_ref(integer_obj
);
1175 enum bt_value_map_insert_entry_status
1176 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1177 const char *key
, int64_t val
)
1179 enum bt_value_map_insert_entry_status ret
;
1180 struct bt_value
*integer_obj
= NULL
;
1182 BT_ASSERT_PRE_NO_ERROR();
1184 integer_obj
= bt_value_integer_signed_create_init(val
);
1185 ret
= insert_map_value_entry(map_obj
, key
,
1186 (void *) integer_obj
, __func__
);
1187 bt_object_put_ref(integer_obj
);
1191 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1192 struct bt_value
*map_obj
, const char *key
, double val
)
1194 enum bt_value_map_insert_entry_status ret
;
1195 struct bt_value
*real_obj
= NULL
;
1197 BT_ASSERT_PRE_NO_ERROR();
1199 real_obj
= bt_value_real_create_init(val
);
1200 ret
= insert_map_value_entry(map_obj
, key
,
1201 (void *) real_obj
, __func__
);
1202 bt_object_put_ref(real_obj
);
1206 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1207 struct bt_value
*map_obj
, const char *key
,
1210 enum bt_value_map_insert_entry_status ret
;
1211 struct bt_value
*string_obj
= NULL
;
1213 BT_ASSERT_PRE_NO_ERROR();
1215 string_obj
= bt_value_string_create_init(val
);
1216 ret
= insert_map_value_entry(map_obj
, key
,
1217 (void *) string_obj
, __func__
);
1218 bt_object_put_ref(string_obj
);
1222 enum bt_value_map_insert_entry_status
1223 bt_value_map_insert_empty_array_entry(
1224 struct bt_value
*map_obj
, const char *key
,
1225 bt_value
**entry_obj
)
1227 enum bt_value_map_insert_entry_status ret
;
1228 struct bt_value
*array_obj
= NULL
;
1230 BT_ASSERT_PRE_NO_ERROR();
1232 array_obj
= bt_value_array_create();
1233 ret
= insert_map_value_entry(map_obj
, key
,
1234 (void *) array_obj
, __func__
);
1237 *entry_obj
= array_obj
;
1240 bt_object_put_ref(array_obj
);
1244 enum bt_value_map_insert_entry_status
1245 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
,
1246 bt_value
**entry_obj
)
1248 enum bt_value_map_insert_entry_status ret
;
1249 struct bt_value
*empty_map_obj
= NULL
;
1251 BT_ASSERT_PRE_NO_ERROR();
1253 empty_map_obj
= bt_value_map_create();
1254 ret
= insert_map_value_entry(map_obj
, key
,
1255 (void *) empty_map_obj
, __func__
);
1258 *entry_obj
= empty_map_obj
;
1261 bt_object_put_ref(empty_map_obj
);
1266 enum bt_value_map_foreach_entry_status
foreach_map_entry(
1267 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1268 void *data
, const char *api_func
,
1269 const char *user_func_name
)
1271 int status
= BT_FUNC_STATUS_OK
;
1272 gpointer key
, element_obj
;
1273 GHashTableIter iter
;
1274 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1276 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
1277 BT_ASSERT_PRE_DEV_VALUE_NON_NULL_FROM_FUNC(api_func
, map_obj
);
1278 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "user-function",
1279 func
, "User function");
1280 BT_ASSERT_PRE_VALUE_HAS_TYPE_FROM_FUNC(api_func
, "value-object",
1281 map_obj
, "map", BT_VALUE_TYPE_MAP
);
1282 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1284 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1285 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1287 status
= func(key_str
, element_obj
, data
);
1288 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(user_func_name
,
1290 if (status
!= BT_FUNC_STATUS_OK
) {
1292 BT_LIB_LOGE_APPEND_CAUSE(
1293 "User function failed while iterating "
1294 "map value entries: "
1295 "status=%s, key=\"%s\", "
1296 "value-addr=%p, data=%p",
1297 bt_common_func_status_string(status
),
1298 key_str
, element_obj
, data
);
1300 if (status
== BT_FUNC_STATUS_ERROR
) {
1302 * User function error becomes a
1303 * user error from this
1304 * function's caller's
1307 status
= BT_FUNC_STATUS_USER_ERROR
;
1310 BT_ASSERT(status
== BT_FUNC_STATUS_INTERRUPTED
);
1311 BT_LOGT("User interrupted the loop: status=%s, "
1312 "key=\"%s\", value-addr=%p, data=%p",
1313 bt_common_func_status_string(status
),
1314 key_str
, element_obj
, data
);
1324 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1325 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1328 return foreach_map_entry(map_obj
, func
, data
, __func__
,
1329 "bt_value_map_foreach_entry_func");
1332 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1333 const struct bt_value
*map_obj
,
1334 bt_value_map_foreach_entry_const_func func
, void *data
)
1336 return (int) foreach_map_entry((void *) map_obj
,
1337 (bt_value_map_foreach_entry_func
) func
, data
, __func__
,
1338 "bt_value_map_foreach_entry_const_func");
1341 struct extend_map_element_data
{
1342 struct bt_value
*base_obj
;
1346 bt_value_map_foreach_entry_const_func_status
extend_map_element(
1347 const char *key
, const struct bt_value
*extension_obj_elem
,
1351 struct extend_map_element_data
*extend_data
= data
;
1352 struct bt_value
*extension_obj_elem_copy
= NULL
;
1354 /* Copy object which is to replace the current one */
1355 status
= bt_value_copy(extension_obj_elem
, &extension_obj_elem_copy
);
1357 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1358 extension_obj_elem
);
1362 BT_ASSERT(extension_obj_elem_copy
);
1364 /* Replace in base map value. */
1365 status
= bt_value_map_insert_entry(extend_data
->base_obj
, key
,
1366 extension_obj_elem_copy
);
1368 BT_LIB_LOGE_APPEND_CAUSE(
1369 "Cannot replace value in base map value: key=\"%s\", "
1370 "%![base-map-value-]+v, %![element-value-]+v",
1371 key
, extend_data
->base_obj
, extension_obj_elem_copy
);
1378 BT_ASSERT(status
< 0);
1381 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1382 BT_ASSERT(status
== BT_FUNC_STATUS_OK
||
1383 status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1387 enum bt_value_map_extend_status
bt_value_map_extend(
1388 struct bt_value
*base_map_obj
,
1389 const struct bt_value
*extension_obj
)
1391 int status
= BT_FUNC_STATUS_OK
;
1392 struct extend_map_element_data extend_data
= {
1396 BT_ASSERT_PRE_NO_ERROR();
1397 BT_ASSERT_PRE_NON_NULL("base-value-object", base_map_obj
,
1398 "Base value object");
1399 BT_ASSERT_PRE_DEV_VALUE_HOT(base_map_obj
);
1400 BT_ASSERT_PRE_NON_NULL("extension-value-object", extension_obj
,
1401 "Extension value object");
1402 BT_ASSERT_PRE_VALUE_HAS_TYPE("base-value-object", base_map_obj
,
1403 "map", BT_VALUE_TYPE_MAP
);
1404 BT_ASSERT_PRE_VALUE_HAS_TYPE("extension-value-object", extension_obj
,
1405 "map", BT_VALUE_TYPE_MAP
);
1406 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1407 base_map_obj
, extension_obj
);
1410 * For each key in the extension map object, replace this key
1411 * in the base map object.
1413 extend_data
.base_obj
= base_map_obj
;
1414 status
= bt_value_map_foreach_entry_const(extension_obj
,
1415 extend_map_element
, &extend_data
);
1416 if (status
!= BT_FUNC_STATUS_OK
) {
1417 BT_ASSERT(status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1418 BT_LIB_LOGE_APPEND_CAUSE(
1419 "Cannot iterate on the extension object's elements: "
1420 "%![extension-value-]+v", extension_obj
);
1426 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1427 struct bt_value
**copy_obj
)
1429 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1431 BT_ASSERT_PRE_NO_ERROR();
1432 BT_ASSERT_PRE_VALUE_NON_NULL(object
);
1433 BT_ASSERT_PRE_NON_NULL("value-object-copy-output", copy_obj
,
1434 "Value object copy (output)");
1435 BT_LOGD("Copying value object: addr=%p", object
);
1436 *copy_obj
= copy_funcs
[object
->type
](object
);
1438 BT_LOGD("Copied value object: copy-value-addr=%p",
1441 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1443 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1449 bt_bool
bt_value_is_equal(const struct bt_value
*object_a
,
1450 const struct bt_value
*object_b
)
1452 bt_bool ret
= BT_FALSE
;
1454 BT_ASSERT_PRE_DEV_NON_NULL("value-object-a", object_a
,
1456 BT_ASSERT_PRE_DEV_NON_NULL("value-object-b", object_b
,
1459 if (object_a
->type
!= object_b
->type
) {
1460 BT_LOGT("Values are different: type mismatch: "
1461 "value-a-addr=%p, value-b-addr=%p, "
1462 "value-a-type=%s, value-b-type=%s",
1464 bt_common_value_type_string(object_a
->type
),
1465 bt_common_value_type_string(object_b
->type
));
1469 ret
= is_equal_funcs
[object_a
->type
](object_a
, object_b
);
1475 void bt_value_get_ref(const struct bt_value
*value
)
1477 bt_object_get_ref(value
);
1480 void bt_value_put_ref(const struct bt_value
*value
)
1482 bt_object_put_ref(value
);