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 "compat/compiler.h"
31 #include "common/common.h"
32 #include <babeltrace2/value-const.h>
33 #include <babeltrace2/value.h>
34 #include "compat/glib.h"
35 #include <babeltrace2/types.h>
36 #include "lib/assert-pre.h"
37 #include "lib/value.h"
38 #include "common/assert.h"
39 #include "func-status.h"
41 #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
42 #define BT_VALUE_TO_INTEGER(_base) ((struct bt_value_integer *) (_base))
43 #define BT_VALUE_TO_REAL(_base) ((struct bt_value_real *) (_base))
44 #define BT_VALUE_TO_STRING(_base) ((struct bt_value_string *) (_base))
45 #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base))
46 #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
48 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_COND(_value, _type) \
49 (((struct bt_value *) (_value))->type == (_type))
51 #define _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT \
52 "Value has the wrong type ID: expected-type=%s, %![value-]+v"
54 #define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
56 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
57 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
58 bt_common_value_type_string(_type), (_value))
60 #define BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(_value, _type) \
62 _BT_ASSERT_PRE_VALUE_IS_TYPE_COND((_value), (_type)), \
63 _BT_ASSERT_PRE_VALUE_IS_TYPE_FMT, \
64 bt_common_value_type_string(_type), (_value))
66 #define BT_ASSERT_PRE_DEV_VALUE_HOT(_value, _name) \
67 BT_ASSERT_PRE_DEV_HOT(((struct bt_value *) (_value)), (_name), \
71 void bt_value_null_instance_release_func(struct bt_object
*obj
)
73 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
77 struct bt_value bt_value_null_instance
= {
81 .release_func
= bt_value_null_instance_release_func
,
82 .spec_release_func
= NULL
,
83 .parent_is_owner_listener_func
= NULL
,
86 .type
= BT_VALUE_TYPE_NULL
,
90 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
93 void bt_value_destroy(struct bt_object
*obj
);
96 void bt_value_string_destroy(struct bt_value
*object
)
98 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
99 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
103 void bt_value_array_destroy(struct bt_value
*object
)
106 * Pointer array's registered value destructor will take care
107 * of putting each contained object.
109 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
110 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
114 void bt_value_map_destroy(struct bt_value
*object
)
117 * Hash table's registered value destructor will take care of
118 * putting each contained object. Keys are GQuarks and cannot
119 * be destroyed anyway.
121 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
122 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
126 void (* const destroy_funcs
[])(struct bt_value
*) = {
127 [BT_VALUE_TYPE_NULL
] = NULL
,
128 [BT_VALUE_TYPE_BOOL
] = NULL
,
129 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
130 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
131 [BT_VALUE_TYPE_REAL
] = NULL
,
132 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
133 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
134 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
138 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
140 return (void *) bt_value_null
;
144 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
146 return bt_value_bool_create_init(
147 BT_VALUE_TO_BOOL(bool_obj
)->value
);
151 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
155 struct bt_value
*bt_value_integer_copy(
156 const struct bt_value
*integer_obj
)
158 return bt_value_integer_create_init(integer_obj
->type
,
159 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
163 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
165 return bt_value_real_create_init(
166 BT_VALUE_TO_REAL(real_obj
)->value
);
170 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
172 return bt_value_string_create_init(
173 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
177 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
181 struct bt_value
*copy_obj
;
182 struct bt_value_array
*typed_array_obj
;
184 BT_LOGD("Copying array value: addr=%p", array_obj
);
185 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
186 copy_obj
= bt_value_array_create();
188 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
192 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
193 struct bt_value
*element_obj_copy
= NULL
;
194 const struct bt_value
*element_obj
=
195 bt_value_array_borrow_element_by_index_const(
198 BT_ASSERT(element_obj
);
199 BT_LOGD("Copying array value's element: element-addr=%p, "
200 "index=%d", element_obj
, i
);
201 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
203 BT_LIB_LOGE_APPEND_CAUSE(
204 "Cannot copy array value's element: "
205 "array-addr=%p, index=%d",
207 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
211 BT_ASSERT(element_obj_copy
);
212 ret
= bt_value_array_append_element(copy_obj
,
213 (void *) element_obj_copy
);
214 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
216 BT_LIB_LOGE_APPEND_CAUSE(
217 "Cannot append to array value: addr=%p",
219 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
224 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
225 array_obj
, copy_obj
);
232 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
236 gpointer key
, element_obj
;
237 struct bt_value
*copy_obj
;
238 struct bt_value
*element_obj_copy
= NULL
;
239 struct bt_value_map
*typed_map_obj
;
241 BT_LOGD("Copying map value: addr=%p", map_obj
);
242 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
243 copy_obj
= bt_value_map_create();
248 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
250 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
251 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
254 BT_LOGD("Copying map value's element: element-addr=%p, "
255 "key=\"%s\"", element_obj
, key_str
);
256 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
258 BT_LIB_LOGE_APPEND_CAUSE(
259 "Cannot copy map value's element: "
260 "map-addr=%p, key=\"%s\"",
262 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
266 BT_ASSERT(element_obj_copy
);
267 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
268 (void *) element_obj_copy
);
269 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
271 BT_LIB_LOGE_APPEND_CAUSE(
272 "Cannot insert into map value: addr=%p, key=\"%s\"",
274 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
279 BT_LOGD("Copied map value: addr=%p", map_obj
);
286 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
287 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
288 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
289 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
290 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
291 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
292 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
293 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
294 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
298 bt_bool
bt_value_null_compare(const struct bt_value
*object_a
,
299 const struct bt_value
*object_b
)
302 * Always BT_TRUE since bt_value_compare() already checks if both
303 * object_a and object_b have the same type, and in the case of
304 * null value objects, they're always the same if it is so.
310 bt_bool
bt_value_bool_compare(const struct bt_value
*object_a
,
311 const struct bt_value
*object_b
)
313 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
314 BT_VALUE_TO_BOOL(object_b
)->value
) {
315 BT_LOGT("Boolean value objects are different: "
316 "bool-a-val=%d, bool-b-val=%d",
317 BT_VALUE_TO_BOOL(object_a
)->value
,
318 BT_VALUE_TO_BOOL(object_b
)->value
);
326 bt_bool
bt_value_integer_compare(const struct bt_value
*object_a
,
327 const struct bt_value
*object_b
)
329 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
330 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
331 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
332 BT_LOGT("Unsigned integer value objects are different: "
333 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
334 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
335 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
337 BT_LOGT("Signed integer value objects are different: "
338 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
339 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
340 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
350 bt_bool
bt_value_real_compare(const struct bt_value
*object_a
,
351 const struct bt_value
*object_b
)
353 if (BT_VALUE_TO_REAL(object_a
)->value
!=
354 BT_VALUE_TO_REAL(object_b
)->value
) {
355 BT_LOGT("Real number value objects are different: "
356 "real-a-val=%f, real-b-val=%f",
357 BT_VALUE_TO_REAL(object_a
)->value
,
358 BT_VALUE_TO_REAL(object_b
)->value
);
366 bt_bool
bt_value_string_compare(const struct bt_value
*object_a
,
367 const struct bt_value
*object_b
)
369 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
370 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
371 BT_LOGT("String value objects are different: "
372 "string-a-val=\"%s\", string-b-val=\"%s\"",
373 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
374 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
382 bt_bool
bt_value_array_compare(const struct bt_value
*object_a
,
383 const struct bt_value
*object_b
)
386 bt_bool ret
= BT_TRUE
;
387 const struct bt_value_array
*array_obj_a
=
388 BT_VALUE_TO_ARRAY(object_a
);
390 if (bt_value_array_get_size(object_a
) !=
391 bt_value_array_get_size(object_b
)) {
392 BT_LOGT("Array values are different: size mismatch "
393 "value-a-addr=%p, value-b-addr=%p, "
394 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
396 bt_value_array_get_size(object_a
),
397 bt_value_array_get_size(object_b
));
402 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
403 const struct bt_value
*element_obj_a
;
404 const struct bt_value
*element_obj_b
;
406 element_obj_a
= bt_value_array_borrow_element_by_index_const(
408 element_obj_b
= bt_value_array_borrow_element_by_index_const(
411 if (!bt_value_compare(element_obj_a
, element_obj_b
)) {
412 BT_LOGT("Array values's elements are different: "
413 "value-a-addr=%p, value-b-addr=%p, index=%d",
414 element_obj_a
, element_obj_b
, i
);
425 bt_bool
bt_value_map_compare(const struct bt_value
*object_a
,
426 const struct bt_value
*object_b
)
428 bt_bool ret
= BT_TRUE
;
430 gpointer key
, element_obj_a
;
431 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
433 if (bt_value_map_get_size(object_a
) !=
434 bt_value_map_get_size(object_b
)) {
435 BT_LOGT("Map values are different: size mismatch "
436 "value-a-addr=%p, value-b-addr=%p, "
437 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
439 bt_value_map_get_size(object_a
),
440 bt_value_map_get_size(object_b
));
445 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
447 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
448 const struct bt_value
*element_obj_b
;
449 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
451 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
454 if (!bt_value_compare(element_obj_a
, element_obj_b
)) {
455 BT_LOGT("Map values's elements are different: "
456 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
457 element_obj_a
, element_obj_b
, key_str
);
468 bt_bool (* const compare_funcs
[])(const struct bt_value
*,
469 const struct bt_value
*) = {
470 [BT_VALUE_TYPE_NULL
] = bt_value_null_compare
,
471 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_compare
,
472 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_compare
,
473 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_compare
,
474 [BT_VALUE_TYPE_REAL
] = bt_value_real_compare
,
475 [BT_VALUE_TYPE_STRING
] = bt_value_string_compare
,
476 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_compare
,
477 [BT_VALUE_TYPE_MAP
] = bt_value_map_compare
,
481 void bt_value_null_freeze(struct bt_value
*object
)
486 void bt_value_generic_freeze(struct bt_value
*object
)
488 object
->frozen
= BT_TRUE
;
492 void bt_value_array_freeze(struct bt_value
*object
)
495 struct bt_value_array
*typed_array_obj
=
496 BT_VALUE_TO_ARRAY(object
);
498 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
499 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
502 bt_value_generic_freeze(object
);
506 void bt_value_map_freeze(struct bt_value
*object
)
509 gpointer key
, element_obj
;
510 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
512 g_hash_table_iter_init(&iter
, map_obj
->ght
);
514 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
515 bt_value_freeze(element_obj
);
518 bt_value_generic_freeze(object
);
522 void (* const freeze_funcs
[])(struct bt_value
*) = {
523 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
524 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
525 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
526 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
527 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
528 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
529 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
530 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
534 void bt_value_destroy(struct bt_object
*obj
)
536 struct bt_value
*value
;
538 value
= container_of(obj
, struct bt_value
, base
);
539 BT_LOGD("Destroying value: addr=%p", value
);
541 if (bt_value_is_null(value
)) {
542 BT_LOGD_STR("Not destroying the null value singleton.");
546 if (destroy_funcs
[value
->type
]) {
547 destroy_funcs
[value
->type
](value
);
554 void _bt_value_freeze(const struct bt_value
*c_object
)
556 const struct bt_value
*object
= (void *) c_object
;
560 if (object
->frozen
) {
564 BT_LOGD("Freezing value: addr=%p", object
);
565 freeze_funcs
[object
->type
]((void *) object
);
571 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
573 BT_ASSERT_PRE_DEV_NON_NULL(object
, "Value object");
578 struct bt_value
bt_value_create_base(enum bt_value_type type
)
580 struct bt_value value
;
583 value
.frozen
= BT_FALSE
;
584 bt_object_init_shared(&value
.base
, bt_value_destroy
);
588 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
590 struct bt_value_bool
*bool_obj
;
592 BT_LOGD("Creating boolean value object: val=%d", val
);
593 bool_obj
= g_new0(struct bt_value_bool
, 1);
595 BT_LIB_LOGE_APPEND_CAUSE(
596 "Failed to allocate one boolean value object.");
600 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
601 bool_obj
->value
= val
;
602 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
605 return (void *) bool_obj
;
608 struct bt_value
*bt_value_bool_create(void)
610 return bt_value_bool_create_init(BT_FALSE
);
614 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
617 struct bt_value_integer
*integer_obj
;
619 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
620 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
622 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
623 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
626 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
630 integer_obj
= g_new0(struct bt_value_integer
, 1);
632 BT_LIB_LOGE_APPEND_CAUSE(
633 "Failed to allocate one integer value object.");
637 integer_obj
->base
= bt_value_create_base(type
);
638 integer_obj
->value
.u
= uval
;
639 BT_LOGD("Created %ssigned integer value object: addr=%p",
640 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
644 return (void *) integer_obj
;
647 struct bt_value
*bt_value_unsigned_integer_create_init(uint64_t val
)
649 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
653 struct bt_value
*bt_value_unsigned_integer_create(void)
655 return bt_value_unsigned_integer_create_init(0);
658 struct bt_value
*bt_value_signed_integer_create_init(int64_t val
)
660 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
664 struct bt_value
*bt_value_signed_integer_create(void)
666 return bt_value_signed_integer_create_init(0);
669 struct bt_value
*bt_value_real_create_init(double val
)
671 struct bt_value_real
*real_obj
;
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 return bt_value_real_create_init(0.);
695 struct bt_value
*bt_value_string_create_init(const char *val
)
697 struct bt_value_string
*string_obj
= NULL
;
699 BT_ASSERT_PRE_NON_NULL(val
, "Value");
700 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
701 string_obj
= g_new0(struct bt_value_string
, 1);
703 BT_LIB_LOGE_APPEND_CAUSE(
704 "Failed to allocate one string object.");
708 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
709 string_obj
->gstr
= g_string_new(val
);
710 if (!string_obj
->gstr
) {
711 BT_LIB_LOGE_APPEND_CAUSE(
712 "Failed to allocate a GString.");
718 BT_LOGD("Created string value object: addr=%p",
722 return (void *) string_obj
;
725 struct bt_value
*bt_value_string_create(void)
727 return bt_value_string_create_init("");
730 struct bt_value
*bt_value_array_create(void)
732 struct bt_value_array
*array_obj
;
734 BT_LOGD_STR("Creating empty array value object.");
735 array_obj
= g_new0(struct bt_value_array
, 1);
737 BT_LIB_LOGE_APPEND_CAUSE(
738 "Failed to allocate one array object.");
742 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
743 array_obj
->garray
= bt_g_ptr_array_new_full(0,
744 (GDestroyNotify
) bt_object_put_ref
);
745 if (!array_obj
->garray
) {
746 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
752 BT_LOGD("Created array value object: addr=%p",
756 return (void *) array_obj
;
759 struct bt_value
*bt_value_map_create(void)
761 struct bt_value_map
*map_obj
;
763 BT_LOGD_STR("Creating empty map value object.");
764 map_obj
= g_new0(struct bt_value_map
, 1);
766 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
770 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
771 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
772 NULL
, (GDestroyNotify
) bt_object_put_ref
);
774 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
780 BT_LOGD("Created map value object: addr=%p",
784 return (void *) map_obj
;
787 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
789 BT_ASSERT_PRE_DEV_NON_NULL(bool_obj
, "Value object");
790 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
791 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
794 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
796 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
797 BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
798 BT_ASSERT_PRE_DEV_VALUE_HOT(bool_obj
, "Value object");
799 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
800 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
804 uint64_t bt_value_unsigned_integer_get(const struct bt_value
*integer_obj
)
806 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
807 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
808 BT_VALUE_TYPE_UNSIGNED_INTEGER
);
809 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
812 int64_t bt_value_signed_integer_get(const struct bt_value
*integer_obj
)
814 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
815 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
816 BT_VALUE_TYPE_SIGNED_INTEGER
);
817 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
821 void bt_value_integer_set(struct bt_value
*integer_obj
,
822 enum bt_value_type expected_type
, uint64_t uval
)
824 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
825 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, expected_type
);
826 BT_ASSERT_PRE_DEV_VALUE_HOT(integer_obj
, "Value object");
827 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
830 void bt_value_unsigned_integer_set(struct bt_value
*integer_obj
,
833 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
);
834 BT_LOGT("Set unsigned integer value's raw value: "
835 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
838 void bt_value_signed_integer_set(struct bt_value
*integer_obj
,
841 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
843 BT_LOGT("Set signed integer value's raw value: "
844 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
847 double bt_value_real_get(const struct bt_value
*real_obj
)
849 BT_ASSERT_PRE_DEV_NON_NULL(real_obj
, "Value object");
850 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
851 return BT_VALUE_TO_REAL(real_obj
)->value
;
854 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
856 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
857 BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
858 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
, "Value object");
859 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
860 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
864 const char *bt_value_string_get(const struct bt_value
*string_obj
)
866 BT_ASSERT_PRE_DEV_NON_NULL(string_obj
, "Value object");
867 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
868 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
871 enum bt_value_string_set_status
bt_value_string_set(
872 struct bt_value
*string_obj
, const char *val
)
874 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
875 BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
876 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
, "Value object");
877 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
878 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
880 return BT_FUNC_STATUS_OK
;
883 uint64_t bt_value_array_get_size(const struct bt_value
*array_obj
)
885 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
886 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
887 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
890 struct bt_value
*bt_value_array_borrow_element_by_index(
891 struct bt_value
*array_obj
, uint64_t index
)
893 struct bt_value_array
*typed_array_obj
=
894 BT_VALUE_TO_ARRAY(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 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
899 return g_ptr_array_index(typed_array_obj
->garray
, index
);
902 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
903 const struct bt_value
*array_obj
,
906 return bt_value_array_borrow_element_by_index(
907 (void *) array_obj
, index
);
910 enum bt_value_array_append_element_status
bt_value_array_append_element(
911 struct bt_value
*array_obj
,
912 struct bt_value
*element_obj
)
914 struct bt_value_array
*typed_array_obj
=
915 BT_VALUE_TO_ARRAY(array_obj
);
917 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
918 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
919 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
920 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
921 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
922 bt_object_get_ref(element_obj
);
923 BT_LOGT("Appended element to array value: array-value-addr=%p, "
924 "element-value-addr=%p, new-size=%u",
925 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
926 return BT_FUNC_STATUS_OK
;
929 enum bt_value_array_append_element_status
930 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
932 enum bt_value_array_append_element_status ret
;
933 struct bt_value
*bool_obj
= NULL
;
935 bool_obj
= bt_value_bool_create_init(val
);
936 ret
= bt_value_array_append_element(array_obj
,
938 bt_object_put_ref(bool_obj
);
942 enum bt_value_array_append_element_status
943 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
946 enum bt_value_array_append_element_status ret
;
947 struct bt_value
*integer_obj
= NULL
;
949 integer_obj
= bt_value_unsigned_integer_create_init(val
);
950 ret
= bt_value_array_append_element(array_obj
,
951 (void *) integer_obj
);
952 bt_object_put_ref(integer_obj
);
956 enum bt_value_array_append_element_status
957 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
960 enum bt_value_array_append_element_status ret
;
961 struct bt_value
*integer_obj
= NULL
;
963 integer_obj
= bt_value_signed_integer_create_init(val
);
964 ret
= bt_value_array_append_element(array_obj
,
965 (void *) integer_obj
);
966 bt_object_put_ref(integer_obj
);
970 enum bt_value_array_append_element_status
971 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
973 enum bt_value_array_append_element_status ret
;
974 struct bt_value
*real_obj
= NULL
;
976 real_obj
= bt_value_real_create_init(val
);
977 ret
= bt_value_array_append_element(array_obj
,
979 bt_object_put_ref(real_obj
);
983 enum bt_value_array_append_element_status
984 bt_value_array_append_string_element(struct bt_value
*array_obj
,
987 enum bt_value_array_append_element_status ret
;
988 struct bt_value
*string_obj
= NULL
;
990 string_obj
= bt_value_string_create_init(val
);
991 ret
= bt_value_array_append_element(array_obj
,
992 (void *) string_obj
);
993 bt_object_put_ref(string_obj
);
997 enum bt_value_array_append_element_status
998 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
)
1000 enum bt_value_array_append_element_status ret
;
1001 struct bt_value
*empty_array_obj
= NULL
;
1003 empty_array_obj
= bt_value_array_create();
1004 ret
= bt_value_array_append_element(array_obj
,
1005 (void *) empty_array_obj
);
1006 bt_object_put_ref(empty_array_obj
);
1010 enum bt_value_array_append_element_status
1011 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
)
1013 enum bt_value_array_append_element_status ret
;
1014 struct bt_value
*map_obj
= NULL
;
1016 map_obj
= bt_value_map_create();
1017 ret
= bt_value_array_append_element(array_obj
,
1019 bt_object_put_ref(map_obj
);
1023 enum bt_value_array_set_element_by_index_status
1024 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1025 struct bt_value
*element_obj
)
1027 struct bt_value_array
*typed_array_obj
=
1028 BT_VALUE_TO_ARRAY(array_obj
);
1030 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1031 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1032 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
1033 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
1034 BT_ASSERT_PRE_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
1035 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1036 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1037 bt_object_get_ref(element_obj
);
1038 BT_LOGT("Set array value's element: array-value-addr=%p, "
1039 "index=%" PRIu64
", element-value-addr=%p",
1040 array_obj
, index
, element_obj
);
1041 return BT_FUNC_STATUS_OK
;
1044 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1046 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1047 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1048 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1051 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1054 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1055 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1056 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1057 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1058 GUINT_TO_POINTER(g_quark_from_string(key
)));
1061 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1062 const struct bt_value
*map_obj
, const char *key
)
1064 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1067 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1069 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1070 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1071 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1072 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1073 GUINT_TO_POINTER(g_quark_from_string(key
)));
1076 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1077 struct bt_value
*map_obj
, const char *key
,
1078 struct bt_value
*element_obj
)
1080 BT_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1081 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1082 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1083 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1084 BT_ASSERT_PRE_DEV_VALUE_HOT(map_obj
, "Map value object");
1085 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1086 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1087 bt_object_get_ref(element_obj
);
1088 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1089 "key=\"%s\", element-value-addr=%p",
1090 map_obj
, key
, element_obj
);
1091 return BT_FUNC_STATUS_OK
;
1094 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1095 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1097 enum bt_value_map_insert_entry_status ret
;
1098 struct bt_value
*bool_obj
= NULL
;
1100 bool_obj
= bt_value_bool_create_init(val
);
1101 ret
= bt_value_map_insert_entry(map_obj
, key
,
1103 bt_object_put_ref(bool_obj
);
1107 enum bt_value_map_insert_entry_status
1108 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1109 const char *key
, uint64_t val
)
1111 enum bt_value_map_insert_entry_status ret
;
1112 struct bt_value
*integer_obj
= NULL
;
1114 integer_obj
= bt_value_unsigned_integer_create_init(val
);
1115 ret
= bt_value_map_insert_entry(map_obj
, key
,
1116 (void *) integer_obj
);
1117 bt_object_put_ref(integer_obj
);
1121 enum bt_value_map_insert_entry_status
1122 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1123 const char *key
, int64_t val
)
1125 enum bt_value_map_insert_entry_status ret
;
1126 struct bt_value
*integer_obj
= NULL
;
1128 integer_obj
= bt_value_signed_integer_create_init(val
);
1129 ret
= bt_value_map_insert_entry(map_obj
, key
,
1130 (void *) integer_obj
);
1131 bt_object_put_ref(integer_obj
);
1135 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1136 struct bt_value
*map_obj
, const char *key
, double val
)
1138 enum bt_value_map_insert_entry_status ret
;
1139 struct bt_value
*real_obj
= NULL
;
1141 real_obj
= bt_value_real_create_init(val
);
1142 ret
= bt_value_map_insert_entry(map_obj
, key
,
1144 bt_object_put_ref(real_obj
);
1148 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1149 struct bt_value
*map_obj
, const char *key
,
1152 enum bt_value_map_insert_entry_status ret
;
1153 struct bt_value
*string_obj
= NULL
;
1155 string_obj
= bt_value_string_create_init(val
);
1156 ret
= bt_value_map_insert_entry(map_obj
, key
,
1157 (void *) string_obj
);
1158 bt_object_put_ref(string_obj
);
1162 enum bt_value_map_insert_entry_status
1163 bt_value_map_insert_empty_array_entry(
1164 struct bt_value
*map_obj
, const char *key
)
1166 enum bt_value_map_insert_entry_status ret
;
1167 struct bt_value
*array_obj
= NULL
;
1169 array_obj
= bt_value_array_create();
1170 ret
= bt_value_map_insert_entry(map_obj
, key
,
1171 (void *) array_obj
);
1172 bt_object_put_ref(array_obj
);
1176 enum bt_value_map_insert_entry_status
1177 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
)
1179 enum bt_value_map_insert_entry_status ret
;
1180 struct bt_value
*empty_map_obj
= NULL
;
1182 empty_map_obj
= bt_value_map_create();
1183 ret
= bt_value_map_insert_entry(map_obj
, key
,
1184 (void *) empty_map_obj
);
1185 bt_object_put_ref(empty_map_obj
);
1189 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1190 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1193 enum bt_value_map_foreach_entry_status ret
= BT_FUNC_STATUS_OK
;
1194 gpointer key
, element_obj
;
1195 GHashTableIter iter
;
1196 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1198 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1199 BT_ASSERT_PRE_DEV_NON_NULL(func
, "Callback");
1200 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1201 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1203 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1204 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1206 if (!func(key_str
, element_obj
, data
)) {
1207 BT_LOGT("User canceled the loop: key=\"%s\", "
1208 "value-addr=%p, data=%p",
1209 key_str
, element_obj
, data
);
1210 ret
= BT_FUNC_STATUS_CANCELED
;
1218 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1219 const struct bt_value
*map_obj
,
1220 bt_value_map_foreach_entry_const_func func
, void *data
)
1222 return (int) bt_value_map_foreach_entry((void *) map_obj
,
1223 (bt_value_map_foreach_entry_func
) func
, data
);
1226 struct extend_map_element_data
{
1227 struct bt_value
*extended_obj
;
1232 bt_bool
extend_map_element(const char *key
,
1233 const struct bt_value
*extension_obj_elem
, void *data
)
1235 bt_bool ret
= BT_TRUE
;
1236 struct extend_map_element_data
*extend_data
= data
;
1237 struct bt_value
*extension_obj_elem_copy
= NULL
;
1239 /* Copy object which is to replace the current one */
1240 extend_data
->status
= bt_value_copy(extension_obj_elem
,
1241 &extension_obj_elem_copy
);
1242 if (extend_data
->status
) {
1243 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1244 extension_obj_elem
);
1248 BT_ASSERT(extension_obj_elem_copy
);
1250 /* Replace in extended object */
1251 extend_data
->status
= bt_value_map_insert_entry(
1252 extend_data
->extended_obj
, key
,
1253 (void *) extension_obj_elem_copy
);
1254 if (extend_data
->status
) {
1255 BT_LIB_LOGE_APPEND_CAUSE(
1256 "Cannot replace value in extended value: key=\"%s\", "
1257 "%![extended-value-]+v, %![element-value-]+v",
1258 key
, extend_data
->extended_obj
,
1259 extension_obj_elem_copy
);
1266 BT_ASSERT(extend_data
->status
!= BT_FUNC_STATUS_OK
);
1270 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1274 enum bt_value_map_extend_status
bt_value_map_extend(
1275 const struct bt_value
*base_map_obj
,
1276 const struct bt_value
*extension_obj
,
1277 struct bt_value
**extended_map_obj
)
1279 struct extend_map_element_data extend_data
= {
1280 .extended_obj
= NULL
,
1281 .status
= BT_FUNC_STATUS_OK
,
1284 BT_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1285 BT_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1286 BT_ASSERT_PRE_NON_NULL(extended_map_obj
,
1287 "Extended value object (output)");
1288 BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_VALUE_TYPE_MAP
);
1289 BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_VALUE_TYPE_MAP
);
1290 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1291 base_map_obj
, extension_obj
);
1292 *extended_map_obj
= NULL
;
1294 /* Create copy of base map object to start with */
1295 extend_data
.status
= bt_value_copy(base_map_obj
, extended_map_obj
);
1296 if (extend_data
.status
) {
1297 BT_LIB_LOGE_APPEND_CAUSE(
1298 "Cannot copy base value: %![base-value-]+v",
1303 BT_ASSERT(extended_map_obj
);
1306 * For each key in the extension map object, replace this key
1307 * in the copied map object.
1309 extend_data
.extended_obj
= *extended_map_obj
;
1311 if (bt_value_map_foreach_entry_const(extension_obj
, extend_map_element
,
1313 BT_LIB_LOGE_APPEND_CAUSE(
1314 "Cannot iterate on the extension object's elements: "
1315 "%![extension-value-]+v", extension_obj
);
1319 if (extend_data
.status
) {
1320 BT_LIB_LOGE_APPEND_CAUSE(
1321 "Failed to successfully iterate on the extension object's elements: "
1322 "%![extension-value-]+v", extension_obj
);
1326 BT_LOGD("Extended map value: extended-value-addr=%p",
1331 BT_OBJECT_PUT_REF_AND_RESET(*extended_map_obj
);
1332 *extended_map_obj
= NULL
;
1335 return extend_data
.status
;
1338 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1339 struct bt_value
**copy_obj
)
1341 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1343 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
1344 BT_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1345 BT_LOGD("Copying value object: addr=%p", object
);
1346 *copy_obj
= copy_funcs
[object
->type
](object
);
1348 BT_LOGD("Copied value object: copy-value-addr=%p",
1351 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1353 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1359 bt_bool
bt_value_compare(const struct bt_value
*object_a
,
1360 const struct bt_value
*object_b
)
1362 bt_bool ret
= BT_FALSE
;
1364 BT_ASSERT_PRE_DEV_NON_NULL(object_a
, "Value object A");
1365 BT_ASSERT_PRE_DEV_NON_NULL(object_b
, "Value object B");
1367 if (object_a
->type
!= object_b
->type
) {
1368 BT_LOGT("Values are different: type mismatch: "
1369 "value-a-addr=%p, value-b-addr=%p, "
1370 "value-a-type=%s, value-b-type=%s",
1372 bt_common_value_type_string(object_a
->type
),
1373 bt_common_value_type_string(object_b
->type
));
1377 ret
= compare_funcs
[object_a
->type
](object_a
, object_b
);
1383 void bt_value_get_ref(const struct bt_value
*value
)
1385 bt_object_get_ref(value
);
1388 void bt_value_put_ref(const struct bt_value
*value
)
1390 bt_object_put_ref(value
);