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"
33 #include <senf/Utils/Console/Console.hh>
35 //#include "Connectors.mpp"
37 ///////////////////////////////cc.p////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////
40 // senf::ppi::connector::Connector
42 prefix_ senf::ppi::connector::Connector::~Connector()
45 Connector & peer (*peer_);
47 if (! peer.initializationScheduled())
48 peer.enqueueInitializable();
49 peer.v_disconnected();
53 prefix_ void senf::ppi::connector::Connector::connect(Connector & target)
55 // The connector is not registered -> route() or noroute() statement missing
57 "senf::ppi::connector::Connector::connect(): (source) "
58 "Missing route() or noroute()" );
59 // The connector is already connected
61 "senf::ppi::connector::Connector::connect(): (source) "
62 "duplicate connection" );
63 // The target connector is not registered -> route() or noroute() statement missing
64 SENF_ASSERT( target.module_,
65 "senf::ppi::connector::Connector::connect(): (target) "
66 "Missing route() or noroute()" );
67 // The target connector is already connected
68 SENF_ASSERT( ! target.peer_,
69 "senf::ppi::connector::Connector::connect(): (target) "
70 "duplicate connection" );
71 if (! (packetTypeID() == typeid(void) ||
72 target.packetTypeID() == typeid(void) ||
73 packetTypeID() == target.packetTypeID()) )
74 throw IncompatibleConnectorsException()
75 << ": " << prettyName(packetTypeID())
76 << " [in module " << prettyName(typeid(*module_)) << "] "
77 << ", " << prettyName(target.packetTypeID())
78 << " [in module " << prettyName(typeid(*target.module_)) << "]";
83 if (! initializationScheduled())
84 enqueueInitializable();
85 if (! peer().initializationScheduled())
86 peer().enqueueInitializable();
89 senf::ppi::connector::Connector::TraceState senf::ppi::connector::Connector::traceState_ (
90 senf::ppi::connector::Connector::NO_TRACING);
92 prefix_ void senf::ppi::connector::Connector::trace(Packet const & p, char const * label)
94 if (traceState_ == NO_TRACING)
97 std::string type (prettyName(p.typeId().id()));
98 log << "PPI packet trace: " << label << " 0x" << std::hex << p.id() << " "
99 << type.substr(21, type.size()-22) << " on " << & module() << " "
100 << prettyName(typeid(module())) << " connector 0x" << this << "\n";
101 if (traceState_ == TRACE_CONTENTS)
106 prefix_ void senf::ppi::connector::Connector::throttleTrace(char const * label,
109 if (traceState_ == NO_TRACING)
112 log << "PPI throttling trace: " << label << " " << type << " on " << & module()
113 << " " << prettyName(typeid(module())) << " connector 0x" << this << "\n";
117 namespace senf { namespace ppi { namespace connector {
119 SENF_CONSOLE_REGISTER_ENUM_MEMBER(
120 Connector, TraceState, (NO_TRACING)(TRACE_IDS)(TRACE_CONTENTS) );
126 struct ConsoleRegister
131 ConsoleRegister::ConsoleRegister()
133 #ifndef SENF_PPI_NOTRACE
134 senf::ppi::ModuleManager::instance().consoleDir()
135 .add("tracing", senf::console::factory::Command(
136 SENF_FNP(senf::ppi::connector::Connector::TraceState,
137 senf::ppi::connector::Connector::tracing, ()))
138 .doc("Log every packet sent or received by any module.\n"
139 "There are three different tracing levels:\n"
141 " NO_TRACING don't output any tracing information\n"
142 " TRACE_IDS trace packet id's but do not show packet contents\n"
143 " TRACE_CONTENTS trace complete packet contents\n"
145 "A log message is generated whenever the packet traverses a connector. The\n"
146 "TRACE_IDS log message has the following format:\n"
148 " PPI packet trace: <direction> <packet-id> <packet-type>\n"
149 " on <module-id> <module-type> connector <connector-id>\n"
150 " PPI throttling trace: <direction> <throttle-msg>\n"
151 " on <module-id> <module-type> connector <connector-id>\n"
155 " direction 'IN' for packets/throttle notifications entering the module,\n"
156 " 'OUT' for packets/throttle notifications leaving it\n"
157 " packet-id Numeric unique packet id. This value is unique for packets\n"
158 " alive at the same time, packets at different times may (and\n"
159 " will) share id's\n"
160 " packet-type The type of the packet header\n"
161 " module-id Unique module id\n"
162 " module-type Type of the module the packet is sent to/from\n"
163 " connector-id Unique connector id\n"
164 " throttle-msg Type of throttling event\n")
167 senf::ppi::ModuleManager::instance().consoleDir()
168 .add("tracing", senf::console::factory::Command(
169 SENF_FNP(void, senf::ppi::connector::Connector::tracing,
170 (senf::ppi::connector::Connector::TraceState)))
171 .arg("state", "new tracing state")
176 ConsoleRegister consoleRegister;
180 prefix_ void senf::ppi::connector::Connector::disconnect()
182 // Cannot disconnected a non-connected connector
184 "senf::ppi::connector::Connector::disconnect(): Not connected" );
186 Connector & peer (*peer_);
190 if (! initializationScheduled())
191 enqueueInitializable();
192 if (! peer.initializationScheduled())
193 peer.enqueueInitializable();
196 peer.v_disconnected();
199 prefix_ std::type_info const & senf::ppi::connector::Connector::packetTypeID()
204 prefix_ void senf::ppi::connector::Connector::v_disconnected()
208 ///////////////////////////////////////////////////////////////////////////
209 // senf::ppi::connector::PassiveConnector
211 ////////////////////////////////////////
214 prefix_ void senf::ppi::connector::PassiveConnector::v_init()
216 Routes::const_iterator i (routes_.begin());
217 Routes::const_iterator const i_end (routes_.end());
218 for (; i != i_end; ++i)
219 if ((*i)->throttled())
222 remoteThrottled_ = false;
229 prefix_ void senf::ppi::connector::PassiveConnector::registerRoute(ForwardingRoute & route)
231 routes_.push_back(&route);
234 prefix_ void senf::ppi::connector::PassiveConnector::unregisterRoute(ForwardingRoute & route)
236 Routes::iterator i (std::find(routes_.begin(), routes_.end(), &route));
237 if (i != routes_.end())
241 prefix_ void senf::ppi::connector::PassiveConnector::v_unthrottleEvent()
244 prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle()
246 if (std::find_if(routes_.begin(), routes_.end(),
247 boost::bind(&ForwardingRoute::throttled, _1)) == routes_.end()) {
248 remoteThrottled_ = false;
249 if (!nativeThrottled_)
252 SENF_PPI_THROTTLE_TRACE("OUT", "not forwarding unthrottle event");
255 ///////////////////////////////////////////////////////////////////////////
256 // senf::ppi::connector::ActiveConnector
258 ////////////////////////////////////////
261 prefix_ void senf::ppi::connector::ActiveConnector::v_init()
267 prefix_ void senf::ppi::connector::ActiveConnector::notifyThrottle()
269 SENF_PPI_THROTTLE_TRACE("IN ", "throttle");
272 if (throttleCallback_)
274 NotifyRoutes::const_iterator i (notifyRoutes_.begin());
275 NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
276 for (; i != i_end; ++i)
277 (*i)->notifyThrottle();
281 prefix_ void senf::ppi::connector::ActiveConnector::notifyUnthrottle()
283 SENF_PPI_THROTTLE_TRACE("IN ", "unthrottle");
286 if (unthrottleCallback_)
287 unthrottleCallback_();
288 NotifyRoutes::const_iterator i (notifyRoutes_.begin());
289 NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
290 for (; i != i_end; ++i)
291 (*i)->notifyUnthrottle();
295 prefix_ void senf::ppi::connector::ActiveConnector::registerRoute(ForwardingRoute & route)
297 notifyRoutes_.push_back(&route);
300 prefix_ void senf::ppi::connector::ActiveConnector::unregisterRoute(ForwardingRoute & route)
302 NotifyRoutes::iterator i (std::find(notifyRoutes_.begin(), notifyRoutes_.end(), &route));
303 if (i != notifyRoutes_.end())
304 notifyRoutes_.erase(i);
307 ///////////////////////////////////////////////////////////////////////////
308 // senf::ppi::connector::InputConnector
310 prefix_ senf::Packet senf::ppi::connector::InputConnector::operator()()
315 Packet p ( queue_.back());
318 SENF_PPI_TRACE(p, "IN ");
321 SENF_PPI_TRACE(Packet(), "IN ");
326 ////////////////////////////////////////
329 prefix_ void senf::ppi::connector::InputConnector::v_requestEvent()
332 prefix_ void senf::ppi::connector::InputConnector::v_enqueueEvent()
335 prefix_ void senf::ppi::connector::InputConnector::v_dequeueEvent()
338 ///////////////////////////////////////////////////////////////////////////
339 // senf::ppi::connector::GenericActiveInput
341 ////////////////////////////////////////
344 prefix_ void senf::ppi::connector::GenericActiveInput::v_requestEvent()
349 ///////////////////////////////////////////////////////////////////////////
350 // senf::ppi::connector::GenericPassiveInput
352 ////////////////////////////////////////
355 prefix_ void senf::ppi::connector::GenericPassiveInput::v_enqueueEvent()
359 qdisc_->update(*this, QueueingDiscipline::ENQUEUE);
362 prefix_ void senf::ppi::connector::GenericPassiveInput::v_dequeueEvent()
365 qdisc_->update(*this, QueueingDiscipline::DEQUEUE);
368 prefix_ void senf::ppi::connector::GenericPassiveInput::qdisc(QueueingDiscipline::None_t)
373 prefix_ void senf::ppi::connector::GenericPassiveInput::v_unthrottleEvent()
375 size_type n (queueSize());
378 size_type nn (queueSize());
385 ///////////////////////////////cc.e////////////////////////////////////////
387 //#include "Connectors.mpp"
393 // comment-column: 40
394 // c-file-style: "senf"
395 // indent-tabs-mode: nil
396 // ispell-local-dictionary: "american"
397 // compile-command: "scons -u test"