4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Connectors non-inline non-template implementation */
26 #include "Connectors.hh"
27 #include "Connectors.ih"
32 #include "ModuleManager.hh"
34 //#include "Connectors.mpp"
36 ///////////////////////////////cc.p////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////
39 // senf::ppi::connector::Connector
41 prefix_ void senf::ppi::connector::Connector::connect(Connector & target)
43 // The connector is not registered -> route() or noroute() statement missing
44 SENF_ASSERT( module_ &&
45 "senf::ppi::connector::Connector::connect(): (source) "
46 "Missing route() or noroute()" );
47 // The connector is already connected
48 SENF_ASSERT( ! peer_ &&
49 "senf::ppi::connector::Connector::connect(): (source) "
50 "duplicate connection" );
51 // The target connector is not registered -> route() or noroute() statement missing
52 SENF_ASSERT( target.module_ &&
53 "senf::ppi::connector::Connector::connect(): (target) "
54 "Missing route() or noroute()" );
55 // The target connector is already connected
56 SENF_ASSERT( ! target.peer_ &&
57 "senf::ppi::connector::Connector::connect(): (target) "
58 "duplicate connection" );
59 if (! (packetTypeID() == typeid(void) ||
60 target.packetTypeID() == typeid(void) ||
61 packetTypeID() == target.packetTypeID()) )
62 throw IncompatibleConnectorsException()
63 << ": " << prettyName(packetTypeID())
64 << " [in module " << prettyName(typeid(*module_)) << "] "
65 << ", " << prettyName(target.packetTypeID())
66 << " [in module " << prettyName(typeid(*target.module_)) << "]";
71 if (! initializationScheduled())
72 enqueueInitializable();
73 if (! peer().initializationScheduled())
74 peer().enqueueInitializable();
77 prefix_ void senf::ppi::connector::Connector::disconnect()
79 // Cannot disconnected a non-connected connector
81 "senf::ppi::connector::Connector::disconnect(): Not connected" );
82 Connector & peer (*peer_);
86 if (! initializationScheduled())
87 enqueueInitializable();
88 if (! peer.initializationScheduled())
89 peer.enqueueInitializable();
92 prefix_ std::type_info const & senf::ppi::connector::Connector::packetTypeID()
97 ///////////////////////////////////////////////////////////////////////////
98 // senf::ppi::connector::PassiveConnector
100 ////////////////////////////////////////
103 prefix_ void senf::ppi::connector::PassiveConnector::v_init()
105 Routes::const_iterator i (routes_.begin());
106 Routes::const_iterator const i_end (routes_.end());
107 for (; i != i_end; ++i)
108 if ((*i)->throttled())
111 remoteThrottled_ = false;
118 prefix_ void senf::ppi::connector::PassiveConnector::v_unthrottleEvent()
121 prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle()
123 if (std::find_if(routes_.begin(), routes_.end(),
124 boost::bind(&ForwardingRoute::throttled, _1)) == routes_.end()) {
125 remoteThrottled_ = false;
126 if (!nativeThrottled_)
131 ///////////////////////////////////////////////////////////////////////////
132 // senf::ppi::connector::ActiveConnector
134 ////////////////////////////////////////
137 prefix_ void senf::ppi::connector::ActiveConnector::v_init()
143 prefix_ void senf::ppi::connector::ActiveConnector::notifyThrottle()
147 if (throttleCallback_)
149 NotifyRoutes::const_iterator i (notifyRoutes_.begin());
150 NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
151 for (; i != i_end; ++i)
152 (*i)->notifyThrottle();
156 prefix_ void senf::ppi::connector::ActiveConnector::notifyUnthrottle()
160 if (unthrottleCallback_)
161 unthrottleCallback_();
162 NotifyRoutes::const_iterator i (notifyRoutes_.begin());
163 NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
164 for (; i != i_end; ++i)
165 (*i)->notifyUnthrottle();
169 prefix_ void senf::ppi::connector::ActiveConnector::registerRoute(ForwardingRoute & route)
171 notifyRoutes_.push_back(&route);
174 ///////////////////////////////////////////////////////////////////////////
175 // senf::ppi::connector::InputConnector
177 prefix_ senf::Packet senf::ppi::connector::InputConnector::operator()()
190 ////////////////////////////////////////
193 prefix_ void senf::ppi::connector::InputConnector::v_requestEvent()
196 prefix_ void senf::ppi::connector::InputConnector::v_enqueueEvent()
199 prefix_ void senf::ppi::connector::InputConnector::v_dequeueEvent()
202 ///////////////////////////////////////////////////////////////////////////
203 // senf::ppi::connector::GenericActiveInput
205 ////////////////////////////////////////
208 prefix_ void senf::ppi::connector::GenericActiveInput::v_requestEvent()
213 ///////////////////////////////////////////////////////////////////////////
214 // senf::ppi::connector::GenericPassiveInput
216 ////////////////////////////////////////
219 prefix_ void senf::ppi::connector::GenericPassiveInput::v_enqueueEvent()
222 qdisc_->update(*this, QueueingDiscipline::ENQUEUE);
225 prefix_ void senf::ppi::connector::GenericPassiveInput::v_dequeueEvent()
227 qdisc_->update(*this, QueueingDiscipline::DEQUEUE);
230 prefix_ void senf::ppi::connector::GenericPassiveInput::v_unthrottleEvent()
232 size_type n (queueSize());
235 size_type nn (queueSize());
242 ///////////////////////////////cc.e////////////////////////////////////////
244 //#include "Connectors.mpp"
250 // comment-column: 40
251 // c-file-style: "senf"
252 // indent-tabs-mode: nil
253 // ispell-local-dictionary: "american"
254 // compile-command: "scons -u test"