ir: add weak reference to parent trace to bt_ctf_stream_class
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 20 Mar 2015 01:43:00 +0000 (21:43 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 20 Mar 2015 01:43:00 +0000 (21:43 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/stream-class.c
formats/ctf/ir/trace.c
include/babeltrace/ctf-ir/stream-class-internal.h

index 9ef5ca790d7bbf8c8fec5ed95620b2ec5f422cef..22ea8a5db6628d819153026dd8201b98487d345d 100644 (file)
@@ -666,6 +666,28 @@ end:
        return ret;
 }
 
+BT_HIDDEN
+int bt_ctf_stream_class_set_trace(struct bt_ctf_stream_class *stream_class,
+               struct bt_ctf_trace *trace)
+{
+       int ret = 0;
+
+       if (!stream_class) {
+               ret = -1;
+               goto end;
+       }
+
+       if (stream_class->trace && trace) {
+               /* Already attached to a trace */
+               ret = -1;
+               goto end;
+       }
+
+       stream_class->trace = trace;
+end:
+       return ret;
+}
+
 static
 void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref)
 {
index e7dcfdaede408f32953414c5dfbeae9fdd3633e4..476d62c363cd958d3ec0b1fa87ef5831007ba043 100644 (file)
@@ -62,6 +62,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 +81,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 +410,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 +439,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;
 }
 
index 8301fea019cdd7353c0421afe95102552c583eda..3b368d1de2230bb26619b7a8763f09a052319af2 100644 (file)
@@ -31,6 +31,7 @@
 #include <babeltrace/ctf-writer/clock.h>
 #include <babeltrace/ctf-writer/event-fields.h>
 #include <babeltrace/ctf-writer/event-types.h>
+#include <babeltrace/ctf-ir/trace.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/ctf/types.h>
 #include <glib.h>
@@ -44,6 +45,8 @@ struct bt_ctf_stream_class {
        uint32_t id;
        uint32_t next_event_id;
        uint32_t next_stream_id;
+       /* Weak reference; a stream class does not have ownership of a trace */
+       struct bt_ctf_trace *trace;
        struct bt_ctf_field_type *packet_context_type;
        struct bt_ctf_field_type *event_header_type;
        struct bt_ctf_field_type *event_context_type;
@@ -67,4 +70,8 @@ BT_HIDDEN
 int _bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class,
                uint32_t id);
 
+BT_HIDDEN
+int bt_ctf_stream_class_set_trace(struct bt_ctf_stream_class *stream_class,
+               struct bt_ctf_trace *trace);
+
 #endif /* BABELTRACE_CTF_IR_STREAM_CLASS_INTERNAL_H */
This page took 0.026771 seconds and 4 git commands to generate.