NEW FILE HEADER / COPYRIGHT FORMAT
[senf.git] / Packets / PacketType.hh
index 5d34507..8a519db 100644 (file)
@@ -1,6 +1,8 @@
+// $Id$
+//
 // Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Fraunhofer Institute for Open Communication Systems (FOKUS) 
+// Competence Center NETwork research (NET), St. Augustin, GERMANY 
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -100,7 +102,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,16 +216,16 @@ 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 
-            : public senf::PacketTypeBase
-              public senf:PacketTypeMixin<SimplePacketType, SomeRegistryTag>
+            : public senf::PacketTypeBase,
+              public senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag>
         {
             typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin;
             typedef senf::ConcretePacket<SimplePacketType> packet;
@@ -266,11 +268,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)
             }
@@ -287,8 +294,8 @@ namespace senf {
 
         \code
         struct SimplePacketType 
-            : public senf::PacketTypeBase
-              public senf:PacketTypeMixin<SimplePacketType, SomeRegistryTag>
+            : public senf::PacketTypeBase,
+              public senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag>
         {
             typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin;
             typedef senf::ConcretePacket<SimplePacketType> packet;
@@ -300,7 +307,7 @@ namespace senf {
             using mixin::init;         
 
             static registry_key_t nextPacketKey(packet p)
-            { return i.fields().typeField(); }
+            { return p->typeField(); }
         };
         \endcode
 
@@ -314,11 +321,30 @@ namespace senf {
     {
     public:
         typedef typename Registry::key_t registry_key_t;
+        typedef boost::optional<registry_key_t> 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
@@ -338,7 +364,7 @@ namespace senf {
 
 ///////////////////////////////hh.e////////////////////////////////////////
 #endif
-#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketType_i_)
+#if !defined(HH_Packets__decls_) && !defined(HH_PacketType_i_)
 #define HH_PacketType_i_
 #include "PacketType.cci"
 //#include "PacketType.ct"