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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Sep 8 14:13:44 CDT 2011


branch "bridgetelephony" has been updated
       via  8329ef134ca920bd05c6e2b73a0d6594931e8a58 (commit)
      from  0b44454a92fe5d0626144ee0b339b0d1cf8c19ad (commit)

Summary of changes:
 src/BridgeImpl.cpp        |    8 +++-
 src/SessionOperations.cpp |   21 +++++++++
 src/SessionOperations.h   |    4 ++
 test/TestBridging.cpp     |  102 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 134 insertions(+), 1 deletions(-)


- Log -----------------------------------------------------------------
commit 8329ef134ca920bd05c6e2b73a0d6594931e8a58
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Thu Sep 8 14:14:49 2011 -0500

    Tests and fixes.

diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index 8a603a7..3a62e0a 100755
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -697,6 +697,8 @@ public:
 protected:
     bool executeImpl()
     {
+        vector<TelephonySessionPrx> ignoreList;
+
         // Assumption: All the sessions we need to connect to are already 
         // part of the bridge's session collection. 
         for (SessionSeq::iterator i = mNewSessions.begin(); i != mNewSessions.end(); ++i)
@@ -708,8 +710,12 @@ protected:
                 continue;
             }
 
-            ConnectTelephonyOperation op(telephonySession, mLogger);
+            ConnectTelephonyOperation op(telephonySession, ignoreList, mLogger);
             mBridge->getSessions()->visitSessions(op);
+
+            // Since this session is now connected to all others in the bridge (including
+            // those in the mNewSessions set) we don't need to connect this one again.
+            ignoreList.push_back(telephonySession);
         }
         return true;
     }
diff --git a/src/SessionOperations.cpp b/src/SessionOperations.cpp
index 2f20789..38c0184 100644
--- a/src/SessionOperations.cpp
+++ b/src/SessionOperations.cpp
@@ -235,8 +235,10 @@ void RemoveStreamsOperation::failed(const Ice::Exception&, const SessionWrapperP
 }
 
 ConnectTelephonyOperation::ConnectTelephonyOperation(const TelephonySessionPrx& sessionToConnect,
+                                                     const vector<TelephonySessionPrx>& ignoreList,
                                                      const Logger& logger)
                                                        : mSessionToConnect(sessionToConnect),
+                                                         mIgnoreList(ignoreList),
                                                          mLogger(logger)
 {
 }
@@ -256,11 +258,30 @@ void ConnectTelephonyOperation::operator()(const SessionWrapperPtr& session)
         return;
     }
 
+    if (inIgnoreList(visitedTelephonySession))
+    {
+        return;
+    }
+
     connectSinks(mSessionToConnect, visitedTelephonySession);
     connectSinks(visitedTelephonySession, mSessionToConnect);
 
 }
 
+bool ConnectTelephonyOperation::inIgnoreList(const TelephonySessionPrx& session)
+{
+    for(vector<TelephonySessionPrx>::iterator i=mIgnoreList.begin();   
+        i != mIgnoreList.end(); ++i)
+    {
+        if (session->ice_getIdentity() == (*i)->ice_getIdentity())
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 void ConnectTelephonyOperation::connectSinks
     (const TelephonySessionPrx& sourceSession, 
      const TelephonySessionPrx& sinkSession)
diff --git a/src/SessionOperations.h b/src/SessionOperations.h
index fbe432d..042fdce 100644
--- a/src/SessionOperations.h
+++ b/src/SessionOperations.h
@@ -121,6 +121,7 @@ class ConnectTelephonyOperation : public std::unary_function<SessionWrapperPtr,
 {
 public:
     ConnectTelephonyOperation(const AsteriskSCF::SessionCommunications::V1::TelephonySessionPrx& sessionToConnect,
+                              const std::vector<AsteriskSCF::SessionCommunications::V1::TelephonySessionPrx>& ignoreList,
                               const AsteriskSCF::System::Logging::Logger& logger);
 
     void operator()(const SessionWrapperPtr& session);
@@ -129,7 +130,10 @@ private:
     void connectSinks(const AsteriskSCF::SessionCommunications::V1::TelephonySessionPrx& sourceSession, 
                       const AsteriskSCF::SessionCommunications::V1::TelephonySessionPrx& sinkSession);
 
+    bool inIgnoreList(const AsteriskSCF::SessionCommunications::V1::TelephonySessionPrx& session);
+
     AsteriskSCF::SessionCommunications::V1::TelephonySessionPrx mSessionToConnect;
+    std::vector<AsteriskSCF::SessionCommunications::V1::TelephonySessionPrx> mIgnoreList;
     AsteriskSCF::System::Logging::Logger mLogger;
 };
 typedef IceUtil::Handle<ConnectTelephonyOperation> ConnectTelephonyOperationPtr;
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index f58155f..090cbac 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -1198,6 +1198,106 @@ public:
         }
     }
 
+    void telephonyConnectTest()
+    {
+        try
+        {
+            IceEnvironment testEnv(env()->properties());
+            try
+            {
+                Ice::ObjectAdapterPtr testAdapter =  testEnv.communicator()->createObjectAdapter("TestUtilAdapter");
+                testAdapter->activate();
+                BridgeManagerListenerIPtr servant = new BridgeManagerListenerI;
+                AsteriskSCF::SessionCommunications::V1::BridgeManagerListenerPrx listenerPrx;
+                addServant(listenerPrx, testAdapter, servant, testEnv.strToIdent(IceUtil::generateUUID()));
+
+                BridgeManagerPrx mgrPrx = env()->primaryBridgeManager();
+                BOOST_CHECK(mgrPrx);
+                mgrPrx->addListener(listenerPrx);
+
+                SessionSeq sessions;
+                TestChannelWrapper channel(env()->properties());
+
+                SessionPrx a = channel.getSession("311");
+                TelephonySessionPrx ta = TelephonySessionPrx::checkedCast(a);
+                BOOST_CHECK(ta != 0);
+
+                TelephonyEventSourceSeq aSources = ta->getSources();
+                TelephonyEventSinkSeq aSinks = ta->getSinks();
+                BOOST_CHECK(aSources.size() == 1);
+                BOOST_CHECK(aSinks.size() == 1);
+                TelephonyEventSinkSeq aConnected = aSources[0]->getSinks();
+                BOOST_CHECK(aConnected.size() == 0);
+
+                SessionPrx b = channel.getSession("312");
+                TelephonySessionPrx tb = TelephonySessionPrx::checkedCast(b);
+                BOOST_CHECK(tb != 0);
+
+                TelephonyEventSourceSeq bSources = tb->getSources();
+                TelephonyEventSinkSeq bSinks = tb->getSinks();
+                BOOST_CHECK(bSources.size() == 1);
+                BOOST_CHECK(bSinks.size() == 1);
+                TelephonyEventSinkSeq bConnected = bSources[0]->getSinks();
+                BOOST_CHECK(bConnected.size() == 0);
+
+                sessions.push_back(a);
+                sessions.push_back(b);
+                BridgePrx bridge(mgrPrx->createBridge(sessions, 0));
+
+                IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(2));
+
+                // Now that we're bridged, insure the sinks are connected as expected.
+                aConnected = aSources[0]->getSinks();
+                BOOST_CHECK(aConnected.size() == 1);
+                BOOST_CHECK(aConnected[0]->ice_getIdentity() == bSinks[0]->ice_getIdentity());
+
+                bConnected = bSources[0]->getSinks();
+                BOOST_CHECK(bConnected.size() == 1);
+                BOOST_CHECK(bConnected[0]->ice_getIdentity() == aSinks[0]->ice_getIdentity());
+
+                SessionPrx c = channel.getSession("314");
+                TelephonySessionPrx tc = TelephonySessionPrx::checkedCast(c);
+                BOOST_CHECK(tc != 0);
+
+                sessions.clear();
+                sessions.push_back(c);
+                TelephonyEventSourceSeq cSources = tc->getSources();
+                TelephonyEventSinkSeq cSinks = tc->getSinks();
+
+                bridge->replaceSession(b, sessions);
+
+                IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(2));
+
+                // We've replaced b with c. Make sure all is well, including disconnecting b. 
+                aConnected = aSources[0]->getSinks();
+                BOOST_CHECK(aConnected.size() == 1);
+                BOOST_CHECK(aConnected[0]->ice_getIdentity() == cSinks[0]->ice_getIdentity());
+
+                TelephonyEventSinkSeq cConnected = cSources[0]->getSinks();
+                BOOST_CHECK(cConnected.size() == 1);
+                BOOST_CHECK(cConnected[0]->ice_getIdentity() == aSinks[0]->ice_getIdentity());
+
+                bConnected = bSources[0]->getSinks();
+                BOOST_CHECK(bConnected.size() == 0);
+            }
+            catch (const Ice::Exception& ex)
+            {
+                std::ostringstream msg;
+                msg << "Unexpected Ice exception " << ex.what();
+                BOOST_FAIL(msg.str());
+            }
+            catch (...)
+            {
+                BOOST_FAIL("Unexpected exception");
+            }
+        }
+        catch (...)
+        {
+            BOOST_FAIL("Unexpected exception");
+        }
+    }
+
+
 private:
     TestEnvironmentPtr mTestEnvironment;
 };
@@ -1208,6 +1308,8 @@ bool init_unit_test()
 {
     boost::shared_ptr<BridgeTester> bridgeTester(new BridgeTester(globalTestEnvironment));
     framework::master_test_suite().
+        add(BOOST_TEST_CASE(boost::bind(&BridgeTester::telephonyConnectTest, bridgeTester)));
+    framework::master_test_suite().
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::createEmptyBridge, bridgeTester)));
     framework::master_test_suite().
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::simpleBridgingTest, bridgeTester)));

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list