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

index 66b29968a6f5ecbf0418e14975a4b425e93a4a9e..d9ce97af03fac11a691ac1656d2e285a4c068e6a 100644 (file)
 #include <babeltrace/component/component-sink.h>
 #include <babeltrace/component/notification/iterator.h>
 #include <babeltrace/component/notification/notification.h>
+#include <plugins-common.h>
 #include <assert.h>
+#include "dummy.h"
+
+static
+void destroy_private_dummy_data(struct dummy *dummy)
+{
+       if (dummy->iterators) {
+               g_ptr_array_free(dummy->iterators, TRUE);
+       }
+       g_free(dummy);
+}
+
+void dummy_destroy(struct bt_component *component)
+{
+       struct dummy *dummy;
+
+       assert(component);
+       dummy = bt_component_get_private_data(component);
+       assert(dummy);
+       destroy_private_dummy_data(dummy);
+}
+
+enum bt_component_status dummy_init(struct bt_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);
+
+       if (!dummy) {
+               ret = BT_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_component_set_private_data(component, dummy);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+end:
+       return ret;
+error:
+       destroy_private_dummy_data(dummy);
+       return ret;
+}
+
+enum bt_component_status dummy_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 dummy *dummy;
+       struct bt_notification_iterator *iterator;
+
+       component = bt_port_get_component(own_port);
+       assert(component);
+
+       dummy = bt_component_get_private_data(component);
+       assert(dummy);
+
+       iterator = bt_connection_create_notification_iterator(connection);
+       if (!iterator) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+
+       g_ptr_array_add(dummy->iterators, iterator);
+end:
+       bt_put(component);
+       return ret;
+}
 
 enum bt_component_status dummy_consume(struct bt_component *component)
 {
        enum bt_component_status ret;
        struct bt_notification *notif = NULL;
-       struct bt_notification_iterator *it = NULL;
-       unsigned int it_count;
        size_t i;
-       bool got_one = false;
+       struct dummy *dummy;
 
-       ret = bt_component_sink_get_input_count(component, &it_count);
-       assert(ret == 0);
+       dummy = bt_component_get_private_data(component);
+       assert(dummy);
 
-       for (i = 0; i < it_count; i++) {
+       /* 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;
 
-               ret = bt_component_sink_get_input_iterator(component, i, &it);
-               assert(ret == 0);
+               it = g_ptr_array_index(dummy->iterators, i);
+
                it_ret = bt_notification_iterator_next(it);
                switch (it_ret) {
                case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
@@ -51,7 +127,8 @@ enum bt_component_status dummy_consume(struct bt_component *component)
                        goto end;
                case BT_NOTIFICATION_ITERATOR_STATUS_END:
                        ret = BT_COMPONENT_STATUS_END;
-                       BT_PUT(it);
+                       g_ptr_array_remove_index(dummy->iterators, i);
+                       i--;
                        continue;
                default:
                        break;
@@ -67,17 +144,13 @@ enum bt_component_status dummy_consume(struct bt_component *component)
                 * Dummy! I'm doing nothing with this notification,
                 * NOTHING.
                 */
-               got_one = true;
-               BT_PUT(it);
                BT_PUT(notif);
        }
 
-       if (!got_one) {
+       if (dummy->iterators->len == 0) {
                ret = BT_COMPONENT_STATUS_END;
        }
-
 end:
-       bt_put(it);
        bt_put(notif);
        return ret;
 }
index 2fcf34be97651b809a4e135921f4f7ff4d6aaa31..a0c674e31d4e6d9faca200a89919d329bcc16583 100644 (file)
  * SOFTWARE.
  */
 
+#include <glib.h>
+#include <babeltrace/component/component.h>
+#include <babeltrace/component/component-port.h>
+#include <babeltrace/component/component-connection.h>
+
+struct dummy {
+       GPtrArray *iterators;
+};
+
+enum bt_component_status dummy_init(struct bt_component *component,
+               struct bt_value *params, void *init_method_data);
+void dummy_destroy(struct bt_component *component);
+enum bt_component_status dummy_new_connection(struct bt_port *own_port,
+               struct bt_connection *connection);
 enum bt_component_status dummy_consume(struct bt_component *component);
 
 #endif /* BABELTRACE_PLUGINS_UTILS_DUMMY_H */
index de25342ce0b52c41f90ec217f01bd55fb5bb5344..8918ce94c6dc183fe81c5e56a11ade4758760216 100644 (file)
@@ -32,6 +32,9 @@ BT_PLUGIN_LICENSE("MIT");
 
 /* dummy sink */
 BT_PLUGIN_SINK_COMPONENT_CLASS(dummy, dummy_consume);
+BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(dummy, dummy_init);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(dummy, dummy_destroy);
+BT_PLUGIN_SINK_COMPONENT_CLASS_NEW_CONNECTION_METHOD(dummy, dummy_new_connection);
 BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(dummy,
     "Dummy sink component class: does absolutely nothing!");
 
This page took 0.026792 seconds and 4 git commands to generate.