X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Futils%2Fdummy%2Fdummy.c;h=a2bab43008f978f128d9db05f4d595d18016013c;hb=b19ff26f04df428047676dd736bd7cc9473906fe;hp=c3434a59929b8f1c6b2d71d4f8cd7405f9d8de77;hpb=73d5c1adb1411e16c9c613c38a4c74a29ee608ae;p=babeltrace.git diff --git a/plugins/utils/dummy/dummy.c b/plugins/utils/dummy/dummy.c index c3434a59..a2bab430 100644 --- a/plugins/utils/dummy/dummy.c +++ b/plugins/utils/dummy/dummy.c @@ -20,146 +20,137 @@ * SOFTWARE. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include -#include +#include #include "dummy.h" -static void destroy_private_dummy_data(struct dummy *dummy) { - if (dummy->iterators) { - g_ptr_array_free(dummy->iterators, TRUE); - } + bt_self_component_port_input_notification_iterator_put_ref(dummy->notif_iter); g_free(dummy); + } -void dummy_finalize(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 +enum 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; + enum 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; } - ret = bt_private_component_sink_add_input_private_port(component, + ret = bt_self_component_sink_add_input_port(component, "in", NULL, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; + if (ret != BT_SELF_COMPONENT_STATUS_OK) { + goto error; } - dummy->iterators = g_ptr_array_new_with_free_func( - (GDestroyNotify) bt_put); - if (!dummy->iterators) { - ret = BT_COMPONENT_STATUS_NOMEM; - goto end; - } + bt_self_component_set_data( + bt_self_component_sink_as_self_component(component), dummy); + goto end; - ret = bt_private_component_set_user_data(component, dummy); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } -end: - return ret; error: destroy_private_dummy_data(dummy); + +end: return ret; } -void dummy_port_connected( - struct bt_private_component *component, - struct bt_private_port *self_port, - struct bt_port *other_port) +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; - 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); - connection = bt_private_port_get_private_connection(self_port); - assert(connection); - conn_status = bt_private_connection_create_notification_iterator( - connection, NULL, &iterator); - if (conn_status != BT_CONNECTION_STATUS_OK) { - dummy->error = true; + bt_self_component_port_input_notification_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_notification_iterator_create( + self_port); + if (!iterator) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } - g_ptr_array_add(dummy->iterators, iterator); + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_MOVE_REF( + dummy->notif_iter, iterator); end: - bt_put(connection); + return status; } -enum bt_component_status dummy_consume(struct bt_private_component *component) +BT_HIDDEN +enum bt_self_component_status dummy_consume( + bt_self_component_sink *component) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_notification *notif = NULL; - size_t i; + enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; + bt_notification_array_const notifs; + uint64_t count; struct dummy *dummy; + enum bt_notification_iterator_status it_ret; + uint64_t i; - dummy = bt_private_component_get_user_data(component); - assert(dummy); + dummy = bt_self_component_get_data( + bt_self_component_sink_as_self_component(component)); + BT_ASSERT(dummy); - if (unlikely(dummy->error)) { - ret = BT_COMPONENT_STATUS_ERROR; + if (unlikely(!dummy->notif_iter)) { + ret = BT_SELF_COMPONENT_STATUS_END; goto end; } - /* 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_AGAIN: - ret = BT_COMPONENT_STATUS_AGAIN; - goto end; - case BT_NOTIFICATION_ITERATOR_STATUS_END: - g_ptr_array_remove_index(dummy->iterators, i); - i--; - continue; - default: - break; + /* Consume one notification */ + it_ret = bt_self_component_port_input_notification_iterator_next( + dummy->notif_iter, ¬ifs, &count); + switch (it_ret) { + case BT_NOTIFICATION_ITERATOR_STATUS_OK: + ret = BT_SELF_COMPONENT_STATUS_OK; + + for (i = 0; i < count; i++) { + bt_notification_put_ref(notifs[i]); } - } - if (dummy->iterators->len == 0) { - ret = BT_COMPONENT_STATUS_END; + break; + case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: + ret = BT_SELF_COMPONENT_STATUS_AGAIN; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_END: + ret = BT_SELF_COMPONENT_STATUS_END; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: + ret = BT_SELF_COMPONENT_STATUS_ERROR; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: + ret = BT_SELF_COMPONENT_STATUS_NOMEM; + goto end; + default: + break; } + end: - bt_put(notif); return ret; }