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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Oct 19 11:56:23 CDT 2010


branch "master" has been updated
       via  82e773dc173a1c02c09092874f24e78ec5c222da (commit)
      from  18c4b0dbd24edb50a5b5903a22396c8fc043ba22 (commit)

Summary of changes:
 src/PJSipSessionModule.cpp |    6 +++---
 src/SipSession.cpp         |   17 ++++++++++++++++-
 src/SipSession.h           |    2 +-
 3 files changed, 20 insertions(+), 5 deletions(-)


- Log -----------------------------------------------------------------
commit 82e773dc173a1c02c09092874f24e78ec5c222da
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Oct 19 09:55:18 2010 -0700

    Add locking to protect the listeners and bridge. After auditing these appear to be the only two items that need it.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 705f9a7..2a51d0a 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -628,7 +628,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
    else if (respCode == 180)
    {
       lg(Debug) << "Got 180 response";
-      std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners = session->getListeners();
+      std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
       std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
 	  lg(Debug) << "Relating ringing state to " << listeners.size() << " listeners";
       for (listener = listeners.begin(); listener != listeners.end(); ++listener)
@@ -648,7 +648,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
       lg(Debug) << "Got 183 response";
       AsteriskSCF::SessionCommunications::V1::ResponseCodePtr response = new AsteriskSCF::SessionCommunications::V1::ResponseCode();
       response->isdnCode = 42;
-      std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners = session->getListeners();
+      std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
       std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
 	  lg(Debug) << "Relating progressing state to " << listeners.size() << " listeners";
       for (listener = listeners.begin(); listener != listeners.end(); ++listener)
@@ -668,7 +668,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
       lg(Debug) << "Got 200 response";
       if (inv->state != PJSIP_INV_STATE_DISCONNECTED)
       {
-         std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners = session->getListeners();
+         std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
          std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
 		 lg(Debug) << "Relating connected state to " << listeners.size() << " listeners";
          for (listener = listeners.begin(); listener != listeners.end(); ++listener)
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index ac0d150..0cc67e4 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -9,6 +9,9 @@
 #include <Ice/Ice.h>
 #include <IceUtil/UUID.h>
 
+#include <boost/thread.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
 #include "PJSipManager.h"
 #include "SipEndpointFactory.h"
 #include "SipEndpoint.h"
@@ -148,6 +151,11 @@ SipSessionPriv(Ice::ObjectAdapterPtr adapter, SipEndpointPtr endpoint,
    AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
 
    AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+
+   /**
+    * Shared mutex lock which protects some of the session.
+    */
+   boost::shared_mutex mLock;
 };
 
 /**
@@ -198,6 +206,7 @@ SipSession::SipSession(Ice::ObjectAdapterPtr adapter, SipEndpointPtr endpoint, c
 
 AsteriskSCF::SessionCommunications::V1::SessionInfoPtr SipSession::addListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current& current)
 {
+   boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
    mImplPriv->mListeners.push_back(listener);
    if (mImplPriv->mInviteSession)
    {
@@ -293,6 +302,8 @@ AsteriskSCF::Media::V1::SessionPrx SipSession::getMediaSession(const Ice::Curren
  */
 AsteriskSCF::SessionCommunications::V1::BridgePrx SipSession::getBridge(const Ice::Current&)
 {
+   boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
    if (mImplPriv->mBridge == 0)
    {
       throw new AsteriskSCF::SessionCommunications::V1::NotBridged();
@@ -318,6 +329,7 @@ AsteriskSCF::SessionCommunications::V1::SessionInfoPtr SipSession::setBridge(con
  */
 void SipSession::setBridge(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge)
 {
+   boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
    mImplPriv->mBridge = bridge;
 }
 
@@ -372,6 +384,7 @@ void SipSession::progress(const AsteriskSCF::SessionCommunications::V1::Response
  */
 void SipSession::removeListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current&)
 {
+   boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
    mImplPriv->mListeners.erase(std::remove(mImplPriv->mListeners.begin(), mImplPriv->mListeners.end(), listener), mImplPriv->mListeners.end());
    if (mImplPriv->mInviteSession)
    {
@@ -682,8 +695,9 @@ AsteriskSCF::Media::V1::StreamSinkSeq& SipSession::getSinks()
 /**
  * Internal function which gets the listeners on this session.
  */
-std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& SipSession::getListeners()
+std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> SipSession::getListeners()
 {
+   boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
    return mImplPriv->mListeners;
 }
 
@@ -716,6 +730,7 @@ AsteriskSCF::Media::V1::SessionPrx& SipSession::getMediaSessionProxy()
  */
 void SipSession::setListeners(const AsteriskSCF::SIP::V1::SessionListenerSeq& listeners)
 {
+   boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
    mImplPriv->mListeners = listeners;
 }
 
diff --git a/src/SipSession.h b/src/SipSession.h
index 5743278..d14b0dd 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -106,7 +106,7 @@ public:
 
    AsteriskSCF::Media::V1::StreamSinkSeq& getSinks();
 
-   std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& getListeners();
+   std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> getListeners();
 
    SipEndpointPtr getEndpoint();
 

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list