switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / MPEGDVBBundle / SNDUPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Thorsten Horstmann <tho@berlios.de>
27
28 /** \file
29     \brief SNDUPacket public header */
30
31 #ifndef HH_SENF_Packets_MPEGDVBBundle_SNDUPacket_
32 #define HH_SENF_Packets_MPEGDVBBundle_SNDUPacket_ 1
33
34 // Custom includes
35 #include <boost/crc.hpp>
36 #include <senf/Packets/Packets.hh>
37 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
38
39 //#include "SNDUPacket.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43
44     /** \brief parse ULE SNDU Packet
45
46         Parser implementing the header and trailer of a ULE SNDU Packet
47
48         \see SNDUPacketType
49      */
50     struct SNDUPacketParser : public PacketParserBase
51     {
52 #       include SENF_PARSER()
53
54         /* We first define the fields as they appear in the field. Some of the fields are declared
55            private. We provide custom accessors for those fields further down. */
56
57         SENF_PARSER_PRIVATE_BITFIELD ( d_bit_       ,  1 , unsigned );
58         SENF_PARSER_BITFIELD         ( length       , 15 , unsigned );
59         SENF_PARSER_FIELD            ( type         , UInt16Parser  );
60         SENF_PARSER_PRIVATE_VARIANT  ( destination_ , d_bit_        ,
61                                                       (MACAddressParser) (VoidPacketParser) );
62
63         SENF_PARSER_FINALIZE( SNDUPacketParser );
64
65         MACAddressParser destination()  ///< Only defined if d_bit() == \c false
66             { return destination_().get<0>(); }
67
68         bool d_bit()                    ///< Destination absent bit
69             { return d_bit_(); }
70
71         void withDestination()          ///< Clear destination absent bit
72             { destination_().init<0>(); }
73
74         void withoutDestination()       ///< Set destination absent bit
75             { destination_().init<1>(); }
76
77         UInt32Parser crc()
78             { return parse<UInt32Parser>( data().size() - 4 ); }
79
80         boost::uint32_t calcCrc() const;
81     };
82
83
84     struct ULEExtHeaderTypes {
85         typedef boost::uint16_t key_t;
86     };
87
88     /** \brief ULE SNDU Packet
89
90         \par Packet type (typedef):
91             \ref SNDUPacket
92
93         \par Fields:
94             \ref SNDUPacketParser
95             \image html SNDUPacket.png
96
97         \ingroup protocolbundle_mpegdvb
98      */
99     struct SNDUPacketType
100         : public PacketTypeBase
101 //          public PacketTypeMixin<SNDUPacketType, ULEExtHeaderTypes>
102     {
103 //        typedef PacketTypeMixin<SNDUPacketType, ULEExtHeaderType> mixin;
104         typedef ConcretePacket<SNDUPacketType> packet;
105         typedef SNDUPacketParser parser;
106
107 //        using mixin::nextPacketRange;
108 //        using mixin::nextPacketType;
109 //        using mixin::init;
110
111 //        static key_t nextPacketKey(packet p);
112
113         static void init(packet p);
114
115         static factory_t nextPacketType(packet p);
116
117         static optional_range nextPacketRange(packet p);
118
119         static void dump(packet p, std::ostream & os);
120
121         static PacketParserBase::size_type initSize();
122
123         static PacketParserBase::size_type initHeadSize();
124     };
125
126     typedef SNDUPacketType::packet SNDUPacket;
127
128     typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> ule_crc32;
129
130
131     /*!
132      \def ULE_END_INDICATOR
133          ULE End Indicator; indicates to the receiver that there are no
134          further SNDUs present within the current TS packet.
135     */
136 #   define ULE_END_INDICATOR 0xffff
137 }
138
139
140 //-/////////////////////////////////////////////////////////////////////////////////////////////////
141 //#include "SNDUPacket.cci"
142 //#include "SNDUPacket.ct"
143 //#include "SNDUPacket.cti"
144 #endif
145
146 \f
147 // Local Variables:
148 // mode: c++
149 // fill-column: 100
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // comment-column: 40
155 // End: