Packets: senf::Parse_Variant documentation
[senf.git] / Packets / MPEGDVBBundle / SNDUPacket.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 SNDUPacket public header */
25
26 #ifndef HH_SNDUPacket_
27 #define HH_SNDUPacket_ 1
28
29 // Custom includes
30 #include <algorithm>
31 #include <boost/crc.hpp>
32 #include "../../Packets/Packets.hh"
33 #include "../DefaultBundle/EthernetPacket.hh"
34
35 //#include "SNDUPacket.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39
40     /** \brief parse ULE SNDU Packet
41     
42         Parser implementing the header and trailer of a ULE SNDU Packet
43         
44         \see SNDUPacketType
45      */
46     struct Parse_SNDUPacket : public PacketParserBase
47     {
48 #       include SENF_PARSER()
49
50         /* We first define the fields as they appear in the field. Some of the fields are declared
51            private. We provide custom accessors for those fields further down. */
52
53         SENF_PARSER_PRIVATE_BITFIELD ( d_bit_       ,  1 , unsigned );
54         SENF_PARSER_BITFIELD         ( length       , 15 , unsigned );
55         SENF_PARSER_FIELD            ( type         , Parse_UInt16  );
56         SENF_PARSER_PRIVATE_VARIANT  ( destination_ , d_bit_        , 
57                                                       (Parse_MAC) (VoidPacketParser) );
58         
59         SENF_PARSER_FINALIZE( Parse_SNDUPacket );
60         
61         Parse_MAC destination()         /// Only defined if d_bit() == \c false
62             { return destination_().get<0>(); }
63
64         bool d_bit()                    /// Destination absent bit
65             { return d_bit_(); }
66
67         void withDestination()          /// Clear destination absent bit
68             { destination_().init<0>(); }
69         
70         void withoutDestination()       /// Set destination absent bit
71             { destination_().init<1>(); }
72
73         Parse_UInt32 crc() 
74             { return parse<Parse_UInt32>( data().size() - 4 ); }
75
76         boost::uint32_t calcCrc() const;
77     };
78
79     
80     struct ULEExtHeaderTypes {
81         typedef boost::uint16_t key_t;
82     };
83     
84     /** \brief ULE SNDU Packet
85         
86         \par Packet type (typedef):
87             \ref SNDUPacket
88
89         \par Fields:
90             \ref Parse_SNDUPacket
91
92         \ingroup protocolbundle_mpegdvb
93      */
94     struct SNDUPacketType
95         : public PacketTypeBase
96 //          public PacketTypeMixin<SNDUPacketType, ULEExtHeaderTypes>
97     {
98 //        typedef PacketTypeMixin<SNDUPacketType, ULEExtHeaderType> mixin;
99         typedef ConcretePacket<SNDUPacketType> packet;
100         typedef Parse_SNDUPacket parser;
101
102 //        using mixin::nextPacketRange;
103 //        using mixin::nextPacketType;
104 //        using mixin::init;
105         
106 //        static registry_key_t nextPacketKey(packet p);
107         
108         static void init(packet p);
109
110         static factory_t nextPacketType(packet p);
111         
112         static optional_range nextPacketRange(packet p);
113         
114         static void dump(packet p, std::ostream & os);
115         
116         static PacketParserBase::size_type initSize();
117         
118         static PacketParserBase::size_type initHeadSize();
119     };
120         
121     typedef SNDUPacketType::packet SNDUPacket;
122     
123     typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> ule_crc32;
124
125
126     /*!
127      \def ULE_END_INDICATOR 
128          ULE End Indicator; indicates to the receiver that there are no 
129          further SNDUs present within the current TS packet.
130     */
131 #   define ULE_END_INDICATOR 0xffff
132 }
133
134
135 ///////////////////////////////hh.e////////////////////////////////////////
136 //#include "SNDUPacket.cci"
137 //#include "SNDUPacket.ct"
138 //#include "SNDUPacket.cti"
139 #endif
140
141 \f
142 // Local Variables:
143 // mode: c++
144 // fill-column: 100
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"
149 // comment-column: 40
150 // End: