#include <senf/Packets/PacketRegistry.hh>
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:
struct SomeTag { typedef some_key_type key_t; };
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.
senf::Packet::factory_t factory (senf::PacketRegistry<SomeTag>::lookup(some_key).factory()); SomeTag::key_t key = PacketRegistry<SomeTag>::key<SomePacket>();
Packets can be registered either dynamically or statically. Dynamic:
// dynamic registration senf::PacketRegistry<SomeTag>::registerPacket<SomePacket>(key_of_somePacket); // static registration. 'registerSomePacket' is an arbitrary symbol name SENF_PACKET_REGISTRY_REGISTER( SomeTag, key_of_somePacket, SomePacket );
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).
Definition at line 87 of file 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. |
|
template<class PacketType > | |
static void | unregisterPacket () |
Unregister packet by packet type. |
|
static void | unregisterPacket (typename Tag::key_t key, int priority=0) |
Unregister packet by key. |
|
template<class PacketType > | |
static Tag::key_t | key () |
Find key of a packet type. |
|
template<class PacketType > | |
static boost::optional < typename Tag::key_t > |
key (NoThrow_t) |
Find key of a packet type. |
|
static Tag::key_t | key (Packet const &packet) |
Find key of a packet. |
|
static boost::optional < typename Tag::key_t > |
key (Packet const &packet, NoThrow_t) |
Find key of a packet. |
|
static Entry const & | lookup (typename Tag::key_t key) |
Lookup a packet by it's key. |
|
static Entry const * | lookup (typename Tag::key_t key, NoThrow_t) |
Lookup a packet by it's key. |
|
static iterator | begin () |
Beginning iterator to list of registered entries. |
|
static iterator | end () |
End iterator to list of registered entries. |
typedef detail::PacketRegistryImpl<typename Tag::key_t>::Entry senf::PacketRegistry< Tag >:: | ||||
Entry | ||||
Definition at line 92 of file PacketRegistry.hh.
typedef detail::PacketRegistryImpl<typename Tag::key_t>::iterator senf::PacketRegistry< Tag >:: | ||||
iterator | ||||
Definition at line 91 of file PacketRegistry.hh.
senf::PacketRegistry< Tag >::iterator senf::PacketRegistry< Tag >:: | ||||
begin | () | |||
Beginning iterator to list of registered entries.
Definition at line 122 of file PacketRegistry.cti.
senf::PacketRegistry< Tag >::iterator senf::PacketRegistry< Tag >:: | ||||
end | () | |||
End iterator to list of registered entries.
Definition at line 128 of file PacketRegistry.cti.
boost::optional< typename Tag::key_t > senf::PacketRegistry< Tag >:: | ||||
key | ( | Packet const & | packet, | |
NoThrow_t | ) | |||
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 |
Definition at line 102 of file PacketRegistry.cti.
Tag::key_t senf::PacketRegistry< Tag >:: | ||||
key | ( | Packet const & | packet | ) |
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. |
Definition at line 95 of file PacketRegistry.cti.
boost::optional< typename Tag::key_t > senf::PacketRegistry< Tag >:: | ||||
key | ( | NoThrow_t | ) | |
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 |
Definition at line 89 of file PacketRegistry.cti.
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. |
Definition at line 82 of file PacketRegistry.cti.
senf::PacketRegistry< Tag >::Entry const * senf::PacketRegistry< Tag >:: | ||||
lookup | ( | typename Tag::key_t | key, | |
NoThrow_t | ) | |||
Lookup a packet by it's key.
Definition at line 116 of file PacketRegistry.cti.
senf::PacketRegistry< Tag >::Entry const & senf::PacketRegistry< Tag >:: | ||||
lookup | ( | typename Tag::key_t | key | ) |
Lookup a packet by it's key.
PacketTypeNotRegistered | if the key is not found in the registry |
Definition at line 109 of file PacketRegistry.cti.
void senf::PacketRegistry< Tag >:: | ||||
registerPacket | ( | typename Tag::key_t | key, | |
int |
priority = 0
|
) | ||
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 |
Definition at line 60 of file PacketRegistry.cti.
void senf::PacketRegistry< Tag >:: | ||||
unregisterPacket | ( | typename Tag::key_t | key, | |
int |
priority = 0
|
) | ||
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 |
Definition at line 74 of file PacketRegistry.cti.
void senf::PacketRegistry< Tag >:: | ||||
unregisterPacket | () | |||
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 |
Definition at line 67 of file PacketRegistry.cti.