[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "transfer" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Oct 13 20:42:48 CDT 2010
branch "transfer" has been updated
via d8fcd1f7f0b249215fc53ae804997b2579920263 (commit)
from 429b0e8a49d210056cad3187eea3ab8d16be2e70 (commit)
Summary of changes:
src/SessionRouter.cpp | 156 +++++++++++++-----------------------------------
1 files changed, 42 insertions(+), 114 deletions(-)
- Log -----------------------------------------------------------------
commit d8fcd1f7f0b249215fc53ae804997b2579920263
Author: Ken Hunt <ken.hunt at digium.com>
Date: Wed Oct 13 20:41:55 2010 -0500
Cleanup of listener handling.
diff --git a/src/SessionRouter.cpp b/src/SessionRouter.cpp
index 5da56e4..f61d58d 100644
--- a/src/SessionRouter.cpp
+++ b/src/SessionRouter.cpp
@@ -36,12 +36,22 @@ namespace BasicRoutingService
class SessionListenerImpl : public SessionListener
{
public:
- SessionListenerImpl(const SessionPrx& source) :
- mTerminated(false), mListenerPrx(0)
+ SessionListenerImpl(Ice::ObjectAdapterPtr adapter, const SessionPrx& source) :
+ mAdapter(adapter), mTerminated(false), mListenerPrx(0)
{
+ Ice::ObjectPrx prx = adapter->addWithUUID(this);
+ mListenerPrx = SessionListenerPrx::checkedCast(prx);
+
addSession(source);
}
+ ~SessionListenerImpl()
+ {
+ unregister();
+
+ mAdapter->remove(mListenerPrx->ice_getIdentity());
+ }
+
void connected(const SessionPrx& session, const Ice::Current&)
{
}
@@ -101,7 +111,7 @@ public:
}
/**
- * Stop listening to all sessions we're monitoring.
+ * git listening to all sessions we're monitoring.
*/
void unregister()
{
@@ -111,22 +121,13 @@ public:
}
}
- void setProxy(SessionListenerPrx proxy)
- {
- mListenerPrx = proxy;
-
- for (SessionSeq::iterator i = mSessions.begin(); i != mSessions.end(); ++i)
- {
- (*i)->addListener(mListenerPrx);
- }
- }
-
SessionListenerPrx getProxy()
{
return mListenerPrx;
}
private:
+ Ice::ObjectAdapterPtr mAdapter;
SessionSeq mSessions;
bool mTerminated;
SessionListenerPrx mListenerPrx;
@@ -146,66 +147,7 @@ public:
~SessionRouterPriv()
{
- for (map<string, SessionListenerImplPtr>::iterator i = mActiveListeners.begin(); i != mActiveListeners.end(); ++i)
- {
- (*i).second->unregister();
- (*i).second = 0;
- }
- mActiveListeners.clear();
- }
-
-
- Ice::Identity getListenerId(const std::string& sourceId)
- {
- return mAdapter->getCommunicator()->stringToIdentity(sourceId + "Listener");
- }
-
- /**
- * Create a listener for the session.
- */
- SessionListenerImplPtr createListener(const SessionPrx& source)
- {
- try
- {
- string sourceId = source->ice_getIdentity().name;
- Ice::Identity sessionListenerId = getListenerId(sourceId);
-
- map<string, SessionListenerImplPtr>::iterator exists = mActiveListeners.find(sourceId);
- if (exists != mActiveListeners.end())
- {
- // A listener for this source is already created. Use it.
- return exists->second;
- }
-
- SessionListenerImplPtr listener = new SessionListenerImpl(source);
-
- Ice::ObjectPrx prx = mAdapter->addWithUUID(listener);
- listener->setProxy(SessionListenerPrx::checkedCast(prx));
-
- mActiveListeners[listener->ice_id()] = listener;
-
- return listener;
- }
- catch(const Ice::Exception &e)
- {
- lg(Error) << "Unable to create listener. " << e.what();
- return 0;
- }
- }
-
- /**
- * Delete the listener.
- */
- void deleteListener(SessionListenerImplPtr listener)
- {
- // Unregister the listener from all sessions that it is monitoring.
- listener->unregister();
-
- // Remove it from our map.
- string key = listener->ice_id();
- mActiveListeners[key] = 0; // Set smart pointer to null.
- mActiveListeners.erase(key);
- }
+ }
void setBridgeAccessor(BridgeManagerAccessorPtr bridgeAccessor)
{
@@ -240,34 +182,28 @@ public:
}
- void forwardStart(SessionListenerImplPtr listener, SessionPrx source)
+ void forwardStart(SessionSeq& sessions)
{
- // Forward the start to all the destinations routed to.
- SessionSeq sessions = listener->getSessions();
for (SessionSeq::iterator s = sessions.begin(); s != sessions.end(); ++s)
{
try
{
- if (source->ice_getIdentity() != (*s)->ice_getIdentity())
- {
- (*s)->start();
- }
+ (*s)->start();
}
catch (const Ice::Exception &e)
{
lg(Error) << "Unable to forward the start() operation to Session. " << e.what();
- deleteListener(listener);
// TBD... probably other bridge cleanup needs to be done.
throw;
}
}
}
+
public:
Ice::ObjectAdapterPtr mAdapter;
EndpointRegistryPtr mEndpointRegistry;
RoutingEventsPtr mEventPublisher;
BridgeManagerAccessorPtr mBridgeManagerAccessor;
- map<string, SessionListenerImplPtr> mActiveListeners;
};
SessionRouter::SessionRouter(const Ice::ObjectAdapterPtr& objectAdapter, const EndpointRegistryPtr& endpointRegistry,
@@ -294,12 +230,13 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
const Ice::Current& current)
{
// Create a listener for the source to handle early termination.
- SessionListenerImplPtr listener = mImpl->createListener(source);
+ SessionListenerImplPtr listener = new SessionListenerImpl(mImpl->mAdapter, source);
// Route the destination
EndpointSeq endpoints = mImpl->lookupEndpoints(destination, current);
// Add a session
+ SessionSeq newSessions;
for (EndpointSeq::iterator e = endpoints.begin(); e != endpoints.end(); ++e)
{
try
@@ -309,6 +246,7 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
// Create a session on the destination.
SessionPrx destSession = sessionEndpoint->createSession(destination, listener->getProxy());
listener->addSession(destSession);
+ newSessions.push_back(destSession);
}
catch(const Ice::Exception &exception)
{
@@ -324,7 +262,6 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
if (listener->isTerminated())
{
- mImpl->deleteListener(listener);
throw SourceTerminatedPreBridgingException(source->getEndpoint()->getId());
}
@@ -337,18 +274,15 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
catch (const Ice::Exception &)
{
listener->unregister();
- mImpl->deleteListener(listener);
throw BridgingException(source->getEndpoint()->getId(), destination);
}
// Forward the start to all the destinations routed to.
- mImpl->forwardStart(listener, source);
+ mImpl->forwardStart(newSessions);
- // We're done with the listener.
- mImpl->deleteListener(listener);
-}
+} // SessionRouter::routeSession(...)
/**
* Replace one session in a Bridge with a new
@@ -377,21 +311,21 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
}
catch(const Ice::Exception &e)
{
- lg(Error) << "Unable to get list of sesssions for bridge in replaceSessionWithDestination(). " ;
+ lg(Error) << "Unable to get list of sesssions for bridge in connectBridgedSessionsWithDestination(). " ;
throw e; // rethrow
}
- // Add a listener to the session not being replaced to handle early termination.
+ // Add a listener to the sessions not being replaced to handle early termination.
SessionListenerImplPtr listener(0);
SessionPrx source(0);
for(SessionSeq::iterator s = seq.begin(); s !=seq.end(); ++s)
{
- if (sessionToReplace->ice_getIdentity() != (*s)->ice_getIdentity())
+ if (sessionToReplace->ice_getIdentity() != (*s)->ice_getIdentity()) // Only listening to the session NOT being dropped out of bridge.
{
if (listener == 0)
{
source = (*s);
- listener = mImpl->createListener(source); // Only listening to the session NOT being transferred.
+ listener = new SessionListenerImpl(mImpl->mAdapter, *s);
}
else
{
@@ -405,6 +339,7 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
// Add a session
SessionPrx destSession(0);
+ SessionSeq newSessions;
for (EndpointSeq::iterator e = endpoints.begin(); e != endpoints.end(); ++e)
{
try
@@ -414,6 +349,7 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
// Create a session on the destination.
destSession = sessionEndpoint->createSession(destination, listener->getProxy());
listener->addSession(destSession);
+ newSessions.push_back(destSession);
}
catch(const Ice::Exception &exception)
{
@@ -424,14 +360,13 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
if (listener->getSessions().size() < 2)
{
- lg(Error) << "Unable to create a new session for destination " << destination << " in replaceSessionWithDestination(). " ;
+ lg(Error) << "Unable to create a new session for destination " << destination << " in connectBridgedSessionsWithDestination(). " ;
throw SessionCreationException(destination);
}
if (listener->isTerminated())
{
- mImpl->deleteListener(listener);
- lg(Notice) << "Source ended session before transfer in replaceSessionWithDestination(). " ;
+ lg(Notice) << "Source ended session before transfer in connectBridgedSessionsWithDestination(). " ;
throw SourceTerminatedPreBridgingException(source->getEndpoint()->getId());
}
@@ -445,18 +380,15 @@ void SessionRouter::connectBridgedSessionsWithDestination(const SessionPrx& sess
catch (const Ice::Exception &e)
{
listener->unregister();
- mImpl->deleteListener(listener);
- lg(Error) << "Exception replacing the session in replaceSessionWithDestination. " << e.what() ;
+ lg(Error) << "Exception replacing the session in connectBridgedSessionsWithDestination. " << e.what() ;
throw BridgingException(source->getEndpoint()->getId(), destination);
}
- mImpl->forwardStart(listener, source);
+ mImpl->forwardStart(newSessions);
- // We're done with the listener.
- mImpl->deleteListener(listener);
-}
+} // SessionRouter::connectBridgedSessionsWithDestination(...)
/**
* Replace one session in a Bridge with sessions from another bridge.
@@ -484,7 +416,7 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
}
catch(const NotBridged& e)
{
- lg(Error) << "Unable to obtain bridge from sessionToReplace in replaceSessionWithSession(). " ;
+ lg(Error) << "Unable to obtain bridge from sessionToReplace in connectBridgedSessions(). " ;
throw e; // rethrow
}
@@ -495,7 +427,7 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
}
catch(const Ice::Exception &e)
{
- lg(Error) << "Unable to get list of sesssions for bridge in replaceSessionWithSession(). " ;
+ lg(Error) << "Unable to get list of sesssions for bridge in connectBridgedSessions(). " ;
throw e; // rethrow
}
@@ -508,8 +440,7 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
{
if (listener == 0)
{
- source = (*s);
- listener = mImpl->createListener(source); // Only listening to sessions NOT being replaced.
+ listener = new SessionListenerImpl(mImpl->mAdapter, *s); // Only listening to sessions NOT being replaced.
}
else
{
@@ -526,14 +457,13 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
}
catch(const NotBridged&)
{
- lg(Warning) << "Unable to get bridge for the bridgedSession in replaceSessionWithSession(). " ;
+ lg(Warning) << "Unable to get bridge for the bridgedSession in connectBridgedSessions(). " ;
}
// Check for early termination by the source.
if (listener->isTerminated())
{
- mImpl->deleteListener(listener);
- lg(Notice) << "Source ended session before transfer in replaceSessionWithSession(). " ;
+ lg(Notice) << "Source ended session before transfer in connectBridgedSessions(). " ;
throw SourceTerminatedPreBridgingException(source->getEndpoint()->getId());
}
@@ -555,7 +485,7 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
}
catch(const Ice::Exception&)
{
- lg(Warning) << "Unable to remove sessions in replaceSessionWithSession(). " ;
+ lg(Warning) << "Unable to remove sessions in connectBridgedSessions(). " ;
// We won't give up because of this.
}
}
@@ -569,13 +499,11 @@ void SessionRouter::connectBridgedSessions(const SessionPrx& sessionToReplace,
}
catch(const Ice::Exception& e)
{
- lg(Error) << "Unable to replace session for bridge in replaceSessionWithSession(). " ;
+ lg(Error) << "Unable to replace session for bridge in connectBridgedSessions(). " ;
throw e; // rethrow
}
- // We're done with the listener.
- mImpl->deleteListener(listener);
-}
+} // SessionRouter::connectBridgedSessions(...)
} // end BasicRoutingService
} // end AsteriskSCF
-----------------------------------------------------------------------
--
asterisk-scf/integration/routing.git
More information about the asterisk-scf-commits
mailing list