senf::PacketRegistry< Tag > Class Template Reference
[Packet Handling]

Packet registration facility More...

#include <senf/Packets/PacketRegistry.hh>

Inheritance diagram for senf::PacketRegistry< Tag >:
Inheritance graph
[legend]

List of all members.


Detailed Description

template<class Tag>
class senf::PacketRegistry< Tag >

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:

struct SomeTag {
    typedef some_key_type key_t;
};
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.

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).

Multiple registration for a single key

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 key as long as the priority is unique. The registration with the highest priority value will take precedence on key lookup.

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.

Member Typedef Documentation

template<class Tag>
typedef detail::PacketRegistryImpl<typename Tag::key_t>::Entry senf::PacketRegistry< Tag >::
Entry

Definition at line 92 of file PacketRegistry.hh.

template<class Tag>
typedef detail::PacketRegistryImpl<typename Tag::key_t>::iterator senf::PacketRegistry< Tag >::
iterator

Definition at line 91 of file PacketRegistry.hh.


Member Function Documentation

template<class Tag >
senf::PacketRegistry< Tag >::iterator senf::PacketRegistry< Tag >::
begin ()

Beginning iterator to list of registered entries.

Definition at line 122 of file PacketRegistry.cti.

template<class Tag >
senf::PacketRegistry< Tag >::iterator senf::PacketRegistry< Tag >::
end ()

End iterator to list of registered entries.

Definition at line 128 of file PacketRegistry.cti.

template<class Tag >
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.

Parameters:
packet  The packet of which the key is requested
Returns:
key of the packet wrapped in a boost::optional or an unbound optional, if the key is not found.

Definition at line 102 of file PacketRegistry.cti.

template<class Tag >
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.

Parameters:
packet  The packet of which the key is requested
Returns:
key of the packet
Exceptions:
PacketTypeNotRegistered  if the packet type is not found in the registry.

Definition at line 95 of file PacketRegistry.cti.

template<class Tag >
template<class PacketType >
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

Template Parameters:
PacketType  packet of which the key is requested
Returns:
key of the packet wrapped in a boost::optional or an unbound optional, if the key is not found.

Definition at line 89 of file PacketRegistry.cti.

template<class Tag >
template<class PacketType >
Tag::key_t senf::PacketRegistry< Tag >::
key ()

Find key of a packet type.

Return the key of PacketType as registered in the Tag registry

Template Parameters:
PacketType  packet of which the key is requested
Returns:
key of the packet
Exceptions:
PacketTypeNotRegistered  if the packet type is not found in the registry.

Definition at line 82 of file PacketRegistry.cti.

template<class Tag>
senf::PacketRegistry< Tag >::Entry const * senf::PacketRegistry< Tag >::
lookup ( typename Tag::key_t  key,
NoThrow_t  )

Lookup a packet by it's key.

Returns:
Pointer to packet entry for given key or 0, if the key is not found in the registry.

Definition at line 116 of file PacketRegistry.cti.

template<class Tag>
senf::PacketRegistry< Tag >::Entry const & senf::PacketRegistry< Tag >::
lookup ( typename Tag::key_t  key )

Lookup a packet by it's key.

Exceptions:
PacketTypeNotRegistered  if the key is not found in the registry
Returns:
Packet entry for given key

Definition at line 109 of file PacketRegistry.cti.

template<class Tag>
template<class PacketType >
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.

Preconditions:
The given pair key, priority must be unique and not be assigned to any other packet class in this registry. The Packet must not already be registered in the registry.
Template Parameters:
PacketType  ConcretePacket instantiation of packet to register
Parameters:
[in]  key  The key of the packet
[in]  priority  Optional priority

Definition at line 60 of file PacketRegistry.cti.

template<class Tag>
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.

Parameters:
[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.

template<class Tag >
template<class PacketType >
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.

Template Parameters:
PacketType  ConcretePacket instantiation of packet to remove from registry

Definition at line 67 of file PacketRegistry.cti.


The documentation for this class was generated from the following files: