00001 // 00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 00024 #ifndef __GIATOKENFACTORY_H_ 00025 #define __GIATOKENFACTORY_H_ 00026 00027 00028 #include <vector> 00029 #include <queue> 00030 00031 #include <omnetpp.h> 00032 00033 #include <InitStages.h> 00034 00035 class Gia; 00036 #include "GiaNeighbors.h" 00037 00038 00045 class GiaTokenFactory : public cSimpleModule 00046 { 00047 public: 00048 // OMNeT++ methodes 00052 virtual int numInitStages() const 00053 { 00054 return MAX_STAGE_OVERLAY + 1; 00055 } 00056 00061 virtual void initialize( int stage ); 00062 00067 virtual void handleMessages( cMessage* msg ); 00068 00069 // class methodes 00074 virtual void setNeighbors( GiaNeighbors* neighbors ); 00075 00080 void setMaxHopCount( uint32_t maxHopCount); 00081 00085 virtual void grantToken(); 00086 00087 protected: 00088 00089 Gia* gia; 00090 00091 // sort rules for priority queue 00092 class tokenCompareGiaNode : public std::binary_function<FullGiaNodeInfo, FullGiaNodeInfo, FullGiaNodeInfo> 00093 { 00094 public: 00095 bool operator()(const FullGiaNodeInfo& x, const FullGiaNodeInfo& y); 00096 }; 00097 00098 typedef std::priority_queue<FullGiaNodeInfo, std::vector<FullGiaNodeInfo>, tokenCompareGiaNode> TokenQueue; 00099 TokenQueue tokenQueue; 00100 GiaNeighbors* neighbors; 00101 std::vector<GiaNode> tokenQueueVector; 00102 uint32_t maxHopCount; 00104 // statistics 00105 uint32_t stat_sentTokens; 00110 void createPriorityQueue(); 00111 00115 void clearTokenQueue(); 00116 00120 void updateQueueVector(); 00121 00125 void updateSentTokens(); 00126 00130 void sendToken(); 00131 }; 00132 00133 #endif