X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fcomponent-class-sink-colander.c;fp=lib%2Fgraph%2Fcomponent-class-sink-colander.c;h=a40f8ea09e813122840db65c8e094aef3fa72bf5;hb=d94d92ac6656fd252a5d7bb4f6c76935ba18e62e;hp=f1067d41afa334c5c87c52de88dd65605a815d29;hpb=28e6ca8b6e08d1cdd1af81ae819aa39baa206eaf;p=babeltrace.git diff --git a/lib/graph/component-class-sink-colander.c b/lib/graph/component-class-sink-colander.c index f1067d41..a40f8ea0 100644 --- a/lib/graph/component-class-sink-colander.c +++ b/lib/graph/component-class-sink-colander.c @@ -25,138 +25,140 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include static -struct bt_component_class *colander_comp_cls; +struct bt_private_component_class_sink *colander_comp_cls; struct colander_data { bt_notification_array notifs; uint64_t *count_addr; - struct bt_notification_iterator *notif_iter; + struct bt_self_component_port_input_notification_iterator *notif_iter; }; static -enum bt_component_status colander_init( - struct bt_private_component *priv_comp, +enum bt_self_component_status colander_init( + struct bt_self_component_sink *self_comp, struct bt_value *params, void *init_method_data) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct colander_data *colander_data = NULL; struct bt_component_class_sink_colander_data *user_provided_data = init_method_data; if (!init_method_data) { BT_LOGW_STR("Component initialization method data is NULL."); - status = BT_COMPONENT_STATUS_INVALID; + status = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } colander_data = g_new0(struct colander_data, 1); if (!colander_data) { BT_LOGE_STR("Failed to allocate colander data."); - status = BT_COMPONENT_STATUS_NOMEM; + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } colander_data->notifs = user_provided_data->notifs; colander_data->count_addr = user_provided_data->count_addr; - status = bt_private_component_sink_add_input_port( - priv_comp, "in", NULL, NULL); - if (status != BT_COMPONENT_STATUS_OK) { + status = bt_self_component_sink_add_input_port(self_comp, "in", + NULL, NULL); + if (status != BT_SELF_COMPONENT_STATUS_OK) { BT_LOGE_STR("Cannot add input port."); goto end; } - (void) bt_private_component_set_user_data(priv_comp, colander_data); + bt_self_component_set_data( + bt_self_component_sink_borrow_self_component(self_comp), + colander_data); end: return status; } static -void colander_finalize(struct bt_private_component *priv_comp) +void colander_finalize(struct bt_self_component_sink *self_comp) { struct colander_data *colander_data = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(self_comp)); if (!colander_data) { return; } - if (colander_data->notif_iter) { - bt_object_put_ref(colander_data->notif_iter); - } - + BT_OBJECT_PUT_REF_AND_RESET(colander_data->notif_iter); g_free(colander_data); } static -enum bt_component_status colander_port_connected(struct bt_private_component *priv_comp, - struct bt_private_port *self_priv_port, - struct bt_port *other_port) +enum bt_self_component_status colander_input_port_connected( + struct bt_self_component_sink *self_comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - enum bt_connection_status conn_status; - struct bt_private_connection *priv_conn = - bt_private_port_get_connection(self_priv_port); + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct colander_data *colander_data = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(self_comp)); - BT_ASSERT(priv_conn); BT_ASSERT(colander_data); BT_OBJECT_PUT_REF_AND_RESET(colander_data->notif_iter); - conn_status = bt_private_connection_create_notification_iterator( - priv_conn, &colander_data->notif_iter); - if (conn_status) { - BT_LOGE("Cannot create notification iterator from connection: " - "comp-addr=%p, conn-addr=%p", priv_comp, priv_conn); - status = BT_COMPONENT_STATUS_ERROR; + colander_data->notif_iter = + bt_self_component_port_input_notification_iterator_create( + self_port); + if (!colander_data->notif_iter) { + BT_LIB_LOGE("Cannot create notification iterator on " + "self component input port: %![port-]+p", + self_port); + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } end: - bt_object_put_ref(priv_conn); return status; } static -enum bt_component_status colander_consume( - struct bt_private_component *priv_comp) +enum bt_self_component_status colander_consume( + struct bt_self_component_sink *self_comp) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; enum bt_notification_iterator_status notif_iter_status; struct colander_data *colander_data = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(self_comp)); bt_notification_array notifs; BT_ASSERT(colander_data); if (!colander_data->notif_iter) { - BT_LOGW("Trying to consume without an upstream notification iterator: " - "comp-addr=%p", priv_comp); + BT_LIB_LOGW("Trying to consume without an " + "upstream notification iterator: %![comp-]+c", + self_comp); goto end; } - notif_iter_status = bt_private_connection_notification_iterator_next( - colander_data->notif_iter, ¬ifs, colander_data->count_addr); + notif_iter_status = + bt_self_component_port_input_notification_iterator_next( + colander_data->notif_iter, ¬ifs, + colander_data->count_addr); switch (notif_iter_status) { case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED: - status = BT_COMPONENT_STATUS_OK; + status = BT_SELF_COMPONENT_STATUS_OK; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - status = BT_COMPONENT_STATUS_AGAIN; + status = BT_SELF_COMPONENT_STATUS_AGAIN; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_END: - status = BT_COMPONENT_STATUS_END; + status = BT_SELF_COMPONENT_STATUS_END; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_OK: /* Move notifications to user (count already set) */ @@ -164,38 +166,38 @@ enum bt_component_status colander_consume( sizeof(*notifs) * *colander_data->count_addr); break; default: - status = BT_COMPONENT_STATUS_ERROR; + status = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } end: - /* Move notification to user's pointer, even if NULL. */ return status; } -struct bt_component_class *bt_component_class_sink_colander_get(void) +struct bt_component_class_sink *bt_component_class_sink_colander_get(void) { if (colander_comp_cls) { goto end; } - colander_comp_cls = bt_component_class_sink_create("colander", - colander_consume); + colander_comp_cls = bt_private_component_class_sink_create( + "colander", colander_consume); if (!colander_comp_cls) { BT_LOGE_STR("Cannot create sink colander component class."); goto end; } - (void) bt_component_class_set_init_method(colander_comp_cls, - colander_init); - (void) bt_component_class_set_finalize_method(colander_comp_cls, - colander_finalize); - (void) bt_component_class_set_port_connected_method(colander_comp_cls, - colander_port_connected); - (void) bt_component_class_freeze(colander_comp_cls); + (void) bt_private_component_class_sink_set_init_method( + colander_comp_cls, colander_init); + (void) bt_private_component_class_sink_set_finalize_method( + colander_comp_cls, colander_finalize); + (void) bt_private_component_class_sink_set_input_port_connected_method( + colander_comp_cls, colander_input_port_connected); end: - return bt_object_get_ref(colander_comp_cls); + return bt_object_get_ref( + bt_private_component_class_sink_borrow_component_class_sink( + colander_comp_cls)); } __attribute__((destructor)) static