Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

packetchainstep.h

00001 /***************************************************************************
00002  * The contents of this file are subject to the Mozilla Public             *
00003  * License Version 1.1 (the "License"); you may not use this file          *
00004  * except in compliance with the License. You may obtain a copy of         *
00005  * the License at http://www.mozilla.org/MPL/                              *
00006  *                                                                         *
00007  * Software distributed under the License is distributed on an "AS         *
00008  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or              *
00009  * implied. See the License for the specific language governing            *
00010  * rights and limitations under the License.                               *
00011  *                                                                         *
00012  * The Original Code is Game Network Framework (GaNeF).                    *
00013  *                                                                         *
00014  * The Initial Developers of the Original Code are                         *
00015  * Lars Langer and Emanuel Greisen                                         *
00016  * Copyright (C) 2005. Lars Langer & Emanuel Greisen                       *
00017  * All Rights Reserved.                                                    *
00018  *                                                                         *
00019  * Contributor(s):                                                         *
00020  *   none yet....                                                          *
00021  *                                                                         *
00022  ***************************************************************************/
00023 #ifndef PACKETCHAINSTEP_H
00024 #define PACKETCHAINSTEP_H
00025 
00026 /**
00027  * @ingroup Common
00028  * @brief This is the interface that a step in a PacketChain must implement.
00029  * All plugins implement this method, as do the queues.
00030  *
00031  * @author Lars Langer and Emanuel Greisen
00032 */
00033 template<class PacketType>
00034 class PacketChainStep
00035 {
00036 protected:
00037    PacketChainStep<PacketType> * next;
00038 
00039 public:
00040    inline void setNext(PacketChainStep<PacketType> * n){ next = n; };
00041 
00042 public:
00043    PacketChainStep();
00044 
00045 public:
00046    /// This method will be called when a packet is packed by the packet-chain.
00047    virtual void pack(PacketType * packet) = 0;
00048    /// This method will be called when a packet is unpacked.
00049    virtual void unpack(PacketType * packet) = 0;
00050    /// This method returns the next step in the chain.
00051    PacketChainStep<PacketType> * getNext() const;
00052    /// This method will call the onPurge() method recursively on all steps in a chain.
00053    void purge();
00054    /// This method will be called when ever the "purge(...)" method is called.
00055    virtual void onPurge() { /* Do nothing as default */ };
00056 };
00057 
00058 template<class PacketType>
00059 PacketChainStep<PacketType>::PacketChainStep( )
00060    : next(0)
00061 {
00062 }
00063 
00064 template<class PacketType>
00065 PacketChainStep<PacketType> * PacketChainStep<PacketType>::getNext( ) const
00066 {
00067    return next;
00068 }
00069 
00070 template<class PacketType>
00071 void PacketChainStep<PacketType>::purge( )
00072 {
00073    onPurge();
00074    if(getNext())
00075       getNext()->purge();
00076 }
00077 
00078 #endif

Generated on Mon Feb 6 12:24:50 2006 for Ganef by  doxygen 1.4.4