4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Thorsten Horstmann <tho@berlios.de>
29 \brief QueueingSocketSink public header */
31 #ifndef HH_SENF_PPI_QueueingSocketSink_
32 #define HH_SENF_PPI_QueueingSocketSink_ 1
36 #include "SocketSink.hh"
37 #include <senf/Utils/Console/ScopedDirectory.hh>
39 //#include "QueueingSocketSink.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 class QueueingAlgorithm
46 : private boost::noncopyable
48 console::ScopedDirectory<QueueingAlgorithm> dir_;
51 typedef QueueingAlgorithm * ptr;
53 virtual ~QueueingAlgorithm() {};
55 console::DirectoryNode & consoleDir();
57 bool enqueue(Packet const & packet);
64 virtual Packet v_dequeue() = 0;
65 virtual bool v_enqueue(Packet const & packet) = 0;
66 virtual unsigned v_size() const = 0;
67 virtual void v_clear() = 0;
72 struct QueueingAlgorithmRegistry_EntryBase
74 virtual QueueingAlgorithm::ptr create() const = 0;
77 template <class QAlgorithm>
78 struct QueueingAlgorithmRegistry_Entry : QueueingAlgorithmRegistry_EntryBase
80 virtual QueueingAlgorithm::ptr create() const;
84 class QueueingAlgorithmRegistry
85 : public senf::singleton<QueueingAlgorithmRegistry>
87 typedef boost::ptr_map<std::string, detail::QueueingAlgorithmRegistry_EntryBase> QAlgoMap;
90 QueueingAlgorithmRegistry() {};
92 using senf::singleton<QueueingAlgorithmRegistry>::instance;
93 friend class senf::singleton<QueueingAlgorithmRegistry>;
95 struct Exception : public senf::Exception {
96 Exception(std::string const & descr) : senf::Exception(descr) {}
99 template <class QAlgorithm>
100 struct RegistrationProxy {
101 RegistrationProxy(std::string const & key);
104 template <class QAlgorithm>
105 void registerQAlgorithm(std::string key);
107 QueueingAlgorithm::ptr createQAlgorithm(std::string const & key) const;
108 void dump(std::ostream & os) const;
112 # define SENF_PPI_REGISTER_QALGORITHM( key, QAlgorithm ) \
114 senf::ppi::QueueingAlgorithmRegistry::RegistrationProxy<QAlgorithm> \
115 BOOST_PP_CAT(qAlgorithmRegistration_, __LINE__)( key); \
119 class FIFOQueueingAlgorithm : public QueueingAlgorithm
121 std::queue<Packet> queue_;
124 FIFOQueueingAlgorithm();
126 virtual Packet v_dequeue();
127 virtual bool v_enqueue(Packet const & packet);
128 virtual unsigned v_size() const;
129 virtual void v_clear();
132 static QueueingAlgorithm::ptr create();
138 /** \brief QueueingSocketSink
142 template <class Writer=ConnectedDgramWriter>
143 class PassiveQueueingSocketSink : public Module
145 SENF_PPI_MODULE(PassiveQueueingSocketSink);
148 typedef typename Writer::Handle Handle; ///< Handle type requested by writer
149 typedef typename Writer::PacketType PacketType;
151 connector::PassiveInput<PacketType> input; ///< Input connector from which data is received
152 console::ScopedDirectory<PassiveQueueingSocketSink<Writer> > dir;
154 explicit PassiveQueueingSocketSink(Handle const & handle, QueueingAlgorithm::ptr qAlgorithm);
156 Writer & writer(); ///< Access the Writer
157 Handle & handle(); ///< Access handle
158 void handle(Handle const & handle);
160 /**< Assigning an empty or in-valid() handle will disable
161 the module until a new valid handle is assigned. */
162 QueueingAlgorithm & qAlgorithm();
163 void qAlgorithm(QueueingAlgorithm::ptr qAlgorithm);
168 void checkThrottle();
169 void setQAlgorithm(std::string const & key);
173 boost::scoped_ptr<QueueingAlgorithm> qAlgo_;
179 //-/////////////////////////////////////////////////////////////////////////////////////////////////
180 #include "QueueingSocketSink.cci"
181 #include "QueueingSocketSink.ct"
182 #include "QueueingSocketSink.cti"
189 // c-file-style: "senf"
190 // indent-tabs-mode: nil
191 // ispell-local-dictionary: "american"
192 // compile-command: "scons -u test"
193 // comment-column: 40