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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Sun Oct 17 20:52:26 CDT 2010


branch "master" has been updated
       via  8aa49d1fbc238e526fb05f7ee7168b0eaeed3a82 (commit)
      from  3f572c52e621b77b1576980a5e5cc26acdb08068 (commit)

Summary of changes:
 src/BridgeImpl.cpp    |   12 +++++-
 src/MediaSplicer.cpp  |  107 +++++++++++++++++++++++++++++++++---------------
 src/MediaSplicer.h    |    1 +
 test/TestBridging.cpp |    1 +
 4 files changed, 86 insertions(+), 35 deletions(-)


- Log -----------------------------------------------------------------
commit 8aa49d1fbc238e526fb05f7ee7168b0eaeed3a82
Author: Brent Eagles <beagles at digium.com>
Date:   Sun Oct 17 23:19:02 2010 -0230

    - Added some more logging.
    - Altered the media connection/disconnection code to handle disconnects
      a bit more thoroughly.
    - Fixed a bug where media wasn't be established on a connected callback
      when a connect() call had been relayed to that leg already.

diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index dafc7ea..aa4954c 100644
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -404,6 +404,7 @@ void AsteriskSCF::BridgeService::BridgeImpl::addSessions(const AsteriskSCF::Sess
     {
         boost::unique_lock<boost::shared_mutex> lock(mLock);
         statePreCheck();
+        lg(Debug) << __FUNCTION__ << ": adding " << sessions.size() << " sessions to " << current.adapter->getCommunicator()->identityToString(current.id);
         for(AsteriskSCF::SessionCommunications::V1::SessionSeq::const_iterator i = sessions.begin();
             i != sessions.end(); ++i)
         {
@@ -415,6 +416,7 @@ void AsteriskSCF::BridgeService::BridgeImpl::addSessions(const AsteriskSCF::Sess
             std::vector<BridgeSessionPtr>::iterator j = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(*i));
             if(j != mSessions.end())
             {
+                lg(Debug) << __FUNCTION__ << ": " << (*i)->ice_toString() << " is already registered with this bridge."; 
                 continue;
             }
 
@@ -424,10 +426,12 @@ void AsteriskSCF::BridgeService::BridgeImpl::addSessions(const AsteriskSCF::Sess
             //
             if(info->currentState == "ready")
             {
+                lg(Debug) << __FUNCTION__ << ": " << (*i)->ice_toString() << " current state is ready (not yet connected), not establishing media connections."; 
                 mSessions.push_back(new BridgeSession(*i, 0, false));
             }
             else
             {
+                lg(Debug) << __FUNCTION__ << ": " << (*i)->ice_toString() << " media is expected to be establishing, plugging media into bridge."; 
                 mSessions.push_back(new BridgeSession(*i, mSplicer.connect(*i), false));;
             }
                 
@@ -713,7 +717,13 @@ 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<BridgeSessionPtr>::iterator i = find_if(mSessions.begin(), mSessions.end(), AsteriskSCF::BridgeService::FindImpl(session));
-    if(i != mSessions.end() && !(*i)->isConnected())
+#ifndef _NDEBUG
+    if(i == mSessions.end())
+    {
+        lg(Debug) << __FUNCTION__ << ": did not find " << session->ice_toString();
+    }
+#endif
+    if(i != mSessions.end())
     {
         (*i)->setConnected();
         (*i)->setConnector(mSplicer.connect(session));
diff --git a/src/MediaSplicer.cpp b/src/MediaSplicer.cpp
index c4d12f0..32ccb55 100644
--- a/src/MediaSplicer.cpp
+++ b/src/MediaSplicer.cpp
@@ -45,6 +45,7 @@ namespace BridgeService
             mPeer(peer),
             mConnected(true)
         {
+            lg(Debug) << __FUNCTION__ << ": setting up a media connector with " << outgoing.size() << " outgoing pairings and " << incoming.size() << " incoming pairings."; 
             for(std::vector<OutgoingPairing>::iterator i = mOutgoing.begin(); i != mOutgoing.end(); ++i)
             {
                 i->second->setSink(i->first);
@@ -59,7 +60,66 @@ namespace BridgeService
 
         void unplug()
         {
-            lg(Debug) << __FUNCTION__ << ": unplugging sinks and sources";
+            lg(Debug) << __FUNCTION__ << ": called.";
+            bool hadMedia = disconnectMedia();
+            if(!hadMedia)
+            {
+                lg(Debug) << __FUNCTION__ << ": we did not have any media. Contacting the peer connector and telling it to disconnect!";
+                MediaConnectorPtr peer;
+                {
+                    IceUtil::Mutex::Lock lock(mMutex);
+                    peer = mPeer;
+                    mPeer = 0;
+                }
+                if(peer)
+                {
+                    peer->disconnectMedia();
+                }
+            }
+            else
+            {
+                lg(Debug) << __FUNCTION__ << ": media connections unplugged. Let's forget about our peer connector now!";
+                MediaConnectorPtr peer;
+                {
+                    IceUtil::Mutex::Lock lock(mMutex);
+                    peer = mPeer;
+                    mPeer = 0;
+                }
+                if(peer)
+                {
+                    peer->clearConnections();
+                }
+                mPeer = 0;
+            }
+            lg(Debug) << __FUNCTION__ << ": finished unplugging.";
+        }
+
+        bool isConnected()
+        {
+            IceUtil::Mutex::Lock lock(mMutex);
+            return mConnected;
+        }
+
+        void clearConnections()
+        {
+            lg(Debug) << __FUNCTION__ << ": clearing connections."; 
+            IceUtil::Mutex::Lock lock(mMutex);
+            mOutgoing.clear();
+            mIncoming.clear();
+        }
+
+        void update(const MediaConnectorPtr& peer, const std::vector<OutgoingPairing>& outgoing, const std::vector<IncomingPairing>& incoming)
+        {
+            lg(Debug) << __FUNCTION__ << ": establishing a new peer connection.";
+            IceUtil::Mutex::Lock lock(mMutex);
+            mPeer = peer;
+            mOutgoing = outgoing;
+            mIncoming = incoming;
+        }
+
+        bool disconnectMedia()
+        {
+            lg(Debug) << __FUNCTION__ << ": unplugging sinks and sources.";
             std::vector<OutgoingPairing> outgoing;
             std::vector<IncomingPairing> incoming;
             {
@@ -70,15 +130,11 @@ namespace BridgeService
                 mIncoming.clear();
                 mConnected = false;
             }
-
-            if(outgoing.size() == 0)
-            {
-                lg(Debug) << __FUNCTION__ << ": no outgoing pairings found for this connector!";
-            }
-            if(incoming.size() == 0)
+            if(outgoing.size() == 0 && incoming.size() == 0)
             {
-                lg(Debug) << __FUNCTION__ << ": no incoming pairings found for this connector!";
+                return false;
             }
+            lg(Debug) << __FUNCTION__ << ": unplugging sinks and sources";
 
             //
             // Disconnect everybody, eating up exceptions in case things have gone away. This is a perfect spot 
@@ -92,15 +148,17 @@ namespace BridgeService
                 {
                     i->second->setSink(0);
                 }
-                catch(const Ice::Exception&)
+                catch(const Ice::Exception& ex)
                 {
+                    lg(Debug) << __FUNCTION__ << ":" << __LINE__ << ": exception, thought you would like to know " << ex.what();
                 }
                 try
                 {
                     i->first->setSource(0);
                 }
-                catch(const Ice::Exception&)
+                catch(const Ice::Exception& ex)
                 {
+                    lg(Debug) << __FUNCTION__ << ":" << __LINE__ << ": exception, thought you would like to know " << ex.what();
                 }
             }
             for(std::vector<IncomingPairing>::iterator i = incoming.begin(); i != incoming.end(); ++i)
@@ -110,39 +168,20 @@ namespace BridgeService
                 {
                     i->first->setSink(0);
                 }
-                catch(const Ice::Exception&)
+                catch(const Ice::Exception& ex)
                 {
+                    lg(Debug) << __FUNCTION__ << ":" << __LINE__ << ": exception, thought you would like to know " << ex.what();
                 }
                 try
                 {
                     i->second->setSource(0);
                 }
-                catch(const Ice::Exception&)
+                catch(const Ice::Exception& ex)
                 {
+                    lg(Debug) << __FUNCTION__ << ":" << __LINE__ << ": exception, thought you would like to know " << ex.what();
                 }
             }
-            mPeer->clearConnections();
-        }
-
-        bool isConnected()
-        {
-            IceUtil::Mutex::Lock lock(mMutex);
-            return mConnected;
-        }
-
-        void clearConnections()
-        {
-            IceUtil::Mutex::Lock lock(mMutex);
-            mOutgoing.clear();
-            mIncoming.clear();
-        }
-
-        void update(const MediaConnectorPtr& peer, const std::vector<OutgoingPairing>& outgoing, const std::vector<IncomingPairing>& incoming)
-        {
-            IceUtil::Mutex::Lock lock(mMutex);
-            mPeer = peer;
-            mOutgoing = outgoing;
-            mIncoming = incoming;
+            return true;
         }
 
     private:
diff --git a/src/MediaSplicer.h b/src/MediaSplicer.h
index 54e0043..7e05a11 100644
--- a/src/MediaSplicer.h
+++ b/src/MediaSplicer.h
@@ -23,6 +23,7 @@ namespace BridgeService
         virtual void unplug() = 0;
         virtual bool isConnected() = 0;
         virtual void clearConnections() = 0;
+        virtual bool disconnectMedia() = 0;
     };
 
     typedef IceUtil::Handle<MediaConnector> MediaConnectorPtr;
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index 8648814..7589df6 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -427,6 +427,7 @@ public:
                 sessions.push_back(a);
 
                 AsteriskSCF::SessionCommunications::V1::SessionPrx c = channel.getSession("333");
+                c->start();
                 sessions.push_back(c);
                 std::string idA = testEnv.communicator()->identityToString(a->ice_getIdentity());
                 std::string idC = testEnv.communicator()->identityToString(c->ice_getIdentity());

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list