4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@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 QueueingSocketSink non-inline template implementation */
26 //#include "QueueingSocketSink.ih"
31 ///////////////////////////////ct.p////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::ppi::QueueingAlgorithmRegistry
36 template <class QAlgorithm>
37 prefix_ void senf::ppi::QueueingAlgorithmRegistry::registerQAlgorithm(std::string key)
39 if (qAlgoMap_.find( key) == qAlgoMap_.end() )
40 qAlgoMap_.insert(key, new detail::QueueingAlgorithmRegistry_Entry<QAlgorithm>() );
42 throw Exception("Duplicated QAlgorithm Registration ") << key;
45 ///////////////////////////////////////////////////////////////////////////
46 // senf::ppi::detail::QueueingAlgorithmRegistry_Entry<QAlgorithm>
48 template <class QAlgorithm>
49 prefix_ senf::ppi::QueueingAlgorithm::ptr senf::ppi::detail::QueueingAlgorithmRegistry_Entry<QAlgorithm>::create()
52 return QAlgorithm::create();
55 ///////////////////////////////////////////////////////////////////////////
56 // senf::ppi::module::PassiveQueueingSocketSink<Writer>
58 template <class Writer>
59 prefix_ senf::ppi::module::PassiveQueueingSocketSink<Writer>::PassiveQueueingSocketSink(Handle const & handle, QueueingAlgorithm::ptr qAlgorithm)
61 handle_( handle), writer_( ),
63 event_( handle_, IOEvent::Write)
65 namespace fty = console::factory;
66 dir.add( "active", qAlgo_->consoleDir());
67 dir.add( "set", fty::Command(
68 &PassiveQueueingSocketSink<Writer>::setQAlgorithm, this) );
69 dir.add( "list", fty::Command(
70 &QueueingAlgorithmRegistry::dump, &QueueingAlgorithmRegistry::instance()));
71 registerEvent( event_, &PassiveQueueingSocketSink::writable );
72 event_.enabled( false);
74 input.onRequest( &PassiveQueueingSocketSink::write);
75 input.qdisc( QueueingDiscipline::NONE);
79 template <class Writer>
80 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::write()
82 PacketType p ( input.read());
83 if (qAlgo_->size() > 0) {
87 if (! writer_( handle_, p)) {
88 if (qAlgo_->enqueue( p) && !event_.enabled()) {
89 event_.enabled( true);
94 template <class Writer>
95 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::writable()
97 PacketType p (qAlgo_->dequeue());
100 if (qAlgo_->size() == 0) {
101 event_.enabled( false);
105 template <class Writer>
106 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::checkThrottle()
114 template <class Writer>
115 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::qAlgorithm(QueueingAlgorithm::ptr qAlgorithm)
117 // dir.remove( "active");
118 qAlgo_.reset( qAlgorithm);
119 dir.add( "active", qAlgo_->consoleDir());
120 if (event_.enabled())
121 event_.enabled( false);
124 template <class Writer>
125 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::setQAlgorithm(std::string const & key)
127 qAlgorithm( QueueingAlgorithmRegistry::instance().createQAlgorithm( key));
130 ///////////////////////////////ct.e////////////////////////////////////////
137 // comment-column: 40
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"