* 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/private-connection.h>
-#include <babeltrace/component/component-sink.h>
-#include <babeltrace/component/notification/iterator.h>
-#include <babeltrace/component/notification/notification.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/babeltrace-internal.h>
#include <plugins-common.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include "dummy.h"
-static
void destroy_private_dummy_data(struct dummy *dummy)
{
- if (dummy->iterators) {
- g_ptr_array_free(dummy->iterators, TRUE);
- }
+ bt_put(dummy->notif_iter);
g_free(dummy);
}
-void dummy_destroy(struct bt_private_component *component)
+void dummy_finalize(struct bt_private_component *component)
{
struct dummy *dummy;
- assert(component);
+ BT_ASSERT(component);
dummy = bt_private_component_get_user_data(component);
- assert(dummy);
+ BT_ASSERT(dummy);
destroy_private_dummy_data(dummy);
}
goto end;
}
- dummy->iterators = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_put);
- if (!dummy->iterators) {
- ret = BT_COMPONENT_STATUS_NOMEM;
+ ret = bt_private_component_sink_add_input_private_port(component,
+ "in", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
}
if (ret != BT_COMPONENT_STATUS_OK) {
goto error;
}
-end:
- return ret;
+
+ goto end;
+
error:
destroy_private_dummy_data(dummy);
+
+end:
return ret;
}
-enum bt_component_status dummy_accept_port_connection(
+void dummy_port_connected(
struct bt_private_component *component,
- struct bt_private_port *self_port)
+ 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_notification_iterator *iterator;
struct bt_private_connection *connection;
+ enum bt_connection_status conn_status;
dummy = bt_private_component_get_user_data(component);
- assert(dummy);
-
+ BT_ASSERT(dummy);
connection = bt_private_port_get_private_connection(self_port);
- assert(connection);
-
- iterator = bt_private_connection_create_notification_iterator(
- connection);
- if (!iterator) {
- ret = BT_COMPONENT_STATUS_ERROR;
+ BT_ASSERT(connection);
+ conn_status = bt_private_connection_create_notification_iterator(
+ connection, &iterator);
+ if (conn_status != BT_CONNECTION_STATUS_OK) {
+ dummy->error = true;
goto end;
}
- g_ptr_array_add(dummy->iterators, iterator);
+ BT_MOVE(dummy->notif_iter, iterator);
+
end:
bt_put(connection);
- return ret;
}
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;
+ enum bt_notification_iterator_status it_ret;
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;
- }
-
- 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);
+ BT_ASSERT(dummy);
+
+ if (unlikely(dummy->error)) {
+ ret = BT_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
+
+ if (unlikely(!dummy->notif_iter)) {
+ ret = BT_COMPONENT_STATUS_END;
+ goto end;
}
- if (dummy->iterators->len == 0) {
+ /* Consume one notification */
+ it_ret = bt_notification_iterator_next(dummy->notif_iter);
+ switch (it_ret) {
+ 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;
+ goto end;
+ default:
+ break;
}
+
end:
bt_put(notif);
return ret;