X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FParseHelpers.hh;h=9eff3949a311422884a3f7c58e2df7c61b214076;hb=bd9f9d3fd6fbcff0112a7bf48ab9284da9576b11;hp=6561dbf79151fbeb9400cf360e5a2c29597d7192;hpb=9f6bb706cb491d4da38f6472746b3076a66202e0;p=senf.git diff --git a/Packets/ParseHelpers.hh b/Packets/ParseHelpers.hh index 6561dbf..9eff394 100644 --- a/Packets/ParseHelpers.hh +++ b/Packets/ParseHelpers.hh @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -23,10 +23,10 @@ /** \file \brief ParseHelpers public header */ -#ifndef HH_ParseHelpers_ -#define HH_ParseHelpers_ 1 +#ifndef HH_SENF_Packets_ParseHelpers_ +#define HH_SENF_Packets_ParseHelpers_ 1 -#ifndef HH_Packets_ +#ifndef HH_SENF_Packets_Packets_ #error "Don't include 'ParseHelpers.hh' directly, include 'Packets.hh'" #endif @@ -47,7 +47,7 @@ the ethernet packet in DefaultBundle/EthernetPacket.hh) \code - struct Parse_EthVLan : public PacketParserBase + struct EthVLanPacketParser : public PacketParserBase { # include SENF_FIXED_PARSER() @@ -55,9 +55,9 @@ SENF_PARSER_BITFIELD( cfi, 1, bool ); SENF_PARSER_BITFIELD( vlanId, 12, unsigned ); - SENF_PARSER_FIELD( type, Parse_UInt16 ); + SENF_PARSER_FIELD( type, UInt16Parser ); - SENF_PARSER_FINALIZE(Parse_EthVLan); + SENF_PARSER_FINALIZE(EthVLanPacketParser); }; \endcode @@ -102,14 +102,14 @@ { # include SENF_FIXED_PARSER() - SENF_PARSER_FIELD ( table_id , Parse_UInt8 ); + SENF_PARSER_FIELD ( table_id , UInt8Parser ); SENF_PARSER_BITFIELD ( ssi , 1 , bool ); SENF_PARSER_BITFIELD ( private_indicator , 1 , bool ); SENF_PARSER_SKIP_BITS( 2 ); SENF_PARSER_BITFIELD ( sec_length , 12 , unsigned ); - SENF_PARSER_FIELD ( table_id_extension , Parse_UInt16 ); + SENF_PARSER_FIELD ( table_id_extension , UInt16Parser ); SENF_PARSER_FINALIZE( Parse_DSMCCSection ); }; @@ -120,15 +120,15 @@ SENF_PARSER_INHERIT( Parse_DSMCCSection ); - SENF_PARSER_FIELD ( mac_addr_4 , Parse_UInt8 ); - SENF_PARSER_FIELD ( mac_addr_3 , Parse_UInt8 ); + SENF_PARSER_FIELD ( mac_addr_4 , UInt8Parser ); + SENF_PARSER_FIELD ( mac_addr_3 , UInt8Parser ); SENF_PARSER_FINALIZE( Parse_DatagramSection ); // Parse table_id_extension as two bytes SENF_PARSER_GOTO( table_id_extension ); - SENF_PARSER_FIELD ( mac_addr_6 , Parse_UInt8 ); - SENF_PARSER_FIELD ( mac_addr_5 , Parse_UInt8 ); + SENF_PARSER_FIELD ( mac_addr_6 , UInt8Parser ); + SENF_PARSER_FIELD ( mac_addr_5 , UInt8Parser ); }; \endcode @@ -180,7 +180,7 @@ \par "" \ref SENF_PARSER_FIELD(), \ref SENF_PARSER_FIELD_RO(), \ref SENF_PARSER_PRIVATE_FIELD(), - \ref SENF_PARSER_PRIVATE_FIELD_RO(), SENF_PARSER_CUSTOM_FIELD() + \ref SENF_PARSER_CUSTOM_FIELD() There are quite a few commands available to define fields. All these macros do the same thing: they define a field accessor plus some auxiliary symbols. The accessor will use the parser type @@ -206,8 +206,7 @@ The field defining macros come in groups which members only differ in their properties:
Standard fields:
\ref SENF_PARSER_FIELD(), \ref SENF_PARSER_FIELD_RO(), - \ref SENF_PARSER_PRIVATE_FIELD(), \ref SENF_PARSER_PRIVATE_FIELD_RO() define standard - fields.
+ \ref SENF_PARSER_PRIVATE_FIELD() define standard fields.
Arbitrary custom field:
\ref SENF_PARSER_CUSTOM_FIELD()
@@ -221,11 +220,11 @@ \par "" \ref SENF_PARSER_BITFIELD(), \ref SENF_PARSER_BITFIELD_RO(), \ref - SENF_PARSER_PRIVATE_BITFIELD(), \ref SENF_PARSER_PRIVATE_BITFIELD_RO() \n + SENF_PARSER_PRIVATE_BITFIELD()\n Bit-fields play a special role. They are quite frequent in packet definitions but don't fit into the byte offset based parsing infrastructure defined so far. Since defining the correctly - parameterized senf::Parse_IntField, senf::Parse_UIntField and senf::Parse_Flag typedefs is quite + parameterized senf::IntFieldParser, senf::UIntFieldParser and senf::FlagParser typedefs is quite tedious, these helper macros are provided. It is important to recognize, that the current offset does \e not include the current bit @@ -239,7 +238,7 @@ at the end), those bit's will be skipped. Since consecutive bit-field commands are aggregated into a single bit-field group, the offset of - all these bit-fields will be the offset of the \e beginning of the bit-field irrespective of the + all these bit-fields will be the offset of the \e beginning of the group irrespective of the number of bits parsed so far. Changing the offset to some bitfield using \ref SENF_PARSER_GOTO() will therefore always go to the position at the beginning of this bitfield group. And since the current offset does not include the bit position, the bit position will be 0, the first bit. You @@ -279,7 +278,7 @@ \ingroup packetparser */ -///\ingroup packetparsermacros +///\addtogroup packetparsermacros ///\{ ///\name Control information @@ -338,7 +337,7 @@ \hideinitializer */ -#define SENF_PARSER_INIT() void init(int) +#define SENF_PARSER_INIT() void init(int) const #ifdef DOXYGEN @@ -354,6 +353,9 @@ SENF_PARSER_INHERIT(BaseParser) \endcode + + If you want to define collection fields which reference auxiliary fields in the base parser, + you must define the base parser as a variable parser not a fixed parser. \param[in] base name of base class \hideinitializer @@ -402,9 +404,8 @@
return_type name() const
The accessor member will return the parsed value when called. For normal fields, return_type equals type, the type of the sub parser. This allows to change the value via the returned - sub-parser. If the field is marked read-only (\ref SENF_PARSER_FIELD_RO() or \ref - SENF_PARSER_PRIVATE_FIELD_RO()), the return type will be - type::value_type.
+ sub-parser. If the field is marked read-only (\ref SENF_PARSER_FIELD_RO()), the return type + will be type::value_type.
typedef type name_t
This typedef symbol is an alias for the fields type.
@@ -420,22 +421,25 @@ \param[in] name field name \param[in] type parser type - \see \ref SENF_PARSER_FIELD_RO(), \ref SENF_PARSER_PRIVATE_FIELD(), \ref - SENF_PARSER_PRIVATE_FIELD_RO() + \see \ref SENF_PARSER_FIELD_RO(), \ref SENF_PARSER_PRIVATE_FIELD() \hideinitializer */ -#define SENF_PARSER_FIELD(name, type) +#define SENF_PARSER_FIELD(name, type) /** \brief Define parser field (read-only) Define read-only parser field. Read-only fields may only be defined for \a type's which are value parsers: The parser \a type must have a \c value_type typedef member and a \c value() member, which returns the current value of the field. + + Defining such a field really defines \e two accessors: A read/write \e private field and a + read-only \e public accessor. The name of the private read/write field is given by adding a + trailing '_' to \a name. The read-only public accessor is called \a name. \see SENF_PARSER_FIELD() \hideinitializer */ -#define SENF_PARSER_FIELD_RO(name, type) +#define SENF_PARSER_FIELD_RO(name, type) /** \brief Define parser field (private) @@ -445,28 +449,16 @@ \see SENF_PARSER_FIELD() \hideinitializer */ -#define SENF_PARSER_PRIVATE_FIELD(name, type) - -/** \brief Define parser field (private + read-only) - - Define a read-only parser field which is marked as \c private and may only be accessed from the - parser class itself. Read-only fields may only be defined for \a type's which are value parsers: - The parser \a type must have a \c value_type typedef member and a \c value() member, which - returns the current value of the field. - - \see SENF_PARSER_FIELD() - \hideinitializer - */ -#define SENF_PARSER_PRIVATE_FIELD_RO(name, type) +#define SENF_PARSER_PRIVATE_FIELD(name, type) /** \brief Define custom field accessor This macro is used to define a field using a custom access method: \code - // The following is the same as SENF_PARSER_FIELD( xyz, senf::Parse_UInt16 ) + // The following is the same as SENF_PARSER_FIELD( xyz, senf::UInt16Parser ) // in a fixed size parser. - SENF_PARSER_CUSTOM_FIELD(xyz, senf::Parse_UInt16, xyz_t::fixed_bytes) { + SENF_PARSER_CUSTOM_FIELD(xyz, senf::UInt16Parser, xyz_t::fixed_bytes) { return parse( xyz_offset ); } \endcode @@ -488,7 +480,7 @@ \param[in] size size of the field, either a single value \a bytes for fixed size parsers or two separate arguments \a bytes and \a init_bytes for dynamically sized parsers */ -#define SENF_PARSER_CUSTOM_FIELD(name, type, size) +#define SENF_PARSER_CUSTOM_FIELD(name, type, size) ///@} @@ -498,13 +490,13 @@ /** \brief Define bit-field Bit fields are supported by a special family of parser macros. These macros simplify defining - fields using the senf::Parse_Int, senf::Parse_UInt and senf::Parse_Flag parsers by keeping track + fields using the senf::Parse_Int, senf::Parse_UInt and senf::FlagParser parsers by keeping track of the current bit position and automatically creating the correct template parameters. The \a type parameter specifies the type of bitfield to define. This value is one of - \li \c signed, for signed bit fields (senf::Parse_IntField) - \li \c unsigned, for unsigned bit fields (senf::Parse_UIntField) or - \li \c bool, for single-bit flags (senf::Parse_Flag). + \li \c signed, for signed bit fields (senf::IntFieldParser) + \li \c unsigned, for unsigned bit fields (senf::UIntFieldParser) or + \li \c bool, for single-bit flags (senf::FlagParser). The \a bits parameter specifies the number of bits the field covers. For \c signed or \c unsigned fields, this value may be any numeric value from 1 to 32, for \c bool fields, this @@ -516,21 +508,19 @@ \param[in] bits number of bits \param[in] type bit field type, one of \c signed, \c unsigned or \c bool - \see \ref SENF_PARSER_BITFIELD_RO(), \ref SENF_PARSER_PRIVATE_BITFIELD(), \ref - SENF_PARSER_PRIVATE_BITFIELD_RO() - + \see \ref SENF_PARSER_BITFIELD_RO(), \ref SENF_PARSER_PRIVATE_BITFIELD() \hideinitializer */ -#define SENF_PARSER_BITFIELD(name, bits, type) +#define SENF_PARSER_BITFIELD(name, bits, type) /** \brief Define bit-field (read-only) - Define read-only bit field. + Define read-only bit field. This is for bit-fields what \ref SENF_PARSER_FIELD_RO is for ordinary fields. - \see \ref SENF_PARSER_BITFIELD() + \see \ref SENF_PARSER_BITFIELD() \n \ref SENF_PARSER_FIELD_RO() \hideinitializer */ -#define SENF_PARSER_BITFIELD_RO(name, bits, type) +#define SENF_PARSER_BITFIELD_RO(name, bits, type) /** \brief Define bit-field (private) @@ -540,17 +530,7 @@ \see \ref SENF_PARSER_BITFIELD() \hideinitializer */ -#define SENF_PARSER_PRIVATE_BITFIELD(name, bits, type) - -/** \brief Define bit-field (private + read-only) - - Define a read-only bit field which is marked as \c private and may only be accessed from the - parser class itself. - - \see \ref SENF_PARSER_BITFIELD() - \hideinitializer - */ -#define SENF_PARSER_PRIVATE_BITFIELD_RO(name, bits, type) +#define SENF_PARSER_PRIVATE_BITFIELD(name, bits, type) ///@} @@ -660,40 +640,53 @@ arbitrary incorrect value otherwise. \pre Field \a name preceded by fixed size fields only - \param[in] field or label name + \param[in] name field or label name \returns compile-time constant offset of the field from parsers start \hideinitializer */ #define SENF_PARSER_FIXED_OFFSET(name) +/** \brief Get current fixed offset, if possible + + This macro will return the current fixed offset, a compile-time constant expression. This is + always possible when defining a fixed size parser. + + Even in dynamically sized parsers this macro will work, if all parser defined \e before the + current position are fixed-size parsers. This macro does \e not validate this condition, it will + return an arbitrary incorrect value otherwise. + + \pre Current position preceded by fixed-size parsers only + \returns compile-time constant offset from parsers start + \hideinitializer + */ +#define SENF_PARSER_CURRENT_FIXED_OFFSET() + ///@} #else -#define SENF_PARSER_INHERIT BOOST_PP_CAT(SENF_PARSER_INHERIT_, SENF_PARSER_TYPE) +#define SENF_PARSER_INHERIT BOOST_PP_CAT( SENF_PARSER_INHERIT_, SENF_PARSER_TYPE ) -#define SENF_PARSER_FIELD BOOST_PP_CAT(SENF_PARSER_FIELD_, SENF_PARSER_TYPE) -#define SENF_PARSER_FIELD_RO BOOST_PP_CAT(SENF_PARSER_FIELD_RO_, SENF_PARSER_TYPE) -#define SENF_PARSER_BITFIELD BOOST_PP_CAT(SENF_PARSER_BITFIELD_, SENF_PARSER_TYPE) -#define SENF_PARSER_BITFIELD_RO BOOST_PP_CAT(SENF_PARSER_BITFIELD_RO_, SENF_PARSER_TYPE) -#define SENF_PARSER_CUSTOM_FIELD BOOST_PP_CAT(SENF_PARSER_CUSTOM_FIELD_, SENF_PARSER_TYPE) +#define SENF_PARSER_FIELD BOOST_PP_CAT( SENF_PARSER_FIELD_, SENF_PARSER_TYPE ) +#define SENF_PARSER_FIELD_RO BOOST_PP_CAT( SENF_PARSER_FIELD_RO_, SENF_PARSER_TYPE ) +#define SENF_PARSER_BITFIELD BOOST_PP_CAT( SENF_PARSER_BITFIELD_, SENF_PARSER_TYPE ) +#define SENF_PARSER_BITFIELD_RO BOOST_PP_CAT( SENF_PARSER_BITFIELD_RO_, SENF_PARSER_TYPE ) +#define SENF_PARSER_CUSTOM_FIELD BOOST_PP_CAT( SENF_PARSER_CUSTOM_FIELD_, SENF_PARSER_TYPE ) -#define SENF_PARSER_PRIVATE_FIELD BOOST_PP_CAT(SENF_PARSER_P_FIELD_, SENF_PARSER_TYPE) -#define SENF_PARSER_PRIVATE_FIELD_RO BOOST_PP_CAT(SENF_PARSER_P_FIELD_RO_, SENF_PARSER_TYPE) -#define SENF_PARSER_PRIVATE_BITFIELD BOOST_PP_CAT(SENF_PARSER_P_BITFIELD_, SENF_PARSER_TYPE) -#define SENF_PARSER_PRIVATE_BITFIELD_RO BOOST_PP_CAT(SENF_PARSER_P_BITFIELD_RO_, SENF_PARSER_TYPE) +#define SENF_PARSER_PRIVATE_FIELD BOOST_PP_CAT( SENF_PARSER_P_FIELD_, SENF_PARSER_TYPE ) +#define SENF_PARSER_PRIVATE_BITFIELD BOOST_PP_CAT( SENF_PARSER_P_BITFIELD_, SENF_PARSER_TYPE ) -#define SENF_PARSER_SKIP BOOST_PP_CAT(SENF_PARSER_SKIP_, SENF_PARSER_TYPE) -#define SENF_PARSER_SKIP_BITS BOOST_PP_CAT(SENF_PARSER_SKIP_BITS_, SENF_PARSER_TYPE) -#define SENF_PARSER_GOTO BOOST_PP_CAT(SENF_PARSER_GOTO_, SENF_PARSER_TYPE) -#define SENF_PARSER_GOTO_OFFSET BOOST_PP_CAT(SENF_PARSER_GOTO_OFFSET_, SENF_PARSER_TYPE) -#define SENF_PARSER_LABEL BOOST_PP_CAT(SENF_PARSER_LABEL_, SENF_PARSER_TYPE) +#define SENF_PARSER_SKIP BOOST_PP_CAT( SENF_PARSER_SKIP_, SENF_PARSER_TYPE ) +#define SENF_PARSER_SKIP_BITS BOOST_PP_CAT( SENF_PARSER_SKIP_BITS_, SENF_PARSER_TYPE ) +#define SENF_PARSER_GOTO BOOST_PP_CAT( SENF_PARSER_GOTO_, SENF_PARSER_TYPE ) +#define SENF_PARSER_GOTO_OFFSET BOOST_PP_CAT( SENF_PARSER_GOTO_OFFSET_, SENF_PARSER_TYPE ) +#define SENF_PARSER_LABEL BOOST_PP_CAT( SENF_PARSER_LABEL_, SENF_PARSER_TYPE ) -#define SENF_PARSER_OFFSET BOOST_PP_CAT(SENF_PARSER_OFFSET_, SENF_PARSER_TYPE) -#define SENF_PARSER_FIXED_OFFSET BOOST_PP_CAT(SENF_PARSER_FIXED_OFFSET_,SENF_PARSER_TYPE) -#define SENF_PARSER_CURRENT_FIXED_OFFSET BOOST_PP_CAT(SENF_PARSER_CURRENT_FIXED_OFFSET_, SENF_PARSER_TYPE) +#define SENF_PARSER_OFFSET BOOST_PP_CAT( SENF_PARSER_OFFSET_, SENF_PARSER_TYPE ) +#define SENF_PARSER_FIXED_OFFSET BOOST_PP_CAT( SENF_PARSER_FIXED_OFFSET_, SENF_PARSER_TYPE ) +#define SENF_PARSER_CURRENT_FIXED_OFFSET BOOST_PP_CAT( SENF_PARSER_CURRENT_FIXED_OFFSET_, SENF_PARSER_TYPE ) -#define SENF_PARSER_FINALIZE BOOST_PP_CAT(SENF_PARSER_FINALIZE_, SENF_PARSER_TYPE) +#define SENF_PARSER_FINALIZE BOOST_PP_CAT( SENF_PARSER_FINALIZE_, SENF_PARSER_TYPE ) #endif @@ -701,8 +694,8 @@ ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(HH_Packets__decls_) && !defined(HH_ParseHelpers_i_) -#define HH_ParseHelpers_i_ +#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_ParseHelpers_i_) +#define HH_SENF_Packets_ParseHelpers_i_ //#include "ParseHelpers.cci" //#include "ParseHelpers.ct" //#include "ParseHelpers.cti"