2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief QueueingSocketSink non-inline template implementation */
17 //#include "QueueingSocketSink.ih"
20 #include <senf/Utils/Console/ParsedCommand.hh>
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::ppi::module::PassiveQueueingSocketSink<Writer>
28 template <class Writer>
29 prefix_ senf::ppi::module::PassiveQueueingSocketSink<Writer>::PassiveQueueingSocketSink(Handle const & handle, QueueingAlgorithm::ptr qAlgorithm)
30 : handle_(handle), writer_(),
31 qAlgo_(qAlgorithm.release()),
32 event_(handle_, IOEvent::Write)
34 namespace fty = console::factory;
35 dir.add( "active", qAlgo_->consoleDir());
36 dir.add( "set", fty::Command(
37 &PassiveQueueingSocketSink<Writer>::setQAlgorithm, this) );
38 dir.add( "list", fty::Command(
39 &QueueingAlgorithmRegistry::dump, &QueueingAlgorithmRegistry::instance()));
40 registerEvent( event_, &PassiveQueueingSocketSink::writable );
41 event_.enabled( false);
43 input.onRequest( &PassiveQueueingSocketSink::write);
44 input.throttlingDisc( ThrottlingDiscipline::NONE);
48 template <class Writer>
49 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::handle(Handle const & handle)
52 event_.set( handle_, IOEvent::Write);
57 template <class Writer>
58 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::write()
60 PacketType const & p ( input());
61 if (qAlgo_->size() > 0) {
65 if (! writer_( handle_, p)) {
66 if (qAlgo_->enqueue( p) && !event_.enabled()) {
67 event_.enabled( true);
72 template <class Writer>
73 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::writable()
75 if (qAlgo_->peek() > 0) {
76 writer_( handle_, static_cast<PacketType const &>(qAlgo_->front()));
79 if (qAlgo_->size() == 0) {
80 event_.enabled( false);
84 template <class Writer>
85 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::checkThrottle()
93 template <class Writer>
94 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::qAlgorithm(QueueingAlgorithm::ptr qAlgorithm)
96 // dir.remove( "active");
97 qAlgo_.reset( qAlgorithm.release());
98 dir.add( "active", qAlgo_->consoleDir());
100 event_.enabled( false);
103 template <class Writer>
104 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::setQAlgorithm(std::string const & key)
106 qAlgorithm( QueueingAlgorithmRegistry::instance().createQAlgorithm( key));
109 //-/////////////////////////////////////////////////////////////////////////////////////////////////
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"