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
,
73 struct bt_ctf_value
*const bt_ctf_value_null
= &bt_ctf_value_null_instance
;
74 struct bt_ctf_private_value
*const bt_ctf_private_value_null
=
75 (void *) &bt_ctf_value_null_instance
;
77 struct bt_ctf_value_bool
{
78 struct bt_ctf_value base
;
82 struct bt_ctf_value_integer
{
83 struct bt_ctf_value base
;
87 struct bt_ctf_value_real
{
88 struct bt_ctf_value base
;
92 struct bt_ctf_value_string
{
93 struct bt_ctf_value base
;
97 struct bt_ctf_value_array
{
98 struct bt_ctf_value base
;
102 struct bt_ctf_value_map
{
103 struct bt_ctf_value base
;
108 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
);
111 void bt_ctf_value_string_destroy(struct bt_ctf_value
*object
)
113 g_string_free(BT_CTF_VALUE_TO_STRING(object
)->gstr
, TRUE
);
114 BT_CTF_VALUE_TO_STRING(object
)->gstr
= NULL
;
118 void bt_ctf_value_array_destroy(struct bt_ctf_value
*object
)
121 * Pointer array's registered value destructor will take care
122 * of putting each contained object.
124 g_ptr_array_free(BT_CTF_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
125 BT_CTF_VALUE_TO_ARRAY(object
)->garray
= NULL
;
129 void bt_ctf_value_map_destroy(struct bt_ctf_value
*object
)
132 * Hash table's registered value destructor will take care of
133 * putting each contained object. Keys are GQuarks and cannot
134 * be destroyed anyway.
136 g_hash_table_destroy(BT_CTF_VALUE_TO_MAP(object
)->ght
);
137 BT_CTF_VALUE_TO_MAP(object
)->ght
= NULL
;
141 void (* const destroy_funcs
[])(struct bt_ctf_value
*) = {
142 [BT_CTF_VALUE_TYPE_NULL
] = NULL
,
143 [BT_CTF_VALUE_TYPE_BOOL
] = NULL
,
144 [BT_CTF_VALUE_TYPE_INTEGER
] = NULL
,
145 [BT_CTF_VALUE_TYPE_REAL
] = NULL
,
146 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_destroy
,
147 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_destroy
,
148 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_destroy
,
152 struct bt_ctf_private_value
*bt_ctf_value_null_copy(const struct bt_ctf_value
*null_obj
)
154 return (void *) bt_ctf_value_null
;
158 struct bt_ctf_private_value
*bt_ctf_value_bool_copy(const struct bt_ctf_value
*bool_obj
)
160 return bt_ctf_private_value_bool_create_init(
161 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
);
165 struct bt_ctf_private_value
*bt_ctf_value_integer_copy(
166 const struct bt_ctf_value
*integer_obj
)
168 return bt_ctf_private_value_integer_create_init(
169 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
);
173 struct bt_ctf_private_value
*bt_ctf_value_real_copy(const struct bt_ctf_value
*real_obj
)
175 return bt_ctf_private_value_real_create_init(
176 BT_CTF_VALUE_TO_REAL(real_obj
)->value
);
180 struct bt_ctf_private_value
*bt_ctf_value_string_copy(const struct bt_ctf_value
*string_obj
)
182 return bt_ctf_private_value_string_create_init(
183 BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
);
187 struct bt_ctf_private_value
*bt_ctf_value_array_copy(const struct bt_ctf_value
*array_obj
)
191 struct bt_ctf_private_value
*copy_obj
;
192 struct bt_ctf_value_array
*typed_array_obj
;
194 BT_LOGD("Copying array value: addr=%p", array_obj
);
195 typed_array_obj
= BT_CTF_VALUE_TO_ARRAY(array_obj
);
196 copy_obj
= bt_ctf_private_value_array_create();
198 BT_LOGE_STR("Cannot create empty array value.");
202 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
203 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
204 struct bt_ctf_value
*element_obj
=
205 bt_ctf_value_array_borrow_element_by_index(
208 BT_ASSERT_DBG(element_obj
);
209 BT_LOGD("Copying array value's element: element-addr=%p, "
210 "index=%d", element_obj
, i
);
211 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
213 BT_LOGE("Cannot copy array value's element: "
214 "array-addr=%p, index=%d",
216 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
220 BT_ASSERT_DBG(element_obj_copy
);
221 ret
= bt_ctf_private_value_array_append_element(copy_obj
,
222 (void *) element_obj_copy
);
223 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
225 BT_LOGE("Cannot append to array value: addr=%p",
227 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
232 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
233 array_obj
, copy_obj
);
240 struct bt_ctf_private_value
*bt_ctf_value_map_copy(const struct bt_ctf_value
*map_obj
)
244 gpointer key
, element_obj
;
245 struct bt_ctf_private_value
*copy_obj
;
246 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
247 struct bt_ctf_value_map
*typed_map_obj
;
249 BT_LOGD("Copying map value: addr=%p", map_obj
);
250 typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
251 copy_obj
= bt_ctf_private_value_map_create();
256 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
258 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
259 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
261 BT_ASSERT_DBG(key_str
);
262 BT_LOGD("Copying map value's element: element-addr=%p, "
263 "key=\"%s\"", element_obj
, key_str
);
264 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
266 BT_LOGE("Cannot copy map value's element: "
267 "map-addr=%p, key=\"%s\"",
269 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
273 BT_ASSERT_DBG(element_obj_copy
);
274 ret
= bt_ctf_private_value_map_insert_entry(copy_obj
, key_str
,
275 (void *) element_obj_copy
);
276 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
278 BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"",
280 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
285 BT_LOGD("Copied map value: addr=%p", map_obj
);
292 struct bt_ctf_private_value
*(* const copy_funcs
[])(const struct bt_ctf_value
*) = {
293 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_copy
,
294 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_copy
,
295 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_copy
,
296 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_copy
,
297 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_copy
,
298 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_copy
,
299 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_copy
,
303 bt_ctf_bool
bt_ctf_value_null_compare(const struct bt_ctf_value
*object_a
,
304 const struct bt_ctf_value
*object_b
)
307 * Always BT_CTF_TRUE since bt_ctf_value_compare() already checks if both
308 * object_a and object_b have the same type, and in the case of
309 * null value objects, they're always the same if it is so.
315 bt_ctf_bool
bt_ctf_value_bool_compare(const struct bt_ctf_value
*object_a
,
316 const struct bt_ctf_value
*object_b
)
318 if (BT_CTF_VALUE_TO_BOOL(object_a
)->value
!=
319 BT_CTF_VALUE_TO_BOOL(object_b
)->value
) {
320 BT_LOGT("Boolean value objects are different: "
321 "bool-a-val=%d, bool-b-val=%d",
322 BT_CTF_VALUE_TO_BOOL(object_a
)->value
,
323 BT_CTF_VALUE_TO_BOOL(object_b
)->value
);
331 bt_ctf_bool
bt_ctf_value_integer_compare(const struct bt_ctf_value
*object_a
,
332 const struct bt_ctf_value
*object_b
)
334 if (BT_CTF_VALUE_TO_INTEGER(object_a
)->value
!=
335 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
) {
336 BT_LOGT("Integer value objects are different: "
337 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
338 BT_CTF_VALUE_TO_INTEGER(object_a
)->value
,
339 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
);
347 bt_ctf_bool
bt_ctf_value_real_compare(const struct bt_ctf_value
*object_a
,
348 const struct bt_ctf_value
*object_b
)
350 if (BT_CTF_VALUE_TO_REAL(object_a
)->value
!=
351 BT_CTF_VALUE_TO_REAL(object_b
)->value
) {
352 BT_LOGT("Real number value objects are different: "
353 "real-a-val=%f, real-b-val=%f",
354 BT_CTF_VALUE_TO_REAL(object_a
)->value
,
355 BT_CTF_VALUE_TO_REAL(object_b
)->value
);
363 bt_ctf_bool
bt_ctf_value_string_compare(const struct bt_ctf_value
*object_a
,
364 const struct bt_ctf_value
*object_b
)
366 if (strcmp(BT_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
367 BT_CTF_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
368 BT_LOGT("String value objects are different: "
369 "string-a-val=\"%s\", string-b-val=\"%s\"",
370 BT_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
371 BT_CTF_VALUE_TO_STRING(object_b
)->gstr
->str
);
379 bt_ctf_bool
bt_ctf_value_array_compare(const struct bt_ctf_value
*object_a
,
380 const struct bt_ctf_value
*object_b
)
383 bt_ctf_bool ret
= BT_CTF_TRUE
;
384 const struct bt_ctf_value_array
*array_obj_a
=
385 BT_CTF_VALUE_TO_ARRAY(object_a
);
387 if (bt_ctf_value_array_get_length(object_a
) !=
388 bt_ctf_value_array_get_length(object_b
)) {
389 BT_LOGT("Array values are different: size mismatch "
390 "value-a-addr=%p, value-b-addr=%p, "
391 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
393 bt_ctf_value_array_get_length(object_a
),
394 bt_ctf_value_array_get_length(object_b
));
399 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
400 struct bt_ctf_value
*element_obj_a
;
401 struct bt_ctf_value
*element_obj_b
;
403 element_obj_a
= bt_ctf_value_array_borrow_element_by_index(
405 element_obj_b
= bt_ctf_value_array_borrow_element_by_index(
408 if (!bt_ctf_value_compare(element_obj_a
, element_obj_b
)) {
409 BT_LOGT("Array values's elements are different: "
410 "value-a-addr=%p, value-b-addr=%p, index=%d",
411 element_obj_a
, element_obj_b
, i
);
422 bt_ctf_bool
bt_ctf_value_map_compare(const struct bt_ctf_value
*object_a
,
423 const struct bt_ctf_value
*object_b
)
425 bt_ctf_bool ret
= BT_CTF_TRUE
;
427 gpointer key
, element_obj_a
;
428 const struct bt_ctf_value_map
*map_obj_a
= BT_CTF_VALUE_TO_MAP(object_a
);
430 if (bt_ctf_value_map_get_size(object_a
) !=
431 bt_ctf_value_map_get_size(object_b
)) {
432 BT_LOGT("Map values are different: size mismatch "
433 "value-a-addr=%p, value-b-addr=%p, "
434 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
436 bt_ctf_value_map_get_size(object_a
),
437 bt_ctf_value_map_get_size(object_b
));
442 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
444 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
445 struct bt_ctf_value
*element_obj_b
;
446 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
448 element_obj_b
= bt_ctf_value_map_borrow_entry_value(object_b
,
451 if (!bt_ctf_value_compare(element_obj_a
, element_obj_b
)) {
452 BT_LOGT("Map values's elements are different: "
453 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
454 element_obj_a
, element_obj_b
, key_str
);
465 bt_ctf_bool (* const compare_funcs
[])(const struct bt_ctf_value
*,
466 const struct bt_ctf_value
*) = {
467 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_compare
,
468 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_compare
,
469 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_compare
,
470 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_compare
,
471 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_compare
,
472 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_compare
,
473 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_compare
,
477 void bt_ctf_value_null_freeze(struct bt_ctf_value
*object
)
482 void bt_ctf_value_generic_freeze(struct bt_ctf_value
*object
)
484 object
->frozen
= BT_CTF_TRUE
;
488 void bt_ctf_value_array_freeze(struct bt_ctf_value
*object
)
491 struct bt_ctf_value_array
*typed_array_obj
=
492 BT_CTF_VALUE_TO_ARRAY(object
);
494 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
495 bt_ctf_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
498 bt_ctf_value_generic_freeze(object
);
502 void bt_ctf_value_map_freeze(struct bt_ctf_value
*object
)
505 gpointer key
, element_obj
;
506 const struct bt_ctf_value_map
*map_obj
= BT_CTF_VALUE_TO_MAP(object
);
508 g_hash_table_iter_init(&iter
, map_obj
->ght
);
510 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
511 bt_ctf_value_freeze(element_obj
);
514 bt_ctf_value_generic_freeze(object
);
518 void (* const freeze_funcs
[])(struct bt_ctf_value
*) = {
519 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_freeze
,
520 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_generic_freeze
,
521 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_generic_freeze
,
522 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_generic_freeze
,
523 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_generic_freeze
,
524 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_freeze
,
525 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_freeze
,
529 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
)
531 struct bt_ctf_value
*value
;
533 value
= container_of(obj
, struct bt_ctf_value
, base
);
534 BT_LOGD("Destroying value: addr=%p", value
);
536 if (bt_ctf_value_is_null(value
)) {
537 BT_LOGD_STR("Not destroying the null value singleton.");
541 if (destroy_funcs
[value
->type
]) {
542 destroy_funcs
[value
->type
](value
);
549 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
)
551 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
553 BT_ASSERT_DBG(object
);
555 if (object
->frozen
) {
559 BT_LOGD("Freezing value: addr=%p", object
);
560 freeze_funcs
[object
->type
](object
);
567 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
)
569 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
574 struct bt_ctf_value
bt_ctf_value_create_base(enum bt_ctf_value_type type
)
576 struct bt_ctf_value value
;
579 value
.frozen
= BT_CTF_FALSE
;
580 bt_ctf_object_init_shared(&value
.base
, bt_ctf_value_destroy
);
585 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_ctf_bool val
)
587 struct bt_ctf_value_bool
*bool_obj
;
589 BT_LOGD("Creating boolean value object: val=%d", val
);
590 bool_obj
= g_new0(struct bt_ctf_value_bool
, 1);
592 BT_LOGE_STR("Failed to allocate one boolean value object.");
596 bool_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_BOOL
);
597 bool_obj
->value
= val
;
598 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
601 return (void *) BT_CTF_VALUE_FROM_CONCRETE(bool_obj
);
605 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create(void)
607 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
);
632 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void)
634 return bt_ctf_private_value_integer_create_init(0);
638 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
)
640 struct bt_ctf_value_real
*real_obj
;
642 BT_LOGD("Creating real number value object: val=%f", val
);
643 real_obj
= g_new0(struct bt_ctf_value_real
, 1);
645 BT_LOGE_STR("Failed to allocate one real number value object.");
649 real_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_REAL
);
650 real_obj
->value
= val
;
651 BT_LOGD("Created real number value object: addr=%p",
655 return (void *) BT_CTF_VALUE_FROM_CONCRETE(real_obj
);
659 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void)
661 return bt_ctf_private_value_real_create_init(0.);
665 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(const char *val
)
667 struct bt_ctf_value_string
*string_obj
= NULL
;
670 BT_LOGW_STR("Invalid parameter: value is NULL.");
674 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
675 string_obj
= g_new0(struct bt_ctf_value_string
, 1);
677 BT_LOGE_STR("Failed to allocate one string object.");
681 string_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_STRING
);
682 string_obj
->gstr
= g_string_new(val
);
683 if (!string_obj
->gstr
) {
684 BT_LOGE_STR("Failed to allocate a GString.");
690 BT_LOGD("Created string value object: addr=%p",
694 return (void *) BT_CTF_VALUE_FROM_CONCRETE(string_obj
);
698 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void)
700 return bt_ctf_private_value_string_create_init("");
704 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void)
706 struct bt_ctf_value_array
*array_obj
;
708 BT_LOGD_STR("Creating empty array value object.");
709 array_obj
= g_new0(struct bt_ctf_value_array
, 1);
711 BT_LOGE_STR("Failed to allocate one array object.");
715 array_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_ARRAY
);
716 array_obj
->garray
= bt_g_ptr_array_new_full(0,
717 (GDestroyNotify
) bt_ctf_object_put_ref
);
718 if (!array_obj
->garray
) {
719 BT_LOGE_STR("Failed to allocate a GPtrArray.");
725 BT_LOGD("Created array value object: addr=%p",
729 return (void *) BT_CTF_VALUE_FROM_CONCRETE(array_obj
);
733 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void)
735 struct bt_ctf_value_map
*map_obj
;
737 BT_LOGD_STR("Creating empty map value object.");
738 map_obj
= g_new0(struct bt_ctf_value_map
, 1);
740 BT_LOGE_STR("Failed to allocate one map object.");
744 map_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_MAP
);
745 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
746 NULL
, (GDestroyNotify
) bt_ctf_object_put_ref
);
748 BT_LOGE_STR("Failed to allocate a GHashTable.");
754 BT_LOGD("Created map value object: addr=%p",
758 return (void *) BT_CTF_VALUE_FROM_CONCRETE(map_obj
);
762 bt_ctf_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
)
764 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
765 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
766 return BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
;
770 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
, bt_ctf_bool val
)
772 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
773 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
774 BT_CTF_ASSERT_PRE_VALUE_HOT(bool_obj
, "Value object");
775 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
= val
;
776 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
781 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
)
783 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
784 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
785 return BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
;
789 void bt_ctf_private_value_integer_set(struct bt_ctf_private_value
*integer_obj
,
792 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
793 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
794 BT_CTF_ASSERT_PRE_VALUE_HOT(integer_obj
, "Value object");
795 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
= val
;
796 BT_LOGT("Set integer value's raw value: value-addr=%p, value=%" PRId64
,
801 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
)
803 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
804 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
805 return BT_CTF_VALUE_TO_REAL(real_obj
)->value
;
809 void bt_ctf_private_value_real_set(struct bt_ctf_private_value
*real_obj
, double val
)
811 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
812 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
813 BT_CTF_ASSERT_PRE_VALUE_HOT(real_obj
, "Value object");
814 BT_CTF_VALUE_TO_REAL(real_obj
)->value
= val
;
815 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
820 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
)
822 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
823 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
824 return BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
;
828 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
829 struct bt_ctf_private_value
*string_obj
, const char *val
)
831 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
832 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
833 BT_CTF_ASSERT_PRE_VALUE_HOT(string_obj
, "Value object");
834 g_string_assign(BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
, val
);
835 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
837 return BT_CTF_VALUE_STATUS_OK
;
841 uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value
*array_obj
)
843 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
844 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
845 return (uint64_t) BT_CTF_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
849 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
850 const struct bt_ctf_value
*array_obj
,
853 struct bt_ctf_value_array
*typed_array_obj
=
854 BT_CTF_VALUE_TO_ARRAY(array_obj
);
856 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
857 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
858 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
859 typed_array_obj
->garray
->len
);
860 return g_ptr_array_index(typed_array_obj
->garray
, index
);
864 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
865 const struct bt_ctf_private_value
*array_obj
,
868 return (void *) bt_ctf_value_array_borrow_element_by_index(
869 (void *) array_obj
, index
);
873 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
874 struct bt_ctf_private_value
*array_obj
,
875 struct bt_ctf_value
*element_obj
)
877 struct bt_ctf_value_array
*typed_array_obj
=
878 BT_CTF_VALUE_TO_ARRAY(array_obj
);
880 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
881 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
882 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
883 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
884 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
885 bt_ctf_object_get_ref(element_obj
);
886 BT_LOGT("Appended element to array value: array-value-addr=%p, "
887 "element-value-addr=%p, new-size=%u",
888 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
889 return BT_CTF_VALUE_STATUS_OK
;
893 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
894 struct bt_ctf_private_value
*array_obj
, bt_ctf_bool val
)
896 enum bt_ctf_value_status ret
;
897 struct bt_ctf_private_value
*bool_obj
= NULL
;
899 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
900 ret
= bt_ctf_private_value_array_append_element(array_obj
,
902 bt_ctf_object_put_ref(bool_obj
);
907 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
908 struct bt_ctf_private_value
*array_obj
, int64_t val
)
910 enum bt_ctf_value_status ret
;
911 struct bt_ctf_private_value
*integer_obj
= NULL
;
913 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
914 ret
= bt_ctf_private_value_array_append_element(array_obj
,
915 (void *) integer_obj
);
916 bt_ctf_object_put_ref(integer_obj
);
921 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
922 struct bt_ctf_private_value
*array_obj
, double val
)
924 enum bt_ctf_value_status ret
;
925 struct bt_ctf_private_value
*real_obj
= NULL
;
927 real_obj
= bt_ctf_private_value_real_create_init(val
);
928 ret
= bt_ctf_private_value_array_append_element(array_obj
,
930 bt_ctf_object_put_ref(real_obj
);
935 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
936 struct bt_ctf_private_value
*array_obj
, const char *val
)
938 enum bt_ctf_value_status ret
;
939 struct bt_ctf_private_value
*string_obj
= NULL
;
941 string_obj
= bt_ctf_private_value_string_create_init(val
);
942 ret
= bt_ctf_private_value_array_append_element(array_obj
,
943 (void *) string_obj
);
944 bt_ctf_object_put_ref(string_obj
);
949 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
950 struct bt_ctf_private_value
*array_obj
)
952 enum bt_ctf_value_status ret
;
953 struct bt_ctf_private_value
*empty_array_obj
= NULL
;
955 empty_array_obj
= bt_ctf_private_value_array_create();
956 ret
= bt_ctf_private_value_array_append_element(array_obj
,
957 (void *) empty_array_obj
);
958 bt_ctf_object_put_ref(empty_array_obj
);
963 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
964 struct bt_ctf_private_value
*array_obj
)
966 enum bt_ctf_value_status ret
;
967 struct bt_ctf_private_value
*map_obj
= NULL
;
969 map_obj
= bt_ctf_private_value_map_create();
970 ret
= bt_ctf_private_value_array_append_element(array_obj
,
972 bt_ctf_object_put_ref(map_obj
);
977 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
978 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
979 struct bt_ctf_value
*element_obj
)
981 struct bt_ctf_value_array
*typed_array_obj
=
982 BT_CTF_VALUE_TO_ARRAY(array_obj
);
984 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
985 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
986 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
987 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
988 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
989 typed_array_obj
->garray
->len
);
990 bt_ctf_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
991 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
992 bt_ctf_object_get_ref(element_obj
);
993 BT_LOGT("Set array value's element: array-value-addr=%p, "
994 "index=%" PRIu64
", element-value-addr=%p",
995 array_obj
, index
, element_obj
);
996 return BT_CTF_VALUE_STATUS_OK
;
1000 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
)
1002 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1003 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1004 return (uint64_t) g_hash_table_size(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
);
1008 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(const struct bt_ctf_value
*map_obj
,
1011 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1012 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1013 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1014 return g_hash_table_lookup(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1015 GUINT_TO_POINTER(g_quark_from_string(key
)));
1019 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
1020 const struct bt_ctf_private_value
*map_obj
, const char *key
)
1022 return (void *) bt_ctf_value_map_borrow_entry_value((void *) map_obj
, key
);
1026 bt_ctf_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
, const char *key
)
1028 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1029 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1030 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1031 return bt_g_hash_table_contains(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1032 GUINT_TO_POINTER(g_quark_from_string(key
)));
1036 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
1037 struct bt_ctf_private_value
*map_obj
,
1038 const char *key
, struct bt_ctf_value
*element_obj
)
1040 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1041 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1042 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1043 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1044 BT_CTF_ASSERT_PRE_VALUE_HOT(map_obj
, "Map value object");
1045 g_hash_table_insert(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1046 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1047 bt_ctf_object_get_ref(element_obj
);
1048 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1049 "key=\"%s\", element-value-addr=%p",
1050 map_obj
, key
, element_obj
);
1051 return BT_CTF_VALUE_STATUS_OK
;
1055 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
1056 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_ctf_bool val
)
1058 enum bt_ctf_value_status ret
;
1059 struct bt_ctf_private_value
*bool_obj
= NULL
;
1061 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
1062 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1064 bt_ctf_object_put_ref(bool_obj
);
1069 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
1070 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
)
1072 enum bt_ctf_value_status ret
;
1073 struct bt_ctf_private_value
*integer_obj
= NULL
;
1075 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
1076 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1077 (void *) integer_obj
);
1078 bt_ctf_object_put_ref(integer_obj
);
1083 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
1084 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
)
1086 enum bt_ctf_value_status ret
;
1087 struct bt_ctf_private_value
*real_obj
= NULL
;
1089 real_obj
= bt_ctf_private_value_real_create_init(val
);
1090 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1092 bt_ctf_object_put_ref(real_obj
);
1097 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
1098 struct bt_ctf_private_value
*map_obj
, const char *key
,
1101 enum bt_ctf_value_status ret
;
1102 struct bt_ctf_private_value
*string_obj
= NULL
;
1104 string_obj
= bt_ctf_private_value_string_create_init(val
);
1105 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1106 (void *) string_obj
);
1107 bt_ctf_object_put_ref(string_obj
);
1112 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
1113 struct bt_ctf_private_value
*map_obj
, const char *key
)
1115 enum bt_ctf_value_status ret
;
1116 struct bt_ctf_private_value
*array_obj
= NULL
;
1118 array_obj
= bt_ctf_private_value_array_create();
1119 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1120 (void *) array_obj
);
1121 bt_ctf_object_put_ref(array_obj
);
1126 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
1127 struct bt_ctf_private_value
*map_obj
, const char *key
)
1129 enum bt_ctf_value_status ret
;
1130 struct bt_ctf_private_value
*empty_map_obj
= NULL
;
1132 empty_map_obj
= bt_ctf_private_value_map_create();
1133 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1134 (void *) empty_map_obj
);
1135 bt_ctf_object_put_ref(empty_map_obj
);
1140 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(const struct bt_ctf_value
*map_obj
,
1141 bt_ctf_value_map_foreach_entry_cb cb
, void *data
)
1143 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
1144 gpointer key
, element_obj
;
1145 GHashTableIter iter
;
1146 struct bt_ctf_value_map
*typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
1148 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1149 BT_CTF_ASSERT_PRE_NON_NULL(cb
, "Callback");
1150 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1151 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1153 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1154 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1156 if (!cb(key_str
, element_obj
, data
)) {
1157 BT_LOGT("User canceled the loop: key=\"%s\", "
1158 "value-addr=%p, data=%p",
1159 key_str
, element_obj
, data
);
1160 ret
= BT_CTF_VALUE_STATUS_CANCELED
;
1169 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
1170 const struct bt_ctf_private_value
*map_obj
,
1171 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
)
1173 return bt_ctf_value_map_foreach_entry((void *) map_obj
,
1174 (bt_ctf_value_map_foreach_entry_cb
) cb
, data
);
1177 struct extend_map_element_data
{
1178 struct bt_ctf_private_value
*extended_obj
;
1179 enum bt_ctf_value_status status
;
1183 bt_ctf_bool
extend_map_element(const char *key
,
1184 struct bt_ctf_value
*extension_obj_elem
, void *data
)
1186 bt_ctf_bool ret
= BT_CTF_TRUE
;
1187 struct extend_map_element_data
*extend_data
= data
;
1188 struct bt_ctf_private_value
*extension_obj_elem_copy
= NULL
;
1190 /* Copy object which is to replace the current one */
1191 extend_data
->status
= bt_ctf_value_copy(&extension_obj_elem_copy
,
1192 extension_obj_elem
);
1193 if (extend_data
->status
) {
1194 BT_LOGE("Cannot copy map element: addr=%p",
1195 extension_obj_elem
);
1199 BT_ASSERT_DBG(extension_obj_elem_copy
);
1201 /* Replace in extended object */
1202 extend_data
->status
= bt_ctf_private_value_map_insert_entry(
1203 extend_data
->extended_obj
, key
,
1204 (void *) extension_obj_elem_copy
);
1205 if (extend_data
->status
) {
1206 BT_LOGE("Cannot replace value in extended value: key=\"%s\", "
1207 "extended-value-addr=%p, element-value-addr=%p",
1208 key
, extend_data
->extended_obj
,
1209 extension_obj_elem_copy
);
1216 BT_ASSERT_DBG(extend_data
->status
!= BT_CTF_VALUE_STATUS_OK
);
1220 BT_CTF_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1225 enum bt_ctf_value_status
bt_ctf_value_map_extend(
1226 struct bt_ctf_private_value
**extended_map_obj
,
1227 const struct bt_ctf_value
*base_map_obj
,
1228 const struct bt_ctf_value
*extension_obj
)
1230 struct extend_map_element_data extend_data
= {
1231 .extended_obj
= NULL
,
1232 .status
= BT_CTF_VALUE_STATUS_OK
,
1235 BT_CTF_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1236 BT_CTF_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1237 BT_CTF_ASSERT_PRE_NON_NULL(extended_map_obj
,
1238 "Extended value object (output)");
1239 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1240 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_CTF_VALUE_TYPE_MAP
);
1241 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1242 base_map_obj
, extension_obj
);
1243 *extended_map_obj
= NULL
;
1245 /* Create copy of base map object to start with */
1246 extend_data
.status
= bt_ctf_value_copy(extended_map_obj
, base_map_obj
);
1247 if (extend_data
.status
) {
1248 BT_LOGE("Cannot copy base value: base-value-addr=%p",
1253 BT_ASSERT_DBG(extended_map_obj
);
1256 * For each key in the extension map object, replace this key
1257 * in the copied map object.
1259 extend_data
.extended_obj
= *extended_map_obj
;
1261 if (bt_ctf_value_map_foreach_entry(extension_obj
, extend_map_element
,
1263 BT_LOGE("Cannot iterate on the extension object's elements: "
1264 "extension-value-addr=%p", extension_obj
);
1268 if (extend_data
.status
) {
1269 BT_LOGE("Failed to successfully iterate on the extension object's elements: "
1270 "extension-value-addr=%p", extension_obj
);
1274 BT_LOGD("Extended map value: extended-value-addr=%p",
1279 BT_CTF_OBJECT_PUT_REF_AND_RESET(*extended_map_obj
);
1280 *extended_map_obj
= NULL
;
1283 return extend_data
.status
;
1287 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy_obj
,
1288 const struct bt_ctf_value
*object
)
1290 enum bt_ctf_value_status status
= BT_CTF_VALUE_STATUS_OK
;
1292 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
1293 BT_CTF_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1294 BT_LOGD("Copying value object: addr=%p", object
);
1295 *copy_obj
= copy_funcs
[object
->type
](object
);
1297 BT_LOGD("Copied value object: copy-value-addr=%p",
1300 status
= BT_CTF_VALUE_STATUS_NOMEM
;
1302 BT_LOGE_STR("Failed to copy value object.");
1309 bt_ctf_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
1310 const struct bt_ctf_value
*object_b
)
1312 bt_ctf_bool ret
= BT_CTF_FALSE
;
1314 BT_CTF_ASSERT_PRE_NON_NULL(object_a
, "Value object A");
1315 BT_CTF_ASSERT_PRE_NON_NULL(object_b
, "Value object B");
1317 if (object_a
->type
!= object_b
->type
) {
1318 BT_LOGT("Values are different: type mismatch: "
1319 "value-a-addr=%p, value-b-addr=%p, "
1320 "value-a-type=%d, value-b-type=%d",
1321 object_a
, object_b
, object_a
->type
, object_b
->type
);
1325 ret
= compare_funcs
[object_a
->type
](object_a
, object_b
);