-// $Id: SNDUPacket.hh 423 2007-08-31 22:05:37Z g0dil $
+// $Id$
//
// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Thorsten Horstmann <tho@berlios.de>
//
// 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
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
- \brief SNDUPacket public header */
+ \brief TLVPacket public header */
#ifndef HH_TLVPacket_
#define HH_TLVPacket_ 1
// Custom includes
#include <algorithm>
-#include "../../Packets/PacketType.hh"
-#include "../../Packets/ParseInt.hh"
-#include "../../Packets/PacketParser.hh"
+#include "../../Packets/Packets.hh"
//#include "TLVPacket.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
-
+ /** \brief xxx
+
+ \todo document me
+ \todo add usefull exceptions strings
+
+ */
struct UnsuportedTLVPacketException : public std::exception
{
virtual char const * what() const throw() {
}
};
- struct Parse_TLVPacketLength
- : public detail::packet::ParseIntOps<Parse_TLVPacketLength, boost::uint32_t>,
+ /** \brief xxx
+ \todo document me
+ */
+ class DynamicTLVLengthParser
+ : public detail::packet::IntParserOps<DynamicTLVLengthParser, boost::uint32_t>,
public PacketParserBase
{
-# ifndef DOXYGEN
-
- SENF_PACKET_PARSER_NO_INIT(Parse_TLVPacketLength);
-
- typedef Parse_Flag < 0 > Parse_extended_length_flag;
- typedef Parse_UIntField < 1, 8 > Parse_fixed_length;
+ public:
+ DynamicTLVLengthParser(data_iterator i, state_type s) : PacketParserBase(i,s) {}
- SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
- ((OverlayField)( extended_length_flag, Parse_extended_length_flag ))
- ((Field )( fixed_length_field, Parse_fixed_length ))
- );
-
-# endif
-
typedef boost::uint32_t value_type;
+ static const size_type init_bytes = 1;
+ static value_type const min_value = 0;
+ static value_type const max_value = 4294967295u;
+
+ value_type value() const;
+ void value(value_type const & v);
- value_type value() const {
- switch( bytes() ) {
- case 1:
- return fixed_length_field().value();
- case 2:
- return parse<Parse_UInt8>( 1 ).value();
- case 3:
- return parse<Parse_UInt16>( 1 ).value();
- case 4:
- return parse<Parse_UInt24>( 1 ).value();
- case 5:
- return parse<Parse_UInt32>( 1 ).value();
- default:
- throw(UnsuportedTLVPacketException());
- };
- }
-
- size_type bytes() const {
- if ( extended_length_flag() )
- return 1 + fixed_length_field();
- else
- return 1;
+ DynamicTLVLengthParser const & operator= (value_type other);
+ size_type bytes() const;
+ void init() const;
+
+ private:
+ typedef FlagParser < 0 > ExtendedLengthFlagParser;
+ typedef UIntFieldParser < 1, 8 > FixedLengthParser;
+
+ ExtendedLengthFlagParser extended_length_flag() const {
+ return parse<ExtendedLengthFlagParser>( 0 );
}
-
- void init() const {
- defaultInit();
- extended_length_flag() = 0;
+
+ FixedLengthParser fixed_length_field() const {
+ return parse<FixedLengthParser>( 0 );
}
+ void resize(size_type size);
};
/** \brief parse TLVPacket Packet
- XXX
-
+ \todo document me
+
\see TLVPacketType
*/
- struct Parse_TLVPacket : public PacketParserBase
+ template <class TypeParser, class LengthParser>
+ struct TLVPacketParser : public PacketParserBase
{
-# ifndef DOXYGEN
+# include SENF_PARSER()
- SENF_PACKET_PARSER_INIT(Parse_TLVPacket);
+ SENF_PARSER_FIELD( type, TypeParser );
+ SENF_PARSER_FIELD( length, LengthParser );
- SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
- ((Field)( type, Parse_UInt32 ))
- ((Field)( length, Parse_TLVPacketLength ))
- );
-
-# endif
-
-// Parse_UInt32 type() const {
-// return parse<Parse_UInt32>( 0 );
-// }
-
-// Parse_TLVPacketLength length() const {
-// return parse<Parse_TLVPacketLength>( 4 );
-// }
-
- PacketParserBase::size_type bytes() const;
-
- static const size_type init_bytes = 4+1; // 4 bytes type + 1 byte length
-
+ SENF_PARSER_FINALIZE(TLVPacketParser);
};
-
- /** \brief TLV Packet
+
+ /** \brief generic TLV Packet type
+
+ \todo document me
- \par Packet type (typedef):
- \ref TLVPacket
-
- \par Fields:
- \ref Parse_TLVPacket
-
\ingroup protocolbundle_mpegdvb
*/
+ template <class TypeParser, class LengthParser>
struct TLVPacketType
- : public PacketTypeBase,
- public PacketTypeMixin<TLVPacketType>
+ : public PacketTypeBase
{
- typedef PacketTypeMixin<TLVPacketType> mixin;
- typedef ConcretePacket<TLVPacketType> packet;
- typedef Parse_TLVPacket parser;
+ typedef ConcretePacket<TLVPacketType<TypeParser, LengthParser> > packet;
+ typedef TLVPacketParser<TypeParser, LengthParser> parser;
- using mixin::nextPacketRange;
- using mixin::init;
+ static optional_range nextPacketRange(packet p);
+ static size_type initSize();
+ static void finalize(packet p);
static void dump(packet p, std::ostream & os);
-
- static PacketParserBase::size_type initSize();
- static PacketParserBase::size_type initHeadSize();
};
-
- typedef TLVPacketType::packet TLVPacket;
+ typedef ConcretePacket<TLVPacketType<UInt32Parser, DynamicTLVLengthParser> > MIHInfoElement;
}
///////////////////////////////hh.e////////////////////////////////////////
//#include "TLVPacket.cci"
-//#include "TLVPacket.ct"
+#include "TLVPacket.ct"
//#include "TLVPacket.cti"
#endif