switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / MPEGDVBBundle / SNDUPacket.cc
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 DSMCCSection non-inline non-template implementation */
30
31 #include "SNDUPacket.hh"
32 //#include "SNDUPacket.ih"
33
34 // Custom includes
35 #include <iomanip>
36
37 #define prefix_
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 prefix_ boost::uint32_t senf::SNDUPacketParser::calcCrc()
41     const
42 {
43     return std::for_each(
44             data().begin(),
45             boost::prior(data().end(), 4),
46             ule_crc32() ).checksum();
47 }
48
49 //prefix_ senf::SNDUPacketType::key_t senf::SNDUPacketType::nextPacketKey(packet p)
50 //{
51 //    return p->type();
52 //}
53
54 prefix_ void senf::SNDUPacketType::init(packet p)
55 {
56     p->init();
57 }
58
59 prefix_ senf::PacketInterpreterBase::factory_t senf::SNDUPacketType::nextPacketType(packet p)
60 {
61     if (p.data().size() < 8)
62         return no_factory();
63     PacketInterpreterBase::factory_t f (no_factory());
64     if (p->type() < 1536) {
65         PacketRegistry<senf::ULEExtHeaderTypes>::Entry const * e (
66             PacketRegistry<senf::ULEExtHeaderTypes>::lookup( p->type(), nothrow ));
67         if (e) f = e->factory();
68     }
69     else {
70         PacketRegistry<senf::EtherTypes>::Entry const * e (
71             PacketRegistry<senf::ULEExtHeaderTypes>::lookup( p->type(), nothrow ));
72         if (e) f = e->factory();
73     }
74     return f;
75 }
76
77 prefix_ senf::PacketInterpreterBase::optional_range
78 senf::SNDUPacketType::nextPacketRange(packet p)
79 {
80     if (p.data().size() < 8)
81         return no_range();
82
83     size_type sz = 2 + 2;  // D-Bit + 15 bits length + 16 bits type field
84     if (! p->d_bit() )
85         sz += 6;  // + 6 Byte NPA destination address
86     return range(
87             boost::next(p.data().begin(), sz),
88             boost::prior(p.data().end(), 4));  // - 32 bits crc
89 }
90
91 prefix_ void senf::SNDUPacketType::dump(packet p, std::ostream & os)
92 {
93     os << "SNDUPacket:\n"
94        << std::dec
95        << senf::fieldName("d_bit")  << p->d_bit() << "\n"
96        << senf::fieldName("length") << unsigned(p->length()) << "\n"
97        << std::hex
98        << senf::fieldName("type")   << "0x" << unsigned(p->type()) << "\n"
99        << std::dec
100        << senf::fieldName("crc")    << unsigned(p->crc()) << "\n";
101 }
102
103 prefix_ senf::PacketParserBase::size_type senf::SNDUPacketType::initSize()
104 {
105     return 2 + 2 + 4;  // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
106 }
107
108 prefix_ senf::PacketParserBase::size_type senf::SNDUPacketType::initHeadSize()
109 {
110     return 2 + 2;  // D-Bit + 15 bits length + 16 bits type field
111 }
112
113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
114 #undef prefix_
115
116 \f
117 // Local Variables:
118 // mode: c++
119 // fill-column: 100
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"
124 // comment-column: 40
125 // End: