Packets: Some more porting of old parsers to the new parse helpers
g0dil [Wed, 17 Oct 2007 07:58:43 +0000 (07:58 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@466 270642c3-0616-0410-b53a-bc976706d245

Packets/MPEGDVBBundle/SNDUPacket.cc
Packets/MPEGDVBBundle/SNDUPacket.hh
Packets/MPEGDVBBundle/TransportPacket.hh
Utils/Exception.hh
doclib/Doxyfile.global

index abf9783..8b5d048 100644 (file)
 //}
 
 
-prefix_ senf::PacketParserBase::size_type senf::Parse_SNDUPacket::bytes()
-    const
-{
-    if ( d_bit() )
-        return 2 + 2 + 4;  // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
-    else
-        return 2 + 2 + 4 + 6;  // + 6 Byte NPA destination address
-}
-
 prefix_ boost::uint32_t senf::Parse_SNDUPacket::calcCrc()
     const
 {
index 872a39e..19d9b8d 100644 (file)
@@ -45,37 +45,29 @@ namespace senf {
      */
     struct Parse_SNDUPacket : public PacketParserBase
     {
-        Parse_SNDUPacket(data_iterator i, state_type s) : PacketParserBase(i,s) {}
-        
-        typedef Parse_Flag      <     0 > Parse_daaf;  // Destination Address Absent Field
-        typedef Parse_UIntField < 1, 16 > Parse_length;
-                
-        Parse_daaf d_bit() const {
-            return parse<Parse_daaf>( 0 );
-        }
-        Parse_length length() const {
-            return parse<Parse_length>( 0 );
-        }
-        Parse_UInt16 type() const {
-            return parse<Parse_UInt16>( 2 );
-        }
-        Parse_MAC destination() const {
+#       include SENF_PARSER()
+
+        SENF_PARSER_BITFIELD     ( d_bit       ,  1 , bool     );
+        SENF_PARSER_BITFIELD     ( length      , 15 , unsigned );
+
+        SENF_PARSER_FIELD        ( type        , Parse_UInt16  );
+
+        // This field only exists, if d_bit() is *not* set. New SNDUPackets are created with d_bit()
+        // set to 0, they have destination. We set the size of this field depending on the value of
+        // d_bit(), the init_bytes value is set to 6 bytes (the size of a MAC address)
+        SENF_PARSER_CUSTOM_FIELD ( destination , Parse_MAC     , d_bit() ? 0 : 6 , 6 ) {
             BOOST_ASSERT( ! d_bit() );
-            return parse<Parse_MAC>( 4 );
+            return parse<destination_t>( destination_offset() );
         }
-        Parse_UInt32 crc() const { 
-            return parse<Parse_UInt32>( data().size()-4 ); 
-        }
-        
-        void init() const {
-            defaultInit();
-            d_bit() = false;
+
+        // This field is placed at the end of the parser. It is therefore only considered for
+        // calculating init_bytes but not for calculating bytes()
+        SENF_PARSER_CUSTOM_FIELD ( crc         , Parse_UInt32  , 0 , 4 ) {
+            return parse<crc_t>( data().size() - 4 );
         }
-        
-        PacketParserBase::size_type bytes() const;
-        
-        static const size_type init_bytes = 2+2+4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
 
+        SENF_PARSER_FINALIZE( Parse_SNDUPacket );
+        
         boost::uint32_t calcCrc() const;
     };
 
index 7f21415..d8d6ff6 100644 (file)
@@ -45,15 +45,15 @@ namespace senf {
     {
 #       include SENF_FIXED_PARSER()
 
-        SENF_PARSER_FIELD( sync_byte, Parse_UInt8 );
+        SENF_PARSER_FIELD    ( sync_byte                 , Parse_UInt8   );
         
-        SENF_PARSER_BITFIELD( transport_error_indicator,  1, bool     );
-        SENF_PARSER_BITFIELD( pusi,                       1, bool     );
-        SENF_PARSER_BITFIELD( transport_priority,         1, bool     );
-        SENF_PARSER_BITFIELD( pid,                       13, unsigned );
-        SENF_PARSER_BITFIELD( transport_scrmbl_ctrl,      2, unsigned );
-        SENF_PARSER_BITFIELD( adaptation_field_ctrl,      2, unsigned );
-        SENF_PARSER_BITFIELD( continuity_counter,         4, unsigned );
+        SENF_PARSER_BITFIELD ( transport_error_indicator ,  1 , bool     );
+        SENF_PARSER_BITFIELD ( pusi                      ,  1 , bool     );
+        SENF_PARSER_BITFIELD ( transport_priority        ,  1 , bool     );
+        SENF_PARSER_BITFIELD ( pid                       , 13 , unsigned );
+        SENF_PARSER_BITFIELD ( transport_scrmbl_ctrl     ,  2 , unsigned );
+        SENF_PARSER_BITFIELD ( adaptation_field_ctrl     ,  2 , unsigned );
+        SENF_PARSER_BITFIELD ( continuity_counter        ,  4 , unsigned );
 
         SENF_PARSER_FINALIZE( Parse_TransportPacket );
     
index 37f18d3..a3c66a9 100644 (file)
@@ -66,6 +66,7 @@ namespace senf {
         int err; ///< Error number
 
         virtual ~SystemException() throw();
+
     private:
         void init();
         std::string buffer_;
index c91d4a1..a9a4c4b 100644 (file)
@@ -29,23 +29,26 @@ MACRO_EXPANSION        = YES
 EXPAND_ONLY_PREDEF     = YES
 PREDEFINED             = DOXYGEN \
                          "SENF_PPI_MODULE(x)=" \
+                         "SENF_PARSER_INHERIT(name)=" \
                          "SENF_PARSER_FIELD(name,type)=type name() const" \
                          "SENF_PARSER_FIELD_RO(name,type)=type::value_type name() const" \
-                         "SENF_PARSER_FIELD_AFTER(name,type,prev)=type name() const" \
-                         "SENF_PARSER_FIELD_AFTER_RO(name,type,prev)=type::value_type name() const" \
-                         "SENF_PARSER_BITFIELD(name, bits, type)=senf::ParseField_ ## type name() const" \
-                         "SENF_PARSER_BITFIELD_RO(name, bits, type)=type ## _ ## bits name() const" \
-                         "SENF_PARSER_INHERIT(name)=" \
-                         "SENF_PARSER_FINALIZE(name)=" \
-                         "SENF_PARSER_INIT()=void init()" \
+                         "SENF_PARSER_BITFIELD(name, bits, type)=senf::ParseField_ ## type(bits) name() const" \
+                         "SENF_PARSER_BITFIELD_RO(name, bits, type)=senf::ParseField_ ## type(bits)::value_type name() const" \
+                         "SENF_PARSER_CUSTOM_FIELD(name, type, size, isize)=type name() const" \
+                         "SENF_PARSER_PRIVATE_FIELD(name,type)=private: type name() const; public:" \
+                         "SENF_PARSER_PRIVATE_FIELD_RO(name, type)=private: type::value_type name() const; public:" \
+                         "SENF_PARSER_PRIVATE_BITFIELD(name, bits, type)=private: senf::ParseField_ ## type(bits) name() const; public:" \
+                         "SENF_PARSER_PRIVATE_BITFIELD_RO(name, bits, type)=private: senf::ParseField_ ## type(bits)::value_type name() const; public:" \
                          "SENF_PARSER_SKIP(x)=" \
                          "SENF_PARSER_SKIP_BITS(x)=" \
                          "SENF_PARSER_GOTO(x)=" \
                          "SENF_PARSER_GOTO_OFFSET(x)=" \
                          "SENF_PARSER_LABEL(x)=" \
-                         "ParseField_unsigned=Parse_UIntField" \
-                         "ParseField_signed=Parse_IntField" \
-                         "ParseField_bool=Parse_Flag"
+                         "SENF_PARSER_INIT()=void init()" \
+                         "SENF_PARSER_FINALIZE(name)=" \
+                         "ParseField_unsigned(b)=Parse_UIntField<?,?+b>" \
+                         "ParseField_signed(b)=Parse_IntField<?,?+b>" \
+                         "ParseField_bool(b)=Parse_Flag<?>"
 EXPAND_AS_DEFINED      = prefix_
 
 HTML_HEADER            = "$(TOPDIR)/doclib/doxy-header.html"