Use graph facilities in text component class
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 22 Feb 2017 15:05:57 +0000 (10:05 -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/text/text.c
plugins/text/text.h

index e6631763122d8f944c9a6ea8d8bafad8098ebcda..8a916fc35705a4feeda57b891b22198d0e0c9589 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>
@@ -41,6 +43,7 @@
 #include <stdbool.h>
 #include <glib.h>
 #include "text.h"
+#include <assert.h>
 
 static
 const char *plugin_options[] = {
@@ -73,6 +76,7 @@ const char *plugin_options[] = {
 static
 void destroy_text_data(struct text_component *text)
 {
+       bt_put(text->input_iterator);
        (void) g_string_free(text->string, TRUE);
        g_free(text->options.output_path);
        g_free(text->options.debug_info_dir);
@@ -153,6 +157,29 @@ end:
        return ret;
 }
 
+static
+enum bt_component_status text_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 text_component *text;
+
+       component = bt_port_get_component(own_port);
+       assert(component);
+       text = bt_component_get_private_data(component);
+       assert(text);
+       assert(!text->input_iterator);
+       text->input_iterator = bt_connection_create_notification_iterator(
+                       connection);
+
+       if (!text->input_iterator) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+       }
+       bt_put(component);
+       return ret;
+}
+
 static
 enum bt_component_status run(struct bt_component *component)
 {
@@ -161,10 +188,7 @@ enum bt_component_status run(struct bt_component *component)
        struct bt_notification_iterator *it;
        struct text_component *text = 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 = text->input_iterator;
 
        if (likely(text->processed_first_event)) {
                enum bt_notification_iterator_status it_ret;
@@ -176,6 +200,7 @@ enum bt_component_status run(struct bt_component *component)
                        goto end;
                case BT_NOTIFICATION_ITERATOR_STATUS_END:
                        ret = BT_COMPONENT_STATUS_END;
+                       BT_PUT(text->input_iterator);
                        goto end;
                default:
                        break;
@@ -190,7 +215,6 @@ enum bt_component_status run(struct bt_component *component)
        ret = handle_notification(text, notification);
        text->processed_first_event = true;
 end:
-       bt_put(it);
        bt_put(notification);
        return ret;
 }
@@ -734,6 +758,7 @@ BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
 BT_PLUGIN_SINK_COMPONENT_CLASS(text, run);
 BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(text, text_component_init);
+BT_PLUGIN_SINK_COMPONENT_CLASS_NEW_CONNECTION_METHOD(text, text_new_connection);
 BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(text, destroy_text);
 BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(text,
        "Formats CTF-IR to text. Formerly known as ctf-text.");
index d6143283d9df604f74a154c30fd76be5bcb1b2f2..c819365f87f2436c92579ad30a9d5661968e458c 100644 (file)
@@ -76,6 +76,7 @@ struct text_options {
 
 struct text_component {
        struct text_options options;
+       struct bt_notification_iterator *input_iterator;
        FILE *out, *err;
        bool processed_first_event; /* Should be per-iterator. */
        int depth;      /* nesting, used for tabulation alignment. */
This page took 0.026622 seconds and 4 git commands to generate.