Index: source/ariba/overlay/BaseOverlay.cpp
===================================================================
--- source/ariba/overlay/BaseOverlay.cpp	(revision 3041)
+++ source/ariba/overlay/BaseOverlay.cpp	(revision 3055)
@@ -40,5 +40,6 @@
 
 #include "ariba/utility/misc/OvlVis.h"
-using ariba::utility::OvlVis;
+#include "ariba/NodeListener.h"
+#include "ariba/CommunicationListener.h"
 
 namespace ariba {
@@ -146,5 +147,5 @@
 
 	// inform all registered services of the event
-	BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+	BOOST_FOREACH( NodeListener* i, nodeListeners ){
 		if( ret ) i->onLeaveSuccess( spovnetId );
 		else      i->onLeaveFail( spovnetId );
@@ -176,5 +177,5 @@
 
 	overlayInterface->joinOverlay();
-	BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+	BOOST_FOREACH( NodeListener* i, nodeListeners ){
 		i->onJoinSuccess( spovnetId );
 	}
@@ -221,10 +222,10 @@
 const LinkID BaseOverlay::establishLink(const EndpointDescriptor& ep, const ServiceID& service){
 
-	if( !listenerMux.contains( service ) ){
+	if( !communicationListeners.contains( service ) ){
 		logging_error( "no registered listener on serviceid " << service.toString() );
 		return LinkID::UNSPECIFIED;
 	}
 
-	ServiceInterface* receiver = listenerMux.get( service );
+	CommunicationListener* receiver = communicationListeners.get( service );
 	const LinkID link = bc->establishLink( ep );
 
@@ -308,30 +309,58 @@
 }
 
-bool BaseOverlay::bind(ServiceInterface* service, const ServiceID& sid) {
-
-	logging_debug( "binding service " << service << " on serviceid " << sid.toString() );
-
-	if( listenerMux.contains( sid ) ){
-		logging_error( "some service already registered for service id " << sid.toString() );
+void BaseOverlay::bind(CommunicationListener* listener, const ServiceID& sid){
+	logging_debug( "binding communication listener " << listener 
+		<< " on serviceid " << sid.toString() );
+
+	if( communicationListeners.contains( sid ) ){
+		logging_error( "some listener already registered for service id " 
+			<< sid.toString() );
 		return false;
 	}
 
-	listenerMux.registerItem( service, sid );
+	communicationListeners.registerItem( listener, sid );
 	return true;
 }
 
-ServiceInterface* BaseOverlay::unbind(const ServiceID& sid){
-
-	logging_debug( "unbinding service from serviceid " << sid.toString() );
-
-	if( !listenerMux.contains( sid ) ){
-		logging_warn( "cannot unbind service. no service registered on service id " << sid.toString() );
-		return NULL;
-	}
-
-	ServiceInterface* iface = listenerMux.get( sid );
-	listenerMux.unregisterItem( sid );
-
-	return NULL; //iface;
+void BaseOverlay::unbind(CommunicationListener* listener, const ServiceID& sid){
+	logging_debug( "unbinding listener " << listener 
+		<< " from serviceid " << sid.toString() );
+
+	if( !communicationListeners.contains( sid ) ){
+		logging_warn( "cannot unbind listener. no listener registered on service id " << sid.toString() );
+		return;
+	}
+
+	if( communicationListeners.get(sid) != listener ){
+		logging_warn( "listener bound to service id " << sid.toString() 
+			<< " is different than listener trying to unbind" );
+		return;
+	}
+
+	communicationListeners.unregisterItem( sid );
+}
+
+void BaseOverlay::bind(NodeListener* listener){
+	logging_debug( "binding node listener " << listener );
+
+	NodeListenerVector::iterator i = nodeListeners.find( listener );
+	if( i != nodeListeners.end() ){
+		logging_warn( "node listener " << listener << " is already bound, cannot bind" );
+		return;
+	}
+	
+	nodeListeners.push_back( listener );
+}
+
+void BaseOverlay::unbind(NodeListener* listener){
+	logging_debug( "unbinding node listener " << listener );
+
+	NodeListenerVector::iterator i = nodeListeners.find( listener );
+	if( i == nodeListeners.end() ){
+		logging_warn( "node listener " << listener << " is not bound, cannot unbind" );
+		return;
+	}
+	
+	nodeListeners.erase( i );
 }
 
@@ -501,5 +530,5 @@
 
 		const ServiceID& service = overlayMsg->getService();
-		ServiceInterface* serviceListener = listenerMux.get( service );
+		CommunicationListener* serviceListener = communicationListeners.get( service );
 
 		logging_debug( "received data for service " << service.toString() );
@@ -544,5 +573,5 @@
 		bool allow = true;
 
-		BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+		BOOST_FOREACH( NodeListener* i, nodeListeners ){
 			allow &= i->isJoinAllowed( overlayMsg->getSourceNode(), spovnetId );
 		}
@@ -615,5 +644,5 @@
 
 			// inform all registered services of the event
-			BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+			BOOST_FOREACH( NodeListener* i, nodeListeners{
 				i->onJoinFail( spovnetId );
 			}
@@ -640,5 +669,5 @@
 
 			// inform all registered services of the event
-			BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+			BOOST_FOREACH( NodeListener* i, nodeListeners ){
 				i->onJoinFail( spovnetId );
 			}
@@ -662,5 +691,5 @@
 
 		// inform all registered services of the event
-		BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+		BOOST_FOREACH( NodeListener* i, nodeListeners ){
 			i->onJoinSuccess( spovnetId );
 		}
@@ -717,10 +746,10 @@
 		//
 
-		if( !listenerMux.contains( service ) ){
+		if( !communicationListeners.contains( service ) ){
 			logging_warn( "linkup event for service that has not been registered" );
 			return false;
 		}
 
-		ServiceInterface* iface = listenerMux.get( service );
+		CommunicationListener* iface = communicationListeners.get( service );
 		if( iface == NULL ){
 			logging_warn( "linkup event for service that has been registered with a NULL interface" );
@@ -762,5 +791,5 @@
 
 			// inform all registered services of the event
-			BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+			BOOST_FOREACH( NodeListener* i, nodeListeners ){
 				i->onLeaveFail( spovnetId );
 			}
@@ -774,5 +803,5 @@
 
 			// inform all registered services of the event
-			BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+			BOOST_FOREACH( NodeListener* i, nodeListeners ){
 				i->onNodeLeave( overlayMsg->getSourceNode(), spovnetId );
 			}
@@ -879,5 +908,5 @@
 				<< node.toString() );
 
-	BOOST_FOREACH( ServiceInterface* i, listenerMux.getOneList() ){
+	BOOST_FOREACH( NodeListener* i, nodeListeners ){
 		i->onNodeJoin( node, spovnetId );
 	}
