X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketType.hh;h=88768f2033575d07bca8c4c5c7328b49aab0a2b0;hb=41fe0d795abca302db24e7a955df6ef15ffed722;hp=03af113c613688f6b5b4ca74b89b49c149b85a1e;hpb=2d6585ff852e9d282c17003ba1db0b73eb3a8500;p=senf.git diff --git a/Packets/PacketType.hh b/Packets/PacketType.hh index 03af113..88768f2 100644 --- a/Packets/PacketType.hh +++ b/Packets/PacketType.hh @@ -100,7 +100,7 @@ namespace senf { \endcode You may leave out any one of the members (you should however always define the \c - interpreter typedef member) + packet typedef member) \ingroup packet_module */ @@ -214,11 +214,11 @@ namespace senf { /** \brief Mixin to provide standard implementations for nextPacketRange and nextPacketType - This mixin class simplifies the definition of simple packets with fixed-size headers and/or - trailers. For this type of Packet, this mixin provides the nextPacketRange() member. If you - additionally provide the optional \a Registry argument, PacketTypeMixin provides a simple - implementation of nextPacketType. When using the PacketTypeMixin, the implementation of a - packet is simplified to: + This mixin class simplifies the definition of simple packets with fixed-size (!) headers + and/or trailers. For this type of Packet, this mixin provides the nextPacketRange() + member. If you additionally provide the optional \a Registry argument, PacketTypeMixin + provides a simple implementation of nextPacketType. When using the PacketTypeMixin, the + implementation of a packet is simplified to: \code // Here 'SomeRegistryTag' is optional struct SimplePacketType @@ -266,11 +266,16 @@ namespace senf { // Return the key in the registry under which the next packet // header is to be found. This member must be given if a Registry argument is // passed to the PacketTypeMixin template. - return i.fields().typeField(); + return p->typeField(); } static void finalize(packet p) { + // Set the type field by querying the type of the next packet. This is an + // optional assignment: If the key is not found, the value returned by 'key' + // is an empty optional and the assignment will be skipped. + p->typeField << key(p.next()); + // optionally complete the packet by generating auto-generated information // (like checksums) } @@ -300,7 +305,7 @@ namespace senf { using mixin::init; static registry_key_t nextPacketKey(packet p) - { return i.fields().typeField(); } + { return p->typeField(); } }; \endcode @@ -314,13 +319,34 @@ namespace senf { { public: typedef typename Registry::key_t registry_key_t; + typedef boost::optional optional_registry_key_t; + + static optional_registry_key_t key (Packet p); ///< Find key of packet from registry + /**< key() will query the registry to find the key of the + given packet. Whereas \c nextPacketKey() as implemented + by the mixin user will provide the registry key of the + next packet from information stored in the current + packets header, the key() member will look up the type + of packet \a p in the registry and return it's + key. + + If either \a p is an in - valid() packet or the packet + type is not found in the registry, the returned + optional value will be empty. */ + + ///\name PacketType interface implementation + ///@{ static PacketInterpreterBase::optional_range nextPacketRange (Packet p); static PacketInterpreterBase::factory_t nextPacketType (Packet p); static PacketInterpreterBase::size_type initSize (); static void init (Packet p); + + ///@} }; +# ifndef DOXYGEN + template class PacketTypeMixin { @@ -330,6 +356,8 @@ namespace senf { static void init (Packet p); }; +# endif + } ///////////////////////////////hh.e//////////////////////////////////////// @@ -352,11 +380,3 @@ namespace senf { // comment-column: 40 // End: -// LocalWords: Fraunhofer Institut fuer offene Kommunikationssysteme FOKUS de -// LocalWords: Kompetenzzentrum Satelitenkommunikation SatCom Bund berlios dil -// LocalWords: PacketType struct SomePacketType senf PacketTypeBase initSize -// LocalWords: ConcretePacket init initHeadSize nextPacketRange NextPacket os -// LocalWords: nextPacketType std ostream endcode ingroup VoidPacketParser Ok -// LocalWords: tt li OtherPacketType Mixin mixin SimplePacketType typeField -// LocalWords: PacketTypeMixin SomeRegistryTag SomePacketParser nextPacketKey -// LocalWords: hh