2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
8 #define BT_LOG_TAG "CTF-WRITER/VALUES"
15 #include <babeltrace2-ctf-writer/object.h>
16 #include <babeltrace2/types.h>
18 #include "common/assert.h"
19 #include "common/common.h"
20 #include "compat/compiler.h"
21 #include "compat/glib.h"
23 #include "assert-pre.h"
27 #define BT_CTF_VALUE_FROM_CONCRETE(_concrete) ((struct bt_ctf_value *) (_concrete))
28 #define BT_CTF_VALUE_TO_BOOL(_base) ((struct bt_ctf_value_bool *) (_base))
29 #define BT_CTF_VALUE_TO_INTEGER(_base) ((struct bt_ctf_value_integer *) (_base))
30 #define BT_CTF_VALUE_TO_REAL(_base) ((struct bt_ctf_value_real *) (_base))
31 #define BT_CTF_VALUE_TO_STRING(_base) ((struct bt_ctf_value_string *) (_base))
32 #define BT_CTF_VALUE_TO_ARRAY(_base) ((struct bt_ctf_value_array *) (_base))
33 #define BT_CTF_VALUE_TO_MAP(_base) ((struct bt_ctf_value_map *) (_base))
35 #define BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
36 BT_CTF_ASSERT_PRE(((struct bt_ctf_value *) (_value))->type == (_type), \
37 "Value has the wrong type ID: expected-type=%d", (_type))
39 #define BT_CTF_ASSERT_PRE_VALUE_HOT(_value, _name) \
40 BT_CTF_ASSERT_PRE_HOT(((struct bt_ctf_value *) (_value)), (_name), "")
42 #define BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count) \
43 BT_CTF_ASSERT_PRE((_index) < (_count), \
44 "Index is out of bound: " \
45 "index=%" PRIu64 ", count=%u", (_index), (_count));
48 struct bt_ctf_object base
;
49 enum bt_ctf_value_type type
;
54 void bt_ctf_value_null_instance_release_func(struct bt_ctf_object
*obj
)
56 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
60 struct bt_ctf_value bt_ctf_value_null_instance
= {
64 .release_func
= bt_ctf_value_null_instance_release_func
,
65 .spec_release_func
= NULL
,
66 .parent_is_owner_listener_func
= NULL
,
69 .type
= BT_CTF_VALUE_TYPE_NULL
,
70 .frozen
= BT_CTF_TRUE
,
74 struct bt_ctf_value
*const bt_ctf_value_null
= &bt_ctf_value_null_instance
;
77 struct bt_ctf_private_value
*const bt_ctf_private_value_null
=
78 (void *) &bt_ctf_value_null_instance
;
80 struct bt_ctf_value_bool
{
81 struct bt_ctf_value base
;
85 struct bt_ctf_value_integer
{
86 struct bt_ctf_value base
;
90 struct bt_ctf_value_real
{
91 struct bt_ctf_value base
;
95 struct bt_ctf_value_string
{
96 struct bt_ctf_value base
;
100 struct bt_ctf_value_array
{
101 struct bt_ctf_value base
;
105 struct bt_ctf_value_map
{
106 struct bt_ctf_value base
;
111 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
);
114 void bt_ctf_value_string_destroy(struct bt_ctf_value
*object
)
116 g_string_free(BT_CTF_VALUE_TO_STRING(object
)->gstr
, TRUE
);
117 BT_CTF_VALUE_TO_STRING(object
)->gstr
= NULL
;
121 void bt_ctf_value_array_destroy(struct bt_ctf_value
*object
)
124 * Pointer array's registered value destructor will take care
125 * of putting each contained object.
127 g_ptr_array_free(BT_CTF_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
128 BT_CTF_VALUE_TO_ARRAY(object
)->garray
= NULL
;
132 void bt_ctf_value_map_destroy(struct bt_ctf_value
*object
)
135 * Hash table's registered value destructor will take care of
136 * putting each contained object. Keys are GQuarks and cannot
137 * be destroyed anyway.
139 g_hash_table_destroy(BT_CTF_VALUE_TO_MAP(object
)->ght
);
140 BT_CTF_VALUE_TO_MAP(object
)->ght
= NULL
;
144 void (* const destroy_funcs
[])(struct bt_ctf_value
*) = {
145 [BT_CTF_VALUE_TYPE_NULL
] = NULL
,
146 [BT_CTF_VALUE_TYPE_BOOL
] = NULL
,
147 [BT_CTF_VALUE_TYPE_INTEGER
] = NULL
,
148 [BT_CTF_VALUE_TYPE_REAL
] = NULL
,
149 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_destroy
,
150 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_destroy
,
151 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_destroy
,
155 struct bt_ctf_private_value
*bt_ctf_value_null_copy(
156 const struct bt_ctf_value
*null_obj
__attribute__((unused
)))
158 return (void *) bt_ctf_value_null
;
162 struct bt_ctf_private_value
*bt_ctf_value_bool_copy(const struct bt_ctf_value
*bool_obj
)
164 return bt_ctf_private_value_bool_create_init(
165 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
);
169 struct bt_ctf_private_value
*bt_ctf_value_integer_copy(
170 const struct bt_ctf_value
*integer_obj
)
172 return bt_ctf_private_value_integer_create_init(
173 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
);
177 struct bt_ctf_private_value
*bt_ctf_value_real_copy(const struct bt_ctf_value
*real_obj
)
179 return bt_ctf_private_value_real_create_init(
180 BT_CTF_VALUE_TO_REAL(real_obj
)->value
);
184 struct bt_ctf_private_value
*bt_ctf_value_string_copy(const struct bt_ctf_value
*string_obj
)
186 return bt_ctf_private_value_string_create_init(
187 BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
);
191 struct bt_ctf_private_value
*bt_ctf_value_array_copy(const struct bt_ctf_value
*array_obj
)
195 struct bt_ctf_private_value
*copy_obj
;
196 struct bt_ctf_value_array
*typed_array_obj
;
198 BT_LOGD("Copying array value: addr=%p", array_obj
);
199 typed_array_obj
= BT_CTF_VALUE_TO_ARRAY(array_obj
);
200 copy_obj
= bt_ctf_private_value_array_create();
202 BT_LOGE_STR("Cannot create empty array value.");
206 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
207 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
208 struct bt_ctf_value
*element_obj
=
209 bt_ctf_value_array_borrow_element_by_index(
212 BT_ASSERT_DBG(element_obj
);
213 BT_LOGD("Copying array value's element: element-addr=%p, "
214 "index=%d", element_obj
, i
);
215 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
217 BT_LOGE("Cannot copy array value's element: "
218 "array-addr=%p, index=%d",
220 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
224 BT_ASSERT_DBG(element_obj_copy
);
225 ret
= bt_ctf_private_value_array_append_element(copy_obj
,
226 (void *) element_obj_copy
);
227 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
229 BT_LOGE("Cannot append to array value: addr=%p",
231 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
236 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
237 array_obj
, copy_obj
);
244 struct bt_ctf_private_value
*bt_ctf_value_map_copy(const struct bt_ctf_value
*map_obj
)
248 gpointer key
, element_obj
;
249 struct bt_ctf_private_value
*copy_obj
;
250 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
251 struct bt_ctf_value_map
*typed_map_obj
;
253 BT_LOGD("Copying map value: addr=%p", map_obj
);
254 typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
255 copy_obj
= bt_ctf_private_value_map_create();
260 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
262 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
263 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
265 BT_ASSERT_DBG(key_str
);
266 BT_LOGD("Copying map value's element: element-addr=%p, "
267 "key=\"%s\"", element_obj
, key_str
);
268 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
270 BT_LOGE("Cannot copy map value's element: "
271 "map-addr=%p, key=\"%s\"",
273 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
277 BT_ASSERT_DBG(element_obj_copy
);
278 ret
= bt_ctf_private_value_map_insert_entry(copy_obj
, key_str
,
279 (void *) element_obj_copy
);
280 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
282 BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"",
284 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
289 BT_LOGD("Copied map value: addr=%p", map_obj
);
296 struct bt_ctf_private_value
*(* const copy_funcs
[])(const struct bt_ctf_value
*) = {
297 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_copy
,
298 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_copy
,
299 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_copy
,
300 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_copy
,
301 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_copy
,
302 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_copy
,
303 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_copy
,
307 bt_ctf_bool
bt_ctf_value_null_compare(
308 const struct bt_ctf_value
*object_a
__attribute__((unused
)),
309 const struct bt_ctf_value
*object_b
__attribute__((unused
)))
312 * Always BT_CTF_TRUE since bt_ctf_value_compare() already checks if both
313 * object_a and object_b have the same type, and in the case of
314 * null value objects, they're always the same if it is so.
320 bt_ctf_bool
bt_ctf_value_bool_compare(const struct bt_ctf_value
*object_a
,
321 const struct bt_ctf_value
*object_b
)
323 if (BT_CTF_VALUE_TO_BOOL(object_a
)->value
!=
324 BT_CTF_VALUE_TO_BOOL(object_b
)->value
) {
325 BT_LOGT("Boolean value objects are different: "
326 "bool-a-val=%d, bool-b-val=%d",
327 BT_CTF_VALUE_TO_BOOL(object_a
)->value
,
328 BT_CTF_VALUE_TO_BOOL(object_b
)->value
);
336 bt_ctf_bool
bt_ctf_value_integer_compare(const struct bt_ctf_value
*object_a
,
337 const struct bt_ctf_value
*object_b
)
339 if (BT_CTF_VALUE_TO_INTEGER(object_a
)->value
!=
340 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
) {
341 BT_LOGT("Integer value objects are different: "
342 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
343 BT_CTF_VALUE_TO_INTEGER(object_a
)->value
,
344 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
);
352 bt_ctf_bool
bt_ctf_value_real_compare(const struct bt_ctf_value
*object_a
,
353 const struct bt_ctf_value
*object_b
)
355 if (BT_CTF_VALUE_TO_REAL(object_a
)->value
!=
356 BT_CTF_VALUE_TO_REAL(object_b
)->value
) {
357 BT_LOGT("Real number value objects are different: "
358 "real-a-val=%f, real-b-val=%f",
359 BT_CTF_VALUE_TO_REAL(object_a
)->value
,
360 BT_CTF_VALUE_TO_REAL(object_b
)->value
);
368 bt_ctf_bool
bt_ctf_value_string_compare(const struct bt_ctf_value
*object_a
,
369 const struct bt_ctf_value
*object_b
)
371 if (strcmp(BT_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
372 BT_CTF_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
373 BT_LOGT("String value objects are different: "
374 "string-a-val=\"%s\", string-b-val=\"%s\"",
375 BT_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
376 BT_CTF_VALUE_TO_STRING(object_b
)->gstr
->str
);
384 bt_ctf_bool
bt_ctf_value_array_compare(const struct bt_ctf_value
*object_a
,
385 const struct bt_ctf_value
*object_b
)
388 bt_ctf_bool ret
= BT_CTF_TRUE
;
389 const struct bt_ctf_value_array
*array_obj_a
=
390 BT_CTF_VALUE_TO_ARRAY(object_a
);
392 if (bt_ctf_value_array_get_length(object_a
) !=
393 bt_ctf_value_array_get_length(object_b
)) {
394 BT_LOGT("Array values are different: size mismatch "
395 "value-a-addr=%p, value-b-addr=%p, "
396 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
398 bt_ctf_value_array_get_length(object_a
),
399 bt_ctf_value_array_get_length(object_b
));
404 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
405 struct bt_ctf_value
*element_obj_a
;
406 struct bt_ctf_value
*element_obj_b
;
408 element_obj_a
= bt_ctf_value_array_borrow_element_by_index(
410 element_obj_b
= bt_ctf_value_array_borrow_element_by_index(
413 if (!bt_ctf_value_compare(element_obj_a
, element_obj_b
)) {
414 BT_LOGT("Array values's elements are different: "
415 "value-a-addr=%p, value-b-addr=%p, index=%d",
416 element_obj_a
, element_obj_b
, i
);
427 bt_ctf_bool
bt_ctf_value_map_compare(const struct bt_ctf_value
*object_a
,
428 const struct bt_ctf_value
*object_b
)
430 bt_ctf_bool ret
= BT_CTF_TRUE
;
432 gpointer key
, element_obj_a
;
433 const struct bt_ctf_value_map
*map_obj_a
= BT_CTF_VALUE_TO_MAP(object_a
);
435 if (bt_ctf_value_map_get_size(object_a
) !=
436 bt_ctf_value_map_get_size(object_b
)) {
437 BT_LOGT("Map values are different: size mismatch "
438 "value-a-addr=%p, value-b-addr=%p, "
439 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
441 bt_ctf_value_map_get_size(object_a
),
442 bt_ctf_value_map_get_size(object_b
));
447 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
449 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
450 struct bt_ctf_value
*element_obj_b
;
451 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
453 element_obj_b
= bt_ctf_value_map_borrow_entry_value(object_b
,
456 if (!bt_ctf_value_compare(element_obj_a
, element_obj_b
)) {
457 BT_LOGT("Map values's elements are different: "
458 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
459 element_obj_a
, element_obj_b
, key_str
);
470 bt_ctf_bool (* const compare_funcs
[])(const struct bt_ctf_value
*,
471 const struct bt_ctf_value
*) = {
472 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_compare
,
473 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_compare
,
474 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_compare
,
475 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_compare
,
476 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_compare
,
477 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_compare
,
478 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_compare
,
482 void bt_ctf_value_null_freeze(struct bt_ctf_value
*object
__attribute__((unused
)))
487 void bt_ctf_value_generic_freeze(struct bt_ctf_value
*object
)
489 object
->frozen
= BT_CTF_TRUE
;
493 void bt_ctf_value_array_freeze(struct bt_ctf_value
*object
)
496 struct bt_ctf_value_array
*typed_array_obj
=
497 BT_CTF_VALUE_TO_ARRAY(object
);
499 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
500 bt_ctf_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
503 bt_ctf_value_generic_freeze(object
);
507 void bt_ctf_value_map_freeze(struct bt_ctf_value
*object
)
510 gpointer key
, element_obj
;
511 const struct bt_ctf_value_map
*map_obj
= BT_CTF_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_ctf_value_freeze(element_obj
);
519 bt_ctf_value_generic_freeze(object
);
523 void (* const freeze_funcs
[])(struct bt_ctf_value
*) = {
524 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_freeze
,
525 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_generic_freeze
,
526 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_generic_freeze
,
527 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_generic_freeze
,
528 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_generic_freeze
,
529 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_freeze
,
530 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_freeze
,
534 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
)
536 struct bt_ctf_value
*value
;
538 value
= container_of(obj
, struct bt_ctf_value
, base
);
539 BT_LOGD("Destroying value: addr=%p", value
);
541 if (bt_ctf_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
);
553 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
)
555 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
557 BT_ASSERT_DBG(object
);
559 if (object
->frozen
) {
563 BT_LOGD("Freezing value: addr=%p", object
);
564 freeze_funcs
[object
->type
](object
);
570 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
)
572 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
577 struct bt_ctf_value
bt_ctf_value_create_base(enum bt_ctf_value_type type
)
579 struct bt_ctf_value value
;
582 value
.frozen
= BT_CTF_FALSE
;
583 bt_ctf_object_init_shared(&value
.base
, bt_ctf_value_destroy
);
587 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_ctf_bool val
)
589 struct bt_ctf_value_bool
*bool_obj
;
591 BT_LOGD("Creating boolean value object: val=%d", val
);
592 bool_obj
= g_new0(struct bt_ctf_value_bool
, 1);
594 BT_LOGE_STR("Failed to allocate one boolean value object.");
598 bool_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_BOOL
);
599 bool_obj
->value
= val
;
600 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
603 return (void *) BT_CTF_VALUE_FROM_CONCRETE(bool_obj
);
606 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create(void)
608 return bt_ctf_private_value_bool_create_init(BT_CTF_FALSE
);
611 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create_init(int64_t val
)
613 struct bt_ctf_value_integer
*integer_obj
;
615 BT_LOGD("Creating integer value object: val=%" PRId64
, val
);
616 integer_obj
= g_new0(struct bt_ctf_value_integer
, 1);
618 BT_LOGE_STR("Failed to allocate one integer value object.");
622 integer_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_INTEGER
);
623 integer_obj
->value
= val
;
624 BT_LOGD("Created integer value object: addr=%p",
628 return (void *) BT_CTF_VALUE_FROM_CONCRETE(integer_obj
);
631 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void)
633 return bt_ctf_private_value_integer_create_init(0);
636 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
)
638 struct bt_ctf_value_real
*real_obj
;
640 BT_LOGD("Creating real number value object: val=%f", val
);
641 real_obj
= g_new0(struct bt_ctf_value_real
, 1);
643 BT_LOGE_STR("Failed to allocate one real number value object.");
647 real_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_REAL
);
648 real_obj
->value
= val
;
649 BT_LOGD("Created real number value object: addr=%p",
653 return (void *) BT_CTF_VALUE_FROM_CONCRETE(real_obj
);
656 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void)
658 return bt_ctf_private_value_real_create_init(0.);
661 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(const char *val
)
663 struct bt_ctf_value_string
*string_obj
= NULL
;
666 BT_LOGW_STR("Invalid parameter: value is NULL.");
670 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
671 string_obj
= g_new0(struct bt_ctf_value_string
, 1);
673 BT_LOGE_STR("Failed to allocate one string object.");
677 string_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_STRING
);
678 string_obj
->gstr
= g_string_new(val
);
679 if (!string_obj
->gstr
) {
680 BT_LOGE_STR("Failed to allocate a GString.");
686 BT_LOGD("Created string value object: addr=%p",
690 return (void *) BT_CTF_VALUE_FROM_CONCRETE(string_obj
);
693 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void)
695 return bt_ctf_private_value_string_create_init("");
698 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void)
700 struct bt_ctf_value_array
*array_obj
;
702 BT_LOGD_STR("Creating empty array value object.");
703 array_obj
= g_new0(struct bt_ctf_value_array
, 1);
705 BT_LOGE_STR("Failed to allocate one array object.");
709 array_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_ARRAY
);
710 array_obj
->garray
= bt_g_ptr_array_new_full(0,
711 (GDestroyNotify
) bt_ctf_object_put_ref
);
712 if (!array_obj
->garray
) {
713 BT_LOGE_STR("Failed to allocate a GPtrArray.");
719 BT_LOGD("Created array value object: addr=%p",
723 return (void *) BT_CTF_VALUE_FROM_CONCRETE(array_obj
);
726 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void)
728 struct bt_ctf_value_map
*map_obj
;
730 BT_LOGD_STR("Creating empty map value object.");
731 map_obj
= g_new0(struct bt_ctf_value_map
, 1);
733 BT_LOGE_STR("Failed to allocate one map object.");
737 map_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_MAP
);
738 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
739 NULL
, (GDestroyNotify
) bt_ctf_object_put_ref
);
741 BT_LOGE_STR("Failed to allocate a GHashTable.");
747 BT_LOGD("Created map value object: addr=%p",
751 return (void *) BT_CTF_VALUE_FROM_CONCRETE(map_obj
);
754 bt_ctf_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
)
756 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
757 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
758 return BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
;
761 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
, bt_ctf_bool val
)
763 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
764 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
765 BT_CTF_ASSERT_PRE_VALUE_HOT(bool_obj
, "Value object");
766 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
= val
;
767 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
771 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
)
773 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
774 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
775 return BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
;
778 void bt_ctf_private_value_integer_set(struct bt_ctf_private_value
*integer_obj
,
781 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
782 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
783 BT_CTF_ASSERT_PRE_VALUE_HOT(integer_obj
, "Value object");
784 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
= val
;
785 BT_LOGT("Set integer value's raw value: value-addr=%p, value=%" PRId64
,
789 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
)
791 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
792 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
793 return BT_CTF_VALUE_TO_REAL(real_obj
)->value
;
796 void bt_ctf_private_value_real_set(struct bt_ctf_private_value
*real_obj
, double val
)
798 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
799 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
800 BT_CTF_ASSERT_PRE_VALUE_HOT(real_obj
, "Value object");
801 BT_CTF_VALUE_TO_REAL(real_obj
)->value
= val
;
802 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
806 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
)
808 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
809 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
810 return BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
;
813 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
814 struct bt_ctf_private_value
*string_obj
, const char *val
)
816 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
817 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
818 BT_CTF_ASSERT_PRE_VALUE_HOT(string_obj
, "Value object");
819 g_string_assign(BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
, val
);
820 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
822 return BT_CTF_VALUE_STATUS_OK
;
825 uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value
*array_obj
)
827 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
828 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
829 return (uint64_t) BT_CTF_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
832 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
833 const struct bt_ctf_value
*array_obj
,
836 struct bt_ctf_value_array
*typed_array_obj
=
837 BT_CTF_VALUE_TO_ARRAY(array_obj
);
839 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
840 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
841 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
842 typed_array_obj
->garray
->len
);
843 return g_ptr_array_index(typed_array_obj
->garray
, index
);
846 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
847 const struct bt_ctf_private_value
*array_obj
,
850 return (void *) bt_ctf_value_array_borrow_element_by_index(
851 (void *) array_obj
, index
);
854 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
855 struct bt_ctf_private_value
*array_obj
,
856 struct bt_ctf_value
*element_obj
)
858 struct bt_ctf_value_array
*typed_array_obj
=
859 BT_CTF_VALUE_TO_ARRAY(array_obj
);
861 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
862 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
863 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
864 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
865 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
866 bt_ctf_object_get_ref(element_obj
);
867 BT_LOGT("Appended element to array value: array-value-addr=%p, "
868 "element-value-addr=%p, new-size=%u",
869 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
870 return BT_CTF_VALUE_STATUS_OK
;
873 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
874 struct bt_ctf_private_value
*array_obj
, bt_ctf_bool val
)
876 enum bt_ctf_value_status ret
;
877 struct bt_ctf_private_value
*bool_obj
= NULL
;
879 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
880 ret
= bt_ctf_private_value_array_append_element(array_obj
,
882 bt_ctf_object_put_ref(bool_obj
);
886 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
887 struct bt_ctf_private_value
*array_obj
, int64_t val
)
889 enum bt_ctf_value_status ret
;
890 struct bt_ctf_private_value
*integer_obj
= NULL
;
892 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
893 ret
= bt_ctf_private_value_array_append_element(array_obj
,
894 (void *) integer_obj
);
895 bt_ctf_object_put_ref(integer_obj
);
899 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
900 struct bt_ctf_private_value
*array_obj
, double val
)
902 enum bt_ctf_value_status ret
;
903 struct bt_ctf_private_value
*real_obj
= NULL
;
905 real_obj
= bt_ctf_private_value_real_create_init(val
);
906 ret
= bt_ctf_private_value_array_append_element(array_obj
,
908 bt_ctf_object_put_ref(real_obj
);
912 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
913 struct bt_ctf_private_value
*array_obj
, const char *val
)
915 enum bt_ctf_value_status ret
;
916 struct bt_ctf_private_value
*string_obj
= NULL
;
918 string_obj
= bt_ctf_private_value_string_create_init(val
);
919 ret
= bt_ctf_private_value_array_append_element(array_obj
,
920 (void *) string_obj
);
921 bt_ctf_object_put_ref(string_obj
);
925 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
926 struct bt_ctf_private_value
*array_obj
)
928 enum bt_ctf_value_status ret
;
929 struct bt_ctf_private_value
*empty_array_obj
= NULL
;
931 empty_array_obj
= bt_ctf_private_value_array_create();
932 ret
= bt_ctf_private_value_array_append_element(array_obj
,
933 (void *) empty_array_obj
);
934 bt_ctf_object_put_ref(empty_array_obj
);
938 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
939 struct bt_ctf_private_value
*array_obj
)
941 enum bt_ctf_value_status ret
;
942 struct bt_ctf_private_value
*map_obj
= NULL
;
944 map_obj
= bt_ctf_private_value_map_create();
945 ret
= bt_ctf_private_value_array_append_element(array_obj
,
947 bt_ctf_object_put_ref(map_obj
);
951 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
952 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
953 struct bt_ctf_value
*element_obj
)
955 struct bt_ctf_value_array
*typed_array_obj
=
956 BT_CTF_VALUE_TO_ARRAY(array_obj
);
958 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
959 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
960 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
961 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
962 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
963 typed_array_obj
->garray
->len
);
964 bt_ctf_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
965 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
966 bt_ctf_object_get_ref(element_obj
);
967 BT_LOGT("Set array value's element: array-value-addr=%p, "
968 "index=%" PRIu64
", element-value-addr=%p",
969 array_obj
, index
, element_obj
);
970 return BT_CTF_VALUE_STATUS_OK
;
973 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
)
975 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
976 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
977 return (uint64_t) g_hash_table_size(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
);
980 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(const struct bt_ctf_value
*map_obj
,
983 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
984 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
985 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
986 return g_hash_table_lookup(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
987 GUINT_TO_POINTER(g_quark_from_string(key
)));
990 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
991 const struct bt_ctf_private_value
*map_obj
, const char *key
)
993 return (void *) bt_ctf_value_map_borrow_entry_value((void *) map_obj
, key
);
996 bt_ctf_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
, const char *key
)
998 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
999 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1000 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1001 return bt_g_hash_table_contains(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1002 GUINT_TO_POINTER(g_quark_from_string(key
)));
1005 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
1006 struct bt_ctf_private_value
*map_obj
,
1007 const char *key
, struct bt_ctf_value
*element_obj
)
1009 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1010 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1011 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1012 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1013 BT_CTF_ASSERT_PRE_VALUE_HOT(map_obj
, "Map value object");
1014 g_hash_table_insert(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1015 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1016 bt_ctf_object_get_ref(element_obj
);
1017 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1018 "key=\"%s\", element-value-addr=%p",
1019 map_obj
, key
, element_obj
);
1020 return BT_CTF_VALUE_STATUS_OK
;
1023 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
1024 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_ctf_bool val
)
1026 enum bt_ctf_value_status ret
;
1027 struct bt_ctf_private_value
*bool_obj
= NULL
;
1029 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
1030 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1032 bt_ctf_object_put_ref(bool_obj
);
1036 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
1037 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
)
1039 enum bt_ctf_value_status ret
;
1040 struct bt_ctf_private_value
*integer_obj
= NULL
;
1042 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
1043 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1044 (void *) integer_obj
);
1045 bt_ctf_object_put_ref(integer_obj
);
1049 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
1050 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
)
1052 enum bt_ctf_value_status ret
;
1053 struct bt_ctf_private_value
*real_obj
= NULL
;
1055 real_obj
= bt_ctf_private_value_real_create_init(val
);
1056 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1058 bt_ctf_object_put_ref(real_obj
);
1062 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
1063 struct bt_ctf_private_value
*map_obj
, const char *key
,
1066 enum bt_ctf_value_status ret
;
1067 struct bt_ctf_private_value
*string_obj
= NULL
;
1069 string_obj
= bt_ctf_private_value_string_create_init(val
);
1070 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1071 (void *) string_obj
);
1072 bt_ctf_object_put_ref(string_obj
);
1076 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
1077 struct bt_ctf_private_value
*map_obj
, const char *key
)
1079 enum bt_ctf_value_status ret
;
1080 struct bt_ctf_private_value
*array_obj
= NULL
;
1082 array_obj
= bt_ctf_private_value_array_create();
1083 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1084 (void *) array_obj
);
1085 bt_ctf_object_put_ref(array_obj
);
1089 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
1090 struct bt_ctf_private_value
*map_obj
, const char *key
)
1092 enum bt_ctf_value_status ret
;
1093 struct bt_ctf_private_value
*empty_map_obj
= NULL
;
1095 empty_map_obj
= bt_ctf_private_value_map_create();
1096 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1097 (void *) empty_map_obj
);
1098 bt_ctf_object_put_ref(empty_map_obj
);
1102 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(const struct bt_ctf_value
*map_obj
,
1103 bt_ctf_value_map_foreach_entry_cb cb
, void *data
)
1105 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
1106 gpointer key
, element_obj
;
1107 GHashTableIter iter
;
1108 struct bt_ctf_value_map
*typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
1110 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1111 BT_CTF_ASSERT_PRE_NON_NULL(cb
, "Callback");
1112 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1113 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1115 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1116 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1118 if (!cb(key_str
, element_obj
, data
)) {
1119 BT_LOGT("User canceled the loop: key=\"%s\", "
1120 "value-addr=%p, data=%p",
1121 key_str
, element_obj
, data
);
1122 ret
= BT_CTF_VALUE_STATUS_CANCELED
;
1130 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
1131 const struct bt_ctf_private_value
*map_obj
,
1132 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
)
1134 return bt_ctf_value_map_foreach_entry((void *) map_obj
,
1135 (bt_ctf_value_map_foreach_entry_cb
) cb
, data
);
1138 struct extend_map_element_data
{
1139 struct bt_ctf_private_value
*extended_obj
;
1140 enum bt_ctf_value_status status
;
1144 bt_ctf_bool
extend_map_element(const char *key
,
1145 struct bt_ctf_value
*extension_obj_elem
, void *data
)
1147 bt_ctf_bool ret
= BT_CTF_TRUE
;
1148 struct extend_map_element_data
*extend_data
= data
;
1149 struct bt_ctf_private_value
*extension_obj_elem_copy
= NULL
;
1151 /* Copy object which is to replace the current one */
1152 extend_data
->status
= bt_ctf_value_copy(&extension_obj_elem_copy
,
1153 extension_obj_elem
);
1154 if (extend_data
->status
) {
1155 BT_LOGE("Cannot copy map element: addr=%p",
1156 extension_obj_elem
);
1160 BT_ASSERT_DBG(extension_obj_elem_copy
);
1162 /* Replace in extended object */
1163 extend_data
->status
= bt_ctf_private_value_map_insert_entry(
1164 extend_data
->extended_obj
, key
,
1165 (void *) extension_obj_elem_copy
);
1166 if (extend_data
->status
) {
1167 BT_LOGE("Cannot replace value in extended value: key=\"%s\", "
1168 "extended-value-addr=%p, element-value-addr=%p",
1169 key
, extend_data
->extended_obj
,
1170 extension_obj_elem_copy
);
1177 BT_ASSERT_DBG(extend_data
->status
!= BT_CTF_VALUE_STATUS_OK
);
1181 BT_CTF_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1185 enum bt_ctf_value_status
bt_ctf_value_map_extend(
1186 struct bt_ctf_private_value
**extended_map_obj
,
1187 const struct bt_ctf_value
*base_map_obj
,
1188 const struct bt_ctf_value
*extension_obj
)
1190 struct extend_map_element_data extend_data
= {
1191 .extended_obj
= NULL
,
1192 .status
= BT_CTF_VALUE_STATUS_OK
,
1195 BT_CTF_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1196 BT_CTF_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1197 BT_CTF_ASSERT_PRE_NON_NULL(extended_map_obj
,
1198 "Extended value object (output)");
1199 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1200 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_CTF_VALUE_TYPE_MAP
);
1201 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1202 base_map_obj
, extension_obj
);
1203 *extended_map_obj
= NULL
;
1205 /* Create copy of base map object to start with */
1206 extend_data
.status
= bt_ctf_value_copy(extended_map_obj
, base_map_obj
);
1207 if (extend_data
.status
) {
1208 BT_LOGE("Cannot copy base value: base-value-addr=%p",
1213 BT_ASSERT_DBG(extended_map_obj
);
1216 * For each key in the extension map object, replace this key
1217 * in the copied map object.
1219 extend_data
.extended_obj
= *extended_map_obj
;
1221 if (bt_ctf_value_map_foreach_entry(extension_obj
, extend_map_element
,
1223 BT_LOGE("Cannot iterate on the extension object's elements: "
1224 "extension-value-addr=%p", extension_obj
);
1228 if (extend_data
.status
) {
1229 BT_LOGE("Failed to successfully iterate on the extension object's elements: "
1230 "extension-value-addr=%p", extension_obj
);
1234 BT_LOGD("Extended map value: extended-value-addr=%p",
1239 BT_CTF_OBJECT_PUT_REF_AND_RESET(*extended_map_obj
);
1240 *extended_map_obj
= NULL
;
1243 return extend_data
.status
;
1246 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy_obj
,
1247 const struct bt_ctf_value
*object
)
1249 enum bt_ctf_value_status status
= BT_CTF_VALUE_STATUS_OK
;
1251 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
1252 BT_CTF_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1253 BT_LOGD("Copying value object: addr=%p", object
);
1254 *copy_obj
= copy_funcs
[object
->type
](object
);
1256 BT_LOGD("Copied value object: copy-value-addr=%p",
1259 status
= BT_CTF_VALUE_STATUS_NOMEM
;
1261 BT_LOGE_STR("Failed to copy value object.");
1267 bt_ctf_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
1268 const struct bt_ctf_value
*object_b
)
1270 bt_ctf_bool ret
= BT_CTF_FALSE
;
1272 BT_CTF_ASSERT_PRE_NON_NULL(object_a
, "Value object A");
1273 BT_CTF_ASSERT_PRE_NON_NULL(object_b
, "Value object B");
1275 if (object_a
->type
!= object_b
->type
) {
1276 BT_LOGT("Values are different: type mismatch: "
1277 "value-a-addr=%p, value-b-addr=%p, "
1278 "value-a-type=%d, value-b-type=%d",
1279 object_a
, object_b
, object_a
->type
, object_b
->type
);
1283 ret
= compare_funcs
[object_a
->type
](object_a
, object_b
);