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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Dec 22 18:57:41 UTC 2010


branch "ami" has been updated
       via  c4e5ac5795ab7bd6b7dd9df51b221ffd4f0a3e07 (commit)
      from  0095b3345f23bf536ea6bf4d2d723416c756dff3 (commit)

Summary of changes:
 src/PJSipSessionModule.cpp |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)


- Log -----------------------------------------------------------------
commit c4e5ac5795ab7bd6b7dd9df51b221ffd4f0a3e07
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Dec 22 13:03:12 2010 -0600

    Make the StoppedCallback more safe.
    
    We were calling listener->begin_stopped and then immediately
    destroying important data. Now we wait until the callback is
    called into to destroy the data.
    
    About to run some tests...

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index d259974..680615f 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -47,6 +47,9 @@ using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::SIP::V1;
 
+class PJSipSessionModInfo;
+class PJSipDialogModInfo;
+
 class RouteSessionCallback : public IceUtil::Shared
 {
 public:
@@ -153,10 +156,34 @@ typedef IceUtil::Handle<ConnectBridgedSessionsWithDestinationCallback> ConnectBr
 class StoppedCallback : public IceUtil::Shared
 {
 public:
-    StoppedCallback() {}
+    StoppedCallback(PJSipSessionModule *module, pjsip_inv_session *inv, const int id) : mModule(module), mInvSession(inv), mModuleId(id) {}
+    void success()
+    {
+        cleanup();
+    }
     void failure(const Ice::Exception &ex)
     {
         lg(Error) << "Ice exception when attempting to relate stopped state: " << ex.what() << std::endl;
+        // Still need to do the same cleanup as for a successful call
+        cleanup();
+    }
+private:
+    PJSipSessionModule *mModule;
+    pjsip_inv_session *mInvSession;
+    const int mModuleId;
+    void cleanup()
+    {
+        pjsip_dialog *dlg = mInvSession->dlg;
+        PJSipSessionModInfo *sessionInfo = (PJSipSessionModInfo *) mInvSession->mod_data[mModuleId];
+        PJSipDialogModInfo *dialogInfo = (PJSipDialogModInfo *) dlg->mod_data[mModuleId];
+        sessionInfo->mNeedsRemoval = true;
+        dialogInfo->mNeedsRemoval = true;
+        lg(Debug) << "Replicating state on DISCONNECTED inv_state.";
+        mModule->replicateState(dialogInfo, NULL, sessionInfo);
+        delete sessionInfo;
+        delete dialogInfo;
+        dlg->mod_data[mModuleId] = 0;
+        mInvSession->mod_data[mModuleId] = 0;
     }
 };
 
@@ -939,9 +966,9 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
         {
             try
             {
-                StoppedCallbackPtr cb(new StoppedCallback());
+                StoppedCallbackPtr cb(new StoppedCallback(this, inv, mModule.id));
                 Callback_SessionListener_stoppedPtr stoppedCB =
-                    newCallback_SessionListener_stopped(cb, &StoppedCallback::failure);
+                    newCallback_SessionListener_stopped(cb, &StoppedCallback::success, &StoppedCallback::failure);
                 (*listener)->begin_stopped(session->getSessionProxy(), response, stoppedCB);
             }
             catch (const Ice::Exception &ex)
@@ -949,16 +976,6 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
                 lg(Error) << "Ice exception when attempting to relate stopped state: " << ex.what() << std::endl;
             }
         }
-        session_mod_info->mNeedsRemoval = true;
-        pjsip_dialog *dlg = inv->dlg;
-        PJSipDialogModInfo *dlg_mod_info = (PJSipDialogModInfo*) dlg->mod_data[mModule.id];
-        dlg_mod_info->mNeedsRemoval = true;
-        lg(Debug) << "Replicating state on DISCONNECTED inv_state.";
-        replicateState(dlg_mod_info, NULL, session_mod_info);
-        delete session_mod_info;
-        delete dlg_mod_info;
-        dlg->mod_data[mModule.id] = 0;
-        inv->mod_data[mModule.id] = 0;
     }
     if (event->type == PJSIP_EVENT_RX_MSG && inv->state == PJSIP_INV_STATE_CONFIRMED)
     {

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


-- 
asterisk-scf/release/sip.git



More information about the asterisk-scf-commits mailing list