[asterisk-scf-commits] asterisk-scf/release/bridging.git branch "default_bridge_listeners" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Dec 9 08:40:23 CST 2010


branch "default_bridge_listeners" has been created
        at  3196083a473be1645896fa18c8ea806957eb10ce (commit)

- Log -----------------------------------------------------------------
commit 3196083a473be1645896fa18c8ea806957eb10ce
Author: Brent Eagles <beagles at digium.com>
Date:   Thu Dec 9 11:00:59 2010 -0330

    Adding default bridge listener support.

diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index 8924abb..a37ba7b 100755
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -424,21 +424,18 @@ private:
 } // End of namespace BridgeService
 } // End of namespace AsteriskSCF
 
-AsteriskSCF::BridgeService::BridgeImpl::BridgeImpl(
-    const Ice::ObjectAdapterPtr& adapter,
-        const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx& ev,
-        const AsteriskSCF::BridgeService::BridgeListenerMgrPtr& listenerMgr,
-        const AsteriskSCF::SessionCommunications::V1::BridgePrx& prx
-    ) :
+AsteriskSCF::BridgeService::BridgeImpl::BridgeImpl(const Ice::ObjectAdapterPtr& adapter, 
+  const std::vector<AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx>& listeners, const AsteriskSCF::BridgeService::BridgeListenerMgrPtr& listenerMgr, 
+  const AsteriskSCF::SessionCommunications::V1::BridgePrx& prx) :
     mState(Running),
     mObjAdapter(adapter),
     mListeners(listenerMgr),
     mSessionListener(new SessionListener(this)),
     mPrx(prx)
 {
-    if(ev)
+    for(std::vector<AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx>::const_iterator i = listeners.begin(); i != listeners.end(); ++i)
     {
-        mListeners->addListener(ev);
+        mListeners->addListener(*i);
     }
     std::string listenerId = mObjAdapter->getCommunicator()->identityToString(prx->ice_getIdentity());
     listenerId += ".sessionListener";
diff --git a/src/BridgeImpl.h b/src/BridgeImpl.h
index 8044d24..9572d8f 100644
--- a/src/BridgeImpl.h
+++ b/src/BridgeImpl.h
@@ -117,7 +117,7 @@ public:
     typedef IceUtil::Handle<BridgeSession> BridgeSessionPtr;
 
     BridgeImpl(const Ice::ObjectAdapterPtr& objAdapter,
-        const SessionCommunications::V1::BridgeListenerPrx& ev,
+        const std::vector<AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx>& listeners,
         const AsteriskSCF::BridgeService::BridgeListenerMgrPtr& listenerMgr,
         const AsteriskSCF::SessionCommunications::V1::BridgePrx& prx);
 
diff --git a/src/BridgeManagerImpl.cpp b/src/BridgeManagerImpl.cpp
index 3540bc6..e8a0242 100644
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@ -21,17 +21,11 @@
 #include "BridgeManagerListenerMgr.h"
 #include "logger.h"
 
-using namespace AsteriskSCF::System::Logging;
-
-namespace
-{
-Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.BridgeService");
-}
-
 //
 // Compiled in constants.
 // TODO: Replace with configuration!
 //
+using namespace AsteriskSCF::System::Logging;
 
 static const std::string TopicPrefix("AsteriskSCF.BridgeManager.");
 
@@ -62,17 +56,16 @@ private:
 } // End of namespace BridgeService
 } // End of namespace AsteriskSCF
 
-AsteriskSCF::BridgeService::BridgeManagerImpl::BridgeManagerImpl(
-    const Ice::ObjectAdapterPtr& adapter,
-        const std::string& name,
-        const AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx& prx) :
+AsteriskSCF::BridgeService::BridgeManagerImpl::BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const std::string& name,
+    const AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx& prx, const AsteriskSCF::System::Logging::LoggerPtr& logger) :
     mName(name),
     mShuttingDown(false),
     mSuspended(false),
     mAdapter(adapter),
-    mSourceProxy(prx)
+    mSourceProxy(prx),
+    mLogger(logger)
 {
-    lg(Info) << "Created AsteriskSCF Session-Oriented Bridge Manager." ;
+    mLogger(Info) << "Created AsteriskSCF Session-Oriented Bridge Manager." ;
     mListeners = new AsteriskSCF::BridgeService::BridgeManagerListenerMgr(mAdapter->getCommunicator(), mName, mSourceProxy);
 }
 
@@ -90,19 +83,9 @@ AsteriskSCF::SessionCommunications::V1::BridgePrx AsteriskSCF::BridgeService::Br
         const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx& listener,
         const Ice::Current& current)
 {
-    lg(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
-
+    mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
     boost::unique_lock<boost::shared_mutex> lock(mLock);
-    if(mShuttingDown)
-    {
-        lg(Debug) << __FUNCTION__ << ": called when shutting down." ;
-        throw AsteriskSCF::System::Component::V1::ShuttingDown();
-    }
-    if(mSuspended || mListeners->isSuspended())
-    {
-        lg(Debug) << __FUNCTION__ << ": called when suspended." ;
-        throw AsteriskSCF::System::Component::V1::Suspended();
-    }
+    statePreCheck(__FUNCTION__);
     reap();
 
     std::string stringId = std::string("bridge.") + IceUtil::generateUUID();
@@ -110,11 +93,15 @@ AsteriskSCF::SessionCommunications::V1::BridgePrx AsteriskSCF::BridgeService::Br
     AsteriskSCF::SessionCommunications::V1::BridgePrx prx(
         AsteriskSCF::SessionCommunications::V1::BridgePrx::uncheckedCast(mAdapter->createProxy(id)));
     AsteriskSCF::BridgeService::BridgeListenerMgrPtr mgr(new BridgeListenerMgr(mAdapter->getCommunicator(), stringId, prx));
-
-    AsteriskSCF::BridgeService::BridgeImplPtr bridge = new AsteriskSCF::BridgeService::BridgeImpl(mAdapter, listener, mgr, prx);
+    std::vector<AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx> listeners(mDefaultBridgeListeners.begin(), mDefaultBridgeListeners.end());
+    if(listener)
+    {
+        listeners.push_back(listener);
+    }
+    AsteriskSCF::BridgeService::BridgeImplPtr bridge = new AsteriskSCF::BridgeService::BridgeImpl(mAdapter, listeners, mgr, prx);
     Ice::ObjectPrx obj = mAdapter->add(bridge, id);
 
-    lg(Info) << current.adapter->getCommunicator()->identityToString(current.id) << ": creating new bridge " << obj->ice_toString() << "." ;
+    mLogger(Info) << current.adapter->getCommunicator()->identityToString(current.id) << ": creating new bridge " << obj->ice_toString() << "." ;
     BridgeInfo info;
     info.servant = bridge;
     info.proxy = AsteriskSCF::SessionCommunications::V1::BridgePrx::uncheckedCast(obj);
@@ -134,17 +121,9 @@ AsteriskSCF::SessionCommunications::V1::BridgePrx AsteriskSCF::BridgeService::Br
 
 void AsteriskSCF::BridgeService::BridgeManagerImpl::addListener(const SessionCommunications::V1::BridgeManagerListenerPrx& listener, const Ice::Current& current)
 {
+    mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
     boost::unique_lock<boost::shared_mutex> lock(mLock);
-    if(mShuttingDown)
-    {
-        lg(Debug) << __FUNCTION__ << ": called when shutting down." ;
-        throw AsteriskSCF::System::Component::V1::ShuttingDown();
-    }
-    if(mSuspended || mListeners->isSuspended())
-    {
-        lg(Debug) << __FUNCTION__ << ": called when suspended." ;
-        throw AsteriskSCF::System::Component::V1::Suspended();
-    }
+    statePreCheck(__FUNCTION__);
     if(!mListeners)
     {
         mSourceProxy = AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx::uncheckedCast(mAdapter->createProxy(current.id));
@@ -155,17 +134,9 @@ void AsteriskSCF::BridgeService::BridgeManagerImpl::addListener(const SessionCom
 
 void AsteriskSCF::BridgeService::BridgeManagerImpl::removeListener(const SessionCommunications::V1::BridgeManagerListenerPrx& listener, const Ice::Current& current)
 {
+    mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
     boost::unique_lock<boost::shared_mutex> lock(mLock);
-    if(mShuttingDown)
-    {
-        lg(Debug) << __FUNCTION__ << ": called when shutting down." ;
-        throw AsteriskSCF::System::Component::V1::ShuttingDown();
-    }
-    if(mSuspended || mListeners->isSuspended())
-    {
-        lg(Debug) << __FUNCTION__ << ": called when suspended." ;
-        throw AsteriskSCF::System::Component::V1::Suspended();
-    }
+    statePreCheck(__FUNCTION__);
     if(!mListeners)
     {
         mSourceProxy = AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx::uncheckedCast(mAdapter->createProxy(current.id));
@@ -174,9 +145,41 @@ void AsteriskSCF::BridgeService::BridgeManagerImpl::removeListener(const Session
     mListeners->removeListener(listener);
 }
 
+void AsteriskSCF::BridgeService::BridgeManagerImpl::addDefaultBridgeListener(const SessionCommunications::V1::BridgeListenerPrx& newListener, const Ice::Current& current)
+{
+    mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
+    if(!newListener)
+    {
+        mLogger(Info) << __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(mLock);
+    statePreCheck(__FUNCTION__);
+    if(mDefaultBridgeListeners.end() == std::find_if(mDefaultBridgeListeners.begin(), mDefaultBridgeListeners.end(), 
+          IdentityComparePred<SessionCommunications::V1::BridgeListenerPrx>(newListener)))
+    {
+        mDefaultBridgeListeners.push_back(newListener);
+    }
+
+}
+
+void AsteriskSCF::BridgeService::BridgeManagerImpl::removeDefaultBridgeListener(const SessionCommunications::V1::BridgeListenerPrx& toRemove, const Ice::Current& current)
+{
+    mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
+    if(!toRemove)
+    {
+        mLogger(Info) << __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(mLock);
+    statePreCheck(__FUNCTION__);
+    std::remove_if(mDefaultBridgeListeners.begin(), mDefaultBridgeListeners.end(), IdentityComparePred<SessionCommunications::V1::BridgeListenerPrx>(toRemove)); 
+}
+
 AsteriskSCF::SessionCommunications::V1::BridgeSeq
-AsteriskSCF::BridgeService::BridgeManagerImpl::listBridges(const Ice::Current&)
+AsteriskSCF::BridgeService::BridgeManagerImpl::listBridges(const Ice::Current& current)
 {
+    mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
     boost::shared_lock<boost::shared_mutex> lock(mLock);
     AsteriskSCF::SessionCommunications::V1::BridgeSeq result;
     for(std::vector<BridgeInfo>::iterator i = mBridges.begin(); i != mBridges.end();++i)
@@ -188,23 +191,14 @@ AsteriskSCF::BridgeService::BridgeManagerImpl::listBridges(const Ice::Current&)
 
 void AsteriskSCF::BridgeService::BridgeManagerImpl::shutdown(const Ice::Current& current)
 {
-    lg(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
+    mLogger(Debug) << __FUNCTION__ << ":" << current.adapter->getCommunicator()->identityToString(current.id) ;
     boost::unique_lock<boost::shared_mutex> lock(mLock);
-    if(mShuttingDown)
-    {
-        lg(Debug) << __FUNCTION__ << ": called when shutting down." ;
-        return;
-    }
-    if(mSuspended)
-    {
-        lg(Debug) << __FUNCTION__ << ": called when suspended." ;
-        throw AsteriskSCF::System::Component::V1::Suspended();
-    }
+    statePreCheck(__FUNCTION__);
     if(mListeners && !mListeners->isSuspended())
     {
         mListeners->stopping();
     }
-    lg(Info) << current.adapter->getCommunicator()->identityToString(current.id) << ": shutting down." ;
+    mLogger(Info) << current.adapter->getCommunicator()->identityToString(current.id) << ": shutting down." ;
     mShuttingDown = true;
     reap();
     if(mBridges.size() > 0)
@@ -221,7 +215,7 @@ void AsteriskSCF::BridgeService::BridgeManagerImpl::shutdown(const Ice::Current&
 
 void AsteriskSCF::BridgeService::BridgeManagerImpl::reap()
 {
-    lg(Debug) << __FUNCTION__ << ": reaping bridge set of " << mBridges.size() << " bridges." ;
+    mLogger(Debug) << __FUNCTION__ << ": reaping bridge set of " << mBridges.size() << " bridges." ;
     std::vector<BridgeInfo>::iterator i = mBridges.begin();
     while(i != mBridges.end())
     {
@@ -234,5 +228,19 @@ void AsteriskSCF::BridgeService::BridgeManagerImpl::reap()
         }
         ++i;
     }
-    lg(Debug) << __FUNCTION__ << ": reaping completed, bridge set size is now " << mBridges.size() << "." ;
+    mLogger(Debug) << __FUNCTION__ << ": reaping completed, bridge set size is now " << mBridges.size() << "." ;
+}
+
+void AsteriskSCF::BridgeService::BridgeManagerImpl::statePreCheck(const std::string& caller)
+{
+    if(mShuttingDown)
+    {
+        mLogger(Debug) << caller << ": called when shutting down." ;
+        return;
+    }
+    if(mSuspended || mListeners->isSuspended())
+    {
+        mLogger(Debug) << caller << ": called when suspended." ;
+        throw AsteriskSCF::System::Component::V1::Suspended();
+    }
 }
diff --git a/src/BridgeManagerImpl.h b/src/BridgeManagerImpl.h
index c2a18a5..7be75cd 100644
--- a/src/BridgeManagerImpl.h
+++ b/src/BridgeManagerImpl.h
@@ -19,6 +19,7 @@
 #include <boost/thread/shared_mutex.hpp>
 #include <vector>
 
+#include "BridgeServiceConfig.h"
 #include "BridgeImpl.h"
 #include "BridgeManagerListenerMgr.h"
 
@@ -30,7 +31,8 @@ class BridgeManagerImpl : public SessionCommunications::V1::BridgeManager
 {
 public:
 
-    BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const std::string& name, const AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx& prx);
+    BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const std::string& name, const AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx& prx,
+      const AsteriskSCF::System::Logging::LoggerPtr& logger);
     ~BridgeManagerImpl();
 
     //
@@ -43,6 +45,10 @@ public:
 
     void addListener(const SessionCommunications::V1::BridgeManagerListenerPrx& listener, const Ice::Current& current);
     void removeListener(const SessionCommunications::V1::BridgeManagerListenerPrx& listener, const Ice::Current& current);
+
+    void addDefaultBridgeListener(const SessionCommunications::V1::BridgeListenerPrx& newListener, const Ice::Current& current);
+    void removeDefaultBridgeListener(const SessionCommunications::V1::BridgeListenerPrx& toRemove, const Ice::Current& current);
+
     SessionCommunications::V1::BridgeSeq listBridges(const Ice::Current& current);
     void shutdown(const Ice::Current& current);
 
@@ -62,7 +68,11 @@ private:
     Ice::ObjectAdapterPtr mAdapter;
     AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx mSourceProxy;
     BridgeManagerListenerMgrPtr mListeners;
+    AsteriskSCF::System::Logging::LoggerPtr mLogger;
+    std::vector<AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx> mDefaultBridgeListeners;
+
     void reap();
+    void statePreCheck(const std::string&);
 };
 
 typedef IceUtil::Handle<BridgeManagerImpl> BridgeManagerImplPtr;
diff --git a/src/BridgeServiceConfig.h b/src/BridgeServiceConfig.h
new file mode 100644
index 0000000..579ad56
--- /dev/null
+++ b/src/BridgeServiceConfig.h
@@ -0,0 +1,72 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+
+
+//
+// Some bridge service wide definitions.
+//
+namespace AsteriskSCF
+{
+namespace System
+{
+namespace Logging
+{
+    class Logger;
+    //
+    // Temporary until the logger is a reference counted entity.
+    //
+    typedef Logger& LoggerPtr; 
+
+} // End of namespace Logging
+} // End of namespace System
+
+namespace BridgeService
+{
+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)
+        {
+            if(mExample == 0)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        if(mExample == 0)
+        {
+            return false;
+        }
+        return (mExample->ice_getIdentity() == toTest->ice_getIdentity());
+    }
+private:
+    T mExample;
+};
+} // End of namespace BridgeService
+} // End of namespace AsteriskSCF
diff --git a/src/Service.cpp b/src/Service.cpp
index cfc0021..a9f151a 100644
--- a/src/Service.cpp
+++ b/src/Service.cpp
@@ -183,7 +183,7 @@ void BridgingApp::start(const std::string& name, const Ice::CommunicatorPtr& com
     AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx s(
         AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx::uncheckedCast(mAdapter->createProxy(id))
         );
-    AsteriskSCF::SessionCommunications::V1::BridgeManagerPtr servant(new AsteriskSCF::BridgeService::BridgeManagerImpl(mAdapter, ManagerName, s));
+    AsteriskSCF::SessionCommunications::V1::BridgeManagerPtr servant(new AsteriskSCF::BridgeService::BridgeManagerImpl(mAdapter, ManagerName, s, lg));
     mAdapter->add(servant, id);
     mAdapter->activate();
 
diff --git a/test/BridgeListenerI.cpp b/test/BridgeListenerI.cpp
index e1cca9b..cc316af 100644
--- a/test/BridgeListenerI.cpp
+++ b/test/BridgeListenerI.cpp
@@ -23,26 +23,26 @@ BridgeListenerI::BridgeListenerI() :
 {
 }
 
-void BridgeListenerI::sessionsAdded(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current)
+void BridgeListenerI::sessionsAdded(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current)
 {
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mAddMonitor);
-    mAdded = sessions;
+    mAdded.insert(mAdded.end(), sessions.begin(), sessions.end());
     mAddMonitor.notify();
 }
 
-void BridgeListenerI::sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current)
+void BridgeListenerI::sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current)
 {
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mRemoveMonitor);
-    mRemoved = sessions;
+    mRemoved.insert(mRemoved.end(), sessions.begin(), sessions.end());
     mRemoveMonitor.notify();
 }
 
-void BridgeListenerI::stopping(const Ice::Current& current)
+void BridgeListenerI::stopping(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const Ice::Current& current)
 {
     mShuttingDown = true;
 }
 
-void BridgeListenerI::stopped(const Ice::Current& current)
+void BridgeListenerI::stopped(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const Ice::Current& current)
 {
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
     mStopped = true;
@@ -92,3 +92,13 @@ bool BridgeListenerI::waitForStopped(unsigned long milliseconds)
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
     return mStateMonitor.timedWait(IceUtil::Time::milliSeconds(milliseconds));
 }
+
+size_t BridgeListenerI::addedCount()
+{
+    return mAdded.size();
+}
+
+size_t BridgeListenerI::removedCount()
+{
+    return mRemoved.size();
+}
diff --git a/test/BridgeListenerI.h b/test/BridgeListenerI.h
index 7f56615..aa7636e 100644
--- a/test/BridgeListenerI.h
+++ b/test/BridgeListenerI.h
@@ -26,10 +26,10 @@ class BridgeListenerI : public AsteriskSCF::SessionCommunications::V1::BridgeLis
 {
 public:
     BridgeListenerI();
-    void sessionsAdded(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current);
-    void sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current);
-    void stopping(const Ice::Current& current);
-    void stopped(const Ice::Current& current);
+    void sessionsAdded(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current);
+    void sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current& current);
+    void stopping(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, const Ice::Current& current);
+    void stopped(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, const Ice::Current& current);
     bool resetShuttingDown();
     bool resetStopped();
 
@@ -37,6 +37,9 @@ public:
     bool waitForRemoved(unsigned long milliseconds, AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions);
     bool waitForStopped(unsigned long milliseconds);
 
+    size_t addedCount();
+    size_t removedCount();
+
 private:
     bool mShuttingDown;
     bool mStopped;
@@ -50,5 +53,7 @@ private:
     bool mSessionsRemoved;
 };
 
+typedef IceUtil::Handle<BridgeListenerI> BridgeListenerPtr;
+
 } /* end of namespace BridgingTest */
 } /* end of namespace AsteriskSCF */
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index 3c03bac..ddeee26 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -30,6 +30,11 @@
 #include <Ice/Ice.h>
 #include <IceBox/IceBox.h>
 
+//
+// TODO:
+// Add tests to exercise input validation.
+//
+
 using namespace AsteriskSCF::BridgingTest;
 
 /* Cache the command line arguments so that Ice can be initialized within the global fixture. */
@@ -125,6 +130,7 @@ public:
         }
         catch(...)
         {
+            std::cerr << "exception on destroy!" << std::endl;
         }
     }
 
@@ -355,6 +361,99 @@ public:
         }
     };
 
+    void bridgeDefaultListenerTest()
+    {
+        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("testBridgeManagerListener"));
+
+                AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx mgrPrx =
+                    AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx::checkedCast(testEnv.communicator()->propertyToProxy("TestBridge.Proxy"));
+                BOOST_CHECK(mgrPrx);
+                mgrPrx->addListener(listenerPrx);
+                BOOST_CHECK(servant->stoppingCalls() == 0);
+                BOOST_CHECK(servant->stoppedCalls() == 0);
+                BOOST_CHECK(servant->createCalls() == 0);
+
+                AsteriskSCF::BridgingTest::BridgeListenerPtr bridgeListener = new BridgeListenerI;
+                AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx bridgeListenerPrx;
+                addServant(bridgeListenerPrx, testAdapter, bridgeListener, testEnv.strToIdent("testBridgeListener"));
+                mgrPrx->addDefaultBridgeListener(bridgeListenerPrx);
+
+                AsteriskSCF::SessionCommunications::V1::SessionSeq sessions;
+                AsteriskSCF::SessionCommunications::V1::BridgePrx bridge(mgrPrx->createBridge(sessions, 0));
+                TestChannelWrapper channel(env()->properties());
+
+                AsteriskSCF::SessionCommunications::V1::SessionPrx a = channel.getSession("311");
+                AsteriskSCF::SessionCommunications::V1::SessionPrx b = channel.getSession("312");
+                sessions.push_back(a);
+                sessions.push_back(b);
+                //
+                // precondition checks for test validity.
+                //
+                std::string idA = testEnv.communicator()->identityToString(a->ice_getIdentity());
+                std::string idB = testEnv.communicator()->identityToString(b->ice_getIdentity());
+                std::vector<std::string> log;
+                channel.commands()->getlog(idA, log);
+                BOOST_CHECK(!find(log, "start"));
+                channel.commands()->getlog(idB, log);
+                BOOST_CHECK(!find(log, "start"));
+
+                bridge->addSessions(sessions);
+                //
+                // Check for regression where the bridge was calling start on sessions.
+                //
+                channel.commands()->getlog(idA, log);
+                BOOST_CHECK(!find(log, "start"));
+                channel.commands()->getlog(idB, log);
+                BOOST_CHECK(!find(log, "start"));
+
+                a->start();
+                b->start();
+
+                channel.commands()->getlog(idA, log);
+                BOOST_CHECK(find(log, "start"));
+                channel.commands()->getlog(idB, log);
+                BOOST_CHECK(find(log, "start"));
+
+                //
+                // Should result in a media hookup!
+                //
+                channel.commands()->answer(idA);
+                channel.commands()->answer(idB);
+
+                BOOST_CHECK(bridgeListener->addedCount() == 2);
+                bridge->shutdown();
+
+                BOOST_CHECK(servant->createCalls() == 1);
+                channel.commands()->getlog(idA, log);
+                BOOST_CHECK(find(log, "stop"));
+                channel.commands()->getlog(idB, log);
+                BOOST_CHECK(find(log, "stop"));
+            }
+            catch(const Ice::Exception& ex)
+            {
+                std::cerr << ex << std::endl;
+                BOOST_CHECK(false);
+            }
+            catch(...)
+            {
+                BOOST_CHECK(false);
+            }
+        }
+        catch(...)
+        {
+            BOOST_CHECK(false);
+        }
+    };
+
     void bridgeManagerListeners()
     {
         try
@@ -492,6 +591,8 @@ bool init_unit_test()
     framework::master_test_suite().
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::simpleBridgingTest, bridgeTester)));
     framework::master_test_suite().
+        add(BOOST_TEST_CASE(boost::bind(&BridgeTester::bridgeDefaultListenerTest, bridgeTester)));
+    framework::master_test_suite().
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::bridgeManagerListeners, bridgeTester)));
     framework::master_test_suite().
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::testReplaceSession, bridgeTester)));

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


-- 
asterisk-scf/release/bridging.git



More information about the asterisk-scf-commits mailing list