applayerprotocols/httpexamples/nwsswsptrhnd/CNwssConnectGuard.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 // System includes
       
    17 #include <wsp/mwspcomethodinvoker.h>
       
    18 #include <wsp/mwspcomethodcallback.h>
       
    19 #include <wsp/mwspcosessioncallback.h>
       
    20 #include <uri8.h>
       
    21 
       
    22 // Local includes 
       
    23 #include "cnwssconnectguard.h"
       
    24 
       
    25 CNwssConnectGuard* CNwssConnectGuard::NewL(MWspCOMethodInvoker& aMethodInvoker, MWspCOSessionCallback& aSessionCallback)
       
    26 	{
       
    27 	CNwssConnectGuard* self = new (ELeave) CNwssConnectGuard(aMethodInvoker, aSessionCallback);
       
    28 	return self;
       
    29 	}
       
    30 
       
    31 CNwssConnectGuard::~CNwssConnectGuard()
       
    32 	{
       
    33 	ResetMethodInfo();
       
    34 	}
       
    35 
       
    36 CNwssConnectGuard::CNwssConnectGuard(MWspCOMethodInvoker& aMethodInvoker, MWspCOSessionCallback& aSessionCallback)
       
    37 : CActive(CActive::EPriorityStandard), iMethodInvoker(aMethodInvoker), iSessionCallback(aSessionCallback)
       
    38 	{
       
    39 	CActiveScheduler::Add(this);
       
    40 	}
       
    41 
       
    42 void CNwssConnectGuard::SendMethodInvokeReq()
       
    43 	{
       
    44 	// Check to see if object is active - this implies that T-MethodAbort.ind
       
    45 	// is waiting to sent.
       
    46 	if( !IsActive() && iMethodCallback )
       
    47 		{
       
    48 		// Send the T-MethodInvoke.req primitive.
       
    49 		iMethodInvoker.MethodInvokeReq(
       
    50 									  *iMethodCallback,
       
    51 									  iMethod,
       
    52 									  iRequestUri->Uri(),
       
    53 									  *iRequestHeaders,
       
    54 									  *iRequestBody,
       
    55 									  EFalse
       
    56 									  );
       
    57 		// Release resources - no longer neeeded
       
    58 		ResetMethodInfo();
       
    59 		}
       
    60 	}
       
    61 
       
    62 void CNwssConnectGuard::SendDisconnectInd(Wap::TWspReason aReason)
       
    63 	{
       
    64 	// Specify that need to send S-Disconnect.ind
       
    65 	iSendDisconnect = ETrue;
       
    66 
       
    67 	// Store the reason code
       
    68 	iDisconnectReason = aReason;
       
    69 
       
    70 	CompleteSelf();
       
    71 	}
       
    72 
       
    73 void CNwssConnectGuard::SendMethodAbortInd()
       
    74 	{
       
    75 	CompleteSelf();
       
    76 	}
       
    77 
       
    78 void CNwssConnectGuard::ReceivedMethodInvokeReqL(
       
    79 												MWspCOMethodCallback&	aMethodCallback,
       
    80 												RStringF				aMethod,
       
    81 												const TUriC8&			aRequestUri,
       
    82 												const TDesC8&			aRequestHeaders,
       
    83 												const TDesC8&			aRequestBody
       
    84 												)
       
    85 	{
       
    86 	if( iMethodCallback )
       
    87 		{
       
    88 		// Have already got method info - leave as this is not allowed.
       
    89 		User::Leave(KErrAlreadyExists);
       
    90 		}
       
    91 	iMethodCallback	= &aMethodCallback;
       
    92 	iMethod			= aMethod.Copy();
       
    93 	iRequestUri		= CUri8::NewL(aRequestUri);
       
    94 	iRequestHeaders	= aRequestHeaders.AllocL();
       
    95 	iRequestBody	= aRequestBody.AllocL();
       
    96 	}
       
    97 
       
    98 void CNwssConnectGuard::RunL()
       
    99 	{
       
   100 	// Check to see if there is any method info.
       
   101 	if( iMethodCallback )
       
   102 		{
       
   103 		Wap::TWspReason reason = Wap::EUserReq;
       
   104 
       
   105 		if( iSendDisconnect && iDisconnectReason != Wap::EUserReq )
       
   106 			{
       
   107 			// The session was disconnected due to a connect failure - could be
       
   108 			// a WTLS failure, etc.
       
   109 			reason = Wap::EConnectErr;
       
   110 			}
       
   111 		// Yep - send the T-MethodAbort.ind
       
   112 		iMethodCallback->MethodAbortInd(reason);
       
   113 
       
   114 		// Release resources - no longer neeeded
       
   115 		ResetMethodInfo();
       
   116 		}
       
   117 	// Send S-Disconnect?
       
   118 	if( iSendDisconnect )
       
   119 		{
       
   120 		TWspRedirectedAddress emptyAddr;
       
   121 		iSessionCallback.DisconnectInd(iDisconnectReason, EFalse, emptyAddr, KNullDesC8(), KNullDesC8());
       
   122 		}
       
   123 	}
       
   124 
       
   125 void CNwssConnectGuard::DoCancel()
       
   126 	{
       
   127 	}
       
   128 
       
   129 void CNwssConnectGuard::CompleteSelf()
       
   130 	{
       
   131 	if (!IsActive())
       
   132 		{
       
   133 		TRequestStatus* pStat = &iStatus;
       
   134 		User::RequestComplete(pStat, KErrNone);
       
   135 		SetActive();
       
   136 		}
       
   137 	}
       
   138 
       
   139 void CNwssConnectGuard::ResetMethodInfo()
       
   140 	{
       
   141 	iMethod.Close();
       
   142 	iMethod = RStringF();
       
   143 	delete iRequestUri;
       
   144 	iRequestUri = NULL;
       
   145 	delete iRequestHeaders;
       
   146 	iRequestHeaders = NULL;
       
   147 	delete iRequestBody;
       
   148 	iRequestBody = NULL;
       
   149 	}