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