f52da1cdb4fb384951d7b09a155a955f570faff2
[senf.git] / Packets / MPEGDVBBundle / TLVPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief TLVPacket public header */
25
26 #ifndef HH_TLVPacket_
27 #define HH_TLVPacket_ 1
28
29 // Custom includes
30 #include <algorithm>
31 #include "../../Packets/Packets.hh"
32
33 //#include "TLVPacket.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37
38     struct UnsuportedTLVPacketException : public std::exception
39     { 
40         virtual char const * what() const throw() { 
41             return "length of length can be max. 4 bytes. Sorry.";
42         }
43     };
44
45     class Parse_TLVPacketLength 
46         : public detail::packet::ParseIntOps<Parse_TLVPacketLength, boost::uint32_t>,
47           public PacketParserBase
48     {
49     public:
50         Parse_TLVPacketLength(data_iterator i, state_type s) : PacketParserBase(i,s) {}
51
52         typedef boost::uint32_t value_type;
53     
54         value_type value() const;
55
56         void value(value_type const & v);
57         
58         Parse_TLVPacketLength const & operator= (value_type other);
59             
60         static const size_type init_bytes = 1;
61
62         size_type bytes() const;
63             
64         void init() const;
65
66     private:
67         typedef Parse_Flag      <    0 > Parse_extended_length_flag;
68         typedef Parse_UIntField < 1, 8 > Parse_fixed_length;
69
70         Parse_extended_length_flag extended_length_flag() const {
71             return parse<Parse_extended_length_flag>( 0 );
72         }
73
74         Parse_fixed_length fixed_length_field() const {
75             return parse<Parse_fixed_length>( 0 );
76         }
77         
78         void resize(size_type size);
79     };  
80         
81     /** \brief parse TLVPacket Packet
82     
83
84         
85         \see TLVPacketType
86      */
87     struct Parse_TLVPacket : public PacketParserBase
88     {
89 #       include SENF_PARSER()
90         
91         SENF_PARSER_FIELD( type,   Parse_UInt32 );
92         SENF_PARSER_FIELD( length, Parse_TLVPacketLength );
93         
94         SENF_PARSER_FINALIZE(Parse_TLVPacket);
95     };
96
97     /** \brief TLV Packet
98         \image html TLV.png
99         
100         \par Packet type (typedef):
101             \ref TLVPacket
102
103         \par Fields:
104             \ref Parse_TLVPacket
105
106         \ingroup protocolbundle_mpegdvb
107      */
108     struct TLVPacketType
109         : public PacketTypeBase
110     {
111         typedef ConcretePacket<TLVPacketType> packet;
112         typedef Parse_TLVPacket parser;
113
114         static optional_range nextPacketRange(packet p);
115         static void init(packet p);
116         static size_type initSize();
117         static void finalize(packet p);
118         static void dump(packet p, std::ostream & os);
119     };
120         
121     typedef TLVPacketType::packet TLVPacket;
122     
123 }
124
125
126 ///////////////////////////////hh.e////////////////////////////////////////
127 //#include "TLVPacket.cci"
128 //#include "TLVPacket.ct"
129 //#include "TLVPacket.cti"
130 #endif
131
132 \f
133 // Local Variables:
134 // mode: c++
135 // fill-column: 100
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"
140 // comment-column: 40
141 // End: