[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "transfer" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Oct 12 09:53:29 CDT 2010


branch "transfer" has been updated
       via  692012f59fdfac9848878698c1870b9659d4fa44 (commit)
      from  b36726c113af2090a69d14b82ed22b23656ec4a7 (commit)

Summary of changes:
 src/BridgeImpl.cpp  |  168 ++++++++++++++++++++++++---------------------------
 src/BridgeImpl.h    |   57 +++++++++++++++---
 test/channel_driver |    2 +-
 3 files changed, 128 insertions(+), 99 deletions(-)


- Log -----------------------------------------------------------------
commit 692012f59fdfac9848878698c1870b9659d4fa44
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Oct 12 12:22:01 2010 -0230

    Boosting the internal BridgeSession structures abilities to allow for some
    session-specific smarts in the bridge.

diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index daa8440..ea3a448 100644
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -50,30 +50,28 @@ namespace BridgeService
     //
     // Functor to support using for_each on shutdown.
     //
-    class ShutdownImpl : public std::unary_function<BridgeImpl::BridgeSession, void>
+    class ShutdownImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, void>
     {
     public:
-        ShutdownImpl(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& response) :
+        ShutdownImpl(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, 
+          const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& response) :
             mListener(listener),
             mResponse(response)
         {
         }
 
-        void operator()(const BridgeImpl::BridgeSession& b) 
+        void operator()(const BridgeImpl::BridgeSessionPtr& b) 
         {
-            b.session->removeBridge(mListener);
-            b.session->stop(mResponse);
-            if(b.connector)
-            {
-                b.connector->unplug();
-            }
+            b->getSession()->removeBridge(mListener);
+            b->getSession()->stop(mResponse);
+            b->disconnect();
         }
     private:
         AsteriskSCF::SessionCommunications::V1::SessionListenerPrx mListener;
         AsteriskSCF::SessionCommunications::V1::ResponseCodePtr mResponse;
     };
     
-    class ProgressingImpl : public std::unary_function<BridgeImpl::BridgeSession, void>
+    class ProgressingImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, void>
     {
     public:
         ProgressingImpl(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr& response) :
@@ -81,15 +79,15 @@ namespace BridgeService
         {
         }
 
-        void operator()(const BridgeImpl::BridgeSession& b) 
+        void operator()(const BridgeImpl::BridgeSessionPtr& b) 
         {
-            b.session->progress(mResponse);
+            b->getSession()->progress(mResponse);
         }
     private:
         AsteriskSCF::SessionCommunications::V1::ResponseCodePtr mResponse;
     };
 
-    class RingImpl : public std::unary_function<BridgeImpl::BridgeSession, void>
+    class RingImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, void>
     {
     public:
         RingImpl(const AsteriskSCF::SessionCommunications::V1::SessionPrx& exclude) :
@@ -97,42 +95,42 @@ namespace BridgeService
         {
         }
         
-        void operator()(const BridgeImpl::BridgeSession& b) 
+        void operator()(const BridgeImpl::BridgeSessionPtr& b) 
         {
-            if(b.session != mExclude)
+            if(b->getSession() != mExclude)
             {
-                b.session->ring();
+                b->getSession()->ring();
             }
         }
     private:
         AsteriskSCF::SessionCommunications::V1::SessionPrx mExclude;
     };
 
-    struct FlashImpl : public std::unary_function<BridgeImpl::BridgeSession, void>
+    struct FlashImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, void>
     {
-        void operator()(const BridgeImpl::BridgeSession& b) 
+        void operator()(const BridgeImpl::BridgeSessionPtr& b) 
         {
-            b.session->flash();
+            b->getSession()->flash();
         }
     };
     
-    struct HoldImpl : public std::unary_function<BridgeImpl::BridgeSession, void>
+    struct HoldImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, void>
     {
-        void operator()(const BridgeImpl::BridgeSession& b) 
+        void operator()(const BridgeImpl::BridgeSessionPtr& b) 
         {
-            b.session->hold();
+            b->getSession()->hold();
         }
     };
     
-    struct UnholdImpl : public std::unary_function<BridgeImpl::BridgeSession, void>
+    struct UnholdImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, void>
     {
-        void operator()(const BridgeImpl::BridgeSession& b) 
+        void operator()(const BridgeImpl::BridgeSessionPtr& b) 
         {
-            b.session->unhold();
+            b->getSession()->unhold();
         }
     };
 
-    class ConnectImpl : public std::unary_function<BridgeImpl::BridgeSession, void>
+    class ConnectImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, void>
     {
     public:
         ConnectImpl(const AsteriskSCF::SessionCommunications::V1::SessionPrx& exclude) :
@@ -140,11 +138,11 @@ namespace BridgeService
         {
         }
         
-        void operator()(const BridgeImpl::BridgeSession& b)
+        void operator()(BridgeImpl::BridgeSessionPtr& b)
         {
-            if(b.session != mExclude)
+            if(b->getSession() != mExclude) 
             {
-                b.session->connect();
+                b->connect();
             }
         }
 
@@ -152,7 +150,7 @@ namespace BridgeService
         AsteriskSCF::SessionCommunications::V1::SessionPrx mExclude;
     };
 
-    class FindImpl : public std::unary_function<BridgeImpl::BridgeSession, bool>
+    class FindImpl : public std::unary_function<BridgeImpl::BridgeSessionPtr, bool>
     {
     public:
         FindImpl(const AsteriskSCF::SessionCommunications::V1::SessionPrx& prx) :
@@ -160,9 +158,9 @@ namespace BridgeService
         {
         }
         
-        bool operator()(const BridgeImpl::BridgeSession& b)
+        bool operator()(const BridgeImpl::BridgeSessionPtr& b)
         {
-            return b.session == mPrx;
+            return b->getSession() == mPrx;
         }
     private:
         AsteriskSCF::SessionCommunications::V1::SessionPrx mPrx;
@@ -185,8 +183,9 @@ namespace BridgeService
         void connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& source, const Ice::Current&)
         {
             mBridge->sessionConnected(source);
-            std::vector<BridgeImpl::BridgeSession> sessions(mBridge->currentSessions());
+            std::vector<BridgeImpl::BridgeSessionPtr> sessions(mBridge->currentSessions());
             std::for_each(sessions.begin(), sessions.end(), ConnectImpl(source));
+
         }
 
         void flashed(const AsteriskSCF::SessionCommunications::V1::SessionPrx& source, const Ice::Current&)
@@ -203,7 +202,7 @@ namespace BridgeService
 
         void ringing(const AsteriskSCF::SessionCommunications::V1::SessionPrx& source, const Ice::Current&)
         {
-            std::vector<BridgeImpl::BridgeSession> sessions(mBridge->currentSessions());
+            std::vector<BridgeImpl::BridgeSessionPtr> sessions(mBridge->currentSessions());
             if(sessions.size() > 0)
             {
                 std::for_each(sessions.begin(), sessions.end(), RingImpl(source));
@@ -299,7 +298,7 @@ void AsteriskSCF::BridgeService::BridgeImpl::addSessions(const AsteriskSCF::Sess
             // impossible to guard against race conditions where multiple call paths might want to add a session
             // more than once for some reason. We should probably just log it and move on.
             //
-            std::vector<BridgeSession>::iterator j = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(*i));
+            std::vector<BridgeSessionPtr>::iterator j = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(*i));
             if(j != mSessions.end())
             {
                 continue;
@@ -311,11 +310,11 @@ void AsteriskSCF::BridgeService::BridgeImpl::addSessions(const AsteriskSCF::Sess
             //
             if(info->currentState == "ready")
             {
-                mSessions.push_back(BridgeSession(*i, 0));
+                mSessions.push_back(new BridgeSession(*i, 0, false));
             }
             else
             {
-                mSessions.push_back(BridgeSession(*i, mSplicer.connect(*i)));;
+                mSessions.push_back(new BridgeSession(*i, mSplicer.connect(*i), false));;
             }
                 
             addedSessions.push_back(*i);
@@ -352,11 +351,11 @@ void AsteriskSCF::BridgeService::BridgeImpl::removeSessions(const AsteriskSCF::S
         statePreCheck();
         for(AsteriskSCF::SessionCommunications::V1::SessionSeq::const_iterator i = sessions.begin(); i != sessions.end(); ++i)
         {
-            std::vector<BridgeSession>::iterator j = std::find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(*i));
+            std::vector<BridgeSessionPtr>::iterator j = std::find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(*i));
             if(j != mSessions.end())
             {
-                j->session->removeBridge(mSessionListenerPrx);
-                j->connector->unplug();
+                (*j)->getSession()->removeBridge(mSessionListenerPrx);
+                (*j)->disconnect();
                 mSessions.erase(j);
                 removedSessions.push_back(*i);
             }
@@ -391,9 +390,9 @@ AsteriskSCF::SessionCommunications::V1::SessionSeq AsteriskSCF::BridgeService::B
     statePreCheck();
     lg(Debug) << __FUNCTION__ << ": working with " << mSessions.size() << " sessions." ;
     AsteriskSCF::SessionCommunications::V1::SessionSeq result;
-    for(std::vector<AsteriskSCF::BridgeService::BridgeImpl::BridgeSession>::const_iterator i = mSessions.begin(); i != mSessions.end(); ++i)
+    for(std::vector<AsteriskSCF::BridgeService::BridgeImpl::BridgeSessionPtr>::const_iterator i = mSessions.begin(); i != mSessions.end(); ++i)
     {
-        result.push_back(i->session);
+        result.push_back((*i)->getSession());
     }
     return result;
 }
@@ -448,21 +447,41 @@ void AsteriskSCF::BridgeService::BridgeImpl::removeListener(const AsteriskSCF::S
 void AsteriskSCF::BridgeService::BridgeImpl::replaceSession(const AsteriskSCF::SessionCommunications::V1::SessionPrx& newSession, 
   const AsteriskSCF::SessionCommunications::V1::SessionPrx& oldSession, const Ice::Current&)
 {
-    //
-    // TODO:Need to find a way to make this as exception safe as possible!
-    //
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    statePreCheck();
-    std::vector<BridgeSession>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(oldSession));
-    //
-    // If it's found, disconnect the media and remove association between bridge and session.
-    //
-    if(i != mSessions.end())
+    BridgeSessionPtr toRemove;
+    BridgeSessionPtr newBridgeMember;
+    AsteriskSCF::SessionCommunications::V1::SessionInfoPtr  info;
+    {
+        //
+        // TODO:Need to find a way to make this as exception safe as possible!
+        //
+        boost::unique_lock<boost::shared_mutex> lock(mLock);
+        statePreCheck();
+
+        info = newSession->setBridge(mPrx, mSessionListenerPrx);
+
+        std::vector<BridgeSessionPtr>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(oldSession));
+        //
+        // If it's found, disconnect the media and remove association between bridge and session.
+        //
+        newBridgeMember = new BridgeSession(newSession, 0, false);
+        if(i != mSessions.end())
+        {
+            toRemove = *i;
+            *i = newBridgeMember;
+            toRemove->disconnect();
+        }
+        else
+        {
+            mSessions.push_back(newBridgeMember); 
+        }
+        newBridgeMember->setConnector(mSplicer.connect(newSession));
+    }
+
+    if(toRemove)
     {
-        i->connector->unplug();
         try
         {
-            i->session->removeBridge(mSessionListenerPrx);
+            toRemove->getSession()->removeBridge(mSessionListenerPrx);
         }
         catch(const AsteriskSCF::SessionCommunications::V1::NotBridged&)
         {
@@ -471,38 +490,12 @@ void AsteriskSCF::BridgeService::BridgeImpl::replaceSession(const AsteriskSCF::S
             //
         }
     }
-   
-    AsteriskSCF::SessionCommunications::V1::SessionInfoPtr info = newSession->setBridge(mPrx, mSessionListenerPrx);
-
-    //
-    // TODO: if setBridge() fails, should the old session/bridge association remain? 
-    //
-
-    //
-    // If the old session wasn't found then we need to add a new one. If we simply insert the new one at the
-    // end and update the iterator "i", we minimize the special case code.
-    //
-    if(i == mSessions.end())
-    {
-        BridgeSession t;
-        i = mSessions.insert(i, t);
-    }
-
-    i->session = newSession;
-    if(info->currentState == "ready")
-    {
-        i->connector = 0;
-    }
-    else
-    {
-        i->connector = mSplicer.connect(newSession);
-    }
 
     AsteriskSCF::SessionCommunications::V1::SessionSeq sessions;
     sessions.push_back(newSession);
     mListeners->sessionsAdded(sessions);
 
-    if(i != mSessions.end())
+    if(toRemove)
     {
         sessions.clear();
         sessions.push_back(oldSession);
@@ -547,10 +540,10 @@ void AsteriskSCF::BridgeService::BridgeImpl::sessionConnected(const AsteriskSCF:
 {
     lg(Debug) << __FUNCTION__ << ": session connected " << session->ice_toString() ;
     boost::unique_lock<boost::shared_mutex> lock(mLock);
-    std::vector<BridgeSession>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(session));
+    std::vector<BridgeSessionPtr>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(session));
     if(i != mSessions.end())
     {
-        i->connector = mSplicer.connect(session);
+        (*i)->setConnector(mSplicer.connect(session));
     }
 }
 
@@ -561,13 +554,10 @@ size_t AsteriskSCF::BridgeService::BridgeImpl::sessionStopped(const AsteriskSCF:
     session->removeBridge(mSessionListenerPrx);
 
     boost::unique_lock<boost::shared_mutex> lock(mLock);
-    std::vector<BridgeSession>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(session));
+    std::vector<BridgeSessionPtr>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(session));
     if(i != mSessions.end())
     {
-        if(i->connector)
-        {
-            i->connector->unplug();
-        }
+        (*i)->disconnect();
         mSessions.erase(i);
     }
 
@@ -588,7 +578,7 @@ void AsteriskSCF::BridgeService::BridgeImpl::statePreCheck()
     }
 }
 
-std::vector<AsteriskSCF::BridgeService::BridgeImpl::BridgeSession> AsteriskSCF::BridgeService::BridgeImpl::currentSessions()
+std::vector<AsteriskSCF::BridgeService::BridgeImpl::BridgeSessionPtr> AsteriskSCF::BridgeService::BridgeImpl::currentSessions()
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
     return mSessions;
diff --git a/src/BridgeImpl.h b/src/BridgeImpl.h
index b8f23df..4a5f4c4 100644
--- a/src/BridgeImpl.h
+++ b/src/BridgeImpl.h
@@ -23,21 +23,60 @@ namespace BridgeService
     class BridgeImpl : public SessionCommunications::V1::Bridge
     {
     public:
-        struct BridgeSession
+        class BridgeSession : public IceUtil::Shared
         {
-            SessionCommunications::V1::SessionPrx session;
-            MediaConnectorPtr connector;
+        public:
 
-            BridgeSession() 
+            BridgeSession(const SessionCommunications::V1::SessionPrx& s, const MediaConnectorPtr& con, bool isConnected) :
+                mSession(s),
+                mConnector(con),
+                mConnected(isConnected)
             {
             }
 
-            BridgeSession(const SessionCommunications::V1::SessionPrx& s, const MediaConnectorPtr& con) :
-                session(s),
-                connector(con)
+            bool isConnected()
             {
+                IceUtil::Mutex::Lock lock(mMutex);
+                return mConnected;
             }
+
+            void connect()
+            {
+                IceUtil::Mutex::Lock lock(mMutex);
+                if(mConnected)
+                    return;
+
+                mSession->connect();
+                mConnected = true;
+            }
+
+            SessionCommunications::V1::SessionPrx getSession() const
+            {
+                return mSession;
+            }
+
+            void setConnector(const MediaConnectorPtr& connector)
+            {
+                IceUtil::Mutex::Lock lock(mMutex);
+                mConnector = connector;
+            }
+
+            void disconnect()
+            {
+                IceUtil::Mutex::Lock lock(mMutex);
+                if(mConnector)
+                {
+                    mConnector->unplug();
+                }
+            }
+
+        private:
+            SessionCommunications::V1::SessionPrx mSession;
+            MediaConnectorPtr mConnector;
+            bool mConnected;
+            IceUtil::Mutex mMutex;
         };
+        typedef IceUtil::Handle<BridgeSession> BridgeSessionPtr;
 
         BridgeImpl(const Ice::ObjectAdapterPtr& objAdapter,
                 const SessionCommunications::V1::BridgeListenerPrx& ev,
@@ -71,7 +110,7 @@ namespace BridgeService
         size_t sessionStopped(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session,
                 const SessionCommunications::V1::ResponseCodePtr& response);
         
-        std::vector<BridgeSession> currentSessions();
+        std::vector<BridgeSessionPtr> currentSessions();
 
     private:
 
@@ -84,7 +123,7 @@ namespace BridgeService
         };
         ServiceStates mState;
 
-        std::vector<BridgeSession> mSessions;
+        std::vector<BridgeSessionPtr> mSessions;
 
         MediaSplicer mSplicer;
 
diff --git a/test/channel_driver b/test/channel_driver
index 3b7128d..9705e7d 160000
--- a/test/channel_driver
+++ b/test/channel_driver
@@ -1 +1 @@
-Subproject commit 3b7128dd68b00ac105076983517f45d383777bec
+Subproject commit 9705e7d70b3721a3aeccd8ada97181242c7f1098

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list