PacketRegistry.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_Packets_PacketRegistry_
18 #define HH_SENF_Packets_PacketRegistry_ 1
19 
20 // Custom includes
21 #include <boost/optional.hpp>
22 #include <boost/preprocessor/cat.hpp>
23 #include <senf/Utils/Exception.hh>
24 #include <senf/Utils/singleton.hh>
25 #include "Packet.hh"
26 
27 #include "PacketRegistry.ih"
28 //#include "PacketRegistry.mpp"
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 namespace senf {
32 
77  template <class Tag>
79  : private senf::singleton< PacketRegistry<Tag> >
80  {
81  public:
83  typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::Entry Entry;
84 
103  template <class PacketType>
105  {
106  ScopedRegistrationProxy(typename Tag::key_t key, int priority=0);
108  };
109 
123  template <class PacketType>
124  static void registerPacket(typename Tag::key_t key, int priority=0);
125 
133  template <class PacketType>
134  static void unregisterPacket();
135 
145  static void unregisterPacket(typename Tag::key_t key, int priority=0);
146 
155  template <class PacketType>
156  static typename Tag::key_t key();
157 
167  template <class PacketType>
168  static typename boost::optional<typename Tag::key_t> key(NoThrow_t);
169 
178  static typename Tag::key_t key(Packet const & packet);
179 
189  static typename boost::optional<typename Tag::key_t> key(Packet const & packet, NoThrow_t);
190 
196  static Entry const & lookup(typename Tag::key_t key);
197 
202  static Entry const * lookup(typename Tag::key_t key, NoThrow_t);
203 
206  static iterator begin();
207 
210  static iterator end();
211 
212  private:
215 
216  PacketRegistry();
217 
218  typedef detail::PacketRegistryImpl<typename Tag::key_t> Registry;
219  static Registry & registry();
220  Registry registry_;
221 
223  };
224 
233 # define SENF_PACKET_REGISTRY_REGISTER( registry, value, type ) \
234  namespace { \
235  senf::PacketRegistry< registry >::ScopedRegistrationProxy< type > \
236  BOOST_PP_CAT(packetRegistration_, __LINE__) ( value ); \
237  }
238 
247 # define SENF_PACKET_REGISTRY_REGISTER_PRIORITY( registry, value, priority, type ) \
248  namespace { \
249  senf::PacketRegistry< registry >::ScopedRegistrationProxy< type > \
250  BOOST_PP_CAT(packetRegistration_, __LINE__) ( value, priority ); \
251  }
252 
258  void dumpPacketRegistries(std::ostream & os);
259 
265  { PacketTypeNotRegisteredException() : senf::Exception("packet type not registered") {} };
266 
267 }
268 
269 //-/////////////////////////////////////////////////////////////////////////////////////////////////
270 #endif
271 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketRegistry_i_)
272 #define HH_SENF_Packets_PacketRegistry_i_
273 #include "PacketRegistry.cci"
274 #include "PacketRegistry.ct"
275 #include "PacketRegistry.cti"
276 #endif
277 
278 
279 // Local Variables:
280 // mode: c++
281 // fill-column: 100
282 // c-file-style: "senf"
283 // indent-tabs-mode: nil
284 // ispell-local-dictionary: "american"
285 // compile-command: "scons -u test"
286 // comment-column: 40
287 // End:
detail::PacketRegistryImpl< typename Tag::key_t >::iterator iterator
void dumpPacketRegistries(std::ostream &os)
Dump all packet registries.
static void registerPacket(typename Tag::key_t key, int priority=0)
Register new packet type.
Statically register a packet type in a PacketRegistry.
static iterator begin()
Beginning iterator to list of registered entries.
Main Packet class.
Definition: Packet.hh:131
raw_container::iterator iterator
Definition: PacketTypes.hh:69
Packet public header.
detail::PacketRegistryImpl< typename Tag::key_t >::Entry Entry
static Entry const & lookup(typename Tag::key_t key)
Lookup a packet by it&#39;s key.
NoThrow_t
ScopedRegistrationProxy(typename Tag::key_t key, int priority=0)
static void unregisterPacket()
Unregister packet by packet type.
static iterator end()
End iterator to list of registered entries.
Packet registration facility
static Tag::key_t key()
Find key of a packet type.
Entry not found in registry.