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