datacommsserver/esockserver/test/TE_EsockTestSteps/src/EsockTestBase.cpp
changeset 0 dfb7c4ff071f
child 1 21d2ab05f085
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     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 //
       
    15 
       
    16 /**
       
    17  @file EsockTestBase.cpp
       
    18 */
       
    19 
       
    20 #include <e32debug.h>
       
    21 #include "EsockTestBase.h"
       
    22 #include <e32std.h>
       
    23 #include <commdbconnpref.h>
       
    24 #include <cs_subconevents.h>
       
    25 #include <es_prot.h>
       
    26 #include <comms-infras/esock_params.h>
       
    27 #include <dummynif_params.h>
       
    28 
       
    29 #include <comms-infras/es_parameterbundle.h>
       
    30 #include <comms-infras/provinfoqueryset.h>
       
    31 #include "ConnectionServer.TestSteps.h"
       
    32 
       
    33 #include <dummynifvar.h>
       
    34 
       
    35 
       
    36 #ifdef _DEBUG
       
    37 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    38 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    39 _LIT(KSpecAssert_ESockTestEsckTst, "ESockTestEsckTst");
       
    40 #endif
       
    41 
       
    42 static const TInt KProtocolInetDummy = 253;
       
    43 
       
    44 // Temporary measure to configure the rconnserv stuff before its backported to 9.4
       
    45 
       
    46 using namespace ConnectionServ;
       
    47 
       
    48 
       
    49 namespace ConnectionServ
       
    50 {
       
    51 	class RConnectionServ;
       
    52 	class CConnectionServParameterBundle;
       
    53 }
       
    54 
       
    55 class CConnServStatusQuery : public CActive
       
    56 	{
       
    57 public:
       
    58 	CConnServStatusQuery(ConnectionServ::RConnectionServ* aConnServ);
       
    59 	static CConnServStatusQuery* NewLC(	ConnectionServ::RConnectionServ* aConnServ,
       
    60 							const ConnectionServ::CConnectionServParameterBundle& aQueryBundle,
       
    61 							ConnectionServ::CConnectionServParameterBundle& aStatusBundle);
       
    62 	void ConstructL(const ConnectionServ::CConnectionServParameterBundle& aQueryBundle,
       
    63 					ConnectionServ::CConnectionServParameterBundle& aStatusBundle);
       
    64 	void RunL();
       
    65 	void DoCancel();
       
    66 
       
    67 	TInt ErrCode() const { return iStatus.Int(); }
       
    68 
       
    69 public:	
       
    70 	ConnectionServ::RConnectionServ* iConnServ;
       
    71 	};
       
    72 
       
    73 
       
    74 CConnServStatusQuery::CConnServStatusQuery(RConnectionServ* aConnServ)
       
    75 	: CActive(0), iConnServ(aConnServ)
       
    76 		{
       
    77 		}
       
    78 
       
    79 CConnServStatusQuery* CConnServStatusQuery::NewLC(	ConnectionServ::RConnectionServ* aConnServ,
       
    80 									const ConnectionServ::CConnectionServParameterBundle& aQueryBundle,
       
    81 									ConnectionServ::CConnectionServParameterBundle& aStatusBundle)
       
    82 	{
       
    83 	CConnServStatusQuery* inst = new CConnServStatusQuery(aConnServ);
       
    84 	CleanupStack::PushL(inst);
       
    85 	inst->ConstructL(aQueryBundle, aStatusBundle);
       
    86 	return inst;
       
    87 	}
       
    88 
       
    89 void CConnServStatusQuery::ConstructL(const ConnectionServ::CConnectionServParameterBundle& aQueryBundle,
       
    90 									ConnectionServ::CConnectionServParameterBundle& aStatusBundle)
       
    91 	{
       
    92 	iConnServ->AccessPointStatusQuery(aQueryBundle, aStatusBundle, iStatus );
       
    93 
       
    94 	// add self to scheduler
       
    95 	CActiveScheduler::Add(this);
       
    96 	SetActive();
       
    97 	}
       
    98 	
       
    99 
       
   100 void CConnServStatusQuery::RunL()
       
   101 	{
       
   102 	CActiveScheduler::Current()->Stop();
       
   103 	}
       
   104 
       
   105 void CConnServStatusQuery::DoCancel()
       
   106 	{
       
   107 	iConnServ->CancelAccessPointStatusQuery();
       
   108 	}
       
   109 	
       
   110 	
       
   111 
       
   112 //
       
   113 // TMigrateToPreferredCarrierParams - container for parameters for accepting a 
       
   114 // move for mobility
       
   115 //
       
   116 
       
   117 void TMigrateToPreferredCarrierParams::Reset()
       
   118 	{
       
   119 	iName.Set(KNullDesC);
       
   120 	iMobilityApiName.Set(KNullDesC);
       
   121 	}
       
   122 
       
   123 
       
   124 //
       
   125 // TCompareIntegersParams - parameters for comparing to saved integer values
       
   126 //
       
   127 void TCompareIntegersParams::Reset()
       
   128 	{
       
   129 	iValue1.Set(KNullDesC);
       
   130 	iValue2.Set(KNullDesC);
       
   131     iDifference = 0;
       
   132 	}
       
   133 
       
   134 //
       
   135 //TSocketDataCheckParams - container for parameters for checking data on a socket
       
   136 void TSocketDataCheckParams::Reset()
       
   137 	{
       
   138 	iSocketCheckName.Set(KNullDesC);
       
   139     iSocketName.Set(KNullDesC);
       
   140     iTransformType = ETransformDataNone;
       
   141     iErrorExpected = EFalse;
       
   142 	}
       
   143 	
       
   144 //
       
   145 //TSocketServerNumProtocolsParams - container for parameters for checking the number of procotols on a socket server instance
       
   146 
       
   147 void TSocketServerNumProtocolsParams::Reset()
       
   148 	{
       
   149 	iSocketServName.Set(KNullDesC);
       
   150 	iNumberExpected = 0;
       
   151 	iSavedAsName.Set(KNullDesC);
       
   152 	iExpected = EFalse;
       
   153 	iToBeSaved = EFalse;
       
   154 	}
       
   155 
       
   156 void TSocketServStartStopProtocolParams::Reset()
       
   157 	{
       
   158 	iSocketServName.Set(KNullDesC);
       
   159 	iAddrFamily = 0;
       
   160 	iProtocol = 0;
       
   161 	iSockType = 0;
       
   162 	}
       
   163 
       
   164 //
       
   165 //TRSocketParams - container for parameters (from an .ini file)
       
   166 //needed for operations on a sockets
       
   167 
       
   168 void TRSocketParams::Reset()
       
   169     {
       
   170     iSockServName.Set(KNullDesC);
       
   171     iConnectionName.Set(KNullDesC);
       
   172     iSocketName.Set(KNullDesC);
       
   173     iSubconnectionName.Set(KNullDesC);
       
   174 
       
   175     iSocketType = 0;
       
   176    	iProtocol = 0;
       
   177 	iPacketSize = 0;
       
   178 	iNrOfPackets = 0;
       
   179 	iLocalIP.FillZ();
       
   180    	iRemoteIP.FillZ();
       
   181    	iShutdownType = (RSocket::TShutdown)0;
       
   182 
       
   183     // Payload colouring
       
   184     iPayloadColouringIsEnabled = EFalse;
       
   185     iPayloadColour = 0;
       
   186     }
       
   187 
       
   188 void TRSocketGetOptParams::Reset()
       
   189 	{
       
   190     iSocketName.Set(KNullDesC);
       
   191 	iOptionName = 0;
       
   192 	iOptionLevel = 0;
       
   193 	iExpectedOptionOutputText.Set(KNullDesC);
       
   194 	iTextExpected = EFalse;
       
   195 	iValueExpected = EFalse;
       
   196 	}
       
   197 
       
   198 void TRSocketIoctlParams::Reset()
       
   199 	{
       
   200     iSocketName.Set(KNullDesC);
       
   201 	iIoctlCommand = 0;
       
   202 	iIoctlLevel = 0;
       
   203 	iExpectedIoctlOutput.Set(KNullDesC);
       
   204 	}
       
   205 
       
   206 TProtocolDescriptionParams::TProtocolDescriptionParams()
       
   207 	{
       
   208 	Mem::FillZ(this, sizeof(this));
       
   209 	}
       
   210 
       
   211 void TProtocolDescriptionParams::Reset()
       
   212 	{
       
   213 	iValuesGiven.Reset();
       
   214 	}
       
   215 
       
   216 void TProtocolDescriptionParams::TProtocolDescParamsExpected::Reset()
       
   217 	{
       
   218 	iName = EFalse;
       
   219 	iAddrFamily = EFalse;
       
   220 	iProtocol = EFalse;
       
   221 	iSockType = EFalse;
       
   222 	iVersion = EFalse;
       
   223 	iByteOrder = EFalse;
       
   224 	iServiceInfo = EFalse;
       
   225 	iNamingServices = EFalse;
       
   226 	iSecurity = EFalse;
       
   227 	iMessageSize = EFalse;
       
   228 	}
       
   229 
       
   230 TBool TProtocolDescriptionParams::MatchesExpected(TProtocolDesc& aProtocolDescription)
       
   231 	{
       
   232 	TBool verdict = ETrue;
       
   233 	
       
   234 	// Default to pass and then just need to find a single one that does not match
       
   235 	if(iValuesGiven.iName && (iValues.iName != aProtocolDescription.iName)) verdict = EFalse;
       
   236 	if(iValuesGiven.iAddrFamily && (iValues.iAddrFamily != aProtocolDescription.iAddrFamily)) verdict = EFalse;
       
   237 	if(iValuesGiven.iProtocol && (iValues.iProtocol != aProtocolDescription.iProtocol)) verdict = EFalse;
       
   238 	if(iValuesGiven.iSockType && (iValues.iSockType != aProtocolDescription.iSockType)) verdict = EFalse;
       
   239 	if(iValuesGiven.iVersion &&
       
   240 		(
       
   241 			iValues.iVersion.iMajor != aProtocolDescription.iVersion.iMajor ||
       
   242 			iValues.iVersion.iMinor != aProtocolDescription.iVersion.iMinor ||
       
   243 			iValues.iVersion.iBuild != aProtocolDescription.iVersion.iBuild
       
   244 		))
       
   245 		verdict = EFalse;
       
   246 	if(iValuesGiven.iByteOrder && (iValues.iByteOrder != aProtocolDescription.iByteOrder)) verdict = EFalse;
       
   247 	if(iValuesGiven.iServiceInfo && (iValues.iServiceInfo != aProtocolDescription.iServiceInfo)) verdict = EFalse;
       
   248 	if(iValuesGiven.iNamingServices && (iValues.iNamingServices != aProtocolDescription.iNamingServices)) verdict = EFalse;
       
   249 	if(iValuesGiven.iSecurity && (iValues.iSecurity != aProtocolDescription.iSecurity)) verdict = EFalse;
       
   250 	if(iValuesGiven.iMessageSize && (iValues.iMessageSize != aProtocolDescription.iMessageSize)) verdict = EFalse;
       
   251 
       
   252 	return verdict;		
       
   253 	}
       
   254 
       
   255 _LIT(KName, "Name");
       
   256 _LIT(KAddrFamily, "AddrFamily");
       
   257 _LIT(KProtocol, "Protocol");
       
   258 _LIT(KSockType, "SockType");
       
   259 _LIT(KVersionMajor, "VersionMajor");
       
   260 _LIT(KVersionMinor, "VersionMinor");
       
   261 _LIT(KVersionBuild, "VersionBuild");
       
   262 _LIT(KByteOrder, "ByteOrder");
       
   263 _LIT(KServiceInfo, "ServiceInfo");
       
   264 _LIT(KNamingServices, "NamingServices");
       
   265 _LIT(KSecurity, "Security");
       
   266 _LIT(KMessageSize, "MessageSize");
       
   267 
       
   268 TInt TProtocolDescriptionParams::FetchDescription(TProtocolDescriptionParams& aParams, CTestStep& aTestStep)
       
   269 	{
       
   270     // Protocol name
       
   271     TPtrC name;
       
   272 	if (aTestStep.GetStringFromConfig(aTestStep.ConfigSection(), KName, name) == 1)
       
   273         {
       
   274 		aParams.iValues.iName.Copy(name);
       
   275 		aParams.iValuesGiven.iName = ETrue;
       
   276         }
       
   277 
       
   278 	// Address family
       
   279 	if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KAddrFamily, (TInt&)aParams.iValues.iAddrFamily) == 1)
       
   280         {
       
   281 		aParams.iValuesGiven.iAddrFamily = ETrue;
       
   282         }
       
   283 
       
   284 	// Protocol
       
   285 	if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KProtocol, (TInt&)aParams.iValues.iProtocol) == 1)
       
   286         {
       
   287 		aParams.iValuesGiven.iProtocol = ETrue;
       
   288         }
       
   289 
       
   290 	// Socket type
       
   291 	if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KSockType, (TInt&)aParams.iValues.iSockType) == 1)
       
   292         {
       
   293 		aParams.iValuesGiven.iSockType = ETrue;
       
   294         }
       
   295 
       
   296 	// Version
       
   297 	TInt versionMajor;
       
   298 	if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KVersionMajor, versionMajor) == 1)
       
   299         {
       
   300 		aParams.iValues.iVersion.iMajor = (TInt8)versionMajor;
       
   301 
       
   302 		TInt versionMinor;
       
   303 		if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KVersionMinor, versionMinor) == 1)
       
   304 			{
       
   305 			aParams.iValues.iVersion.iMinor = (TInt8)versionMinor;
       
   306 
       
   307 			TInt versionBuild;
       
   308 			if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KVersionBuild, versionBuild) == 1)
       
   309 				{
       
   310 				aParams.iValues.iVersion.iBuild = (TInt16)versionBuild;
       
   311 
       
   312 				// Got all the version info
       
   313 				aParams.iValuesGiven.iVersion = ETrue;
       
   314 				}
       
   315 			}
       
   316         }
       
   317 
       
   318 	// Byte order
       
   319 	if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KByteOrder, (TInt&)aParams.iValues.iByteOrder) == 1)
       
   320         {
       
   321 		aParams.iValuesGiven.iByteOrder = ETrue;
       
   322         }
       
   323 
       
   324 	// Service info
       
   325 	if (aTestStep.GetHexFromConfig(aTestStep.ConfigSection(), KServiceInfo, (TInt&)aParams.iValues.iServiceInfo) == 1)
       
   326         {
       
   327 		aParams.iValuesGiven.iServiceInfo = ETrue;
       
   328         }
       
   329 
       
   330 	// Naming services
       
   331 	if (aTestStep.GetHexFromConfig(aTestStep.ConfigSection(), KNamingServices, (TInt&)aParams.iValues.iNamingServices) == 1)
       
   332         {
       
   333 		aParams.iValuesGiven.iNamingServices = ETrue;
       
   334         }
       
   335 
       
   336 	// Security
       
   337 	if (aTestStep.GetHexFromConfig(aTestStep.ConfigSection(), KSecurity, (TInt&)aParams.iValues.iSecurity) == 1)
       
   338         {
       
   339 		aParams.iValuesGiven.iSecurity = ETrue;
       
   340         }
       
   341 
       
   342 	// Message size
       
   343 	if (aTestStep.GetIntFromConfig(aTestStep.ConfigSection(), KMessageSize, (TInt&)aParams.iValues.iMessageSize) == 1)
       
   344         {
       
   345 		aParams.iValuesGiven.iMessageSize = ETrue;
       
   346         }
       
   347 
       
   348 	return aParams.iValuesGiven.AllExpected() ? KErrNone : KErrNotFound;
       
   349 	}
       
   350 
       
   351 TBool TProtocolDescriptionParams::TProtocolDescParamsExpected::NoneExpected()
       
   352 	{
       
   353 	return (!iName && !iAddrFamily && !iProtocol && !iSockType && !iVersion && !iByteOrder && !iServiceInfo && !iNamingServices && !iSecurity && !iMessageSize) ?
       
   354 		ETrue :
       
   355 		EFalse;
       
   356 	}
       
   357 	
       
   358 TBool TProtocolDescriptionParams::TProtocolDescParamsExpected::AllExpected()
       
   359 	{
       
   360 	return (iName && iAddrFamily && iProtocol && iSockType && iVersion && iByteOrder && iServiceInfo && iNamingServices && iSecurity && iMessageSize) ?
       
   361 		ETrue :
       
   362 		EFalse;
       
   363 	}
       
   364 
       
   365 void TSocketProtocolDescriptionParams::Reset()
       
   366 	{
       
   367 	iSocketName.Set(KNullDesC);
       
   368 	iProtocolDescParams.Reset();
       
   369 	}
       
   370 
       
   371 void TSocketServFindProtocolParams::Reset()
       
   372 	{
       
   373 	iSocketServName.Set(KNullDesC);
       
   374 	iProtocolDescParams.Reset();
       
   375 	}
       
   376 
       
   377 void TSocketServGetProtocolInfoParams::Reset()
       
   378 	{
       
   379 	iSocketServName.Set(KNullDesC);
       
   380 	iProtocolIndex = 0;
       
   381 	iProtocolDescParams.Reset();
       
   382 	}
       
   383 
       
   384 
       
   385 //
       
   386 //TRConnectionParams - container for parameters (from an .ini file)
       
   387 //needed for operations on a connections
       
   388 
       
   389 void TRConnectionParams::Reset()
       
   390     {
       
   391     iSockServName.Set(KNullDesC);
       
   392     iConnectionName.Set(KNullDesC);
       
   393     iAttachToConnectionName.Set(KNullDesC);
       
   394 
       
   395 	iBearer = 0;
       
   396 	iIAP = 0;
       
   397 	iNET = 0;
       
   398 	iSNAP = 0;
       
   399 
       
   400     iConnStopType = (RConnection::TConnStopType)0;
       
   401     iConnAttachType = (RConnection::TConnAttachType)0;
       
   402     iStartWithOldPreferences = 0;
       
   403     iStartWithSnapPreferences = 0;
       
   404     iAsynch = EFalse;
       
   405     }
       
   406 
       
   407 //
       
   408 //TRSubConnectionParams - container for parameters (from an .ini file)
       
   409 //needed for operations on a subconnections
       
   410 
       
   411 void TRSubConnectionParams::Reset()
       
   412     {
       
   413     iSockServName.Set(KNullDesC);
       
   414 	iConnectionName.Set(KNullDesC);
       
   415 	iSubConnectionName.Set(KNullDesC);
       
   416 	iSocketName.Set(KNullDesC);
       
   417 
       
   418 	iSubConnectionParamsName.Set(KNullDesC);
       
   419 	iSubConnectionEventName.Set(KNullDesC);
       
   420 
       
   421     iSubConnType = (RSubConnection::TSubConnType)0;
       
   422     }
       
   423 
       
   424 //
       
   425 //TEsockTestEventContainer - encapsulates all necessary RConnection
       
   426 //or RSubConnection event data so that it can be conveniently stored in a map.
       
   427 
       
   428 void TEventContainerParams::Reset()
       
   429     {
       
   430     iEventName.Set(KNullDesC);
       
   431 	iSubConnectionName.Set(KNullDesC);
       
   432 	iConnectionName.Set(KNullDesC);
       
   433 	iAvailabilityExtName.Set(KNullDesC);
       
   434 	iConnectionManagerExtName.Set(KNullDesC);
       
   435 	iExtensionName.Set(KNullDesC);
       
   436 	iMobilityExtName.Set(KNullDesC);
       
   437 	iAllEvents = EFalse;
       
   438 	iGenericEvents = EFalse;
       
   439 	iEventMask = 0;
       
   440 	iTimeoutMiliSecs = 0;
       
   441     }
       
   442 
       
   443 TEsockTestEventContainer::~TEsockTestEventContainer()
       
   444     {
       
   445     iEventNotifBuf.Zero();
       
   446     }
       
   447 
       
   448 //
       
   449 // TEsockTestDataMonitoringEventContainer - encapsulates all necessary data monitoring
       
   450 // event data so that it can be conveniently stored in a map.    
       
   451 
       
   452 void TDataMonitorEventParams::Reset()
       
   453 	{
       
   454 	iEventName.Copy(KNullDesC);
       
   455 	iConnectionName.Set(KNullDesC);
       
   456 	iSubConnectionName.Set(KNullDesC);
       
   457 	iDataMonitorName.Set(KNullDesC);
       
   458 	
       
   459 	iDelta = 0;
       
   460 	iMinExpectedVolume = 0;
       
   461 	}
       
   462 
       
   463 TPtrC& TDataMonitorEventParams::ConnOrSubConnName()
       
   464 	{
       
   465 	if(iConnectionName.Length() > 0)
       
   466 		{
       
   467 		return iConnectionName;
       
   468 		}
       
   469 	else 
       
   470 		{
       
   471 		// We return this regardless and consider the default KNullDesC
       
   472 		// to represent an error
       
   473 		return iSubConnectionName;
       
   474 		}
       
   475 	}
       
   476 
       
   477 //
       
   478 //TRSimtsyEventParams - container for parameters (from an .ini file)
       
   479 void TSimTsyEventParams::Reset()
       
   480     {
       
   481 
       
   482 	iConnectionName.Set(KNullDesC);
       
   483 	iSimTsyEventName.Set(KNullDesC);
       
   484 	iEventName.Set(KNullDesC);
       
   485 	iEventKey=0;
       
   486 	iEventIndex=0;
       
   487 
       
   488     }
       
   489 
       
   490 
       
   491 //
       
   492 //CCEsockTestBase
       
   493 
       
   494 CCEsockTestBase::~CCEsockTestBase()
       
   495 	{
       
   496 	CleanAll();
       
   497 	}
       
   498 
       
   499 //
       
   500 //socket server functions library
       
   501 
       
   502 TInt CCEsockTestBase::CreateSocketServer(const TDesC& aSockServName)
       
   503 	{
       
   504     //check if this secket server hasn't been created already
       
   505     if (iSockServs.Find(aSockServName)!=NULL)
       
   506     	return KErrAlreadyExists;
       
   507 
       
   508     RSocketServ* ss = new RSocketServ;
       
   509     if (ss==NULL)
       
   510     	return KErrNoMemory;
       
   511 
       
   512 	TInt error = iSockServs.Add(ss,aSockServName);
       
   513 	if (error!=KErrNone)
       
   514 		delete ss;
       
   515 
       
   516 
       
   517 	return error;
       
   518 	}
       
   519 
       
   520 TInt CCEsockTestBase::ConnectSocketServer(const TDesC& aSockServName)
       
   521 	{
       
   522     //check if this secket server hasn't been created already
       
   523     RSocketServ* ss = iSockServs.Find(aSockServName);
       
   524     if (ss==NULL)
       
   525     	return KErrNotFound;
       
   526 
       
   527 	return ss->Connect();
       
   528 	}
       
   529 
       
   530 TInt CCEsockTestBase::CloseSocketServer(const TDesC& aSockServName)
       
   531 	{
       
   532     //check if this secket server hasn't been created already
       
   533     RSocketServ* ss = iSockServs.Find(aSockServName);
       
   534     if (ss==NULL)
       
   535     	return KErrNotFound;
       
   536 
       
   537 	ss->Close();
       
   538 	return KErrNone;
       
   539 	}
       
   540 
       
   541 TInt CCEsockTestBase::SocketServerNumProtocols(TSocketServerNumProtocolsParams& aParams, TInt& aNumProtocols)
       
   542 	{
       
   543     // Fetch the socket server instance which must already exist
       
   544     RSocketServ* ss = iSockServs.Find(aParams.iSocketServName);
       
   545     if (ss == NULL)
       
   546     	return KErrNotFound;
       
   547 
       
   548 	TInt error = ss->NumProtocols((TUint&)aNumProtocols);
       
   549 	if(error != KErrNone)
       
   550 		{
       
   551 		return error;
       
   552 		}
       
   553 	
       
   554 	if(aParams.iToBeSaved)
       
   555 		{
       
   556 		// If we are saving the value then do so
       
   557 		// If it exists already then update it
       
   558 		TInt* currentValue = NULL;
       
   559 		currentValue = iIntegerValues.Find(aParams.iSavedAsName);
       
   560 		if(currentValue != NULL)
       
   561 			{
       
   562 			*currentValue = aNumProtocols;
       
   563 			return KErrNone;
       
   564 			}
       
   565 
       
   566 		// Else create the new variable
       
   567 		currentValue = new TInt(aNumProtocols);
       
   568 		if (currentValue == NULL)
       
   569 			return KErrNoMemory;
       
   570 
       
   571 		error = iIntegerValues.Add(currentValue, aParams.iSavedAsName);
       
   572 		}
       
   573 
       
   574 	return error;
       
   575 	}
       
   576 
       
   577 TInt CCEsockTestBase::SocketServerFindProtocol(TSocketServFindProtocolParams& aParams, TProtocolDesc& aProtocolDescription)
       
   578 	{
       
   579     // Fetch the socket server instance which must already exist
       
   580     RSocketServ* ss = iSockServs.Find(aParams.iSocketServName);
       
   581     if (ss == NULL)
       
   582     	return KErrNotFound;
       
   583 
       
   584 	return ss->FindProtocol(aParams.iProtocolDescParams.iValues.iName, aProtocolDescription);
       
   585 	}
       
   586 
       
   587 TInt CCEsockTestBase::SocketServerGetProtocolInfo(TSocketServGetProtocolInfoParams& aParams, TProtocolDesc& aProtocolDescription)
       
   588 	{
       
   589     // Fetch the socket server instance which must already exist
       
   590     RSocketServ* ss = iSockServs.Find(aParams.iSocketServName);
       
   591     if (ss == NULL)
       
   592     	return KErrNotFound;
       
   593 
       
   594 	return ss->GetProtocolInfo(aParams.iProtocolIndex, aProtocolDescription);
       
   595 	}
       
   596 
       
   597 
       
   598 TInt CCEsockTestBase::SocketServerStartProtocol(TSocketServStartStopProtocolParams& aParams, TRequestStatus& aStatus)
       
   599 	{
       
   600     // Fetch the socket server instance which must already exist
       
   601     RSocketServ* ss = iSockServs.Find(aParams.iSocketServName);
       
   602     if (ss == NULL)
       
   603     	return KErrNotFound;
       
   604 
       
   605 	// Start the protocol
       
   606 	ss->StartProtocol(
       
   607 		aParams.iAddrFamily,
       
   608 		aParams.iSockType,
       
   609 		aParams.iProtocol,
       
   610 		aStatus);
       
   611 	return KErrNone;	
       
   612 	}
       
   613 
       
   614 
       
   615 TInt CCEsockTestBase::SocketServerStopProtocol(TSocketServStartStopProtocolParams& aParams, TRequestStatus& aStatus)
       
   616 	{
       
   617     // Fetch the socket server instance which must already exist
       
   618     RSocketServ* ss = iSockServs.Find(aParams.iSocketServName);
       
   619     if (ss == NULL)
       
   620     	return KErrNotFound;
       
   621 
       
   622 	// Stop the protocol
       
   623 	ss->StopProtocol(
       
   624 		aParams.iAddrFamily,
       
   625 		aParams.iSockType,
       
   626 		aParams.iProtocol,
       
   627 		aStatus);
       
   628 	return KErrNone;	
       
   629 	}
       
   630 
       
   631 
       
   632 TInt CCEsockTestBase::__DbgFailNext(const TDesC& aSockServName, TInt aCount)
       
   633 	{
       
   634 	RSocketServ* ss = iSockServs.Find(aSockServName);
       
   635     if (ss==NULL)
       
   636 		return KErrNotFound;
       
   637 
       
   638 	return ss->__DbgFailNext(aCount);
       
   639 	}	
       
   640 
       
   641 TBool CCEsockTestBase::__DbgCheckFailNext(const TDesC& aSockServName)
       
   642     {
       
   643 	RSocketServ* ss = iSockServs.Find(aSockServName);
       
   644     if (ss==NULL)
       
   645 		return KErrNotFound;
       
   646 
       
   647 	return ss->__DbgCheckFailNext();
       
   648     }
       
   649 
       
   650 
       
   651 //
       
   652 //connection server functions library
       
   653 TInt CCEsockTestBase::CreateConnectionServer(const TDesC& aConnectionServName)
       
   654 	{
       
   655     if (iConnectionServs.Find(aConnectionServName) != NULL)
       
   656     	return KErrAlreadyExists;
       
   657 
       
   658     RConnectionServ* connServ = new RConnectionServ;
       
   659     if (connServ == NULL)
       
   660     	return KErrNoMemory;
       
   661 
       
   662 	TInt error = iConnectionServs.Add(connServ, aConnectionServName);
       
   663 	if (error != KErrNone)
       
   664 		delete connServ;
       
   665 
       
   666 	return error;
       
   667 	}
       
   668 
       
   669 TInt CCEsockTestBase::ConnectConnectionServer(const TDesC& aConnectionServName, TUint aTierId)
       
   670 	{
       
   671     //check if this secket server hasn't been created already
       
   672     RConnectionServ* connServ = iConnectionServs.Find(aConnectionServName);
       
   673     if (connServ == NULL)
       
   674     	return KErrNotFound;
       
   675 
       
   676 	return connServ->Connect(aTierId);
       
   677 	}
       
   678 
       
   679 TInt CCEsockTestBase::CloseConnectionServer(const TDesC& aConnectionServName)
       
   680 	{
       
   681     // Find the connection server we are referring to
       
   682     RConnectionServ* connServ = iConnectionServs.Find(aConnectionServName);
       
   683     if (connServ == NULL)
       
   684     	return KErrNotFound;
       
   685 
       
   686 	connServ->Close();
       
   687 	return KErrNone;
       
   688 	}
       
   689 
       
   690 TInt CCEsockTestBase::ConnectionAccessPointStatusQuery(
       
   691 		const TDesC& aConnectionServName,
       
   692 		const ConnectionServ::CConnectionServParameterBundle& aQueryBundle,
       
   693 		ConnectionServ::CConnectionServParameterBundle& aResultBundle)
       
   694 	{
       
   695 	RConnectionServ* connServ = iConnectionServs.Find(aConnectionServName);
       
   696 
       
   697 	if(connServ == NULL)
       
   698 		return KErrNotFound;
       
   699 		
       
   700 	// Need a local active scheduler for the RConnectionServ API
       
   701 	CActiveScheduler* as = new(ELeave) CActiveScheduler;
       
   702 	CleanupStack::PushL(as);
       
   703 	CActiveScheduler::Install(as);
       
   704 
       
   705 	CConnServStatusQuery* sq = CConnServStatusQuery::NewLC(connServ, aQueryBundle, aResultBundle);
       
   706 
       
   707 	TRAP_IGNORE(CActiveScheduler::Start())
       
   708 
       
   709 	TInt res2 = sq->ErrCode();
       
   710 
       
   711 	CleanupStack::PopAndDestroy(sq);	
       
   712 	CleanupStack::PopAndDestroy(as);
       
   713 
       
   714 	return res2;
       
   715 	}
       
   716 
       
   717 class CMyTimer : public CTimer
       
   718 	{
       
   719 public:
       
   720 	static CMyTimer* NewL()
       
   721 		{
       
   722 		CMyTimer* timer = new CMyTimer();
       
   723 		if(timer)
       
   724 			{
       
   725 			timer->ConstructL();
       
   726 			CActiveScheduler::Add(timer);
       
   727 			}
       
   728 		return timer;
       
   729 		}
       
   730 		
       
   731 	CMyTimer() : CTimer(EPriorityStandard)
       
   732 		{
       
   733 		}
       
   734 	void RunL()
       
   735 		{
       
   736 		// Simply stop the scheduler as this will force the cancellation we are after
       
   737 		CActiveScheduler::Current()->Stop();		
       
   738 		}
       
   739 	};
       
   740 
       
   741 const TInt KHalfASecondInMicroSeconds = 500000;
       
   742 
       
   743 TInt CCEsockTestBase::CancelAccessPointStatusQuery(
       
   744 		const TDesC& aConnectionServName,
       
   745 		const ConnectionServ::CConnectionServParameterBundle& aQueryBundle,
       
   746 		ConnectionServ::CConnectionServParameterBundle& aResultBundle)
       
   747 	{
       
   748 	RConnectionServ* connServ = iConnectionServs.Find(aConnectionServName);
       
   749 
       
   750 	if(connServ == NULL)
       
   751 		return KErrNotFound;
       
   752 		
       
   753 	// Need a local active scheduler for the RConnectionServ API
       
   754 	CActiveScheduler* as = new(ELeave) CActiveScheduler;
       
   755 	CleanupStack::PushL(as);
       
   756 	CActiveScheduler::Install(as);
       
   757 
       
   758 	// Create a timer that will complete almost immediately and stop the scheduler
       
   759 	// thereby canceling the query while it is in progress
       
   760 	// This all requires a long running query
       
   761 	CMyTimer* timer = CMyTimer::NewL();
       
   762 	CleanupStack::PushL(timer);
       
   763 	timer->After(KHalfASecondInMicroSeconds);
       
   764 	
       
   765 	// Create active object to manage the query
       
   766 	CConnServStatusQuery* sq = CConnServStatusQuery::NewLC(connServ, aQueryBundle, aResultBundle);
       
   767 	
       
   768 	// Start the scheduler
       
   769 	TRAP_IGNORE(CActiveScheduler::Start())
       
   770 
       
   771 	sq->Cancel();
       
   772 	timer->Cancel();
       
   773 
       
   774 	// Check that the cancel status is what we expected
       
   775 	TInt res2 = sq->ErrCode();
       
   776 
       
   777 	CleanupStack::PopAndDestroy(sq);
       
   778 	CleanupStack::PopAndDestroy(timer);
       
   779 	CleanupStack::PopAndDestroy(as);
       
   780 	
       
   781 	return res2;
       
   782 	}
       
   783 
       
   784 
       
   785 //
       
   786 //socket functions library
       
   787 
       
   788 RSocket* CCEsockTestBase::FindSocket(const TDesC& aSocketName)
       
   789     {
       
   790     return iSocks.Find(aSocketName);
       
   791     }
       
   792 
       
   793 TInt CCEsockTestBase::CreateSocket(const TDesC& aSocketName)
       
   794 	{
       
   795     //check if this socket hasn't been created already
       
   796     if (iSocks.Find(aSocketName)!=NULL)
       
   797     	return KErrAlreadyExists;
       
   798 
       
   799     RSocket* s = new RSocket;
       
   800     if (s==NULL)
       
   801     	return KErrNoMemory;
       
   802 
       
   803 	TInt error = iSocks.Add(s,aSocketName);
       
   804 	if (error!=KErrNone)
       
   805 		delete s;
       
   806 
       
   807 	return error;
       
   808 	}
       
   809 
       
   810 TInt CCEsockTestBase::OpenSocket(const TRSocketParams& aParams)
       
   811 	{
       
   812     RSocketServ* ss = iSockServs.Find(aParams.iSockServName);
       
   813     if (ss==NULL)
       
   814 		return KErrNotFound;
       
   815 
       
   816     RSocket* s = iSocks.Find(aParams.iSocketName);
       
   817 	if (s==NULL)
       
   818 		return KErrNotFound;
       
   819 
       
   820     TInt error;
       
   821 
       
   822     //try to find the connection (if specified)
       
   823     if (aParams.iConnectionName.Length()>0)
       
   824     	{
       
   825 		RConnection* c = iConns.Find(aParams.iConnectionName);
       
   826 		if (c==NULL)
       
   827 			return KErrNotFound;
       
   828 		error = s->Open(*ss, KAfInet, aParams.iSocketType, aParams.iProtocol, *c);
       
   829 		}
       
   830 	else if (aParams.iSubconnectionName.Length()>0)
       
   831     	{
       
   832 		RSubConnection* sc = iSubConns.Find(aParams.iSubconnectionName);
       
   833 		if (sc==NULL)
       
   834 			{
       
   835 			return KErrNotFound;
       
   836 			}
       
   837 		error = s->Open(*ss, KAfInet, aParams.iSocketType, aParams.iProtocol, *sc);
       
   838 		}
       
   839 	else if (aParams.iProtocolName.Length()>0)
       
   840 		{
       
   841 		error = s->Open(*ss,aParams.iProtocolName);
       
   842 		}
       
   843 	else
       
   844 		{
       
   845 		error = s->Open(*ss, KAfInet, aParams.iSocketType, aParams.iProtocol);
       
   846 		}
       
   847 
       
   848 
       
   849 	return error;
       
   850 	}
       
   851 
       
   852 TInt CCEsockTestBase::BindSocket(const TRSocketParams& /*aParams*/)
       
   853 	{
       
   854     return KErrNotSupported;
       
   855     /*
       
   856     RSocket* s = iSocks.Find(aSockeSParams.iSocketName);
       
   857 	if (s==NULL)
       
   858 		return KErrNotFound;
       
   859 
       
   860 	TInt error = KErrNone;
       
   861 	if (aSockeSParams.iProtocol==KProtocolInetUdp)
       
   862 	    error = s->SetOpt(KSoUdpSynchronousSend,KSolInetUdp,1);
       
   863 	if (error!=KErrNone)
       
   864 		return error;
       
   865 
       
   866 	//bind to Local address for TCP or UDP
       
   867 	return s->Bind(aSockeSParams.iLocalIP);
       
   868 	*/
       
   869 	}
       
   870 
       
   871 TInt CCEsockTestBase::ConnectSocket(TRSocketParams& aParams, TRequestStatus& aRequestStatus)
       
   872 	{
       
   873     RSocket* s = iSocks.Find(aParams.iSocketName);
       
   874 	if (s==NULL)
       
   875 	    {
       
   876 		return KErrNotFound;
       
   877 	    }
       
   878 
       
   879     TInt err = KErrNone;
       
   880 
       
   881     if (aParams.iProtocol==KProtocolInetUdp)
       
   882         {
       
   883         err = s->SetOpt(KSoUdpSynchronousSend,KSolInetUdp,1);
       
   884         if (err != KErrNone)
       
   885             {
       
   886             return err;
       
   887             }
       
   888         }
       
   889 
       
   890     if (!aParams.iLocalIP.IsUnspecified() || !aParams.iLocalIP.IsWildPort())
       
   891         {
       
   892         err = s->Bind(aParams.iLocalIP);
       
   893         }
       
   894 
       
   895     if (err == KErrNone)
       
   896         {
       
   897         s->Connect(aParams.iRemoteIP, aRequestStatus);
       
   898         }
       
   899 
       
   900     return err;
       
   901 	}
       
   902 
       
   903 TInt CCEsockTestBase::CancelConnectSocket(const TRSocketParams& aParams)
       
   904 	{
       
   905     RSocket* s = iSocks.Find(aParams.iSocketName);
       
   906 	if (s==NULL)
       
   907 		return KErrNotFound;
       
   908 
       
   909     s->CancelConnect();
       
   910     return KErrNone;
       
   911 	}
       
   912 
       
   913 void CCEsockTestBase::SendAndReceiveDataL(const TRSocketParams& aParams)
       
   914 	{
       
   915     RSocket* s = iSocks.Find(aParams.iSocketName);
       
   916 	if (s==NULL)
       
   917 		User::Leave(KErrNotFound);
       
   918 
       
   919 	TInt recvCount = 0;
       
   920 	TRequestStatus stat;
       
   921 	TBuf8<50> Data;
       
   922 
       
   923 	//set up buffers
       
   924 	HBufC8* writebuf = HBufC8::NewMaxLC(aParams.iPacketSize);
       
   925 	HBufC8* readbuf  = HBufC8::NewMaxLC(aParams.iPacketSize);
       
   926 	
       
   927 	// In the case of armv5, HBufC8 MaxLength is set as 1504 or 1512
       
   928 	// To sort it out we use TPtr8(TUint8* ,MaxLenghth) constructor
       
   929 	// instead of using
       
   930 	// TPtr8 ptrwritebuf = writebuf->Des();
       
   931 	// TPtr8 ptrreadbuf = readbuf->Des();
       
   932 	TPtr8 ptrwritebuf(const_cast<TUint8*>(writebuf->Ptr()), aParams.iPacketSize);
       
   933 	TPtr8 ptrreadbuf(const_cast<TUint8*>(readbuf->Ptr()), aParams.iPacketSize);
       
   934 	
       
   935 	// NewMaxLC may give a max size bigger than specified. Make sure length and max length are in sync so that
       
   936 	// the Read will complete. For example, NewMaxLC(1500) may give back a buffer 1504 as the max size. if you Write
       
   937 	// then Read on that, it'll write the length (1500) but try to read the max length (1504). this'll never complete
       
   938 	// because we'll only get back as many bytes as we wrote the the echo server.
       
   939 	ptrwritebuf.SetLength(ptrwritebuf.MaxLength());
       
   940 	ptrreadbuf.SetLength(ptrreadbuf.MaxLength());
       
   941 
       
   942     if (aParams.iProtocol==KProtocolInetTcp)
       
   943         {
       
   944    		for (TInt i = 0; i < aParams.iNrOfPackets; i++)
       
   945     		{
       
   946 	    	// initialise data
       
   947 		    Data.Format(_L8("TCP-packet:%d helloworld"),i);
       
   948 		    ptrwritebuf.Repeat( Data );
       
   949 
       
   950 		    // write data
       
   951 		    s->Write(ptrwritebuf,stat);
       
   952 		    User::WaitForRequest(stat);
       
   953 		    User::LeaveIfError(stat.Int());
       
   954 
       
   955 		    // read data
       
   956 		    s->Read(ptrreadbuf, stat);
       
   957 		    User::WaitForRequest(stat);
       
   958 			User::LeaveIfError(stat.Int());
       
   959 
       
   960 		    // compare the data
       
   961 		    if (ptrwritebuf.Compare(ptrreadbuf) != 0)
       
   962 		    	User::Leave(KErrGeneral);
       
   963 
       
   964 		    recvCount+=ptrreadbuf.Length();
       
   965 	    	}
       
   966 		}
       
   967 	else if (aParams.iProtocol==KProtocolInetUdp || aParams.iProtocol == KProtocolInetDummy)
       
   968 		{
       
   969         for (TInt i = 0; i < aParams.iNrOfPackets; i++)
       
   970 		    {
       
   971 		    // initialise data
       
   972 		    Data.Format(_L8("UDP-packet:%d helloworld"),i);
       
   973 		    ptrwritebuf.Repeat( Data );
       
   974 
       
   975 		    // If we are colouring the payload then first prefix outgoing payload with command byte to tell the stack so
       
   976 		    if(aParams.iPayloadColouringIsEnabled)
       
   977 		    	{
       
   978 				ptrwritebuf[0] = 0xF9; // KColourDataByLinkTierAccessPointId; TODO_CDG
       
   979 				}
       
   980 		    
       
   981 		    // write data
       
   982 		    s->Send(ptrwritebuf, 0, stat);
       
   983 		    User::WaitForRequest(stat);
       
   984 		    User::LeaveIfError(stat.Int());
       
   985 
       
   986 		    // If the returned data will be coloured by the IP stack for test purposes
       
   987 		    // then we had better change what we compare it with
       
   988 		    if(aParams.iPayloadColouringIsEnabled)
       
   989 		    	{
       
   990 		    	ptrwritebuf[0] += static_cast<TUint8>(aParams.iPayloadColour);
       
   991 				}
       
   992 		    
       
   993 		    s->Recv(ptrreadbuf, 0, stat);
       
   994 		    User::WaitForRequest(stat);
       
   995 		    User::LeaveIfError(stat.Int());
       
   996 
       
   997 		    // compare the data
       
   998 		    if (ptrwritebuf.Compare(ptrreadbuf) != 0 )
       
   999 		    	User::Leave(KErrGeneral);
       
  1000 
       
  1001 		    recvCount += ptrreadbuf.Length();
       
  1002 		    }
       
  1003 		}
       
  1004 	else
       
  1005         User::Leave(KErrNotFound);
       
  1006 
       
  1007     CleanupStack::PopAndDestroy(2, writebuf);	//	writebuf and readbuf
       
  1008 
       
  1009 	// check the total received (95 per cent is allowable for us)
       
  1010 	if (recvCount*aParams.iPacketSize < (0.95*(aParams.iNrOfPackets*aParams.iPacketSize)))
       
  1011 		User::Leave(KErrGeneral);
       
  1012 	}
       
  1013 
       
  1014 TInt CCEsockTestBase::CloseSocket(const TDesC& aSocketName)
       
  1015 	{
       
  1016     RSocket* s = iSocks.Find(aSocketName);
       
  1017 	if (s==NULL)
       
  1018 		return KErrNotFound;
       
  1019 
       
  1020 	s->Close();
       
  1021     return KErrNone;
       
  1022 	}
       
  1023 
       
  1024 TInt CCEsockTestBase::ShutdownSocket(const TRSocketParams& aParams, TRequestStatus& aRequestStatus)
       
  1025 	{
       
  1026     RSocket* s = iSocks.Find(aParams.iSocketName);
       
  1027 	if (s==NULL)
       
  1028 		return KErrNotFound;
       
  1029 
       
  1030 	s->Shutdown(aParams.iShutdownType,aRequestStatus);
       
  1031     return KErrNone;
       
  1032 	}
       
  1033 
       
  1034 TInt CCEsockTestBase::IoctlSocket(const TRSocketIoctlParams& aParams, TDes8& aIoctlOutput, TRequestStatus& aRequestStatus)
       
  1035 	{
       
  1036     RSocket* s = iSocks.Find(aParams.iSocketName);
       
  1037 	if (s == NULL)
       
  1038 		return KErrNotFound;
       
  1039 
       
  1040 	s->Ioctl(aParams.iIoctlCommand, aRequestStatus, &aIoctlOutput, aParams.iIoctlLevel);
       
  1041 	User::WaitForRequest(aRequestStatus);
       
  1042 
       
  1043     return KErrNone;
       
  1044 	}
       
  1045 
       
  1046 TInt CCEsockTestBase::GetOptSocket(const TRSocketGetOptParams& aParams, TDes8& aGetOptOutput)
       
  1047 	{
       
  1048     RSocket* s = iSocks.Find(aParams.iSocketName);
       
  1049 	if (s == NULL)
       
  1050 		return KErrNotFound;
       
  1051 
       
  1052 	return s->GetOpt(aParams.iOptionName, aParams.iOptionLevel, aGetOptOutput);
       
  1053 	}
       
  1054 
       
  1055 TInt CCEsockTestBase::GetOptSocket(const TRSocketGetOptParams& aParams, TInt& aGetOptOutput)
       
  1056 	{
       
  1057     RSocket* s = iSocks.Find(aParams.iSocketName);
       
  1058 	if (s == NULL)
       
  1059 		return KErrNotFound;
       
  1060 
       
  1061 	return s->GetOpt(aParams.iOptionName, aParams.iOptionLevel, aGetOptOutput);
       
  1062 	}
       
  1063 
       
  1064 TInt CCEsockTestBase::ProtocolDescription(
       
  1065 	const TSocketProtocolDescriptionParams& aParams,
       
  1066 	TProtocolDesc& aProtocolDescriptionOutput)
       
  1067 	{
       
  1068     RSocket* s = iSocks.Find(aParams.iSocketName);
       
  1069 	if (s == NULL)
       
  1070 		return KErrNotFound;
       
  1071 
       
  1072 	return s->Info(aProtocolDescriptionOutput);
       
  1073 	}
       
  1074 
       
  1075 
       
  1076 //
       
  1077 //connection functions library
       
  1078 
       
  1079 RConnection* CCEsockTestBase::FindConnection(const TDesC& aConnectionName)
       
  1080     {
       
  1081     return iConns.Find(aConnectionName);
       
  1082     }
       
  1083 
       
  1084 TInt CCEsockTestBase::CreateConnection(const TDesC& aConnectionName)
       
  1085 	{
       
  1086     //check if this connection hasn't been created already
       
  1087     if (iConns.Find(aConnectionName)!=NULL)
       
  1088     	return KErrAlreadyExists;
       
  1089 
       
  1090     RConnection* c = new RConnection;
       
  1091     if (c==NULL)
       
  1092     	return KErrNoMemory;
       
  1093 
       
  1094 	TInt error = iConns.Add(c,aConnectionName);
       
  1095 	if (error!=KErrNone)
       
  1096 		delete c;
       
  1097 
       
  1098 	return error;
       
  1099 	}
       
  1100 
       
  1101 TInt CCEsockTestBase::OpenConnection(const TRConnectionParams& aParams)
       
  1102 	{
       
  1103     RSocketServ* ss = iSockServs.Find(aParams.iSockServName);
       
  1104     if (ss==NULL)
       
  1105 		return KErrNotFound;
       
  1106 
       
  1107     RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1108 	if (c==NULL)
       
  1109 		return KErrNotFound;
       
  1110 
       
  1111 	if(aParams.iConnectionType != -1)
       
  1112 	   return c->Open(*ss,aParams.iConnectionType);
       
  1113 
       
  1114 	return c->Open(*ss);
       
  1115 	}
       
  1116 
       
  1117 TInt CCEsockTestBase::WaitforIncomingConnection(const TRSubConnectionParams& aParams)
       
  1118 	{
       
  1119     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1120 	if (sc==NULL)
       
  1121 		return KErrNotFound;
       
  1122 
       
  1123 	RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1124 	if (c==NULL)
       
  1125 		return KErrNotFound;
       
  1126 
       
  1127 	return c->WaitForIncoming(*sc);
       
  1128 	}
       
  1129 
       
  1130 TInt CCEsockTestBase::WaitforIncomingConnection(const TRSubConnectionParams& aParams,TRequestStatus& reqStat)
       
  1131 	{
       
  1132     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1133 	if (sc==NULL)
       
  1134 		return KErrNotFound;
       
  1135 
       
  1136 	RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1137 	if (c==NULL)
       
  1138 		return KErrNotFound;
       
  1139 
       
  1140 	c->WaitForIncoming(*sc,reqStat);
       
  1141 
       
  1142 	return KErrNone;
       
  1143 	}
       
  1144 
       
  1145 TInt CCEsockTestBase::AcceptIncomingConnection(const TRSubConnectionParams& aParams)
       
  1146 	{
       
  1147     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1148 	if (sc==NULL)
       
  1149 		return KErrNotFound;
       
  1150 
       
  1151 	sc->Start();
       
  1152 	
       
  1153 	return KErrNone;
       
  1154 	}
       
  1155 	
       
  1156 TInt CCEsockTestBase::AsyncAcceptIncomingConnection(const TRSubConnectionParams& aParams, TRequestStatus& reqStat)
       
  1157 	{
       
  1158     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1159 	if (sc==NULL)
       
  1160 		return KErrNotFound;
       
  1161 
       
  1162 	sc->Start(reqStat);
       
  1163 	
       
  1164 	return KErrNone;
       
  1165 	}
       
  1166 	
       
  1167 TInt CCEsockTestBase::RejectIncomingConnection(const TRSubConnectionParams& aParams)
       
  1168 	{
       
  1169     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1170 	if (sc==NULL)
       
  1171 		return KErrNotFound;
       
  1172 
       
  1173 	sc->Stop();
       
  1174 
       
  1175 	return KErrNone;
       
  1176 	}
       
  1177 
       
  1178 TInt CCEsockTestBase::CancelIncomingConnection(const TRSubConnectionParams& aParams)
       
  1179 	{
       
  1180     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1181 	if (sc==NULL)
       
  1182 		return KErrNotFound;
       
  1183 
       
  1184 	RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1185 	if (c==NULL)
       
  1186 		return KErrNotFound;
       
  1187 
       
  1188 	c->CancelWaitForIncoming();
       
  1189 
       
  1190 	return KErrNone;
       
  1191 	}
       
  1192 
       
  1193 
       
  1194 TInt CCEsockTestBase::StartConnection(RConnection& aConn, TConnPref& aPrefs, TRequestStatus* aRequestStatus)
       
  1195 	{
       
  1196 	if (aRequestStatus)
       
  1197 		{
       
  1198 		aConn.Start(aPrefs, *aRequestStatus);
       
  1199 		}
       
  1200 	else
       
  1201 		{
       
  1202 		return aConn.Start(aPrefs);
       
  1203 		}
       
  1204 	return KErrNone;
       
  1205 	}
       
  1206 
       
  1207 TInt CCEsockTestBase::StartConnection(TRConnectionParams& aParams)
       
  1208 	{
       
  1209     RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1210 	if (c==NULL)
       
  1211 		return KErrNotFound;
       
  1212 	TRequestStatus* requestStatus = NULL;
       
  1213 	if (aParams.iAsynch)
       
  1214 		{
       
  1215 		requestStatus = new TRequestStatus;
       
  1216 	    if (requestStatus==NULL)
       
  1217 	    	return KErrNoMemory;
       
  1218 	    
       
  1219 		TInt error = iRequestStatuses.Add(requestStatus, aParams.iConnectionName);
       
  1220 		if (error!=KErrNone)
       
  1221 			{
       
  1222 			delete requestStatus;
       
  1223 			return error;
       
  1224 			}
       
  1225 		}
       
  1226 
       
  1227 	TInt error;
       
  1228 	if (aParams.iStartWithSnapPreferences)
       
  1229 		{
       
  1230 		TCommSnapPref prefs;
       
  1231 		prefs.SetSnap(aParams.iSNAP);
       
  1232 
       
  1233 		error = StartConnection(*c, prefs, requestStatus);
       
  1234 		}
       
  1235 	else if (aParams.iStartWithOldPreferences)
       
  1236 		{
       
  1237 		TCommDbConnPref prefs;
       
  1238 		prefs.SetBearerSet(aParams.iBearer);
       
  1239 		prefs.SetIapId(aParams.iIAP);
       
  1240 		error = StartConnection(*c, prefs, requestStatus);
       
  1241 		}
       
  1242 	else if(aParams.iStartWithConPrefList)
       
  1243 		{
       
  1244 		TConnPrefList* prefs = TConnPrefList::NewL();
       
  1245 		CleanupStack::PushL(prefs);
       
  1246 		TConnAPPref* APPref = TConnAPPref::NewL(aParams.iSNAP);
       
  1247 		CleanupStack::PushL(APPref);
       
  1248 		TDummyPref* dummyPref = TDummyPref::NewL(aParams.iDummy);
       
  1249 		CleanupStack::PushL(dummyPref);
       
  1250 		if(aParams.iStartWithDummy)
       
  1251 			prefs->AppendL(dummyPref);
       
  1252 		
       
  1253 		TConnAutoStartPref* autoPref = TConnAutoStartPref::NewL();
       
  1254 		CleanupStack::PushL(autoPref);
       
  1255 		if(aParams.iStartAuto)
       
  1256 			prefs->AppendL(autoPref);
       
  1257 		
       
  1258 		prefs->AppendL(APPref);
       
  1259 		error = StartConnection(*c, *prefs, requestStatus);
       
  1260 		
       
  1261 		delete APPref;
       
  1262 		delete dummyPref;
       
  1263 		delete autoPref;
       
  1264 		if (aParams.iStartAuto)
       
  1265 			prefs->Remove(0);
       
  1266 		if (aParams.iStartWithDummy)
       
  1267 			prefs->Remove(0);
       
  1268 		prefs->Remove(0);
       
  1269 		delete prefs;
       
  1270 		
       
  1271 		CleanupStack::Pop(4);
       
  1272 		}
       
  1273 	else
       
  1274 		{
       
  1275 		if (requestStatus)
       
  1276 			{
       
  1277 			c->Start(*requestStatus);
       
  1278 			}
       
  1279 		else
       
  1280 			{
       
  1281 			error = c->Start();
       
  1282 			}
       
  1283 		}
       
  1284 	
       
  1285 	return error;
       
  1286 	}
       
  1287 
       
  1288 TInt CCEsockTestBase::AttachToConnection(const TRConnectionParams& aParams)
       
  1289 	{
       
  1290 	RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1291 	if (c==NULL)
       
  1292 		return KErrNotFound;
       
  1293 
       
  1294 	TUint count = 0;
       
  1295 		c->EnumerateConnections(count);
       
  1296 	
       
  1297 	if(count < 1)
       
  1298 		return KErrNotFound;
       
  1299 
       
  1300 	//
       
  1301 	TInt error = KErrNotSupported;
       
  1302 	RConnection* atc = iConns.Find(aParams.iAttachToConnectionName);
       
  1303 	if (atc!=NULL)
       
  1304 		{ //Currently this is only for the new attach (TConnProviderInfo)
       
  1305 		//If you want to extend this test step for legacy attach (TConnectionInfo),
       
  1306 		//you need to add a parameter to recognise which attach it is.
       
  1307 
       
  1308 		ESock::XProviderInfoQuerySet* querySet = ESock::XProviderInfoQuerySet::NewL();
       
  1309 		CleanupDeletePushL(querySet);
       
  1310 		
       
  1311 		// CProviderInfoQuerySet takes ownership of the X-class
       
  1312 		ESock::CProviderInfoQuerySet* queryContainer = ESock::CProviderInfoQuerySet::NewL(querySet);
       
  1313 		CleanupStack::Pop(querySet);
       
  1314 		CleanupStack::PushL(queryContainer);
       
  1315 		
       
  1316 		error = atc->GetParameters(*queryContainer);
       
  1317 		if (error != KErrNone)
       
  1318 			return error;
       
  1319 
       
  1320 		ESock::XProviderInfoQuerySet& outputQuerySet = queryContainer->DataObject();
       
  1321 
       
  1322 		TPckg<TConnProviderInfo> pkgConnInfo(outputQuerySet.ConnProviderInfo());
       
  1323 		error = c->Attach(pkgConnInfo, aParams.iConnAttachType);
       
  1324 		
       
  1325 		CleanupStack::PopAndDestroy(queryContainer);
       
  1326 		}
       
  1327 	else
       
  1328 		{
       
  1329 		TConnectionInfo connInfo;
       
  1330 		TPckg<TConnectionInfo> pkgConnInfo(connInfo);
       
  1331 
       
  1332 		TBool found = EFalse;
       
  1333 		for(TInt index = 1; index <= count; ++index)
       
  1334 			{
       
  1335 			error = c->GetConnectionInfo(index, pkgConnInfo);
       
  1336 			if(error != KErrNone)
       
  1337 				return error;
       
  1338 			
       
  1339 			if(aParams.iIAP == 0 && aParams.iNET == 0)
       
  1340 				{
       
  1341 				found = ETrue;
       
  1342 				}
       
  1343 			else if(aParams.iIAP > 0 && aParams.iNET > 0)	
       
  1344 				{
       
  1345 				found = (aParams.iIAP == connInfo.iIapId && aParams.iNET == connInfo.iNetId) ? ETrue : EFalse;
       
  1346 				}
       
  1347 			else if(aParams.iIAP > 0)
       
  1348 				{
       
  1349 				found = aParams.iIAP == connInfo.iIapId ? ETrue : EFalse;
       
  1350 				}
       
  1351 			else if(aParams.iNET > 0)	
       
  1352 				{
       
  1353 				found = aParams.iNET == connInfo.iNetId ? ETrue : EFalse;
       
  1354 				}
       
  1355 			
       
  1356 			if(found) 
       
  1357 				break;	
       
  1358 			}
       
  1359 			if(!found)	
       
  1360 				return KErrNotFound;
       
  1361 			
       
  1362 			error = c->Attach(pkgConnInfo,aParams.iConnAttachType);
       
  1363 		}
       
  1364 	
       
  1365 	return error;
       
  1366 	}
       
  1367 
       
  1368 TInt CCEsockTestBase::StopConnection(const TRConnectionParams& aParams)
       
  1369     {
       
  1370     RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1371 	if (c==NULL)
       
  1372 		return KErrNotFound;
       
  1373 
       
  1374 	c->Stop(aParams.iConnStopType);
       
  1375 	return KErrNone;
       
  1376     }
       
  1377 
       
  1378 TInt CCEsockTestBase::CloseConnection(const TDesC& aConnectionName)
       
  1379 	{
       
  1380     RConnection* c = iConns.Find(aConnectionName);
       
  1381 	if (c==NULL)
       
  1382 		return KErrNotFound;
       
  1383 
       
  1384 	c->Close();
       
  1385 	return KErrNone;
       
  1386 	}
       
  1387 
       
  1388 //
       
  1389 //connection events
       
  1390 //(each event notification request is encapsulated in a "EventContainer" that can easily be stored in a map.)
       
  1391 
       
  1392 TInt CCEsockTestBase::RegisterForProgressNotificationEvent(const TEventContainerParams& aParams)
       
  1393 	{
       
  1394 	TEsockTestEventContainer* ec = iConnEvents.Find(aParams.iEventName);
       
  1395 	if (ec==NULL)
       
  1396 		{
       
  1397 		ec = new TEsockTestEventContainer;
       
  1398 		if (ec==NULL)
       
  1399 			return KErrNoMemory;
       
  1400 
       
  1401 		TInt error = iConnEvents.Add(ec,aParams.iEventName);
       
  1402 		if (error!=KErrNone)
       
  1403 			{
       
  1404 			delete ec;
       
  1405 			return error;
       
  1406 			}
       
  1407 		}
       
  1408 
       
  1409 	__ASSERT_DEBUG(ec->iEventReceived != KRequestPending, User::Panic(KSpecAssert_ESockTestEsckTst, 1));
       
  1410 	RConnection* conn = iConns.Find(aParams.iConnectionName);
       
  1411 	if (conn==NULL)
       
  1412 		{
       
  1413 		return KErrNotFound;
       
  1414 		}
       
  1415 	
       
  1416 	if (aParams.iEventMask == 0)
       
  1417 		return KErrArgument;
       
  1418 
       
  1419 	conn->ProgressNotification(ec->iProgressBuf, ec->iEventReceived, aParams.iEventMask);
       
  1420 	return KErrNone;
       
  1421 	}
       
  1422 
       
  1423 TInt CCEsockTestBase::ReceiveProgressNotificationEvent(TNifProgress*&aNifProgress, const TDesC& aEventName, TUint aTimeoutInMiliSec)
       
  1424 	{
       
  1425 	TEsockTestEventContainer* ec = iConnEvents.Find(aEventName);
       
  1426 	if (ec==NULL)
       
  1427 		return KErrNotFound;
       
  1428 	if (aTimeoutInMiliSec)
       
  1429 	    {
       
  1430 	    RTimer timer;
       
  1431 	    timer.CreateLocal();	    
       
  1432 	    TRequestStatus timerStatus;
       
  1433 	    timer.After(timerStatus, aTimeoutInMiliSec * 1000);
       
  1434 	    User::WaitForRequest(ec->iEventReceived, timerStatus);
       
  1435 	    }
       
  1436 	else
       
  1437 	    {
       
  1438 	    User::WaitForRequest(ec->iEventReceived);
       
  1439 	    }
       
  1440 	aNifProgress = (ec->iEventReceived.Int()==KErrNone)? &ec->iProgressBuf() : NULL;
       
  1441 	return ec->iEventReceived.Int();
       
  1442 	}
       
  1443 
       
  1444 
       
  1445 //mobility extensions
       
  1446 RCommsMobilityApiExt* CCEsockTestBase::FindMobilityExtension(const TDesC& aMobilityExtensionName)
       
  1447     {
       
  1448     return iMobilityExts.Find(aMobilityExtensionName);
       
  1449     }
       
  1450 
       
  1451 TInt CCEsockTestBase::CreateMobilityExtension(const TDesC& aMobilityExtensionName)
       
  1452     {
       
  1453     //check if this extension hasn't been created already
       
  1454     if (iMobilityExts.Find(aMobilityExtensionName)!=NULL)
       
  1455     	return KErrAlreadyExists;
       
  1456 
       
  1457     RCommsMobilityApiExt* me = new RCommsMobilityApiExt;
       
  1458     if (me==NULL)
       
  1459     	return KErrNoMemory;
       
  1460 
       
  1461 	TInt error = iMobilityExts.Add(me,aMobilityExtensionName);
       
  1462 	if (error!=KErrNone)
       
  1463 		delete me;
       
  1464 
       
  1465 	return error;
       
  1466     }
       
  1467 
       
  1468 
       
  1469 // Data monitoring
       
  1470 //----------------
       
  1471 
       
  1472 RCommsDataMonitoringApiExt* CCEsockTestBase::FindDataMonitoringExtension(const TDataMonitorEventParams& aParams)
       
  1473    {
       
  1474    return iDataMonitoringExts.Find(aParams.iDataMonitorName);
       
  1475    }
       
  1476 
       
  1477 
       
  1478 TEsockTestDataMonitoringResponse* CCEsockTestBase::FindDataMonitoringResponder(const TDataMonitorEventParams& aParams)
       
  1479 	{
       
  1480 	return iDataMonitoringEvents.Find(aParams.iEventName);
       
  1481 	}
       
  1482 
       
  1483 TInt CCEsockTestBase::CreateDataMonitoringExtension(const TDataMonitorEventParams& aParams)
       
  1484    {
       
  1485    if(iDataMonitoringExts.Find(aParams.iDataMonitorName) != NULL)
       
  1486       {
       
  1487       return KErrAlreadyExists;
       
  1488       }
       
  1489 
       
  1490    RCommsDataMonitoringApiExt* ext = new RCommsDataMonitoringApiExt();
       
  1491 
       
  1492    if(!ext)
       
  1493       {
       
  1494     	return KErrNoMemory;
       
  1495       }
       
  1496 
       
  1497    TInt error = iDataMonitoringExts.Add(ext, aParams.iDataMonitorName);
       
  1498    
       
  1499 	if (error != KErrNone)
       
  1500       {
       
  1501       delete ext;
       
  1502       }
       
  1503 
       
  1504 	return error;
       
  1505    }
       
  1506 
       
  1507 TEsockTestDataMonitoringResponse* CCEsockTestBase::FindOrCreateDataMonitoringResponder(const TDataMonitorEventParams& aParams)
       
  1508 	{
       
  1509 	TEsockTestDataMonitoringResponse* response = FindDataMonitoringResponder(aParams);
       
  1510 	if(response)
       
  1511 		{
       
  1512 		return response;
       
  1513 		}
       
  1514 	
       
  1515 	if(NULL == (response = new TEsockTestDataMonitoringResponse()))
       
  1516 		{
       
  1517 		return NULL;
       
  1518 		}
       
  1519 
       
  1520 	TInt err = iDataMonitoringEvents.Add(response, aParams.iEventName);
       
  1521 	if(err != KErrNone)
       
  1522 		{
       
  1523 		delete response;
       
  1524 		response = NULL;
       
  1525 		}
       
  1526 		
       
  1527 	return response;
       
  1528 	}
       
  1529 	
       
  1530 TInt CCEsockTestBase::OpenDataMonitoringExtension(const TDataMonitorEventParams& aParams)
       
  1531 	{
       
  1532 	RCommsSubSession* connOrSubConn = NULL;
       
  1533 	
       
  1534 	if(aParams.iConnectionName.Length() > 0)
       
  1535 		{ // Open extension on an RConnection if specified
       
  1536 		connOrSubConn = iConns.Find(aParams.iConnectionName);
       
  1537 		if(!connOrSubConn) 
       
  1538 			{
       
  1539 			return KErrNotFound;
       
  1540 			}
       
  1541 		}
       
  1542 	else if(aParams.iSubConnectionName.Length() > 0)
       
  1543 		{ // Otherwise open extension on an RSubConnection
       
  1544 		connOrSubConn = iSubConns.Find(aParams.iSubConnectionName);
       
  1545 		if(!connOrSubConn) 
       
  1546 			{
       
  1547 			return KErrNotFound;
       
  1548 			}
       
  1549 		}
       
  1550 	else
       
  1551 		{ // Neither an RConnection or an RSubConnection was specified
       
  1552 		return KErrArgument;
       
  1553 		}
       
  1554 	
       
  1555 	RCommsDataMonitoringApiExt* ext = iDataMonitoringExts.Find(aParams.iDataMonitorName);
       
  1556 	if(!ext)
       
  1557 		{
       
  1558 		return KErrNotFound;
       
  1559 		}
       
  1560 		
       
  1561 	return ext->Open(*connOrSubConn);
       
  1562 	}
       
  1563 
       
  1564 TInt CCEsockTestBase::CloseDataMonitoringExtension(const TDataMonitorEventParams& aParams)
       
  1565 	{
       
  1566 	RCommsDataMonitoringApiExt* ext = iDataMonitoringExts.Find(aParams.iDataMonitorName);
       
  1567 	if(!ext)
       
  1568 		{
       
  1569 		return KErrNotFound;
       
  1570 		}
       
  1571 		
       
  1572 	ext->Close();
       
  1573 	
       
  1574 	return KErrNone;
       
  1575 	}
       
  1576 
       
  1577 TInt CCEsockTestBase::RequestDataTransferred(const TDataMonitorEventParams& aParams, TDes8& aResponseBuf)
       
  1578 	{
       
  1579 	RCommsDataMonitoringApiExt* ext = iDataMonitoringExts.Find(aParams.iDataMonitorName);
       
  1580 	if(!ext)
       
  1581 		{
       
  1582 		return KErrNotFound;
       
  1583 		}
       
  1584 
       
  1585 	TRequestStatus status;	
       
  1586 	ext->RequestDataTransferred(aResponseBuf, status);
       
  1587 	User::WaitForRequest(status);
       
  1588 	
       
  1589 	return KErrNone;
       
  1590 	}
       
  1591 
       
  1592 // Find saved stats from a previous DataTransferred request
       
  1593 TDataMonitorStats* CCEsockTestBase::FetchSavedDataMonitorStats(const TDesC& aDataMonitorStatsSavedName)
       
  1594 	{
       
  1595 	return iSavedDataMonitorStats.Find(aDataMonitorStatsSavedName);
       
  1596 	}
       
  1597 
       
  1598 // Save data monitor stats for future reference
       
  1599 TInt CCEsockTestBase::SaveDataMonitorStats(const TDesC& aSavedName, TDataMonitorStats& aStatsToSave)
       
  1600 	{
       
  1601 	TInt err;
       
  1602 	
       
  1603 	// Simply add if doesn't already exist
       
  1604 	if(iSavedDataMonitorStats.Find(aSavedName) == NULL)
       
  1605 		{
       
  1606 		err = iSavedDataMonitorStats.Add(&aStatsToSave, aSavedName);
       
  1607 		}
       
  1608 	else
       
  1609 		{
       
  1610 		// Already exists so delete and add in order to replace
       
  1611 		iSavedDataMonitorStats.Remove(aSavedName);
       
  1612 		err = iSavedDataMonitorStats.Add(&aStatsToSave, aSavedName);
       
  1613 		}
       
  1614 		
       
  1615 	return err;
       
  1616 	}
       
  1617 
       
  1618 TInt CCEsockTestBase::RequestDataReceivedNotification(const TDataMonitorEventParams& aParams)
       
  1619 	{
       
  1620 	RCommsDataMonitoringApiExt* ext = FindDataMonitoringExtension(aParams);
       
  1621 	if(!ext)
       
  1622 		{
       
  1623 		return KErrNotFound;
       
  1624 		}
       
  1625 
       
  1626 	TEsockTestDataMonitoringResponse* response =	FindOrCreateDataMonitoringResponder(aParams);
       
  1627 	if(!response)
       
  1628 		{
       
  1629 		return KErrNoMemory;
       
  1630 		}
       
  1631 
       
  1632 	ext->RequestDataReceivedNotification(aParams.iDelta, aParams.iMinExpectedVolume, response->iBuffer, response->iStatus);
       
  1633 	
       
  1634 	return KErrNone;
       
  1635 	}
       
  1636 
       
  1637 TInt CCEsockTestBase::CancelDataReceivedNotificationRequest(const TDataMonitorEventParams& aParams)
       
  1638 	{
       
  1639 	RCommsDataMonitoringApiExt* ext = FindDataMonitoringExtension(aParams);	
       
  1640 	if(!ext)
       
  1641 		{
       
  1642 		return KErrNotFound;
       
  1643 		}
       
  1644 
       
  1645 	TEsockTestDataMonitoringResponse* response = FindOrCreateDataMonitoringResponder(aParams);
       
  1646 	if(!response)
       
  1647 		{
       
  1648 		return KErrNoMemory;
       
  1649 		}
       
  1650 
       
  1651 	ext->CancelDataReceivedNotificationRequest();
       
  1652 	User::WaitForRequest(response->iStatus);
       
  1653 	
       
  1654 	// Return the status code from the cancellation
       
  1655 	return response->iStatus.Int();
       
  1656 	}
       
  1657 
       
  1658 TInt CCEsockTestBase::ReceiveDataReceivedNotification(const TDataMonitorEventParams& aParams, TDesC8*& aResponseBuf)
       
  1659 	{
       
  1660 	TEsockTestDataMonitoringResponse* response =	FindDataMonitoringResponder(aParams);
       
  1661 	if(!response)
       
  1662 		{
       
  1663 		return KErrNotFound;
       
  1664 		}
       
  1665 
       
  1666 	// Check that its not complete already
       
  1667 	if(response->iComplete)
       
  1668 		{
       
  1669 		return KErrGeneral;
       
  1670 		}
       
  1671 
       
  1672 	RTimer timer;
       
  1673 	timer.CreateLocal();
       
  1674 	
       
  1675 	TRequestStatus timerStatus;
       
  1676 	timer.After(timerStatus, response->iTimeout * 1000000);
       
  1677 	
       
  1678 	User::WaitForRequest(response->iStatus, timerStatus);
       
  1679 	
       
  1680 	TInt result;
       
  1681 	if(response->iStatus.Int() != KErrNone)
       
  1682 		{
       
  1683 		result = KErrTimedOut;
       
  1684 		}
       
  1685 	else
       
  1686 		{
       
  1687 		timer.Cancel();
       
  1688 		User::WaitForRequest(timerStatus);
       
  1689 
       
  1690 	   aResponseBuf = NULL;
       
  1691 	   if(response->iStatus.Int() == KErrNone) 
       
  1692 	   	{
       
  1693 	   	aResponseBuf = &response->iBuffer;
       
  1694 	   	}
       
  1695    	result = response->iStatus.Int();
       
  1696    	response->iComplete = ETrue;
       
  1697 		}
       
  1698 		
       
  1699 	timer.Close();
       
  1700 	
       
  1701 	return result;
       
  1702 	}
       
  1703 
       
  1704 TInt CCEsockTestBase::RequestDataSentNotification(const TDataMonitorEventParams& aParams)
       
  1705 	{
       
  1706 	// Find the data monitoring extension to start with
       
  1707 	RCommsDataMonitoringApiExt* ext = FindDataMonitoringExtension(aParams);
       
  1708 	if(!ext)
       
  1709 		{
       
  1710 		return KErrNotFound;
       
  1711 		}
       
  1712 		
       
  1713 	// Find the data monitoring responder that goes with it
       
  1714 	TEsockTestDataMonitoringResponse* response =	FindDataMonitoringResponder(aParams);
       
  1715 	if(!response)
       
  1716 		{
       
  1717 		return KErrNotFound;
       
  1718 		}
       
  1719 
       
  1720 	// Make the request on the data monitor
       
  1721 	ext->RequestDataSentNotification(aParams.iDelta, aParams.iMinExpectedVolume, response->iBuffer, response->iStatus);
       
  1722 	
       
  1723 	return KErrNone;
       
  1724 	}
       
  1725 
       
  1726 TInt CCEsockTestBase::CancelDataSentNotificationRequest(const TDataMonitorEventParams& aParams)
       
  1727 	{
       
  1728 	RCommsDataMonitoringApiExt* ext = FindDataMonitoringExtension(aParams);
       
  1729 	if(!ext)
       
  1730 		{
       
  1731 		return KErrNotFound;
       
  1732 		}
       
  1733 
       
  1734 	TEsockTestDataMonitoringResponse* response =	FindDataMonitoringResponder(aParams);
       
  1735 	if(!response)
       
  1736 		{
       
  1737 		return KErrNotFound;
       
  1738 		}
       
  1739 
       
  1740 	ext->CancelDataSentNotificationRequest();
       
  1741 	User::WaitForRequest(response->iStatus);
       
  1742 	
       
  1743 	// Return the status code from the cancellation
       
  1744 	return response->iStatus.Int();
       
  1745 	}
       
  1746 
       
  1747 TInt CCEsockTestBase::ReceiveDataSentNotification(const TDataMonitorEventParams& aParams, TDesC8*& aResponseBuf)
       
  1748 	{
       
  1749 	TEsockTestDataMonitoringResponse* response =	FindDataMonitoringResponder(aParams);
       
  1750 	if(!response)
       
  1751 		{
       
  1752 		return KErrNotFound;
       
  1753 		}
       
  1754 
       
  1755 	// Check that its not complete already
       
  1756 	if(response->iComplete)
       
  1757 		{
       
  1758 		return KErrGeneral;
       
  1759 		}
       
  1760 
       
  1761 	RTimer timer;
       
  1762 	timer.CreateLocal();
       
  1763 	
       
  1764 	TRequestStatus timerStatus;
       
  1765 	timer.After(timerStatus, response->iTimeout * 1000000);
       
  1766 	
       
  1767 	User::WaitForRequest(response->iStatus, timerStatus);
       
  1768 	
       
  1769 	TInt result;
       
  1770 	if(response->iStatus.Int() != KErrNone)
       
  1771 		{
       
  1772 		result = KErrTimedOut;
       
  1773 		}
       
  1774 	else
       
  1775 		{
       
  1776 		timer.Cancel();
       
  1777 		User::WaitForRequest(timerStatus);
       
  1778 
       
  1779 	   aResponseBuf = NULL;
       
  1780 	   if(response->iStatus.Int() == KErrNone) 
       
  1781 	   	{
       
  1782 	   	aResponseBuf = &response->iBuffer;
       
  1783 	   	}
       
  1784    	result = response->iStatus.Int();
       
  1785    	response->iComplete = ETrue;
       
  1786 		}
       
  1787 		
       
  1788 	timer.Close();
       
  1789 	
       
  1790 	return result;
       
  1791 	}
       
  1792 
       
  1793 #if 0
       
  1794 //
       
  1795 //CommsServer functions library
       
  1796 
       
  1797 TInt CCEsockTestBase::CreateCommsServer(const TDesC& aCommsServerName)
       
  1798 	{
       
  1799     //check if this comms server hasn't been created already
       
  1800     if (iCommsServers.Find(aCommsServerName)!=NULL)
       
  1801     	return KErrAlreadyExists;
       
  1802 
       
  1803     RConnection* c = new RConnection;
       
  1804     if (c==NULL)
       
  1805     	return KErrNoMemory;
       
  1806 
       
  1807 	TInt error = iConns.Add(c,aConnectionName);
       
  1808 	if (error!=KErrNone)
       
  1809 		delete c;
       
  1810 
       
  1811 	return error;
       
  1812 	}
       
  1813 
       
  1814 TInt CCEsockTestBase::StartCommsServer(const TRCommsServerParams& aParams, TRequestStatus& aRequestStatus)
       
  1815 	{
       
  1816 	RConnManager* c = iCommsServers.Find(aParams.iCommsServerName);
       
  1817 	if (c==NULL)
       
  1818 		return KErrNotFound;
       
  1819 	
       
  1820 	c->Start(prefs,aRequestStatus);
       
  1821 		}
       
  1822 	else if (aParams.iStartWithOldPreferences)
       
  1823 		{
       
  1824 		TCommDbConnPref prefs;
       
  1825 		prefs.SetBearerSet(aParams.iBearer);
       
  1826 		prefs.SetIapId(aParams.iIAP);
       
  1827 		c->Start(prefs,aRequestStatus);
       
  1828 		}
       
  1829 	else
       
  1830 		c->Start(aRequestStatus);
       
  1831 
       
  1832 	return KErrNone;
       
  1833 	}
       
  1834 
       
  1835 TInt CCEsockTestBase::StartConnection(const TRConnectionParams& aParams)
       
  1836 	{
       
  1837     RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1838 	if (c==NULL)
       
  1839 		return KErrNotFound;
       
  1840 
       
  1841 	TInt error;
       
  1842 	if (aParams.iStartWithSnapPreferences)
       
  1843 		{
       
  1844 		TCommSnapPref prefs;
       
  1845 		prefs.SetSnap(aParams.iSNAP);
       
  1846 		error = c->Start(prefs);
       
  1847 		}
       
  1848 	else if (aParams.iStartWithOldPreferences)
       
  1849 		{
       
  1850 		TCommDbConnPref prefs;
       
  1851 		prefs.SetBearerSet(aParams.iBearer);
       
  1852 		prefs.SetIapId(aParams.iIAP);
       
  1853 		error = c->Start(prefs);
       
  1854 		}
       
  1855 	else
       
  1856 		error = c->Start();
       
  1857 
       
  1858 	return error;
       
  1859 	}
       
  1860 
       
  1861 TInt CCEsockTestBase::StopConnection(const TRConnectionParams& aParams)
       
  1862     {
       
  1863     RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1864 	if (c==NULL)
       
  1865 		return KErrNotFound;
       
  1866 
       
  1867 	c->Stop(aParams.iConnStopType);
       
  1868 	return KErrNone;
       
  1869     }
       
  1870 #endif
       
  1871 
       
  1872 
       
  1873 // SubConnections
       
  1874 //---------------
       
  1875 
       
  1876 RSubConnection* CCEsockTestBase::FindSubConnection(const TDesC& aSubConnectionName)
       
  1877     {
       
  1878     return iSubConns.Find(aSubConnectionName);
       
  1879     }
       
  1880 
       
  1881 TInt CCEsockTestBase::CreateSubConnection(const TDesC& aSubConnectionName)
       
  1882 	{
       
  1883     //check if this sub connection hasn't been created already
       
  1884     if (iSubConns.Find(aSubConnectionName)!=NULL)
       
  1885     	return KErrAlreadyExists;
       
  1886 
       
  1887     RSubConnection* sc = new RSubConnection;
       
  1888     if (sc==NULL)
       
  1889     	return KErrNoMemory;
       
  1890 
       
  1891 	TInt error = iSubConns.Add(sc,aSubConnectionName);
       
  1892 	if (error!=KErrNone)
       
  1893 		delete sc;
       
  1894 
       
  1895 	return error;
       
  1896 	}
       
  1897 
       
  1898 TInt CCEsockTestBase::OpenSubConnection(const TRSubConnectionParams& aParams)
       
  1899 	{
       
  1900     RSocketServ* ss = iSockServs.Find(aParams.iSockServName);
       
  1901     if (ss==NULL)
       
  1902 		return KErrNotFound;
       
  1903 
       
  1904     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1905 	if (sc==NULL)
       
  1906 		return KErrNotFound;
       
  1907 
       
  1908 	RConnection* c = iConns.Find(aParams.iConnectionName);
       
  1909 	if (c==NULL)
       
  1910 		return KErrNotFound;
       
  1911 
       
  1912 	return sc->Open(*ss, aParams.iSubConnType, *c);
       
  1913 	}
       
  1914 
       
  1915 TInt CCEsockTestBase::CloseSubConnection(const TDesC& aSubConnectionName)
       
  1916 	{
       
  1917     RSubConnection* sc = iSubConns.Find(aSubConnectionName);
       
  1918 	if (sc==NULL)
       
  1919 		return KErrNotFound;
       
  1920 
       
  1921 	sc->Close();
       
  1922 	return KErrNone;
       
  1923 	}
       
  1924 
       
  1925 TInt CCEsockTestBase::AddSocketToSubConnection(const TRSubConnectionParams& aParams, TRequestStatus& aStatus)
       
  1926     {
       
  1927     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1928 	if (sc==NULL)
       
  1929 		return KErrNotFound;
       
  1930 
       
  1931     RSocket* s = iSocks.Find(aParams.iSocketName);
       
  1932 	if (s==NULL)
       
  1933 		return KErrNotFound;
       
  1934 
       
  1935 	sc->Add(*s,aStatus);
       
  1936 	return KErrNone;
       
  1937 	}
       
  1938 
       
  1939 TInt CCEsockTestBase::RemoveSocketFromSubConnection(const TRSubConnectionParams& aParams, TRequestStatus& aStatus)
       
  1940     {
       
  1941     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1942 	if (sc==NULL)
       
  1943 		return KErrNotFound;
       
  1944 
       
  1945     RSocket* s = iSocks.Find(aParams.iSocketName);
       
  1946 	if (s==NULL)
       
  1947 		return KErrNotFound;
       
  1948 
       
  1949 	sc->Remove(*s,aStatus);
       
  1950 	return KErrNone;
       
  1951     }
       
  1952 
       
  1953 TInt CCEsockTestBase::SetSubConnectionParameters(const TRSubConnectionParams& aParams)
       
  1954 	{
       
  1955     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1956 	if (sc==NULL)
       
  1957 		return KErrNotFound;
       
  1958 
       
  1959 	RSubConParameterBundle* scp = iSubConnParams.Find(aParams.iSubConnectionParamsName);
       
  1960 	if (scp==NULL)
       
  1961 		return KErrNotFound;
       
  1962 
       
  1963 	return sc->SetParameters(*scp);
       
  1964 	}
       
  1965 
       
  1966 TInt CCEsockTestBase::GetSubConnectionParameters(const TRSubConnectionParams& aParams)
       
  1967 	{
       
  1968     if (iSubConnParams.Find(aParams.iSubConnectionParamsName)!=NULL)
       
  1969     	return KErrAlreadyExists;
       
  1970 
       
  1971     RSubConParameterBundle* scp = new RSubConParameterBundle;
       
  1972     if (scp==NULL)
       
  1973     	return KErrNoMemory;
       
  1974 
       
  1975 	TInt error = iSubConnParams.Add(scp,aParams.iSubConnectionParamsName);
       
  1976 	if (error!=KErrNone)
       
  1977 	    {
       
  1978 		delete scp;
       
  1979 		return error;
       
  1980 	    }
       
  1981 
       
  1982     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  1983 	if (sc==NULL)
       
  1984 		return KErrNotFound;
       
  1985 
       
  1986 	return sc->GetParameters(*scp);
       
  1987 	}
       
  1988 
       
  1989 TInt CCEsockTestBase::CompareIntegerValues(const TCompareIntegersParams& aParams, TInt& aDifference)
       
  1990 	{
       
  1991     TInt* value1;
       
  1992     value1 = iIntegerValues.Find(aParams.iValue1);
       
  1993     if(value1 == NULL)
       
  1994     	{
       
  1995 		return KErrNotFound;
       
  1996 		}
       
  1997 
       
  1998     TInt* value2;
       
  1999     value2 = iIntegerValues.Find(aParams.iValue2);
       
  2000 	if (value2 == NULL)
       
  2001     	{
       
  2002 		return KErrNotFound;
       
  2003 		}
       
  2004 
       
  2005 	// Confirm the values
       
  2006 	aDifference = (*value1 - *value2 + aParams.iDifference);
       
  2007 	return KErrNone;
       
  2008 	}
       
  2009 
       
  2010 TInt CCEsockTestBase::AwaitRequestStatus(const TDesC& aStatusName)
       
  2011 	{
       
  2012     TRequestStatus* req = iRequestStatuses.Find(aStatusName);
       
  2013     ASSERT(req);
       
  2014    	User::WaitForRequest(*req);
       
  2015    	return req->Int();
       
  2016 	}
       
  2017 
       
  2018 //
       
  2019 //subconnection parameters
       
  2020 TInt CCEsockTestBase::CreateRSubConnectionParams(const TDesC& aSubConParamsName)
       
  2021 	{
       
  2022 	RSubConParameterBundle* scp = new RSubConParameterBundle;
       
  2023     if (scp==NULL)
       
  2024     	return KErrNoMemory;
       
  2025 
       
  2026 	TInt error = iSubConnParams.Add(scp,aSubConParamsName);
       
  2027 	if (error!=KErrNone)
       
  2028 		delete scp;
       
  2029 
       
  2030 	return error;
       
  2031 	}
       
  2032 // SBLP functions
       
  2033 
       
  2034 TInt CCEsockTestBase::CreateTFlowId(const TDesC& aFlowIdName)
       
  2035 	{
       
  2036 	TFlowId* fid = new TFlowId;
       
  2037 	if (fid==NULL)
       
  2038     	return KErrNoMemory;
       
  2039 
       
  2040 	TInt error = iFlowId.Add(fid,aFlowIdName);
       
  2041 	if (error!=KErrNone)
       
  2042 		delete fid;
       
  2043 
       
  2044 	return error;
       
  2045 
       
  2046 	}
       
  2047 
       
  2048 TFlowId* CCEsockTestBase::FindTFlowId(const TDesC& aFlowId)
       
  2049 	{
       
  2050 		return iFlowId.Find(aFlowId);
       
  2051 	}
       
  2052 
       
  2053 TInt CCEsockTestBase::CloseRSubConnectionParams(const TDesC& aSubConParamsName)
       
  2054 	{
       
  2055 	RSubConParameterBundle* scp = iSubConnParams.Find(aSubConParamsName);
       
  2056 	if (scp==NULL)
       
  2057 		return KErrNotFound;
       
  2058 
       
  2059 	scp->Close();
       
  2060 	return KErrNone;
       
  2061 	}
       
  2062 
       
  2063 
       
  2064 RSubConParameterBundle* CCEsockTestBase::FindRSubConnectionParams(const TDesC& aSubConParamsName)
       
  2065 	{
       
  2066 		return iSubConnParams.Find(aSubConParamsName);
       
  2067 	}
       
  2068 
       
  2069 CSubConParameterFamily* CCEsockTestBase::FindRSubConnectionParameterFamily(const TDesC& aSubConParamsName, const TInt aFamilyId)
       
  2070     {
       
  2071     RSubConParameterBundle* bundle = FindRSubConnectionParams(aSubConParamsName);
       
  2072     if (bundle==NULL)
       
  2073         return NULL;
       
  2074 
       
  2075     return bundle->FindFamily(aFamilyId);
       
  2076     }
       
  2077 
       
  2078 //
       
  2079 //subconnection events
       
  2080 //(each event notification request is encapsulated in a "EventContainer" that can easily be stored in a map.)
       
  2081 
       
  2082 TInt CCEsockTestBase::RegisterForRSubConnectionEvent(const TEventContainerParams& aParams)
       
  2083     {
       
  2084     TEsockTestEventContainer* ec = iSubConnEvents.Find(aParams.iEventName);
       
  2085 	if (ec==NULL)
       
  2086 	    {
       
  2087     	ec = new TEsockTestEventContainer;
       
  2088         if (ec==NULL)
       
  2089     	    return KErrNoMemory;
       
  2090 
       
  2091     	TInt error = iSubConnEvents.Add(ec,aParams.iEventName);
       
  2092 	    if (error!=KErrNone)
       
  2093 	        {
       
  2094 		    delete ec;
       
  2095 		    return error;
       
  2096 	        }
       
  2097 	    }
       
  2098 
       
  2099     __ASSERT_DEBUG(ec->iEventReceived != KRequestPending, User::Panic(KSpecAssert_ESockTestEsckTst, 2));
       
  2100     RSubConnection* sc = iSubConns.Find(aParams.iSubConnectionName);
       
  2101 	if (sc==NULL)
       
  2102 	    {
       
  2103 		return KErrNotFound;
       
  2104 	    }
       
  2105 
       
  2106 	//check if we should simply register for all event
       
  2107 	if (aParams.iAllEvents)
       
  2108 	    {
       
  2109         sc->EventNotification(static_cast<TNotificationEventBuf&>(ec->iEventNotifBuf), EFalse, ec->iEventReceived);
       
  2110 	    return KErrNone;
       
  2111 	    }
       
  2112 
       
  2113 	//no.. what about only generic ones?
       
  2114 	if (aParams.iGenericEvents)
       
  2115 	    {
       
  2116         sc->EventNotification(static_cast<TNotificationEventBuf&>(ec->iEventNotifBuf), ETrue, ec->iEventReceived);
       
  2117 	    return KErrNone;
       
  2118 	    }
       
  2119 
       
  2120 	//no.. reqister for specific events
       
  2121     if (aParams.iEventMask == 0)
       
  2122         return KErrArgument;
       
  2123 
       
  2124     (ec->iSubconnEventFilter).iEventGroupUid = KSubConnGenericEventsImplUid;
       
  2125     (ec->iSubconnEventFilter).iEventMask = aParams.iEventMask;
       
  2126     sc->EventNotification(static_cast<TNotificationEventBuf&>(ec->iEventNotifBuf), &(ec->iSubconnEventFilter), 1, ec->iEventReceived);
       
  2127     return KErrNone;
       
  2128     }
       
  2129 
       
  2130 TInt CCEsockTestBase::ReceiveRSubConnectionEvent(TNotificationEventBuf*& aBufferPtr, const TDesC& aSubConEventName)
       
  2131     {
       
  2132     TEsockTestEventContainer* ec = iSubConnEvents.Find(aSubConEventName);
       
  2133 	if (ec==NULL)
       
  2134 		return KErrNotFound;
       
  2135 
       
  2136     User::WaitForRequest(ec->iEventReceived);
       
  2137     aBufferPtr = (ec->iEventReceived.Int()==KErrNone)? &static_cast<TNotificationEventBuf&>(ec->iEventNotifBuf) : NULL;
       
  2138     __ASSERT_DEBUG(aBufferPtr->GroupId(), User::Panic(KSpecAssert_ESockTestEsckTst, 3));
       
  2139     return ec->iEventReceived.Int();
       
  2140     }
       
  2141 
       
  2142 //
       
  2143 //mobility notifications
       
  2144 //(each notification request is encapsulated in a "EventContainer" that can easily be stored in a map.)
       
  2145 
       
  2146 TInt CCEsockTestBase::RegisterForMobilityNotification(const TEventContainerParams& aParams)
       
  2147     {
       
  2148     TEsockTestEventContainer* ec = iConnEvents.Find(aParams.iEventName);
       
  2149 	if (ec==NULL)
       
  2150 	    {
       
  2151     	ec = new TEsockTestEventContainer;
       
  2152         if (ec==NULL)
       
  2153     	    return KErrNoMemory;
       
  2154 
       
  2155     	TInt error = iConnEvents.Add(ec,aParams.iEventName);
       
  2156 	    if (error!=KErrNone)
       
  2157 	        {
       
  2158 		    delete ec;
       
  2159 		    return error;
       
  2160 	        }
       
  2161 	    }
       
  2162 
       
  2163     RCommsMobilityApiExt* me = iMobilityExts.Find(aParams.iMobilityExtName);
       
  2164 	if (me==NULL)
       
  2165 	    {
       
  2166 		return KErrNotFound;
       
  2167 	    }
       
  2168 
       
  2169 	//reqister
       
  2170     __ASSERT_DEBUG(ec->iEventReceived != KRequestPending, User::Panic(KSpecAssert_ESockTestEsckTst, 4));
       
  2171 	me->RegisterForMobilityNotification(ec->iEventNotifBuf,ec->iEventReceived);
       
  2172 
       
  2173     return KErrNone;
       
  2174     }
       
  2175 
       
  2176 TInt CCEsockTestBase::ReceiveMobilityNotification(TDesC8*& aBufferPtr, const TEventContainerParams& aParams)
       
  2177     {
       
  2178     TEsockTestEventContainer* ec = iConnEvents.Find(aParams.iEventName);
       
  2179 	if (ec==NULL)
       
  2180 		return KErrNotFound;
       
  2181 
       
  2182     RCommsMobilityApiExt* me = iMobilityExts.Find(aParams.iMobilityExtName);
       
  2183 	if (me==NULL)
       
  2184 		return KErrNotFound;
       
  2185 
       
  2186 	if (aParams.iTimeoutMiliSecs!=0)
       
  2187 		{
       
  2188 		TRequestStatus timeoutStatus;
       
  2189 		RTimer timer;
       
  2190 		timer.CreateLocal();
       
  2191 		timer.After(timeoutStatus,aParams.iTimeoutMiliSecs*1000);
       
  2192     	User::WaitForRequest(ec->iEventReceived,timeoutStatus);
       
  2193     	timer.Cancel();
       
  2194     	timer.Close();
       
  2195     	if (ec->iEventReceived==KRequestPending)
       
  2196     		{
       
  2197     		me->CancelMobilityNotification();
       
  2198     		}
       
  2199     	}
       
  2200     else
       
  2201     	{
       
  2202     	User::WaitForRequest(ec->iEventReceived);
       
  2203     	
       
  2204     	}
       
  2205 
       
  2206     aBufferPtr = (ec->iEventReceived.Int()==KErrNone)? &ec->iEventNotifBuf : NULL;
       
  2207     return ec->iEventReceived.Int();
       
  2208     }
       
  2209 
       
  2210 //
       
  2211 //cleanup
       
  2212 
       
  2213 void CCEsockTestBase::CleanAll()
       
  2214 	{
       
  2215     iSockServs.ResetAndDestroy();
       
  2216     iSocks.ResetAndDestroy();
       
  2217 	iConns.ResetAndDestroy();
       
  2218 	iSubConns.ResetAndDestroy();
       
  2219 	iConnectionServs.ResetAndDestroy();
       
  2220 	iMobilityExts.ResetAndDestroy();
       
  2221 	iDataMonitoringExts.ResetAndDestroy();
       
  2222 	iDataMonitoringEvents.ResetAndDestroy();
       
  2223 	iNotifWatchers.ResetAndDestroy();
       
  2224     TInt i = 0;
       
  2225     for (i = 0; i < iSubConnParams.Count(); i++)
       
  2226         {
       
  2227         iSubConnParams[i]->Close();
       
  2228         }
       
  2229 	iSubConnParams.ResetAndDestroy();
       
  2230 	iSubConnEvents.ResetAndDestroy();
       
  2231 	iConnEvents.ResetAndDestroy();
       
  2232 	iFlowId.ResetAndDestroy();
       
  2233 	iIntegerValues.ResetAndDestroy();
       
  2234 	iRequestStatuses.ResetAndDestroy();
       
  2235 	}
       
  2236 
       
  2237 //
       
  2238 //general utils
       
  2239 
       
  2240 
       
  2241 //
       
  2242 // Simtsy Trigger Event functionality
       
  2243 
       
  2244 /**
       
  2245  Instructs the simtsy to complete a given request/notification. The supported commands are given in TEtelRequestType.
       
  2246  The parameter supplied in aNewValue instructs the simtsy what data from the config.txt to use in the completion of the request.
       
  2247  The aNewValue is the index to the entry to be used to complete the request for the current test step section, ie if aNewValue
       
  2248  is 0, iTestNumber is 3, and aEtelCommand is ENetworkQoSChange, the entry will complete any NotifyNetworkQoSChange calls
       
  2249  with data from the first QosNetworkNotification= entry of section [test3] in the config.txt file
       
  2250 */
       
  2251 
       
  2252 
       
  2253 TInt CCEsockTestBase::EtelRequestL(TUint aEventKey, TInt aNewValue)
       
  2254 	{
       
  2255   	// simtsy will listen for any changes to the property, and complete the corresponding request
       
  2256 	TInt error = RProperty::Set(KUidPSSimTsyCategory, aEventKey, aNewValue);
       
  2257 
       
  2258 	return error;
       
  2259 	}
       
  2260 
       
  2261 
       
  2262 //
       
  2263 
       
  2264 
       
  2265 
       
  2266 //
       
  2267 //simtsy functionality
       
  2268 
       
  2269 TInt TSimTsy::Start()
       
  2270     {
       
  2271     //define name of the Phone module to be used for the RTelServer
       
  2272     _LIT(KMtsyName, "SIM");
       
  2273     TInt res = StartC32();
       
  2274     if (res!=KErrNone)
       
  2275             return res;
       
  2276     TInt error = iServer.Connect();
       
  2277     if (error!=KErrNone)
       
  2278             return error;
       
  2279     error = iServer.LoadPhoneModule(KMtsyName);
       
  2280    	if (error!=KErrNone)
       
  2281             return error;
       
  2282    	error = iPhone.Open(iServer, KPhoneName);
       
  2283     if (error!=KErrNone)
       
  2284             return error;
       
  2285     error = SetTestNumber(0);
       
  2286 	return error;
       
  2287     }
       
  2288 
       
  2289 
       
  2290 void TSimTsy::Stop()
       
  2291     {
       
  2292     iPhone.Close();
       
  2293     iServer.Close();
       
  2294     }
       
  2295 
       
  2296 
       
  2297 TInt TSimTsy::SetTestNumber(TInt aTestSectionNumber)
       
  2298 	{
       
  2299    	return RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, aTestSectionNumber);
       
  2300 	}
       
  2301 
       
  2302 //
       
  2303