Use graph facilities in writer component class
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 22 Feb 2017 15:04:52 +0000 (10:04 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:38 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/writer/writer.c
plugins/writer/writer.h

index 8e4703768f9473a6e6f5da5bde9910f94ec55477..1c8faab12478d4e3137d2c32322f58af62f427f4 100644 (file)
@@ -30,6 +30,8 @@
 #include <babeltrace/plugin/plugin-dev.h>
 #include <babeltrace/component/component.h>
 #include <babeltrace/component/component-sink.h>
+#include <babeltrace/component/component-port.h>
+#include <babeltrace/component/component-connection.h>
 #include <babeltrace/component/notification/notification.h>
 #include <babeltrace/component/notification/iterator.h>
 #include <babeltrace/component/notification/event.h>
 #include <stdbool.h>
 #include <glib.h>
 #include "writer.h"
+#include <assert.h>
 
 static
 void destroy_writer_component_data(struct writer_component *writer_component)
 {
+       bt_put(writer_component->input_iterator);
        g_hash_table_destroy(writer_component->stream_map);
        g_hash_table_destroy(writer_component->stream_class_map);
        g_hash_table_destroy(writer_component->trace_map);
@@ -180,6 +184,29 @@ end:
        return ret;
 }
 
+static
+enum bt_component_status writer_component_new_connection(
+               struct bt_port *own_port, struct bt_connection *connection)
+{
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_component *component;
+       struct writer_component *writer;
+
+       component = bt_port_get_component(own_port);
+       assert(component);
+       writer = bt_component_get_private_data(component);
+       assert(writer);
+       assert(!writer->input_iterator);
+        writer->input_iterator = bt_connection_create_notification_iterator(
+                       connection);
+
+       if (!writer->input_iterator) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+       }
+       bt_put(component);
+       return ret;
+}
+
 static
 enum bt_component_status run(struct bt_component *component)
 {
@@ -189,10 +216,8 @@ enum bt_component_status run(struct bt_component *component)
        struct writer_component *writer_component =
                bt_component_get_private_data(component);
 
-       ret = bt_component_sink_get_input_iterator(component, 0, &it);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto end;
-       }
+       it = writer_component->input_iterator;
+       assert(it);
 
        notification = bt_notification_iterator_get_notification(it);
        if (!notification) {
@@ -268,5 +293,7 @@ BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
 BT_PLUGIN_SINK_COMPONENT_CLASS(writer, run);
 BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(writer, writer_component_init);
+BT_PLUGIN_SINK_COMPONENT_CLASS_NEW_CONNECTION_METHOD(writer,
+               writer_component_new_connection);
 BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(writer, destroy_writer_component);
 BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(writer, "Formats CTF-IR to CTF.");
index 21aae60150a25c49e91c7a9784bb33934dcb84a9..12e2b65fbdfc83a807b6f16b09dffba48f413f23 100644 (file)
@@ -44,6 +44,7 @@ struct writer_component {
        /* Map between reader and writer stream class. */
        GHashTable *stream_class_map;
        FILE *err;
+       struct bt_notification_iterator *input_iterator;
 };
 
 BT_HIDDEN
This page took 0.025477 seconds and 4 git commands to generate.