QueueingAlgorithm.cc
Go to the documentation of this file.
1 //
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
6 //
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
11 //
12 
13 
17 #include "QueueingSocketSink.hh"
18 //#include "QueueingSocketSink.ih"
19 
20 // Custom includes
22 
23 #define prefix_
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
28 
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 // senf::ppi::QueueingAlgorithm
31 
33 {
34  namespace fty = console::factory;
35  dir_.add("size", fty::Command( &QueueingAlgorithm::size, this));
36  dir_.add("clear", fty::Command( &QueueingAlgorithm::clear, this));
37 }
38 
40 {
41  return dir_;
42 }
43 
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 // senf::ppi::QueueingAlgorithmRegistry
46 
48  const
49 {
50  for (QAlgoMap::const_iterator i = qAlgoMap_.begin(); i != qAlgoMap_.end(); ++i) {
51  os << i->first << std::endl;
52  }
53 }
54 
56  const
57 {
58  QAlgoMap::const_iterator i (qAlgoMap_.find( key));
59  if (i != qAlgoMap_.end())
60  return i->second->create();
61  else
62  throw Exception("QueueingAlgorithm not registered: ") << key;
63 }
64 
65 //-/////////////////////////////////////////////////////////////////////////////////////////////////
66 // senf::ppi::FIFOQueueingAlgorithm
67 
68 prefix_ senf::ppi::FIFOQueueingAlgorithm::FIFOQueueingAlgorithm()
69  : max_size_( 64)
70 {
71  consoleDir().add("max-size", console::factory::Variable(max_size_) );
72 }
73 
74 prefix_ bool senf::ppi::FIFOQueueingAlgorithm::v_enqueue(Packet const & packet, bool force)
75 {
76  if (!force and (queue_.size() >= max_size_))
77  return false;
78 
79  queue_.push( packet);
80  return true;
81 }
82 
83 prefix_ void senf::ppi::FIFOQueueingAlgorithm::v_clear()
84 {
85  while (! queue_.empty())
86  queue_.pop();
87 }
88 
90 {
92 }
93 
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
95 #undef prefix_
SENF_PPI_REGISTER_QALGORITHM("FIFOQueueingAlgorithm", senf::ppi::FIFOQueueingAlgorithm)
QueueingSocketSink public header.
#define prefix_
std::unique_ptr< QueueingAlgorithm > ptr
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
static QueueingAlgorithm::ptr create()
void dump(std::ostream &os) const
QueueingAlgorithm::ptr createQAlgorithm(std::string const &key) const
console::DirectoryNode & consoleDir()
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)