//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-// 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.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+// http://senf.berlios.de/license.html
//
-// 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.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on,
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
//
-// 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.
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+// Stefan Bund <g0dil@berlios.de>
/** \file
\brief PacketType public header */
#include "Packet.hh"
//#include "PacketType.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
namespace senf {
{
typedef senf::ConcretePacket<SomePacketType> packet;
typedef SomePacketParser parser;
-
+
static size_type initSize()
{
// This value can in most cases be taken from the parser
struct PacketTypeBase
{
typedef Packet packet;
-
+
typedef senf::detail::packet::iterator iterator;
typedef senf::detail::packet::const_iterator const_iterator;
typedef senf::detail::packet::size_type size_type;
typedef VoidPacketParser parser;
///< Parser to parser packet fields
/**< This typedef has to be set to the parser of the packet
-
+
The default is a VoidPacketParser which does not parse
any field. */
/**< This function gives the index within a newly created,
empty packet where a sub-packet is to be placed.
- The default implementation returns initSize().
-
+ The default implementation returns initSize().
+
\implementation Ok, it does not really return
initSize(), it returns size_type(-1) which is
interpreted to mean initSize(). It can't return
The default implementation does nothing. */
-
+
static optional_range nextPacketRange(packet p);
///< Get next packet placement
/**< nextPacketRange returns the iterator range where the
next packet (header) is placed within the current
packet.
-
+
The default implementation always returns
<tt>no_range()</tt>.
///< Get type of next packet
/**< nextPacketType retrieves the type of the next packet
returning a factory to create that packet.
-
+
The default implementation always returns
<tt>no_factory()</tt>.
/**< finalize() will be called to complete a packet after it
has been modified. This function must calculate any
checksums, set size fields from the interpreter chain
- etc.
-
+ etc.
+
The default implementation does nothing. */
static void dump(packet p, std::ostream & os);
/** \brief Mixin to provide standard implementations for nextPacketRange and nextPacketType
This mixin class simplifies the definition of simple packets:
-
+
\li The packets consist of three sections: The header, the payload and an optional trailer.
\li If the packet has a trailer, both the header and the trailer must have a fixed size.
This mixin provides the nextPacketRange() member as well as initSize() and init(). If you
additionally provide the optional \a Registry argument, PacketTypeMixin provides a simple
- implementation of nextPacketType().
+ implementation of nextPacketType().
When using the PacketTypeMixin, the implementation of a packet is simplified to:
\code
// Here 'SomeRegistryTag' is optional
- struct SimplePacketType
+ struct SimplePacketType
: public senf::PacketTypeBase,
public senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag>
{
typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin;
typedef senf::ConcretePacket<SimplePacketType> packet;
typedef SomePacketParser parser;
-
+
using mixin::nextPacketRange;
using mixin::nextPacketType; // Only if the optional 'Registry' argument is provided
using mixin::initSize;
static void finalize(packet p)
{
- // Set the type field by querying the type of the next packet. This is an
+ // Set the type field by querying the type of the next packet. This is an
// optional assignment: If the key is not found, the value returned by 'key'
// is an empty optional and the assignment will be skipped.
p->typeField << key(p.next(senf::nothrow));
Most of the members are optional, which reduces the minimal implementation of a packet to:
\code
- struct SimplePacketType
+ struct SimplePacketType
: public senf::PacketTypeBase,
public senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag>
{
typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin;
typedef senf::ConcretePacket<SimplePacketType> packet;
typedef SomePacketParser parser;
-
+
using mixin::nextPacketRange;
- using mixin::nextPacketType;
+ using mixin::nextPacketType;
using mixin::initSize;
using mixin::init;
next packet from information stored in the current
packets header, the key() member will look up the type
of packet \a p in the registry and return it's
- key.
-
+ key.
+
If either \a p is an in - valid() packet or the packet
type is not found in the registry, the returned
optional value will be empty. */
no_factory() will be returned. */
///\name PacketType interface implementation
- ///@{
+ //\{
- static PacketInterpreterBase::optional_range nextPacketRange (Packet const & p);
- static PacketInterpreterBase::factory_t nextPacketType (Packet const & p);
+ static PacketInterpreterBase::optional_range nextPacketRange (ConcretePacket<Self> const & p);
+ static PacketInterpreterBase::factory_t nextPacketType (ConcretePacket<Self> const & p);
static PacketInterpreterBase::size_type initSize ();
- static void init (Packet const & p);
-
- ///@}
+ static void init (ConcretePacket<Self> const & p);
+
+ //\}
};
# ifndef DOXYGEN
class PacketTypeMixin<Self,void>
{
public:
- static PacketInterpreterBase::optional_range nextPacketRange (Packet const & p);
+ static PacketInterpreterBase::optional_range nextPacketRange (ConcretePacket<Self> const & p);
static PacketInterpreterBase::size_type initSize ();
- static void init (Packet const & p);
+ static void init (ConcretePacket<Self> const & p);
};
# endif
}
-///////////////////////////////hh.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
#endif
#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketType_i_)
#define HH_SENF_Packets_PacketType_i_