[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
Mon Jan 17 17:13:20 CST 2011


branch "master" has been updated
       via  aa85fdfbfc3d130e68239e6baf166ca9a1b94f5c (commit)
      from  c2d48627f6cf02af6dd8e483af977eb50b6269bb (commit)

Summary of changes:
 src/PJSipSessionModule.cpp |  146 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 119 insertions(+), 27 deletions(-)


- Log -----------------------------------------------------------------
commit aa85fdfbfc3d130e68239e6baf166ca9a1b94f5c
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Jan 17 17:20:35 2011 -0600

    Merged the 'ami' branch.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 3256155..3c1ece4 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -33,6 +33,11 @@ using namespace AsteriskSCF::System::Logging;
 namespace
 {
 Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
+//Constants used for AMI callback class construction when calling
+//SessionListenerPrx methods.
+const std::string RingingCallbackName("ringing");
+const std::string ProgressingCallbackName("progressing");
+const std::string ConnectedCallbackName("connected");
 }
 
 namespace AsteriskSCF
@@ -76,6 +81,94 @@ private:
 };
 typedef IceUtil::Handle<RouteSessionCallback> RouteSessionCallbackPtr;
 
+class ConnectBridgedSessionsCallback : public IceUtil::Shared
+{
+public:
+    ConnectBridgedSessionsCallback(pjsip_inv_session *inv_session, pjsip_rx_data *rdata, SipSessionPtr session)
+        : mInvSession(inv_session), mRData(rdata), mSession(session) { }
+
+    void callback(const Ice::AsyncResultPtr &r)
+    {
+        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
+        try
+        {
+            router->end_connectBridgedSessions(r);
+        }
+        catch (const std::exception &e)
+        {
+            lg(Debug) << "ConnectBridgedSessionsCallback sending 400 due to exception:  " << e.what() << std::endl;
+            pjsip_dlg_respond(mInvSession->dlg, mRData, 400, NULL, NULL, NULL);
+            return;
+        }
+        pjsip_dlg_respond(mInvSession->dlg, mRData, 200, NULL, NULL, NULL);
+        
+        Ice::Current current;
+        lg(Debug) << "ConnectBridgedSessionsCallback calling session->stop(). " << std::endl;
+        mSession->stop(new ResponseCode(16), current);
+    }
+private:
+    pjsip_inv_session *mInvSession;
+    pjsip_rx_data *mRData;
+    SipSessionPtr mSession;
+};
+
+typedef IceUtil::Handle<ConnectBridgedSessionsCallback> ConnectBridgedSessionsCallbackPtr;
+
+class ConnectBridgedSessionsWithDestinationCallback : public IceUtil::Shared
+{
+public:
+    ConnectBridgedSessionsWithDestinationCallback(pjsip_inv_session *inv_session, pjsip_rx_data *rdata, SipSessionPtr session, std::string target)
+        : mInvSession(inv_session), mRData(rdata), mSession(session), mTarget(target) { }
+
+    void callback(const Ice::AsyncResultPtr &r)
+    {
+        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
+        try
+        {
+            router->end_connectBridgedSessions(r);
+        }
+        catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException &)
+        {
+            lg(Debug) << "ConnectBridgedSessionsWithDestination sending 404 due to destination not found for target: "<< mTarget <<  std::endl;
+
+            pjsip_dlg_respond(mInvSession->dlg, mRData, 404, NULL, NULL, NULL);
+            return;
+        }
+        catch (const std::exception &e)
+        {
+            lg(Debug) << "ConnectBridgedSessionsWithDestination sending 400 due to exception:  " << e.what() << std::endl;
+            pjsip_dlg_respond(mInvSession->dlg, mRData, 400, NULL, NULL, NULL);
+            return;
+        }
+        pjsip_dlg_respond(mInvSession->dlg, mRData, 200, NULL, NULL, NULL);
+        
+        Ice::Current current;
+        lg(Debug) << "ConnectBridgedSessionsWithDestination calling session->stop(). " << std::endl;
+        mSession->stop(new ResponseCode(16), current);
+    }
+private:
+    pjsip_inv_session *mInvSession;
+    pjsip_rx_data *mRData;
+    SipSessionPtr mSession;
+    std::string mTarget;
+};
+
+typedef IceUtil::Handle<ConnectBridgedSessionsWithDestinationCallback> ConnectBridgedSessionsWithDestinationCallbackPtr;
+
+class ListenerCallback : public IceUtil::Shared
+{
+public:
+    ListenerCallback(const std::string name) : mCallbackName(name) {}
+    void failure(const Ice::Exception &ex)
+    {
+        lg(Error) << "Ice exception when attempting to relate " << mCallbackName << " state: " << ex.what() << std::endl;
+    }
+private:
+    const std::string mCallbackName;
+};
+
+typedef IceUtil::Handle<ListenerCallback> ListenerCallbackPtr;
+
 PJSipSessionModInfo::PJSipSessionModInfo(pjsip_inv_session *inv_session,
     SipSessionPtr session)
     :
@@ -595,17 +688,17 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
 
         try
         {
+            ConnectBridgedSessionsCallbackPtr cb(new ConnectBridgedSessionsCallback(inv, rdata, session));
+            Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsCallback::callback);
+
             lg(Debug) << "handleRefer() calling router connectBridgedSessions(). " << std::endl;
-            mSessionRouter->connectBridgedSessions(session->getSessionProxy(), other_session->getSessionProxy());
-            pjsip_dlg_respond(inv->dlg, rdata, 200, NULL, NULL, NULL);
-            Ice::Current current;
-            lg(Debug) << "handleRefer() calling session->stop(). " << std::endl;
-            session->stop(new ResponseCode(16), current);
+            mSessionRouter->begin_connectBridgedSessions(session->getSessionProxy(), other_session->getSessionProxy(), d);
         }
-        catch (const std::exception& e)
+        catch (const Ice::CommunicatorDestroyedException &)
         {
-            lg(Debug) << "handleRefer() sending 400 due to exception:  " << e.what() << std::endl;
-            pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
+            lg(Debug) << "handleRefer() sending 503 due to communicator destruction" << std::endl;
+            pjsip_dlg_respond(inv->dlg, rdata, 503, NULL, NULL, NULL);
+            return;
         }
         pjsip_dlg_dec_lock(other_dlg);
     }
@@ -618,26 +711,16 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
         {
             PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
             SipSessionPtr session = session_mod_info->getSessionPtr();
+            ConnectBridgedSessionsWithDestinationCallbackPtr cb(new ConnectBridgedSessionsWithDestinationCallback(inv, rdata, session, target));
+            Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsWithDestinationCallback::callback);
 
             lg(Debug) << "handleRefer() calling router connectBridgedSessionsWithDestination(). " << std::endl;
-            mSessionRouter->connectBridgedSessionsWithDestination(session->getSessionProxy(), target);
-            pjsip_dlg_respond(inv->dlg, rdata, 200, NULL, NULL, NULL);
-            Ice::Current current;
-
-            lg(Debug) << "handleRefer() calling session->stop(). " << std::endl;
-            session->stop(new ResponseCode(16), current);
-        }
-        catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException&)
-        {
-            lg(Debug) << "handleRefer() sending 404 due to destination not found for target:  " << target << std::endl;
-
-            pjsip_dlg_respond(inv->dlg, rdata, 404, NULL, NULL, NULL);
-            return;
+            mSessionRouter->begin_connectBridgedSessionsWithDestination(session->getSessionProxy(), target, d);
         }
-        catch (const std::exception& e)
+        catch (const Ice::CommunicatorDestroyedException &)
         {
-            lg(Debug) << "handleRefer() sending 400 due to exception:  " << e.what() << std::endl;
-            pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
+            lg(Debug) << "handleRefer() sending 503 due to communicator destruction" << std::endl;
+            pjsip_dlg_respond(inv->dlg, rdata, 503, NULL, NULL, NULL);
             return;
         }
     }
@@ -728,7 +811,10 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
         {
             try
             {
-                (*listener)->ringing(session->getSessionProxy());
+                ListenerCallbackPtr cb(new ListenerCallback(RingingCallbackName));
+                Callback_SessionListener_ringingPtr ringingCB =
+                    newCallback_SessionListener_ringing(cb, &ListenerCallback::failure);
+                (*listener)->begin_ringing(session->getSessionProxy(), ringingCB);
             }
             catch (const Ice::Exception &ex)
             {
@@ -748,7 +834,10 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
         {
             try
             {
-                (*listener)->progressing(session->getSessionProxy(), response);
+                ListenerCallbackPtr cb(new ListenerCallback(ProgressingCallbackName));
+                Callback_SessionListener_progressingPtr progressingCB =
+                    newCallback_SessionListener_progressing(cb, &ListenerCallback::failure);
+                (*listener)->begin_progressing(session->getSessionProxy(), response, progressingCB);
             }
             catch (const Ice::Exception &ex)
             {
@@ -768,7 +857,10 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
             {
                 try
                 {
-                    (*listener)->connected(session->getSessionProxy());
+                    ListenerCallbackPtr cb(new ListenerCallback(ConnectedCallbackName));
+                    Callback_SessionListener_connectedPtr connectedCB =
+                        newCallback_SessionListener_connected(cb, &ListenerCallback::failure);
+                    (*listener)->begin_connected(session->getSessionProxy(), connectedCB);
                 }
                 catch (const Ice::Exception &ex)
                 {

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


-- 
asterisk-scf/release/sip.git



More information about the asterisk-scf-commits mailing list