X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FConnectors.cc;h=6c1dade6bc3da79006227b3a4d85298c2cfe133b;hb=af1d0936ba912bb301ac6604965df5b28d79c63e;hp=5c4ceff4e3a4553f49049e74250cb31ca89218b7;hpb=17d44437f7fb8ee68a96ed55fc327c746c161142;p=senf.git diff --git a/PPI/Connectors.cc b/PPI/Connectors.cc index 5c4ceff..6c1dade 100644 --- a/PPI/Connectors.cc +++ b/PPI/Connectors.cc @@ -29,6 +29,7 @@ // Custom includes #include "Route.hh" #include "Module.hh" +#include "ModuleManager.hh" //#include "Connectors.mpp" #define prefix_ @@ -39,7 +40,22 @@ prefix_ void senf::ppi::connector::Connector::connect(Connector & target) { - SENF_ASSERT( module_ && ! peer_ && target.module_ && ! target.peer_ ); + // The connector is not registered -> route() or noroute() statement missing + SENF_ASSERT( module_ && + "senf::ppi::connector::Connector::connect(): (source) " + "Missing route() or noroute()" ); + // The connector is already connected + SENF_ASSERT( ! peer_ && + "senf::ppi::connector::Connector::connect(): (source) " + "duplicate connection" ); + // The target connector is not registered -> route() or noroute() statement missing + SENF_ASSERT( target.module_ && + "senf::ppi::connector::Connector::connect(): (target) " + "Missing route() or noroute()" ); + // The target connector is already connected + SENF_ASSERT( ! target.peer_ && + "senf::ppi::connector::Connector::connect(): (target) " + "duplicate connection" ); if (! (packetTypeID() == typeid(void) || target.packetTypeID() == typeid(void) || packetTypeID() == target.packetTypeID()) ) @@ -51,6 +67,31 @@ prefix_ void senf::ppi::connector::Connector::connect(Connector & target) peer_ = & target; target.peer_ = this; + + if (! initializationScheduled()) + enqueueInitializable(); + if (! peer().initializationScheduled()) + peer().enqueueInitializable(); +} + +prefix_ void senf::ppi::connector::Connector::disconnect() +{ + // Cannot disconnected a non-connected connector + SENF_ASSERT( peer_ && + "senf::ppi::connector::Connector::disconnect(): Not connected" ); + Connector & peer (*peer_); + peer_ = 0; + peer.peer_ = 0; + + if (! initializationScheduled()) + enqueueInitializable(); + if (! peer.initializationScheduled()) + peer.enqueueInitializable(); +} + +prefix_ std::type_info const & senf::ppi::connector::Connector::packetTypeID() +{ + return typeid(void); } /////////////////////////////////////////////////////////////////////////// @@ -59,21 +100,32 @@ prefix_ void senf::ppi::connector::Connector::connect(Connector & target) //////////////////////////////////////// // private members -prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle() +prefix_ void senf::ppi::connector::PassiveConnector::v_init() { - if (throttled() && !nativeThrottled_) { - Routes::const_iterator i (routes_.begin()); - Routes::const_iterator const i_end (routes_.end()); - for (; i != i_end; ++i) - if ((*i)->throttled()) - break; - if (i == i_end) { - remoteThrottled_ = false; - emitUnthrottle(); - } - } + Routes::const_iterator i (routes_.begin()); + Routes::const_iterator const i_end (routes_.end()); + for (; i != i_end; ++i) + if ((*i)->throttled()) + break; + if (i == i_end) + remoteThrottled_ = false; + if (throttled()) + emitThrottle(); else + emitUnthrottle(); +} + +prefix_ void senf::ppi::connector::PassiveConnector::v_unthrottleEvent() +{} + +prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle() +{ + if (std::find_if(routes_.begin(), routes_.end(), + boost::bind(&ForwardingRoute::throttled, _1)) == routes_.end()) { remoteThrottled_ = false; + if (!nativeThrottled_) + emitUnthrottle(); + } } /////////////////////////////////////////////////////////////////////////// @@ -82,24 +134,36 @@ prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle() //////////////////////////////////////// // private members +prefix_ void senf::ppi::connector::ActiveConnector::v_init() +{ + if (! connected()) + notifyThrottle(); +} + prefix_ void senf::ppi::connector::ActiveConnector::notifyThrottle() { - if (throttleCallback_) - throttleCallback_(); - NotifyRoutes::const_iterator i (notifyRoutes_.begin()); - NotifyRoutes::const_iterator const i_end (notifyRoutes_.end()); - for (; i != i_end; ++i) - (*i)->notifyThrottle(); + if (! throttled_) { + throttled_ = true; + if (throttleCallback_) + throttleCallback_(); + NotifyRoutes::const_iterator i (notifyRoutes_.begin()); + NotifyRoutes::const_iterator const i_end (notifyRoutes_.end()); + for (; i != i_end; ++i) + (*i)->notifyThrottle(); + } } prefix_ void senf::ppi::connector::ActiveConnector::notifyUnthrottle() { - if (unthrottleCallback_) - unthrottleCallback_(); - NotifyRoutes::const_iterator i (notifyRoutes_.begin()); - NotifyRoutes::const_iterator const i_end (notifyRoutes_.end()); - for (; i != i_end; ++i) - (*i)->notifyUnthrottle(); + if (throttled_) { + throttled_ = false; + if (unthrottleCallback_) + unthrottleCallback_(); + NotifyRoutes::const_iterator i (notifyRoutes_.begin()); + NotifyRoutes::const_iterator const i_end (notifyRoutes_.end()); + for (; i != i_end; ++i) + (*i)->notifyUnthrottle(); + } } prefix_ void senf::ppi::connector::ActiveConnector::registerRoute(ForwardingRoute & route)