Visibility: split graph API into public and private interfaces
[babeltrace.git] / plugins / text / text.c
index e6631763122d8f944c9a6ea8d8bafad8098ebcda..ecd6bbea65e54fc2a2336e5cc1896192a799ce68 100644 (file)
 
 #include <babeltrace/plugin/plugin-dev.h>
 #include <babeltrace/component/component.h>
+#include <babeltrace/component/private-component.h>
 #include <babeltrace/component/component-sink.h>
+#include <babeltrace/component/port.h>
+#include <babeltrace/component/private-port.h>
+#include <babeltrace/component/connection.h>
+#include <babeltrace/component/private-connection.h>
 #include <babeltrace/component/notification/notification.h>
 #include <babeltrace/component/notification/iterator.h>
 #include <babeltrace/component/notification/event.h>
@@ -41,6 +46,7 @@
 #include <stdbool.h>
 #include <glib.h>
 #include "text.h"
+#include <assert.h>
 
 static
 const char *plugin_options[] = {
@@ -73,6 +79,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);
@@ -102,9 +109,9 @@ error:
 }
 
 static
-void destroy_text(struct bt_component *component)
+void destroy_text(struct bt_private_component *component)
 {
-       void *data = bt_component_get_private_data(component);
+       void *data = bt_private_component_get_user_data(component);
 
        destroy_text_data(data);
 }
@@ -154,17 +161,40 @@ end:
 }
 
 static
-enum bt_component_status run(struct bt_component *component)
+enum bt_component_status text_accept_port_connection(
+               struct bt_private_component *component,
+               struct bt_private_port *self_port)
+{
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_private_connection *connection;
+       struct text_component *text;
+
+       text = bt_private_component_get_user_data(component);
+       assert(text);
+       assert(!text->input_iterator);
+       connection = bt_private_port_get_private_connection(self_port);
+       assert(connection);
+       text->input_iterator =
+               bt_private_connection_create_notification_iterator(connection);
+
+       if (!text->input_iterator) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+       }
+
+       bt_put(connection);
+       return ret;
+}
+
+static
+enum bt_component_status run(struct bt_private_component *component)
 {
        enum bt_component_status ret;
        struct bt_notification *notification = NULL;
        struct bt_notification_iterator *it;
-       struct text_component *text = bt_component_get_private_data(component);
+       struct text_component *text =
+               bt_private_component_get_user_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 +206,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 +221,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;
 }
@@ -337,8 +367,8 @@ enum bt_component_status apply_params(struct text_component *text,
                        goto end;
                }
 
-               ret = bt_value_string_get(color_value, &color);
-               if (ret) {
+               status = bt_value_string_get(color_value, &color);
+               if (status) {
                        warn_wrong_color_param(text);
                } else {
                        if (strcmp(color, "never") == 0) {
@@ -686,7 +716,8 @@ void init_stream_packet_context_quarks(void)
 
 static
 enum bt_component_status text_component_init(
-               struct bt_component *component, struct bt_value *params,
+               struct bt_private_component *component,
+               struct bt_value *params,
                UNUSED_VAR void *init_method_data)
 {
        enum bt_component_status ret;
@@ -713,7 +744,7 @@ enum bt_component_status text_component_init(
 
        set_use_colors(text);
 
-       ret = bt_component_set_private_data(component, text);
+       ret = bt_private_component_set_user_data(component, text);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
@@ -734,6 +765,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_ACCEPT_PORT_CONNECTION_METHOD(text, text_accept_port_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.");
This page took 0.02524 seconds and 4 git commands to generate.