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 #include "GlobalCoordinator.h" 00025 00026 Define_Module(GlobalCoordinator); 00027 00028 void GlobalCoordinator::initialize() 00029 { 00030 PositionSize = 0; 00031 PeerCount = 0; 00032 Position = NULL; 00033 Seed = par("seed"); 00034 00035 WATCH(PositionSize); 00036 } 00037 00038 GlobalCoordinator::~GlobalCoordinator() 00039 { 00040 delete[] this->Position; 00041 } 00042 00043 void GlobalCoordinator::handleMessage(cMessage* msg) 00044 { 00045 error("this module doesn't handle messages, it runs only in initialize()"); 00046 } 00047 00048 void GlobalCoordinator::increasePositionSize() 00049 { 00050 Enter_Method_Silent(); 00051 PositionSize++; 00052 Vector2D *Temp = new Vector2D[PositionSize]; 00053 for(int i=0; i<PositionSize-1; i++) 00054 Temp[i] = this->Position[i]; 00055 00056 delete[] this->Position; 00057 this->Position = Temp; 00058 } 00059 00060 void GlobalCoordinator::increasePeerCount() 00061 { 00062 Enter_Method_Silent(); 00063 PeerCount++; 00064 } 00065 00066 int GlobalCoordinator::getPeerCount() 00067 { 00068 Enter_Method_Silent(); 00069 return PeerCount; 00070 } 00071 00072 Vector2D& GlobalCoordinator::getPosition(int k) 00073 { 00074 Enter_Method_Silent(); 00075 if(k >= PositionSize || k < 0) { 00076 throw cRuntimeError("Array out of bounds exception! getPosition(%d)", k); 00077 } 00078 return Position[k]; 00079 } 00080 00081 void GlobalCoordinator::setPosition(int k, const Vector2D& Position) 00082 { 00083 Enter_Method_Silent(); 00084 if(k >= PositionSize || k < 0) { 00085 throw cRuntimeError("Array out of bounds exception! setPosition(%d, ...)", k); 00086 } 00087 this->Position[k] = Position; 00088 } 00089 00090 unsigned int GlobalCoordinator::getSeed() 00091 { 00092 return Seed; 00093 }