Packets: Macros and unit-tests for the PacketRegistry priority support
[senf.git] / senf / Packets / PacketRegistry.hh
index e766914..befc1a5 100644 (file)
@@ -91,6 +91,7 @@ namespace senf {
     {
     public:
         typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::iterator iterator;
+        typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::Entry Entry;
 
         /** \brief Statically register a packet type in a PacketRegistry
 
@@ -108,7 +109,7 @@ namespace senf {
         template <class PacketType>
         struct RegistrationProxy
         {
-            RegistrationProxy(typename Tag::key_t key);
+            RegistrationProxy(typename Tag::key_t key, int priority=0);
             ~RegistrationProxy();
         };
 
@@ -125,11 +126,11 @@ namespace senf {
             \param key The key of the packet
          */
         template <class PacketType>
-        static void registerPacket(typename Tag::key_t key);
+        static void registerPacket(typename Tag::key_t key, int priority=0);
 
         template <class PacketType>
         static void unregisterPacket();
-        static void unregisterPacket(typename Tag::key_t key);
+        static void unregisterPacket(typename Tag::key_t key, int priority=0);
 
         /** \brief Find key of a packet type
 
@@ -180,13 +181,13 @@ namespace senf {
             \throws PacketTypeNotRegistered if the \a key is not found in the registry
             \return %Packet entry for given \a key
          */
-        static PkReg_Entry const & lookup(typename Tag::key_t key);
+        static Entry const & lookup(typename Tag::key_t key);
 
         /** \brief Lookup a packet by it's key
             \return Pointer to packet entry for given \a key or 0, if the key is not found in the
                 registry.
          */
-        static PkReg_Entry const * lookup(typename Tag::key_t key, NoThrow_t);
+        static Entry const * lookup(typename Tag::key_t key, NoThrow_t);
 
         /** \brief Beginning iterator to list of registered keys
          */
@@ -209,10 +210,24 @@ namespace senf {
         \ingroup packet_module
         \hideinitializer
      */
-#   define SENF_PACKET_REGISTRY_REGISTER( registry, value, type )                                 \
-        namespace {                                                                               \
-            senf::PacketRegistry< registry >::RegistrationProxy< type >                           \
-                BOOST_PP_CAT(packetRegistration_, __LINE__) ( value );                            \
+#   define SENF_PACKET_REGISTRY_REGISTER( registry, value, type )       \
+        namespace {                                                     \
+            senf::PacketRegistry< registry >::RegistrationProxy< type > \
+            BOOST_PP_CAT(packetRegistration_, __LINE__) ( value );      \
+        }
+
+    /** \brief Statically add an entry to a packet registry
+
+        This macro will declare an anonymous global variable in such a way, that constructing this
+        variable will add a registration to the given packet registry.
+
+        \ingroup packet_module
+        \hideinitializer
+     */
+#   define SENF_PACKET_REGISTRY_REGISTER_PRIORITY( registry, value, priority, type ) \
+        namespace {                                                     \
+            senf::PacketRegistry< registry >::RegistrationProxy< type > \
+            BOOST_PP_CAT(packetRegistration_, __LINE__) ( value, priority ); \
         }
 
     /** \brief Dump all packet registries