[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
Tue Jul 26 17:58:07 CDT 2011


branch "master" has been updated
       via  736155bbeb65c6636154eb241939bdee6ad97947 (commit)
      from  9679afdc83b045a770a457d3bcc0f45d9e84031a (commit)

Summary of changes:
 src/PJSipSessionModule.cpp |   22 ++++++-------
 src/PJSipSessionModule.h   |   72 ++++++++++++-------------------------------
 2 files changed, 30 insertions(+), 64 deletions(-)


- Log -----------------------------------------------------------------
commit 736155bbeb65c6636154eb241939bdee6ad97947
Author: Mark Michelson <mmichelson at digium.com>
Date:   Tue Jul 26 17:57:56 2011 -0500

    Properly deal with multiple AMI calls in a single queued operation.
    
    This likely will fix an intermittent crash I was seeing, plus it fixes
    a more direct bug I found in the transfer-improvements branch.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 9f2fe59..90da6e7 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -523,12 +523,12 @@ protected:
         return Complete;
     }
 
-    SuspendableWorkResult calledBack(const SuspendableWorkListenerPtr&)
+    SuspendableWorkResult calledBack(const Ice::AsyncResultPtr& asyncResult)
     {
-        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(mAsyncResult->getProxy());
+        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(asyncResult->getProxy());
         try
         {
-            router->end_routeSession(mAsyncResult);
+            router->end_routeSession(asyncResult);
         }
         catch (const DestinationNotFoundException &)
         {
@@ -892,19 +892,18 @@ protected:
      * Once the routing service has allowed for work to be resumed,
      * this is where the final work is done
      */
-    SuspendableWorkResult calledBack(const SuspendableWorkListenerPtr&)
+    SuspendableWorkResult calledBack(const Ice::AsyncResultPtr& asyncResult)
     {
-        assert(mAsyncResult);
-        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(mAsyncResult->getProxy());
+        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(asyncResult->getProxy());
         try
         {
             if (mWasWithDestination)
             {
-                router->end_connectBridgedSessionsWithDestination(mAsyncResult);
+                router->end_connectBridgedSessionsWithDestination(asyncResult);
             }
             else
             {
-                router->end_connectBridgedSessions(mAsyncResult);
+                router->end_connectBridgedSessions(asyncResult);
             }
         }
         catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException &)
@@ -1203,13 +1202,12 @@ protected:
         return Complete;
     }
 
-    SuspendableWorkResult calledBack(const SuspendableWorkListenerPtr&)
+    SuspendableWorkResult calledBack(const Ice::AsyncResultPtr& asyncResult)
     {
-        assert(mAsyncResult);
-        SessionListenerPrx listener = SessionListenerPrx::uncheckedCast(mAsyncResult->getProxy());
+        SessionListenerPrx listener = SessionListenerPrx::uncheckedCast(asyncResult->getProxy());
         try
         {
-            listener->end_indicated(mAsyncResult);
+            listener->end_indicated(asyncResult);
         }
         catch (const Ice::Exception&)
         {
diff --git a/src/PJSipSessionModule.h b/src/PJSipSessionModule.h
index a90ef7d..79b0212 100644
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@ -176,40 +176,15 @@ typedef IceUtil::Handle<PJSipSessionModule> PJSipSessionModulePtr;
 class SipQueueableOperation : virtual public AsteriskSCF::System::WorkQueue::V1::SuspendableWork
 {
 public:
-    SipQueueableOperation() : mState(Initial) { }
+    SipQueueableOperation() { }
     virtual ~SipQueueableOperation() { }
-    /**
-     * Queueable operations may call out to AMI methods. AMI callbacks happen
-     * in Ice client threads. We want to process the result of the AMI call in one
-     * of our thread pool's threads, though. The AMI callback can set the operation's
-     * AsyncResult so that the operation may process the result of the AMI call in
-     * one of our threads.
-     */
-    void setAsyncResult(const Ice::AsyncResultPtr& r) {mAsyncResult = r;}
 
     /**
      * Override of SuspendableWorkExecute()
      */
     AsteriskSCF::System::WorkQueue::V1::SuspendableWorkResult execute(const AsteriskSCF::System::WorkQueue::V1::SuspendableWorkListenerPtr& listener)
     {
-        AsteriskSCF::System::WorkQueue::V1::SuspendableWorkResult result =
-            AsteriskSCF::System::WorkQueue::V1::Complete;
-        switch (mState)
-        {
-            case Initial:
-                result = initial(listener);
-                // Change the state now so that
-                // when the AMI callback occurs,
-                // the proper followup will be called.
-                mState = CalledBack;
-                break;
-            case CalledBack:
-                result = calledBack(listener);
-                break;
-            default:
-                break;
-        }
-        return result;
+        return initial(listener);
     }
 
 protected:
@@ -220,6 +195,7 @@ protected:
     virtual AsteriskSCF::System::WorkQueue::V1::SuspendableWorkResult initial(
             const AsteriskSCF::System::WorkQueue::V1::SuspendableWorkListenerPtr&) = 0;
 
+public:
     /**
      * If a SipQueueableOperation has made an AMI call, then when the AMI method
      * returns, this will be where the AMI result can be processed.
@@ -228,36 +204,29 @@ protected:
      * not always be overloaded.
      */
     virtual AsteriskSCF::System::WorkQueue::V1::SuspendableWorkResult calledBack(
-            const AsteriskSCF::System::WorkQueue::V1::SuspendableWorkListenerPtr&)
+            const Ice::AsyncResultPtr&)
     {
         return AsteriskSCF::System::WorkQueue::V1::Complete;
     }
-
-    enum states
-    {
-        /**
-         * State of the operation upon construction.
-         * @see initial
-         */
-        Initial,
-        /**
-         * State when AMI result is received.
-         * @see calledBack
-         */
-        CalledBack,
-    } mState;
-
-    /**
-     * Ice asynchronous result.
-     *
-     * Used for processing the result of AMI calls.
-     * @see setAsyncResult
-     */
-    Ice::AsyncResultPtr mAsyncResult;
 };
 
 typedef IceUtil::Handle<SipQueueableOperation> SipQueueableOperationPtr;
 
+class SipAMICallbackOperation : public AsteriskSCF::System::WorkQueue::V1::SuspendableWork
+{
+public:
+    SipAMICallbackOperation(const Ice::AsyncResultPtr& r, const SipQueueableOperationPtr& operation)
+        : mAsyncResultPtr(r), mOperation(operation) { }
+    AsteriskSCF::System::WorkQueue::V1::SuspendableWorkResult execute(
+            const AsteriskSCF::System::WorkQueue::V1::SuspendableWorkListenerPtr&)
+    {
+        return mOperation->calledBack(mAsyncResultPtr);
+    }
+private:
+    Ice::AsyncResultPtr mAsyncResultPtr;
+    SipQueueableOperationPtr mOperation;
+};
+
 /**
  * General AMI callback class used with SipQueueableOperation
  *
@@ -282,14 +251,13 @@ public:
 
     void callback(const Ice::AsyncResultPtr &r)
     {
-        mOperation->setAsyncResult(r);
         if (mIsSuspended)
         {
             mListener->workResumable();
         }
         else if (mNeedsRequeuing)
         {
-            mSession->enqueueSessionWork(mOperation);
+            mSession->enqueueSessionWork(new SipAMICallbackOperation(r, mOperation));
         }
     }
 

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


-- 
asterisk-scf/release/sip.git



More information about the asterisk-scf-commits mailing list