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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Aug 10 19:16:34 CDT 2011


branch "master" has been updated
       via  b40da7f6b1d4a5dd3b7375b6c04ec3280ff83e92 (commit)
      from  8067347207ab8b70244c586ffc07ab0559122399 (commit)

Summary of changes:
 .../SipSessionManager/SipStateReplicationIf.ice    |   13 ++
 src/SipEndpoint.cpp                                |  145 ++++++++++++++++++--
 src/SipEndpoint.h                                  |   18 +++
 src/SipSession.cpp                                 |   24 +++-
 src/SipSession.h                                   |    4 +-
 src/SipStateReplicatorListener.cpp                 |   53 +++++++
 6 files changed, 240 insertions(+), 17 deletions(-)


- Log -----------------------------------------------------------------
commit b40da7f6b1d4a5dd3b7375b6c04ec3280ff83e92
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Wed Aug 10 19:16:29 2011 -0500

    Support for default session listeners and default cookies.

diff --git a/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice b/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice
index 655d213..b6fabde 100644
--- a/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice
+++ b/slice/AsteriskSCF/Replication/SipSessionManager/SipStateReplicationIf.ice
@@ -160,6 +160,19 @@ module V1
       AsteriskSCF::SessionCommunications::V1::SessionCookieDict cookies;
    };
 
+
+   class DefaultSessionListenerItem extends SipStateItem
+   {
+      string endpointName;
+      AsteriskSCF::SessionCommunications::V1::SessionListener* listener;
+   };
+
+   class DefaultSessionCookieItem extends SipStateItem
+   {
+      string endpointName;
+      AsteriskSCF::SessionCommunications::V1::SessionCookie cookie;
+   };
+
    class SipRegistrarStateItem extends SipStateItem
    {
       /**
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 52912e2..2be7517 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -21,15 +21,20 @@
 
 #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
 #include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Collections/Set.h>
 #include <AsteriskSCF/Media/MediaIf.h>
 #include <AsteriskSCF/Media/SDP/MediaSDPIf.h>
 
 #include "NATOptions.h"
 
+using namespace std;
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::Media::SDP::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::Replication::SipSessionManager::V1;
+using namespace AsteriskSCF::Discovery;
 
 namespace
 {
@@ -41,6 +46,12 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
+string cookieKey(string &endpointName, const SessionCookiePtr& cookie)
+{
+    string key = endpointName + "::" + cookie->ice_id();
+    return key;
+}
+
 /**
  * Class used to store information about the configured formats.
  */
@@ -174,6 +185,12 @@ public:
     {
     };
     
+    string replicaKeyName(SessionListenerPrx listener)
+    {
+        std::string key = mName + "::" + mAdapter->getCommunicator()->identityToString(listener->ice_getIdentity());
+        return key;
+    }
+     
     /**
      * The name of the endpoint.
      */
@@ -214,15 +231,10 @@ public:
      */
     PJSipManagerPtr mManager;
 
-    /**
-     *
-     */
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
-
-    /**
-     *
-     */
     SipReplicationContextPtr mReplicationContext;
+    AsteriskSCF::Collections::ProxySet<SessionListenerPrx>::SetPtr mDefaultListeners;
+    AsteriskSCF::Collections::HandleSet<SessionCookiePtr>::SetPtr mDefaultSessionCookies;
 };
 
 SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, 
@@ -376,7 +388,16 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(co
         return 0;
     }
 
-    SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, listener, mImplPriv->mManager,
+    // Combine the default listeners and the argument listener.
+    vector<SessionListenerPrx> listeners = mImplPriv->mDefaultListeners->getAll();
+    if (listener != 0)
+    {
+        listeners.push_back(listener);
+    }
+
+    SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
+
+    SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, listeners, defaultCookies, mImplPriv->mManager,
         mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, 
 	true, mImplPriv->mConfig, NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
         mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
@@ -389,7 +410,10 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(co
 
 AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination)
 {
-    SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, 0, mImplPriv->mManager,
+    vector<SessionListenerPrx> defaultListeners = mImplPriv->mDefaultListeners->getAll();
+    SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
+
+    SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, defaultListeners, defaultCookies, mImplPriv->mManager,
         mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false, 
 	mImplPriv->mConfig, 
 	NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
@@ -401,6 +425,11 @@ AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const s
     return session;
 }
 
+/**
+ * This factory method is only used to create replica sessions for a component in standby mode.
+ * Note: Default session cookies and listeners are part of the replicated state, so none are added
+ * here. 
+ */
 AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination,
                                                                          const Ice::Identity& sessionid, const Ice::Identity& controllerid,
                                                                          const Ice::Identity& mediaid,
@@ -451,6 +480,104 @@ AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx SipEndpoint::getEndpo
     return mImplPriv->mEndpointProxy;
 }
 
+void SipEndpoint::addDefaultSessionListener(const SessionListenerPrx& listener, const Ice::Current& current)
+{
+    mImplPriv->mDefaultListeners->add(listener);
+
+    if (mImplPriv->mReplicationContext->isReplicating() == false)
+    {
+        return;
+    }
+
+    // Replicate this change.
+    SipStateItemSeq items;
+    items.push_back(new DefaultSessionListenerItem
+            (mImplPriv->replicaKeyName(listener), 
+            "", 
+             mImplPriv->mName, 
+            listener));
+
+    mImplPriv->mReplicationContext->getReplicator().tryOneWay()->setState(items);
+}
+
+void SipEndpoint::removeDefaultSessionListener(const SessionListenerPrx& listener, const Ice::Current&)
+{
+    mImplPriv->mDefaultListeners->remove(listener);
+
+    if (mImplPriv->mReplicationContext->isReplicating() == false)
+    {
+        return;
+    }
+
+    // Replicate this change. 
+    SipStateItemSeq items;
+    items.push_back(new DefaultSessionListenerItem
+            (mImplPriv->replicaKeyName(listener), 
+            "", 
+                mImplPriv->mName, 
+            listener));
+
+    mImplPriv->mReplicationContext->getReplicator().tryOneWay()->removeStateForItems(items);
+}
+
+void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+{
+    mImplPriv->mDefaultSessionCookies->add(cookies);
+
+    if (mImplPriv->mReplicationContext->isReplicating() == false)
+    {
+        return;
+    }
+
+    // Replicate this change. 
+    SipStateItemSeq items;
+    for(SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
+    {
+        items.push_back(new DefaultSessionCookieItem(cookieKey(mImplPriv->mName,  *i),
+                "", 
+                    mImplPriv->mName, 
+                (*i)));
+    }
+
+    mImplPriv->mReplicationContext->getReplicator().tryOneWay()->setState(items);
+}
+
+void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+{
+    mImplPriv->mDefaultSessionCookies->remove(cookies);
+
+    if (mImplPriv->mReplicationContext->isReplicating() == false)
+    {
+        return;
+    }
+
+    // Replicate this change. 
+    SipStateItemSeq items;
+    for(SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
+    {
+        items.push_back(new DefaultSessionCookieItem(cookieKey(mImplPriv->mName,  *i),
+                "", 
+                    mImplPriv->mName, 
+                (*i)));
+    }
+
+    mImplPriv->mReplicationContext->getReplicator().tryOneWay()->removeStateForItems(items);
+}
+
+void SipEndpoint::addDefaultSessionCookie(const SessionCookiePtr& cookie)
+{
+    SessionCookies cookies;
+    cookies.push_back(cookie);
+    addDefaultSessionCookies(cookies);
+}
+
+void SipEndpoint::removeDefaultSessionCookie(const SessionCookiePtr& cookie)
+{
+    SessionCookies cookies;
+    cookies.push_back(cookie);
+    removeDefaultSessionCookies(cookies);
+}
+
 SDPDescriptorServicePrx SipEndpoint::getDescriptorService(const SDPDescriptorPtr& descriptor)
 {
     for (std::vector<ConfiguredFormatPtr>::const_iterator configuredFormat = mImplPriv->mFormats.begin();
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index 89c166b..3480fba 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -283,6 +283,18 @@ public:
     AsteriskSCF::SessionCommunications::V1::SessionPrx createSession(const std::string&,
             const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, const Ice::Current&);
     AsteriskSCF::SessionCommunications::V1::SessionSeq getSessions(const Ice::Current&);
+    void addDefaultSessionListener(
+        const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, 
+        const Ice::Current& = Ice::Current());
+    void removeDefaultSessionListener(
+        const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
+         const Ice::Current& = Ice::Current());
+     void addDefaultSessionCookies(
+         const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies,
+         const Ice::Current& = Ice::Current());
+     void removeDefaultSessionCookies(
+         const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies,
+         const Ice::Current& = Ice::Current());
 
     /**
      * Implementation specific.
@@ -340,6 +352,12 @@ public:
     AsteriskSCF::Media::V1::StreamInformationDict getStreamTopology();
     void setDTMFMethod(AsteriskSCF::Configuration::SipSessionManager::V1::SipDTMFOption dtmf);
 
+    void addDefaultSessionCookie(
+        const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr& cookie);
+
+    void removeDefaultSessionCookie(
+        const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr& cookie);
+
 private:
     /**
      * Private implementation details.
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 3592529..0279d67 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -39,6 +39,7 @@
 
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::System::NAT::V1;
+using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Media::RTP::V1;
 using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::Media;
@@ -776,18 +777,27 @@ void SipSession::setTelephonyEventSourcesAndSinks(const SipEndpointConfig& confi
 }
 
 /**
- * Default constructor.
+ * Standard constructor for use by an active component.
  */
-SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
-        const std::string& destination, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
-        const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const SipReplicationContextPtr& replicationContext, bool /* ipv6 */, bool isUAC, const SipEndpointConfig &config,
+SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, 
+        const SipEndpointPtr& endpoint,
+        const std::string& destination, 
+        const vector<SessionListenerPrx>& listeners,
+        const SessionCookies& cookies,
+        const PJSipManagerPtr& manager, 
+        const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+        const SipReplicationContextPtr& replicationContext, 
+        bool /* ipv6 */, 
+        bool isUAC, 
+        const SipEndpointConfig &config,
         const NATEndpointOptions& natOptions)
     : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext, natOptions))
 {
-    if (listener != 0)
+    mImplPriv->mListeners.insert(mImplPriv->mListeners.end(), listeners.begin(), listeners.end());
+
+    for(SessionCookies::const_iterator i = cookies.begin(); i != cookies.end(); ++i)
     {
-        mImplPriv->mListeners.push_back(listener);
+        mImplPriv->mSessionCookies[(*i)->ice_id()] = (*i);
     }
 
     activateIceObjects(mImplPriv->mManager->getSessionModule()->getSessionCreationHooks());
diff --git a/src/SipSession.h b/src/SipSession.h
index 744b9ed..e3ebff1 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -111,7 +111,9 @@ class SipSession : public AsteriskSCF::SessionCommunications::V1::TelephonySessi
 {
 public:
     SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&,
-        const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, const PJSipManagerPtr& manager,
+        const std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>&,         
+        const AsteriskSCF::SessionCommunications::V1::SessionCookies&, 
+        const PJSipManagerPtr& manager,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
         const SipReplicationContextPtr& replicationContext,
         bool ipv6, bool isUAC, const SipEndpointConfig& config, const NATEndpointOptions& natOptions);
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index d9159fb..1b57ef1 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -137,6 +137,9 @@ public:
         for (SipStateItemSeq::const_iterator iter = items.begin(); iter != items.end(); ++iter)
         {
             SipRegistrarStateItemPtr regItem;
+            DefaultSessionListenerItemPtr defaultListenerItem;
+            DefaultSessionCookieItemPtr defaultCookieItem;
+
             if ((regItem = SipRegistrarStateItemPtr::dynamicCast((*iter))))
             {
                 PJSipRegistrarModulePtr regModule;
@@ -149,6 +152,30 @@ public:
                 }
                 removeRegistrationState(regModule, regItem);
             }
+            else if(defaultListenerItem = DefaultSessionListenerItemPtr::dynamicCast((*iter)))
+            {
+                SipEndpointPtr endpoint = mEndpointFactory->findByName(defaultListenerItem->endpointName);
+
+                // If we lack the endpoint (due to misconfiguration) we can't procceed
+                if (endpoint == 0)
+                {
+                    continue;
+                }
+
+                endpoint->removeDefaultSessionListener(defaultListenerItem->listener);
+            }
+            else if(defaultCookieItem = DefaultSessionCookieItemPtr::dynamicCast((*iter)))
+            {
+                SipEndpointPtr endpoint = mEndpointFactory->findByName(defaultCookieItem->endpointName);
+
+                // If we lack the endpoint (due to misconfiguration) we can't procceed
+                if (endpoint == 0)
+                {
+                    continue;
+                }
+
+                endpoint->removeDefaultSessionCookie(defaultCookieItem->cookie);
+            }
         }
     }
 
@@ -239,6 +266,8 @@ public:
             SipTransactionStateItemPtr transaction;
             SipRegistrarStateItemPtr regItem;
             boost::shared_ptr<SipStateReplicatorItem> localitem;
+            DefaultSessionListenerItemPtr defaultListenerItem;
+            DefaultSessionCookieItemPtr defaultCookieItem;
 
             // Depending on the type of state item we apply it differently
             if ((session = SipSessionStateItemPtr::dynamicCast((*item))))
@@ -432,6 +461,30 @@ public:
                 }
                 setRegistrationState(regModule, regItem);
             }
+            else if (defaultListenerItem  = DefaultSessionListenerItemPtr::dynamicCast((*item)))
+            {
+                SipEndpointPtr endpoint = mEndpointFactory->findByName(defaultListenerItem->endpointName);
+
+                // If we lack the endpoint (due to misconfiguration) we can't procceed
+                if (endpoint == 0)
+                {
+                    continue;
+                }
+
+                endpoint->addDefaultSessionListener(defaultListenerItem->listener);
+            }
+            else if (defaultCookieItem  = DefaultSessionCookieItemPtr::dynamicCast((*item)))
+            {
+                SipEndpointPtr endpoint = mEndpointFactory->findByName(defaultCookieItem->endpointName);
+
+                // If we lack the endpoint (due to misconfiguration) we can't procceed
+                if (endpoint == 0)
+                {
+                    continue;
+                }
+
+                endpoint->addDefaultSessionCookie(defaultCookieItem->cookie);
+            }
         }
     }
     std::string mId;

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


-- 
asterisk-scf/release/sip.git



More information about the asterisk-scf-commits mailing list