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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Jul 14 17:32:08 CDT 2011


branch "master" has been updated
       via  b0ed098755f70b5ccd942d79547edf1d926bf78a (commit)
      from  96d470ec32c37b0602c6bb537d86688ed8a1a144 (commit)

Summary of changes:
 config/test_bridging.conf                          |    1 +
 .../BridgeService/BridgeReplicatorIf.ice           |    2 +
 src/BridgeImpl.cpp                                 |  120 +++++++-
 src/BridgeListenerMgr.cpp                          |   16 +-
 src/BridgeListenerMgr.h                            |   10 +-
 src/Service.cpp                                    |   39 ++--
 test/BridgeListenerI.cpp                           |   62 +++--
 test/BridgeListenerI.h                             |   26 ++-
 test/CMakeLists.txt                                |    2 +
 test/TestBridging.cpp                              |  304 ++++++++++++++++++++
 test/TestCookieIf.ice                              |   54 ++++
 11 files changed, 568 insertions(+), 68 deletions(-)
 create mode 100644 test/TestCookieIf.ice


- Log -----------------------------------------------------------------
commit b0ed098755f70b5ccd942d79547edf1d926bf78a
Author: Brent Eagles <beagles at digium.com>
Date:   Thu Jul 14 20:00:56 2011 -0230

    - Bridge cookie support
    
    - Added some component tests for cookie support. These tests may also do a fair
    job of testing unsliceable support, but I'm not at all sure that this is the
    case as everything is run in a single process.
    
    - Also added a workaround in the bridge service for an issue which prevent the
    test suite from running. This is *not* a desirable state of affairs. I think
    that there will be a better solution once the pending changes to service
    discovery are completed.

diff --git a/config/test_bridging.conf b/config/test_bridging.conf
index e88f751..4e19d47 100644
--- a/config/test_bridging.conf
+++ b/config/test_bridging.conf
@@ -105,6 +105,7 @@ ServiceLocatorLocalAdapter.Endpoints=tcp -p 4412
 #
 LocatorService.Proxy=LocatorService:default -p 4411
 ServiceLocatorManagementProxy=LocatorServiceManagement:tcp -p 4422
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 
 #
 # The IceBox entries for loading the services.
diff --git a/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice b/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice
index 4b404cb..6f5c177 100644
--- a/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice
+++ b/slice/AsteriskSCF/Replication/BridgeService/BridgeReplicatorIf.ice
@@ -203,6 +203,8 @@ class BridgeStateItem extends ReplicatedStateItem
     ServiceState runningState;
 
     MediaOperationReplicationPolicy mediaReplicationPolicy;
+
+    AsteriskSCF::SessionCommunications::V1::BridgeCookieDict cookies;
 };
 
 class BridgeListenerStateItem extends ReplicatedStateItem
diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index f669b40..a9cd9e1 100755
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -92,6 +92,10 @@ public:
     void replaceSession_async(const AMD_Bridge_replaceSessionPtr& callbac, const SessionPrx& sessionToReplace,
             const SessionSeq& newSessions, const Ice::Current& current);
 
+    void setCookies(const BridgeCookies& cookies, const Ice::Current&);
+    void removeCookies(const BridgeCookies& cookies, const Ice::Current&);
+    BridgeCookies getCookies(const BridgeCookies& cookies, const Ice::Current&);
+
     //
     // BridgeServant methods
     //
@@ -112,6 +116,16 @@ public:
 
     void getAddSessionsTasks(QueuedTasks& tasks, const SessionSeq& sessions);
 
+    BridgeCookies getCookies()
+    {
+        BridgeCookies result;
+        for (BridgeCookieDict::const_iterator i = mState->cookies.begin(); i != mState->cookies.end(); ++i)
+        {
+            result.push_back(i->second);
+        }
+        return result;
+    }
+
 private:
 
     boost::shared_mutex mLock;
@@ -246,10 +260,11 @@ class RemoveSessionsNotify : public QueuedTask
 {
 public:
     RemoveSessionsNotify(const BridgeListenerMgrPtr& bridgeListeners,
-            const SessionsTrackerPtr& tracker) :
+            const SessionsTrackerPtr& tracker, const BridgeCookies& cookies) :
         QueuedTask("RemoveSessionsNotify"),
         mBridgeListeners(bridgeListeners),
-        mTracker(tracker)
+        mTracker(tracker),
+        mCookies(cookies)
     {
     }
     
@@ -259,7 +274,7 @@ protected:
         SessionSeq sessions = mTracker->getSessions();
         if (!sessions.empty())
         {
-            mBridgeListeners->sessionsRemoved(sessions);
+            mBridgeListeners->sessionsRemoved(sessions, mCookies);
         }
         return true;
     }
@@ -267,6 +282,7 @@ protected:
 private:
     BridgeListenerMgrPtr mBridgeListeners;
     SessionsTrackerPtr mTracker;
+    BridgeCookies mCookies;
 };
 
 class SetBridgeTask : public QueuedTask
@@ -368,23 +384,26 @@ private:
 class AddToListeners : public QueuedTask
 {
 public:
-    AddToListeners(const BridgeListenerMgrPtr& listeners, const SessionsTrackerPtr& tracker) :
+    AddToListeners(const BridgeListenerMgrPtr& listeners, const SessionsTrackerPtr& tracker,
+        const BridgeCookies& cookies) :
         QueuedTask("AddToListeners"),
         mListeners(listeners),
-        mTracker(tracker)
+        mTracker(tracker),
+        mCookies(cookies)
     {
     }
     
 protected:
     bool executeImpl()
     {
-        mListeners->sessionsAdded(mTracker->getSessions());
+        mListeners->sessionsAdded(mTracker->getSessions(), mCookies);
         return true;
     }
     
 private:
     BridgeListenerMgrPtr mListeners;
     SessionsTrackerPtr mTracker;
+    BridgeCookies mCookies;
 };
 
 class CheckShutdown : public QueuedTask
@@ -543,7 +562,7 @@ void BridgeImpl::addSessions_async(const AMD_Bridge_addSessionsPtr& callback, co
         SessionsTrackerPtr tracker(new SessionsTracker);
         QueuedTasks tasks;
         tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, sessions, tracker));
-        tasks.push_back(new AddToListeners(mListeners, tracker));
+        tasks.push_back(new AddToListeners(mListeners, tracker, getCookies()));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_addSessionsPtr>(callback, tracker));
         tasks.push_back(new UpdateTask(this));
         ExecutorPtr executor(new Executor(tasks, mLogger));
@@ -596,7 +615,13 @@ void BridgeImpl::removeSessions_async(const AMD_Bridge_removeSessionsPtr& callba
             }
         }
         QueuedTasks tasks;
-        tasks.push_back(new RemoveSessionsNotify(mListeners, removed));
+
+        BridgeCookies cookies;
+        {
+            boost::shared_lock<boost::shared_mutex> lock(mLock);
+            cookies = getCookies();
+        }
+        tasks.push_back(new RemoveSessionsNotify(mListeners, removed, cookies));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_removeSessionsPtr>(callback, removed));
         tasks.push_back(new CheckShutdown(this, mPrx));
         ExecutorPtr runner(new Executor(tasks, mLogger));
@@ -648,7 +673,7 @@ void BridgeImpl::shutdown(const Ice::Current& current)
         }
         mState->runningState = ShuttingDown;
 
-        mListeners->stopping();
+        mListeners->stopping(getCookies());
         update = createUpdate();
     }
     pushUpdate(update);
@@ -661,8 +686,8 @@ void BridgeImpl::shutdown(const Ice::Current& current)
         ResponseCodePtr responseCode = new ResponseCode;
         ShutdownSessionOperation shutdownOp(mSessionListenerPrx, responseCode, mLogger);
         mSessions->visitSessions(shutdownOp);
-        mListeners->stopped();
         boost::unique_lock<boost::shared_mutex> lock(mLock);
+        mListeners->stopped(getCookies());
         mLogger(Info) << objectIdFromCurrent(current) << ": is shutdown." ;
         mState->runningState = Destroyed;
         //
@@ -694,7 +719,7 @@ void BridgeImpl::destroy(const Ice::Current& current)
         }
         mState->runningState = Destroyed;
         mLogger(Info) << objectIdFromCurrent(current) << ": is now destroyed." ;
-        mListeners->stopped();
+        mListeners->stopped(getCookies());
         mSessionListener = 0;
         update = createUpdate();
     }
@@ -794,9 +819,14 @@ void BridgeImpl::replaceSession_async(const AMD_Bridge_replaceSessionPtr& callba
         
         SessionsTrackerPtr tracker(new SessionsTracker);
         QueuedTasks tasks;
-        tasks.push_back(new RemoveSessionsNotify(mListeners, removeTracker));
+        BridgeCookies cookies;
+        {
+            boost::shared_lock<boost::shared_mutex> lock(mLock);
+            cookies = getCookies();
+        }
+        tasks.push_back(new RemoveSessionsNotify(mListeners, removeTracker, cookies));
         tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, newSessions, tracker));
-        tasks.push_back(new AddToListeners(mListeners, tracker));
+        tasks.push_back(new AddToListeners(mListeners, tracker, cookies));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_replaceSessionPtr>(callback, tracker));
         tasks.push_back(new UpdateTask(this));
         ExecutorPtr executor(new Executor(tasks, mLogger));
@@ -812,6 +842,68 @@ void BridgeImpl::replaceSession_async(const AMD_Bridge_replaceSessionPtr& callba
     }
 }
 
+void BridgeImpl::setCookies(const BridgeCookies& cookies, const Ice::Current& current)
+{
+    mLogger(Debug) << FUNLOG << ":" << objectIdFromCurrent(current);
+    BridgeStateItemPtr update;
+    {
+        boost::unique_lock<boost::shared_mutex> lock(mLock);
+        for (BridgeCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
+        {
+            if ((*i))
+            {
+                mState->cookies[(*i)->ice_id()] = (*i);
+            }
+        }
+        if (!cookies.empty())
+        {
+            update = createUpdate();
+        }
+    }
+    pushUpdate(update);
+}
+
+void BridgeImpl::removeCookies(const BridgeCookies& cookies, const Ice::Current& current)
+{
+    mLogger(Debug) << FUNLOG << ":" << objectIdFromCurrent(current);
+    BridgeStateItemPtr update;
+    {
+        boost::unique_lock<boost::shared_mutex> lock(mLock);
+        bool dirty = false;
+        for (BridgeCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
+        {
+            BridgeCookieDict::iterator v = mState->cookies.find((*i)->ice_id());
+            if (v != mState->cookies.end())
+            {
+                dirty = true;
+                mState->cookies.erase(v);
+            }
+        }
+
+        if (dirty)
+        {
+            update = createUpdate();
+        }
+    }
+    pushUpdate(update);
+}
+
+BridgeCookies BridgeImpl::getCookies(const BridgeCookies& cookies, const Ice::Current& current)
+{
+    BridgeCookies result;
+    mLogger(Debug) << FUNLOG << ":" << objectIdFromCurrent(current);
+    boost::shared_lock<boost::shared_mutex> lock(mLock);
+    for (BridgeCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
+    {
+        BridgeCookieDict::const_iterator v = mState->cookies.find((*i)->ice_id());
+        if (v != mState->cookies.end())
+        {
+            result.push_back(v->second);
+        }
+    }
+    return result;
+}
+
 bool BridgeImpl::destroyed()
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
@@ -944,7 +1036,7 @@ void BridgeImpl::getAddSessionsTasks(QueuedTasks& tasks,
 {
     SessionsTrackerPtr tracker(new SessionsTracker);
     tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, sessions, tracker));
-    tasks.push_back(new AddToListeners(mListeners, tracker));
+    tasks.push_back(new AddToListeners(mListeners, tracker, getCookies()));
     tasks.push_back(new UpdateTask(this));
 }
 
diff --git a/src/BridgeListenerMgr.cpp b/src/BridgeListenerMgr.cpp
index 146162e..d4e214f 100644
--- a/src/BridgeListenerMgr.cpp
+++ b/src/BridgeListenerMgr.cpp
@@ -26,22 +26,22 @@ BridgeListenerMgr::BridgeListenerMgr(const Ice::CommunicatorPtr& comm,
 {
 }
 
-void BridgeListenerMgr::sessionsAdded(const SessionSeq& sessions)
+void BridgeListenerMgr::sessionsAdded(const SessionSeq& sessions, const BridgeCookies& cookies)
 {
-    mPublisher->sessionsAdded(mPrx, sessions);
+    mPublisher->sessionsAdded(mPrx, sessions, cookies);
 }
 
-void BridgeListenerMgr::sessionsRemoved(const SessionSeq& sessions)
+void BridgeListenerMgr::sessionsRemoved(const SessionSeq& sessions, const BridgeCookies& cookies)
 {
-    mPublisher->sessionsRemoved(mPrx, sessions);
+    mPublisher->sessionsRemoved(mPrx, sessions, cookies);
 }
 
-void BridgeListenerMgr::stopped()
+void BridgeListenerMgr::stopped(const BridgeCookies& cookies)
 {
-    mPublisher->stopped(mPrx);
+    mPublisher->stopped(mPrx, cookies);
 }
 
-void BridgeListenerMgr::stopping()
+void BridgeListenerMgr::stopping(const BridgeCookies& cookies)
 {
-    mPublisher->stopping(mPrx);
+    mPublisher->stopping(mPrx, cookies);
 }
diff --git a/src/BridgeListenerMgr.h b/src/BridgeListenerMgr.h
index 5c31156..6bf07b1 100644
--- a/src/BridgeListenerMgr.h
+++ b/src/BridgeListenerMgr.h
@@ -30,10 +30,12 @@ public:
     BridgeListenerMgr(const Ice::CommunicatorPtr& communicator, const std::string& name,
         const AsteriskSCF::SessionCommunications::V1::BridgePrx& source);
 
-    void sessionsAdded(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions);
-    void sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions);
-    void stopped();
-    void stopping();
+    void sessionsAdded(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies);
+    void sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies);
+    void stopped(const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies);
+    void stopping(const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies);
 
 private:
     AsteriskSCF::SessionCommunications::V1::BridgePrx mPrx;
diff --git a/src/Service.cpp b/src/Service.cpp
index f0379d4..73aeb19 100644
--- a/src/Service.cpp
+++ b/src/Service.cpp
@@ -278,26 +278,27 @@ void BridgingApp::start(const std::string& name, const Ice::CommunicatorPtr& com
         manager->activate();
     }
 
-    if (!onStandby)
+    //
+    // This was only set if the service was not active, but I think this may change with the changes to the discovery params 
+    // and being able to specify ids.
+    //
+    bool registered = false;
+    try
     {
-        bool registered = false;
-        try
-        {
-            ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
-            parameters->category = BridgeServiceDiscoveryCategory;
-            mLocator = 
-                new LocatorRegistrationWrapper<BridgeManagerPrx>(communicator, serviceLocatorManagementProperty, bridgeManagerPrx, 
-                        adapterName, parameters);
-            registered = mLocator->registerService();
-        }
-        catch (const Ice::Exception&)
-        {
-        }
-        if (!registered)
-        {
-            mRegisterThread = new RegisterThread<BridgeManagerPrx>(mLocator);
-            mRegisterThread->start();
-        }
+        ServiceLocatorParamsPtr parameters(new ServiceLocatorParams);
+        parameters->category = BridgeServiceDiscoveryCategory;
+        mLocator = 
+            new LocatorRegistrationWrapper<BridgeManagerPrx>(communicator, serviceLocatorManagementProperty, bridgeManagerPrx, 
+                    adapterName, parameters);
+        registered = mLocator->registerService();
+    }
+    catch (const Ice::Exception&)
+    {
+    }
+    if (!registered)
+    {
+        mRegisterThread = new RegisterThread<BridgeManagerPrx>(mLocator);
+        mRegisterThread->start();
     }
     //
     // TODO: We need to know whether or not to activate!
diff --git a/test/BridgeListenerI.cpp b/test/BridgeListenerI.cpp
index 1499846..222995f 100644
--- a/test/BridgeListenerI.cpp
+++ b/test/BridgeListenerI.cpp
@@ -16,6 +16,7 @@
 #include "BridgeListenerI.h"
 
 using namespace AsteriskSCF::BridgingTest;
+using namespace std;
 
 BridgeListenerI::BridgeListenerI() :
     mShuttingDown(false),
@@ -23,27 +24,39 @@ BridgeListenerI::BridgeListenerI() :
 {
 }
 
-void BridgeListenerI::sessionsAdded(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current&)
+void BridgeListenerI::sessionsAdded(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, 
+    const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
+    const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    updateCookieMap("sessionsAdded", cookies);
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mAddMonitor);
-    mAdded.insert(mAdded.end(), sessions.begin(), sessions.end());
+    mAdded =sessions;
     mAddMonitor.notify();
 }
 
-void BridgeListenerI::sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const Ice::Current&)
+void BridgeListenerI::sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, 
+    const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
+    const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    updateCookieMap("sessionsRemoved", cookies);
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mRemoveMonitor);
-    mRemoved.insert(mRemoved.end(), sessions.begin(), sessions.end());
+    mRemoved = sessions;
     mRemoveMonitor.notify();
 }
 
-void BridgeListenerI::stopping(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const Ice::Current&)
+void BridgeListenerI::stopping(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, 
+    const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    updateCookieMap("stopping", cookies);
+    IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
     mShuttingDown = true;
+    mStateMonitor.notify();
 }
 
-void BridgeListenerI::stopped(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, const Ice::Current&)
+void BridgeListenerI::stopped(const AsteriskSCF::SessionCommunications::V1::BridgePrx&, 
+    const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current&)
 {
+    updateCookieMap("stopped", cookies);
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
     mStopped = true;
     mStateMonitor.notify();
@@ -53,6 +66,7 @@ bool BridgeListenerI::resetShuttingDown()
 {
     bool result = mShuttingDown;
     mShuttingDown = false;
+    mCookieMap.clear();
     return result;
 }
 
@@ -60,6 +74,7 @@ bool BridgeListenerI::resetStopped()
 {
     bool result = mStopped;
     mStopped = false;
+    mCookieMap.clear();
     return result;
 }
 
@@ -67,30 +82,26 @@ bool BridgeListenerI::waitForAdded(unsigned long milliseconds, AsteriskSCF::Sess
 {
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mAddMonitor);
     bool waitResult = mAddMonitor.timedWait(IceUtil::Time::milliSeconds(milliseconds));
-    if(waitResult && mAdded.size() > 0)
-    {
-        added = mAdded;
-        return true;
-    }
-    return false;
+    added = mAdded;
+    mAdded.clear();
+    return !added.empty();
 }
 
 bool BridgeListenerI::waitForRemoved(unsigned long milliseconds, AsteriskSCF::SessionCommunications::V1::SessionSeq& removed)
 {
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mRemoveMonitor);
     bool waitResult = mRemoveMonitor.timedWait(IceUtil::Time::milliSeconds(milliseconds));
-    if(waitResult && mRemoved.size() > 0)
-    {
-        removed = mRemoved;
-        return true;
-    }
-    return false;
+    removed = mRemoved;
+    mRemoved.clear();
+    return !removed.empty();
+
 }
 
 bool BridgeListenerI::waitForStopped(unsigned long milliseconds)
 {
     IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mStateMonitor);
-    return mStateMonitor.timedWait(IceUtil::Time::milliSeconds(milliseconds));
+    mStateMonitor.timedWait(IceUtil::Time::milliSeconds(milliseconds));
+    return mStopped;
 }
 
 size_t BridgeListenerI::addedCount()
@@ -102,3 +113,16 @@ size_t BridgeListenerI::removedCount()
 {
     return mRemoved.size();
 }
+
+CookieMap BridgeListenerI::getCookieMap()
+{
+    IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mCookieMapMonitor);
+    return mCookieMap;
+}
+
+void BridgeListenerI::updateCookieMap(const string& operation, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies)
+{
+    IceUtil::Monitor<IceUtil::Mutex>::Lock lock(mCookieMapMonitor);
+    mCookieMap[operation] = cookies;
+}
diff --git a/test/BridgeListenerI.h b/test/BridgeListenerI.h
index c8550e5..881de6b 100644
--- a/test/BridgeListenerI.h
+++ b/test/BridgeListenerI.h
@@ -16,20 +16,29 @@
 #pragma once
 
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
+#include <map>
+#include <string>
 
 namespace AsteriskSCF
 {
 namespace BridgingTest
 {
+typedef std::map<std::string, AsteriskSCF::SessionCommunications::V1::BridgeCookies> CookieMap;
 
 class BridgeListenerI : public AsteriskSCF::SessionCommunications::V1::BridgeListener
 {
 public:
     BridgeListenerI();
-    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);
+    void sessionsAdded(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, 
+        const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current& current);
+    void sessionsRemoved(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, 
+        const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current& current);
+    void stopping(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current& current);
+    void stopped(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies, const Ice::Current& current);
     bool resetShuttingDown();
     bool resetStopped();
 
@@ -40,6 +49,8 @@ public:
     size_t addedCount();
     size_t removedCount();
 
+    CookieMap getCookieMap();
+
 private:
     bool mShuttingDown;
     bool mStopped;
@@ -47,10 +58,17 @@ private:
     IceUtil::Monitor<IceUtil::Mutex> mAddMonitor;
     IceUtil::Monitor<IceUtil::Mutex> mRemoveMonitor;
     IceUtil::Monitor<IceUtil::Mutex> mStateMonitor;
+
+    IceUtil::Monitor<IceUtil::Mutex> mCookieMapMonitor;
+    CookieMap mCookieMap;
+
     AsteriskSCF::SessionCommunications::V1::SessionSeq mAdded;
     AsteriskSCF::SessionCommunications::V1::SessionSeq mRemoved;
     bool mSessionsAdded;
     bool mSessionsRemoved;
+
+    void updateCookieMap(const std::string& operation, 
+        const AsteriskSCF::SessionCommunications::V1::BridgeCookies& cookies);
 };
 
 typedef IceUtil::Handle<BridgeListenerI> BridgeListenerPtr;
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index a9de994..6f2f1af 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -6,7 +6,9 @@ include_directories(../src)
 astscf_slice_include_collection(TEST_CHANNEL)
 
 astscf_component_init(bridge_component_test)
+astscf_slice_collection(LOCAL PATH "${CMAKE_CURRENT_SOURCE_DIR}")
 astscf_component_add_slices(bridge_component_test TEST_CHANNEL AsteriskSCF/TestChannel/CommandsIf.ice)
+astscf_component_add_slices(bridge_component_test LOCAL TestCookieIf.ice)
 astscf_component_add_files(bridge_component_test TestBridging.cpp)
 astscf_component_add_files(bridge_component_test BridgeListenerI.h)
 astscf_component_add_files(bridge_component_test BridgeListenerI.cpp)
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index 82edf8d..38ecc55 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -28,6 +28,8 @@
 #include "TestCommandDriver.h"
 #include "../src/ServiceUtil.h"
 
+#include "TestCookieIf.h"
+
 #include <Ice/Ice.h>
 #include <IceBox/IceBox.h>
 
@@ -39,12 +41,108 @@ using namespace AsteriskSCF::BridgingTest;
 using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::Core::Routing::V1;
+using namespace AsteriskSCFTest;
 using namespace std;
 
 /* Cache the command line arguments so that Ice can be initialized within the global fixture. */
 namespace
 {
 
+BridgeCookies bakeTestCookies()
+{
+    BridgeCookies result;
+    TestCookieAPtr aCookie = new TestCookieA;
+    aCookie->astring = "I'm just a simple test cookie";
+    result.push_back(aCookie);
+
+    TestCookieBPtr bCookie = new TestCookieB;
+    bCookie->blong = 0xdeadbeef;
+    result.push_back(bCookie);
+
+    TestCookieDerivedFromBPtr derivedFromB = new TestCookieDerivedFromB;
+    derivedFromB->blong = 0xfeeffeef;
+    derivedFromB->bstring = "What the hex?";
+    result.push_back(derivedFromB);
+
+    TestNestedPtr nested1 = new TestNested;
+    nested1->baseString = "simple nested";
+
+    TestNestedDerivedPtr derivedNested= new TestNestedDerived;
+    derivedNested->baseString = "slightly less simple nested";
+    derivedNested->derivedLong = 42;
+
+    NestedTestSeq nestedObjs;
+    nestedObjs.push_back(nested1);
+    nestedObjs.push_back(derivedNested);
+    TestCookieCPtr cCookie = new TestCookieC;
+    cCookie->gettingALittleCrazyArentWe = nestedObjs;
+    result.push_back(cCookie);
+    return result;
+}
+
+void tasteCookies(const BridgeCookies& cookies, bool a, bool b, bool c, bool d)
+{
+    int count = 0;
+    if (a)
+    {
+        ++count;
+    }
+    if (b)
+    {
+        ++count;
+    }
+    if (c)
+    {
+        ++count;
+    }
+    if (d)
+    {
+        ++count;
+    }
+    BOOST_REQUIRE(cookies.size() == count);
+    for (BridgeCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
+    {
+        BridgeCookiePtr cookie = *i;
+        if (cookie->ice_id() == TestCookieA::ice_staticId())
+        {
+            a = !a;
+            BOOST_REQUIRE(TestCookieAPtr::dynamicCast(cookies[0])->astring == "I'm just a simple test cookie");
+        }
+        else if (cookie->ice_id() == TestCookieB::ice_staticId())
+        {
+            b = !b;
+            BOOST_REQUIRE(TestCookieBPtr::dynamicCast(cookies[1])->blong == 0xdeadbeef);
+        }
+        else if (cookie->ice_id() == TestCookieDerivedFromB::ice_staticId())
+        {
+            c = !c;
+            BOOST_REQUIRE(TestCookieDerivedFromBPtr::dynamicCast(cookie)->blong == 0xfeeffeef);
+            BOOST_REQUIRE(TestCookieDerivedFromBPtr::dynamicCast(cookie)->bstring == "What the hex?");
+        }
+        else if (cookie->ice_id() == TestCookieC::ice_staticId())
+        {
+            d = !d;
+            NestedTestSeq nestedObjs = TestCookieCPtr::dynamicCast(cookie)->gettingALittleCrazyArentWe;
+            BOOST_REQUIRE(nestedObjs.size() == 2);
+            BOOST_REQUIRE(nestedObjs[0]->ice_id() == TestNested::ice_staticId());
+            BOOST_REQUIRE(TestNestedPtr::dynamicCast(nestedObjs[0])->baseString == "simple nested");
+            BOOST_REQUIRE(nestedObjs[1]->ice_id() == TestNestedDerived::ice_staticId());
+            BOOST_REQUIRE(TestNestedDerivedPtr::dynamicCast(nestedObjs[1])->baseString == "slightly less simple nested");
+            BOOST_REQUIRE(TestNestedDerivedPtr::dynamicCast(nestedObjs[1])->derivedLong == 42);
+        }
+    }
+
+    BOOST_REQUIRE(!a);
+    BOOST_REQUIRE(!b);
+    BOOST_REQUIRE(!c);
+    BOOST_REQUIRE(!d);
+}
+
+void tasteCookies(const BridgeCookies& cookies)
+{
+    tasteCookies(cookies, true, true, true, true);
+}
+
 void propGetSet(const Ice::PropertiesPtr& p, const string& propertyName, const string& value)
 {
     p->setProperty(propertyName, p->getPropertyWithDefault(propertyName, value));
@@ -852,6 +950,208 @@ public:
         }
     }
 
+    //
+    // The following tests validate the operation of the bridge cookie API and the corresponding listener
+    // interface. The listener apis are evaluated for each method, but only once (for adding). After 
+    // that the getCookies is used to confirm the end result. We duplicate the tests that include replication
+    // to verify that replication of the cookies is occurring also.
+    //
+
+    void simpleCookieAddTest()
+    {
+        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()));
+
+                AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx mgrPrx = env()->primaryBridgeManager();
+                BOOST_CHECK(mgrPrx);
+                mgrPrx->addListener(listenerPrx);
+                BOOST_CHECK(servant->stoppingCalls() == 0);
+                BOOST_CHECK(servant->stoppedCalls() == 0);
+                BOOST_CHECK(servant->createCalls() == 0);
+                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"));
+                BridgeCookies cookies = bakeTestCookies();
+                bridge->setCookies(cookies);
+                AsteriskSCF::BridgingTest::BridgeListenerPtr bridgeListener = new BridgeListenerI;
+                AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx bridgeListenerPrx;
+                addServant(bridgeListenerPrx, testAdapter, bridgeListener, testEnv.strToIdent(IceUtil::generateUUID()));
+                bridge->addListener(bridgeListenerPrx);
+
+                AsteriskSCF::SessionCommunications::V1::SessionSeq eventSessions;
+                bridge->addSessions(sessions);
+                BOOST_REQUIRE(bridgeListener->waitForAdded(5000, eventSessions));
+                CookieMap cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(!cookieMap.empty());
+                BOOST_REQUIRE(!eventSessions.empty());
+
+                BOOST_REQUIRE(cookieMap.find("sessionsAdded") != cookieMap.end());
+                BridgeCookies returnedCookies = cookieMap["sessionsAdded"];
+                tasteCookies(returnedCookies);
+
+                sessions.clear();
+                sessions.push_back(b);
+                eventSessions.clear();
+                bridge->removeSessions(sessions);
+                BOOST_REQUIRE(bridgeListener->waitForRemoved(5000, eventSessions));
+                cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(!cookieMap.empty());
+                BOOST_REQUIRE(cookieMap.find("sessionsRemoved") != cookieMap.end());
+                returnedCookies = cookieMap["sessionsRemoved"];
+                tasteCookies(returnedCookies);
+
+                BOOST_REQUIRE(bridgeListener->waitForStopped(5000));
+                cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(cookieMap.find("stopping") != cookieMap.end());
+                returnedCookies = cookieMap["stopping"];
+                tasteCookies(returnedCookies);
+                BOOST_REQUIRE(cookieMap.find("stopped") != cookieMap.end());
+                returnedCookies = cookieMap["stopped"];
+                BOOST_REQUIRE(!returnedCookies.empty());
+                tasteCookies(returnedCookies);
+                returnedCookies = bridge->getCookies(cookies);
+                tasteCookies(returnedCookies);
+                
+            }
+            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");
+        }
+    }
+
+    void cookieAddRemoveTest()
+    {
+        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()));
+
+                AsteriskSCF::SessionCommunications::V1::BridgeManagerPrx mgrPrx = env()->primaryBridgeManager();
+                BOOST_CHECK(mgrPrx);
+                mgrPrx->addListener(listenerPrx);
+                BOOST_CHECK(servant->stoppingCalls() == 0);
+                BOOST_CHECK(servant->stoppedCalls() == 0);
+                BOOST_CHECK(servant->createCalls() == 0);
+                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"));
+                BridgeCookies cookies = bakeTestCookies();
+                bridge->setCookies(cookies);
+                AsteriskSCF::BridgingTest::BridgeListenerPtr bridgeListener = new BridgeListenerI;
+                AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx bridgeListenerPrx;
+                addServant(bridgeListenerPrx, testAdapter, bridgeListener, testEnv.strToIdent(IceUtil::generateUUID()));
+                bridge->addListener(bridgeListenerPrx);
+
+                AsteriskSCF::SessionCommunications::V1::SessionSeq eventSessions;
+                bridge->addSessions(sessions);
+                BOOST_REQUIRE(bridgeListener->waitForAdded(5000, eventSessions));
+                CookieMap cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(!cookieMap.empty());
+                BOOST_REQUIRE(!eventSessions.empty());
+
+                BOOST_REQUIRE(cookieMap.find("sessionsAdded") != cookieMap.end());
+                BridgeCookies returnedCookies = cookieMap["sessionsAdded"];
+                tasteCookies(returnedCookies);
+                BridgeCookies toRemove;
+                toRemove.push_back(cookies[1]);
+                bridge->removeCookies(toRemove);
+
+                sessions.clear();
+                sessions.push_back(b);
+                eventSessions.clear();
+                bridge->removeSessions(sessions);
+                BOOST_REQUIRE(bridgeListener->waitForRemoved(5000, eventSessions));
+                cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(!cookieMap.empty());
+                BOOST_REQUIRE(cookieMap.find("sessionsRemoved") != cookieMap.end());
+                returnedCookies = cookieMap["sessionsRemoved"];
+                tasteCookies(returnedCookies, true, false, true, true);
+
+                BOOST_REQUIRE(bridgeListener->waitForStopped(5000));
+                cookieMap = bridgeListener->getCookieMap();
+                BOOST_REQUIRE(cookieMap.find("stopping") != cookieMap.end());
+                returnedCookies = cookieMap["stopping"];
+                tasteCookies(returnedCookies, true, false, true, true);
+                BOOST_REQUIRE(cookieMap.find("stopped") != cookieMap.end());
+                returnedCookies = cookieMap["stopped"];
+                BOOST_REQUIRE(!returnedCookies.empty());
+                tasteCookies(returnedCookies, true, false, true, true);
+                cookies.erase(cookies.begin() +1); 
+                returnedCookies = bridge->getCookies(cookies);
+                tasteCookies(returnedCookies, true, false, true, true);
+            }
+            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;
 };
@@ -875,6 +1175,10 @@ bool init_unit_test()
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::testReplaceSession, bridgeTester)));
     framework::master_test_suite().
         add(BOOST_TEST_CASE(boost::bind(&BridgeTester::testBridgeManagerListenerReplication, bridgeTester)));
+    framework::master_test_suite().
+        add(BOOST_TEST_CASE(boost::bind(&BridgeTester::simpleCookieAddTest, bridgeTester)));
+    framework::master_test_suite().
+        add(BOOST_TEST_CASE(boost::bind(&BridgeTester::cookieAddRemoveTest, bridgeTester)));
     return true;
 }
 
diff --git a/test/TestCookieIf.ice b/test/TestCookieIf.ice
new file mode 100644
index 0000000..dbd46ad
--- /dev/null
+++ b/test/TestCookieIf.ice
@@ -0,0 +1,54 @@
+/*
+ * 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
+
+#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.ice>
+
+module AsteriskSCFTest
+{
+unsliceable class TestCookieA extends AsteriskSCF::SessionCommunications::V1::BridgeCookie
+{
+    string astring;
+};
+
+unsliceable class TestCookieB extends AsteriskSCF::SessionCommunications::V1::BridgeCookie
+{
+    long blong;
+};
+
+unsliceable class TestCookieDerivedFromB extends TestCookieB
+{
+    string bstring;
+};
+
+unsliceable class TestNested
+{
+    string baseString;
+};
+
+unsliceable class TestNestedDerived extends TestNested
+{
+    long derivedLong;
+};
+
+sequence<TestNested> NestedTestSeq;
+
+unsliceable class TestCookieC extends AsteriskSCF::SessionCommunications::V1::BridgeCookie
+{
+    NestedTestSeq gettingALittleCrazyArentWe;
+};
+
+}; /* End of module AsteriskSCFTest */

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


-- 
asterisk-scf/release/bridging.git



More information about the asterisk-scf-commits mailing list