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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Feb 6 11:13:12 CST 2012


branch "master" has been updated
       via  7a6f0639c52a5fa0c0196088819ab7dcf2692c60 (commit)
      from  3b3d792e8612d861dde1c04efbf5a00d5d51205e (commit)

Summary of changes:
 src/CMakeLists.txt               |    2 +-
 src/ComponentStateReplicator.cpp |  104 +++++++++++++
 src/UdptlStateReplicatorApp.cpp  |  304 --------------------------------------
 3 files changed, 105 insertions(+), 305 deletions(-)
 create mode 100644 src/ComponentStateReplicator.cpp
 delete mode 100644 src/UdptlStateReplicatorApp.cpp


- Log -----------------------------------------------------------------
commit 7a6f0639c52a5fa0c0196088819ab7dcf2692c60
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Feb 3 18:19:24 2012 -0600

    Using base replicator class ComponentStateReplicator.cpp

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d62083b..0bb8125 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -52,7 +52,7 @@ pjproject_link(MediaTransportUDPTL pjnath)
 astscf_component_install(MediaTransportUDPTL)
 
 astscf_component_init(UdptlStateReplicator)
-astscf_component_add_files(UdptlStateReplicator UdptlStateReplicatorApp.cpp)
+astscf_component_add_files(UdptlStateReplicator ComponentStateReplicator.cpp)
 astscf_component_add_files(UdptlStateReplicator UdptlStateReplicator.h)
 astscf_component_add_slices(UdptlStateReplicator PROJECT AsteriskSCF/Replication/UDPTL/UdptlStateReplicationIf.ice)
 astscf_component_add_slices(UdptlStateReplicator PROJECT AsteriskSCF/Configuration/UDPTL/UdptlConfigurationIf.ice)
diff --git a/src/ComponentStateReplicator.cpp b/src/ComponentStateReplicator.cpp
new file mode 100644
index 0000000..1a521fc
--- /dev/null
+++ b/src/ComponentStateReplicator.cpp
@@ -0,0 +1,104 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, 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 <AsteriskSCF/Media/UDPTL/MediaUDPTLIf.h>
+
+#include "UdptlConfigurationIf.h"
+#include "UdptlStateReplicator.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::Media::UDPTL::V1;
+using namespace AsteriskSCF::Replication::UDPTL::V1;
+using namespace AsteriskSCF::Configuration::UDPTL::V1;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaUDPTL");
+}
+
+class ComponentStateReplicator : public AsteriskSCF::Component::ComponentStateReplicator
+{
+public:
+    ComponentStateReplicator() :
+      AsteriskSCF::Component::ComponentStateReplicator(lg, 
+          AsteriskSCF::Replication::UDPTL::V1::StateReplicatorComponentCategory, 
+          true)  // if true, supports configuration
+    {
+    }
+
+    ~ComponentStateReplicator() {};
+
+    ///////////////////////////////////////////////////
+    // Required overrides
+
+    void createPrimaryServices();
+    void preparePrimaryServicesForDiscovery();
+
+private:
+    UdptlStateReplicatorIPtr mStateReplicator;
+    UdptlStateReplicatorPrx mStateReplicatorPrx;
+    LocatorRegistrationWrapperPtr mStateReplicatorRegistration;
+};
+
+static const string ServiceDiscoveryId("UdptlStateReplicatorService");
+
+/**
+ * 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::UDPTL::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 UdptlStateReplicatorI();
+
+    mStateReplicatorPrx = UdptlStateReplicatorPrx::uncheckedCast(
+       getServiceAdapter()->add(mStateReplicator, getCommunicator()->stringToIdentity(ServiceDiscoveryId)));
+}
+
+extern "C"
+{
+ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
+{
+    return new ComponentStateReplicator;
+}
+}
+
diff --git a/src/UdptlStateReplicatorApp.cpp b/src/UdptlStateReplicatorApp.cpp
deleted file mode 100644
index 59016bd..0000000
--- a/src/UdptlStateReplicatorApp.cpp
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2011, 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/IceLogger.h>
-#include <AsteriskSCF/Logger.h>
-#include <AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h>
-#include <AsteriskSCF/System/Component/ConfigurationIf.h>
-#include <AsteriskSCF/Media/UDPTL/MediaUDPTLIf.h>
-
-#include "UdptlConfigurationIf.h"
-#include "UdptlStateReplicator.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;
-using namespace AsteriskSCF::Media::UDPTL::V1;
-using namespace AsteriskSCF::Replication::UDPTL::V1;
-using namespace AsteriskSCF::Configuration::UDPTL::V1;
-using namespace AsteriskSCF::CollocatedIceStorm;
-using namespace AsteriskSCF::System::Configuration::V1;
-
-namespace
-{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaUDPTL");
-}
-
-class UdptlStateReplicatorService : public IceBox::Service
-{
-public:
-    UdptlStateReplicatorService() { };
-    ~UdptlStateReplicatorService()
-    {
-        mComponentService = 0;
-        mAdapter = 0;
-        mStateReplicator = 0;
-    mConfigurationReplicator = 0;
-    };
-    virtual void start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
-    virtual void stop();
-
-private:
-    void initialize(const string& appName, const Ice::CommunicatorPtr& ic);
-    void registerWithServiceLocator(const Ice::CommunicatorPtr& ic);
-    void deregisterFromServiceLocator();
-    std::string mAppName;
-    Ice::ObjectAdapterPtr mAdapter;
-    ServiceLocatorManagementPrx mServiceLocatorManagement;
-    Discovery::V1::ServiceManagementPrx mComponentServiceManagement;
-    Discovery::V1::ServiceManagementPrx mStateReplicationManagement;
-    ConfiguredIceLoggerPtr mIceLogger;
-    ComponentServicePtr mComponentService;
-    UdptlStateReplicatorIPtr mStateReplicator;
-    ConfigurationReplicatorPtr mConfigurationReplicator;
-    CollocatedIceStormPtr mIceStorm;
-    Ice::ObjectPrx mConfigurationPublisher;
-    Discovery::V1::ServiceManagementPrx mConfigurationManagement;
-};
-
-static const string ComponentServiceId("UdptlStateReplicatorComponent");
-static const string ServiceDiscoveryId("UdptlStateReplicatorService");
-
-/**
- * This class provides implementation for the ComponentService interface, which
- * every Asterisk SCF component is expected to publish.
- */
-class ComponentServiceImpl : public ComponentService
-{
-public:
-    ComponentServiceImpl(UdptlStateReplicatorService &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:
-    UdptlStateReplicatorService& mService;
-};
-
-class ConfigurationReplicatorI : public ConfigurationReplicator
-{
-public:
-    ConfigurationReplicatorI(const IceStorm::TopicPrx& topic) : mConfigurationReplicationTopic(topic) { };
-    void registerConfigurationService(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx&, const Ice::Current&);
-private:
-    IceStorm::TopicPrx mConfigurationReplicationTopic;    
-};
-
-void ConfigurationReplicatorI::registerConfigurationService(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx& service, const Ice::Current&)
-{
-    if (mConfigurationReplicationTopic)
-    {
-        IceStorm::QoS qos;
-        qos["reliability"] = "ordered";
-    
-        try
-        {
-            mConfigurationReplicationTopic->subscribeAndGetPublisher(qos, service);
-        }
-        catch (const IceStorm::AlreadySubscribed&)
-        {
-            // This is perfectly okay actually, it just means what they wanted us to do
-            // is already done.
-        }
-    }
-}
-
-/**
- * Register this component's primary public interfaces with the Service Locator.
- * This enables other Asterisk SCF components to locate our interfaces.
- */
-void UdptlStateReplicatorService::registerWithServiceLocator(const Ice::CommunicatorPtr& ic)
-{
-    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(ic->propertyToProxy("LocatorServiceManagement.Proxy"));
-
-        if (mServiceLocatorManagement == 0)
-        {
-            lg(Error) << "Unable to obtain proxy to LocatorServiceManagement interface. Check config file. "
-                "This component can't be found until this is corrected.";
-            return;
-        }
-
-        // Get a proxy to our ComponentService interface and add it to the Service Locator.
-        Ice::ObjectPrx componentServiceObjectPrx = mAdapter->createDirectProxy(ic->stringToIdentity(ComponentServiceId));
-        ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
-
-        // The GUID passed in to add service needs to be unique for reporting.
-        string componentServiceGuid(AsteriskSCF::Replication::UDPTL::V1::StateReplicatorComponentCategory);
-        mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(
-            mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
-
-        // Add category as a parameter to enable other components look this component up.
-        ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
-        genericparams->category = AsteriskSCF::Replication::UDPTL::V1::StateReplicatorComponentCategory;
-        genericparams->service =  ic->getProperties()->getPropertyWithDefault(mAppName + ".ServiceName", "default");
-        genericparams->id = mAppName;
-        mComponentServiceManagement->addLocatorParams(genericparams, "");
-
-        Ice::ObjectPrx stateReplicatorObjectPrx = mAdapter->createDirectProxy(ic->stringToIdentity(ServiceDiscoveryId));
-        UdptlStateReplicatorPrx stateReplicatorPrx = UdptlStateReplicatorPrx::checkedCast(stateReplicatorObjectPrx);
-
-        string stateReplicationGuid(AsteriskSCF::Replication::UDPTL::V1::StateReplicatorDiscoveryCategory);
-        mStateReplicationManagement = ServiceManagementPrx::uncheckedCast(
-            mServiceLocatorManagement->addService(stateReplicatorPrx, stateReplicationGuid));
-
-        ServiceLocatorParamsPtr discoveryParams = new ServiceLocatorParams;
-        discoveryParams->category = AsteriskSCF::Replication::UDPTL::V1::StateReplicatorDiscoveryCategory;
-        discoveryParams->service = ic->getProperties()->getPropertyWithDefault(mAppName + ".ServiceName", "default");
-        discoveryParams->id = mAppName;
-        mStateReplicationManagement->addLocatorParams(discoveryParams, "");
-
-        // Publish the configuration service IceStorm topic so everybody gets configuration
-        mConfigurationManagement = ServiceManagementPrx::uncheckedCast(
-        mServiceLocatorManagement->addService(mConfigurationPublisher, ""));
-
-        // Populate the configuration parameters with details so we can be found
-        ServiceLocatorParamsPtr configurationParams = new ServiceLocatorParams();
-        configurationParams->category = ConfigurationDiscoveryCategory;
-        configurationParams->service = ic->getProperties()->getPropertyWithDefault(mAppName + ".ServiceName", "default");
-        configurationParams->id = mAppName;
-        mConfigurationManagement->addLocatorParams(configurationParams, "");
-
-        // TBD... We may have other interfaces to publish to the Service Locator.
-    }
-    catch(...)
-    {
-        lg(Error) << "Exception in " << mAppName << " registerWithServiceLocator()";
-    }
-}
-
-/**
- * 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 UdptlStateReplicatorService::deregisterFromServiceLocator()
-{
-    try
-    {
-        mComponentServiceManagement->unregister();
-        mConfigurationManagement->unregister();
-    }
-    catch(...)
-    {
-        lg(Error) << "Had trouble in deregisterFromServiceLocator().";
-    }
-}
-
-void UdptlStateReplicatorService::initialize(const string& appName, const Ice::CommunicatorPtr& ic)
-{
-    mIceStorm = new CollocatedIceStorm(appName, ic->getProperties());
-
-    IceStorm::TopicManagerPrx topicManager = mIceStorm->createTopicManagerProxy(ic);
-
-    IceStorm::TopicPrx topic;
-
-    if (topicManager)
-    {
-        try
-        {
-        topic = topicManager->retrieve("ConfigurationReplication");
-        }
-        catch (const IceStorm::NoSuchTopic&)
-        {
-            try
-            {
-                topic = topicManager->create("ConfigurationReplication");
-            }
-            catch (const IceStorm::TopicExists&)
-            {
-                lg(Error) << "Oh snap! Race condition creating topic, aborting";
-                return;
-            }
-        }
-    // There is no cast here on purpose as this is just going to get passed to
-    // the service locator which just takes a plain ol' proxy anyway.
-    mConfigurationPublisher = topic->getPublisher();
-    }
-    else
-    {
-        lg(Info) << "IceStorm topic manager proxy not present, unable to perform configuration replication.";
-    }
-
-    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 UdptlStateReplicatorI();
-    mAdapter->add(mStateReplicator, ic->stringToIdentity(ServiceDiscoveryId));
-    mConfigurationReplicator = new ConfigurationReplicatorI(topic);
-    mAdapter->addFacet(mConfigurationReplicator, ic->stringToIdentity(ServiceDiscoveryId),
-    ReplicatorFacet);
-
-    mAdapter->activate();
-}
-
-void UdptlStateReplicatorService::start(const string &name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq&)
-{
-    initialize(name, ic);
-    // Plug into the Asterisk SCF discovery system so that the interfaces we provide
-    // can be located.
-    registerWithServiceLocator(ic);
-}
-
-void UdptlStateReplicatorService::stop()
-{
-    // Remove our interfaces from the service locator.
-    deregisterFromServiceLocator();
-
-    // Stop our local IceStorm instance
-    mIceStorm->stop();
-}
-
-extern "C"
-{
-ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
-{
-    return new UdptlStateReplicatorService;
-}
-}
-

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


-- 
asterisk-scf/release/media_transport_udptl.git



More information about the asterisk-scf-commits mailing list