Packets/80221Bundle: more GenericTLVBase integration; removed GenericTLVPacket; some...
[senf.git] / senf / Packets / 80221Bundle / MIHPacket.cc
index 748bec4..409f9b8 100644 (file)
@@ -27,7 +27,6 @@
 //#include "MIHPacket.ih"
 
 // Custom includes
-#include <senf/Packets/Packets.hh>
 #include <senf/Utils/hexdump.hh>
 #include <boost/io/ios_state.hpp>
 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
@@ -36,7 +35,7 @@
 ///////////////////////////////cc.p////////////////////////////////////////
 
 namespace {
-    SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, 0x86dd, senf::MIHPacket);
+    SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, 0x8917, senf::MIHPacket);
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -105,29 +104,29 @@ prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
 {
     boost::io::ios_all_saver ias(os);
     os << "MIH Packet:\n"
-       <<     "  protocol header:\n"
-       <<     "    version               : " << unsigned( p->version()) << "\n"
-       <<     "    ack request           : " << p->ackRequest() << "\n"
-       <<     "    ack response          : " << p->ackResponse() << "\n"
-       <<     "    UIR                   : " << p->uir() << "\n"
-       <<     "    more fragments        : " << p->moreFragment() << "\n"
-       <<     "    fragment number       : " << p->fragmentNr() << "\n"
-       <<     "    message ID (MID)      : " << unsigned( p->messageId()) << "\n"
-       <<     "      sid                 : " << unsigned( p->sid()) << "\n"        
-       <<     "      opcode              : " << unsigned( p->opcode()) << "\n"
-       <<     "      aid                 : " << unsigned( p->aid()) << "\n"      
-       <<     "    transaction id        : " << unsigned( p->transactionId()) << "\n"
-       <<     "    payload length        : " << unsigned( p->payloadLength()) << "\n"
-       <<     "  source MIHF_Id TLV      :\n"
-       <<     "    type                  : " << unsigned (p->src_mihfId().type()) << "\n"
-       <<     "    length                : " << unsigned (p->src_mihfId().length()) << "\n"
-       <<     "    value                 :\n";
+       << "  protocol header:\n"
+       << senf::fieldName("  version")                 << unsigned( p->version()) << "\n"
+       << senf::fieldName("  ack request")             << p->ackRequest() << "\n"
+       << senf::fieldName("  ack response")            << p->ackResponse() << "\n"
+       << senf::fieldName("  UIR")                     << p->uir() << "\n"
+       << senf::fieldName("  more fragments")          << p->moreFragment() << "\n"
+       << senf::fieldName("  fragment number")         << p->fragmentNr() << "\n"
+       << senf::fieldName("  message ID (MID)")        << unsigned( p->messageId()) << "\n"
+       << senf::fieldName("    sid")                   << unsigned( p->sid()) << "\n"        
+       << senf::fieldName("    opcode")                << unsigned( p->opcode()) << "\n"
+       << senf::fieldName("    aid")                   << unsigned( p->aid()) << "\n"      
+       << senf::fieldName("  transaction id")          << unsigned( p->transactionId()) << "\n"
+       << senf::fieldName("  payload length")          << unsigned( p->payloadLength()) << "\n"
+       << "  source MIHF_Id TLV:\n"
+       << senf::fieldName("  type")                    << unsigned (p->src_mihfId().type()) << "\n"
+       << senf::fieldName("  length")                  << unsigned (p->src_mihfId().length()) << "\n"
+       << "    value:\n";
     std::string src_mihfId (p->src_mihfId().asString());
     hexdump(src_mihfId.begin(), src_mihfId.end(), os);
-    os <<     "  destination MIHF_Id TLV:\n"
-       <<     "    type                  : " << unsigned (p->dst_mihfId().type()) << "\n"
-       <<     "    length                : " << unsigned (p->dst_mihfId().length()) << "\n"
-       <<     "    value                 :\n";
+    os << "  destination MIHF_Id TLV:\n"
+       << senf::fieldName("  type")                    << unsigned (p->dst_mihfId().type()) << "\n"
+       << senf::fieldName("  length")                  << unsigned (p->dst_mihfId().length()) << "\n"
+       << "    value:\n";
     std::string dst_mihfId (p->dst_mihfId().asString());
     hexdump(dst_mihfId.begin(), dst_mihfId.end(), os);
 }
@@ -145,16 +144,28 @@ prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketTy
     if (p.data().size() < initSize())
         return no_factory();
     PkReg_Entry const * e (PacketRegistry<MIHMessageRegistry>::lookup( p->messageId(), nothrow ));
-    return e ? e->factory() : MIHPayloadPacket::factory();
+    return e ? e->factory() : MIHGenericPayloadPacket::factory();
 }
 
-prefix_ void senf::MIHPayloadPacketType::dump(packet p, std::ostream &os)
+///////////////////////////////////////////////////////////////////////////
+// MIHGenericPayloadPacketType
+
+prefix_ void senf::MIHGenericPayloadPacketType::dump(packet p, std::ostream &os)
 {
     boost::io::ios_all_saver ias(os);
     os << "MIH Payload (service specific TLVs):\n"
        << "  ToDo!\n";
 }
 
+prefix_ void senf::MIHGenericPayloadPacketType::finalize(packet p)
+{
+    typedef parser::tlv_list_t::container tlvContainer_t;
+    tlvContainer_t tlvs (p->tlv_list() );
+    for (tlvContainer_t::iterator i (tlvs.begin()); i != tlvs.end(); ++i)
+        i->finalizeLength();
+}
+
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_