Fix SCons 1.2.0 build failure
[senf.git] / senf / Packets / MPEGDVBBundle / MPESection.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 MPESection non-inline non-template implementation */
25
26 #include "MPESection.hh"
27 //#include "MPESection.ih"
28
29 // Custom includes
30 #include <iomanip>
31 #include <boost/io/ios_state.hpp>
32 #include "../../Packets/DefaultBundle/LlcSnapPacket.hh"
33 #include "../../Packets/DefaultBundle/IPv4Packet.hh"
34 #include "../../Packets/DefaultBundle/IPv6Packet.hh"
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39
40 prefix_ boost::uint32_t senf::MPESectionParser::calcCrc()
41     const
42 {
43     return std::for_each(
44             data().begin(),
45             boost::prior(data().end(), 4),
46             crc32_t() ).checksum();
47 }
48
49
50 prefix_ void senf::MPESectionType::dump(packet p, std::ostream & os)
51 {
52     boost::io::ios_all_saver ias(os);
53     os << "MPE Section:\n"
54        << std::hex
55        <<     "  table_id                : 0x" << unsigned(p->table_id()) << "\n"
56        <<     "  section syntax indicator: " << p->section_syntax_indicator() << "\n"
57        <<     "  private indicator       : " << p->private_indicator() << "\n"
58        << std::dec
59        <<     "  section length          : " << p->section_length() << "\n"
60        << std::hex
61        <<     "  MAC address 6           : 0x" << unsigned(p->mac_addr_6()) << "\n"
62        <<     "  MAC address 5           : 0x" << unsigned(p->mac_addr_5()) << "\n"
63        <<     "  payload scrambling ctrl : 0x" << p->payload_scrmbl_ctrl() << "\n"
64        <<     "  address scrambling ctrl : 0x" << p-> addr_scrmbl_ctrl()  << "\n"
65        <<     "  LLC/SNAP flag           : 0x" << p->llc_snap_flag() << "\n"
66        <<     "  current next indicator  : 0x" << p->curr_next_indicator() << "\n"
67        <<     "  section number          : 0x" << unsigned(p->section_num()) << "\n"
68        <<     "  last section number     : 0x" << unsigned(p->last_section_num()) << "\n"
69        <<     "  real time parameters    : \n"
70        <<     "    delta_t               : 0x" << unsigned(p->real_time_parameters().delta_t()) << "\n"
71        <<     "    table boundary        : 0x" << unsigned(p->real_time_parameters().table_boundary()) << "\n"
72        <<     "    frame boundary        : 0x" << unsigned(p->real_time_parameters().frame_boundary()) << "\n"
73        <<     "    address               : 0x" << unsigned(p->real_time_parameters().address()) << "\n"
74        << std::dec
75        <<     "  crc                     : " << unsigned(p->crc()) << "\n";
76 }
77
78 prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initSize()
79 {
80     return parser::fixed_bytes + 32/8;
81 }
82
83 prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initHeadSize()
84 {
85     return parser::fixed_bytes;
86 }
87
88 prefix_ senf::PacketInterpreterBase::factory_t senf::MPESectionType::nextPacketType(packet p)
89 {
90     if (p.data().size() > initSize()+1) {
91         if (p->llc_snap_flag())
92             return LlcSnapPacket::factory();
93         if (p->ip_datagram_version().value() == 4)
94             return IPv4Packet::factory();
95         if (p->ip_datagram_version().value() == 6)
96             return IPv6Packet::factory();
97     }
98     return no_factory();
99 }
100
101 prefix_ void senf::MPESectionType::finalize(packet p)
102 {
103     p->llc_snap_flag() = p.next(nothrow) && p.next().is<LlcSnapPacket>() ? 1 : 0;
104     p->section_length() = p.data().size() - 3;
105     p->crc() = p->calcCrc();
106 }
107
108 ///////////////////////////////cc.e////////////////////////////////////////
109 #undef prefix_
110
111
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: