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 PRESENDINGCHAIN_H 00024 #define PRESENDINGCHAIN_H 00025 00026 #include <vector> 00027 #include <set> 00028 00029 #include "plugin.h" 00030 #include "../common/queue.h" 00031 00032 template<class PacketType> 00033 class PacketChainStep; 00034 class ServerFramework; 00035 00036 /** 00037 * @ingroup Common 00038 * @brief This is a chain of plugins(PacketChainStep) ending with the outbound queue. 00039 * @author Lars Langer and Emanuel Greisen 00040 */ 00041 template<class PacketType> 00042 class PreSendingChain 00043 { 00044 private: 00045 typedef typename std::vector<Plugin<PacketType> *>::const_reverse_iterator PluginVecIt; 00046 00047 private: 00048 PacketChainStep<PacketType> * first_station; 00049 PacketChainStep<PacketType> * end_station; 00050 00051 public: 00052 PreSendingChain(const std::vector<Plugin<PacketType> *> & stations, Queue<PacketType> *outqueue); 00053 //PreSendingChain(const PluginVec & stations, Queue<PacketType> *outqueue); 00054 ~PreSendingChain(); 00055 void pack(PacketType * packet); 00056 void unpack(PacketType * packet); 00057 void purge(); 00058 00059 public: 00060 void appendUniqueIds(std::set<unsigned int> & pluginids); 00061 }; 00062 00063 00064 template<class PacketType> 00065 PreSendingChain<PacketType>::PreSendingChain(const std::vector<Plugin<PacketType> *> & stations, Queue<PacketType> * outqueue) 00066 : end_station(outqueue),first_station(outqueue) 00067 { 00068 for(PluginVecIt it = stations.rbegin(); it != stations.rend(); ++it) 00069 { 00070 (*it)->setNext(first_station); 00071 first_station = *it; 00072 } 00073 } 00074 00075 template<class PacketType> 00076 PreSendingChain<PacketType>::~PreSendingChain() 00077 { 00078 } 00079 00080 template<class PacketType> 00081 void PreSendingChain<PacketType>::appendUniqueIds( std::set< unsigned int > & pluginids ) 00082 { 00083 PacketChainStep<PacketType> * tmp_station = first_station; 00084 00085 while(tmp_station != end_station) 00086 { 00087 pluginids.insert(dynamic_cast<Plugin<PacketType> *>(tmp_station)->getUniqueId()); 00088 tmp_station = tmp_station->getNext(); 00089 } 00090 } 00091 00092 template<class PacketType> 00093 void PreSendingChain<PacketType>::pack( PacketType * packet ) 00094 { 00095 if(!first_station) 00096 std::cout << "CRAPPPPPP, the first station does not exist:"<<first_station<<std::endl; 00097 first_station->pack(packet); 00098 } 00099 00100 template<class PacketType> 00101 void PreSendingChain<PacketType>::unpack( PacketType * packet ) 00102 { 00103 first_station->unpack(packet); 00104 } 00105 00106 template<class PacketType> 00107 void PreSendingChain<PacketType>::purge( ) 00108 { 00109 first_station->purge(); 00110 } 00111 00112 00113 00114 00115 00116 #endif