InterfaceDecorator.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_Ext_NetEmu_InterfaceDecorator_
18 #define HH_SENF_Ext_NetEmu_InterfaceDecorator_ 1
19 
20 // Custom includes
21 #include <boost/mpl/if.hpp>
22 #include <boost/type_traits/is_base_of.hpp>
23 #include <boost/utility/base_from_member.hpp>
24 #include <senf/PPI/Jack.hh>
26 #include <senf/Utils/mpl.hh>
27 
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 namespace senf {
31 namespace emu {
32 
33  class Interface;
34  class Receiver;
35  class Transmitter;
36 
42  {
43  public:
44  virtual ~ReceiverDecorator();
45 
47 
48  protected:
49  template <class Connector>
50  ReceiverDecorator(Connector & connector);
51  };
52 
58  {
59  public:
60  virtual ~TransmitterDecorator();
61 
63 
64  protected:
65  template <class Connector>
66  TransmitterDecorator(Connector & connector);
67  };
68 
76  : private boost::noncopyable
77  {
78  public:
79  virtual ~InterfaceDecorator();
80 
81  Interface & interface();
82  Interface const & interface() const;
83 
84  Interface * operator->();
85  Interface const * operator->() const;
86 
87  ReceiverDecorator & receiverDecorator();
88  ReceiverDecorator const & receiverDecorator() const;
89  TransmitterDecorator & transmitterDecorator();
90  TransmitterDecorator const & transmitterDecorator() const;
91 
92  bool canReceive() const;
93  bool canTransmit() const;
94  MACAddress id() const;
95 
96  protected:
97  InterfaceDecorator(Interface & interface);
98 
99  private:
100  Interface & interface_;
101  };
102 
103 #ifndef DOXYGEN
104 
105  template <class InterfaceType, class Base=InterfaceDecorator>
107  : public Base
108  {
109  public:
110  InterfaceType & interface();
111  InterfaceType const & interface() const;
112 
113  protected:
114  TypedInterfaceDecorator(InterfaceType & interface);
115  };
116 
117 #else
118 
129  template <class InterfaceType, class Base>
131  : public InterfaceDecorator
132  {
133  public:
134  InterfaceType & interface();
135  InterfaceType const & interface() const;
136 
137  protected:
138  TypedInterfaceDecorator(InterfaceType & interface);
139  };
140 
141 #endif
142 
153  template <class ReceiveModule>
155  : private boost::base_from_member<ReceiveModule>,
156  public ReceiverDecorator
157  {
158  typedef boost::base_from_member<ReceiveModule> ModuleMember;
159  public:
160  ReceiveModule & receiveModule();
161  ReceiveModule const & receiveModule() const;
162 
163  protected:
164  template <class Interface>
166  };
167 
168 #ifndef DOXYGEN
169 
170  template <>
172  : public ReceiverDecorator
173  {
174  protected:
175  template <class Interface>
177  };
178 
179 #endif
180 
191  template <class TransmitModule>
193  : private boost::base_from_member<TransmitModule>,
194  public TransmitterDecorator
195  {
196  typedef boost::base_from_member<TransmitModule> ModuleMember;
197  public:
198  TransmitModule & transmitModule();
199  TransmitModule const & transmitModule() const;
200 
201  protected:
202  template <class Interface>
204  };
205 
206 #ifndef DOXYGEN
207 
208  template <>
210  : public TransmitterDecorator
211  {
212  protected:
213  template <class Interface>
215  };
216 
217 #endif
218 
219 namespace detail {
220 
221 #ifndef DOXYGEN
222 
223  struct NoDecorator
224  {
225  template <class Interface>
226  NoDecorator(Interface & interface);
227  };
228 
229  template <class InterfaceType, class CheckBase, class Implementation>
230  struct CheckDecoratorBase
231  : public boost::mpl::if_<
232  boost::is_base_of<CheckBase, InterfaceType>,
233  Implementation,
234  NoDecorator >
235  {};
236 
237 #endif
238 
239 }
240 
241 #ifndef DOXYGEN
242 
243  template <class InterfaceType, class ReceiveModule, class TransmitModule>
245  : private boost::base_from_member<InterfaceType>,
246  public InterfaceType::Decorator,
247  public detail::CheckDecoratorBase<
248  InterfaceType,
249  Receiver,
250  ReceiverDecoratorImplementation<ReceiveModule>
251  >::type,
252  public detail::CheckDecoratorBase<
253  InterfaceType,
254  Transmitter,
255  TransmitterDecoratorImplementation<TransmitModule>
256  >::type
257  {
258  typedef boost::base_from_member<InterfaceType> InterfaceBase;
259  typedef typename detail::CheckDecoratorBase<
260  InterfaceType,
261  Receiver,
263  typedef typename detail::CheckDecoratorBase<
264  InterfaceType,
265  Transmitter,
267 
268  public:
270  template <class A1> explicit InterfaceDecoratorImplementation(A1 const & a1);
271  template <class A1, class A2> explicit InterfaceDecoratorImplementation(A1 const & a1, A2 const & a2);
272  };
273 
274 #else
275 
288  template <class InterfaceType, class ReceiveModule, class TransmitModule>
290  : public TypedInterfaceDecorator<InterfaceType>,
291  public ReceiverDecoratorImplementation<ReceiveModule>,
292  public TransmitterDecoratorImplementation<TransmitModule>
293  {};
294 
295 #endif
296 
416  template <class ReceiveModule=senf::mpl::nil, class TransmitModule=senf::mpl::nil>
418  {
419 #ifndef DOXYGEN
420  template <class InterfaceType>
421  struct apply
422  {
424  InterfaceType, ReceiveModule, TransmitModule> type;
425 
426  };
427 #endif
428 
429  static ReceiveModule & receiveModule(InterfaceDecorator & interface);
430  static ReceiveModule const & receiveModule(InterfaceDecorator const & interface);
431 
432  static TransmitModule & transmitModule(InterfaceDecorator & interface);
433  static TransmitModule const & transmitModule(InterfaceDecorator const & interface);
434  };
435 
436 }}
437 
438 //-/////////////////////////////////////////////////////////////////////////////////////////////////
439 #include "InterfaceDecorator.cci"
440 //#include "InterfaceDecorator.ct"
441 #include "InterfaceDecorator.cti"
442 #endif
443 
444 
445 // Local Variables:
446 // mode: c++
447 // fill-column: 100
448 // comment-column: 40
449 // c-file-style: "senf"
450 // indent-tabs-mode: nil
451 // ispell-local-dictionary: "american"
452 // compile-command: "scons -u test"
453 // End:
Interface API base class
u8 type
Decorator for Receivers.
ppi::connector::ActiveOutputJack< EthernetPacket > output
Apply additional modules to an interface.
Decorator for Transmitters.
Interface API base class for receive capable interfaces.
Interface API base class for transmit capable interfaces.
Decorate InterfaceType with additional processing modules.
Implementing the transmitter decorator.
ReceiverDecorator(Connector &connector)
Specialized Interface decorator base-class.
ppi::connector::PassiveInputJack< EthernetPacket > input
Implementing the receiver decorator.
Generic Interface decorator base-class.