Move bt_ctf_attributes API to internal headers
[babeltrace.git] / formats / ctf / ir / trace.c
index 6939ac34d924b0ba26fa59dc33f523c60fb34c97..ca74d1703498086697c74e636037c5aa61990c27 100644 (file)
@@ -32,6 +32,7 @@
 #include <babeltrace/ctf-ir/stream-class-internal.h>
 #include <babeltrace/ctf-writer/functor-internal.h>
 #include <babeltrace/ctf-ir/event-types-internal.h>
+#include <babeltrace/ctf-ir/attributes-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
 #include <babeltrace/compiler.h>
 #include <babeltrace/objects.h>
@@ -62,6 +63,13 @@ const unsigned int field_type_aliases_sizes[] = {
        [FIELD_TYPE_ALIAS_UINT64_T] = 64,
 };
 
+static
+void put_stream_class(struct bt_ctf_stream_class *stream_class)
+{
+       (void) bt_ctf_stream_class_set_trace(stream_class, NULL);
+       bt_ctf_stream_class_put(stream_class);
+}
+
 struct bt_ctf_trace *bt_ctf_trace_create(void)
 {
        struct bt_ctf_trace *trace = NULL;
@@ -74,11 +82,11 @@ struct bt_ctf_trace *bt_ctf_trace_create(void)
        bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE);
        bt_ctf_ref_init(&trace->ref_count);
        trace->clocks = g_ptr_array_new_with_free_func(
-               (GDestroyNotify)bt_ctf_clock_put);
+               (GDestroyNotify) bt_ctf_clock_put);
        trace->streams = g_ptr_array_new_with_free_func(
-               (GDestroyNotify)bt_ctf_stream_put);
+               (GDestroyNotify) bt_ctf_stream_put);
        trace->stream_classes = g_ptr_array_new_with_free_func(
-               (GDestroyNotify)bt_ctf_stream_class_put);
+               (GDestroyNotify) put_stream_class);
        if (!trace->clocks || !trace->stream_classes || !trace->streams) {
                goto error_destroy;
        }
@@ -403,6 +411,13 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                }
        }
 
+       /* Set weak reference to trace in stream class */
+       ret = bt_ctf_stream_class_set_trace(stream_class, trace);
+       if (ret) {
+               /* Stream class already part of another trace */
+               goto end;
+       }
+
        bt_ctf_stream_class_get(stream_class);
        g_ptr_array_add(trace->stream_classes, stream_class);
 
@@ -425,6 +440,9 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
        bt_ctf_attributes_freeze(trace->environment);
 
 end:
+       if (ret) {
+               (void) bt_ctf_stream_class_set_trace(stream_class, NULL);
+       }
        return ret;
 }
 
@@ -561,8 +579,6 @@ void append_env_metadata(struct bt_ctf_trace *trace,
        for (i = 0; i < env_size; ++i) {
                struct bt_object *env_field_value_obj = NULL;
                const char *entry_name;
-               int64_t int_value;
-               int ret;
 
                entry_name = bt_ctf_attributes_get_field_name(
                        trace->environment, i);
@@ -575,6 +591,10 @@ void append_env_metadata(struct bt_ctf_trace *trace,
 
                switch (bt_object_get_type(env_field_value_obj)) {
                case BT_OBJECT_TYPE_INTEGER:
+               {
+                       int ret;
+                       int64_t int_value;
+
                        ret = bt_object_integer_get(env_field_value_obj,
                                &int_value);
 
@@ -586,7 +606,7 @@ void append_env_metadata(struct bt_ctf_trace *trace,
                                "\t%s = %" PRId64 ";\n", entry_name,
                                int_value);
                        break;
-
+               }
                case BT_OBJECT_TYPE_STRING:
                {
                        int ret;
This page took 0.02404 seconds and 4 git commands to generate.