lib: rename include dir to babeltrace2
[babeltrace.git] / plugins / utils / dummy / dummy.c
index 23db9d3283f559479c542dca671fed0598a308be..59d851521ab5e4af8dc6cdc7b4b5c5749cea447e 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/plugin/plugin-dev.h>
-#include <babeltrace/component/component.h>
-#include <babeltrace/component/private-component.h>
-#include <babeltrace/component/private-port.h>
-#include <babeltrace/component/port.h>
-#include <babeltrace/component/private-connection.h>
-#include <babeltrace/component/component-sink.h>
-#include <babeltrace/component/notification/iterator.h>
-#include <babeltrace/component/notification/notification.h>
+#include <babeltrace2/babeltrace.h>
+#include <babeltrace2/babeltrace-internal.h>
 #include <plugins-common.h>
-#include <assert.h>
+#include <babeltrace2/assert-internal.h>
 #include "dummy.h"
 
 static
+const char * const in_port_name = "in";
+
 void destroy_private_dummy_data(struct dummy *dummy)
 {
-       if (dummy->iterators) {
-               g_ptr_array_free(dummy->iterators, TRUE);
-       }
+       bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter);
        g_free(dummy);
+
 }
 
-void dummy_destroy(struct bt_private_component *component)
+BT_HIDDEN
+void dummy_finalize(bt_self_component_sink *comp)
 {
        struct dummy *dummy;
 
-       assert(component);
-       dummy = bt_private_component_get_user_data(component);
-       assert(dummy);
+       BT_ASSERT(comp);
+       dummy = bt_self_component_get_data(
+                       bt_self_component_sink_as_self_component(comp));
+       BT_ASSERT(dummy);
        destroy_private_dummy_data(dummy);
 }
 
-enum bt_component_status dummy_init(struct bt_private_component *component,
-               struct bt_value *params, UNUSED_VAR void *init_method_data)
+BT_HIDDEN
+bt_self_component_status dummy_init(
+               bt_self_component_sink *component,
+               const bt_value *params,
+               UNUSED_VAR void *init_method_data)
 {
-       enum bt_component_status ret;
+       bt_self_component_status ret;
        struct dummy *dummy = g_new0(struct dummy, 1);
 
        if (!dummy) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
+               ret = BT_SELF_COMPONENT_STATUS_NOMEM;
                goto end;
        }
 
-       dummy->iterators = g_ptr_array_new_with_free_func(
-                       (GDestroyNotify) bt_put);
-       if (!dummy->iterators) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
-               goto end;
-       }
-
-       ret = bt_private_component_set_user_data(component, dummy);
-       if (ret != BT_COMPONENT_STATUS_OK) {
+       ret = bt_self_component_sink_add_input_port(component,
+               "in", NULL, NULL);
+       if (ret != BT_SELF_COMPONENT_STATUS_OK) {
                goto error;
        }
-end:
-       return ret;
+
+       bt_self_component_set_data(
+               bt_self_component_sink_as_self_component(component), dummy);
+       goto end;
+
 error:
        destroy_private_dummy_data(dummy);
+
+end:
        return ret;
 }
 
-enum bt_component_status dummy_accept_port_connection(
-               struct bt_private_component *component,
-               struct bt_private_port *self_port,
-               struct bt_port *other_port)
+BT_HIDDEN
+bt_self_component_status dummy_graph_is_configured(
+               bt_self_component_sink *comp)
 {
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
        struct dummy *dummy;
-       struct bt_notification_iterator *iterator;
-       struct bt_private_connection *connection;
-
-       dummy = bt_private_component_get_user_data(component);
-       assert(dummy);
-
-       connection = bt_private_port_get_private_connection(self_port);
-       assert(connection);
-
-       iterator = bt_private_connection_create_notification_iterator(
-               connection);
+       bt_self_component_port_input_message_iterator *iterator;
+
+       dummy = bt_self_component_get_data(
+               bt_self_component_sink_as_self_component(comp));
+       BT_ASSERT(dummy);
+       iterator = bt_self_component_port_input_message_iterator_create(
+               bt_self_component_sink_borrow_input_port_by_name(comp,
+                       in_port_name));
        if (!iterator) {
-               ret = BT_COMPONENT_STATUS_ERROR;
+               status = BT_SELF_COMPONENT_STATUS_NOMEM;
                goto end;
        }
 
-       g_ptr_array_add(dummy->iterators, iterator);
+       BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
+               dummy->msg_iter, iterator);
+
 end:
-       bt_put(connection);
-       return ret;
+       return status;
 }
 
-enum bt_component_status dummy_consume(struct bt_private_component *component)
+BT_HIDDEN
+bt_self_component_status dummy_consume(
+               bt_self_component_sink *component)
 {
-       enum bt_component_status ret;
-       struct bt_notification *notif = NULL;
-       size_t i;
+       bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
+       bt_message_array_const msgs;
+       uint64_t count;
        struct dummy *dummy;
+       bt_message_iterator_status it_ret;
+       uint64_t i;
 
-       dummy = bt_private_component_get_user_data(component);
-       assert(dummy);
-
-       /* Consume one notification from each iterator. */
-       for (i = 0; i < dummy->iterators->len; i++) {
-               struct bt_notification_iterator *it;
-               enum bt_notification_iterator_status it_ret;
-
-               it = g_ptr_array_index(dummy->iterators, i);
-
-               it_ret = bt_notification_iterator_next(it);
-               switch (it_ret) {
-               case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
-                       ret = BT_COMPONENT_STATUS_ERROR;
-                       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;
-               }
+       dummy = bt_self_component_get_data(
+               bt_self_component_sink_as_self_component(component));
+       BT_ASSERT(dummy);
+
+       if (unlikely(!dummy->msg_iter)) {
+               ret = BT_SELF_COMPONENT_STATUS_END;
+               goto end;
+       }
 
-               notif = bt_notification_iterator_get_notification(it);
-               if (!notif) {
-                       ret = BT_COMPONENT_STATUS_ERROR;
-                       goto end;
+       /* Consume one message  */
+       it_ret = bt_self_component_port_input_message_iterator_next(
+               dummy->msg_iter, &msgs, &count);
+       switch (it_ret) {
+       case BT_MESSAGE_ITERATOR_STATUS_OK:
+               ret = BT_SELF_COMPONENT_STATUS_OK;
+
+               for (i = 0; i < count; i++) {
+                       bt_message_put_ref(msgs[i]);
                }
 
-               /*
-                * Dummy! I'm doing nothing with this notification,
-                * NOTHING.
-                */
-               BT_PUT(notif);
+               break;
+       case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
+               ret = BT_SELF_COMPONENT_STATUS_AGAIN;
+               goto end;
+       case BT_MESSAGE_ITERATOR_STATUS_END:
+               ret = BT_SELF_COMPONENT_STATUS_END;
+               goto end;
+       case BT_MESSAGE_ITERATOR_STATUS_ERROR:
+               ret = BT_SELF_COMPONENT_STATUS_ERROR;
+               goto end;
+       case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
+               ret = BT_SELF_COMPONENT_STATUS_NOMEM;
+               goto end;
+       default:
+               break;
        }
 
-       if (dummy->iterators->len == 0) {
-               ret = BT_COMPONENT_STATUS_END;
-       }
 end:
-       bt_put(notif);
        return ret;
 }
This page took 0.025425 seconds and 4 git commands to generate.