[asterisk-scf-commits] team/beagles/fileplayback.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Dec 16 21:14:07 UTC 2010


branch "master" has been updated
       via  4aac66d00621005c7c2e6aeb7111c44e8c942359 (commit)
       via  cf71ee3222347185fb64fc3c0ac30ed03d2f29e9 (commit)
      from  f320f0e9cb5e44d62109ea68c7418e7601c0b7e9 (commit)

Summary of changes:
 src/FilePlaybackService.h           |   27 +++++++++++++-
 src/FilePlaybackSessionEndpoint.cpp |   70 +++++++++++++++++++++++++++++++++-
 src/FilePlaybackSessionEndpoint.h   |    5 ++-
 src/MediaEchoThread.cpp             |   37 ++++++++----------
 src/RemoteControl.ice               |    6 +++
 src/Service.cpp                     |    7 ++-
 src/TestEndpoint.cpp                |   50 +++++++++++++++++++++++--
 7 files changed, 171 insertions(+), 31 deletions(-)


- Log -----------------------------------------------------------------
commit 4aac66d00621005c7c2e6aeb7111c44e8c942359
Author: Brent Eagles <beagles at digium.com>
Date:   Thu Dec 16 17:41:50 2010 -0330

    Add a facility to the test channel to permit hooking into the test sessions
    right way (addDefaultSessionListener). This is only available to the
    test remote control interfaces.

diff --git a/src/FilePlaybackService.h b/src/FilePlaybackService.h
index bae7ecb..dccfa29 100644
--- a/src/FilePlaybackService.h
+++ b/src/FilePlaybackService.h
@@ -43,5 +43,30 @@ inline std::string getId(const Ice::Current& current)
     return current.adapter->getCommunicator()->identityToString(current.id);
 }
 }
-
 } // End of namespace AsteriskSCF
+
+template <class T>
+class IdentityComparePred : public std::unary_function<T, bool>
+{
+public:
+    IdentityComparePred(const T& example) :
+        mExample(example)
+    {
+    }
+
+    bool operator()(const T& toTest)
+    {
+        if(toTest == 0)
+        {
+            return (mExample == 0);
+        }
+        if(mExample == 0)
+        {
+            return false;
+        }
+        return (mExample->ice_getIdentity() == toTest->ice_getIdentity());
+    }
+private:
+    T mExample;
+};
+
diff --git a/src/FilePlaybackSessionEndpoint.cpp b/src/FilePlaybackSessionEndpoint.cpp
index c209d3d..023317b 100644
--- a/src/FilePlaybackSessionEndpoint.cpp
+++ b/src/FilePlaybackSessionEndpoint.cpp
@@ -702,10 +702,15 @@ public:
       const Ice::Current& current)
     {
         mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " for " << AsteriskSCF::FilePlayback::getId(current);
-        SessionListenerMgr::addListener(listener);
+        addListenerImpl(listener);
         return updateInfo();
     }
 
+    void addListenerImpl(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener)
+    {
+        SessionListenerMgr::addListener(listener);
+    }
+
     void removeListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, 
       const Ice::Current& current)
     {
@@ -717,6 +722,7 @@ public:
     {
         mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " for " << AsteriskSCF::FilePlayback::getId(current);
         mStartTime = time(0);
+        mPublisher->connected(mProxy);
     }
 
     void flash(const Ice::Current& current)
@@ -745,6 +751,7 @@ public:
     void hold(const Ice::Current& current)
     {
         mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " for " << AsteriskSCF::FilePlayback::getId(current);
+        mPublisher->held(mProxy);
     }
 
     void progress(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& responseCode, const Ice::Current& current)
@@ -755,6 +762,7 @@ public:
     void ring(const Ice::Current& current)
     {
         mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " for " << AsteriskSCF::FilePlayback::getId(current);
+        mPublisher->ringing(mProxy);
     }
 
     void start(const Ice::Current& current)
@@ -764,11 +772,14 @@ public:
         // Initialize the media sessions now or later? I think I will create the media sessions when I create
         // the file session but do something a little different once the session is started.
         // 
+        mPublisher->connected(mProxy);
     }
 
     void stop(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& responseCode, const Ice::Current& current)
     {
         mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " for " << AsteriskSCF::FilePlayback::getId(current);
+        mPublisher->stopped(mProxy, responseCode);
+        mMediaSession->destroyImpl();
     }
 
     void unhold(const Ice::Current& current)
@@ -868,11 +879,14 @@ public:
     AsteriskSCF::SessionCommunications::V1::SessionPrx createSession(const std::string& destination, 
       const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current&);
     AsteriskSCF::SessionCommunications::V1::SessionSeq getSessions(const Ice::Current&);
+    void addDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current);
+    void removeDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current);
 private:
 
     AsteriskSCF::System::Logging::LoggerPtr mLogger;
     Ice::ObjectAdapterPtr mAdapter;
     std::vector<FileSessionInfo> mSessions;
+    std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> mDefaultListeners;
     IceUtil::Mutex mMutex;
 
     void reap();
@@ -893,7 +907,7 @@ AsteriskSCF::FilePlayback::FilePlaybackEndpointImpl::FilePlaybackEndpointImpl(co
 static bool
 nonIdChar(const char c)
 {
-    return !isalpha(c);
+    return !isalnum(c);
 }
 
 static std::string
@@ -943,13 +957,18 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx AsteriskSCF::FilePlayback::Fi
         // requests.
         //
         newSession->initialize();
+        for(std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator i = mDefaultListeners.begin();
+          i != mDefaultListeners.end(); ++i)
+        {
+            newSession->addListenerImpl(*i);
+        }
         AsteriskSCF::SessionCommunications::V1::SessionPrx prx(
           AsteriskSCF::SessionCommunications::V1::SessionPrx::uncheckedCast(
               mAdapter->add(newSession, mAdapter->getCommunicator()->stringToIdentity(myId))));
         newSession->publishProxy(prx);
         if(listener)
         {
-            newSession->addListener(listener, current);
+            newSession->addListenerImpl(listener);
         }
         FileSessionInfo info;
         info.servant = newSession;
@@ -977,6 +996,38 @@ AsteriskSCF::SessionCommunications::V1::SessionSeq AsteriskSCF::FilePlayback::Fi
     return result;
 }
 
+void AsteriskSCF::FilePlayback::FilePlaybackEndpointImpl::addDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current)
+{
+    mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " for " << AsteriskSCF::FilePlayback::getId(current);
+    if(!listener)
+    {
+        mLogger(Debug) << __FUNCTION__ << ":" << 
+            current.adapter->getCommunicator()->identityToString(current.id) <<  " attempting to add a null proxy";
+        throw AsteriskSCF::SessionCommunications::V1::NullProxyException();
+    }
+    IceUtil::Mutex::Lock lock(mMutex);
+    if(mDefaultListeners.end() == std::find_if(mDefaultListeners.begin(), mDefaultListeners.end(), 
+          IdentityComparePred<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>(listener)))
+    {
+        mDefaultListeners.push_back(listener);
+    }
+}
+
+void AsteriskSCF::FilePlayback::FilePlaybackEndpointImpl::removeDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current)
+{
+    mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " for " << AsteriskSCF::FilePlayback::getId(current);
+    std::cerr << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) << std::endl;
+    if(!listener)
+    {
+        mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) 
+            <<  " attempting to remove a null proxy";
+        throw AsteriskSCF::SessionCommunications::V1::NullProxyException();
+    }
+    IceUtil::Mutex::Lock lock(mMutex);
+    std::remove_if(mDefaultListeners.begin(), mDefaultListeners.end(), 
+      IdentityComparePred<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>(listener)); 
+}
+
 void AsteriskSCF::FilePlayback::FilePlaybackEndpointImpl::reap()
 {
     mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << " reaping.";
@@ -1027,3 +1078,16 @@ std::string AsteriskSCF::FilePlayback::FilePlaybackEndpoint::getId(const Ice::Cu
     return mId;
 }
 
+void AsteriskSCF::FilePlayback::FilePlaybackEndpoint::addDefaultSessionListener(
+  const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
+  const Ice::Current& current)
+{
+    mImpl->addDefaultSessionListener(listener, current);
+}
+
+void AsteriskSCF::FilePlayback::FilePlaybackEndpoint::removeDefaultSessionListener(
+  const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
+  const Ice::Current& current)
+{
+    mImpl->removeDefaultSessionListener(listener, current);
+}
diff --git a/src/FilePlaybackSessionEndpoint.h b/src/FilePlaybackSessionEndpoint.h
index 09429c6..b41c404 100644
--- a/src/FilePlaybackSessionEndpoint.h
+++ b/src/FilePlaybackSessionEndpoint.h
@@ -18,6 +18,7 @@
 
 #include "FilePlaybackService.h"
 #include <SessionCommunications/SessionCommunicationsIf.h>
+#include <RemoteControl.h>
 #include <string>
 #include <Ice/Ice.h>
 
@@ -27,7 +28,7 @@ namespace FilePlayback
 {
     class FilePlaybackEndpointImpl;
 
-    class FilePlaybackEndpoint : public AsteriskSCF::SessionCommunications::V1::SessionEndpoint
+    class FilePlaybackEndpoint : public AsteriskSCF::RemoteControl::V1::SessionFactory
     {
     public:
         FilePlaybackEndpoint(const Ice::ObjectAdapterPtr& adapter, const AsteriskSCF::System::Logging::LoggerPtr&);
@@ -38,6 +39,8 @@ namespace FilePlayback
         AsteriskSCF::SessionCommunications::V1::SessionSeq getSessions(const Ice::Current&);
         std::string getId(const Ice::Current&);
 
+        void addDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current);
+        void removeDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current);
     private:
         FilePlaybackEndpointImpl* mImpl;
         std::string mId;
diff --git a/src/RemoteControl.ice b/src/RemoteControl.ice
index 697a5b1..d2be87b 100644
--- a/src/RemoteControl.ice
+++ b/src/RemoteControl.ice
@@ -17,6 +17,7 @@
 
 #include <Media/MediaIf.ice>
 #include <Ice/BuiltinSequences.ice>
+#include <SessionCommunications/SessionCommunicationsIf.ice>
 
 module AsteriskSCF
 {
@@ -72,6 +73,11 @@ interface Sink
     void destroy();
 };
 
+interface SessionFactory extends AsteriskSCF::SessionCommunications::V1::SessionEndpoint
+{
+    void addDefaultSessionListener(AsteriskSCF::SessionCommunications::V1::SessionListener* listener);
+    void removeDefaultSessionListener(AsteriskSCF::SessionCommunications::V1::SessionListener* listener);
+};
 
 }; /* End of module V1 */
 }; /* End of module RemoteControl */
diff --git a/src/TestEndpoint.cpp b/src/TestEndpoint.cpp
index f8b3eff..6fab1c8 100644
--- a/src/TestEndpoint.cpp
+++ b/src/TestEndpoint.cpp
@@ -21,6 +21,7 @@
 #include <IceUtil/UUID.h>
 
 #include <SessionCommunications/SessionCommunicationsIf.h>
+#include <RemoteControl.h>
 
 #include <boost/thread/locks.hpp>
 #include <boost/thread/shared_mutex.hpp>
@@ -57,7 +58,6 @@ public:
 };
 typedef IceUtil::Handle<InternalManagerIf> InternalManagerPtr;
 
-
 //
 // Specialization of ListenerManagerT helper template for SessionListeners. Basically takes care of invoking the
 // appropriate method on a publisher.
@@ -130,7 +130,8 @@ class SessionI : public AsteriskSCF::SessionCommunications::V1::Session
 {
 public:
     SessionI(const InternalManagerPtr& m, const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& prx,  const std::string& id,
-        const Ice::ObjectAdapterPtr& adapter) :
+      const std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners,
+      const Ice::ObjectAdapterPtr& adapter) :
         mEndpointManager(m),
         mEndpointPrx(prx),
         mId(id),
@@ -138,6 +139,12 @@ public:
     {
         mInfo = new AsteriskSCF::SessionCommunications::V1::SessionInfo;
         mInfo->currentState = "ready";
+        std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> t(listeners);
+        for(std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator i = listeners.begin();
+          i != listeners.end(); ++i)
+        {
+            mListeners->addListener(*i);
+        }
     }
 
     AsteriskSCF::SessionCommunications::V1::SessionInfoPtr addListener(
@@ -300,7 +307,7 @@ typedef IceUtil::Handle<SessionI> SessionIPtr;
 class EndpointManager :
         virtual public IceUtil::Shared,
         virtual public InternalManagerIf,
-        virtual public AsteriskSCF::SessionCommunications::V1::SessionEndpoint
+        virtual public AsteriskSCF::RemoteControl::V1::SessionFactory
 {
 public:
 
@@ -317,9 +324,11 @@ public:
     {
         InternalSessionInfo info;
         info.id = mId + "." + destination + "." + IceUtil::generateUUID();
+        std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners(mDefaultListeners);
+        listeners.push_back(listener);
         info.servant = new SessionI(this,
             AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx::checkedCast(current.adapter->createProxy(current.id)),
-            info.id, current.adapter);
+            info.id, listeners, current.adapter);
         info.session =  AsteriskSCF::SessionCommunications::V1::SessionPrx::checkedCast(current.adapter->add(info.servant, current.adapter->getCommunicator()->stringToIdentity(info.id)));
         info.servant->setProxy(info.session);
         boost::unique_lock<boost::shared_mutex> lock(mMutex);
@@ -450,6 +459,37 @@ public:
         std::cerr << "Unknown id" << std::endl;
     }
 
+    void addDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current)
+    {
+        std::cerr << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) << std::endl;
+        if(!listener)
+        {
+            std::cerr << __FUNCTION__ << ":" << 
+                current.adapter->getCommunicator()->identityToString(current.id) <<  " attempting to add a null proxy";
+            throw AsteriskSCF::SessionCommunications::V1::NullProxyException();
+        }
+        boost::shared_lock<boost::shared_mutex> lock(mMutex);
+        if(mDefaultListeners.end() == std::find_if(mDefaultListeners.begin(), mDefaultListeners.end(), 
+              IdentityComparePred<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>(listener)))
+        {
+            mDefaultListeners.push_back(listener);
+        }
+    }
+
+    void removeDefaultSessionListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current)
+    {
+        std::cerr << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) << std::endl;
+        if(!listener)
+        {
+            std::cerr << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) 
+                <<  " attempting to remove a null proxy";
+            throw AsteriskSCF::SessionCommunications::V1::NullProxyException();
+        }
+        boost::shared_lock<boost::shared_mutex> lock(mMutex);
+        std::remove_if(mDefaultListeners.begin(), mDefaultListeners.end(), 
+          IdentityComparePred<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>(listener)); 
+    }
+
 private:
 
     struct InternalSessionInfo
@@ -466,6 +506,8 @@ private:
     AsteriskSCF::TestUtil::Logger mLogger;
     Ice::ObjectAdapterPtr mAdapter;
     std::string mId;
+
+    std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> mDefaultListeners;
 };
 
 class CommandImpl : public AsteriskSCF::TestChannel::V1::Commands

commit cf71ee3222347185fb64fc3c0ac30ed03d2f29e9
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Dec 15 15:52:13 2010 -0330

    Fix spelling in temporary debugging text.
    Fix possible misuse of service discovery.

diff --git a/src/MediaEchoThread.cpp b/src/MediaEchoThread.cpp
index 92c5fd3..2a5f9d5 100644
--- a/src/MediaEchoThread.cpp
+++ b/src/MediaEchoThread.cpp
@@ -20,7 +20,7 @@ using namespace AsteriskSCF::TestUtil;
 MediaEchoThread::MediaEchoThread():
     mDone(false),
     mPaused(true),
-    mInterval(IceUtil::Time::microSecondsDouble(1000000.0 / 8 * 1024))
+    mInterval(IceUtil::Time::microSecondsDouble(1000000.0 / (8 * 1024)))
 {
 }
 
@@ -45,35 +45,31 @@ void MediaEchoThread::run()
     AsteriskSCF::Media::V1::FrameSeq currentFrames;
     size_t numberOfFramesWritten = 0;
     AsteriskSCF::Media::V1::StreamSinkPrx sink;
-    while(true)
+    while(!done)
     {
         std::cerr << "looping" << std::endl;
         {
             IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mMonitor);
-            if(mFrames.size() == 0 && !mDone)
+            if(mFrames.size() == 0 || mSink == 0)
             {
+                std::cerr << "no frames or no sink... continuing to wait" << std::endl;
                 mMonitor.wait();
             }
+            if(mDone)
+            {
+                std::cerr << "this thread is done" << std::endl;
+                done = true;
+                break;
+            }
 
-            //
-            // Copy our working state. For this iteration.
-            done = mDone;
             sink = mSink;
-            if(!done)
+            std::cerr << "not done yet " << std::endl;
+            if(numberOfFramesWritten != 0)
             {
-                std::cerr << "not done yet " << std::endl;
-                if(numberOfFramesWritten != 0)
-                {
-                    mFrames.erase(mFrames.begin(), mFrames.begin() + numberOfFramesWritten);
-                    numberOfFramesWritten = 0;
-                }
-                currentFrames.assign(mFrames.begin(), mFrames.end());
+                mFrames.erase(mFrames.begin(), mFrames.begin() + numberOfFramesWritten);
+                numberOfFramesWritten = 0;
             }
-        }
-        if(done)
-        {
-            std::cerr << "done! thread terminating" << std::endl;
-            break;
+            currentFrames.assign(mFrames.begin(), mFrames.end());
         }
 
         AsteriskSCF::Media::V1::FrameSeq::iterator current = currentFrames.begin();
@@ -97,6 +93,7 @@ void MediaEchoThread::run()
             ++numberOfFramesWritten;
             ++current;
         }
+        std::cerr << "done .. going back to wait loop" << std::endl;
     }
 }
 
@@ -105,7 +102,7 @@ void MediaEchoThread::pushFrames(const AsteriskSCF::Media::V1::FrameSeq& newFram
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mMonitor);
     std::cerr << "pushing " << newFrames.size() << " frames" << std::endl;
     mFrames.insert(mFrames.end(), newFrames.begin(), newFrames.end());
-    if(!mPaused)
+    if(!mPaused && mSink != 0)
     {
         mMonitor.notify();
     }
diff --git a/src/Service.cpp b/src/Service.cpp
index dd5dc3d..96d5fbc 100644
--- a/src/Service.cpp
+++ b/src/Service.cpp
@@ -15,6 +15,7 @@
  */
 #include <Ice/Ice.h>
 #include <IceBox/IceBox.h>
+#include <IceUtil/UUID.h>
 
 #include <Core/Discovery/ServiceLocatorIf.h>
 #include <Core/Routing/RoutingIf.h>
@@ -53,8 +54,10 @@ void TestChannelDriver::start(const std::string& name, const Ice::CommunicatorPt
     AsteriskSCF::Core::Routing::V1::EndpointLocatorPrx endpointLocatorPrx =
         AsteriskSCF::Core::Routing::V1::EndpointLocatorPrx::checkedCast(mAdapter->add(servant, communicator->stringToIdentity("TestChannel")));
 
-    AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx management = AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx::checkedCast(communicator->propertyToProxy("ServiceLocatorManagementProxy"));
-    mServiceManagement = AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(management->addService(endpointLocatorPrx, "TestChannel"));
+    AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx management = 
+        AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx::checkedCast(communicator->propertyToProxy("ServiceLocatorManagementProxy"));
+    mServiceManagement = 
+        AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(management->addService(endpointLocatorPrx, IceUtil::generateUUID()));
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params = new AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams();
     params->category = "TestChannel";
     mServiceManagement->addLocatorParams(params, "");

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


-- 
team/beagles/fileplayback.git



More information about the asterisk-scf-commits mailing list