[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Sep 10 11:26:39 CDT 2010


branch "master" has been updated
       via  8bf8cea02658395e14bf122152c4511ea845163c (commit)
      from  dadd727879727a839f02d20a0a8615f3015885a7 (commit)

Summary of changes:
 src/BasicRoutingServiceApp.cpp       |   72 ++++++--
 src/BasicRoutingServiceDataModel.h   |   10 +
 src/CMakeLists.txt                   |    2 +
 src/EndpointRegistry.cpp             |    7 +
 src/EndpointRegistry.h               |    7 +
 src/LuaScriptProcessor.cpp           |    7 +
 src/LuaScriptProcessor.h             |    7 +
 src/RoutingAdmin.cpp                 |    7 +
 src/RoutingAdmin.h                   |    7 +
 src/RoutingServiceEventPublisher.cpp |    7 +
 src/RoutingServiceEventPublisher.h   |    7 +
 src/ScriptProcessor.h                |    7 +
 src/SessionRouter.cpp                |  302 ++++++++++++++++++++++++++++++++++
 src/SessionRouter.h                  |   43 +++++
 14 files changed, 474 insertions(+), 18 deletions(-)
 create mode 100644 src/SessionRouter.cpp
 create mode 100644 src/SessionRouter.h


- Log -----------------------------------------------------------------
commit 8bf8cea02658395e14bf122152c4511ea845163c
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Sep 10 11:25:08 2010 -0500

    First implementation of SessionRouter. Needs testing!

diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index 09d186a..f07c796 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #include <Ice/Ice.h>
 #include <IceStorm/IceStorm.h>
 
@@ -6,6 +13,14 @@
 
 #include "RoutingIf.h"
 #include "ServiceLocatorIf.h"
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#include "BridgingIf.h"
 #include "ComponentServiceIf.h"
 #include "BasicRoutingServiceDataModel.h"
 #include "LuaScriptProcessor.h"
@@ -15,6 +30,7 @@
 
 using namespace std;
 using namespace AsteriskSCF::BasicRoutingService;
+using namespace AsteriskSCF::SessionCommunications::Bridging::V1;
 using namespace AsteriskSCF::Core;
 using namespace AsteriskSCF::Core::Routing::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
@@ -47,7 +63,17 @@ public: // Overrides of the BasicRoutingServiceDataModel singleton's public inte
       return *mEndpointRegistry;
    }
 
-public: // Implementation details are visible on to this file's classes. 
+   virtual Ice::ObjectAdapterPtr getObjectAdapter()
+   {
+      return mAdapter;
+   }
+
+   virtual BridgeManagerPrx getBridgeManager()
+   {
+      return mBridgeManager;
+   }
+
+public: // Implementation details are visible to this file's classes. 
    /**
     * Cleanup the dangling cruft. 
     */
@@ -63,8 +89,12 @@ public: // Implementation details are visible on to this file's classes.
    }
 
    Ice::CommunicatorPtr mCommunicator;
+   Ice::ObjectAdapterPtr mAdapter;
    RoutingServiceEventPublisher *mEventPublisher;
    EndpointRegistry *mEndpointRegistry;
+   ServiceLocatorPrx mServiceLocator;
+   BridgeManagerPrx mBridgeManager;
+
    bool mPaused;
 
    BasicRoutingServiceDataModelImpl() : mPaused(false) {}
@@ -103,7 +133,6 @@ private:
 
    bool mDone;
    std::string mAppName;
-   Ice::ObjectAdapterPtr mAdapter;
    ServiceLocatorManagementPrx mServiceLocatorManagement;
 
    Discovery::V1::ServiceManagementPrx mRegistryLocatorManagement;
@@ -177,6 +206,8 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
 {
    try
    {
+      Ice::ObjectAdapterPtr adapter = mDataModelInstance.mAdapter;
+
       // Get a proxy to the management interface for the Service Locator, so we can add ourselves into the system discovery mechanisms.
 	   mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(communicator()->propertyToProxy("LocatorServiceManagement.Proxy")); 
 
@@ -187,28 +218,25 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
       }
 
       // Get a proxy to our RoutingAdmin interface and add it to the Service Locator. 
-      Ice::ObjectPrx adminObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(RoutingAdminObjectId));
+      Ice::ObjectPrx adminObjectPrx = adapter->createDirectProxy(communicator()->stringToIdentity(RoutingAdminObjectId));
       RoutingServiceAdminPrx adminPrx = RoutingServiceAdminPrx::checkedCast(adminObjectPrx);
-      // The GUID passed in to add service needs to be unique for reporting. 
-      string adminServiceGuid("BasicRoutingServiceAdmin"); 
+      string adminServiceGuid("BasicRoutingServiceAdmin"); // Should be unique for reporting.
       mAdminManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(adminPrx, adminServiceGuid));
 	   
       setCategory(mAdminManagement, Routing::V1::RoutingServiceAdminDiscoveryCategory);
    	
       // Get a proxy to our RegistryLocator interface and add it to the Service Locator. 
-      Ice::ObjectPrx locatorObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(RegistryLocatorObjectId));
+      Ice::ObjectPrx locatorObjectPrx = adapter->createDirectProxy(communicator()->stringToIdentity(RegistryLocatorObjectId));
       LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::checkedCast(locatorObjectPrx);
-      // The GUID passed in to add service needs to be unique for reporting. 
-      string locatorServiceGuid("BasicRoutingServiceRegistryLocator"); 
+      string locatorServiceGuid("BasicRoutingServiceRegistryLocator");  // Should be unique for reporting.
       mRegistryLocatorManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(locatorRegistryPrx, locatorServiceGuid));
 	   
       setCategory(mRegistryLocatorManagement, Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);
 
       // Get a proxy to our ComponentService interface and add it to the Service Locator. 
-      Ice::ObjectPrx componentServiceObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(ComponentServiceId));
+      Ice::ObjectPrx componentServiceObjectPrx = adapter->createDirectProxy(communicator()->stringToIdentity(ComponentServiceId));
       ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
-      // The GUID passed in to add service needs to be unique for reporting. 
-      string componentServiceGuid("BasicRoutingService");  
+      string componentServiceGuid("BasicRoutingService");   // Should be unique for reporting.
       mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
 	   
       setCategory(mRegistryLocatorManagement, Routing::V1::ComponentServiceDiscoveryCategory);
@@ -254,7 +282,7 @@ void BasicRoutingServiceApp::initialize(const std::string appName)
       mDataModelInstance.mEventPublisher = new RoutingServiceEventPublisher(); 
 
       // Create the adapter. 
-      mAdapter = communicator()->createObjectAdapter("BasicRoutingServiceAdapter");
+      mDataModelInstance.mAdapter = communicator()->createObjectAdapter("BasicRoutingServiceAdapter");
 
       // Create and configure the EndpointRegistry. 
       mDataModelInstance.mEndpointRegistry = new EndpointRegistry();
@@ -263,21 +291,29 @@ void BasicRoutingServiceApp::initialize(const std::string appName)
 
       // Publish the LocatorRegistry interface.  
       mLocatorRegistry = mDataModelInstance.mEndpointRegistry;
-      mAdapter->add(mLocatorRegistry, communicator()->stringToIdentity(RegistryLocatorObjectId));
+      mDataModelInstance.mAdapter->add(mLocatorRegistry, communicator()->stringToIdentity(RegistryLocatorObjectId));
 
       // Create and publish the Admin interface support.
       mAdminInteface = new RoutingAdmin();
-      mAdapter->add(mAdminInteface, communicator()->stringToIdentity(RoutingAdminObjectId));
+      mDataModelInstance.mAdapter->add(mAdminInteface, communicator()->stringToIdentity(RoutingAdminObjectId));
 
       mComponentService = new ComponentServiceImpl(*this);
-      mAdapter->add(mComponentService, communicator()->stringToIdentity(ComponentServiceId));
+      mDataModelInstance.mAdapter->add(mComponentService, communicator()->stringToIdentity(ComponentServiceId));
+
+      mDataModelInstance.mAdapter->activate();
 
-      mAdapter->activate();
+      // Get a proxy to the management interface for the Service Locator.
+	   mDataModelInstance.mServiceLocator = ServiceLocatorPrx::checkedCast(communicator()->propertyToProxy("LocatorService.Proxy")); 
 
+      // Use the locator to find the BridgeManger. 
+      ServiceLocatorParamsPtr nameparam = new ServiceLocatorParams();
+      nameparam->category = communicator()->getProperties()->getProperty("BridgeManager.ServiceLocatorId");
+      Ice::ObjectPrx bridgeManagerObject = mDataModelInstance.mServiceLocator->locate(nameparam);
+      mDataModelInstance.mBridgeManager = BridgeManagerPrx::checkedCast(bridgeManagerObject);
    }
-   catch(...)
+   catch(const Ice::Exception &exception)
    {
-      cout << "Major problems in " << mAppName << " initialization()" << endl;
+      cout << "Major problems in " << mAppName << " initialization(): " << exception.what() << endl;
    }
 }
 
diff --git a/src/BasicRoutingServiceDataModel.h b/src/BasicRoutingServiceDataModel.h
index 5622890..6184bf4 100644
--- a/src/BasicRoutingServiceDataModel.h
+++ b/src/BasicRoutingServiceDataModel.h
@@ -1,6 +1,14 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #pragma once
 
 #include <Ice/Ice.h>
+#include "BridgingIf.h"
 
 namespace AsteriskSCF
 {
@@ -18,8 +26,10 @@ public:
    static BasicRoutingServiceDataModel &getInstance();
 
    virtual const Ice::CommunicatorPtr getCommunicator() = 0;
+   virtual Ice::ObjectAdapterPtr getObjectAdapter() = 0;
    virtual const RoutingServiceEventPublisher& getEventPublisher() = 0;
    virtual EndpointRegistry& getEndpointRegistry() = 0;
+   virtual AsteriskSCF::SessionCommunications::Bridging::V1::BridgeManagerPrx getBridgeManager() = 0;
 
 protected:
    BasicRoutingServiceDataModel() {};
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1d5ddbc..245452e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,6 +10,8 @@ hydra_component_add_slice(BasicRoutingService BridgingIf)
 hydra_component_add_slice(BasicRoutingService ComponentServiceIf)
 hydra_component_add_file(BasicRoutingService BasicRoutingServiceApp.cpp)
 hydra_component_add_file(BasicRoutingService BasicRoutingServiceDataModel.h)
+hydra_component_add_file(BasicRoutingService SessionRouter.cpp)
+hydra_component_add_file(BasicRoutingService SessionRouter.h)
 hydra_component_add_file(BasicRoutingService RoutingAdmin.cpp)
 hydra_component_add_file(BasicRoutingService RoutingAdmin.h)
 hydra_component_add_file(BasicRoutingService EndpointRegistry.cpp)
diff --git a/src/EndpointRegistry.cpp b/src/EndpointRegistry.cpp
index 8abdf99..f4f0612 100644
--- a/src/EndpointRegistry.cpp
+++ b/src/EndpointRegistry.cpp
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #include <boost/regex.hpp> 
 
 #include "BasicRoutingServiceDataModel.h"
diff --git a/src/EndpointRegistry.h b/src/EndpointRegistry.h
index 4c9e9c6..2a28869 100644
--- a/src/EndpointRegistry.h
+++ b/src/EndpointRegistry.h
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #pragma once
 
 #include <boost/shared_ptr.hpp>
diff --git a/src/LuaScriptProcessor.cpp b/src/LuaScriptProcessor.cpp
index c3c0125..9e866bc 100644
--- a/src/LuaScriptProcessor.cpp
+++ b/src/LuaScriptProcessor.cpp
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #include "lua.hpp"
 
 #include <boost/thread/locks.hpp>
diff --git a/src/LuaScriptProcessor.h b/src/LuaScriptProcessor.h
index f6c5150..29f25f0 100644
--- a/src/LuaScriptProcessor.h
+++ b/src/LuaScriptProcessor.h
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #pragma once
 
 #include <boost/shared_ptr.hpp>
diff --git a/src/RoutingAdmin.cpp b/src/RoutingAdmin.cpp
index 8ac67ba..d3a03d3 100644
--- a/src/RoutingAdmin.cpp
+++ b/src/RoutingAdmin.cpp
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #include <boost/regex.hpp> 
 
 #include "RoutingAdmin.h"
diff --git a/src/RoutingAdmin.h b/src/RoutingAdmin.h
index 5879fa0..3538038 100644
--- a/src/RoutingAdmin.h
+++ b/src/RoutingAdmin.h
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #pragma once
 
 #include <boost/shared_ptr.hpp>
diff --git a/src/RoutingServiceEventPublisher.cpp b/src/RoutingServiceEventPublisher.cpp
index 0be461e..becf19a 100644
--- a/src/RoutingServiceEventPublisher.cpp
+++ b/src/RoutingServiceEventPublisher.cpp
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #include <Ice/Ice.h>
 #include <IceStorm/IceStorm.h>
 
diff --git a/src/RoutingServiceEventPublisher.h b/src/RoutingServiceEventPublisher.h
index ff45422..6c82f86 100644
--- a/src/RoutingServiceEventPublisher.h
+++ b/src/RoutingServiceEventPublisher.h
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #pragma once
 
 #include <boost/shared_ptr.hpp>
diff --git a/src/ScriptProcessor.h b/src/ScriptProcessor.h
index e03c80c..c876e82 100644
--- a/src/ScriptProcessor.h
+++ b/src/ScriptProcessor.h
@@ -1,3 +1,10 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
 #pragma once
 
 #include "RoutingIf.h"
diff --git a/src/SessionRouter.cpp b/src/SessionRouter.cpp
new file mode 100644
index 0000000..70dd4c5
--- /dev/null
+++ b/src/SessionRouter.cpp
@@ -0,0 +1,302 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#include "SessionRouter.h"
+#include "EndpointRegistry.h"
+#include "BasicRoutingServiceDataModel.h"
+#include "RoutingIf.h"
+#include "EndpointIf.h"
+
+using namespace ::AsteriskSCF::Core::Routing::V1;
+using namespace ::AsteriskSCF::Core::Endpoint::V1;
+using namespace ::AsteriskSCF::SessionCommunications::V1;
+using namespace ::AsteriskSCF::SessionCommunications::Bridging::V1;
+using namespace ::AsteriskSCF::BasicRoutingService;
+
+using namespace ::std;
+
+/**
+ * TBD... This code should be refactored for AMD and use AMI on outgoing calls. 
+ */
+namespace AsteriskSCF
+{
+namespace BasicRoutingService
+{
+
+class SessionListenerImpl : public SessionListener
+{
+public:
+   SessionListenerImpl(const SessionPrx& source) : mTerminated(false)
+    {
+       addSession(source);
+    }
+
+    virtual void connected(const SessionPrx& session, const ::Ice::Current& = ::Ice::Current())
+    {
+    }
+
+    virtual void flashed(const SessionPrx& session, const ::Ice::Current& = ::Ice::Current()) 
+    {
+    }
+
+    virtual void held(const SessionPrx& session, const ::Ice::Current& = ::Ice::Current())
+    {
+    }
+
+    virtual void progressing(const SessionPrx& session, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current& = ::Ice::Current())
+    {
+    }
+
+    virtual void ringing(const SessionPrx& session, const ::Ice::Current& = ::Ice::Current())
+    {
+    }
+
+    virtual void stopped(const SessionPrx& session, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& responseCode, const ::Ice::Current& = ::Ice::Current())
+    {
+       mTerminated = true;
+
+       // Forward the stop message to all sessions other than the one that originally sent it.
+       SessionSeq::iterator s;
+       for(s=mSessions.begin(); s != mSessions.end(); ++s)
+       {
+          if (session->ice_getIdentity() != (*s)->ice_getIdentity())
+          {
+             (*s)->stop(responseCode);
+          }
+       }
+
+    }
+
+    virtual void unheld(const SessionPrx& session, const ::Ice::Current& = ::Ice::Current())
+    {
+    }
+
+    void addSession(SessionPrx session)
+    {
+       mSessions.push_back(session);
+       session->addListener(mListenerPrx);
+    }
+    
+    SessionSeq& getSessions()
+    {
+       return mSessions;
+    }
+
+    bool isTerminated() // Lots of shoring up to do for asynchronous operations!
+    {
+       return mTerminated;
+    }
+
+    /**
+     * Stop listening to all sessions we're monitoring. 
+     */
+    void unregister()
+    {
+       SessionSeq::iterator s;
+       for(s=mSessions.begin(); s != mSessions.end(); ++s)
+       {
+          (*s)->removeListener(mListenerPrx);
+       }
+    }
+
+    void setProxy(SessionListenerPrx proxy)
+    {
+       mListenerPrx = proxy;
+    }
+
+    SessionListenerPrx getProxy()
+    {
+       return mListenerPrx;
+    }
+
+private:
+    SessionSeq mSessions;
+    bool mTerminated;
+    SessionListenerPrx mListenerPrx;
+};
+typedef ::IceInternal::Handle<SessionListenerImpl> SessionListenerImplPtr;
+
+class SessionRouterPriv
+{
+public: 
+   SessionRouterPriv()  {}
+   ~SessionRouterPriv()  
+   {
+      for (map<string, SessionListenerImplPtr>::iterator i = mActiveListeners.begin(); i != mActiveListeners.end(); ++i) 
+      {
+         (*i).second->unregister();
+         (*i).second = 0;
+      }
+      mActiveListeners.clear();
+   }
+
+   map<string, SessionListenerImplPtr> mActiveListeners;
+
+   Ice::Identity getListenerId(string sourceId)
+   {
+      return BasicRoutingServiceDataModel::getInstance().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 = BasicRoutingServiceDataModel::getInstance().getObjectAdapter()->addWithUUID(listener);
+         listener->setProxy(SessionListenerPrx::checkedCast(prx));
+
+         mActiveListeners[listener->ice_id()] = listener;
+
+         return listener;
+      }
+      catch(const Ice::Exception &e)
+      {
+         cout << "Unable to create listener. " << e.what() << endl;
+         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 point to null. 
+      mActiveListeners.erase(key);
+   }
+};
+
+SessionRouter::SessionRouter() : mImpl(new SessionRouterPriv())
+{
+}
+
+SessionRouter::~SessionRouter() 
+{
+   mImpl.reset();
+}
+
+/**
+ * Route the session by looking up the destination endpoint and configuring a complimentary session for the destination. 
+ *   TBD - Need to rework with asynch support.
+ */
+void SessionRouter::routeSession(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& source, 
+                                      const ::std::string& destination, 
+                                      const ::Ice::Current& current)
+{
+   // Create a listener for the source to handle early termination. 
+   SessionListenerImplPtr listener = mImpl->createListener(source);
+
+   EndpointSeq endpoints;
+   try
+   {
+      // Lookup the destination. 
+      endpoints = BasicRoutingServiceDataModel::getInstance().getEndpointRegistry().lookup(destination, current);
+
+      if (endpoints.empty())
+      {
+         throw DestinationNotFoundException(destination);
+      }
+   }
+   catch (const DestinationNotFoundException&)
+   {
+      // rethrow
+      throw;
+   }
+   catch (const Ice::Exception &)
+   {
+      // Probably couldn't access the EndpointLocator of the registered channel. 
+      throw EndpointUnreachableException(destination);
+   }
+
+   for (EndpointSeq::iterator e = endpoints.begin(); e != endpoints.end(); ++e) 
+   {
+      try
+      {
+         SessionEndpointPrx sessionEndpoint = SessionEndpointPrx::checkedCast(*e);
+
+         // Create a session on the destination. 
+         SessionPrx destSession = sessionEndpoint->createSession(destination, listener->getProxy());
+         listener->addSession(destSession);
+      }
+      catch(const Ice::Exception &exception)
+      {
+         cout << "Unable to create sessionEndpoint for " << destination << ". " << exception.what() << endl;
+         // We may be able to reach SOME of the endpoints.
+      }
+   }
+
+   if (listener->getSessions().size() < 2)
+   {
+      throw SessionCreationException(destination);
+   }
+
+   if (listener->isTerminated())
+   {
+      mImpl->deleteListener(listener);
+      throw SourceTerminatedPreBridgingException(source->getEndpoint()->getId());
+   }
+
+   // Create the bridge
+   BridgePrx bridge;
+   try
+   {
+      bridge = BasicRoutingServiceDataModel::getInstance().getBridgeManager()->createBridge(listener->getSessions(), 0);
+   }
+   catch (const Ice::Exception &)
+   {
+      listener->unregister();
+      mImpl->deleteListener(listener);
+      
+      throw BridgingException(source->getEndpoint()->getId(), destination);
+   }
+
+   // Forward the start to all the destinations routed to.
+   SessionSeq sessions = listener->getSessions();
+   SessionSeq::iterator s;
+   for (s=sessions.begin(); s != sessions.end(); ++s)
+   {
+      try
+      {
+         if (source->ice_getIdentity() != (*s)->ice_getIdentity())
+         {
+            (*s)->start();
+         }
+      }
+      catch (const Ice::Exception &)
+      {
+          mImpl->deleteListener(listener);
+          // TBD... probably other bridge cleanup needs to be done.
+          throw;
+      }
+   }
+  
+   // We're done with the listener.
+   mImpl->deleteListener(listener);
+}
+
+}; // end BasicRoutingService
+}; // end AsteriskSCF
\ No newline at end of file
diff --git a/src/SessionRouter.h b/src/SessionRouter.h
new file mode 100644
index 0000000..0b2647b
--- /dev/null
+++ b/src/SessionRouter.h
@@ -0,0 +1,43 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include "SessionCommunicationsIf.h"
+
+namespace AsteriskSCF
+{
+namespace BasicRoutingService
+{
+class SessionRouterPriv;
+
+/**
+ * This class routes sessions. 
+ */
+class SessionRouter : public AsteriskSCF::SessionCommunications::V1::SessionRouter
+{
+public:
+   SessionRouter();
+   ~SessionRouter();
+
+public:  
+    // SessionRouter overrides
+
+   /**
+    * Execute the routing functionality for the given session. 
+    */
+   virtual void routeSession(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& source, 
+                             const ::std::string& destination, 
+                             const ::Ice::Current& = ::Ice::Current());
+private: 
+   boost::shared_ptr<SessionRouterPriv> mImpl;
+};
+
+}; // end BasicRoutingService
+}; // end AsteriskSCF
\ No newline at end of file

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list