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_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
25 #define BT_VALUE_TO_INTEGER(_base) ((struct bt_value_integer *) (_base))
26 #define BT_VALUE_TO_REAL(_base) ((struct bt_value_real *) (_base))
27 #define BT_VALUE_TO_STRING(_base) ((struct bt_value_string *) (_base))
28 #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base))
29 #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
31 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_COND(_value, _type) \
32 (((struct bt_value *) (_value))->type == (_type))
34 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT \
35 "Value has the wrong type ID: expected-type=%s, %![value-]+v"
37 #define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
39 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
40 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
41 bt_common_value_type_string(_type), (_value))
43 #define BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(_value, _type) \
45 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
46 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
47 bt_common_value_type_string(_type), (_value))
49 #define BT_ASSERT_PRE_DEV_VALUE_HOT(_value, _name) \
50 BT_ASSERT_PRE_DEV_HOT(((struct bt_value *) (_value)), (_name), \
54 void bt_value_null_instance_release_func(struct bt_object
*obj
)
56 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
60 struct bt_value bt_value_null_instance
= {
64 .release_func
= bt_value_null_instance_release_func
,
65 .spec_release_func
= NULL
,
66 .parent_is_owner_listener_func
= NULL
,
69 .type
= BT_VALUE_TYPE_NULL
,
73 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
76 void bt_value_destroy(struct bt_object
*obj
);
79 void bt_value_string_destroy(struct bt_value
*object
)
81 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
82 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
86 void bt_value_array_destroy(struct bt_value
*object
)
89 * Pointer array's registered value destructor will take care
90 * of putting each contained object.
92 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
93 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
97 void bt_value_map_destroy(struct bt_value
*object
)
100 * Hash table's registered value destructor will take care of
101 * putting each contained object. Keys are GQuarks and cannot
102 * be destroyed anyway.
104 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
105 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
109 void (* const destroy_funcs
[])(struct bt_value
*) = {
110 [BT_VALUE_TYPE_NULL
] = NULL
,
111 [BT_VALUE_TYPE_BOOL
] = NULL
,
112 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
113 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
114 [BT_VALUE_TYPE_REAL
] = NULL
,
115 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
116 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
117 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
121 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
123 BT_ASSERT(null_obj
== bt_value_null
);
125 bt_object_get_ref_no_null_check(bt_value_null
);
126 return (void *) bt_value_null
;
130 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
132 return bt_value_bool_create_init(
133 BT_VALUE_TO_BOOL(bool_obj
)->value
);
137 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
141 struct bt_value
*bt_value_integer_copy(
142 const struct bt_value
*integer_obj
)
144 return bt_value_integer_create_init(integer_obj
->type
,
145 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
149 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
151 return bt_value_real_create_init(
152 BT_VALUE_TO_REAL(real_obj
)->value
);
156 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
158 return bt_value_string_create_init(
159 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
163 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
167 struct bt_value
*copy_obj
;
168 struct bt_value_array
*typed_array_obj
;
170 BT_LOGD("Copying array value: addr=%p", array_obj
);
171 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
172 copy_obj
= bt_value_array_create();
174 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
178 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
179 struct bt_value
*element_obj_copy
= NULL
;
180 const struct bt_value
*element_obj
=
181 bt_value_array_borrow_element_by_index_const(
184 BT_LOGD("Copying array value's element: element-addr=%p, "
185 "index=%d", element_obj
, i
);
186 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
188 BT_LIB_LOGE_APPEND_CAUSE(
189 "Cannot copy array value's element: "
190 "array-addr=%p, index=%d",
192 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
196 BT_ASSERT(element_obj_copy
);
197 ret
= bt_value_array_append_element(copy_obj
,
198 (void *) element_obj_copy
);
199 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
201 BT_LIB_LOGE_APPEND_CAUSE(
202 "Cannot append to array value: addr=%p",
204 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
209 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
210 array_obj
, copy_obj
);
217 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
221 gpointer key
, element_obj
;
222 struct bt_value
*copy_obj
;
223 struct bt_value
*element_obj_copy
= NULL
;
224 struct bt_value_map
*typed_map_obj
;
226 BT_LOGD("Copying map value: addr=%p", map_obj
);
227 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
228 copy_obj
= bt_value_map_create();
233 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
235 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
236 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
239 BT_LOGD("Copying map value's element: element-addr=%p, "
240 "key=\"%s\"", element_obj
, key_str
);
241 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
243 BT_LIB_LOGE_APPEND_CAUSE(
244 "Cannot copy map value's element: "
245 "map-addr=%p, key=\"%s\"",
247 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
251 BT_ASSERT(element_obj_copy
);
252 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
253 (void *) element_obj_copy
);
254 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
256 BT_LIB_LOGE_APPEND_CAUSE(
257 "Cannot insert into map value: addr=%p, key=\"%s\"",
259 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
264 BT_LOGD("Copied map value: addr=%p", map_obj
);
271 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
272 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
273 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
274 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
275 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
276 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
277 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
278 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
279 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
283 bt_bool
bt_value_null_is_equal(const struct bt_value
*object_a
,
284 const struct bt_value
*object_b
)
287 * Always BT_TRUE since bt_value_is_equal() already checks if both
288 * object_a and object_b have the same type, and in the case of
289 * null value objects, they're always the same if it is so.
295 bt_bool
bt_value_bool_is_equal(const struct bt_value
*object_a
,
296 const struct bt_value
*object_b
)
298 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
299 BT_VALUE_TO_BOOL(object_b
)->value
) {
300 BT_LOGT("Boolean value objects are different: "
301 "bool-a-val=%d, bool-b-val=%d",
302 BT_VALUE_TO_BOOL(object_a
)->value
,
303 BT_VALUE_TO_BOOL(object_b
)->value
);
311 bt_bool
bt_value_integer_is_equal(const struct bt_value
*object_a
,
312 const struct bt_value
*object_b
)
314 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
315 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
316 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
317 BT_LOGT("Unsigned integer value objects are different: "
318 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
319 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
320 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
322 BT_LOGT("Signed integer value objects are different: "
323 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
324 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
325 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
335 bt_bool
bt_value_real_is_equal(const struct bt_value
*object_a
,
336 const struct bt_value
*object_b
)
338 if (BT_VALUE_TO_REAL(object_a
)->value
!=
339 BT_VALUE_TO_REAL(object_b
)->value
) {
340 BT_LOGT("Real number value objects are different: "
341 "real-a-val=%f, real-b-val=%f",
342 BT_VALUE_TO_REAL(object_a
)->value
,
343 BT_VALUE_TO_REAL(object_b
)->value
);
351 bt_bool
bt_value_string_is_equal(const struct bt_value
*object_a
,
352 const struct bt_value
*object_b
)
354 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
355 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
356 BT_LOGT("String value objects are different: "
357 "string-a-val=\"%s\", string-b-val=\"%s\"",
358 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
359 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
367 bt_bool
bt_value_array_is_equal(const struct bt_value
*object_a
,
368 const struct bt_value
*object_b
)
371 bt_bool ret
= BT_TRUE
;
372 const struct bt_value_array
*array_obj_a
=
373 BT_VALUE_TO_ARRAY(object_a
);
375 if (bt_value_array_get_length(object_a
) !=
376 bt_value_array_get_length(object_b
)) {
377 BT_LOGT("Array values are different: size mismatch "
378 "value-a-addr=%p, value-b-addr=%p, "
379 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
381 bt_value_array_get_length(object_a
),
382 bt_value_array_get_length(object_b
));
387 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
388 const struct bt_value
*element_obj_a
;
389 const struct bt_value
*element_obj_b
;
391 element_obj_a
= bt_value_array_borrow_element_by_index_const(
393 element_obj_b
= bt_value_array_borrow_element_by_index_const(
396 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
397 BT_LOGT("Array values's elements are different: "
398 "value-a-addr=%p, value-b-addr=%p, index=%d",
399 element_obj_a
, element_obj_b
, i
);
410 bt_bool
bt_value_map_is_equal(const struct bt_value
*object_a
,
411 const struct bt_value
*object_b
)
413 bt_bool ret
= BT_TRUE
;
415 gpointer key
, element_obj_a
;
416 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
418 if (bt_value_map_get_size(object_a
) !=
419 bt_value_map_get_size(object_b
)) {
420 BT_LOGT("Map values are different: size mismatch "
421 "value-a-addr=%p, value-b-addr=%p, "
422 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
424 bt_value_map_get_size(object_a
),
425 bt_value_map_get_size(object_b
));
430 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
432 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
433 const struct bt_value
*element_obj_b
;
434 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
436 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
439 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
440 BT_LOGT("Map values's elements are different: "
441 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
442 element_obj_a
, element_obj_b
, key_str
);
453 bt_bool (* const is_equal_funcs
[])(const struct bt_value
*,
454 const struct bt_value
*) = {
455 [BT_VALUE_TYPE_NULL
] = bt_value_null_is_equal
,
456 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_is_equal
,
457 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_is_equal
,
458 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_is_equal
,
459 [BT_VALUE_TYPE_REAL
] = bt_value_real_is_equal
,
460 [BT_VALUE_TYPE_STRING
] = bt_value_string_is_equal
,
461 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_is_equal
,
462 [BT_VALUE_TYPE_MAP
] = bt_value_map_is_equal
,
466 void bt_value_null_freeze(struct bt_value
*object
)
471 void bt_value_generic_freeze(struct bt_value
*object
)
473 object
->frozen
= BT_TRUE
;
477 void bt_value_array_freeze(struct bt_value
*object
)
480 struct bt_value_array
*typed_array_obj
=
481 BT_VALUE_TO_ARRAY(object
);
483 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
484 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
487 bt_value_generic_freeze(object
);
491 void bt_value_map_freeze(struct bt_value
*object
)
494 gpointer key
, element_obj
;
495 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
497 g_hash_table_iter_init(&iter
, map_obj
->ght
);
499 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
500 bt_value_freeze(element_obj
);
503 bt_value_generic_freeze(object
);
507 void (* const freeze_funcs
[])(struct bt_value
*) = {
508 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
509 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
510 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
511 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
512 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
513 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
514 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
515 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
519 void bt_value_destroy(struct bt_object
*obj
)
521 struct bt_value
*value
;
523 value
= container_of(obj
, struct bt_value
, base
);
524 BT_LOGD("Destroying value: addr=%p", value
);
526 if (bt_value_is_null(value
)) {
527 BT_LOGD_STR("Not destroying the null value singleton.");
531 if (destroy_funcs
[value
->type
]) {
532 destroy_funcs
[value
->type
](value
);
539 void _bt_value_freeze(const struct bt_value
*c_object
)
541 const struct bt_value
*object
= (void *) c_object
;
545 if (object
->frozen
) {
549 BT_LOGD("Freezing value: addr=%p", object
);
550 freeze_funcs
[object
->type
]((void *) object
);
556 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
558 BT_ASSERT_PRE_DEV_NON_NULL(object
, "Value object");
563 struct bt_value
bt_value_create_base(enum bt_value_type type
)
565 struct bt_value value
;
568 value
.frozen
= BT_FALSE
;
569 bt_object_init_shared(&value
.base
, bt_value_destroy
);
573 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
575 struct bt_value_bool
*bool_obj
;
577 BT_ASSERT_PRE_NO_ERROR();
579 BT_LOGD("Creating boolean value object: val=%d", val
);
580 bool_obj
= g_new0(struct bt_value_bool
, 1);
582 BT_LIB_LOGE_APPEND_CAUSE(
583 "Failed to allocate one boolean value object.");
587 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
588 bool_obj
->value
= val
;
589 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
592 return (void *) bool_obj
;
595 struct bt_value
*bt_value_bool_create(void)
597 BT_ASSERT_PRE_NO_ERROR();
599 return bt_value_bool_create_init(BT_FALSE
);
603 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
606 struct bt_value_integer
*integer_obj
;
608 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
609 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
611 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
612 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
615 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
619 integer_obj
= g_new0(struct bt_value_integer
, 1);
621 BT_LIB_LOGE_APPEND_CAUSE(
622 "Failed to allocate one integer value object.");
626 integer_obj
->base
= bt_value_create_base(type
);
627 integer_obj
->value
.u
= uval
;
628 BT_LOGD("Created %ssigned integer value object: addr=%p",
629 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
633 return (void *) integer_obj
;
636 struct bt_value
*bt_value_integer_unsigned_create_init(uint64_t val
)
638 BT_ASSERT_PRE_NO_ERROR();
640 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
644 struct bt_value
*bt_value_integer_unsigned_create(void)
646 BT_ASSERT_PRE_NO_ERROR();
648 return bt_value_integer_unsigned_create_init(0);
651 struct bt_value
*bt_value_integer_signed_create_init(int64_t val
)
653 BT_ASSERT_PRE_NO_ERROR();
655 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
659 struct bt_value
*bt_value_integer_signed_create(void)
661 BT_ASSERT_PRE_NO_ERROR();
663 return bt_value_integer_signed_create_init(0);
666 struct bt_value
*bt_value_real_create_init(double val
)
668 struct bt_value_real
*real_obj
;
670 BT_ASSERT_PRE_NO_ERROR();
672 BT_LOGD("Creating real number value object: val=%f", val
);
673 real_obj
= g_new0(struct bt_value_real
, 1);
675 BT_LIB_LOGE_APPEND_CAUSE(
676 "Failed to allocate one real number value object.");
680 real_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_REAL
);
681 real_obj
->value
= val
;
682 BT_LOGD("Created real number value object: addr=%p",
686 return (void *) real_obj
;
689 struct bt_value
*bt_value_real_create(void)
691 BT_ASSERT_PRE_NO_ERROR();
693 return bt_value_real_create_init(0.);
696 struct bt_value
*bt_value_string_create_init(const char *val
)
698 struct bt_value_string
*string_obj
= NULL
;
700 BT_ASSERT_PRE_NO_ERROR();
701 BT_ASSERT_PRE_NON_NULL(val
, "Value");
703 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
704 string_obj
= g_new0(struct bt_value_string
, 1);
706 BT_LIB_LOGE_APPEND_CAUSE(
707 "Failed to allocate one string object.");
711 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
712 string_obj
->gstr
= g_string_new(val
);
713 if (!string_obj
->gstr
) {
714 BT_LIB_LOGE_APPEND_CAUSE(
715 "Failed to allocate a GString.");
721 BT_LOGD("Created string value object: addr=%p",
725 return (void *) string_obj
;
728 struct bt_value
*bt_value_string_create(void)
730 BT_ASSERT_PRE_NO_ERROR();
732 return bt_value_string_create_init("");
735 struct bt_value
*bt_value_array_create(void)
737 struct bt_value_array
*array_obj
;
739 BT_ASSERT_PRE_NO_ERROR();
741 BT_LOGD_STR("Creating empty array value object.");
742 array_obj
= g_new0(struct bt_value_array
, 1);
744 BT_LIB_LOGE_APPEND_CAUSE(
745 "Failed to allocate one array object.");
749 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
750 array_obj
->garray
= bt_g_ptr_array_new_full(0,
751 (GDestroyNotify
) bt_object_put_ref
);
752 if (!array_obj
->garray
) {
753 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
759 BT_LOGD("Created array value object: addr=%p",
763 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
;
796 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
798 BT_ASSERT_PRE_DEV_NON_NULL(bool_obj
, "Value object");
799 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
800 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
803 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
805 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
806 BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
807 BT_ASSERT_PRE_DEV_VALUE_HOT(bool_obj
, "Value object");
808 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
809 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
813 uint64_t bt_value_integer_unsigned_get(const struct bt_value
*integer_obj
)
815 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
816 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
817 BT_VALUE_TYPE_UNSIGNED_INTEGER
);
818 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
821 int64_t bt_value_integer_signed_get(const struct bt_value
*integer_obj
)
823 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
824 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
825 BT_VALUE_TYPE_SIGNED_INTEGER
);
826 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
830 void bt_value_integer_set(struct bt_value
*integer_obj
,
831 enum bt_value_type expected_type
, uint64_t uval
)
833 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
834 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, expected_type
);
835 BT_ASSERT_PRE_DEV_VALUE_HOT(integer_obj
, "Value object");
836 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
839 void bt_value_integer_unsigned_set(struct bt_value
*integer_obj
,
842 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
);
843 BT_LOGT("Set unsigned integer value's raw value: "
844 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
847 void bt_value_integer_signed_set(struct bt_value
*integer_obj
,
850 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
852 BT_LOGT("Set signed integer value's raw value: "
853 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
856 double bt_value_real_get(const struct bt_value
*real_obj
)
858 BT_ASSERT_PRE_DEV_NON_NULL(real_obj
, "Value object");
859 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
860 return BT_VALUE_TO_REAL(real_obj
)->value
;
863 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
865 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
866 BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
867 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
, "Value object");
868 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
869 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
873 const char *bt_value_string_get(const struct bt_value
*string_obj
)
875 BT_ASSERT_PRE_DEV_NON_NULL(string_obj
, "Value object");
876 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
877 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
880 enum bt_value_string_set_status
bt_value_string_set(
881 struct bt_value
*string_obj
, const char *val
)
883 BT_ASSERT_PRE_NO_ERROR();
884 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
885 BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
886 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
, "Value object");
887 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
888 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
890 return BT_FUNC_STATUS_OK
;
893 uint64_t bt_value_array_get_length(const struct bt_value
*array_obj
)
895 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
896 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
897 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
900 struct bt_value
*bt_value_array_borrow_element_by_index(
901 struct bt_value
*array_obj
, uint64_t index
)
903 struct bt_value_array
*typed_array_obj
=
904 BT_VALUE_TO_ARRAY(array_obj
);
906 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
907 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
908 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
909 return g_ptr_array_index(typed_array_obj
->garray
, index
);
912 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
913 const struct bt_value
*array_obj
,
916 return bt_value_array_borrow_element_by_index(
917 (void *) array_obj
, index
);
920 enum bt_value_array_append_element_status
bt_value_array_append_element(
921 struct bt_value
*array_obj
,
922 struct bt_value
*element_obj
)
924 struct bt_value_array
*typed_array_obj
=
925 BT_VALUE_TO_ARRAY(array_obj
);
927 BT_ASSERT_PRE_NO_ERROR();
928 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
929 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
930 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
931 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
932 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
933 bt_object_get_ref(element_obj
);
934 BT_LOGT("Appended element to array value: array-value-addr=%p, "
935 "element-value-addr=%p, new-size=%u",
936 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
937 return BT_FUNC_STATUS_OK
;
940 enum bt_value_array_append_element_status
941 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
943 enum bt_value_array_append_element_status ret
;
944 struct bt_value
*bool_obj
= NULL
;
946 BT_ASSERT_PRE_NO_ERROR();
948 bool_obj
= bt_value_bool_create_init(val
);
949 ret
= bt_value_array_append_element(array_obj
,
951 bt_object_put_ref(bool_obj
);
955 enum bt_value_array_append_element_status
956 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
959 enum bt_value_array_append_element_status ret
;
960 struct bt_value
*integer_obj
= NULL
;
962 BT_ASSERT_PRE_NO_ERROR();
964 integer_obj
= bt_value_integer_unsigned_create_init(val
);
965 ret
= bt_value_array_append_element(array_obj
,
966 (void *) integer_obj
);
967 bt_object_put_ref(integer_obj
);
971 enum bt_value_array_append_element_status
972 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
975 enum bt_value_array_append_element_status ret
;
976 struct bt_value
*integer_obj
= NULL
;
978 BT_ASSERT_PRE_NO_ERROR();
980 integer_obj
= bt_value_integer_signed_create_init(val
);
981 ret
= bt_value_array_append_element(array_obj
,
982 (void *) integer_obj
);
983 bt_object_put_ref(integer_obj
);
987 enum bt_value_array_append_element_status
988 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
990 enum bt_value_array_append_element_status ret
;
991 struct bt_value
*real_obj
= NULL
;
993 BT_ASSERT_PRE_NO_ERROR();
995 real_obj
= bt_value_real_create_init(val
);
996 ret
= bt_value_array_append_element(array_obj
,
998 bt_object_put_ref(real_obj
);
1002 enum bt_value_array_append_element_status
1003 bt_value_array_append_string_element(struct bt_value
*array_obj
,
1006 enum bt_value_array_append_element_status ret
;
1007 struct bt_value
*string_obj
= NULL
;
1009 BT_ASSERT_PRE_NO_ERROR();
1011 string_obj
= bt_value_string_create_init(val
);
1012 ret
= bt_value_array_append_element(array_obj
,
1013 (void *) string_obj
);
1014 bt_object_put_ref(string_obj
);
1018 enum bt_value_array_append_element_status
1019 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
,
1020 struct bt_value
**element_obj
)
1022 enum bt_value_array_append_element_status ret
;
1023 struct bt_value
*empty_array_obj
= NULL
;
1025 BT_ASSERT_PRE_NO_ERROR();
1027 empty_array_obj
= bt_value_array_create();
1028 ret
= bt_value_array_append_element(array_obj
,
1029 (void *) empty_array_obj
);
1032 *element_obj
= empty_array_obj
;
1035 bt_object_put_ref(empty_array_obj
);
1039 enum bt_value_array_append_element_status
1040 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
,
1041 struct bt_value
**element_obj
)
1043 enum bt_value_array_append_element_status ret
;
1044 struct bt_value
*map_obj
= NULL
;
1046 BT_ASSERT_PRE_NO_ERROR();
1048 map_obj
= bt_value_map_create();
1049 ret
= bt_value_array_append_element(array_obj
,
1053 *element_obj
= map_obj
;
1056 bt_object_put_ref(map_obj
);
1060 enum bt_value_array_set_element_by_index_status
1061 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1062 struct bt_value
*element_obj
)
1064 struct bt_value_array
*typed_array_obj
=
1065 BT_VALUE_TO_ARRAY(array_obj
);
1067 BT_ASSERT_PRE_NO_ERROR();
1068 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1069 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1070 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
1071 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
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_NON_NULL(map_obj
, "Value object");
1085 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
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_NON_NULL(map_obj
, "Value object");
1093 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1094 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
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_NON_NULL(map_obj
, "Value object");
1108 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1109 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1110 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1111 GUINT_TO_POINTER(g_quark_from_string(key
)));
1114 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1115 struct bt_value
*map_obj
, const char *key
,
1116 struct bt_value
*element_obj
)
1118 BT_ASSERT_PRE_NO_ERROR();
1119 BT_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1120 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1121 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1122 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1123 BT_ASSERT_PRE_DEV_VALUE_HOT(map_obj
, "Map value object");
1124 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1125 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1126 bt_object_get_ref(element_obj
);
1127 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1128 "key=\"%s\", element-value-addr=%p",
1129 map_obj
, key
, element_obj
);
1130 return BT_FUNC_STATUS_OK
;
1133 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1134 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1136 enum bt_value_map_insert_entry_status ret
;
1137 struct bt_value
*bool_obj
= NULL
;
1139 BT_ASSERT_PRE_NO_ERROR();
1141 bool_obj
= bt_value_bool_create_init(val
);
1142 ret
= bt_value_map_insert_entry(map_obj
, key
,
1144 bt_object_put_ref(bool_obj
);
1148 enum bt_value_map_insert_entry_status
1149 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1150 const char *key
, uint64_t val
)
1152 enum bt_value_map_insert_entry_status ret
;
1153 struct bt_value
*integer_obj
= NULL
;
1155 BT_ASSERT_PRE_NO_ERROR();
1157 integer_obj
= bt_value_integer_unsigned_create_init(val
);
1158 ret
= bt_value_map_insert_entry(map_obj
, key
,
1159 (void *) integer_obj
);
1160 bt_object_put_ref(integer_obj
);
1164 enum bt_value_map_insert_entry_status
1165 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1166 const char *key
, int64_t val
)
1168 enum bt_value_map_insert_entry_status ret
;
1169 struct bt_value
*integer_obj
= NULL
;
1171 BT_ASSERT_PRE_NO_ERROR();
1173 integer_obj
= bt_value_integer_signed_create_init(val
);
1174 ret
= bt_value_map_insert_entry(map_obj
, key
,
1175 (void *) integer_obj
);
1176 bt_object_put_ref(integer_obj
);
1180 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1181 struct bt_value
*map_obj
, const char *key
, double val
)
1183 enum bt_value_map_insert_entry_status ret
;
1184 struct bt_value
*real_obj
= NULL
;
1186 BT_ASSERT_PRE_NO_ERROR();
1188 real_obj
= bt_value_real_create_init(val
);
1189 ret
= bt_value_map_insert_entry(map_obj
, key
,
1191 bt_object_put_ref(real_obj
);
1195 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1196 struct bt_value
*map_obj
, const char *key
,
1199 enum bt_value_map_insert_entry_status ret
;
1200 struct bt_value
*string_obj
= NULL
;
1202 BT_ASSERT_PRE_NO_ERROR();
1204 string_obj
= bt_value_string_create_init(val
);
1205 ret
= bt_value_map_insert_entry(map_obj
, key
,
1206 (void *) string_obj
);
1207 bt_object_put_ref(string_obj
);
1211 enum bt_value_map_insert_entry_status
1212 bt_value_map_insert_empty_array_entry(
1213 struct bt_value
*map_obj
, const char *key
,
1214 bt_value
**entry_obj
)
1216 enum bt_value_map_insert_entry_status ret
;
1217 struct bt_value
*array_obj
= NULL
;
1219 BT_ASSERT_PRE_NO_ERROR();
1221 array_obj
= bt_value_array_create();
1222 ret
= bt_value_map_insert_entry(map_obj
, key
,
1223 (void *) array_obj
);
1226 *entry_obj
= array_obj
;
1229 bt_object_put_ref(array_obj
);
1233 enum bt_value_map_insert_entry_status
1234 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
,
1235 bt_value
**entry_obj
)
1237 enum bt_value_map_insert_entry_status ret
;
1238 struct bt_value
*empty_map_obj
= NULL
;
1240 BT_ASSERT_PRE_NO_ERROR();
1242 empty_map_obj
= bt_value_map_create();
1243 ret
= bt_value_map_insert_entry(map_obj
, key
,
1244 (void *) empty_map_obj
);
1247 *entry_obj
= empty_map_obj
;
1250 bt_object_put_ref(empty_map_obj
);
1254 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1255 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1258 int status
= BT_FUNC_STATUS_OK
;
1259 gpointer key
, element_obj
;
1260 GHashTableIter iter
;
1261 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1263 BT_ASSERT_PRE_NO_ERROR();
1265 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1266 BT_ASSERT_PRE_DEV_NON_NULL(func
, "Callback");
1267 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1268 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1270 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1271 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1273 status
= func(key_str
, element_obj
, data
);
1274 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status
);
1275 if (status
!= BT_FUNC_STATUS_OK
) {
1277 BT_LIB_LOGE_APPEND_CAUSE(
1278 "User function failed while iterating "
1279 "map value entries: "
1280 "status=%s, key=\"%s\", "
1281 "value-addr=%p, data=%p",
1282 bt_common_func_status_string(status
),
1283 key_str
, element_obj
, data
);
1285 if (status
== BT_FUNC_STATUS_ERROR
) {
1287 * User function error becomes a
1288 * user error from this
1289 * function's caller's
1292 status
= BT_FUNC_STATUS_USER_ERROR
;
1295 BT_ASSERT(status
== BT_FUNC_STATUS_INTERRUPTED
);
1296 BT_LOGT("User interrupted the loop: status=%s, "
1297 "key=\"%s\", value-addr=%p, data=%p",
1298 bt_common_func_status_string(status
),
1299 key_str
, element_obj
, data
);
1309 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1310 const struct bt_value
*map_obj
,
1311 bt_value_map_foreach_entry_const_func func
, void *data
)
1313 BT_ASSERT_PRE_NO_ERROR();
1315 return (int) bt_value_map_foreach_entry((void *) map_obj
,
1316 (bt_value_map_foreach_entry_func
) func
, data
);
1319 struct extend_map_element_data
{
1320 struct bt_value
*base_obj
;
1324 bt_value_map_foreach_entry_const_func_status
extend_map_element(
1325 const char *key
, const struct bt_value
*extension_obj_elem
,
1329 struct extend_map_element_data
*extend_data
= data
;
1330 struct bt_value
*extension_obj_elem_copy
= NULL
;
1332 /* Copy object which is to replace the current one */
1333 status
= bt_value_copy(extension_obj_elem
, &extension_obj_elem_copy
);
1335 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1336 extension_obj_elem
);
1340 BT_ASSERT(extension_obj_elem_copy
);
1342 /* Replace in base map value. */
1343 status
= bt_value_map_insert_entry(extend_data
->base_obj
, key
,
1344 extension_obj_elem_copy
);
1346 BT_LIB_LOGE_APPEND_CAUSE(
1347 "Cannot replace value in base map value: key=\"%s\", "
1348 "%![base-map-value-]+v, %![element-value-]+v",
1349 key
, extend_data
->base_obj
, extension_obj_elem_copy
);
1356 BT_ASSERT(status
< 0);
1359 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1360 BT_ASSERT(status
== BT_FUNC_STATUS_OK
||
1361 status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1365 enum bt_value_map_extend_status
bt_value_map_extend(
1366 struct bt_value
*base_map_obj
,
1367 const struct bt_value
*extension_obj
)
1369 int status
= BT_FUNC_STATUS_OK
;
1370 struct extend_map_element_data extend_data
= {
1374 BT_ASSERT_PRE_NO_ERROR();
1375 BT_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1376 BT_ASSERT_PRE_DEV_VALUE_HOT(base_map_obj
, "Base value object");
1377 BT_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1378 BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_VALUE_TYPE_MAP
);
1379 BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_VALUE_TYPE_MAP
);
1380 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1381 base_map_obj
, extension_obj
);
1384 * For each key in the extension map object, replace this key
1385 * in the base map object.
1387 extend_data
.base_obj
= base_map_obj
;
1388 status
= bt_value_map_foreach_entry_const(extension_obj
,
1389 extend_map_element
, &extend_data
);
1390 if (status
!= BT_FUNC_STATUS_OK
) {
1391 BT_ASSERT(status
== BT_FUNC_STATUS_MEMORY_ERROR
);
1392 BT_LIB_LOGE_APPEND_CAUSE(
1393 "Cannot iterate on the extension object's elements: "
1394 "%![extension-value-]+v", extension_obj
);
1400 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1401 struct bt_value
**copy_obj
)
1403 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1405 BT_ASSERT_PRE_NO_ERROR();
1406 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
1407 BT_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1408 BT_LOGD("Copying value object: addr=%p", object
);
1409 *copy_obj
= copy_funcs
[object
->type
](object
);
1411 BT_LOGD("Copied value object: copy-value-addr=%p",
1414 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1416 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1422 bt_bool
bt_value_is_equal(const struct bt_value
*object_a
,
1423 const struct bt_value
*object_b
)
1425 bt_bool ret
= BT_FALSE
;
1427 BT_ASSERT_PRE_DEV_NON_NULL(object_a
, "Value object A");
1428 BT_ASSERT_PRE_DEV_NON_NULL(object_b
, "Value object B");
1430 if (object_a
->type
!= object_b
->type
) {
1431 BT_LOGT("Values are different: type mismatch: "
1432 "value-a-addr=%p, value-b-addr=%p, "
1433 "value-a-type=%s, value-b-type=%s",
1435 bt_common_value_type_string(object_a
->type
),
1436 bt_common_value_type_string(object_b
->type
));
1440 ret
= is_equal_funcs
[object_a
->type
](object_a
, object_b
);
1446 void bt_value_get_ref(const struct bt_value
*value
)
1448 bt_object_get_ref(value
);
1451 void bt_value_put_ref(const struct bt_value
*value
)
1453 bt_object_put_ref(value
);