Packet registration facility More...
#include <senf/Packets/PacketRegistry.hh>
Classes | |
struct | ScopedRegistrationProxy |
Statically register a packet type in a PacketRegistry. More... | |
Public Types | |
typedef detail::PacketRegistryImpl< typename Tag::key_t >::iterator | iterator |
typedef detail::PacketRegistryImpl< typename Tag::key_t >::Entry | Entry |
Static Public Member Functions | |
template<class PacketType > | |
static void | registerPacket (typename Tag::key_t key, int priority=0) |
Register new packet type. More... | |
template<class PacketType > | |
static void | unregisterPacket () |
Unregister packet by packet type. More... | |
static void | unregisterPacket (typename Tag::key_t key, int priority=0) |
Unregister packet by key. More... | |
template<class PacketType > | |
static Tag::key_t | key () |
Find key of a packet type. More... | |
template<class PacketType > | |
static boost::optional< typename Tag::key_t > | key (NoThrow_t) |
Find key of a packet type. More... | |
static Tag::key_t | key (Packet const &packet) |
Find key of a packet. More... | |
static boost::optional< typename Tag::key_t > | key (Packet const &packet, NoThrow_t) |
Find key of a packet. More... | |
static Entry const & | lookup (typename Tag::key_t key) |
Lookup a packet by it's key. More... | |
static Entry const * | lookup (typename Tag::key_t key, NoThrow_t) |
Lookup a packet by it's key. More... | |
static iterator | begin () |
Beginning iterator to list of registered entries. More... | |
static iterator | end () |
End iterator to list of registered entries. More... | |
Packet registration facility
The PacketRegistry provides a generic facility to associate an arbitrary key with Packets. Example keys are Ethertype or IP protocols.
Every PacketRegistry is identified by a type tag:
The key type can be an arbitrary value type. The PacketRegistry for this Tag can then be accessed using senf::PacketRegistry<SomeTag>::
.
The PacketRegistry class has only static members and provides access to the packet registry. It allows two-way lookup either by key or by packet type.
Packets can be registered either dynamically or statically. Dynamic:
SENF_PACKET_REGISTRY_REGISTER will declare an anonymous global variable which will ensure, the packet is registered automatically during global initialization (as long as the object file is linked into the final executable).
Ordinarily, the PacketRegistry will reject registering the same key twice. However, the registry supports an additional priority parameter when registering a packet. You may register multiple Packets with the same \a key as long as the \a priority is unique. The registration with the highest \a priority value will take precedence on key lookup.
Definition at line 78 of file PacketRegistry.hh.
typedef detail::PacketRegistryImpl<typename Tag::key_t>::Entry senf::PacketRegistry< Tag >::Entry |
Definition at line 83 of file PacketRegistry.hh.
typedef detail::PacketRegistryImpl<typename Tag::key_t>::iterator senf::PacketRegistry< Tag >::iterator |
Definition at line 82 of file PacketRegistry.hh.
|
static |
Beginning iterator to list of registered entries.
|
static |
End iterator to list of registered entries.
|
static |
Find key of a packet type.
Return the key of PacketType as registered in the Tag registry
PacketType | packet of which the key is requested |
PacketTypeNotRegistered | if the packet type is not found in the registry. |
|
static |
Find key of a packet type.
Return the key of PacketType as registered in the Tag registry
PacketType | packet of which the key is requested |
|
static |
Find key of a packet.
Return the key of packet, an arbitrary packet, as registered in the Tag registry.
packet | The packet of which the key is requested |
PacketTypeNotRegistered | if the packet type is not found in the registry. |
|
static |
Find key of a packet.
Return the key of packet, an arbitrary packet, as registered in the Tag registry.
packet | The packet of which the key is requested |
|
static |
Lookup a packet by it's key.
PacketTypeNotRegistered | if the key is not found in the registry |
|
static |
Lookup a packet by it's key.
|
static |
Register new packet type.
Register PacketType in the packet registry Tag under the given key.
PacketType | ConcretePacket instantiation of packet to register |
[in] | key | The key of the packet |
[in] | priority | Optional priority |
|
static |
Unregister packet by packet type.
Removes PacketType from the packet registry. If the packet type is not registered, this is a no-op.
PacketType | ConcretePacket instantiation of packet to remove from registry |
|
static |
Unregister packet by key.
Removes the packet registration for key (and priority) from the registry. If no packet is registered with the given pair key, priority, this operation is a no-op.
[in] | key | Key to remove from the registry |
[in] | priority | Optional priority of the key to remove |