[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "partyidhook" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Sep 15 20:07:42 CDT 2011


branch "partyidhook" has been created
        at  343318d7cfa8902a4f85857dfce97eaf451ab39d (commit)

- Log -----------------------------------------------------------------
commit 343318d7cfa8902a4f85857dfce97eaf451ab39d
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Thu Sep 15 20:04:55 2011 -0500

    Support extension point for modifying party id info.

diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index 1563ec9..427729b 100755
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -33,6 +33,7 @@
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::SessionCommunications::PartyIdentification::V1;
+using namespace AsteriskSCF::SessionCommunications::ExtensionPoints::V1;
 using namespace AsteriskSCF::BridgeService;
 using namespace AsteriskSCF::Replication::BridgeService::V1;
 using namespace AsteriskSCF;
@@ -69,6 +70,7 @@ public:
     BridgeImpl(const string& name, const Ice::ObjectAdapterPtr& objAdapter,
             const vector<BridgeListenerPrx>& listeners,
             const BridgeListenerMgrPtr& listenerMgr,
+            const BridgePartyIdHooksPtr& partyIdHooks,
             const ReplicatorSmartPrx& replicator,
             const BridgeStateItemPtr& state,
             const Logger& logger);
@@ -116,6 +118,11 @@ public:
 
     void getAddSessionsTasks(QueuedTasks& tasks, const SessionSeq& sessions);
 
+    BridgePartyIdHooksPtr getPartyIdHooks()
+    {
+        return mPartyIdHooks;
+    }
+
     BridgeCookies getCookies()
     {
         BridgeCookies result;
@@ -126,6 +133,9 @@ public:
         return result;
     }
 
+    void updateConnectedLine(const SessionWrapperPtr& sourceSession, const ConnectedLinePtr& connectedLine);
+    void redirectingUpdated(const SessionWrapperPtr& sourceSession, const RedirectingPtr& redirecting);
+
 private:
 
     boost::shared_mutex mLock;
@@ -149,6 +159,7 @@ private:
     Ice::ObjectAdapterPtr mObjAdapter;
 
     BridgeListenerMgrPtr mListeners;
+    BridgePartyIdHooksPtr mPartyIdHooks;
     ReplicatorSmartPrx mReplicator;
     
     //
@@ -256,6 +267,273 @@ private:
 };
 typedef IceUtil::Handle<SessionsTracker> SessionsTrackerPtr;
 
+
+/**
+ * Forwards the redirecting record for the specified session
+ * to every other session in the bridge. Applies the 
+ * ForwardingRedirecting hooks to the Redirecting record
+ * in the process. 
+ *
+ * Note: For now we forward the Redirecting record 
+ * without considering whether there are more then two
+ * sessions in the bridge. The API may need a more complex 
+ * class than Redirecting to push the Redirecting state
+ * of all Sessions in the bridge. 
+ */
+class ForwardRedirectingUpdatedTask : public QueuedTask
+{
+public:
+    ForwardRedirectingUpdatedTask(const BridgeImplPtr& bridge, 
+            const SessionWrapperPtr& sourceSession,
+            const RedirectingPtr& redirecting,
+            const Logger& logger) :
+        QueuedTask("ForwardRedirectingUpdatedTask"),
+        mBridge(bridge),
+        mSourceSession(sourceSession),
+        mRedirecting(redirecting),
+        mLogger(logger)
+    {
+    }
+    
+protected:
+    bool executeImpl()
+    {
+        try
+        {
+            mLogger(Debug) << FUNLOG;
+
+            BridgePartyIdHooksPtr partyIdHooks = mBridge->getPartyIdHooks();
+
+            // Forward the ConnectedLine to each bridged session.
+            SessionSeq sessions = mBridge->getSessions()->getSessionSeq();
+            for(SessionSeq::iterator i = sessions.begin();
+                i != sessions.end(); ++i)
+            {
+                if ((*i)->ice_getIdentity() == mSourceSession->getSession()->ice_getIdentity())
+                {
+                    continue;
+                }
+
+                SessionWrapperPtr destSessionWrapper = mBridge->getSessions()->getSession(*i);
+                forward(destSessionWrapper, mRedirecting);
+            }
+
+        }
+        catch (const std::exception e)
+        {
+            mLogger(Debug) << FUNLOG << " : " << e.what();
+        }
+
+        return true;
+    }
+           
+    void forward(const SessionWrapperPtr destinationSession, const RedirectingPtr& redirecting)
+    {
+        try
+        {
+            mLogger(Debug) << FUNLOG;
+
+            RedirectingPtr currentRedirecting = redirecting;
+            RedirectingPtr destSpecificRedirecting = redirecting;
+
+            BridgePartyIdHooksPtr partyIdHooks = mBridge->getPartyIdHooks();
+
+            // Allow the ForwardingRedirectingPartyId hooks to alter the Redirecting record. 
+            for(vector<ForwardingRedirectingPartyIdHookPrx>::const_iterator i = partyIdHooks->getForwardingRedirectingPartyIdHooks().begin();
+                i != partyIdHooks->getForwardingRedirectingPartyIdHooks().end(); ++i)
+            {
+                AsteriskSCF::System::Hook::V1::HookResult hookResult = (*i)->modifyForwardingRedirecting(mSourceSession->getSession(),
+                    destinationSession->getSession(),
+                    currentRedirecting, destSpecificRedirecting);
+
+                if (hookResult.status == AsteriskSCF::System::Hook::V1::Succeeded)
+                {
+                    currentRedirecting = destSpecificRedirecting;
+                }
+            }
+
+            // Forward the info via the SessionController for this session.
+            destinationSession->getSessionController()->redirectingUpdated(currentRedirecting);
+        }
+        catch (const std::exception e)
+        {
+            mLogger(Debug) << FUNLOG << " : " << e.what();
+        }
+    }
+
+private:
+    BridgeImplPtr mBridge;
+    SessionWrapperPtr mSourceSession;
+    RedirectingPtr mRedirecting;
+    Logger mLogger;
+};
+
+/**
+ * Sends the cached ConnectedLine info for the specified session
+ * to every other session in the bridge. Applies the 
+ * ForwardingConnectedLine hooks to the ConnectedLine record
+ * in the process. 
+ *
+ * Note: For now we forward the ConnectedLine record 
+ * without considering whether there are more then two
+ * sessions in the bridge. The API may need a more complex 
+ * class than ConnectedLine to push the state
+ * of more than one Session. 
+ */
+class ForwardConnectedLineTask : public QueuedTask
+{
+public:
+    ForwardConnectedLineTask(const BridgeImplPtr& bridge, 
+            const SessionWrapperPtr& sourceSession,
+            const Logger& logger) :
+        QueuedTask("ForwardConnectedLineTask"),
+        mBridge(bridge),
+        mSourceSession(sourceSession),
+        mLogger(logger)
+    {
+    }
+    
+protected:
+    bool executeImpl()
+    {
+        try
+        {
+            mLogger(Debug) << FUNLOG;
+
+            ConnectedLinePtr currentConnectedLine;
+            bool isSet = mSourceSession->getConnectedLine(currentConnectedLine);
+
+            if (!isSet)
+            {
+                mLogger(Error) << "ConnectedLine not cached for forwarding. " ;
+                return true; 
+            }
+
+            // Forward the ConnectedLine to each bridged session.
+            SessionSeq sessions = mBridge->getSessions()->getSessionSeq();
+            for(SessionSeq::iterator i = sessions.begin();
+                i != sessions.end(); ++i)
+            {
+                if ((*i)->ice_getIdentity() == mSourceSession->getSession()->ice_getIdentity())
+                {
+                    continue;
+                }
+
+                SessionWrapperPtr destSessionWrapper = mBridge->getSessions()->getSession(*i);
+                forward(destSessionWrapper, currentConnectedLine);
+            }
+
+        }
+        catch (const std::exception e)
+        {
+            mLogger(Debug) << FUNLOG << " : " << e.what();
+        }
+
+        return true;
+    }
+           
+    void forward(const SessionWrapperPtr destinationSession, const ConnectedLinePtr& connectedLine)
+    {
+        try
+        {
+            mLogger(Debug) << FUNLOG;
+
+            ConnectedLinePtr currentConnectedLine = connectedLine;
+            ConnectedLinePtr destSpecificConnectedLine = connectedLine;
+
+            BridgePartyIdHooksPtr partyIdHooks = mBridge->getPartyIdHooks();
+
+            // Allow the ForwardingConnectedLinePartyId hooks to alter the ConnectedLine record. 
+            for(vector<ForwardingConnectedLinePartyIdHookPrx>::const_iterator i = partyIdHooks->getForwardingConnectedLinePartyIdHooks().begin();
+                i != partyIdHooks->getForwardingConnectedLinePartyIdHooks().end(); ++i)
+            {
+                AsteriskSCF::System::Hook::V1::HookResult hookResult = (*i)->modifyForwardingConnectedLine(mSourceSession->getSession(),
+                    destinationSession->getSession(),
+                    currentConnectedLine, destSpecificConnectedLine);
+
+                if (hookResult.status == AsteriskSCF::System::Hook::V1::Succeeded)
+                {
+                    currentConnectedLine = destSpecificConnectedLine;
+                }
+            }
+
+            // Forward the info via the SessionController for this session.
+            destinationSession->getSessionController()->updateConnectedLine(currentConnectedLine);
+        }
+        catch (const std::exception e)
+        {
+            mLogger(Debug) << FUNLOG << " : " << e.what();
+        }
+    }
+
+private:
+    BridgeImplPtr mBridge;
+    SessionWrapperPtr mSourceSession;
+    Logger mLogger;
+};
+
+/**
+ * Applies the ReceiveConnectedLine hooks to the new ConnectedLine
+ * information before caching it for the specified session. 
+ */
+class UpdateConnectedLineTask : public QueuedTask
+{
+public:
+    UpdateConnectedLineTask(const BridgeImplPtr& bridge, 
+            const SessionWrapperPtr& sourceSession,
+            const ConnectedLinePtr& connectedLine,
+            const Logger& logger) :
+        QueuedTask("UpdateConnectedLineTask"),
+        mBridge(bridge),
+        mSourceSession(sourceSession),
+        mConnectedLine(connectedLine),
+        mLogger(logger)
+    {
+    }
+    
+protected:
+    bool executeImpl()
+    {
+        try
+        {
+            mLogger(Debug) << FUNLOG;
+
+            ConnectedLinePtr currentConnectedLine = mConnectedLine;
+            ConnectedLinePtr updatedConnectedLine = mConnectedLine;
+
+            BridgePartyIdHooksPtr partyIdHooks = mBridge->getPartyIdHooks();
+
+            // Allow the ReceivedConnectedLinePartyId hooks to alter the ConnectedLine record. 
+            for(vector<ReceivedConnectedLinePartyIdHookPrx>::const_iterator i = partyIdHooks->getReceivedConnectedLinePartyIdHooks().begin();
+                i != partyIdHooks->getReceivedConnectedLinePartyIdHooks().end(); ++i)
+            {
+                AsteriskSCF::System::Hook::V1::HookResult hookResult = (*i)->modifyReceivedConnectedLine(mSourceSession->getSession(),
+                    currentConnectedLine, updatedConnectedLine);
+
+                if (hookResult.status == AsteriskSCF::System::Hook::V1::Succeeded)
+                {
+                    currentConnectedLine = updatedConnectedLine;
+                }
+            }
+
+            // Cache this value.
+            mSourceSession->setConnectedLine(currentConnectedLine);
+        }
+        catch (const std::exception e)
+        {
+            mLogger(Debug) << FUNLOG << " : " << e.what();
+        }
+
+        return true;
+    }
+           
+private:
+    BridgeImplPtr mBridge;
+    SessionWrapperPtr mSourceSession;
+    ConnectedLinePtr mConnectedLine;
+    Logger mLogger;
+};
+
 class RemoveSessionsNotify : public QueuedTask
 {
 public:
@@ -410,14 +688,14 @@ public:
         cb->ice_response();
     }
 
-    void updateConnectedLine(const ConnectedLinePtr&, const Ice::Current&)
+    void updateConnectedLine(const ConnectedLinePtr& connectedLine, const Ice::Current&)
     {
-        // TBD
+        mBridge->updateConnectedLine(mSelf, connectedLine);
     }
 
-    void updateRedirecting(const RedirectingPtr&, const ::Ice::Current&) 
+    void redirectingUpdated(const RedirectingPtr& redirecting, const ::Ice::Current&) 
     {
-        // TBD
+        mBridge->redirectingUpdated(mSelf, redirecting);
     }
 
 private:
@@ -697,6 +975,7 @@ private:
 BridgeImpl::BridgeImpl(const string& name, const Ice::ObjectAdapterPtr& adapter, 
         const vector<BridgeListenerPrx>& listeners, 
         const BridgeListenerMgrPtr& listenerMgr,
+        const BridgePartyIdHooksPtr& partyIdHooks,
         const ReplicatorSmartPrx& replicator,
         const BridgeStateItemPtr& state,
         const Logger& logger) :
@@ -706,6 +985,7 @@ BridgeImpl::BridgeImpl(const string& name, const Ice::ObjectAdapterPtr& adapter,
     mName(name),
     mObjAdapter(adapter),
     mListeners(listenerMgr),
+    mPartyIdHooks(partyIdHooks),
     mReplicator(replicator),
     mSessionListener(createSessionListener(mSessions, logger)),
     mLogger(logger)
@@ -727,6 +1007,55 @@ BridgeImpl::~BridgeImpl()
     //
 }
 
+/** 
+ * Process an updated ConnectedLine record from a session. 
+ */
+void BridgeImpl::updateConnectedLine(const SessionWrapperPtr& sourceSession, const ConnectedLinePtr& connectedLine)
+{
+     try
+    {
+        QueuedTasks tasks;
+
+        // Updates the cached ConnectedLine party id information for the given session.
+        //  - Applies receive hooks on the received ConnectedLine info before caching.
+        tasks.push_back(new UpdateConnectedLineTask(this, sourceSession, connectedLine, mLogger));
+
+
+        // Forwards the ConnectedLine information to the other sessions in the bridge.
+        //  - Applies forwarding hooks to the cached ConnectedLine info before forwarding.
+        tasks.push_back(new ForwardConnectedLineTask(this, sourceSession, mLogger));
+
+        ExecutorPtr runner(new Executor(tasks, mLogger));
+        runner->start();
+    }
+    catch (const std::exception e)
+    {
+        mLogger(Debug) << FUNLOG << " : " << e.what();
+    }
+}
+
+/** 
+ * Process an updated Redirecting record from a session. 
+ */
+void BridgeImpl::redirectingUpdated(const SessionWrapperPtr& sourceSession, const RedirectingPtr& redirecting)
+{
+     try
+    {
+        QueuedTasks tasks;
+
+
+        // Forwards the Redirecting information to the other sessions in the bridge.
+        //  - Applies forwarding hooks to the Redirecrting info before forwarding.
+        tasks.push_back(new ForwardRedirectingUpdatedTask(this, sourceSession, redirecting, mLogger));
+        ExecutorPtr runner(new Executor(tasks, mLogger));
+        runner->start();
+    }
+    catch (const std::exception e)
+    {
+        mLogger(Debug) << FUNLOG << " : " << e.what();
+    }
+}
+
 void BridgeImpl::addSessions_async(const AMD_Bridge_addSessionsPtr& callback, const SessionSeq& sessions,
         const Ice::Current&)
 {
@@ -1300,6 +1629,7 @@ IceUtil::Handle<AsteriskSCF::BridgeService::BridgeServant>
 AsteriskSCF::BridgeService::BridgeServant::create(const string& name, const Ice::ObjectAdapterPtr& objectAdapter,
         const vector<BridgeListenerPrx>& listeners,
         const AsteriskSCF::BridgeService::BridgeListenerMgrPtr& listenerMgr,
+        const BridgePartyIdHooksPtr& partyIdHooks,
         const ReplicatorSmartPrx& replicator,
         const Logger& logger)
 {
@@ -1312,12 +1642,13 @@ AsteriskSCF::BridgeService::BridgeServant::create(const string& name, const Ice:
     // allowing localized resources to be used.
     //
     state->mediaReplicationPolicy = Replicate;
-    return new BridgeImpl(name, objectAdapter, listeners, listenerMgr, replicator, state, logger);
+    return new BridgeImpl(name, objectAdapter, listeners, listenerMgr, partyIdHooks, replicator, state, logger);
 }
 
 IceUtil::Handle<AsteriskSCF::BridgeService::BridgeServant>
 AsteriskSCF::BridgeService::BridgeServant::create(const Ice::ObjectAdapterPtr& objectAdapter,
         const AsteriskSCF::BridgeService::BridgeListenerMgrPtr& listenerMgr,
+        const BridgePartyIdHooksPtr& partyIdHooks,
         const ReplicatorSmartPrx& replicator,
         const Logger& logger,
         const AsteriskSCF::Replication::BridgeService::V1::BridgeStateItemPtr& state)
@@ -1325,7 +1656,7 @@ AsteriskSCF::BridgeService::BridgeServant::create(const Ice::ObjectAdapterPtr& o
     logger(Debug) << FUNLOG << ": creating replica for " << state->bridgeId;
     IceUtil::Handle<AsteriskSCF::BridgeService::BridgeServant> bridge(
         new BridgeImpl(state->bridgeId, objectAdapter, vector<BridgeListenerPrx>(),
-                    listenerMgr, replicator, state, logger));
+                    listenerMgr, partyIdHooks, replicator, state, logger));
     
     return bridge;
 }
diff --git a/src/BridgeImpl.h b/src/BridgeImpl.h
index 2c9ab9f..7f29bb9 100644
--- a/src/BridgeImpl.h
+++ b/src/BridgeImpl.h
@@ -18,6 +18,7 @@
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
 #include <boost/thread/shared_mutex.hpp>
 #include <vector>
+#include "BridgePartyIdExtensionPoint.h"
 #include "BridgeReplicatorIf.h"
 #include "BridgeListenerMgr.h"
 #include "BridgeServiceConfig.h"
@@ -136,6 +137,7 @@ public:
             const Ice::ObjectAdapterPtr& objectAdapter,
             const std::vector<AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx>& listeners,
             const AsteriskSCF::BridgeService::BridgeListenerMgrPtr& listenerMgr,
+            const AsteriskSCF::BridgeService::BridgePartyIdHooksPtr& partyIdHooks,
             const ReplicatorSmartPrx& replicator, 
             const AsteriskSCF::System::Logging::Logger& logger);
 
@@ -146,6 +148,7 @@ public:
      **/
     static IceUtil::Handle<BridgeServant> create(const Ice::ObjectAdapterPtr& objectAdapter,
             const AsteriskSCF::BridgeService::BridgeListenerMgrPtr& listenerMgr,
+            const AsteriskSCF::BridgeService::BridgePartyIdHooksPtr& partyIdHooks,
             const ReplicatorSmartPrx& replicator,
             const AsteriskSCF::System::Logging::Logger& logger,
             const AsteriskSCF::Replication::BridgeService::V1::BridgeStateItemPtr& state);
diff --git a/src/BridgeManagerImpl.cpp b/src/BridgeManagerImpl.cpp
index 7361dc5..b596b99 100644
--- a/src/BridgeManagerImpl.cpp
+++ b/src/BridgeManagerImpl.cpp
@@ -44,7 +44,9 @@ class BridgeManagerImpl : public BridgeManagerServant
 {
 public:
 
-    BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const string& name,
+    BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, 
+            const string& name,
+            const BridgePartyIdExtensionPointPtr& partyIdExtensionPoint,
             const BridgeReplicationContextPtr& replicationContext, const Logging::Logger& logger);
     ~BridgeManagerImpl();
 
@@ -92,6 +94,7 @@ private:
 
     boost::shared_mutex mLock;
     string mName;
+    BridgePartyIdExtensionPointPtr mPartyIdExtensionPoint;
     vector<BridgeInfo> mBridges;
     Ice::ObjectAdapterPtr mAdapter;
     BridgeReplicationContextPtr mReplicationContext;
@@ -109,13 +112,17 @@ private:
 
 typedef IceUtil::Handle<BridgeManagerImpl> BridgeManagerImplPtr;
 
-BridgeManagerImpl::BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, const string& name, const BridgeReplicationContextPtr& replicationContext,
-        const Logger& logger) :
-    mName(name),
-    mAdapter(adapter),
-    mReplicationContext(replicationContext), 
-    mLogger(logger),
-    mState(new BridgeManagerStateItem)
+BridgeManagerImpl::BridgeManagerImpl(const Ice::ObjectAdapterPtr& adapter, 
+    const string& name, 
+    const BridgePartyIdExtensionPointPtr& partyIdExtensionPoint,
+    const BridgeReplicationContextPtr& replicationContext,
+    const Logger& logger) :
+        mName(name),
+        mPartyIdExtensionPoint(partyIdExtensionPoint),
+        mAdapter(adapter),
+        mReplicationContext(replicationContext), 
+        mLogger(logger),
+        mState(new BridgeManagerStateItem)
 {
     mLogger(Info) << "Created AsteriskSCF Session-Oriented Bridge Manager." ;
     mListeners = new BridgeManagerListenerMgr(mAdapter->getCommunicator(), mName, mSourceProxy);
@@ -189,7 +196,8 @@ void BridgeManagerImpl::createBridge_async(const AMD_BridgeManager_createBridgeP
             listeners.push_back(listener);
         }
 
-        BridgeServantPtr bridge = BridgeServant::create(stringId, mAdapter, listeners, mgr, mReplicationContext->getReplicator(), mLogger);
+        BridgeServantPtr bridge = BridgeServant::create(stringId, mAdapter, listeners, mgr, 
+             mPartyIdExtensionPoint->getHooks(), mReplicationContext->getReplicator(), mLogger);
         Ice::ObjectPrx obj = mAdapter->add(bridge, id);
 
         mLogger(Info) << objectIdFromCurrent(current) << ": creating new bridge " << obj->ice_toString() << "." ;
@@ -388,7 +396,8 @@ void BridgeManagerImpl::createBridgeReplica(const BridgeStateItemPtr& state)
     BridgePrx prx(BridgePrx::uncheckedCast(mAdapter->createProxy(id)));
     BridgeListenerMgrPtr mgr(new BridgeListenerMgr(mAdapter->getCommunicator(), state->bridgeId, prx));
 
-    BridgeServantPtr bridge = BridgeServant::create(mAdapter, mgr, mReplicationContext->getReplicator(), mLogger, state);
+    BridgeServantPtr bridge = BridgeServant::create(mAdapter, mgr, 
+        mPartyIdExtensionPoint->getHooks(), mReplicationContext->getReplicator(), mLogger, state);
     Ice::ObjectPrx obj = mAdapter->add(bridge, id);
 
     mLogger(Info) << ": creating bridge replica " << obj->ice_toString() << "." ;
@@ -471,9 +480,11 @@ void BridgeManagerImpl::update()
 } // End of anonymous namespace
 
 BridgeManagerServantPtr 
-AsteriskSCF::BridgeService::createBridgeManager(const Ice::ObjectAdapterPtr& adapter, const string& name,
-        const BridgeReplicationContextPtr& replicationContext,
-        const Logger& logger)
+AsteriskSCF::BridgeService::createBridgeManager(const Ice::ObjectAdapterPtr& adapter, 
+    const string& name,
+    const BridgePartyIdExtensionPointPtr& partyIdExtensionPoint,
+    const BridgeReplicationContextPtr& replicationContext,
+    const Logger& logger)
 {
-    return new BridgeManagerImpl(adapter, name, replicationContext, logger);
+    return new BridgeManagerImpl(adapter, name, partyIdExtensionPoint, replicationContext, logger);
 }
diff --git a/src/BridgeManagerImpl.h b/src/BridgeManagerImpl.h
index 62090a2..e1998dd 100644
--- a/src/BridgeManagerImpl.h
+++ b/src/BridgeManagerImpl.h
@@ -66,6 +66,10 @@ typedef IceUtil::Handle<BridgeManagerServant> BridgeManagerServantPtr;
  *
  * @param adapter The Ice object adapter for the BridgeManager all of the servants it will create.
  *
+ *
+ * @param partyIdExtensionPoint Object that manages the hooks that have been added to this component for
+ * modifying Party Id information.
+ *
  * @param name A name for this servant. This will be used to construct the new BridgeManager object's Ice::Identity. 
  *             It is used to construct relative object ids for all objects that the bridge manager creates.
  *
@@ -73,7 +77,9 @@ typedef IceUtil::Handle<BridgeManagerServant> BridgeManagerServantPtr;
  *
  **/
 BridgeManagerServantPtr createBridgeManager(const Ice::ObjectAdapterPtr& adapter,
-        const std::string& name, const BridgeReplicationContextPtr& replicationContext,
+        const std::string& name, 
+        const BridgePartyIdExtensionPointPtr& partyIdExtensionPoint,
+        const BridgeReplicationContextPtr& replicationContext,
         const AsteriskSCF::System::Logging::Logger& logger);
 
 };
diff --git a/src/BridgePartyIdExtensionPoint.cpp b/src/BridgePartyIdExtensionPoint.cpp
new file mode 100644
index 0000000..2d168b2
--- /dev/null
+++ b/src/BridgePartyIdExtensionPoint.cpp
@@ -0,0 +1,189 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, 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.
+ */
+
+#include <boost/thread/shared_mutex.hpp>
+
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Collections/ProxySet.h>
+#include <AsteriskSCF/SessionCommunications/SessionCommunicationsExtensionPointsIf.h>
+
+#include "BridgePartyIdExtensionPoint.h"
+
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::ExtensionPoints::V1;
+using namespace AsteriskSCF::BridgeService;
+
+namespace
+{
+
+class BridgePartyIdHooksImpl : public BridgePartyIdHooks
+{
+public:
+    BridgePartyIdHooksImpl(const std::vector<ReceivedConnectedLinePartyIdHookPrx>& receiveConnectedLineHooks,
+                           const std::vector<ForwardingConnectedLinePartyIdHookPrx>& forwardingConnectedLineHooks,
+                           const std::vector<ForwardingRedirectingPartyIdHookPrx>& forwardingRedirectingHooks);
+
+    const std::vector<ReceivedConnectedLinePartyIdHookPrx>& getReceivedConnectedLinePartyIdHooks();
+    const std::vector<ForwardingConnectedLinePartyIdHookPrx>& getForwardingConnectedLinePartyIdHooks();
+    const std::vector<ForwardingRedirectingPartyIdHookPrx>& getForwardingRedirectingPartyIdHooks();
+
+private:
+    std::vector<ReceivedConnectedLinePartyIdHookPrx> mReceiveConnectedLineHooks;
+    std::vector<ForwardingConnectedLinePartyIdHookPrx> mForwardingConnectedLineHooks;
+    std::vector<ForwardingRedirectingPartyIdHookPrx> mForwardingRedirectingHooks;
+};
+
+BridgePartyIdHooksImpl::BridgePartyIdHooksImpl(const std::vector<ReceivedConnectedLinePartyIdHookPrx>& receiveConnectedLineHooks,
+    const std::vector<ForwardingConnectedLinePartyIdHookPrx>& forwardingConnectedLineHooks,
+    const std::vector<ForwardingRedirectingPartyIdHookPrx>& forwardingRedirectingHooks) 
+    : mReceiveConnectedLineHooks(receiveConnectedLineHooks),
+      mForwardingConnectedLineHooks(forwardingConnectedLineHooks),
+      mForwardingRedirectingHooks(forwardingRedirectingHooks)
+{
+}
+
+const std::vector<ReceivedConnectedLinePartyIdHookPrx>& 
+    BridgePartyIdHooksImpl::getReceivedConnectedLinePartyIdHooks()
+{
+    return mReceiveConnectedLineHooks;
+}
+
+const std::vector<ForwardingConnectedLinePartyIdHookPrx>&
+    BridgePartyIdHooksImpl::getForwardingConnectedLinePartyIdHooks()
+{
+    return mForwardingConnectedLineHooks;
+}
+
+const std::vector<ForwardingRedirectingPartyIdHookPrx>&
+    BridgePartyIdHooksImpl::getForwardingRedirectingPartyIdHooks()
+{
+    return mForwardingRedirectingHooks;
+}
+
+class BridgePartyIdExtensionPointImpl : 
+    public AsteriskSCF::BridgeService::BridgePartyIdExtensionPoint
+{
+public:
+    BridgePartyIdExtensionPointImpl(const Ice::ObjectAdapterPtr& adapter,
+        const AsteriskSCF::System::Logging::Logger& logger);
+
+    // PartyIdentificationExtensionPoint API implementation
+    void addReceivedConnectedLinePartyIdHook(
+        const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ReceivedConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current);
+    void addForwardingConnectedLinePartyIdHook(
+        const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current);
+    void addForwardingRedirectingPartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingRedirectingPartyIdHookPrx& hook,
+        const Ice::Current& current);
+
+    void removeReceivedConnectedLinePartyIdHook(
+        const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ReceivedConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current);
+    void removeForwardingConnectedLinePartyIdHook(
+        const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current);
+    void removeForwardingRedirectingPartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingRedirectingPartyIdHookPrx& hook,
+        const Ice::Current& current);
+
+    void clearPartyIdentificationHooks(const Ice::Current& current);
+
+    virtual BridgePartyIdHooksPtr getHooks();
+
+private:
+    AsteriskSCF::Collections::ProxySet<ReceivedConnectedLinePartyIdHookPrx>::SetPtr mReceiveConnectedLineHooks;
+    AsteriskSCF::Collections::ProxySet<ForwardingConnectedLinePartyIdHookPrx>::SetPtr mForwardingConnectedLineHooks;
+    AsteriskSCF::Collections::ProxySet<ForwardingRedirectingPartyIdHookPrx>::SetPtr mForwardingRedirectingHooks;
+
+    Logger mLogger;
+};
+
+} // end anon namespace
+
+BridgePartyIdExtensionPointImpl::BridgePartyIdExtensionPointImpl(
+    const Ice::ObjectAdapterPtr& adapter,
+    const AsteriskSCF::System::Logging::Logger& logger) 
+      : mLogger(logger)
+    
+{
+}
+
+// PartyIdentificationExtensionPoint API implementation
+void BridgePartyIdExtensionPointImpl::addReceivedConnectedLinePartyIdHook(
+    const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ReceivedConnectedLinePartyIdHookPrx& hook,
+    const Ice::Current& current)
+{
+    mReceiveConnectedLineHooks->add(hook);
+}
+
+void BridgePartyIdExtensionPointImpl::addForwardingConnectedLinePartyIdHook(
+    const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingConnectedLinePartyIdHookPrx& hook,
+    const Ice::Current& current)
+{
+    mForwardingConnectedLineHooks->add(hook);
+}
+
+void BridgePartyIdExtensionPointImpl::addForwardingRedirectingPartyIdHook(
+    const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingRedirectingPartyIdHookPrx& hook,
+    const Ice::Current& current)
+{
+    mForwardingRedirectingHooks->add(hook);
+}
+
+void BridgePartyIdExtensionPointImpl::removeReceivedConnectedLinePartyIdHook(
+    const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ReceivedConnectedLinePartyIdHookPrx& hook,
+    const Ice::Current& current)
+{
+    mReceiveConnectedLineHooks->remove(hook);
+}
+
+void BridgePartyIdExtensionPointImpl::removeForwardingConnectedLinePartyIdHook(
+    const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingConnectedLinePartyIdHookPrx& hook,
+    const Ice::Current& current)
+{
+    mForwardingConnectedLineHooks->remove(hook);
+}
+
+void BridgePartyIdExtensionPointImpl::removeForwardingRedirectingPartyIdHook(
+    const ::AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingRedirectingPartyIdHookPrx& hook,
+    const Ice::Current& current)
+{
+    mForwardingRedirectingHooks->remove(hook);
+}
+
+void BridgePartyIdExtensionPointImpl::clearPartyIdentificationHooks(const Ice::Current& current)
+{
+    mReceiveConnectedLineHooks->clear();
+    mForwardingConnectedLineHooks->clear();
+    mForwardingRedirectingHooks->clear();
+}
+
+BridgePartyIdHooksPtr BridgePartyIdExtensionPointImpl::getHooks()
+{
+    return new BridgePartyIdHooksImpl(mReceiveConnectedLineHooks->getAll(),
+                                      mForwardingConnectedLineHooks->getAll(),
+                                      mForwardingRedirectingHooks->getAll());
+}
+
+AsteriskSCF::BridgeService::BridgePartyIdExtensionPointPtr 
+    AsteriskSCF::BridgeService::createPartyIdExtensionPoint(const Ice::ObjectAdapterPtr& adapter,
+        const AsteriskSCF::System::Logging::Logger& logger)
+{
+    return new BridgePartyIdExtensionPointImpl(adapter, logger);
+}
diff --git a/src/BridgePartyIdExtensionPoint.h b/src/BridgePartyIdExtensionPoint.h
new file mode 100644
index 0000000..376e0a8
--- /dev/null
+++ b/src/BridgePartyIdExtensionPoint.h
@@ -0,0 +1,111 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, 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/SessionCommunicationsExtensionPointsIf.h>
+#include <AsteriskSCF/logger.h>
+
+namespace AsteriskSCF
+{
+namespace BridgeService
+{
+
+/** 
+ * This class is used to hold a snapshot of the party id hooks
+ * at the time of bridge creation. The hook proxies are internally thread safe. 
+ * We provide each bridge its own copy of the hooks to alleviate
+ * contention for a lock that would be required if each bridge was 
+ * trying to fetch the hooks directly from the BridgePartyIdExtensionPoint (which
+ * has the primary cache of party id hooks). 
+ */
+class BridgePartyIdHooks : public IceUtil::Shared
+{
+public:
+    virtual ~BridgePartyIdHooks() {}
+
+    /**
+     * Get the received ConnectedLine party id hooks.
+     */
+    virtual const std::vector<AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ReceivedConnectedLinePartyIdHookPrx>& 
+        getReceivedConnectedLinePartyIdHooks() = 0;
+
+    /**
+     * Get the forwarding ConnectedLine Party Id hooks. 
+     */
+    virtual const std::vector<AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingConnectedLinePartyIdHookPrx>& 
+        getForwardingConnectedLinePartyIdHooks() = 0;
+
+    /**
+     * Get the forwarding Redirecting Party Id hooks. 
+     */
+    virtual const std::vector<AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingRedirectingPartyIdHookPrx>& 
+        getForwardingRedirectingPartyIdHooks() = 0;
+};
+
+typedef IceUtil::Handle<BridgePartyIdHooks> BridgePartyIdHooksPtr;
+
+/**
+ * This is our servant for the PartyIdentificationExtensionPoint. It caches the
+ * hooks that are added. 
+ */
+class BridgePartyIdExtensionPoint : 
+    public AsteriskSCF::SessionCommunications::ExtensionPoints::V1::PartyIdentificationExtensionPoint
+{
+public:
+    virtual ~BridgePartyIdExtensionPoint() {}
+
+    // PartyIdentificationExtensionPoint API implementation
+
+    virtual void addReceivedConnectedLinePartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ReceivedConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current) = 0;
+    virtual void addForwardingConnectedLinePartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current) = 0;
+    virtual void addForwardingRedirectingPartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingRedirectingPartyIdHookPrx& hook,
+        const Ice::Current& current) = 0;
+
+    virtual void removeReceivedConnectedLinePartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ReceivedConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current) = 0;
+    virtual void removeForwardingConnectedLinePartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingConnectedLinePartyIdHookPrx& hook,
+        const Ice::Current& current) = 0;
+    virtual void removeForwardingRedirectingPartyIdHook(
+        const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::ForwardingRedirectingPartyIdHookPrx& hook,
+        const Ice::Current& current) = 0;
+
+    virtual void clearPartyIdentificationHooks(const Ice::Current& current) = 0;
+
+    // Implementation
+
+    /** 
+     * This method provides a BridgePartyIdHooks object
+     * which contains a copy of the hooks as they exist 
+     * at the time this operation is called. 
+     */
+    virtual BridgePartyIdHooksPtr getHooks() = 0;
+};
+
+typedef IceUtil::Handle<BridgePartyIdExtensionPoint> BridgePartyIdExtensionPointPtr;
+
+
+BridgePartyIdExtensionPointPtr createPartyIdExtensionPoint(const Ice::ObjectAdapterPtr& adapter,
+        const AsteriskSCF::System::Logging::Logger& logger);
+
+} // End of namespace Bridging.
+} // End of namespace AsteriskSCF.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c7fbc72..82839c2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,6 +22,8 @@ astscf_component_add_files(bridgeservice SessionCollection.cpp)
 astscf_component_add_files(bridgeservice SessionCollection.h)
 astscf_component_add_files(bridgeservice SessionOperations.cpp)
 astscf_component_add_files(bridgeservice SessionOperations.h)
+astscf_component_add_files(bridgeservice BridgePartyIdExtensionPoint.cpp)
+astscf_component_add_files(bridgeservice BridgePartyIdExtensionPoint.h)
 astscf_component_add_files(bridgeservice ServiceUtil.h)
 astscf_component_add_files(bridgeservice DebugUtil.h)
 astscf_component_add_files(bridgeservice MediaSplicer.h)
diff --git a/src/Component.cpp b/src/Component.cpp
index 03b6484..6e42dae 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -29,9 +29,11 @@
 #include "BridgeManagerImpl.h"
 #include "BridgeReplicatorStateListenerI.h"
 #include "BridgeReplicationContext.h"
+#include "BridgePartyIdExtensionPoint.h"
 
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::ExtensionPoints::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::System::Component::V1;
 using namespace AsteriskSCF::BridgeService;
@@ -75,10 +77,13 @@ private:
     // Other base Component overrides
     virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
 
+    BridgePartyIdExtensionPointPtr mPartyIdExtensionPoint;
+    PartyIdentificationExtensionPointPrx mPartyIdExtensionPointPrx;
     ReplicatorSmartPrx mReplicator;
     BridgeManagerServantPtr mBridgeManager;
     BridgeManagerPrx mBridgeManagerPrx;
     LocatorRegistrationWrapperPtr mBridgeManagerRegistration;
+    LocatorRegistrationWrapperPtr mPartyIdExtensionRegistration;
     RegisterThreadPtr mRegisterThread;
     ReplicatorListenerPrx mReplicatorListenerPrx;
     bool mListeningToReplicator;
@@ -120,13 +125,19 @@ void Component::createPrimaryServices()
 {
      std::string managerName = 
         getCommunicator()->getProperties()->getPropertyWithDefault(getName() + ".ManagerId", "BridgeManager");
-
     //
     // It's very important that uncheckedCast's be used here as there are no guarantees
     // that the object adapter is activated yet. If it is not, then this can hang.
     //
+
+    std::string extensionPointName = 
+        getCommunicator()->getProperties()->getPropertyWithDefault(getName() + ".PartyIdentExtensionPoint", "BridgePartyIdExtensionPoint");
+    mPartyIdExtensionPoint = createPartyIdExtensionPoint(getServiceAdapter(), lg);
+    mPartyIdExtensionPointPrx = PartyIdentificationExtensionPointPrx::uncheckedCast(getServiceAdapter()->add(mPartyIdExtensionPoint,
+        getCommunicator()->stringToIdentity(extensionPointName)));
+
     BridgeReplicationContextPtr replicationContext = boost::static_pointer_cast<BridgeReplicationContext>(getReplicationContext());
-    mBridgeManager = createBridgeManager(getServiceAdapter(), managerName, replicationContext, lg);
+    mBridgeManager = createBridgeManager(getServiceAdapter(), managerName, mPartyIdExtensionPoint, replicationContext, lg);
     mBridgeManagerPrx = BridgeManagerPrx::uncheckedCast(getServiceAdapter()->add(mBridgeManager, 
           getCommunicator()->stringToIdentity(managerName)));
     assert(mBridgeManagerPrx != 0);
@@ -134,6 +145,7 @@ void Component::createPrimaryServices()
     {
         throw IceBox::FailureException(__FILE__, __LINE__, "Unable to instantiate bridge manager object");
     }
+
 }
 
 /**
@@ -146,6 +158,11 @@ void Component::preparePrimaryServicesForDiscovery()
         mBridgeManagerRegistration = this->wrapServiceForRegistration(mBridgeManagerPrx,
                                                                       BridgeManagerDiscoveryCategory);
         managePrimaryService(mBridgeManagerRegistration);
+
+        mPartyIdExtensionRegistration = this->wrapServiceForRegistration(mPartyIdExtensionPointPrx,
+                                                                         PartyIdentificationHookLocatorCategory);
+        managePrimaryService(mPartyIdExtensionRegistration);
+                                                                         
     }
     catch (const Ice::Exception& e)
     {
diff --git a/src/SessionWrapper.cpp b/src/SessionWrapper.cpp
index 1178f5e..b625441 100644
--- a/src/SessionWrapper.cpp
+++ b/src/SessionWrapper.cpp
@@ -22,6 +22,7 @@
 
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::PartyIdentification::V1;
 using namespace AsteriskSCF::BridgeService;
 using namespace AsteriskSCF::Replication::BridgeService::V1;
 using namespace AsteriskSCF;
@@ -391,7 +392,8 @@ SessionWrapper::SessionWrapper(const BridgedSessionPtr& session,
     mLogger(logger),
     mId(mSession->key),
     mSplicer(splicer),
-    mActivities(new Executor(mLogger))
+    mActivities(new Executor(mLogger)),
+    mConnectedLineSet(false)
 {
 }
 
@@ -614,6 +616,32 @@ void SessionWrapper::shutdown(const SessionListenerPrx& listener, const Response
     // shutdownRunner->start();
 }
 
+/**
+ * Set the connected line information associcated with this session.
+ */
+void SessionWrapper::setConnectedLine(const ConnectedLinePtr& connectedLine)
+{
+    boost::unique_lock<boost::shared_mutex> lock(mLock);
+    mConnectedLine = connectedLine;
+    mConnectedLineSet = true;
+}
+    
+/**
+ * Get the connected line information that's been cached for this session. 
+ */
+bool SessionWrapper::getConnectedLine(ConnectedLinePtr& connectedLine)
+{
+    boost::unique_lock<boost::shared_mutex> lock(mLock);
+    if (!mConnectedLineSet)
+    {
+        return false;
+    }
+
+    connectedLine = mConnectedLine;
+    return true;
+}
+
+
 AsteriskSCF::Replication::BridgeService::V1::BridgedSessionState SessionWrapper::setState(const AsteriskSCF::Replication::BridgeService::V1::BridgedSessionState newState)
 {
     mLogger(Debug) << FUNLOG << ": updating state " << mId;
diff --git a/src/SessionWrapper.h b/src/SessionWrapper.h
index 0bdef83..6fc3f43 100644
--- a/src/SessionWrapper.h
+++ b/src/SessionWrapper.h
@@ -145,6 +145,19 @@ public:
      * Disconnection helper.
      **/
     void unplugMedia();
+
+    /**
+     * Set the connected line information associcated with this session.
+     * This is information received from the session. 
+     */
+    void setConnectedLine(const AsteriskSCF::SessionCommunications::PartyIdentification::V1::ConnectedLinePtr& connectedLine);
+
+    /**
+     * Gets a reference to the cached Connected Line party identification information if it's available. 
+     * @param connectedLine A reference to set the cached Connected Line record (if available). 
+     * @return true if the connectedLine parameter was set. 
+     */
+    bool getConnectedLine(AsteriskSCF::SessionCommunications::PartyIdentification::V1::ConnectedLinePtr& connectedLine);
     
 private:
 
@@ -157,6 +170,9 @@ private:
     MediaSplicerPtr mSplicer;
     ExecutorPtr mActivities;
     AsteriskSCF::SessionCommunications::V1::SessionControllerPrx mSessionController;
+    AsteriskSCF::SessionCommunications::PartyIdentification::V1::ConnectedLinePtr mConnectedLine;
+    bool mConnectedLineSet;
+   
 
     /**
      * Sends changes to the replication service. This should never occur

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list