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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Dec 6 18:05:05 CST 2010


branch "master" has been updated
       via  a5a2987c5fbbb78bca98f2cc4c7f94e99d332fdc (commit)
      from  e971cf16fcd669f6fbec5b48ff2c36aca9e1ad6a (commit)

Summary of changes:
 src/BasicRoutingServiceApp.cpp |   16 +++--
 src/BridgeManagerAccessor.cpp  |  134 ----------------------------------------
 src/BridgeManagerAccessor.h    |   48 --------------
 src/CMakeLists.txt             |    4 +-
 src/SessionRouter.cpp          |   38 ++++++++----
 src/SessionRouter.h            |    6 +-
 6 files changed, 40 insertions(+), 206 deletions(-)
 delete mode 100644 src/BridgeManagerAccessor.cpp
 delete mode 100644 src/BridgeManagerAccessor.h


- Log -----------------------------------------------------------------
commit a5a2987c5fbbb78bca98f2cc4c7f94e99d332fdc
Author: David M. Lee <dlee at digium.com>
Date:   Fri Dec 3 13:35:12 2010 -0600

    BridgeManagerAccessor -> SmartProxy.

diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index 6b2684e..3920cc2 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -19,6 +19,7 @@
 #include <boost/thread.hpp>
 #include <boost/shared_ptr.hpp>
 
+#include "SmartProxy.h"
 #include "Core/Routing/RoutingIf.h"
 #include "Core/Discovery/ServiceLocatorIf.h"
 #include "SessionCommunications/SessionCommunicationsIf.h"
@@ -39,6 +40,7 @@ using namespace AsteriskSCF::Core::Routing::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::System::Component::V1;
 using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::SmartProxy;
 
 namespace
 {
@@ -66,7 +68,6 @@ public:
         mAdminInteface = 0;
         mComponentService = 0;
         mEndpointRegistry = 0;
-        mBridgeManagerAccessor.reset();
         mEventPublisher = 0;
         // XXX unnecessary.
     }
@@ -101,7 +102,7 @@ private:
     BasicSessionRouterPtr mSessionRouter;
     RoutingServiceAdminPtr mAdminInteface;
     ComponentServicePtr mComponentService;
-    BridgeManagerAccessorPtr mBridgeManagerAccessor;
+    AsteriskSCF::SmartProxy::SmartProxy<BridgeManagerPrx> mBridgeManager;
     RoutingEventsPtr mEventPublisher;
     EndpointRegistryPtr mEndpointRegistry;
 
@@ -285,12 +286,13 @@ void BasicRoutingServiceApp::initialize()
         lg(Error) << "Problems in " << mAppName << " initialization(): " << exception.what();
     }
 
+    mBridgeManager = AsteriskSCF::SmartProxy::SmartProxy<BridgeManagerPrx>(
+        mServiceLocator,
+        new ServiceLocatorParams(BridgeServiceDiscoveryCategory),
+        lg);
+    mSessionRouter->setBridgeManager(mBridgeManager);
 
-    BridgeManagerAccessorPtr ptr(new BridgeManagerAccessor(mServiceLocator));
-    mBridgeManagerAccessor = ptr;
-    mSessionRouter->setBridgeManagerAccessor(mBridgeManagerAccessor);
-
-    if (!mBridgeManagerAccessor->isInitialized())
+    if (!mBridgeManager.isInitialized())
     {
         lg(Debug) << "Probabaly safe to ignore ServiceNotFound during startup. Will attempt to locate Bridge Service again when it is needed.";
     }
diff --git a/src/BridgeManagerAccessor.cpp b/src/BridgeManagerAccessor.cpp
deleted file mode 100644
index ab85026..0000000
--- a/src/BridgeManagerAccessor.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-#include <Ice/Ice.h>
-#include <IceStorm/IceStorm.h>
-
-#include "Core/Discovery/ServiceLocatorIf.h"
-#include "SessionCommunications/SessionCommunicationsIf.h"
-#include "BridgeManagerAccessor.h"
-
-using namespace std;
-using namespace AsteriskSCF::Core::Discovery::V1;
-using namespace AsteriskSCF::SessionCommunications::V1;
-
-namespace AsteriskSCF
-{
-namespace BasicRoutingService
-{
-
-/**
- * The private implementation of BridgeManagerAccessor.
- */
-class BridgeManagerAccessorPriv
-{
-public:
-    BridgeManagerAccessorPriv(const ServiceLocatorPrx& locator) :
-        mServiceLocator(locator), mInitialized(false)
-    {
-        initialize();
-    }
-
-    /**
-     * Initialization. Primarily involves acquring access to specific IceStorm topic.
-     */
-    void initialize()
-    {
-        try
-        {
-            // Use the locator to find the BridgeManger.
-            ServiceLocatorParamsPtr nameparam = new ServiceLocatorParams;
-            nameparam->category = BridgeServiceDiscoveryCategory;
-            Ice::ObjectPrx bridgeManagerObject = mServiceLocator->locate(nameparam);
-            mBridgeManager = BridgeManagerPrx::checkedCast(bridgeManagerObject);
-        }
-        catch(const Ice::Exception &e)
-        {
-            cout << "Exception locating " << BridgeServiceDiscoveryCategory << ": " << e.what() << endl;
-            return;
-        }
-
-        if (mBridgeManager == 0)
-        {
-            cout << "Unable to locate " << BridgeServiceDiscoveryCategory << endl;
-        }
-
-        mInitialized = true;
-    }
-
-    /**
-     * Utiltity to check for initialization state.
-     */
-    bool verifyInitialized()
-    {
-        if (mInitialized)
-        {
-            return true;
-        }
-
-        // Try again to initialize.
-        initialize();
-
-        if (!mInitialized)
-        {
-            // TBD...Logging
-            cerr << "Routing Service can't locate BridgeManager at this time." << endl;
-        }
-
-        return mInitialized;
-    }
-
-    bool isInitialized()
-    {
-        return mInitialized;
-    }
-
-public:
-    BridgeManagerPrx mBridgeManager;
-
-private:
-    ServiceLocatorPrx mServiceLocator;
-    bool mInitialized;
-};
-
-/**
- * Class constructor.
- */
-BridgeManagerAccessor::BridgeManagerAccessor(const ServiceLocatorPrx& locator) :
-    mImpl(new BridgeManagerAccessorPriv(locator))
-{
-}
-
-/**
- * Provide acess to the actual proxy.
- */
-const BridgeManagerPrx& BridgeManagerAccessor::getBridgeManager() const
-{
-    if (!mImpl->verifyInitialized())
-    {
-        throw "No access to BridgeManager.";
-    }
-
-    return mImpl->mBridgeManager;
-}
-
-bool BridgeManagerAccessor::isInitialized()
-{
-    return mImpl->isInitialized();
-}
-
-} // end BasicRoutingService
-} // end AsteriskSCF
-
diff --git a/src/BridgeManagerAccessor.h b/src/BridgeManagerAccessor.h
deleted file mode 100644
index 0892930..0000000
--- a/src/BridgeManagerAccessor.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-#pragma once
-
-#include <Ice/Ice.h>
-#include <boost/shared_ptr.hpp>
-
-#include "Core/Discovery/ServiceLocatorIf.h"
-#include "SessionCommunications/SessionCommunicationsIf.h"
-
-namespace AsteriskSCF
-{
-namespace BasicRoutingService
-{
-class BridgeManagerAccessorPriv;
-
-/**
- * A wrapper for the Bridge Manager proxy.
- */
-class BridgeManagerAccessor
-{
-public:
-    BridgeManagerAccessor(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator);
-
-    const SessionCommunications::V1::BridgeManagerPrx& getBridgeManager() const;
-    bool isInitialized();
-
-private:
-    boost::shared_ptr<BridgeManagerAccessorPriv> mImpl; // pimpl idiom applied.
-};
-
-typedef boost::shared_ptr<BridgeManagerAccessor> BridgeManagerAccessorPtr;
-
-} // end BasicRoutingService
-} // end AsteriskSCF
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0a3f840..0d8cbfc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,8 +19,6 @@ asterisk_scf_component_add_file(BasicRoutingService LuaScriptProcessor.cpp)
 asterisk_scf_component_add_file(BasicRoutingService LuaScriptProcessor.h)
 asterisk_scf_component_add_file(BasicRoutingService RoutingServiceEventPublisher.cpp)
 asterisk_scf_component_add_file(BasicRoutingService RoutingServiceEventPublisher.h)
-asterisk_scf_component_add_file(BasicRoutingService BridgeManagerAccessor.cpp)
-asterisk_scf_component_add_file(BasicRoutingService BridgeManagerAccessor.h)
 
 asterisk_scf_component_add_ice_libraries(BasicRoutingService IceStorm)
 asterisk_scf_component_add_boost_libraries(BasicRoutingService thread core regex)
@@ -31,6 +29,8 @@ endif()
 include_directories(${logger_dir}/common)
 include_directories(${logger_dir}/client/src)
 
+include_directories(${utils_dir}/SmartProxy/src)
+
 asterisk_scf_component_build_icebox(BasicRoutingService)
 target_link_libraries(BasicRoutingService ${LUA_LIBRARIES})
 target_link_libraries(BasicRoutingService logging-client)
diff --git a/src/SessionRouter.cpp b/src/SessionRouter.cpp
index ce6a266..26b54ad 100644
--- a/src/SessionRouter.cpp
+++ b/src/SessionRouter.cpp
@@ -21,7 +21,6 @@
 #include "RoutingIf.h"
 #include "EndpointIf.h"
 #include "logger.h"
-#include "BridgeManagerAccessor.h"
 
 using namespace AsteriskSCF::Core::Routing::V1;
 using namespace AsteriskSCF::Core::Endpoint::V1;
@@ -393,15 +392,16 @@ public:
     }
 
     /**
-     * Set the accessor to the bridge. 
+     * Set the accessor to the bridge.
      */
-    void setBridgeAccessor(BridgeManagerAccessorPtr bridgeAccessor)
+    void setBridgeAccessor(const AsteriskSCF::SmartProxy::SmartProxy<
+            SessionCommunications::V1::BridgeManagerPrx>&  bridgeAccessor)
     {
-        mBridgeManagerAccessor = bridgeAccessor;
+        mBridgeManager = bridgeAccessor;
     }
 
     /**
-     * Do a lookup of the requested endpoint. 
+     * Do a lookup of the requested endpoint.
      */
     EndpointSeq lookupEndpoints(const std::string& destination, const Ice::Current& current)
     {
@@ -587,7 +587,8 @@ public:
     Ice::ObjectAdapterPtr mAdapter;
     EndpointRegistryPtr mEndpointRegistry;
     RoutingEventsPtr mEventPublisher;
-    BridgeManagerAccessorPtr mBridgeManagerAccessor;
+    AsteriskSCF::SmartProxy::SmartProxy<
+        SessionCommunications::V1::BridgeManagerPrx> mBridgeManager;
 };
 
 SessionRouter::SessionRouter(const Ice::ObjectAdapterPtr& objectAdapter, const EndpointRegistryPtr& endpointRegistry,
@@ -601,20 +602,31 @@ SessionRouter::~SessionRouter()
     mImpl.reset();
 }
 
-void SessionRouter::setBridgeManagerAccessor(const BridgeManagerAccessorPtr& bridgeAccessor)
+void SessionRouter::setBridgeManager(
+    const AsteriskSCF::SmartProxy::SmartProxy<
+        SessionCommunications::V1::BridgeManagerPrx>& bridgeAccessor)
 {
-    mImpl->mBridgeManagerAccessor = bridgeAccessor;
+    mImpl->mBridgeManager = bridgeAccessor;
 }
 
 /**
  * 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,
+void SessionRouter::routeSession(
+    const AsteriskSCF::SessionCommunications::V1::SessionPrx& source,
+    const std::string& destination,
     const Ice::Current& current)
 {
     lg(Debug) << "routeSession() entered with destination " << destination ;
 
+    if (!mImpl->mBridgeManager.initializeOnce())
+    {
+        lg(Error) << "No proxy to BridgeManager.  "
+            "Make sure all services are running.";
+        throw BridgingException(source->getEndpoint()->getId(), destination);
+    }
+
     // Create a listener for the source to handle early termination.
     // The wrapper we're using will remove the listener and free it when
     // this method is left.
@@ -624,7 +636,7 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
     lg(Debug) << "routeSession(): Routing destination " << destination;
     EndpointSeq endpoints = mImpl->lookupEndpoints(destination, current);
 
-    // Add a session to the endpoints. 
+    // Add a session to the endpoints.
     SessionSeq newSessions = mImpl->createSessionForEndpoints(endpoints, destination, listener);
 
     if (listener->getNumSessions() < 2)
@@ -637,8 +649,8 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
         throw SourceTerminatedPreBridgingException(source->getEndpoint()->getId());
     }
 
-    // We're through listening, and we will probably interfere with the Bridge's functionality if
-    // we keep listening.
+    // We're through listening, and we will probably interfere with the
+    // Bridge's functionality if we keep listening.
     listener->unregister();
 
     // Create the bridge
@@ -652,7 +664,7 @@ void SessionRouter::routeSession(const AsteriskSCF::SessionCommunications::V1::S
         bridgedSessions.insert(bridgedSessions.end(), newSessions.begin(), newSessions.end());
 
         lg(Debug) << "routeSession(): Creating bridge.";
-        bridge = mImpl->mBridgeManagerAccessor->getBridgeManager()->createBridge(bridgedSessions, 0);
+        bridge = mImpl->mBridgeManager->createBridge(bridgedSessions, 0);
     }
     catch (const Ice::Exception &e)
     {
diff --git a/src/SessionRouter.h b/src/SessionRouter.h
index 3453436..d955519 100644
--- a/src/SessionRouter.h
+++ b/src/SessionRouter.h
@@ -18,8 +18,8 @@
 #include <Ice/Ice.h>
 #include <boost/shared_ptr.hpp>
 
+#include "SmartProxy.h"
 #include "SessionCommunications/SessionCommunicationsIf.h"
-#include "BridgeManagerAccessor.h"
 #include "EndpointRegistry.h"
 
 namespace AsteriskSCF
@@ -38,7 +38,9 @@ public:
         const AsteriskSCF::Core::Routing::V1::Event::RoutingEventsPtr& eventPublisher);
     ~SessionRouter();
 
-    void setBridgeManagerAccessor(const BridgeManagerAccessorPtr& bridgeAccessor);
+    void setBridgeManager(
+        const AsteriskSCF::SmartProxy::SmartProxy<
+            SessionCommunications::V1::BridgeManagerPrx>& bridgeAccessor);
 
 public:
     // SessionRouter overrides

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


-- 
asterisk-scf/release/routing.git



More information about the asterisk-scf-commits mailing list