telephonyprotocols/umtsgprsscpr/Test/te_spud/src/InputRequestListener.cpp
changeset 64 b34bb05ac869
parent 56 ab72d5c1d770
equal deleted inserted replaced
56:ab72d5c1d770 64:b34bb05ac869
     1 // Copyright (c) 2004-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 // Implementation of CInputRequestListener
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 
       
    24 #include "CPdpFsmInterface.h"
       
    25 
       
    26 #include "SpudUnitTestServer.h"
       
    27 #include "InputRequestListener.h"
       
    28 #include <in_iface.h>
       
    29 #include "reteldriverinput.h"
       
    30 #include "ceteldriverfactory.h"
       
    31 #include "cpdpfsmfactory.h"
       
    32 #include "DefaultContextParameters.h"
       
    33 
       
    34 CInputRequestListener* CInputRequestListener::NewL(TBool aUseTestPdpInterface)
       
    35 	{
       
    36 	CInputRequestListener *me = new(ELeave) CInputRequestListener(aUseTestPdpInterface);
       
    37 	CleanupStack::PushL(me);
       
    38 	me->ConstructL();
       
    39 	CleanupStack::Pop(me);
       
    40 	return me;
       
    41 	}
       
    42 
       
    43 CInputRequestListener::CInputRequestListener(TBool aUseTestPdpFsmInterface) : CActive(EPriorityStandard), iUseTestPdpFsmInterface(aUseTestPdpFsmInterface)
       
    44 	{
       
    45 	iReadyForInputRequest = KRequestPending;
       
    46 	iThreadDestructed     = KRequestPending;
       
    47 	iThreadInitialized    = KRequestPending;
       
    48 
       
    49 	iEtelDriverInputResponseStatus             = KRequestPending;
       
    50 	iEtelDriverConfigGPRSNotificationStatus    = KRequestPending;
       
    51 	iEtelDriverContextStatusNotificationStatus = KRequestPending;
       
    52 	iEtelDriverQosNotificationStatus           = KRequestPending;
       
    53 	iEtelDriverServiceNotificationStatus       = KRequestPending;
       
    54 	
       
    55 	iFsmInputResponseStatus          = KRequestPending;
       
    56 	iFsmNetworkStatusStatus          = KRequestPending;
       
    57 	iFsmContextParameterChangeStatus = KRequestPending;
       
    58 	iFsmContextSuspendedStatus       = KRequestPending;
       
    59 	iFsmContextResumedStatus         = KRequestPending;	
       
    60     iFsmObjectCreateResponse         = KRequestPending;	
       
    61 	}
       
    62 	
       
    63 void CInputRequestListener::ConstructL()
       
    64 	{
       
    65 	iSpudManInterface = new(ELeave) TSpudManInterfaceTest(*this);
       
    66 	}
       
    67 
       
    68 CInputRequestListener::~CInputRequestListener()
       
    69 	{
       
    70 	Cancel();
       
    71 	if (iEtelDriver)
       
    72 		{
       
    73 		iEtelDriver->Close();
       
    74 		delete iEtelDriver;
       
    75 		iEtelDriver = NULL;
       
    76 		}
       
    77 	
       
    78 	if (iPdpFsmInterfaceTest)
       
    79 		{
       
    80 		iPdpFsmInterfaceTest->Close();
       
    81 		delete iPdpFsmInterfaceTest;
       
    82 		iPdpFsmInterfaceTest = NULL;
       
    83 		}
       
    84 
       
    85 	if (iPdpFsmInterface)
       
    86 		{
       
    87 		iPdpFsmInterface->Close();
       
    88 		delete iPdpFsmInterface;
       
    89 		iPdpFsmInterface = NULL;
       
    90 		}
       
    91 	}
       
    92 	
       
    93 void CInputRequestListener::DoCancel()
       
    94 	{
       
    95 	iStatus = KErrCancel;
       
    96 	}
       
    97 	
       
    98 /**
       
    99  Wrapper for private method CActive::SetActive()
       
   100  */
       
   101 void CInputRequestListener::Activate()
       
   102 	{
       
   103 	iStatus = KRequestPending;
       
   104 	SetActive();
       
   105 	}
       
   106 
       
   107 /**
       
   108  If iStatus was completed with EEtelDriverInputRequest, REtelDriverInput::Input is called with the parameters supplied in iInputData
       
   109  If iStatus was completed with EEtelDriverCancelPdpRequest, REtelDriverInput::Cancel is called with the parameters supplied in iEtelDriverCancelRequestData
       
   110  If iStatus was completed with EFsmInputRequest, RPdpFsmInterface::Input is called with the parameters supplied in iFsmInputRequestData
       
   111  If iStatus was completed with ECleanup, or anything else, the active scheduler is stopped
       
   112  */
       
   113 void CInputRequestListener::RunL()
       
   114 	{
       
   115 	TRequestStatus status = iStatus;
       
   116 	iStatus = KRequestPending;
       
   117 	
       
   118 	if (status == EEtelDriverInputRequest     || 
       
   119 	    status == EEtelDriverCancelPdpRequest ||
       
   120 	    status == EFsmInputRequest            || 
       
   121 	    status == EFsmObjectCreate)
       
   122 		{
       
   123 		switch (status.Int())
       
   124 		    {
       
   125 		    case EEtelDriverInputRequest:
       
   126 		        {
       
   127     			// the main test thread requested a call to REtelDriverInput::Input
       
   128     			iEtelDriver->Input(iEtelDriverInputRequestData.iPdpId, iEtelDriverInputRequestData.iOperation); // error
       
   129     			break;
       
   130     			}
       
   131 		    case EEtelDriverCancelPdpRequest:
       
   132 		        {
       
   133     			iEtelDriver->CancelPdp(iEtelDriverCancelRequestPdpId);
       
   134     			break;
       
   135     			}
       
   136 		    case EFsmInputRequest:
       
   137 		        {
       
   138     			iPdpFsmInterface->Input(iFsmInputRequestData.iPdpId, iFsmInputRequestData.iOperation);
       
   139     			break;
       
   140     			}
       
   141 		    case EFsmObjectCreate:
       
   142     			{
       
   143     			TInt err = iPdpFsmInterface->NewFsmContext(iFsmInputRequestData.iPdpId);
       
   144 
       
   145                 // Reproduce completion  as per 'SpudManInterfaceTest::Input()' 
       
   146                 // - since we're not being called asynchronously from EtelPkt
       
   147                 
       
   148         		iFsmInputResponseData.iPdpId = iFsmInputRequestData.iPdpId;
       
   149 
       
   150         		TRequestStatus *readyStatus = &iFsmObjectCreateResponse;
       
   151         	 	iParentThread.RequestComplete(readyStatus, err);
       
   152         	 	break;
       
   153     			}
       
   154     		default:
       
   155     		    ASSERT(EFalse);
       
   156     		}
       
   157 
       
   158 		// we are finished with the iInputData or iControlData parameters, so this signals to the main test thread
       
   159 		// that this data can be updated with new parameters
       
   160 		TRequestStatus *readyStatus = &iReadyForInputRequest;
       
   161 	 	iParentThread.RequestComplete(readyStatus, KErrNone);
       
   162 	 	
       
   163 		SetActive(); 	
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		// the status was ECleanup, or we don't recognize the status, so abort the active scheduler, and the thread will be exited
       
   168 		CActiveScheduler::Stop();
       
   169 		}
       
   170 	}
       
   171 	
       
   172 /**
       
   173  Creates the unit under test - the FSM if iUseTestPdpFsmInterface is false, and the EtelDriver otherwise
       
   174  */
       
   175 void CInputRequestListener::CreateUnitUnderTestL()
       
   176 	{
       
   177 	if (iUseTestPdpFsmInterface)
       
   178 		{
       
   179 		CreateEtelDriverL();
       
   180 		}
       
   181 	else
       
   182 		{
       
   183 		CreatePdpFsmL();
       
   184 		}
       
   185 	}
       
   186 
       
   187 /**
       
   188  Create and initialize the SPUDTEL
       
   189  */
       
   190 void CInputRequestListener::CreateEtelDriverL()
       
   191 	{
       
   192 	iEtelDriver = NewEtelDriverInputL();
       
   193 	
       
   194 	iPdpFsmInterfaceTest = new(ELeave)CPdpFsmInterfaceTest(*this);
       
   195 
       
   196 	iEtelDriver->OpenL(*iPdpFsmInterfaceTest);
       
   197 	iPdpFsmInterfaceTest->OpenL(NULL, SimTsyName());
       
   198 	
       
   199 	for (TContextId i = 0; i < KMaxPdpContexts; i++)
       
   200 		{
       
   201 		iEtelDriver->CreatePdpL(i);
       
   202 		}
       
   203 	}
       
   204 
       
   205 /**
       
   206  Create and initialize the SPUD FSM
       
   207  */
       
   208 void CInputRequestListener::CreatePdpFsmL()
       
   209 	{
       
   210 	iPdpFsmInterface = new(ELeave)CPdpFsmInterface();
       
   211 	iPdpFsmInterface->OpenL(iSpudManInterface, SimTsyName());
       
   212 	}
       
   213 
       
   214 /**
       
   215  Delete and cleanup and resources associated with SPUDTEL and SPUDFSM
       
   216  */
       
   217 void CInputRequestListener::DeleteUnitUnderTest()
       
   218 	{
       
   219 	if (iEtelDriver)
       
   220 		{
       
   221 		iEtelDriver->Close();
       
   222 		delete iEtelDriver;
       
   223 		iEtelDriver = NULL;
       
   224 		}
       
   225 		
       
   226 	if (iPdpFsmInterfaceTest)
       
   227 		{
       
   228 		iPdpFsmInterfaceTest->Close();
       
   229 		delete iPdpFsmInterfaceTest;
       
   230 		iPdpFsmInterfaceTest = NULL;
       
   231 		}
       
   232 
       
   233 	if (iPdpFsmInterface)
       
   234 		{
       
   235 		iPdpFsmInterface->Close();
       
   236 		delete iPdpFsmInterface;
       
   237 		iPdpFsmInterface = NULL;
       
   238 		}
       
   239 	}