- updated MPESection creation
[senf.git] / 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 prefix_ boost::uint32_t senf::MPESectionParser::calcCrc()
40     const
41 {
42     return std::for_each(
43             data().begin(),
44             boost::prior(data().end(), 4),
45             crc32_t() ).checksum();
46 }
47
48
49 prefix_ void senf::MPESectionType::dump(packet p, std::ostream & os)
50 {
51     boost::io::ios_all_saver ias(os);
52     os << "MPE Section:\n"
53        << std::hex
54        << "  table_id: 0x" << unsigned(p->table_id()) << "\n"
55        << "  section_syntax_indicator: " << p->section_syntax_indicator() << "\n"
56        << "  private_indicator: " << p->private_indicator() << "\n"
57        << std::dec
58        << "  section_length: " << p->section_length() << "\n"
59        << std::hex 
60        << "  MAC_address_6: 0x" << unsigned(p->mac_addr_6()) << "\n"
61        << "  MAC_address_5: 0x" << unsigned(p->mac_addr_5()) << "\n"
62        << "  payload_scrambling_control: 0x" << p->payload_scrmbl_ctrl() << "\n"
63        << "  address_scrambling_control: 0x" << p-> addr_scrmbl_ctrl()  << "\n"
64        << "  LLC_SNAP_flag: 0x" << p->llc_snap_flag() << "\n"
65        << "  current_next_indicator: 0x" << p->curr_next_indicator() << "\n"
66        << "  section_number: 0x" << unsigned(p->section_num()) << "\n"
67        << "  last_section_number: 0x" << unsigned(p->last_section_num()) << "\n"
68        << "  real_time_parameters: \n"
69        << "    delta_t: 0x" << unsigned(p->real_time_parameters().delta_t()) << "\n"
70        << "    table_boundary: 0x" << unsigned(p->real_time_parameters().table_boundary()) << "\n"
71        << "    frame_boundary: 0x" << unsigned(p->real_time_parameters().frame_boundary()) << "\n"
72        << "    address: 0x" << unsigned(p->real_time_parameters().address()) << "\n"
73        << std::dec
74        << "  CRC: " << unsigned(p->crc()) << "\n";
75 }
76
77 prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initSize()
78 {
79     return parser::fixed_bytes + 32/8;
80 }
81
82 prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initHeadSize()
83 {
84     return parser::fixed_bytes;
85 }
86
87 prefix_ senf::PacketInterpreterBase::factory_t senf::MPESectionType::nextPacketType(packet p)
88 {
89     if (p.data().size() > initSize()+1) {
90         if (p->llc_snap_flag())
91             return LlcSnapPacket::factory();
92         if (p->ip_datagram_version().value() == 4)
93             return IPv4Packet::factory();
94         if (p->ip_datagram_version().value() == 6)
95             return IPv6Packet::factory();
96     }
97     return no_factory();
98 }
99
100 prefix_ void senf::MPESectionType::finalize(packet p)
101 {
102     p->llc_snap_flag() = p.next(nothrow) && p.next().is<LlcSnapPacket>() ? 1 : 0;
103     p->section_length() = p.data().size() - 3;
104     p->crc() = p->calcCrc();
105 }
106
107 ///////////////////////////////cc.e////////////////////////////////////////
108 #undef prefix_
109
110 \f
111 // Local Variables:
112 // mode: c++
113 // fill-column: 100
114 // c-file-style: "senf"
115 // indent-tabs-mode: nil
116 // ispell-local-dictionary: "american"
117 // compile-command: "scons -u test"
118 // comment-column: 40
119 // End: