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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Jun 20 14:42:07 CDT 2011


branch "master" has been updated
       via  5ab8dc52554d57f2265898924fe099d208730d1d (commit)
       via  669bb7f1ebe9c45a756c82cf5d94152897a6db5e (commit)
       via  9a727a38321226821b3c1dda7ba504a7e824d639 (commit)
      from  424f6070ba77f654b30bf835e093f2921a7d80a4 (commit)

Summary of changes:
 config/MediaFormatGeneric.config                  |   14 +
 config/MediaFormatGenericConfigurator.py          |   62 ++++
 local-slice/MediaFormatGenericConfigurationIf.ice |  104 ++++++
 src/CMakeLists.txt                                |    5 +-
 src/MediaFormatGeneric.cpp                        |  314 ++++++++++---------
 src/MediaFormatGeneric.h                          |   86 +++++
 src/MediaFormatGenericConfiguration.cpp           |  349 +++++++++++++++++++++
 src/MediaFormatGenericConfiguration.h             |   55 ++++
 8 files changed, 842 insertions(+), 147 deletions(-)
 create mode 100644 config/MediaFormatGeneric.config
 create mode 100755 config/MediaFormatGenericConfigurator.py
 create mode 100644 local-slice/MediaFormatGenericConfigurationIf.ice
 create mode 100644 src/MediaFormatGeneric.h
 create mode 100644 src/MediaFormatGenericConfiguration.cpp
 create mode 100644 src/MediaFormatGenericConfiguration.h


- Log -----------------------------------------------------------------
commit 5ab8dc52554d57f2265898924fe099d208730d1d
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Jun 20 16:41:45 2011 -0300

    Finish up configuration support. You can now push basic formats in from a python script. More tweaking to come!

diff --git a/config/MediaFormatGenericConfigurator.py b/config/MediaFormatGenericConfigurator.py
index 7d17d94..f135e28 100755
--- a/config/MediaFormatGenericConfigurator.py
+++ b/config/MediaFormatGenericConfigurator.py
@@ -30,10 +30,11 @@ class MediaFormatGenericSectionVisitors(Configurator.SectionVisitors):
     def __init__(self):
         self.formats = AsteriskSCF.Media.FormatGeneric.V1.FormatsGroup()
         self.formats.configurationItems = { }
-        self.added = False
+        self.groups = [ ]
+        self.groups.append(self.formats)
 
     def visit_unsupported(self, config, section):
-        format = AsteriskSCF.Media.FormatGeneric.FormatItem()
+        format = AsteriskSCF.Media.FormatGeneric.V1.FormatConfigurationItem()
         format.descriptor = AsteriskSCF.Media.SDP.V1.SDPDescriptor()
         format.name = section
 
@@ -43,9 +44,14 @@ class MediaFormatGenericSectionVisitors(Configurator.SectionVisitors):
         format.descriptor.subtype = config.get(section, 'subtype')
         format.descriptor.samplerate = config.getint(section, 'samplerate')
 
-        if self.added == False:
-            self.groups.append(self.formats)
-            self.added = True
+        # Populate the Media format concrete class
+        if format.descriptor.type == 'audio':
+            format.format = AsteriskSCF.Media.V1.AudioFormat()
+        elif format.descriptor.type == 'video':
+            format.format = AsteriskSCF.Media.V1.VideoFormat()
+        format.format.name = section
+
+        self.formats.configurationItems[section] = format
 
 # In order to do service locator based lookup we need to pass in a params object
 serviceLocatorParams = AsteriskSCF.Media.FormatGeneric.V1.ConfigurationParams()
diff --git a/local-slice/MediaFormatGenericConfigurationIf.ice b/local-slice/MediaFormatGenericConfigurationIf.ice
index 8d16145..d4791a0 100644
--- a/local-slice/MediaFormatGenericConfigurationIf.ice
+++ b/local-slice/MediaFormatGenericConfigurationIf.ice
@@ -19,6 +19,7 @@
 #include <Ice/BuiltinSequences.ice>
 #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice>
 #include <AsteriskSCF/System/Component/ConfigurationIf.ice>
+#include <AsteriskSCF/Media/MediaIf.ice>
 #include <AsteriskSCF/Media/SDP/MediaSDPIf.ice>
 
 module AsteriskSCF
@@ -83,6 +84,11 @@ module V1
        string name;
 
        /**
+        * Media format concrete class.
+        */
+       AsteriskSCF::Media::V1::Format format;
+
+       /**
         * SDP Descriptor containing SDP parameters for the format.
         */
        AsteriskSCF::Media::SDP::V1::SDPDescriptor descriptor;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f8ead77..d5db525 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,7 +6,9 @@ asterisk_scf_slice_include_directories(${API_SLICE_DIR})
 
 asterisk_scf_component_init(mediaformatgenetic)
 asterisk_scf_component_add_file(mediaformatgeneric MediaFormatGeneric.cpp)
-asterisk_scf_component_add_boost_libraries(mediaformatgeneric core thread)
+asterisk_scf_component_add_file(mediaformatgeneric MediaFormatGeneric.h)
+asterisk_scf_component_add_file(mediaformatgeneric MediaFormatGenericConfiguration.cpp)
+asterisk_scf_component_add_file(mediaformatgeneric MediaFormatGenericConfiguration.h)
 asterisk_scf_component_add_slice(mediaformatgeneric ../local-slice/MediaFormatGenericConfigurationIf.ice)
 asterisk_scf_component_build_icebox(mediaformatgeneric)
 target_link_libraries(mediaformatgeneric logging-client)
diff --git a/src/MediaFormatGeneric.cpp b/src/MediaFormatGeneric.cpp
index 1db9884..95710e0 100644
--- a/src/MediaFormatGeneric.cpp
+++ b/src/MediaFormatGeneric.cpp
@@ -18,8 +18,6 @@
 #include <IceBox/IceBox.h>
 #include <IceUtil/UUID.h>
 
-#include <boost/shared_ptr.hpp>
-
 #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
 #include <AsteriskSCF/Media/MediaIf.h>
 #include <AsteriskSCF/Media/SDP/MediaSDPIf.h>
@@ -28,11 +26,16 @@
 #include <AsteriskSCF/Logger/IceLogger.h>
 #include <AsteriskSCF/logger.h>
 
+#include "MediaFormatGeneric.h"
+#include "MediaFormatGenericConfiguration.h"
+#include "MediaFormatGenericConfigurationIf.h"
+
 using namespace std;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::Media::SDP::V1;
 using namespace AsteriskSCF::Media::Formats::Audio::V1;
+using namespace AsteriskSCF::Media::FormatGeneric::V1;
 using namespace AsteriskSCF::System::Component::V1;
 using namespace AsteriskSCF::System::Logging;
 
@@ -42,197 +45,198 @@ Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaFormatGeneric");
 }
 
 /**
- * Implementation of the ServiceLocatorParamsCompare class
+ * Implementation of the IceBox::Service class
  */
-class SDPDescriptorCompareServiceImpl : public ServiceLocatorParamsCompare
+class MediaFormatGenericApp : public IceBox::Service
 {
 public:
-    bool isSupported(const ServiceLocatorParamsPtr& params, const Ice::Current&)
-    {
-        SDPDescriptorServiceLocatorParamsPtr descriptorParams = SDPDescriptorServiceLocatorParamsPtr::dynamicCast(params);
+    void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&);
+    void stop();
 
-        if (descriptorParams == 0)
-        {
-            return false;
-        }
+private:
+    /**
+     * Ice Communicator used for this service.
+     */
+    Ice::CommunicatorPtr mCommunicator;
 
-        Ice::StringSeq::const_iterator format = std::find(mSupportedFormats.begin(), mSupportedFormats.end(), descriptorParams->name);
+    /**
+     * Object adapter that stuff is associated with.
+     */
+    Ice::ObjectAdapterPtr mAdapter;
 
-        if (format == mSupportedFormats.end())
-        {
-            return false;
-        }
+    /**
+     * A proxy to the service locator manager for our SDP descriptor service.
+     */
+    ServiceManagementPrx mServiceManagement;
 
-        return true;
-    };
+    /**
+     * A proxy to the service locator manager for our configuration service.
+     */
+    ServiceManagementPrx mConfigurationServiceManagement;
 
-    void addFormat(const std::string& name)
-    {
-        mSupportedFormats.push_back(name);
-    };
+    /**
+     * A proxy to the service locator management service.
+     */
+    ServiceLocatorManagementPrx mManagement;
 
-private:
     /**
-     * Supported formats in named form
+     * Unique guid for SDP descriptor service name comparator.
      */
-    Ice::StringSeq mSupportedFormats;
+    std::string mCompareGuid;
 };
 
-/**
- * Smart pointer for the SDPDescriptorCompareServiceImpl class
- */
-typedef IceUtil::Handle<SDPDescriptorCompareServiceImpl> SDPDescriptorCompareServiceImplPtr;
-
-/**
- * Implementation of the SDPDescriptorService class
- *
- * Note that this does not have a lock on purpose because the supported formats will not
- * be changed once the service goes into operation.
- */
-class SDPDescriptorServiceImpl : public SDPDescriptorService
+bool SDPDescriptorCompareServiceImpl::isSupported(const ServiceLocatorParamsPtr& params, const Ice::Current&)
 {
-public:
-    FormatPtr getNamedFormat(const std::string& name, const Ice::Current&)
-    {
-        std::map<std::string, FormatPtr>::const_iterator format = mNamedFormats.find(name);
+    SDPDescriptorServiceLocatorParamsPtr descriptorParams = SDPDescriptorServiceLocatorParamsPtr::dynamicCast(params);
 
-        if (format == mNamedFormats.end())
-        {
-            return 0;
-        }
+    if (descriptorParams == 0)
+    {
+        return false;
+    }
 
-        return format->second;
-    };
+    Ice::StringSeq::const_iterator format = std::find(mSupportedFormats.begin(), mSupportedFormats.end(), descriptorParams->name);
 
-    FormatPtr getDescribedFormat(const SDPDescriptorPtr& descriptor, const Ice::Current&)
+    if (format == mSupportedFormats.end())
     {
-        if (descriptor->payload < 96)
-        {
-            std::map<int, FormatPtr>::iterator format = mPayloadNumberFormats.find(descriptor->payload);
+        return false;
+    }
 
-            if (format == mPayloadNumberFormats.end())
-            {
-                return 0;
-            }
+    return true;
+}
 
-            return format->second;
-        }
-        else
-        {
-            std::map<std::string, FormatPtr>::iterator format = mPayloadNameFormats.find(descriptor->subtype);
+void SDPDescriptorCompareServiceImpl::addFormat(const std::string& name)
+{
+    mSupportedFormats.push_back(name);
+}
 
-            if (format == mPayloadNameFormats.end())
-            {
-                return 0;
-            }
+void SDPDescriptorCompareServiceImpl::removeFormat(const std::string& name)
+{
+    Ice::StringSeq::iterator format = std::find(mSupportedFormats.begin(), mSupportedFormats.end(), name);
 
-            return format->second;
-        }
+    if (format != mSupportedFormats.end())
+    {
+        mSupportedFormats.erase(format);
+    }
+}
+
+void SDPDescriptorCompareServiceImpl::removeAllFormats()
+{
+    mSupportedFormats.clear();
+}
 
-        // This will never get reached but just in case the compiler is silly...
+FormatPtr SDPDescriptorServiceImpl::getNamedFormat(const std::string& name, const Ice::Current&)
+{
+    std::map<std::string, FormatPtr>::const_iterator format = mNamedFormats.find(name);
+
+    if (format == mNamedFormats.end())
+    {
         return 0;
-    };
+    }
+
+    return format->second;
+}
 
-    SDPDescriptorPtr getDescriptor(const FormatPtr& format, const Ice::Current&)
+FormatPtr SDPDescriptorServiceImpl::getDescribedFormat(const SDPDescriptorPtr& descriptor, const Ice::Current&)
+{
+    if (descriptor->payload < 96)
     {
-        std::map<std::string, SDPDescriptorPtr>::const_iterator descriptor = mFormatDescriptors.find(format->ice_id());
+        std::map<int, FormatPtr>::iterator format = mPayloadNumberFormats.find(descriptor->payload);
 
-        if (descriptor == mFormatDescriptors.end())
+        if (format == mPayloadNumberFormats.end())
         {
             return 0;
         }
 
-        return descriptor->second;
-    };
-
-    /**
-     * Implementation specific function which adds a format to this descriptor service
-     */
-    void addFormat(const std::string& name, const FormatPtr& format, const SDPDescriptorPtr& descriptor)
+        return format->second;
+    }
+    else
     {
-        mNamedFormats.insert(make_pair(name, format));
-        mFormatDescriptors.insert(make_pair(format->ice_id(), descriptor));
+        std::map<std::string, FormatPtr>::iterator format = mPayloadNameFormats.find(descriptor->subtype);
 
-        if (descriptor->payload < 96)
+        if (format == mPayloadNameFormats.end())
         {
-            /*
-             * If this is a static payload we store solely on the payload number itself
-             * since some endpoints do not provide a payload name.
-             */
-            mPayloadNumberFormats.insert(make_pair(descriptor->payload, format));
-        }
-        else
-        {
-            /*
-             * If this is a dynamic payload we store based on the payload name since the
-             * payload number itself is not assigned to it.
-             */
-            mPayloadNameFormats.insert(make_pair(descriptor->subtype, format));
+            return 0;
         }
-    };
 
-private:
-    /**
-     * Mapping for named formats
-     */
-    std::map<std::string, FormatPtr> mNamedFormats;
+        return format->second;
+    }
 
-    /**
-     * Mapping for described formats using static payload number
-     */
-    std::map<int, FormatPtr> mPayloadNumberFormats;
+    // This will never get reached but just in case the compiler is silly...
+    return 0;
+}
 
-    /**
-     * Mapping for described formats using payload name
-     */
-    std::map<std::string, FormatPtr> mPayloadNameFormats;
+SDPDescriptorPtr SDPDescriptorServiceImpl::getDescriptor(const FormatPtr& format, const Ice::Current&)
+{
+    std::map<std::string, SDPDescriptorPtr>::const_iterator descriptor = mFormatDescriptors.find(format->ice_id());
 
-    /**
-     * Mapping for format descriptors
-     */
-    std::map<std::string, SDPDescriptorPtr> mFormatDescriptors;
-};
+    if (descriptor == mFormatDescriptors.end())
+    {
+        return 0;
+    }
 
-/**
- * Smart pointer for the SDPDescriptorServiceImpl class
- */
-typedef IceUtil::Handle<SDPDescriptorServiceImpl> SDPDescriptorServiceImplPtr;
+    return descriptor->second;
+}
 
 /**
- * Implementation of the IceBox::Service class
+ * Implementation specific function which adds a format to this descriptor service
  */
-class MediaFormatGenericApp : public IceBox::Service
+void SDPDescriptorServiceImpl::addFormat(const std::string& name, const FormatPtr& format, const SDPDescriptorPtr& descriptor)
 {
-public:
-    void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&);
-    void stop();
+    mNamedFormats.insert(make_pair(name, format));
+    mFormatDescriptors.insert(make_pair(format->ice_id(), descriptor));
 
-private:
-    /**
-     * Ice Communicator used for this service.
-     */
-    Ice::CommunicatorPtr mCommunicator;
+    if (descriptor->payload < 96)
+    {
+        /*
+         * If this is a static payload we store solely on the payload number itself
+         * since some endpoints do not provide a payload name.
+         */
+        mPayloadNumberFormats.insert(make_pair(descriptor->payload, format));
+    }
+    else
+    {
+        /*
+         * If this is a dynamic payload we store based on the payload name since the
+         * payload number itself is not assigned to it.
+         */
+        mPayloadNameFormats.insert(make_pair(descriptor->subtype, format));
+    }
+}
 
-    /**
-     * Object adapter that stuff is associated with.
-     */
-    Ice::ObjectAdapterPtr mAdapter;
+void SDPDescriptorServiceImpl::removeFormat(const std::string& name)
+{
+    std::map<std::string, AsteriskSCF::Media::V1::FormatPtr>::iterator format = mNamedFormats.find(name);
 
-    /**
-     * A proxy to the service locator manager for our SDP descriptor service.
-     */
-    ServiceManagementPrx mServiceManagement;
+    if (format == mNamedFormats.end())
+    {
+        return;
+    }
 
-    /**
-     * A proxy to the service locator management service.
-     */
-    ServiceLocatorManagementPrx mManagement;
+    std::map<std::string, AsteriskSCF::Media::SDP::V1::SDPDescriptorPtr>::iterator descriptor = mFormatDescriptors.find(
+        format->second->ice_id());
 
-    /**
-     * Unique guid for SDP descriptor service name comparator.
-     */
-    std::string mCompareGuid;
-};
+    if (descriptor->second->payload < 96)
+    {
+        std::map<int, AsteriskSCF::Media::V1::FormatPtr>::iterator number = mPayloadNumberFormats.find(descriptor->second->payload);
+        mPayloadNumberFormats.erase(number);
+    }
+    else
+    {
+        std::map<std::string, AsteriskSCF::Media::V1::FormatPtr>::iterator subtype = mPayloadNameFormats.find(descriptor->second->subtype);
+        mPayloadNameFormats.erase(subtype);
+    }
+
+    mFormatDescriptors.erase(descriptor);
+    mNamedFormats.erase(format);
+}
+
+void SDPDescriptorServiceImpl::removeAllFormats()
+{
+    mNamedFormats.clear();
+    mPayloadNumberFormats.clear();
+    mPayloadNameFormats.clear();
+    mFormatDescriptors.clear();
+}
 
 /**
  * Implementation of the IceBox::Service::start method.
@@ -251,8 +255,11 @@ void MediaFormatGenericApp::start(const std::string&, const Ice::CommunicatorPtr
     // 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
-    ULAWPtr ulaw = new ULAW();
+    G711uLAWPtr ulaw = new G711uLAW();
     SDPDescriptorPtr ulawSDP = new SDPDescriptor();
     ulawSDP->payload = 0;
     ulawSDP->type = "audio";
@@ -262,7 +269,7 @@ void MediaFormatGenericApp::start(const std::string&, const Ice::CommunicatorPtr
     comparatorService->addFormat("ulaw");
 
     // Add the alaw audio format
-    ALAWPtr alaw = new ALAW();
+    G711aLAWPtr alaw = new G711aLAW();
     SDPDescriptorPtr alawSDP = new SDPDescriptor();
     alawSDP->payload = 8;
     alawSDP->type = "audio";
@@ -277,6 +284,18 @@ void MediaFormatGenericApp::start(const std::string&, const Ice::CommunicatorPtr
     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(
@@ -300,6 +319,9 @@ void MediaFormatGenericApp::stop()
     // Remove our comparator from the service locator
     mManagement->removeCompare(mCompareGuid);
 
+    // Remove our configuration service from the service locator
+    mConfigurationServiceManagement->unregister();
+
     // Remove our SDP descriptor service from the service locator
     mServiceManagement->unregister();
 }

commit 669bb7f1ebe9c45a756c82cf5d94152897a6db5e
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Jun 20 16:29:15 2011 -0300

    Add pushable configuration of formats.

diff --git a/src/MediaFormatGeneric.h b/src/MediaFormatGeneric.h
new file mode 100644
index 0000000..c52b931
--- /dev/null
+++ b/src/MediaFormatGeneric.h
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <Ice/Ice.h>
+
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/Media/SDP/MediaSDPIf.h>
+
+class SDPDescriptorCompareServiceImpl : public AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsCompare
+{
+public:
+    bool isSupported(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const Ice::Current&);
+    void addFormat(const std::string&);
+    void removeFormat(const std::string&);
+    void removeAllFormats();
+
+private:
+    /**
+     * Supported formats in named form
+     */
+    Ice::StringSeq mSupportedFormats;
+};
+
+/**
+ * Smart pointer for the SDPDescriptorCompareServiceImpl class
+ */
+typedef IceUtil::Handle<SDPDescriptorCompareServiceImpl> SDPDescriptorCompareServiceImplPtr;
+
+/**
+ * Implementation of the SDPDescriptorService class
+ */
+class SDPDescriptorServiceImpl : public AsteriskSCF::Media::SDP::V1::SDPDescriptorService
+{
+public:
+    AsteriskSCF::Media::V1::FormatPtr getNamedFormat(const std::string&, const Ice::Current&);
+    AsteriskSCF::Media::V1::FormatPtr getDescribedFormat(const AsteriskSCF::Media::SDP::V1::SDPDescriptorPtr&,
+                                                         const Ice::Current&);
+    AsteriskSCF::Media::SDP::V1::SDPDescriptorPtr getDescriptor(const AsteriskSCF::Media::V1::FormatPtr&,
+                                                                const Ice::Current&);
+    void addFormat(const std::string&, const AsteriskSCF::Media::V1::FormatPtr&,
+                   const AsteriskSCF::Media::SDP::V1::SDPDescriptorPtr&);
+    void removeFormat(const std::string&);
+    void removeAllFormats();
+
+private:
+    /**
+     * Mapping for named formats
+     */
+    std::map<std::string, AsteriskSCF::Media::V1::FormatPtr> mNamedFormats;
+
+    /**
+     * Mapping for described formats using static payload number
+     */
+    std::map<int, AsteriskSCF::Media::V1::FormatPtr> mPayloadNumberFormats;
+
+    /**
+     * Mapping for described formats using payload name
+     */
+    std::map<std::string, AsteriskSCF::Media::V1::FormatPtr> mPayloadNameFormats;
+
+    /**
+     * Mapping for format descriptors
+     */
+    std::map<std::string, AsteriskSCF::Media::SDP::V1::SDPDescriptorPtr> mFormatDescriptors;
+};
+
+/**
+ * Smart pointer for the SDPDescriptorServiceImpl class
+ */
+typedef IceUtil::Handle<SDPDescriptorServiceImpl> SDPDescriptorServiceImplPtr;
diff --git a/src/MediaFormatGenericConfiguration.cpp b/src/MediaFormatGenericConfiguration.cpp
new file mode 100644
index 0000000..c205d86
--- /dev/null
+++ b/src/MediaFormatGenericConfiguration.cpp
@@ -0,0 +1,349 @@
+/*
+ * 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 <IceUtil/UUID.h>
+
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+#include "MediaFormatGenericConfigurationIf.h"
+#include "MediaFormatGenericConfiguration.h"
+#include "MediaFormatGeneric.h"
+
+using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::Media::FormatGeneric::V1;
+
+class ConfigurationServiceImplPriv
+{
+public:
+    ConfigurationServiceImplPriv(const SDPDescriptorServiceImplPtr& descriptorService,
+                                 const SDPDescriptorCompareServiceImplPtr& comparatorService) :
+        mDescriptorService(descriptorService), mComparatorService(comparatorService) { };
+
+    /**
+     * Formats configuration group
+     */
+    FormatsGroupPtr mFormatsGroup;
+
+    /**
+     * A pointer to the SDP descriptor service implementation.
+     */
+    SDPDescriptorServiceImplPtr mDescriptorService;
+
+    /**
+     * A pointer to the SDP descriptor comparator service implementation.
+     */
+    SDPDescriptorCompareServiceImplPtr mComparatorService;
+
+    /**
+     * Shared mutex lock which protects the configuration
+     */
+    boost::shared_mutex mLock;
+};
+
+ConfigurationServiceImpl::ConfigurationServiceImpl(const SDPDescriptorServiceImplPtr& descriptorService,
+                                                   const SDPDescriptorCompareServiceImplPtr& comparatorService) :
+    mImplPriv(new ConfigurationServiceImplPriv(descriptorService, comparatorService))
+{
+}
+
+ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public FormatsConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv, ConfigurationGroupSeq& visitorGroups) : mImplPriv(implPriv), mGroups(visitorGroups) { };
+
+    private:
+        /**
+         * Internal helper function which determines what configuration items should be returned
+         */
+        void insertRequestedConfigurationItems(const ConfigurationItemDict& requestedItems,
+            const ConfigurationItemDict& localItems,
+            ConfigurationItemDict& returnedItems)
+        {
+
+            boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+            for (ConfigurationItemDict::const_iterator requestedItem = requestedItems.begin();
+                 requestedItem != requestedItems.end();
+                 ++requestedItem)
+            {
+                ConfigurationItemDict::const_iterator localItem = localItems.find(requestedItem->first);
+
+                if (localItem != localItems.end())
+                {
+                    returnedItems.insert((*requestedItem));
+                }
+            }
+        }
+
+        void visitFormatsGroup(const FormatsGroupPtr& group)
+        {
+            if (!mImplPriv->mFormatsGroup)
+            {
+                return;
+            }
+
+            FormatsGroupPtr returnedGroup = new FormatsGroup();
+
+            insertRequestedConfigurationItems(group->configurationItems, mImplPriv->mFormatsGroup->configurationItems, returnedGroup->configurationItems);
+
+            mGroups.push_back(returnedGroup);
+        };
+
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+        ConfigurationGroupSeq& mGroups;
+    };
+    
+    ConfigurationGroupSeq newGroups;
+    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv, newGroups);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+    
+    return newGroups;
+}
+
+ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public FormatsConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv, ConfigurationGroupSeq& visitorGroups) :
+            mImplPriv(implPriv), mGroups(visitorGroups) { };
+ 
+    private:
+        void visitFormatsGroup(const FormatsGroupPtr&)
+        {
+            if (!mImplPriv->mFormatsGroup)
+            {
+                return;
+            }
+     
+            mGroups.push_back(mImplPriv->mFormatsGroup);
+        };
+        
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+        ConfigurationGroupSeq& mGroups;
+    };
+    
+    ConfigurationGroupSeq newGroups;
+    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv, newGroups);
+
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+    
+    return newGroups;
+}
+
+ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationGroups(const Ice::Current&)
+{
+    ConfigurationGroupSeq groups;
+ 
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+   
+    if (mImplPriv->mFormatsGroup)
+    {
+        FormatsGroupPtr general = new FormatsGroup();
+        groups.push_back(general);
+    }
+    
+    return groups;
+}
+
+void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public FormatsConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
+ 
+    private:
+        /**
+         * Helper function which performs serial number checking of items
+         */
+        void performSerialCheck(const ConfigurationItemDict& changedItems, const ConfigurationItemDict& localItems,
+            const AsteriskSCF::System::Configuration::V1::ConfigurationGroupPtr& group)
+        {
+            for (ConfigurationItemDict::const_iterator item = changedItems.begin();
+                 item != changedItems.end();
+                 ++item)
+            {
+                // If serial checking is to be skipped for this item just skip over it
+                if (item->second->serialNumber == -1)
+                {
+                    continue;
+                }
+  
+                ConfigurationItemDict::const_iterator localItem = localItems.find(item->first);
+  
+                if (localItem == localItems.end())
+                {
+                    // This is a new item so serial checking does not apply
+                    continue;
+                }
+  
+                if (item->second->serialNumber < localItem->second->serialNumber)
+                {
+                    throw SerialConflict(group, item->second);
+                }
+            }
+        }
+ 
+        void visitFormatsGroup(const FormatsGroupPtr& group)
+        {
+            if (!mImplPriv->mFormatsGroup)
+            {
+                mImplPriv->mFormatsGroup = new FormatsGroup();
+            }
+            else
+            {
+                performSerialCheck(group->configurationItems, mImplPriv->mFormatsGroup->configurationItems, group);
+            }
+     
+            for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
+                 item != group->configurationItems.end();
+                 ++item)
+            {
+                FormatConfigurationItemPtr format;
+
+                if ((format = FormatConfigurationItemPtr::dynamicCast((item->second))))
+                {
+                    mImplPriv->mDescriptorService->addFormat(format->name, format->format, format->descriptor);
+                    mImplPriv->mComparatorService->addFormat(format->name);
+                }
+
+                mImplPriv->mFormatsGroup->configurationItems.erase(item->first);
+                mImplPriv->mFormatsGroup->configurationItems.insert((*item));
+            }
+        }
+ 
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+    };
+    
+    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+void ConfigurationServiceImpl::removeConfigurationItems(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public FormatsConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
+        
+        void removeItems(FormatsConfigurationItemVisitor* visitor, ConfigurationItemDict& itemsToRemove,
+                         ConfigurationItemDict& localItems)
+        {
+            for (ConfigurationItemDict::const_iterator item = itemsToRemove.begin();
+                 item != itemsToRemove.end();
+                 ++item)
+            {
+                ConfigurationItemDict::iterator localItem = localItems.find(item->first);
+                if (localItem ==  localItems.end())
+                {
+                    continue;
+                }
+                if (visitor != 0)
+                {
+                    item->second->visit(visitor);
+                }
+
+		FormatConfigurationItemPtr format;
+
+                if ((format = FormatConfigurationItemPtr::dynamicCast((localItem->second))))
+                {
+                    mImplPriv->mDescriptorService->removeFormat(format->name);
+                    mImplPriv->mComparatorService->removeFormat(format->name);
+                }
+
+                localItems.erase(localItem);
+            }
+        }
+ 
+        void visitFormatsGroup(const FormatsGroupPtr& group)
+        {
+            if (!mImplPriv->mFormatsGroup)
+            {
+                return;
+            }
+            
+            removeItems(0, group->configurationItems, mImplPriv->mFormatsGroup->configurationItems);
+        };
+ 
+    private:
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+    };
+    
+    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+void ConfigurationServiceImpl::removeConfigurationGroups(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public FormatsConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
+ 
+    private:
+        void visitFormatsGroup(const FormatsGroupPtr&)
+        {
+            if (!mImplPriv->mFormatsGroup)
+            {
+                return;
+            }
+
+            mImplPriv->mDescriptorService->removeAllFormats();
+            mImplPriv->mComparatorService->removeAllFormats();
+            
+            mImplPriv->mFormatsGroup = 0;
+        };
+        
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+    };
+    
+    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
diff --git a/src/MediaFormatGenericConfiguration.h b/src/MediaFormatGenericConfiguration.h
new file mode 100644
index 0000000..5982fc7
--- /dev/null
+++ b/src/MediaFormatGenericConfiguration.h
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <Ice/Ice.h>
+
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+#include "MediaFormatGeneric.h"
+
+/*
+ * Private implementation class for ConfigurationServiceImpl.
+ */
+class ConfigurationServiceImplPriv;
+
+/**
+ * Implementation of the configuration service.
+ */
+class ConfigurationServiceImpl : public AsteriskSCF::System::Configuration::V1::ConfigurationService
+{
+public:
+    ConfigurationServiceImpl(const SDPDescriptorServiceImplPtr&, const SDPDescriptorCompareServiceImplPtr&);
+
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfigurationAll(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfigurationGroups(const Ice::Current&);
+    void setConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    void removeConfigurationItems(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    void removeConfigurationGroups(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+
+private:
+    /**
+     * Private implementation details.
+     */
+    boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+};
+
+/**
+ * A typedef which creates a smart pointer type for ConfigurationServiceImpl.
+ */
+typedef IceUtil::Handle<ConfigurationServiceImpl> ConfigurationServiceImplPtr;

commit 9a727a38321226821b3c1dda7ba504a7e824d639
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Jun 20 12:50:32 2011 -0300

    Add configuration slice for this component, as well as a python configurator and example configuration file.

diff --git a/config/MediaFormatGeneric.config b/config/MediaFormatGeneric.config
new file mode 100644
index 0000000..7e550d9
--- /dev/null
+++ b/config/MediaFormatGeneric.config
@@ -0,0 +1,14 @@
+# Define a dummy format
+[bob8]
+
+# Type of media this format is for, valid options are audio and video
+type=audio
+
+# RTP payload for this format
+payload=101
+
+# SDP subtype
+subtype=BOB
+
+# Sample rate, obviously
+samplerate=8000
diff --git a/config/MediaFormatGenericConfigurator.py b/config/MediaFormatGenericConfigurator.py
new file mode 100755
index 0000000..7d17d94
--- /dev/null
+++ b/config/MediaFormatGenericConfigurator.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+#
+# 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.
+#
+
+# Rtp configurator
+
+# Bring in the common configuration infrastructure
+import Ice, Configurator, sys
+
+# Load our component specific configuration definitions
+Ice.loadSlice('-I. -I/opt/Ice-3.4.1/slice -I../../slice --all ../local-slice/MediaFormatGenericConfigurationIf.ice')
+import AsteriskSCF.Media.FormatGeneric.V1
+
+# Add our own visitor implementations for the sections we support
+class MediaFormatGenericSectionVisitors(Configurator.SectionVisitors):
+    def __init__(self):
+        self.formats = AsteriskSCF.Media.FormatGeneric.V1.FormatsGroup()
+        self.formats.configurationItems = { }
+        self.added = False
+
+    def visit_unsupported(self, config, section):
+        format = AsteriskSCF.Media.FormatGeneric.FormatItem()
+        format.descriptor = AsteriskSCF.Media.SDP.V1.SDPDescriptor()
+        format.name = section
+
+        # Populate the SDP descriptor with configured values
+        format.descriptor.payload = config.getint(section, 'payload')
+        format.descriptor.type = config.get(section, 'type')
+        format.descriptor.subtype = config.get(section, 'subtype')
+        format.descriptor.samplerate = config.getint(section, 'samplerate')
+
+        if self.added == False:
+            self.groups.append(self.formats)
+            self.added = True
+
+# In order to do service locator based lookup we need to pass in a params object
+serviceLocatorParams = AsteriskSCF.Media.FormatGeneric.V1.ConfigurationParams()
+serviceLocatorParams.category = AsteriskSCF.Media.FormatGeneric.V1.ConfigurationDiscoveryCategory
+
+# Make a configurator application and let it run
+app = Configurator.ConfiguratorApp('MediaFormatGeneric.config', MediaFormatGenericSectionVisitors(), None, serviceLocatorParams)
+sys.exit(app.main(sys.argv))
diff --git a/local-slice/MediaFormatGenericConfigurationIf.ice b/local-slice/MediaFormatGenericConfigurationIf.ice
new file mode 100644
index 0000000..8d16145
--- /dev/null
+++ b/local-slice/MediaFormatGenericConfigurationIf.ice
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <Ice/BuiltinSequences.ice>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice>
+#include <AsteriskSCF/System/Component/ConfigurationIf.ice>
+#include <AsteriskSCF/Media/SDP/MediaSDPIf.ice>
+
+module AsteriskSCF
+{
+
+module Media
+{
+
+module FormatGeneric
+{
+
+["suppress"]
+module V1
+{
+   /**
+    * Service locator category for finding the configuration service
+    */
+   const string ConfigurationDiscoveryCategory = "MediaFormatGenericConfiguration";
+
+   /**
+    * Service locator parameters class for discovering the configuration service
+    */
+   unsliceable class ConfigurationParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
+   {
+       /**
+	* Unique name for the configuration service
+	*/
+       string name;
+   };
+
+   /**
+    * Local visitor class for visiting formats group
+    */
+   local class FormatsConfigurationGroupVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationGroupVisitor
+   {
+   };
+
+   /**
+    * User defined media format configuration group
+    */
+   ["visitor:FormatsConfigurationGroupVisitor"] class FormatsGroup extends AsteriskSCF::System::Configuration::V1::ConfigurationGroup
+   {
+   };
+
+   /**
+    * Local visitor class for visiting format item
+    */
+   local class FormatsConfigurationItemVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationItemVisitor
+   {
+   };
+
+   /**
+    * Individual format configuration item
+    *
+    * This should be inserted into the group using the unique format name.
+    */
+   ["visitor:FormatsConfigurationItemVisitor"] class FormatConfigurationItem extends AsteriskSCF::System::Configuration::V1::ConfigurationItem
+   {
+       /**
+        * Name of the format.
+        */
+       string name;
+
+       /**
+        * SDP Descriptor containing SDP parameters for the format.
+        */
+       AsteriskSCF::Media::SDP::V1::SDPDescriptor descriptor;
+   };
+
+}; /* module V1 */
+
+}; /* module RTP */
+
+}; /* module Media */
+
+}; /* module Asterisk SCF */
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fb48104..f8ead77 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,7 @@ asterisk_scf_slice_include_directories(${API_SLICE_DIR})
 asterisk_scf_component_init(mediaformatgenetic)
 asterisk_scf_component_add_file(mediaformatgeneric MediaFormatGeneric.cpp)
 asterisk_scf_component_add_boost_libraries(mediaformatgeneric core thread)
+asterisk_scf_component_add_slice(mediaformatgeneric ../local-slice/MediaFormatGenericConfigurationIf.ice)
 asterisk_scf_component_build_icebox(mediaformatgeneric)
 target_link_libraries(mediaformatgeneric logging-client)
 target_link_libraries(mediaformatgeneric asterisk-scf-api)

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


-- 
asterisk-scf/integration/mediaformatgeneric.git



More information about the asterisk-scf-commits mailing list