From: g0dil Date: Tue, 16 Oct 2007 01:39:51 +0000 (+0000) Subject: Packets: Complete reimplementation of parse helper macros X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=54eed72c506b09ef5b4be0b62fecedfbc0e3f261;p=senf.git Packets: Complete reimplementation of parse helper macros git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@462 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/DataPacket.hh b/Packets/DataPacket.hh index 62e1200..ec536c0 100644 --- a/Packets/DataPacket.hh +++ b/Packets/DataPacket.hh @@ -53,7 +53,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_DataPacket_impl_) +#if !defined(HH_Packets__decls_) && !defined(HH_DataPacket_impl_) #define HH_DataPacket_impl_ //#include "DataPacket.cci" //#include "DataPacket.ct" diff --git a/Packets/DefaultBundle/EthernetPacket.hh b/Packets/DefaultBundle/EthernetPacket.hh index 359f05d..04516db 100644 --- a/Packets/DefaultBundle/EthernetPacket.hh +++ b/Packets/DefaultBundle/EthernetPacket.hh @@ -68,24 +68,13 @@ namespace senf { */ struct Parse_Ethernet : public PacketParserBase { - typedef Parse_UInt16 Parse_Type; +# include SENF_FIXED_PARSER() -# ifndef DOXYGEN + SENF_PARSE_FIELD( destination, Parse_MAC ); + SENF_PARSE_FIELD( source, Parse_MAC ); + SENF_PARSE_FIELD( type, Parse_UInt16 ); - SENF_PACKET_PARSER_INIT(Parse_Ethernet); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field)( destination, Parse_MAC )) - ((Field)( source, Parse_MAC )) - ((Field)( type, Parse_Type )) ); - -# else - - Parse_MAC destination(); - Parse_MAC source(); - Parse_Type type(); - -# endif + SENF_PARSER_FINALIZE(Parse_Ethernet); }; /** \brief EtherType registry @@ -146,29 +135,15 @@ namespace senf { */ struct Parse_EthVLan : public PacketParserBase { - typedef Parse_UIntField < 0, 3 > Parse_Priority; - typedef Parse_Flag < 3 > Parse_CFI; - typedef Parse_UIntField < 4, 16 > Parse_VLanId; - typedef Parse_UInt16 Parse_Type; - -# ifndef DOXYGEN - - SENF_PACKET_PARSER_INIT(Parse_EthVLan); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((OverlayField)( priority, Parse_Priority )) - ((OverlayField)( cfi, Parse_CFI )) - ((Field )( vlanId, Parse_VLanId )) - ((Field )( type, Parse_Type )) ); +# include SENF_FIXED_PARSER() -# else + SENF_PARSE_BITFIELD( priority, 3, unsigned ); + SENF_PARSE_BITFIELD( cfi, 1, bool ); + SENF_PARSE_BITFIELD( vlanId, 12, unsigned ); - Parse_Priority priority(); - Parse_CFI cfi(); - Parse_VLanId vlanId(); - Parse_Type type(); + SENF_PARSE_FIELD( type, Parse_UInt16 ); -# endif + SENF_PARSER_FINALIZE(Parse_EthVLan); }; /** \brief Ethernet VLAN tag diff --git a/Packets/DefaultBundle/IpV4Packet.hh b/Packets/DefaultBundle/IpV4Packet.hh index 855f957..f293909 100644 --- a/Packets/DefaultBundle/IpV4Packet.hh +++ b/Packets/DefaultBundle/IpV4Packet.hh @@ -67,63 +67,36 @@ namespace senf { */ struct Parse_IpV4 : public PacketParserBase { - typedef Parse_UIntField < 0, 4 > Parse_Version; - typedef Parse_UIntField < 4, 8 > Parse_IHL; - typedef Parse_UInt8 Parse_8bit; - typedef Parse_UInt16 Parse_16bit; - typedef Parse_Flag < 0 > Parse_R; - typedef Parse_Flag < 1 > Parse_DF; - typedef Parse_Flag < 2 > Parse_MF; - typedef Parse_UIntField < 3, 16 > Parse_Frag; - typedef Parse_UInt32 Parse_32bit; - typedef Parse_INet4Address Parse_Addr; - -# ifndef DOXYGEN - - SENF_PACKET_PARSER_NO_INIT(Parse_IpV4); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((OverlayField)( version, Parse_Version )) - ((Field )( ihl, Parse_IHL )) - ((Field )( tos, Parse_8bit )) - ((Field )( length, Parse_16bit )) - ((Field )( identifier, Parse_16bit )) - ((OverlayField)( reserved, Parse_R )) - ((OverlayField)( df, Parse_DF )) - ((OverlayField)( mf, Parse_MF )) - ((Field )( frag, Parse_Frag )) - ((Field )( ttl, Parse_8bit )) - ((Field )( protocol, Parse_8bit )) - ((Field )( checksum, Parse_16bit )) - ((Field )( source, Parse_Addr )) - ((Field )( destination, Parse_Addr )) ); - -# else - - Parse_Version version() const; - Parse_IHL ihl() const; - Parse_8bit tos() const; - Parse_16bit length() const; - Parse_16bit identifier() const; - Parse_R reserved() const; - Parse_DF df() const; - Parse_MF mf() const; - Parse_Frag frag() const; - Parse_8bit ttl() const; - Parse_8bit protocol() const; - Parse_16bit checksum() const; - Parse_Addr source() const; - Parse_Addr destination() const; - -# endif - - void init() { +# include SENF_FIXED_PARSER() + + SENF_PARSE_BITFIELD( version, 4, unsigned ); + SENF_PARSE_BITFIELD( ihl, 4, unsigned ); + + SENF_PARSE_FIELD( tos, Parse_UInt8 ); + SENF_PARSE_FIELD( length, Parse_UInt16 ); + SENF_PARSE_FIELD( identifier, Parse_UInt16 ); + + SENF_PARSE_BITFIELD( reserved, 1, bool ); + SENF_PARSE_BITFIELD( df, 1, bool ); + SENF_PARSE_BITFIELD( mf, 1, bool ); + SENF_PARSE_BITFIELD( frag, 13, unsigned ); + + SENF_PARSE_FIELD( ttl, Parse_UInt8 ); + SENF_PARSE_FIELD( protocol, Parse_UInt8 ); + SENF_PARSE_FIELD( checksum, Parse_UInt16 ); + SENF_PARSE_FIELD( source, Parse_INet4Address ); + SENF_PARSE_FIELD( destination, Parse_INet4Address ); + + SENF_PARSER_INIT() { version() = 4; // We don't support option headers at the moment ... ihl() = 5; } + + SENF_PARSER_FINALIZE(Parse_IpV4); boost::uint16_t calcChecksum() const; + bool validateChecksum() const { return checksum() == calcChecksum(); } diff --git a/Packets/DefaultBundle/IpV6Extensions.hh b/Packets/DefaultBundle/IpV6Extensions.hh index 37e74c7..e04c6bb 100644 --- a/Packets/DefaultBundle/IpV6Extensions.hh +++ b/Packets/DefaultBundle/IpV6Extensions.hh @@ -41,34 +41,18 @@ namespace senf { */ struct Parse_IpV6Extension_Fragment : public PacketParserBase { - typedef Parse_UInt8 Parse_8bit; - typedef Parse_UIntField < 0, 13 > Parse_Offset; - typedef Parse_UIntField < 13, 15 > Parse_Reserved; - typedef Parse_Flag < 15 > Parse_More; - typedef Parse_UInt32 Parse_32bit; - -# ifndef DOXYGEN - - SENF_PACKET_PARSER_INIT(Parse_IpV6Extension_Fragment); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field )( nextHeader , Parse_8bit )) - ((Field )( reserved1 , Parse_8bit )) - ((OverlayField)( fragmentOffset , Parse_Offset )) - ((OverlayField)( reserved2 , Parse_Reserved )) - ((Field )( moreFragments , Parse_More )) - ((Field )( id , Parse_32bit )) ); - -# else - - Parse_8bit nextHeader(); - Parse_8bit reserved1(); - Parse_Offset fragmentOffset(); - Parse_Reserved reserved2(); - Parse_More moreFragments(); - Parse_32bit id(); - -# endif +# include SENF_FIXED_PARSER() + + SENF_PARSE_FIELD( nextHeader , Parse_UInt8 ); + SENF_PARSE_FIELD( reserved1 , Parse_UInt8 ); + + SENF_PARSE_BITFIELD( fragmentOffset, 13, unsigned ); + SENF_PARSE_BITFIELD( reserved2, 2, unsigned ); + SENF_PARSE_BITFIELD( moreFragments, 1, bool ); + + SENF_PARSE_FIELD( id , Parse_UInt32 ); + + SENF_PARSER_FINALIZE(Parse_IpV6Extension_Fragment); }; /** \brief IpV6 fragment extension diff --git a/Packets/DefaultBundle/IpV6Packet.hh b/Packets/DefaultBundle/IpV6Packet.hh index 94a8799..646dd1c 100644 --- a/Packets/DefaultBundle/IpV6Packet.hh +++ b/Packets/DefaultBundle/IpV6Packet.hh @@ -62,43 +62,23 @@ namespace senf { */ struct Parse_IpV6 : public PacketParserBase { - typedef Parse_UIntField < 0, 4 > Parse_Version; - typedef Parse_UIntField < 4, 12 > Parse_Class; - typedef Parse_UIntField < 12, 32 > Parse_FlowLabel; - typedef Parse_UInt8 Parse_8bit; - typedef Parse_UInt16 Parse_16bit; - typedef Parse_INet6Address Parse_Addr; - -# ifndef DOXYGEN - - SENF_PACKET_PARSER_NO_INIT(Parse_IpV6); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((OverlayField)( version, Parse_Version )) - ((OverlayField)( trafficClass, Parse_Class )) - ((Field )( flowLabel, Parse_FlowLabel )) - ((Field )( length, Parse_16bit )) - ((Field )( nextHeader, Parse_8bit )) - ((Field )( hopLimit, Parse_8bit )) - ((Field )( source, Parse_Addr )) - ((Field )( destination, Parse_Addr )) ); - -# else - - Parse_Version version() const; - Parse_Class trafficClass() const; - Parse_FlowLabel flowLabel() const; - Parse_16bit length() const; - Parse_8bit nextHeader() const; - Parse_8bit hopLimit() const; - Parse_Addr source() const; - Parse_Addr destination() const; - -# endif - - void init() { +# include SENF_FIXED_PARSER() + + SENF_PARSE_BITFIELD( version, 4, unsigned ); + SENF_PARSE_BITFIELD( trafficClass, 8, unsigned ); + SENF_PARSE_BITFIELD( flowLabel, 20, unsigned ); + + SENF_PARSE_FIELD( length, Parse_UInt16 ); + SENF_PARSE_FIELD( nextHeader, Parse_UInt8 ); + SENF_PARSE_FIELD( hopLimit, Parse_UInt8 ); + SENF_PARSE_FIELD( source, Parse_INet6Address ); + SENF_PARSE_FIELD( destination, Parse_INet6Address ); + + SENF_PARSER_INIT() { version() = 6; } + + SENF_PARSER_FINALIZE(Parse_IpV6); }; /** \brief IpV6 packet diff --git a/Packets/DefaultBundle/UDPPacket.hh b/Packets/DefaultBundle/UDPPacket.hh index 1e566a1..f881497 100644 --- a/Packets/DefaultBundle/UDPPacket.hh +++ b/Packets/DefaultBundle/UDPPacket.hh @@ -43,28 +43,17 @@ namespace senf { */ struct Parse_UDP : public PacketParserBase { - typedef Parse_UInt16 Parse_16bit; +# include SENF_FIXED_PARSER() -# ifndef DOXYGEN + SENF_PARSE_FIELD( source, senf::Parse_UInt16 ); + SENF_PARSE_FIELD( destination, senf::Parse_UInt16 ); + SENF_PARSE_FIELD( length, senf::Parse_UInt16 ); + SENF_PARSE_FIELD( checksum, senf::Parse_UInt16 ); - SENF_PACKET_PARSER_INIT(Parse_UDP); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field)( source, Parse_16bit )) - ((Field)( destination, Parse_16bit )) - ((Field)( length, Parse_16bit )) - ((Field)( checksum, Parse_16bit )) ); - -# else - - Parse_16bit source(); - Parse_16bit destination(); - Parse_16bit length(); - Parse_16bit checksum(); - -# endif + SENF_PARSER_FINALIZE(Parse_UDP); boost::uint16_t calcChecksum() const; + bool validateChecksum() const { return checksum() == 0u || checksum() == calcChecksum(); } diff --git a/Packets/MPEGDVBBundle/DSMCCSection.cc b/Packets/MPEGDVBBundle/DSMCCSection.cc index 8c4e488..689d4d1 100644 --- a/Packets/MPEGDVBBundle/DSMCCSection.cc +++ b/Packets/MPEGDVBBundle/DSMCCSection.cc @@ -49,7 +49,7 @@ prefix_ void senf::DSMCCSectionType::dump(packet p, std::ostream & os) << std::dec << " section_length: " << p->sec_length() << "\n" << std::hex - << " table_id_extension: " << p->tabel_id_extension() << "\n" + << " table_id_extension: " << p->table_id_extension() << "\n" << " reserved_2: " << p->reserved_2() << "\n" << " version_number: " << p->version_num() << "\n" << " current_next_indicator: " << p->curr_next_indicator() << "\n" diff --git a/Packets/MPEGDVBBundle/DSMCCSection.hh b/Packets/MPEGDVBBundle/DSMCCSection.hh index 1f47945..e0881f9 100644 --- a/Packets/MPEGDVBBundle/DSMCCSection.hh +++ b/Packets/MPEGDVBBundle/DSMCCSection.hh @@ -28,9 +28,7 @@ // Custom includes #include -#include "../../Packets/PacketType.hh" -#include "../../Packets/ParseInt.hh" -#include "../../Packets/PacketParser.hh" +#include "../../Packets/Packets.hh" //#include "DSMCCSection.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -45,49 +43,26 @@ namespace senf { */ struct Parse_DSMCCSection : public PacketParserBase { - typedef Parse_UInt8 Parse_table_id; - typedef Parse_Flag < 0 > Parse_ssi; // section_syntax_indicator - typedef Parse_Flag < 1 > Parse_pi; // private_indicator - typedef Parse_UIntField < 2, 4 > Parse_reserved_1; - typedef Parse_UIntField < 4, 16 > Parse_sec_length; - typedef Parse_UIntField < 0, 2 > Parse_reserved_2; - typedef Parse_UIntField < 2, 7 > Parse_version_num; - typedef Parse_Flag < 7 > Parse_curr_next_indicator; - -# ifndef DOXYGEN - - SENF_PACKET_PARSER_INIT(Parse_DSMCCSection); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field ) ( table_id, Parse_table_id )) - ((OverlayField) ( ssi, Parse_ssi )) - ((OverlayField) ( private_indicator, Parse_pi )) - ((OverlayField) ( reserved_1, Parse_reserved_1 )) - ((Field ) ( sec_length, Parse_sec_length )) - ((Field ) ( tabel_id_extension, Parse_UInt16 )) - ((OverlayField) ( reserved_2, Parse_reserved_2 )) - ((OverlayField) ( version_num, Parse_version_num )) - ((Field ) ( curr_next_indicator, Parse_curr_next_indicator )) - ((Field ) ( sec_num, Parse_UInt8 )) - ((Field ) ( last_sec_num, Parse_UInt8 )) - ); - -# else - - Parse_table_id table_id() const; - Parse_ssi ssi() const; - Parse_pi pi() const; - Parse_reserved_1 reserved_1() const; - Parse_sec_length sec_length const; - Parse_UInt16 tabel_id_extension() const; - Parse_reserved_2 reserved_2() const; - Parse_version_num version_num() const; - Parse_curr_next_indicator curr_next_indicator() const; - Parse_UInt8 sec_num() const; - Parse_UInt8 last_sec_num() const; +# include SENF_FIXED_PARSER() + + SENF_PARSE_FIELD( table_id, Parse_UInt8 ); -# endif + SENF_PARSE_BITFIELD( ssi, 1, bool ); + SENF_PARSE_BITFIELD( private_indicator, 1, bool ); + SENF_PARSE_BITFIELD( reserved_1, 2, unsigned ); + SENF_PARSE_BITFIELD( sec_length, 12, unsigned ); + + SENF_PARSE_FIELD( table_id_extension, Parse_UInt16 ); + + SENF_PARSE_BITFIELD( reserved_2, 2, unsigned ); + SENF_PARSE_BITFIELD( version_num, 5, unsigned ); + SENF_PARSE_BITFIELD( curr_next_indicator, 1, bool ); + + SENF_PARSE_FIELD( sec_num, Parse_UInt8 ); + SENF_PARSE_FIELD( last_sec_num, Parse_UInt8 ); + SENF_PARSER_FINALIZE(Parse_DSMCCSection); + Parse_UInt32 crc() const { return parse( data().size()-4 ); } }; diff --git a/Packets/MPEGDVBBundle/DatagramSection.hh b/Packets/MPEGDVBBundle/DatagramSection.hh index 110feab..4ca4110 100644 --- a/Packets/MPEGDVBBundle/DatagramSection.hh +++ b/Packets/MPEGDVBBundle/DatagramSection.hh @@ -28,11 +28,8 @@ // Custom includes #include -#include "../../Packets/PacketType.hh" -#include "../../Packets/ParseInt.hh" -#include "../../Packets/PacketRegistry.hh" -#include "../../Packets/PacketParser.hh" -#include "../../Packets/MPEGDVBBundle/DSMCCSection.hh" +#include "../../Packets/Packets.hh" +#include "DSMCCSection.hh" //#include "DatagramSection.mpp" @@ -48,47 +45,35 @@ namespace senf { */ struct Parse_DatagramSection : public Parse_DSMCCSection { - Parse_DatagramSection(data_iterator i, state_type s) : senf::Parse_DSMCCSection(i,s) {} +# include SENF_FIXED_PARSER() + + SENF_PARSER_INHERIT(Parse_DSMCCSection); + + SENF_PARSE_FIELD( mac_addr_4, Parse_UInt8 ); + SENF_PARSE_FIELD( mac_addr_3, Parse_UInt8 ); + SENF_PARSE_FIELD( mac_addr_2, Parse_UInt8 ); + SENF_PARSE_FIELD( mac_addr_1, Parse_UInt8 ); + + SENF_PARSER_FINALIZE_INHERITED(Parse_DatagramSection, Parse_DSMCCSection); typedef Parse_UIntField < 2, 4 > Parse_payload_scrmbl_ctrl; typedef Parse_UIntField < 4, 6 > Parse_addr_scrmbl_ctrl; typedef Parse_Flag < 6 > Parse_llc_snap_flag; - -# ifndef DOXYGEN - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS_OFFSET(Parse_DSMCCSection::fixed_bytes, - ((Field ) ( mac_addr_4, Parse_UInt8 )) - ((Field ) ( mac_addr_3, Parse_UInt8 )) - ((Field ) ( mac_addr_2, Parse_UInt8 )) - ((Field ) ( mac_addr_1, Parse_UInt8 )) - ); - -# else - - Parse_UInt8 mac_addr_4() const; - Parse_UInt8 mac_addr_3() const; - Parse_UInt8 mac_addr_2() const; - Parse_UInt8 mac_addr_1() const; - -# endif - + Parse_UInt8 mac_addr_6() const { return parse( 3 ); } Parse_UInt8 mac_addr_5() const { return parse( 4 ); } + Parse_payload_scrmbl_ctrl payload_scrmbl_ctrl() const { return parse( 5 ); } + Parse_addr_scrmbl_ctrl addr_scrmbl_ctrl() const { return parse( 5 ); } + Parse_llc_snap_flag llc_snap_flag() const { return parse( 5 ); } - - void init() - { - Parse_DSMCCSection::init(); - defaultInit(); - } }; /** \brief Datagram Section diff --git a/Packets/MPEGDVBBundle/SNDUPacket.hh b/Packets/MPEGDVBBundle/SNDUPacket.hh index 3645b57..872a39e 100644 --- a/Packets/MPEGDVBBundle/SNDUPacket.hh +++ b/Packets/MPEGDVBBundle/SNDUPacket.hh @@ -29,11 +29,8 @@ // Custom includes #include #include -#include "../../Packets/PacketType.hh" -#include "../../Packets/ParseInt.hh" -#include "../../Packets/PacketRegistry.hh" -#include "../../Packets/PacketParser.hh" -#include "../../Packets/DefaultBundle/EthernetPacket.hh" +#include "../../Packets/Packets.hh" +#include "../DefaultBundle/EthernetPacket.hh" //#include "SNDUPacket.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -48,11 +45,7 @@ namespace senf { */ struct Parse_SNDUPacket : public PacketParserBase { -# ifndef DOXYGEN - - SENF_PACKET_PARSER_NO_INIT(Parse_SNDUPacket); - -# endif + 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; diff --git a/Packets/MPEGDVBBundle/TLVPacket.hh b/Packets/MPEGDVBBundle/TLVPacket.hh index e0ff4e0..5f43f8b 100644 --- a/Packets/MPEGDVBBundle/TLVPacket.hh +++ b/Packets/MPEGDVBBundle/TLVPacket.hh @@ -28,9 +28,7 @@ // Custom includes #include -#include "../../Packets/PacketType.hh" -#include "../../Packets/ParseInt.hh" -#include "../../Packets/PacketParser.hh" +#include "../../Packets/Packets.hh" //#include "TLVPacket.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -49,11 +47,7 @@ namespace senf { 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; @@ -92,16 +86,12 @@ namespace senf { */ struct Parse_TLVPacket : public PacketParserBase { -# ifndef DOXYGEN - - SENF_PACKET_PARSER_INIT(Parse_TLVPacket); +# include SENF_PARSER() - SENF_PACKET_PARSER_DEFINE_FIELDS( - ((Field)( type, Parse_UInt32 )) - ((Field)( length, Parse_TLVPacketLength )) - ); + SENF_PARSE_FIELD( type, Parse_UInt32 ); + SENF_PARSE_FIELD( length, Parse_TLVPacketLength ); -# endif + SENF_PARSER_FINALIZE(Parse_TLVPacket); }; /** \brief TLV Packet diff --git a/Packets/MPEGDVBBundle/TransportPacket.hh b/Packets/MPEGDVBBundle/TransportPacket.hh index 31b66cd..6aac38c 100644 --- a/Packets/MPEGDVBBundle/TransportPacket.hh +++ b/Packets/MPEGDVBBundle/TransportPacket.hh @@ -28,9 +28,7 @@ // Custom includes #include -#include "../../Packets/PacketType.hh" -#include "../../Packets/ParseInt.hh" -#include "../../Packets/PacketParser.hh" +#include "../../Packets/Packets.hh" //#include "TransportPacket.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -45,42 +43,20 @@ namespace senf { */ struct Parse_TransportPacket : public PacketParserBase { - typedef Parse_Flag < 0 > Parse_tei; // transport_error_indicator - typedef Parse_Flag < 1 > Parse_pusi; // payload_unit_start_indicator - typedef Parse_Flag < 2 > Parse_transportPrio; // transport_priority - typedef Parse_UIntField < 2, 16 > Parse_pid; - typedef Parse_UIntField < 0, 2 > Parse_tsc; // transport_scrambling_control - typedef Parse_UIntField < 2, 4 > Parse_adaptCtrl; // adaptation_field_control - typedef Parse_UIntField < 4, 8 > Parse_contCounter; // continuity_counter - -# ifndef DOXYGEN - - SENF_PACKET_PARSER_INIT(Parse_TransportPacket); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field ) ( sync_byte, Parse_UInt8 )) - ((OverlayField) ( transport_error_indicator, Parse_tei )) - ((OverlayField) ( pusi, Parse_pusi )) - ((OverlayField) ( transport_priority, Parse_transportPrio )) - ((Field ) ( pid, Parse_pid )) - ((OverlayField) ( transport_scrmbl_ctrl, Parse_tsc )) - ((OverlayField) ( adaptation_field_ctrl, Parse_adaptCtrl )) - ((Field ) ( continuity_counter, Parse_contCounter )) - ); - -# else - - Parse_UInt8 sync_byte() const; - Parse_tei transport_error_indicator() const; - Parse_pusi pusi() const; - Parse_transportPrio transport_priority() const; - Parse_pid pid() const; - Parse_tsc transport_scrmbl_ctrl() const; - Parse_adaptCtrl adaptation_field_ctrl() const; - Parse_contCounter continuity_counter() const; +# include SENF_FIXED_PARSER() -# endif + SENF_PARSE_FIELD( sync_byte, Parse_UInt8 ); + SENF_PARSE_BITFIELD( transport_error_indicator, 1, bool ); + SENF_PARSE_BITFIELD( pusi, 1, bool ); + SENF_PARSE_BITFIELD( transport_priority, 1, bool ); + SENF_PARSE_BITFIELD( pid, 13, unsigned ); + SENF_PARSE_BITFIELD( transport_scrmbl_ctrl, 2, unsigned ); + SENF_PARSE_BITFIELD( adaptation_field_ctrl, 2, unsigned ); + SENF_PARSE_BITFIELD( continuity_counter, 4, unsigned ); + + SENF_PARSER_FINALIZE( Parse_TransportPacket ); + // Parse_UInt8 payload_pointer() const { // return parse( Parse_TransportPacket::fixed_bytes ); // } diff --git a/Packets/Packet.hh b/Packets/Packet.hh index 59f7d56..7fa54fa 100644 --- a/Packets/Packet.hh +++ b/Packets/Packet.hh @@ -594,7 +594,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_Packet_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_Packet_i_) #define HH_Packet_i_ #include "Packet.cci" #include "Packet.ct" diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index a33ccd4..88208f4 100644 --- a/Packets/Packet.test.cc +++ b/Packets/Packet.test.cc @@ -55,15 +55,13 @@ namespace { struct BarPacketParser : public senf::PacketParserBase { - SENF_PACKET_PARSER_INIT(BarPacketParser); +# include SENF_FIXED_PARSER() - typedef senf::Parse_UInt16 Parse_Type; - typedef senf::Parse_Int32 Parse_Length; - typedef senf::Parse_UInt16 Parse_Reserved; + SENF_PARSE_FIELD( type, senf::Parse_UInt16 ); + SENF_PARSE_FIELD( length, senf::Parse_Int32 ); + SENF_PARSE_FIELD( reserved, senf::Parse_UInt16 ); - Parse_Type type() const { return parse (i()); } - Parse_Length length() const { return parse (i()+2); } - Parse_Reserved reserved() const { return parse (i()+6); } + SENF_PARSER_FINALIZE(BarPacketParser); }; struct BarPacketType @@ -152,7 +150,7 @@ BOOST_AUTO_UNIT_TEST(packet) packet.finalize(); BOOST_CHECK_EQUAL( packet.last().as()->type(), - BarPacket::type::parser::Parse_Type::value_type(-1) ); + BarPacket::type::parser::type_t::value_type(-1) ); packet.last().append(FooPacket::create()); packet.finalize(); BOOST_CHECK_EQUAL( packet.next()->type(), 1u ); diff --git a/Packets/PacketData.hh b/Packets/PacketData.hh index 8365924..c316778 100644 --- a/Packets/PacketData.hh +++ b/Packets/PacketData.hh @@ -225,7 +225,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketData_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_PacketData_i_) #define HH_PacketData_i_ #include "PacketData.cci" //#include "PacketData.ct" diff --git a/Packets/PacketImpl.hh b/Packets/PacketImpl.hh index ad254d6..02ea462 100644 --- a/Packets/PacketImpl.hh +++ b/Packets/PacketImpl.hh @@ -128,7 +128,7 @@ namespace detail { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketImpl_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_PacketImpl_i_) #define HH_PacketImpl_i_ #include "PacketImpl.cci" //#include "PacketImpl.ct" diff --git a/Packets/PacketInterpreter.hh b/Packets/PacketInterpreter.hh index fe1b27a..a4f8b26 100644 --- a/Packets/PacketInterpreter.hh +++ b/Packets/PacketInterpreter.hh @@ -384,7 +384,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketInterpreter_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_PacketInterpreter_i_) #define HH_PacketInterpreter_i_ #include "PacketInterpreter.cci" #include "PacketInterpreter.ct" diff --git a/Packets/PacketParser.hh b/Packets/PacketParser.hh index 76b8252..b3e2996 100644 --- a/Packets/PacketParser.hh +++ b/Packets/PacketParser.hh @@ -154,8 +154,9 @@ #include "../Utils/SafeBool.hh" #include "PacketTypes.hh" #include "PacketData.hh" +#include "ParseHelpers.hh" -#include "PacketParser.mpp" +//#include "PacketParser.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { @@ -434,227 +435,13 @@ namespace senf { Parser operator<<(Parser target, boost::optional const & value); # endif - /** \defgroup packetparsermacros Helper macros for defining new packet parsers - - To simplify the definition of simple packet parsers, several macros are provided. Before - using these macros you should familiarize yourself with the packet parser interface as - described in senf::PacketParserBase. - - These macros simplify providing the above defined interface. A typical packet declaration - using these macros has the following form (This is a concrete example from the definition of - the ethernet packet in DefaultBundle/EthernetPacket.hh) - - \code - struct Parse_EthVLan : public PacketParserBase - { - typedef Parse_UIntField < 0, 3 > Parse_Priority; - typedef Parse_Flag < 3 > Parse_CFI; - typedef Parse_UIntField < 4, 16 > Parse_VLanId; - typedef Parse_UInt16 Parse_Type; - - SENF_PACKET_PARSER_INIT(Parse_EthVLan); - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((OverlayField)( priority, Parse_Priority )) - ((OverlayField)( cfi, Parse_CFI )) - ((Field )( vlanId, Parse_VLanId )) - ((Field )( type, Parse_Type )) ); - }; - \endcode - - The macros take care of the following: - \li They define the accessor functions returning parsers of the given type. - \li They automatically calculate the offset of the fields from the preceding fields. - \li The macros provide a definition for \c init() - \li The macros define the \c bytes(), \c fixed_bytes and \c init_bytes members as needed. - - You may define either a fixed or a dynamically sized parser. Fixed size parsers are defined - using \ref SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS, dynamically sized parsers are defined - using \ref SENF_PACKET_PARSER_DEFINE_FIELDS. The different members are implemented such - that: - - \li The needed parser constructor is defined - \li \c init() calls \c defaultInit(). \c defaultInit() is defined to call \c init() on each - of the fields. - \li \c bytes() (on dynamically sized parser) respectively \c fixed_bytes (on fixed size - parsers) is defined to return the sum of the sizes of all fields. - \li On dynamically sized parsers, \c init_bytes is defined to return the sum of the - \c init_size's of all fields - - The central definition macros are \ref SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS and \ref - SENF_PACKET_PARSER_DEFINE_FIELDS. The argument to both has the same structure. It is a - (boost preprocessor style) sequence of field definitions where each field definition - provides the builder macro to use and the name and type of the field to define: - \code - SENF_PACKET_PARSER_DEFINE[_FIXED]_FIELDS( - (( )( , )) - ... - ) - \endcode - - For each field, this command will define - \li A method \a name() returning an instance of the \a type parser - \li \a name_t as a typedef for \a type, the fields value - \li \a name_offset to give the offset of the field from the beginning of the - parser. If the parser is a fixed size parser, this will be a static constant, otherwise - it will be a method. - - The \a builder argument selects, how the field is defined - \li Field defines a field and increments the current position by the size of the - field - \li OverlayField defines a field like Field but does \e not increment the - position. In the above example, this is used to overlay the different bitfield parsers: - All overlaying bitfield parser except the last one (the one with the highest bit - numbers) is marked as OverlayField. - - The \a name argument defines the name of the accessor method. - - The \a type argument is the parser to return for that field. Since none of the arguments may - contain a comma, This argument cannot be a multi-parameter template. Always use - typedefs to access templated parsers as shown above. - - The \ref SENF_PACKET_PARSER_INIT macro defines the constructor and the \c init() member. If - you want to provide your own \c init() implementation, use \ref - SENF_PACKET_PARSER_NO_INIT. The first statement in your init method should probably to call - \c defaultInit(). This will call the \c init() member of all the fields. Afterwards you can - set up the field values as needed: - \code - struct SomePacket : public senf::PacketParserBase - { - SENF_PACKET_PARSER_NO_INIT(SomePacket); - - typedef senf::Parse_UInt8 Parse_Type; - typedef senf::Parse_Vector< senf::Parse_UInt32, - senf::SimpleVectorSizer - > Parse_Elements; - - SENF_PACKET_PARSER_DEFINE_FIELDS( - ((Field)( type, Parse_Type )) - ((Field)( elements, Parse_Elements )) - ); - - void init() const { - defaultInit(); - type() = 0x01; - elements().push_back(0x01020304u); - } - } - \endcode - - \ingroup packetparser - */ - - /** \brief Define initialization members of a parser - - This macro defines the packet parser constructor and the \c init() member. \c init() is - defined to just call \c defaultInit() which is defined by the other macros to call \c init() - on each of the parsers fields. - - \ingroup packetparsermacros - \hideinitializer - */ -# define SENF_PACKET_PARSER_INIT(name) \ - name(data_iterator i, state_type s) : senf::PacketParserBase(i,s) {} \ - void init() const { defaultInit(); } - - /** \brief Define initialization members of a parser except init() - - This macro is like SENF_PACKET_PARSER_INIT but does \e not define \c init(). This allows you - to provide your own implementation. You should call \c defaultInit() first before - initializing your data fields. - - \ingroup packetparsermacros - \hideinitializer - */ -# define SENF_PACKET_PARSER_NO_INIT(name) \ - name(data_iterator i, state_type s) : senf::PacketParserBase(i,s) {} - - /** \brief Define fields for a dynamically sized parser - - Define the fields as specified in \a fields. This macro supports dynamically sized - subfields, the resulting parser will be dynamically sized. - - \ingroup packetparsermacros - \hideinitializer - */ -# define SENF_PACKET_PARSER_DEFINE_FIELDS(fields) \ - SENF_PACKET_PARSER_I_DEFINE_FIELDS(0,fields) - - /** \brief Define fields for a dynamically sized parser (with offset) - - Define the fields as specified in \a fields. This macro supports dynamically sized - subfields, the resulting parser will be dynamically sized. - - The \a offset argument gives the byte offset at which to start parsing the fields. This - helps defining extended parser deriving from a base parser: - \code - struct ExtendedParser : public BaseParser - { - ExtendedParser(data_iterator i, state_type s) : BaseParser(i,s) {} - - SENF_PACKET_PARSER_DEFINE_FIELDS_OFFSET(senf::bytes(BaseParser(*this)), - ( ... fields ... ) ); - - void init() { - BaseParser::init(); - defaultInit(); - // other init code - } - } - \endcode - - \ingroup packetparsermacros - \hideinitializer - */ -# define SENF_PACKET_PARSER_DEFINE_FIELDS_OFFSET(offset,fields) \ - SENF_PACKET_PARSER_I_DEFINE_FIELDS(offset,fields) - - /** \brief Define fields for a fixed size parser - - Define the fields as specified in \a fields. This macro only supports fixed size - subfields, the resulting parser will also be a fixed size parser. - - \ingroup packetparsermacros - \hideinitializer - */ -# define SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(fields) \ - SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(0,fields) - - /** \brief Define fields for a fixed size parser - - Define the fields as specified in \a fields. This macro only supports fixed size - subfields, the resulting parser will also be a fixed size parser. - - The \a offset argument gives the byte offset at which to start parsing the fields. This - helps defining extended parser deriving from a base parser: - \code - struct ExtendedParser : public BaseParser - { - ExtendedParser(data_iterator i, state_type s) : BaseParser(i,s) {} - - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS_OFFSET(BaseParser::fixed_bytes, - ( ... fields ... ) ); - - void init() { - BaseParser::init(); - defaultInit(); - // other init code - } - } - \endcode - - \ingroup packetparsermacros - \hideinitializer - */ -# define SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS_OFFSET(offset,fields) \ - SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(offset,fields) - /** \brief Default parser parsing nothing */ struct VoidPacketParser : public PacketParserBase { - SENF_PACKET_PARSER_INIT(VoidPacketParser); +# include SENF_FIXED_PARSER() + SENF_PARSER_FINALIZE(VoidPacketParser); }; /** \brief Iterator re-validating Parser wrapper @@ -718,7 +505,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketParser_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_PacketParser_i_) #define HH_PacketParser_i_ #include "PacketParser.cci" #include "PacketParser.ct" diff --git a/Packets/PacketParser.mpp b/Packets/PacketParser.mpp deleted file mode 100644 index c9c112e..0000000 --- a/Packets/PacketParser.mpp +++ /dev/null @@ -1,150 +0,0 @@ -# // Copyright (C) 2007 -# // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -# // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -# // Stefan Bund -# // -# // This program is free software; you can redistribute it and/or modify -# // it under the terms of the GNU General Public License as published by -# // the Free Software Foundation; either version 2 of the License, or -# // (at your option) any later version. -# // -# // This program is distributed in the hope that it will be useful, -# // but WITHOUT ANY WARRANTY; without even the implied warranty of -# // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# // GNU General Public License for more details. -# // -# // You should have received a copy of the GNU General Public License -# // along with this program; if not, write to the -# // Free Software Foundation, Inc., -# // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# /** \file -# \brief PacketParser Boost.Preprocesser definitions */ -# -# if !defined(MPP_PacketParser_) -# define MPP_PacketParser_ 1 -# -# // Custom includes -# include -# include -# include -# include -# include -# include -# include -# -# ///////////////////////////////mpp.p/////////////////////////////////////// -# -# define SENF_PACKET_PARSER_I_UNWRAP(n,elt) (n,SENF_PACKET_PARSER_I_UNWRAP_1 elt) -# define SENF_PACKET_PARSER_I_UNWRAP_1(x) x,SENF_PACKET_PARSER_I_UNWRAP_2 -# define SENF_PACKET_PARSER_I_UNWRAP_2(x,y) x,y -# -# define SENF_PACKET_PARSER_I_GET_NAME(elt) SENF_PACKET_PARSER_I_GET_NAME_1 elt -# define SENF_PACKET_PARSER_I_GET_NAME_1(x) SENF_PACKET_PARSER_I_GET_NAME_2 -# define SENF_PACKET_PARSER_I_GET_NAME_2(name,type) name -# -# define SENF_PACKET_PARSER_I_GET_TYPE(elt) SENF_PACKET_PARSER_I_GET_TYPE_1 elt -# define SENF_PACKET_PARSER_I_GET_TYPE_1(x) SENF_PACKET_PARSER_I_GET_TYPE_2 -# define SENF_PACKET_PARSER_I_GET_TYPE_2(name,type) type -# -# define SENF_PACKET_PARSER_I_DEFINE_INIT_C(_0,_1,elt) \ - SENF_PACKET_PARSER_I_GET_NAME(elt) ().init(); -# -# define SENF_PACKET_PARSER_I_DEFINE_INIT(fields) \ - void defaultInit() const { \ - BOOST_PP_SEQ_FOR_EACH( SENF_PACKET_PARSER_I_DEFINE_INIT_C, _, fields) \ - } -# -# define SENF_PACKET_PARSER_I_FIELD_DISPATCH(n,t,name,type) \ - SENF_PACKET_PARSER_I_ ## t(n,name,type) -# -# define SENF_PACKET_PARSER_I_FIELD_C(_0,_1,n,elt) \ - BOOST_PP_EXPAND( \ - SENF_PACKET_PARSER_I_FIELD_DISPATCH SENF_PACKET_PARSER_I_UNWRAP(n,elt)) -# -# define SENF_PACKET_PARSER_I_INITSIZE_C(_0,_1,n,elt) \ - BOOST_PP_IF(n,+,) senf::init_bytes< SENF_PACKET_PARSER_I_GET_TYPE(elt) >::value -# -# define SENF_PACKET_PARSER_I_DEFINE_FIELDS(offset,fields) \ - size_type offset_0_() const { return offset; } \ - BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_FIELD_C, _, fields) \ - size_type bytes() const { \ - return BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_SEQ_SIZE(fields),_)) (); \ - } \ - SENF_PACKET_PARSER_I_DEFINE_INIT(fields) \ - static const size_type init_bytes = \ - BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_INITSIZE_C, _, fields) ; -# -# define SENF_PACKET_PARSER_I_FIXED_FIELD_DISPATCH(n,t,name,type) \ - SENF_PACKET_PARSER_I_FIXED_ ## t(n,name,type) -# -# define SENF_PACKET_PARSER_I_FIXED_FIELD_C(_0,_1,n,elt) \ - BOOST_PP_EXPAND( \ - SENF_PACKET_PARSER_I_FIXED_FIELD_DISPATCH SENF_PACKET_PARSER_I_UNWRAP(n,elt)) -# -# define SENF_PACKET_PARSER_I_DEFINE_FIXED_FIELDS(offset,fields) \ - static const size_type offset_0_ = offset; \ - BOOST_PP_SEQ_FOR_EACH_I(SENF_PACKET_PARSER_I_FIXED_FIELD_C, _, fields) \ - static const size_type fixed_bytes = \ - BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_SEQ_SIZE(fields),_)); \ - SENF_PACKET_PARSER_I_DEFINE_INIT(fields) -# -# /////////////////////////////////////////////////////////////////////////// -# // Definition of the field types -# -# define SENF_PACKET_PARSER_I_Field(n,name,type) \ - typedef type BOOST_PP_CAT(name,_t) ; \ - type name () const { \ - return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \ - } \ - size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \ - return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () + senf::bytes( name () ); \ - } \ - size_type BOOST_PP_CAT(name, _offset) () const { \ - return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ; \ - } -# -# define SENF_PACKET_PARSER_I_FIXED_Field(n,name,type) \ - typedef type BOOST_PP_CAT(name,_t) ; \ - type name () const { \ - return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \ - } \ - static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \ - BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) + type::fixed_bytes; \ - static const size_type BOOST_PP_CAT(name,_offset) = \ - BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)); -# -# define SENF_PACKET_PARSER_I_OverlayField(n,name,type) \ - typedef type BOOST_PP_CAT(name,_t) ; \ - type name () const { \ - return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ); \ - } \ - size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) () const { \ - return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) (); \ - } \ - size_type BOOST_PP_CAT(name, _offset) () const { \ - return BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) () ; \ - } -# -# define SENF_PACKET_PARSER_I_FIXED_OverlayField(n,name,type) \ - typedef type BOOST_PP_CAT(name,_t) ; \ - type name () const { \ - return parse< type >( BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)) ); \ - } \ - static const size_type BOOST_PP_CAT(offset_,BOOST_PP_CAT(BOOST_PP_INC(n),_)) = \ - BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)); \ - static const size_type BOOST_PP_CAT(name,_offset) = \ - BOOST_PP_CAT(offset_,BOOST_PP_CAT(n,_)); -# -# ///////////////////////////////mpp.e/////////////////////////////////////// -# endif -# -# -# // Local Variables: -# // mode: c++ -# // fill-column: 100 -# // c-file-style: "senf" -# // indent-tabs-mode: nil -# // ispell-local-dictionary: "american" -# // compile-command: "scons -u test" -# // End: diff --git a/Packets/PacketParser.test.cc b/Packets/PacketParser.test.cc index 23b1be9..bde87e1 100644 --- a/Packets/PacketParser.test.cc +++ b/Packets/PacketParser.test.cc @@ -38,7 +38,8 @@ namespace { struct SimpleParser : public senf::PacketParserBase { - SENF_PACKET_PARSER_INIT(SimpleParser); +# include SENF_FIXED_PARSER() + SENF_PARSER_FINALIZE(SimpleParser); using senf::PacketParserBase::check; using senf::PacketParserBase::validate; @@ -46,20 +47,22 @@ namespace { struct FooParser : public senf::PacketParserBase { - SENF_PACKET_PARSER_INIT(FooParser); +# include SENF_FIXED_PARSER() - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field)( name, senf::Parse_UInt16 )) - ((Field)( id, senf::Parse_Int32 )) ); + SENF_PARSE_FIELD( name, senf::Parse_UInt16 ); + SENF_PARSE_FIELD( id, senf::Parse_Int32 ); + + SENF_PARSER_FINALIZE(FooParser); }; struct BarParser : public senf::PacketParserBase { - SENF_PACKET_PARSER_INIT(BarParser); +# include SENF_PARSER() + + SENF_PARSE_FIELD( name, senf::Parse_UInt16 ); + SENF_PARSE_FIELD( id, senf::Parse_Int32 ); - SENF_PACKET_PARSER_DEFINE_FIELDS( - ((Field)( name, senf::Parse_UInt16 )) - ((Field)( id, senf::Parse_Int32 )) ); + SENF_PARSER_FINALIZE(BarParser); }; } diff --git a/Packets/PacketRegistry.hh b/Packets/PacketRegistry.hh index c1e1798..5d35eb9 100644 --- a/Packets/PacketRegistry.hh +++ b/Packets/PacketRegistry.hh @@ -204,7 +204,7 @@ packet of which the key is requested ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketRegistryImpl_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_PacketRegistryImpl_i_) #define HH_PacketRegistryImpl_i_ //#include "PacketRegistry.cci" #include "PacketRegistry.ct" diff --git a/Packets/PacketType.hh b/Packets/PacketType.hh index 88768f2..e01db87 100644 --- a/Packets/PacketType.hh +++ b/Packets/PacketType.hh @@ -362,7 +362,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" diff --git a/Packets/PacketTypes.hh b/Packets/PacketTypes.hh index 8d662e6..9e661b3 100644 --- a/Packets/PacketTypes.hh +++ b/Packets/PacketTypes.hh @@ -77,7 +77,7 @@ namespace test { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketTypes_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_PacketTypes_i_) #define HH_PacketTypes_i_ //#include "PacketTypes.cci" //#include "PacketTypes.ct" diff --git a/Packets/Packets.hh b/Packets/Packets.hh index 9178325..9e7186b 100644 --- a/Packets/Packets.hh +++ b/Packets/Packets.hh @@ -24,11 +24,11 @@ #ifndef HH_Packets_ #define HH_Packets_ 1 -#define SENF_PACKETS_DECL_ONLY +#define HH_Packets__decls_ #include "all_includes.hh" -#undef SENF_PACKETS_DECL_ONLY +#undef HH_Packets__decls_ #include "all_includes.hh" diff --git a/Packets/ParseArray.hh b/Packets/ParseArray.hh index c4feca4..a42f406 100644 --- a/Packets/ParseArray.hh +++ b/Packets/ParseArray.hh @@ -99,7 +99,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseArray_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_ParseArray_i_) #define HH_ParseArray_i_ //#include "ParseArray.cci" #include "ParseArray.ct" diff --git a/Packets/ParseArray.test.cc b/Packets/ParseArray.test.cc index 44b406d..0ced2cf 100644 --- a/Packets/ParseArray.test.cc +++ b/Packets/ParseArray.test.cc @@ -40,23 +40,25 @@ namespace { struct SomePacketParser : public senf::PacketParserBase { - SENF_PACKET_PARSER_INIT(SomePacketParser); +# include SENF_FIXED_PARSER() typedef senf::Parse_Array<2,senf::Parse_UInt24> Parse_Array2; - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field)( array, Parse_Array2 )) - ((Field)( index, senf::Parse_UInt16 )) ); + SENF_PARSE_FIELD( array, Parse_Array2 ); + SENF_PARSE_FIELD( index, senf::Parse_UInt16 ); + + SENF_PARSER_FINALIZE(SomePacketParser); }; struct SomeOtherParser : public senf::PacketParserBase { - SENF_PACKET_PARSER_INIT(SomeOtherParser); +# include SENF_FIXED_PARSER() typedef senf::Parse_Array<1,SomePacketParser> Parse_Array1; - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field)( fields, Parse_Array1 )) ); + SENF_PARSE_FIELD( fields, Parse_Array1 ); + + SENF_PARSER_FINALIZE(SomeOtherParser); }; } diff --git a/Packets/ParseHelpers.hh b/Packets/ParseHelpers.hh new file mode 100644 index 0000000..905aaf6 --- /dev/null +++ b/Packets/ParseHelpers.hh @@ -0,0 +1,241 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief ParseHelpers public header */ + +#ifndef HH_ParseHelpers_ +#define HH_ParseHelpers_ 1 + +#ifndef HH_Packets_ +#error "Don't include 'ParseHelpers.hh' directly, include 'Packets.hh'" +#endif + +// Custom includes + +//#include "ParseHelpers.mpp" +#include "ParseHelpers.ih" +///////////////////////////////hh.p//////////////////////////////////////// + +/** \defgroup packetparsermacros Helper macros for defining new packet parsers + + To simplify the definition of simple packet parsers, several macros are provided. Before + using these macros you should familiarize yourself with the packet parser interface as + described in senf::PacketParserBase. + + These macros simplify providing the above defined interface. A typical packet declaration + using these macros has the following form (This is a concrete example from the definition of + the ethernet packet in DefaultBundle/EthernetPacket.hh) + + \code + struct Parse_EthVLan : public PacketParserBase + { + typedef Parse_UIntField < 0, 3 > Parse_Priority; + typedef Parse_Flag < 3 > Parse_CFI; + typedef Parse_UIntField < 4, 16 > Parse_VLanId; + typedef Parse_UInt16 Parse_Type; + + SENF_PACKET_PARSER_INIT(Parse_EthVLan); + + SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( + ((OverlayField)( priority, Parse_Priority )) + ((OverlayField)( cfi, Parse_CFI )) + ((Field )( vlanId, Parse_VLanId )) + ((Field )( type, Parse_Type )) ); + }; + \endcode + + The macros take care of the following: + \li They define the accessor functions returning parsers of the given type. + \li They automatically calculate the offset of the fields from the preceding fields. + \li The macros provide a definition for \c init() + \li The macros define the \c bytes(), \c fixed_bytes and \c init_bytes members as needed. + + You may define either a fixed or a dynamically sized parser. Fixed size parsers are defined + using \ref SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS, dynamically sized parsers are defined + using \ref SENF_PACKET_PARSER_DEFINE_FIELDS. The different members are implemented such + that: + + \li The needed parser constructor is defined + \li \c init() calls \c defaultInit(). \c defaultInit() is defined to call \c init() on each + of the fields. + \li \c bytes() (on dynamically sized parser) respectively \c fixed_bytes (on fixed size + parsers) is defined to return the sum of the sizes of all fields. + \li On dynamically sized parsers, \c init_bytes is defined to return the sum of the + \c init_size's of all fields + + The central definition macros are \ref SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS and \ref + SENF_PACKET_PARSER_DEFINE_FIELDS. The argument to both has the same structure. It is a + (boost preprocessor style) sequence of field definitions where each field definition + provides the builder macro to use and the name and type of the field to define: + \code + SENF_PACKET_PARSER_DEFINE[_FIXED]_FIELDS( + (( )( , )) + ... + ) + \endcode + + For each field, this command will define + \li A method \a name() returning an instance of the \a type parser + \li \a name_t as a typedef for \a type, the fields value + \li \a name_offset to give the offset of the field from the beginning of the + parser. If the parser is a fixed size parser, this will be a static constant, otherwise + it will be a method. + + The \a builder argument selects, how the field is defined + \li Field defines a field and increments the current position by the size of the + field + \li OverlayField defines a field like Field but does \e not increment the + position. In the above example, this is used to overlay the different bitfield parsers: + All overlaying bitfield parser except the last one (the one with the highest bit + numbers) is marked as OverlayField. + + The \a name argument defines the name of the accessor method. + + The \a type argument is the parser to return for that field. Since none of the arguments may + contain a comma, This argument cannot be a multi-parameter template. Always use + typedefs to access templated parsers as shown above. + + The \ref SENF_PACKET_PARSER_INIT macro defines the constructor and the \c init() member. If + you want to provide your own \c init() implementation, use \ref + SENF_PACKET_PARSER_NO_INIT. The first statement in your init method should probably to call + \c defaultInit(). This will call the \c init() member of all the fields. Afterwards you can + set up the field values as needed: + \code + struct SomePacket : public senf::PacketParserBase + { + SENF_PACKET_PARSER_NO_INIT(SomePacket); + + typedef senf::Parse_UInt8 Parse_Type; + typedef senf::Parse_Vector< senf::Parse_UInt32, + senf::SimpleVectorSizer + > Parse_Elements; + + SENF_PACKET_PARSER_DEFINE_FIELDS( + ((Field)( type, Parse_Type )) + ((Field)( elements, Parse_Elements )) + ); + + void init() const { + defaultInit(); + type() = 0x01; + elements().push_back(0x01020304u); + } + } + \endcode + + \ingroup packetparser + */ + +#define SENF_FIXED_PARSER() SENF_ABSOLUTE_INCLUDE_PATH(Packets/parse_fixed_setup.hh) +#define SENF_PARSER() SENF_ABSOLUTE_INCLUDE_PATH(Packets/parse_setup.hh) + +#define SENF_FIXED_PARSER_INITIALIZE() \ + private: \ + SENF_MPL_SLOT_DEF_ZERO(index); \ + SENF_MPL_SLOT_DEF_ZERO(offset); \ + SENF_MPL_SLOT_DEF_ZERO(bit); \ + SENF_MPL_SLOT_DEF_ZERO(bitfield_size); \ + void init_chain(senf::mpl::rv<0>*) {} \ + public: + +#define SENF_PARSER_INITIALIZE() \ + private: \ + SENF_MPL_SLOT_DEF_ZERO(index); \ + SENF_MPL_SLOT_DEF_ZERO(init_bytes); \ + SENF_MPL_SLOT_DEF_ZERO(bit); \ + SENF_MPL_SLOT_DEF_ZERO(bitfield_size); \ + void init_chain(senf::mpl::rv<0>*) {} \ + size_type field_offset_(senf::mpl::rv<0>*) const { return 0; } \ + public: + +#define SENF_PARSER_FIELD(name, type) SENF_PARSER_FIELD_I(name, type, var, rw) +#define SENF_PARSER_FIELD_RO(name, type) SENF_PARSER_FIELD_I(name, type, var, ro) +#define SENF_PARSER_CUSTOM_FIELD(name, type, size) SENF_PARSER_CUSTOM_FIELD_I(name, type, size, var) + +#define SENF_PARSER_FIXED_FIELD(name, type) SENF_PARSER_FIELD_I(name, type, fix, rw) +#define SENF_PARSER_FIXED_FIELD_RO(name, type) SENF_PARSER_FIELD_I(name, type, fix, ro) +#define SENF_PARSER_FIXED_CUSTOM_FIELD(name, type, size) SENF_PARSER_CUSTOM_FIELD_I(name, type, size, fix) + +#define SENF_PARSER_FIELD_AFTER(name, type, prev) SENF_PARSER_FIELD_I_AFTER(name, type, prev, var, rw) +#define SENF_PARSER_FIELD_RO_AFTER(name, type, prev) SENF_PARSER_FIELD_I_AFTER(name, type, prev, var, ro) +#define SENF_PARSER_CUSTOM_FIELD_AFTER(name, type, size, prev) SENF_PARSER_CUSTOM_FIELD_I_AFTER(name, type, size, prev, var) + +#define SENF_PARSER_FIXED_FIELD_AFTER(name, type, prev) SENF_PARSER_FIELD_I_AFTER(name, type, prev, fix, rw) +#define SENF_PARSER_FIXED_FIELD_RO_AFTER(name, type, prev) SENF_PARSER_FIELD_I_AFTER(name, type, prev, fix, ro) +#define SENF_PARSER_FIXED_CUSTOM_FIELD_AFTER(name, type, size, prev) SENF_PARSER_CUSTOM_FIELD_I_AFTER(name, type, size, prev, fix) + +#define SENF_PARSER_BITFIELD(name, bits, type) SENF_PARSER_BITFIELD_I(name, bits, type, var, rw) +#define SENF_PARSER_BITFIELD_RO(name, bits, type) SENF_PARSER_BITFIELD_I(name, bits, type, var, ro) + +#define SENF_PARSER_FIXED_BITFIELD(name, bits, type) SENF_PARSER_BITFIELD_I(name, bits, type, fix, rw) +#define SENF_PARSER_FIXED_BITFIELD_RO(name, bits, type) SENF_PARSER_BITFIELD_I(name, bits, type, fix, ro) + +#define SENF_PARSER_INIT() \ + void init(int) + +#define SENF_PARSER_FINALIZE_GENERIC(name, base) \ + void defaultInit() { \ + init_chain(static_cast*>(0)); \ + } \ + name(data_iterator i, state_type s) : base(i,s) {} \ + private: \ + template void init(T) { defaultInit(); } \ + public: \ + void init() { init(0); } + +#define SENF_PARSER_FINALIZE_INHERITED_DYNAMIC(name, base) \ + SENF_PARSER_FINALIZE_GENERIC(name, base) \ + size_type bytes() const { \ + return field_offset_(static_cast*>(0)); \ + } \ + static size_type const init_bytes = SENF_MPL_SLOT_GET(init_bytes) + +#define SENF_PARSER_FINALIZE_INHERITED_FIXED(name, base) \ + SENF_PARSER_FINALIZE_GENERIC(name, base) \ + static size_type const fixed_bytes = SENF_MPL_SLOT_GET(offset); + +#define SENF_PARSER_FINALIZE_FIXED(name) \ + SENF_PARSER_FINALIZE_INHERITED_FIXED(name, senf::PacketParserBase) + +#define SENF_PARSER_FINALIZE_DYNAMIC(name) \ + SENF_PARSER_FINALIZE_INHERITED_DYNAMIC(name, senf::PacketParserBase) + +///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(HH_Packets__decls_) && !defined(HH_ParseHelpers_i_) +#define HH_ParseHelpers_i_ +//#include "ParseHelpers.cci" +//#include "ParseHelpers.ct" +//#include "ParseHelpers.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Packets/ParseHelpers.ih b/Packets/ParseHelpers.ih new file mode 100644 index 0000000..bebd898 --- /dev/null +++ b/Packets/ParseHelpers.ih @@ -0,0 +1,222 @@ +# // Copyright (C) 2007 +# // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +# // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +# // Stefan Bund +# // +# // This program is free software; you can redistribute it and/or modify +# // it under the terms of the GNU General Public License as published by +# // the Free Software Foundation; either version 2 of the License, or +# // (at your option) any later version. +# // +# // This program is distributed in the hope that it will be useful, +# // but WITHOUT ANY WARRANTY; without even the implied warranty of +# // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# // GNU General Public License for more details. +# // +# // You should have received a copy of the GNU General Public License +# // along with this program; if not, write to the +# // Free Software Foundation, Inc., +# // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# /** \file +# \brief ParseHelpers internal header */ +# +# if !defined(IH_ParseHelpers_) +# define IH_ParseHelpers_ 1 +# +# // Custom includes +# include +# include +# include "../Utils/mpl.hh" +# +# ////////////////////////////////ih.p/////////////////////////////////////// +# +# define SENF_PARSER_I_FIELD_INTRO(name, type) \ + typedef type BOOST_PP_CAT(name, _t); \ + static size_type const BOOST_PP_CAT(name,_index) = SENF_MPL_SLOT_GET(index)+1; \ + private: \ + SENF_MPL_SLOT_SET(index, BOOST_PP_CAT(name,_index)); \ + public: +# +# define SENF_PARSER_I_FIELD_INIT_rw(name, type) \ + private: \ + void init_chain(senf::mpl::rv*) { \ + init_chain(static_cast*>(0)); \ + name().init(); \ + } \ + public: +# +# define SENF_PARSER_I_FIELD_INIT_ro(name, type) \ + private: \ + void init_chain(senf::mpl::rv*) { \ + init_chain(static_cast*>(0)); \ + } \ + public: +# +# define SENF_PARSER_I_SIZE_var(name, type) senf::bytes(name()) +# define SENF_PARSER_I_INITBYTES_var(name, type) senf::init_bytes::value +# +# define SENF_PARSER_I_ADVANCE_OFS_var(name, type, size, isize) \ + private: \ + size_type BOOST_PP_CAT(name, _next_offset)() const { \ + return BOOST_PP_CAT(name,_offset)() + size; \ + } \ + size_type field_offset_(senf::mpl::rv*) const { \ + return BOOST_PP_CAT(name, _next_offset)(); \ + } \ + SENF_MPL_SLOT_SET(init_bytes, SENF_MPL_SLOT_GET(init_bytes) + isize); \ + public: +# +# define SENF_PARSER_I_FIELD_OFS_var(name, type) \ + size_type BOOST_PP_CAT(name,_offset)() const { \ + return field_offset_(static_cast*>(0)); \ + } +# +# define SENF_PARSER_I_FIELD_OFS_AFTER_var(name, type, prev) \ + size_type BOOST_PP_CAT(name,_offset)() const { \ + return BOOST_PP_CAT(prev,_next_offset)(); \ + } +# +# define SENF_PARSER_I_SIZE_fix(name, type) type::fixed_bytes +# define SENF_PARSER_I_INITBYTES_fix(name, type) void +# +# define SENF_PARSER_I_ADVANCE_OFS_fix(name, type, size, isize) \ + private: \ + static size_type const BOOST_PP_CAT(name, _next_offset) = \ + BOOST_PP_CAT(name, _offset) + size; \ + SENF_MPL_SLOT_SET(offset, BOOST_PP_CAT(name, _next_offset)); \ + public: +# +# define SENF_PARSER_I_FIELD_OFS_fix(name, type) \ + static size_type const BOOST_PP_CAT(name, _offset) = SENF_MPL_SLOT_GET(offset); +# +# define SENF_PARSER_I_FIELD_OFS_AFTER_fix(name, type, prev) \ + static size_type const BOOST_PP_CAT(name, _offset) = BOOST_PP_CAT(prev, _next_offset); +# +# define SENF_PARSER_I_MAYBECALL_var() () +# define SENF_PARSER_I_MAYBECALL_fix() +# +# define SENF_PARSER_I_FIELD_VAL_rw(name,type,ofstype) \ + BOOST_PP_CAT(name, _t) name() const { \ + return parse( \ + BOOST_PP_CAT(name,_offset) BOOST_PP_CAT(SENF_PARSER_I_MAYBECALL_, ofstype)()); \ + } +# +# define SENF_PARSER_I_FIELD_VAL_ro(name,type,ofstype) \ + BOOST_PP_CAT(name, _t)::value_type name() const { \ + return parse( \ + BOOST_PP_CAT(name,_offset) BOOST_PP_CAT(SENF_PARSER_I_MAYBECALL_, ofstype)() \ + .value() \ + } +# +# define SENF_PARSER_FIELD_I(name, type, ofstype, rwtype) \ + SENF_PARSER_I_BITFIELD_RESET() \ + SENF_PARSER_I_FIELD_INTRO(name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_INIT_, rwtype) (name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \ + name, type, \ + BOOST_PP_CAT(SENF_PARSER_I_SIZE_, ofstype) (name, type), \ + BOOST_PP_CAT(SENF_PARSER_I_INITBYTES_, ofstype) (name, type) ) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, ofstype) +# +# define SENF_PARSER_FIELD_I_AFTER(name, type, prev, ofstype, rwtype) \ + SENF_PARSER_I_BITFIELD_RESET() \ + SENF_PARSER_I_FIELD_INTRO(name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_INIT_, rwtype) (name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_AFTER_, ofstype) (name, type, prev); \ + BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \ + name, type, \ + BOOST_PP_CAT(SENF_PARSER_I_SIZE_, ofstype) (name, type), \ + BOOST_PP_CAT(SENF_PARSER_I_INITBYTES_, ofstype) (name, type) ) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, ofstype) +# +# define SENF_PARSER_CUSTOM_FIELD_I(name, type, size, isize, ofstype) \ + SENF_PARSER_I_BITFIELD_RESET() \ + SENF_PARSER_I_FIELD_INTRO(name, type) \ + SENF_PARSER_I_FIELD_INIT_ro(name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_, ofstype) (name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) (name, type, size, isize) \ + BOOST_PP_CAT(name, _t) name() const +# +# define SENF_PARSER_CUSTOM_FIELD_I_AFTER(name, type, size, isize, prev, ofstype) \ + SENF_PARSER_I_BITFIELD_RESET() \ + SENF_PARSER_I_FIELD_INTRO(name, type) \ + SENF_PARSER_I_FIELD_INIT_ro(name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_OFS_AFTER, ofstype) (name, type, prev) \ + BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) (name, type, size) \ + BOOST_PP_CAT(name, _t) name() const +# +# define SENF_PARSER_I_BITFIELD_RESET() \ + SENF_MPL_SLOT_SET(bit, 0); \ + SENF_MPL_SLOT_SET(bitfield_size, 0); +# +# define SENF_PARSER_BITFIELD_I(name, bits, type, ofstype, rwtype) \ + static size_type const BOOST_PP_CAT(name, _bit) = SENF_MPL_SLOT_GET(bit); \ + private: \ + SENF_MPL_SLOT_SET(bit, BOOST_PP_CAT(name, _bit) + bits); \ + typedef BOOST_PP_CAT(SENF_PARSER_BITFIELD_TYPE_, type)( BOOST_PP_CAT(name, _bit), bits ) \ + BOOST_PP_CAT(name,_bit_t ); \ + public: \ + SENF_PARSER_BITFIELD_II( name, bits, BOOST_PP_CAT(name, _bit_t), ofstype, rwtype) +# +# define SENF_PARSER_BITFIELD_TYPE_signed(start, bits) senf::Parse_IntField +# define SENF_PARSER_BITFIELD_TYPE_unsigned(start, bits) senf::Parse_UIntField +# define SENF_PARSER_BITFIELD_TYPE_bool(start, bits) senf::Parse_Flag +# +# define SENF_PARSER_BITFIELD_II(name, bits, type, ofstype, rwtype) \ + SENF_PARSER_I_FIELD_INTRO(name, type) \ + SENF_PARSER_I_FIELD_INIT_ro(name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_BITFIELD_OFS_, ofstype) (name, type) \ + BOOST_PP_CAT(SENF_PARSER_I_ADVANCE_OFS_, ofstype) ( \ + name, type, \ + BOOST_PP_CAT(name, _t)::fixed_bytes, BOOST_PP_CAT(name, _t)::fixed_bytes ) \ + private: \ + SENF_MPL_SLOT_SET(bitfield_size, BOOST_PP_CAT(name, _t)::fixed_bytes); \ + public: \ + BOOST_PP_CAT(SENF_PARSER_I_FIELD_VAL_, rwtype) (name, type, ofstype) +# +# define SENF_PARSER_I_BITFIELD_OFS_var(name, type) \ + size_type BOOST_PP_CAT(name,_offset)() const { \ + return field_offset_(static_cast*>(0)) \ + - SENF_MPL_SLOT_GET(bitfield_size); \ + } +# +# define SENF_PARSER_I_BITFIELD_OFS_fix(name, type) \ + static size_type const BOOST_PP_CAT(name, _offset) = SENF_MPL_SLOT_GET(offset) \ + - SENF_MPL_SLOT_GET(bitfield_size); +# +# define SENF_PARSER_INHERIT_I(name) \ + private: \ + SENF_MPL_SLOT_SET(index, 1); \ + SENF_MPL_SLOT_SET(init_bytes, senf::init_bytes::value); \ + size_type field_offset_(senf::mpl::rv<1>*) const { \ + return senf::bytes( *static_cast(this) ); \ + } \ + void init_chain(senf::mpl::rv*) { \ + name::init(); \ + } \ + public: +# +# define SENF_PARSER_FIXED_INHERIT_I(name) \ + private: \ + SENF_MPL_SLOT_SET(offset, name::fixed_bytes); \ + SENF_MPL_SLOT_SET(index, 1); \ + void init_chain(senf::mpl::rv<1>*) { \ + name::init(); \ + } \ + public: +# +# +# ////////////////////////////////ih.e/////////////////////////////////////// +# endif +# +# +# // Local Variables: +# // mode: c++ +# // fill-column: 100 +# // c-file-style: "senf" +# // indent-tabs-mode: nil +# // ispell-local-dictionary: "american" +# // compile-command: "scons -u test" +# // End: diff --git a/Packets/ParseInt.hh b/Packets/ParseInt.hh index ee97811..7612398 100644 --- a/Packets/ParseInt.hh +++ b/Packets/ParseInt.hh @@ -413,7 +413,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseInt_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_ParseInt_i_) #define HH_ParseInt_i_ //#include "ParseInt.cci" //#include "ParseInt.ct" diff --git a/Packets/ParseList.hh b/Packets/ParseList.hh index 3b7506b..dc757bf 100644 --- a/Packets/ParseList.hh +++ b/Packets/ParseList.hh @@ -370,7 +370,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseList_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_ParseList_i_) #define HH_ParseList_i_ //#include "ParseList.cci" #include "ParseList.ct" diff --git a/Packets/ParseListB.hh b/Packets/ParseListB.hh index f3506c5..5fa118c 100644 --- a/Packets/ParseListB.hh +++ b/Packets/ParseListB.hh @@ -69,7 +69,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseListB_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_ParseListB_i_) #define HH_ParseListB_i_ //#include "ParseListB.cci" //#include "ParseListB.ct" diff --git a/Packets/ParseListN.hh b/Packets/ParseListN.hh index 9151a61..28524bc 100644 --- a/Packets/ParseListN.hh +++ b/Packets/ParseListN.hh @@ -59,7 +59,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseListN_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_ParseListN_i_) #define HH_ParseListN_i_ //#include "ParseListN.cci" #include "ParseListN.ct" diff --git a/Packets/ParseVec.hh b/Packets/ParseVec.hh index 1154671..ded220a 100644 --- a/Packets/ParseVec.hh +++ b/Packets/ParseVec.hh @@ -310,7 +310,7 @@ namespace senf { ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseVec_i_) +#if !defined(HH_Packets__decls_) && !defined(HH_ParseVec_i_) #define HH_ParseVec_i_ //#include "ParseVec.cci" #include "ParseVec.ct" diff --git a/Packets/SConscript b/Packets/SConscript index 4f738bb..64bc78c 100644 --- a/Packets/SConscript +++ b/Packets/SConscript @@ -6,7 +6,7 @@ import SENFSCons, glob ########################################################################### SENFSCons.AllIncludesHH(env, [ f for f in glob.glob("*.hh") - if 'defined(SENF_PACKETS_DECL_ONLY)' in file(f).read() ]) + if 'defined(HH_Packets__decls_)' in file(f).read() ]) SENFSCons.StandardTargets(env) SENFSCons.Lib(env, diff --git a/Packets/parse_fixed_setup.hh b/Packets/parse_fixed_setup.hh new file mode 100644 index 0000000..a714b9d --- /dev/null +++ b/Packets/parse_fixed_setup.hh @@ -0,0 +1,67 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief parse_fixed_setup public header */ + +#ifdef SENF_PARSER_SETUP_INCLUDED +# undef SENF_PARSE_FIELD +# undef SENF_PARSE_FIELD_RO +# undef SENF_PARSE_FIELD_AFTER +# undef SENF_PARSE_FIELD_AFTER_RO +# undef SENF_PARSE_CUSTOM_FIELD +# undef SENF_PARSE_CUSTOM_FIELD_AFTER +# undef SENF_PARSE_BITFIELD +# undef SENF_PARSE_BITFIELD_RO +# undef SENF_PARSER_INHERIT +# undef SENF_PARSER_FINALIZE +# undef SENF_PARSER_FINALIZE_INHERITED +# undef SENF_PARSER_SETUP_INCLUDED +#endif + +#define SENF_PARSE_FIELD SENF_PARSER_FIXED_FIELD +#define SENF_PARSE_FIELD_RO SENF_PARSER_FIXED_FIELD_RO +#define SENF_PARSE_FIELD_AFTER SENF_PARSER_FIXED_FIELD_AFTER +#define SENF_PARSE_FIELD_AFTER_RO SENF_PARSER_FIXED_FIELD_AFTER_RO +#define SENF_PARSE_CUSTOM_FIELD SENF_PARSER_FIXED_CUSTOM_FIELD +#define SENF_PARSE_CUSTOM_FIELD_AFTER SENF_PARSER_FIXED_CUSTOM_FIELD_AFTER +#define SENF_PARSE_BITFIELD SENF_PARSER_FIXED_BITFIELD +#define SENF_PARSE_BITFIELD_RO SENF_PARSER_FIXED_BITFIELD_RO + +#define SENF_PARSER_INHERIT SENF_PARSER_FIXED_INHERIT_I +#define SENF_PARSER_FINALIZE SENF_PARSER_FINALIZE_FIXED +#define SENF_PARSER_FINALIZE_INHERITED SENF_PARSER_FINALIZE_INHERITED_FIXED + +#define SENF_PARSER_SETUP_INCLUDED 1 + +SENF_FIXED_PARSER_INITIALIZE() + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Packets/parse_setup.hh b/Packets/parse_setup.hh new file mode 100644 index 0000000..b097271 --- /dev/null +++ b/Packets/parse_setup.hh @@ -0,0 +1,67 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief parse_setup public header */ + +#ifdef SENF_PARSER_SETUP_INCLUDED +# undef SENF_PARSE_FIELD +# undef SENF_PARSE_FIELD_RO +# undef SENF_PARSE_FIELD_AFTER +# undef SENF_PARSE_FIELD_AFTER_RO +# undef SENF_PARSE_CUSTOM_FIELD +# undef SENF_PARSE_CUSTOM_FIELD_AFTER +# undef SENF_PARSE_BITFIELD +# undef SENF_PARSE_BITFIELD_RO +# undef SENF_PARSER_INHERIT +# undef SENF_PARSER_FINALIZE +# undef SENF_PARSER_FINALIZE_INHERITED +# undef SENF_PARSER_SETUP_INCLUDED +#endif + +#define SENF_PARSE_FIELD SENF_PARSER_FIELD +#define SENF_PARSE_FIELD_RO SENF_PARSER_FIELD_RO +#define SENF_PARSE_FIELD_AFTER SENF_PARSER_FIELD_AFTER +#define SENF_PARSE_FIELD_AFTER_RO SENF_PARSER_FIELD_AFTER_RO +#define SENF_PARSE_CUSTOM_FIELD SENF_PARSER_CUSTOM_FIELD +#define SENF_PARSE_CUSTOM_FIELD_AFTER SENF_PARSER_CUSTOM_FIELD_AFTER +#define SENF_PARSE_BITFIELD SENF_PARSER_BITFIELD +#define SENF_PARSE_BITFIELD_RO SENF_PARSER_BITFIELD_RO + +#define SENF_PARSER_INHERIT SENF_PARSER_INHERIT_I +#define SENF_PARSER_FINALIZE SENF_PARSER_FINALIZE_DYNAMIC +#define SENF_PARSER_FINALIZE_INHERITED SENF_PARSER_FINALIZE_INHERITED_DYNAMIC + +#define SENF_PARSER_SETUP_INCLUDED 1 + +SENF_PARSER_INITIALIZE() + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Utils/Logger/SConscript b/Utils/Logger/SConscript index 138b282..ab682dd 100644 --- a/Utils/Logger/SConscript +++ b/Utils/Logger/SConscript @@ -8,7 +8,8 @@ import SENFSCons, glob SENFSCons.StandardTargets(env) SENFSCons.AllIncludesHH(env, [ f for f in glob.glob("*.hh") - if f not in ('all_includes.hh','INet.hh') and not f.endswith('.test.hh') ]) + if ( f not in ('all_includes.hh','Logger.hh') + and not f.endswith('.test.hh') ) ]) sources = SENFSCons.GlobSources() objects = SENFSCons.Objects( env, sources = sources, LIBS = [ 'Utils' ] ) diff --git a/Utils/mpl.hh b/Utils/mpl.hh index ba60083..bb9115e 100644 --- a/Utils/mpl.hh +++ b/Utils/mpl.hh @@ -182,6 +182,17 @@ namespace mpl { static senf::mpl::rv<0> _SENF_MPL_SLOT_ ## name (_); \ SENF_MPL_SLOT_SET(name,value) + /** \brief Define MPL slot initialized to 0 + + This is like \ref SENF_MPL_SLOT_DEF() but initializes the slot to the fixed value 0. The + advantage over \ref SENF_MPL_SLOT_DEF() is, that this macro may be called from an include + file whereas all the other \\c SENF_MPL_SLOT_ macros must always be called from the relevant + file. + */ +# define SENF_MPL_SLOT_DEF_ZERO(name) \ + template \ + static senf::mpl::rv<0> _SENF_MPL_SLOT_ ## name (_); + /** \brief Set MPL slot \see \ref SENF_MPL_SLOT_DEF() \ingroup senfmpl diff --git a/doclib/Doxyfile.global b/doclib/Doxyfile.global index 753c4c5..87f3c31 100644 --- a/doclib/Doxyfile.global +++ b/doclib/Doxyfile.global @@ -27,7 +27,16 @@ SEARCHENGINE = YES MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES -PREDEFINED = DOXYGEN SENF_PPI_MODULE(x)= +PREDEFINED = DOXYGEN \ + "SENF_PPI_MODULE(x)=" \ + "SENF_PARSE_FIELD(name,type)=type name()" \ + "SENF_PARSE_FIELD_RO(name,type)=type::value_type name()" \ + "SENF_PARSE_FIELD_AFTER(name,type,prev)=type name()" \ + "SENF_PARSE_FIELD_AFTER_RO(name,type,prev)=type::value_type name()" \ + "SENF_PARSE_BITFIELD(name, bits, type)=type ## _ ## bits name()" \ + "SENF_PARSE_BITFIELD_RO(name, bits, type)=type ## _ ## bits name()" \ + "SENF_PARSER_FINALIZE(name)=" \ + "SENF_PARSER_INIT()=void init()" EXPAND_AS_DEFINED = prefix_ HTML_HEADER = "$(TOPDIR)/doclib/doxy-header.html" diff --git a/find-sources.sh b/find-sources.sh index be46965..46677f7 100755 --- a/find-sources.sh +++ b/find-sources.sh @@ -31,5 +31,7 @@ find . \ -name .test.bin -o \ -name "*.stamp" -o \ -name ".sconsign*" -o \ + -name "semantic.cache" -o \ + -name "all_includes.hh" -o \ -type f $cond \( "$@" \)