Changeset 3056
- Timestamp:
- Apr 23, 2009, 6:58:34 PM (16 years ago)
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/pingpong/PingPong.cpp
r3055 r3056 13 13 14 14 // the service that the pingpong wants to use 15 ServiceID PingPong::PINGPONG_ ID = ServiceID( 111 );15 ServiceID PingPong::PINGPONG_SERVICEID = ServiceID( 111 ); 16 16 17 17 // construction … … 63 63 64 64 // bind communication and node listener 65 node->bind( this ); /*NodeListener*/66 node->bind( this, PingPong::PINGPONG_ ID); /*CommunicationListener*/65 node->bind( this ); /*NodeListener*/ 66 node->bind( this, PingPong::PINGPONG_SERVICEID); /*CommunicationListener*/ 67 67 68 68 // start node module … … 88 88 89 89 // unbind communication and node listener 90 node->unbind( this ); /*NodeListener*/91 node->unbind( this, PingPong::PINGPONG_ ID ); /*CommunicationListener*/90 node->unbind( this ); /*NodeListener*/ 91 node->unbind( this, PingPong::PINGPONG_SERVICEID ); /*CommunicationListener*/ 92 92 93 93 // leave spovnet … … 121 121 vector<NodeID> nodes = node->getNeighborNodes(); 122 122 BOOST_FOREACH( NodeID nid, nodes ){ 123 node->sendMessage( pingmsg, nid, PingPong::PINGPONG_ ID );123 node->sendMessage( pingmsg, nid, PingPong::PINGPONG_SERVICEID ); 124 124 } 125 125 … … 128 128 // internally, gets all neighboring nodes and sends the message 129 129 //----------------------------------------------------------------------- 130 // node->sendBroadcastMessage( pingmsg, PingPong::PINGPONG_ ID );130 // node->sendBroadcastMessage( pingmsg, PingPong::PINGPONG_SERVICEID ); 131 131 } 132 132 133 // node listener interface134 133 void PingPong::onJoinCompleted( const SpoVNetID& vid ) { 135 134 logging_info( "pingpong node join completed, spovnetid=" << vid.toString() ); … … 153 152 // communication listener 154 153 bool PingPong::onLinkRequest(const NodeID& remote, const DataMessage& msg) { 155 return false; 154 logging_debug( "node " << remote.toString() << " wants to build up a link with us ... allowing" ); 155 return true; 156 156 } 157 157 … … 191 191 } 192 192 193 void PingPong::onMessageSent(seqnum_t seq_num, bool failed, const DataMessage& msg ){194 logging_info( "received message sent event for seqnum " << seq_num195 << " with result " << failed );196 }197 198 193 }}} // namespace ariba, application, pingpong -
sample/pingpong/PingPong.h
r3037 r3056 42 42 virtual void onLinkFail(const LinkID& lnk, const NodeID& remote); 43 43 virtual void onLinkQoSChanged(const LinkID& lnk, const NodeID& remote, const LinkProperties& prop); 44 virtual void onMessageSent(seqnum_t seq_num, bool failed, const DataMessage& msg = DataMessage::UNSPECIFIED);45 44 46 45 // node listener interface … … 60 59 // the ariba module and a node 61 60 AribaModule* ariba; 62 Node* node;61 Node* node; 63 62 64 63 // flag, whether this node initiates or just joins the spovnet … … 66 65 67 66 // the ping pong service id 68 static ServiceID PINGPONG_ ID;67 static ServiceID PINGPONG_SERVICEID; 69 68 70 69 // the current ping id -
source/ariba/CommunicationListener.cpp
r3055 r3056 65 65 bool CommunicationListener::onLinkRequest(const NodeID& remote, 66 66 const DataMessage& msg) { 67 return false;67 return true; 68 68 } 69 69 … … 72 72 } 73 73 74 // --- extended message functionality --- 74 75 // void CommunicationListener::onMessageSent(seqnum_t seq_num, bool failed, 75 76 // const DataMessage& msg) { -
source/ariba/CommunicationListener.h
r3055 r3056 40 40 #define COMMUNICATIONLISTENER_H_ 41 41 42 namespace ariba {43 // forward declaration44 class CommunicationListener;45 }46 47 42 #include "Message.h" 48 43 #include "Identifiers.h" … … 52 47 namespace ariba { 53 48 49 // forward decl 50 namespace overlay { 51 class BaseOverlay; 52 } 53 54 54 /** 55 55 * Listener for communication events on links. 56 56 */ 57 57 class CommunicationListener { 58 friend class Node;58 friend class ariba::overlay::BaseOverlay; 59 59 protected: 60 60 CommunicationListener(); -
source/ariba/NodeListener.h
r3055 r3056 40 40 #define NODELISTENER_H_ 41 41 42 // forward declaration43 namespace ariba {44 class NodeListener;45 class Node;46 }47 48 42 #include "Identifiers.h" 49 43 50 44 namespace ariba { 45 46 // forward decl 47 namespace overlay { 48 class BaseOverlay; 49 } 51 50 52 51 /** … … 57 56 */ 58 57 class NodeListener { 59 friend class Node;58 friend class ariba::overlay::BaseOverlay; 60 59 public: 61 60 NodeListener(); 62 61 virtual ~NodeListener(); 62 63 63 protected: 64 64 /** -
source/ariba/overlay/BaseOverlay.cpp
r3055 r3056 148 148 // inform all registered services of the event 149 149 BOOST_FOREACH( NodeListener* i, nodeListeners ){ 150 if( ret ) i->onLeave Success( spovnetId );151 else i->onLeaveFail ( spovnetId );150 if( ret ) i->onLeaveCompleted( spovnetId ); 151 else i->onLeaveFailed( spovnetId ); 152 152 } 153 153 } … … 178 178 overlayInterface->joinOverlay(); 179 179 BOOST_FOREACH( NodeListener* i, nodeListeners ){ 180 i->onJoin Success( spovnetId );180 i->onJoinCompleted( spovnetId ); 181 181 } 182 182 … … 252 252 253 253 if( item.interface != NULL ) 254 item.interface->onLinkDown( spovnetId, nodeId, item.node );254 item.interface->onLinkDown( link, item.node ); 255 255 } 256 256 … … 310 310 311 311 void BaseOverlay::bind(CommunicationListener* listener, const ServiceID& sid){ 312 logging_debug( "binding communication listener " << listener 312 logging_debug( "binding communication listener " << listener 313 313 << " on serviceid " << sid.toString() ); 314 314 315 315 if( communicationListeners.contains( sid ) ){ 316 logging_error( "some listener already registered for service id " 316 logging_error( "some listener already registered for service id " 317 317 << sid.toString() ); 318 return false;318 return; 319 319 } 320 320 321 321 communicationListeners.registerItem( listener, sid ); 322 return true;323 322 } 324 323 325 324 void BaseOverlay::unbind(CommunicationListener* listener, const ServiceID& sid){ 326 logging_debug( "unbinding listener " << listener 325 logging_debug( "unbinding listener " << listener 327 326 << " from serviceid " << sid.toString() ); 328 327 … … 333 332 334 333 if( communicationListeners.get(sid) != listener ){ 335 logging_warn( "listener bound to service id " << sid.toString() 334 logging_warn( "listener bound to service id " << sid.toString() 336 335 << " is different than listener trying to unbind" ); 337 336 return; … … 344 343 logging_debug( "binding node listener " << listener ); 345 344 346 NodeListenerVector::iterator i = nodeListeners.find(listener );345 NodeListenerVector::iterator i = find( nodeListeners.begin(), nodeListeners.end(), listener ); 347 346 if( i != nodeListeners.end() ){ 348 347 logging_warn( "node listener " << listener << " is already bound, cannot bind" ); 349 348 return; 350 349 } 351 350 352 351 nodeListeners.push_back( listener ); 353 352 } … … 356 355 logging_debug( "unbinding node listener " << listener ); 357 356 358 NodeListenerVector::iterator i = nodeListeners.find(listener );357 NodeListenerVector::iterator i = find( nodeListeners.begin(), nodeListeners.end(), listener ); 359 358 if( i == nodeListeners.end() ){ 360 359 logging_warn( "node listener " << listener << " is not bound, cannot unbind" ); 361 360 return; 362 361 } 363 362 364 363 nodeListeners.erase( i ); 365 364 } … … 451 450 452 451 if( i->second.interface != NULL ) 453 i->second.interface->onLinkDown( id, nodeId,i->second.node );452 i->second.interface->onLinkDown( id, i->second.node ); 454 453 455 454 linkMapping.erase( i ); … … 468 467 469 468 if( i->second.interface != NULL ) 470 i->second.interface->onLinkChanged( id, nodeId,i->second.node );469 i->second.interface->onLinkChanged( id, i->second.node ); 471 470 472 471 i->second.markused(); … … 485 484 486 485 if( i->second.interface != NULL ) 487 i->second.interface->onLinkFail( id, nodeId,i->second.node );486 i->second.interface->onLinkFail( id, i->second.node ); 488 487 489 488 i->second.markused(); … … 501 500 if( i == linkMapping.end() ) return; 502 501 502 // TODO: convert QoSParameterSet to the LinkProperties properties 503 503 if( i->second.interface != NULL ) 504 i->second.interface->onLinkQoSChanged( id, nodeId, i->second.node, qos);504 i->second.interface->onLinkQoSChanged( id, i->second.node, LinkProperties::DEFAULT ); 505 505 506 506 i->second.markused(); … … 535 535 536 536 if( serviceListener != NULL ) 537 serviceListener-> receiveMessage( overlayMsg, link, overlayMsg->getSourceNode());537 serviceListener->onMessage( overlayMsg, overlayMsg->getSourceNode(), link ); 538 538 539 539 return true; … … 571 571 // 572 572 573 // TODO: here you can implement mechanisms to deny joining of a node 573 574 bool allow = true; 574 575 BOOST_FOREACH( NodeListener* i, nodeListeners ){576 allow &= i->isJoinAllowed( overlayMsg->getSourceNode(), spovnetId );577 }578 575 579 576 logging_info( "sending back join reply for spovnet " << … … 644 641 645 642 // inform all registered services of the event 646 BOOST_FOREACH( NodeListener* i, nodeListeners {647 i->onJoinFail ( spovnetId );643 BOOST_FOREACH( NodeListener* i, nodeListeners ){ 644 i->onJoinFailed( spovnetId ); 648 645 } 649 646 … … 670 667 // inform all registered services of the event 671 668 BOOST_FOREACH( NodeListener* i, nodeListeners ){ 672 i->onJoinFail ( spovnetId );669 i->onJoinFailed( spovnetId ); 673 670 } 674 671 … … 692 689 // inform all registered services of the event 693 690 BOOST_FOREACH( NodeListener* i, nodeListeners ){ 694 i->onJoin Success( spovnetId );691 i->onJoinCompleted( spovnetId ); 695 692 } 696 693 … … 758 755 759 756 i->second.interface = iface; 760 iface->onLinkUp( link, nodeId,sourcenode );757 iface->onLinkUp( link, sourcenode ); 761 758 i->second.markused(); 762 759 … … 792 789 // inform all registered services of the event 793 790 BOOST_FOREACH( NodeListener* i, nodeListeners ){ 794 i->onLeaveFail ( spovnetId );791 i->onLeaveFailed( spovnetId ); 795 792 } 796 793 … … 802 799 logging_info( "node left " << overlayMsg->getSourceNode() ); 803 800 804 // inform all registered services of the event805 BOOST_FOREACH( NodeListener* i, nodeListeners ){806 i->onNodeLeave( overlayMsg->getSourceNode(), spovnetId );807 }808 801 } 809 802 … … 908 901 << node.toString() ); 909 902 910 BOOST_FOREACH( NodeListener* i, nodeListeners ){911 i->onNodeJoin( node, spovnetId );912 }913 914 903 joiningNodes.erase( i ); 915 904 } -
source/ariba/overlay/BaseOverlay.h
r3055 r3056 70 70 class NodeListener; 71 71 class CommunicationListener; 72 73 72 namespace utility { 74 73 class OvlVis; … … 204 203 */ 205 204 void bind(CommunicationListener* listener, const ServiceID& sid); 206 205 207 206 /** 208 207 * TODO 209 208 */ 210 209 void unbind(CommunicationListener* listener, const ServiceID& sid); 211 210 212 211 /** 213 212 * TODO 214 213 */ 215 214 void bind(NodeListener* listener); 216 215 217 216 /** 218 217 * TODO … … 289 288 */ 290 289 virtual void incomingRouteMessage( Message* msg ); 291 290 292 291 /** 293 292 * see OverlayStructureEvents.h, called from specific OverlayInterface class … … 295 294 virtual void onNodeJoin( const NodeID& node ); 296 295 297 296 298 297 /** 299 298 * TODO, for timer events … … 407 406 LinkMapping linkMapping; 408 407 409 410 /** 411 * nodes with pending joines. TODO: should be cleaned every 408 409 /** 410 * nodes with pending joines. TODO: should be cleaned every 412 411 * some seconds, add timestamps to each, and check on occasion 413 412 */ -
source/ariba/overlay/modules/OverlayInterface.cpp
r2473 r3056 57 57 58 58 OverlayInterface::~OverlayInterface(){ 59 baseoverlay.unbind( OVERLAY_SERVICE_ID );59 baseoverlay.unbind( this, OVERLAY_SERVICE_ID ); 60 60 } 61 61
Note:
See TracChangeset
for help on using the changeset viewer.