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 PLUGIN_H 00024 #define PLUGIN_H 00025 00026 #include <string> 00027 #include <ptypes.h> 00028 00029 #include "../common/packetchainstep.h" 00030 00031 template<class PacketType> 00032 class PreSendingChain; 00033 00034 /** 00035 * @ingroup Common 00036 * @brief This interface is for plugins. It is assumed that plugins have both a "pack(p)" and an "unpack(p)". 00037 * @author Lars Langer and Emanuel Greisen 00038 */ 00039 template<class PacketType> 00040 class Plugin : public PacketChainStep<PacketType> 00041 { 00042 friend class PreSendingChain<PacketType>; 00043 00044 public: 00045 Plugin(); 00046 virtual ~Plugin(); 00047 00048 protected: 00049 /// This method will send the packet along the chain of plugins when packing. 00050 void forwardPack(PacketType * packet); 00051 /// This method will send the packet along the chain of plugins when unpacking. 00052 void forwardUnpack(PacketType * packet); 00053 00054 public: 00055 /// This method must return a unique number identifying the plugin. 00056 virtual const unsigned int getUniqueId() const = 0; 00057 /// Will be called when ever a packet must be packed, Remember to call forwardPack(packet) with your resulting packet. 00058 virtual void pack(PacketType * packet) = 0; 00059 /// Will be called when ever a packet must be unpacked, Remember to call forwardUnpack(packet) with your resulting packet. 00060 virtual void unpack(PacketType * packet) = 0; 00061 }; 00062 00063 00064 template<class PacketType> 00065 Plugin<PacketType>::Plugin() : PacketChainStep<PacketType>() 00066 { 00067 } 00068 00069 template<class PacketType> 00070 Plugin<PacketType>::~Plugin() 00071 { 00072 } 00073 00074 template<class PacketType> 00075 void Plugin<PacketType>::forwardPack( PacketType * packet ) 00076 { 00077 this->getNext()->pack(packet); 00078 } 00079 00080 template<class PacketType> 00081 void Plugin<PacketType>::forwardUnpack( PacketType * packet ) 00082 { 00083 this->getNext()->unpack(packet); 00084 } 00085 00086 #endif