[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
Thu Oct 7 13:48:45 CDT 2010
branch "master" has been updated
via d6c7c8c4a4bf3a254ea2b6d9a4f1fffe2fcf530b (commit)
from af210fdef0c282046a39317bf8d577230eb3f6c8 (commit)
Summary of changes:
config/basicrouting.config | 4 +-
src/BasicRoutingServiceApp.cpp | 153 ++++++++++++++++++++++++---------------
src/CMakeLists.txt | 2 +-
3 files changed, 98 insertions(+), 61 deletions(-)
- Log -----------------------------------------------------------------
commit d6c7c8c4a4bf3a254ea2b6d9a4f1fffe2fcf530b
Author: Ken Hunt <ken.hunt at digium.com>
Date: Thu Oct 7 13:35:12 2010 -0500
Conversion to IceBox service.
diff --git a/config/basicrouting.config b/config/basicrouting.config
index d4a2594..ae9cc08 100644
--- a/config/basicrouting.config
+++ b/config/basicrouting.config
@@ -1,8 +1,10 @@
# This is a configuration file for the Basic Routing Service
-# Endpoints for the adapter
+IceBox.Service.BasicRoutingService=BasicRoutingService:create --Ice.Config=config/basicrouting.config
+
BasicRoutingServiceAdapter.Endpoints=tcp -p 10050
+
BasicRoutingServiceAdapter.ThreadPool.Size=4
BasicRoutingServiceAdapter.ThreadPool.SizeMax=10
BasicRoutingServiceAdapter.ThreadPool.SizeWarn=9
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index 15d2481..4ca3de5 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -6,7 +6,7 @@
* All rights reserved.
*/
#include <Ice/Ice.h>
-#include <IceStorm/IceStorm.h>
+#include <IceBox/IceBox.h>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
@@ -46,10 +46,10 @@ namespace AsteriskSCF
namespace BasicRoutingService
{
-class BasicRoutingServiceApp : public Ice::Application
+class BasicRoutingServiceApp : public IceBox::Service
{
public:
- BasicRoutingServiceApp() : mDone(false), mPaused(false) {}
+ BasicRoutingServiceApp() : mDone(false), mInitialized(false), mRunning(false) {}
~BasicRoutingServiceApp()
{
// Smart pointers do your thing.
@@ -61,22 +61,17 @@ public:
mEventPublisher = 0;
}
- bool isPaused()
- {
- return mPaused;
- }
-
- void setPaused(bool val)
- {
- mPaused = val;
- }
+ void resume();
+ void suspend();
-public: // Overrides of Ice::Application
- virtual int run(int, char*[]);
- virtual void interruptCallback(int);
+public: // Overrides of IceBox::Service
+ virtual void start(const string& name,
+ const Ice::CommunicatorPtr& ic,
+ const Ice::StringSeq& args);
+ virtual void stop();
private:
- void initialize(const std::string appName);
+ void initialize();
void registerWithServiceLocator();
void deregisterFromServiceLocator();
void setCategory(Discovery::V1::ServiceManagementPrx serviceManagement, const string &category);
@@ -101,7 +96,9 @@ private:
// Implementation
Ice::ObjectAdapterPtr mAdapter;
- bool mPaused;
+ Ice::CommunicatorPtr mCommunicator;
+ bool mRunning;
+ bool mInitialized;
};
static const string RegistryLocatorObjectId("RoutingServiceLocatorRegistry");
@@ -121,17 +118,17 @@ public:
public: // Overrides of the ComponentService interface.
virtual void suspend(const ::Ice::Current& = ::Ice::Current())
{
- mApp.setPaused(true);
+ mApp.suspend();
}
virtual void resume(const ::Ice::Current& = ::Ice::Current())
{
- mApp.setPaused(false);
+ mApp.resume();
}
virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
{
- mApp.interruptCallback(EXIT_SUCCESS);
+ mApp.stop();
}
private:
@@ -139,18 +136,6 @@ private:
};
/**
- * Handles control characters in case the component is invoked as a console app.
- */
-void BasicRoutingServiceApp::interruptCallback(int val)
-{
- lg(Info) << "Exiting...";
- mDone = true;
- // Remove our interfaces from the service locator.
- deregisterFromServiceLocator();
- _exit(EXIT_SUCCESS);
-}
-
-/**
* Helper function to add some parameters to one of our registered interfaces in the ServiceLocator, so that
* other components can look up our interfaces.
*/
@@ -171,7 +156,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
try
{
// 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"));
+ mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(mCommunicator->propertyToProxy("LocatorServiceManagement.Proxy"));
if (mServiceLocatorManagement == 0)
{
@@ -180,7 +165,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
}
// Register our RoutingAdmin interface with the Service Locator.
- Ice::ObjectPrx adminObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(RoutingAdminObjectId));
+ Ice::ObjectPrx adminObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(RoutingAdminObjectId));
RoutingServiceAdminPrx adminPrx = RoutingServiceAdminPrx::checkedCast(adminObjectPrx);
string adminServiceGuid("BasicRoutingServiceAdmin"); // Should be unique for reporting.
mAdminManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(adminPrx, adminServiceGuid));
@@ -188,7 +173,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
setCategory(mAdminManagement, Routing::V1::RoutingServiceAdminDiscoveryCategory);
// Register our RegistryLocator interface with the Service Locator.
- Ice::ObjectPrx locatorObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(RegistryLocatorObjectId));
+ Ice::ObjectPrx locatorObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(RegistryLocatorObjectId));
LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::checkedCast(locatorObjectPrx);
string locatorServiceGuid("BasicRoutingServiceRegistryLocator"); // Should be unique for reporting.
mRegistryLocatorManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(locatorRegistryPrx, locatorServiceGuid));
@@ -196,7 +181,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
setCategory(mRegistryLocatorManagement, Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);
// Register the ComponentService interface with the Service Locator.
- Ice::ObjectPrx componentServiceObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(ComponentServiceId));
+ Ice::ObjectPrx componentServiceObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(ComponentServiceId));
ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
string componentServiceGuid("BasicRoutingService"); // Should be unique for reporting.
mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
@@ -204,7 +189,7 @@ void BasicRoutingServiceApp::registerWithServiceLocator()
setCategory(mComponentServiceManagement, Routing::V1::ComponentServiceDiscoveryCategory);
// Register the SessionRouter interface with the Service Locator.
- Ice::ObjectPrx sessionRouterObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(SessionRouterObjectId));
+ Ice::ObjectPrx sessionRouterObjectPrx = mAdapter->createDirectProxy(mCommunicator->stringToIdentity(SessionRouterObjectId));
AsteriskSCF::SessionCommunications::V1::SessionRouterPrx sessionRouterPrx = AsteriskSCF::SessionCommunications::V1::SessionRouterPrx::checkedCast(sessionRouterObjectPrx);
string sessionRouterGuid("SessionRouter"); // Should be unique
mSessionRouterManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(sessionRouterPrx, sessionRouterGuid));
@@ -241,14 +226,12 @@ void BasicRoutingServiceApp::deregisterFromServiceLocator()
* Create the primary functional objects of this component.
* @param appName Name of the application or component.
*/
-void BasicRoutingServiceApp::initialize(const std::string appName)
+void BasicRoutingServiceApp::initialize()
{
try
{
- mAppName = appName;
-
// Create the adapter.
- mAdapter = communicator()->createObjectAdapter("BasicRoutingServiceAdapter");
+ mAdapter = mCommunicator->createObjectAdapter("BasicRoutingServiceAdapter");
mEventPublisher = new RoutingServiceEventPublisher(mAdapter);
@@ -261,26 +244,28 @@ void BasicRoutingServiceApp::initialize(const std::string appName)
mEndpointRegistry = new EndpointRegistry(scriptProcesor, mEventPublisher);
// Publish the LocatorRegistry interface.
- mAdapter->add(mEndpointRegistry, communicator()->stringToIdentity(RegistryLocatorObjectId));
+ mAdapter->add(mEndpointRegistry, mCommunicator->stringToIdentity(RegistryLocatorObjectId));
// Create publish the SessionRouter interface.
SessionRouter *rawSessionRouter(new SessionRouter(mAdapter, mEndpointRegistry, mEventPublisher));
BasicSessionRouterPtr basicSessionPtr(rawSessionRouter);
mSessionRouter = basicSessionPtr;
- mAdapter->add(rawSessionRouter, communicator()->stringToIdentity(SessionRouterObjectId));
+ mAdapter->add(rawSessionRouter, mCommunicator->stringToIdentity(SessionRouterObjectId));
// Create and publish the Admin interface support.
mAdminInteface = new RoutingAdmin(mEndpointRegistry);
- mAdapter->add(mAdminInteface, communicator()->stringToIdentity(RoutingAdminObjectId));
+ mAdapter->add(mAdminInteface, mCommunicator->stringToIdentity(RoutingAdminObjectId));
// Create and publish the ComponentService interface.
mComponentService = new ComponentServiceImpl(*this);
- mAdapter->add(mComponentService, communicator()->stringToIdentity(ComponentServiceId));
+ mAdapter->add(mComponentService, mCommunicator->stringToIdentity(ComponentServiceId));
mAdapter->activate();
// Get a proxy to the interface for the Service Locator.
- mServiceLocator = ServiceLocatorPrx::checkedCast(communicator()->propertyToProxy("LocatorService.Proxy"));
+ mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
+
+ mInitialized = true;
}
catch(const Ice::Exception &exception)
{
@@ -299,32 +284,82 @@ void BasicRoutingServiceApp::initialize(const std::string appName)
}
/**
- * Overload of the Ice::Application::run method.
+ * Implementation of the required IceBox::Service start method.
*/
-int BasicRoutingServiceApp::run(int argc, char* argv[])
+void BasicRoutingServiceApp::start(const string& name,
+ const Ice::CommunicatorPtr& communicator,
+ const Ice::StringSeq& args)
{
- callbackOnInterrupt();
+ lg(Info) << "Starting...";
- // Initialize this component.
- initialize(argv[0]);
+ mCommunicator = communicator;
+ mAppName = name;
- // Plug into the Asterisk SCF discovery system so that the interfaces we provide
+ if (!mInitialized)
+ {
+ initialize();
+ }
+ else
+ {
+ mAdapter->activate();
+ }
+
+ // Plug back into the Asterisk SCF discovery system so that the interfaces we provide
// can be located.
registerWithServiceLocator();
- // Run until it's time to run no more.
- communicator()->waitForShutdown();
+ mRunning = true;
+ lg(Info) << "Started";
+}
+
+/**
+ * Things we do to resume operation after a pause().
+ */
+void BasicRoutingServiceApp::resume()
+{
+ if (!mRunning)
+ {
+ mAdapter->activate();
+
+ // Plug back into the Asterisk SCF discovery system so that the interfaces we provide
+ // can be located.
+ registerWithServiceLocator();
+ }
- return EXIT_SUCCESS;
+ mRunning = true;
}
+void BasicRoutingServiceApp::suspend()
+{
+ stop();
+}
+
+/**
+ * Implementation of the required IceBox::Service stop method.
+ */
+void BasicRoutingServiceApp::stop()
+{
+ lg(Info) << "Stopping...";
+
+ if (mRunning)
+ {
+ deregisterFromServiceLocator();
+ mAdapter->deactivate();
+ }
+
+ mRunning = false;
+ lg(Info) << "Stopped.";
+}
+
+
}; // end BasicRoutingService
}; // end AsteriskSCF
-static BasicRoutingServiceApp app;
-// Application entry point.
-int main(int argc, char* argv[])
+extern "C"
{
- return app.main(argc, argv);
+ HYDRA_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr communicator)
+ {
+ return new AsteriskSCF::BasicRoutingService::BasicRoutingServiceApp();
+ }
}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f1bac0f..06f770f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -32,7 +32,7 @@ endif()
include_directories(${logger_dir}/common)
include_directories(${logger_dir}/client/src)
-hydra_component_build_standalone(BasicRoutingService)
+hydra_component_build_icebox(BasicRoutingService)
target_link_libraries(BasicRoutingService ${LUA_LIBRARIES})
target_link_libraries(BasicRoutingService logging-client)
-----------------------------------------------------------------------
--
asterisk-scf/integration/routing.git
More information about the asterisk-scf-commits
mailing list