2 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
3 * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "CTF-WRITER-VALUES"
31 #include <babeltrace2/ctf-writer/object.h>
32 #include <babeltrace2/types.h>
34 #include "common/assert.h"
35 #include "common/common.h"
36 #include "compat/compiler.h"
37 #include "compat/glib.h"
39 #include "assert-pre.h"
43 #define BT_CTF_VALUE_FROM_CONCRETE(_concrete) ((struct bt_ctf_value *) (_concrete))
44 #define BT_CTF_VALUE_TO_BOOL(_base) ((struct bt_ctf_value_bool *) (_base))
45 #define BT_CTF_VALUE_TO_INTEGER(_base) ((struct bt_ctf_value_integer *) (_base))
46 #define BT_CTF_VALUE_TO_REAL(_base) ((struct bt_ctf_value_real *) (_base))
47 #define BT_CTF_VALUE_TO_STRING(_base) ((struct bt_ctf_value_string *) (_base))
48 #define BT_CTF_VALUE_TO_ARRAY(_base) ((struct bt_ctf_value_array *) (_base))
49 #define BT_CTF_VALUE_TO_MAP(_base) ((struct bt_ctf_value_map *) (_base))
51 #define BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
52 BT_CTF_ASSERT_PRE(((struct bt_ctf_value *) (_value))->type == (_type), \
53 "Value has the wrong type ID: expected-type=%d", (_type))
55 #define BT_CTF_ASSERT_PRE_VALUE_HOT(_value, _name) \
56 BT_CTF_ASSERT_PRE_HOT(((struct bt_ctf_value *) (_value)), (_name), "")
58 #define BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count) \
59 BT_CTF_ASSERT_PRE((_index) < (_count), \
60 "Index is out of bound: " \
61 "index=%" PRIu64 ", count=%u", (_index), (_count));
64 struct bt_ctf_object base
;
65 enum bt_ctf_value_type type
;
70 void bt_ctf_value_null_instance_release_func(struct bt_ctf_object
*obj
)
72 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
76 struct bt_ctf_value bt_ctf_value_null_instance
= {
80 .release_func
= bt_ctf_value_null_instance_release_func
,
81 .spec_release_func
= NULL
,
82 .parent_is_owner_listener_func
= NULL
,
85 .type
= BT_CTF_VALUE_TYPE_NULL
,
89 struct bt_ctf_value
*const bt_ctf_value_null
= &bt_ctf_value_null_instance
;
90 struct bt_ctf_private_value
*const bt_ctf_private_value_null
=
91 (void *) &bt_ctf_value_null_instance
;
93 struct bt_ctf_value_bool
{
94 struct bt_ctf_value base
;
98 struct bt_ctf_value_integer
{
99 struct bt_ctf_value base
;
103 struct bt_ctf_value_real
{
104 struct bt_ctf_value base
;
108 struct bt_ctf_value_string
{
109 struct bt_ctf_value base
;
113 struct bt_ctf_value_array
{
114 struct bt_ctf_value base
;
118 struct bt_ctf_value_map
{
119 struct bt_ctf_value base
;
124 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
);
127 void bt_ctf_value_string_destroy(struct bt_ctf_value
*object
)
129 g_string_free(BT_CTF_VALUE_TO_STRING(object
)->gstr
, TRUE
);
130 BT_CTF_VALUE_TO_STRING(object
)->gstr
= NULL
;
134 void bt_ctf_value_array_destroy(struct bt_ctf_value
*object
)
137 * Pointer array's registered value destructor will take care
138 * of putting each contained object.
140 g_ptr_array_free(BT_CTF_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
141 BT_CTF_VALUE_TO_ARRAY(object
)->garray
= NULL
;
145 void bt_ctf_value_map_destroy(struct bt_ctf_value
*object
)
148 * Hash table's registered value destructor will take care of
149 * putting each contained object. Keys are GQuarks and cannot
150 * be destroyed anyway.
152 g_hash_table_destroy(BT_CTF_VALUE_TO_MAP(object
)->ght
);
153 BT_CTF_VALUE_TO_MAP(object
)->ght
= NULL
;
157 void (* const destroy_funcs
[])(struct bt_ctf_value
*) = {
158 [BT_CTF_VALUE_TYPE_NULL
] = NULL
,
159 [BT_CTF_VALUE_TYPE_BOOL
] = NULL
,
160 [BT_CTF_VALUE_TYPE_INTEGER
] = NULL
,
161 [BT_CTF_VALUE_TYPE_REAL
] = NULL
,
162 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_destroy
,
163 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_destroy
,
164 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_destroy
,
168 struct bt_ctf_private_value
*bt_ctf_value_null_copy(const struct bt_ctf_value
*null_obj
)
170 return (void *) bt_ctf_value_null
;
174 struct bt_ctf_private_value
*bt_ctf_value_bool_copy(const struct bt_ctf_value
*bool_obj
)
176 return bt_ctf_private_value_bool_create_init(
177 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
);
181 struct bt_ctf_private_value
*bt_ctf_value_integer_copy(
182 const struct bt_ctf_value
*integer_obj
)
184 return bt_ctf_private_value_integer_create_init(
185 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
);
189 struct bt_ctf_private_value
*bt_ctf_value_real_copy(const struct bt_ctf_value
*real_obj
)
191 return bt_ctf_private_value_real_create_init(
192 BT_CTF_VALUE_TO_REAL(real_obj
)->value
);
196 struct bt_ctf_private_value
*bt_ctf_value_string_copy(const struct bt_ctf_value
*string_obj
)
198 return bt_ctf_private_value_string_create_init(
199 BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
);
203 struct bt_ctf_private_value
*bt_ctf_value_array_copy(const struct bt_ctf_value
*array_obj
)
207 struct bt_ctf_private_value
*copy_obj
;
208 struct bt_ctf_value_array
*typed_array_obj
;
210 BT_LOGD("Copying array value: addr=%p", array_obj
);
211 typed_array_obj
= BT_CTF_VALUE_TO_ARRAY(array_obj
);
212 copy_obj
= bt_ctf_private_value_array_create();
214 BT_LOGE_STR("Cannot create empty array value.");
218 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
219 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
220 struct bt_ctf_value
*element_obj
=
221 bt_ctf_value_array_borrow_element_by_index(
224 BT_ASSERT(element_obj
);
225 BT_LOGD("Copying array value's element: element-addr=%p, "
226 "index=%d", element_obj
, i
);
227 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
229 BT_LOGE("Cannot copy array value's element: "
230 "array-addr=%p, index=%d",
232 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
236 BT_ASSERT(element_obj_copy
);
237 ret
= bt_ctf_private_value_array_append_element(copy_obj
,
238 (void *) element_obj_copy
);
239 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
241 BT_LOGE("Cannot append to array value: addr=%p",
243 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
248 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
249 array_obj
, copy_obj
);
256 struct bt_ctf_private_value
*bt_ctf_value_map_copy(const struct bt_ctf_value
*map_obj
)
260 gpointer key
, element_obj
;
261 struct bt_ctf_private_value
*copy_obj
;
262 struct bt_ctf_private_value
*element_obj_copy
= NULL
;
263 struct bt_ctf_value_map
*typed_map_obj
;
265 BT_LOGD("Copying map value: addr=%p", map_obj
);
266 typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
267 copy_obj
= bt_ctf_private_value_map_create();
272 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
274 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
275 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
278 BT_LOGD("Copying map value's element: element-addr=%p, "
279 "key=\"%s\"", element_obj
, key_str
);
280 ret
= bt_ctf_value_copy(&element_obj_copy
, element_obj
);
282 BT_LOGE("Cannot copy map value's element: "
283 "map-addr=%p, key=\"%s\"",
285 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
289 BT_ASSERT(element_obj_copy
);
290 ret
= bt_ctf_private_value_map_insert_entry(copy_obj
, key_str
,
291 (void *) element_obj_copy
);
292 BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
294 BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"",
296 BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj
);
301 BT_LOGD("Copied map value: addr=%p", map_obj
);
308 struct bt_ctf_private_value
*(* const copy_funcs
[])(const struct bt_ctf_value
*) = {
309 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_copy
,
310 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_copy
,
311 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_copy
,
312 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_copy
,
313 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_copy
,
314 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_copy
,
315 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_copy
,
319 bt_bool
bt_ctf_value_null_compare(const struct bt_ctf_value
*object_a
,
320 const struct bt_ctf_value
*object_b
)
323 * Always BT_TRUE since bt_ctf_value_compare() already checks if both
324 * object_a and object_b have the same type, and in the case of
325 * null value objects, they're always the same if it is so.
331 bt_bool
bt_ctf_value_bool_compare(const struct bt_ctf_value
*object_a
,
332 const struct bt_ctf_value
*object_b
)
334 if (BT_CTF_VALUE_TO_BOOL(object_a
)->value
!=
335 BT_CTF_VALUE_TO_BOOL(object_b
)->value
) {
336 BT_LOGV("Boolean value objects are different: "
337 "bool-a-val=%d, bool-b-val=%d",
338 BT_CTF_VALUE_TO_BOOL(object_a
)->value
,
339 BT_CTF_VALUE_TO_BOOL(object_b
)->value
);
347 bt_bool
bt_ctf_value_integer_compare(const struct bt_ctf_value
*object_a
,
348 const struct bt_ctf_value
*object_b
)
350 if (BT_CTF_VALUE_TO_INTEGER(object_a
)->value
!=
351 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
) {
352 BT_LOGV("Integer value objects are different: "
353 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
354 BT_CTF_VALUE_TO_INTEGER(object_a
)->value
,
355 BT_CTF_VALUE_TO_INTEGER(object_b
)->value
);
363 bt_bool
bt_ctf_value_real_compare(const struct bt_ctf_value
*object_a
,
364 const struct bt_ctf_value
*object_b
)
366 if (BT_CTF_VALUE_TO_REAL(object_a
)->value
!=
367 BT_CTF_VALUE_TO_REAL(object_b
)->value
) {
368 BT_LOGV("Real number value objects are different: "
369 "real-a-val=%f, real-b-val=%f",
370 BT_CTF_VALUE_TO_REAL(object_a
)->value
,
371 BT_CTF_VALUE_TO_REAL(object_b
)->value
);
379 bt_bool
bt_ctf_value_string_compare(const struct bt_ctf_value
*object_a
,
380 const struct bt_ctf_value
*object_b
)
382 if (strcmp(BT_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
383 BT_CTF_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
384 BT_LOGV("String value objects are different: "
385 "string-a-val=\"%s\", string-b-val=\"%s\"",
386 BT_CTF_VALUE_TO_STRING(object_a
)->gstr
->str
,
387 BT_CTF_VALUE_TO_STRING(object_b
)->gstr
->str
);
395 bt_bool
bt_ctf_value_array_compare(const struct bt_ctf_value
*object_a
,
396 const struct bt_ctf_value
*object_b
)
399 bt_bool ret
= BT_TRUE
;
400 const struct bt_ctf_value_array
*array_obj_a
=
401 BT_CTF_VALUE_TO_ARRAY(object_a
);
403 if (bt_ctf_value_array_get_size(object_a
) !=
404 bt_ctf_value_array_get_size(object_b
)) {
405 BT_LOGV("Array values are different: size mismatch "
406 "value-a-addr=%p, value-b-addr=%p, "
407 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
409 bt_ctf_value_array_get_size(object_a
),
410 bt_ctf_value_array_get_size(object_b
));
415 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
416 struct bt_ctf_value
*element_obj_a
;
417 struct bt_ctf_value
*element_obj_b
;
419 element_obj_a
= bt_ctf_value_array_borrow_element_by_index(
421 element_obj_b
= bt_ctf_value_array_borrow_element_by_index(
424 if (!bt_ctf_value_compare(element_obj_a
, element_obj_b
)) {
425 BT_LOGV("Array values's elements are different: "
426 "value-a-addr=%p, value-b-addr=%p, index=%d",
427 element_obj_a
, element_obj_b
, i
);
438 bt_bool
bt_ctf_value_map_compare(const struct bt_ctf_value
*object_a
,
439 const struct bt_ctf_value
*object_b
)
441 bt_bool ret
= BT_TRUE
;
443 gpointer key
, element_obj_a
;
444 const struct bt_ctf_value_map
*map_obj_a
= BT_CTF_VALUE_TO_MAP(object_a
);
446 if (bt_ctf_value_map_get_size(object_a
) !=
447 bt_ctf_value_map_get_size(object_b
)) {
448 BT_LOGV("Map values are different: size mismatch "
449 "value-a-addr=%p, value-b-addr=%p, "
450 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
452 bt_ctf_value_map_get_size(object_a
),
453 bt_ctf_value_map_get_size(object_b
));
458 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
460 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
461 struct bt_ctf_value
*element_obj_b
;
462 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
464 element_obj_b
= bt_ctf_value_map_borrow_entry_value(object_b
,
467 if (!bt_ctf_value_compare(element_obj_a
, element_obj_b
)) {
468 BT_LOGV("Map values's elements are different: "
469 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
470 element_obj_a
, element_obj_b
, key_str
);
481 bt_bool (* const compare_funcs
[])(const struct bt_ctf_value
*,
482 const struct bt_ctf_value
*) = {
483 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_compare
,
484 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_bool_compare
,
485 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_integer_compare
,
486 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_real_compare
,
487 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_string_compare
,
488 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_compare
,
489 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_compare
,
493 void bt_ctf_value_null_freeze(struct bt_ctf_value
*object
)
498 void bt_ctf_value_generic_freeze(struct bt_ctf_value
*object
)
500 object
->frozen
= BT_TRUE
;
504 void bt_ctf_value_array_freeze(struct bt_ctf_value
*object
)
507 struct bt_ctf_value_array
*typed_array_obj
=
508 BT_CTF_VALUE_TO_ARRAY(object
);
510 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
511 bt_ctf_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
514 bt_ctf_value_generic_freeze(object
);
518 void bt_ctf_value_map_freeze(struct bt_ctf_value
*object
)
521 gpointer key
, element_obj
;
522 const struct bt_ctf_value_map
*map_obj
= BT_CTF_VALUE_TO_MAP(object
);
524 g_hash_table_iter_init(&iter
, map_obj
->ght
);
526 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
527 bt_ctf_value_freeze(element_obj
);
530 bt_ctf_value_generic_freeze(object
);
534 void (* const freeze_funcs
[])(struct bt_ctf_value
*) = {
535 [BT_CTF_VALUE_TYPE_NULL
] = bt_ctf_value_null_freeze
,
536 [BT_CTF_VALUE_TYPE_BOOL
] = bt_ctf_value_generic_freeze
,
537 [BT_CTF_VALUE_TYPE_INTEGER
] = bt_ctf_value_generic_freeze
,
538 [BT_CTF_VALUE_TYPE_REAL
] = bt_ctf_value_generic_freeze
,
539 [BT_CTF_VALUE_TYPE_STRING
] = bt_ctf_value_generic_freeze
,
540 [BT_CTF_VALUE_TYPE_ARRAY
] = bt_ctf_value_array_freeze
,
541 [BT_CTF_VALUE_TYPE_MAP
] = bt_ctf_value_map_freeze
,
545 void bt_ctf_value_destroy(struct bt_ctf_object
*obj
)
547 struct bt_ctf_value
*value
;
549 value
= container_of(obj
, struct bt_ctf_value
, base
);
550 BT_LOGD("Destroying value: addr=%p", value
);
552 if (bt_ctf_value_is_null(value
)) {
553 BT_LOGD_STR("Not destroying the null value singleton.");
557 if (destroy_funcs
[value
->type
]) {
558 destroy_funcs
[value
->type
](value
);
565 enum bt_ctf_value_status
_bt_ctf_value_freeze(struct bt_ctf_value
*object
)
567 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
571 if (object
->frozen
) {
575 BT_LOGD("Freezing value: addr=%p", object
);
576 freeze_funcs
[object
->type
](object
);
583 enum bt_ctf_value_type
bt_ctf_value_get_type(const struct bt_ctf_value
*object
)
585 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
590 struct bt_ctf_value
bt_ctf_value_create_base(enum bt_ctf_value_type type
)
592 struct bt_ctf_value value
;
595 value
.frozen
= BT_FALSE
;
596 bt_ctf_object_init_shared(&value
.base
, bt_ctf_value_destroy
);
601 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create_init(bt_bool val
)
603 struct bt_ctf_value_bool
*bool_obj
;
605 BT_LOGD("Creating boolean value object: val=%d", val
);
606 bool_obj
= g_new0(struct bt_ctf_value_bool
, 1);
608 BT_LOGE_STR("Failed to allocate one boolean value object.");
612 bool_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_BOOL
);
613 bool_obj
->value
= val
;
614 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
617 return (void *) BT_CTF_VALUE_FROM_CONCRETE(bool_obj
);
621 struct bt_ctf_private_value
*bt_ctf_private_value_bool_create(void)
623 return bt_ctf_private_value_bool_create_init(BT_FALSE
);
627 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create_init(int64_t val
)
629 struct bt_ctf_value_integer
*integer_obj
;
631 BT_LOGD("Creating integer value object: val=%" PRId64
, val
);
632 integer_obj
= g_new0(struct bt_ctf_value_integer
, 1);
634 BT_LOGE_STR("Failed to allocate one integer value object.");
638 integer_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_INTEGER
);
639 integer_obj
->value
= val
;
640 BT_LOGD("Created integer value object: addr=%p",
644 return (void *) BT_CTF_VALUE_FROM_CONCRETE(integer_obj
);
648 struct bt_ctf_private_value
*bt_ctf_private_value_integer_create(void)
650 return bt_ctf_private_value_integer_create_init(0);
654 struct bt_ctf_private_value
*bt_ctf_private_value_real_create_init(double val
)
656 struct bt_ctf_value_real
*real_obj
;
658 BT_LOGD("Creating real number value object: val=%f", val
);
659 real_obj
= g_new0(struct bt_ctf_value_real
, 1);
661 BT_LOGE_STR("Failed to allocate one real number value object.");
665 real_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_REAL
);
666 real_obj
->value
= val
;
667 BT_LOGD("Created real number value object: addr=%p",
671 return (void *) BT_CTF_VALUE_FROM_CONCRETE(real_obj
);
675 struct bt_ctf_private_value
*bt_ctf_private_value_real_create(void)
677 return bt_ctf_private_value_real_create_init(0.);
681 struct bt_ctf_private_value
*bt_ctf_private_value_string_create_init(const char *val
)
683 struct bt_ctf_value_string
*string_obj
= NULL
;
686 BT_LOGW_STR("Invalid parameter: value is NULL.");
690 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
691 string_obj
= g_new0(struct bt_ctf_value_string
, 1);
693 BT_LOGE_STR("Failed to allocate one string object.");
697 string_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_STRING
);
698 string_obj
->gstr
= g_string_new(val
);
699 if (!string_obj
->gstr
) {
700 BT_LOGE_STR("Failed to allocate a GString.");
706 BT_LOGD("Created string value object: addr=%p",
710 return (void *) BT_CTF_VALUE_FROM_CONCRETE(string_obj
);
714 struct bt_ctf_private_value
*bt_ctf_private_value_string_create(void)
716 return bt_ctf_private_value_string_create_init("");
720 struct bt_ctf_private_value
*bt_ctf_private_value_array_create(void)
722 struct bt_ctf_value_array
*array_obj
;
724 BT_LOGD_STR("Creating empty array value object.");
725 array_obj
= g_new0(struct bt_ctf_value_array
, 1);
727 BT_LOGE_STR("Failed to allocate one array object.");
731 array_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_ARRAY
);
732 array_obj
->garray
= bt_g_ptr_array_new_full(0,
733 (GDestroyNotify
) bt_ctf_object_put_ref
);
734 if (!array_obj
->garray
) {
735 BT_LOGE_STR("Failed to allocate a GPtrArray.");
741 BT_LOGD("Created array value object: addr=%p",
745 return (void *) BT_CTF_VALUE_FROM_CONCRETE(array_obj
);
749 struct bt_ctf_private_value
*bt_ctf_private_value_map_create(void)
751 struct bt_ctf_value_map
*map_obj
;
753 BT_LOGD_STR("Creating empty map value object.");
754 map_obj
= g_new0(struct bt_ctf_value_map
, 1);
756 BT_LOGE_STR("Failed to allocate one map object.");
760 map_obj
->base
= bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_MAP
);
761 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
762 NULL
, (GDestroyNotify
) bt_ctf_object_put_ref
);
764 BT_LOGE_STR("Failed to allocate a GHashTable.");
770 BT_LOGD("Created map value object: addr=%p",
774 return (void *) BT_CTF_VALUE_FROM_CONCRETE(map_obj
);
778 bt_bool
bt_ctf_value_bool_get(const struct bt_ctf_value
*bool_obj
)
780 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
781 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
782 return BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
;
786 void bt_ctf_private_value_bool_set(struct bt_ctf_private_value
*bool_obj
, bt_bool val
)
788 BT_CTF_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
789 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_CTF_VALUE_TYPE_BOOL
);
790 BT_CTF_ASSERT_PRE_VALUE_HOT(bool_obj
, "Value object");
791 BT_CTF_VALUE_TO_BOOL(bool_obj
)->value
= val
;
792 BT_LOGV("Set boolean value's raw value: value-addr=%p, value=%d",
797 int64_t bt_ctf_value_integer_get(const struct bt_ctf_value
*integer_obj
)
799 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
800 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
801 return BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
;
805 void bt_ctf_private_value_integer_set(struct bt_ctf_private_value
*integer_obj
,
808 BT_CTF_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
809 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, BT_CTF_VALUE_TYPE_INTEGER
);
810 BT_CTF_ASSERT_PRE_VALUE_HOT(integer_obj
, "Value object");
811 BT_CTF_VALUE_TO_INTEGER(integer_obj
)->value
= val
;
812 BT_LOGV("Set integer value's raw value: value-addr=%p, value=%" PRId64
,
817 double bt_ctf_value_real_get(const struct bt_ctf_value
*real_obj
)
819 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
820 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
821 return BT_CTF_VALUE_TO_REAL(real_obj
)->value
;
825 void bt_ctf_private_value_real_set(struct bt_ctf_private_value
*real_obj
, double val
)
827 BT_CTF_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
828 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_CTF_VALUE_TYPE_REAL
);
829 BT_CTF_ASSERT_PRE_VALUE_HOT(real_obj
, "Value object");
830 BT_CTF_VALUE_TO_REAL(real_obj
)->value
= val
;
831 BT_LOGV("Set real number value's raw value: value-addr=%p, value=%f",
836 const char *bt_ctf_value_string_get(const struct bt_ctf_value
*string_obj
)
838 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
839 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
840 return BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
->str
;
844 enum bt_ctf_value_status
bt_ctf_private_value_string_set(
845 struct bt_ctf_private_value
*string_obj
, const char *val
)
847 BT_CTF_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
848 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_CTF_VALUE_TYPE_STRING
);
849 BT_CTF_ASSERT_PRE_VALUE_HOT(string_obj
, "Value object");
850 g_string_assign(BT_CTF_VALUE_TO_STRING(string_obj
)->gstr
, val
);
851 BT_LOGV("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
853 return BT_CTF_VALUE_STATUS_OK
;
857 uint64_t bt_ctf_value_array_get_size(const struct bt_ctf_value
*array_obj
)
859 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
860 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
861 return (uint64_t) BT_CTF_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
865 struct bt_ctf_value
*bt_ctf_value_array_borrow_element_by_index(
866 const struct bt_ctf_value
*array_obj
,
869 struct bt_ctf_value_array
*typed_array_obj
=
870 BT_CTF_VALUE_TO_ARRAY(array_obj
);
872 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
873 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
874 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
875 typed_array_obj
->garray
->len
);
876 return g_ptr_array_index(typed_array_obj
->garray
, index
);
880 struct bt_ctf_private_value
*bt_ctf_private_value_array_borrow_element_by_index(
881 const struct bt_ctf_private_value
*array_obj
,
884 return (void *) bt_ctf_value_array_borrow_element_by_index(
885 (void *) array_obj
, index
);
889 enum bt_ctf_value_status
bt_ctf_private_value_array_append_element(
890 struct bt_ctf_private_value
*array_obj
,
891 struct bt_ctf_value
*element_obj
)
893 struct bt_ctf_value_array
*typed_array_obj
=
894 BT_CTF_VALUE_TO_ARRAY(array_obj
);
896 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
897 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
898 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
899 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
900 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
901 bt_ctf_object_get_ref(element_obj
);
902 BT_LOGV("Appended element to array value: array-value-addr=%p, "
903 "element-value-addr=%p, new-size=%u",
904 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
905 return BT_CTF_VALUE_STATUS_OK
;
909 enum bt_ctf_value_status
bt_ctf_private_value_array_append_bool_element(
910 struct bt_ctf_private_value
*array_obj
, bt_bool val
)
912 enum bt_ctf_value_status ret
;
913 struct bt_ctf_private_value
*bool_obj
= NULL
;
915 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
916 ret
= bt_ctf_private_value_array_append_element(array_obj
,
918 bt_ctf_object_put_ref(bool_obj
);
923 enum bt_ctf_value_status
bt_ctf_private_value_array_append_integer_element(
924 struct bt_ctf_private_value
*array_obj
, int64_t val
)
926 enum bt_ctf_value_status ret
;
927 struct bt_ctf_private_value
*integer_obj
= NULL
;
929 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
930 ret
= bt_ctf_private_value_array_append_element(array_obj
,
931 (void *) integer_obj
);
932 bt_ctf_object_put_ref(integer_obj
);
937 enum bt_ctf_value_status
bt_ctf_private_value_array_append_real_element(
938 struct bt_ctf_private_value
*array_obj
, double val
)
940 enum bt_ctf_value_status ret
;
941 struct bt_ctf_private_value
*real_obj
= NULL
;
943 real_obj
= bt_ctf_private_value_real_create_init(val
);
944 ret
= bt_ctf_private_value_array_append_element(array_obj
,
946 bt_ctf_object_put_ref(real_obj
);
951 enum bt_ctf_value_status
bt_ctf_private_value_array_append_string_element(
952 struct bt_ctf_private_value
*array_obj
, const char *val
)
954 enum bt_ctf_value_status ret
;
955 struct bt_ctf_private_value
*string_obj
= NULL
;
957 string_obj
= bt_ctf_private_value_string_create_init(val
);
958 ret
= bt_ctf_private_value_array_append_element(array_obj
,
959 (void *) string_obj
);
960 bt_ctf_object_put_ref(string_obj
);
965 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_array_element(
966 struct bt_ctf_private_value
*array_obj
)
968 enum bt_ctf_value_status ret
;
969 struct bt_ctf_private_value
*empty_array_obj
= NULL
;
971 empty_array_obj
= bt_ctf_private_value_array_create();
972 ret
= bt_ctf_private_value_array_append_element(array_obj
,
973 (void *) empty_array_obj
);
974 bt_ctf_object_put_ref(empty_array_obj
);
979 enum bt_ctf_value_status
bt_ctf_private_value_array_append_empty_map_element(
980 struct bt_ctf_private_value
*array_obj
)
982 enum bt_ctf_value_status ret
;
983 struct bt_ctf_private_value
*map_obj
= NULL
;
985 map_obj
= bt_ctf_private_value_map_create();
986 ret
= bt_ctf_private_value_array_append_element(array_obj
,
988 bt_ctf_object_put_ref(map_obj
);
993 enum bt_ctf_value_status
bt_ctf_private_value_array_set_element_by_index(
994 struct bt_ctf_private_value
*array_obj
, uint64_t index
,
995 struct bt_ctf_value
*element_obj
)
997 struct bt_ctf_value_array
*typed_array_obj
=
998 BT_CTF_VALUE_TO_ARRAY(array_obj
);
1000 BT_CTF_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1001 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1002 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_CTF_VALUE_TYPE_ARRAY
);
1003 BT_CTF_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
1004 BT_CTF_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
1005 typed_array_obj
->garray
->len
);
1006 bt_ctf_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1007 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1008 bt_ctf_object_get_ref(element_obj
);
1009 BT_LOGV("Set array value's element: array-value-addr=%p, "
1010 "index=%" PRIu64
", element-value-addr=%p",
1011 array_obj
, index
, element_obj
);
1012 return BT_CTF_VALUE_STATUS_OK
;
1016 uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value
*map_obj
)
1018 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1019 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1020 return (uint64_t) g_hash_table_size(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
);
1024 struct bt_ctf_value
*bt_ctf_value_map_borrow_entry_value(const struct bt_ctf_value
*map_obj
,
1027 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1028 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1029 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1030 return g_hash_table_lookup(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1031 GUINT_TO_POINTER(g_quark_from_string(key
)));
1035 struct bt_ctf_private_value
*bt_ctf_private_value_map_borrow_entry_value(
1036 const struct bt_ctf_private_value
*map_obj
, const char *key
)
1038 return (void *) bt_ctf_value_map_borrow_entry_value((void *) map_obj
, key
);
1042 bt_bool
bt_ctf_value_map_has_entry(const struct bt_ctf_value
*map_obj
, const char *key
)
1044 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1045 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1046 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1047 return bt_g_hash_table_contains(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1048 GUINT_TO_POINTER(g_quark_from_string(key
)));
1052 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_entry(
1053 struct bt_ctf_private_value
*map_obj
,
1054 const char *key
, struct bt_ctf_value
*element_obj
)
1056 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1057 BT_CTF_ASSERT_PRE_NON_NULL(key
, "Key");
1058 BT_CTF_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1059 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1060 BT_CTF_ASSERT_PRE_VALUE_HOT(map_obj
, "Map value object");
1061 g_hash_table_insert(BT_CTF_VALUE_TO_MAP(map_obj
)->ght
,
1062 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1063 bt_ctf_object_get_ref(element_obj
);
1064 BT_LOGV("Inserted value into map value: map-value-addr=%p, "
1065 "key=\"%s\", element-value-addr=%p",
1066 map_obj
, key
, element_obj
);
1067 return BT_CTF_VALUE_STATUS_OK
;
1071 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_bool_entry(
1072 struct bt_ctf_private_value
*map_obj
, const char *key
, bt_bool val
)
1074 enum bt_ctf_value_status ret
;
1075 struct bt_ctf_private_value
*bool_obj
= NULL
;
1077 bool_obj
= bt_ctf_private_value_bool_create_init(val
);
1078 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1080 bt_ctf_object_put_ref(bool_obj
);
1085 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_integer_entry(
1086 struct bt_ctf_private_value
*map_obj
, const char *key
, int64_t val
)
1088 enum bt_ctf_value_status ret
;
1089 struct bt_ctf_private_value
*integer_obj
= NULL
;
1091 integer_obj
= bt_ctf_private_value_integer_create_init(val
);
1092 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1093 (void *) integer_obj
);
1094 bt_ctf_object_put_ref(integer_obj
);
1099 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_real_entry(
1100 struct bt_ctf_private_value
*map_obj
, const char *key
, double val
)
1102 enum bt_ctf_value_status ret
;
1103 struct bt_ctf_private_value
*real_obj
= NULL
;
1105 real_obj
= bt_ctf_private_value_real_create_init(val
);
1106 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1108 bt_ctf_object_put_ref(real_obj
);
1113 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_string_entry(
1114 struct bt_ctf_private_value
*map_obj
, const char *key
,
1117 enum bt_ctf_value_status ret
;
1118 struct bt_ctf_private_value
*string_obj
= NULL
;
1120 string_obj
= bt_ctf_private_value_string_create_init(val
);
1121 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1122 (void *) string_obj
);
1123 bt_ctf_object_put_ref(string_obj
);
1128 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_array_entry(
1129 struct bt_ctf_private_value
*map_obj
, const char *key
)
1131 enum bt_ctf_value_status ret
;
1132 struct bt_ctf_private_value
*array_obj
= NULL
;
1134 array_obj
= bt_ctf_private_value_array_create();
1135 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1136 (void *) array_obj
);
1137 bt_ctf_object_put_ref(array_obj
);
1142 enum bt_ctf_value_status
bt_ctf_private_value_map_insert_empty_map_entry(
1143 struct bt_ctf_private_value
*map_obj
, const char *key
)
1145 enum bt_ctf_value_status ret
;
1146 struct bt_ctf_private_value
*empty_map_obj
= NULL
;
1148 empty_map_obj
= bt_ctf_private_value_map_create();
1149 ret
= bt_ctf_private_value_map_insert_entry(map_obj
, key
,
1150 (void *) empty_map_obj
);
1151 bt_ctf_object_put_ref(empty_map_obj
);
1156 enum bt_ctf_value_status
bt_ctf_value_map_foreach_entry(const struct bt_ctf_value
*map_obj
,
1157 bt_ctf_value_map_foreach_entry_cb cb
, void *data
)
1159 enum bt_ctf_value_status ret
= BT_CTF_VALUE_STATUS_OK
;
1160 gpointer key
, element_obj
;
1161 GHashTableIter iter
;
1162 struct bt_ctf_value_map
*typed_map_obj
= BT_CTF_VALUE_TO_MAP(map_obj
);
1164 BT_CTF_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1165 BT_CTF_ASSERT_PRE_NON_NULL(cb
, "Callback");
1166 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1167 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1169 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1170 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1172 if (!cb(key_str
, element_obj
, data
)) {
1173 BT_LOGV("User canceled the loop: key=\"%s\", "
1174 "value-addr=%p, data=%p",
1175 key_str
, element_obj
, data
);
1176 ret
= BT_CTF_VALUE_STATUS_CANCELED
;
1185 enum bt_ctf_value_status
bt_ctf_private_value_map_foreach_entry(
1186 const struct bt_ctf_private_value
*map_obj
,
1187 bt_ctf_private_value_map_foreach_entry_cb cb
, void *data
)
1189 return bt_ctf_value_map_foreach_entry((void *) map_obj
,
1190 (bt_ctf_value_map_foreach_entry_cb
) cb
, data
);
1193 struct extend_map_element_data
{
1194 struct bt_ctf_private_value
*extended_obj
;
1195 enum bt_ctf_value_status status
;
1199 bt_bool
extend_map_element(const char *key
,
1200 struct bt_ctf_value
*extension_obj_elem
, void *data
)
1202 bt_bool ret
= BT_TRUE
;
1203 struct extend_map_element_data
*extend_data
= data
;
1204 struct bt_ctf_private_value
*extension_obj_elem_copy
= NULL
;
1206 /* Copy object which is to replace the current one */
1207 extend_data
->status
= bt_ctf_value_copy(&extension_obj_elem_copy
,
1208 extension_obj_elem
);
1209 if (extend_data
->status
) {
1210 BT_LOGE("Cannot copy map element: addr=%p",
1211 extension_obj_elem
);
1215 BT_ASSERT(extension_obj_elem_copy
);
1217 /* Replace in extended object */
1218 extend_data
->status
= bt_ctf_private_value_map_insert_entry(
1219 extend_data
->extended_obj
, key
,
1220 (void *) extension_obj_elem_copy
);
1221 if (extend_data
->status
) {
1222 BT_LOGE("Cannot replace value in extended value: key=\"%s\", "
1223 "extended-value-addr=%p, element-value-addr=%p",
1224 key
, extend_data
->extended_obj
,
1225 extension_obj_elem_copy
);
1232 BT_ASSERT(extend_data
->status
!= BT_CTF_VALUE_STATUS_OK
);
1236 BT_CTF_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1241 enum bt_ctf_value_status
bt_ctf_value_map_extend(
1242 struct bt_ctf_private_value
**extended_map_obj
,
1243 const struct bt_ctf_value
*base_map_obj
,
1244 const struct bt_ctf_value
*extension_obj
)
1246 struct extend_map_element_data extend_data
= {
1247 .extended_obj
= NULL
,
1248 .status
= BT_CTF_VALUE_STATUS_OK
,
1251 BT_CTF_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1252 BT_CTF_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1253 BT_CTF_ASSERT_PRE_NON_NULL(extended_map_obj
,
1254 "Extended value object (output)");
1255 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_CTF_VALUE_TYPE_MAP
);
1256 BT_CTF_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_CTF_VALUE_TYPE_MAP
);
1257 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1258 base_map_obj
, extension_obj
);
1259 *extended_map_obj
= NULL
;
1261 /* Create copy of base map object to start with */
1262 extend_data
.status
= bt_ctf_value_copy(extended_map_obj
, base_map_obj
);
1263 if (extend_data
.status
) {
1264 BT_LOGE("Cannot copy base value: base-value-addr=%p",
1269 BT_ASSERT(extended_map_obj
);
1272 * For each key in the extension map object, replace this key
1273 * in the copied map object.
1275 extend_data
.extended_obj
= *extended_map_obj
;
1277 if (bt_ctf_value_map_foreach_entry(extension_obj
, extend_map_element
,
1279 BT_LOGE("Cannot iterate on the extension object's elements: "
1280 "extension-value-addr=%p", extension_obj
);
1284 if (extend_data
.status
) {
1285 BT_LOGE("Failed to successfully iterate on the extension object's elements: "
1286 "extension-value-addr=%p", extension_obj
);
1290 BT_LOGD("Extended map value: extended-value-addr=%p",
1295 BT_CTF_OBJECT_PUT_REF_AND_RESET(*extended_map_obj
);
1296 *extended_map_obj
= NULL
;
1299 return extend_data
.status
;
1303 enum bt_ctf_value_status
bt_ctf_value_copy(struct bt_ctf_private_value
**copy_obj
,
1304 const struct bt_ctf_value
*object
)
1306 enum bt_ctf_value_status status
= BT_CTF_VALUE_STATUS_OK
;
1308 BT_CTF_ASSERT_PRE_NON_NULL(object
, "Value object");
1309 BT_CTF_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1310 BT_LOGD("Copying value object: addr=%p", object
);
1311 *copy_obj
= copy_funcs
[object
->type
](object
);
1313 BT_LOGD("Copied value object: copy-value-addr=%p",
1316 status
= BT_CTF_VALUE_STATUS_NOMEM
;
1318 BT_LOGE_STR("Failed to copy value object.");
1325 bt_bool
bt_ctf_value_compare(const struct bt_ctf_value
*object_a
,
1326 const struct bt_ctf_value
*object_b
)
1328 bt_bool ret
= BT_FALSE
;
1330 BT_CTF_ASSERT_PRE_NON_NULL(object_a
, "Value object A");
1331 BT_CTF_ASSERT_PRE_NON_NULL(object_b
, "Value object B");
1333 if (object_a
->type
!= object_b
->type
) {
1334 BT_LOGV("Values are different: type mismatch: "
1335 "value-a-addr=%p, value-b-addr=%p, "
1336 "value-a-type=%d, value-b-type=%d",
1337 object_a
, object_b
, object_a
->type
, object_b
->type
);
1341 ret
= compare_funcs
[object_a
->type
](object_a
, object_b
);