2 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "LIB/VALUE"
24 #include "lib/logging.h"
30 #include <babeltrace2/babeltrace.h>
32 #include "compat/compiler.h"
33 #include "common/common.h"
34 #include "compat/glib.h"
35 #include "lib/assert-pre.h"
36 #include "lib/value.h"
37 #include "common/assert.h"
38 #include "func-status.h"
40 #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
41 #define BT_VALUE_TO_INTEGER(_base) ((struct bt_value_integer *) (_base))
42 #define BT_VALUE_TO_REAL(_base) ((struct bt_value_real *) (_base))
43 #define BT_VALUE_TO_STRING(_base) ((struct bt_value_string *) (_base))
44 #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base))
45 #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
47 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_COND(_value, _type) \
48 (((struct bt_value *) (_value))->type == (_type))
50 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT \
51 "Value has the wrong type ID: expected-type=%s, %![value-]+v"
53 #define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
55 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
56 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
57 bt_common_value_type_string(_type), (_value))
59 #define BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(_value, _type) \
61 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
62 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
63 bt_common_value_type_string(_type), (_value))
65 #define BT_ASSERT_PRE_DEV_VALUE_HOT(_value, _name) \
66 BT_ASSERT_PRE_DEV_HOT(((struct bt_value *) (_value)), (_name), \
70 void bt_value_null_instance_release_func(struct bt_object
*obj
)
72 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
76 struct bt_value bt_value_null_instance
= {
80 .release_func
= bt_value_null_instance_release_func
,
81 .spec_release_func
= NULL
,
82 .parent_is_owner_listener_func
= NULL
,
85 .type
= BT_VALUE_TYPE_NULL
,
89 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
92 void bt_value_destroy(struct bt_object
*obj
);
95 void bt_value_string_destroy(struct bt_value
*object
)
97 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
98 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
102 void bt_value_array_destroy(struct bt_value
*object
)
105 * Pointer array's registered value destructor will take care
106 * of putting each contained object.
108 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
109 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
113 void bt_value_map_destroy(struct bt_value
*object
)
116 * Hash table's registered value destructor will take care of
117 * putting each contained object. Keys are GQuarks and cannot
118 * be destroyed anyway.
120 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
121 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
125 void (* const destroy_funcs
[])(struct bt_value
*) = {
126 [BT_VALUE_TYPE_NULL
] = NULL
,
127 [BT_VALUE_TYPE_BOOL
] = NULL
,
128 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
129 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
130 [BT_VALUE_TYPE_REAL
] = NULL
,
131 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
132 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
133 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
137 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
139 return (void *) bt_value_null
;
143 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
145 return bt_value_bool_create_init(
146 BT_VALUE_TO_BOOL(bool_obj
)->value
);
150 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
154 struct bt_value
*bt_value_integer_copy(
155 const struct bt_value
*integer_obj
)
157 return bt_value_integer_create_init(integer_obj
->type
,
158 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
162 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
164 return bt_value_real_create_init(
165 BT_VALUE_TO_REAL(real_obj
)->value
);
169 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
171 return bt_value_string_create_init(
172 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
176 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
180 struct bt_value
*copy_obj
;
181 struct bt_value_array
*typed_array_obj
;
183 BT_LOGD("Copying array value: addr=%p", array_obj
);
184 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
185 copy_obj
= bt_value_array_create();
187 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
191 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
192 struct bt_value
*element_obj_copy
= NULL
;
193 const struct bt_value
*element_obj
=
194 bt_value_array_borrow_element_by_index_const(
197 BT_ASSERT(element_obj
);
198 BT_LOGD("Copying array value's element: element-addr=%p, "
199 "index=%d", element_obj
, i
);
200 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
202 BT_LIB_LOGE_APPEND_CAUSE(
203 "Cannot copy array value's element: "
204 "array-addr=%p, index=%d",
206 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
210 BT_ASSERT(element_obj_copy
);
211 ret
= bt_value_array_append_element(copy_obj
,
212 (void *) element_obj_copy
);
213 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
215 BT_LIB_LOGE_APPEND_CAUSE(
216 "Cannot append to array value: addr=%p",
218 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
223 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
224 array_obj
, copy_obj
);
231 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
235 gpointer key
, element_obj
;
236 struct bt_value
*copy_obj
;
237 struct bt_value
*element_obj_copy
= NULL
;
238 struct bt_value_map
*typed_map_obj
;
240 BT_LOGD("Copying map value: addr=%p", map_obj
);
241 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
242 copy_obj
= bt_value_map_create();
247 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
249 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
250 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
253 BT_LOGD("Copying map value's element: element-addr=%p, "
254 "key=\"%s\"", element_obj
, key_str
);
255 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
257 BT_LIB_LOGE_APPEND_CAUSE(
258 "Cannot copy map value's element: "
259 "map-addr=%p, key=\"%s\"",
261 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
265 BT_ASSERT(element_obj_copy
);
266 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
267 (void *) element_obj_copy
);
268 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
270 BT_LIB_LOGE_APPEND_CAUSE(
271 "Cannot insert into map value: addr=%p, key=\"%s\"",
273 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
278 BT_LOGD("Copied map value: addr=%p", map_obj
);
285 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
286 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
287 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
288 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
289 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
290 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
291 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
292 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
293 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
297 bt_bool
bt_value_null_compare(const struct bt_value
*object_a
,
298 const struct bt_value
*object_b
)
301 * Always BT_TRUE since bt_value_compare() already checks if both
302 * object_a and object_b have the same type, and in the case of
303 * null value objects, they're always the same if it is so.
309 bt_bool
bt_value_bool_compare(const struct bt_value
*object_a
,
310 const struct bt_value
*object_b
)
312 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
313 BT_VALUE_TO_BOOL(object_b
)->value
) {
314 BT_LOGT("Boolean value objects are different: "
315 "bool-a-val=%d, bool-b-val=%d",
316 BT_VALUE_TO_BOOL(object_a
)->value
,
317 BT_VALUE_TO_BOOL(object_b
)->value
);
325 bt_bool
bt_value_integer_compare(const struct bt_value
*object_a
,
326 const struct bt_value
*object_b
)
328 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
329 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
330 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
331 BT_LOGT("Unsigned integer value objects are different: "
332 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
333 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
334 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
336 BT_LOGT("Signed integer value objects are different: "
337 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
338 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
339 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
349 bt_bool
bt_value_real_compare(const struct bt_value
*object_a
,
350 const struct bt_value
*object_b
)
352 if (BT_VALUE_TO_REAL(object_a
)->value
!=
353 BT_VALUE_TO_REAL(object_b
)->value
) {
354 BT_LOGT("Real number value objects are different: "
355 "real-a-val=%f, real-b-val=%f",
356 BT_VALUE_TO_REAL(object_a
)->value
,
357 BT_VALUE_TO_REAL(object_b
)->value
);
365 bt_bool
bt_value_string_compare(const struct bt_value
*object_a
,
366 const struct bt_value
*object_b
)
368 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
369 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
370 BT_LOGT("String value objects are different: "
371 "string-a-val=\"%s\", string-b-val=\"%s\"",
372 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
373 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
381 bt_bool
bt_value_array_compare(const struct bt_value
*object_a
,
382 const struct bt_value
*object_b
)
385 bt_bool ret
= BT_TRUE
;
386 const struct bt_value_array
*array_obj_a
=
387 BT_VALUE_TO_ARRAY(object_a
);
389 if (bt_value_array_get_size(object_a
) !=
390 bt_value_array_get_size(object_b
)) {
391 BT_LOGT("Array values are different: size mismatch "
392 "value-a-addr=%p, value-b-addr=%p, "
393 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
395 bt_value_array_get_size(object_a
),
396 bt_value_array_get_size(object_b
));
401 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
402 const struct bt_value
*element_obj_a
;
403 const struct bt_value
*element_obj_b
;
405 element_obj_a
= bt_value_array_borrow_element_by_index_const(
407 element_obj_b
= bt_value_array_borrow_element_by_index_const(
410 if (!bt_value_compare(element_obj_a
, element_obj_b
)) {
411 BT_LOGT("Array values's elements are different: "
412 "value-a-addr=%p, value-b-addr=%p, index=%d",
413 element_obj_a
, element_obj_b
, i
);
424 bt_bool
bt_value_map_compare(const struct bt_value
*object_a
,
425 const struct bt_value
*object_b
)
427 bt_bool ret
= BT_TRUE
;
429 gpointer key
, element_obj_a
;
430 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
432 if (bt_value_map_get_size(object_a
) !=
433 bt_value_map_get_size(object_b
)) {
434 BT_LOGT("Map values are different: size mismatch "
435 "value-a-addr=%p, value-b-addr=%p, "
436 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
438 bt_value_map_get_size(object_a
),
439 bt_value_map_get_size(object_b
));
444 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
446 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
447 const struct bt_value
*element_obj_b
;
448 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
450 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
453 if (!bt_value_compare(element_obj_a
, element_obj_b
)) {
454 BT_LOGT("Map values's elements are different: "
455 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
456 element_obj_a
, element_obj_b
, key_str
);
467 bt_bool (* const compare_funcs
[])(const struct bt_value
*,
468 const struct bt_value
*) = {
469 [BT_VALUE_TYPE_NULL
] = bt_value_null_compare
,
470 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_compare
,
471 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_compare
,
472 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_compare
,
473 [BT_VALUE_TYPE_REAL
] = bt_value_real_compare
,
474 [BT_VALUE_TYPE_STRING
] = bt_value_string_compare
,
475 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_compare
,
476 [BT_VALUE_TYPE_MAP
] = bt_value_map_compare
,
480 void bt_value_null_freeze(struct bt_value
*object
)
485 void bt_value_generic_freeze(struct bt_value
*object
)
487 object
->frozen
= BT_TRUE
;
491 void bt_value_array_freeze(struct bt_value
*object
)
494 struct bt_value_array
*typed_array_obj
=
495 BT_VALUE_TO_ARRAY(object
);
497 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
498 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
501 bt_value_generic_freeze(object
);
505 void bt_value_map_freeze(struct bt_value
*object
)
508 gpointer key
, element_obj
;
509 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
511 g_hash_table_iter_init(&iter
, map_obj
->ght
);
513 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
514 bt_value_freeze(element_obj
);
517 bt_value_generic_freeze(object
);
521 void (* const freeze_funcs
[])(struct bt_value
*) = {
522 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
523 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
524 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
525 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
526 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
527 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
528 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
529 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
533 void bt_value_destroy(struct bt_object
*obj
)
535 struct bt_value
*value
;
537 value
= container_of(obj
, struct bt_value
, base
);
538 BT_LOGD("Destroying value: addr=%p", value
);
540 if (bt_value_is_null(value
)) {
541 BT_LOGD_STR("Not destroying the null value singleton.");
545 if (destroy_funcs
[value
->type
]) {
546 destroy_funcs
[value
->type
](value
);
553 void _bt_value_freeze(const struct bt_value
*c_object
)
555 const struct bt_value
*object
= (void *) c_object
;
559 if (object
->frozen
) {
563 BT_LOGD("Freezing value: addr=%p", object
);
564 freeze_funcs
[object
->type
]((void *) object
);
570 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
572 BT_ASSERT_PRE_DEV_NON_NULL(object
, "Value object");
577 struct bt_value
bt_value_create_base(enum bt_value_type type
)
579 struct bt_value value
;
582 value
.frozen
= BT_FALSE
;
583 bt_object_init_shared(&value
.base
, bt_value_destroy
);
587 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
589 struct bt_value_bool
*bool_obj
;
591 BT_LOGD("Creating boolean value object: val=%d", val
);
592 bool_obj
= g_new0(struct bt_value_bool
, 1);
594 BT_LIB_LOGE_APPEND_CAUSE(
595 "Failed to allocate one boolean value object.");
599 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
600 bool_obj
->value
= val
;
601 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
604 return (void *) bool_obj
;
607 struct bt_value
*bt_value_bool_create(void)
609 return bt_value_bool_create_init(BT_FALSE
);
613 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
616 struct bt_value_integer
*integer_obj
;
618 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
619 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
621 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
622 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
625 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
629 integer_obj
= g_new0(struct bt_value_integer
, 1);
631 BT_LIB_LOGE_APPEND_CAUSE(
632 "Failed to allocate one integer value object.");
636 integer_obj
->base
= bt_value_create_base(type
);
637 integer_obj
->value
.u
= uval
;
638 BT_LOGD("Created %ssigned integer value object: addr=%p",
639 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
643 return (void *) integer_obj
;
646 struct bt_value
*bt_value_integer_unsigned_create_init(uint64_t val
)
648 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
652 struct bt_value
*bt_value_integer_unsigned_create(void)
654 return bt_value_integer_unsigned_create_init(0);
657 struct bt_value
*bt_value_integer_signed_create_init(int64_t val
)
659 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
663 struct bt_value
*bt_value_integer_signed_create(void)
665 return bt_value_integer_signed_create_init(0);
668 struct bt_value
*bt_value_real_create_init(double val
)
670 struct bt_value_real
*real_obj
;
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 return bt_value_real_create_init(0.);
694 struct bt_value
*bt_value_string_create_init(const char *val
)
696 struct bt_value_string
*string_obj
= NULL
;
698 BT_ASSERT_PRE_NON_NULL(val
, "Value");
699 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
700 string_obj
= g_new0(struct bt_value_string
, 1);
702 BT_LIB_LOGE_APPEND_CAUSE(
703 "Failed to allocate one string object.");
707 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
708 string_obj
->gstr
= g_string_new(val
);
709 if (!string_obj
->gstr
) {
710 BT_LIB_LOGE_APPEND_CAUSE(
711 "Failed to allocate a GString.");
717 BT_LOGD("Created string value object: addr=%p",
721 return (void *) string_obj
;
724 struct bt_value
*bt_value_string_create(void)
726 return bt_value_string_create_init("");
729 struct bt_value
*bt_value_array_create(void)
731 struct bt_value_array
*array_obj
;
733 BT_LOGD_STR("Creating empty array value object.");
734 array_obj
= g_new0(struct bt_value_array
, 1);
736 BT_LIB_LOGE_APPEND_CAUSE(
737 "Failed to allocate one array object.");
741 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
742 array_obj
->garray
= bt_g_ptr_array_new_full(0,
743 (GDestroyNotify
) bt_object_put_ref
);
744 if (!array_obj
->garray
) {
745 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
751 BT_LOGD("Created array value object: addr=%p",
755 return (void *) array_obj
;
758 struct bt_value
*bt_value_map_create(void)
760 struct bt_value_map
*map_obj
;
762 BT_LOGD_STR("Creating empty map value object.");
763 map_obj
= g_new0(struct bt_value_map
, 1);
765 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
769 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
770 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
771 NULL
, (GDestroyNotify
) bt_object_put_ref
);
773 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
779 BT_LOGD("Created map value object: addr=%p",
783 return (void *) map_obj
;
786 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
788 BT_ASSERT_PRE_DEV_NON_NULL(bool_obj
, "Value object");
789 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
790 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
793 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
795 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
796 BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
797 BT_ASSERT_PRE_DEV_VALUE_HOT(bool_obj
, "Value object");
798 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
799 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
803 uint64_t bt_value_integer_unsigned_get(const struct bt_value
*integer_obj
)
805 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
806 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
807 BT_VALUE_TYPE_UNSIGNED_INTEGER
);
808 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
811 int64_t bt_value_integer_signed_get(const struct bt_value
*integer_obj
)
813 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
814 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
815 BT_VALUE_TYPE_SIGNED_INTEGER
);
816 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
820 void bt_value_integer_set(struct bt_value
*integer_obj
,
821 enum bt_value_type expected_type
, uint64_t uval
)
823 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
824 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, expected_type
);
825 BT_ASSERT_PRE_DEV_VALUE_HOT(integer_obj
, "Value object");
826 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
829 void bt_value_integer_unsigned_set(struct bt_value
*integer_obj
,
832 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
);
833 BT_LOGT("Set unsigned integer value's raw value: "
834 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
837 void bt_value_integer_signed_set(struct bt_value
*integer_obj
,
840 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
842 BT_LOGT("Set signed integer value's raw value: "
843 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
846 double bt_value_real_get(const struct bt_value
*real_obj
)
848 BT_ASSERT_PRE_DEV_NON_NULL(real_obj
, "Value object");
849 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
850 return BT_VALUE_TO_REAL(real_obj
)->value
;
853 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
855 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
856 BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
857 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
, "Value object");
858 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
859 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
863 const char *bt_value_string_get(const struct bt_value
*string_obj
)
865 BT_ASSERT_PRE_DEV_NON_NULL(string_obj
, "Value object");
866 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
867 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
870 enum bt_value_string_set_status
bt_value_string_set(
871 struct bt_value
*string_obj
, const char *val
)
873 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
874 BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
875 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
, "Value object");
876 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
877 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
879 return BT_FUNC_STATUS_OK
;
882 uint64_t bt_value_array_get_size(const struct bt_value
*array_obj
)
884 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
885 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
886 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
889 struct bt_value
*bt_value_array_borrow_element_by_index(
890 struct bt_value
*array_obj
, uint64_t index
)
892 struct bt_value_array
*typed_array_obj
=
893 BT_VALUE_TO_ARRAY(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 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
898 return g_ptr_array_index(typed_array_obj
->garray
, index
);
901 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
902 const struct bt_value
*array_obj
,
905 return bt_value_array_borrow_element_by_index(
906 (void *) array_obj
, index
);
909 enum bt_value_array_append_element_status
bt_value_array_append_element(
910 struct bt_value
*array_obj
,
911 struct bt_value
*element_obj
)
913 struct bt_value_array
*typed_array_obj
=
914 BT_VALUE_TO_ARRAY(array_obj
);
916 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
917 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
918 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
919 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
920 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
921 bt_object_get_ref(element_obj
);
922 BT_LOGT("Appended element to array value: array-value-addr=%p, "
923 "element-value-addr=%p, new-size=%u",
924 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
925 return BT_FUNC_STATUS_OK
;
928 enum bt_value_array_append_element_status
929 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
931 enum bt_value_array_append_element_status ret
;
932 struct bt_value
*bool_obj
= NULL
;
934 bool_obj
= bt_value_bool_create_init(val
);
935 ret
= bt_value_array_append_element(array_obj
,
937 bt_object_put_ref(bool_obj
);
941 enum bt_value_array_append_element_status
942 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
945 enum bt_value_array_append_element_status ret
;
946 struct bt_value
*integer_obj
= NULL
;
948 integer_obj
= bt_value_integer_unsigned_create_init(val
);
949 ret
= bt_value_array_append_element(array_obj
,
950 (void *) integer_obj
);
951 bt_object_put_ref(integer_obj
);
955 enum bt_value_array_append_element_status
956 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
959 enum bt_value_array_append_element_status ret
;
960 struct bt_value
*integer_obj
= NULL
;
962 integer_obj
= bt_value_integer_signed_create_init(val
);
963 ret
= bt_value_array_append_element(array_obj
,
964 (void *) integer_obj
);
965 bt_object_put_ref(integer_obj
);
969 enum bt_value_array_append_element_status
970 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
972 enum bt_value_array_append_element_status ret
;
973 struct bt_value
*real_obj
= NULL
;
975 real_obj
= bt_value_real_create_init(val
);
976 ret
= bt_value_array_append_element(array_obj
,
978 bt_object_put_ref(real_obj
);
982 enum bt_value_array_append_element_status
983 bt_value_array_append_string_element(struct bt_value
*array_obj
,
986 enum bt_value_array_append_element_status ret
;
987 struct bt_value
*string_obj
= NULL
;
989 string_obj
= bt_value_string_create_init(val
);
990 ret
= bt_value_array_append_element(array_obj
,
991 (void *) string_obj
);
992 bt_object_put_ref(string_obj
);
996 enum bt_value_array_append_element_status
997 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
)
999 enum bt_value_array_append_element_status ret
;
1000 struct bt_value
*empty_array_obj
= NULL
;
1002 empty_array_obj
= bt_value_array_create();
1003 ret
= bt_value_array_append_element(array_obj
,
1004 (void *) empty_array_obj
);
1005 bt_object_put_ref(empty_array_obj
);
1009 enum bt_value_array_append_element_status
1010 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
)
1012 enum bt_value_array_append_element_status ret
;
1013 struct bt_value
*map_obj
= NULL
;
1015 map_obj
= bt_value_map_create();
1016 ret
= bt_value_array_append_element(array_obj
,
1018 bt_object_put_ref(map_obj
);
1022 enum bt_value_array_set_element_by_index_status
1023 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1024 struct bt_value
*element_obj
)
1026 struct bt_value_array
*typed_array_obj
=
1027 BT_VALUE_TO_ARRAY(array_obj
);
1029 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1030 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1031 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
1032 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
1033 BT_ASSERT_PRE_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
1034 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1035 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1036 bt_object_get_ref(element_obj
);
1037 BT_LOGT("Set array value's element: array-value-addr=%p, "
1038 "index=%" PRIu64
", element-value-addr=%p",
1039 array_obj
, index
, element_obj
);
1040 return BT_FUNC_STATUS_OK
;
1043 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1045 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1046 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1047 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1050 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1053 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1054 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1055 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1056 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1057 GUINT_TO_POINTER(g_quark_from_string(key
)));
1060 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1061 const struct bt_value
*map_obj
, const char *key
)
1063 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1066 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1068 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1069 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1070 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1071 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1072 GUINT_TO_POINTER(g_quark_from_string(key
)));
1075 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1076 struct bt_value
*map_obj
, const char *key
,
1077 struct bt_value
*element_obj
)
1079 BT_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1080 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1081 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1082 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1083 BT_ASSERT_PRE_DEV_VALUE_HOT(map_obj
, "Map value object");
1084 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1085 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1086 bt_object_get_ref(element_obj
);
1087 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1088 "key=\"%s\", element-value-addr=%p",
1089 map_obj
, key
, element_obj
);
1090 return BT_FUNC_STATUS_OK
;
1093 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1094 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1096 enum bt_value_map_insert_entry_status ret
;
1097 struct bt_value
*bool_obj
= NULL
;
1099 bool_obj
= bt_value_bool_create_init(val
);
1100 ret
= bt_value_map_insert_entry(map_obj
, key
,
1102 bt_object_put_ref(bool_obj
);
1106 enum bt_value_map_insert_entry_status
1107 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1108 const char *key
, uint64_t val
)
1110 enum bt_value_map_insert_entry_status ret
;
1111 struct bt_value
*integer_obj
= NULL
;
1113 integer_obj
= bt_value_integer_unsigned_create_init(val
);
1114 ret
= bt_value_map_insert_entry(map_obj
, key
,
1115 (void *) integer_obj
);
1116 bt_object_put_ref(integer_obj
);
1120 enum bt_value_map_insert_entry_status
1121 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1122 const char *key
, int64_t val
)
1124 enum bt_value_map_insert_entry_status ret
;
1125 struct bt_value
*integer_obj
= NULL
;
1127 integer_obj
= bt_value_integer_signed_create_init(val
);
1128 ret
= bt_value_map_insert_entry(map_obj
, key
,
1129 (void *) integer_obj
);
1130 bt_object_put_ref(integer_obj
);
1134 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1135 struct bt_value
*map_obj
, const char *key
, double val
)
1137 enum bt_value_map_insert_entry_status ret
;
1138 struct bt_value
*real_obj
= NULL
;
1140 real_obj
= bt_value_real_create_init(val
);
1141 ret
= bt_value_map_insert_entry(map_obj
, key
,
1143 bt_object_put_ref(real_obj
);
1147 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1148 struct bt_value
*map_obj
, const char *key
,
1151 enum bt_value_map_insert_entry_status ret
;
1152 struct bt_value
*string_obj
= NULL
;
1154 string_obj
= bt_value_string_create_init(val
);
1155 ret
= bt_value_map_insert_entry(map_obj
, key
,
1156 (void *) string_obj
);
1157 bt_object_put_ref(string_obj
);
1161 enum bt_value_map_insert_entry_status
1162 bt_value_map_insert_empty_array_entry(
1163 struct bt_value
*map_obj
, const char *key
)
1165 enum bt_value_map_insert_entry_status ret
;
1166 struct bt_value
*array_obj
= NULL
;
1168 array_obj
= bt_value_array_create();
1169 ret
= bt_value_map_insert_entry(map_obj
, key
,
1170 (void *) array_obj
);
1171 bt_object_put_ref(array_obj
);
1175 enum bt_value_map_insert_entry_status
1176 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
)
1178 enum bt_value_map_insert_entry_status ret
;
1179 struct bt_value
*empty_map_obj
= NULL
;
1181 empty_map_obj
= bt_value_map_create();
1182 ret
= bt_value_map_insert_entry(map_obj
, key
,
1183 (void *) empty_map_obj
);
1184 bt_object_put_ref(empty_map_obj
);
1188 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1189 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1192 enum bt_value_map_foreach_entry_status ret
= BT_FUNC_STATUS_OK
;
1193 gpointer key
, element_obj
;
1194 GHashTableIter iter
;
1195 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1197 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1198 BT_ASSERT_PRE_DEV_NON_NULL(func
, "Callback");
1199 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1200 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1202 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1203 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1205 if (!func(key_str
, element_obj
, data
)) {
1206 BT_LOGT("User interrupted the loop: key=\"%s\", "
1207 "value-addr=%p, data=%p",
1208 key_str
, element_obj
, data
);
1209 ret
= BT_FUNC_STATUS_INTERRUPTED
;
1217 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1218 const struct bt_value
*map_obj
,
1219 bt_value_map_foreach_entry_const_func func
, void *data
)
1221 return (int) bt_value_map_foreach_entry((void *) map_obj
,
1222 (bt_value_map_foreach_entry_func
) func
, data
);
1225 struct extend_map_element_data
{
1226 struct bt_value
*extended_obj
;
1231 bt_bool
extend_map_element(const char *key
,
1232 const struct bt_value
*extension_obj_elem
, void *data
)
1234 bt_bool ret
= BT_TRUE
;
1235 struct extend_map_element_data
*extend_data
= data
;
1236 struct bt_value
*extension_obj_elem_copy
= NULL
;
1238 /* Copy object which is to replace the current one */
1239 extend_data
->status
= bt_value_copy(extension_obj_elem
,
1240 &extension_obj_elem_copy
);
1241 if (extend_data
->status
) {
1242 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1243 extension_obj_elem
);
1247 BT_ASSERT(extension_obj_elem_copy
);
1249 /* Replace in extended object */
1250 extend_data
->status
= bt_value_map_insert_entry(
1251 extend_data
->extended_obj
, key
,
1252 (void *) extension_obj_elem_copy
);
1253 if (extend_data
->status
) {
1254 BT_LIB_LOGE_APPEND_CAUSE(
1255 "Cannot replace value in extended value: key=\"%s\", "
1256 "%![extended-value-]+v, %![element-value-]+v",
1257 key
, extend_data
->extended_obj
,
1258 extension_obj_elem_copy
);
1265 BT_ASSERT(extend_data
->status
!= BT_FUNC_STATUS_OK
);
1269 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1273 enum bt_value_map_extend_status
bt_value_map_extend(
1274 const struct bt_value
*base_map_obj
,
1275 const struct bt_value
*extension_obj
,
1276 struct bt_value
**extended_map_obj
)
1278 struct extend_map_element_data extend_data
= {
1279 .extended_obj
= NULL
,
1280 .status
= BT_FUNC_STATUS_OK
,
1283 BT_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1284 BT_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1285 BT_ASSERT_PRE_NON_NULL(extended_map_obj
,
1286 "Extended value object (output)");
1287 BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_VALUE_TYPE_MAP
);
1288 BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_VALUE_TYPE_MAP
);
1289 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1290 base_map_obj
, extension_obj
);
1291 *extended_map_obj
= NULL
;
1293 /* Create copy of base map object to start with */
1294 extend_data
.status
= bt_value_copy(base_map_obj
, extended_map_obj
);
1295 if (extend_data
.status
) {
1296 BT_LIB_LOGE_APPEND_CAUSE(
1297 "Cannot copy base value: %![base-value-]+v",
1302 BT_ASSERT(extended_map_obj
);
1305 * For each key in the extension map object, replace this key
1306 * in the copied map object.
1308 extend_data
.extended_obj
= *extended_map_obj
;
1310 if (bt_value_map_foreach_entry_const(extension_obj
, extend_map_element
,
1312 BT_LIB_LOGE_APPEND_CAUSE(
1313 "Cannot iterate on the extension object's elements: "
1314 "%![extension-value-]+v", extension_obj
);
1318 if (extend_data
.status
) {
1319 BT_LIB_LOGE_APPEND_CAUSE(
1320 "Failed to successfully iterate on the extension object's elements: "
1321 "%![extension-value-]+v", extension_obj
);
1325 BT_LOGD("Extended map value: extended-value-addr=%p",
1330 BT_OBJECT_PUT_REF_AND_RESET(*extended_map_obj
);
1331 *extended_map_obj
= NULL
;
1334 return extend_data
.status
;
1337 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1338 struct bt_value
**copy_obj
)
1340 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1342 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
1343 BT_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1344 BT_LOGD("Copying value object: addr=%p", object
);
1345 *copy_obj
= copy_funcs
[object
->type
](object
);
1347 BT_LOGD("Copied value object: copy-value-addr=%p",
1350 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1352 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1358 bt_bool
bt_value_compare(const struct bt_value
*object_a
,
1359 const struct bt_value
*object_b
)
1361 bt_bool ret
= BT_FALSE
;
1363 BT_ASSERT_PRE_DEV_NON_NULL(object_a
, "Value object A");
1364 BT_ASSERT_PRE_DEV_NON_NULL(object_b
, "Value object B");
1366 if (object_a
->type
!= object_b
->type
) {
1367 BT_LOGT("Values are different: type mismatch: "
1368 "value-a-addr=%p, value-b-addr=%p, "
1369 "value-a-type=%s, value-b-type=%s",
1371 bt_common_value_type_string(object_a
->type
),
1372 bt_common_value_type_string(object_b
->type
));
1376 ret
= compare_funcs
[object_a
->type
](object_a
, object_b
);
1382 void bt_value_get_ref(const struct bt_value
*value
)
1384 bt_object_get_ref(value
);
1387 void bt_value_put_ref(const struct bt_value
*value
)
1389 bt_object_put_ref(value
);