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 public header */
26 #ifndef HH_SENF_PPI_QueueingSocketSink_
27 #define HH_SENF_PPI_QueueingSocketSink_ 1
31 #include "SocketSink.hh"
32 #include <senf/Utils/Console/Console.hh>
34 //#include "QueueingSocketSink.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
40 class QueueingAlgorithm
41 : private boost::noncopyable
43 console::ScopedDirectory<QueueingAlgorithm> dir_;
46 typedef QueueingAlgorithm * ptr;
48 virtual ~QueueingAlgorithm() {};
50 console::DirectoryNode & consoleDir();
52 bool enqueue(Packet const & packet);
59 virtual Packet v_dequeue() = 0;
60 virtual bool v_enqueue(Packet const & packet) = 0;
61 virtual unsigned v_size() const = 0;
62 virtual void v_clear() = 0;
67 struct QueueingAlgorithmRegistry_EntryBase
69 virtual QueueingAlgorithm::ptr create() const = 0;
72 template <class QAlgorithm>
73 struct QueueingAlgorithmRegistry_Entry : QueueingAlgorithmRegistry_EntryBase
75 virtual QueueingAlgorithm::ptr create() const;
79 class QueueingAlgorithmRegistry
80 : public senf::singleton<QueueingAlgorithmRegistry>
82 typedef boost::ptr_map<std::string, detail::QueueingAlgorithmRegistry_EntryBase> QAlgoMap;
85 QueueingAlgorithmRegistry() {};
87 using senf::singleton<QueueingAlgorithmRegistry>::instance;
88 friend class senf::singleton<QueueingAlgorithmRegistry>;
90 struct Exception : public senf::Exception {
91 Exception(std::string const & descr) : senf::Exception(descr) {}
94 template <class QAlgorithm>
95 struct RegistrationProxy {
96 RegistrationProxy(std::string const & key);
99 template <class QAlgorithm>
100 void registerQAlgorithm(std::string key);
102 QueueingAlgorithm::ptr createQAlgorithm(std::string const & key) const;
103 void dump(std::ostream & os) const;
107 # define SENF_PPI_REGISTER_QALGORITHM( key, QAlgorithm ) \
109 senf::ppi::QueueingAlgorithmRegistry::RegistrationProxy<QAlgorithm> \
110 BOOST_PP_CAT(qAlgorithmRegistration_, __LINE__)( key); \
114 class FIFOQueueingAlgorithm : public QueueingAlgorithm
116 std::queue<Packet> queue_;
119 FIFOQueueingAlgorithm();
121 virtual Packet v_dequeue();
122 virtual bool v_enqueue(Packet const & packet);
123 virtual unsigned v_size() const;
124 virtual void v_clear();
127 static QueueingAlgorithm::ptr create();
133 /** \brief QueueingSocketSink
137 template <class Writer=ConnectedDgramWriter>
138 class PassiveQueueingSocketSink : public Module
140 SENF_PPI_MODULE(PassiveQueueingSocketSink);
143 typedef typename Writer::Handle Handle; ///< Handle type requested by writer
144 typedef typename Writer::PacketType PacketType;
146 connector::PassiveInput<PacketType> input; ///< Input connector from which data is received
147 console::ScopedDirectory<PassiveQueueingSocketSink<Writer> > dir;
149 explicit PassiveQueueingSocketSink(Handle const & handle, QueueingAlgorithm::ptr qAlgorithm);
151 Writer & writer(); ///< Access the Writer
152 Handle & handle(); ///< Access handle
153 void handle(Handle const & handle);
155 /**< Assigning an empty or in-valid() handle will disable
156 the module until a new valid handle is assigned. */
157 QueueingAlgorithm & qAlgorithm();
158 void qAlgorithm(QueueingAlgorithm::ptr qAlgorithm);
163 void checkThrottle();
164 void setQAlgorithm(std::string const & key);
168 boost::scoped_ptr<QueueingAlgorithm> qAlgo_;
174 ///////////////////////////////hh.e////////////////////////////////////////
175 #include "QueueingSocketSink.cci"
176 #include "QueueingSocketSink.ct"
177 #include "QueueingSocketSink.cti"
184 // c-file-style: "senf"
185 // indent-tabs-mode: nil
186 // ispell-local-dictionary: "american"
187 // compile-command: "scons -u test"
188 // comment-column: 40