[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Oct 6 14:05:23 CDT 2010
branch "master" has been updated
via 2ff8d2a251abf609d08a3f2db714d4f76e8c8ac8 (commit)
from 3a1fe7ff546ca1ed5fe5abb40f6058fbc28ad817 (commit)
Summary of changes:
logger | 2 +-
src/CMakeLists.txt | 2 +-
src/Service.cpp | 146 +++++++++++++++++++++++++++++++++++++++++++++++----
test/CMakeLists.txt | 1 +
4 files changed, 138 insertions(+), 13 deletions(-)
- Log -----------------------------------------------------------------
commit 2ff8d2a251abf609d08a3f2db714d4f76e8c8ac8
Author: Brent Eagles <beagles at digium.com>
Date: Wed Oct 6 16:34:16 2010 -0230
Add missing linker command and make service startup a little more forgiving
with respect to the service discovery services (still needs icestorm tolerance)
diff --git a/logger b/logger
index 0cc0c02..a867306 160000
--- a/logger
+++ b/logger
@@ -1 +1 @@
-Subproject commit 0cc0c02a16e404b94d54c8cb6736dee14a671352
+Subproject commit a867306cbc5dce5b0cd899094b3215921f0263d3
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d59b09a..8236292 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -26,4 +26,4 @@ include_directories(${logger_dir}/common)
include_directories(${logger_dir}/client/src)
hydra_component_build_icebox(bridgeservice)
-
+target_link_libraries(bridgeservice logging-client)
diff --git a/src/Service.cpp b/src/Service.cpp
index e0899a8..cf8582c 100644
--- a/src/Service.cpp
+++ b/src/Service.cpp
@@ -21,10 +21,115 @@ namespace
{
Logger &lg = getLoggerFactory().getLogger(
"AsteriskSCF.BridgeService");
-}
static const std::string ManagerName = "BridgeManager";
+class ServiceLocatorWrapper : public IceUtil::Shared
+{
+public:
+ ServiceLocatorWrapper(const Ice::CommunicatorPtr& communicator, const std::string& proxyString, const AsteriskSCF::SessionCommunications::Bridging::V1::BridgeManagerPrx& bridge,
+ const std::string& name) :
+ mCommunicator(communicator),
+ mProxyString(proxyString),
+ mBridgeManager(bridge),
+ mName(name)
+ {
+ }
+
+ bool registerBridgeManager()
+ {
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx management =
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx::checkedCast(mCommunicator->stringToProxy(mProxyString));
+ if(management)
+ {
+ IceUtil::Mutex::Lock lock(mLock);
+ mServiceManagement = AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(management->addService(mBridgeManager, mName));
+ if(mServiceManagement)
+ {
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params = new AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams();
+ params->category = AsteriskSCF::SessionCommunications::Bridging::V1::BridgeServiceDiscoveryCategory;
+ mServiceManagement->addLocatorParams(params, "");
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void unregister()
+ {
+ {
+ IceUtil::Mutex::Lock lock(mLock);
+ if(!mServiceManagement)
+ {
+ return;
+ }
+ }
+ mServiceManagement->unregister();
+ }
+
+private:
+
+ IceUtil::Mutex mLock;
+ Ice::CommunicatorPtr mCommunicator;
+ std::string mProxyString;
+ AsteriskSCF::SessionCommunications::Bridging::V1::BridgeManagerPrx mBridgeManager;
+ std::string mName;
+ AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx mServiceManagement;
+};
+typedef IceUtil::Handle<ServiceLocatorWrapper> ServiceLocatorWrapperPtr;
+
+//
+// This thread takes care of registering the bridge if the service discovery components are unavailable during startup.
+//
+class RegisterThread : public IceUtil::Thread
+{
+public:
+ RegisterThread(const ServiceLocatorWrapperPtr& locator) :
+ mLocator(locator),
+ mStopped(false)
+ {
+ }
+
+ void run()
+ {
+ bool result = false;
+ do
+ {
+ //
+ // TODO: Make configurable.
+ //
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mMonitor);
+ mMonitor.timedWait(IceUtil::Time::seconds(60));
+ if(mStopped)
+ {
+ break;
+ }
+ try
+ {
+ result = mLocator->registerBridgeManager();
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ }
+ while(result == false);
+ }
+
+ void stop()
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mMonitor);
+ mStopped = true;
+ mMonitor.notify();
+ }
+
+private:
+ IceUtil::Monitor<IceUtil::Mutex> mMonitor;
+ ServiceLocatorWrapperPtr mLocator;
+ bool mStopped;
+};
+
+typedef IceUtil::Handle<RegisterThread> RegisterThreadPtr;
+
class BridgingApp : public IceBox::Service
{
public:
@@ -38,8 +143,9 @@ private:
/**
* A proxy to the service locator manager for the bridge manager service.
*/
- AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx mServiceManagement;
+ ServiceLocatorWrapperPtr mLocator;
Ice::ObjectAdapterPtr mAdapter;
+ RegisterThreadPtr mRegisterThread;
};
BridgingApp::BridgingApp()
@@ -73,20 +179,38 @@ void BridgingApp::start(const std::string& name, const Ice::CommunicatorPtr& com
mAdapter->add(servant, id);
mAdapter->activate();
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx management =
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx::checkedCast(communicator->propertyToProxy("ServiceLocatorManagementProxy"));
- mServiceManagement = AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(management->addService(s, adapterName));
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params = new AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams();
- params->category = AsteriskSCF::SessionCommunications::Bridging::V1::BridgeServiceDiscoveryCategory;
- mServiceManagement->addLocatorParams(params, "");
+ std::string property = communicator->getProperties()->getProperty("ServiceLocatorManagementProxy");
+ if(property.size() == 0)
+ {
+ throw IceBox::FailureException(__FILE__, __LINE__, "Configuration error: Unable to locate property `ServiceLocatorManagementProxy'");
+ }
+
+ bool registered = false;
+ try
+ {
+ mLocator = new ServiceLocatorWrapper(communicator, property, s, adapterName);
+ registered = mLocator->registerBridgeManager();
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ if(!registered)
+ {
+ mRegisterThread = new RegisterThread(mLocator);
+ mRegisterThread->start();
+ }
}
void BridgingApp::stop()
{
- mServiceManagement->unregister();
- mAdapter->deactivate();
+ if(mRegisterThread)
+ {
+ mRegisterThread->stop();
+ }
+ mLocator->unregister();
+ mAdapter->deactivate();
+}
}
-
extern "C" {
HYDRA_ICEBOX_EXPORT ::IceBox::Service* create(Ice::CommunicatorPtr communicator)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 31b63c4..f200682 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -27,4 +27,5 @@ include_directories(${logger_dir}/common)
include_directories(${logger_dir}/client/src)
hydra_component_build_icebox(bridging_unit_test)
+target_link_libraries(bridging_unit_test logging-client)
boost_add_test(bridging_unit_test)
-----------------------------------------------------------------------
--
asterisk-scf/integration/bridging.git
More information about the asterisk-scf-commits
mailing list