Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PacketType.ct

Go to the documentation of this file.
00001 // $Id: PacketType.ct 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 //#include "PacketType.ih"
00027 
00028 // Custom includes
00029 
00030 #define prefix_
00031 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00032 
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 // senf::PacketTypeMixin<Self,void>
00035 
00036 template <class Self>
00037 prefix_ senf::PacketInterpreterBase::optional_range
00038 senf::PacketTypeMixin<Self,void>::nextPacketRange(ConcretePacket<Self> const & p)
00039 {
00040     typename Self::size_type sz (Self::initHeadSize());
00043     if (sz == PacketTypeBase::size_type(-1)) {
00044         typename Self::size_type headsz (bytes(p.parser()));
00045         return p.data().size() < headsz ?
00046             PacketTypeBase::no_range() :
00047             PacketInterpreterBase::optional_range(
00048                 PacketTypeBase::range(boost::next(p.data().begin(), headsz),
00049                                       p.data().end()));
00050     }
00051     else
00052         // If we have a trailer, we do *not* use the 'bytes' value but initSize/initHeadSize, this
00053         // is much safer since the bytes() value will probably not be very correct anyways (what
00054         // should it return ? the size of the header only, the combined size of header and trailer
00055         // or the size of the packet from header to trailer including payload?).
00056         //
00057         // So, the helper only works with fixed-size parsers if the packet has a trailer.
00058         return p.data().size() < Self::initSize() ?
00059             PacketTypeBase::no_range() :
00060             PacketInterpreterBase::optional_range(
00061                 PacketTypeBase::range(boost::next(p.data().begin(),sz),
00062                                       boost::prior(p.data().end(),Self::initSize()-sz)));
00063 }
00064 
00065 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00066 #undef prefix_
00067 
00068 
00069 // Local Variables:
00070 // mode: c++
00071 // fill-column: 100
00072 // comment-column: 40
00073 // c-file-style: "senf"
00074 // indent-tabs-mode: nil
00075 // ispell-local-dictionary: "american"
00076 // compile-command: "scons -u test"
00077 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research