* SOFTWARE.
*/
-#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 <assert.h>
-
-enum bt_component_status dummy_consume(struct bt_component *component)
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <plugins-common.h>
+#include <babeltrace/assert-internal.h>
+#include "dummy.h"
+
+void destroy_private_dummy_data(struct dummy *dummy)
{
- 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;
-
- ret = bt_component_sink_get_input_count(component, &it_count);
- assert(ret == 0);
-
- for (i = 0; i < it_count; i++) {
- enum bt_notification_iterator_status it_ret;
-
- ret = bt_component_sink_get_input_iterator(component, i, &it);
- assert(ret == 0);
- 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;
- BT_PUT(it);
- continue;
- default:
- break;
- }
+ bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter);
+ g_free(dummy);
- notif = bt_notification_iterator_get_notification(it);
- if (!notif) {
- ret = BT_COMPONENT_STATUS_ERROR;
- goto end;
- }
+}
+
+BT_HIDDEN
+void dummy_finalize(bt_self_component_sink *comp)
+{
+ struct dummy *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);
+}
+
+BT_HIDDEN
+enum bt_self_component_status dummy_init(
+ bt_self_component_sink *component,
+ const bt_value *params,
+ UNUSED_VAR void *init_method_data)
+{
+ enum bt_self_component_status ret;
+ struct dummy *dummy = g_new0(struct dummy, 1);
+
+ if (!dummy) {
+ ret = BT_SELF_COMPONENT_STATUS_NOMEM;
+ goto end;
+ }
+
+ ret = bt_self_component_sink_add_input_port(component,
+ "in", NULL, NULL);
+ if (ret != BT_SELF_COMPONENT_STATUS_OK) {
+ goto error;
+ }
+
+ 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;
+}
+
+BT_HIDDEN
+enum bt_self_component_status dummy_port_connected(
+ bt_self_component_sink *comp,
+ bt_self_component_port_input *self_port,
+ const bt_port_output *other_port)
+{
+ enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
+ struct dummy *dummy;
+ bt_self_component_port_input_message_iterator *iterator;
- /*
- * Dummy! I'm doing nothing with this notification,
- * NOTHING.
- */
- got_one = true;
- BT_PUT(it);
- BT_PUT(notif);
+ 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(
+ self_port);
+ if (!iterator) {
+ status = BT_SELF_COMPONENT_STATUS_NOMEM;
+ goto end;
}
- if (!got_one) {
- ret = BT_COMPONENT_STATUS_END;
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
+ dummy->msg_iter, iterator);
+
+end:
+ return status;
+}
+
+BT_HIDDEN
+enum bt_self_component_status dummy_consume(
+ bt_self_component_sink *component)
+{
+ enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
+ bt_message_array_const msgs;
+ uint64_t count;
+ struct dummy *dummy;
+ enum bt_message_iterator_status it_ret;
+ uint64_t i;
+
+ 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;
+ }
+
+ /* 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]);
+ }
+
+ 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;
}
end:
- bt_put(it);
- bt_put(notif);
return ret;
}