[asterisk-scf-commits] asterisk-scf/integration/file_media_service.git branch "initial_development" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jan 10 12:36:30 CST 2012


branch "initial_development" has been updated
       via  c41ae398a9a76b91868f5e6221eeca964a4971e4 (commit)
       via  32be5e591671578e4aa438347b29b5f965a235be (commit)
       via  915f96365b7f1f6b5d42bd4d943d098215179334 (commit)
      from  617046b139730653a0aa0baf5caf427193a1b503 (commit)

Summary of changes:
 config/FileMediaServiceConfigurator.py             |   21 ++--
 .../FileMediaServiceConfigurationIf.ice            |    1 -
 src/Component.cpp                                  |    7 +-
 src/Configuration.cpp                              |   57 ++++++--
 src/ContainerConfigurationAdapter.h                |    2 +
 src/ContainerImpl.cpp                              |  161 +++++++++++++++++---
 src/ContainerImpl.h                                |    7 +-
 src/ContainerRepository.cpp                        |  122 ++++++++++++++-
 src/RepositoryConfigurationAdapter.h               |   33 ++++-
 9 files changed, 348 insertions(+), 63 deletions(-)


- Log -----------------------------------------------------------------
commit c41ae398a9a76b91868f5e6221eeca964a4971e4
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Jan 10 15:05:48 2012 -0330

    Fixup configuration script and missing supported format sequence parameter
    passing for source managers.

diff --git a/config/FileMediaServiceConfigurator.py b/config/FileMediaServiceConfigurator.py
index 93c86a7..151dbba 100755
--- a/config/FileMediaServiceConfigurator.py
+++ b/config/FileMediaServiceConfigurator.py
@@ -64,8 +64,9 @@ class SectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_container_group(self, config, section):
-        group = AsteriskSCF.Configuration.FileMediaService.V1.ContainerGroup()
-        group.configurationItems = { }
+        if not self.containerGroup:
+            self.containerGroup = AsteriskSCF.Configuration.FileMediaService.V1.ContainerGroup()
+            group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
 
@@ -83,21 +84,19 @@ class SectionVisitors(Configurator.SectionVisitors):
                     return AsteriskSCF.Media.File.V1.FileOperations.Recording
                 if (self.config.get(section, item) == 'both'):
                     return AsteriskSCF.Media.File.V1.FileOperations.Both
+                
 
         mapper = Configurator.OptionMapper()
         item = AsteriskSCF.Configuration.FileMediaService.V1.ContainerConfiguration()
-        mapper.map('catalog_id', item, 'catalogId',
-                   AsteriskSCF.Configuration.FileMediaService.V1.ContainerConfigurationItem, config.get, None)
-        mapper.map('path', item, 'uri',
-                   AsteriskSCF.Configuration.FileMediaService.V1.ContainerConfigurationItem, config.get, None)
+        item.catalogId = section
+        mapper.map('path', item, 'uri', item.catalogId, config.get, None)
         fileOpTransformer = FileOperationTransformer(config)
         mapper.map('supported_operations', item, 'operations',
-                   AsteriskSCF.Configuration.FileMediaService.V1.ContainerConfigurationItem, fileOpTransformer.get,
-                   AsteriskSCF.Media.File.V1.FileOperations.Playback)
+                   item.catalogId, fileOpTransformer.get, AsteriskSCF.Media.File.V1.FileOperations.Playback)
         for option in config.options(section):
-            mapper.execute(group, section, option)
-        mapper.finish(group)
-        self.groups.append(group)
+            mapper.execute(self.containerGroup, section, option)
+        mapper.finish(self.containerGroup)
+        self.groups.append(self.containerGroup)
 
     def visit_unsupported(self, config, section):
         if config.get(section, 'type') == 'repository':
diff --git a/src/Component.cpp b/src/Component.cpp
index b7239a4..f4304b0 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -221,11 +221,8 @@ public:
 
     void preparePrimaryServicesForDiscovery()
     {
-        //
-        // XXX: create feature for the repo or change how this is activated.
-        //
-//        mMediaServicePrx = AsteriskSCF::Media::File::V1::FileMediaServicePrx::uncheckedCast(
-//            mContainerRepository->activate(getServiceAdapter()));
+        mMediaServicePrx = mContainerRepository->mediaService();
+        addFeatureProxyToServices(mMediaServicePrx, AsteriskSCF::Media::File::V1::DiscoveryCategory);
     }
 
 private:
diff --git a/src/ContainerImpl.cpp b/src/ContainerImpl.cpp
index 26d8f9b..6f68ed4 100644
--- a/src/ContainerImpl.cpp
+++ b/src/ContainerImpl.cpp
@@ -1228,12 +1228,13 @@ public:
     class SourceManager : public AsteriskSCF::Media::V1::StreamSink
     {
     public:
-        SourceManager(const string& id, const FrameWriterPtr& writer, unsigned trackNo) :
+        SourceManager(const string& id, const FrameWriterPtr& writer, const AsteriskSCF::Media::V1::FormatPtr& format, unsigned trackNo) :
             mId(id),
             mWriter(writer),
             mTrack(trackNo),
             mWriting(false)
         {
+            mSupportedFormats.push_back(format);
         }
 
         void write(const AsteriskSCF::Media::V1::FrameSeq& newFrames, const Ice::Current&) 
@@ -1266,11 +1267,11 @@ public:
 
         AsteriskSCF::Media::V1::FormatSeq getFormats(const Ice::Current&)
         {
+            SharedLock lock(mLock);
             //
-            // XXX
+            // TODO: right now, the only media format we can really support is signed linear. 
             //
-            SharedLock lock(mLock);
-            return AsteriskSCF::Media::V1::FormatSeq();
+            return mSupportedFormats;
         }
 
         string getId(const Ice::Current&)
@@ -1301,6 +1302,7 @@ public:
         IceUtil::Time mStartTime;
         AsteriskSCF::Media::V1::FrameSeq mQueuedFrames;
         boost::shared_mutex mLock;
+        AsteriskSCF::Media::V1::FormatSeq mSupportedFormats;
     };
     typedef IceUtil::Handle<SourceManager> SourceManagerPtr;
     typedef vector<SourceManagerPtr> SourceManagers;
@@ -1457,9 +1459,6 @@ public:
             }
             mWriter = new FrameWriter(mContainer, static_cast<unsigned int>(mSpec.formats.size()));
         }
-        //
-        // XXX exceptions should be logged.
-        //
         catch (const exception& ex)
         {
             if (mStream)
@@ -1483,9 +1482,11 @@ public:
         // in exception handlers is ickier.
         //
         int trackNumber = 1;
+        AsteriskSCF::Media::V1::FormatSeq::const_iterator formatIter = mSpec.formats.begin();
         for (vector<string>::const_iterator iter = trackIds.begin(); iter != trackIds.end(); ++iter)
         {
-            SourceManagerPtr s = new SourceManager(*iter, mWriter, trackNumber++);
+            AsteriskSCF::Media::V1::FormatPtr thisTracksFormat = *formatIter;
+            SourceManagerPtr s = new SourceManager(*iter, mWriter, thisTracksFormat, trackNumber++);
             mSourceManagers.push_back(s);
             mSinks.push_back(AsteriskSCF::Media::V1::StreamSinkPrx::uncheckedCast(mObjectAdapter->add(s,
                             mObjectAdapter->getCommunicator()->stringToIdentity(*iter))));
diff --git a/src/ContainerRepository.cpp b/src/ContainerRepository.cpp
index 8a257b3..93c2ede 100644
--- a/src/ContainerRepository.cpp
+++ b/src/ContainerRepository.cpp
@@ -468,7 +468,7 @@ AsteriskSCF::Media::File::V1::FileMediaServicePrx ContainerRepositoryServant::me
         }
     }
     return AsteriskSCF::Media::File::V1::FileMediaServicePrx::uncheckedCast(
-        mAdapter->createProxy(mAdapter->getCommunicator()->stringToIdentity(mName)));
+        mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(mName)));
 }
 
 RepositoryConfigurationAdapterPtr ContainerRepositoryServant::configurationAdapter()

commit 32be5e591671578e4aa438347b29b5f965a235be
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Jan 10 12:51:03 2012 -0330

    Fix up lots of configuration issues (script change outstanding)

diff --git a/slice/AsteriskSCF/Configuration/FileMediaService/FileMediaServiceConfigurationIf.ice b/slice/AsteriskSCF/Configuration/FileMediaService/FileMediaServiceConfigurationIf.ice
index 745770b..8d6101c 100644
--- a/slice/AsteriskSCF/Configuration/FileMediaService/FileMediaServiceConfigurationIf.ice
+++ b/slice/AsteriskSCF/Configuration/FileMediaService/FileMediaServiceConfigurationIf.ice
@@ -113,7 +113,6 @@ class ContainerGroup extends FileMediaServiceGroup
 {
 };
 
-const string ContainerConfigurationItem = "containerSpecification";
 class ContainerConfiguration extends FileMediaServiceItem
 {
     /**
diff --git a/src/Configuration.cpp b/src/Configuration.cpp
index 227958c..b2ea921 100644
--- a/src/Configuration.cpp
+++ b/src/Configuration.cpp
@@ -99,16 +99,21 @@ public:
             ContainerGroupPtr containerGroup = ContainerGroupPtr::dynamicCast(*iter);
             if (containerGroup)
             {
-                ConfigurationItemDict::const_iterator itemIter =
-                    containerGroup->configurationItems.find(ContainerConfigurationItem);
-                if (itemIter != containerGroup->configurationItems.end())
+                //
+                // Basically the deal is that the containers are stored by
+                // catalog id so we need to iterate through them all. Since
+                // everything in container group should be a container, we
+                // don't really expect to see anything that is not
+                // container configuration.
+                //
+                ContainerGroupPtr resultGroup = new ContainerGroup;
+                for (ConfigurationItemDict::const_iterator itemIter = containerGroup->configurationItems.begin();
+                     itemIter != containerGroup->configurationItems.end(); ++itemIter)
                 {
-                    ContainerConfigurationPtr containerQuery =
-                        ContainerConfigurationPtr::dynamicCast(itemIter->second);
-                    if (containerQuery)
+                    if (!itemIter->first.empty())
                     {
                         ContainerConfigurationAdapterPtr containerConfig =
-                            configAdapter->getContainer(containerQuery->catalogId);
+                            configAdapter->getContainer(itemIter->first);
                         if (containerConfig)
                         {
                             ContainerConfigurationPtr containerData =
@@ -116,13 +121,14 @@ public:
                             containerData->catalogId = containerConfig->catalogId();
                             containerData->uri = containerConfig->uri();
                             containerData->operations = containerConfig->operations();
-                            ContainerGroupPtr resultGroup = new ContainerGroup;
-                            resultGroup->configurationItems[ContainerConfigurationItem] = containerData;
-                            result.push_back(resultGroup);
-
+                            resultGroup->configurationItems[containerData->catalogId] = containerData;
                         }
                     }
                 }
+                if (!resultGroup->configurationItems.empty())
+                {
+                    result.push_back(resultGroup);
+                }
                 continue;
             }
         }
@@ -141,16 +147,39 @@ public:
             {
                 ProgressUpdateIntervalPtr updateInterval = new ProgressUpdateInterval;
                 updateInterval->value = configAdapter->getProgressUpdateInterval();
+                ReplicationParameterGroupPtr group = new ReplicationParameterGroup;
+                group->configurationItems[ProgressUpdateIntervalItem] = updateInterval;
+                result.push_back(group);
                 continue;
             }
-            ContainerConfigurationPtr containerGroup = ContainerConfigurationPtr::dynamicCast(*iter);
+            ContainerGroupPtr containerGroup = ContainerGroupPtr::dynamicCast(*iter);
             if (containerGroup)
             {
+                ContainerGroupPtr group = new ContainerGroup;
+                ContainerConfigurationAdapterSeq containers = configAdapter->getContainers();
+                for (ContainerConfigurationAdapterSeq::const_iterator containerIter = containers.begin();
+                     containerIter != containers.end(); ++containerIter)
+                {
+                    ContainerConfigurationAdapterPtr containerConfig = *containerIter;
+                    ContainerConfigurationPtr containerData =
+                        new ContainerConfiguration;
+                    containerData->catalogId = containerConfig->catalogId();
+                    containerData->uri = containerConfig->uri();
+                    containerData->operations = containerConfig->operations();
+                    group->configurationItems[containerData->catalogId] = containerData;
+                }
+                result.push_back(group);
                 continue;
             }
+            
             RepositoryGroupPtr repositoryGroup = RepositoryGroupPtr::dynamicCast(*iter);
             if (repositoryGroup)
             {
+                RepositoryLocationPtr location = new RepositoryLocation;
+                location->pathname = configAdapter->getRootPath();
+                RepositoryGroupPtr group = new RepositoryGroup;
+                result.push_back(group);
+                group->configurationItems[RepositoryLocationItem] = location;
                 continue;
             }
         }
@@ -161,6 +190,10 @@ public:
     ConfigurationGroupSeq getConfigurationGroups(const Ice::Current&)
     {
         ConfigurationGroupSeq groups;
+
+        groups.push_back(new RepositoryGroup);
+        groups.push_back(new ContainerGroup);
+        groups.push_back(new ReplicationParameterGroup);
         return groups;
     }
 
diff --git a/src/ContainerConfigurationAdapter.h b/src/ContainerConfigurationAdapter.h
index 1335e02..d73dcc9 100644
--- a/src/ContainerConfigurationAdapter.h
+++ b/src/ContainerConfigurationAdapter.h
@@ -18,6 +18,7 @@
 
 #include <IceUtil/Handle.h>
 #include <AsteriskSCF/Media/File/FileMediaIf.h>
+#include <vector>
 
 namespace AsteriskSCF
 {
@@ -40,6 +41,7 @@ public:
 };
 
 typedef IceUtil::Handle<ContainerConfigurationAdapter> ContainerConfigurationAdapterPtr;
+typedef std::vector<ContainerConfigurationAdapterPtr> ContainerConfigurationAdapterSeq;
 
 } /* End of namespace FileMediaService */
 } /* End of namespace AsteriskSCF */
diff --git a/src/ContainerImpl.cpp b/src/ContainerImpl.cpp
index 62a146c..26d8f9b 100644
--- a/src/ContainerImpl.cpp
+++ b/src/ContainerImpl.cpp
@@ -50,6 +50,16 @@ namespace FileMediaService
 namespace Implementation
 {
 
+class ConfigUpdateImpl : public virtual IceUtil::Shared
+{
+public:
+    virtual ~ConfigUpdateImpl(){}
+
+    virtual void update(const ContainerInfoPtr& info) = 0;
+};
+
+typedef IceUtil::Handle<ConfigUpdateImpl> ConfigUpdateImplPtr;
+
 typedef boost::unique_lock<boost::shared_mutex> UniqueLock;
 typedef boost::shared_lock<boost::shared_mutex> SharedLock;
 
@@ -1498,7 +1508,7 @@ private:
 };
 typedef IceUtil::Handle<RecordingSessionImpl> RecordingSessionImplPtr;
 
-class ContainerServant : public ContainerImpl
+class ContainerServant : public ContainerImpl, virtual public ConfigUpdateImpl
 {
 public:
     ContainerServant(const ContainerInfoPtr& info, 
@@ -1506,6 +1516,7 @@ public:
         Matroska::Environment* matroskaEnvironment,
         const Ice::ObjectAdapterPtr& adapter, const Logger& logger) :
         ContainerImpl(info->catalogId),
+        mDestroyed(false),
         mInfo(info),
         mSpec(spec),
         mMatroskaEnvironment(matroskaEnvironment),
@@ -1542,6 +1553,53 @@ public:
         mInfo->supportedOperations = supportedOperations;
     }
 
+    void destroy()
+    {
+        UniqueLock lock(mLock);
+        mDestroyed = true;
+    }
+
+    class ConfigurationAdapterImpl : public ContainerConfigurationAdapter
+    {
+    public:
+        ConfigurationAdapterImpl(const ContainerInfoPtr& info, const ConfigUpdateImplPtr& updateTarget) :
+            mInfo(new ContainerInfo),
+            mTarget(updateTarget)
+        {
+            *mInfo = *info;
+        }
+
+        string catalogId()
+        {
+            return mInfo->catalogId;
+        }
+
+        string uri()
+        {
+            return mInfo->filename;
+        }
+
+        AsteriskSCF::Media::File::V1::FileOperations operations()
+        {
+            return mInfo->supportedOperations;
+        }
+
+        void update(const string& uriParam, AsteriskSCF::Media::File::V1::FileOperations supportedOperations)
+        {
+            mInfo->filename = uriParam;
+            mInfo->supportedOperations = supportedOperations;
+            mTarget->update(mInfo);
+        }
+    private:
+        ContainerInfoPtr mInfo;
+        ConfigUpdateImplPtr mTarget;
+    };
+
+    ContainerConfigurationAdapterPtr configurationAdapter()
+    {
+        return new ConfigurationAdapterImpl(getInfo(), this);
+    }
+
     ContainerInfoPtr getInfo()
     {
         return getInfoImpl();
@@ -1549,6 +1607,7 @@ public:
 
     AsteriskSCF::Media::File::V1::FileSessionPrx getMediaSession()
     {
+        stateCheck();
         if (mInfo->supportedOperations == AsteriskSCF::Media::File::V1::Playback)
         {
             string id = getInfoImpl()->catalogId;
@@ -1596,8 +1655,16 @@ public:
         return 0;
     }
 
+        void update(const ContainerInfoPtr& info)
+        {
+            UniqueLock lock(mLock);
+            mInfo->filename  = info->filename;
+            mInfo->supportedOperations = info->supportedOperations;
+        }
+
 private:
     boost::shared_mutex mLock;
+    bool mDestroyed;
 
     ContainerInfoPtr mInfo;
     AsteriskSCF::Media::File::V1::FileMediaSpecification mSpec;
@@ -1605,6 +1672,15 @@ private:
     Ice::ObjectAdapterPtr mAdapter;
     Logger mLogger;
 
+    void stateCheck()
+    {
+        SharedLock lock(mLock);
+        if (mDestroyed)
+        {
+            throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+        }
+    }
+
     ContainerInfoPtr getInfoImpl()
     {
         SharedLock lock(mLock);
diff --git a/src/ContainerImpl.h b/src/ContainerImpl.h
index 1dd9966..ada80b5 100644
--- a/src/ContainerImpl.h
+++ b/src/ContainerImpl.h
@@ -20,6 +20,7 @@
 #include "ContainerRepository.h"
 #include "ContainerInfo.h"
 #include "ReplicatedObject.h"
+#include "ContainerConfigurationAdapter.h"
 
 #include <AsteriskSCF/Media/File/FileMediaIf.h>
 #include <vector>
@@ -37,7 +38,7 @@ namespace AsteriskSCF
 namespace FileMediaService
 {
 
-class ContainerImpl : public IceUtil::Shared,
+class ContainerImpl : virtual public IceUtil::Shared,
                       public ReplicatedObject
 {
 public:
@@ -51,6 +52,10 @@ public:
     virtual void updateInfo(const std::string& uri, 
         const AsteriskSCF::Media::File::V1::FileOperations supportedOperations) = 0;
 
+    virtual void destroy() = 0;
+
+    virtual ContainerConfigurationAdapterPtr configurationAdapter() = 0; 
+
     static IceUtil::Handle<ContainerImpl> create(
         const ContainerInfoPtr& info,
         const AsteriskSCF::Media::File::V1::FileMediaSpecification& spec, 
diff --git a/src/ContainerRepository.cpp b/src/ContainerRepository.cpp
index 733f462..8a257b3 100644
--- a/src/ContainerRepository.cpp
+++ b/src/ContainerRepository.cpp
@@ -71,6 +71,8 @@ public:
     ContainerImplSeq getContainerList();
     ContainerImplPtr getContainer(const string& containerId);
 
+    void removeContainer(const string& containerId);
+
     /**
      *
      * Component implementation.
@@ -100,7 +102,7 @@ public:
     //
     void updateContainerInfo(const string& id, const string& uri, 
         AsteriskSCF::Media::File::V1::FileOperations supportedOperations);
-    
+
 private:
     boost::shared_mutex mLock;
     
@@ -124,15 +126,67 @@ private:
     Matroska::Environment* mMatroskaEnvironment;
     int mSessionReplicationUpdateInterval;
 
+    bool mServiceInstantiated;
+
     //
     // A *locked* accessor for obtaining the path string. Handy for methods that want the path,
     // but don't have a lock yet. NOT for use in locked scenarios.
     //
     string getPath();
 };
-
 typedef IceUtil::Handle<ContainerRepositoryServant> ContainerRepositoryServantPtr;
 
+class MediaServiceServant : public AsteriskSCF::Media::File::V1::FileMediaService
+{
+public:
+    MediaServiceServant(const ContainerRepositoryServantPtr& containerRepository, const Logger& logger) :
+        mContainerRepository(containerRepository),
+        mLogger(logger)
+    {
+    }
+
+    AsteriskSCF::Media::File::V1::FileSessionPrx create(const FileMediaSpecification& parameters, const Ice::Current&)
+    {
+        try
+        {
+            ContainerImplPtr container = mContainerRepository->getContainer(parameters.catalogID);
+            if (!container)
+            {
+                throw AsteriskSCF::Media::File::V1::UnknownCatalogID(parameters.catalogID);
+            }
+            ContainerInfoPtr info = container->getInfo();
+
+            //
+            // validate the required parameters and the abilities of the container.
+            //
+            if (parameters.supportedOperations ==  AsteriskSCF::Media::File::V1::Both ||
+                parameters.supportedOperations != info->supportedOperations)
+            {
+                //
+                // TODO: pass back an informative message.
+                //
+                throw AsteriskSCF::Media::File::V1::FileOperationNotAvailable();
+            }
+            return container->getMediaSession();
+        }
+        catch (const exception& ex)
+        {
+            mLogger(Error) << ex.what() << " thrown when getting a file session.";
+            throw;
+        }
+        catch (...)
+        {
+            mLogger(Error) << " unknown exception thrown when attempting to get a file session.";
+            throw;
+        }
+        return AsteriskSCF::Media::File::V1::FileSessionPrx();
+    }
+
+private:
+    ContainerRepositoryServantPtr mContainerRepository;
+    Logger mLogger;
+};
+
 class ReplicationAdapterImpl : public RepositoryReplicationAdapter
 {
 public:
@@ -149,6 +203,9 @@ public:
     ConfigurationAdapterImpl(const ContainerRepositoryServantPtr& containerRepository, const Logger&);
     ~ConfigurationAdapterImpl();
 
+    /**
+     * RepositoryConfigurationAdapter interface implementation.
+     */
     void startConfiguration();
     void commit();
 
@@ -161,6 +218,7 @@ public:
     ContainerConfigurationAdapterPtr addContainer(const string& catalogId, const string& filename,
         AsteriskSCF::Media::File::V1::FileOperations);
     ContainerConfigurationAdapterPtr getContainer(const string& id);
+    ContainerConfigurationAdapterSeq getContainers();
     void removeContainer(const string& catalogId);
 
 private:
@@ -286,13 +344,39 @@ ContainerConfigurationAdapterPtr ConfigurationAdapterImpl::addContainer(const st
     return ContainerConfigurationAdapterPtr();
 }
 
-ContainerConfigurationAdapterPtr ConfigurationAdapterImpl::getContainer(const string&)
+// NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE
+//
+// Memento objects are more for changing the state of the repository itself
+// and are awkward for managing changes to existing objects. That being
+// said, it might be worth it for transactional configuration support. Left
+// as a TODO.
+//
+// NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE * NOTE 
+
+ContainerConfigurationAdapterPtr ConfigurationAdapterImpl::getContainer(const string& catalogId)
 {
+    ContainerImplPtr container = mRepository->getContainer(catalogId);
+    if (container)
+    {
+        return container->configurationAdapter();
+    }
     return ContainerConfigurationAdapterPtr();
 }
 
-void ConfigurationAdapterImpl::removeContainer(const string&)
+ContainerConfigurationAdapterSeq ConfigurationAdapterImpl::getContainers()
 {
+    ContainerImplSeq containers = mRepository->getContainerList();
+    ContainerConfigurationAdapterSeq result;
+    for (ContainerImplSeq::const_iterator iter = containers.begin(); iter != containers.end(); ++iter)
+    {
+        result.push_back((*iter)->configurationAdapter());
+    }
+    return result;
+}
+
+void ConfigurationAdapterImpl::removeContainer(const string& catalogId)
+{
+    mRepository->removeContainer(catalogId);
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -351,12 +435,40 @@ ContainerImplPtr ContainerRepositoryServant::getContainer(const string& containe
     {
         return iter->second;
     }
+    mLogger(Warning) << "Attempting to retrieve a non existent container : " << containerId;
     return ContainerImplPtr();
 }
 
+void ContainerRepositoryServant::removeContainer(const string& containerId)
+{
+    UniqueLock lock(mLock);
+    ContainerMap::iterator iter = mContainers.find(containerId);
+    if (iter != mContainers.end())
+    {
+        iter->second->destroy();
+        mContainers.erase(iter);
+    }
+    else
+    {
+        mLogger(Warning) << "Attempting to remove a non-existent container : " << containerId;
+    }
+}
+
 AsteriskSCF::Media::File::V1::FileMediaServicePrx ContainerRepositoryServant::mediaService()
 {
-    return AsteriskSCF::Media::File::V1::FileMediaServicePrx();
+    {
+        UniqueLock lock(mLock);
+        if (!mServiceInstantiated)
+        {
+            mServiceInstantiated = true;
+            AsteriskSCF::Media::File::V1::FileMediaServicePtr servant =
+                new MediaServiceServant(this, mLogger);
+            return AsteriskSCF::Media::File::V1::FileMediaServicePrx::uncheckedCast(
+                mAdapter->add(servant, mAdapter->getCommunicator()->stringToIdentity(mName)));
+        }
+    }
+    return AsteriskSCF::Media::File::V1::FileMediaServicePrx::uncheckedCast(
+        mAdapter->createProxy(mAdapter->getCommunicator()->stringToIdentity(mName)));
 }
 
 RepositoryConfigurationAdapterPtr ContainerRepositoryServant::configurationAdapter()
diff --git a/src/RepositoryConfigurationAdapter.h b/src/RepositoryConfigurationAdapter.h
index bba27ea..b742dae 100644
--- a/src/RepositoryConfigurationAdapter.h
+++ b/src/RepositoryConfigurationAdapter.h
@@ -26,6 +26,14 @@ namespace AsteriskSCF
 {
 namespace FileMediaService
 {
+//
+// Note: this configuration adapter implies a different sort of strategy
+// for keeping configuration sane across multiple related requests on an
+// adapter. It is not as fully implemented as it could be, left as an TODO.
+//
+// TODO: document comments for all interface methods
+// TODO: some configuration specific exceptions that can be interpreted by Configuration.cpp
+//
 
 
 /**
@@ -36,15 +44,28 @@ class RepositoryConfigurationAdapter : public IceUtil::Shared
 public:
 
     /**
-     *
-     * A sort of transactional configuration. Only affects options, etc. Container
-     * addition and removal are atomic in and of themselves and do not need the transaction
-     * facility
-     *
+     * A sort of transactional configuration. Only affects options, etc. It is not
+     * really possible to make the container addition/removal atomic without some
+     * rewriting. Left as a TODO.
+     */
+
+    /**
+     * Obtain/set memento for configuration. Ideally, there should only be
+     * one memento active at one time allowing configuration to be
+     * serialized on the memento. This is not implemented yet, but does not
+     * involve a lot of extra code.
      */
     virtual void startConfiguration() = 0;
+
+    /**
+     * Commit the current changes. Does nothing if a memento is not set.
+     */
     virtual void commit() = 0;
 
+    /**
+     * Accessors/modifiers for state.. pretty self evident so individual
+     * comments are not provided at this time.
+     */
     virtual int getProgressUpdateInterval() = 0;
     virtual void setProgressUpdateInterval(int updateInterval) = 0;
     
@@ -56,6 +77,8 @@ public:
 
     virtual ContainerConfigurationAdapterPtr getContainer(const std::string& catalogId) =0;
 
+    virtual ContainerConfigurationAdapterSeq getContainers() = 0;
+
     virtual void removeContainer(const std::string& catalogId) = 0;
 };
 

commit 915f96365b7f1f6b5d42bd4d943d098215179334
Author: Brent Eagles <beagles at digium.com>
Date:   Thu Jan 5 15:50:26 2012 -0330

    Fix missing recording session setup code.

diff --git a/src/ContainerImpl.cpp b/src/ContainerImpl.cpp
index ee0c72c..62a146c 100644
--- a/src/ContainerImpl.cpp
+++ b/src/ContainerImpl.cpp
@@ -1211,7 +1211,7 @@ private:
 
 typedef IceUtil::Handle<FrameWriter> FrameWriterPtr;
 
-class RecordingSessionImpl : public FileSessionIODriver
+class RecordingSessionImpl : public AsteriskSCF::Media::File::V1::FileSession
 {
 public:
 
@@ -1297,16 +1297,33 @@ public:
 
     RecordingSessionImpl(const Ice::ObjectAdapterPtr& adapter, const string& id, 
         const AsteriskSCF::Media::File::V1::FileMediaSpecification& spec,
-        Matroska::Environment* matroskaEnvironment) :
+        Matroska::Environment* matroskaEnvironment,
+        const Logger& logger) :
         mObjectAdapter(adapter),
         mId(id),
         mSpec(spec),
         mMatroskaEnvironment(matroskaEnvironment),
-        mStream(0)
+        mStream(0),
+        mLogger(logger)
     {
 
     }
 
+    AsteriskSCF::Media::V1::StreamSourceSeq getSources(const Ice::Current&)
+    {
+        return AsteriskSCF::Media::V1::StreamSourceSeq();
+    }
+
+    AsteriskSCF::Media::V1::StreamSinkSeq getSinks(const Ice::Current&)
+    {
+        return mSinks;
+    }
+
+    string getId(const Ice::Current&)
+    {
+        return mId;
+    }
+
     void setCookies(const AsteriskSCF::Media::V1::SessionCookies& cookies, const Ice::Current&)
     {
         mCookieManager.setCookies(cookies);
@@ -1401,7 +1418,7 @@ public:
         }
     }
 
-    void setup(const string& filename)
+    bool setup(const string& filename)
     {
         //
         // Matroska related initialization!
@@ -1409,10 +1426,8 @@ public:
         mStream = StreamOpen(mMatroskaEnvironment->parserContext(), filename.c_str(), SFLAG_WRONLY | SFLAG_CREATE);
         if (!mStream)
         {
-            //
-            // XXX: error handling.
-            //
-            assert((const char*)"XXX: Error handling" == 0);
+            mLogger(Error) << "Unable to open " << filename.c_str() << " for writing.";
+            return false;
         }
         vector<string> trackIds;
         try
@@ -1435,17 +1450,21 @@ public:
         //
         // XXX exceptions should be logged.
         //
-        catch (const exception&)
+        catch (const exception& ex)
         {
             if (mStream)
             {
                 StreamClose(mStream);
             }
             mContainer.reset();
+            mLogger(Error) << "Unexpected " << ex.what() << " exception occured. Unable to start recording session.";
+            return false;
         }
         catch (...)
         {
+            mLogger(Error) << "Unknown exception occured. Unable to start recording session.";
             mContainer.reset();
+            return false;
         }
 
         //
@@ -1461,6 +1480,7 @@ public:
             mSinks.push_back(AsteriskSCF::Media::V1::StreamSinkPrx::uncheckedCast(mObjectAdapter->add(s,
                             mObjectAdapter->getCommunicator()->stringToIdentity(*iter))));
         }
+        return true;
     }
 
 private:
@@ -1474,7 +1494,9 @@ private:
     SourceManagers mSourceManagers;
     stream* mStream;
     FrameWriterPtr mWriter;
+    Logger mLogger;
 };
+typedef IceUtil::Handle<RecordingSessionImpl> RecordingSessionImplPtr;
 
 class ContainerServant : public ContainerImpl
 {
@@ -1529,10 +1551,6 @@ public:
     {
         if (mInfo->supportedOperations == AsteriskSCF::Media::File::V1::Playback)
         {
-            //
-            // Just stick to using the adapter to keep track of servants for now.
-            //
-
             string id = getInfoImpl()->catalogId;
             id += ".";
             id += IceUtil::generateUUID();
@@ -1545,7 +1563,7 @@ public:
             //
             // Creates sources and gets ready to produce data. 
             //
-            if (playback->setup(getInfoImpl()->filename))
+            if (!playback->setup(getInfoImpl()->filename))
             {
                 return AsteriskSCF::Media::File::V1::FileSessionPrx();
             }
@@ -1553,7 +1571,27 @@ public:
         }
         else if(mInfo->supportedOperations == AsteriskSCF::Media::File::V1::Recording)
         {
+            //
+            // TODO: need a way to distinguish among recordings... really the catalog id should map
+            // back to something application specific.
+            //
+            string id = getInfoImpl()->catalogId;
+            id += ".";
+            id += IceUtil::generateUUID();
+            Ice::Identity iceId = mAdapter->getCommunicator()->stringToIdentity(id);
+            RecordingSessionImplPtr recordingSession =
+                new RecordingSessionImpl(mAdapter, id, mSpec, mMatroskaEnvironment, mLogger);
 
+            AsteriskSCF::Media::File::V1::FileSessionPrx result =  
+                AsteriskSCF::Media::File::V1::FileSessionPrx::uncheckedCast(mAdapter->add(recordingSession, iceId));
+            //
+            // Creates sources and gets ready to produce data. 
+            //
+            if (!recordingSession->setup(getInfoImpl()->filename))
+            {
+                return AsteriskSCF::Media::File::V1::FileSessionPrx();
+            }
+            return result;
         }
         return 0;
     }

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


-- 
asterisk-scf/integration/file_media_service.git



More information about the asterisk-scf-commits mailing list