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 prefix_ senf::ppi::connector::PassiveConnector::~PassiveConnector()
213 // Must be here and NOT in base so it is called before destructing the routes_ member
214 unregisterConnector();
217 ////////////////////////////////////////
220 prefix_ void senf::ppi::connector::PassiveConnector::v_init()
222 Routes::const_iterator i (routes_.begin());
223 Routes::const_iterator const i_end (routes_.end());
224 for (; i != i_end; ++i)
225 if ((*i)->throttled())
228 remoteThrottled_ = false;
235 prefix_ void senf::ppi::connector::PassiveConnector::registerRoute(ForwardingRoute & route)
237 routes_.push_back(&route);
240 prefix_ void senf::ppi::connector::PassiveConnector::unregisterRoute(ForwardingRoute & route)
242 Routes::iterator i (std::find(routes_.begin(), routes_.end(), &route));
243 if (i != routes_.end())
247 prefix_ void senf::ppi::connector::PassiveConnector::v_unthrottleEvent()
250 prefix_ void senf::ppi::connector::PassiveConnector::notifyUnthrottle()
252 if (std::find_if(routes_.begin(), routes_.end(),
253 boost::bind(&ForwardingRoute::throttled, _1)) == routes_.end()) {
254 remoteThrottled_ = false;
255 if (!nativeThrottled_)
258 SENF_PPI_THROTTLE_TRACE("OUT", "not forwarding unthrottle event");
261 ///////////////////////////////////////////////////////////////////////////
262 // senf::ppi::connector::ActiveConnector
264 prefix_ senf::ppi::connector::ActiveConnector::~ActiveConnector()
266 // Must be here and NOT in base so it is called before destructing the routes_ member
267 unregisterConnector();
270 ////////////////////////////////////////
273 prefix_ void senf::ppi::connector::ActiveConnector::v_init()
279 prefix_ void senf::ppi::connector::ActiveConnector::notifyThrottle()
281 SENF_PPI_THROTTLE_TRACE("IN ", "throttle");
284 if (throttleCallback_)
286 NotifyRoutes::const_iterator i (notifyRoutes_.begin());
287 NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
288 for (; i != i_end; ++i)
289 (*i)->notifyThrottle();
293 prefix_ void senf::ppi::connector::ActiveConnector::notifyUnthrottle()
295 SENF_PPI_THROTTLE_TRACE("IN ", "unthrottle");
298 if (unthrottleCallback_)
299 unthrottleCallback_();
300 NotifyRoutes::const_iterator i (notifyRoutes_.begin());
301 NotifyRoutes::const_iterator const i_end (notifyRoutes_.end());
302 for (; i != i_end; ++i)
303 (*i)->notifyUnthrottle();
307 prefix_ void senf::ppi::connector::ActiveConnector::registerRoute(ForwardingRoute & route)
309 notifyRoutes_.push_back(&route);
312 prefix_ void senf::ppi::connector::ActiveConnector::unregisterRoute(ForwardingRoute & route)
314 NotifyRoutes::iterator i (std::find(notifyRoutes_.begin(), notifyRoutes_.end(), &route));
315 if (i != notifyRoutes_.end())
316 notifyRoutes_.erase(i);
319 ///////////////////////////////////////////////////////////////////////////
320 // senf::ppi::connector::InputConnector
322 prefix_ senf::Packet senf::ppi::connector::InputConnector::operator()()
327 Packet p ( queue_.back());
330 SENF_PPI_TRACE(p, "IN ");
333 SENF_PPI_TRACE(Packet(), "IN ");
338 ////////////////////////////////////////
341 prefix_ void senf::ppi::connector::InputConnector::v_requestEvent()
344 prefix_ void senf::ppi::connector::InputConnector::v_enqueueEvent()
347 prefix_ void senf::ppi::connector::InputConnector::v_dequeueEvent()
350 ///////////////////////////////////////////////////////////////////////////
351 // senf::ppi::connector::GenericActiveInput
353 ////////////////////////////////////////
356 prefix_ void senf::ppi::connector::GenericActiveInput::v_requestEvent()
361 ///////////////////////////////////////////////////////////////////////////
362 // senf::ppi::connector::GenericPassiveInput
364 ////////////////////////////////////////
367 prefix_ void senf::ppi::connector::GenericPassiveInput::v_enqueueEvent()
371 qdisc_->update(*this, QueueingDiscipline::ENQUEUE);
374 prefix_ void senf::ppi::connector::GenericPassiveInput::v_dequeueEvent()
377 qdisc_->update(*this, QueueingDiscipline::DEQUEUE);
380 prefix_ void senf::ppi::connector::GenericPassiveInput::qdisc(QueueingDiscipline::None_t)
385 prefix_ void senf::ppi::connector::GenericPassiveInput::v_unthrottleEvent()
387 size_type n (queueSize());
390 size_type nn (queueSize());
397 ///////////////////////////////cc.e////////////////////////////////////////
399 //#include "Connectors.mpp"
405 // comment-column: 40
406 // c-file-style: "senf"
407 // indent-tabs-mode: nil
408 // ispell-local-dictionary: "american"
409 // compile-command: "scons -u test"