[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
Wed Aug 18 19:53:27 CDT 2010
branch "master" has been updated
via 5fe2c81a2a762bb857f6a35ecf28bcd9ab414bfc (commit)
from b49daf3aafd6328def263508c4a00c44d0b4d70d (commit)
Summary of changes:
src/BasicRoutingServiceApp.cpp | 216 +++++++++++++++++++++++++++++++++++-----
src/CMakeLists.txt | 3 +
2 files changed, 193 insertions(+), 26 deletions(-)
- Log -----------------------------------------------------------------
commit 5fe2c81a2a762bb857f6a35ecf28bcd9ab414bfc
Author: Ken Hunt <ken.hunt at digium.com>
Date: Wed Aug 18 19:50:32 2010 -0500
Added the ServiceLocator registration.
Added the ComponentService interface implementation.
diff --git a/src/BasicRoutingServiceApp.cpp b/src/BasicRoutingServiceApp.cpp
index 3cddc8f..014f48c 100644
--- a/src/BasicRoutingServiceApp.cpp
+++ b/src/BasicRoutingServiceApp.cpp
@@ -4,8 +4,10 @@
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
-#include "BasicRoutingServiceDataModel.h"
#include "RoutingIf.h"
+#include "ServiceLocatorIf.h"
+#include "ComponentServiceIf.h"
+#include "BasicRoutingServiceDataModel.h"
#include "LuaScriptProcessor.h"
#include "RoutingServiceEventPublisher.h"
#include "EndpointRegistry.h"
@@ -13,18 +15,23 @@
using namespace std;
using namespace Hydra::BasicRoutingService;
+using namespace Hydra::Core;
using namespace Hydra::Core::Routing::V1;
+using namespace Hydra::Core::Discovery::V1;
+using namespace Hydra::System::Component::V1;
namespace Hydra
{
namespace BasicRoutingService
{
/**
- * Private implementation of the BasicRoutingServiceDataModel singleton.
+ * Private implementation of the BasicRoutingServiceDataModel singleton. This
+ * object provides access to the data model of the component.
*/
class BasicRoutingServiceDataModelImpl : public BasicRoutingServiceDataModel
{
-public:
+public: // Overrides of the BasicRoutingServiceDataModel singleton's public interface.
+
virtual const Ice::CommunicatorPtr getCommunicator()
{
return mCommunicator;
@@ -40,6 +47,7 @@ public:
return *mEndpointRegistry;
}
+public: // Implementation details are visible on to this file's classes.
/**
* Cleanup the dangling cruft.
*/
@@ -57,68 +65,222 @@ public:
Ice::CommunicatorPtr mCommunicator;
RoutingServiceEventPublisher *mEventPublisher;
EndpointRegistry *mEndpointRegistry;
+ bool mPaused;
+
+ BasicRoutingServiceDataModelImpl() : mPaused(false) {}
};
-static BasicRoutingServiceDataModelImpl mDataModelInstance;
+BasicRoutingServiceDataModelImpl mDataModelInstance;
BasicRoutingServiceDataModel& BasicRoutingServiceDataModel::getInstance()
{
return mDataModelInstance;
}
/**
- * This private class defines the service's main entry point.
+ * This private class initializes the startup and controls the shutdown of the component.
*/
class BasicRoutingServiceApp : public Ice::Application
{
public:
BasicRoutingServiceApp() : mDone(false) {}
+ ~BasicRoutingServiceApp()
+ {
+ mLocatorRegistry = 0;
+ mAdminInteface = 0;
+ }
- // Overrides
+public: // Overrides of Ice::Application
virtual int run(int, char*[]);
- virtual void interruptCallback(int);
+ virtual void interruptCallback(int);
private:
+ void initialize(const std::string appName);
+ void registerWithServiceLocator();
+ void deregisterFromServiceLocator();
+ void setCategory(Discovery::V1::ServiceManagementPrx serviceManagement, const string &category);
+
bool mDone;
std::string mAppName;
+ Ice::ObjectAdapterPtr mAdapter;
+ ServiceLocatorManagementPrx mServiceLocatorManagement;
+ Discovery::V1::ServiceManagementPrx mRegistryLocatorManagement;
+ Discovery::V1::ServiceManagementPrx mAdminManagement;
+ Discovery::V1::ServiceManagementPrx mComponentServiceManagement;
+ LocatorRegistryPtr mLocatorRegistry;
+ RoutingServiceAdminPtr mAdminInteface;
+};
+
+static const string RegistryLocatorObjectId("RoutingServiceRegistryLocator");
+static const string RoutingAdminObjectId("RoutingAdmin");
+static const string ComponentServiceId("BasicRoutingService");
+
+/**
+ * This class provides implementation for the ComponentService interface.
+ * Every Asterisk SCF component is expected to expose the ComponentService interface.
+ */
+class ComponentServiceImpl : ComponentService
+{
+public:
+ ComponentServiceImpl(BasicRoutingServiceApp &app) : mApp(app) {}
+
+public: // Overrides of the ComponentService interface.
+ virtual void suspend(const ::Ice::Current& = ::Ice::Current())
+ {
+ mDataModelInstance.mPaused = true;
+ }
+
+ virtual void resume(const ::Ice::Current& = ::Ice::Current())
+ {
+ mDataModelInstance.mPaused = false;
+ }
+
+ virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
+ {
+ mApp.interruptCallback(EXIT_SUCCESS);
+ }
+
+private:
+ BasicRoutingServiceApp& mApp;
};
+/**
+ * Handles control characters in case the component is invoked as a console app.
+ */
void BasicRoutingServiceApp::interruptCallback(int val)
{
- cout << "Interrupted..." << endl;
+ cout << "Exiting..." << endl;
mDone = true;
_exit(EXIT_SUCCESS);
}
/**
- * Overload of the Ice::Application::run method.
+ * Helper function to add some parameters to one of our registered interfaces in the ServiceLocator, so that
+ * other components can look up our interfaces.
*/
-int BasicRoutingServiceApp::run(int argc, char* argv[])
+void BasicRoutingServiceApp::setCategory(Discovery::V1::ServiceManagementPrx serviceManagement, const string &category)
{
- // Init the Data Model singleton.
- mDataModelInstance.mCommunicator = communicator();
+ // Add category as a parameter to enable other components look this component up.
+ ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
+ genericparams->category = category;
+ serviceManagement->addLocatorParams(genericparams, "");
+}
- mDataModelInstance.mEventPublisher = new RoutingServiceEventPublisher();
+/**
+ * Register this component's primary public interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate the interfaces we are publishing.
+ */
+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("ServiceLocatorManagementProxy"));
- // Create the adapter.
- mAppName = argv[0];
- Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("BasicRoutingServiceAdapter");
+ // Get a proxy to our RoutingAdmin interface and add it to the Service Locator.
+ Ice::ObjectPrx adminObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(RoutingAdminObjectId));
+ RoutingServiceAdminPrx adminPrx = RoutingServiceAdminPrx::checkedCast(adminObjectPrx);
+ mAdminManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(adminPrx, "BasicRoutingServiceAdmin"));
+
+ 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));
+ LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::checkedCast(locatorObjectPrx);
+ mRegistryLocatorManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(locatorRegistryPrx, "BasicRoutingServiceRegistryLocator"));
+
+ setCategory(mRegistryLocatorManagement, Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory);
- // Create and configure the EndpointRegistry.
- mDataModelInstance.mEndpointRegistry = new EndpointRegistry();
- boost::shared_ptr<ScriptProcessor> scriptProcesor(new LuaScriptProcessor());
- mDataModelInstance.mEndpointRegistry->setScriptProcessor(scriptProcesor);
+ // Get a proxy to our ComponentService interface and add it to the Service Locator.
+ Ice::ObjectPrx componentServiceObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(ComponentServiceId));
+ ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
+ mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, "BasicRoutingService"));
+
+ setCategory(mRegistryLocatorManagement, Routing::V1::ComponentServiceDiscoveryCategory);
+ }
+ catch(...)
+ {
+ cout << "Major problems in " << mAppName << " registerWithServiceLocator()" << endl;
+ }
+}
+
+/**
+ * Deregister this component's primary public interfaces from the Service Locator.
+ * This is done at shutdown, and whenever we want to keep other services from locating
+ * our interfaces.
+ */
+void BasicRoutingServiceApp::deregisterFromServiceLocator()
+{
+ try
+ {
+ mRegistryLocatorManagement->unregister();
+ mAdminManagement->unregister();
+ mComponentServiceManagement->unregister();
+ }
+ catch(...)
+ {
+ cout << "Had trouble in deregisterFromServiceLocator()." << endl;
+ }
+}
+
+/**
+ * Create the primary functional objects of this component.
+ * @param appName Name of the application or component.
+ */
+void BasicRoutingServiceApp::initialize(const std::string appName)
+{
+ try
+ {
+ mAppName = appName;
+
+ // Init the fields of the Data Model singleton.
+ mDataModelInstance.mCommunicator = communicator();
- LocatorRegistryPtr locatorRegistry(mDataModelInstance.mEndpointRegistry);
- adapter->add(locatorRegistry, communicator()->stringToIdentity("RoutingService"));
+ mDataModelInstance.mEventPublisher = new RoutingServiceEventPublisher();
- // Create and configure the Admin interface
- RoutingServiceAdminPtr adminInterface = new RoutingAdmin();
- adapter->add(adminInterface, communicator()->stringToIdentity("RoutingAdmin"));
+ // Create the adapter.
+ mAdapter = communicator()->createObjectAdapter("BasicRoutingServiceAdapter");
- adapter->activate();
+ // Create and configure the EndpointRegistry.
+ mDataModelInstance.mEndpointRegistry = new EndpointRegistry();
+ boost::shared_ptr<ScriptProcessor> scriptProcesor(new LuaScriptProcessor());
+ mDataModelInstance.mEndpointRegistry->setScriptProcessor(scriptProcesor);
+ // Publish the LocatorRegistry interface.
+ mLocatorRegistry = mDataModelInstance.mEndpointRegistry;
+ mAdapter->add(mLocatorRegistry, communicator()->stringToIdentity(RegistryLocatorObjectId));
+
+ // Create and configure the Admin interface.
+ mAdminInteface = new RoutingAdmin();
+ mAdapter->add(mAdminInteface, communicator()->stringToIdentity(RoutingAdminObjectId));
+
+ mAdapter->activate();
+
+ }
+ catch(...)
+ {
+ cout << "Major problems in " << mAppName << " initialization()" << endl;
+ }
+}
+
+/**
+ * Overload of the Ice::Application::run method.
+ */
+int BasicRoutingServiceApp::run(int argc, char* argv[])
+{
+ // Initialize this component.
+ initialize(argv[0]);
+
+ // Plug 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();
+ // Remove our interfaces from the service locator.
+ deregisterFromServiceLocator();
+
+ // Give our singleton a chance to shut down gracefully.
mDataModelInstance.cleanup();
return EXIT_SUCCESS;
@@ -128,6 +290,8 @@ int BasicRoutingServiceApp::run(int argc, char* argv[])
}; // end Hydra
static BasicRoutingServiceApp app;
+
+// Application entry point.
int main(int argc, char* argv[])
{
app.callbackOnInterrupt();
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4c14ab1..a0e46fc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,6 +5,9 @@ get_filename_component(LUA_LOC ${LUA_LIBRARIES} PATH)
LINK_DIRECTORIES(${LUA_LOC})
include_directories(${LUA_INCLUDE_DIR})
hydra_component_add_slice(BasicRoutingService RoutingIf)
+hydra_component_add_slice(BasicRoutingService ServiceLocatorIf)
+hydra_component_add_slice(BasicRoutingService EndpointIf)
+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 RoutingAdmin.cpp)
-----------------------------------------------------------------------
--
asterisk-scf/integration/routing.git
More information about the asterisk-scf-commits
mailing list