- Timestamp:
- Feb 23, 2009, 2:21:49 PM (16 years ago)
- Location:
- sample/pingpong
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/pingpong/PingPong.cpp
r2432 r2473 1 2 1 #include "PingPong.h" 3 2 #include "ariba/utility/configuration/Configuration.h" … … 11 10 12 11 // logging 13 use_logging_cpp( PingPong );12 use_logging_cpp( PingPong ); 14 13 15 14 // the service id of the ping pong service 16 ServiceID PingPong::PINGPONG_ID = ServiceID( 111);15 ServiceID PingPong::PINGPONG_ID = ServiceID( 111 ); 17 16 18 17 // construction … … 27 26 void PingPong::startup() { 28 27 28 logging_info( "starting up PingPong service ... " ); 29 29 30 // create ariba module 30 logging_ info("Creating ariba underlay module ... ");31 logging_debug( "creating ariba underlay module ... " ); 31 32 ariba = new AribaModule(); 32 33 33 logging_info("Starting up PingPong service ... "); 34 35 // --- get config --- 34 // get the configuration object 36 35 Configuration& config = Configuration::instance(); 37 36 … … 66 65 node->start(); 67 66 68 if (!isInitiator) { 69 node->join(spovnetName); 70 } else { 71 node->initiate(spovnetName); 72 } 67 // initiate or join the spovnet 68 if (!isInitiator) node->join(spovnetName); 69 else node->initiate(spovnetName); 73 70 74 71 // bind communication and node listener 75 72 node->bind(this); 76 73 node->bind(this, PingPong::PINGPONG_ID); 77 74 78 75 // ping pong started up... 79 logging_info( "PingPong started up");76 logging_info( "pingpong started up "); 80 77 } 81 78 82 79 // implementation of the startup interface 83 80 void PingPong::shutdown() { 84 logging_info("PingPong service starting shutdown sequence ..."); 81 82 logging_info( "pingpong service starting shutdown sequence ..." ); 85 83 86 84 // stop timer 87 85 Timer::stop(); 88 89 // leave spovnet90 node->leave();91 86 92 87 // unbind listeners … … 94 89 node->unbind( this, PingPong::PINGPONG_ID ); 95 90 91 // leave spovnet 92 node->leave(); 93 94 // stop the ariba module 96 95 ariba->stop(); 96 97 // delete node and ariba module 97 98 delete node; 98 99 delete ariba; 99 100 100 logging_info("PingPong service shut down!"); 101 // now we are completely shut down 102 logging_info( "pingpong service shut down" ); 101 103 } 102 104 103 105 // node listener interface 104 106 void PingPong::onJoinCompleted( const SpoVNetID& vid ) { 105 logging_info("PingPong node join completed, spovnetid=" << vid.toString() ); 107 logging_info( "pingpong node join completed, spovnetid=" << vid.toString() ); 108 109 // start the timer to ping every second 110 Timer::setInterval( 1000 ); 111 Timer::start(); 106 112 } 107 113 108 114 void PingPong::onJoinFailed( const SpoVNetID& vid ) { 109 logging_ info("PingPong node join failed, spovnetid=" << vid.toString() );115 logging_error(" pingpong node join failed, spovnetid=" << vid.toString() ); 110 116 } 111 117 … … 115 121 } 116 122 117 void PingPong::onMessage(Message* msg, const NodeID& remote, const LinkID& lnk = 118 LinkID::UNSPECIFIED) { 119 PingPongMessage* incoming = msg->decapsulate<PingPongMessage> (); 123 void PingPong::onMessage(Message* msg, const NodeID& remote, 124 const LinkID& lnk = LinkID::UNSPECIFIED) { 120 125 121 logging_info("received ping message on link " << lnk.toString() 122 << " from node with id " << (int) incoming->getid()); 126 PingPongMessage* pingmsg = msg->decapsulate<PingPongMessage> (); 127 128 logging_info( "received ping message on link " << lnk.toString() 129 << " from node " << remote.toString() 130 << ": " << pingmsg->toString() ); 123 131 } 124 132 125 133 // timer event 126 134 void PingPong::eventFunction() { 135 136 // we ping all nodes that are known in the overlay structure 137 // this can be all nodes (OneHop) overlay or just some neighbors 138 // in case of a Chord or Kademlia structure 139 140 logging_info( "pinging overlay neighbors with ping id " << ++pingId ); 141 142 PingPongMessage pingmsg( pingId ); 143 node->sendBroadcastMessage( pingmsg, PingPong::PINGPONG_ID ); 144 127 145 } 128 146 -
sample/pingpong/PingPong.h
r2413 r2473 4 4 #include "ariba/ariba.h" 5 5 #include "PingPongMessage.h" 6 #include "ariba/utility/system/StartupInterface.h" 7 #include "ariba/utility/system/Timer.h" 6 8 7 9 using namespace ariba; 8 9 #include "ariba/utility/system/StartupInterface.h"10 #include "ariba/utility/system/Timer.h"11 10 using ariba::utility::StartupInterface; 12 11 using ariba::utility::Timer; … … 55 54 Node* node; 56 55 57 // flag, wheter this node i s the initiator of thisspovnet56 // flag, wheter this node initiates or just joins the spovnet 58 57 bool isInitiator; 59 58 … … 65 64 }; 66 65 67 //ARIBA_SIMULATION_SERVICE(PingPong); 66 // needed for simulation support 67 ARIBA_SIMULATION_SERVICE(PingPong); 68 68 69 69 }}} // namespace ariba, application, pingpong
Note:
See TracChangeset
for help on using the changeset viewer.