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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu May 12 16:37:42 CDT 2011


branch "threading" has been updated
       via  0aa8e7cbb655426867811936cf679d2add799d33 (commit)
      from  c7611f180ddcaab977b7c2450d1c2af7f5c30d22 (commit)

Summary of changes:
 src/PJSipSessionModule.cpp |  106 +++++++++++++++++++++++---------------------
 src/PJSipSessionModule.h   |   24 +++++++---
 2 files changed, 74 insertions(+), 56 deletions(-)


- Log -----------------------------------------------------------------
commit 0aa8e7cbb655426867811936cf679d2add799d33
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu May 12 16:36:42 2011 -0500

    Finished with the HandleReferOperation queueable operation.
    
    It compiles...

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 19a6c81..576f6af 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -56,6 +56,7 @@ using namespace AsteriskSCF::SIP::V1;
 using namespace AsteriskSCF::System::ThreadPool::V1;
 using namespace AsteriskSCF::System::WorkQueue::V1;
 using namespace AsteriskSCF::WorkQueue;
+using namespace AsteriskSCF::SmartProxy;
 
 class RouteSessionCallback : public IceUtil::Shared
 {
@@ -66,7 +67,7 @@ public:
                          const std::string& destination,
                          const std::string& operationId)
         : mInvSession(inv_session), 
-          mTData(tdata),
+          mTdata(tdata),
           mSession(session),
           mDestination(destination),
           mOperationId(operationId)
@@ -82,18 +83,18 @@ public:
         }
         catch (const DestinationNotFoundException &)
         {
-            pjsip_inv_end_session(mInvSession, 404, NULL, &mTData);
-            pjsip_inv_send_msg(mInvSession, mTData);
+            pjsip_inv_end_session(mInvSession, 404, NULL, &mTdata);
+            pjsip_inv_send_msg(mInvSession, mTdata);
         }
         catch (...)
         {
-            pjsip_inv_end_session(mInvSession, 500, NULL, &mTData);
-            pjsip_inv_send_msg(mInvSession, mTData);
+            pjsip_inv_end_session(mInvSession, 500, NULL, &mTdata);
+            pjsip_inv_send_msg(mInvSession, mTdata);
         }
     }
 private:
     pjsip_inv_session *mInvSession;
-    pjsip_tx_data *mTData;
+    pjsip_tx_data *mTdata;
     SipSessionPtr mSession;
     std::string mDestination;
     std::string mOperationId;
@@ -111,7 +112,7 @@ public:
                                                   const std::string& target,
                                                   const std::string& operationId)
         : mInvSession(inv_session), 
-          mTData(tdata), 
+          mTdata(tdata), 
           mTsx(tsx),
           mSession(session), 
           mTarget(target),
@@ -131,18 +132,18 @@ public:
             lg(Debug) << "ConnectBridgedSessionsWithDestination sending 404 due to destination not found for target: "
                       << mTarget;
 
-            pjsip_dlg_modify_response(mInvSession->dlg, mTData, 400, NULL);
-            pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
+            pjsip_dlg_modify_response(mInvSession->dlg, mTdata, 400, NULL);
+            pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTdata);
             return;
         }
         catch (const std::exception &e)
         {
             lg(Debug) << "ConnectBridgedSessionsWithDestination sending 400 due to exception:  " << e.what();
-            pjsip_dlg_modify_response(mInvSession->dlg, mTData, 400, NULL);
-            pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
+            pjsip_dlg_modify_response(mInvSession->dlg, mTdata, 400, NULL);
+            pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTdata);
             return;
         }
-        pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
+        pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTdata);
         
         Ice::Current current;
         lg(Debug) << "ConnectBridgedSessionsWithDestination calling session->stop(). ";
@@ -150,7 +151,7 @@ public:
     }
 private:
     pjsip_inv_session *mInvSession;
-    pjsip_tx_data *mTData;
+    pjsip_tx_data *mTdata;
     pjsip_transaction *mTsx;
     SipSessionPtr mSession;
     std::string mTarget;
@@ -625,7 +626,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
     }
 }
 
-class HandleReferOperation : public SuspendableWork, public IceUtil::Shared
+class HandleReferOperation : public SuspendableWork, public SipQueueableOperation 
 {
 public:
     HandleReferOperation(
@@ -634,9 +635,10 @@ public:
             pjsip_tx_data *tdata,
             pjsip_sip_uri *target_sip_uri,
             const SipSessionPtr& session,
-            const SmartProxy<SessionRouterPrx>& sessionRouter)
+            const AsteriskSCF::SmartProxy::SmartProxy<SessionRouterPrx>& sessionRouter,
+            const int moduleId)
         : mState(Initial), mInv(inv), mTsx(tsx), mTdata(tdata), 
-        mTargetSipUri(target_sip_uri), mSession(session), mSessionRouter(sessionRouter) { }
+        mTargetSipUri(target_sip_uri), mSession(session), mSessionRouter(sessionRouter), mModuleId(moduleId) { }
 
     SuspendableWorkResult execute(const SuspendableWorkListenerPtr& workListener)
     {
@@ -652,34 +654,30 @@ public:
         }
     }
 
-    void changeState()
-    {
-        ++mState;
-    }
-
-    SuspendableWorkResult processRoutingResponse(workListener)
+    SuspendableWorkResult processRoutingResponse(const SuspendableWorkListenerPtr&)
     {
         assert(mAsyncResult);
-        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
+        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(mAsyncResult->getProxy());
         try
         {
-            router->end_connectBridgedSessions(r);
+            router->end_connectBridgedSessions(mAsyncResult);
         }
         catch (const std::exception &e)
         {
             lg(Debug) << "ConnectBridgedSessionsCallback sending 400 due to exception:  " << e.what();
-            pjsip_dlg_modify_response(mInv->dlg, mTData, 400, NULL);
-            pjsip_dlg_send_response(mInv->dlg, mTsx, mTData);
-            return;
+            pjsip_dlg_modify_response(mInv->dlg, mTdata, 400, NULL);
+            pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
+            return Complete;
         }
-        pjsip_dlg_send_response(mInv->dlg, mTsx, mTData);
+        pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
         
         Ice::Current current;
         lg(Debug) << "ConnectBridgedSessionsCallback calling session->stop(). ";
         mSession->stop(new ResponseCode(16), current);
+        return Complete;
     }
 
-    SuspendableWorkResult processRefer(const SuspendableWorKListenerPtr& workListener)
+    SuspendableWorkResult processRefer(const SuspendableWorkListenerPtr& workListener)
     {
         // Determine if this is a blind transfer or an attended transfer
         pj_str_t replaces = pj_str((char*)"Replaces");
@@ -715,8 +713,8 @@ public:
                 if (from_tag_pos == std::string::npos || to_tag_pos == std::string::npos)
                 {
                     lg(Debug) << "handleRefer() sending 400 due to From or To missing. ";
-                    pjsip_dlg_modify_response(mInv->dlg, mTData, 400, NULL);
-                    pjsip_dlg_send_response(mInv->dlg, mTsx, mTData);
+                    pjsip_dlg_modify_response(mInv->dlg, mTdata, 400, NULL);
+                    pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
                     return Complete;
                 }
 
@@ -734,8 +732,8 @@ public:
             if (!other_dlg)
             {
                 lg(Debug) << "handleRefer() sending PJSIP_SC_CALL_TSX_DOES_NOT_EXIST due to no other_dlg. ";
-                pjsip_dlg_modify_response(mInv->dlg, mTData, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL);
-                pjsip_dlg_send_response(mInv->dlg, mTsx, mTData);
+                pjsip_dlg_modify_response(mInv->dlg, mTdata, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL);
+                pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
                 return Complete;
             }
 
@@ -744,8 +742,8 @@ public:
             if (!other_inv)
             {
                 lg(Debug) << "handleRefer() sending PJSIP_SC_CALL_TSX_DOES_NOT_EXIST due to no other_inv. ";
-                pjsip_dlg_modify_response(mInv->dlg, mTData, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL);
-                pjsip_dlg_send_response(mInv->dlg, mTsx, mTData);
+                pjsip_dlg_modify_response(mInv->dlg, mTdata, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL);
+                pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
                 pjsip_dlg_dec_lock(other_dlg);
                 return Complete;
             }
@@ -754,8 +752,8 @@ public:
             {
                 lg(Debug) << "handleRefer() sending PJSIP_SC_DECLINE due to state > PJSIP_INV_STATE_DISCONNECTED. ";
 
-                pjsip_dlg_modify_response(mInv->dlg, mTData, PJSIP_SC_DECLINE, NULL);
-                pjsip_dlg_send_response(mInv->dlg, mTsx, mTData);
+                pjsip_dlg_modify_response(mInv->dlg, mTdata, PJSIP_SC_DECLINE, NULL);
+                pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
                 pjsip_dlg_dec_lock(other_dlg);
                 return Complete;
             }
@@ -764,32 +762,35 @@ public:
             {
                 lg(Debug) << "handleRefer() sending PJSIP_SC_CALL_TSX_DOES_NOT_EXIST due to other_inv->state < PJSIP_INV_STATE_EARLY and role not UAC. ";
 
-                pjsip_dlg_modify_response(mInv->dlg, mTData, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL);
-                pjsip_dlg_send_response(mInv->dlg, mTsx, mTData);
+                pjsip_dlg_modify_response(mInv->dlg, mTdata, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL);
+                pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
                 pjsip_dlg_dec_lock(other_dlg);
                 return Complete;
             }
 
-            PJSipSessionModInfo *other_session_mod_info = (PJSipSessionModInfo*)other_inv->mod_data[mModule.id];
+            PJSipSessionModInfo *other_session_mod_info = (PJSipSessionModInfo*)other_inv->mod_data[mModuleId];
             SipSessionPtr other_session = other_session_mod_info->getSessionPtr();
 
             try
             {
                 std::string operationId = ::IceUtil::generateUUID();
                 SipAMICallbackPtr cb(new SipAMICallback(workListener, this));
-                Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsCallback::callback);
+                Ice::CallbackPtr d = Ice::newCallback(cb, &SipAMICallback::callback);
 
                 lg(Debug) << "handleRefer() calling router connectBridgedSessions(). ";
+                mState = CalledBack;
                 mSessionRouter->begin_connectBridgedSessions(operationId, mSession->getSessionProxy(), other_session->getSessionProxy(), d);
+                pjsip_dlg_dec_lock(other_dlg);
                 return Suspended;
             }
             catch (const Ice::CommunicatorDestroyedException &)
             {
                 lg(Debug) << "handleRefer() sending 503 due to communicator destruction";
-                pjsip_dlg_respond(mInv->dlg, rdata, 503, NULL, NULL, NULL);
+                pjsip_dlg_modify_response(mInv->dlg, mTdata, 503, NULL);
+                pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
+                pjsip_dlg_dec_lock(other_dlg);
                 return Complete;
             }
-            pjsip_dlg_dec_lock(other_dlg);
         }
         else
         {
@@ -799,19 +800,21 @@ public:
             try
             {
                 std::string operationId = ::IceUtil::generateUUID();
-                PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)mInv->mod_data[mModule.id];
+                PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)mInv->mod_data[mModuleId];
                 SipSessionPtr session = session_mod_info->getSessionPtr();
                 SipAMICallbackPtr cb(new SipAMICallback(workListener, this));
-                Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsWithDestinationCallback::callback);
+                Ice::CallbackPtr d = Ice::newCallback(cb, &SipAMICallback::callback);
 
                 lg(Debug) << "handleRefer() calling router connectBridgedSessionsWithDestination(). ";
+                mState = CalledBack;
                 mSessionRouter->begin_connectBridgedSessionsWithDestination(operationId, session->getSessionProxy(), target, d);
                 return Suspended;
             }
             catch (const Ice::CommunicatorDestroyedException &)
             {
                 lg(Debug) << "handleRefer() sending 503 due to communicator destruction";
-                pjsip_dlg_respond(mInv->dlg, rdata, 503, NULL, NULL, NULL);
+                pjsip_dlg_modify_response(mInv->dlg, mTdata, 503, NULL);
+                pjsip_dlg_send_response(mInv->dlg, mTsx, mTdata);
                 return Complete;
             }
         }
@@ -847,7 +850,11 @@ public:
     /**
      * Session router...nothing more to say really
      */
-    SmartProxy<SessionRouterPrx> mSessionRouter;
+    AsteriskSCF::SmartProxy::SmartProxy<SessionRouterPrx> mSessionRouter;
+    /**
+     * The identifier of the PJSipSessionModule. Used for retrieving module data from mInv
+     */
+    const int mModuleId;
     /**
      * The result of any AMI calls we make
      */
@@ -900,7 +907,7 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
     pjsip_tx_data *tdata;
     pjsip_dlg_create_response(inv->dlg, rdata, 200, NULL, &tdata);
 
-    session->enqueueSessionWork(new HandleReferOperation(inv, tsx, tdata, target_sip_uri, session, mSessionRouter));
+    session->enqueueSessionWork(new HandleReferOperation(inv, tsx, tdata, target_sip_uri, session, mSessionRouter, mModule.id));
 }
 
 pj_bool_t PJSipSessionModule::on_rx_request(pjsip_rx_data *rdata)
@@ -1431,8 +1438,7 @@ void SessionWork::emptied()
 
 void SessionWork::execute()
 {
-    SuspendableWorkListenerPtr listener(new SipSessionSuspendableWorkListener(this));
-    while(mInternalQueue->executeWork(listener));
+    while(mInternalQueue->executeWork());
 }
 
 void SessionWork::enqueueWork(const SuspendableWorkPtr& work)
diff --git a/src/PJSipSessionModule.h b/src/PJSipSessionModule.h
index dbbd95a..a1c87ea 100644
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@ -125,28 +125,40 @@ private:
     AsteriskSCF::System::ThreadPool::V1::PoolListenerPtr mPoolListener;
 };
 
-template <class T>
+class SipQueueableOperation : virtual public IceUtil::Shared
+{
+public:
+    virtual ~SipQueueableOperation();
+    void setAsyncResult(const Ice::AsyncResultPtr& r) {mAsyncResult = r;}
+protected:
+    Ice::AsyncResultPtr mAsyncResult;
+    SipQueueableOperation();
+};
+
+typedef IceUtil::Handle<SipQueueableOperation> SipQueueableOperationPtr;
+
 class SipAMICallback : public IceUtil::Shared
 {
 public:
     SipAMICallback(
             const AsteriskSCF::System::WorkQueue::V1::SuspendableWorkListenerPtr& listener,
-            const T& operation)
+            const SipQueueableOperationPtr& operation)
         : mListener(listener), mOperation(operation)
     {
     }
 
     void callback(const Ice::AsyncResultPtr &r)
     {
-        mOperation->mAsyncResult = r;
-        mOperation->changeState();
+        mOperation->setAsyncResult(r);
         mListener->workResumable();
     }
 
 private:
-    AsteriskSCF::System::WorkQueue::V1::SuspendableWorkListenerPtr& mListener;
-    T& mOperation;
+    AsteriskSCF::System::WorkQueue::V1::SuspendableWorkListenerPtr mListener;
+    SipQueueableOperationPtr mOperation;
 };
 
+typedef IceUtil::Handle<SipAMICallback> SipAMICallbackPtr;
+
 }; //end namespace SipSessionManager
 }; //end namespace AsteriskSCF

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list