[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "mediasessioncookies" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Sun Aug 28 20:08:29 CDT 2011


branch "mediasessioncookies" has been created
        at  26b7c71907502838f937bed4673cf1f84f18e496 (commit)

- Log -----------------------------------------------------------------
commit 26b7c71907502838f937bed4673cf1f84f18e496
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Sun Aug 28 20:04:39 2011 -0500

    Changes related to Media Session cookie support.
    - The SessionCookies types need to be namespaced qualified in lots of places
    - SipMediaSession supports cookies now, even though it is probably not long for this world.
    - The regular Session getCookies needed to be AMD'ified so that it could be enqueued. It wasn't thread safe.

diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index f88691b..37cba14 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -47,7 +47,7 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-string cookieKey(string &endpointName, const SessionCookiePtr& cookie)
+string cookieKey(string &endpointName, const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr& cookie)
 {
     string key = endpointName + "::" + cookie->ice_id();
     return key;
@@ -184,7 +184,7 @@ public:
         mName(name), mAdapter(adapter), mEndpointFactory(factory), mManager(manager), mServiceLocator(serviceLocator),
         mReplicationContext(replicationContext),
         mDefaultListeners(new AsteriskSCF::Collections::ProxySet<SessionListenerPrx>(adapter, lg, "Default Session Listeners")),
-        mDefaultSessionCookies(new AsteriskSCF::Collections::HandleSet<SessionCookiePtr>(lg, "Default Cookies"))
+        mDefaultSessionCookies(new AsteriskSCF::Collections::HandleSet<AsteriskSCF::SessionCommunications::V1::SessionCookiePtr>(lg, "Default Cookies"))
     {
     };
     
@@ -237,7 +237,7 @@ public:
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
     SipReplicationContextPtr mReplicationContext;
     AsteriskSCF::Collections::ProxySet<SessionListenerPrx>::SetPtr mDefaultListeners;
-    AsteriskSCF::Collections::HandleSet<SessionCookiePtr>::SetPtr mDefaultSessionCookies;
+    AsteriskSCF::Collections::HandleSet<AsteriskSCF::SessionCommunications::V1::SessionCookiePtr>::SetPtr mDefaultSessionCookies;
 };
 
 SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, 
@@ -401,7 +401,7 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(
         listeners.push_back(listener);
     }
 
-    SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
+    AsteriskSCF::SessionCommunications::V1::SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
 
     SipSessionPtr session = new SipSession(
             mImplPriv->mAdapter,
@@ -428,7 +428,7 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(
 AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination)
 {
     vector<SessionListenerPrx> defaultListeners = mImplPriv->mDefaultListeners->getAll();
-    SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
+    AsteriskSCF::SessionCommunications::V1::SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
 
     SipSessionPtr session = new SipSession(
             mImplPriv->mAdapter,
@@ -562,7 +562,7 @@ void SipEndpoint::removeDefaultSessionListener(const SessionListenerPrx& listene
     mImplPriv->mReplicationContext->getReplicator().tryOneWay()->removeStateForItems(items);
 }
 
-void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+void SipEndpoint::addDefaultSessionCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies, const Ice::Current&)
 {
     mImplPriv->mDefaultSessionCookies->add(cookies);
 
@@ -573,7 +573,7 @@ void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, const
 
     // Replicate this change. 
     SipStateItemSeq items;
-    for(SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
+    for(AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
     {
         items.push_back(new DefaultSessionCookieItem(cookieKey(mImplPriv->mName,  *i),
                 "", 
@@ -584,7 +584,7 @@ void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, const
     mImplPriv->mReplicationContext->getReplicator().tryOneWay()->setState(items);
 }
 
-void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+void SipEndpoint::removeDefaultSessionCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies, const Ice::Current&)
 {
     mImplPriv->mDefaultSessionCookies->remove(cookies);
 
@@ -595,7 +595,7 @@ void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, con
 
     // Replicate this change. 
     SipStateItemSeq items;
-    for(SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
+    for(AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
     {
         items.push_back(new DefaultSessionCookieItem(cookieKey(mImplPriv->mName,  *i),
                 "", 
@@ -606,16 +606,16 @@ void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, con
     mImplPriv->mReplicationContext->getReplicator().tryOneWay()->removeStateForItems(items);
 }
 
-void SipEndpoint::addDefaultSessionCookie(const SessionCookiePtr& cookie)
+void SipEndpoint::addDefaultSessionCookie(const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr& cookie)
 {
-    SessionCookies cookies;
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
     cookies.push_back(cookie);
     addDefaultSessionCookies(cookies);
 }
 
-void SipEndpoint::removeDefaultSessionCookie(const SessionCookiePtr& cookie)
+void SipEndpoint::removeDefaultSessionCookie(const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr& cookie)
 {
-    SessionCookies cookies;
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
     cookies.push_back(cookie);
     removeDefaultSessionCookies(cookies);
 }
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index f550ce9..6ee1cca 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -36,6 +36,7 @@
 #include <AsteriskSCF/Media/SDP/MediaSDPIf.h>
 #include <AsteriskSCF/Media/RTP/MediaRTCPIf.h>
 #include <AsteriskSCF/SessionCookies/SipSessionManager/SipSessionCookiesIf.h>
+#include <AsteriskSCF/Collections/HandleSet.h>
 #include "NATOptions.h"
 
 using namespace AsteriskSCF::System::Logging;
@@ -59,38 +60,6 @@ namespace SipSessionManager
 
 using namespace AsteriskSCF::System::WorkQueue::V1;
 
-class SipMediaSession : public Media::V1::Session
-{
-public:
-    SipMediaSession(const SipSessionPtr& session) : mId(IceUtil::generateUUID()), mSession(session) { };
-
-    AsteriskSCF::Media::V1::StreamSourceSeq getSources(const Ice::Current&)
-    {
-        return mSession->getMediaSources();
-    }
-
-    AsteriskSCF::Media::V1::StreamSinkSeq getSinks(const Ice::Current&)
-    {
-        return mSession->getMediaSinks();
-    }
-
-    virtual std::string getId(const Ice::Current&)
-    {
-        return mId;
-    }
-
-private:
-    /**
-     * Unique identifier for the media session.
-     */
-    std::string mId;
-
-    /**
-     * A pointer to the communications session that created us.
-     */
-    SipSessionPtr mSession;
-};
-
 /**
  * Private implementation details for SipSession.
  */
@@ -337,6 +306,193 @@ public:
 
     AsteriskSCF::SessionCommunications::V1::TelephonyEventSourceSeq mExternalEventSources;
 };
+typedef boost::shared_ptr<SipSessionPriv> SipSessionPrivPtr;
+
+/**
+ * Get the specified cookies from the media sessions and pass it to 
+ * the given AMD callback handle. 
+ */
+class GetMediaSessionCookiesOperation : public SuspendableWork
+{
+public:
+    /**
+     * ctor()
+     * @param cb The AMD callback reference.
+     * @param cookieTypes The cookies to get. 
+     * @param sessionPriv The session for whom the information is requested from.
+     */
+    GetMediaSessionCookiesOperation(
+        const AsteriskSCF::Media::V1::AMD_Session_getCookiesPtr& cb,
+        const AsteriskSCF::Media::V1::SessionCookies& cookieTypes, 
+        const SipSessionPtr& session)
+         : mCb(cb), mCookieTypes(cookieTypes), mSession(session)
+    {
+    }
+
+    SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
+    {
+        lg(Debug) << "Executing a GetMediaSessionCookiesOperation operation";
+
+        AsteriskSCF::Media::V1::SessionCookies results;
+
+        // Gather the cookies from all of the Session's RTP Media Sessions. 
+        RTPMediaSessionSeq mediaSessions = mSession->getRTPMediaSessions();
+        for(RTPMediaSessionSeq::iterator i = mediaSessions.begin(); 
+            i != mediaSessions.end(); ++i)
+        {
+            AsteriskSCF::Media::V1::SessionCookies cookies = (*i)->getCookies(mCookieTypes);
+            results.insert(results.end(), cookies.begin(), cookies.end());
+        }
+
+        mCb->ice_response(results);
+
+        return Complete;
+    }
+
+private:
+    AsteriskSCF::Media::V1::AMD_Session_getCookiesPtr mCb;
+    AsteriskSCF::Media::V1::SessionCookies mCookieTypes;
+    SipSessionPtr mSession;
+};
+
+/**
+ * Set the specified cookies on the media sessions. 
+ */
+class SetMediaSessionCookiesOperation : public SuspendableWork
+{
+public:
+    /**
+     * ctor()
+     * @param cookieTypes The cookies to get. 
+     * @param sessionPriv The session for whom the information is requested from.
+     */
+    SetMediaSessionCookiesOperation(
+        const AsteriskSCF::Media::V1::SessionCookies& cookies, 
+        const SipSessionPtr& session)
+         : mCookies(cookies), mSession(session)
+    {
+    }
+
+    SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
+    {
+        lg(Debug) << "Executing a SetMediaSessionCookiesOperation operation";
+
+        AsteriskSCF::Media::V1::SessionCookies results;
+
+        // Set the cookies on all of the Session's RTP Media Sessions. 
+        RTPMediaSessionSeq mediaSessions = mSession->getRTPMediaSessions();
+        for(RTPMediaSessionSeq::iterator i = mediaSessions.begin(); 
+            i != mediaSessions.end(); ++i)
+        {
+            (*i)->setCookies(mCookies);
+        }
+
+        return Complete;
+    }
+
+private:
+    AsteriskSCF::Media::V1::SessionCookies mCookies;
+    SipSessionPtr mSession;
+};
+
+/**
+ * Remove the specified cookies from the media sessions. 
+ */
+class RemoveMediaSessionCookiesOperation : public SuspendableWork
+{
+public:
+    /**
+     * ctor()
+     * @param cookieTypes The cookies to get. 
+     * @param sessionPriv The session for whom the information is requested from.
+     */
+    RemoveMediaSessionCookiesOperation(
+        const AsteriskSCF::Media::V1::SessionCookies& cookieTypes, 
+        const SipSessionPtr& session)
+         : mCookieTypes(cookieTypes), mSession(session)
+    {
+    }
+
+    SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
+    {
+        lg(Debug) << "Executing a RemoveMediaSessionCookiesOperation operation";
+
+        AsteriskSCF::Media::V1::SessionCookies results;
+
+        // Set the cookies on all of the Session's RTP Media Sessions. 
+        RTPMediaSessionSeq mediaSessions = mSession->getRTPMediaSessions();
+        for(RTPMediaSessionSeq::iterator i = mediaSessions.begin(); 
+            i != mediaSessions.end(); ++i)
+        {
+            (*i)->removeCookies(mCookieTypes);
+        }
+
+        return Complete;
+    }
+
+private:
+    AsteriskSCF::Media::V1::SessionCookies mCookieTypes;
+    SipSessionPtr mSession;
+};
+
+/** 
+ * Servant for the Sessions's media Session interface.
+ */
+class SipMediaSession : public Media::V1::Session
+{
+public:
+    SipMediaSession(const SipSessionPtr& session) 
+        : mId(IceUtil::generateUUID()), 
+          mSession(session)
+    {
+    }
+
+    AsteriskSCF::Media::V1::StreamSourceSeq getSources(const Ice::Current&)
+    {
+        return mSession->getMediaSources();
+    }
+
+    AsteriskSCF::Media::V1::StreamSinkSeq getSinks(const Ice::Current&)
+    {
+        return mSession->getMediaSinks();
+    }
+
+    virtual std::string getId(const Ice::Current&)
+    {
+        return mId;
+    }
+
+    void setCookies(const AsteriskSCF::Media::V1::SessionCookies& cookies, 
+                    const Ice::Current&)
+    {
+        mSession->enqueueSessionWork(new SetMediaSessionCookiesOperation(cookies, mSession));
+    }
+
+    void getCookies_async(
+          const ::AsteriskSCF::Media::V1::AMD_Session_getCookiesPtr& cb,
+          const AsteriskSCF::Media::V1::SessionCookies& cookiesToGet, 
+          const Ice::Current&)
+    {
+        mSession->enqueueSessionWork(new GetMediaSessionCookiesOperation(cb, cookiesToGet, mSession));
+    }
+
+    void removeCookies(const AsteriskSCF::Media::V1::SessionCookies& cookies, 
+                    const Ice::Current&)
+    {
+        mSession->enqueueSessionWork(new RemoveMediaSessionCookiesOperation(cookies, mSession));
+    }
+
+private:
+    /**
+     * Unique identifier for the media session.
+     */
+    std::string mId;
+
+    /**
+     * A pointer to the communications session that created us.
+     */
+    SipSessionPtr mSession;
+};
 
 /**
  * Template for allocating from a pool.
@@ -1606,28 +1762,68 @@ void SipSession::removeCookies(const AsteriskSCF::SessionCommunications::V1::Ses
 }
 
 /**
- * An implementation of the getCookies method as defined in SessionCommunications.ice which gets specific cookies
- * from the session.
+ * Get the specified cookies from the session and pass it to 
+ * the given AMD callback handle. 
+ *
+ * @param cb The AMD callback reference.
+ * @param cookieTypes The cookies to get. 
+ * @param sessionPriv The session for whom the information is requested from.
  */
-AsteriskSCF::SessionCommunications::V1::SessionCookies SipSession::getCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookieTypes, const Ice::Current&)
+class GetCookiesOperation : public SuspendableWork
 {
-    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+public:
+    /**
+     * @param cb The callback handle for the AMD operation that requested the information.
+     * @param session The session for whom the information is requested from.
+     */
+    GetCookiesOperation(const AsteriskSCF::SessionCommunications::V1::AMD_Session_getCookiesPtr& cb,
+                        const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookieTypes,
+                        const SipSessionPrivPtr& sessionPriv)
+        : mCb(cb), mCookieTypes(cookieTypes), mImplPriv(sessionPriv)
+    {
+    }
 
-    for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = cookieTypes.begin();
-	 i != cookieTypes.end();
-	 ++i)
+    SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
     {
-	AsteriskSCF::SessionCommunications::V1::SessionCookieDict::const_iterator cookie = mImplPriv->mSessionCookies.find((*i)->ice_id());
+        lg(Debug) << "Executing a GetCookies operation";
 
-	if (cookie == mImplPriv->mSessionCookies.end())
-	{
-	    continue;
-	}
+        AsteriskSCF::SessionCommunications::V1::SessionCookies results;
+
+        for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = mCookieTypes.begin();
+	     i != mCookieTypes.end(); ++i)
+        {
+	    AsteriskSCF::SessionCommunications::V1::SessionCookieDict::const_iterator foundItem = 
+                mImplPriv->mSessionCookies.find((*i)->ice_id());
 
-	cookies.push_back(cookie->second);
+	    if (foundItem == mImplPriv->mSessionCookies.end())
+	    {
+	        continue;
+	    }
+
+	    results.push_back(foundItem->second);
+        }
+
+        mCb->ice_response(results);
+
+        return Complete;
     }
 
-    return cookies;
+private:
+    AsteriskSCF::SessionCommunications::V1::AMD_Session_getCookiesPtr mCb;
+    AsteriskSCF::SessionCommunications::V1::SessionCookies mCookieTypes;
+    SipSessionPrivPtr mImplPriv;
+};
+
+/**
+ * An implementation of the getCookies method as defined in SessionCommunications.ice which gets specific cookies
+ * from the session.
+ */
+void SipSession::getCookies_async(
+    const ::AsteriskSCF::SessionCommunications::V1::AMD_Session_getCookiesPtr&cb,
+    const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookieTypes, 
+    const Ice::Current&)
+{
+     enqueueSessionWork(new GetCookiesOperation(cb, cookieTypes, mImplPriv));
 }
 
 /**
diff --git a/src/SipSession.h b/src/SipSession.h
index 8da0248..d07b5cc 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -210,7 +210,10 @@ public:
      */
     void setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookieDict&);
     void removeCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
-    AsteriskSCF::SessionCommunications::V1::SessionCookies getCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
+    void getCookies_async(
+        const ::AsteriskSCF::SessionCommunications::V1::AMD_Session_getCookiesPtr&, 
+        const AsteriskSCF::SessionCommunications::V1::SessionCookies&, 
+        const Ice::Current&);
     AsteriskSCF::SessionCommunications::V1::SessionCookies getCookies();
     AsteriskSCF::SessionCommunications::V1::SessionCookieDict getAllCookies();
 

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list