First GRE pipe is running.
[senf.git] / Packets / MPEGDVBBundle / TLVPacket.hh
index e0ff4e0..3954df9 100644 (file)
 
 // Custom includes
 #include <algorithm>
-#include "../../Packets/PacketType.hh"
-#include "../../Packets/ParseInt.hh"
-#include "../../Packets/PacketParser.hh"
+#include "../../Packets/Packets.hh"
 
 //#include "TLVPacket.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
 
 namespace senf {
 
+    /** \brief xxx
+        
+        \todo document me
+        \todo add usefull exceptions strings
+         
+    */
     struct UnsuportedTLVPacketException : public std::exception
     { 
         virtual char const * what() const throw() { 
@@ -44,27 +48,26 @@ namespace senf {
         }
     };
 
+    /** \brief xxx
+        \todo document me
+    */
     class Parse_TLVPacketLength 
         : public detail::packet::ParseIntOps<Parse_TLVPacketLength, boost::uint32_t>,
           public PacketParserBase
     {
     public:
-#       ifndef DOXYGEN
-        
-        SENF_PACKET_PARSER_NO_INIT(Parse_TLVPacketLength);
-
-#       endif
+        Parse_TLVPacketLength(data_iterator i, state_type s) : PacketParserBase(i,s) {}
 
         typedef boost::uint32_t value_type;
-    
-        value_type value() const;
+        static const size_type init_bytes = 1;
+        static value_type const min_value = 0;
+        static value_type const max_value = 4294967295u;
 
+        value_type value() const;
         void value(value_type const & v);
         
         Parse_TLVPacketLength const & operator= (value_type other);
-            
-        static const size_type init_bytes = 1;
-
+    
         size_type bytes() const;
             
         void init() const;
@@ -86,55 +89,55 @@ namespace senf {
         
     /** \brief parse TLVPacket Packet
     
-        XXX
-        
+        \todo document me
+     
         \see TLVPacketType
      */
+    template <class LengthParser>
     struct Parse_TLVPacket : public PacketParserBase
     {
-#       ifndef DOXYGEN
+#       include SENF_PARSER()
         
-        SENF_PACKET_PARSER_INIT(Parse_TLVPacket);
+        SENF_PARSER_FIELD( type,   Parse_UInt32 );
+        SENF_PARSER_FIELD( length, LengthParser );
         
-        SENF_PACKET_PARSER_DEFINE_FIELDS(
-            ((Field)( type,   Parse_UInt32          ))
-            ((Field)( length, Parse_TLVPacketLength ))
-        );
-        
-#       endif
+        SENF_PARSER_FINALIZE(Parse_TLVPacket);
     };
-
-    /** \brief TLV Packet
+    
+    /** \brief generic TLV Packet type
+        
+        \todo document me
         
-        \par Packet type (typedef):
-            \ref TLVPacket
-
-        \par Fields:
-            \ref Parse_TLVPacket
-
         \ingroup protocolbundle_mpegdvb
      */
+    template <class LengthParser>
     struct TLVPacketType
         : public PacketTypeBase
     {
-        typedef ConcretePacket<TLVPacketType> packet;
-        typedef Parse_TLVPacket parser;
-
+#ifndef DOXYGEN
+        typedef ConcretePacket<TLVPacketType<LengthParser> > packet;
+        typedef Parse_TLVPacket<LengthParser> parser;
+#endif
         static optional_range nextPacketRange(packet p);
-        static void init(packet p);
         static size_type initSize();
+        
         static void finalize(packet p);
+        
         static void dump(packet p, std::ostream & os);
     };
-        
-    typedef TLVPacketType::packet TLVPacket;
+
+    typedef TLVPacketType<Parse_TLVPacketLength>::packet TLVPacket;
     
+    typedef ConcretePacket<TLVPacketType<Parse_UInt8> >  TLVFix8Packet;
+    typedef ConcretePacket<TLVPacketType<Parse_UInt16> > TLVFix16Packet;
+    typedef ConcretePacket<TLVPacketType<Parse_UInt24> > TLVFix24Packet;
+    typedef ConcretePacket<TLVPacketType<Parse_UInt32> > TLVFix32Packet;
 }
 
 
 ///////////////////////////////hh.e////////////////////////////////////////
 //#include "TLVPacket.cci"
-//#include "TLVPacket.ct"
+#include "TLVPacket.ct"
 //#include "TLVPacket.cti"
 #endif