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 "ScribeTest.h" 00025 00026 Define_Module(ScribeTest); 00027 00028 void ScribeTest::handleMessage( cMessage* msg ) 00029 { 00030 if( msg == timer ) { 00031 double random = uniform( 0, 1 ); 00032 if( random < 0.1 || groupNum < 1 ) { 00033 joinGroup( ++groupNum ); 00034 } else if( random < 0.2 ) { 00035 leaveGroup( groupNum-- ); 00036 } else { 00037 sendDataToGroup( intuniform( 1, groupNum )); 00038 } 00039 scheduleAt( simTime() + 10, timer ); 00040 00041 } else if( ALMMulticastMessage* mcast = dynamic_cast<ALMMulticastMessage*>(msg) ){ 00042 handleMCast( mcast ); 00043 } else if( CompReadyMessage* readyMsg = dynamic_cast<CompReadyMessage*>(msg) ){ 00044 if( readyMsg->getReady() ) { 00045 groupNum = 0; 00046 cancelEvent( timer ); 00047 scheduleAt( simTime() + 1, timer ); 00048 } 00049 delete msg; 00050 } 00051 } 00052 00053 void ScribeTest::joinGroup(int i) 00054 { 00055 ALMSubscribeMessage* msg = new ALMSubscribeMessage; 00056 msg->setGroupId(OverlayKey(i)); 00057 send(msg, "to_lowerTier"); 00058 } 00059 00060 void ScribeTest::leaveGroup(int i) 00061 { 00062 ALMLeaveMessage* msg = new ALMLeaveMessage; 00063 msg->setGroupId(OverlayKey(i)); 00064 send(msg, "to_lowerTier"); 00065 } 00066 00067 void ScribeTest::sendDataToGroup( int i ) 00068 { 00069 ALMMulticastMessage* msg = new ALMMulticastMessage("FOO!"); 00070 msg->setGroupId(OverlayKey(i)); 00071 send(msg, "to_lowerTier"); 00072 } 00073 00074 void ScribeTest::handleMCast( ALMMulticastMessage* mcast ) 00075 { 00076 getParentModule()->getParentModule()->bubble("Received message!"); 00077 EV << "[ScribeTest::handleMCast()]\n" 00078 << " App received data message for group: " << mcast->getGroupId() 00079 << endl; 00080 delete mcast; 00081 }
1.5.8