applayerprotocols/httptransportfw/Test/T_HttpIntegration/CEventDispatcher.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 // $Header$
       
    15 // This source file implements the basic event management control (active
       
    16 // objects) for our domain command supprt.
       
    17 // based loosely on the WSP version...
       
    18 // Note: you must regenerate from this for the domain you require, providing the
       
    19 // appropriate callbacks - this way reuse and oo is maintained.
       
    20 // 
       
    21 //
       
    22 
       
    23 #include "CEventDispatcher.h"
       
    24 #include "CTimeoutTimer.h"
       
    25 #include "MHTTPEventCallback.h"
       
    26 
       
    27 //-----------------------------------------------------------------------------
       
    28 
       
    29 const TInt KSecondsToMicroSecondsFactor	= 1000000;
       
    30 
       
    31 //-----------------------------------------------------------------------------
       
    32 
       
    33 CEventDispatcher *CEventDispatcher::NewL(MHTTPEventCallback& aCallback)
       
    34 {
       
    35 CEventDispatcher *self = new (ELeave) CEventDispatcher(aCallback);
       
    36 CleanupStack::PushL(self);
       
    37 self->ConstructL();
       
    38 CleanupStack::Pop(self);
       
    39 return self;
       
    40 }
       
    41 
       
    42 //-----------------------------------------------------------------------------
       
    43 
       
    44 CEventDispatcher::~CEventDispatcher()
       
    45 {
       
    46 Cancel();
       
    47 
       
    48 delete iTimer;
       
    49 }
       
    50 
       
    51 //-----------------------------------------------------------------------------
       
    52 
       
    53 CEventDispatcher::CEventDispatcher(MHTTPEventCallback &aCallback)
       
    54 	: 
       
    55 	CActive(EPriorityStandard), 
       
    56 	iCallback(aCallback),
       
    57 	iSession(NULL),
       
    58 	iTransaction(NULL)
       
    59 {
       
    60 CActiveScheduler::Add(this);
       
    61 }
       
    62 
       
    63 //-----------------------------------------------------------------------------
       
    64 
       
    65 void CEventDispatcher::ConstructL()
       
    66 {
       
    67 iTimer = CTimeoutTimer::NewL(*this);
       
    68 }
       
    69 
       
    70 //-----------------------------------------------------------------------------
       
    71 
       
    72 void CEventDispatcher::WaitForHTTPEvent(RHTTPSession *aSess, TInt aTimeoutValueSeconds)
       
    73 {
       
    74 iSession = aSess;
       
    75 
       
    76 // Request the get event from the co session
       
    77 //iTrans = NULL;
       
    78 //iConn->GetEvent(iEvent, iTrans, iStatus);
       
    79 
       
    80 // Set ourselves active
       
    81 SetActive();
       
    82 
       
    83 // Start the timeout timer
       
    84 iTimer->After(aTimeoutValueSeconds * KSecondsToMicroSecondsFactor);
       
    85 }
       
    86 
       
    87 //-----------------------------------------------------------------------------
       
    88 
       
    89 void CEventDispatcher::CancelWait()
       
    90 {
       
    91 Cancel();
       
    92 }
       
    93 
       
    94 //-----------------------------------------------------------------------------
       
    95 //	Methods from CActive
       
    96 
       
    97 void CEventDispatcher::RunL()
       
    98 {
       
    99 // Check to see if this event is for a transaction in the aborting state
       
   100 if (iTransaction != NULL)
       
   101 	{
       
   102 	/*
       
   103 	// Check the state
       
   104 	TWspMethodState state;
       
   105 	iTrans->GetState(state);
       
   106 
       
   107 	if (state == EAborting && iEvent != EMethodAbortInd)
       
   108 		{
       
   109 		// Transaction is in Aborting state and this not the S-MethodAbort.ind
       
   110 		// event - need to ignore this event. Ask the session for next event.
       
   111 		iTrans = NULL;
       
   112 		iConn->GetEvent(iEvent, iTrans, iStatus);
       
   113 
       
   114 		// Set ourselves active
       
   115 		SetActive();
       
   116 
       
   117 		// NOTE - don't cancel timeout timer, nor start it again.
       
   118 		return;
       
   119 		}
       
   120 	*/
       
   121 	}
       
   122 
       
   123 //	Record the iStatus
       
   124 TRequestStatus status = iStatus;
       
   125 
       
   126 //	Cancel the timer
       
   127 iTimer->Cancel();
       
   128 
       
   129 //	We are waiting for HTTP event	
       
   130 iCallback.HandleHTTPEvent(iEvent, iSession, status);
       
   131 }
       
   132 
       
   133 //-----------------------------------------------------------------------------
       
   134 
       
   135 void CEventDispatcher::DoCancel()
       
   136 {
       
   137 if (iTransaction)
       
   138 	iTransaction->Cancel();
       
   139 iTimer->Cancel();
       
   140 }
       
   141 
       
   142 //-----------------------------------------------------------------------------
       
   143 //	Methods from MTimeoutCallback
       
   144 
       
   145 void CEventDispatcher::Timeout()
       
   146 {
       
   147 // Cancel the get event request
       
   148 Cancel();
       
   149 
       
   150 // Inform the call back
       
   151 iCallback.HandleHTTPEvent(iEvent, iSession, KRequestPending);
       
   152 }
       
   153 
       
   154 //-----------------------------------------------------------------------------