Skip to content
Snippets Groups Projects
  • g0dil's avatar
    1ee23334
    Utils: Implement IpChecksum helper class · 1ee23334
    g0dil authored
    Packets: Implemnet generic assignment of boost::optional's to parsers
    Packets: Fix <n>_offset field definition in BOOST_PACKET_PARSER_DEFINE_FIELDS
    Packets: Implement PacketTypeMixin::key() helper
    Packets: Clarify documentation regiarding valid()/in-valid() packets
    Packets/DefaultBundle: Implement EthernetPacket, EthVLanPacket and IpV4Packet's finalize()
    1ee23334
    History
    Utils: Implement IpChecksum helper class
    g0dil authored
    Packets: Implemnet generic assignment of boost::optional's to parsers
    Packets: Fix <n>_offset field definition in BOOST_PACKET_PARSER_DEFINE_FIELDS
    Packets: Implement PacketTypeMixin::key() helper
    Packets: Clarify documentation regiarding valid()/in-valid() packets
    Packets/DefaultBundle: Implement EthernetPacket, EthVLanPacket and IpV4Packet's finalize()
PacketType.cti 4.34 KiB
// Copyright (C) 2007 
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
//     Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

/** \file
    \brief PacketType inline template implementation */

//#include "PacketType.ih"

// Custom includes
#include <boost/utility.hpp>
#include "PacketRegistry.hh"

#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
// senf::PacketTypeBase

template <class PacketType>
prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeBase::factory()
{
    return PacketInterpreter<PacketType>::factory();
}

///////////////////////////////////////////////////////////////////////////
// senf::PacketTypeMixin<Self,Registry>

template <class Self, class Registry>
prefix_ senf::PacketInterpreterBase::optional_range
senf::PacketTypeMixin<Self,Registry>::nextPacketRange(Packet p)
{
    // Call the member defined in the specialization below
    return PacketTypeMixin<Self>::nextPacketRange(p);
}

template <class Self, class Registry>
prefix_ senf::PacketInterpreterBase::factory_t
senf::PacketTypeMixin<Self,Registry>::nextPacketType(Packet p)
{
    if (p.data().size() < Self::initSize())
        return Self::no_factory();
    PkReg_Entry const * e (PacketRegistry<Registry>::lookup( 
                               Self::nextPacketKey(p.as< ConcretePacket<Self> >()), nothrow));
    return e ? e->factory() : PacketTypeBase::no_factory();
}

template <class Self, class Registry>
prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,Registry>::initSize()
{
    return senf::init_bytes< typename Self::parser >::value;
}

template <class Self, class Registry>
prefix_ void senf::PacketTypeMixin<Self,Registry>::init(Packet p)
{
    p.as< ConcretePacket<Self> >()->init();
}

template <class Self, class Registry>
prefix_ typename senf::PacketTypeMixin<Self,Registry>::optional_registry_key_t
senf::PacketTypeMixin<Self,Registry>::key(Packet p)
{
    return p ? PacketRegistry<Registry>::key(p, nothrow) : optional_registry_key_t();
}

///////////////////////////////////////////////////////////////////////////
// senf::PacketTypeMixin<Self,void>

template <class Self>
prefix_ senf::PacketInterpreterBase::optional_range
senf::PacketTypeMixin<Self,void>::nextPacketRange(Packet p)
{
    if (p.data().size() < Self::initSize())
        return PacketTypeBase::no_range();
    typename Self::size_type sz (Self::initHeadSize());
    ///\idea This if condition could be replaced with a compile time switch by checking, wether
    /// (the function address) Self::initHeadSize is different from PacketTypeBase::initHeadSize
    if (sz == PacketTypeBase::size_type(-1))
        return PacketTypeBase::range(boost::next(p.data().begin(),Self::initSize()),
                                     p.data().end());
    else
        return PacketTypeBase::range(boost::next(p.data().begin(),sz),
                                     boost::prior(p.data().end(),Self::initSize()-sz));
}

template <class Self>
prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,void>::initSize()
{
    return senf::init_bytes< typename Self::parser >::value;
}

template <class Self>
prefix_ void senf::PacketTypeMixin<Self,void>::init(Packet p)
{
    p.as< ConcretePacket<Self> >()->init();
}

///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_


// Local Variables:
// mode: c++
// fill-column: 100
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// comment-column: 40
// End: