senf::PacketRegistry< Tag > Class Template Reference

Packet registration facility More...

#include <senf/Packets/PacketRegistry.hh>

Inheritance diagram for senf::PacketRegistry< Tag >:

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

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.

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

Member Typedef Documentation

◆ Entry

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

Definition at line 83 of file PacketRegistry.hh.

◆ iterator

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

Definition at line 82 of file PacketRegistry.hh.

Member Function Documentation

◆ begin()

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

Beginning iterator to list of registered entries.

◆ end()

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

End iterator to list of registered entries.

◆ key() [1/4]

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

Find key of a packet type.

Return the key of PacketType as registered in the Tag registry

Template Parameters
PacketTypepacket of which the key is requested
Returns
key of the packet
Exceptions
PacketTypeNotRegisteredif the packet type is not found in the registry.

◆ key() [2/4]

template<class Tag>
template<class PacketType >
static boost::optional<typename Tag::key_t> senf::PacketRegistry< Tag >::key ( NoThrow_t  )
static

Find key of a packet type.

Return the key of PacketType as registered in the Tag registry

Template Parameters
PacketTypepacket 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.

◆ key() [3/4]

template<class Tag>
static Tag::key_t senf::PacketRegistry< Tag >::key ( Packet const &  packet)
static

Find key of a packet.

Return the key of packet, an arbitrary packet, as registered in the Tag registry.

Parameters
packetThe packet of which the key is requested
Returns
key of the packet
Exceptions
PacketTypeNotRegisteredif the packet type is not found in the registry.

◆ key() [4/4]

template<class Tag>
static boost::optional<typename Tag::key_t> senf::PacketRegistry< Tag >::key ( Packet const &  packet,
NoThrow_t   
)
static

Find key of a packet.

Return the key of packet, an arbitrary packet, as registered in the Tag registry.

Parameters
packetThe 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.

◆ lookup() [1/2]

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

Lookup a packet by it's key.

Exceptions
PacketTypeNotRegisteredif the key is not found in the registry
Returns
Packet entry for given key

◆ lookup() [2/2]

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

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.

◆ registerPacket()

template<class Tag>
template<class PacketType >
static void senf::PacketRegistry< Tag >::registerPacket ( typename Tag::key_t  key,
int  priority = 0 
)
static

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
PacketTypeConcretePacket instantiation of packet to register
Parameters
[in]keyThe key of the packet
[in]priorityOptional priority

◆ unregisterPacket() [1/2]

template<class Tag>
template<class PacketType >
static void senf::PacketRegistry< Tag >::unregisterPacket ( )
static

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
PacketTypeConcretePacket instantiation of packet to remove from registry

◆ unregisterPacket() [2/2]

template<class Tag>
static void senf::PacketRegistry< Tag >::unregisterPacket ( typename Tag::key_t  key,
int  priority = 0 
)
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.

Parameters
[in]keyKey to remove from the registry
[in]priorityOptional priority of the key to remove

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