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>
17 #include "common/assert.h"
18 #include "common/common.h"
19 #include "compat/compiler.h"
20 #include "compat/glib.h"
22 #include "assert-pre.h"
26 #define BT_CTF_VALUE_FROM_CONCRETE(_concrete) ((struct bt_ctf_value *) (_concrete))
27 #define BT_CTF_VALUE_TO_BOOL(_base) ((struct bt_ctf_value_bool *) (_base))
28 #define BT_CTF_VALUE_TO_INTEGER(_base) ((struct bt_ctf_value_integer *) (_base))
29 #define BT_CTF_VALUE_TO_REAL(_base) ((struct bt_ctf_value_real *) (_base))
30 #define BT_CTF_VALUE_TO_STRING(_base) ((struct bt_ctf_value_string *) (_base))
31 #define BT_CTF_VALUE_TO_ARRAY(_base) ((struct bt_ctf_value_array *) (_base))
32 #define BT_CTF_VALUE_TO_MAP(_base) ((struct bt_ctf_value_map *) (_base))
34 #define BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
35 BT_CTF_ASSERT_PRE(((struct bt_ctf_value *) (_value))->type == (_type), \
36 "Value has the wrong type ID: expected-type=%d", (_type))
38 #define BT_CTF_ASSERT_PRE_VALUE_HOT(_value, _name) \
39 BT_CTF_ASSERT_PRE_HOT(((struct bt_ctf_value *) (_value)), (_name), "")
41 #define BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count) \
42 BT_CTF_ASSERT_PRE((_index) < (_count), \
43 "Index is out of bound: " \
44 "index=%" PRIu64 ", count=%u", (_index), (_count));
47 struct bt_ctf_object base
;
48 enum bt_ctf_value_type type
;
53 void bt_ctf_value_null_instance_release_func(struct bt_ctf_object
*obj
)
55 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
59 struct bt_ctf_value bt_ctf_value_null_instance
= {
63 .release_func
= bt_ctf_value_null_instance_release_func
,
64 .spec_release_func
= NULL
,
65 .parent_is_owner_listener_func
= NULL
,
68 .type
= BT_CTF_VALUE_TYPE_NULL
,
69 .frozen
= BT_CTF_TRUE
,
73 struct bt_ctf_value
*const bt_ctf_value_null
= &bt_ctf_value_null_instance
;
76 struct bt_ctf_private_value
*const bt_ctf_private_value_null
=
77 (void *) &bt_ctf_value_null_instance
;
79 struct bt_ctf_value_bool
{
80 struct bt_ctf_value base
;
84 struct bt_ctf_value_integer
{
85 struct bt_ctf_value base
;
89 struct bt_ctf_value_real
{
90 struct bt_ctf_value base
;
94 struct bt_ctf_value_string
{
95 struct bt_ctf_value base
;
99 struct bt_ctf_value_array
{
100 struct bt_ctf_value base
;
104 struct bt_ctf_value_map
{
105 struct bt_ctf_value base
;
110 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
);
113 void bt_ctf_value_string_destroy(struct bt_ctf_value
*object
)
115 g_string_free(BT_CTF_VALUE_TO_STRING(object
)->gstr
, TRUE
);
116 BT_CTF_VALUE_TO_STRING(object
)->gstr
= NULL
;
120 void bt_ctf_value_array_destroy(struct bt_ctf_value
*object
)
123 * Pointer array's registered value destructor will take care
124 * of putting each contained object.
126 g_ptr_array_free(BT_CTF_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
127 BT_CTF_VALUE_TO_ARRAY(object
)->garray
= NULL
;
131 void bt_ctf_value_map_destroy(struct bt_ctf_value
*object
)
134 * Hash table's registered value destructor will take care of
135 * putting each contained object. Keys are GQuarks and cannot
136 * be destroyed anyway.
138 g_hash_table_destroy(BT_CTF_VALUE_TO_MAP(object
)->ght
);
139 BT_CTF_VALUE_TO_MAP(object
)->ght
= NULL
;
143 void (* const destroy_funcs
[])(struct bt_ctf_value
*) = {
144 [BT_CTF_VALUE_TYPE_NULL
] = NULL
,
145 [BT_CTF_VALUE_TYPE_BOOL
] = NULL
,
146 [BT_CTF_VALUE_TYPE_INTEGER
] = NULL
,
147 [BT_CTF_VALUE_TYPE_REAL
] = NULL
,
148 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_destroy
,
149 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_destroy
,
150 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_destroy
,
154 struct bt_ctf_private_value
*bt_ctf_value_null_copy(
155 const struct bt_ctf_value
*null_obj
__attribute__((unused
)))
157 return (void *) bt_ctf_value_null
;
161 struct bt_ctf_private_value
*bt_ctf_value_bool_copy(const struct bt_ctf_value
*bool_obj
)
163 return bt_ctf_private_value_bool_create_init(
164 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
);
168 struct bt_ctf_private_value
*bt_ctf_value_integer_copy(
169 const struct bt_ctf_value
*integer_obj
)
171 return bt_ctf_private_value_integer_create_init(
172 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
);
176 struct bt_ctf_private_value
*bt_ctf_value_real_copy(const struct bt_ctf_value
*real_obj
)
178 return bt_ctf_private_value_real_create_init(
179 BT_CTF_VALUE_TO_REAL(real_obj
)->value
);
183 struct bt_ctf_private_value
*bt_ctf_value_string_copy(const struct bt_ctf_value
*string_obj
)
185 return bt_ctf_private_value_string_create_init(
186 BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
);
190 struct bt_ctf_private_value
*bt_ctf_value_array_copy(const struct bt_ctf_value
*array_obj
)
194 struct bt_ctf_private_value
*copy_obj
;
195 struct bt_ctf_value_array
*typed_array_obj
;
197 BT_LOGD("Copying array value: addr=%p", array_obj
);
198 typed_array_obj
= BT_CTF_VALUE_TO_ARRAY(array_obj
);
199 copy_obj
= bt_ctf_private_value_array_create();
201 BT_LOGE_STR("Cannot create empty array value.");
205 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
206 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
207 struct bt_ctf_value
*element_obj
=
208 bt_ctf_value_array_borrow_element_by_index(
211 BT_ASSERT_DBG(element_obj
);
212 BT_LOGD("Copying array value's element: element-addr=%p, "
213 "index=%d", element_obj
, i
);
214 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
216 BT_LOGE("Cannot copy array value's element: "
217 "array-addr=%p, index=%d",
219 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
223 BT_ASSERT_DBG(element_obj_copy
);
224 ret
= bt_ctf_private_value_array_append_element(copy_obj
,
225 (void *) element_obj_copy
);
226 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
228 BT_LOGE("Cannot append to array value: addr=%p",
230 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
235 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
236 array_obj
, copy_obj
);
243 struct bt_ctf_private_value
*bt_ctf_value_map_copy(const struct bt_ctf_value
*map_obj
)
247 gpointer key
, element_obj
;
248 struct bt_ctf_private_value
*copy_obj
;
249 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
250 struct bt_ctf_value_map
*typed_map_obj
;
252 BT_LOGD("Copying map value: addr=%p", map_obj
);
253 typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
254 copy_obj
= bt_ctf_private_value_map_create();
259 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
261 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
262 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
264 BT_ASSERT_DBG(key_str
);
265 BT_LOGD("Copying map value's element: element-addr=%p, "
266 "key=\"%s\"", element_obj
, key_str
);
267 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
269 BT_LOGE("Cannot copy map value's element: "
270 "map-addr=%p, key=\"%s\"",
272 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
276 BT_ASSERT_DBG(element_obj_copy
);
277 ret
= bt_ctf_private_value_map_insert_entry(copy_obj
, key_str
,
278 (void *) element_obj_copy
);
279 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
281 BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"",
283 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
288 BT_LOGD("Copied map value: addr=%p", map_obj
);
295 struct bt_ctf_private_value
*(* const copy_funcs
[])(const struct bt_ctf_value
*) = {
296 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_copy
,
297 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_copy
,
298 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_copy
,
299 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_copy
,
300 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_copy
,
301 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_copy
,
302 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_copy
,
306 bt_ctf_bool
bt_ctf_value_null_compare(
307 const struct bt_ctf_value
*object_a
__attribute__((unused
)),
308 const struct bt_ctf_value
*object_b
__attribute__((unused
)))
311 * Always BT_CTF_TRUE since bt_ctf_value_compare() already checks if both
312 * object_a and object_b have the same type, and in the case of
313 * null value objects, they're always the same if it is so.
319 bt_ctf_bool
bt_ctf_value_bool_compare(const struct bt_ctf_value
*object_a
,
320 const struct bt_ctf_value
*object_b
)
322 if (BT_CTF_VALUE_TO_BOOL(object_a
)->value
!=
323 BT_CTF_VALUE_TO_BOOL(object_b
)->value
) {
324 BT_LOGT("Boolean value objects are different: "
325 "bool-a-val=%d, bool-b-val=%d",
326 BT_CTF_VALUE_TO_BOOL(object_a
)->value
,
327 BT_CTF_VALUE_TO_BOOL(object_b
)->value
);
335 bt_ctf_bool
bt_ctf_value_integer_compare(const struct bt_ctf_value
*object_a
,
336 const struct bt_ctf_value
*object_b
)
338 if (BT_CTF_VALUE_TO_INTEGER(object_a
)->value
!=
339 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
) {
340 BT_LOGT("Integer value objects are different: "
341 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
342 BT_CTF_VALUE_TO_INTEGER(object_a
)->value
,
343 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
);
351 bt_ctf_bool
bt_ctf_value_real_compare(const struct bt_ctf_value
*object_a
,
352 const struct bt_ctf_value
*object_b
)
354 if (BT_CTF_VALUE_TO_REAL(object_a
)->value
!=
355 BT_CTF_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_CTF_VALUE_TO_REAL(object_a
)->value
,
359 BT_CTF_VALUE_TO_REAL(object_b
)->value
);
367 bt_ctf_bool
bt_ctf_value_string_compare(const struct bt_ctf_value
*object_a
,
368 const struct bt_ctf_value
*object_b
)
370 if (strcmp(BT_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
371 BT_CTF_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_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
375 BT_CTF_VALUE_TO_STRING(object_b
)->gstr
->str
);
383 bt_ctf_bool
bt_ctf_value_array_compare(const struct bt_ctf_value
*object_a
,
384 const struct bt_ctf_value
*object_b
)
387 bt_ctf_bool ret
= BT_CTF_TRUE
;
388 const struct bt_ctf_value_array
*array_obj_a
=
389 BT_CTF_VALUE_TO_ARRAY(object_a
);
391 if (bt_ctf_value_array_get_length(object_a
) !=
392 bt_ctf_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_ctf_value_array_get_length(object_a
),
398 bt_ctf_value_array_get_length(object_b
));
403 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
404 struct bt_ctf_value
*element_obj_a
;
405 struct bt_ctf_value
*element_obj_b
;
407 element_obj_a
= bt_ctf_value_array_borrow_element_by_index(
409 element_obj_b
= bt_ctf_value_array_borrow_element_by_index(
412 if (!bt_ctf_value_compare(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_ctf_bool
bt_ctf_value_map_compare(const struct bt_ctf_value
*object_a
,
427 const struct bt_ctf_value
*object_b
)
429 bt_ctf_bool ret
= BT_CTF_TRUE
;
431 gpointer key
, element_obj_a
;
432 const struct bt_ctf_value_map
*map_obj_a
= BT_CTF_VALUE_TO_MAP(object_a
);
434 if (bt_ctf_value_map_get_size(object_a
) !=
435 bt_ctf_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_ctf_value_map_get_size(object_a
),
441 bt_ctf_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 struct bt_ctf_value
*element_obj_b
;
450 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
452 element_obj_b
= bt_ctf_value_map_borrow_entry_value(object_b
,
455 if (!bt_ctf_value_compare(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_ctf_bool (* const compare_funcs
[])(const struct bt_ctf_value
*,
470 const struct bt_ctf_value
*) = {
471 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_compare
,
472 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_compare
,
473 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_compare
,
474 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_compare
,
475 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_compare
,
476 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_compare
,
477 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_compare
,
481 void bt_ctf_value_null_freeze(struct bt_ctf_value
*object
__attribute__((unused
)))
486 void bt_ctf_value_generic_freeze(struct bt_ctf_value
*object
)
488 object
->frozen
= BT_CTF_TRUE
;
492 void bt_ctf_value_array_freeze(struct bt_ctf_value
*object
)
495 struct bt_ctf_value_array
*typed_array_obj
=
496 BT_CTF_VALUE_TO_ARRAY(object
);
498 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
499 bt_ctf_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
502 bt_ctf_value_generic_freeze(object
);
506 void bt_ctf_value_map_freeze(struct bt_ctf_value
*object
)
509 gpointer key
, element_obj
;
510 const struct bt_ctf_value_map
*map_obj
= BT_CTF_VALUE_TO_MAP(object
);
512 g_hash_table_iter_init(&iter
, map_obj
->ght
);
514 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
515 bt_ctf_value_freeze(element_obj
);
518 bt_ctf_value_generic_freeze(object
);
522 void (* const freeze_funcs
[])(struct bt_ctf_value
*) = {
523 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_freeze
,
524 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_generic_freeze
,
525 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_generic_freeze
,
526 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_generic_freeze
,
527 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_generic_freeze
,
528 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_freeze
,
529 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_freeze
,
533 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
)
535 struct bt_ctf_value
*value
;
537 value
= container_of(obj
, struct bt_ctf_value
, base
);
538 BT_LOGD("Destroying value: addr=%p", value
);
540 if (bt_ctf_value_is_null(value
)) {
541 BT_LOGD_STR("Not destroying the null value singleton.");
545 if (destroy_funcs
[value
->type
]) {
546 destroy_funcs
[value
->type
](value
);
552 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
)
554 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
556 BT_ASSERT_DBG(object
);
558 if (object
->frozen
) {
562 BT_LOGD("Freezing value: addr=%p", object
);
563 freeze_funcs
[object
->type
](object
);
569 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
)
571 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
576 struct bt_ctf_value
bt_ctf_value_create_base(enum bt_ctf_value_type type
)
578 struct bt_ctf_value value
;
581 value
.frozen
= BT_CTF_FALSE
;
582 bt_ctf_object_init_shared(&value
.base
, bt_ctf_value_destroy
);
586 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_ctf_bool val
)
588 struct bt_ctf_value_bool
*bool_obj
;
590 BT_LOGD("Creating boolean value object: val=%d", val
);
591 bool_obj
= g_new0(struct bt_ctf_value_bool
, 1);
593 BT_LOGE_STR("Failed to allocate one boolean value object.");
597 bool_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_BOOL
);
598 bool_obj
->value
= val
;
599 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
602 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
);
610 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create_init(int64_t val
)
612 struct bt_ctf_value_integer
*integer_obj
;
614 BT_LOGD("Creating integer value object: val=%" PRId64
, val
);
615 integer_obj
= g_new0(struct bt_ctf_value_integer
, 1);
617 BT_LOGE_STR("Failed to allocate one integer value object.");
621 integer_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_INTEGER
);
622 integer_obj
->value
= val
;
623 BT_LOGD("Created integer value object: addr=%p",
627 return (void *) BT_CTF_VALUE_FROM_CONCRETE(integer_obj
);
630 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void)
632 return bt_ctf_private_value_integer_create_init(0);
635 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
)
637 struct bt_ctf_value_real
*real_obj
;
639 BT_LOGD("Creating real number value object: val=%f", val
);
640 real_obj
= g_new0(struct bt_ctf_value_real
, 1);
642 BT_LOGE_STR("Failed to allocate one real number value object.");
646 real_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_REAL
);
647 real_obj
->value
= val
;
648 BT_LOGD("Created real number value object: addr=%p",
652 return (void *) BT_CTF_VALUE_FROM_CONCRETE(real_obj
);
655 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void)
657 return bt_ctf_private_value_real_create_init(0.);
660 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(const char *val
)
662 struct bt_ctf_value_string
*string_obj
= NULL
;
665 BT_LOGW_STR("Invalid parameter: value is NULL.");
669 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
670 string_obj
= g_new0(struct bt_ctf_value_string
, 1);
672 BT_LOGE_STR("Failed to allocate one string object.");
676 string_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_STRING
);
677 string_obj
->gstr
= g_string_new(val
);
678 if (!string_obj
->gstr
) {
679 BT_LOGE_STR("Failed to allocate a GString.");
685 BT_LOGD("Created string value object: addr=%p",
689 return (void *) BT_CTF_VALUE_FROM_CONCRETE(string_obj
);
692 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void)
694 return bt_ctf_private_value_string_create_init("");
697 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void)
699 struct bt_ctf_value_array
*array_obj
;
701 BT_LOGD_STR("Creating empty array value object.");
702 array_obj
= g_new0(struct bt_ctf_value_array
, 1);
704 BT_LOGE_STR("Failed to allocate one array object.");
708 array_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_ARRAY
);
709 array_obj
->garray
= bt_g_ptr_array_new_full(0,
710 (GDestroyNotify
) bt_ctf_object_put_ref
);
711 if (!array_obj
->garray
) {
712 BT_LOGE_STR("Failed to allocate a GPtrArray.");
718 BT_LOGD("Created array value object: addr=%p",
722 return (void *) BT_CTF_VALUE_FROM_CONCRETE(array_obj
);
725 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void)
727 struct bt_ctf_value_map
*map_obj
;
729 BT_LOGD_STR("Creating empty map value object.");
730 map_obj
= g_new0(struct bt_ctf_value_map
, 1);
732 BT_LOGE_STR("Failed to allocate one map object.");
736 map_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_MAP
);
737 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
738 NULL
, (GDestroyNotify
) bt_ctf_object_put_ref
);
740 BT_LOGE_STR("Failed to allocate a GHashTable.");
746 BT_LOGD("Created map value object: addr=%p",
750 return (void *) BT_CTF_VALUE_FROM_CONCRETE(map_obj
);
753 bt_ctf_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
)
755 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
756 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
757 return BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
;
760 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
, bt_ctf_bool val
)
762 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
763 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
764 BT_CTF_ASSERT_PRE_VALUE_HOT(bool_obj
, "Value object");
765 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
= val
;
766 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
770 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
)
772 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
773 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
774 return BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
;
777 void bt_ctf_private_value_integer_set(struct bt_ctf_private_value
*integer_obj
,
780 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
781 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
782 BT_CTF_ASSERT_PRE_VALUE_HOT(integer_obj
, "Value object");
783 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
= val
;
784 BT_LOGT("Set integer value's raw value: value-addr=%p, value=%" PRId64
,
788 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
)
790 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
791 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
792 return BT_CTF_VALUE_TO_REAL(real_obj
)->value
;
795 void bt_ctf_private_value_real_set(struct bt_ctf_private_value
*real_obj
, double val
)
797 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
798 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
799 BT_CTF_ASSERT_PRE_VALUE_HOT(real_obj
, "Value object");
800 BT_CTF_VALUE_TO_REAL(real_obj
)->value
= val
;
801 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
805 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
)
807 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
808 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
809 return BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
;
812 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
813 struct bt_ctf_private_value
*string_obj
, const char *val
)
815 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
816 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
817 BT_CTF_ASSERT_PRE_VALUE_HOT(string_obj
, "Value object");
818 g_string_assign(BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
, val
);
819 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
821 return BT_CTF_VALUE_STATUS_OK
;
824 uint64_t bt_ctf_value_array_get_length(const struct bt_ctf_value
*array_obj
)
826 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
827 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
828 return (uint64_t) BT_CTF_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
831 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
832 const struct bt_ctf_value
*array_obj
,
835 struct bt_ctf_value_array
*typed_array_obj
=
836 BT_CTF_VALUE_TO_ARRAY(array_obj
);
838 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
839 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
840 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
841 typed_array_obj
->garray
->len
);
842 return g_ptr_array_index(typed_array_obj
->garray
, index
);
845 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
846 const struct bt_ctf_private_value
*array_obj
,
849 return (void *) bt_ctf_value_array_borrow_element_by_index(
850 (void *) array_obj
, index
);
853 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
854 struct bt_ctf_private_value
*array_obj
,
855 struct bt_ctf_value
*element_obj
)
857 struct bt_ctf_value_array
*typed_array_obj
=
858 BT_CTF_VALUE_TO_ARRAY(array_obj
);
860 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
861 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
862 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
863 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
864 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
865 bt_ctf_object_get_ref(element_obj
);
866 BT_LOGT("Appended element to array value: array-value-addr=%p, "
867 "element-value-addr=%p, new-size=%u",
868 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
869 return BT_CTF_VALUE_STATUS_OK
;
872 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
873 struct bt_ctf_private_value
*array_obj
, bt_ctf_bool val
)
875 enum bt_ctf_value_status ret
;
876 struct bt_ctf_private_value
*bool_obj
= NULL
;
878 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
879 ret
= bt_ctf_private_value_array_append_element(array_obj
,
881 bt_ctf_object_put_ref(bool_obj
);
885 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
886 struct bt_ctf_private_value
*array_obj
, int64_t val
)
888 enum bt_ctf_value_status ret
;
889 struct bt_ctf_private_value
*integer_obj
= NULL
;
891 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
892 ret
= bt_ctf_private_value_array_append_element(array_obj
,
893 (void *) integer_obj
);
894 bt_ctf_object_put_ref(integer_obj
);
898 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
899 struct bt_ctf_private_value
*array_obj
, double val
)
901 enum bt_ctf_value_status ret
;
902 struct bt_ctf_private_value
*real_obj
= NULL
;
904 real_obj
= bt_ctf_private_value_real_create_init(val
);
905 ret
= bt_ctf_private_value_array_append_element(array_obj
,
907 bt_ctf_object_put_ref(real_obj
);
911 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
912 struct bt_ctf_private_value
*array_obj
, const char *val
)
914 enum bt_ctf_value_status ret
;
915 struct bt_ctf_private_value
*string_obj
= NULL
;
917 string_obj
= bt_ctf_private_value_string_create_init(val
);
918 ret
= bt_ctf_private_value_array_append_element(array_obj
,
919 (void *) string_obj
);
920 bt_ctf_object_put_ref(string_obj
);
924 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
925 struct bt_ctf_private_value
*array_obj
)
927 enum bt_ctf_value_status ret
;
928 struct bt_ctf_private_value
*empty_array_obj
= NULL
;
930 empty_array_obj
= bt_ctf_private_value_array_create();
931 ret
= bt_ctf_private_value_array_append_element(array_obj
,
932 (void *) empty_array_obj
);
933 bt_ctf_object_put_ref(empty_array_obj
);
937 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
938 struct bt_ctf_private_value
*array_obj
)
940 enum bt_ctf_value_status ret
;
941 struct bt_ctf_private_value
*map_obj
= NULL
;
943 map_obj
= bt_ctf_private_value_map_create();
944 ret
= bt_ctf_private_value_array_append_element(array_obj
,
946 bt_ctf_object_put_ref(map_obj
);
950 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
951 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
952 struct bt_ctf_value
*element_obj
)
954 struct bt_ctf_value_array
*typed_array_obj
=
955 BT_CTF_VALUE_TO_ARRAY(array_obj
);
957 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
958 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
959 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
960 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
961 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
962 typed_array_obj
->garray
->len
);
963 bt_ctf_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
964 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
965 bt_ctf_object_get_ref(element_obj
);
966 BT_LOGT("Set array value's element: array-value-addr=%p, "
967 "index=%" PRIu64
", element-value-addr=%p",
968 array_obj
, index
, element_obj
);
969 return BT_CTF_VALUE_STATUS_OK
;
972 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
)
974 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
975 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
976 return (uint64_t) g_hash_table_size(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
);
979 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(const struct bt_ctf_value
*map_obj
,
982 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
983 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
984 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
985 return g_hash_table_lookup(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
986 GUINT_TO_POINTER(g_quark_from_string(key
)));
989 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
990 const struct bt_ctf_private_value
*map_obj
, const char *key
)
992 return (void *) bt_ctf_value_map_borrow_entry_value((void *) map_obj
, key
);
995 bt_ctf_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
, const char *key
)
997 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
998 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
999 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1000 return bt_g_hash_table_contains(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1001 GUINT_TO_POINTER(g_quark_from_string(key
)));
1004 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
1005 struct bt_ctf_private_value
*map_obj
,
1006 const char *key
, struct bt_ctf_value
*element_obj
)
1008 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1009 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1010 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1011 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1012 BT_CTF_ASSERT_PRE_VALUE_HOT(map_obj
, "Map value object");
1013 g_hash_table_insert(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1014 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1015 bt_ctf_object_get_ref(element_obj
);
1016 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1017 "key=\"%s\", element-value-addr=%p",
1018 map_obj
, key
, element_obj
);
1019 return BT_CTF_VALUE_STATUS_OK
;
1022 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
1023 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_ctf_bool val
)
1025 enum bt_ctf_value_status ret
;
1026 struct bt_ctf_private_value
*bool_obj
= NULL
;
1028 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
1029 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1031 bt_ctf_object_put_ref(bool_obj
);
1035 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
1036 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
)
1038 enum bt_ctf_value_status ret
;
1039 struct bt_ctf_private_value
*integer_obj
= NULL
;
1041 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
1042 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1043 (void *) integer_obj
);
1044 bt_ctf_object_put_ref(integer_obj
);
1048 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
1049 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
)
1051 enum bt_ctf_value_status ret
;
1052 struct bt_ctf_private_value
*real_obj
= NULL
;
1054 real_obj
= bt_ctf_private_value_real_create_init(val
);
1055 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1057 bt_ctf_object_put_ref(real_obj
);
1061 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
1062 struct bt_ctf_private_value
*map_obj
, const char *key
,
1065 enum bt_ctf_value_status ret
;
1066 struct bt_ctf_private_value
*string_obj
= NULL
;
1068 string_obj
= bt_ctf_private_value_string_create_init(val
);
1069 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1070 (void *) string_obj
);
1071 bt_ctf_object_put_ref(string_obj
);
1075 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
1076 struct bt_ctf_private_value
*map_obj
, const char *key
)
1078 enum bt_ctf_value_status ret
;
1079 struct bt_ctf_private_value
*array_obj
= NULL
;
1081 array_obj
= bt_ctf_private_value_array_create();
1082 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1083 (void *) array_obj
);
1084 bt_ctf_object_put_ref(array_obj
);
1088 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
1089 struct bt_ctf_private_value
*map_obj
, const char *key
)
1091 enum bt_ctf_value_status ret
;
1092 struct bt_ctf_private_value
*empty_map_obj
= NULL
;
1094 empty_map_obj
= bt_ctf_private_value_map_create();
1095 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1096 (void *) empty_map_obj
);
1097 bt_ctf_object_put_ref(empty_map_obj
);
1101 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(const struct bt_ctf_value
*map_obj
,
1102 bt_ctf_value_map_foreach_entry_cb cb
, void *data
)
1104 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
1105 gpointer key
, element_obj
;
1106 GHashTableIter iter
;
1107 struct bt_ctf_value_map
*typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
1109 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1110 BT_CTF_ASSERT_PRE_NON_NULL(cb
, "Callback");
1111 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1112 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1114 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1115 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1117 if (!cb(key_str
, element_obj
, data
)) {
1118 BT_LOGT("User canceled the loop: key=\"%s\", "
1119 "value-addr=%p, data=%p",
1120 key_str
, element_obj
, data
);
1121 ret
= BT_CTF_VALUE_STATUS_CANCELED
;
1129 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
1130 const struct bt_ctf_private_value
*map_obj
,
1131 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
)
1133 return bt_ctf_value_map_foreach_entry((void *) map_obj
,
1134 (bt_ctf_value_map_foreach_entry_cb
) cb
, data
);
1137 struct extend_map_element_data
{
1138 struct bt_ctf_private_value
*extended_obj
;
1139 enum bt_ctf_value_status status
;
1143 bt_ctf_bool
extend_map_element(const char *key
,
1144 struct bt_ctf_value
*extension_obj_elem
, void *data
)
1146 bt_ctf_bool ret
= BT_CTF_TRUE
;
1147 struct extend_map_element_data
*extend_data
= data
;
1148 struct bt_ctf_private_value
*extension_obj_elem_copy
= NULL
;
1150 /* Copy object which is to replace the current one */
1151 extend_data
->status
= bt_ctf_value_copy(&extension_obj_elem_copy
,
1152 extension_obj_elem
);
1153 if (extend_data
->status
) {
1154 BT_LOGE("Cannot copy map element: addr=%p",
1155 extension_obj_elem
);
1159 BT_ASSERT_DBG(extension_obj_elem_copy
);
1161 /* Replace in extended object */
1162 extend_data
->status
= bt_ctf_private_value_map_insert_entry(
1163 extend_data
->extended_obj
, key
,
1164 (void *) extension_obj_elem_copy
);
1165 if (extend_data
->status
) {
1166 BT_LOGE("Cannot replace value in extended value: key=\"%s\", "
1167 "extended-value-addr=%p, element-value-addr=%p",
1168 key
, extend_data
->extended_obj
,
1169 extension_obj_elem_copy
);
1176 BT_ASSERT_DBG(extend_data
->status
!= BT_CTF_VALUE_STATUS_OK
);
1180 BT_CTF_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1184 enum bt_ctf_value_status
bt_ctf_value_map_extend(
1185 struct bt_ctf_private_value
**extended_map_obj
,
1186 const struct bt_ctf_value
*base_map_obj
,
1187 const struct bt_ctf_value
*extension_obj
)
1189 struct extend_map_element_data extend_data
= {
1190 .extended_obj
= NULL
,
1191 .status
= BT_CTF_VALUE_STATUS_OK
,
1194 BT_CTF_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1195 BT_CTF_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1196 BT_CTF_ASSERT_PRE_NON_NULL(extended_map_obj
,
1197 "Extended value object (output)");
1198 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1199 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_CTF_VALUE_TYPE_MAP
);
1200 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1201 base_map_obj
, extension_obj
);
1202 *extended_map_obj
= NULL
;
1204 /* Create copy of base map object to start with */
1205 extend_data
.status
= bt_ctf_value_copy(extended_map_obj
, base_map_obj
);
1206 if (extend_data
.status
) {
1207 BT_LOGE("Cannot copy base value: base-value-addr=%p",
1212 BT_ASSERT_DBG(extended_map_obj
);
1215 * For each key in the extension map object, replace this key
1216 * in the copied map object.
1218 extend_data
.extended_obj
= *extended_map_obj
;
1220 if (bt_ctf_value_map_foreach_entry(extension_obj
, extend_map_element
,
1222 BT_LOGE("Cannot iterate on the extension object's elements: "
1223 "extension-value-addr=%p", extension_obj
);
1227 if (extend_data
.status
) {
1228 BT_LOGE("Failed to successfully iterate on the extension object's elements: "
1229 "extension-value-addr=%p", extension_obj
);
1233 BT_LOGD("Extended map value: extended-value-addr=%p",
1238 BT_CTF_OBJECT_PUT_REF_AND_RESET(*extended_map_obj
);
1239 *extended_map_obj
= NULL
;
1242 return extend_data
.status
;
1245 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy_obj
,
1246 const struct bt_ctf_value
*object
)
1248 enum bt_ctf_value_status status
= BT_CTF_VALUE_STATUS_OK
;
1250 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
1251 BT_CTF_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1252 BT_LOGD("Copying value object: addr=%p", object
);
1253 *copy_obj
= copy_funcs
[object
->type
](object
);
1255 BT_LOGD("Copied value object: copy-value-addr=%p",
1258 status
= BT_CTF_VALUE_STATUS_NOMEM
;
1260 BT_LOGE_STR("Failed to copy value object.");
1266 bt_ctf_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
1267 const struct bt_ctf_value
*object_b
)
1269 bt_ctf_bool ret
= BT_CTF_FALSE
;
1271 BT_CTF_ASSERT_PRE_NON_NULL(object_a
, "Value object A");
1272 BT_CTF_ASSERT_PRE_NON_NULL(object_b
, "Value object B");
1274 if (object_a
->type
!= object_b
->type
) {
1275 BT_LOGT("Values are different: type mismatch: "
1276 "value-a-addr=%p, value-b-addr=%p, "
1277 "value-a-type=%d, value-b-type=%d",
1278 object_a
, object_b
, object_a
->type
, object_b
->type
);
1282 ret
= compare_funcs
[object_a
->type
](object_a
, object_b
);