X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FConnectors.cc;h=22f39296691b132ecee76ebb2d22272eec171450;hb=f2f5d59e83863f3b513950173baee1b6da2aee3c;hp=e11e5e23307733c50042d1524458d40c59dfab36;hpb=8aa27cfde664f462f1aebd601f1521c186d819c3;p=senf.git diff --git a/PPI/Connectors.cc b/PPI/Connectors.cc index e11e5e2..22f3929 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,14 @@ 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_ ); + // The connector is already connected + SENF_ASSERT( ! peer_ ); + // The target connector is not registered -> route() or noroute() statement missing + SENF_ASSERT( target.module_ ); + // The target connector is already connected + SENF_ASSERT( ! target.peer_ ); if (! (packetTypeID() == typeid(void) || target.packetTypeID() == typeid(void) || packetTypeID() == target.packetTypeID()) ) @@ -51,6 +59,25 @@ 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_ ); + 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() @@ -64,6 +91,24 @@ prefix_ std::type_info const & senf::ppi::connector::Connector::packetTypeID() //////////////////////////////////////// // private members +prefix_ void senf::ppi::connector::PassiveConnector::v_init() +{ + 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 (throttled() && !nativeThrottled_) { @@ -87,24 +132,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)