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 BT_ASSERT(null_obj
== bt_value_null
);
141 bt_object_get_ref_no_null_check(bt_value_null
);
142 return (void *) bt_value_null
;
146 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
148 return bt_value_bool_create_init(
149 BT_VALUE_TO_BOOL(bool_obj
)->value
);
153 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
157 struct bt_value
*bt_value_integer_copy(
158 const struct bt_value
*integer_obj
)
160 return bt_value_integer_create_init(integer_obj
->type
,
161 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
165 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
167 return bt_value_real_create_init(
168 BT_VALUE_TO_REAL(real_obj
)->value
);
172 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
174 return bt_value_string_create_init(
175 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
179 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
183 struct bt_value
*copy_obj
;
184 struct bt_value_array
*typed_array_obj
;
186 BT_LOGD("Copying array value: addr=%p", array_obj
);
187 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
188 copy_obj
= bt_value_array_create();
190 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
194 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
195 struct bt_value
*element_obj_copy
= NULL
;
196 const struct bt_value
*element_obj
=
197 bt_value_array_borrow_element_by_index_const(
200 BT_LOGD("Copying array value's element: element-addr=%p, "
201 "index=%d", element_obj
, i
);
202 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
204 BT_LIB_LOGE_APPEND_CAUSE(
205 "Cannot copy array value's element: "
206 "array-addr=%p, index=%d",
208 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
212 BT_ASSERT(element_obj_copy
);
213 ret
= bt_value_array_append_element(copy_obj
,
214 (void *) element_obj_copy
);
215 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
217 BT_LIB_LOGE_APPEND_CAUSE(
218 "Cannot append to array value: addr=%p",
220 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
225 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
226 array_obj
, copy_obj
);
233 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
237 gpointer key
, element_obj
;
238 struct bt_value
*copy_obj
;
239 struct bt_value
*element_obj_copy
= NULL
;
240 struct bt_value_map
*typed_map_obj
;
242 BT_LOGD("Copying map value: addr=%p", map_obj
);
243 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
244 copy_obj
= bt_value_map_create();
249 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
251 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
252 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
255 BT_LOGD("Copying map value's element: element-addr=%p, "
256 "key=\"%s\"", element_obj
, key_str
);
257 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
259 BT_LIB_LOGE_APPEND_CAUSE(
260 "Cannot copy map value's element: "
261 "map-addr=%p, key=\"%s\"",
263 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
267 BT_ASSERT(element_obj_copy
);
268 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
269 (void *) element_obj_copy
);
270 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
272 BT_LIB_LOGE_APPEND_CAUSE(
273 "Cannot insert into map value: addr=%p, key=\"%s\"",
275 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
280 BT_LOGD("Copied map value: addr=%p", map_obj
);
287 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
288 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
289 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
290 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
291 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
292 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
293 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
294 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
295 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
299 bt_bool
bt_value_null_is_equal(const struct bt_value
*object_a
,
300 const struct bt_value
*object_b
)
303 * Always BT_TRUE since bt_value_is_equal() already checks if both
304 * object_a and object_b have the same type, and in the case of
305 * null value objects, they're always the same if it is so.
311 bt_bool
bt_value_bool_is_equal(const struct bt_value
*object_a
,
312 const struct bt_value
*object_b
)
314 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
315 BT_VALUE_TO_BOOL(object_b
)->value
) {
316 BT_LOGT("Boolean value objects are different: "
317 "bool-a-val=%d, bool-b-val=%d",
318 BT_VALUE_TO_BOOL(object_a
)->value
,
319 BT_VALUE_TO_BOOL(object_b
)->value
);
327 bt_bool
bt_value_integer_is_equal(const struct bt_value
*object_a
,
328 const struct bt_value
*object_b
)
330 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
331 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
332 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
333 BT_LOGT("Unsigned integer value objects are different: "
334 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
335 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
336 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
338 BT_LOGT("Signed integer value objects are different: "
339 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
340 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
341 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
351 bt_bool
bt_value_real_is_equal(const struct bt_value
*object_a
,
352 const struct bt_value
*object_b
)
354 if (BT_VALUE_TO_REAL(object_a
)->value
!=
355 BT_VALUE_TO_REAL(object_b
)->value
) {
356 BT_LOGT("Real number value objects are different: "
357 "real-a-val=%f, real-b-val=%f",
358 BT_VALUE_TO_REAL(object_a
)->value
,
359 BT_VALUE_TO_REAL(object_b
)->value
);
367 bt_bool
bt_value_string_is_equal(const struct bt_value
*object_a
,
368 const struct bt_value
*object_b
)
370 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
371 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
372 BT_LOGT("String value objects are different: "
373 "string-a-val=\"%s\", string-b-val=\"%s\"",
374 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
375 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
383 bt_bool
bt_value_array_is_equal(const struct bt_value
*object_a
,
384 const struct bt_value
*object_b
)
387 bt_bool ret
= BT_TRUE
;
388 const struct bt_value_array
*array_obj_a
=
389 BT_VALUE_TO_ARRAY(object_a
);
391 if (bt_value_array_get_length(object_a
) !=
392 bt_value_array_get_length(object_b
)) {
393 BT_LOGT("Array values are different: size mismatch "
394 "value-a-addr=%p, value-b-addr=%p, "
395 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
397 bt_value_array_get_length(object_a
),
398 bt_value_array_get_length(object_b
));
403 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
404 const struct bt_value
*element_obj_a
;
405 const struct bt_value
*element_obj_b
;
407 element_obj_a
= bt_value_array_borrow_element_by_index_const(
409 element_obj_b
= bt_value_array_borrow_element_by_index_const(
412 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
413 BT_LOGT("Array values's elements are different: "
414 "value-a-addr=%p, value-b-addr=%p, index=%d",
415 element_obj_a
, element_obj_b
, i
);
426 bt_bool
bt_value_map_is_equal(const struct bt_value
*object_a
,
427 const struct bt_value
*object_b
)
429 bt_bool ret
= BT_TRUE
;
431 gpointer key
, element_obj_a
;
432 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
434 if (bt_value_map_get_size(object_a
) !=
435 bt_value_map_get_size(object_b
)) {
436 BT_LOGT("Map values are different: size mismatch "
437 "value-a-addr=%p, value-b-addr=%p, "
438 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
440 bt_value_map_get_size(object_a
),
441 bt_value_map_get_size(object_b
));
446 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
448 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
449 const struct bt_value
*element_obj_b
;
450 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
452 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
455 if (!bt_value_is_equal(element_obj_a
, element_obj_b
)) {
456 BT_LOGT("Map values's elements are different: "
457 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
458 element_obj_a
, element_obj_b
, key_str
);
469 bt_bool (* const is_equal_funcs
[])(const struct bt_value
*,
470 const struct bt_value
*) = {
471 [BT_VALUE_TYPE_NULL
] = bt_value_null_is_equal
,
472 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_is_equal
,
473 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_is_equal
,
474 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_is_equal
,
475 [BT_VALUE_TYPE_REAL
] = bt_value_real_is_equal
,
476 [BT_VALUE_TYPE_STRING
] = bt_value_string_is_equal
,
477 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_is_equal
,
478 [BT_VALUE_TYPE_MAP
] = bt_value_map_is_equal
,
482 void bt_value_null_freeze(struct bt_value
*object
)
487 void bt_value_generic_freeze(struct bt_value
*object
)
489 object
->frozen
= BT_TRUE
;
493 void bt_value_array_freeze(struct bt_value
*object
)
496 struct bt_value_array
*typed_array_obj
=
497 BT_VALUE_TO_ARRAY(object
);
499 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
500 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
503 bt_value_generic_freeze(object
);
507 void bt_value_map_freeze(struct bt_value
*object
)
510 gpointer key
, element_obj
;
511 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
513 g_hash_table_iter_init(&iter
, map_obj
->ght
);
515 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
516 bt_value_freeze(element_obj
);
519 bt_value_generic_freeze(object
);
523 void (* const freeze_funcs
[])(struct bt_value
*) = {
524 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
525 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
526 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
527 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
528 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
529 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
530 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
531 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
535 void bt_value_destroy(struct bt_object
*obj
)
537 struct bt_value
*value
;
539 value
= container_of(obj
, struct bt_value
, base
);
540 BT_LOGD("Destroying value: addr=%p", value
);
542 if (bt_value_is_null(value
)) {
543 BT_LOGD_STR("Not destroying the null value singleton.");
547 if (destroy_funcs
[value
->type
]) {
548 destroy_funcs
[value
->type
](value
);
555 void _bt_value_freeze(const struct bt_value
*c_object
)
557 const struct bt_value
*object
= (void *) c_object
;
561 if (object
->frozen
) {
565 BT_LOGD("Freezing value: addr=%p", object
);
566 freeze_funcs
[object
->type
]((void *) object
);
572 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
574 BT_ASSERT_PRE_DEV_NON_NULL(object
, "Value object");
579 struct bt_value
bt_value_create_base(enum bt_value_type type
)
581 struct bt_value value
;
584 value
.frozen
= BT_FALSE
;
585 bt_object_init_shared(&value
.base
, bt_value_destroy
);
589 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
591 struct bt_value_bool
*bool_obj
;
593 BT_LOGD("Creating boolean value object: val=%d", val
);
594 bool_obj
= g_new0(struct bt_value_bool
, 1);
596 BT_LIB_LOGE_APPEND_CAUSE(
597 "Failed to allocate one boolean value object.");
601 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
602 bool_obj
->value
= val
;
603 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
606 return (void *) bool_obj
;
609 struct bt_value
*bt_value_bool_create(void)
611 return bt_value_bool_create_init(BT_FALSE
);
615 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
618 struct bt_value_integer
*integer_obj
;
620 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
621 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
623 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
624 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
627 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
631 integer_obj
= g_new0(struct bt_value_integer
, 1);
633 BT_LIB_LOGE_APPEND_CAUSE(
634 "Failed to allocate one integer value object.");
638 integer_obj
->base
= bt_value_create_base(type
);
639 integer_obj
->value
.u
= uval
;
640 BT_LOGD("Created %ssigned integer value object: addr=%p",
641 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
645 return (void *) integer_obj
;
648 struct bt_value
*bt_value_integer_unsigned_create_init(uint64_t val
)
650 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
654 struct bt_value
*bt_value_integer_unsigned_create(void)
656 return bt_value_integer_unsigned_create_init(0);
659 struct bt_value
*bt_value_integer_signed_create_init(int64_t val
)
661 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
665 struct bt_value
*bt_value_integer_signed_create(void)
667 return bt_value_integer_signed_create_init(0);
670 struct bt_value
*bt_value_real_create_init(double val
)
672 struct bt_value_real
*real_obj
;
674 BT_LOGD("Creating real number value object: val=%f", val
);
675 real_obj
= g_new0(struct bt_value_real
, 1);
677 BT_LIB_LOGE_APPEND_CAUSE(
678 "Failed to allocate one real number value object.");
682 real_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_REAL
);
683 real_obj
->value
= val
;
684 BT_LOGD("Created real number value object: addr=%p",
688 return (void *) real_obj
;
691 struct bt_value
*bt_value_real_create(void)
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_NON_NULL(val
, "Value");
701 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
702 string_obj
= g_new0(struct bt_value_string
, 1);
704 BT_LIB_LOGE_APPEND_CAUSE(
705 "Failed to allocate one string object.");
709 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
710 string_obj
->gstr
= g_string_new(val
);
711 if (!string_obj
->gstr
) {
712 BT_LIB_LOGE_APPEND_CAUSE(
713 "Failed to allocate a GString.");
719 BT_LOGD("Created string value object: addr=%p",
723 return (void *) string_obj
;
726 struct bt_value
*bt_value_string_create(void)
728 return bt_value_string_create_init("");
731 struct bt_value
*bt_value_array_create(void)
733 struct bt_value_array
*array_obj
;
735 BT_LOGD_STR("Creating empty array value object.");
736 array_obj
= g_new0(struct bt_value_array
, 1);
738 BT_LIB_LOGE_APPEND_CAUSE(
739 "Failed to allocate one array object.");
743 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
744 array_obj
->garray
= bt_g_ptr_array_new_full(0,
745 (GDestroyNotify
) bt_object_put_ref
);
746 if (!array_obj
->garray
) {
747 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
753 BT_LOGD("Created array value object: addr=%p",
757 return (void *) array_obj
;
760 struct bt_value
*bt_value_map_create(void)
762 struct bt_value_map
*map_obj
;
764 BT_LOGD_STR("Creating empty map value object.");
765 map_obj
= g_new0(struct bt_value_map
, 1);
767 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
771 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
772 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
773 NULL
, (GDestroyNotify
) bt_object_put_ref
);
775 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
781 BT_LOGD("Created map value object: addr=%p",
785 return (void *) map_obj
;
788 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
790 BT_ASSERT_PRE_DEV_NON_NULL(bool_obj
, "Value object");
791 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
792 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
795 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
797 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
798 BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
799 BT_ASSERT_PRE_DEV_VALUE_HOT(bool_obj
, "Value object");
800 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
801 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
805 uint64_t bt_value_integer_unsigned_get(const struct bt_value
*integer_obj
)
807 BT_ASSERT_PRE_DEV_NON_NULL(integer_obj
, "Value object");
808 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj
,
809 BT_VALUE_TYPE_UNSIGNED_INTEGER
);
810 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
813 int64_t bt_value_integer_signed_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_SIGNED_INTEGER
);
818 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
822 void bt_value_integer_set(struct bt_value
*integer_obj
,
823 enum bt_value_type expected_type
, uint64_t uval
)
825 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
826 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, expected_type
);
827 BT_ASSERT_PRE_DEV_VALUE_HOT(integer_obj
, "Value object");
828 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
831 void bt_value_integer_unsigned_set(struct bt_value
*integer_obj
,
834 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
);
835 BT_LOGT("Set unsigned integer value's raw value: "
836 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
839 void bt_value_integer_signed_set(struct bt_value
*integer_obj
,
842 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
844 BT_LOGT("Set signed integer value's raw value: "
845 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
848 double bt_value_real_get(const struct bt_value
*real_obj
)
850 BT_ASSERT_PRE_DEV_NON_NULL(real_obj
, "Value object");
851 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
852 return BT_VALUE_TO_REAL(real_obj
)->value
;
855 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
857 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
858 BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
859 BT_ASSERT_PRE_DEV_VALUE_HOT(real_obj
, "Value object");
860 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
861 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
865 const char *bt_value_string_get(const struct bt_value
*string_obj
)
867 BT_ASSERT_PRE_DEV_NON_NULL(string_obj
, "Value object");
868 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
869 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
872 enum bt_value_string_set_status
bt_value_string_set(
873 struct bt_value
*string_obj
, const char *val
)
875 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
876 BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
877 BT_ASSERT_PRE_DEV_VALUE_HOT(string_obj
, "Value object");
878 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
879 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
881 return BT_FUNC_STATUS_OK
;
884 uint64_t bt_value_array_get_length(const struct bt_value
*array_obj
)
886 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
887 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
888 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
891 struct bt_value
*bt_value_array_borrow_element_by_index(
892 struct bt_value
*array_obj
, uint64_t index
)
894 struct bt_value_array
*typed_array_obj
=
895 BT_VALUE_TO_ARRAY(array_obj
);
897 BT_ASSERT_PRE_DEV_NON_NULL(array_obj
, "Value object");
898 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
899 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
900 return g_ptr_array_index(typed_array_obj
->garray
, index
);
903 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
904 const struct bt_value
*array_obj
,
907 return bt_value_array_borrow_element_by_index(
908 (void *) array_obj
, index
);
911 enum bt_value_array_append_element_status
bt_value_array_append_element(
912 struct bt_value
*array_obj
,
913 struct bt_value
*element_obj
)
915 struct bt_value_array
*typed_array_obj
=
916 BT_VALUE_TO_ARRAY(array_obj
);
918 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
919 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
920 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
921 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
922 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
923 bt_object_get_ref(element_obj
);
924 BT_LOGT("Appended element to array value: array-value-addr=%p, "
925 "element-value-addr=%p, new-size=%u",
926 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
927 return BT_FUNC_STATUS_OK
;
930 enum bt_value_array_append_element_status
931 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
933 enum bt_value_array_append_element_status ret
;
934 struct bt_value
*bool_obj
= NULL
;
936 bool_obj
= bt_value_bool_create_init(val
);
937 ret
= bt_value_array_append_element(array_obj
,
939 bt_object_put_ref(bool_obj
);
943 enum bt_value_array_append_element_status
944 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
947 enum bt_value_array_append_element_status ret
;
948 struct bt_value
*integer_obj
= NULL
;
950 integer_obj
= bt_value_integer_unsigned_create_init(val
);
951 ret
= bt_value_array_append_element(array_obj
,
952 (void *) integer_obj
);
953 bt_object_put_ref(integer_obj
);
957 enum bt_value_array_append_element_status
958 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
961 enum bt_value_array_append_element_status ret
;
962 struct bt_value
*integer_obj
= NULL
;
964 integer_obj
= bt_value_integer_signed_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_real_element(struct bt_value
*array_obj
, double val
)
974 enum bt_value_array_append_element_status ret
;
975 struct bt_value
*real_obj
= NULL
;
977 real_obj
= bt_value_real_create_init(val
);
978 ret
= bt_value_array_append_element(array_obj
,
980 bt_object_put_ref(real_obj
);
984 enum bt_value_array_append_element_status
985 bt_value_array_append_string_element(struct bt_value
*array_obj
,
988 enum bt_value_array_append_element_status ret
;
989 struct bt_value
*string_obj
= NULL
;
991 string_obj
= bt_value_string_create_init(val
);
992 ret
= bt_value_array_append_element(array_obj
,
993 (void *) string_obj
);
994 bt_object_put_ref(string_obj
);
998 enum bt_value_array_append_element_status
999 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
,
1000 struct bt_value
**element_obj
)
1002 enum bt_value_array_append_element_status ret
;
1003 struct bt_value
*empty_array_obj
= NULL
;
1005 empty_array_obj
= bt_value_array_create();
1006 ret
= bt_value_array_append_element(array_obj
,
1007 (void *) empty_array_obj
);
1010 *element_obj
= empty_array_obj
;
1013 bt_object_put_ref(empty_array_obj
);
1017 enum bt_value_array_append_element_status
1018 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
,
1019 struct bt_value
**element_obj
)
1021 enum bt_value_array_append_element_status ret
;
1022 struct bt_value
*map_obj
= NULL
;
1024 map_obj
= bt_value_map_create();
1025 ret
= bt_value_array_append_element(array_obj
,
1029 *element_obj
= map_obj
;
1032 bt_object_put_ref(map_obj
);
1036 enum bt_value_array_set_element_by_index_status
1037 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1038 struct bt_value
*element_obj
)
1040 struct bt_value_array
*typed_array_obj
=
1041 BT_VALUE_TO_ARRAY(array_obj
);
1043 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1044 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1045 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
1046 BT_ASSERT_PRE_DEV_VALUE_HOT(array_obj
, "Array value object");
1047 BT_ASSERT_PRE_VALID_INDEX(index
, typed_array_obj
->garray
->len
);
1048 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1049 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1050 bt_object_get_ref(element_obj
);
1051 BT_LOGT("Set array value's element: array-value-addr=%p, "
1052 "index=%" PRIu64
", element-value-addr=%p",
1053 array_obj
, index
, element_obj
);
1054 return BT_FUNC_STATUS_OK
;
1057 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1059 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1060 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1061 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1064 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1067 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1068 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1069 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1070 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1071 GUINT_TO_POINTER(g_quark_from_string(key
)));
1074 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1075 const struct bt_value
*map_obj
, const char *key
)
1077 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1080 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1082 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1083 BT_ASSERT_PRE_DEV_NON_NULL(key
, "Key");
1084 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1085 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1086 GUINT_TO_POINTER(g_quark_from_string(key
)));
1089 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1090 struct bt_value
*map_obj
, const char *key
,
1091 struct bt_value
*element_obj
)
1093 BT_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1094 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1095 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1096 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1097 BT_ASSERT_PRE_DEV_VALUE_HOT(map_obj
, "Map value object");
1098 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1099 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1100 bt_object_get_ref(element_obj
);
1101 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1102 "key=\"%s\", element-value-addr=%p",
1103 map_obj
, key
, element_obj
);
1104 return BT_FUNC_STATUS_OK
;
1107 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1108 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1110 enum bt_value_map_insert_entry_status ret
;
1111 struct bt_value
*bool_obj
= NULL
;
1113 bool_obj
= bt_value_bool_create_init(val
);
1114 ret
= bt_value_map_insert_entry(map_obj
, key
,
1116 bt_object_put_ref(bool_obj
);
1120 enum bt_value_map_insert_entry_status
1121 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1122 const char *key
, uint64_t val
)
1124 enum bt_value_map_insert_entry_status ret
;
1125 struct bt_value
*integer_obj
= NULL
;
1127 integer_obj
= bt_value_integer_unsigned_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
1135 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1136 const char *key
, int64_t val
)
1138 enum bt_value_map_insert_entry_status ret
;
1139 struct bt_value
*integer_obj
= NULL
;
1141 integer_obj
= bt_value_integer_signed_create_init(val
);
1142 ret
= bt_value_map_insert_entry(map_obj
, key
,
1143 (void *) integer_obj
);
1144 bt_object_put_ref(integer_obj
);
1148 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1149 struct bt_value
*map_obj
, const char *key
, double val
)
1151 enum bt_value_map_insert_entry_status ret
;
1152 struct bt_value
*real_obj
= NULL
;
1154 real_obj
= bt_value_real_create_init(val
);
1155 ret
= bt_value_map_insert_entry(map_obj
, key
,
1157 bt_object_put_ref(real_obj
);
1161 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1162 struct bt_value
*map_obj
, const char *key
,
1165 enum bt_value_map_insert_entry_status ret
;
1166 struct bt_value
*string_obj
= NULL
;
1168 string_obj
= bt_value_string_create_init(val
);
1169 ret
= bt_value_map_insert_entry(map_obj
, key
,
1170 (void *) string_obj
);
1171 bt_object_put_ref(string_obj
);
1175 enum bt_value_map_insert_entry_status
1176 bt_value_map_insert_empty_array_entry(
1177 struct bt_value
*map_obj
, const char *key
,
1178 bt_value
**entry_obj
)
1180 enum bt_value_map_insert_entry_status ret
;
1181 struct bt_value
*array_obj
= NULL
;
1183 array_obj
= bt_value_array_create();
1184 ret
= bt_value_map_insert_entry(map_obj
, key
,
1185 (void *) array_obj
);
1188 *entry_obj
= array_obj
;
1191 bt_object_put_ref(array_obj
);
1195 enum bt_value_map_insert_entry_status
1196 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
,
1197 bt_value
**entry_obj
)
1199 enum bt_value_map_insert_entry_status ret
;
1200 struct bt_value
*empty_map_obj
= NULL
;
1202 empty_map_obj
= bt_value_map_create();
1203 ret
= bt_value_map_insert_entry(map_obj
, key
,
1204 (void *) empty_map_obj
);
1207 *entry_obj
= empty_map_obj
;
1210 bt_object_put_ref(empty_map_obj
);
1214 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1215 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1218 enum bt_value_map_foreach_entry_status ret
= BT_FUNC_STATUS_OK
;
1219 gpointer key
, element_obj
;
1220 GHashTableIter iter
;
1221 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1223 BT_ASSERT_PRE_DEV_NON_NULL(map_obj
, "Value object");
1224 BT_ASSERT_PRE_DEV_NON_NULL(func
, "Callback");
1225 BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1226 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1228 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1229 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1231 if (!func(key_str
, element_obj
, data
)) {
1232 BT_LOGT("User interrupted the loop: key=\"%s\", "
1233 "value-addr=%p, data=%p",
1234 key_str
, element_obj
, data
);
1235 ret
= BT_FUNC_STATUS_INTERRUPTED
;
1243 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1244 const struct bt_value
*map_obj
,
1245 bt_value_map_foreach_entry_const_func func
, void *data
)
1247 return (int) bt_value_map_foreach_entry((void *) map_obj
,
1248 (bt_value_map_foreach_entry_func
) func
, data
);
1251 struct extend_map_element_data
{
1252 struct bt_value
*base_obj
;
1257 bt_bool
extend_map_element(const char *key
,
1258 const struct bt_value
*extension_obj_elem
, void *data
)
1260 bt_bool ret
= BT_TRUE
;
1261 struct extend_map_element_data
*extend_data
= data
;
1262 struct bt_value
*extension_obj_elem_copy
= NULL
;
1264 /* Copy object which is to replace the current one */
1265 extend_data
->status
= bt_value_copy(extension_obj_elem
,
1266 &extension_obj_elem_copy
);
1267 if (extend_data
->status
) {
1268 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1269 extension_obj_elem
);
1273 BT_ASSERT(extension_obj_elem_copy
);
1275 /* Replace in base map value. */
1276 extend_data
->status
= bt_value_map_insert_entry(
1277 extend_data
->base_obj
, key
,
1278 (void *) extension_obj_elem_copy
);
1279 if (extend_data
->status
) {
1280 BT_LIB_LOGE_APPEND_CAUSE(
1281 "Cannot replace value in base map value: key=\"%s\", "
1282 "%![base-map-value-]+v, %![element-value-]+v",
1283 key
, extend_data
->base_obj
,
1284 extension_obj_elem_copy
);
1291 BT_ASSERT(extend_data
->status
!= BT_FUNC_STATUS_OK
);
1295 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1299 enum bt_value_map_extend_status
bt_value_map_extend(
1300 struct bt_value
*base_map_obj
,
1301 const struct bt_value
*extension_obj
)
1303 struct extend_map_element_data extend_data
= {
1305 .status
= BT_FUNC_STATUS_OK
,
1308 BT_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1309 BT_ASSERT_PRE_DEV_VALUE_HOT(base_map_obj
, "Base value object");
1310 BT_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1311 BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_VALUE_TYPE_MAP
);
1312 BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_VALUE_TYPE_MAP
);
1313 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1314 base_map_obj
, extension_obj
);
1317 * For each key in the extension map object, replace this key
1318 * in the base map object.
1320 extend_data
.base_obj
= base_map_obj
;
1322 if (bt_value_map_foreach_entry_const(extension_obj
, extend_map_element
,
1324 BT_LIB_LOGE_APPEND_CAUSE(
1325 "Cannot iterate on the extension object's elements: "
1326 "%![extension-value-]+v", extension_obj
);
1329 return extend_data
.status
;
1332 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1333 struct bt_value
**copy_obj
)
1335 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1337 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
1338 BT_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1339 BT_LOGD("Copying value object: addr=%p", object
);
1340 *copy_obj
= copy_funcs
[object
->type
](object
);
1342 BT_LOGD("Copied value object: copy-value-addr=%p",
1345 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1347 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1353 bt_bool
bt_value_is_equal(const struct bt_value
*object_a
,
1354 const struct bt_value
*object_b
)
1356 bt_bool ret
= BT_FALSE
;
1358 BT_ASSERT_PRE_DEV_NON_NULL(object_a
, "Value object A");
1359 BT_ASSERT_PRE_DEV_NON_NULL(object_b
, "Value object B");
1361 if (object_a
->type
!= object_b
->type
) {
1362 BT_LOGT("Values are different: type mismatch: "
1363 "value-a-addr=%p, value-b-addr=%p, "
1364 "value-a-type=%s, value-b-type=%s",
1366 bt_common_value_type_string(object_a
->type
),
1367 bt_common_value_type_string(object_b
->type
));
1371 ret
= is_equal_funcs
[object_a
->type
](object_a
, object_b
);
1377 void bt_value_get_ref(const struct bt_value
*value
)
1379 bt_object_get_ref(value
);
1382 void bt_value_put_ref(const struct bt_value
*value
)
1384 bt_object_put_ref(value
);