X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPPI%2FQueueingSocketSink.hh;h=428235a183393bee5182e3caccace83054cc6b52;hb=ab7ff164ab5ae711ec09ce2b24228510f1ffdcff;hp=6c5c15c39fc6c24cbee362fdd1cf390b4004ea43;hpb=ed55b722ff15975fb0b090a1b132c9b830829124;p=senf.git diff --git a/senf/PPI/QueueingSocketSink.hh b/senf/PPI/QueueingSocketSink.hh index 6c5c15c..428235a 100644 --- a/senf/PPI/QueueingSocketSink.hh +++ b/senf/PPI/QueueingSocketSink.hh @@ -2,23 +2,28 @@ // // Copyright (C) 2010 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Thorsten Horstmann // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Thorsten Horstmann /** \file \brief QueueingSocketSink public header */ @@ -29,38 +34,102 @@ // Custom includes #include #include "SocketSink.hh" +#include //#include "QueueingSocketSink.mpp" -///////////////////////////////hh.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { namespace ppi { - template class QueueingAlgorithm + : private boost::noncopyable { + console::ScopedDirectory dir_; + public: + typedef QueueingAlgorithm * ptr; + virtual ~QueueingAlgorithm() {}; - virtual PacketType dequeue() = 0; - virtual bool enqueue(PacketType const & packet) = 0; - virtual unsigned size() const = 0; - virtual void clear() = 0; + + console::DirectoryNode & consoleDir(); + Packet dequeue(); + bool enqueue(Packet const & packet); + unsigned size(); + void clear(); + + protected: + QueueingAlgorithm(); + + virtual Packet v_dequeue() = 0; + virtual bool v_enqueue(Packet const & packet) = 0; + virtual unsigned v_size() const = 0; + virtual void v_clear() = 0; }; - template - class FIFOQueueingAlgorithm : public QueueingAlgorithm + + namespace detail { + struct QueueingAlgorithmRegistry_EntryBase + { + virtual QueueingAlgorithm::ptr create() const = 0; + }; + + template + struct QueueingAlgorithmRegistry_Entry : QueueingAlgorithmRegistry_EntryBase + { + virtual QueueingAlgorithm::ptr create() const; + }; + } + + class QueueingAlgorithmRegistry + : public senf::singleton { + typedef boost::ptr_map QAlgoMap; + QAlgoMap qAlgoMap_; + + QueueingAlgorithmRegistry() {}; public: - FIFOQueueingAlgorithm(unsigned size); + using senf::singleton::instance; + friend class senf::singleton; - virtual PacketType dequeue(); - virtual bool enqueue(PacketType const & packet); - virtual unsigned size() const; - virtual void clear(); + struct Exception : public senf::Exception { + Exception(std::string const & descr) : senf::Exception(descr) {} + }; - private: - std::queue queue_; - unsigned size_; + template + struct RegistrationProxy { + RegistrationProxy(std::string const & key); + }; + + template + void registerQAlgorithm(std::string key); + + QueueingAlgorithm::ptr createQAlgorithm(std::string const & key) const; + void dump(std::ostream & os) const; + }; + + +# define SENF_PPI_REGISTER_QALGORITHM( key, QAlgorithm ) \ + namespace { \ + senf::ppi::QueueingAlgorithmRegistry::RegistrationProxy \ + BOOST_PP_CAT(qAlgorithmRegistration_, __LINE__)( key); \ + } + + + class FIFOQueueingAlgorithm : public QueueingAlgorithm + { + std::queue queue_; + unsigned max_size_; + + FIFOQueueingAlgorithm(); + + virtual Packet v_dequeue(); + virtual bool v_enqueue(Packet const & packet); + virtual unsigned v_size() const; + virtual void v_clear(); + + public: + static QueueingAlgorithm::ptr create(); }; @@ -80,32 +149,35 @@ namespace module { typedef typename Writer::PacketType PacketType; connector::PassiveInput input; ///< Input connector from which data is received + console::ScopedDirectory > dir; - template - explicit PassiveQueueingSocketSink(Handle handle, QAlgorithm const & qAlgorithm); + explicit PassiveQueueingSocketSink(Handle const & handle, QueueingAlgorithm::ptr qAlgorithm); Writer & writer(); ///< Access the Writer Handle & handle(); ///< Access handle - void handle(Handle handle); ///< Set handle + void handle(Handle const & handle); + ///< Set handle /**< Assigning an empty or in-valid() handle will disable the module until a new valid handle is assigned. */ - QueueingAlgorithm & qAlgorithm(); + QueueingAlgorithm & qAlgorithm(); + void qAlgorithm(QueueingAlgorithm::ptr qAlgorithm); private: void write(); void writable(); void checkThrottle(); + void setQAlgorithm(std::string const & key); Handle handle_; Writer writer_; - boost::scoped_ptr > qAlgo_; + boost::scoped_ptr qAlgo_; IOEvent event_; }; }}} -///////////////////////////////hh.e//////////////////////////////////////// -//#include "QueueingSocketSink.cci" +//-///////////////////////////////////////////////////////////////////////////////////////////////// +#include "QueueingSocketSink.cci" #include "QueueingSocketSink.ct" #include "QueueingSocketSink.cti" #endif