servicediscoveryandcontrol/pnp/test/integtest/src/testpnpmanager.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 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 // Contains implementation of CTestPnPManager class
       
    15 // Contains implemenatation of CTestPnPManager, CTestPnPObserver, CTestPnPTimer, 
       
    16 // and CAction classes
       
    17 // 
       
    18 //
       
    19 
       
    20 #include "testpnpmanager.h"
       
    21 
       
    22 
       
    23 /*
       
    24   Constructor:
       
    25   @test
       
    26 */
       
    27 CTestPnPManager::CTestPnPManager()
       
    28 :	CTestStep()
       
    29 	{
       
    30 	iCancelDiscovery = EFalse;
       
    31 	}
       
    32 
       
    33 /*
       
    34    Initializes all member vaiables.
       
    35    @param		None.
       
    36    @return		None.
       
    37 */
       
    38 void CTestPnPManager::InitializeL()
       
    39 	{
       
    40     iScheduler = new (ELeave) CActiveScheduler;
       
    41 	CActiveScheduler::Install(iScheduler);
       
    42 	}
       
    43 
       
    44 /*
       
    45    Destructor
       
    46    @test
       
    47 */
       
    48 CTestPnPManager::~CTestPnPManager()
       
    49 	{
       
    50 	_LIT(KInfoDesctructorBegin, "Begin: In Destructor CTestPnPanager....\n");
       
    51 	INFO_PRINTF1(KInfoDesctructorBegin);
       
    52 	delete iScheduler;
       
    53 	iScheduler = NULL;	
       
    54 	iControlChannel.Close();	
       
    55 	iControlPoint.Close();
       
    56 	iServicePoint.Close();
       
    57 	}
       
    58 
       
    59 
       
    60 
       
    61 /*
       
    62    Implementation of CTestStep base class virtual and this is used for doing all
       
    63    initialisation common
       
    64     to derived classes here.
       
    65    @param  None
       
    66    @return TVerdict
       
    67  */
       
    68 TVerdict CTestPnPManager::doTestStepPreambleL()
       
    69 	{
       
    70     InitializeL();
       
    71 	return CTestStep::doTestStepPreambleL();
       
    72 	}
       
    73 
       
    74 
       
    75 /*
       
    76  return Script File name..if any
       
    77 */
       
    78 const TDesC& CTestPnPManager::ScriptFileName()
       
    79 	{
       
    80 	return iScriptName;
       
    81 	}
       
    82 
       
    83 
       
    84 /*
       
    85    Implementation of CTestStep base class virtual and it is used for doing all
       
    86    after test treatment common to derived classes in here.
       
    87    @return TVerdict
       
    88  */
       
    89 TVerdict CTestPnPManager::doTestStepPostambleL()
       
    90 	{
       
    91 	return CTestStep::doTestStepPostambleL();
       
    92 	}
       
    93 
       
    94 
       
    95 TVerdict CTestPnPManager::doTestStepL()
       
    96 	{
       
    97 	SequenceOperationsL();
       
    98 	return TestStepResult();
       
    99 	}
       
   100 
       
   101 /*
       
   102    This function performs operations based on sequence specified in the ini file
       
   103    @param  None
       
   104    @return None
       
   105 */
       
   106 void CTestPnPManager::SequenceOperationsL()
       
   107 	{
       
   108 	_LIT(KInfoLogFile, "SequenceOperationsL().... \n");
       
   109 	INFO_PRINTF1(KInfoLogFile);
       
   110 	RArray<TPtrC> sequenceList;
       
   111 	CleanupClosePushL(sequenceList);
       
   112 	TPtrC listOfSequences;
       
   113 	_LIT(KListOfSequences, "listofsequences");
       
   114 	GetStringFromConfig(ConfigSection(), KListOfSequences, listOfSequences);
       
   115 
       
   116 	TokenizeStringL(listOfSequences, sequenceList);
       
   117 	TInt numOperations = sequenceList.Count();
       
   118 
       
   119 	for(TInt i(0); i < numOperations; i++)
       
   120 		{
       
   121 		SetCurrentSection(sequenceList[i]);
       
   122 		PerformDesiredOperationsL(sequenceList[i]);
       
   123 		}
       
   124 	CleanupStack::PopAndDestroy(); 
       
   125 	_LIT(KInfoLogFile1, "SequenceOperationsL() End.... \n");
       
   126 	INFO_PRINTF1(KInfoLogFile1);
       
   127 	}
       
   128 
       
   129 
       
   130 /*
       
   131    This function performs desired operations specified as a parameter
       
   132    @param  aOperation string representing operation to be performed
       
   133    @return None
       
   134 */
       
   135 void CTestPnPManager::PerformDesiredOperationsL(const TDesC& aOperation)
       
   136 	{
       
   137 	const TInt KMatch = 0;
       
   138 	TPtrC operationType;
       
   139 	_LIT(KOperationType, "operationtype");
       
   140 	GetStringFromConfig(aOperation, KOperationType, operationType);
       
   141 	
       
   142 	if(operationType.Compare(KOpenDiscoverer) == KMatch)
       
   143 		{
       
   144 		OpenDiscovererL();
       
   145 		}
       
   146 	else if(operationType.Compare(KOpenPublisher) == KMatch)
       
   147 		{
       
   148 		OpenPublisherL();
       
   149 		}
       
   150 	else if(operationType.Compare(KDiscovery) == KMatch)
       
   151 		{
       
   152 		DiscoverL();
       
   153 		}
       
   154 	else if(operationType.Compare(KCancelDiscover) == KMatch)
       
   155 		{
       
   156 		CancelDiscoverL();
       
   157 		}
       
   158 	else if(operationType.Compare(KDescribe) == 0)
       
   159 	    {
       
   160     	DescribeServiceL();
       
   161     	}
       
   162     else if(operationType.Compare(KCancelDescribe) == KMatch)
       
   163 		{
       
   164 		CancelDescribeL();
       
   165 		}
       
   166 	else if(operationType.Compare(KPublishService) == KMatch)
       
   167 		{
       
   168 		PublishServiceL(aOperation);
       
   169 		}
       
   170 	else if(operationType.Compare(KSubscribe) == KMatch)
       
   171 		{
       
   172 		SubscribeForStateChangeNotificationsL();
       
   173 		}
       
   174 	else if(operationType.Compare(KRegisterAnnouncement) == KMatch)
       
   175 		{
       
   176 		RegisterForAnnouncementsL();
       
   177 		}
       
   178 	else if(operationType.Compare(KCancelNotify) == KMatch)
       
   179 		{
       
   180 		CancelNotifyAnnouncementL();
       
   181 		}
       
   182 	else if(operationType.Compare(KNotify) == KMatch)
       
   183 		{
       
   184 	    SendNotificationsL();
       
   185 		}
       
   186 	else if(operationType.Compare(KOpenDiscovererFail) == KMatch)
       
   187 	   {
       
   188 	   OpenDiscovererFailed();
       
   189 	   }
       
   190     else if(operationType.Compare(KOpenPublisherFail) == KMatch)
       
   191 	   {
       
   192 	   OpenPublisherFailed();   
       
   193 	   }
       
   194 	}
       
   195 
       
   196 /*
       
   197    Parses a comma separated string and constructs a list out of the values
       
   198    @param	aString a reference to a string to be tokenized
       
   199    @param	aList is an out parameter to store a list of tokens in an arry
       
   200    @param	aSeparator is a character used to delimit the tokens
       
   201   */
       
   202 void CTestPnPManager::TokenizeStringL(const TDesC& aString, RArray<TPtrC>& aList, TChar aSeparator)
       
   203 	{
       
   204 	TLex lexer(aString);
       
   205 
       
   206 	while(!lexer.Eos())
       
   207 		{
       
   208 		lexer.SkipSpaceAndMark();
       
   209 
       
   210 		while(!lexer.Eos() && lexer.Get() != aSeparator)
       
   211 			{
       
   212 			}
       
   213 
       
   214 		if(!lexer.Eos())
       
   215 			{
       
   216 			lexer.UnGet();
       
   217 			}
       
   218 		aList.AppendL(lexer.MarkedToken());
       
   219 		lexer.Inc();
       
   220 		}
       
   221 	}
       
   222 
       
   223 
       
   224 /*
       
   225    Sets the current config section.
       
   226    @param	aCurrentSection - a reference string that represent current config section
       
   227    @return	None
       
   228  */
       
   229 void CTestPnPManager::SetCurrentSection(const TDesC& aCurrentSection)
       
   230 	{
       
   231 	iCurrentSection = aCurrentSection;
       
   232 	}
       
   233 
       
   234 /*
       
   235    Retrieve the current config section.
       
   236    @param
       
   237    @return	Reference to current config section
       
   238  */
       
   239 TDesC& CTestPnPManager::GetCurrentSection()
       
   240 	{
       
   241 	return	iCurrentSection;
       
   242 	}
       
   243 
       
   244 /*
       
   245 	Tests whether discovering services/devices is performed
       
   246 	@param		aOperationType is reference to a section name in ini file where required parameters
       
   247 				needs to be referred for this operation.
       
   248 	@return		None.
       
   249  */
       
   250 void CTestPnPManager::DiscoverL()
       
   251 	{
       
   252 	RArray<TPtrC> serviceTypeList;
       
   253 	TPtrC listOfServiceTypes;
       
   254 	_LIT(KListOfServiceTypes, "listofservicetypes");
       
   255 	_LIT(KInfoLogFile, "DiscoverL.... \n");
       
   256 	INFO_PRINTF1(KInfoLogFile);
       
   257 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   258 	
       
   259 	RPnPParameterBundle pnpBundle;
       
   260 	pnpBundle.Open ();
       
   261 	CleanupClosePushL( pnpBundle );
       
   262 	pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   263 
       
   264 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (ETestPnPDiscoverRequestParamSet);
       
   265 	if(!GetStringFromConfig(GetCurrentSection(), KListOfServiceTypes, listOfServiceTypes))
       
   266 		{
       
   267 		_LIT(KErrInfo, "Problem in reading values from ini. \n Expected fields are: \n%S \n");
       
   268 		ERR_PRINTF2( KErrInfo, &KListOfServiceTypes );
       
   269 		return;
       
   270 		}
       
   271 
       
   272 	TokenizeStringL(listOfServiceTypes, serviceTypeList);
       
   273 	TInt numUris = serviceTypeList.Count();
       
   274 
       
   275 	serviceTypeList.Close();
       
   276 	iControlPoint.Discover(pnpBundle);
       
   277 
       
   278 	_LIT(KInfoLogFile1, "DiscoverL End... \n");
       
   279 	INFO_PRINTF1(KInfoLogFile1);
       
   280 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   281 	}
       
   282 
       
   283 
       
   284 /*
       
   285 	Tests whether Publishing a Service/Device is performed
       
   286 	@param			aOperationType is reference to a section name in ini file where required parameters
       
   287 					needs to be referred for this operation.
       
   288 	@return			None.
       
   289  */
       
   290 void CTestPnPManager::PublishServiceL (const TDesC& aOperationType)
       
   291 	{
       
   292 	_LIT(KInfoLogFile, "PublishServiceL().... \n");
       
   293 	INFO_PRINTF1(KInfoLogFile);
       
   294 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   295 	RPnPParameterBundle pnpBundle ;
       
   296 	pnpBundle.Open();
       
   297 	
       
   298     CleanupClosePushL( pnpBundle );
       
   299     pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   300     RParameterFamily family = pnpBundle.CreateFamilyL(ETestPnPServiceRegisterParamSet);
       
   301     
       
   302     TPtrC serviceType;
       
   303 	GetStringFromConfig(aOperationType, KServiceType, serviceType);
       
   304 	RBuf8 serviceTypeBuf;
       
   305 	serviceTypeBuf.Create(serviceType.Length());
       
   306 	serviceTypeBuf.Copy(serviceType);
       
   307 	
       
   308 	iServicePoint.Publish( pnpBundle );
       
   309     serviceTypeBuf.Close();
       
   310     
       
   311 	_LIT(KInfoLogFile1, "PublishServiceL() End.... \n");
       
   312 	INFO_PRINTF1(KInfoLogFile1);
       
   313 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   314 	}
       
   315 
       
   316 
       
   317 void CTestPnPManager::SendNotificationsL ()
       
   318 	{
       
   319 	_LIT(KInfoLogFile, "SendNotificationsL.... \n");
       
   320 	INFO_PRINTF1(KInfoLogFile);
       
   321  
       
   322     RPnPParameterBundle pnpBundle;
       
   323     pnpBundle.CreateL();   
       
   324     CleanupClosePushL( pnpBundle );
       
   325 
       
   326 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL(ETestPnPServiceNotificationParamSet);
       
   327 
       
   328 	iServicePoint.SendNotify( pnpBundle );
       
   329     _LIT(KInfoLogFile1, "SendNotificationsL End.... \n");
       
   330 	INFO_PRINTF1(KInfoLogFile1);
       
   331 	CleanupStack::Pop( &pnpBundle );	
       
   332 	}
       
   333 
       
   334 
       
   335 /*	Opens a handle to a RPnPServiceDiscovery object
       
   336 	@param			None.
       
   337 	@return			None.
       
   338  */
       
   339 void CTestPnPManager::OpenDiscovererL()
       
   340 	{
       
   341 	_LIT(KInfoLogFile, "OpenDiscovererL().... \n");
       
   342 	INFO_PRINTF1(KInfoLogFile);
       
   343 	
       
   344 	TBool cpStatus = EFalse;
       
   345 	TInt openStatus = 0;
       
   346 	_LIT(KCpStatus, "cpstatus");
       
   347 	GetBoolFromConfig(GetCurrentSection(), KCpStatus, cpStatus);
       
   348 	if(!cpStatus)
       
   349 		{
       
   350 		_LIT(KInfoDiscoverer, "Control Point should not be Created \n");
       
   351 		INFO_PRINTF1(KInfoDiscoverer);
       
   352 		return;
       
   353 		}
       
   354 
       
   355 	openStatus = iControlPoint.Open(KTestTierId);
       
   356 	
       
   357 	if(openStatus != KErrNone) 
       
   358 		{
       
   359 		_LIT(KOpenDiscovererFailed, "Control Point discovery open failed with error %d ");
       
   360 		ERR_PRINTF2(KOpenDiscovererFailed, openStatus);
       
   361 		SetTestStepError(openStatus);
       
   362 		}
       
   363 	else
       
   364 		{
       
   365 		_LIT(KOpenDiscovererSuccess, "Control Point Discovery was successfully started with return value %d :");
       
   366 		INFO_PRINTF2(KOpenDiscovererSuccess, openStatus);
       
   367 		}
       
   368 		
       
   369 	_LIT8(KUri, "Prakash");
       
   370 	TBuf8<255> buf(KUri);
       
   371 	iControlPoint.InitiateControl(iControlChannel,buf);
       
   372 	iMsg.SetMessagePtr(buf);
       
   373     TPtrC8 iPtr=iMsg.MessagePtr();	
       
   374     if ( !iMsg.IsLast () )
       
   375 	      {
       
   376 	      iMsg.ClearFlags();
       
   377 	      iControlChannel.Send(iMsg,iStatus);
       
   378 	      CTestTimer* testTimer = CTestTimer::NewL(*this);
       
   379 	      testTimer->After(2000000);
       
   380 	      CActiveScheduler::Start();
       
   381 	      delete testTimer;
       
   382 		  }
       
   383 	}
       
   384 
       
   385 
       
   386 /*
       
   387 	Opens a handle to a RPnPServicePublisher object 
       
   388 	@param			None.
       
   389 	@return			TBool representing success or failure of the operation.
       
   390  */
       
   391 void CTestPnPManager::OpenPublisherL()
       
   392 	{
       
   393 	_LIT(KInfoLogFile, "OpenPublisherL().... \n");
       
   394 	INFO_PRINTF1(KInfoLogFile);
       
   395 	
       
   396 	TBool spStatus = EFalse;
       
   397 	TInt openStatus = 0;
       
   398 	_LIT(KSpStatus, "spstatus");
       
   399 	GetBoolFromConfig(GetCurrentSection(), KSpStatus, spStatus);
       
   400 
       
   401 	openStatus = iServicePoint.Open(KTestTierId);
       
   402 
       
   403   	if( openStatus != KErrNone )
       
   404   		{
       
   405  		_LIT(KOpenDiscovererFailed, "Publisher open failed with error %d ");
       
   406  		ERR_PRINTF2(KOpenDiscovererFailed, openStatus);
       
   407  		SetTestStepError(openStatus);
       
   408  		}
       
   409  	else
       
   410  		{
       
   411  		_LIT(KOpenPublisherSuccess, "Service publisher was successfully started with return value %d :");
       
   412   		INFO_PRINTF2(KOpenPublisherSuccess, openStatus);
       
   413  		}
       
   414  		
       
   415  	iServicePoint.InitiateControl(iControlChannel);
       
   416 	_LIT8(KUri, "Rajesh");
       
   417 	TBufC8<255> buf(KUri);	
       
   418 	iMsg.SetMessageDes ( buf );    
       
   419     iMsg.SetLast ();
       
   420     TPtrC8 iPtr= iMsg.MessageDes();
       
   421 	TInt newLen = buf.Length();
       
   422 	iMsg.SetMaxLength (newLen);
       
   423 	TInt maxLen =iMsg.MaxLength();
       
   424 	iControlChannel.Recv(iMsg,iStatus);
       
   425     CTestTimer* testTimer = CTestTimer::NewL(*this);
       
   426 	testTimer->After(2000000);
       
   427 	CActiveScheduler::Start();
       
   428 	delete testTimer;
       
   429 	}
       
   430 	
       
   431 
       
   432 /*
       
   433 Test for Register announcements ssdp:alive and ssdp:byebye messages
       
   434 	@param			aOperationType is reference to a section name in ini file where required parameters
       
   435 					needs to be referred for this operation.
       
   436 	@return			None.
       
   437 */
       
   438 void  CTestPnPManager::RegisterForAnnouncementsL ()
       
   439 	{
       
   440 	_LIT(KInfoLogFile, "RegisterForAnnouncementsL().... \n");
       
   441 	INFO_PRINTF1(KInfoLogFile);
       
   442 	RArray<TPtrC> uriTypeList;
       
   443 	TPtrC listOfUriTypes;
       
   444 	_LIT(KListOfUriTypes, "listofuritypes");
       
   445 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   446 	
       
   447 	RPnPParameterBundle pnpBundle;
       
   448 	pnpBundle.CreateL ();
       
   449 	CleanupClosePushL( pnpBundle );
       
   450 	pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   451 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (ETestPnPRegisterAnnouncementParamSet);
       
   452 	
       
   453 	if(!GetStringFromConfig(GetCurrentSection(), KListOfUriTypes, listOfUriTypes))
       
   454 		{
       
   455 		_LIT(KErrInfo, "Problem in reading values from ini. \n Expected fields are: %S \n");
       
   456 		ERR_PRINTF2( KErrInfo, &KListOfUriTypes);
       
   457 		return;
       
   458 		}
       
   459 
       
   460 	TokenizeStringL(listOfUriTypes, uriTypeList);
       
   461 	TInt numUris = uriTypeList.Count();
       
   462 
       
   463 	uriTypeList.Close();
       
   464 	iControlPoint.RegisterNotify( pnpBundle );
       
   465 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   466 	_LIT(KInfoLogFile1, "RegisterForAnnouncementsL() End.... \n");
       
   467 	INFO_PRINTF1(KInfoLogFile1);	
       
   468 	}
       
   469 
       
   470 /*
       
   471 	Tests whether subscribtion to event change notifications is performed
       
   472 	@param			None.
       
   473 	@return			None.
       
   474  */
       
   475 void  CTestPnPManager::SubscribeForStateChangeNotificationsL()
       
   476 	{
       
   477 	_LIT(KInfoLogFile, "SubscribeForStateChangeNotificationsL() start.... \n");
       
   478 	INFO_PRINTF1(KInfoLogFile);
       
   479 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   480 	CleanupStack::PushL( pnpObserver );
       
   481 	RPnPParameterBundle pnpBundle;
       
   482 	pnpBundle.CreateL ();
       
   483 	CleanupClosePushL( pnpBundle );
       
   484 	pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   485 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (ETestPnPSubscribeRequestParamSet);
       
   486 
       
   487 	iControlPoint.Subscribe( pnpBundle );
       
   488 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   489 	CleanupStack::PopAndDestroy( pnpObserver );
       
   490 	_LIT(KInfoLogFile1, "SubscribeForStateChangeNotificationsL() End.... \n");
       
   491 	INFO_PRINTF1(KInfoLogFile1);
       
   492 	}
       
   493 
       
   494 
       
   495 /*	Test for Cancelling Discovery Operation
       
   496 	@param			aOperationType is reference to a section name in ini file where required parameters
       
   497 					needs to be referred for this operation.
       
   498 	@return			None.
       
   499 */
       
   500 void CTestPnPManager::CancelDiscoverL()
       
   501 	{
       
   502 	iCancelDiscovery = ETrue;
       
   503 	_LIT(KInfoLogFile, "CancelDiscoverL().... \n");
       
   504 	INFO_PRINTF1(KInfoLogFile);
       
   505 	
       
   506 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   507 	
       
   508 	RPnPParameterBundle pnpBundle;
       
   509 	pnpBundle.CreateL ();
       
   510 	CleanupClosePushL( pnpBundle );
       
   511 	pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   512 
       
   513 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (ETestPnPCancelDiscoverParamSet);
       
   514 
       
   515 	iControlPoint.Cancel ( pnpBundle );
       
   516 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   517 	
       
   518 	_LIT(KInfoLogFile1, "CancelDiscoverL() End.... \n");
       
   519 	INFO_PRINTF1(KInfoLogFile1);
       
   520 	}
       
   521 
       
   522 void CTestPnPManager::CancelDescribeL()
       
   523 	{
       
   524 	_LIT(KInfoLogFile, "CancelDescribeL().... \n");
       
   525 	INFO_PRINTF1(KInfoLogFile);
       
   526 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   527 	
       
   528 	RPnPParameterBundle pnpBundle;
       
   529 	pnpBundle.CreateL ();
       
   530 	CleanupClosePushL( pnpBundle );
       
   531 	pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   532 
       
   533 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (ETestPnPCancelDescribeParamSet);
       
   534 
       
   535 	iControlPoint.Cancel ( pnpBundle );
       
   536 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   537 	_LIT(KInfoLogFile1, "CancelDescribeL() End.... \n");
       
   538 	INFO_PRINTF1(KInfoLogFile1);
       
   539 	}
       
   540 
       
   541 
       
   542 
       
   543 /*	Test for Cancelling Register Announcement
       
   544 	@param			aOperationType is reference to a section name in ini file where required parameters
       
   545 					needs to be referred for this operation.
       
   546 	@return			None.
       
   547  */
       
   548 void  CTestPnPManager::CancelNotifyAnnouncementL()
       
   549 	{
       
   550 	_LIT(KInfoLogFile, "CancelNotifyAnnouncementL().... \n");
       
   551 	INFO_PRINTF1(KInfoLogFile);
       
   552 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   553 		
       
   554 	RPnPParameterBundle pnpBundle;
       
   555 	pnpBundle.CreateL ();
       
   556 	CleanupClosePushL( pnpBundle );
       
   557 	pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   558 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL ( ETestPnPCancelRegisterNotifyParamSet );
       
   559 	
       
   560 	iControlPoint.Cancel ( pnpBundle);
       
   561 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   562 	_LIT(KInfoLogFile1, "CancelNotifyAnnouncementL() End.... \n");
       
   563 	INFO_PRINTF1(KInfoLogFile1);
       
   564 	}
       
   565 
       
   566 /*
       
   567   Constructor:
       
   568 */
       
   569 CTestPnPObserver::CTestPnPObserver()
       
   570 	:iSequence(0)
       
   571 	{
       
   572 	}
       
   573 
       
   574 /*
       
   575   Destructor
       
   576 */
       
   577 CTestPnPObserver::~CTestPnPObserver()
       
   578 	{
       
   579 	}
       
   580 
       
   581 
       
   582 /*
       
   583 	Static factory constructor. Uses two phase construction and leaves nothing on the
       
   584 	CleanupStack. Creates a CTestControlPointService object.
       
   585 	@param			aManager	A pointer to a CTestPnPManager object.
       
   586 	@return			A pointer to the newly created CPnPObserver object.
       
   587 	@post			A fully constructed and initialized CPnPObserver object.
       
   588  */
       
   589 CTestPnPObserver* CTestPnPObserver::NewL(CTestPnPManager* aManager)
       
   590 	{
       
   591 	CTestPnPObserver* self = new(ELeave) CTestPnPObserver;
       
   592 	CleanupStack::PushL(self);
       
   593 	self->ConstructL(aManager);
       
   594 	CleanupStack::Pop(self);
       
   595 	return self;
       
   596 	}
       
   597 
       
   598 /*
       
   599 	Second phase of two-phase construction method. Does any allocations required to fully construct
       
   600 	the object.
       
   601 	@pre 		First phase of construction is complete.
       
   602 	@param		aManager	A pointer to a CTestPnPManager object.
       
   603 	@post		The object is fully constructed and initialized.
       
   604  */
       
   605 void CTestPnPObserver::ConstructL(CTestPnPManager* aManager)
       
   606 	{
       
   607 	iManager = aManager;
       
   608 	}
       
   609 
       
   610 
       
   611 
       
   612 /*
       
   613    This method returns a reference to the CTestPnPManager object.
       
   614    @param None
       
   615    return a reference to the CTestPnPManager object
       
   616  */
       
   617 CTestPnPManager& CTestPnPObserver::Manager()
       
   618 	{
       
   619 	return *iManager;
       
   620 	}
       
   621 
       
   622 /*
       
   623    This is called when callback hits. And this method stores the bundle results
       
   624    and meta information related to that results into results array maintained by manager
       
   625    for later verification.
       
   626    @param  aParameterBundle a reference to CPnPParameterBundleBase
       
   627    @return None
       
   628  */
       
   629 void CTestPnPObserver::OnPnPEventL ( RPnPParameterBundleBase& aParameterBundle)
       
   630 	{
       
   631 	_LIT(KInfoLogFile, "OnPnPEventL ().... \n");
       
   632 	Manager().INFO_PRINTF1(KInfoLogFile);
       
   633 
       
   634 	RParameterFamily paramFamily = aParameterBundle.GetFamilyAtIndex(0);
       
   635 	
       
   636 	if( paramFamily.IsNull ())
       
   637 		{
       
   638 		switch ( paramFamily.Id() )
       
   639 			{
       
   640 			case ETestPnPDiscoverResponseParamSet:
       
   641 				{				
       
   642 				_LIT(KInfoLogFile, "Discovery Response\n \n");
       
   643 	            Manager().INFO_PRINTF1(KInfoLogFile);
       
   644 				}
       
   645 			break;
       
   646 			
       
   647 			case ETestPnPPresenceAnnouncementParamSet:
       
   648 				{
       
   649 				_LIT(KInfoLogFile, "Presence Announcement Response\n");
       
   650 	            Manager().INFO_PRINTF1(KInfoLogFile);
       
   651 				}
       
   652 			break;
       
   653 
       
   654 			case ETestPnPAbsenceAnnouncementParamSet:
       
   655 				{				
       
   656 				_LIT(KInfoLogFile, "Absence Announcement Response\n");
       
   657 	            Manager().INFO_PRINTF1(KInfoLogFile);
       
   658 				}
       
   659 			break;
       
   660 
       
   661 			case ETestPnPPublishResponseParamSet:
       
   662 				{
       
   663                 _LIT(KInfoLogFile, "Publish Response\n");
       
   664 	            Manager().INFO_PRINTF1(KInfoLogFile);
       
   665 				}
       
   666 			break;
       
   667 			
       
   668 			case ETestPnPDescribeResponseParamSet:
       
   669 				{							
       
   670 				_LIT(KInfoLogFile, "Describe Response\n");
       
   671 	            Manager().INFO_PRINTF1(KInfoLogFile);
       
   672 			    }
       
   673 			break;
       
   674 			
       
   675 			case ETestPnPSubscribeResponseParamSet:
       
   676 				{				
       
   677                 _LIT(KInfoLogFile, "Subscribe Response\n");
       
   678 	            Manager().INFO_PRINTF1(KInfoLogFile);
       
   679              	}
       
   680 			break;
       
   681 			
       
   682 			case ETestPnPNotifyEventParamSet:
       
   683 				{//receives event notifications sent at client
       
   684 				_LIT(KInfoLogFile, "Notify Event Response\n");
       
   685 	            Manager().INFO_PRINTF1(KInfoLogFile);
       
   686 				}
       
   687 			break;
       
   688 			
       
   689 			default:
       
   690 			break;
       
   691 			}
       
   692 		}
       
   693 	}
       
   694 
       
   695 /*
       
   696    Error handling,asynchronous one.
       
   697    @param  aError Error Code
       
   698    @return None
       
   699  */
       
   700 void CTestPnPObserver::OnPnPError(TInt aError)
       
   701 	{
       
   702 	_LIT(KPositiveCase,"positivecase");
       
   703 	TBool positiveCase = ETrue;
       
   704 	Manager().GetBoolFromConfig(Manager().GetCurrentSection(), KPositiveCase, positiveCase);
       
   705 	// Note down the error and stop scheduler
       
   706 	_LIT(KErrorMessage, "Error occurred in the Test PnP Observer : %d \n");
       
   707 	Manager().ERR_PRINTF2(KErrorMessage, aError);
       
   708 	}
       
   709 
       
   710 
       
   711 void CTestPnPManager::DescribeServiceL()
       
   712 	{
       
   713 	_LIT(KInfoLogFile, "CTestPnPManager::DescribeServiceL().... \n");
       
   714 	INFO_PRINTF1(KInfoLogFile);
       
   715 
       
   716 	CTestPnPObserver* pnpObserver = CTestPnPObserver::NewL(this);
       
   717 	CleanupStack::PushL( pnpObserver );	
       
   718 	
       
   719 	RPnPParameterBundle pnpBundle;
       
   720 	pnpBundle.Open ();
       
   721 	CleanupClosePushL( pnpBundle );
       
   722 	pnpBundle.SetPnPObserver((MPnPObserver*)pnpObserver);
       
   723 
       
   724 	RParameterFamily pnpFamily = pnpBundle.CreateFamilyL (ETestPnPDescribeRequestParamSet);	
       
   725 
       
   726 	iControlPoint.Describe( pnpBundle );
       
   727 	_LIT(KInfoLogFile1, "CTestPnPManager::DescribeServiceL() End.... \n");
       
   728 	INFO_PRINTF1(KInfoLogFile1);
       
   729 	
       
   730 	CleanupStack::PopAndDestroy( &pnpBundle );
       
   731 	CleanupStack::PopAndDestroy( pnpObserver );
       
   732 	}
       
   733 
       
   734 
       
   735 /*Fails to open a handle to a RPnPServiceDiscovery object
       
   736   @param			None.
       
   737   @return			None.
       
   738  */
       
   739 void CTestPnPManager::OpenDiscovererFailed()
       
   740 	{
       
   741 	_LIT(KInfoLogFile, "OpenDiscovererFailed().... \n");
       
   742 	INFO_PRINTF1(KInfoLogFile);
       
   743 	
       
   744 	TInt openStatus = 0;
       
   745 	openStatus = iControlPoint.Open(KInvalidTestTierId);
       
   746 	
       
   747 	if(openStatus != KErrNone) 
       
   748 		{
       
   749 		_LIT(KOpenDiscovererFailed, "Control Point discovery open failed with error %d ");
       
   750 		ERR_PRINTF2(KOpenDiscovererFailed, openStatus);
       
   751 		SetTestStepError(openStatus);
       
   752 		}
       
   753 	else
       
   754 		{
       
   755 		_LIT(KOpenDiscovererSuccess, "Control Point Discovery was successfully started with return value %d :");
       
   756 		INFO_PRINTF2(KOpenDiscovererSuccess, openStatus);
       
   757 		}
       
   758 	}
       
   759 	
       
   760 	
       
   761 /*Fails to open a handle to a RPnPServicePublisher object
       
   762   @param			None.
       
   763   @return			None.
       
   764  */
       
   765 void CTestPnPManager::OpenPublisherFailed()
       
   766 	{
       
   767 	_LIT(KInfoLogFile, "OpenPublisherFailed().... \n");
       
   768 	INFO_PRINTF1(KInfoLogFile);
       
   769 	
       
   770 	TInt openStatus = 0;	
       
   771 	openStatus = iServicePoint.Open(KInvalidTestTierId);
       
   772 		
       
   773 	if( openStatus != KErrNone )
       
   774   		{
       
   775  		_LIT(KOpenPublisherFailed, "Publisher open failed with error %d ");
       
   776  		ERR_PRINTF2(KOpenPublisherFailed, openStatus);
       
   777  		SetTestStepError(openStatus);
       
   778  		}
       
   779  	else
       
   780  		{
       
   781  		_LIT(KOpenPublisherSuccess, "Service publisher was successfully started with return value %d :");
       
   782   		INFO_PRINTF2(KOpenPublisherSuccess, openStatus);
       
   783  		}
       
   784 	}
       
   785 	
       
   786 void CTestPnPManager::TimedOut()
       
   787 	{
       
   788 	iControlChannel.CancelRecv();
       
   789 	iControlChannel.CancelSend();
       
   790 	CActiveScheduler::Stop();	
       
   791 	}
       
   792 	
       
   793 // CTestTimer //
       
   794 CTestTimer* CTestTimer::NewL(MTimerObserver& aObserver)
       
   795 	{
       
   796 	return new(ELeave) CTestTimer(aObserver);	
       
   797 	}
       
   798 
       
   799 CTestTimer::~CTestTimer()
       
   800 	{
       
   801 	Cancel();
       
   802 	iTimer.Close();
       
   803 	}
       
   804 
       
   805 CTestTimer::CTestTimer(MTimerObserver& aObserver)
       
   806 :CActive(EPriorityStandard), iObserver(aObserver)
       
   807 	{
       
   808 	CActiveScheduler::Add(this);
       
   809 	iTimer.CreateLocal();
       
   810 	}
       
   811 
       
   812 void CTestTimer::RunL()
       
   813 	{
       
   814 	iObserver.TimedOut();
       
   815 	}
       
   816 
       
   817 void CTestTimer::DoCancel()
       
   818 	{
       
   819 	iTimer.Cancel();	
       
   820 	}
       
   821 	
       
   822 void CTestTimer::After(TTimeIntervalMicroSeconds32 aInterval)
       
   823 	{
       
   824 	iTimer.After(iStatus,  aInterval);
       
   825 	SetActive();
       
   826 	}
       
   827 	
       
   828 	
       
   829