[asterisk-scf-commits] asterisk-scf/integration/servicediscovery.git branch "baserep" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Dec 16 08:46:15 CST 2011


branch "baserep" has been created
        at  91b390e9cee4e2e2e78390417723494bfb55dfc5 (commit)

- Log -----------------------------------------------------------------
commit 91b390e9cee4e2e2e78390417723494bfb55dfc5
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Dec 16 08:46:03 2011 -0600

    Renmaed ServiceLocatorStateReplicatorApp.cpp, which now also uses base replicator class.

diff --git a/slice/AsteriskSCF/Replication/ServiceLocator/ServiceLocatorStateReplicationIf.ice b/slice/AsteriskSCF/Replication/ServiceLocator/ServiceLocatorStateReplicationIf.ice
index 3ec0dd1..3f509a9 100644
--- a/slice/AsteriskSCF/Replication/ServiceLocator/ServiceLocatorStateReplicationIf.ice
+++ b/slice/AsteriskSCF/Replication/ServiceLocator/ServiceLocatorStateReplicationIf.ice
@@ -32,6 +32,9 @@ module ServiceLocator
 ["suppress"]
 module V1
 {
+   const string StateReplicatorComponentCategory = "ServiceLocatorStateReplicatorComponent";
+   const string StateReplicatorDiscoveryCategory = "ServiceLocatorStateReplicator";
+
    class ServiceLocatorStateItem
    {
       string key;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cfd57d9..9efd4c8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -18,10 +18,10 @@ astscf_component_install(service_locator)
 
 astscf_component_init(ServiceLocatorStateReplicator)
 astscf_component_add_slices(ServiceLocatorStateReplicator PROJECT AsteriskSCF/Replication/ServiceLocator/ServiceLocatorStateReplicationIf.ice)
-astscf_component_add_files(ServiceLocatorStateReplicator ServiceLocatorStateReplicatorApp.cpp)
+astscf_component_add_files(ServiceLocatorStateReplicator ComponentStateReplicator.cpp)
 astscf_component_add_files(ServiceLocatorStateReplicator ServiceLocatorStateReplicator.h)
 astscf_component_add_ice_libraries(ServiceLocatorStateReplicator IceStorm)
 astscf_component_add_boost_libraries(ServiceLocatorStateReplicator thread date_time)
 astscf_component_build_icebox(ServiceLocatorStateReplicator)
-target_link_libraries(ServiceLocatorStateReplicator logging-client)
+target_link_libraries(ServiceLocatorStateReplicator logging-client astscf-ice-util-cpp)
 astscf_component_install(ServiceLocatorStateReplicator)
diff --git a/src/ComponentStateReplicator.cpp b/src/ComponentStateReplicator.cpp
new file mode 100644
index 0000000..92dcd09
--- /dev/null
+++ b/src/ComponentStateReplicator.cpp
@@ -0,0 +1,99 @@
+/*
+ * 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 <AsteriskSCF/Component/ComponentStateReplicator.h>
+#include <AsteriskSCF/logger.h>
+#include "ServiceLocatorStateReplicator.h"
+
+using namespace std;
+using namespace AsteriskSCF::Core;
+using namespace AsteriskSCF::Discovery;
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::Replication::ServiceLocator::V1;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.ServiceLocatorStateReplicator");
+}
+
+class ComponentStateReplicator : public AsteriskSCF::Component::ComponentStateReplicator
+{
+public:
+    ComponentStateReplicator() :
+      AsteriskSCF::Component::ComponentStateReplicator(lg, 
+          AsteriskSCF::Replication::ServiceLocator::V1::StateReplicatorComponentCategory, 
+          false)  // if true, supports configuration
+    {
+    }
+
+    ~ComponentStateReplicator() {};
+
+    ///////////////////////////////////////////////////
+    // Required overrides
+
+    void createPrimaryServices();
+    void preparePrimaryServicesForDiscovery();
+
+private:
+    ServiceLocatorStateReplicatorIPtr mStateReplicator;
+    ServiceLocatorStateReplicatorPrx mStateReplicatorPrx;
+    LocatorRegistrationWrapperPtr mStateReplicatorRegistration;
+};
+
+static const string ServiceDiscoveryId("ServiceLocatorStateReplicatorService");
+
+/**
+ * Register this component's primary public interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate our interfaces.
+ */
+void ComponentStateReplicator::preparePrimaryServicesForDiscovery()
+{
+    try
+    {
+        // Wrap our authentication extensions point for the Service Locator.
+        mStateReplicatorRegistration = wrapServiceForRegistration(mStateReplicatorPrx,
+                                                                  AsteriskSCF::Replication::ServiceLocator::V1::StateReplicatorDiscoveryCategory);
+        managePrimaryService(mStateReplicatorRegistration);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION <<
+            ". Exception: " << e.what();
+        throw; // rethrow
+    }
+}
+
+void ComponentStateReplicator::createPrimaryServices()
+{
+    // Create the state replicator servant
+    mStateReplicator = new ServiceLocatorStateReplicatorI();
+
+    mStateReplicatorPrx = ServiceLocatorStateReplicatorPrx::uncheckedCast(
+       getServiceAdapter()->add(mStateReplicator, getCommunicator()->stringToIdentity(ServiceDiscoveryId)));
+}
+
+extern "C"
+{
+ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
+{
+    return new ComponentStateReplicator;
+}
+}
+
diff --git a/src/ServiceLocatorStateReplicatorApp.cpp b/src/ServiceLocatorStateReplicatorApp.cpp
deleted file mode 100644
index 23378f7..0000000
--- a/src/ServiceLocatorStateReplicatorApp.cpp
+++ /dev/null
@@ -1,122 +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 <IceUtil/UUID.h>
-#include <IceStorm/IceStorm.h>
-#include <IceBox/IceBox.h>
-
-#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
-#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
-#include <AsteriskSCF/logger.h>
-#include <AsteriskSCF/Logger/IceLogger.h>
-#include "ServiceLocatorStateReplicator.h"
-
-using namespace std;
-using namespace AsteriskSCF::Core;
-using namespace AsteriskSCF::Core::Discovery::V1;
-using namespace AsteriskSCF::System::Component::V1;
-using namespace AsteriskSCF::System::Logging;
-
-class ServiceLocatorStateReplicatorService : public IceBox::Service
-{
-public:
-    ServiceLocatorStateReplicatorService() { };
-    ~ServiceLocatorStateReplicatorService()
-    {
-        mComponentService = 0;
-        mAdapter = 0;
-        mStateReplicator = 0;
-    };
-    virtual void start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
-    virtual void stop();
-private:
-    void initialize(std::string appName, const Ice::CommunicatorPtr& ic);
-    std::string mAppName;
-    Ice::ObjectAdapterPtr mAdapter;
-    ConfiguredIceLoggerPtr mIceLogger;
-    ComponentServicePtr mComponentService;
-    ServiceLocatorStateReplicatorIPtr mStateReplicator;
-};
-
-static const string ComponentServiceId("ServiceLocatorStateReplicatorComponent");
-static const string ServiceDiscoveryId("ServiceLocatorStateReplicatorService");
-
-/**
- * This class provides implementation for the ComponentService interface, which
- * every Asterisk SCF component is expected to publish.
- */
-class ComponentServiceImpl : public ComponentService
-{
-public:
-    ComponentServiceImpl(ServiceLocatorStateReplicatorService &service) : mService(service) {}
-
-public: // Overrides of the ComponentService interface.
-    virtual void suspend(const ::Ice::Current& = ::Ice::Current())
-    {
-        // TBD
-    }
-
-    virtual void resume(const ::Ice::Current& = ::Ice::Current())
-    {
-        // TBD
-    }
-
-    virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
-    {
-        // TBD
-    }
-
-private:
-    ServiceLocatorStateReplicatorService& mService;
-};
-
-void ServiceLocatorStateReplicatorService::initialize(const std::string appName, const Ice::CommunicatorPtr& ic)
-{
-    mAdapter = ic->createObjectAdapter(appName + ".Adapter");
-
-    // setup logging client
-    mIceLogger = createIceLogger(mAdapter);
-    getLoggerFactory().setLogOutput(mIceLogger->getLogger());
-
-    mAppName = appName;
-
-    // Create and publish our ComponentService interface support.
-    mComponentService = new ComponentServiceImpl(*this);
-    mAdapter->add(mComponentService, ic->stringToIdentity(ComponentServiceId));
-    mStateReplicator = new ServiceLocatorStateReplicatorI();
-    mAdapter->add(mStateReplicator, ic->stringToIdentity(ServiceDiscoveryId));
-
-    mAdapter->activate();
-}
-
-void ServiceLocatorStateReplicatorService::start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq&)
-{
-    initialize(name, ic);
-}
-
-void ServiceLocatorStateReplicatorService::stop()
-{
-}
-
-extern "C"
-{
-ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
-{
-    return new ServiceLocatorStateReplicatorService;
-}
-}
-

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


-- 
asterisk-scf/integration/servicediscovery.git



More information about the asterisk-scf-commits mailing list