kerneltest/e32test/resourceman/d_rescontrolcli.cpp
branchRCL_3
changeset 256 c1f20ce4abcf
parent 31 56f325a607ea
child 257 3e88ff8f41d5
equal deleted inserted replaced
249:a179b74831c9 256:c1f20ce4abcf
   281 
   281 
   282 DTestResManLddFactory::~DTestResManLddFactory()
   282 DTestResManLddFactory::~DTestResManLddFactory()
   283 	{
   283 	{
   284 	if(iDfcQ)
   284 	if(iDfcQ)
   285 	  iDfcQ->Destroy();
   285 	  iDfcQ->Destroy();
   286 	if(iStaticRes)
       
   287 		delete iStaticRes;
       
   288 	if(iStaticResArray[0])
       
   289 		delete iStaticResArray[0];
       
   290 	if(iStaticResArray[2])
       
   291 		delete iStaticResArray[2];
       
   292 	}
   286 	}
   293 
   287 
   294 /** Entry point for this driver */
   288 /** Entry point for this driver */
   295 DECLARE_STANDARD_LDD()
   289 DECLARE_STANDARD_LDD()
   296 	{
   290 	{
   317 		p->iDfcQ->Destroy();
   311 		p->iDfcQ->Destroy();
   318 		p->AsyncDelete();
   312 		p->AsyncDelete();
   319 		return NULL;
   313 		return NULL;
   320 		}
   314 		}
   321 	//Allocating memory earlier so that during failure conditions can cleanup easily
   315 	//Allocating memory earlier so that during failure conditions can cleanup easily
   322 	p->iStaticRes = new DLaterRegisterStaticResource();
   316 	p->iStaticRes = new DLaterRegisterStaticResource(); // it will be registered, and later destroyed by the ResourceManager
   323 	if(!p->iStaticRes)
   317 	if(!p->iStaticRes)
   324 		{
   318 		{
   325 		delete p->iClient.pName;
   319 		delete p->iClient.pName;
   326 		p->iDfcQ->Destroy();
   320 		p->iDfcQ->Destroy();
   327 		p->AsyncDelete();
   321 		p->AsyncDelete();
   328 		return NULL;
   322 		return NULL;
   329 		}
   323 		}
   330 	p->iStaticResArray[0] = new DLaterRegisterStaticResource1();
   324 	p->iStaticResArray[0] = new DLaterRegisterStaticResource1(); // it will be registered, and later destroyed by the ResourceManager
   331 	if(!p->iStaticResArray[0])
   325 	if(!p->iStaticResArray[0])
   332 		{
   326 		{
   333 		delete p->iStaticRes;
   327 		delete p->iStaticRes;
   334 		delete p->iClient.pName;
   328 		delete p->iClient.pName;
   335 		p->iDfcQ->Destroy();
   329 		p->iDfcQ->Destroy();
   410 /** Create logical channel, only open of one channel is allowed */
   404 /** Create logical channel, only open of one channel is allowed */
   411 TInt DTestResManLddFactory::Create(DLogicalChannelBase*& aChannel)
   405 TInt DTestResManLddFactory::Create(DLogicalChannelBase*& aChannel)
   412 	{
   406 	{
   413    	if (iOpenChannels != 0) //A Channel is already open
   407    	if (iOpenChannels != 0) //A Channel is already open
   414 		return KErrInUse;
   408 		return KErrInUse;
   415 	//Deregister the client registered in ldd init. 
       
   416 	TInt r = PowerResourceManager::DeRegisterClient(DTestResManLddFactory::iClient.iClientId);
       
   417 	if(r != KErrNone)
       
   418 		Kern::Fault("PRM CLIENT DEREGISTER FAILED", __LINE__);
       
   419 	delete DTestResManLddFactory::iClient.pName;
       
   420 	DTestResManLddFactory::iClient.pName = NULL;
       
   421 	DTestResManLddFactory::iClient.iClientId = 0;
       
   422 	aChannel = new DTestResManLdd;
   409 	aChannel = new DTestResManLdd;
   423 	if(!aChannel)
   410 	if(!aChannel)
   424 		return KErrNoMemory;
   411 		return KErrNoMemory;
   425 	return KErrNone;
   412 	return KErrNone;
   426 	}
   413 	}
   512 		TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
   499 		TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
   513 		m.Complete(r,ETrue);
   500 		m.Complete(r,ETrue);
   514 		}
   501 		}
   515 	}
   502 	}
   516 
   503 
   517 
   504 /** 
       
   505 	Function used for polling the PostBoot Notification status. 
       
   506 */
       
   507 TBool PollingPostBootStatus(TAny* aLddFactory)
       
   508 	{
       
   509 	if(aLddFactory)
       
   510 		if(((DTestResManLddFactory *)aLddFactory)->iPostBootNotiCount == EXPECTED_POST_NOTI_COUNT)
       
   511 			return ETrue;
       
   512 	return EFalse;
       
   513 	}
       
   514 	
   518 /**
   515 /**
   519   Process synchronous 'control' requests
   516   Process synchronous 'control' requests
   520 */
   517 */
   521 TInt DTestResManLdd::DoControl(TInt aFunction, TAny* a1, TAny* a2)
   518 TInt DTestResManLdd::DoControl(TInt aFunction, TAny* a1, TAny* a2)
   522 	{
   519 	{
   988 			r = Kern::ThreadDesWrite(iClientThreadPtr, a2, (const TDesC8&)*pBuf, 0);
   985 			r = Kern::ThreadDesWrite(iClientThreadPtr, a2, (const TDesC8&)*pBuf, 0);
   989 			break;
   986 			break;
   990 			}
   987 			}
   991 		case RTestResMan::ECheckPostBootLevelNotifications:
   988 		case RTestResMan::ECheckPostBootLevelNotifications:
   992 			{
   989 			{
   993 				if(DTestResManLddFactory::iPostBootNotiCount != EXPECTED_POST_NOTI_COUNT)
   990 			//aPollPeriodMs = 3ms (3rd argument)
   994 				{
   991 			//aMaxPoll = 1000 (in total ~3000 ms timeout)
   995 				r = KErrUnderflow;
   992 			r = Kern::PollingWait(PollingPostBootStatus, (TAny*)iDevice, 3, 1000);
   996 				break;
       
   997 				}
       
   998 			r = KErrNone;
       
   999 			break;
   993 			break;
  1000 			}
   994 			}
  1001 		case RTestResMan::EGetControllerVersion:
   995 		case RTestResMan::EGetControllerVersion:
  1002 			{
   996 			{
  1003 			TUint Version;
   997 			TUint Version;
  1333 void DTestResManLddFactory::PostBootNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam)
  1327 void DTestResManLddFactory::PostBootNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam)
  1334 	{
  1328 	{
  1335 	iPostBootNotiCount++;
  1329 	iPostBootNotiCount++;
  1336 	DPowerResourceNotification *ptr = (DPowerResourceNotification*)aParam;
  1330 	DPowerResourceNotification *ptr = (DPowerResourceNotification*)aParam;
  1337 	TInt r = PowerResourceManager::CancelNotification(iClient.iClientId, aResId, *ptr);
  1331 	TInt r = PowerResourceManager::CancelNotification(iClient.iClientId, aResId, *ptr);
  1338 	if(r == KErrNone)
  1332 	if(r == KErrCancel)
  1339 		delete ptr;
  1333 		{
  1340 	}
  1334 		ptr->AsyncDelete();
       
  1335 		if(iPostBootNotiCount == EXPECTED_POST_NOTI_COUNT)
       
  1336 			{
       
  1337 			r = PowerResourceManager::DeRegisterClient(DTestResManLddFactory::iClient.iClientId);
       
  1338 			if(r != KErrNone)
       
  1339 				Kern::Fault("PRM CLIENT DEREGISTER FAILED", __LINE__);
       
  1340 			delete DTestResManLddFactory::iClient.pName;
       
  1341 			DTestResManLddFactory::iClient.pName = NULL;
       
  1342 			DTestResManLddFactory::iClient.iClientId = 0;
       
  1343 			}
       
  1344 		}
       
  1345 	}