Subscribe to notifications when creating a notif. iterator
[babeltrace.git] / plugins / utils / dummy / dummy.c
index 79b8f5bad557df62f248bdeef39fb3f122eab376..5f7c62d64b56dbe4b145fab37b88ec6ca6dfee52 100644 (file)
  */
 
 #include <babeltrace/plugin/plugin-dev.h>
-#include <babeltrace/component/component.h>
-#include <babeltrace/component/component-sink.h>
-#include <babeltrace/component/notification/iterator.h>
-#include <babeltrace/component/notification/notification.h>
+#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/private-component.h>
+#include <babeltrace/graph/private-component-sink.h>
+#include <babeltrace/graph/private-port.h>
+#include <babeltrace/graph/port.h>
+#include <babeltrace/graph/private-connection.h>
+#include <babeltrace/graph/component-sink.h>
+#include <babeltrace/graph/notification-iterator.h>
+#include <babeltrace/graph/notification.h>
+#include <babeltrace/babeltrace-internal.h>
 #include <plugins-common.h>
 #include <assert.h>
 #include "dummy.h"
@@ -38,27 +44,36 @@ void destroy_private_dummy_data(struct dummy *dummy)
        g_free(dummy);
 }
 
-void dummy_destroy(struct bt_component *component)
+void dummy_finalize(struct bt_private_component *component)
 {
        struct dummy *dummy;
 
        assert(component);
-       dummy = bt_component_get_private_data(component);
+       dummy = bt_private_component_get_user_data(component);
        assert(dummy);
        destroy_private_dummy_data(dummy);
 }
 
-enum bt_component_status dummy_init(struct bt_component *component,
+enum bt_component_status dummy_init(struct bt_private_component *component,
                struct bt_value *params, UNUSED_VAR void *init_method_data)
 {
        enum bt_component_status ret;
        struct dummy *dummy = g_new0(struct dummy, 1);
+       void *priv_port;
 
        if (!dummy) {
                ret = BT_COMPONENT_STATUS_NOMEM;
                goto end;
        }
 
+       priv_port = bt_private_component_sink_add_input_private_port(component,
+               "in", NULL);
+       if (!priv_port) {
+               ret = BT_COMPONENT_STATUS_NOMEM;
+               goto end;
+       }
+
+       bt_put(priv_port);
        dummy->iterators = g_ptr_array_new_with_free_func(
                        (GDestroyNotify) bt_put);
        if (!dummy->iterators) {
@@ -66,7 +81,7 @@ enum bt_component_status dummy_init(struct bt_component *component,
                goto end;
        }
 
-       ret = bt_component_set_private_data(component, dummy);
+       ret = bt_private_component_set_user_data(component, dummy);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
@@ -77,42 +92,47 @@ error:
        return ret;
 }
 
-enum bt_component_status dummy_accept_port_connection(struct bt_component *component,
-               struct bt_port *self_port)
+void dummy_port_connected(
+               struct bt_private_component *component,
+               struct bt_private_port *self_port,
+               struct bt_port *other_port)
 {
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        struct dummy *dummy;
-       struct bt_connection *connection;
        struct bt_notification_iterator *iterator;
+       struct bt_private_connection *connection;
 
-       dummy = bt_component_get_private_data(component);
+       dummy = bt_private_component_get_user_data(component);
        assert(dummy);
-
-       connection = bt_port_get_connection(self_port);
+       connection = bt_private_port_get_private_connection(self_port);
        assert(connection);
-
-       iterator = bt_connection_create_notification_iterator(connection);
+       iterator = bt_private_connection_create_notification_iterator(
+               connection, NULL);
        if (!iterator) {
-               ret = BT_COMPONENT_STATUS_ERROR;
+               dummy->error = true;
                goto end;
        }
 
        g_ptr_array_add(dummy->iterators, iterator);
+
 end:
        bt_put(connection);
-       return ret;
 }
 
-enum bt_component_status dummy_consume(struct bt_component *component)
+enum bt_component_status dummy_consume(struct bt_private_component *component)
 {
-       enum bt_component_status ret;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        struct bt_notification *notif = NULL;
        size_t i;
        struct dummy *dummy;
 
-       dummy = bt_component_get_private_data(component);
+       dummy = bt_private_component_get_user_data(component);
        assert(dummy);
 
+       if (unlikely(dummy->error)) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+
        /* Consume one notification from each iterator. */
        for (i = 0; i < dummy->iterators->len; i++) {
                struct bt_notification_iterator *it;
@@ -125,26 +145,16 @@ enum bt_component_status dummy_consume(struct bt_component *component)
                case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
+               case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
+                       ret = BT_COMPONENT_STATUS_AGAIN;
+                       goto end;
                case BT_NOTIFICATION_ITERATOR_STATUS_END:
-                       ret = BT_COMPONENT_STATUS_END;
                        g_ptr_array_remove_index(dummy->iterators, i);
                        i--;
                        continue;
                default:
                        break;
                }
-
-               notif = bt_notification_iterator_get_notification(it);
-               if (!notif) {
-                       ret = BT_COMPONENT_STATUS_ERROR;
-                       goto end;
-               }
-
-               /*
-                * Dummy! I'm doing nothing with this notification,
-                * NOTHING.
-                */
-               BT_PUT(notif);
        }
 
        if (dummy->iterators->len == 0) {
This page took 0.025669 seconds and 4 git commands to generate.