PlayerTable Class Reference

#include <PlayerTable.h>

List of all members.

Public Member Functions

virtual int numInitStages () const
virtual void initialize (int stage)
virtual void finish ()
virtual void handleMessage (cMessage *msg)
 ~PlayerTable ()
int add (int id, IPAddress ip, int Bandwith, int Cpu)
bool remove (int id)
void remove (IPAddress ip)
int getSize ()
PlayerNode getHeadAndModify (int subSpaceId, IPAddress ip, int diff)
PlayerNodefindPlayerNodeByIp (IPAddress playerIp)
void modify (int subSpaceId, IPAddress playerIp, int nodeType)

Public Attributes

std::list< PlayerNodeplayerTable
std::list< PlayerNode >::iterator b
int player_autoincrement_id
std::list< PlayerNode * > nodeQueue
std::list< PlayerNode
* >::iterator 
n
SubSpaceTablesubSpaceTable


Constructor & Destructor Documentation

PlayerTable::~PlayerTable (  ) 

00035                           {
00036         this->finish();
00037 }


Member Function Documentation

virtual int PlayerTable::numInitStages ( void   )  const [inline, virtual]

00030 {return 6;}

void PlayerTable::initialize ( int  stage  )  [virtual]

00025 {
00026         // Wait for IPAdressResolver
00027         if ( stage != 5 ) return;
00028         // 
00029         subSpaceTable = check_and_cast<SubSpaceTable*>(simulation.moduleByPath("globalObserver.globalFunctions[0]"));
00030 
00031         player_autoincrement_id = 0;
00032         WATCH_LIST(playerTable);
00033         //WATCH_PTRLIST(nodeQueue);
00034 }

void PlayerTable::finish (  )  [virtual]

00045 {
00046         //no statistics yet
00047         //cleanup
00048         nodeQueue.clear();
00049         playerTable.clear();
00050 }

void PlayerTable::handleMessage ( cMessage *  msg  )  [virtual]

00040 {
00041         error("this module doesn't handle messages");
00042 }

int PlayerTable::add ( int  id,
IPAddress  ip,
int  Bandwith,
int  Cpu 
)

00052                                                                 {
00053         if( id == 0 ) {
00054                 id = ++player_autoincrement_id;
00055         } 
00056         playerTable.push_back(PlayerNode(id, ip, Bandwith, Cpu));
00057         if( Bandwith >= 100 && nodeQueue.size() < (20 + playerTable.size() / 5)) {
00058                 nodeQueue.push_front( &playerTable.back() );
00059         }
00060         return id;
00061 }

bool PlayerTable::remove ( int  id  ) 

00063                                {
00064         // Delete from PlayerList
00065         for(n=nodeQueue.begin(); n != nodeQueue.end(); ++n) {   
00066                 if ( (*n)->getId() == id ) {
00067                         nodeQueue.erase(n);
00068                 }
00069         }
00070         for(b=playerTable.begin(); b != playerTable.end(); ++b) {       
00071                 if ( b->getId() == id ) {
00072                         playerTable.erase(b);
00073                         return true;
00074                 }
00075         }
00076         return false;
00077 }

void PlayerTable::remove ( IPAddress  ip  ) 

00078                                      {
00079         // Delete from PlayerList
00080         for(n=nodeQueue.begin(); n != nodeQueue.end(); ++n) {   
00081                 if ( (*n)->getIp() == ip ) {
00082                         nodeQueue.erase(n);
00083                         break;
00084                 }
00085         }
00086         for(b=playerTable.begin(); b != playerTable.end(); ++b) {       
00087                 if ( b->getIp() == ip ) {
00088                         playerTable.erase(b);
00089                         return;
00090                 }
00091         }
00092         return;
00093 }

int PlayerTable::getSize (  ) 

00094                          {
00095         return playerTable.size();
00096 }

PlayerNode PlayerTable::getHeadAndModify ( int  subSpaceId,
IPAddress  ip,
int  diff 
)

00097                                                                                {
00098         PlayerNode tmp = PlayerNode((IPAddress) "127.0.0.1");
00099         for(n=nodeQueue.begin(); n != nodeQueue.end(); ++n) {
00100                 if( ( ! subSpaceTable->isInNodeList(subSpaceId, (*n)->getIp() ) ) && ip != (*n)->getIp() ) {
00101                                 subSpaceTable->addNode(subSpaceId, (*n)->getIp() );
00102                                 PlayerNode* tmp = *n;
00103                                 tmp->modifyBandwith(diff);
00104                                 nodeQueue.erase(n);
00105                                 if(tmp->getBandwith() > 100 && nodeQueue.size() < (10 + ( playerTable.size() / 5 )) ) {
00106                                         nodeQueue.push_back(tmp);
00107                                 }
00108                                 return *tmp;
00109                 }
00110         }
00111         //If all choosen Nodes in BackupNodeQueue already are nodes of this subSpace, choose one out of all players.
00112         playerTable.sort();
00113         for(b=playerTable.begin(); b != playerTable.end(); ++b) {
00114                 if( b->getIp() != ip && !subSpaceTable->isInNodeList(subSpaceId, (*n)->getIp() ) ) {
00115                         if( b->getBandwith() < abs(diff) ) {
00116                                 return tmp;
00117                         }
00118                         (*b).modifyBandwith(diff);
00119                         return *b;
00120                 }
00121         }
00122         return tmp;
00123 }

PlayerNode * PlayerTable::findPlayerNodeByIp ( IPAddress  playerIp  ) 

00135                                                               {
00136         for( b = playerTable.begin() ; b != playerTable.end() ; ++b) {
00137                 if( b->getIp() == playerIp) {
00138                         return &*b;
00139                 }
00140         }
00141         return NULL;
00142 }

void PlayerTable::modify ( int  subSpaceId,
IPAddress  playerIp,
int  nodeType 
)

00125                                                                           {
00126         if( nodeType == INTERMEDIATENODE) {
00127                 subSpaceTable->removeNode(subSpaceId, playerIp);
00128                 PlayerNode* player = findPlayerNodeByIp(playerIp);
00129                 if( player != NULL ) {
00130                         player->modifyBandwith(+100);
00131                 }
00132         }
00133 }


Member Data Documentation

std::list<PlayerNode> PlayerTable::playerTable

std::list<PlayerNode>::iterator PlayerTable::b

int PlayerTable::player_autoincrement_id

std::list<PlayerNode*> PlayerTable::nodeQueue

std::list<PlayerNode*>::iterator PlayerTable::n

SubSpaceTable* PlayerTable::subSpaceTable


The documentation for this class was generated from the following files:
Generated on Tue Jul 24 16:51:19 2007 for ITM OverSim by  doxygen 1.5.1