CTF writer: use own `bt_ctf_object` and `bt_ctf_value` internal APIs
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 3 Dec 2018 21:08:48 +0000 (16:08 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
Removing CTF writer's implementation's dependency on `bt_object` and
`bt_value` makes it even more independent so as to be free to change the
`bt_object` and `bt_value` APIs without having to update the CTF writer
part.

Both APIs are not public as of this patch, so I'm hiding the public CTF
writer functions to get a trace's environment field (and their tests),
which is a `bt_ctf_value` object. This is not breaking backward
compatibility with Babeltrace 1.5.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
50 files changed:
include/babeltrace/ctf-writer/attributes-internal.h
include/babeltrace/ctf-writer/clock-class-internal.h
include/babeltrace/ctf-writer/clock-internal.h
include/babeltrace/ctf-writer/clock.h
include/babeltrace/ctf-writer/event-class-internal.h
include/babeltrace/ctf-writer/event-fields.h
include/babeltrace/ctf-writer/event-internal.h
include/babeltrace/ctf-writer/event-types.h
include/babeltrace/ctf-writer/event.h
include/babeltrace/ctf-writer/field-path-internal.h
include/babeltrace/ctf-writer/field-types-internal.h
include/babeltrace/ctf-writer/field-wrapper-internal.h
include/babeltrace/ctf-writer/fields-internal.h
include/babeltrace/ctf-writer/object-internal.h [new file with mode: 0644]
include/babeltrace/ctf-writer/object-pool-internal.h [new file with mode: 0644]
include/babeltrace/ctf-writer/object.h [new file with mode: 0644]
include/babeltrace/ctf-writer/resolve-internal.h
include/babeltrace/ctf-writer/stream-class-internal.h
include/babeltrace/ctf-writer/stream-class.h
include/babeltrace/ctf-writer/stream-internal.h
include/babeltrace/ctf-writer/stream.h
include/babeltrace/ctf-writer/trace-internal.h
include/babeltrace/ctf-writer/trace.h
include/babeltrace/ctf-writer/validation-internal.h
include/babeltrace/ctf-writer/values-internal.h [new file with mode: 0644]
include/babeltrace/ctf-writer/visitor.h
include/babeltrace/ctf-writer/writer-internal.h
include/babeltrace/ctf-writer/writer.h
lib/ctf-writer/Makefile.am
lib/ctf-writer/attributes.c
lib/ctf-writer/clock-class.c
lib/ctf-writer/clock.c
lib/ctf-writer/event-class.c
lib/ctf-writer/event.c
lib/ctf-writer/field-path.c
lib/ctf-writer/field-types.c
lib/ctf-writer/field-wrapper.c
lib/ctf-writer/fields.c
lib/ctf-writer/object-pool.c [new file with mode: 0644]
lib/ctf-writer/object.c [new file with mode: 0644]
lib/ctf-writer/resolve.c
lib/ctf-writer/stream-class.c
lib/ctf-writer/stream.c
lib/ctf-writer/trace.c
lib/ctf-writer/utils.c
lib/ctf-writer/validation.c
lib/ctf-writer/values.c [new file with mode: 0644]
lib/ctf-writer/visitor.c
lib/ctf-writer/writer.c
tests/lib/test_ctf_writer.c

index d0f19dfab26a128d60a9979bbac8b86ba4dcbe5b..8b372f6e04d7d72900eda63a9082a7afcd367f59 100644 (file)
@@ -30,35 +30,35 @@ extern "C" {
 
 #include <stdint.h>
 #include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/private-values.h>
+#include <babeltrace/ctf-writer/values-internal.h>
 
 BT_HIDDEN
-struct bt_private_value *bt_ctf_attributes_create(void);
+struct bt_ctf_private_value *bt_ctf_attributes_create(void);
 
 BT_HIDDEN
-void bt_ctf_attributes_destroy(struct bt_private_value *attr_obj);
+void bt_ctf_attributes_destroy(struct bt_ctf_private_value *attr_obj);
 
 BT_HIDDEN
-int64_t bt_ctf_attributes_get_count(struct bt_private_value *attr_obj);
+int64_t bt_ctf_attributes_get_count(struct bt_ctf_private_value *attr_obj);
 
 BT_HIDDEN
-const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj,
+const char *bt_ctf_attributes_get_field_name(struct bt_ctf_private_value *attr_obj,
                uint64_t index);
 
 BT_HIDDEN
-struct bt_private_value *bt_ctf_attributes_borrow_field_value(struct bt_private_value *attr_obj,
+struct bt_ctf_private_value *bt_ctf_attributes_borrow_field_value(struct bt_ctf_private_value *attr_obj,
                uint64_t index);
 
 BT_HIDDEN
-int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj,
-               const char *name, struct bt_private_value *value_obj);
+int bt_ctf_attributes_set_field_value(struct bt_ctf_private_value *attr_obj,
+               const char *name, struct bt_ctf_private_value *value_obj);
 
 BT_HIDDEN
-struct bt_private_value *bt_ctf_attributes_borrow_field_value_by_name(
-               struct bt_private_value *attr_obj, const char *name);
+struct bt_ctf_private_value *bt_ctf_attributes_borrow_field_value_by_name(
+               struct bt_ctf_private_value *attr_obj, const char *name);
 
 BT_HIDDEN
-int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj);
+int bt_ctf_attributes_freeze(struct bt_ctf_private_value *attr_obj);
 
 #ifdef __cplusplus
 }
index 04baaa32cf1f2d54fb61a0f569096ec40db2e1c0..f57434229754f5178fb71740a9f5bad40f8a5164 100644 (file)
@@ -25,7 +25,7 @@
  * SOFTWARE.
  */
 
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/object-pool-internal.h>
 #include <babeltrace/compat/uuid-internal.h>
@@ -35,7 +35,7 @@
 #include <glib.h>
 
 struct bt_ctf_clock_class {
-       struct bt_object base;
+       struct bt_ctf_object base;
        GString *name;
        GString *description;
        uint64_t frequency;
index d4c45f334ab50670e4c2caef466cb4e027a99df3..c263b1bee9cfd5e8684393f98ecf8c9ad0fac672 100644 (file)
 #include <babeltrace/ctf-writer/clock.h>
 #include <babeltrace/ctf-writer/clock-class-internal.h>
 #include <babeltrace/ctf-writer/trace-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <glib.h>
 #include <babeltrace/compat/uuid-internal.h>
 
 struct bt_ctf_clock {
-       struct bt_object base;
+       struct bt_ctf_object base;
        struct bt_ctf_clock_class *clock_class;
        uint64_t value;         /* Current clock value */
 };
index 485f7a5188740732de714be015fad7a3c3c4ad67..909ebe00d2caa9d916ebb0c3de7ab1d8845396a0 100644 (file)
@@ -29,7 +29,7 @@
  */
 
 #include <stdint.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <babeltrace/types.h>
 
 #ifdef __cplusplus
@@ -271,14 +271,14 @@ extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock,
 static inline
 void bt_ctf_clock_get(struct bt_ctf_clock *clock)
 {
-        bt_object_get_ref(clock);
+        bt_ctf_object_get_ref(clock);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_clock_put(struct bt_ctf_clock *clock)
 {
-        bt_object_put_ref(clock);
+        bt_ctf_object_put_ref(clock);
 }
 
 extern struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name,
index 5da23c23be6a72d1ebe83d82b9ed2b6236bf4307..3a7b8617d20b1f41eed70c10685dfe6aa03ea123 100644 (file)
 #include <babeltrace/ctf-writer/stream-class.h>
 #include <babeltrace/ctf-writer/stream.h>
 #include <babeltrace/ctf-writer/trace-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/values.h>
 #include <glib.h>
 
 struct bt_ctf_event_class_common {
-       struct bt_object base;
+       struct bt_ctf_object base;
        struct bt_ctf_field_type_common *context_field_type;
        struct bt_ctf_field_type_common *payload_field_type;
        int frozen;
@@ -70,18 +70,18 @@ struct bt_ctf_stream_class_common *bt_ctf_event_class_common_borrow_stream_class
                struct bt_ctf_event_class_common *event_class)
 {
        BT_ASSERT(event_class);
-       return (void *) bt_object_borrow_parent(&event_class->base);
+       return (void *) bt_ctf_object_borrow_parent(&event_class->base);
 }
 
 typedef struct bt_ctf_field_type_common *(*bt_ctf_field_type_structure_create_func)();
 
 BT_HIDDEN
 int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common *event_class,
-               const char *name, bt_object_release_func release_func,
+               const char *name, bt_ctf_object_release_func release_func,
                bt_ctf_field_type_structure_create_func ft_struct_create_func);
 
 BT_HIDDEN
-void bt_ctf_event_class_common_finalize(struct bt_object *obj);
+void bt_ctf_event_class_common_finalize(struct bt_ctf_object *obj);
 
 BT_HIDDEN
 int bt_ctf_event_class_common_validate_single_clock_class(
@@ -333,8 +333,9 @@ int bt_ctf_event_class_common_set_context_field_type(
                goto end;
        }
 
-       bt_object_put_ref(event_class->context_field_type);
-       event_class->context_field_type = bt_object_get_ref(context_ft);
+       bt_ctf_object_put_ref(event_class->context_field_type);
+       event_class->context_field_type = context_ft;
+       bt_ctf_object_get_ref(event_class->context_field_type);
        BT_LOGV("Set event class's context field type: "
                "event-class-addr=%p, event-class-name=\"%s\", "
                "event-class-id=%" PRId64 ", context-ft-addr=%p",
@@ -379,8 +380,9 @@ int bt_ctf_event_class_common_set_payload_field_type(
                goto end;
        }
 
-       bt_object_put_ref(event_class->payload_field_type);
-       event_class->payload_field_type = bt_object_get_ref(payload_ft);
+       bt_ctf_object_put_ref(event_class->payload_field_type);
+       event_class->payload_field_type = payload_ft;
+       bt_ctf_object_get_ref(event_class->payload_field_type);
        BT_LOGV("Set event class's payload field type: "
                "event-class-addr=%p, event-class-name=\"%s\", "
                "event-class-id=%" PRId64 ", payload-ft-addr=%p",
index 399c0e0416f3748d8e8a94f220fdc8d85930278e..f99f6812020a1789b29ac105cbc3056165ca445a 100644 (file)
@@ -28,7 +28,7 @@
  * http://www.efficios.com/ctf
  */
 
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <babeltrace/ctf-writer/field-types.h>
 #include <babeltrace/ctf-writer/fields.h>
 
@@ -40,7 +40,7 @@ extern "C" {
  * bt_ctf_field_get and bt_ctf_field_put: increment and decrement the
  * field's reference count.
  *
- * You may also use bt_object_get_ref() and bt_object_put_ref() with field objects.
+ * You may also use bt_ctf_object_get_ref() and bt_ctf_object_put_ref() with field objects.
  *
  * These functions ensure that the field won't be destroyed when it
  * is in use. The same number of get and put (plus one extra put to
@@ -57,14 +57,14 @@ extern "C" {
 static inline
 void bt_ctf_field_get(struct bt_ctf_field *field)
 {
-       bt_object_get_ref(field);
+       bt_ctf_object_get_ref(field);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_field_put(struct bt_ctf_field *field)
 {
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
 }
 
 #ifdef __cplusplus
index e6e15bdd62af40e7f76d71776ec31102cb496853..d6297570de7830e60cbea4fee8aed030fbf4067b 100644 (file)
@@ -41,7 +41,7 @@
 #include <babeltrace/ctf-writer/stream-internal.h>
 #include <babeltrace/ctf-writer/stream.h>
 #include <babeltrace/ctf-writer/validation-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/values.h>
 
 struct bt_ctf_stream_class;
@@ -49,7 +49,7 @@ struct bt_ctf_stream_pos;
 struct metadata_context;
 
 struct bt_ctf_event_common {
-       struct bt_object base;
+       struct bt_ctf_object base;
        struct bt_ctf_event_class_common *class;
        struct bt_ctf_field_wrapper *header_field;
        struct bt_ctf_field_common *stream_event_context_field;
@@ -93,7 +93,7 @@ BT_HIDDEN
 int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
                struct bt_ctf_event_class_common *event_class,
                struct bt_ctf_clock_class *init_expected_clock_class,
-               bool is_shared_with_parent, bt_object_release_func release_func,
+               bool is_shared_with_parent, bt_ctf_object_release_func release_func,
                bt_ctf_validation_flag_copy_field_type_func field_type_copy_func,
                bool must_be_in_trace,
                int (*map_clock_classes_func)(struct bt_ctf_stream_class_common *stream_class,
@@ -193,7 +193,7 @@ end:
 }
 
 static inline
-void bt_ctf_event_common_finalize(struct bt_object *obj,
+void bt_ctf_event_common_finalize(struct bt_ctf_object *obj,
                void (*field_release_func)(void *),
                void (*header_field_release_func)(void *, struct bt_ctf_event_common *))
 {
@@ -236,7 +236,7 @@ void bt_ctf_event_common_finalize(struct bt_object *obj,
                 * common ancestor with it to guarantee they would both have the
                 * same lifetime.
                 */
-               bt_object_put_ref(event->class);
+               bt_ctf_object_put_ref(event->class);
        }
 }
 
index 6e0295f60cce80c1f796106d074b66c667354e79..176fbb42eeef92baa50870a8fbfa41b8881166bb 100644 (file)
@@ -28,7 +28,7 @@
  * http://www.efficios.com/ctf
  */
 
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <babeltrace/ctf-writer/field-types.h>
 
 #ifdef __cplusplus
@@ -39,7 +39,7 @@ extern "C" {
  * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
  * the field type's reference count.
  *
- * You may also use bt_object_get_ref() and bt_object_put_ref() with field type objects.
+ * You may also use bt_ctf_object_get_ref() and bt_ctf_object_put_ref() with field type objects.
  *
  * These functions ensure that the field type won't be destroyed while it
  * is in use. The same number of get and put (plus one extra put to
@@ -56,14 +56,14 @@ extern "C" {
 static inline
 void bt_ctf_field_type_get(struct bt_ctf_field_type *type)
 {
-       bt_object_get_ref(type);
+       bt_ctf_object_get_ref(type);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_field_type_put(struct bt_ctf_field_type *type)
 {
-       bt_object_put_ref(type);
+       bt_ctf_object_put_ref(type);
 }
 
 #ifdef __cplusplus
index bac0010bcbcc499f4ff440a26211b7dcf7636259..c4e8965b8f1a487ba6c4d16c6a152ac167c10398 100644 (file)
@@ -28,7 +28,7 @@
  * http://www.efficios.com/ctf
  */
 
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -136,14 +136,14 @@ extern struct bt_ctf_event_class *bt_ctf_event_get_class(
 static inline
 void bt_ctf_event_get(struct bt_ctf_event *event)
 {
-       bt_object_get_ref(event);
+       bt_ctf_object_get_ref(event);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_event_put(struct bt_ctf_event *event)
 {
-       bt_object_put_ref(event);
+       bt_ctf_object_put_ref(event);
 }
 
 extern struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
@@ -199,14 +199,14 @@ extern struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(
 static inline
 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class)
 {
-       bt_object_get_ref(event_class);
+       bt_ctf_object_get_ref(event_class);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class)
 {
-       bt_object_put_ref(event_class);
+       bt_ctf_object_put_ref(event_class);
 }
 
 #ifdef __cplusplus
index f64cc93627ed9c87aa7445266ff8140ddb8f0ca6..8bf1b4b291f3fda2432b33a9de14cd142eb76c75 100644 (file)
  */
 
 #include <babeltrace/common-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/assert-internal.h>
 #include <babeltrace/ctf-writer/field-types.h>
 #include <glib.h>
 
 struct bt_ctf_field_path {
-       struct bt_object base;
+       struct bt_ctf_object base;
        enum bt_ctf_scope root;
 
        /*
index 2412d518df89fa4fdbcdbe84680b6c74041b800a..48a365386c965042ad2ecbe480db4316b7541a61 100644 (file)
@@ -36,7 +36,7 @@
 #include <babeltrace/ctf-writer/clock-class-internal.h>
 #include <babeltrace/ctf-writer/field-types.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/types.h>
 
 #define BT_ASSERT_PRE_CTF_FT_COMMON_HAS_ID(_ft, _type_id, _name)       \
@@ -79,7 +79,7 @@ struct bt_ctf_field_type_common_methods {
 };
 
 struct bt_ctf_field_type_common {
-       struct bt_object base;
+       struct bt_ctf_object base;
        enum bt_ctf_field_type_id id;
        unsigned int alignment;
 
@@ -171,7 +171,7 @@ enum bt_ctf_field_type_enumeration_mapping_iterator_type {
 };
 
 struct bt_ctf_field_type_enumeration_mapping_iterator {
-       struct bt_object base;
+       struct bt_ctf_object base;
 
        /* Owned by this */
        struct bt_ctf_field_type_common_enumeration *enumeration_ft;
@@ -281,45 +281,45 @@ typedef struct bt_ctf_field_common *(* bt_ctf_field_common_create_func)(
 
 BT_HIDDEN
 void bt_ctf_field_type_common_initialize(struct bt_ctf_field_type_common *ft,
-               bool init_bo, bt_object_release_func release_func,
+               bool init_bo, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
 void bt_ctf_field_type_common_integer_initialize(
                struct bt_ctf_field_type_common *ft,
-               unsigned int size, bt_object_release_func release_func,
+               unsigned int size, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
 void bt_ctf_field_type_common_floating_point_initialize(
                struct bt_ctf_field_type_common *ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
 void bt_ctf_field_type_common_enumeration_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *container_ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
 void bt_ctf_field_type_common_string_initialize(
                struct bt_ctf_field_type_common *ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
 void bt_ctf_field_type_common_structure_initialize(
                struct bt_ctf_field_type_common *ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
 void bt_ctf_field_type_common_array_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *element_ft,
-               unsigned int length, bt_object_release_func release_func,
+               unsigned int length, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
@@ -327,7 +327,7 @@ void bt_ctf_field_type_common_sequence_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *element_ft,
                const char *length_field_name,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
@@ -335,32 +335,32 @@ void bt_ctf_field_type_common_variant_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *tag_ft,
                const char *tag_name,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_integer_destroy(struct bt_object *obj);
+void bt_ctf_field_type_common_integer_destroy(struct bt_ctf_object *obj);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_floating_point_destroy(struct bt_object *obj);
+void bt_ctf_field_type_common_floating_point_destroy(struct bt_ctf_object *obj);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_object *obj);
+void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_ctf_object *obj);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_string_destroy(struct bt_object *obj);
+void bt_ctf_field_type_common_string_destroy(struct bt_ctf_object *obj);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_object *obj);
+void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_ctf_object *obj);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_array_destroy_recursive(struct bt_object *obj);
+void bt_ctf_field_type_common_array_destroy_recursive(struct bt_ctf_object *obj);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_object *obj);
+void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_ctf_object *obj);
 
 BT_HIDDEN
-void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_object *obj);
+void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_ctf_object *obj);
 
 BT_HIDDEN
 int bt_ctf_field_type_common_integer_validate(struct bt_ctf_field_type_common *ft);
index f75f43b4cc3198cc1728be2ea2fe9497baccb837..d3a49d7f87bcc80110144fdc814c83092cc2569a 100644 (file)
  */
 
 #include <babeltrace/ctf-writer/fields-internal.h>
-#include <babeltrace/object-pool-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-pool-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 
 struct bt_ctf_field_wrapper {
-       struct bt_object base;
+       struct bt_ctf_object base;
 
        /* Owned by this */
        struct bt_ctf_field_common *field;
@@ -42,6 +42,6 @@ void bt_ctf_field_wrapper_destroy(struct bt_ctf_field_wrapper *field);
 
 BT_HIDDEN
 struct bt_ctf_field_wrapper *bt_ctf_field_wrapper_create(
-               struct bt_object_pool *pool, struct bt_ctf_field_type *ft);
+               struct bt_ctf_object_pool *pool, struct bt_ctf_field_type *ft);
 
 #endif /* BABELTRACE_CTF_WRITER_FIELD_WRAPPER_INTERNAL_H */
index 3fb4852c95e11602ec5907c6494d6705996e4939..97e14484ccc7428dd2a26a08fad9ed5d8802d27c 100644 (file)
@@ -39,7 +39,7 @@
 #include <babeltrace/ctf-writer/fields.h>
 #include <babeltrace/ctf-writer/serialize-internal.h>
 #include <babeltrace/ctf-writer/utils-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/types.h>
 #include <glib.h>
 #include <inttypes.h>
@@ -79,7 +79,7 @@ struct bt_ctf_field_common_methods {
 };
 
 struct bt_ctf_field_common {
-       struct bt_object base;
+       struct bt_ctf_object base;
        struct bt_ctf_field_type_common *type;
        struct bt_ctf_field_common_methods *methods;
        bool payload_set;
@@ -166,7 +166,7 @@ struct bt_ctf_field_common *bt_ctf_field_common_copy(struct bt_ctf_field_common
 BT_HIDDEN
 int bt_ctf_field_common_structure_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                bt_ctf_field_common_create_func field_create_func,
                GDestroyNotify field_release_func);
@@ -174,7 +174,7 @@ int bt_ctf_field_common_structure_initialize(struct bt_ctf_field_common *field,
 BT_HIDDEN
 int bt_ctf_field_common_array_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                bt_ctf_field_common_create_func field_create_func,
                GDestroyNotify field_destroy_func);
@@ -182,14 +182,14 @@ int bt_ctf_field_common_array_initialize(struct bt_ctf_field_common *field,
 BT_HIDDEN
 int bt_ctf_field_common_sequence_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                GDestroyNotify field_destroy_func);
 
 BT_HIDDEN
 int bt_ctf_field_common_variant_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                bt_ctf_field_common_create_func field_create_func,
                GDestroyNotify field_release_func);
@@ -197,7 +197,7 @@ int bt_ctf_field_common_variant_initialize(struct bt_ctf_field_common *field,
 BT_HIDDEN
 int bt_ctf_field_common_string_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods);
 
 BT_HIDDEN
@@ -348,14 +348,14 @@ end:
 static inline
 void bt_ctf_field_common_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *ft, bool is_shared,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods)
 {
        BT_ASSERT(field);
        BT_ASSERT(ft);
-       bt_object_init(&field->base, is_shared, release_func);
+       bt_ctf_object_init(&field->base, is_shared, release_func);
        field->methods = methods;
-       field->type = bt_object_get_ref(ft);
+       field->type = (void *) bt_ctf_object_get_ref(ft);
 }
 
 static inline
@@ -696,7 +696,7 @@ void bt_ctf_field_common_finalize(struct bt_ctf_field_common *field)
 {
        BT_ASSERT(field);
        BT_LOGD_STR("Putting field's type.");
-       bt_object_put_ref(field->type);
+       bt_ctf_object_put_ref(field->type);
 }
 
 static inline
diff --git a/include/babeltrace/ctf-writer/object-internal.h b/include/babeltrace/ctf-writer/object-internal.h
new file mode 100644 (file)
index 0000000..1b5f3ae
--- /dev/null
@@ -0,0 +1,317 @@
+#ifndef BABELTRACE_CTF_WRITER_OBJECT_INTERNAL_H
+#define BABELTRACE_CTF_WRITER_OBJECT_INTERNAL_H
+
+/*
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <stdbool.h>
+
+struct bt_ctf_object;
+
+typedef void (*bt_ctf_object_release_func)(struct bt_ctf_object *);
+typedef void (*bt_ctf_object_parent_is_owner_listener_func)(
+               struct bt_ctf_object *);
+
+static inline
+void *bt_ctf_object_get_no_null_check(struct bt_ctf_object *obj);
+
+static inline
+void bt_ctf_object_put_no_null_check(struct bt_ctf_object *obj);
+
+/*
+ * Babeltrace object base.
+ *
+ * All objects publicly exposed by Babeltrace APIs must contain this
+ * object as their first member.
+ */
+struct bt_ctf_object {
+       /*
+        * True if this object is shared, that is, it has a reference
+        * count.
+        */
+       bool is_shared;
+
+       /*
+        * Current reference count.
+        */
+       unsigned long long ref_count;
+
+       /*
+        * Release function called when the object's reference count
+        * falls to zero. For an object with a parent, this function is
+        * bt_ctf_object_with_parent_release_func(), which calls
+        * `spec_release_func` below if there's no current parent.
+        */
+       bt_ctf_object_release_func release_func;
+
+       /*
+        * Specific release function called by
+        * bt_ctf_object_with_parent_release_func() or directly by a
+        * parent object.
+        */
+       bt_ctf_object_release_func spec_release_func;
+
+       /*
+        * Optional callback for an object with a parent, called by
+        * bt_ctf_object_with_parent_release_func() to indicate to the
+        * object that its parent is its owner.
+        */
+       bt_ctf_object_parent_is_owner_listener_func
+               parent_is_owner_listener_func;
+
+       /*
+        * Optional parent object.
+        */
+       struct bt_ctf_object *parent;
+};
+
+static inline
+unsigned long long bt_ctf_object_get_ref_count(struct bt_ctf_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+       return obj->ref_count;
+}
+
+static inline
+struct bt_ctf_object *bt_ctf_object_borrow_parent(struct bt_ctf_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+       return obj->parent;
+}
+
+static inline
+struct bt_ctf_object *bt_ctf_object_get_parent(struct bt_ctf_object *obj)
+{
+       struct bt_ctf_object *parent = bt_ctf_object_borrow_parent(obj);
+
+       if (parent) {
+               bt_ctf_object_get_no_null_check(parent);
+       }
+
+       return parent;
+}
+
+static inline
+void bt_ctf_object_set_parent(struct bt_ctf_object *child, struct bt_ctf_object *parent)
+{
+       BT_ASSERT(child);
+       BT_ASSERT(child->is_shared);
+
+#ifdef BT_LOGV
+       BT_LOGV("Setting object's parent: addr=%p, parent-addr=%p",
+               child, parent);
+#endif
+
+       /*
+        * It is assumed that a "child" having a parent is publicly
+        * reachable. Therefore, a reference to its parent must be
+        * taken. The reference to the parent will be released once the
+        * object's reference count falls to zero.
+        */
+       if (parent) {
+               BT_ASSERT(!child->parent);
+               child->parent = parent;
+               bt_ctf_object_get_no_null_check(parent);
+       } else {
+               if (child->parent) {
+                       bt_ctf_object_put_no_null_check(child->parent);
+               }
+
+               child->parent = NULL;
+       }
+}
+
+static inline
+void bt_ctf_object_try_spec_release(struct bt_ctf_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+       BT_ASSERT(obj->spec_release_func);
+
+       if (bt_ctf_object_get_ref_count(obj) == 0) {
+               obj->spec_release_func(obj);
+       }
+}
+
+static inline
+void bt_ctf_object_with_parent_release_func(struct bt_ctf_object *obj)
+{
+       if (obj->parent) {
+               /*
+                * Keep our own copy of the parent address because `obj`
+                * could be destroyed in
+                * obj->parent_is_owner_listener_func().
+                */
+               struct bt_ctf_object *parent = obj->parent;
+
+#ifdef BT_LOGV
+               BT_LOGV("Releasing parented object: addr=%p, ref-count=%llu, "
+                       "parent-addr=%p, parent-ref-count=%llu",
+                       obj, obj->ref_count,
+                       parent, parent->ref_count);
+#endif
+
+               if (obj->parent_is_owner_listener_func) {
+                       /*
+                        * Object has a chance to destroy itself here
+                        * under certain conditions and notify its
+                        * parent. At this point the parent is
+                        * guaranteed to exist because it's not put yet.
+                        */
+                       obj->parent_is_owner_listener_func(obj);
+               }
+
+               /* The release function will be invoked by the parent. */
+               bt_ctf_object_put_no_null_check(parent);
+       } else {
+               bt_ctf_object_try_spec_release(obj);
+       }
+}
+
+static inline
+void bt_ctf_object_init(struct bt_ctf_object *obj, bool is_shared,
+               bt_ctf_object_release_func release_func)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(!is_shared || release_func);
+       obj->is_shared = is_shared;
+       obj->release_func = release_func;
+       obj->parent_is_owner_listener_func = NULL;
+       obj->spec_release_func = NULL;
+       obj->parent = NULL;
+       obj->ref_count = 1;
+}
+
+static inline
+void bt_ctf_object_init_shared(struct bt_ctf_object *obj,
+               bt_ctf_object_release_func release_func)
+{
+       bt_ctf_object_init(obj, true, release_func);
+}
+
+static inline
+void bt_ctf_object_init_unique(struct bt_ctf_object *obj)
+{
+       bt_ctf_object_init(obj, false, NULL);
+}
+
+static inline
+void bt_ctf_object_init_shared_with_parent(struct bt_ctf_object *obj,
+               bt_ctf_object_release_func spec_release_func)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(spec_release_func);
+       bt_ctf_object_init_shared(obj, bt_ctf_object_with_parent_release_func);
+       obj->spec_release_func = spec_release_func;
+}
+
+static inline
+void bt_ctf_object_set_parent_is_owner_listener_func(struct bt_ctf_object *obj,
+               bt_ctf_object_parent_is_owner_listener_func func)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+       BT_ASSERT(obj->spec_release_func);
+       ((struct bt_ctf_object *) obj)->parent_is_owner_listener_func = func;
+}
+
+static inline
+void bt_ctf_object_inc_ref_count(struct bt_ctf_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+       obj->ref_count++;
+       BT_ASSERT(obj->ref_count != 0);
+}
+
+static inline
+void *bt_ctf_object_get_no_null_check_no_parent_check(struct bt_ctf_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+
+#ifdef BT_LOGV
+       BT_LOGV("Incrementing object's reference count: %llu -> %llu: "
+               "addr=%p, cur-count=%llu, new-count=%llu",
+               obj->ref_count, obj->ref_count + 1,
+               obj, obj->ref_count, obj->ref_count + 1);
+#endif
+
+       bt_ctf_object_inc_ref_count(obj);
+       return obj;
+}
+
+static inline
+void *bt_ctf_object_get_no_null_check(struct bt_ctf_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+
+       if (unlikely(obj->parent && bt_ctf_object_get_ref_count(obj) == 0)) {
+#ifdef BT_LOGV
+               BT_LOGV("Incrementing object's parent's reference count: "
+                       "addr=%p, parent-addr=%p", obj, obj->parent);
+#endif
+
+               bt_ctf_object_get_no_null_check(obj->parent);
+       }
+
+#ifdef BT_LOGV
+       BT_LOGV("Incrementing object's reference count: %llu -> %llu: "
+               "addr=%p, cur-count=%llu, new-count=%llu",
+               obj->ref_count, obj->ref_count + 1,
+               obj, obj->ref_count, obj->ref_count + 1);
+#endif
+
+       bt_ctf_object_inc_ref_count(obj);
+       return obj;
+}
+
+static inline
+void bt_ctf_object_put_no_null_check(struct bt_ctf_object *obj)
+{
+       BT_ASSERT(obj);
+       BT_ASSERT(obj->is_shared);
+       BT_ASSERT(obj->ref_count > 0);
+
+#ifdef BT_LOGV
+       BT_LOGV("Decrementing object's reference count: %llu -> %llu: "
+               "addr=%p, cur-count=%llu, new-count=%llu",
+               obj->ref_count, obj->ref_count - 1,
+               obj, obj->ref_count, obj->ref_count - 1);
+#endif
+
+       obj->ref_count--;
+
+       if (obj->ref_count == 0) {
+               BT_ASSERT(obj->release_func);
+               obj->release_func(obj);
+       }
+}
+
+#endif /* BABELTRACE_CTF_WRITER_OBJECT_INTERNAL_H */
diff --git a/include/babeltrace/ctf-writer/object-pool-internal.h b/include/babeltrace/ctf-writer/object-pool-internal.h
new file mode 100644 (file)
index 0000000..f72deb4
--- /dev/null
@@ -0,0 +1,183 @@
+#ifndef BABELTRACE_CTF_WRITER_OBJECT_POOL_INTERNAL_H
+#define BABELTRACE_CTF_WRITER_OBJECT_POOL_INTERNAL_H
+
+/*
+ * Copyright (c) 2018 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * This is a generic object pool to avoid memory allocation/deallocation
+ * for objects of which the lifespan is typically short, but which are
+ * created a lot.
+ *
+ * The object pool, thanks to two user functions, knows how to allocate
+ * a brand new object in memory when the pool is empty and how to
+ * destroy an object when we destroy the pool.
+ *
+ * The object pool's user is responsible for:
+ *
+ * * Setting whatever references the object needs to keep and reset some
+ *   properties _after_ calling bt_ctf_object_pool_create_object(). This is
+ *   typically done in the bt_*_create() function which calls
+ *   bt_ctf_object_pool_create_object() (which could call the user-provided
+ *   allocation function if the pool is empty) and then sets the
+ *   appropriate properties on the possibly recycled object.
+ *
+ * * Releasing whatever references the object keeps _before_ calling
+ *   bt_ctf_object_pool_recycle_object(). This is typically done in a custom
+ *   bt_*_recycle() function which does the necessary before calling
+ *   bt_ctf_object_pool_recycle_object() with an object ready to be reused
+ *   at any time.
+ */
+
+#include <glib.h>
+#include <babeltrace/ctf-writer/object-internal.h>
+
+typedef void *(*bt_ctf_object_pool_new_object_func)(void *data);
+typedef void *(*bt_ctf_object_pool_destroy_object_func)(void *obj, void *data);
+
+struct bt_ctf_object_pool {
+       /*
+        * Container of recycled objects, owned by this. The array's size
+        * is the pool's capacity.
+        */
+       GPtrArray *objects;
+
+       /*
+        * Pool's size, that is, number of elements in the array above,
+        * starting at index 0, which exist as recycled objects.
+        */
+       size_t size;
+
+       /* User functions */
+       struct {
+               /* Allocate a new object in memory */
+               bt_ctf_object_pool_new_object_func new_object;
+
+               /* Free direct and indirect memory occupied by object */
+               bt_ctf_object_pool_destroy_object_func destroy_object;
+       } funcs;
+
+       /* User data passed to user functions */
+       void *data;
+};
+
+/*
+ * Initializes an object pool which is already allocated.
+ */
+int bt_ctf_object_pool_initialize(struct bt_ctf_object_pool *pool,
+               bt_ctf_object_pool_new_object_func new_object_func,
+               bt_ctf_object_pool_destroy_object_func destroy_object_func,
+               void *data);
+
+/*
+ * Finalizes an object pool without deallocating it.
+ */
+void bt_ctf_object_pool_finalize(struct bt_ctf_object_pool *pool);
+
+/*
+ * Creates an object from an object pool. If the pool is empty, this
+ * function calls the "new" user function to allocate a new object
+ * before returning it. Otherwise this function returns a recycled
+ * object, removing it from the pool.
+ *
+ * The returned object is owned by the caller.
+ */
+static inline
+void *bt_ctf_object_pool_create_object(struct bt_ctf_object_pool *pool)
+{
+       struct bt_ctf_object *obj;
+
+       BT_ASSERT(pool);
+
+#ifdef BT_LOGV
+       BT_LOGV("Creating object from pool: pool-addr=%p, pool-size=%zu, pool-cap=%u",
+               pool, pool->size, pool->objects->len);
+#endif
+
+       if (pool->size > 0) {
+               /* Pick one from the pool */
+               pool->size--;
+               obj = pool->objects->pdata[pool->size];
+               pool->objects->pdata[pool->size] = NULL;
+               goto end;
+       }
+
+       /* Pool is empty: create a brand new object */
+#ifdef BT_LOGV
+       BT_LOGV("Pool is empty: allocating new object: pool-addr=%p",
+               pool);
+#endif
+
+       obj = pool->funcs.new_object(pool->data);
+
+end:
+#ifdef BT_LOGV
+       BT_LOGV("Created one object from pool: pool-addr=%p, obj-addr=%p",
+               pool, obj);
+#endif
+
+       return obj;
+}
+
+/*
+ * Recycles an object, that is, puts it back into the pool.
+ *
+ * The pool becomes the sole owner of the object to recycle.
+ */
+static inline
+void bt_ctf_object_pool_recycle_object(struct bt_ctf_object_pool *pool, void *obj)
+{
+       struct bt_ctf_object *bt_obj = obj;
+
+       BT_ASSERT(pool);
+       BT_ASSERT(obj);
+
+#ifdef BT_LOGV
+       BT_LOGV("Recycling object: pool-addr=%p, pool-size=%zu, pool-cap=%u, obj-addr=%p",
+               pool, pool->size, pool->objects->len, obj);
+#endif
+
+       if (pool->size == pool->objects->len) {
+               /* Backing array is full: make place for recycled object */
+#ifdef BT_LOGV
+               BT_LOGV("Object pool is full: increasing object pool capacity: "
+                       "pool-addr=%p, old-pool-cap=%u, new-pool-cap=%u",
+                       pool, pool->objects->len, pool->objects->len + 1);
+#endif
+               g_ptr_array_set_size(pool->objects, pool->size + 1);
+       }
+
+       /* Reset reference count to 1 since it could be 0 now */
+       bt_obj->ref_count = 1;
+
+       /* Back to the pool */
+       pool->objects->pdata[pool->size] = obj;
+       pool->size++;
+
+#ifdef BT_LOGV
+       BT_LOGV("Recycled object: pool-addr=%p, pool-size=%zu, pool-cap=%u, obj-addr=%p",
+               pool, pool->size, pool->objects->len, obj);
+#endif
+}
+
+#endif /* BABELTRACE_CTF_WRITER_OBJECT_POOL_INTERNAL_H */
diff --git a/include/babeltrace/ctf-writer/object.h b/include/babeltrace/ctf-writer/object.h
new file mode 100644 (file)
index 0000000..12df751
--- /dev/null
@@ -0,0 +1,215 @@
+#ifndef BABELTRACE_CTF_WRITER_OBJECT_H
+#define BABELTRACE_CTF_WRITER_OBJECT_H
+
+/*
+ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
+ * Copyright (c) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+@defgroup refs Reference counting management
+@ingroup apiref
+@brief Common reference counting management for all Babeltrace objects.
+
+@code
+#include <babeltrace/ctf-writer/object.h>
+@endcode
+
+The macros and functions of this module are everything that is needed
+to handle the <strong><em>reference counting</em></strong> of
+Babeltrace objects.
+
+Any Babeltrace object can be shared by multiple owners thanks to
+<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
+counting</a>.
+
+The Babeltrace C API complies with the following key principles:
+
+1. When you call an API function which accepts a Babeltrace object
+   pointer as a parameter, the API function <strong>borrows the
+   reference</strong> for the <strong>duration of the function</strong>.
+
+   @image html ref-count-user-calls.png
+
+   The API function can also get a new reference if the system needs a
+   more persistent reference, but the ownership is <strong>never
+   transferred</strong> from the caller to the API function.
+
+   In other words, the caller still owns the object after calling any
+   API function: no function "steals" the user's reference (except
+   bt_ctf_object_put_ref()).
+
+2. An API function which \em returns a Babeltrace object pointer to the
+   user returns a <strong>new reference</strong>. The caller becomes an
+   owner of the object.
+
+   @image html ref-count-api-returns.png
+
+   It is your responsibility to discard the object when you don't
+   need it anymore with bt_ctf_object_put_ref().
+
+   For example, see bt_ctf_value_array_get().
+
+3. A Babeltrace object pointer received as a parameter in a user
+   function called back from an API function is a
+   <strong>borrowed</strong>, or <strong>weak reference</strong>: if you
+   need a reference which is more persistent than the duration of the
+   user function, call bt_ctf_object_get_ref() on the pointer.
+
+   @image html ref-count-callback.png
+
+   For example, see bt_ctf_value_map_foreach_entry().
+
+The two macros BT_CTF_OBJECT_PUT_REF_AND_RESET() and BT_CTF_OBJECT_MOVE_REF() operate on \em variables rather
+than pointer values. You should use BT_CTF_OBJECT_PUT_REF_AND_RESET() instead of bt_ctf_object_put_ref() when
+possible to avoid "double puts". For the same reason, you should use use
+BT_CTF_OBJECT_MOVE_REF() instead of performing manual reference moves between
+variables.
+
+@file
+@brief Reference counting management macros and functions.
+@sa refs
+
+@addtogroup refs
+@{
+*/
+
+/**
+@brief Calls bt_ctf_object_put_ref() on a variable named \p _var, then
+       sets \p _var to \c NULL.
+
+Using this macro is considered safer than calling bt_ctf_object_put_ref() because it
+makes sure that the variable which used to contain a reference to a
+Babeltrace object is set to \c NULL so that a future BT_CTF_OBJECT_PUT_REF_AND_RESET() or
+bt_ctf_object_put_ref() call will not cause another, unwanted reference decrementation.
+
+@param[in,out] _var    Name of a variable containing a
+                       Babeltrace object's address (this address
+                       can be \c NULL).
+
+@post <strong>If \p _var does not contain \p NULL</strong>,
+       its reference count is decremented.
+@post \p _var contains \c NULL.
+
+@sa BT_CTF_OBJECT_MOVE_REF(): Transfers the ownership of a Babeltrace object from a
+       variable to another.
+*/
+#define BT_CTF_OBJECT_PUT_REF_AND_RESET(_var)  \
+       do {                                    \
+               bt_ctf_object_put_ref(_var);    \
+               (_var) = NULL;                  \
+       } while (0)
+
+/**
+@brief Transfers the ownership of a Babeltrace object from a variable
+       named \p _var_src to a variable named \p _var_dst.
+
+This macro implements the following common pattern:
+
+  1. Call bt_ctf_object_put_ref() on \p _var_dst to make sure the previous reference
+     held by \p _var_dst is discarded.
+  2. Assign \p _var_src to \p _var_dst.
+  3. Set \p _var_src to \c NULL to avoid future, unwanted reference
+     decrementation of \p _var_src.
+
+@warning
+You must \em not use this macro when both \p _var_dst and
+\p _var_src contain the same Babeltrace object address and the reference
+count of this object is 1. The initial call to bt_ctf_object_put_ref() on \p _var_dst
+would destroy the object and leave a dangling pointer in \p _var_dst.
+
+@param[in,out] _var_dst        Name of the destination variable, containing
+                       either the address of a Babeltrace object to
+                       put first, or \c NULL.
+@param[in,out] _var_src        Name of the source variable, containing
+                       either the address of a Babeltrace object to
+                       move, or \c NULL.
+
+@pre <strong>If \p _var_dst and \p _var_src contain the same
+       value which is not \c NULL</strong>, this object's reference
+       count is greater than 1.
+@post <strong>If \c _var_dst is not \c NULL</strong>, its reference
+       count is decremented.
+@post \p _var_dst is equal to the value of \p _var_src \em before
+       you called this macro.
+@post \p _var_src is \c NULL.
+
+@sa BT_CTF_OBJECT_PUT_REF_AND_RESET(): Calls bt_ctf_object_put_ref() on a variable, then sets it to \c NULL.
+*/
+#define BT_CTF_OBJECT_MOVE_REF(_var_dst, _var_src)     \
+       do {                                    \
+               bt_ctf_object_put_ref(_var_dst);        \
+               (_var_dst) = (_var_src);        \
+               (_var_src) = NULL;              \
+       } while (0)
+
+/**
+@brief  Increments the reference count of the Babeltrace object \p obj.
+
+@param[in] obj Babeltrace object of which to get a new reference
+               (can be \c NULL).
+@returns       \p obj
+
+@post <strong>If \c obj is not \c NULL</strong>, its reference
+       count is incremented.
+
+@sa bt_ctf_object_put_ref(): Decrements the reference count of a Babeltrace object.
+*/
+void *bt_ctf_object_get_ref(void *obj);
+
+/**
+@brief Decrements the reference count of the Babeltrace object
+       \p obj.
+
+When the object's reference count reaches 0, the object can no longer
+be accessed and is considered \em destroyed.
+
+@remarks
+You should use the BT_CTF_OBJECT_PUT_REF_AND_RESET() macro instead of calling bt_ctf_object_put_ref() since the
+former is generally safer.
+
+@param[in] obj Babeltrace object of which to drop a reference
+               (can be \c NULL).
+
+@post <strong>If \c obj is not \c NULL</strong>, its reference
+       count is decremented.
+
+@sa BT_CTF_OBJECT_PUT_REF_AND_RESET(): Calls bt_ctf_object_put_ref() on a variable, then sets it to \c NULL.
+@sa BT_CTF_OBJECT_MOVE_REF(): Transfers the ownership of a Babeltrace object from a
+       variable to another.
+@sa bt_ctf_object_get_ref(): Increments the reference count of a Babeltrace object.
+*/
+void bt_ctf_object_put_ref(void *obj);
+
+/**
+@}
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_CTF_WRITER_OBJECT_H */
index bd8e14682a554c6438db3d25d5bb303789c1af77..340694e5ab0e87cfeb107209eedcf5f3e9049133 100644 (file)
@@ -29,7 +29,7 @@
 
 #include <babeltrace/ctf-writer/field-types.h>
 #include <babeltrace/ctf-writer/field-types-internal.h>
-#include <babeltrace/private-values.h>
+#include <babeltrace/ctf-writer/values-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <glib.h>
 
@@ -58,7 +58,7 @@ enum bt_ctf_resolve_flag {
  * All parameters are owned by the caller.
  */
 BT_HIDDEN
-int bt_ctf_resolve_types(struct bt_private_value *environment,
+int bt_ctf_resolve_types(struct bt_ctf_private_value *environment,
                struct bt_ctf_field_type_common *packet_header_type,
                struct bt_ctf_field_type_common *packet_context_type,
                struct bt_ctf_field_type_common *event_header_type,
index dbb003f49d8a71e2bca7a25a752ba15e1d7da35f..83f0bd4136161fda5edf210a6349e8acfe041100 100644 (file)
 #include <babeltrace/ctf-writer/utils-internal.h>
 #include <babeltrace/ctf-writer/validation-internal.h>
 #include <babeltrace/ctf-writer/visitor.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <inttypes.h>
 
 struct bt_ctf_stream_class_common {
-       struct bt_object base;
+       struct bt_ctf_object base;
        GString *name;
 
        /* Array of pointers to event class addresses */
@@ -89,7 +89,7 @@ struct bt_ctf_event_class_common;
 
 BT_HIDDEN
 int bt_ctf_stream_class_common_initialize(struct bt_ctf_stream_class_common *stream_class,
-               const char *name, bt_object_release_func release_func);
+               const char *name, bt_ctf_object_release_func release_func);
 
 BT_HIDDEN
 void bt_ctf_stream_class_common_finalize(struct bt_ctf_stream_class_common *stream_class);
@@ -155,7 +155,7 @@ struct bt_ctf_trace_common *bt_ctf_stream_class_common_borrow_trace(
                struct bt_ctf_stream_class_common *stream_class)
 {
        BT_ASSERT(stream_class);
-       return (void *) bt_object_borrow_parent(&stream_class->base);
+       return (void *) bt_ctf_object_borrow_parent(&stream_class->base);
 }
 
 static inline
@@ -357,9 +357,9 @@ int bt_ctf_stream_class_common_set_packet_context_field_type(
                goto end;
        }
 
-       bt_object_put_ref(stream_class->packet_context_field_type);
-       bt_object_get_ref(packet_context_type);
+       bt_ctf_object_put_ref(stream_class->packet_context_field_type);
        stream_class->packet_context_field_type = packet_context_type;
+       bt_ctf_object_get_ref(stream_class->packet_context_field_type);
        BT_LOGV("Set stream class's packet context field type: "
                "addr=%p, name=\"%s\", id=%" PRId64 ", "
                "packet-context-ft-addr=%p",
@@ -434,8 +434,9 @@ int bt_ctf_stream_class_common_set_event_header_field_type(
                goto end;
        }
 
-       bt_object_put_ref(stream_class->event_header_field_type);
-       stream_class->event_header_field_type = bt_object_get_ref(event_header_type);
+       bt_ctf_object_put_ref(stream_class->event_header_field_type);
+       stream_class->event_header_field_type = event_header_type;
+       bt_ctf_object_get_ref(stream_class->event_header_field_type);
        BT_LOGV("Set stream class's event header field type: "
                "addr=%p, name=\"%s\", id=%" PRId64 ", "
                "event-header-ft-addr=%p",
@@ -503,8 +504,9 @@ int bt_ctf_stream_class_common_set_event_context_field_type(
                goto end;
        }
 
-       bt_object_put_ref(stream_class->event_context_field_type);
-       stream_class->event_context_field_type = bt_object_get_ref(event_context_type);
+       bt_ctf_object_put_ref(stream_class->event_context_field_type);
+       stream_class->event_context_field_type = event_context_type;
+       bt_ctf_object_get_ref(stream_class->event_context_field_type);
        BT_LOGV("Set stream class's event context field type: "
                "addr=%p, name=\"%s\", id=%" PRId64 ", "
                "event-context-ft-addr=%p",
index eb8da8a1fb77fd5d4e2faa9c5c8babba50c2d520..f9f494366d73a6d60c64d5265cc6f52315bdc2d1 100644 (file)
@@ -28,7 +28,7 @@
  * http://www.efficios.com/ctf
  */
 
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -105,14 +105,14 @@ extern struct bt_ctf_clock *bt_ctf_stream_class_get_clock(
 static inline
 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class)
 {
-       bt_object_get_ref(stream_class);
+       bt_ctf_object_get_ref(stream_class);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class)
 {
-       bt_object_put_ref(stream_class);
+       bt_ctf_object_put_ref(stream_class);
 }
 
 #ifdef __cplusplus
index 9928f16f0c897131e7339d4f7e1cd6158bd97938..1b74770cef0eec5dbd5539510bcc641df4017e56 100644 (file)
 #include <babeltrace/ctf-writer/stream-internal.h>
 #include <babeltrace/ctf-writer/stream.h>
 #include <babeltrace/ctf-writer/utils-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <stdint.h>
 
 struct bt_ctf_stream_common;
 
 struct bt_ctf_stream_common {
-       struct bt_object base;
+       struct bt_ctf_object base;
        int64_t id;
        struct bt_ctf_stream_class_common *stream_class;
        GString *name;
@@ -52,7 +52,7 @@ BT_HIDDEN
 int bt_ctf_stream_common_initialize(
                struct bt_ctf_stream_common *stream,
                struct bt_ctf_stream_class_common *stream_class, const char *name,
-               uint64_t id, bt_object_release_func release_func);
+               uint64_t id, bt_ctf_object_release_func release_func);
 
 BT_HIDDEN
 void bt_ctf_stream_common_finalize(struct bt_ctf_stream_common *stream);
index ff14adebfc7ba6e3fe92d3708c33464db77ae064..bc368f4e435ea73e84873adeb54620600c8fb61f 100644 (file)
@@ -170,14 +170,14 @@ extern int64_t bt_ctf_stream_get_id(struct bt_ctf_stream *stream);
 static inline
 void bt_ctf_stream_get(struct bt_ctf_stream *stream)
 {
-       bt_object_get_ref(stream);
+       bt_ctf_object_get_ref(stream);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_stream_put(struct bt_ctf_stream *stream)
 {
-       bt_object_put_ref(stream);
+       bt_ctf_object_put_ref(stream);
 }
 
 #ifdef __cplusplus
index 10a10f28b95feb376d89e31dfa5c8b1a72f3c0e4..b11042568fed9d4234d2d9eb5b37609edccb37f0 100644 (file)
 #include <babeltrace/ctf-writer/stream-class-internal.h>
 #include <babeltrace/ctf-writer/trace.h>
 #include <babeltrace/ctf-writer/validation-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/types.h>
-#include <babeltrace/values.h>
-#include <babeltrace/private-values.h>
+#include <babeltrace/values-internal.h>
 #include <glib.h>
 #include <sys/types.h>
 
 struct bt_ctf_trace_common {
-       struct bt_object base;
+       struct bt_ctf_object base;
        GString *name;
        int frozen;
        unsigned char uuid[BABELTRACE_UUID_LEN];
        bt_bool uuid_set;
        enum bt_ctf_byte_order native_byte_order;
-       struct bt_private_value *environment;
+       struct bt_ctf_private_value *environment;
        GPtrArray *clock_classes; /* Array of pointers to bt_ctf_clock_class */
        GPtrArray *stream_classes; /* Array of ptrs to bt_ctf_stream_class_common */
        GPtrArray *streams; /* Array of ptrs to bt_ctf_stream_common */
@@ -72,7 +71,7 @@ bt_bool bt_ctf_trace_common_has_clock_class(struct bt_ctf_trace_common *trace,
 
 BT_HIDDEN
 int bt_ctf_trace_common_initialize(struct bt_ctf_trace_common *trace,
-               bt_object_release_func release_func);
+               bt_ctf_object_release_func release_func);
 
 BT_HIDDEN
 void bt_ctf_trace_common_finalize(struct bt_ctf_trace_common *trace);
@@ -99,7 +98,7 @@ int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace, const unsign
 
 BT_HIDDEN
 int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace,
-               const char *name, struct bt_private_value *value);
+               const char *name, struct bt_ctf_private_value *value);
 
 BT_HIDDEN
 int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common *trace,
@@ -131,7 +130,7 @@ bt_ctf_trace_common_get_environment_field_name_by_index(
 }
 
 static inline
-struct bt_private_value *
+struct bt_ctf_private_value *
 bt_ctf_trace_common_borrow_environment_field_value_by_index(
                struct bt_ctf_trace_common *trace, uint64_t index)
 {
@@ -140,7 +139,7 @@ bt_ctf_trace_common_borrow_environment_field_value_by_index(
 }
 
 static inline
-struct bt_private_value *
+struct bt_ctf_private_value *
 bt_ctf_trace_common_borrow_environment_field_value_by_name(
                struct bt_ctf_trace_common *trace, const char *name)
 {
@@ -370,4 +369,22 @@ BT_HIDDEN
 int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace,
                struct bt_ctf_clock_class *clock_class);
 
+BT_HIDDEN
+int64_t bt_ctf_trace_get_environment_field_count(
+               struct bt_ctf_trace *trace);
+
+BT_HIDDEN
+const char *bt_ctf_trace_get_environment_field_name_by_index(
+               struct bt_ctf_trace *trace, uint64_t index);
+
+BT_HIDDEN
+struct bt_ctf_value *
+bt_ctf_trace_get_environment_field_value_by_index(struct bt_ctf_trace *trace,
+               uint64_t index);
+
+BT_HIDDEN
+struct bt_ctf_value *
+bt_ctf_trace_get_environment_field_value_by_name(
+               struct bt_ctf_trace *trace, const char *name);
+
 #endif /* BABELTRACE_CTF_WRITER_TRACE_INTERNAL_H */
index 944af83a01e6227b40ab74e0307c4d2282bd4662..27b18214958bfa39ea872b238aad65bb50777c81 100644 (file)
@@ -48,21 +48,6 @@ extern const unsigned char *bt_ctf_trace_get_uuid(
 extern int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace,
                const unsigned char *uuid);
 
-extern int64_t bt_ctf_trace_get_environment_field_count(
-               struct bt_ctf_trace *trace);
-
-extern const char *
-bt_ctf_trace_get_environment_field_name_by_index(
-               struct bt_ctf_trace *trace, uint64_t index);
-
-extern struct bt_value *
-bt_ctf_trace_get_environment_field_value_by_index(struct bt_ctf_trace *trace,
-               uint64_t index);
-
-extern struct bt_value *
-bt_ctf_trace_get_environment_field_value_by_name(
-               struct bt_ctf_trace *trace, const char *name);
-
 extern int bt_ctf_trace_set_environment_field_integer(
                struct bt_ctf_trace *trace, const char *name,
                int64_t value);
index ead8c8b484d559b07b392b933d1de221e4dc8c01..235a262394cceae2de235a534f4dc2e8996e1585 100644 (file)
@@ -23,8 +23,8 @@
  * SOFTWARE.
  */
 
-#include <babeltrace/private-values.h>
 #include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/values-internal.h>
 
 struct bt_ctf_trace_common;
 struct bt_ctf_stream_class_common;
@@ -80,7 +80,7 @@ struct bt_ctf_validation_output {
  * All parameters are owned by the caller.
  */
 BT_HIDDEN
-int bt_ctf_validate_class_types(struct bt_private_value *environment,
+int bt_ctf_validate_class_types(struct bt_ctf_private_value *environment,
                struct bt_ctf_field_type_common *packet_header_type,
                struct bt_ctf_field_type_common *packet_context_type,
                struct bt_ctf_field_type_common *event_header_type,
diff --git a/include/babeltrace/ctf-writer/values-internal.h b/include/babeltrace/ctf-writer/values-internal.h
new file mode 100644 (file)
index 0000000..332626f
--- /dev/null
@@ -0,0 +1,334 @@
+#ifndef BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
+#define BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H
+
+/*
+ * Copyright (c) 2015-2017 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015-2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/babeltrace-internal.h>
+
+struct bt_ctf_value;
+struct bt_ctf_private_value;
+
+/**
+@brief Status codes.
+*/
+enum bt_ctf_value_status {
+       /// Operation canceled.
+       BT_CTF_VALUE_STATUS_CANCELED    = 125,
+
+       /// Cannot allocate memory.
+       BT_CTF_VALUE_STATUS_NOMEM       = -12,
+
+       /// Okay, no error.
+       BT_CTF_VALUE_STATUS_OK          = 0,
+};
+
+BT_HIDDEN
+enum bt_ctf_value_status _bt_ctf_value_freeze(struct bt_ctf_value *object);
+
+#ifdef BT_DEV_MODE
+# define bt_ctf_value_freeze   _bt_ctf_value_freeze
+#else
+# define bt_ctf_value_freeze(_value)
+#endif /* BT_DEV_MODE */
+
+struct bt_ctf_value *bt_ctf_value_null;
+
+enum bt_ctf_value_type {
+       /// Null value object.
+       BT_CTF_VALUE_TYPE_NULL =                0,
+
+       /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
+       BT_CTF_VALUE_TYPE_BOOL =                1,
+
+       /// Integer value object (holds a signed 64-bit integer raw value).
+       BT_CTF_VALUE_TYPE_INTEGER =             2,
+
+       /// Floating point number value object (holds a \c double raw value).
+       BT_CTF_VALUE_TYPE_REAL =                3,
+
+       /// String value object.
+       BT_CTF_VALUE_TYPE_STRING =              4,
+
+       /// Array value object.
+       BT_CTF_VALUE_TYPE_ARRAY =               5,
+
+       /// Map value object.
+       BT_CTF_VALUE_TYPE_MAP =         6,
+};
+
+BT_HIDDEN
+enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object);
+
+static inline
+bt_bool bt_ctf_value_is_null(const struct bt_ctf_value *object)
+{
+       return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_NULL;
+}
+
+static inline
+bt_bool bt_ctf_value_is_bool(const struct bt_ctf_value *object)
+{
+       return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_BOOL;
+}
+
+static inline
+bt_bool bt_ctf_value_is_integer(const struct bt_ctf_value *object)
+{
+       return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_INTEGER;
+}
+
+static inline
+bt_bool bt_ctf_value_is_real(const struct bt_ctf_value *object)
+{
+       return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_REAL;
+}
+
+static inline
+bt_bool bt_ctf_value_is_string(const struct bt_ctf_value *object)
+{
+       return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_STRING;
+}
+
+static inline
+bt_bool bt_ctf_value_is_array(const struct bt_ctf_value *object)
+{
+       return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_ARRAY;
+}
+
+static inline
+bt_bool bt_ctf_value_is_map(const struct bt_ctf_value *object)
+{
+       return bt_ctf_value_get_type(object) == BT_CTF_VALUE_TYPE_MAP;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy,
+               const struct bt_ctf_value *object);
+
+BT_HIDDEN
+bt_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b);
+
+BT_HIDDEN
+bt_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj);
+
+BT_HIDDEN
+int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj);
+
+BT_HIDDEN
+double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj);
+
+BT_HIDDEN
+const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj);
+
+BT_HIDDEN
+uint64_t bt_ctf_value_array_get_size(const struct bt_ctf_value *array_obj);
+
+static inline
+bt_bool bt_ctf_value_array_is_empty(const struct bt_ctf_value *array_obj)
+{
+       return bt_ctf_value_array_get_size(array_obj) == 0;
+}
+
+BT_HIDDEN
+struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index(
+               const struct bt_ctf_value *array_obj, uint64_t index);
+
+BT_HIDDEN
+uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj);
+
+static inline
+bt_bool bt_ctf_value_map_is_empty(const struct bt_ctf_value *map_obj)
+{
+       return bt_ctf_value_map_get_size(map_obj) == 0;
+}
+
+BT_HIDDEN
+struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value(
+               const struct bt_ctf_value *map_obj, const char *key);
+
+typedef bt_bool (* bt_ctf_value_map_foreach_entry_cb)(const char *key,
+       struct bt_ctf_value *object, void *data);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_value_map_foreach_entry(
+               const struct bt_ctf_value *map_obj,
+               bt_ctf_value_map_foreach_entry_cb cb, void *data);
+
+BT_HIDDEN
+bt_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj,
+               const char *key);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_value_map_extend(
+               struct bt_ctf_private_value **extended_map_obj,
+               const struct bt_ctf_value *base_map_obj,
+               const struct bt_ctf_value *extension_map_obj);
+
+
+struct bt_ctf_value;
+struct bt_ctf_private_value;
+
+struct bt_ctf_private_value *bt_ctf_private_value_null;
+
+static inline
+struct bt_ctf_value *bt_ctf_private_value_as_value(
+               struct bt_ctf_private_value *priv_value)
+{
+       return (void *) priv_value;
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_bool val);
+
+BT_HIDDEN
+void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj,
+               bt_bool val);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init(
+               int64_t val);
+
+BT_HIDDEN
+void bt_ctf_private_value_integer_set(
+               struct bt_ctf_private_value *integer_obj, int64_t val);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_real_create(void);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val);
+
+BT_HIDDEN
+void bt_ctf_private_value_real_set(
+               struct bt_ctf_private_value *real_obj, double val);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_string_create(void);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_string_create_init(
+               const char *val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_string_set(
+               struct bt_ctf_private_value *string_obj,
+               const char *val);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_array_create(void);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_array_borrow_element_by_index(
+               const struct bt_ctf_private_value *array_obj, uint64_t index);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_element(
+               struct bt_ctf_private_value *array_obj,
+               struct bt_ctf_value *element_obj);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_bool_element(
+               struct bt_ctf_private_value *array_obj,
+               bt_bool val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_integer_element(
+               struct bt_ctf_private_value *array_obj,
+               int64_t val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element(
+               struct bt_ctf_private_value *array_obj,
+               double val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element(
+               struct bt_ctf_private_value *array_obj, const char *val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element(
+               struct bt_ctf_private_value *array_obj);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element(
+               struct bt_ctf_private_value *array_obj);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_set_element_by_index(
+               struct bt_ctf_private_value *array_obj, uint64_t index,
+               struct bt_ctf_value *element_obj);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_map_create(void);
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_map_borrow_entry_value(
+               const struct bt_ctf_private_value *map_obj, const char *key);
+
+typedef bt_bool (* bt_ctf_private_value_map_foreach_entry_cb)(const char *key,
+               struct bt_ctf_private_value *object, void *data);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_foreach_entry(
+               const struct bt_ctf_private_value *map_obj,
+               bt_ctf_private_value_map_foreach_entry_cb cb, void *data);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_entry(
+               struct bt_ctf_private_value *map_obj, const char *key,
+               struct bt_ctf_value *element_obj);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_bool_entry(
+               struct bt_ctf_private_value *map_obj, const char *key, bt_bool val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_integer_entry(
+               struct bt_ctf_private_value *map_obj, const char *key, int64_t val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_real_entry(
+               struct bt_ctf_private_value *map_obj, const char *key, double val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_string_entry(
+               struct bt_ctf_private_value *map_obj, const char *key,
+               const char *val);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_array_entry(
+               struct bt_ctf_private_value *map_obj, const char *key);
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_map_entry(
+               struct bt_ctf_private_value *map_obj, const char *key);
+
+#endif /* BABELTRACE_CTF_WRITER_VALUES_INTERNAL_H */
index 60d0a45bc39f3ca9ea438be032997ed882e70d09..f6bbd0c4f59028d9e47e466baf43ac3f4df4e7c2 100644 (file)
@@ -63,18 +63,18 @@ pre-order fashion.
 */
 
 /**
-@struct bt_object
+@struct bt_ctf_object
 @brief A CTF IR object wrapper.
 
 This structure wraps both a CTF IR object and its type
-(see #bt_object_type). It is used in the visiting function.
+(see #bt_ctf_object_type). It is used in the visiting function.
 
-You can use the bt_object_get_type() and
-bt_object_get_object() accessors to get the type and wrapped
+You can use the bt_ctf_object_get_type() and
+bt_ctf_object_get_object() accessors to get the type and wrapped
 CTF IR object of a CTF IR object wrapper.
 
 A CTF IR object wrapper has <strong>no reference count</strong>: do \em
-not use bt_object_put_ref() or bt_object_get_ref() on it.
+not use bt_ctf_object_put_ref() or bt_ctf_object_get_ref() on it.
 
 @sa ctfirvisitor
 */
@@ -114,7 +114,7 @@ bt_ctf_stream_class_visit() when visiting the CTF IR object wrapper
 \p object.
 
 \p object has <strong>no reference count</strong>: do \em not use
-bt_object_put_ref() or bt_object_get_ref() on it.
+bt_ctf_object_put_ref() or bt_ctf_object_get_ref() on it.
 
 @param[in] object      Currently visited CTF IR object wrapper.
 @param[in] data                User data.
@@ -149,7 +149,7 @@ enum bt_ctf_visitor_object_type bt_ctf_visitor_object_get_type(
        wrapper \p object.
 
 The reference count of \p object is \em not incremented by this
-function. On success, you must call bt_object_get_ref() on the return value to
+function. On success, you must call bt_ctf_object_get_ref() on the return value to
 have your own reference.
 
 @param[in] object      Object wrapper of which to get the wrapped
index 4c2f93bfacd47c30bed91026473e728da539590f..3a885dee8334b2d3536bfe8ae3bca7086bc05171 100644 (file)
@@ -31,7 +31,7 @@
 #include <dirent.h>
 #include <sys/types.h>
 #include <babeltrace/ctf-writer/trace.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 
 struct metadata_context {
        GString *string;
@@ -40,7 +40,7 @@ struct metadata_context {
 };
 
 struct bt_ctf_writer {
-       struct bt_object base;
+       struct bt_ctf_object base;
        int frozen; /* Protects attributes that can't be changed mid-trace */
        struct bt_ctf_trace *trace;
        GString *path;
index 8c82593b7f27be0261d0df5d47c84372ef5255a9..82719c66aebdf09f9e1cea56c224ec78a902837a 100644 (file)
@@ -187,14 +187,14 @@ extern int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer,
 static inline
 void bt_ctf_writer_get(struct bt_ctf_writer *writer)
 {
-       bt_object_get_ref(writer);
+       bt_ctf_object_get_ref(writer);
 }
 
 /* Pre-2.0 CTF writer compatibility */
 static inline
 void bt_ctf_writer_put(struct bt_ctf_writer *writer)
 {
-       bt_object_put_ref(writer);
+       bt_ctf_object_put_ref(writer);
 }
 
 #ifdef __cplusplus
index b387f2531eb19bf4ae095d648ecf8609af444fa4..4ed7b1f4701f471e7938cee2ad5949744d08b475 100644 (file)
@@ -11,6 +11,8 @@ libctf_writer_la_SOURCES = \
        field-types.c \
        field-wrapper.c \
        functor.c \
+       object.c \
+       object-pool.c \
        resolve.c \
        serialize.c \
        stream.c \
@@ -18,6 +20,7 @@ libctf_writer_la_SOURCES = \
        trace.c \
        utils.c \
        validation.c \
+       values.c \
        visitor.c \
        writer.c
 
index cbaf29fbf7cfe7ceaeb15fd59c45e065161c2f52..49b84993bff6e4ee30785a463e61379ec68836ec 100644 (file)
 #include <babeltrace/assert-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compat/string-internal.h>
-#include <babeltrace/object.h>
-#include <babeltrace/values-internal.h>
-#include <babeltrace/values.h>
-#include <babeltrace/private-values.h>
+#include <babeltrace/ctf-writer/object.h>
+#include <babeltrace/ctf-writer/values-internal.h>
+#include <babeltrace/ctf-writer/values-internal.h>
+#include <babeltrace/ctf-writer/values-internal.h>
 #include <inttypes.h>
 
 #define BT_CTF_ATTR_NAME_INDEX         0
 #define BT_CTF_ATTR_VALUE_INDEX                1
 
 BT_HIDDEN
-struct bt_private_value *bt_ctf_attributes_create(void)
+struct bt_ctf_private_value *bt_ctf_attributes_create(void)
 {
-       struct bt_private_value *attr_obj;
+       struct bt_ctf_private_value *attr_obj;
 
        /*
         * Attributes: array value object of array value objects, each one
@@ -60,7 +60,7 @@ struct bt_private_value *bt_ctf_attributes_create(void)
         *     ]
         */
        BT_LOGD_STR("Creating attributes object.");
-       attr_obj = bt_private_value_array_create();
+       attr_obj = bt_ctf_private_value_array_create();
        if (!attr_obj) {
                BT_LOGE_STR("Failed to create array value.");
        } else {
@@ -72,39 +72,39 @@ struct bt_private_value *bt_ctf_attributes_create(void)
 }
 
 BT_HIDDEN
-void bt_ctf_attributes_destroy(struct bt_private_value *attr_obj)
+void bt_ctf_attributes_destroy(struct bt_ctf_private_value *attr_obj)
 {
        BT_LOGD("Destroying attributes object: addr=%p", attr_obj);
-       bt_object_put_ref(attr_obj);
+       bt_ctf_object_put_ref(attr_obj);
 }
 
 BT_HIDDEN
-int64_t bt_ctf_attributes_get_count(struct bt_private_value *attr_obj)
+int64_t bt_ctf_attributes_get_count(struct bt_ctf_private_value *attr_obj)
 {
-       return bt_value_array_get_size(bt_private_value_as_value(attr_obj));
+       return bt_ctf_value_array_get_size(bt_ctf_private_value_as_value(attr_obj));
 }
 
 BT_HIDDEN
-const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj,
+const char *bt_ctf_attributes_get_field_name(struct bt_ctf_private_value *attr_obj,
                uint64_t index)
 {
        const char *ret = NULL;
-       struct bt_private_value *attr_field_obj = NULL;
-       struct bt_private_value *attr_field_name_obj = NULL;
+       struct bt_ctf_private_value *attr_field_obj = NULL;
+       struct bt_ctf_private_value *attr_field_name_obj = NULL;
 
        if (!attr_obj) {
                BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
                goto end;
        }
 
-       if (index >= bt_value_array_get_size(bt_private_value_as_value(attr_obj))) {
+       if (index >= bt_ctf_value_array_get_size(bt_ctf_private_value_as_value(attr_obj))) {
                BT_LOGW("Invalid parameter: index is out of bounds: "
                        "index=%" PRIu64 ", count=%" PRId64,
-                       index, bt_value_array_get_size(bt_private_value_as_value(attr_obj)));
+                       index, bt_ctf_value_array_get_size(bt_ctf_private_value_as_value(attr_obj)));
                goto end;
        }
 
-       attr_field_obj = bt_private_value_array_borrow_element_by_index(
+       attr_field_obj = bt_ctf_private_value_array_borrow_element_by_index(
                attr_obj, index);
        if (!attr_field_obj) {
                BT_LOGE("Cannot get attributes object's array value's element by index: "
@@ -113,7 +113,7 @@ const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj,
        }
 
        attr_field_name_obj =
-               bt_private_value_array_borrow_element_by_index(
+               bt_ctf_private_value_array_borrow_element_by_index(
                        attr_field_obj, BT_CTF_ATTR_NAME_INDEX);
        if (!attr_field_name_obj) {
                BT_LOGE("Cannot get attribute array value's element by index: "
@@ -122,33 +122,33 @@ const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj,
                goto end;
        }
 
-       ret = bt_value_string_get(
-               bt_private_value_as_value(attr_field_name_obj));
+       ret = bt_ctf_value_string_get(
+               bt_ctf_private_value_as_value(attr_field_name_obj));
 
 end:
        return ret;
 }
 
 BT_HIDDEN
-struct bt_private_value *bt_ctf_attributes_borrow_field_value(struct bt_private_value *attr_obj,
+struct bt_ctf_private_value *bt_ctf_attributes_borrow_field_value(struct bt_ctf_private_value *attr_obj,
                uint64_t index)
 {
-       struct bt_private_value *value_obj = NULL;
-       struct bt_private_value *attr_field_obj = NULL;
+       struct bt_ctf_private_value *value_obj = NULL;
+       struct bt_ctf_private_value *attr_field_obj = NULL;
 
        if (!attr_obj) {
                BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
                goto end;
        }
 
-       if (index >= bt_value_array_get_size(bt_private_value_as_value(attr_obj))) {
+       if (index >= bt_ctf_value_array_get_size(bt_ctf_private_value_as_value(attr_obj))) {
                BT_LOGW("Invalid parameter: index is out of bounds: "
                        "index=%" PRIu64 ", count=%" PRId64,
-                       index, bt_value_array_get_size(bt_private_value_as_value(attr_obj)));
+                       index, bt_ctf_value_array_get_size(bt_ctf_private_value_as_value(attr_obj)));
                goto end;
        }
 
-       attr_field_obj = bt_private_value_array_borrow_element_by_index(
+       attr_field_obj = bt_ctf_private_value_array_borrow_element_by_index(
                attr_obj, index);
        if (!attr_field_obj) {
                BT_LOGE("Cannot get attributes object's array value's element by index: "
@@ -156,7 +156,7 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_value(struct bt_private_
                goto end;
        }
 
-       value_obj = bt_private_value_array_borrow_element_by_index(attr_field_obj,
+       value_obj = bt_ctf_private_value_array_borrow_element_by_index(attr_field_obj,
                BT_CTF_ATTR_VALUE_INDEX);
        if (!value_obj) {
                BT_LOGE("Cannot get attribute array value's element by index: "
@@ -169,15 +169,15 @@ end:
 }
 
 static
-struct bt_private_value *bt_ctf_attributes_borrow_field_by_name(
-               struct bt_private_value *attr_obj, const char *name)
+struct bt_ctf_private_value *bt_ctf_attributes_borrow_field_by_name(
+               struct bt_ctf_private_value *attr_obj, const char *name)
 {
        uint64_t i;
        int64_t attr_size;
-       struct bt_private_value *value_obj = NULL;
-       struct bt_private_value *attr_field_name_obj = NULL;
+       struct bt_ctf_private_value *value_obj = NULL;
+       struct bt_ctf_private_value *attr_field_name_obj = NULL;
 
-       attr_size = bt_value_array_get_size(bt_private_value_as_value(attr_obj));
+       attr_size = bt_ctf_value_array_get_size(bt_ctf_private_value_as_value(attr_obj));
        if (attr_size < 0) {
                BT_LOGE("Cannot get array value's size: value-addr=%p",
                        attr_obj);
@@ -187,14 +187,14 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_by_name(
        for (i = 0; i < attr_size; ++i) {
                const char *field_name;
 
-               value_obj = bt_private_value_array_borrow_element_by_index(attr_obj, i);
+               value_obj = bt_ctf_private_value_array_borrow_element_by_index(attr_obj, i);
                if (!value_obj) {
                        BT_LOGE("Cannot get attributes object's array value's element by index: "
                                "value-addr=%p, index=%" PRIu64, attr_obj, i);
                        goto error;
                }
 
-               attr_field_name_obj = bt_private_value_array_borrow_element_by_index(value_obj,
+               attr_field_name_obj = bt_ctf_private_value_array_borrow_element_by_index(value_obj,
                        BT_CTF_ATTR_NAME_INDEX);
                if (!attr_field_name_obj) {
                        BT_LOGE("Cannot get attribute array value's element by index: "
@@ -203,8 +203,8 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_by_name(
                        goto error;
                }
 
-               field_name = bt_value_string_get(
-                       bt_private_value_as_value(attr_field_name_obj));
+               field_name = bt_ctf_value_string_get(
+                       bt_ctf_private_value_as_value(attr_field_name_obj));
 
                if (!strcmp(field_name, name)) {
                        break;
@@ -221,11 +221,11 @@ error:
 }
 
 BT_HIDDEN
-int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj,
-               const char *name, struct bt_private_value *value_obj)
+int bt_ctf_attributes_set_field_value(struct bt_ctf_private_value *attr_obj,
+               const char *name, struct bt_ctf_private_value *value_obj)
 {
        int ret = 0;
-       struct bt_private_value *attr_field_obj = NULL;
+       struct bt_ctf_private_value *attr_field_obj = NULL;
 
        if (!attr_obj || !name || !value_obj) {
                BT_LOGW("Invalid parameter: attributes object, name, or value object is NULL: "
@@ -237,31 +237,31 @@ int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj,
 
        attr_field_obj = bt_ctf_attributes_borrow_field_by_name(attr_obj, name);
        if (attr_field_obj) {
-               ret = bt_private_value_array_set_element_by_index(
+               ret = bt_ctf_private_value_array_set_element_by_index(
                        attr_field_obj, BT_CTF_ATTR_VALUE_INDEX,
-                       bt_private_value_as_value(value_obj));
+                       bt_ctf_private_value_as_value(value_obj));
                attr_field_obj = NULL;
                goto end;
        }
 
-       attr_field_obj = bt_private_value_array_create();
+       attr_field_obj = bt_ctf_private_value_array_create();
        if (!attr_field_obj) {
                BT_LOGE_STR("Failed to create empty array value.");
                ret = -1;
                goto end;
        }
 
-       ret = bt_private_value_array_append_string_element(attr_field_obj, name);
-       ret |= bt_private_value_array_append_element(attr_field_obj,
-               bt_private_value_as_value(value_obj));
+       ret = bt_ctf_private_value_array_append_string_element(attr_field_obj, name);
+       ret |= bt_ctf_private_value_array_append_element(attr_field_obj,
+               bt_ctf_private_value_as_value(value_obj));
        if (ret) {
                BT_LOGE("Cannot append elements to array value: addr=%p",
                        attr_field_obj);
                goto end;
        }
 
-       ret = bt_private_value_array_append_element(attr_obj,
-               bt_private_value_as_value(attr_field_obj));
+       ret = bt_ctf_private_value_array_append_element(attr_obj,
+               bt_ctf_private_value_as_value(attr_field_obj));
        if (ret) {
                BT_LOGE("Cannot append element to array value: "
                        "array-value-addr=%p, element-value-addr=%p",
@@ -269,16 +269,16 @@ int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj,
        }
 
 end:
-       bt_object_put_ref(attr_field_obj);
+       bt_ctf_object_put_ref(attr_field_obj);
        return ret;
 }
 
 BT_HIDDEN
-struct bt_private_value *bt_ctf_attributes_borrow_field_value_by_name(
-               struct bt_private_value *attr_obj, const char *name)
+struct bt_ctf_private_value *bt_ctf_attributes_borrow_field_value_by_name(
+               struct bt_ctf_private_value *attr_obj, const char *name)
 {
-       struct bt_private_value *value_obj = NULL;
-       struct bt_private_value *attr_field_obj = NULL;
+       struct bt_ctf_private_value *value_obj = NULL;
+       struct bt_ctf_private_value *attr_field_obj = NULL;
 
        if (!attr_obj || !name) {
                BT_LOGW("Invalid parameter: attributes object or name is NULL: "
@@ -293,7 +293,7 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_value_by_name(
                goto end;
        }
 
-       value_obj = bt_private_value_array_borrow_element_by_index(attr_field_obj,
+       value_obj = bt_ctf_private_value_array_borrow_element_by_index(attr_field_obj,
                BT_CTF_ATTR_VALUE_INDEX);
        if (!value_obj) {
                BT_LOGE("Cannot get attribute array value's element by index: "
@@ -306,7 +306,7 @@ end:
 }
 
 BT_HIDDEN
-int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj)
+int bt_ctf_attributes_freeze(struct bt_ctf_private_value *attr_obj)
 {
        uint64_t i;
        int64_t count;
@@ -319,7 +319,7 @@ int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj)
        }
 
        BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj);
-       count = bt_value_array_get_size(bt_private_value_as_value(attr_obj));
+       count = bt_ctf_value_array_get_size(bt_ctf_private_value_as_value(attr_obj));
        BT_ASSERT(count >= 0);
 
        /*
@@ -328,7 +328,7 @@ int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj)
         * attribute is frozen one by one.
         */
        for (i = 0; i < count; ++i) {
-               struct bt_private_value *obj = NULL;
+               struct bt_ctf_private_value *obj = NULL;
 
                obj = bt_ctf_attributes_borrow_field_value(attr_obj, i);
                if (!obj) {
@@ -339,7 +339,7 @@ int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj)
                        goto end;
                }
 
-               bt_value_freeze(bt_private_value_as_value(obj));
+               bt_ctf_value_freeze(bt_ctf_private_value_as_value(obj));
        }
 
 end:
index 02fe8b5b1e77aadf9daa76336d5e0feafb184b5f..bc8961c13ac8faaf27ca01ad0a0acbff578ed737 100644 (file)
 #include <babeltrace/compat/uuid-internal.h>
 #include <babeltrace/ctf-writer/clock-class-internal.h>
 #include <babeltrace/ctf-writer/utils.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/types.h>
 #include <babeltrace/compat/string-internal.h>
 #include <inttypes.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <babeltrace/assert-internal.h>
 
 static
-void bt_ctf_clock_class_destroy(struct bt_object *obj);
+void bt_ctf_clock_class_destroy(struct bt_ctf_object *obj);
 
 BT_HIDDEN
 bt_bool bt_ctf_clock_class_is_valid(struct bt_ctf_clock_class *clock_class)
@@ -136,7 +136,7 @@ struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name,
 
        clock_class->precision = 1;
        clock_class->frequency = freq;
-       bt_object_init_shared(&clock_class->base, bt_ctf_clock_class_destroy);
+       bt_ctf_object_init_shared(&clock_class->base, bt_ctf_clock_class_destroy);
 
        if (name) {
                ret = bt_ctf_clock_class_set_name(clock_class, name);
@@ -150,7 +150,7 @@ struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name,
                clock_class, name);
        return clock_class;
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(clock_class);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(clock_class);
        return clock_class;
 }
 
@@ -536,7 +536,7 @@ void bt_ctf_clock_class_freeze(struct bt_ctf_clock_class *clock_class)
 }
 
 static
-void bt_ctf_clock_class_destroy(struct bt_object *obj)
+void bt_ctf_clock_class_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_clock_class *clock_class;
 
index fdb8f498f7012c6e8260c7d032a314f6ffd1419b..acca0d89f6619b5c80fb91ddbb2e44c83e70483f 100644 (file)
 #include <babeltrace/ctf-writer/clock-internal.h>
 #include <babeltrace/ctf-writer/utils.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
-#include <babeltrace/object-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object-internal.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <inttypes.h>
 
 static
-void bt_ctf_clock_destroy(struct bt_object *obj);
+void bt_ctf_clock_destroy(struct bt_ctf_object *obj);
 
 struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
 {
@@ -56,7 +56,7 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
                goto error;
        }
 
-       bt_object_init_shared(&clock->base, bt_ctf_clock_destroy);
+       bt_ctf_object_init_shared(&clock->base, bt_ctf_clock_destroy);
        clock->value = 0;
 
        /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
@@ -76,7 +76,7 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
        return clock;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(clock);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(clock);
        return clock;
 }
 
@@ -212,12 +212,12 @@ int bt_ctf_clock_get_value(struct bt_ctf_clock *clock, uint64_t *value)
 }
 
 static
-void bt_ctf_clock_destroy(struct bt_object *obj)
+void bt_ctf_clock_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_clock *clock;
 
        clock = container_of(obj, struct bt_ctf_clock, base);
-       bt_object_put_ref(clock->clock_class);
+       bt_ctf_object_put_ref(clock->clock_class);
        g_free(clock);
 }
 
index 1c33dd9626d425a4f9e24a699686e30dde02ba1f..47bcd2aba8af08f91984ed5eb769981c44e742d8 100644 (file)
 #include <babeltrace/ctf-writer/validation-internal.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
 #include <babeltrace/endian-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <babeltrace/types.h>
-#include <babeltrace/values-internal.h>
+#include <babeltrace/ctf-writer/values-internal.h>
 #include <glib.h>
 #include <inttypes.h>
 #include <inttypes.h>
 #include <stdlib.h>
 
 BT_HIDDEN
-void bt_ctf_event_class_common_finalize(struct bt_object *obj)
+void bt_ctf_event_class_common_finalize(struct bt_ctf_object *obj)
 {
        struct bt_ctf_event_class_common *event_class;
 
@@ -69,21 +69,21 @@ void bt_ctf_event_class_common_finalize(struct bt_object *obj)
        }
 
        BT_LOGD_STR("Putting context field type.");
-       bt_object_put_ref(event_class->context_field_type);
+       bt_ctf_object_put_ref(event_class->context_field_type);
        BT_LOGD_STR("Putting payload field type.");
-       bt_object_put_ref(event_class->payload_field_type);
+       bt_ctf_object_put_ref(event_class->payload_field_type);
 }
 
 BT_HIDDEN
 int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common *event_class,
-               const char *name, bt_object_release_func release_func,
+               const char *name, bt_ctf_object_release_func release_func,
                bt_ctf_field_type_structure_create_func ft_struct_create_func)
 {
        int ret = 0;
 
        BT_LOGD("Initializing common event class object: name=\"%s\"",
                name);
-       bt_object_init_shared_with_parent(&event_class->base, release_func);
+       bt_ctf_object_init_shared_with_parent(&event_class->base, release_func);
        event_class->payload_field_type = ft_struct_create_func();
        if (!event_class->payload_field_type) {
                BT_LOGE_STR("Cannot create event class's initial payload field type object.");
@@ -182,7 +182,7 @@ end:
 }
 
 static
-void bt_ctf_event_class_destroy(struct bt_object *obj)
+void bt_ctf_event_class_destroy(struct bt_ctf_object *obj)
 {
        bt_ctf_event_class_common_finalize(obj);
        g_free(obj);
@@ -217,7 +217,7 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name)
        goto end;
 
 error:
-       bt_object_put_ref(ctf_event_class);
+       bt_ctf_object_put_ref(ctf_event_class);
 
 end:
        return ctf_event_class;
@@ -269,14 +269,14 @@ struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(
                struct bt_ctf_event_class *event_class)
 {
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
-       return bt_object_get_ref(bt_ctf_event_class_common_borrow_stream_class(
+       return bt_ctf_object_get_ref(bt_ctf_event_class_common_borrow_stream_class(
                BT_CTF_TO_COMMON(event_class)));
 }
 
 struct bt_ctf_field_type *bt_ctf_event_class_get_payload_field_type(
                struct bt_ctf_event_class *event_class)
 {
-       return bt_object_get_ref(bt_ctf_event_class_common_borrow_payload_field_type(
+       return bt_ctf_object_get_ref(bt_ctf_event_class_common_borrow_payload_field_type(
                BT_CTF_TO_COMMON(event_class)));
 }
 
@@ -291,7 +291,7 @@ int bt_ctf_event_class_set_payload_field_type(
 struct bt_ctf_field_type *bt_ctf_event_class_get_context_field_type(
                struct bt_ctf_event_class *event_class)
 {
-       return bt_object_get_ref(bt_ctf_event_class_common_borrow_context_field_type(
+       return bt_ctf_object_get_ref(bt_ctf_event_class_common_borrow_context_field_type(
                BT_CTF_TO_COMMON(event_class)));
 }
 
@@ -470,7 +470,7 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class,
                struct metadata_context *context)
 {
        int ret = 0;
-       struct bt_value *attr_value = NULL;
+       struct bt_ctf_value *attr_value = NULL;
 
        BT_ASSERT(event_class);
        BT_ASSERT(context);
@@ -539,7 +539,7 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class,
 
 end:
        context->current_indentation_level = 0;
-       BT_OBJECT_PUT_REF_AND_RESET(attr_value);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(attr_value);
        return ret;
 }
 
@@ -577,7 +577,7 @@ struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(
         * No need to increment field_type's reference count since getting it
         * from the structure already does.
         */
-       field_type = bt_object_get_ref(
+       field_type = bt_ctf_object_get_ref(
                bt_ctf_field_type_common_structure_borrow_field_type_by_name(
                        event_class->common.payload_field_type, name));
 
index 59ee3786c4bd75c8dd4c455ec94aa0814b0cedeb..e5ed458efc1e0b583d164ee6a96b4534d4df9d9c 100644 (file)
@@ -44,7 +44,7 @@
 #include <babeltrace/ctf-writer/trace.h>
 #include <babeltrace/ctf-writer/utils.h>
 #include <babeltrace/ctf-writer/validation-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <inttypes.h>
 
 static
@@ -66,7 +66,7 @@ int bt_ctf_event_common_validate_types_for_create(
        struct bt_ctf_field_type_common *event_context_type = NULL;
        struct bt_ctf_field_type_common *event_payload_type = NULL;
        int trace_valid = 0;
-       struct bt_private_value *environment = NULL;
+       struct bt_ctf_private_value *environment = NULL;
 
        stream_class = bt_ctf_event_class_common_borrow_stream_class(event_class);
        BT_ASSERT(stream_class);
@@ -310,7 +310,7 @@ BT_HIDDEN
 int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
                struct bt_ctf_event_class_common *event_class,
                struct bt_ctf_clock_class *init_expected_clock_class,
-               bool is_shared_with_parent, bt_object_release_func release_func,
+               bool is_shared_with_parent, bt_ctf_object_release_func release_func,
                bt_ctf_validation_flag_copy_field_type_func field_type_copy_func,
                bool must_be_in_trace,
                int (*map_clock_classes_func)(struct bt_ctf_stream_class_common *stream_class,
@@ -330,7 +330,7 @@ int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
        struct bt_ctf_field_common *event_payload = NULL;
        struct bt_ctf_validation_output validation_output = { 0 };
        struct bt_ctf_clock_class *expected_clock_class =
-               init_expected_clock_class ? bt_object_get_ref(init_expected_clock_class) :
+               init_expected_clock_class ? bt_ctf_object_get_ref(init_expected_clock_class) :
                NULL;
 
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
@@ -360,9 +360,9 @@ int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
         * destroy it.
         */
        if (is_shared_with_parent) {
-               bt_object_init_shared_with_parent(&event->base, release_func);
+               bt_ctf_object_init_shared_with_parent(&event->base, release_func);
        } else {
-               bt_object_init_unique(&event->base);
+               bt_ctf_object_init_unique(&event->base);
        }
 
        if (!stream_class->frozen) {
@@ -425,7 +425,7 @@ int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
         * from that point, the event and its class will share the same
         * lifetime.
         */
-       event->class = bt_object_get_ref(event_class);
+       event->class = bt_ctf_object_get_ref(event_class);
 
        ret = bt_ctf_event_common_create_fields(stream_class,
                &validation_output,
@@ -472,7 +472,7 @@ int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
         * now because the stream class is frozen.
         */
        if (expected_clock_class) {
-               BT_OBJECT_MOVE_REF(stream_class->clock_class, expected_clock_class);
+               BT_CTF_OBJECT_MOVE_REF(stream_class->clock_class, expected_clock_class);
        }
 
        /*
@@ -491,7 +491,7 @@ int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
 
 error:
        bt_ctf_validation_output_put_types(&validation_output);
-       bt_object_put_ref(expected_clock_class);
+       bt_ctf_object_put_ref(expected_clock_class);
 
        if (event_header) {
                release_header_field_func(event_header, stream_class);
@@ -535,7 +535,7 @@ static
 void destroy_event_header_field(struct bt_ctf_field_wrapper *field_wrapper)
 {
        BT_ASSERT(field_wrapper);
-       bt_object_put_ref(field_wrapper->field);
+       bt_ctf_object_put_ref(field_wrapper->field);
        bt_ctf_field_wrapper_destroy(field_wrapper);
 }
 
@@ -561,7 +561,7 @@ struct bt_ctf_field_wrapper *create_event_header_field(
        goto end;
 
 error:
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
 
        if (field_wrapper) {
                destroy_event_header_field(field_wrapper);
@@ -577,14 +577,14 @@ void release_event_header_field(struct bt_ctf_field_wrapper *field_wrapper,
                struct bt_ctf_event_common *event_common)
 {
        BT_ASSERT(field_wrapper);
-       BT_OBJECT_PUT_REF_AND_RESET(field_wrapper->field);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(field_wrapper->field);
        bt_ctf_field_wrapper_destroy(field_wrapper);
 }
 
 static
-void bt_ctf_event_destroy(struct bt_object *obj)
+void bt_ctf_event_destroy(struct bt_ctf_object *obj)
 {
-       bt_ctf_event_common_finalize(obj, (void *) bt_object_put_ref,
+       bt_ctf_event_common_finalize(obj, (void *) bt_ctf_object_put_ref,
                (void *) release_event_header_field);
        g_free(obj);
 }
@@ -618,7 +618,7 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
                        bt_ctf_field_type_copy,
                false, map_clock_classes_func,
                (create_field_func) bt_ctf_field_create,
-               (release_field_func) bt_object_put_ref,
+               (release_field_func) bt_ctf_object_put_ref,
                (create_header_field_func) create_event_header_field,
                (release_header_field_func) destroy_event_header_field);
        if (ret) {
@@ -629,7 +629,7 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(event);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(event);
 
 end:
        return event;
@@ -638,7 +638,7 @@ end:
 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event)
 {
        BT_ASSERT_PRE_NON_NULL(event, "Event");
-       return bt_object_get_ref(bt_ctf_event_common_borrow_class(BT_CTF_TO_COMMON(event)));
+       return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_class(BT_CTF_TO_COMMON(event)));
 }
 
 BT_HIDDEN
@@ -646,13 +646,13 @@ struct bt_ctf_stream *bt_ctf_event_borrow_stream(struct bt_ctf_event *event)
 {
        BT_ASSERT(event);
        return (struct bt_ctf_stream *)
-               bt_object_borrow_parent(&BT_CTF_TO_COMMON(event)->base);
+               bt_ctf_object_borrow_parent(&BT_CTF_TO_COMMON(event)->base);
 }
 
 struct bt_ctf_stream *bt_ctf_event_get_stream(struct bt_ctf_event *event)
 {
        BT_ASSERT_PRE_NON_NULL(event, "Event");
-       return bt_object_get_ref(bt_ctf_event_borrow_stream(event));
+       return bt_ctf_object_get_ref(bt_ctf_event_borrow_stream(event));
 }
 
 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name,
@@ -677,7 +677,7 @@ struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event,
                        BT_CTF_FROM_COMMON(event->common.payload_field), name);
        } else {
                field = BT_CTF_FROM_COMMON(event->common.payload_field);
-               bt_object_get_ref(field);
+               bt_ctf_object_get_ref(field);
        }
 
        return field;
@@ -686,23 +686,23 @@ struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event,
 struct bt_ctf_field *bt_ctf_event_get_payload_field(
                struct bt_ctf_event *event)
 {
-       return bt_object_get_ref(bt_ctf_event_common_borrow_payload(BT_CTF_TO_COMMON(event)));
+       return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_payload(BT_CTF_TO_COMMON(event)));
 }
 
 struct bt_ctf_field *bt_ctf_event_get_header(struct bt_ctf_event *event)
 {
-       return bt_object_get_ref(bt_ctf_event_common_borrow_header(BT_CTF_TO_COMMON(event)));
+       return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_header(BT_CTF_TO_COMMON(event)));
 }
 
 struct bt_ctf_field *bt_ctf_event_get_context(struct bt_ctf_event *event)
 {
-       return bt_object_get_ref(bt_ctf_event_common_borrow_context(BT_CTF_TO_COMMON(event)));
+       return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_context(BT_CTF_TO_COMMON(event)));
 }
 
 struct bt_ctf_field *bt_ctf_event_get_stream_event_context(
                struct bt_ctf_event *event)
 {
-       return bt_object_get_ref(bt_ctf_event_common_borrow_stream_event_context(
+       return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_stream_event_context(
                BT_CTF_TO_COMMON(event)));
 }
 
@@ -786,8 +786,8 @@ int bt_ctf_event_set_header(struct bt_ctf_event *event,
                        bt_ctf_event_class_common_borrow_stream_class(event->common.class)->event_header_field_type);
        }
 
-       bt_object_put_ref(event->common.header_field->field);
-       event->common.header_field->field = bt_object_get_ref(header);
+       bt_ctf_object_put_ref(event->common.header_field->field);
+       event->common.header_field->field = bt_ctf_object_get_ref(header);
        BT_LOGV("Set event's header field: event-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
                "header-field-addr=%p",
@@ -820,8 +820,8 @@ int bt_ctf_event_common_set_payload(struct bt_ctf_event *event,
                        event, event->common.class->payload_field_type);
        }
 
-       bt_object_put_ref(event->common.payload_field);
-       event->common.payload_field = bt_object_get_ref(payload);
+       bt_ctf_object_put_ref(event->common.payload_field);
+       event->common.payload_field = bt_ctf_object_get_ref(payload);
        BT_LOGV("Set event's payload field: event-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
                "payload-field-addr=%p",
@@ -853,8 +853,8 @@ int bt_ctf_event_set_context(struct bt_ctf_event *event,
                        event, event->common.class->context_field_type);
        }
 
-       bt_object_put_ref(event->common.context_field);
-       event->common.context_field = bt_object_get_ref(context);
+       bt_ctf_object_put_ref(event->common.context_field);
+       event->common.context_field = bt_ctf_object_get_ref(context);
        BT_LOGV("Set event's context field: event-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
                "context-field-addr=%p",
@@ -888,8 +888,8 @@ int bt_ctf_event_set_stream_event_context(struct bt_ctf_event *event,
                        bt_ctf_event_class_common_borrow_stream_class(event->common.class)->event_context_field_type);
        }
 
-       bt_object_put_ref(event->common.stream_event_context_field);
-       event->common.stream_event_context_field = bt_object_get_ref(stream_event_context);
+       bt_ctf_object_put_ref(event->common.stream_event_context_field);
+       event->common.stream_event_context_field = bt_ctf_object_get_ref(stream_event_context);
        BT_LOGV("Set event's stream event context field: event-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
                "stream-event-context-field-addr=%p",
index 21d4b6925bbfe6f4a36a96e9b83f04be66cd256b..ce3f2bee42b5e11f4031c1591ec1c3fd4843b137 100644 (file)
@@ -38,7 +38,7 @@
 #include <stdint.h>
 
 static
-void field_path_destroy(struct bt_object *obj)
+void field_path_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_path *field_path = (struct bt_ctf_field_path *) obj;
 
@@ -67,7 +67,7 @@ struct bt_ctf_field_path *bt_ctf_field_path_create(void)
                goto error;
        }
 
-       bt_object_init_shared(&field_path->base, field_path_destroy);
+       bt_ctf_object_init_shared(&field_path->base, field_path_destroy);
        field_path->root = BT_CTF_SCOPE_UNKNOWN;
        field_path->indexes = g_array_new(TRUE, FALSE, sizeof(int));
        if (!field_path->indexes) {
@@ -79,7 +79,7 @@ struct bt_ctf_field_path *bt_ctf_field_path_create(void)
        return field_path;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(field_path);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(field_path);
        return NULL;
 }
 
index ba7c7ecdb7733ba5228908c6bb0f7d54ce20e19f..f337d248c43604e3d9ad2d1349fdc4b9371c6b23 100644 (file)
@@ -38,8 +38,8 @@
 #include <babeltrace/ctf-writer/utils-internal.h>
 #include <babeltrace/ctf-writer/utils.h>
 #include <babeltrace/endian-internal.h>
-#include <babeltrace/object-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object-internal.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <float.h>
 #include <inttypes.h>
 #include <stdlib.h>
@@ -52,13 +52,13 @@ void destroy_enumeration_mapping(struct bt_ctf_enumeration_mapping *mapping)
 
 BT_HIDDEN
 void bt_ctf_field_type_common_initialize(struct bt_ctf_field_type_common *ft,
-               bool init_bo, bt_object_release_func release_func,
+               bool init_bo, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        BT_ASSERT(ft && (ft->id > BT_CTF_FIELD_TYPE_ID_UNKNOWN) &&
                (ft->id < BT_CTF_FIELD_TYPE_ID_NR));
 
-       bt_object_init_shared(&ft->base, release_func);
+       bt_ctf_object_init_shared(&ft->base, release_func);
        ft->methods = methods;
 
        if (init_bo) {
@@ -77,7 +77,7 @@ void bt_ctf_field_type_common_initialize(struct bt_ctf_field_type_common *ft,
 BT_HIDDEN
 void bt_ctf_field_type_common_integer_initialize(
                struct bt_ctf_field_type_common *ft,
-               unsigned int size, bt_object_release_func release_func,
+               unsigned int size, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_integer *int_ft = BT_CTF_FROM_COMMON(ft);
@@ -97,7 +97,7 @@ void bt_ctf_field_type_common_integer_initialize(
 BT_HIDDEN
 void bt_ctf_field_type_common_floating_point_initialize(
                struct bt_ctf_field_type_common *ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_floating_point *flt_ft = BT_CTF_FROM_COMMON(ft);
@@ -116,7 +116,7 @@ BT_HIDDEN
 void bt_ctf_field_type_common_enumeration_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *container_ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_enumeration *enum_ft = BT_CTF_FROM_COMMON(ft);
@@ -125,7 +125,7 @@ void bt_ctf_field_type_common_enumeration_initialize(
        BT_LOGD("Initializing common enumeration field type object: int-ft-addr=%p",
                container_ft);
        ft->id = BT_CTF_FIELD_TYPE_ID_ENUM;
-       enum_ft->container_ft = bt_object_get_ref(container_ft);
+       enum_ft->container_ft = bt_ctf_object_get_ref(container_ft);
        enum_ft->entries = g_ptr_array_new_with_free_func(
                (GDestroyNotify) destroy_enumeration_mapping);
        bt_ctf_field_type_common_initialize(ft, false, release_func, methods);
@@ -137,7 +137,7 @@ void bt_ctf_field_type_common_enumeration_initialize(
 BT_HIDDEN
 void bt_ctf_field_type_common_string_initialize(
                struct bt_ctf_field_type_common *ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_string *string_ft = BT_CTF_FROM_COMMON(ft);
@@ -153,7 +153,7 @@ void bt_ctf_field_type_common_string_initialize(
 BT_HIDDEN
 void bt_ctf_field_type_common_structure_initialize(
                struct bt_ctf_field_type_common *ft,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_structure *struct_ft = BT_CTF_FROM_COMMON(ft);
@@ -171,7 +171,7 @@ BT_HIDDEN
 void bt_ctf_field_type_common_array_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *element_ft,
-               unsigned int length, bt_object_release_func release_func,
+               unsigned int length, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_array *array_ft = BT_CTF_FROM_COMMON(ft);
@@ -180,7 +180,7 @@ void bt_ctf_field_type_common_array_initialize(
        BT_LOGD("Initializing common array field type object: element-ft-addr=%p, "
                "length=%u", element_ft, length);
        ft->id = BT_CTF_FIELD_TYPE_ID_ARRAY;
-       array_ft->element_ft = bt_object_get_ref(element_ft);
+       array_ft->element_ft = bt_ctf_object_get_ref(element_ft);
        array_ft->length = length;
        bt_ctf_field_type_common_initialize(ft, false, release_func, methods);
        BT_LOGD("Initialized common array field type object: addr=%p, "
@@ -192,7 +192,7 @@ void bt_ctf_field_type_common_sequence_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *element_ft,
                const char *length_field_name,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_sequence *seq_ft = BT_CTF_FROM_COMMON(ft);
@@ -203,7 +203,7 @@ void bt_ctf_field_type_common_sequence_initialize(
        BT_LOGD("Initializing common sequence field type object: element-ft-addr=%p, "
                "length-field-name=\"%s\"", element_ft, length_field_name);
        ft->id = BT_CTF_FIELD_TYPE_ID_SEQUENCE;
-       seq_ft->element_ft = bt_object_get_ref(element_ft);
+       seq_ft->element_ft = bt_ctf_object_get_ref(element_ft);
        seq_ft->length_field_name = g_string_new(length_field_name);
        bt_ctf_field_type_common_initialize(ft, false, release_func, methods);
        BT_LOGD("Initialized common sequence field type object: addr=%p, "
@@ -216,7 +216,7 @@ void bt_ctf_field_type_common_variant_initialize(
                struct bt_ctf_field_type_common *ft,
                struct bt_ctf_field_type_common *tag_ft,
                const char *tag_name,
-               bt_object_release_func release_func,
+               bt_ctf_object_release_func release_func,
                struct bt_ctf_field_type_common_methods *methods)
 {
        struct bt_ctf_field_type_common_variant *var_ft = BT_CTF_FROM_COMMON(ft);
@@ -232,7 +232,7 @@ void bt_ctf_field_type_common_variant_initialize(
                sizeof(struct bt_ctf_field_type_common_variant_choice));
 
        if (tag_ft) {
-               var_ft->tag_ft = bt_object_get_ref(tag_ft);
+               var_ft->tag_ft = bt_ctf_object_get_ref(tag_ft);
        }
 
        bt_ctf_field_type_common_initialize(ft, true, release_func, methods);
@@ -244,7 +244,7 @@ void bt_ctf_field_type_common_variant_initialize(
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_integer_destroy(struct bt_object *obj)
+void bt_ctf_field_type_common_integer_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_integer *ft = (void *) obj;
 
@@ -254,12 +254,12 @@ void bt_ctf_field_type_common_integer_destroy(struct bt_object *obj)
 
        BT_LOGD("Destroying integer field type object: addr=%p", ft);
        BT_LOGD_STR("Putting mapped clock class.");
-       bt_object_put_ref(ft->mapped_clock_class);
+       bt_ctf_object_put_ref(ft->mapped_clock_class);
        g_free(ft);
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_floating_point_destroy(struct bt_object *obj)
+void bt_ctf_field_type_common_floating_point_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_floating_point *ft = (void *) obj;
 
@@ -272,7 +272,7 @@ void bt_ctf_field_type_common_floating_point_destroy(struct bt_object *obj)
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_object *obj)
+void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_enumeration *ft = (void *) obj;
 
@@ -283,12 +283,12 @@ void bt_ctf_field_type_common_enumeration_destroy_recursive(struct bt_object *ob
        BT_LOGD("Destroying enumeration field type object: addr=%p", ft);
        g_ptr_array_free(ft->entries, TRUE);
        BT_LOGD_STR("Putting container field type.");
-       bt_object_put_ref(ft->container_ft);
+       bt_ctf_object_put_ref(ft->container_ft);
        g_free(ft);
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_string_destroy(struct bt_object *obj)
+void bt_ctf_field_type_common_string_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_string *ft = (void *) obj;
 
@@ -312,11 +312,11 @@ void bt_ctf_field_type_common_structure_field_finalize(
                "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
                field, field->type, g_quark_to_string(field->name));
        BT_LOGD_STR("Putting field type.");
-       bt_object_put_ref(field->type);
+       bt_ctf_object_put_ref(field->type);
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_object *obj)
+void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_structure *ft = (void *) obj;
        uint64_t i;
@@ -345,7 +345,7 @@ void bt_ctf_field_type_common_structure_destroy_recursive(struct bt_object *obj)
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_array_destroy_recursive(struct bt_object *obj)
+void bt_ctf_field_type_common_array_destroy_recursive(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_array *ft = (void *) obj;
 
@@ -355,12 +355,12 @@ void bt_ctf_field_type_common_array_destroy_recursive(struct bt_object *obj)
 
        BT_LOGD("Destroying array field type object: addr=%p", ft);
        BT_LOGD_STR("Putting element field type.");
-       bt_object_put_ref(ft->element_ft);
+       bt_ctf_object_put_ref(ft->element_ft);
        g_free(ft);
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_object *obj)
+void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_sequence *ft = (void *) obj;
 
@@ -370,10 +370,10 @@ void bt_ctf_field_type_common_sequence_destroy_recursive(struct bt_object *obj)
 
        BT_LOGD("Destroying sequence field type object: addr=%p", ft);
        BT_LOGD_STR("Putting element field type.");
-       bt_object_put_ref(ft->element_ft);
+       bt_ctf_object_put_ref(ft->element_ft);
        g_string_free(ft->length_field_name, TRUE);
        BT_LOGD_STR("Putting length field path.");
-       bt_object_put_ref(ft->length_field_path);
+       bt_ctf_object_put_ref(ft->length_field_path);
        g_free(ft);
 }
 
@@ -389,7 +389,7 @@ void bt_ctf_field_type_common_variant_choice_finalize(
                "addr=%p, field-ft-addr=%p, field-name=\"%s\"",
                choice, choice->type, g_quark_to_string(choice->name));
        BT_LOGD_STR("Putting field type.");
-       bt_object_put_ref(choice->type);
+       bt_ctf_object_put_ref(choice->type);
 
        if (choice->ranges) {
                g_array_free(choice->ranges, TRUE);
@@ -397,7 +397,7 @@ void bt_ctf_field_type_common_variant_choice_finalize(
 }
 
 BT_HIDDEN
-void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_object *obj)
+void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_common_variant *ft = (void *) obj;
        uint64_t i;
@@ -427,9 +427,9 @@ void bt_ctf_field_type_common_variant_destroy_recursive(struct bt_object *obj)
        }
 
        BT_LOGD_STR("Putting tag field type.");
-       bt_object_put_ref(ft->tag_ft);
+       bt_ctf_object_put_ref(ft->tag_ft);
        BT_LOGD_STR("Putting tag field path.");
-       bt_object_put_ref(ft->tag_field_path);
+       bt_ctf_object_put_ref(ft->tag_field_path);
        g_free(ft);
 }
 
@@ -568,7 +568,7 @@ int add_structure_variant_member(GArray *members,
        }
 
        *member_name = name_quark;
-       *member_ft = bt_object_get_ref(field_type);
+       *member_ft = bt_ctf_object_get_ref(field_type);
        g_hash_table_insert(field_name_to_index,
                GUINT_TO_POINTER(name_quark),
                GUINT_TO_POINTER(members->len - 1));
@@ -599,7 +599,7 @@ end:
 }
 
 static
-void bt_ctf_field_type_enum_iter_destroy(struct bt_object *obj)
+void bt_ctf_field_type_enum_iter_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_field_type_enumeration_mapping_iterator *iter =
                container_of(obj,
@@ -609,7 +609,7 @@ void bt_ctf_field_type_enum_iter_destroy(struct bt_object *obj)
        BT_LOGD("Destroying enumeration field type mapping iterator: addr=%p",
                obj);
        BT_LOGD_STR("Putting parent enumeration field type.");
-       bt_object_put_ref(iter->enumeration_ft);
+       bt_ctf_object_put_ref(iter->enumeration_ft);
        g_free(iter);
 }
 
@@ -630,8 +630,8 @@ bt_ctf_field_type_common_enumeration_find_mappings_type(
                goto end;
        }
 
-       bt_object_init_shared(&iter->base, bt_ctf_field_type_enum_iter_destroy);
-       iter->enumeration_ft = bt_object_get_ref(ft);
+       bt_ctf_object_init_shared(&iter->base, bt_ctf_field_type_enum_iter_destroy);
+       iter->enumeration_ft = bt_ctf_object_get_ref(ft);
        iter->index = -1;
        iter->type = iterator_type;
 
@@ -666,7 +666,7 @@ bt_ctf_field_type_common_enumeration_find_mappings_by_name(
        return iter;
 
 error:
-       bt_object_put_ref(iter);
+       bt_ctf_object_put_ref(iter);
        return NULL;
 }
 
@@ -773,7 +773,7 @@ bt_ctf_field_type_common_enumeration_signed_find_mappings_by_value(
        return iter;
 
 error:
-       bt_object_put_ref(iter);
+       bt_ctf_object_put_ref(iter);
        return NULL;
 }
 
@@ -804,7 +804,7 @@ bt_ctf_field_type_common_enumeration_unsigned_find_mappings_by_value(
        return iter;
 
 error:
-       bt_object_put_ref(iter);
+       bt_ctf_object_put_ref(iter);
        return NULL;
 }
 
@@ -1381,8 +1381,8 @@ int bt_ctf_field_type_common_integer_set_mapped_clock_class_no_check_frozen(
                goto end;
        }
 
-       bt_object_put_ref(int_ft->mapped_clock_class);
-       int_ft->mapped_clock_class = bt_object_get_ref(clock_class);
+       bt_ctf_object_put_ref(int_ft->mapped_clock_class);
+       int_ft->mapped_clock_class = bt_ctf_object_get_ref(clock_class);
        BT_LOGV("Set integer field type's mapped clock class: ft-addr=%p, "
                "clock-class-addr=%p, clock-class-name=\"%s\"",
                ft, clock_class, bt_ctf_clock_class_get_name(clock_class));
@@ -1832,8 +1832,8 @@ int bt_ctf_field_type_common_structure_replace_field(
                        BT_CTF_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(ft, i);
 
                if (field->name == name_quark) {
-                       bt_object_put_ref(field->type);
-                       field->type = bt_object_get_ref(field_type);
+                       bt_ctf_object_put_ref(field->type);
+                       field->type = bt_ctf_object_get_ref(field_type);
                }
        }
 
@@ -2343,10 +2343,10 @@ int bt_ctf_field_type_common_array_set_element_field_type(
        }
 
        if (array_ft->element_ft) {
-               BT_OBJECT_PUT_REF_AND_RESET(array_ft->element_ft);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(array_ft->element_ft);
        }
 
-       array_ft->element_ft = bt_object_get_ref(element_ft);
+       array_ft->element_ft = bt_ctf_object_get_ref(element_ft);
        BT_LOGV("Set array field type's element field type: array-ft-addr=%p, "
                "element-ft-addr=%p", ft, element_ft);
 
@@ -2406,11 +2406,11 @@ int bt_ctf_field_type_common_sequence_set_element_field_type(
        }
 
        if (seq_ft->element_ft) {
-               BT_OBJECT_PUT_REF_AND_RESET(seq_ft->element_ft);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(seq_ft->element_ft);
        }
 
        seq_ft->element_ft = element_ft;
-       bt_object_get_ref(seq_ft->element_ft);
+       bt_ctf_object_get_ref(seq_ft->element_ft);
        BT_LOGV("Set sequence field type's element field type: sequence-ft-addr=%p, "
                "element-ft-addr=%p", ft, element_ft);
 
@@ -2925,8 +2925,8 @@ int bt_ctf_field_type_common_sequence_set_length_field_path(
                goto end;
        }
 
-       bt_object_get_ref(path);
-       BT_OBJECT_MOVE_REF(seq_ft->length_field_path, path);
+       bt_ctf_object_get_ref(path);
+       BT_CTF_OBJECT_MOVE_REF(seq_ft->length_field_path, path);
        BT_LOGV("Set sequence field type's length field path: ft-addr=%p, "
                "field-path-addr=%p", ft, path);
 
@@ -2956,8 +2956,8 @@ int bt_ctf_field_type_common_variant_set_tag_field_path(
                goto end;
        }
 
-       bt_object_get_ref(path);
-       BT_OBJECT_MOVE_REF(var_ft->tag_field_path, path);
+       bt_ctf_object_get_ref(path);
+       BT_CTF_OBJECT_MOVE_REF(var_ft->tag_field_path, path);
        BT_LOGV("Set variant field type's tag field path: ft-addr=%p, "
                "field-path-addr=%p", ft, path);
 
@@ -2993,8 +2993,8 @@ int bt_ctf_field_type_common_variant_set_tag_field_type(
                goto end;
        }
 
-       bt_object_put_ref(var_ft->tag_ft);
-       var_ft->tag_ft = bt_object_get_ref(tag_ft);
+       bt_ctf_object_put_ref(var_ft->tag_ft);
+       var_ft->tag_ft = bt_ctf_object_get_ref(tag_ft);
        BT_LOGV("Set variant field type's tag field type: variant-ft-addr=%p, "
                "tag-ft-addr=%p", ft, tag_ft);
 
@@ -3093,7 +3093,7 @@ int bt_ctf_field_type_common_variant_update_choices(struct bt_ctf_field_type_com
                        g_array_append_val(choice->ranges, range);
                }
 
-               bt_object_put_ref(iter);
+               bt_ctf_object_put_ref(iter);
        }
 
        var_ft->choices_up_to_date = true;
@@ -3891,7 +3891,7 @@ int bt_ctf_field_type_common_validate_single_clock_class(
 
                if (!*expected_clock_class) {
                        /* Move reference to output parameter */
-                       *expected_clock_class = bt_object_get_ref(mapped_clock_class);
+                       *expected_clock_class = bt_ctf_object_get_ref(mapped_clock_class);
                        mapped_clock_class = NULL;
                        BT_LOGV("Setting expected clock class: "
                                "expected-clock-class-addr=%p",
@@ -3908,7 +3908,7 @@ int bt_ctf_field_type_common_validate_single_clock_class(
                                        bt_ctf_clock_class_get_name(mapped_clock_class),
                                        *expected_clock_class,
                                        bt_ctf_clock_class_get_name(*expected_clock_class));
-                               bt_object_put_ref(mapped_clock_class);
+                               bt_ctf_object_put_ref(mapped_clock_class);
                                ret = -1;
                                goto end;
                        }
@@ -4583,7 +4583,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size)
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(integer);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(integer);
 
 end:
        return (void *) integer;
@@ -4641,7 +4641,7 @@ int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *ft,
 struct bt_ctf_clock_class *bt_ctf_field_type_integer_get_mapped_clock_class(
                struct bt_ctf_field_type *ft)
 {
-       return bt_object_get_ref(bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
+       return bt_ctf_object_get_ref(bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
                (void *) ft));
 }
 
@@ -4710,7 +4710,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(enumeration);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(enumeration);
 
 end:
        return (void *) enumeration;
@@ -4719,7 +4719,7 @@ end:
 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_field_type(
                struct bt_ctf_field_type *ft)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_field_type_common_enumeration_borrow_container_field_type(
                        (void *) ft));
 }
@@ -4822,7 +4822,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void)
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(structure);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(structure);
 
 end:
        return (void *) structure;
@@ -4850,7 +4850,7 @@ int bt_ctf_field_type_structure_get_field_by_index(
                (void *) ft, field_name, (void *) field_type, index);
 
        if (ret == 0 && field_type) {
-               bt_object_get_ref(*field_type);
+               bt_ctf_object_get_ref(*field_type);
        }
 
        return ret;
@@ -4859,7 +4859,7 @@ int bt_ctf_field_type_structure_get_field_by_index(
 struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(
                struct bt_ctf_field_type *ft, const char *name)
 {
-       return bt_object_get_ref(bt_ctf_field_type_common_structure_borrow_field_type_by_name(
+       return bt_ctf_object_get_ref(bt_ctf_field_type_common_structure_borrow_field_type_by_name(
                (void *) ft, name));
 }
 
@@ -4897,7 +4897,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_create(
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(var_ft);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(var_ft);
 
 end:
        return (void *) var_ft;
@@ -4906,7 +4906,7 @@ end:
 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_field_type(
                struct bt_ctf_field_type *ft)
 {
-       return bt_object_get_ref(bt_ctf_field_type_common_variant_borrow_tag_field_type(
+       return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_tag_field_type(
                (void *) ft));
 }
 
@@ -4933,7 +4933,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(
                struct bt_ctf_field_type *ft,
                const char *field_name)
 {
-       return bt_object_get_ref(bt_ctf_field_type_common_variant_borrow_field_type_by_name(
+       return bt_ctf_object_get_ref(bt_ctf_field_type_common_variant_borrow_field_type_by_name(
                (void *) ft, field_name));
 }
 
@@ -5005,7 +5005,7 @@ int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type *ft,
                (void *) ft, field_name, (void *) field_type, index);
 
        if (ret == 0 && field_type) {
-               bt_object_get_ref(*field_type);
+               bt_ctf_object_get_ref(*field_type);
        }
 
        return ret;
@@ -5047,7 +5047,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_create(
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(array);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(array);
 
 end:
        return (void *) array;
@@ -5056,7 +5056,7 @@ end:
 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_field_type(
                struct bt_ctf_field_type *ft)
 {
-       return bt_object_get_ref(bt_ctf_field_type_common_array_borrow_element_field_type(
+       return bt_ctf_object_get_ref(bt_ctf_field_type_common_array_borrow_element_field_type(
                (void *) ft));
 }
 
@@ -5103,7 +5103,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(sequence);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(sequence);
 
 end:
        return (void *) sequence;
@@ -5112,7 +5112,7 @@ end:
 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_field_type(
                struct bt_ctf_field_type *ft)
 {
-       return bt_object_get_ref(bt_ctf_field_type_common_sequence_borrow_element_field_type(
+       return bt_ctf_object_get_ref(bt_ctf_field_type_common_sequence_borrow_element_field_type(
                (void *) ft));
 }
 
@@ -5206,7 +5206,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_integer_copy(
                goto end;
        }
 
-       copy_ft->mapped_clock_class = bt_object_get_ref(int_ft->mapped_clock_class);
+       copy_ft->mapped_clock_class = bt_ctf_object_get_ref(int_ft->mapped_clock_class);
        copy_ft->user_byte_order = int_ft->user_byte_order;
        copy_ft->is_signed = int_ft->is_signed;
        copy_ft->size = int_ft->size;
@@ -5266,12 +5266,12 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_copy_recursive(
                ft, copy_ft);
 
 end:
-       bt_object_put_ref(container_copy_ft);
+       bt_ctf_object_put_ref(container_copy_ft);
        return (void *) copy_ft;
 
 error:
-       bt_object_put_ref(container_copy_ft);
-        BT_OBJECT_PUT_REF_AND_RESET(copy_ft);
+       bt_ctf_object_put_ref(container_copy_ft);
+        BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft);
        return (void *) copy_ft;
 }
 
@@ -5359,7 +5359,7 @@ end:
        return (void *) copy_ft;
 
 error:
-        BT_OBJECT_PUT_REF_AND_RESET(copy_ft);
+        BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft);
        return NULL;
 }
 
@@ -5455,12 +5455,12 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_copy_recursive(
                ft, copy_ft);
 
 end:
-       bt_object_put_ref(tag_ft_copy);
+       bt_ctf_object_put_ref(tag_ft_copy);
        return (void *) copy_ft;
 
 error:
-       bt_object_put_ref(tag_ft_copy);
-        BT_OBJECT_PUT_REF_AND_RESET(copy_ft);
+       bt_ctf_object_put_ref(tag_ft_copy);
+        BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft);
        return NULL;
 }
 
@@ -5491,7 +5491,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_copy_recursive(
                ft, copy_ft);
 
 end:
-       bt_object_put_ref(container_ft_copy);
+       bt_ctf_object_put_ref(container_ft_copy);
        return (void *) copy_ft;
 }
 
@@ -5534,11 +5534,11 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_copy_recursive(
                ft, copy_ft);
 
 end:
-       bt_object_put_ref(container_ft_copy);
+       bt_ctf_object_put_ref(container_ft_copy);
        return (void *) copy_ft;
 error:
-       bt_object_put_ref(container_ft_copy);
-       BT_OBJECT_PUT_REF_AND_RESET(copy_ft);
+       bt_ctf_object_put_ref(container_ft_copy);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_ft);
        return NULL;
 }
 
index 254f744476df162baafa9f651b058413806e6ea1..70ada9012bbfde12a8fb9fbdfb6b92e1489e2ad9 100644 (file)
@@ -26,7 +26,7 @@
 #include <babeltrace/ctf-writer/field-wrapper-internal.h>
 #include <babeltrace/ctf-writer/fields-internal.h>
 #include <babeltrace/object-pool-internal.h>
-#include <babeltrace/object-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
 #include <glib.h>
 
 BT_HIDDEN
@@ -42,7 +42,7 @@ struct bt_ctf_field_wrapper *bt_ctf_field_wrapper_new(void *data)
                goto end;
        }
 
-       bt_object_init_unique(&field_wrapper->base);
+       bt_ctf_object_init_unique(&field_wrapper->base);
        BT_LOGD("Created empty field wrapper object: addr=%p",
                field_wrapper);
 
@@ -61,13 +61,13 @@ void bt_ctf_field_wrapper_destroy(struct bt_ctf_field_wrapper *field_wrapper)
 
 BT_HIDDEN
 struct bt_ctf_field_wrapper *bt_ctf_field_wrapper_create(
-               struct bt_object_pool *pool, struct bt_ctf_field_type *ft)
+               struct bt_ctf_object_pool *pool, struct bt_ctf_field_type *ft)
 {
        struct bt_ctf_field_wrapper *field_wrapper = NULL;
 
        BT_ASSERT(pool);
        BT_ASSERT(ft);
-       field_wrapper = bt_object_pool_create_object(pool);
+       field_wrapper = bt_ctf_object_pool_create_object(pool);
        if (!field_wrapper) {
                BT_LIB_LOGE("Cannot allocate one field wrapper from field wrapper pool: "
                        "%![pool-]+o", pool);
index 7583ad5b2ff4dc668a5f1af8196874cbf2511ca9..e8c124981150b53d6b0b3c8c519b925eec780a7e 100644 (file)
@@ -34,8 +34,8 @@
 #include <babeltrace/ctf-writer/fields-internal.h>
 #include <babeltrace/ctf-writer/serialize-internal.h>
 #include <babeltrace/endian-internal.h>
-#include <babeltrace/object-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object-internal.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <float.h>
 #include <inttypes.h>
 #include <inttypes.h>
@@ -70,7 +70,7 @@ end:
 BT_HIDDEN
 int bt_ctf_field_common_structure_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                bt_ctf_field_common_create_func field_create_func,
                GDestroyNotify field_release_func)
@@ -114,7 +114,7 @@ end:
 BT_HIDDEN
 int bt_ctf_field_common_variant_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                bt_ctf_field_common_create_func field_create_func,
                GDestroyNotify field_release_func)
@@ -166,7 +166,7 @@ end:
 BT_HIDDEN
 int bt_ctf_field_common_string_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods)
 {
        int ret = 0;
@@ -192,7 +192,7 @@ end:
 BT_HIDDEN
 int bt_ctf_field_common_array_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                bt_ctf_field_common_create_func field_create_func,
                GDestroyNotify field_destroy_func)
@@ -236,7 +236,7 @@ end:
 BT_HIDDEN
 int bt_ctf_field_common_sequence_initialize(struct bt_ctf_field_common *field,
                struct bt_ctf_field_type_common *type,
-               bool is_shared, bt_object_release_func release_func,
+               bool is_shared, bt_ctf_object_release_func release_func,
                struct bt_ctf_field_common_methods *methods,
                GDestroyNotify field_destroy_func)
 {
@@ -806,7 +806,7 @@ void bt_ctf_field_enumeration_destroy_recursive(struct bt_ctf_field *field)
        BT_LOGD("Destroying CTF writer enumeration field object: addr=%p",
                field);
        BT_LOGD_STR("Putting container field.");
-       bt_object_put_ref(enumeration->container);
+       bt_ctf_object_put_ref(enumeration->container);
        bt_ctf_field_common_finalize((void *) field);
        g_free(field);
 }
@@ -826,7 +826,7 @@ void bt_ctf_field_variant_destroy_recursive(struct bt_ctf_field *field)
 
        BT_LOGD("Destroying CTF writer variant field object: addr=%p", field);
        BT_LOGD_STR("Putting tag field.");
-       bt_object_put_ref(variant->tag);
+       bt_ctf_object_put_ref(variant->tag);
        bt_ctf_field_common_variant_finalize_recursive((void *) field);
        g_free(field);
 }
@@ -1184,8 +1184,8 @@ int bt_ctf_field_string_serialize(struct bt_ctf_field_common *field,
        }
 
 end:
-       bt_object_put_ref(character);
-       bt_object_put_ref(character_type);
+       bt_ctf_object_put_ref(character);
+       bt_ctf_object_put_ref(character_type);
        return ret;
 }
 
@@ -1212,7 +1212,7 @@ end:
 
 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field)
 {
-       return bt_object_get_ref(bt_ctf_field_common_borrow_type((void *) field));
+       return bt_ctf_object_get_ref(bt_ctf_field_common_borrow_type((void *) field));
 }
 
 enum bt_ctf_field_type_id bt_ctf_field_get_type_id(struct bt_ctf_field *field)
@@ -1253,28 +1253,28 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field,
 struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index(
                struct bt_ctf_field *field, uint64_t index)
 {
-       return bt_object_get_ref(bt_ctf_field_common_structure_borrow_field_by_index(
+       return bt_ctf_object_get_ref(bt_ctf_field_common_structure_borrow_field_by_index(
                (void *) field, index));
 }
 
 struct bt_ctf_field *bt_ctf_field_structure_get_field_by_name(
                struct bt_ctf_field *field, const char *name)
 {
-       return bt_object_get_ref(bt_ctf_field_common_structure_borrow_field_by_name(
+       return bt_ctf_object_get_ref(bt_ctf_field_common_structure_borrow_field_by_name(
                (void *) field, name));
 }
 
 struct bt_ctf_field *bt_ctf_field_array_get_field(
                struct bt_ctf_field *field, uint64_t index)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_field_common_array_borrow_field((void *) field, index));
 }
 
 struct bt_ctf_field *bt_ctf_field_sequence_get_field(
                struct bt_ctf_field *field, uint64_t index)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_field_common_sequence_borrow_field((void *) field, index));
 }
 
@@ -1329,8 +1329,8 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field,
                goto end;
        }
 
-       bt_object_put_ref(variant_field->tag);
-       variant_field->tag = bt_object_get_ref(tag_field);
+       bt_ctf_object_put_ref(variant_field->tag);
+       variant_field->tag = bt_ctf_object_get_ref(tag_field);
        current_field = bt_ctf_field_variant_get_current_field(field);
        BT_ASSERT(current_field);
 
@@ -1341,7 +1341,7 @@ end:
 struct bt_ctf_field *bt_ctf_field_variant_get_current_field(
                struct bt_ctf_field *variant_field)
 {
-       return bt_object_get_ref(bt_ctf_field_common_variant_borrow_current_field(
+       return bt_ctf_object_get_ref(bt_ctf_field_common_variant_borrow_current_field(
                (void *) variant_field));
 }
 
@@ -1361,7 +1361,7 @@ struct bt_ctf_field *bt_ctf_field_enumeration_borrow_container(
 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(
                struct bt_ctf_field *field)
 {
-       return bt_object_get_ref(bt_ctf_field_enumeration_borrow_container(field));
+       return bt_ctf_object_get_ref(bt_ctf_field_enumeration_borrow_container(field));
 }
 
 int bt_ctf_field_integer_signed_get_value(struct bt_ctf_field *field,
@@ -1492,7 +1492,7 @@ struct bt_ctf_field *bt_ctf_field_integer_create(struct bt_ctf_field_type *type)
        if (integer) {
                bt_ctf_field_common_initialize(BT_CTF_TO_COMMON(integer), (void *) type,
                        true,
-                       (bt_object_release_func) bt_ctf_field_integer_destroy,
+                       (bt_ctf_object_release_func) bt_ctf_field_integer_destroy,
                        &bt_ctf_field_integer_methods);
                integer->common.spec.writer.serialize_func =
                        (bt_ctf_field_serialize_recursive_func) bt_ctf_field_integer_serialize;
@@ -1522,13 +1522,13 @@ struct bt_ctf_field *bt_ctf_field_enumeration_create(
 
        bt_ctf_field_common_initialize(BT_CTF_TO_COMMON(enumeration),
                (void *) type,
-               true, (bt_object_release_func)
+               true, (bt_ctf_object_release_func)
                        bt_ctf_field_enumeration_destroy_recursive,
                &bt_ctf_field_enumeration_methods);
        enumeration->container = (void *) bt_ctf_field_create(
                BT_CTF_FROM_COMMON(enum_ft->container_ft));
        if (!enumeration->container) {
-               BT_OBJECT_PUT_REF_AND_RESET(enumeration);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(enumeration);
                goto end;
        }
 
@@ -1554,7 +1554,7 @@ struct bt_ctf_field *bt_ctf_field_floating_point_create(
        if (floating_point) {
                bt_ctf_field_common_initialize(BT_CTF_TO_COMMON(floating_point),
                        (void *) type,
-                       true, (bt_object_release_func)
+                       true, (bt_ctf_object_release_func)
                                bt_ctf_field_floating_point_destroy,
                        &bt_ctf_field_floating_point_methods);
                floating_point->common.spec.writer.serialize_func =
@@ -1585,15 +1585,15 @@ struct bt_ctf_field *bt_ctf_field_structure_create(
 
        iret = bt_ctf_field_common_structure_initialize(BT_CTF_TO_COMMON(structure),
                (void *) type,
-               true, (bt_object_release_func)
+               true, (bt_ctf_object_release_func)
                        bt_ctf_field_structure_destroy_recursive,
                &bt_ctf_field_structure_methods,
                (bt_ctf_field_common_create_func) bt_ctf_field_create,
-               (GDestroyNotify) bt_object_put_ref);
+               (GDestroyNotify) bt_ctf_object_put_ref);
        structure->common.spec.writer.serialize_func =
                (bt_ctf_field_serialize_recursive_func) bt_ctf_field_structure_serialize_recursive;
        if (iret) {
-               BT_OBJECT_PUT_REF_AND_RESET(structure);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(structure);
                goto end;
        }
 
@@ -1620,11 +1620,11 @@ struct bt_ctf_field *bt_ctf_field_variant_create(struct bt_ctf_field_type *type)
 
        bt_ctf_field_common_variant_initialize(BT_CTF_TO_COMMON(BT_CTF_TO_COMMON(variant)),
                (void *) type,
-               true, (bt_object_release_func)
+               true, (bt_ctf_object_release_func)
                        bt_ctf_field_variant_destroy_recursive,
                &bt_ctf_field_variant_methods,
                (bt_ctf_field_common_create_func) bt_ctf_field_create,
-               (GDestroyNotify) bt_object_put_ref);
+               (GDestroyNotify) bt_ctf_object_put_ref);
        variant->tag = (void *) bt_ctf_field_create(
                BT_CTF_FROM_COMMON(var_ft->tag_ft));
        variant->common.common.spec.writer.serialize_func =
@@ -1653,15 +1653,15 @@ struct bt_ctf_field *bt_ctf_field_array_create(struct bt_ctf_field_type *type)
 
        ret = bt_ctf_field_common_array_initialize(BT_CTF_TO_COMMON(array),
                (void *) type,
-               true, (bt_object_release_func)
+               true, (bt_ctf_object_release_func)
                        bt_ctf_field_array_destroy_recursive,
                &bt_ctf_field_array_methods,
                (bt_ctf_field_common_create_func) bt_ctf_field_create,
-               (GDestroyNotify) bt_object_put_ref);
+               (GDestroyNotify) bt_ctf_object_put_ref);
        array->common.spec.writer.serialize_func =
                (bt_ctf_field_serialize_recursive_func) bt_ctf_field_array_serialize_recursive;
        if (ret) {
-               BT_OBJECT_PUT_REF_AND_RESET(array);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(array);
                goto end;
        }
 
@@ -1683,10 +1683,10 @@ struct bt_ctf_field *bt_ctf_field_sequence_create(struct bt_ctf_field_type *type
        if (sequence) {
                bt_ctf_field_common_sequence_initialize(BT_CTF_TO_COMMON(sequence),
                        (void *) type,
-                       true, (bt_object_release_func)
+                       true, (bt_ctf_object_release_func)
                                bt_ctf_field_sequence_destroy_recursive,
                        &bt_ctf_field_sequence_methods,
-                       (GDestroyNotify) bt_object_put_ref);
+                       (GDestroyNotify) bt_ctf_object_put_ref);
                sequence->common.spec.writer.serialize_func =
                        (bt_ctf_field_serialize_recursive_func) bt_ctf_field_sequence_serialize_recursive;
                BT_LOGD("Created CTF writer sequence field object: addr=%p, ft-addr=%p",
@@ -1709,7 +1709,7 @@ struct bt_ctf_field *bt_ctf_field_string_create(struct bt_ctf_field_type *type)
        if (string) {
                bt_ctf_field_common_string_initialize(BT_CTF_TO_COMMON(string),
                        (void *) type,
-                       true, (bt_object_release_func)
+                       true, (bt_ctf_object_release_func)
                                bt_ctf_field_string_destroy,
                        &bt_ctf_field_string_methods);
                string->common.spec.writer.serialize_func =
@@ -1905,8 +1905,8 @@ int bt_ctf_field_structure_set_field_by_name(struct bt_ctf_field *field,
                ret = -1;
                goto end;
        }
-       bt_object_get_ref(value);
-       BT_OBJECT_MOVE_REF(structure->fields->pdata[index], value);
+       bt_ctf_object_get_ref(value);
+       BT_CTF_OBJECT_MOVE_REF(structure->fields->pdata[index], value);
 
 end:
        return ret;
diff --git a/lib/ctf-writer/object-pool.c b/lib/ctf-writer/object-pool.c
new file mode 100644 (file)
index 0000000..6cbc194
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2018 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define BT_LOG_TAG "OBJECT-POOL"
+#include <babeltrace/lib-logging-internal.h>
+
+#include <stdint.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/ctf-writer/object-pool-internal.h>
+
+int bt_ctf_object_pool_initialize(struct bt_ctf_object_pool *pool,
+               bt_ctf_object_pool_new_object_func new_object_func,
+               bt_ctf_object_pool_destroy_object_func destroy_object_func,
+               void *data)
+{
+       int ret = 0;
+
+       BT_ASSERT(new_object_func);
+       BT_ASSERT(destroy_object_func);
+       BT_LOGD("Initializing object pool: addr=%p, data-addr=%p",
+               pool, data);
+       pool->objects = g_ptr_array_new();
+       if (!pool->objects) {
+               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               goto error;
+       }
+
+       pool->funcs.new_object = new_object_func;
+       pool->funcs.destroy_object = destroy_object_func;
+       pool->data = data;
+       pool->size = 0;
+       BT_LIB_LOGD("Initialized object pool: %!+o", pool);
+       goto end;
+
+error:
+       if (pool) {
+               bt_ctf_object_pool_finalize(pool);
+       }
+
+       ret = -1;
+
+end:
+       return ret;
+}
+
+void bt_ctf_object_pool_finalize(struct bt_ctf_object_pool *pool)
+{
+       uint64_t i;
+
+       BT_ASSERT(pool);
+       BT_LIB_LOGD("Finalizing object pool: %!+o", pool);
+
+       if (pool->objects) {
+               for (i = 0; i < pool->size; i++) {
+                       void *obj = pool->objects->pdata[i];
+
+                       if (obj) {
+                               pool->funcs.destroy_object(obj, pool->data);
+                       }
+               }
+
+               g_ptr_array_free(pool->objects, TRUE);
+               pool->objects = NULL;
+       }
+}
diff --git a/lib/ctf-writer/object.c b/lib/ctf-writer/object.c
new file mode 100644 (file)
index 0000000..0ed50de
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/ctf-writer/object-internal.h>
+
+void *bt_ctf_object_get_ref(void *obj)
+{
+       if (unlikely(!obj)) {
+               goto end;
+       }
+
+       bt_ctf_object_get_no_null_check(obj);
+
+end:
+       return obj;
+}
+
+void bt_ctf_object_put_ref(void *obj)
+{
+       if (unlikely(!obj)) {
+               return;
+       }
+
+       bt_ctf_object_put_no_null_check(obj);
+}
index eb9265d7f222b44ed65a074b41f1c3e6af1de093..5ef8973988e84758403ad2aa5cf3f289a3f9bcfa 100644 (file)
@@ -38,9 +38,9 @@
 #include <babeltrace/ctf-writer/resolve-internal.h>
 #include <babeltrace/ctf-writer/stream-class.h>
 #include <babeltrace/ctf-writer/utils-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <babeltrace/types.h>
-#include <babeltrace/values.h>
+#include <babeltrace/ctf-writer/values-internal.h>
 #include <glib.h>
 #include <inttypes.h>
 #include <limits.h>
@@ -76,7 +76,7 @@ struct type_stack_frame {
  *   * Event payload
  */
 struct resolve_context {
-       struct bt_private_value *environment;
+       struct bt_ctf_private_value *environment;
        struct bt_ctf_field_type_common *scopes[6];
 
        /* Root scope being visited */
@@ -115,7 +115,7 @@ void type_stack_destroy_notify(gpointer data)
 {
        struct type_stack_frame *frame = data;
 
-       BT_OBJECT_PUT_REF_AND_RESET(frame->type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(frame->type);
        g_free(frame);
 }
 
@@ -165,7 +165,7 @@ int type_stack_push(type_stack *stack, struct bt_ctf_field_type_common *type)
 
        BT_LOGV("Pushing field type on context's stack: "
                "ft-addr=%p, stack-size-before=%u", type, stack->len);
-       frame->type = bt_object_get_ref(type);
+       frame->type = bt_ctf_object_get_ref(type);
        g_ptr_array_add(stack, frame);
 
 end:
@@ -402,7 +402,7 @@ int ptokens_to_field_path(GList *ptokens, struct bt_ctf_field_path *field_path,
        bt_bool first_level_done = BT_FALSE;
 
        /* Get our own reference */
-       bt_object_get_ref(type);
+       bt_ctf_object_get_ref(type);
 
        /* Locate target */
        while (cur_ptoken) {
@@ -460,12 +460,12 @@ int ptokens_to_field_path(GList *ptokens, struct bt_ctf_field_path *field_path,
                }
 
                /* Move child type to current type */
-               bt_object_get_ref(child_type);
-               BT_OBJECT_MOVE_REF(type, child_type);
+               bt_ctf_object_get_ref(child_type);
+               BT_CTF_OBJECT_MOVE_REF(type, child_type);
        }
 
 end:
-       bt_object_put_ref(type);
+       bt_ctf_object_put_ref(type);
        return ret;
 }
 
@@ -617,7 +617,7 @@ int relative_ptokens_to_field_path(GList *ptokens,
        }
 
 end:
-       BT_OBJECT_PUT_REF_AND_RESET(tail_field_path);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(tail_field_path);
        return ret;
 }
 
@@ -704,7 +704,7 @@ struct bt_ctf_field_path *pathstr_to_field_path(const char *pathstr,
 
 end:
        if (ret) {
-               BT_OBJECT_PUT_REF_AND_RESET(field_path);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(field_path);
        }
 
        ptokens_destroy(ptokens);
@@ -727,7 +727,7 @@ struct bt_ctf_field_type_common *field_path_to_field_type(
 
        /* Start with root type */
        type = get_type_from_ctx(ctx, field_path->root);
-       bt_object_get_ref(type);
+       bt_ctf_object_get_ref(type);
        if (!type) {
                /* Error: root type is not available */
                BT_LOGW("Root field type is not available: root-scope=%s",
@@ -751,14 +751,14 @@ struct bt_ctf_field_type_common *field_path_to_field_type(
                }
 
                /* Move child type to current type */
-               bt_object_get_ref(child_type);
-               BT_OBJECT_MOVE_REF(type, child_type);
+               bt_ctf_object_get_ref(child_type);
+               BT_CTF_OBJECT_MOVE_REF(type, child_type);
        }
 
        return type;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(type);
        return type;
 }
 
@@ -792,7 +792,7 @@ struct bt_ctf_field_path *get_ctx_stack_field_path(struct resolve_context *ctx)
        return field_path;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(field_path);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(field_path);
        return field_path;
 }
 
@@ -988,7 +988,7 @@ int validate_target_field_path(struct bt_ctf_field_path *target_field_path,
        }
 
 end:
-       BT_OBJECT_PUT_REF_AND_RESET(ctx_field_path);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(ctx_field_path);
        return ret;
 }
 
@@ -1104,8 +1104,8 @@ end:
                g_string_free(target_field_path_pretty, TRUE);
        }
 
-       BT_OBJECT_PUT_REF_AND_RESET(target_field_path);
-       BT_OBJECT_PUT_REF_AND_RESET(target_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(target_field_path);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(target_type);
        return ret;
 }
 
@@ -1229,7 +1229,7 @@ int resolve_root_type(enum bt_ctf_scope root_scope, struct resolve_context *ctx)
 
 BT_HIDDEN
 int bt_ctf_resolve_types(
-               struct bt_private_value *environment,
+               struct bt_ctf_private_value *environment,
                struct bt_ctf_field_type_common *packet_header_type,
                struct bt_ctf_field_type_common *packet_context_type,
                struct bt_ctf_field_type_common *event_header_type,
index 63bf4a793068133c7ae353f67b78d0f658e52556..baf96aee53bddd393449084838fe0303c33a70ab 100644 (file)
 #include <babeltrace/ctf-writer/visitor-internal.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
 #include <babeltrace/endian-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
 
 BT_HIDDEN
 int bt_ctf_stream_class_common_initialize(struct bt_ctf_stream_class_common *stream_class,
-               const char *name, bt_object_release_func release_func)
+               const char *name, bt_ctf_object_release_func release_func)
 {
        BT_LOGD("Initializing common stream class object: name=\"%s\"", name);
 
-       bt_object_init_shared_with_parent(&stream_class->base, release_func);
+       bt_ctf_object_init_shared_with_parent(&stream_class->base, release_func);
        stream_class->name = g_string_new(name);
        stream_class->event_classes = g_ptr_array_new_with_free_func(
-               (GDestroyNotify) bt_object_try_spec_release);
+               (GDestroyNotify) bt_ctf_object_try_spec_release);
        if (!stream_class->event_classes) {
                BT_LOGE_STR("Failed to allocate a GPtrArray.");
                goto error;
@@ -84,7 +84,7 @@ void bt_ctf_stream_class_common_finalize(struct bt_ctf_stream_class_common *stre
        BT_LOGD("Finalizing common stream class: addr=%p, name=\"%s\", id=%" PRId64,
                stream_class, bt_ctf_stream_class_common_get_name(stream_class),
                bt_ctf_stream_class_common_get_id(stream_class));
-       bt_object_put_ref(stream_class->clock_class);
+       bt_ctf_object_put_ref(stream_class->clock_class);
 
        if (stream_class->event_classes_ht) {
                g_hash_table_destroy(stream_class->event_classes_ht);
@@ -99,11 +99,11 @@ void bt_ctf_stream_class_common_finalize(struct bt_ctf_stream_class_common *stre
        }
 
        BT_LOGD_STR("Putting event header field type.");
-       bt_object_put_ref(stream_class->event_header_field_type);
+       bt_ctf_object_put_ref(stream_class->event_header_field_type);
        BT_LOGD_STR("Putting packet context field type.");
-       bt_object_put_ref(stream_class->packet_context_field_type);
+       bt_ctf_object_put_ref(stream_class->packet_context_field_type);
        BT_LOGD_STR("Putting event context field type.");
-       bt_object_put_ref(stream_class->event_context_field_type);
+       bt_ctf_object_put_ref(stream_class->event_context_field_type);
 }
 
 static
@@ -198,7 +198,7 @@ int bt_ctf_stream_class_common_add_event_class(
                 * context) could change before the next call to one of
                 * those two functions.
                 */
-               expected_clock_class = bt_object_get_ref(stream_class->clock_class);
+               expected_clock_class = bt_ctf_object_get_ref(stream_class->clock_class);
 
                /*
                 * At this point, `expected_clock_class` can be NULL,
@@ -334,7 +334,7 @@ int bt_ctf_stream_class_common_add_event_class(
                *event_id = stream_class->next_event_id;
        }
 
-       bt_object_set_parent(&event_class->base, &stream_class->base);
+       bt_ctf_object_set_parent(&event_class->base, &stream_class->base);
 
        if (trace) {
                /*
@@ -370,7 +370,7 @@ int bt_ctf_stream_class_common_add_event_class(
        if (stream_class->frozen && expected_clock_class) {
                BT_ASSERT(!stream_class->clock_class ||
                        stream_class->clock_class == expected_clock_class);
-               BT_OBJECT_MOVE_REF(stream_class->clock_class, expected_clock_class);
+               BT_CTF_OBJECT_MOVE_REF(stream_class->clock_class, expected_clock_class);
        }
 
        BT_LOGD("Added event class to stream class: "
@@ -385,7 +385,7 @@ int bt_ctf_stream_class_common_add_event_class(
 
 end:
        bt_ctf_validation_output_put_types(&validation_output);
-       bt_object_put_ref(expected_clock_class);
+       bt_ctf_object_put_ref(expected_clock_class);
        g_free(event_id);
        return ret;
 }
@@ -587,18 +587,18 @@ int init_event_header(struct bt_ctf_stream_class *stream_class)
                goto end;
        }
 
-       bt_object_put_ref(stream_class->common.event_header_field_type);
+       bt_ctf_object_put_ref(stream_class->common.event_header_field_type);
        stream_class->common.event_header_field_type =
                (void *) event_header_type;
        event_header_type = NULL;
 
 end:
        if (ret) {
-               bt_object_put_ref(event_header_type);
+               bt_ctf_object_put_ref(event_header_type);
        }
 
-       bt_object_put_ref(_uint32_t);
-       bt_object_put_ref(_uint64_t);
+       bt_ctf_object_put_ref(_uint32_t);
+       bt_ctf_object_put_ref(_uint64_t);
        return ret;
 }
 
@@ -664,24 +664,24 @@ int init_packet_context(struct bt_ctf_stream_class *stream_class)
                goto end;
        }
 
-       bt_object_put_ref(stream_class->common.packet_context_field_type);
+       bt_ctf_object_put_ref(stream_class->common.packet_context_field_type);
        stream_class->common.packet_context_field_type =
                (void *) packet_context_type;
        packet_context_type = NULL;
 
 end:
        if (ret) {
-               bt_object_put_ref(packet_context_type);
+               bt_ctf_object_put_ref(packet_context_type);
                goto end;
        }
 
-       bt_object_put_ref(_uint64_t);
-       bt_object_put_ref(ts_begin_end_uint64_t);
+       bt_ctf_object_put_ref(_uint64_t);
+       bt_ctf_object_put_ref(ts_begin_end_uint64_t);
        return ret;
 }
 
 static
-void bt_ctf_stream_class_destroy(struct bt_object *obj)
+void bt_ctf_stream_class_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_stream_class *stream_class;
 
@@ -690,7 +690,7 @@ void bt_ctf_stream_class_destroy(struct bt_object *obj)
                stream_class, bt_ctf_stream_class_get_name(stream_class),
                bt_ctf_stream_class_get_id(stream_class));
        bt_ctf_stream_class_common_finalize(BT_CTF_TO_COMMON(stream_class));
-       bt_object_put_ref(stream_class->clock);
+       bt_ctf_object_put_ref(stream_class->clock);
        g_free(stream_class);
 }
 
@@ -730,7 +730,7 @@ struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name)
        return stream_class;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(stream_class);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_class);
        return stream_class;
 }
 
@@ -781,7 +781,7 @@ int try_map_clock_class(struct bt_ctf_stream_class *stream_class,
 
                ret = bt_ctf_field_type_common_structure_replace_field(
                        (void *) parent_ft, field_name, (void *) ft_copy);
-               bt_object_put_ref(ft_copy);
+               bt_ctf_object_put_ref(ft_copy);
                BT_LOGV("Automatically mapped field type to stream class's clock class: "
                        "stream-class-addr=%p, stream-class-name=\"%s\", "
                        "stream-class-id=%" PRId64 ", ft-addr=%p, "
@@ -792,8 +792,8 @@ int try_map_clock_class(struct bt_ctf_stream_class *stream_class,
        }
 
 end:
-       bt_object_put_ref(ft);
-       bt_object_put_ref(mapped_clock_class);
+       bt_ctf_object_put_ref(ft);
+       bt_ctf_object_put_ref(mapped_clock_class);
        return ret;
 }
 
@@ -860,7 +860,7 @@ struct bt_ctf_clock *bt_ctf_stream_class_get_clock(
                goto end;
        }
 
-       clock = bt_object_get_ref(stream_class->clock);
+       clock = bt_ctf_object_get_ref(stream_class->clock);
 
 end:
        return clock;
@@ -891,8 +891,8 @@ int bt_ctf_stream_class_set_clock(
        }
 
        /* Replace the current clock of this stream class. */
-       bt_object_put_ref(stream_class->clock);
-       stream_class->clock = bt_object_get_ref(clock);
+       bt_ctf_object_put_ref(stream_class->clock);
+       stream_class->clock = bt_ctf_object_get_ref(clock);
        BT_LOGV("Set stream class's clock: "
                "addr=%p, name=\"%s\", id=%" PRId64 ", "
                "clock-addr=%p, clock-name=\"%s\"",
@@ -961,7 +961,7 @@ int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class,
                                "\tid = %" PRId64 ";\n",
                                stream_class->common.id);
                }
-               bt_object_put_ref(stream_id_type);
+               bt_ctf_object_put_ref(stream_id_type);
        }
        if (stream_class->common.event_header_field_type) {
                BT_LOGD_STR("Serializing stream class's event header field type's metadata.");
@@ -1025,7 +1025,7 @@ int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class,
        }
 
 end:
-       bt_object_put_ref(packet_header_type);
+       bt_ctf_object_put_ref(packet_header_type);
        context->current_indentation_level = 0;
        return ret;
 }
@@ -1033,7 +1033,7 @@ end:
 struct bt_ctf_trace *bt_ctf_stream_class_get_trace(
                struct bt_ctf_stream_class *stream_class)
 {
-       return bt_object_get_ref(bt_ctf_stream_class_common_borrow_trace(
+       return bt_ctf_object_get_ref(bt_ctf_stream_class_common_borrow_trace(
                BT_CTF_TO_COMMON(stream_class)));
 }
 
@@ -1065,7 +1065,7 @@ int bt_ctf_stream_class_set_id(
 struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(
                struct bt_ctf_stream_class *stream_class)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_stream_class_common_borrow_packet_context_field_type(
                        BT_CTF_TO_COMMON(stream_class)));
 }
@@ -1082,7 +1082,7 @@ struct bt_ctf_field_type *
 bt_ctf_stream_class_get_event_header_type(
                struct bt_ctf_stream_class *stream_class)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_stream_class_common_borrow_event_header_field_type(
                        BT_CTF_TO_COMMON(stream_class)));
 }
@@ -1099,7 +1099,7 @@ struct bt_ctf_field_type *
 bt_ctf_stream_class_get_event_context_type(
                struct bt_ctf_stream_class *stream_class)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_stream_class_common_borrow_event_context_field_type(
                        BT_CTF_TO_COMMON(stream_class)));
 }
@@ -1122,7 +1122,7 @@ int64_t bt_ctf_stream_class_get_event_class_count(
 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_index(
                struct bt_ctf_stream_class *stream_class, uint64_t index)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_stream_class_common_borrow_event_class_by_index(
                        BT_CTF_TO_COMMON(stream_class), index));
 }
@@ -1130,7 +1130,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_index(
 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id(
                struct bt_ctf_stream_class *stream_class, uint64_t id)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_stream_class_common_borrow_event_class_by_id(
                        BT_CTF_TO_COMMON(stream_class), id));
 }
index 6fedfb685bef854dd71a3a46d216cb408e27e05c..503bee374d1b772ae1ae10df00882d83adb13236 100644 (file)
@@ -39,7 +39,7 @@
 #include <babeltrace/ctf-writer/trace-internal.h>
 #include <babeltrace/ctf-writer/trace.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <inttypes.h>
 #include <stdint.h>
 #include <unistd.h>
@@ -59,12 +59,12 @@ BT_HIDDEN
 int bt_ctf_stream_common_initialize(
                struct bt_ctf_stream_common *stream,
                struct bt_ctf_stream_class_common *stream_class, const char *name,
-               uint64_t id, bt_object_release_func release_func)
+               uint64_t id, bt_ctf_object_release_func release_func)
 {
        int ret = 0;
        struct bt_ctf_trace_common *trace = NULL;
 
-       bt_object_init_shared_with_parent(&stream->base, release_func);
+       bt_ctf_object_init_shared_with_parent(&stream->base, release_func);
 
        if (!stream_class) {
                BT_LOGW_STR("Invalid parameter: stream class is NULL.");
@@ -113,7 +113,7 @@ int bt_ctf_stream_common_initialize(
         * Acquire reference to parent since stream will become publicly
         * reachable; it needs its parent to remain valid.
         */
-       bt_object_set_parent(&stream->base, &trace->base);
+       bt_ctf_object_set_parent(&stream->base, &trace->base);
        stream->stream_class = stream_class;
        stream->id = (int64_t) id;
 
@@ -139,7 +139,7 @@ end:
 }
 
 static
-void bt_ctf_stream_destroy(struct bt_object *obj);
+void bt_ctf_stream_destroy(struct bt_ctf_object *obj);
 
 static
 int try_set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t);
@@ -191,7 +191,7 @@ int set_integer_field_value(struct bt_ctf_field* field, uint64_t value)
                }
        }
 end:
-       bt_object_put_ref(field_type);
+       bt_ctf_object_put_ref(field_type);
        return ret;
 }
 
@@ -228,7 +228,7 @@ int set_packet_header_magic(struct bt_ctf_stream *stream)
                        magic_field, (uint64_t) magic_value);
        }
 end:
-       bt_object_put_ref(magic_field);
+       bt_ctf_object_put_ref(magic_field);
        return ret;
 }
 
@@ -252,7 +252,7 @@ int set_packet_header_uuid(struct bt_ctf_stream *stream)
        }
 
        trace = (struct bt_ctf_trace *)
-               bt_object_get_parent(&stream->common.base);
+               bt_ctf_object_get_parent(&stream->common.base);
 
        for (i = 0; i < 16; i++) {
                struct bt_ctf_field *uuid_element =
@@ -260,7 +260,7 @@ int set_packet_header_uuid(struct bt_ctf_stream *stream)
 
                ret = bt_ctf_field_integer_unsigned_set_value(
                        uuid_element, (uint64_t) trace->common.uuid[i]);
-               bt_object_put_ref(uuid_element);
+               bt_ctf_object_put_ref(uuid_element);
                if (ret) {
                        BT_LOGW("Cannot set integer field's value (for `uuid` packet header field): "
                                "stream-addr=%p, stream-name=\"%s\", field-addr=%p, "
@@ -276,8 +276,8 @@ int set_packet_header_uuid(struct bt_ctf_stream *stream)
                stream, bt_ctf_stream_get_name(stream), uuid_field);
 
 end:
-       bt_object_put_ref(uuid_field);
-       BT_OBJECT_PUT_REF_AND_RESET(trace);
+       bt_ctf_object_put_ref(uuid_field);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(trace);
        return ret;
 }
 static
@@ -313,7 +313,7 @@ int set_packet_header_stream_id(struct bt_ctf_stream *stream)
        }
 
 end:
-       bt_object_put_ref(stream_id_field);
+       bt_ctf_object_put_ref(stream_id_field);
        return ret;
 }
 
@@ -390,7 +390,7 @@ int set_packet_context_packet_size(struct bt_ctf_stream *stream)
        }
 
 end:
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
        return ret;
 }
 
@@ -426,7 +426,7 @@ int set_packet_context_content_size(struct bt_ctf_stream *stream)
        }
 
 end:
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
        return ret;
 }
 
@@ -494,7 +494,7 @@ int set_packet_context_events_discarded(struct bt_ctf_stream *stream)
        }
 
 end:
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
        return ret;
 }
 
@@ -554,7 +554,7 @@ int visit_field_update_clock_value(struct bt_ctf_field *field, uint64_t *val)
                        goto end;
                }
 
-               bt_object_put_ref(cc);
+               bt_ctf_object_put_ref(cc);
                val_size = bt_ctf_field_type_integer_get_size(
                        (void *) field_common->type);
                BT_ASSERT(val_size >= 1);
@@ -584,7 +584,7 @@ int visit_field_update_clock_value(struct bt_ctf_field *field, uint64_t *val)
 
                BT_ASSERT(int_field);
                ret = visit_field_update_clock_value(int_field, val);
-               bt_object_put_ref(int_field);
+               bt_ctf_object_put_ref(int_field);
                break;
        }
        case BT_CTF_FIELD_TYPE_ID_ARRAY:
@@ -601,7 +601,7 @@ int visit_field_update_clock_value(struct bt_ctf_field *field, uint64_t *val)
 
                        BT_ASSERT(elem_field);
                        ret = visit_field_update_clock_value(elem_field, val);
-                       bt_object_put_ref(elem_field);
+                       bt_ctf_object_put_ref(elem_field);
                        if (ret) {
                                goto end;
                        }
@@ -625,7 +625,7 @@ int visit_field_update_clock_value(struct bt_ctf_field *field, uint64_t *val)
 
                        BT_ASSERT(elem_field);
                        ret = visit_field_update_clock_value(elem_field, val);
-                       bt_object_put_ref(elem_field);
+                       bt_ctf_object_put_ref(elem_field);
                        if (ret) {
                                goto end;
                        }
@@ -646,7 +646,7 @@ int visit_field_update_clock_value(struct bt_ctf_field *field, uint64_t *val)
 
                        BT_ASSERT(member_field);
                        ret = visit_field_update_clock_value(member_field, val);
-                       bt_object_put_ref(member_field);
+                       bt_ctf_object_put_ref(member_field);
                        if (ret) {
                                goto end;
                        }
@@ -664,7 +664,7 @@ int visit_field_update_clock_value(struct bt_ctf_field *field, uint64_t *val)
                }
 
                ret = visit_field_update_clock_value(cur_field, val);
-               bt_object_put_ref(cur_field);
+               bt_ctf_object_put_ref(cur_field);
                break;
        }
        default:
@@ -682,7 +682,7 @@ int visit_event_update_clock_value(struct bt_ctf_event *event, uint64_t *val)
 
        field = bt_ctf_event_get_header(event);
        ret = visit_field_update_clock_value(field, val);
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
        if (ret) {
                BT_LOGW_STR("Cannot automatically update clock value in "
                        "event's header.");
@@ -691,7 +691,7 @@ int visit_event_update_clock_value(struct bt_ctf_event *event, uint64_t *val)
 
        field = bt_ctf_event_get_stream_event_context(event);
        ret = visit_field_update_clock_value(field, val);
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
        if (ret) {
                BT_LOGW_STR("Cannot automatically update clock value in "
                        "event's stream event context.");
@@ -700,7 +700,7 @@ int visit_event_update_clock_value(struct bt_ctf_event *event, uint64_t *val)
 
        field = bt_ctf_event_get_context(event);
        ret = visit_field_update_clock_value(field, val);
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
        if (ret) {
                BT_LOGW_STR("Cannot automatically update clock value in "
                        "event's context.");
@@ -709,7 +709,7 @@ int visit_event_update_clock_value(struct bt_ctf_event *event, uint64_t *val)
 
        field = bt_ctf_event_get_payload_field(event);
        ret = visit_field_update_clock_value(field, val);
-       bt_object_put_ref(field);
+       bt_ctf_object_put_ref(field);
        if (ret) {
                BT_LOGW_STR("Cannot automatically update clock value in "
                        "event's payload.");
@@ -796,31 +796,31 @@ int set_packet_context_timestamps(struct bt_ctf_stream *stream)
 
                if (strcmp(member_name, "packet_size") == 0 &&
                                !bt_ctf_field_is_set_recursive(member_field)) {
-                       bt_object_put_ref(member_field);
+                       bt_ctf_object_put_ref(member_field);
                        continue;
                }
 
                if (strcmp(member_name, "content_size") == 0 &&
                                !bt_ctf_field_is_set_recursive(member_field)) {
-                       bt_object_put_ref(member_field);
+                       bt_ctf_object_put_ref(member_field);
                        continue;
                }
 
                if (strcmp(member_name, "events_discarded") == 0 &&
                                !bt_ctf_field_is_set_recursive(member_field)) {
-                       bt_object_put_ref(member_field);
+                       bt_ctf_object_put_ref(member_field);
                        continue;
                }
 
                if (strcmp(member_name, "packet_seq_num") == 0 &&
                                !bt_ctf_field_is_set_recursive(member_field)) {
-                       bt_object_put_ref(member_field);
+                       bt_ctf_object_put_ref(member_field);
                        continue;
                }
 
                ret = visit_field_update_clock_value(member_field,
                        &cur_clock_value);
-               bt_object_put_ref(member_field);
+               bt_ctf_object_put_ref(member_field);
                if (ret) {
                        BT_LOGW("Cannot automatically update clock value "
                                "in stream's packet context: "
@@ -894,8 +894,8 @@ int set_packet_context_timestamps(struct bt_ctf_stream *stream)
        }
 
 end:
-       bt_object_put_ref(ts_begin_field);
-       bt_object_put_ref(ts_end_field);
+       bt_ctf_object_put_ref(ts_begin_field);
+       bt_ctf_object_put_ref(ts_end_field);
        return ret;
 }
 
@@ -953,16 +953,16 @@ end:
 static
 void release_event(struct bt_ctf_event *event)
 {
-       if (bt_object_get_ref_count(&event->common.base)) {
+       if (bt_ctf_object_get_ref_count(&event->common.base)) {
                /*
                 * The event is being orphaned, but it must guarantee the
                 * existence of its event class for the duration of its
                 * lifetime.
                 */
-               bt_object_get_ref(event->common.class);
-               BT_OBJECT_PUT_REF_AND_RESET(event->common.base.parent);
+               bt_ctf_object_get_ref(event->common.class);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(event->common.base.parent);
        } else {
-               bt_object_try_spec_release(&event->common.base);
+               bt_ctf_object_try_spec_release(&event->common.base);
        }
 }
 
@@ -1106,7 +1106,7 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id(
 
        stream->pos.fd = -1;
        writer = (struct bt_ctf_writer *)
-               bt_object_get_parent(&trace->common.base);
+               bt_ctf_object_get_parent(&trace->common.base);
        stream->last_ts_end = -1ULL;
        BT_LOGD("CTF writer stream object belongs writer's trace: "
                "writer-addr=%p", writer);
@@ -1187,10 +1187,10 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id(
        goto end;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(stream);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(stream);
 
 end:
-       bt_object_put_ref(writer);
+       bt_ctf_object_put_ref(writer);
        return stream;
 }
 
@@ -1260,7 +1260,7 @@ int set_packet_context_events_discarded_field(struct bt_ctf_stream *stream,
        }
 
 end:
-       bt_object_put_ref(events_discarded_field);
+       bt_ctf_object_put_ref(events_discarded_field);
        return ret;
 }
 
@@ -1317,7 +1317,7 @@ void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
                stream, bt_ctf_stream_get_name(stream), event_count);
 
 end:
-       bt_object_put_ref(events_discarded_field);
+       bt_ctf_object_put_ref(events_discarded_field);
 }
 
 static int auto_populate_event_header(struct bt_ctf_stream *stream,
@@ -1404,9 +1404,9 @@ static int auto_populate_event_header(struct bt_ctf_stream *stream,
                stream, bt_ctf_stream_get_name(stream), event);
 
 end:
-       bt_object_put_ref(id_field);
-       bt_object_put_ref(timestamp_field);
-       bt_object_put_ref(mapped_clock_class);
+       bt_ctf_object_put_ref(id_field);
+       bt_ctf_object_put_ref(timestamp_field);
+       bt_ctf_object_put_ref(mapped_clock_class);
        return ret;
 }
 
@@ -1455,7 +1455,7 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       bt_object_set_parent(&event->common.base, &stream->common.base);
+       bt_ctf_object_set_parent(&event->common.base, &stream->common.base);
        BT_LOGV_STR("Automatically populating the header of the event to append.");
        ret = auto_populate_event_header(stream, event);
        if (ret) {
@@ -1480,7 +1480,7 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
         * longer needed.
         */
        BT_LOGV_STR("Putting the event's class.");
-       bt_object_put_ref(event->common.class);
+       bt_ctf_object_put_ref(event->common.class);
        BT_LOGV("Appended event to stream: "
                "stream-addr=%p, stream-name=\"%s\", event-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64,
@@ -1498,7 +1498,7 @@ error:
         * Orphan the event; we were not successful in associating it to
         * a stream.
         */
-       bt_object_set_parent(&event->common.base, NULL);
+       bt_ctf_object_set_parent(&event->common.base, NULL);
        return ret;
 }
 
@@ -1520,7 +1520,7 @@ struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stre
 
        packet_context = stream->packet_context;
        if (packet_context) {
-               bt_object_get_ref(packet_context);
+               bt_ctf_object_get_ref(packet_context);
        }
 end:
        return packet_context;
@@ -1557,9 +1557,9 @@ int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       bt_object_put_ref(field_type);
-       bt_object_put_ref(stream->packet_context);
-       stream->packet_context = bt_object_get_ref(field);
+       bt_ctf_object_put_ref(field_type);
+       bt_ctf_object_put_ref(stream->packet_context);
+       stream->packet_context = bt_ctf_object_get_ref(field);
        BT_LOGV("Set stream's packet context field: "
                "stream-addr=%p, stream-name=\"%s\", "
                "packet-context-field-addr=%p",
@@ -1586,7 +1586,7 @@ struct bt_ctf_field *bt_ctf_stream_get_packet_header(struct bt_ctf_stream *strea
 
        packet_header = stream->packet_header;
        if (packet_header) {
-               bt_object_get_ref(packet_header);
+               bt_ctf_object_get_ref(packet_header);
        }
 end:
        return packet_header;
@@ -1612,7 +1612,7 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
        }
 
        trace = (struct bt_ctf_trace *)
-               bt_object_get_parent(&stream->common.base);
+               bt_ctf_object_get_parent(&stream->common.base);
 
        if (!field) {
                if (trace->common.packet_header_field_type) {
@@ -1645,15 +1645,15 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
        }
 
 skip_validation:
-       bt_object_put_ref(stream->packet_header);
-       stream->packet_header = bt_object_get_ref(field);
+       bt_ctf_object_put_ref(stream->packet_header);
+       stream->packet_header = bt_ctf_object_get_ref(field);
        BT_LOGV("Set stream's packet header field: "
                "stream-addr=%p, stream-name=\"%s\", "
                "packet-header-field-addr=%p",
                stream, bt_ctf_stream_get_name(stream), field);
 end:
-       BT_OBJECT_PUT_REF_AND_RESET(trace);
-       bt_object_put_ref(field_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(trace);
+       bt_ctf_object_put_ref(field_type);
        return ret;
 }
 
@@ -1665,7 +1665,7 @@ void reset_structure_field(struct bt_ctf_field *structure, const char *name)
        member = bt_ctf_field_structure_get_field_by_name(structure, name);
        if (member) {
                bt_ctf_field_common_reset_recursive((void *) member);
-               bt_object_put_ref(member);
+               bt_ctf_object_put_ref(member);
        }
 }
 
@@ -1696,7 +1696,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                packet_size_field = bt_ctf_field_structure_get_field_by_name(
                                stream->packet_context, "packet_size");
                has_packet_size = (packet_size_field != NULL);
-               bt_object_put_ref(packet_size_field);
+               bt_ctf_object_put_ref(packet_size_field);
        }
 
        if (stream->flushed_packet_count == 1) {
@@ -1846,7 +1846,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                struct bt_ctf_field *field = bt_ctf_field_structure_get_field_by_name(
                        stream->packet_context, "content_size");
 
-               bt_object_put_ref(field);
+               bt_ctf_object_put_ref(field);
                if (!field) {
                        if (stream->pos.offset != stream->pos.packet_size) {
                                BT_LOGW("Stream's packet context's `content_size` field is missing, "
@@ -1919,7 +1919,7 @@ end_no_stream:
 }
 
 static
-void bt_ctf_stream_destroy(struct bt_object *obj)
+void bt_ctf_stream_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_stream *stream = (void *) obj;
 
@@ -1958,9 +1958,9 @@ void bt_ctf_stream_destroy(struct bt_object *obj)
        }
 
        BT_LOGD_STR("Putting packet header field.");
-       bt_object_put_ref(stream->packet_header);
+       bt_ctf_object_put_ref(stream->packet_header);
        BT_LOGD_STR("Putting packet context field.");
-       bt_object_put_ref(stream->packet_context);
+       bt_ctf_object_put_ref(stream->packet_context);
        g_free(stream);
 }
 
@@ -2016,8 +2016,8 @@ int _set_structure_field_integer(struct bt_ctf_field *structure, char *name,
        }
        ret = !ret ? 1 : ret;
 end:
-       bt_object_put_ref(integer);
-       bt_object_put_ref(field_type);
+       bt_ctf_object_put_ref(integer);
+       bt_ctf_object_put_ref(field_type);
        return ret;
 }
 
@@ -2037,7 +2037,7 @@ int try_set_structure_field_integer(struct bt_ctf_field *structure, char *name,
 struct bt_ctf_stream_class *bt_ctf_stream_get_class(
                struct bt_ctf_stream *stream)
 {
-       return bt_object_get_ref(bt_ctf_stream_common_borrow_class(BT_CTF_TO_COMMON(stream)));
+       return bt_ctf_object_get_ref(bt_ctf_stream_common_borrow_class(BT_CTF_TO_COMMON(stream)));
 }
 
 const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream)
index b21ec0f0abc0dc307255d25461cb5ae92cef412b..2ef0d8e56f51ef3457dbb75f61d5155a14537322 100644 (file)
 #include <babeltrace/ctf-writer/visitor-internal.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
 #include <babeltrace/endian-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <babeltrace/types.h>
-#include <babeltrace/values-internal.h>
-#include <babeltrace/values.h>
+#include <babeltrace/ctf-writer/values-internal.h>
 #include <inttypes.h>
 #include <stdint.h>
 #include <stdlib.h>
 
 BT_HIDDEN
 int bt_ctf_trace_common_initialize(struct bt_ctf_trace_common *trace,
-               bt_object_release_func release_func)
+               bt_ctf_object_release_func release_func)
 {
        int ret = 0;
 
        BT_LOGD_STR("Initializing common trace object.");
        trace->native_byte_order = BT_CTF_BYTE_ORDER_UNSPECIFIED;
-       bt_object_init_shared_with_parent(&trace->base, release_func);
+       bt_ctf_object_init_shared_with_parent(&trace->base, release_func);
        trace->clock_classes = g_ptr_array_new_with_free_func(
-               (GDestroyNotify) bt_object_put_ref);
+               (GDestroyNotify) bt_ctf_object_put_ref);
        if (!trace->clock_classes) {
                BT_LOGE_STR("Failed to allocate one GPtrArray.");
                goto error;
        }
 
        trace->streams = g_ptr_array_new_with_free_func(
-               (GDestroyNotify) bt_object_try_spec_release);
+               (GDestroyNotify) bt_ctf_object_try_spec_release);
        if (!trace->streams) {
                BT_LOGE_STR("Failed to allocate one GPtrArray.");
                goto error;
        }
 
        trace->stream_classes = g_ptr_array_new_with_free_func(
-               (GDestroyNotify) bt_object_try_spec_release);
+               (GDestroyNotify) bt_ctf_object_try_spec_release);
        if (!trace->stream_classes) {
                BT_LOGE_STR("Failed to allocate one GPtrArray.");
                goto error;
@@ -134,7 +133,7 @@ void bt_ctf_trace_common_finalize(struct bt_ctf_trace_common *trace)
        }
 
        BT_LOGD_STR("Putting packet header field type.");
-       bt_object_put_ref(trace->packet_header_field_type);
+       bt_ctf_object_put_ref(trace->packet_header_field_type);
 }
 
 BT_HIDDEN
@@ -230,7 +229,7 @@ end:
 
 BT_HIDDEN
 int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace,
-               const char *name, struct bt_private_value *value)
+               const char *name, struct bt_ctf_private_value *value)
 {
        int ret = 0;
 
@@ -261,15 +260,15 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace,
                goto end;
        }
 
-       if (!bt_value_is_integer(bt_private_value_as_value(value)) &&
-                       !bt_value_is_string(bt_private_value_as_value(value))) {
+       if (!bt_ctf_value_is_integer(bt_ctf_private_value_as_value(value)) &&
+                       !bt_ctf_value_is_string(bt_ctf_private_value_as_value(value))) {
                BT_LOGW("Invalid parameter: environment field's value is not an integer or string value: "
                        "trace-addr=%p, trace-name=\"%s\", "
                        "env-name=\"%s\", env-value-type=%s",
                        trace, bt_ctf_trace_common_get_name(trace), name,
                        bt_common_value_type_string(
-                               bt_value_get_type(
-                                       bt_private_value_as_value(value))));
+                               bt_ctf_value_get_type(
+                                       bt_ctf_private_value_as_value(value))));
                ret = -1;
                goto end;
        }
@@ -281,7 +280,7 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace,
                 *
                 * The object passed is frozen like all other attributes.
                 */
-               struct bt_private_value *attribute =
+               struct bt_ctf_private_value *attribute =
                        bt_ctf_attributes_borrow_field_value_by_name(
                                trace->environment, name);
 
@@ -294,7 +293,7 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace,
                        goto end;
                }
 
-               bt_value_freeze(bt_private_value_as_value(value));
+               bt_ctf_value_freeze(bt_ctf_private_value_as_value(value));
        }
 
        ret = bt_ctf_attributes_set_field_value(trace->environment, name,
@@ -320,7 +319,7 @@ int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common
                const char *name, const char *value)
 {
        int ret = 0;
-       struct bt_private_value *env_value_string_obj = NULL;
+       struct bt_ctf_private_value *env_value_string_obj = NULL;
 
        if (!value) {
                BT_LOGW_STR("Invalid parameter: value is NULL.");
@@ -328,7 +327,7 @@ int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common
                goto end;
        }
 
-       env_value_string_obj = bt_private_value_string_create_init(value);
+       env_value_string_obj = bt_ctf_private_value_string_create_init(value);
        if (!env_value_string_obj) {
                BT_LOGE_STR("Cannot create string value object.");
                ret = -1;
@@ -340,7 +339,7 @@ int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common
                env_value_string_obj);
 
 end:
-       bt_object_put_ref(env_value_string_obj);
+       bt_ctf_object_put_ref(env_value_string_obj);
        return ret;
 }
 
@@ -349,9 +348,9 @@ int bt_ctf_trace_common_set_environment_field_integer(
                struct bt_ctf_trace_common *trace, const char *name, int64_t value)
 {
        int ret = 0;
-       struct bt_private_value *env_value_integer_obj = NULL;
+       struct bt_ctf_private_value *env_value_integer_obj = NULL;
 
-       env_value_integer_obj = bt_private_value_integer_create_init(value);
+       env_value_integer_obj = bt_ctf_private_value_integer_create_init(value);
        if (!env_value_integer_obj) {
                BT_LOGE_STR("Cannot create integer value object.");
                ret = -1;
@@ -363,7 +362,7 @@ int bt_ctf_trace_common_set_environment_field_integer(
                env_value_integer_obj);
 
 end:
-       bt_object_put_ref(env_value_integer_obj);
+       bt_ctf_object_put_ref(env_value_integer_obj);
        return ret;
 }
 
@@ -400,7 +399,7 @@ int bt_ctf_trace_common_add_clock_class(struct bt_ctf_trace_common *trace,
                goto end;
        }
 
-       bt_object_get_ref(clock_class);
+       bt_ctf_object_get_ref(clock_class);
        g_ptr_array_add(trace->clock_classes, clock_class);
 
        if (trace->frozen) {
@@ -870,7 +869,7 @@ int check_packet_header_type_has_no_clock_class(struct bt_ctf_trace_common *trac
                ret = bt_ctf_field_type_common_validate_single_clock_class(
                        trace->packet_header_field_type,
                        &clock_class);
-               bt_object_put_ref(clock_class);
+               bt_ctf_object_put_ref(clock_class);
                if (ret || clock_class) {
                        BT_LOGW("Trace's packet header field type cannot "
                                "contain a field type which is mapped to "
@@ -915,7 +914,7 @@ int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace,
        int64_t event_class_count;
        struct bt_ctf_trace_common *current_parent_trace = NULL;
        struct bt_ctf_clock_class *expected_clock_class =
-               bt_object_get_ref(init_expected_clock_class);
+               bt_ctf_object_get_ref(init_expected_clock_class);
 
        BT_ASSERT(copy_field_type_func);
 
@@ -1191,7 +1190,7 @@ int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace,
                }
        }
 
-       bt_object_set_parent(&stream_class->base, &trace->base);
+       bt_ctf_object_set_parent(&stream_class->base, &trace->base);
        g_ptr_array_add(trace->stream_classes, stream_class);
 
        /*
@@ -1239,7 +1238,7 @@ int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace,
         * now because the stream class is frozen.
         */
        if (expected_clock_class) {
-               BT_OBJECT_MOVE_REF(stream_class->clock_class, expected_clock_class);
+               BT_CTF_OBJECT_MOVE_REF(stream_class->clock_class, expected_clock_class);
        }
 
        BT_LOGD("Added stream class to trace: "
@@ -1252,7 +1251,7 @@ int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace,
 
 end:
        if (ret) {
-               bt_object_set_parent(&stream_class->base, NULL);
+               bt_ctf_object_set_parent(&stream_class->base, NULL);
 
                if (ec_validation_outputs) {
                        for (i = 0; i < event_class_count; i++) {
@@ -1264,7 +1263,7 @@ end:
 
        g_free(ec_validation_outputs);
        bt_ctf_validation_output_put_types(&trace_sc_validation_output);
-       bt_object_put_ref(expected_clock_class);
+       bt_ctf_object_put_ref(expected_clock_class);
        return ret;
 }
 
@@ -1362,8 +1361,8 @@ int bt_ctf_trace_common_set_packet_header_field_type(struct bt_ctf_trace_common
                goto end;
        }
 
-       bt_object_put_ref(trace->packet_header_field_type);
-       trace->packet_header_field_type = bt_object_get_ref(packet_header_type);
+       bt_ctf_object_put_ref(trace->packet_header_field_type);
+       trace->packet_header_field_type = bt_ctf_object_get_ref(packet_header_type);
        BT_LOGV("Set trace's packet header field type: "
                "addr=%p, name=\"%s\", packet-context-ft-addr=%p",
                trace, bt_ctf_trace_common_get_name(trace), packet_header_type);
@@ -1421,7 +1420,7 @@ end:
 }
 
 static
-void bt_ctf_trace_destroy(struct bt_object *obj)
+void bt_ctf_trace_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_trace *trace = (void *) obj;
 
@@ -1455,7 +1454,7 @@ struct bt_ctf_trace *bt_ctf_trace_create(void)
        return trace;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(trace);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(trace);
        return trace;
 }
 
@@ -1497,17 +1496,17 @@ bt_ctf_trace_get_environment_field_name_by_index(struct bt_ctf_trace *trace,
                BT_CTF_TO_COMMON(trace), index);
 }
 
-struct bt_value *bt_ctf_trace_get_environment_field_value_by_index(
+struct bt_ctf_value *bt_ctf_trace_get_environment_field_value_by_index(
                struct bt_ctf_trace *trace, uint64_t index)
 {
-       return bt_object_get_ref(bt_ctf_trace_common_borrow_environment_field_value_by_index(
+       return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_environment_field_value_by_index(
                BT_CTF_TO_COMMON(trace), index));
 }
 
-struct bt_value *bt_ctf_trace_get_environment_field_value_by_name(
+struct bt_ctf_value *bt_ctf_trace_get_environment_field_value_by_name(
                struct bt_ctf_trace *trace, const char *name)
 {
-       return bt_object_get_ref(bt_ctf_trace_common_borrow_environment_field_value_by_name(
+       return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_environment_field_value_by_name(
                BT_CTF_TO_COMMON(trace), name));
 }
 
@@ -1529,7 +1528,7 @@ BT_HIDDEN
 struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_index(
                struct bt_ctf_trace *trace, uint64_t index)
 {
-       return bt_object_get_ref(bt_ctf_trace_common_borrow_clock_class_by_index(
+       return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_clock_class_by_index(
                BT_CTF_TO_COMMON(trace), index));
 }
 
@@ -1646,7 +1645,7 @@ int64_t bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace)
 struct bt_ctf_stream *bt_ctf_trace_get_stream_by_index(
                struct bt_ctf_trace *trace, uint64_t index)
 {
-       return bt_object_get_ref(bt_ctf_trace_common_borrow_stream_by_index(
+       return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_stream_by_index(
                BT_CTF_TO_COMMON(trace), index));
 }
 
@@ -1658,14 +1657,14 @@ int64_t bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace)
 struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_index(
                struct bt_ctf_trace *trace, uint64_t index)
 {
-       return bt_object_get_ref(bt_ctf_trace_common_borrow_stream_class_by_index(
+       return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_stream_class_by_index(
                BT_CTF_TO_COMMON(trace), index));
 }
 
 struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id(
                struct bt_ctf_trace *trace, uint64_t id)
 {
-       return bt_object_get_ref(bt_ctf_trace_common_borrow_stream_class_by_id(
+       return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_stream_class_by_id(
                BT_CTF_TO_COMMON(trace), id));
 }
 
@@ -1673,7 +1672,7 @@ BT_HIDDEN
 struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_name(
                struct bt_ctf_trace *trace, const char *name)
 {
-       return bt_object_get_ref(
+       return bt_ctf_object_get_ref(
                bt_ctf_trace_common_borrow_clock_class_by_name(BT_CTF_TO_COMMON(trace),
                        name));
 }
@@ -1748,7 +1747,7 @@ void append_env_metadata(struct bt_ctf_trace *trace,
        g_string_append(context->string, "env {\n");
 
        for (i = 0; i < env_size; i++) {
-               struct bt_private_value *env_field_value_obj = NULL;
+               struct bt_ctf_private_value *env_field_value_obj = NULL;
                const char *entry_name;
 
                entry_name = bt_ctf_attributes_get_field_name(
@@ -1759,27 +1758,27 @@ void append_env_metadata(struct bt_ctf_trace *trace,
                BT_ASSERT(entry_name);
                BT_ASSERT(env_field_value_obj);
 
-               switch (bt_value_get_type(
-                       bt_private_value_as_value(env_field_value_obj))) {
-               case BT_VALUE_TYPE_INTEGER:
+               switch (bt_ctf_value_get_type(
+                       bt_ctf_private_value_as_value(env_field_value_obj))) {
+               case BT_CTF_VALUE_TYPE_INTEGER:
                {
                        int64_t int_value;
 
-                       int_value = bt_value_integer_get(
-                               bt_private_value_as_value(
+                       int_value = bt_ctf_value_integer_get(
+                               bt_ctf_private_value_as_value(
                                        env_field_value_obj));
                        g_string_append_printf(context->string,
                                "\t%s = %" PRId64 ";\n", entry_name,
                                int_value);
                        break;
                }
-               case BT_VALUE_TYPE_STRING:
+               case BT_CTF_VALUE_TYPE_STRING:
                {
                        const char *str_value;
                        char *escaped_str = NULL;
 
-                       str_value = bt_value_string_get(
-                               bt_private_value_as_value(
+                       str_value = bt_ctf_value_string_get(
+                               bt_ctf_private_value_as_value(
                                        env_field_value_obj));
                        escaped_str = g_strescape(str_value, NULL);
                        if (!escaped_str) {
@@ -1867,7 +1866,7 @@ int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace,
 struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_field_type(
                struct bt_ctf_trace *trace)
 {
-       return bt_object_get_ref(bt_ctf_trace_common_borrow_packet_header_field_type(
+       return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_packet_header_field_type(
                BT_CTF_TO_COMMON(trace)));
 }
 
index 17cc4c0bee75d52b033c8f3ef3e0888410b223cc..369edb9e50b043ea71e85ac92a3f70cefebd3a76 100644 (file)
@@ -33,7 +33,7 @@
 #include <babeltrace/ctf-writer/clock-class-internal.h>
 #include <babeltrace/ctf-writer/field-types-internal.h>
 #include <babeltrace/ctf-writer/utils.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <glib.h>
 #include <stdlib.h>
 
index 03ad36ff6f8c021d6893a067c144ca8871e44485..217ff028d0ad546494bb51fd41eb99c6e3b45ac7 100644 (file)
@@ -36,8 +36,8 @@
 #include <babeltrace/ctf-writer/stream-class-internal.h>
 #include <babeltrace/ctf-writer/trace-internal.h>
 #include <babeltrace/ctf-writer/validation-internal.h>
-#include <babeltrace/object.h>
-#include <babeltrace/values.h>
+#include <babeltrace/ctf-writer/object.h>
+#include <babeltrace/ctf-writer/values-internal.h>
 
 /*
  * This function resolves and validates the field types of an event
@@ -48,7 +48,7 @@
  * All parameters are owned by the caller.
  */
 static
-int validate_event_class_types(struct bt_private_value *environment,
+int validate_event_class_types(struct bt_ctf_private_value *environment,
                struct bt_ctf_field_type_common *packet_header_type,
                struct bt_ctf_field_type_common *packet_context_type,
                struct bt_ctf_field_type_common *event_header_type,
@@ -112,7 +112,7 @@ end:
  * All parameters are owned by the caller.
  */
 static
-int validate_stream_class_types(struct bt_private_value *environment,
+int validate_stream_class_types(struct bt_ctf_private_value *environment,
                struct bt_ctf_field_type_common *packet_header_type,
                struct bt_ctf_field_type_common *packet_context_type,
                struct bt_ctf_field_type_common *event_header_type,
@@ -180,7 +180,7 @@ end:
  * All parameters are owned by the caller.
  */
 static
-int validate_trace_types(struct bt_private_value *environment,
+int validate_trace_types(struct bt_ctf_private_value *environment,
                struct bt_ctf_field_type_common *packet_header_type)
 {
        int ret = 0;
@@ -262,7 +262,7 @@ end:
 }
 
 BT_HIDDEN
-int bt_ctf_validate_class_types(struct bt_private_value *environment,
+int bt_ctf_validate_class_types(struct bt_ctf_private_value *environment,
                struct bt_ctf_field_type_common *packet_header_type,
                struct bt_ctf_field_type_common *packet_context_type,
                struct bt_ctf_field_type_common *event_header_type,
@@ -309,12 +309,12 @@ int bt_ctf_validate_class_types(struct bt_private_value *environment,
        }
 
        /* Own the type parameters */
-       bt_object_get_ref(packet_header_type);
-       bt_object_get_ref(packet_context_type);
-       bt_object_get_ref(event_header_type);
-       bt_object_get_ref(stream_event_ctx_type);
-       bt_object_get_ref(event_context_type);
-       bt_object_get_ref(event_payload_type);
+       bt_ctf_object_get_ref(packet_header_type);
+       bt_ctf_object_get_ref(packet_context_type);
+       bt_ctf_object_get_ref(event_header_type);
+       bt_ctf_object_get_ref(stream_event_ctx_type);
+       bt_ctf_object_get_ref(event_context_type);
+       bt_ctf_object_get_ref(event_payload_type);
 
        /* Validate trace */
        if ((validate_flags & BT_CTF_VALIDATION_FLAG_TRACE) && !trace_valid) {
@@ -331,7 +331,7 @@ int bt_ctf_validate_class_types(struct bt_private_value *environment,
                        } else if (!contains_seq_var) {
                                /* No copy is needed */
                                packet_header_type_copy = packet_header_type;
-                               bt_object_get_ref(packet_header_type_copy);
+                               bt_ctf_object_get_ref(packet_header_type_copy);
                                goto skip_packet_header_type_copy;
                        }
 
@@ -354,7 +354,7 @@ int bt_ctf_validate_class_types(struct bt_private_value *environment,
 
 skip_packet_header_type_copy:
                /* Put original reference and move copy */
-               BT_OBJECT_MOVE_REF(packet_header_type, packet_header_type_copy);
+               BT_CTF_OBJECT_MOVE_REF(packet_header_type, packet_header_type_copy);
 
                /* Validate trace field types */
                valid_ret = validate_trace_types(environment,
@@ -382,7 +382,7 @@ skip_packet_header_type_copy:
                        } else if (!contains_seq_var) {
                                /* No copy is needed */
                                packet_context_type_copy = packet_context_type;
-                               bt_object_get_ref(packet_context_type_copy);
+                               bt_ctf_object_get_ref(packet_context_type_copy);
                                goto skip_packet_context_type_copy;
                        }
 
@@ -413,7 +413,7 @@ skip_packet_context_type_copy:
                        } else if (!contains_seq_var) {
                                /* No copy is needed */
                                event_header_type_copy = event_header_type;
-                               bt_object_get_ref(event_header_type_copy);
+                               bt_ctf_object_get_ref(event_header_type_copy);
                                goto skip_event_header_type_copy;
                        }
 
@@ -445,7 +445,7 @@ skip_event_header_type_copy:
                                /* No copy is needed */
                                stream_event_ctx_type_copy =
                                        stream_event_ctx_type;
-                               bt_object_get_ref(stream_event_ctx_type_copy);
+                               bt_ctf_object_get_ref(stream_event_ctx_type_copy);
                                goto skip_stream_event_ctx_type_copy;
                        }
 
@@ -467,9 +467,9 @@ skip_event_header_type_copy:
 
 skip_stream_event_ctx_type_copy:
                /* Put original references and move copies */
-               BT_OBJECT_MOVE_REF(packet_context_type, packet_context_type_copy);
-               BT_OBJECT_MOVE_REF(event_header_type, event_header_type_copy);
-               BT_OBJECT_MOVE_REF(stream_event_ctx_type, stream_event_ctx_type_copy);
+               BT_CTF_OBJECT_MOVE_REF(packet_context_type, packet_context_type_copy);
+               BT_CTF_OBJECT_MOVE_REF(event_header_type, event_header_type_copy);
+               BT_CTF_OBJECT_MOVE_REF(stream_event_ctx_type, stream_event_ctx_type_copy);
 
                /* Validate stream class field types */
                valid_ret = validate_stream_class_types(environment,
@@ -483,9 +483,9 @@ skip_stream_event_ctx_type_copy:
                goto sc_validation_done;
 
 sc_validation_error:
-               BT_OBJECT_PUT_REF_AND_RESET(packet_context_type_copy);
-               BT_OBJECT_PUT_REF_AND_RESET(event_header_type_copy);
-               BT_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_type_copy);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_context_type_copy);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(event_header_type_copy);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_type_copy);
                ret = -1;
                goto error;
        }
@@ -507,7 +507,7 @@ sc_validation_done:
                        } else if (!contains_seq_var) {
                                /* No copy is needed */
                                event_context_type_copy = event_context_type;
-                               bt_object_get_ref(event_context_type_copy);
+                               bt_ctf_object_get_ref(event_context_type_copy);
                                goto skip_event_context_type_copy;
                        }
 
@@ -538,7 +538,7 @@ skip_event_context_type_copy:
                        } else if (!contains_seq_var) {
                                /* No copy is needed */
                                event_payload_type_copy = event_payload_type;
-                               bt_object_get_ref(event_payload_type_copy);
+                               bt_ctf_object_get_ref(event_payload_type_copy);
                                goto skip_event_payload_type_copy;
                        }
 
@@ -560,8 +560,8 @@ skip_event_context_type_copy:
 
 skip_event_payload_type_copy:
                /* Put original references and move copies */
-               BT_OBJECT_MOVE_REF(event_context_type, event_context_type_copy);
-               BT_OBJECT_MOVE_REF(event_payload_type, event_payload_type_copy);
+               BT_CTF_OBJECT_MOVE_REF(event_context_type, event_context_type_copy);
+               BT_CTF_OBJECT_MOVE_REF(event_payload_type, event_payload_type_copy);
 
                /* Validate event class field types */
                valid_ret = validate_event_class_types(environment,
@@ -576,8 +576,8 @@ skip_event_payload_type_copy:
                goto ec_validation_done;
 
 ec_validation_error:
-               BT_OBJECT_PUT_REF_AND_RESET(event_context_type_copy);
-               BT_OBJECT_PUT_REF_AND_RESET(event_payload_type_copy);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(event_context_type_copy);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(event_payload_type_copy);
                ret = -1;
                goto error;
        }
@@ -588,21 +588,21 @@ ec_validation_done:
         * to validate (and that were possibly altered by the validation
         * process) to the output values.
         */
-       BT_OBJECT_MOVE_REF(output->packet_header_type, packet_header_type);
-       BT_OBJECT_MOVE_REF(output->packet_context_type, packet_context_type);
-       BT_OBJECT_MOVE_REF(output->event_header_type, event_header_type);
-       BT_OBJECT_MOVE_REF(output->stream_event_ctx_type, stream_event_ctx_type);
-       BT_OBJECT_MOVE_REF(output->event_context_type, event_context_type);
-       BT_OBJECT_MOVE_REF(output->event_payload_type, event_payload_type);
+       BT_CTF_OBJECT_MOVE_REF(output->packet_header_type, packet_header_type);
+       BT_CTF_OBJECT_MOVE_REF(output->packet_context_type, packet_context_type);
+       BT_CTF_OBJECT_MOVE_REF(output->event_header_type, event_header_type);
+       BT_CTF_OBJECT_MOVE_REF(output->stream_event_ctx_type, stream_event_ctx_type);
+       BT_CTF_OBJECT_MOVE_REF(output->event_context_type, event_context_type);
+       BT_CTF_OBJECT_MOVE_REF(output->event_payload_type, event_payload_type);
        return ret;
 
 error:
-       BT_OBJECT_PUT_REF_AND_RESET(packet_header_type);
-       BT_OBJECT_PUT_REF_AND_RESET(packet_context_type);
-       BT_OBJECT_PUT_REF_AND_RESET(event_header_type);
-       BT_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_type);
-       BT_OBJECT_PUT_REF_AND_RESET(event_context_type);
-       BT_OBJECT_PUT_REF_AND_RESET(event_payload_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_header_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_context_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(event_header_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(event_context_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(event_payload_type);
        return ret;
 }
 
@@ -615,7 +615,7 @@ void bt_ctf_validation_replace_types(struct bt_ctf_trace_common *trace,
 {
        if ((replace_flags & BT_CTF_VALIDATION_FLAG_TRACE) && trace) {
                bt_ctf_field_type_common_freeze(trace->packet_header_field_type);
-               BT_OBJECT_MOVE_REF(trace->packet_header_field_type,
+               BT_CTF_OBJECT_MOVE_REF(trace->packet_header_field_type,
                        output->packet_header_type);
        }
 
@@ -623,19 +623,19 @@ void bt_ctf_validation_replace_types(struct bt_ctf_trace_common *trace,
                bt_ctf_field_type_common_freeze(stream_class->packet_context_field_type);
                bt_ctf_field_type_common_freeze(stream_class->event_header_field_type);
                bt_ctf_field_type_common_freeze(stream_class->event_context_field_type);
-               BT_OBJECT_MOVE_REF(stream_class->packet_context_field_type,
+               BT_CTF_OBJECT_MOVE_REF(stream_class->packet_context_field_type,
                        output->packet_context_type);
-               BT_OBJECT_MOVE_REF(stream_class->event_header_field_type,
+               BT_CTF_OBJECT_MOVE_REF(stream_class->event_header_field_type,
                        output->event_header_type);
-               BT_OBJECT_MOVE_REF(stream_class->event_context_field_type,
+               BT_CTF_OBJECT_MOVE_REF(stream_class->event_context_field_type,
                        output->stream_event_ctx_type);
        }
 
        if ((replace_flags & BT_CTF_VALIDATION_FLAG_EVENT) && event_class) {
                bt_ctf_field_type_common_freeze(event_class->context_field_type);
                bt_ctf_field_type_common_freeze(event_class->payload_field_type);
-               BT_OBJECT_MOVE_REF(event_class->context_field_type, output->event_context_type);
-               BT_OBJECT_MOVE_REF(event_class->payload_field_type, output->event_payload_type);
+               BT_CTF_OBJECT_MOVE_REF(event_class->context_field_type, output->event_context_type);
+               BT_CTF_OBJECT_MOVE_REF(event_class->payload_field_type, output->event_payload_type);
        }
 }
 
@@ -643,10 +643,10 @@ BT_HIDDEN
 void bt_ctf_validation_output_put_types(
                struct bt_ctf_validation_output *output)
 {
-       BT_OBJECT_PUT_REF_AND_RESET(output->packet_header_type);
-       BT_OBJECT_PUT_REF_AND_RESET(output->packet_context_type);
-       BT_OBJECT_PUT_REF_AND_RESET(output->event_header_type);
-       BT_OBJECT_PUT_REF_AND_RESET(output->stream_event_ctx_type);
-       BT_OBJECT_PUT_REF_AND_RESET(output->event_context_type);
-       BT_OBJECT_PUT_REF_AND_RESET(output->event_payload_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(output->packet_header_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(output->packet_context_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(output->event_header_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(output->stream_event_ctx_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(output->event_context_type);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(output->event_payload_type);
 }
diff --git a/lib/ctf-writer/values.c b/lib/ctf-writer/values.c
new file mode 100644 (file)
index 0000000..e67d8b5
--- /dev/null
@@ -0,0 +1,1347 @@
+/*
+ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define BT_LOG_TAG "CTF-WRITER-VALUES"
+#include <babeltrace/lib-logging-internal.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <string.h>
+#include <inttypes.h>
+#include <babeltrace/compiler-internal.h>
+#include <babeltrace/common-internal.h>
+#include <babeltrace/ctf-writer/object.h>
+#include <babeltrace/ctf-writer/values-internal.h>
+#include <babeltrace/compat/glib-internal.h>
+#include <babeltrace/types.h>
+#include <babeltrace/ctf-writer/object-internal.h>
+#include <babeltrace/ctf-writer/values-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
+
+#define BT_CTF_VALUE_FROM_CONCRETE(_concrete) ((struct bt_ctf_value *) (_concrete))
+#define BT_CTF_VALUE_TO_BOOL(_base) ((struct bt_ctf_value_bool *) (_base))
+#define BT_CTF_VALUE_TO_INTEGER(_base) ((struct bt_ctf_value_integer *) (_base))
+#define BT_CTF_VALUE_TO_REAL(_base) ((struct bt_ctf_value_real *) (_base))
+#define BT_CTF_VALUE_TO_STRING(_base) ((struct bt_ctf_value_string *) (_base))
+#define BT_CTF_VALUE_TO_ARRAY(_base) ((struct bt_ctf_value_array *) (_base))
+#define BT_CTF_VALUE_TO_MAP(_base) ((struct bt_ctf_value_map *) (_base))
+
+#define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type)                     \
+       BT_ASSERT_PRE(((struct bt_ctf_value *) (_value))->type == (_type),      \
+               "Value has the wrong type ID: expected-type=%d, "       \
+               "%![value-]+v", (_type),        \
+               (_value))
+
+#define BT_ASSERT_PRE_VALUE_HOT(_value, _name)                         \
+       BT_ASSERT_PRE_HOT(((struct bt_ctf_value *) (_value)), (_name),  \
+               ": %!+v", (_value))
+
+#define BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count)            \
+       BT_ASSERT_PRE((_index) < (_count),                              \
+               "Index is out of bound: "                               \
+               "index=%" PRIu64 ", count=%u", (_index), (_count));
+
+struct bt_ctf_value {
+       struct bt_ctf_object base;
+       enum bt_ctf_value_type type;
+       bt_bool frozen;
+};
+
+static
+void bt_ctf_value_null_instance_release_func(struct bt_ctf_object *obj)
+{
+       BT_LOGW("Releasing the null value singleton: addr=%p", obj);
+}
+
+static
+struct bt_ctf_value bt_ctf_value_null_instance = {
+       .base = {
+               .is_shared = true,
+               .ref_count = 1,
+               .release_func = bt_ctf_value_null_instance_release_func,
+               .spec_release_func = NULL,
+               .parent_is_owner_listener_func = NULL,
+               .parent = NULL,
+       },
+       .type = BT_CTF_VALUE_TYPE_NULL,
+       .frozen = BT_TRUE,
+};
+
+struct bt_ctf_value *bt_ctf_value_null = &bt_ctf_value_null_instance;
+struct bt_ctf_private_value *bt_ctf_private_value_null =
+       (void *) &bt_ctf_value_null_instance;
+
+struct bt_ctf_value_bool {
+       struct bt_ctf_value base;
+       bt_bool value;
+};
+
+struct bt_ctf_value_integer {
+       struct bt_ctf_value base;
+       int64_t value;
+};
+
+struct bt_ctf_value_real {
+       struct bt_ctf_value base;
+       double value;
+};
+
+struct bt_ctf_value_string {
+       struct bt_ctf_value base;
+       GString *gstr;
+};
+
+struct bt_ctf_value_array {
+       struct bt_ctf_value base;
+       GPtrArray *garray;
+};
+
+struct bt_ctf_value_map {
+       struct bt_ctf_value base;
+       GHashTable *ght;
+};
+
+static
+void bt_ctf_value_destroy(struct bt_ctf_object *obj);
+
+static
+void bt_ctf_value_string_destroy(struct bt_ctf_value *object)
+{
+       g_string_free(BT_CTF_VALUE_TO_STRING(object)->gstr, TRUE);
+       BT_CTF_VALUE_TO_STRING(object)->gstr = NULL;
+}
+
+static
+void bt_ctf_value_array_destroy(struct bt_ctf_value *object)
+{
+       /*
+        * Pointer array's registered value destructor will take care
+        * of putting each contained object.
+        */
+       g_ptr_array_free(BT_CTF_VALUE_TO_ARRAY(object)->garray, TRUE);
+       BT_CTF_VALUE_TO_ARRAY(object)->garray = NULL;
+}
+
+static
+void bt_ctf_value_map_destroy(struct bt_ctf_value *object)
+{
+       /*
+        * Hash table's registered value destructor will take care of
+        * putting each contained object. Keys are GQuarks and cannot
+        * be destroyed anyway.
+        */
+       g_hash_table_destroy(BT_CTF_VALUE_TO_MAP(object)->ght);
+       BT_CTF_VALUE_TO_MAP(object)->ght = NULL;
+}
+
+static
+void (* const destroy_funcs[])(struct bt_ctf_value *) = {
+       [BT_CTF_VALUE_TYPE_NULL] =              NULL,
+       [BT_CTF_VALUE_TYPE_BOOL] =              NULL,
+       [BT_CTF_VALUE_TYPE_INTEGER] =   NULL,
+       [BT_CTF_VALUE_TYPE_REAL] =              NULL,
+       [BT_CTF_VALUE_TYPE_STRING] =    bt_ctf_value_string_destroy,
+       [BT_CTF_VALUE_TYPE_ARRAY] =             bt_ctf_value_array_destroy,
+       [BT_CTF_VALUE_TYPE_MAP] =               bt_ctf_value_map_destroy,
+};
+
+static
+struct bt_ctf_private_value *bt_ctf_value_null_copy(const struct bt_ctf_value *null_obj)
+{
+       return (void *) bt_ctf_value_null;
+}
+
+static
+struct bt_ctf_private_value *bt_ctf_value_bool_copy(const struct bt_ctf_value *bool_obj)
+{
+       return bt_ctf_private_value_bool_create_init(
+               BT_CTF_VALUE_TO_BOOL(bool_obj)->value);
+}
+
+static
+struct bt_ctf_private_value *bt_ctf_value_integer_copy(
+               const struct bt_ctf_value *integer_obj)
+{
+       return bt_ctf_private_value_integer_create_init(
+               BT_CTF_VALUE_TO_INTEGER(integer_obj)->value);
+}
+
+static
+struct bt_ctf_private_value *bt_ctf_value_real_copy(const struct bt_ctf_value *real_obj)
+{
+       return bt_ctf_private_value_real_create_init(
+               BT_CTF_VALUE_TO_REAL(real_obj)->value);
+}
+
+static
+struct bt_ctf_private_value *bt_ctf_value_string_copy(const struct bt_ctf_value *string_obj)
+{
+       return bt_ctf_private_value_string_create_init(
+               BT_CTF_VALUE_TO_STRING(string_obj)->gstr->str);
+}
+
+static
+struct bt_ctf_private_value *bt_ctf_value_array_copy(const struct bt_ctf_value *array_obj)
+{
+       int i;
+       int ret;
+       struct bt_ctf_private_value *copy_obj;
+       struct bt_ctf_value_array *typed_array_obj;
+
+       BT_LOGD("Copying array value: addr=%p", array_obj);
+       typed_array_obj = BT_CTF_VALUE_TO_ARRAY(array_obj);
+       copy_obj = bt_ctf_private_value_array_create();
+       if (!copy_obj) {
+               BT_LOGE_STR("Cannot create empty array value.");
+               goto end;
+       }
+
+       for (i = 0; i < typed_array_obj->garray->len; ++i) {
+               struct bt_ctf_private_value *element_obj_copy = NULL;
+               struct bt_ctf_value *element_obj =
+                       bt_ctf_value_array_borrow_element_by_index(
+                               array_obj, i);
+
+               BT_ASSERT(element_obj);
+               BT_LOGD("Copying array value's element: element-addr=%p, "
+                       "index=%d", element_obj, i);
+               ret = bt_ctf_value_copy(&element_obj_copy, element_obj);
+               if (ret) {
+                       BT_LOGE("Cannot copy array value's element: "
+                               "array-addr=%p, index=%d",
+                               array_obj, i);
+                       BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj);
+                       goto end;
+               }
+
+               BT_ASSERT(element_obj_copy);
+               ret = bt_ctf_private_value_array_append_element(copy_obj,
+                       (void *) element_obj_copy);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy);
+               if (ret) {
+                       BT_LOGE("Cannot append to array value: addr=%p",
+                               array_obj);
+                       BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj);
+                       goto end;
+               }
+       }
+
+       BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
+               array_obj, copy_obj);
+
+end:
+       return copy_obj;
+}
+
+static
+struct bt_ctf_private_value *bt_ctf_value_map_copy(const struct bt_ctf_value *map_obj)
+{
+       int ret;
+       GHashTableIter iter;
+       gpointer key, element_obj;
+       struct bt_ctf_private_value *copy_obj;
+       struct bt_ctf_private_value *element_obj_copy = NULL;
+       struct bt_ctf_value_map *typed_map_obj;
+
+       BT_LOGD("Copying map value: addr=%p", map_obj);
+       typed_map_obj = BT_CTF_VALUE_TO_MAP(map_obj);
+       copy_obj = bt_ctf_private_value_map_create();
+       if (!copy_obj) {
+               goto end;
+       }
+
+       g_hash_table_iter_init(&iter, typed_map_obj->ght);
+
+       while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
+               const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
+
+               BT_ASSERT(key_str);
+               BT_LOGD("Copying map value's element: element-addr=%p, "
+                       "key=\"%s\"", element_obj, key_str);
+               ret = bt_ctf_value_copy(&element_obj_copy, element_obj);
+               if (ret) {
+                       BT_LOGE("Cannot copy map value's element: "
+                               "map-addr=%p, key=\"%s\"",
+                               map_obj, key_str);
+                       BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj);
+                       goto end;
+               }
+
+               BT_ASSERT(element_obj_copy);
+               ret = bt_ctf_private_value_map_insert_entry(copy_obj, key_str,
+                       (void *) element_obj_copy);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(element_obj_copy);
+               if (ret) {
+                       BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"",
+                               map_obj, key_str);
+                       BT_CTF_OBJECT_PUT_REF_AND_RESET(copy_obj);
+                       goto end;
+               }
+       }
+
+       BT_LOGD("Copied map value: addr=%p", map_obj);
+
+end:
+       return copy_obj;
+}
+
+static
+struct bt_ctf_private_value *(* const copy_funcs[])(const struct bt_ctf_value *) = {
+       [BT_CTF_VALUE_TYPE_NULL] =              bt_ctf_value_null_copy,
+       [BT_CTF_VALUE_TYPE_BOOL] =              bt_ctf_value_bool_copy,
+       [BT_CTF_VALUE_TYPE_INTEGER] =   bt_ctf_value_integer_copy,
+       [BT_CTF_VALUE_TYPE_REAL] =              bt_ctf_value_real_copy,
+       [BT_CTF_VALUE_TYPE_STRING] =    bt_ctf_value_string_copy,
+       [BT_CTF_VALUE_TYPE_ARRAY] =             bt_ctf_value_array_copy,
+       [BT_CTF_VALUE_TYPE_MAP] =               bt_ctf_value_map_copy,
+};
+
+static
+bt_bool bt_ctf_value_null_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b)
+{
+       /*
+        * Always BT_TRUE since bt_ctf_value_compare() already checks if both
+        * object_a and object_b have the same type, and in the case of
+        * null value objects, they're always the same if it is so.
+        */
+       return BT_TRUE;
+}
+
+static
+bt_bool bt_ctf_value_bool_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b)
+{
+       if (BT_CTF_VALUE_TO_BOOL(object_a)->value !=
+                       BT_CTF_VALUE_TO_BOOL(object_b)->value) {
+               BT_LOGV("Boolean value objects are different: "
+                       "bool-a-val=%d, bool-b-val=%d",
+                       BT_CTF_VALUE_TO_BOOL(object_a)->value,
+                       BT_CTF_VALUE_TO_BOOL(object_b)->value);
+               return BT_FALSE;
+       }
+
+       return BT_TRUE;
+}
+
+static
+bt_bool bt_ctf_value_integer_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b)
+{
+       if (BT_CTF_VALUE_TO_INTEGER(object_a)->value !=
+                       BT_CTF_VALUE_TO_INTEGER(object_b)->value) {
+               BT_LOGV("Integer value objects are different: "
+                       "int-a-val=%" PRId64 ", int-b-val=%" PRId64,
+                       BT_CTF_VALUE_TO_INTEGER(object_a)->value,
+                       BT_CTF_VALUE_TO_INTEGER(object_b)->value);
+               return BT_FALSE;
+       }
+
+       return BT_TRUE;
+}
+
+static
+bt_bool bt_ctf_value_real_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b)
+{
+       if (BT_CTF_VALUE_TO_REAL(object_a)->value !=
+                       BT_CTF_VALUE_TO_REAL(object_b)->value) {
+               BT_LOGV("Real number value objects are different: "
+                       "real-a-val=%f, real-b-val=%f",
+                       BT_CTF_VALUE_TO_REAL(object_a)->value,
+                       BT_CTF_VALUE_TO_REAL(object_b)->value);
+               return BT_FALSE;
+       }
+
+       return BT_TRUE;
+}
+
+static
+bt_bool bt_ctf_value_string_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b)
+{
+       if (strcmp(BT_CTF_VALUE_TO_STRING(object_a)->gstr->str,
+                       BT_CTF_VALUE_TO_STRING(object_b)->gstr->str) != 0) {
+               BT_LOGV("String value objects are different: "
+                       "string-a-val=\"%s\", string-b-val=\"%s\"",
+                       BT_CTF_VALUE_TO_STRING(object_a)->gstr->str,
+                       BT_CTF_VALUE_TO_STRING(object_b)->gstr->str);
+               return BT_FALSE;
+       }
+
+       return BT_TRUE;
+}
+
+static
+bt_bool bt_ctf_value_array_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b)
+{
+       int i;
+       bt_bool ret = BT_TRUE;
+       const struct bt_ctf_value_array *array_obj_a =
+               BT_CTF_VALUE_TO_ARRAY(object_a);
+
+       if (bt_ctf_value_array_get_size(object_a) !=
+                       bt_ctf_value_array_get_size(object_b)) {
+               BT_LOGV("Array values are different: size mismatch "
+                       "value-a-addr=%p, value-b-addr=%p, "
+                       "value-a-size=%" PRId64 ", value-b-size=%" PRId64,
+                       object_a, object_b,
+                       bt_ctf_value_array_get_size(object_a),
+                       bt_ctf_value_array_get_size(object_b));
+               ret = BT_FALSE;
+               goto end;
+       }
+
+       for (i = 0; i < array_obj_a->garray->len; ++i) {
+               struct bt_ctf_value *element_obj_a;
+               struct bt_ctf_value *element_obj_b;
+
+               element_obj_a = bt_ctf_value_array_borrow_element_by_index(
+                       object_a, i);
+               element_obj_b = bt_ctf_value_array_borrow_element_by_index(
+                       object_b, i);
+
+               if (!bt_ctf_value_compare(element_obj_a, element_obj_b)) {
+                       BT_LOGV("Array values's elements are different: "
+                               "value-a-addr=%p, value-b-addr=%p, index=%d",
+                               element_obj_a, element_obj_b, i);
+                       ret = BT_FALSE;
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
+static
+bt_bool bt_ctf_value_map_compare(const struct bt_ctf_value *object_a,
+               const struct bt_ctf_value *object_b)
+{
+       bt_bool ret = BT_TRUE;
+       GHashTableIter iter;
+       gpointer key, element_obj_a;
+       const struct bt_ctf_value_map *map_obj_a = BT_CTF_VALUE_TO_MAP(object_a);
+
+       if (bt_ctf_value_map_get_size(object_a) !=
+                       bt_ctf_value_map_get_size(object_b)) {
+               BT_LOGV("Map values are different: size mismatch "
+                       "value-a-addr=%p, value-b-addr=%p, "
+                       "value-a-size=%" PRId64 ", value-b-size=%" PRId64,
+                       object_a, object_b,
+                       bt_ctf_value_map_get_size(object_a),
+                       bt_ctf_value_map_get_size(object_b));
+               ret = BT_FALSE;
+               goto end;
+       }
+
+       g_hash_table_iter_init(&iter, map_obj_a->ght);
+
+       while (g_hash_table_iter_next(&iter, &key, &element_obj_a)) {
+               struct bt_ctf_value *element_obj_b;
+               const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
+
+               element_obj_b = bt_ctf_value_map_borrow_entry_value(object_b,
+                       key_str);
+
+               if (!bt_ctf_value_compare(element_obj_a, element_obj_b)) {
+                       BT_LOGV("Map values's elements are different: "
+                               "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
+                               element_obj_a, element_obj_b, key_str);
+                       ret = BT_FALSE;
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
+static
+bt_bool (* const compare_funcs[])(const struct bt_ctf_value *,
+               const struct bt_ctf_value *) = {
+       [BT_CTF_VALUE_TYPE_NULL] =              bt_ctf_value_null_compare,
+       [BT_CTF_VALUE_TYPE_BOOL] =              bt_ctf_value_bool_compare,
+       [BT_CTF_VALUE_TYPE_INTEGER] =   bt_ctf_value_integer_compare,
+       [BT_CTF_VALUE_TYPE_REAL] =              bt_ctf_value_real_compare,
+       [BT_CTF_VALUE_TYPE_STRING] =    bt_ctf_value_string_compare,
+       [BT_CTF_VALUE_TYPE_ARRAY] =             bt_ctf_value_array_compare,
+       [BT_CTF_VALUE_TYPE_MAP] =               bt_ctf_value_map_compare,
+};
+
+static
+void bt_ctf_value_null_freeze(struct bt_ctf_value *object)
+{
+}
+
+static
+void bt_ctf_value_generic_freeze(struct bt_ctf_value *object)
+{
+       object->frozen = BT_TRUE;
+}
+
+static
+void bt_ctf_value_array_freeze(struct bt_ctf_value *object)
+{
+       int i;
+       struct bt_ctf_value_array *typed_array_obj =
+               BT_CTF_VALUE_TO_ARRAY(object);
+
+       for (i = 0; i < typed_array_obj->garray->len; ++i) {
+               bt_ctf_value_freeze(g_ptr_array_index(typed_array_obj->garray, i));
+       }
+
+       bt_ctf_value_generic_freeze(object);
+}
+
+static
+void bt_ctf_value_map_freeze(struct bt_ctf_value *object)
+{
+       GHashTableIter iter;
+       gpointer key, element_obj;
+       const struct bt_ctf_value_map *map_obj = BT_CTF_VALUE_TO_MAP(object);
+
+       g_hash_table_iter_init(&iter, map_obj->ght);
+
+       while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
+               bt_ctf_value_freeze(element_obj);
+       }
+
+       bt_ctf_value_generic_freeze(object);
+}
+
+static
+void (* const freeze_funcs[])(struct bt_ctf_value *) = {
+       [BT_CTF_VALUE_TYPE_NULL] =              bt_ctf_value_null_freeze,
+       [BT_CTF_VALUE_TYPE_BOOL] =              bt_ctf_value_generic_freeze,
+       [BT_CTF_VALUE_TYPE_INTEGER] =   bt_ctf_value_generic_freeze,
+       [BT_CTF_VALUE_TYPE_REAL] =              bt_ctf_value_generic_freeze,
+       [BT_CTF_VALUE_TYPE_STRING] =    bt_ctf_value_generic_freeze,
+       [BT_CTF_VALUE_TYPE_ARRAY] =             bt_ctf_value_array_freeze,
+       [BT_CTF_VALUE_TYPE_MAP] =               bt_ctf_value_map_freeze,
+};
+
+static
+void bt_ctf_value_destroy(struct bt_ctf_object *obj)
+{
+       struct bt_ctf_value *value;
+
+       value = container_of(obj, struct bt_ctf_value, base);
+       BT_LOGD("Destroying value: addr=%p", value);
+
+       if (bt_ctf_value_is_null(value)) {
+               BT_LOGD_STR("Not destroying the null value singleton.");
+               return;
+       }
+
+       if (destroy_funcs[value->type]) {
+               destroy_funcs[value->type](value);
+       }
+
+       g_free(value);
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status _bt_ctf_value_freeze(struct bt_ctf_value *object)
+{
+       enum bt_ctf_value_status ret = BT_CTF_VALUE_STATUS_OK;
+
+       BT_ASSERT(object);
+
+       if (object->frozen) {
+               goto end;
+       }
+
+       BT_LOGD("Freezing value: addr=%p", object);
+       freeze_funcs[object->type](object);
+
+end:
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_type bt_ctf_value_get_type(const struct bt_ctf_value *object)
+{
+       BT_ASSERT_PRE_NON_NULL(object, "Value object");
+       return object->type;
+}
+
+static
+struct bt_ctf_value bt_ctf_value_create_base(enum bt_ctf_value_type type)
+{
+       struct bt_ctf_value value;
+
+       value.type = type;
+       value.frozen = BT_FALSE;
+       bt_ctf_object_init_shared(&value.base, bt_ctf_value_destroy);
+       return value;
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_bool_create_init(bt_bool val)
+{
+       struct bt_ctf_value_bool *bool_obj;
+
+       BT_LOGD("Creating boolean value object: val=%d", val);
+       bool_obj = g_new0(struct bt_ctf_value_bool, 1);
+       if (!bool_obj) {
+               BT_LOGE_STR("Failed to allocate one boolean value object.");
+               goto end;
+       }
+
+       bool_obj->base = bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_BOOL);
+       bool_obj->value = val;
+       BT_LOGD("Created boolean value object: addr=%p", bool_obj);
+
+end:
+       return (void *) BT_CTF_VALUE_FROM_CONCRETE(bool_obj);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_bool_create(void)
+{
+       return bt_ctf_private_value_bool_create_init(BT_FALSE);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_integer_create_init(int64_t val)
+{
+       struct bt_ctf_value_integer *integer_obj;
+
+       BT_LOGD("Creating integer value object: val=%" PRId64, val);
+       integer_obj = g_new0(struct bt_ctf_value_integer, 1);
+       if (!integer_obj) {
+               BT_LOGE_STR("Failed to allocate one integer value object.");
+               goto end;
+       }
+
+       integer_obj->base = bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_INTEGER);
+       integer_obj->value = val;
+       BT_LOGD("Created integer value object: addr=%p",
+               integer_obj);
+
+end:
+       return (void *) BT_CTF_VALUE_FROM_CONCRETE(integer_obj);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_integer_create(void)
+{
+       return bt_ctf_private_value_integer_create_init(0);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_real_create_init(double val)
+{
+       struct bt_ctf_value_real *real_obj;
+
+       BT_LOGD("Creating real number value object: val=%f", val);
+       real_obj = g_new0(struct bt_ctf_value_real, 1);
+       if (!real_obj) {
+               BT_LOGE_STR("Failed to allocate one real number value object.");
+               goto end;
+       }
+
+       real_obj->base = bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_REAL);
+       real_obj->value = val;
+       BT_LOGD("Created real number value object: addr=%p",
+               real_obj);
+
+end:
+       return (void *) BT_CTF_VALUE_FROM_CONCRETE(real_obj);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_real_create(void)
+{
+       return bt_ctf_private_value_real_create_init(0.);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_string_create_init(const char *val)
+{
+       struct bt_ctf_value_string *string_obj = NULL;
+
+       if (!val) {
+               BT_LOGW_STR("Invalid parameter: value is NULL.");
+               goto end;
+       }
+
+       BT_LOGD("Creating string value object: val-len=%zu", strlen(val));
+       string_obj = g_new0(struct bt_ctf_value_string, 1);
+       if (!string_obj) {
+               BT_LOGE_STR("Failed to allocate one string object.");
+               goto end;
+       }
+
+       string_obj->base = bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_STRING);
+       string_obj->gstr = g_string_new(val);
+       if (!string_obj->gstr) {
+               BT_LOGE_STR("Failed to allocate a GString.");
+               g_free(string_obj);
+               string_obj = NULL;
+               goto end;
+       }
+
+       BT_LOGD("Created string value object: addr=%p",
+               string_obj);
+
+end:
+       return (void *) BT_CTF_VALUE_FROM_CONCRETE(string_obj);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_string_create(void)
+{
+       return bt_ctf_private_value_string_create_init("");
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_array_create(void)
+{
+       struct bt_ctf_value_array *array_obj;
+
+       BT_LOGD_STR("Creating empty array value object.");
+       array_obj = g_new0(struct bt_ctf_value_array, 1);
+       if (!array_obj) {
+               BT_LOGE_STR("Failed to allocate one array object.");
+               goto end;
+       }
+
+       array_obj->base = bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_ARRAY);
+       array_obj->garray = bt_g_ptr_array_new_full(0,
+               (GDestroyNotify) bt_ctf_object_put_ref);
+       if (!array_obj->garray) {
+               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               g_free(array_obj);
+               array_obj = NULL;
+               goto end;
+       }
+
+       BT_LOGD("Created array value object: addr=%p",
+               array_obj);
+
+end:
+       return (void *) BT_CTF_VALUE_FROM_CONCRETE(array_obj);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_map_create(void)
+{
+       struct bt_ctf_value_map *map_obj;
+
+       BT_LOGD_STR("Creating empty map value object.");
+       map_obj = g_new0(struct bt_ctf_value_map, 1);
+       if (!map_obj) {
+               BT_LOGE_STR("Failed to allocate one map object.");
+               goto end;
+       }
+
+       map_obj->base = bt_ctf_value_create_base(BT_CTF_VALUE_TYPE_MAP);
+       map_obj->ght = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+               NULL, (GDestroyNotify) bt_ctf_object_put_ref);
+       if (!map_obj->ght) {
+               BT_LOGE_STR("Failed to allocate a GHashTable.");
+               g_free(map_obj);
+               map_obj = NULL;
+               goto end;
+       }
+
+       BT_LOGD("Created map value object: addr=%p",
+               map_obj);
+
+end:
+       return (void *) BT_CTF_VALUE_FROM_CONCRETE(map_obj);
+}
+
+BT_HIDDEN
+bt_bool bt_ctf_value_bool_get(const struct bt_ctf_value *bool_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(bool_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj, BT_CTF_VALUE_TYPE_BOOL);
+       return BT_CTF_VALUE_TO_BOOL(bool_obj)->value;
+}
+
+BT_HIDDEN
+void bt_ctf_private_value_bool_set(struct bt_ctf_private_value *bool_obj, bt_bool val)
+{
+       BT_ASSERT_PRE_NON_NULL(bool_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj, BT_CTF_VALUE_TYPE_BOOL);
+       BT_ASSERT_PRE_VALUE_HOT(bool_obj, "Value object");
+       BT_CTF_VALUE_TO_BOOL(bool_obj)->value = val;
+       BT_LOGV("Set boolean value's raw value: value-addr=%p, value=%d",
+               bool_obj, val);
+}
+
+BT_HIDDEN
+int64_t bt_ctf_value_integer_get(const struct bt_ctf_value *integer_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_CTF_VALUE_TYPE_INTEGER);
+       return BT_CTF_VALUE_TO_INTEGER(integer_obj)->value;
+}
+
+BT_HIDDEN
+void bt_ctf_private_value_integer_set(struct bt_ctf_private_value *integer_obj,
+               int64_t val)
+{
+       BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_CTF_VALUE_TYPE_INTEGER);
+       BT_ASSERT_PRE_VALUE_HOT(integer_obj, "Value object");
+       BT_CTF_VALUE_TO_INTEGER(integer_obj)->value = val;
+       BT_LOGV("Set integer value's raw value: value-addr=%p, value=%" PRId64,
+               integer_obj, val);
+}
+
+BT_HIDDEN
+double bt_ctf_value_real_get(const struct bt_ctf_value *real_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(real_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj, BT_CTF_VALUE_TYPE_REAL);
+       return BT_CTF_VALUE_TO_REAL(real_obj)->value;
+}
+
+BT_HIDDEN
+void bt_ctf_private_value_real_set(struct bt_ctf_private_value *real_obj, double val)
+{
+       BT_ASSERT_PRE_NON_NULL(real_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj, BT_CTF_VALUE_TYPE_REAL);
+       BT_ASSERT_PRE_VALUE_HOT(real_obj, "Value object");
+       BT_CTF_VALUE_TO_REAL(real_obj)->value = val;
+       BT_LOGV("Set real number value's raw value: value-addr=%p, value=%f",
+               real_obj, val);
+}
+
+BT_HIDDEN
+const char *bt_ctf_value_string_get(const struct bt_ctf_value *string_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(string_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj, BT_CTF_VALUE_TYPE_STRING);
+       return BT_CTF_VALUE_TO_STRING(string_obj)->gstr->str;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_string_set(
+               struct bt_ctf_private_value *string_obj, const char *val)
+{
+       BT_ASSERT_PRE_NON_NULL(string_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj, BT_CTF_VALUE_TYPE_STRING);
+       BT_ASSERT_PRE_VALUE_HOT(string_obj, "Value object");
+       g_string_assign(BT_CTF_VALUE_TO_STRING(string_obj)->gstr, val);
+       BT_LOGV("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
+               string_obj, val);
+       return BT_CTF_VALUE_STATUS_OK;
+}
+
+BT_HIDDEN
+uint64_t bt_ctf_value_array_get_size(const struct bt_ctf_value *array_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(array_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_CTF_VALUE_TYPE_ARRAY);
+       return (uint64_t) BT_CTF_VALUE_TO_ARRAY(array_obj)->garray->len;
+}
+
+BT_HIDDEN
+struct bt_ctf_value *bt_ctf_value_array_borrow_element_by_index(
+               const struct bt_ctf_value *array_obj,
+               uint64_t index)
+{
+       struct bt_ctf_value_array *typed_array_obj =
+               BT_CTF_VALUE_TO_ARRAY(array_obj);
+
+       BT_ASSERT_PRE_NON_NULL(array_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_CTF_VALUE_TYPE_ARRAY);
+       BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index,
+               typed_array_obj->garray->len);
+       return g_ptr_array_index(typed_array_obj->garray, index);
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_array_borrow_element_by_index(
+               const struct bt_ctf_private_value *array_obj,
+               uint64_t index)
+{
+       return (void *) bt_ctf_value_array_borrow_element_by_index(
+               (void *) array_obj, index);
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_element(
+               struct bt_ctf_private_value *array_obj,
+               struct bt_ctf_value *element_obj)
+{
+       struct bt_ctf_value_array *typed_array_obj =
+               BT_CTF_VALUE_TO_ARRAY(array_obj);
+
+       BT_ASSERT_PRE_NON_NULL(array_obj, "Array value object");
+       BT_ASSERT_PRE_NON_NULL(element_obj, "Element value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_CTF_VALUE_TYPE_ARRAY);
+       BT_ASSERT_PRE_VALUE_HOT(array_obj, "Array value object");
+       g_ptr_array_add(typed_array_obj->garray, element_obj);
+       bt_ctf_object_get_ref(element_obj);
+       BT_LOGV("Appended element to array value: array-value-addr=%p, "
+               "element-value-addr=%p, new-size=%u",
+               array_obj, element_obj, typed_array_obj->garray->len);
+       return BT_CTF_VALUE_STATUS_OK;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_bool_element(
+               struct bt_ctf_private_value *array_obj, bt_bool val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *bool_obj = NULL;
+
+       bool_obj = bt_ctf_private_value_bool_create_init(val);
+       ret = bt_ctf_private_value_array_append_element(array_obj,
+               (void *) bool_obj);
+       bt_ctf_object_put_ref(bool_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_integer_element(
+               struct bt_ctf_private_value *array_obj, int64_t val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *integer_obj = NULL;
+
+       integer_obj = bt_ctf_private_value_integer_create_init(val);
+       ret = bt_ctf_private_value_array_append_element(array_obj,
+               (void *) integer_obj);
+       bt_ctf_object_put_ref(integer_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_real_element(
+               struct bt_ctf_private_value *array_obj, double val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *real_obj = NULL;
+
+       real_obj = bt_ctf_private_value_real_create_init(val);
+       ret = bt_ctf_private_value_array_append_element(array_obj,
+               (void *) real_obj);
+       bt_ctf_object_put_ref(real_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_string_element(
+               struct bt_ctf_private_value *array_obj, const char *val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *string_obj = NULL;
+
+       string_obj = bt_ctf_private_value_string_create_init(val);
+       ret = bt_ctf_private_value_array_append_element(array_obj,
+               (void *) string_obj);
+       bt_ctf_object_put_ref(string_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_array_element(
+               struct bt_ctf_private_value *array_obj)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *empty_array_obj = NULL;
+
+       empty_array_obj = bt_ctf_private_value_array_create();
+       ret = bt_ctf_private_value_array_append_element(array_obj,
+               (void *) empty_array_obj);
+       bt_ctf_object_put_ref(empty_array_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_append_empty_map_element(
+               struct bt_ctf_private_value *array_obj)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *map_obj = NULL;
+
+       map_obj = bt_ctf_private_value_map_create();
+       ret = bt_ctf_private_value_array_append_element(array_obj,
+               (void *) map_obj);
+       bt_ctf_object_put_ref(map_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_array_set_element_by_index(
+               struct bt_ctf_private_value *array_obj, uint64_t index,
+               struct bt_ctf_value *element_obj)
+{
+       struct bt_ctf_value_array *typed_array_obj =
+               BT_CTF_VALUE_TO_ARRAY(array_obj);
+
+       BT_ASSERT_PRE_NON_NULL(array_obj, "Array value object");
+       BT_ASSERT_PRE_NON_NULL(element_obj, "Element value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_CTF_VALUE_TYPE_ARRAY);
+       BT_ASSERT_PRE_VALUE_HOT(array_obj, "Array value object");
+       BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index,
+               typed_array_obj->garray->len);
+       bt_ctf_object_put_ref(g_ptr_array_index(typed_array_obj->garray, index));
+       g_ptr_array_index(typed_array_obj->garray, index) = element_obj;
+       bt_ctf_object_get_ref(element_obj);
+       BT_LOGV("Set array value's element: array-value-addr=%p, "
+               "index=%" PRIu64 ", element-value-addr=%p",
+               array_obj, index, element_obj);
+       return BT_CTF_VALUE_STATUS_OK;
+}
+
+BT_HIDDEN
+uint64_t bt_ctf_value_map_get_size(const struct bt_ctf_value *map_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(map_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_CTF_VALUE_TYPE_MAP);
+       return (uint64_t) g_hash_table_size(BT_CTF_VALUE_TO_MAP(map_obj)->ght);
+}
+
+BT_HIDDEN
+struct bt_ctf_value *bt_ctf_value_map_borrow_entry_value(const struct bt_ctf_value *map_obj,
+               const char *key)
+{
+       BT_ASSERT_PRE_NON_NULL(map_obj, "Value object");
+       BT_ASSERT_PRE_NON_NULL(key, "Key");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_CTF_VALUE_TYPE_MAP);
+       return g_hash_table_lookup(BT_CTF_VALUE_TO_MAP(map_obj)->ght,
+               GUINT_TO_POINTER(g_quark_from_string(key)));
+}
+
+BT_HIDDEN
+struct bt_ctf_private_value *bt_ctf_private_value_map_borrow_entry_value(
+               const struct bt_ctf_private_value *map_obj, const char *key)
+{
+       return (void *) bt_ctf_value_map_borrow_entry_value((void *) map_obj, key);
+}
+
+BT_HIDDEN
+bt_bool bt_ctf_value_map_has_entry(const struct bt_ctf_value *map_obj, const char *key)
+{
+       BT_ASSERT_PRE_NON_NULL(map_obj, "Value object");
+       BT_ASSERT_PRE_NON_NULL(key, "Key");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_CTF_VALUE_TYPE_MAP);
+       return bt_g_hash_table_contains(BT_CTF_VALUE_TO_MAP(map_obj)->ght,
+               GUINT_TO_POINTER(g_quark_from_string(key)));
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_entry(
+               struct bt_ctf_private_value *map_obj,
+               const char *key, struct bt_ctf_value *element_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(map_obj, "Map value object");
+       BT_ASSERT_PRE_NON_NULL(key, "Key");
+       BT_ASSERT_PRE_NON_NULL(element_obj, "Element value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_CTF_VALUE_TYPE_MAP);
+       BT_ASSERT_PRE_VALUE_HOT(map_obj, "Map value object");
+       g_hash_table_insert(BT_CTF_VALUE_TO_MAP(map_obj)->ght,
+               GUINT_TO_POINTER(g_quark_from_string(key)), element_obj);
+       bt_ctf_object_get_ref(element_obj);
+       BT_LOGV("Inserted value into map value: map-value-addr=%p, "
+               "key=\"%s\", element-value-addr=%p",
+               map_obj, key, element_obj);
+       return BT_CTF_VALUE_STATUS_OK;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_bool_entry(
+               struct bt_ctf_private_value *map_obj, const char *key, bt_bool val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *bool_obj = NULL;
+
+       bool_obj = bt_ctf_private_value_bool_create_init(val);
+       ret = bt_ctf_private_value_map_insert_entry(map_obj, key,
+               (void *) bool_obj);
+       bt_ctf_object_put_ref(bool_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_integer_entry(
+               struct bt_ctf_private_value *map_obj, const char *key, int64_t val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *integer_obj = NULL;
+
+       integer_obj = bt_ctf_private_value_integer_create_init(val);
+       ret = bt_ctf_private_value_map_insert_entry(map_obj, key,
+               (void *) integer_obj);
+       bt_ctf_object_put_ref(integer_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_real_entry(
+               struct bt_ctf_private_value *map_obj, const char *key, double val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *real_obj = NULL;
+
+       real_obj = bt_ctf_private_value_real_create_init(val);
+       ret = bt_ctf_private_value_map_insert_entry(map_obj, key,
+               (void *) real_obj);
+       bt_ctf_object_put_ref(real_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_string_entry(
+               struct bt_ctf_private_value *map_obj, const char *key,
+               const char *val)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *string_obj = NULL;
+
+       string_obj = bt_ctf_private_value_string_create_init(val);
+       ret = bt_ctf_private_value_map_insert_entry(map_obj, key,
+               (void *) string_obj);
+       bt_ctf_object_put_ref(string_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_array_entry(
+               struct bt_ctf_private_value *map_obj, const char *key)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *array_obj = NULL;
+
+       array_obj = bt_ctf_private_value_array_create();
+       ret = bt_ctf_private_value_map_insert_entry(map_obj, key,
+               (void *) array_obj);
+       bt_ctf_object_put_ref(array_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_insert_empty_map_entry(
+               struct bt_ctf_private_value *map_obj, const char *key)
+{
+       enum bt_ctf_value_status ret;
+       struct bt_ctf_private_value *empty_map_obj = NULL;
+
+       empty_map_obj = bt_ctf_private_value_map_create();
+       ret = bt_ctf_private_value_map_insert_entry(map_obj, key,
+               (void *) empty_map_obj);
+       bt_ctf_object_put_ref(empty_map_obj);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_value_map_foreach_entry(const struct bt_ctf_value *map_obj,
+               bt_ctf_value_map_foreach_entry_cb cb, void *data)
+{
+       enum bt_ctf_value_status ret = BT_CTF_VALUE_STATUS_OK;
+       gpointer key, element_obj;
+       GHashTableIter iter;
+       struct bt_ctf_value_map *typed_map_obj = BT_CTF_VALUE_TO_MAP(map_obj);
+
+       BT_ASSERT_PRE_NON_NULL(map_obj, "Value object");
+       BT_ASSERT_PRE_NON_NULL(cb, "Callback");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_CTF_VALUE_TYPE_MAP);
+       g_hash_table_iter_init(&iter, typed_map_obj->ght);
+
+       while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
+               const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
+
+               if (!cb(key_str, element_obj, data)) {
+                       BT_LOGV("User canceled the loop: key=\"%s\", "
+                               "value-addr=%p, data=%p",
+                               key_str, element_obj, data);
+                       ret = BT_CTF_VALUE_STATUS_CANCELED;
+                       break;
+               }
+       }
+
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_private_value_map_foreach_entry(
+               const struct bt_ctf_private_value *map_obj,
+               bt_ctf_private_value_map_foreach_entry_cb cb, void *data)
+{
+       return bt_ctf_value_map_foreach_entry((void *) map_obj,
+               (bt_ctf_value_map_foreach_entry_cb) cb, data);
+}
+
+struct extend_map_element_data {
+       struct bt_ctf_private_value *extended_obj;
+       enum bt_ctf_value_status status;
+};
+
+static
+bt_bool extend_map_element(const char *key,
+               struct bt_ctf_value *extension_obj_elem, void *data)
+{
+       bt_bool ret = BT_TRUE;
+       struct extend_map_element_data *extend_data = data;
+       struct bt_ctf_private_value *extension_obj_elem_copy = NULL;
+
+       /* Copy object which is to replace the current one */
+       extend_data->status = bt_ctf_value_copy(&extension_obj_elem_copy,
+               extension_obj_elem);
+       if (extend_data->status) {
+               BT_LOGE("Cannot copy map element: addr=%p",
+                       extension_obj_elem);
+               goto error;
+       }
+
+       BT_ASSERT(extension_obj_elem_copy);
+
+       /* Replace in extended object */
+       extend_data->status = bt_ctf_private_value_map_insert_entry(
+               extend_data->extended_obj, key,
+               (void *) extension_obj_elem_copy);
+       if (extend_data->status) {
+               BT_LOGE("Cannot replace value in extended value: key=\"%s\", "
+                       "extended-value-addr=%p, element-value-addr=%p",
+                       key, extend_data->extended_obj,
+                       extension_obj_elem_copy);
+               goto error;
+       }
+
+       goto end;
+
+error:
+       BT_ASSERT(extend_data->status != BT_CTF_VALUE_STATUS_OK);
+       ret = BT_FALSE;
+
+end:
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy);
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_value_map_extend(
+               struct bt_ctf_private_value **extended_map_obj,
+               const struct bt_ctf_value *base_map_obj,
+               const struct bt_ctf_value *extension_obj)
+{
+       struct extend_map_element_data extend_data = {
+               .extended_obj = NULL,
+               .status = BT_CTF_VALUE_STATUS_OK,
+       };
+
+       BT_ASSERT_PRE_NON_NULL(base_map_obj, "Base value object");
+       BT_ASSERT_PRE_NON_NULL(extension_obj, "Extension value object");
+       BT_ASSERT_PRE_NON_NULL(extended_map_obj,
+               "Extended value object (output)");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj, BT_CTF_VALUE_TYPE_MAP);
+       BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj, BT_CTF_VALUE_TYPE_MAP);
+       BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
+               base_map_obj, extension_obj);
+       *extended_map_obj = NULL;
+
+       /* Create copy of base map object to start with */
+       extend_data.status = bt_ctf_value_copy(extended_map_obj, base_map_obj);
+       if (extend_data.status) {
+               BT_LOGE("Cannot copy base value: base-value-addr=%p",
+                       base_map_obj);
+               goto error;
+       }
+
+       BT_ASSERT(extended_map_obj);
+
+       /*
+        * For each key in the extension map object, replace this key
+        * in the copied map object.
+        */
+       extend_data.extended_obj = *extended_map_obj;
+
+       if (bt_ctf_value_map_foreach_entry(extension_obj, extend_map_element,
+                       &extend_data)) {
+               BT_LOGE("Cannot iterate on the extension object's elements: "
+                       "extension-value-addr=%p", extension_obj);
+               goto error;
+       }
+
+       if (extend_data.status) {
+               BT_LOGE("Failed to successfully iterate on the extension object's elements: "
+                       "extension-value-addr=%p", extension_obj);
+               goto error;
+       }
+
+       BT_LOGD("Extended map value: extended-value-addr=%p",
+               *extended_map_obj);
+       goto end;
+
+error:
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(*extended_map_obj);
+       *extended_map_obj = NULL;
+
+end:
+       return extend_data.status;
+}
+
+BT_HIDDEN
+enum bt_ctf_value_status bt_ctf_value_copy(struct bt_ctf_private_value **copy_obj,
+               const struct bt_ctf_value *object)
+{
+       enum bt_ctf_value_status status = BT_CTF_VALUE_STATUS_OK;
+
+       BT_ASSERT_PRE_NON_NULL(object, "Value object");
+       BT_ASSERT_PRE_NON_NULL(copy_obj, "Value object copy (output)");
+       BT_LOGD("Copying value object: addr=%p", object);
+       *copy_obj = copy_funcs[object->type](object);
+       if (*copy_obj) {
+               BT_LOGD("Copied value object: copy-value-addr=%p",
+                       copy_obj);
+       } else {
+               status = BT_CTF_VALUE_STATUS_NOMEM;
+               *copy_obj = NULL;
+               BT_LOGE_STR("Failed to copy value object.");
+       }
+
+       return status;
+}
+
+BT_HIDDEN
+bt_bool bt_ctf_value_compare(const struct bt_ctf_value *object_a,
+       const struct bt_ctf_value *object_b)
+{
+       bt_bool ret = BT_FALSE;
+
+       BT_ASSERT_PRE_NON_NULL(object_a, "Value object A");
+       BT_ASSERT_PRE_NON_NULL(object_b, "Value object B");
+
+       if (object_a->type != object_b->type) {
+               BT_LOGV("Values are different: type mismatch: "
+                       "value-a-addr=%p, value-b-addr=%p, "
+                       "value-a-type=%d, value-b-type=%d",
+                       object_a, object_b, object_a->type, object_b->type);
+               goto end;
+       }
+
+       ret = compare_funcs[object_a->type](object_a, object_b);
+
+end:
+       return ret;
+}
index e416e7be1a7c84606774808524b4157329741933..76b65a0c14fa902caec806ad6042a117130fbacc 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 #include <babeltrace/ctf-writer/visitor-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 
 BT_HIDDEN
 int bt_ctf_visitor_helper(struct bt_ctf_visitor_object *root,
@@ -59,7 +59,7 @@ int bt_ctf_visitor_helper(struct bt_ctf_visitor_object *root,
                        goto end;
                }
                ret = child_visitor(child, visitor, data);
-               BT_OBJECT_PUT_REF_AND_RESET(child);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(child);
                if (ret) {
                        goto end;
                }
index 7365243c926f278d095fa48c6c7f47a3275d1ffc..b0e3dc45ad276c8689bafcb71e22b5c8d36afd68 100644 (file)
@@ -41,7 +41,7 @@
 #include <babeltrace/ctf-writer/trace-internal.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
 #include <babeltrace/endian-internal.h>
-#include <babeltrace/object.h>
+#include <babeltrace/ctf-writer/object.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
@@ -51,7 +51,7 @@
 #include <unistd.h>
 
 static
-void bt_ctf_writer_destroy(struct bt_object *obj);
+void bt_ctf_writer_destroy(struct bt_ctf_object *obj);
 
 static
 int init_trace_packet_header(struct bt_ctf_trace *trace)
@@ -95,10 +95,10 @@ int init_trace_packet_header(struct bt_ctf_trace *trace)
                goto end;
        }
 end:
-       bt_object_put_ref(uuid_array_type);
-       bt_object_put_ref(_uint32_t);
-       bt_object_put_ref(_uint8_t);
-       bt_object_put_ref(trace_packet_header_type);
+       bt_ctf_object_put_ref(uuid_array_type);
+       bt_ctf_object_put_ref(_uint32_t);
+       bt_ctf_object_put_ref(_uint8_t);
+       bt_ctf_object_put_ref(trace_packet_header_type);
        return ret;
 }
 
@@ -120,7 +120,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
 
        metadata_path = g_build_filename(path, "metadata", NULL);
 
-       bt_object_init_shared(&writer->base, bt_ctf_writer_destroy);
+       bt_ctf_object_init_shared(&writer->base, bt_ctf_writer_destroy);
        writer->path = g_string_new(path);
        if (!writer->path) {
                goto error_destroy;
@@ -148,8 +148,8 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
                goto error_destroy;
        }
 
-       bt_object_set_parent(&writer->trace->common.base, &writer->base);
-       bt_object_put_ref(writer->trace);
+       bt_ctf_object_set_parent(&writer->trace->common.base, &writer->base);
+       bt_ctf_object_put_ref(writer->trace);
 
        /* Default to little-endian */
        ret = bt_ctf_writer_set_byte_order(writer, BT_CTF_BYTE_ORDER_NATIVE);
@@ -173,13 +173,13 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
        return writer;
 
 error_destroy:
-       BT_OBJECT_PUT_REF_AND_RESET(writer);
+       BT_CTF_OBJECT_PUT_REF_AND_RESET(writer);
 error:
        g_free(metadata_path);
        return writer;
 }
 
-void bt_ctf_writer_destroy(struct bt_object *obj)
+void bt_ctf_writer_destroy(struct bt_ctf_object *obj)
 {
        struct bt_ctf_writer *writer;
 
@@ -195,7 +195,7 @@ void bt_ctf_writer_destroy(struct bt_object *obj)
                }
        }
 
-       bt_object_try_spec_release(&writer->trace->common.base);
+       bt_ctf_object_try_spec_release(&writer->trace->common.base);
        g_free(writer);
 }
 
@@ -208,7 +208,7 @@ struct bt_ctf_trace *bt_ctf_writer_get_trace(struct bt_ctf_writer *writer)
        }
 
        trace = writer->trace;
-       bt_object_get_ref(trace);
+       bt_ctf_object_get_ref(trace);
 end:
        return trace;
 }
@@ -240,7 +240,7 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer,
                        stream_class_found = BT_TRUE;
                }
 
-               BT_OBJECT_PUT_REF_AND_RESET(existing_stream_class);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(existing_stream_class);
 
                if (stream_class_found) {
                        break;
@@ -264,7 +264,7 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer,
        return stream;
 
 error:
-        BT_OBJECT_PUT_REF_AND_RESET(stream);
+        BT_CTF_OBJECT_PUT_REF_AND_RESET(stream);
        return stream;
 }
 
@@ -422,7 +422,7 @@ struct bt_ctf_field_type *get_field_type(enum field_type_alias alias)
        field_type = bt_ctf_field_type_integer_create(size);
        ret = bt_ctf_field_type_set_alignment(field_type, alignment);
        if (ret) {
-               BT_OBJECT_PUT_REF_AND_RESET(field_type);
+               BT_CTF_OBJECT_PUT_REF_AND_RESET(field_type);
        }
 end:
        return field_type;
index 8e6df9e5d9f0065e1c563d449f992952acbea265..a893188dab794dcb2b087e14d1278ce71b80f747 100644 (file)
@@ -57,7 +57,7 @@
 #define DEFAULT_CLOCK_TIME 0
 #define DEFAULT_CLOCK_VALUE 0
 
-#define NR_TESTS 335
+#define NR_TESTS 325
 
 struct bt_utsname {
        char sysname[BABELTRACE_HOST_NAME_MAX];
@@ -1613,8 +1613,6 @@ int main(int argc, char **argv)
        struct bt_ctf_field *packet_header, *packet_header_field;
        struct bt_ctf_trace *trace;
        int ret;
-       int64_t ret_int64_t;
-       struct bt_value *obj;
 
        if (argc < 2) {
                printf("Usage: tests-ctf-writer path_to_babeltrace\n");
@@ -1690,54 +1688,10 @@ int main(int argc, char **argv)
                "oh yeah"),
                "bt_ctf_trace_set_environment_field_string succeeds");
 
-       /* Test bt_ctf_trace_get_environment_field_count */
-       ok(bt_ctf_trace_get_environment_field_count(trace) == 3,
-               "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
-
-       /* Test bt_ctf_trace_get_environment_field_name */
-       ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 0);
-       ok(ret_string && !strcmp(ret_string, "host"),
-               "bt_ctf_trace_get_environment_field_name returns a correct field name");
-       ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 1);
-       ok(ret_string && !strcmp(ret_string, "test_env_int"),
-               "bt_ctf_trace_get_environment_field_name returns a correct field name");
-       ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 2);
-       ok(ret_string && !strcmp(ret_string, "test_env_str"),
-               "bt_ctf_trace_get_environment_field_name returns a correct field name");
-
-       /* Test bt_ctf_trace_get_environment_field_value */
-       obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 1);
-       ret_int64_t = bt_value_integer_get(obj);
-       ok(ret_int64_t == -164973,
-               "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
-       BT_OBJECT_PUT_REF_AND_RESET(obj);
-       obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 2);
-       ret_string = bt_value_string_get(obj);
-       ok(ret_string && !strcmp(ret_string, "oh yeah"),
-               "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
-       BT_OBJECT_PUT_REF_AND_RESET(obj);
-
-       /* Test bt_ctf_trace_get_environment_field_value_by_name */
-       ok(!bt_ctf_trace_get_environment_field_value_by_name(trace, "oh oh"),
-               "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
-       obj = bt_ctf_trace_get_environment_field_value_by_name(trace,
-               "test_env_str");
-       ret_string = bt_value_string_get(obj);
-       ok(ret_string && !strcmp(ret_string, "oh yeah"),
-               "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
-       BT_OBJECT_PUT_REF_AND_RESET(obj);
-
        /* Test environment field replacement */
        ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int",
                654321),
                "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
-       ok(bt_ctf_trace_get_environment_field_count(trace) == 3,
-               "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
-       obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 1);
-       ret_int64_t = bt_value_integer_get(obj);
-       ok(ret_int64_t == 654321,
-               "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
-       BT_OBJECT_PUT_REF_AND_RESET(obj);
 
        ok(bt_ctf_writer_add_environment_field(writer, "sysname", name.sysname)
                == 0, "Add sysname (%s) environment field to writer instance",
This page took 0.157923 seconds and 4 git commands to generate.