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-pre.h"
20 #include "lib/assert-post.h"
21 #include "lib/value.h"
22 #include "common/assert.h"
23 #include "func-status.h"
25 #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
26 #define BT_VALUE_TO_INTEGER(_base) ((struct bt_value_integer *) (_base))
27 #define BT_VALUE_TO_REAL(_base) ((struct bt_value_real *) (_base))
28 #define BT_VALUE_TO_STRING(_base) ((struct bt_value_string *) (_base))
29 #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base))
30 #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
32 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_COND(_value, _type) \
33 (((struct bt_value *) (_value))->type == (_type))
35 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT \
36 "Value has the wrong type ID: expected-type=%s, %![value-]+v"
38 #define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
40 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
41 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
42 bt_common_value_type_string(_type), (_value))
44 #define BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(_value, _type) \
46 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
47 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
48 bt_common_value_type_string(_type), (_value))
50 #define BT_ASSERT_PRE_DEV_VALUE_HOT(_value, _name) \
51 BT_ASSERT_PRE_DEV_HOT(((struct bt_value *) (_value)), (_name), \
55 void bt_value_null_instance_release_func(struct bt_object
*obj
)
57 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
61 struct bt_value bt_value_null_instance
= {
65 .release_func
= bt_value_null_instance_release_func
,
66 .spec_release_func
= NULL
,
67 .parent_is_owner_listener_func
= NULL
,
70 .type
= BT_VALUE_TYPE_NULL
,
74 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
77 void bt_value_destroy(struct bt_object
*obj
);
80 void bt_value_string_destroy(struct bt_value
*object
)
82 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
83 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
87 void bt_value_array_destroy(struct bt_value
*object
)
90 * Pointer array's registered value destructor will take care
91 * of putting each contained object.
93 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
94 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
98 void bt_value_map_destroy(struct bt_value
*object
)
101 * Hash table's registered value destructor will take care of
102 * putting each contained object. Keys are GQuarks and cannot
103 * be destroyed anyway.
105 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
106 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
110 void (* const destroy_funcs
[])(struct bt_value
*) = {
111 [BT_VALUE_TYPE_NULL
] = NULL
,
112 [BT_VALUE_TYPE_BOOL
] = NULL
,
113 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
114 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
115 [BT_VALUE_TYPE_REAL
] = NULL
,
116 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
117 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
118 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
122 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
124 BT_ASSERT(null_obj
== bt_value_null
);
126 bt_object_get_ref_no_null_check(bt_value_null
);
127 return (void *) bt_value_null
;
131 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
133 return bt_value_bool_create_init(
134 BT_VALUE_TO_BOOL(bool_obj
)->value
);
138 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
142 struct bt_value
*bt_value_integer_copy(
143 const struct bt_value
*integer_obj
)
145 return bt_value_integer_create_init(integer_obj
->type
,
146 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
150 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
152 return bt_value_real_create_init(
153 BT_VALUE_TO_REAL(real_obj
)->value
);
157 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
159 return bt_value_string_create_init(
160 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
164 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
168 struct bt_value
*copy_obj
;
169 struct bt_value_array
*typed_array_obj
;
171 BT_LOGD("Copying array value: addr=%p", array_obj
);
172 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
173 copy_obj
= bt_value_array_create();
175 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
179 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
180 struct bt_value
*element_obj_copy
= NULL
;
181 const struct bt_value
*element_obj
=
182 bt_value_array_borrow_element_by_index_const(
185 BT_LOGD("Copying array value's element: element-addr=%p, "
186 "index=%d", element_obj
, i
);
187 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
189 BT_LIB_LOGE_APPEND_CAUSE(
190 "Cannot copy array value's element: "
191 "array-addr=%p, index=%d",
193 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
197 BT_ASSERT(element_obj_copy
);
198 ret
= bt_value_array_append_element(copy_obj
,
199 (void *) element_obj_copy
);
200 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
202 BT_LIB_LOGE_APPEND_CAUSE(
203 "Cannot append to array value: addr=%p",
205 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
210 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
211 array_obj
, copy_obj
);
218 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
222 gpointer key
, element_obj
;
223 struct bt_value
*copy_obj
;
224 struct bt_value
*element_obj_copy
= NULL
;
225 struct bt_value_map
*typed_map_obj
;
227 BT_LOGD("Copying map value: addr=%p", map_obj
);
228 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
229 copy_obj
= bt_value_map_create();
234 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
236 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
237 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
240 BT_LOGD("Copying map value's element: element-addr=%p, "
241 "key=\"%s\"", element_obj
, key_str
);
242 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
244 BT_LIB_LOGE_APPEND_CAUSE(
245 "Cannot copy map value's element: "
246 "map-addr=%p, key=\"%s\"",
248 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
252 BT_ASSERT(element_obj_copy
);
253 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
254 (void *) element_obj_copy
);
255 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
257 BT_LIB_LOGE_APPEND_CAUSE(
258 "Cannot insert into map value: addr=%p, key=\"%s\"",
260 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
265 BT_LOGD("Copied map value: addr=%p", map_obj
);
272 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
273 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
274 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
275 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
276 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
277 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
278 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
279 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
280 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
284 bt_bool
bt_value_null_is_equal(const struct bt_value
*object_a
,
285 const struct bt_value
*object_b
)
288 * Always BT_TRUE since bt_value_is_equal() already checks if both
289 * object_a and object_b have the same type, and in the case of
290 * null value objects, they're always the same if it is so.
296 bt_bool
bt_value_bool_is_equal(const struct bt_value
*object_a
,
297 const struct bt_value
*object_b
)
299 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
300 BT_VALUE_TO_BOOL(object_b
)->value
) {
301 BT_LOGT("Boolean value objects are different: "
302 "bool-a-val=%d, bool-b-val=%d",
303 BT_VALUE_TO_BOOL(object_a
)->value
,
304 BT_VALUE_TO_BOOL(object_b
)->value
);
312 bt_bool
bt_value_integer_is_equal(const struct bt_value
*object_a
,
313 const struct bt_value
*object_b
)
315 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
316 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
317 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
318 BT_LOGT("Unsigned integer value objects are different: "
319 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
320 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
321 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
323 BT_LOGT("Signed integer value objects are different: "
324 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
325 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
326 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
336 bt_bool
bt_value_real_is_equal(const struct bt_value
*object_a
,
337 const struct bt_value
*object_b
)
339 if (BT_VALUE_TO_REAL(object_a
)->value
!=
340 BT_VALUE_TO_REAL(object_b
)->value
) {
341 BT_LOGT("Real number value objects are different: "
342 "real-a-val=%f, real-b-val=%f",
343 BT_VALUE_TO_REAL(object_a
)->value
,
344 BT_VALUE_TO_REAL(object_b
)->value
);
352 bt_bool
bt_value_string_is_equal(const struct bt_value
*object_a
,
353 const struct bt_value
*object_b
)
355 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
356 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
357 BT_LOGT("String value objects are different: "
358 "string-a-val=\"%s\", string-b-val=\"%s\"",
359 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
360 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
368 bt_bool
bt_value_array_is_equal(const struct bt_value
*object_a
,
369 const struct bt_value
*object_b
)
372 bt_bool ret
= BT_TRUE
;
373 const struct bt_value_array
*array_obj_a
=
374 BT_VALUE_TO_ARRAY(object_a
);
376 if (bt_value_array_get_length(object_a
) !=
377 bt_value_array_get_length(object_b
)) {
378 BT_LOGT("Array values are different: size mismatch "
379 "value-a-addr=%p, value-b-addr=%p, "
380 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
382 bt_value_array_get_length(object_a
),
383 bt_value_array_get_length(object_b
));
388 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
389 const struct bt_value
*element_obj_a
;
390 const struct bt_value
*element_obj_b
;
392 element_obj_a
= bt_value_array_borrow_element_by_index_const(
394 element_obj_b
= bt_value_array_borrow_element_by_index_const(
397 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
398 BT_LOGT("Array values's elements are different: "
399 "value-a-addr=%p, value-b-addr=%p, index=%d",
400 element_obj_a
, element_obj_b
, i
);
411 bt_bool
bt_value_map_is_equal(const struct bt_value
*object_a
,
412 const struct bt_value
*object_b
)
414 bt_bool ret
= BT_TRUE
;
416 gpointer key
, element_obj_a
;
417 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
419 if (bt_value_map_get_size(object_a
) !=
420 bt_value_map_get_size(object_b
)) {
421 BT_LOGT("Map values are different: size mismatch "
422 "value-a-addr=%p, value-b-addr=%p, "
423 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
425 bt_value_map_get_size(object_a
),
426 bt_value_map_get_size(object_b
));
431 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
433 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
434 const struct bt_value
*element_obj_b
;
435 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
437 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
440 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
441 BT_LOGT("Map values's elements are different: "
442 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
443 element_obj_a
, element_obj_b
, key_str
);
454 bt_bool (* const is_equal_funcs
[])(const struct bt_value
*,
455 const struct bt_value
*) = {
456 [BT_VALUE_TYPE_NULL
] = bt_value_null_is_equal
,
457 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_is_equal
,
458 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_is_equal
,
459 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_is_equal
,
460 [BT_VALUE_TYPE_REAL
] = bt_value_real_is_equal
,
461 [BT_VALUE_TYPE_STRING
] = bt_value_string_is_equal
,
462 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_is_equal
,
463 [BT_VALUE_TYPE_MAP
] = bt_value_map_is_equal
,
467 void bt_value_null_freeze(struct bt_value
*object
)
472 void bt_value_generic_freeze(struct bt_value
*object
)
474 object
->frozen
= BT_TRUE
;
478 void bt_value_array_freeze(struct bt_value
*object
)
481 struct bt_value_array
*typed_array_obj
=
482 BT_VALUE_TO_ARRAY(object
);
484 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
485 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
488 bt_value_generic_freeze(object
);
492 void bt_value_map_freeze(struct bt_value
*object
)
495 gpointer key
, element_obj
;
496 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
498 g_hash_table_iter_init(&iter
, map_obj
->ght
);
500 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
501 bt_value_freeze(element_obj
);
504 bt_value_generic_freeze(object
);
508 void (* const freeze_funcs
[])(struct bt_value
*) = {
509 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
510 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
511 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
512 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
513 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
514 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
515 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
516 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
520 void bt_value_destroy(struct bt_object
*obj
)
522 struct bt_value
*value
;
524 value
= container_of(obj
, struct bt_value
, base
);
525 BT_LOGD("Destroying value: addr=%p", value
);
527 if (bt_value_is_null(value
)) {
528 BT_LOGD_STR("Not destroying the null value singleton.");
532 if (destroy_funcs
[value
->type
]) {
533 destroy_funcs
[value
->type
](value
);
540 void _bt_value_freeze(const struct bt_value
*c_object
)
542 const struct bt_value
*object
= (void *) c_object
;
546 if (object
->frozen
) {
550 BT_LOGD("Freezing value: addr=%p", object
);
551 freeze_funcs
[object
->type
]((void *) object
);
557 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
559 BT_ASSERT_PRE_DEV_NON_NULL(object
, "Value object");
564 struct bt_value
bt_value_create_base(enum bt_value_type type
)
566 struct bt_value value
;
569 value
.frozen
= BT_FALSE
;
570 bt_object_init_shared(&value
.base
, bt_value_destroy
);
574 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
576 struct bt_value_bool
*bool_obj
;
578 BT_ASSERT_PRE_NO_ERROR();
580 BT_LOGD("Creating boolean value object: val=%d", val
);
581 bool_obj
= g_new0(struct bt_value_bool
, 1);
583 BT_LIB_LOGE_APPEND_CAUSE(
584 "Failed to allocate one boolean value object.");
588 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
589 bool_obj
->value
= val
;
590 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
593 return (void *) bool_obj
;
596 struct bt_value
*bt_value_bool_create(void)
598 BT_ASSERT_PRE_NO_ERROR();
600 return bt_value_bool_create_init(BT_FALSE
);
604 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
607 struct bt_value_integer
*integer_obj
;
609 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
610 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
612 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
613 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
616 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
620 integer_obj
= g_new0(struct bt_value_integer
, 1);
622 BT_LIB_LOGE_APPEND_CAUSE(
623 "Failed to allocate one integer value object.");
627 integer_obj
->base
= bt_value_create_base(type
);
628 integer_obj
->value
.u
= uval
;
629 BT_LOGD("Created %ssigned integer value object: addr=%p",
630 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
634 return (void *) integer_obj
;
637 struct bt_value
*bt_value_integer_unsigned_create_init(uint64_t val
)
639 BT_ASSERT_PRE_NO_ERROR();
641 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
645 struct bt_value
*bt_value_integer_unsigned_create(void)
647 BT_ASSERT_PRE_NO_ERROR();
649 return bt_value_integer_unsigned_create_init(0);
652 struct bt_value
*bt_value_integer_signed_create_init(int64_t val
)
654 BT_ASSERT_PRE_NO_ERROR();
656 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
660 struct bt_value
*bt_value_integer_signed_create(void)
662 BT_ASSERT_PRE_NO_ERROR();
664 return bt_value_integer_signed_create_init(0);
667 struct bt_value
*bt_value_real_create_init(double val
)
669 struct bt_value_real
*real_obj
;
671 BT_ASSERT_PRE_NO_ERROR();
673 BT_LOGD("Creating real number value object: val=%f", val
);
674 real_obj
= g_new0(struct bt_value_real
, 1);
676 BT_LIB_LOGE_APPEND_CAUSE(
677 "Failed to allocate one real number value object.");
681 real_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_REAL
);
682 real_obj
->value
= val
;
683 BT_LOGD("Created real number value object: addr=%p",
687 return (void *) real_obj
;
690 struct bt_value
*bt_value_real_create(void)
692 BT_ASSERT_PRE_NO_ERROR();
694 return bt_value_real_create_init(0.);
697 struct bt_value
*bt_value_string_create_init(const char *val
)
699 struct bt_value_string
*string_obj
= NULL
;
701 BT_ASSERT_PRE_NO_ERROR();
702 BT_ASSERT_PRE_NON_NULL(val
, "Value");
704 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
705 string_obj
= g_new0(struct bt_value_string
, 1);
707 BT_LIB_LOGE_APPEND_CAUSE(
708 "Failed to allocate one string object.");
712 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
713 string_obj
->gstr
= g_string_new(val
);
714 if (!string_obj
->gstr
) {
715 BT_LIB_LOGE_APPEND_CAUSE(
716 "Failed to allocate a GString.");
722 BT_LOGD("Created string value object: addr=%p",
726 return (void *) string_obj
;
729 struct bt_value
*bt_value_string_create(void)
731 BT_ASSERT_PRE_NO_ERROR();
733 return bt_value_string_create_init("");
736 struct bt_value
*bt_value_array_create(void)
738 struct bt_value_array
*array_obj
;
740 BT_ASSERT_PRE_NO_ERROR();
742 BT_LOGD_STR("Creating empty array value object.");
743 array_obj
= g_new0(struct bt_value_array
, 1);
745 BT_LIB_LOGE_APPEND_CAUSE(
746 "Failed to allocate one array object.");
750 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
751 array_obj
->garray
= bt_g_ptr_array_new_full(0,
752 (GDestroyNotify
) bt_object_put_ref
);
753 if (!array_obj
->garray
) {
754 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
760 BT_LOGD("Created array value object: addr=%p",
764 return (void *) array_obj
;
767 struct bt_value
*bt_value_map_create(void)
769 struct bt_value_map
*map_obj
;
771 BT_ASSERT_PRE_NO_ERROR();
773 BT_LOGD_STR("Creating empty map value object.");
774 map_obj
= g_new0(struct bt_value_map
, 1);
776 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
780 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
781 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
782 NULL
, (GDestroyNotify
) bt_object_put_ref
);
784 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
790 BT_LOGD("Created map value object: addr=%p",
794 return (void *) map_obj
;
797 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
799 BT_ASSERT_PRE_DEV_NON_NULL(bool_obj
, "Value object");
800 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
801 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
804 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
806 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
807 BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
808 BT_ASSERT_PRE_DEV_VALUE_HOT(bool_obj
, "Value object");
809 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
810 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
814 uint64_t bt_value_integer_unsigned_get(const struct bt_value
*integer_obj
)
816 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
817 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
818 BT_VALUE_TYPE_UNSIGNED_INTEGER
);
819 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
822 int64_t bt_value_integer_signed_get(const struct bt_value
*integer_obj
)
824 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
825 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
826 BT_VALUE_TYPE_SIGNED_INTEGER
);
827 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
831 void bt_value_integer_set(struct bt_value
*integer_obj
,
832 enum bt_value_type expected_type
, uint64_t uval
)
834 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
835 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, expected_type
);
836 BT_ASSERT_PRE_DEV_VALUE_HOT(integer_obj
, "Value object");
837 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
840 void bt_value_integer_unsigned_set(struct bt_value
*integer_obj
,
843 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
);
844 BT_LOGT("Set unsigned integer value's raw value: "
845 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
848 void bt_value_integer_signed_set(struct bt_value
*integer_obj
,
851 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
853 BT_LOGT("Set signed integer value's raw value: "
854 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
857 double bt_value_real_get(const struct bt_value
*real_obj
)
859 BT_ASSERT_PRE_DEV_NON_NULL(real_obj
, "Value object");
860 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
861 return BT_VALUE_TO_REAL(real_obj
)->value
;
864 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
866 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
867 BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
868 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
, "Value object");
869 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
870 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
874 const char *bt_value_string_get(const struct bt_value
*string_obj
)
876 BT_ASSERT_PRE_DEV_NON_NULL(string_obj
, "Value object");
877 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
878 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
881 enum bt_value_string_set_status
bt_value_string_set(
882 struct bt_value
*string_obj
, const char *val
)
884 BT_ASSERT_PRE_NO_ERROR();
885 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
886 BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
887 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
, "Value object");
888 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
889 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
891 return BT_FUNC_STATUS_OK
;
894 uint64_t bt_value_array_get_length(const struct bt_value
*array_obj
)
896 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
897 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
898 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
901 struct bt_value
*bt_value_array_borrow_element_by_index(
902 struct bt_value
*array_obj
, uint64_t index
)
904 struct bt_value_array
*typed_array_obj
=
905 BT_VALUE_TO_ARRAY(array_obj
);
907 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
908 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
909 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
910 return g_ptr_array_index(typed_array_obj
->garray
, index
);
913 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
914 const struct bt_value
*array_obj
,
917 return bt_value_array_borrow_element_by_index(
918 (void *) array_obj
, index
);
921 enum bt_value_array_append_element_status
bt_value_array_append_element(
922 struct bt_value
*array_obj
,
923 struct bt_value
*element_obj
)
925 struct bt_value_array
*typed_array_obj
=
926 BT_VALUE_TO_ARRAY(array_obj
);
928 BT_ASSERT_PRE_NO_ERROR();
929 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
930 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
931 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
932 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
933 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
934 bt_object_get_ref(element_obj
);
935 BT_LOGT("Appended element to array value: array-value-addr=%p, "
936 "element-value-addr=%p, new-size=%u",
937 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
938 return BT_FUNC_STATUS_OK
;
941 enum bt_value_array_append_element_status
942 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
944 enum bt_value_array_append_element_status ret
;
945 struct bt_value
*bool_obj
= NULL
;
947 BT_ASSERT_PRE_NO_ERROR();
949 bool_obj
= bt_value_bool_create_init(val
);
950 ret
= bt_value_array_append_element(array_obj
,
952 bt_object_put_ref(bool_obj
);
956 enum bt_value_array_append_element_status
957 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
960 enum bt_value_array_append_element_status ret
;
961 struct bt_value
*integer_obj
= NULL
;
963 BT_ASSERT_PRE_NO_ERROR();
965 integer_obj
= bt_value_integer_unsigned_create_init(val
);
966 ret
= bt_value_array_append_element(array_obj
,
967 (void *) integer_obj
);
968 bt_object_put_ref(integer_obj
);
972 enum bt_value_array_append_element_status
973 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
976 enum bt_value_array_append_element_status ret
;
977 struct bt_value
*integer_obj
= NULL
;
979 BT_ASSERT_PRE_NO_ERROR();
981 integer_obj
= bt_value_integer_signed_create_init(val
);
982 ret
= bt_value_array_append_element(array_obj
,
983 (void *) integer_obj
);
984 bt_object_put_ref(integer_obj
);
988 enum bt_value_array_append_element_status
989 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
991 enum bt_value_array_append_element_status ret
;
992 struct bt_value
*real_obj
= NULL
;
994 BT_ASSERT_PRE_NO_ERROR();
996 real_obj
= bt_value_real_create_init(val
);
997 ret
= bt_value_array_append_element(array_obj
,
999 bt_object_put_ref(real_obj
);
1003 enum bt_value_array_append_element_status
1004 bt_value_array_append_string_element(struct bt_value
*array_obj
,
1007 enum bt_value_array_append_element_status ret
;
1008 struct bt_value
*string_obj
= NULL
;
1010 BT_ASSERT_PRE_NO_ERROR();
1012 string_obj
= bt_value_string_create_init(val
);
1013 ret
= bt_value_array_append_element(array_obj
,
1014 (void *) string_obj
);
1015 bt_object_put_ref(string_obj
);
1019 enum bt_value_array_append_element_status
1020 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
,
1021 struct bt_value
**element_obj
)
1023 enum bt_value_array_append_element_status ret
;
1024 struct bt_value
*empty_array_obj
= NULL
;
1026 BT_ASSERT_PRE_NO_ERROR();
1028 empty_array_obj
= bt_value_array_create();
1029 ret
= bt_value_array_append_element(array_obj
,
1030 (void *) empty_array_obj
);
1033 *element_obj
= empty_array_obj
;
1036 bt_object_put_ref(empty_array_obj
);
1040 enum bt_value_array_append_element_status
1041 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
,
1042 struct bt_value
**element_obj
)
1044 enum bt_value_array_append_element_status ret
;
1045 struct bt_value
*map_obj
= NULL
;
1047 BT_ASSERT_PRE_NO_ERROR();
1049 map_obj
= bt_value_map_create();
1050 ret
= bt_value_array_append_element(array_obj
,
1054 *element_obj
= map_obj
;
1057 bt_object_put_ref(map_obj
);
1061 enum bt_value_array_set_element_by_index_status
1062 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1063 struct bt_value
*element_obj
)
1065 struct bt_value_array
*typed_array_obj
=
1066 BT_VALUE_TO_ARRAY(array_obj
);
1068 BT_ASSERT_PRE_NO_ERROR();
1069 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1070 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1071 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
1072 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
1073 BT_ASSERT_PRE_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
1074 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1075 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1076 bt_object_get_ref(element_obj
);
1077 BT_LOGT("Set array value's element: array-value-addr=%p, "
1078 "index=%" PRIu64
", element-value-addr=%p",
1079 array_obj
, index
, element_obj
);
1080 return BT_FUNC_STATUS_OK
;
1083 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1085 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1086 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1087 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1090 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1093 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1094 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1095 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1096 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1097 GUINT_TO_POINTER(g_quark_from_string(key
)));
1100 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1101 const struct bt_value
*map_obj
, const char *key
)
1103 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1106 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1108 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1109 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1110 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1111 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1112 GUINT_TO_POINTER(g_quark_from_string(key
)));
1115 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1116 struct bt_value
*map_obj
, const char *key
,
1117 struct bt_value
*element_obj
)
1119 BT_ASSERT_PRE_NO_ERROR();
1120 BT_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1121 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1122 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1123 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1124 BT_ASSERT_PRE_DEV_VALUE_HOT(map_obj
, "Map value object");
1125 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1126 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1127 bt_object_get_ref(element_obj
);
1128 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1129 "key=\"%s\", element-value-addr=%p",
1130 map_obj
, key
, element_obj
);
1131 return BT_FUNC_STATUS_OK
;
1134 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1135 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1137 enum bt_value_map_insert_entry_status ret
;
1138 struct bt_value
*bool_obj
= NULL
;
1140 BT_ASSERT_PRE_NO_ERROR();
1142 bool_obj
= bt_value_bool_create_init(val
);
1143 ret
= bt_value_map_insert_entry(map_obj
, key
,
1145 bt_object_put_ref(bool_obj
);
1149 enum bt_value_map_insert_entry_status
1150 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1151 const char *key
, uint64_t val
)
1153 enum bt_value_map_insert_entry_status ret
;
1154 struct bt_value
*integer_obj
= NULL
;
1156 BT_ASSERT_PRE_NO_ERROR();
1158 integer_obj
= bt_value_integer_unsigned_create_init(val
);
1159 ret
= bt_value_map_insert_entry(map_obj
, key
,
1160 (void *) integer_obj
);
1161 bt_object_put_ref(integer_obj
);
1165 enum bt_value_map_insert_entry_status
1166 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1167 const char *key
, int64_t val
)
1169 enum bt_value_map_insert_entry_status ret
;
1170 struct bt_value
*integer_obj
= NULL
;
1172 BT_ASSERT_PRE_NO_ERROR();
1174 integer_obj
= bt_value_integer_signed_create_init(val
);
1175 ret
= bt_value_map_insert_entry(map_obj
, key
,
1176 (void *) integer_obj
);
1177 bt_object_put_ref(integer_obj
);
1181 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1182 struct bt_value
*map_obj
, const char *key
, double val
)
1184 enum bt_value_map_insert_entry_status ret
;
1185 struct bt_value
*real_obj
= NULL
;
1187 BT_ASSERT_PRE_NO_ERROR();
1189 real_obj
= bt_value_real_create_init(val
);
1190 ret
= bt_value_map_insert_entry(map_obj
, key
,
1192 bt_object_put_ref(real_obj
);
1196 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1197 struct bt_value
*map_obj
, const char *key
,
1200 enum bt_value_map_insert_entry_status ret
;
1201 struct bt_value
*string_obj
= NULL
;
1203 BT_ASSERT_PRE_NO_ERROR();
1205 string_obj
= bt_value_string_create_init(val
);
1206 ret
= bt_value_map_insert_entry(map_obj
, key
,
1207 (void *) string_obj
);
1208 bt_object_put_ref(string_obj
);
1212 enum bt_value_map_insert_entry_status
1213 bt_value_map_insert_empty_array_entry(
1214 struct bt_value
*map_obj
, const char *key
,
1215 bt_value
**entry_obj
)
1217 enum bt_value_map_insert_entry_status ret
;
1218 struct bt_value
*array_obj
= NULL
;
1220 BT_ASSERT_PRE_NO_ERROR();
1222 array_obj
= bt_value_array_create();
1223 ret
= bt_value_map_insert_entry(map_obj
, key
,
1224 (void *) array_obj
);
1227 *entry_obj
= array_obj
;
1230 bt_object_put_ref(array_obj
);
1234 enum bt_value_map_insert_entry_status
1235 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
,
1236 bt_value
**entry_obj
)
1238 enum bt_value_map_insert_entry_status ret
;
1239 struct bt_value
*empty_map_obj
= NULL
;
1241 BT_ASSERT_PRE_NO_ERROR();
1243 empty_map_obj
= bt_value_map_create();
1244 ret
= bt_value_map_insert_entry(map_obj
, key
,
1245 (void *) empty_map_obj
);
1248 *entry_obj
= empty_map_obj
;
1251 bt_object_put_ref(empty_map_obj
);
1255 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1256 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1259 int status
= BT_FUNC_STATUS_OK
;
1260 gpointer key
, element_obj
;
1261 GHashTableIter iter
;
1262 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1264 BT_ASSERT_PRE_NO_ERROR();
1266 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1267 BT_ASSERT_PRE_DEV_NON_NULL(func
, "Callback");
1268 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1269 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1271 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1272 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1274 status
= func(key_str
, element_obj
, data
);
1275 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status
);
1276 if (status
!= BT_FUNC_STATUS_OK
) {
1278 BT_LIB_LOGE_APPEND_CAUSE(
1279 "User function failed while iterating "
1280 "map value entries: "
1281 "status=%s, key=\"%s\", "
1282 "value-addr=%p, data=%p",
1283 bt_common_func_status_string(status
),
1284 key_str
, element_obj
, data
);
1286 if (status
== BT_FUNC_STATUS_ERROR
) {
1288 * User function error becomes a
1289 * user error from this
1290 * function's caller's
1293 status
= BT_FUNC_STATUS_USER_ERROR
;
1296 BT_ASSERT(status
== BT_FUNC_STATUS_INTERRUPTED
);
1297 BT_LOGT("User interrupted the loop: status=%s, "
1298 "key=\"%s\", value-addr=%p, data=%p",
1299 bt_common_func_status_string(status
),
1300 key_str
, element_obj
, data
);
1310 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1311 const struct bt_value
*map_obj
,
1312 bt_value_map_foreach_entry_const_func func
, void *data
)
1314 BT_ASSERT_PRE_NO_ERROR();
1316 return (int) bt_value_map_foreach_entry((void *) map_obj
,
1317 (bt_value_map_foreach_entry_func
) func
, data
);
1320 struct extend_map_element_data
{
1321 struct bt_value
*base_obj
;
1325 bt_value_map_foreach_entry_const_func_status
extend_map_element(
1326 const char *key
, const struct bt_value
*extension_obj_elem
,
1330 struct extend_map_element_data
*extend_data
= data
;
1331 struct bt_value
*extension_obj_elem_copy
= NULL
;
1333 /* Copy object which is to replace the current one */
1334 status
= bt_value_copy(extension_obj_elem
, &extension_obj_elem_copy
);
1336 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1337 extension_obj_elem
);
1341 BT_ASSERT(extension_obj_elem_copy
);
1343 /* Replace in base map value. */
1344 status
= bt_value_map_insert_entry(extend_data
->base_obj
, key
,
1345 extension_obj_elem_copy
);
1347 BT_LIB_LOGE_APPEND_CAUSE(
1348 "Cannot replace value in base map value: key=\"%s\", "
1349 "%![base-map-value-]+v, %![element-value-]+v",
1350 key
, extend_data
->base_obj
, extension_obj_elem_copy
);
1357 BT_ASSERT(status
< 0);
1360 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1361 BT_ASSERT(status
== BT_FUNC_STATUS_OK
||
1362 status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1366 enum bt_value_map_extend_status
bt_value_map_extend(
1367 struct bt_value
*base_map_obj
,
1368 const struct bt_value
*extension_obj
)
1370 int status
= BT_FUNC_STATUS_OK
;
1371 struct extend_map_element_data extend_data
= {
1375 BT_ASSERT_PRE_NO_ERROR();
1376 BT_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1377 BT_ASSERT_PRE_DEV_VALUE_HOT(base_map_obj
, "Base value object");
1378 BT_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1379 BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_VALUE_TYPE_MAP
);
1380 BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_VALUE_TYPE_MAP
);
1381 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1382 base_map_obj
, extension_obj
);
1385 * For each key in the extension map object, replace this key
1386 * in the base map object.
1388 extend_data
.base_obj
= base_map_obj
;
1389 status
= bt_value_map_foreach_entry_const(extension_obj
,
1390 extend_map_element
, &extend_data
);
1391 if (status
!= BT_FUNC_STATUS_OK
) {
1392 BT_ASSERT(status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1393 BT_LIB_LOGE_APPEND_CAUSE(
1394 "Cannot iterate on the extension object's elements: "
1395 "%![extension-value-]+v", extension_obj
);
1401 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1402 struct bt_value
**copy_obj
)
1404 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1406 BT_ASSERT_PRE_NO_ERROR();
1407 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
1408 BT_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1409 BT_LOGD("Copying value object: addr=%p", object
);
1410 *copy_obj
= copy_funcs
[object
->type
](object
);
1412 BT_LOGD("Copied value object: copy-value-addr=%p",
1415 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1417 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1423 bt_bool
bt_value_is_equal(const struct bt_value
*object_a
,
1424 const struct bt_value
*object_b
)
1426 bt_bool ret
= BT_FALSE
;
1428 BT_ASSERT_PRE_DEV_NON_NULL(object_a
, "Value object A");
1429 BT_ASSERT_PRE_DEV_NON_NULL(object_b
, "Value object B");
1431 if (object_a
->type
!= object_b
->type
) {
1432 BT_LOGT("Values are different: type mismatch: "
1433 "value-a-addr=%p, value-b-addr=%p, "
1434 "value-a-type=%s, value-b-type=%s",
1436 bt_common_value_type_string(object_a
->type
),
1437 bt_common_value_type_string(object_b
->type
));
1441 ret
= is_equal_funcs
[object_a
->type
](object_a
, object_b
);
1447 void bt_value_get_ref(const struct bt_value
*value
)
1449 bt_object_get_ref(value
);
1452 void bt_value_put_ref(const struct bt_value
*value
)
1454 bt_object_put_ref(value
);