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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Sep 20 12:03:26 CDT 2011


branch "master" has been updated
       via  408e18897ab9e63f0c30d66032baa15d7a95f97c (commit)
      from  f487411d8aab56dce4a78fcc766d4d543040c343 (commit)

Summary of changes:
 src/CMakeLists.txt                            |    5 +-
 src/{MediaFormatGeneric.cpp => Component.cpp} |  264 ++++++++++++++-----------
 2 files changed, 147 insertions(+), 122 deletions(-)
 rename src/{MediaFormatGeneric.cpp => Component.cpp} (54%)


- Log -----------------------------------------------------------------
commit 408e18897ab9e63f0c30d66032baa15d7a95f97c
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Sep 20 12:03:15 2011 -0500

    This Component now uses the base Component class.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e216ea7..7ff06ab 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,7 +1,8 @@
 include_directories(${logger_dir}/include)
+include_directories(${astscf-ice-util-cpp_dir}/include)
 
 astscf_component_init(mediaformatgeneric)
-astscf_component_add_files(mediaformatgeneric MediaFormatGeneric.cpp)
+astscf_component_add_files(mediaformatgeneric Component.cpp)
 astscf_component_add_files(mediaformatgeneric MediaFormatGeneric.h)
 astscf_component_add_files(mediaformatgeneric MediaFormatGenericConfiguration.cpp)
 astscf_component_add_files(mediaformatgeneric MediaFormatGenericConfiguration.h)
@@ -9,6 +10,6 @@ astscf_component_add_slices(mediaformatgeneric PROJECT AsteriskSCF/Configuration
 astscf_component_add_boost_libraries(mediaformatgeneric core thread)
 astscf_component_add_slice_collection_libraries(mediaformatgeneric ASTSCF)
 astscf_component_build_icebox(mediaformatgeneric)
-target_link_libraries(mediaformatgeneric logging-client)
+target_link_libraries(mediaformatgeneric astscf-ice-util-cpp logging-client)
 astscf_component_install(mediaformatgeneric)
 
diff --git a/src/MediaFormatGeneric.cpp b/src/Component.cpp
similarity index 54%
rename from src/MediaFormatGeneric.cpp
rename to src/Component.cpp
index 33c84e6..209e69b 100644
--- a/src/MediaFormatGeneric.cpp
+++ b/src/Component.cpp
@@ -25,6 +25,8 @@
 #include <AsteriskSCF/System/Component/ComponentServiceIf.h>
 #include <AsteriskSCF/Logger/IceLogger.h>
 #include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Discovery/LocatorRegistrationWrapper.h>
+#include <AsteriskSCF/Component/Component.h>
 
 #include "MediaFormatGeneric.h"
 #include "MediaFormatGenericConfiguration.h"
@@ -38,53 +40,14 @@ using namespace AsteriskSCF::Media::Formats::Audio::V1;
 using namespace AsteriskSCF::Configuration::FormatGeneric::V1;
 using namespace AsteriskSCF::System::Component::V1;
 using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::Discovery;
 
 namespace
 {
 Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaFormatGeneric");
 }
 
-/**
- * Implementation of the IceBox::Service class
- */
-class MediaFormatGenericApp : public IceBox::Service
-{
-public:
-    void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&);
-    void stop();
-
-private:
-    /**
-     * Ice Communicator used for this service.
-     */
-    Ice::CommunicatorPtr mCommunicator;
-
-    /**
-     * Object adapter that stuff is associated with.
-     */
-    Ice::ObjectAdapterPtr mAdapter;
-
-    /**
-     * A proxy to the service locator manager for our SDP descriptor service.
-     */
-    ServiceManagementPrx mServiceManagement;
-
-    /**
-     * A proxy to the service locator manager for our configuration service.
-     */
-    ServiceManagementPrx mConfigurationServiceManagement;
-
-    /**
-     * A proxy to the service locator management service.
-     */
-    ServiceLocatorManagementPrx mManagement;
-
-    /**
-     * Unique guid for SDP descriptor service name comparator.
-     */
-    std::string mCompareGuid;
-};
-
 bool SDPDescriptorCompareServiceImpl::isSupported(const ServiceLocatorParamsPtr& params, const Ice::Current&)
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
@@ -250,100 +213,161 @@ void SDPDescriptorServiceImpl::removeAllFormats()
     mFormatDescriptors.clear();
 }
 
+class Component : public AsteriskSCF::Component::Component
+{
+public:
+    Component() : 
+        AsteriskSCF::Component::Component(lg, 
+                                          "MediaFormatGeneric")   {}
+
+private:
+    // Optional base Component notification overrides. 
+    virtual void createBackplaneServices();
+    virtual void prepareBackplaneServicesForDiscovery();
+
+    // Required base Component overrides
+    virtual void createPrimaryServices();
+    virtual void preparePrimaryServicesForDiscovery();
+    virtual void createReplicationStateListeners() {} // No-op. This component doesn't replicate.
+    virtual void stopListeningToStateReplicators() {}
+    virtual void listenToStateReplicators() {}
+    virtual void findRemoteServices() {}
+
+    SDPDescriptorServiceImplPtr mSdpDescriptorService;
+    SDPDescriptorServicePrx mSdpDescriptorPrx;
+    LocatorRegistrationWrapperPtr mSdpDescriptorRegistration;
+
+    ConfigurationServiceImplPtr mConfigService;
+    ConfigurationServicePrx mConfigServicePrx;
+    LocatorRegistrationWrapperPtr mConfigurationRegistration;
+
+    // Unique guid for SDP descriptor service name comparator.
+    std::string mCompareGuid;
+    SDPDescriptorCompareServiceImplPtr mSdpComparator;
+};
+
 /**
- * Implementation of the IceBox::Service::start method.
+ * Create the objects that implement the main services this component provides 
+ * the system.
  */
-void MediaFormatGenericApp::start(const std::string&, const Ice::CommunicatorPtr& communicator,
-                                  const Ice::StringSeq&)
+void Component::createPrimaryServices()
+{
+    try
+    {
+        // Create an instance of our SDP descriptor service
+        mSdpDescriptorService = new SDPDescriptorServiceImpl();
+        mSdpDescriptorPrx = SDPDescriptorServicePrx::uncheckedCast(getServiceAdapter()->addWithUUID(mSdpDescriptorService));
+
+        // Create an instance of our custom comparator service
+        mSdpComparator = new SDPDescriptorCompareServiceImpl();
+
+        // Add the ulaw audio format
+        G711uLAWPtr ulaw = new G711uLAW();
+        ulaw->name = "ulaw";
+        SDPDescriptorPtr ulawSDP = new SDPDescriptor();
+        ulawSDP->payload = 0;
+        ulawSDP->type = "audio";
+        ulawSDP->subtype = "PCMU";
+        ulawSDP->samplerate = 8000;
+        mSdpDescriptorService->addFormat(ulaw->name, ulaw, ulawSDP);
+        mSdpComparator->addFormat(ulaw->name);
+
+        // Add the alaw audio format
+        G711aLAWPtr alaw = new G711aLAW();
+        alaw->name = "alaw";
+        SDPDescriptorPtr alawSDP = new SDPDescriptor();
+        alawSDP->payload = 8;
+        alawSDP->type = "audio";
+        alawSDP->subtype = "PCMA";
+        alawSDP->samplerate = 8000;
+        mSdpDescriptorService->addFormat(alaw->name, alaw, alawSDP);
+        mSdpComparator->addFormat(alaw->name);
+
+        // Register our custom comparator with the service locator
+        ServiceLocatorParamsComparePrx comparatorServicePrx = ServiceLocatorParamsComparePrx::uncheckedCast(
+	    getServiceAdapter()->addWithUUID(mSdpComparator));
+        mCompareGuid = getName() + ".Media/SDP_Descriptor";
+        getServiceLocatorManagement()->addCompare(mCompareGuid, comparatorServicePrx);
+
+    }
+    catch(const Ice::Exception& e)
+    {
+       lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+    }
+}
+
+void Component::createBackplaneServices()
 {
-    // Use the configured value for the service locator management to create a proxy
-    mManagement = ServiceLocatorManagementPrx::checkedCast(communicator->propertyToProxy("ServiceLocatorManagementProxy"));
-    
-    mAdapter = communicator->createObjectAdapter("MediaFormatGenericAdapter");
-
-    // Create an instance of our SDP descriptor service
-    SDPDescriptorServiceImplPtr descriptorService = new SDPDescriptorServiceImpl();
-
-    // Create an instance of our custom comparator service
-    SDPDescriptorCompareServiceImplPtr comparatorService = new SDPDescriptorCompareServiceImpl();
-
-    // Create an instance of our configuration service
-    ConfigurationServiceImplPtr configurationService = new ConfigurationServiceImpl(descriptorService, comparatorService);
-
-    // Add the ulaw audio format
-    G711uLAWPtr ulaw = new G711uLAW();
-    ulaw->name = "ulaw";
-    SDPDescriptorPtr ulawSDP = new SDPDescriptor();
-    ulawSDP->payload = 0;
-    ulawSDP->type = "audio";
-    ulawSDP->subtype = "PCMU";
-    ulawSDP->samplerate = 8000;
-    descriptorService->addFormat(ulaw->name, ulaw, ulawSDP);
-    comparatorService->addFormat(ulaw->name);
-
-    // Add the alaw audio format
-    G711aLAWPtr alaw = new G711aLAW();
-    alaw->name = "alaw";
-    SDPDescriptorPtr alawSDP = new SDPDescriptor();
-    alawSDP->payload = 8;
-    alawSDP->type = "audio";
-    alawSDP->subtype = "PCMA";
-    alawSDP->samplerate = 8000;
-    descriptorService->addFormat(alaw->name, alaw, alawSDP);
-    comparatorService->addFormat(alaw->name);
-
-    // Register our custom comparator with the service locator
-    ServiceLocatorParamsComparePrx comparatorServicePrx = ServiceLocatorParamsComparePrx::uncheckedCast(
-	mAdapter->addWithUUID(comparatorService));
-    mCompareGuid = IceUtil::generateUUID();
-    mManagement->addCompare(mCompareGuid, comparatorServicePrx);
-
-    // Add our configuration service to the service locator
-    Ice::ObjectPrx configurationServicePrx = mAdapter->addWithUUID(configurationService);
-    mConfigurationServiceManagement = ServiceManagementPrx::uncheckedCast(
-        mManagement->addService(configurationServicePrx, "Configuration/MediaFormatGeneric"));
-
-    // Populate some locator params so we can be found
-    ConfigurationParamsPtr configurationParams = new ConfigurationParams();
-    configurationParams->category = ConfigurationDiscoveryCategory;
-
-    // Tada! Add these and boom we are found
-    mConfigurationServiceManagement->addLocatorParams(configurationParams, "");
-
-    // Add ourselves to the service locator
-    Ice::ObjectPrx descriptorServicePrx = mAdapter->addWithUUID(descriptorService);
-    mServiceManagement = ServiceManagementPrx::uncheckedCast(
-	mManagement->addService(descriptorServicePrx, "Media/SDP_Descriptor"));
-
-    // Populate some locator parameters so we can be found
-    SDPDescriptorServiceLocatorParamsPtr params = new SDPDescriptorServiceLocatorParams();
-    params->category = "Media/SDP_Descriptor";
-
-    // Now we can add these parameters and tada we shall be found
-    mServiceManagement->addLocatorParams(params, mCompareGuid);
-
-    mAdapter->activate();
+    // Include the base Component services. 
+    AsteriskSCF::Component::Component::createBackplaneServices();
+
+    try
+    {
+        // Create an instance of our configuration service
+        mConfigService = new ConfigurationServiceImpl(mSdpDescriptorService, mSdpComparator);
+
+        mConfigServicePrx = ConfigurationServicePrx::uncheckedCast(
+            getBackplaneAdapter()->addWithUUID(mConfigService));
+
+        lg(Debug) << "Created Generic Format Configuration servant";
+
+    }
+    catch(const Ice::Exception& e)
+    {
+       lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+    }
 }
 
 /**
- * Implementation of the IceBox::Service::stop method.
+ * Register this component's primary public interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate our interfaces.
  */
-void MediaFormatGenericApp::stop()
+void Component::preparePrimaryServicesForDiscovery()
 {
-    // Remove our comparator from the service locator
-    mManagement->removeCompare(mCompareGuid);
+    try
+    {
+        // Wrap our authentication extensions point for the Service Locator.
+        mSdpDescriptorRegistration = wrapServiceForRegistration(mSdpDescriptorPrx, 
+                                                                "Media/SDP_Descriptor",
+                                                                getServiceName(),
+                                                                getName());
+
+        managePrimaryService(mSdpDescriptorRegistration);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION << 
+            ". Exception: " << e.what();
+        throw; // rethrow
+    }
+}
 
-    // Remove our configuration service from the service locator
-    mConfigurationServiceManagement->unregister();
 
-    // Remove our SDP descriptor service from the service locator
-    mServiceManagement->unregister();
+/**
+ * Prepare this component's backplane interfaces for discovery via the Service Locator.
+ */
+void Component::prepareBackplaneServicesForDiscovery()
+{
+    // Insure the default Component services are prepped. 
+    AsteriskSCF::Component::Component::prepareBackplaneServicesForDiscovery();
+
+    try
+    {
+        // Wrap our configuration interface for the Service Locator.
+        mConfigurationRegistration = wrapServiceForRegistration(mConfigServicePrx, 
+                                                                ConfigurationDiscoveryCategory);
+        manageBackplaneService(mConfigurationRegistration);
+    }
+    catch(const std::exception& e)
+    {
+        lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION <<  " : " << e.what();
+    }
 }
 
 extern "C"
 {
 ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
 {
-    return new MediaFormatGenericApp;
+    return new Component;
 }
 }

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


-- 
asterisk-scf/release/mediaformatgeneric.git



More information about the asterisk-scf-commits mailing list