QueueingAlgorithm.hh
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 #ifndef HH_SENF_PPI_QueueingAlgorithm_
18 #define HH_SENF_PPI_QueueingAlgorithm_ 1
19 
20 // Custom includes
21 #include <queue>
22 #include <senf/Packets/Packets.hh>
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 namespace senf {
28 namespace ppi {
29 
31  : private boost::noncopyable
32  {
34 
35  public:
36  typedef std::unique_ptr<QueueingAlgorithm> ptr;
37 
38  virtual ~QueueingAlgorithm() {};
39 
41  void pop();
42  Packet const & front() const;
43  bool enqueue(Packet const & packet, bool force = false);
44  unsigned size() const;
45  unsigned peek(unsigned maxSize = 0x7fffffff) const;
46  void clear();
47  bool empty() const;
48 
49  protected:
51 
52  virtual Packet const & v_front() const = 0;
53  virtual void v_pop() = 0;
54  virtual bool v_enqueue(Packet const & packet, bool force) = 0;
55  virtual unsigned v_size() const = 0;
56  virtual unsigned v_peek(unsigned maxSize) const = 0;
57  virtual void v_clear() = 0;
58  virtual bool v_empty() const = 0;
59  };
60 
61 
62  namespace detail {
64  {
66  virtual QueueingAlgorithm::ptr create() const = 0;
67  };
68 
69  template <class QAlgorithm>
71  {
72  virtual QueueingAlgorithm::ptr create() const;
73  };
74  }
75 
76 
78  : public senf::singleton<QueueingAlgorithmRegistry>
79  {
80  typedef boost::ptr_map<std::string, detail::QueueingAlgorithmRegistry_EntryBase> QAlgoMap;
81  QAlgoMap qAlgoMap_;
82 
84 
85  public:
88 
89  struct Exception : public senf::Exception {
90  Exception(std::string const & descr) : senf::Exception(descr) {}
91  };
92 
93  template <class QAlgorithm>
95  RegistrationProxy(std::string const & key);
96  };
97 
98  template <class QAlgorithm>
99  void registerQAlgorithm(std::string key);
100 
101  QueueingAlgorithm::ptr createQAlgorithm(std::string const & key) const;
102  void dump(std::ostream & os) const;
103  };
104 
105 
106 # define SENF_PPI_REGISTER_QALGORITHM( key, QAlgorithm ) \
107  namespace { \
108  senf::ppi::QueueingAlgorithmRegistry::RegistrationProxy<QAlgorithm> \
109  BOOST_PP_CAT(qAlgorithmRegistration_, __LINE__)( key); \
110  }
111 
112 
114  {
115  std::queue<Packet> queue_;
116  unsigned max_size_;
117 
119 
120  virtual Packet const & v_front() const;
121  virtual unsigned v_peek(unsigned maxSize) const;
122  virtual void v_pop();
123  virtual bool v_enqueue(Packet const & packet, bool force);
124  virtual unsigned v_size() const;
125  virtual void v_clear();
126  virtual bool v_empty() const;
127 
128  public:
129  static QueueingAlgorithm::ptr create();
130  };
131 
132 
134  {
135  virtual Packet const & v_front() const;
136  virtual unsigned v_peek(unsigned maxSize) const;
137  virtual void v_pop();
138  virtual bool v_enqueue(Packet const & packet, bool force);
139  virtual unsigned v_size() const;
140  virtual void v_clear();
141  virtual bool v_empty() const;
142 
143  public:
144  static QueueingAlgorithm::ptr create();
145  };
146 
147 
148 }}
149 
150 //-/////////////////////////////////////////////////////////////////////////////////////////////////
151 #include "QueueingAlgorithm.cci"
152 //#include "QueueingAlgorithm.ct"
153 #include "QueueingAlgorithm.cti"
154 #endif
155 
156 
157 // Local Variables:
158 // mode: c++
159 // fill-column: 100
160 // c-file-style: "senf"
161 // indent-tabs-mode: nil
162 // ispell-local-dictionary: "american"
163 // compile-command: "scons -u test"
164 // comment-column: 40
165 // End:
Packet const & front() const
virtual unsigned v_size() const =0
virtual unsigned v_peek(unsigned maxSize) const =0
unsigned peek(unsigned maxSize=0x7fffffff) const
std::unique_ptr< QueueingAlgorithm > ptr
virtual bool v_empty() const =0
void dump(std::ostream &os, DirectoryNode &dir=root())
virtual Packet const & v_front() const =0
virtual bool v_enqueue(Packet const &packet, bool force)=0
console::DirectoryNode & consoleDir()
bool enqueue(Packet const &packet, bool force=false)