kernel/eka/drivers/resourceman/resourcecontrol.cpp
changeset 259 57b9594f5772
parent 247 d8d70de2bd36
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // e32\drivers\resourceman\resourcecontrol.cpp
    14 // e32\drivers\resourceman\resourcecontrol.cpp
    15 // 
    15 //
    16 //
    16 //
    17 
    17 
    18 #include <drivers/resourcecontrol.h>
    18 #include <drivers/resourcecontrol.h>
    19 #include <drivers/resourcecontrol_trace.h>
    19 #include <drivers/resourcecontrol_trace.h>
    20 #ifdef DEBUG_VERSION
    20 #ifdef DEBUG_VERSION
   311     {
   311     {
   312     __KTRACE_OPT(KRESMANAGER, Kern::Printf(">TInterface::ControlIO"));
   312     __KTRACE_OPT(KRESMANAGER, Kern::Printf(">TInterface::ControlIO"));
   313     return PowerResourceController->GetInterface(aClientId, aFunction, aParam1, aParam2, aParam3);
   313     return PowerResourceController->GetInterface(aClientId, aFunction, aParam1, aParam2, aParam3);
   314     }
   314     }
   315 
   315 
   316 /** Resouce controller panic */
   316 /** Resource controller panic */
   317 void DPowerResourceController::Panic(TUint8 aPanic)
   317 void DPowerResourceController::Panic(TUint8 aPanic)
   318 	{
   318 	{
   319 	Kern::Fault("Power Resource Controller", aPanic);
   319 	Kern::Fault("Power Resource Controller", aPanic);
   320 	}
   320 	}
   321 
   321 
   322 /** Constructor for power controller. Creates message queue and generates ID for power controller to use. */
   322 /** Constructor for power controller. Creates message queue and generates ID for power controller to use. */
       
   323 extern RPointerArray <DStaticPowerResource> *StaticResourceArrayPtr;
       
   324 #ifdef PRM_ENABLE_EXTENDED_VERSION
       
   325 extern RPointerArray <DStaticPowerResourceD> *StaticResourceDependencyArrayPtr;
       
   326 #endif
   323 DPowerResourceController::DPowerResourceController()
   327 DPowerResourceController::DPowerResourceController()
   324 	{
   328 	{
   325     __KTRACE_OPT(KRESMANAGER, Kern::Printf("DPowerResourceController::DPowerResouceController()"));
   329 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("DPowerResourceController::DPowerResouceController()"));
   326 	//Constructor is expected to invoke multiple times (during creation, variant init 0 and extension init 1)
   330 	// Constructor is expected to invoke multiple times, i.e.: 
   327 	if(PowerResourceController) 
   331 	// during creation: variant init 0(KModuleEntryReasonVariantInit0) and later extension init 1 (KModuleEntryReasonExtensionInit1)
       
   332 	if(PowerResourceController)
       
   333 		{
       
   334 		// If InitController() was called in the Init3() static resource arrays were populated already and invocation of this 
       
   335 		// constructor has zeroed the dynamic pointer arrays (calling their default constructors). In such case we need to 
       
   336 		// restore these arrays from their temporary shadow copies (i.e. copies of RPointerArray objects, not their content)
       
   337 		// (See comments in RegisterStaticResources())
       
   338 		if(StaticResourceArrayPtr)
       
   339 			{
       
   340 			// by making a (binary) copy of RPointerArray object (compiler's auto-generated code)
       
   341 			// we are taking the ownership of content (pointers stored/owned by that array) of this temporary array
       
   342 			iStaticResourceArray = *StaticResourceArrayPtr;
       
   343 			}
       
   344 #ifdef PRM_ENABLE_EXTENDED_VERSION
       
   345 		// the same applies to static resources with dependencies for extended version.
       
   346 		// Temporary object are de-allocated in InitResources()
       
   347 		if(StaticResourceDependencyArrayPtr)
       
   348 			{
       
   349 			iStaticResDependencyArray = *StaticResourceDependencyArrayPtr;
       
   350 			}
       
   351 #endif
   328 		return;
   352 		return;
       
   353 		}
   329     PowerResourceController = this;
   354     PowerResourceController = this;
   330 	iClientList.Initialise(0);
   355 	iClientList.Initialise(0);
   331 	iUserSideClientList.Initialise(0);
   356 	iUserSideClientList.Initialise(0);
   332 	iInitialised = EResConCreated;
   357 	iInitialised = EResConCreated;
   333 #ifdef PRM_ENABLE_EXTENDED_VERSION
   358 #ifdef PRM_ENABLE_EXTENDED_VERSION
   334 	iDynamicResourceList.Initialise(0);
   359 	iDynamicResourceList.Initialise(0);
   335 	iDynamicResDependencyList.Initialise(0);
   360 	iDynamicResDependencyList.Initialise(0);
   336 #endif
   361 #endif
   337 	}
       
   338 
       
   339 /** Destructor for power controller. Frees the memory allocated in kernel heap. */
       
   340 DPowerResourceController::~DPowerResourceController()
       
   341 	{
       
   342 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("DPowerResourceController::~DPowerResourceController()"));
       
   343 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
       
   344 	iCleanList.ResetAndDestroy();
       
   345 #endif
       
   346 	iClientList.Delete();
       
   347 	iUserSideClientList.Delete();
       
   348 
       
   349 
       
   350 		
       
   351 #ifdef PRM_ENABLE_EXTENDED_VERSION
       
   352 	iDynamicResourceList.Delete();
       
   353 	iDynamicResDependencyList.Delete();
       
   354 #endif
       
   355 
       
   356 	SPowerResourceClientLevel *pCL = iClientLevelPool;
       
   357 	while(iClientLevelPool) //Find the starting position of array to delete
       
   358 		{
       
   359 		if(iClientLevelPool < pCL)
       
   360 			pCL = iClientLevelPool;
       
   361 		iClientLevelPool = iClientLevelPool->iNextInList;
       
   362 		}
       
   363 	//delete pCL;
       
   364 	delete []pCL;
       
   365 	SPowerRequest *pReq = iRequestPool;
       
   366 	while(iRequestPool) //Find the starting position of array to delete
       
   367 		{
       
   368 		if(iRequestPool < pReq)
       
   369 			pReq = iRequestPool;
       
   370 		iRequestPool = iRequestPool->iNext;
       
   371 		}
       
   372 	//delete pR
       
   373 	delete []pReq;
       
   374 #ifdef PRM_ENABLE_EXTENDED_VERSION
       
   375 	pCL = iResourceLevelPool;
       
   376 	while(iResourceLevelPool)
       
   377 		{
       
   378 		if(iResourceLevelPool < pCL)
       
   379 			pCL = iResourceLevelPool;
       
   380 		iResourceLevelPool = iResourceLevelPool->iNextInList;
       
   381 		}
       
   382 	//delete resource pool
       
   383 	delete []pCL;
       
   384 	//delete Message Queue dependency
       
   385 	delete iMsgQDependency;
       
   386 #endif
       
   387 	//delete Message Queue
       
   388 	delete iMsgQ;
       
   389 	}
   362 	}
   390 
   363 
   391 /** Send notificatins to clients registered for it for the specified resource. */
   364 /** Send notificatins to clients registered for it for the specified resource. */
   392 void DPowerResourceController::CompleteNotifications(TInt aClientId, DStaticPowerResource* aResource, TInt aState, 
   365 void DPowerResourceController::CompleteNotifications(TInt aClientId, DStaticPowerResource* aResource, TInt aState, 
   393 													      TInt aReturnCode, TInt aLevelOwnerId, TBool aLock)
   366 													      TInt aReturnCode, TInt aLevelOwnerId, TBool aLock)
   710 		{
   683 		{
   711 		TInt aNewState = aReq->Level();
   684 		TInt aNewState = aReq->Level();
   712 		PRM_CLIENT_CHANGE_STATE_END_TRACE
   685 		PRM_CLIENT_CHANGE_STATE_END_TRACE
   713 		}
   686 		}
   714 #endif
   687 #endif
   715 	//Check whether callback is cancelled and if not queue the DFC.
   688 	//Check whether callback is canceled and if not queue the DFC.
   716     TPowerResourceCb* pCb = aReq->ResourceCb();
   689     TPowerResourceCb* pCb = aReq->ResourceCb();
   717     if(pCb)
   690     if(pCb)
   718 		{
   691 		{
   719         pCb->iMutex = pRC->iResourceMutex;
   692         pCb->iMutex = pRC->iResourceMutex;
   720         pCb->iPendingRequestCount++;    
   693         pCb->iPendingRequestCount++;    
   756 		{
   729 		{
   757 		pC = &tRes;
   730 		pC = &tRes;
   758 		pC->iClientId = aReq->ClientId();
   731 		pC->iClientId = aReq->ClientId();
   759 		DDynamicPowerResourceD* pDRes;
   732 		DDynamicPowerResourceD* pDRes;
   760 		if(aReq->ClientId() & KIdMaskDynamic)
   733 		if(aReq->ClientId() & KIdMaskDynamic)
   761 			pDRes = pRC->iDynamicResDependencyList[(TUint16)(aReq->ClientId() & ID_INDEX_BIT_MASK)];	
   734 			pDRes = pRC->iDynamicResDependencyList[(aReq->ClientId() & ID_INDEX_BIT_MASK)];	
   762 		else
   735 		else
   763 			pDRes = (DDynamicPowerResourceD*)pRC->iStaticResDependencyArray[(aReq->ClientId() & ID_INDEX_BIT_MASK) - 1];
   736 			pDRes = (DDynamicPowerResourceD*)pRC->iStaticResDependencyArray[(aReq->ClientId() & ID_INDEX_BIT_MASK) - 1];
   764 		pC->iName = pDRes->iName;
   737 		
       
   738 		if (pDRes != NULL)
       
   739 		    {
       
   740             pC->iName = pDRes->iName;
       
   741 		    }
       
   742 		else
       
   743 		    {
       
   744             pC->iName = &KNullDesC;
       
   745 		    }
   765 		}
   746 		}
   766 	else if((aReq->ClientId() == -1) || (aReq->ClientId() == KDynamicResourceDeRegistering))
   747 	else if((aReq->ClientId() == -1) || (aReq->ClientId() == KDynamicResourceDeRegistering))
   767 		{
   748 		{
   768         pC = &tRes;
   749         pC = &tRes;
   769         pC->iClientId = (TUint)-1;
   750         pC->iClientId = (TUint)-1;
   785 		{
   766 		{
   786 		TInt aNewState = aReq->Level();
   767 		TInt aNewState = aReq->Level();
   787 		PRM_CLIENT_CHANGE_STATE_END_TRACE
   768 		PRM_CLIENT_CHANGE_STATE_END_TRACE
   788 		}
   769 		}
   789 #endif
   770 #endif
   790 	//Check whether callback is cancelled and if not queue the DFC.
   771 	//Check whether callback is canceled and if not queue the DFC.
   791     TPowerResourceCb* pCb = aReq->ResourceCb();
   772     TPowerResourceCb* pCb = aReq->ResourceCb();
   792     if(pCb)
   773     if(pCb)
   793 		{
   774 		{
   794         pCb->iMutex = pRC->iResourceMutex;
   775         pCb->iMutex = pRC->iResourceMutex;
   795         pCb->iPendingRequestCount++;       
   776         pCb->iPendingRequestCount++;       
   854    Finally mark resource controller as fully initialised (ready to accept state change and get request)
   835    Finally mark resource controller as fully initialised (ready to accept state change and get request)
   855    and start the message queue if exists. */
   836    and start the message queue if exists. */
   856 TInt DPowerResourceController::InitResources()
   837 TInt DPowerResourceController::InitResources()
   857 	{
   838 	{
   858     __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::InitResources()"));
   839     __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::InitResources()"));
   859 	TUint16 count;
   840 	TInt count;
   860 	//Create a Kernel client object for Power Controller
   841 	//Create a Kernel client object for Power Controller
   861 	Lock();
   842 	Lock();
   862 	SPowerResourceClient * pC = NULL;
   843 	SPowerResourceClient * pC = NULL;
   863 	// By now client pool should be created
   844 	// By now client pool should be created
   864 	LIST_POP(iClientPool, pC, iNextInList);
   845 	LIST_POP(iClientPool, pC, iNextInList);
   865 	TUint16 growBy = iClientList.GrowBy();
   846 	TInt growBy = iClientList.GrowBy();
   866 	if(!pC)
   847 	if(!pC)
   867 		{
   848 		{
   868 		UnLock();
   849 		UnLock();
   869 		// coverity[alloc_fn]
   850 		// coverity[alloc_fn]
   870 		SPowerResourceClient *pCL = new SPowerResourceClient[growBy];
   851 		SPowerResourceClient *pCL = new SPowerResourceClient[growBy];
   898 	iClientList.Add(pC, iPowerControllerId);
   879 	iClientList.Add(pC, iPowerControllerId);
   899 	pC->iClientId = iPowerControllerId | CLIENT_POWER_CONTROLLER_BIT_MASK;
   880 	pC->iClientId = iPowerControllerId | CLIENT_POWER_CONTROLLER_BIT_MASK;
   900 	iPowerControllerId = pC->iClientId;
   881 	iPowerControllerId = pC->iClientId;
   901     iClientCount++;
   882     iClientCount++;
   902     if(TPowerController::PowerController())
   883     if(TPowerController::PowerController())
   903        TPowerController::PowerController()->RegisterResourceController(this, iPowerControllerId);
   884 		{
       
   885 		if(TPowerController::PowerController()->RegisterResourceController(this, iPowerControllerId))
       
   886 			{
       
   887 #ifndef RESOURCE_MANAGER_SIMULATED_PSL
       
   888 			Panic(EControllerAlreadyExists);	//	Panic with this error for any error returned by RegisterResourceController
       
   889 #endif
       
   890 			}
       
   891 		}
       
   892 
   904 	iInitialised =EResConStartupCompleted;
   893 	iInitialised =EResConStartupCompleted;
   905 	UnLock();
   894 	UnLock();
   906 	//Check the resource for postboot level and send notifications to clients registered for it.
   895 	//Check the resource for postboot level and send notifications to clients registered for it.
   907 	DStaticPowerResource *pR = NULL;
   896 	DStaticPowerResource *pR = NULL;
   908 	TInt r;
   897 	TInt r;
   909 	TPowerRequest req = TPowerRequest::Get();
   898 	TPowerRequest req = TPowerRequest::Get();
   910 	//For Static resource with no dependencies
   899 	//For Static resource with no dependencies
   911     for(count = 0; count< iStaticResourceArrayEntries; count++)
   900     for(count = 0; count < iStaticResourceArray.Count(); count++)
   912 		{
   901 		{
   913 		pR = iStaticResourceArray[count];
   902 		pR = iStaticResourceArray[count];
   914 		if(pR && (pR->iFlags & SET_VALID_POST_BOOT_LEVEL))
   903 		if(pR && (pR->iFlags & SET_VALID_POST_BOOT_LEVEL))
   915 			{
   904 			{
   916             //Form the request message
   905             //Form the request message
   929 				}
   918 				}
   930 			}
   919 			}
   931 		}
   920 		}
   932 #ifdef PRM_ENABLE_EXTENDED_VERSION
   921 #ifdef PRM_ENABLE_EXTENDED_VERSION
   933 	//For Static resource with dependencies 
   922 	//For Static resource with dependencies 
   934 	for(count = 0; count < iStaticResDependencyCount; count++)
   923 	for(count = 0; count < iStaticResDependencyArray.Count(); count++)
   935 		{
   924 		{
   936 		pR = iStaticResDependencyArray[count];
   925 		pR = iStaticResDependencyArray[count];
   937 		if(pR->iFlags & SET_VALID_POST_BOOT_LEVEL)
   926 		if(pR->iFlags & SET_VALID_POST_BOOT_LEVEL)
   938 			{
   927 			{
   939 			req.ReqType() = TPowerRequest::EChange;
   928 			req.ReqType() = TPowerRequest::EChange;
   944 			req.ResourceCb() = NULL;
   933 			req.ResourceCb() = NULL;
   945 			req.RequiresChange() = ETrue;
   934 			req.RequiresChange() = ETrue;
   946 			//Form the request message
   935 			//Form the request message
   947 			((DStaticPowerResourceD*)pR)->HandleChangePropagation(req, EChangeStart, req.ClientId(), KNoClient);
   936 			((DStaticPowerResourceD*)pR)->HandleChangePropagation(req, EChangeStart, req.ClientId(), KNoClient);
   948 			}
   937 			}
       
   938 		}
       
   939 #endif
       
   940 	
       
   941 	// delete the temporary copy of static resource array used during initialization.
       
   942 	if(StaticResourceArrayPtr)
       
   943 		{
       
   944 		delete StaticResourceArrayPtr;
       
   945 		StaticResourceArrayPtr = NULL;
       
   946 		}
       
   947 #ifdef PRM_ENABLE_EXTENDED_VERSION
       
   948 	// the same applies to dependency resources array for extended version.
       
   949 	if(StaticResourceDependencyArrayPtr)
       
   950 		{
       
   951 		delete StaticResourceDependencyArrayPtr;
       
   952 		StaticResourceDependencyArrayPtr = NULL;
   949 		}
   953 		}
   950 #endif
   954 #endif
   951 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::InitResources()"));
   955 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::InitResources()"));
   952     return KErrNone;
   956     return KErrNone;
   953 	}
   957 	}
  1259         iClientList.Delete();
  1263         iClientList.Delete();
  1260 		return KErrNoMemory;
  1264 		return KErrNoMemory;
  1261 		}
  1265 		}
  1262 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1266 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1263 	SPowerResourceClientLevel* pRL = NULL;
  1267 	SPowerResourceClientLevel* pRL = NULL;
  1264 	if(iStaticResDependencyCount)
  1268 	if(iStaticResDependencyArray.Count())
  1265 		{
  1269 		{
  1266 		pRL = new SPowerResourceClientLevel[iStaticResDependencyCount];
  1270 		pRL = new SPowerResourceClientLevel[iStaticResDependencyArray.Count()];
  1267 		if(!pRL)
  1271 		if(!pRL)
  1268 			{
  1272 			{
  1269 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Resource level Pool Allocation Failed"));
  1273 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Resource level Pool Allocation Failed"));
  1270 			delete []pC;
  1274 			delete []pC;
  1271 			delete []pCL;
  1275 			delete []pCL;
  1277 		}
  1281 		}
  1278 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1282 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1279 	iCleanList.Append(pC);
  1283 	iCleanList.Append(pC);
  1280 #endif
  1284 #endif
  1281 	Lock();
  1285 	Lock();
  1282 	TUint16 c;
  1286 	TInt c;
  1283 	for(c = 0; c < iStaticResDependencyCount; c++)
  1287 	for(c = 0; c < iStaticResDependencyArray.Count(); c++)
  1284 		{
  1288 		{
  1285 		LIST_PUSH(iResourceLevelPool, &pRL[c], iNextInList);
  1289 		LIST_PUSH(iResourceLevelPool, &pRL[c], iNextInList);
  1286 		}
  1290 		}
  1287 	iResourceLevelPoolCount = iStaticResDependencyCount;
  1291 	iResourceLevelPoolCount = (TUint16)iStaticResDependencyArray.Count();
  1288 #else
  1292 #else
  1289 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1293 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1290     iCleanList.Append(pC);
  1294     iCleanList.Append(pC);
  1291 #endif
  1295 #endif
  1292     Lock();
  1296     Lock();
  1293     TUint16 c;
  1297     TUint16 c;
  1294 #endif
  1298 #endif
  1295     // Create Client pool list
  1299     // Create Client pool list
  1296     for(c = 0; c< (aKClients + aUClients); c++)
  1300     for(c = 0; c < TUint16(aKClients + aUClients); c++)
  1297 		{
  1301 		{
  1298         LIST_PUSH(iClientPool, &pC[c], iNextInList);
  1302         LIST_PUSH(iClientPool, &pC[c], iNextInList);
  1299 		}
  1303 		}
  1300     // Create client level pool list
  1304     // Create client level pool list
  1301     for(c = 0; c < aNClientLevels; c++)
  1305     for(c = 0; c < aNClientLevels; c++)
  1377 	req->ReqType() = TPowerRequest::ERegisterKernelClient;
  1381 	req->ReqType() = TPowerRequest::ERegisterKernelClient;
  1378 	UnLock();
  1382 	UnLock();
  1379 	req->SendReceive(iMsgQ);
  1383 	req->SendReceive(iMsgQ);
  1380 	if(req->ReturnCode() == KErrNone)
  1384 	if(req->ReturnCode() == KErrNone)
  1381 		{
  1385 		{
  1382 		pC = iClientList[(TUint16)(req->ClientId() & ID_INDEX_BIT_MASK)];
  1386 		pC = iClientList[(req->ClientId() & ID_INDEX_BIT_MASK)];
  1383 		if(aType == EOwnerThread)
  1387 		if(aType == EOwnerThread)
  1384 			{
  1388 			{
  1385 			pC->iClientId |= CLIENT_THREAD_RELATIVE_BIT_MASK; //Set 31st bit;
  1389 			pC->iClientId |= CLIENT_THREAD_RELATIVE_BIT_MASK; //Set 31st bit;
  1386 			//Store the current thread Id;
  1390 			//Store the current thread Id;
  1387 			pC->iThreadId = thread.iId;
  1391 			pC->iThreadId = thread.iId;
  1388 			}
  1392 			}
  1389 		pC->iName = &aName;
  1393 		pC->iName = &aName;
  1390 		aClientId = pC->iClientId;
  1394 		aClientId = pC->iClientId;
  1391 		}
  1395 	    PRM_CLIENT_REGISTER_TRACE
  1392     PRM_CLIENT_REGISTER_TRACE
  1396 	    __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::RegisterClient, clientId = 0x%x", aClientId));
  1393 	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::RegisterClient, clientId = 0x%x", aClientId));
  1397 		}
  1394 	return(req->ReturnCode());
  1398 	return(req->ReturnCode());
  1395 	}
  1399 	}
  1396 
  1400 
  1397 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1401 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1398 TInt DPowerResourceController::HandleResourceRegistration(TPowerRequest& aReq)
  1402 TInt DPowerResourceController::HandleResourceRegistration(TPowerRequest& aReq)
  1426 	if(aRequest.ReqType() == TPowerRequest::ERegisterKernelClient)
  1430 	if(aRequest.ReqType() == TPowerRequest::ERegisterKernelClient)
  1427 		{
  1431 		{
  1428 		//Get Next client from FreePool
  1432 		//Get Next client from FreePool
  1429 		LIST_POP(iClientPool, pC, iNextInList);
  1433 		LIST_POP(iClientPool, pC, iNextInList);
  1430 
  1434 
  1431 		TUint16 growBy = iClientList.GrowBy();
  1435 		TInt growBy = iClientList.GrowBy();
  1432 		if(!pC)
  1436 		if(!pC)
  1433 			{
  1437 			{
  1434 			//Free Pool is empty, so try to grow the pool.
  1438 			//Free Pool is empty, so try to grow the pool.
  1435 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Client pool exhausted so growing client Pool by %d", growBy));
  1439 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Client pool exhausted so growing client Pool by %d", growBy));
  1436 			// coverity[alloc_fn]
  1440 			// coverity[alloc_fn]
  1471 		}
  1475 		}
  1472 	else // Request is registration of user side client
  1476 	else // Request is registration of user side client
  1473 		{
  1477 		{
  1474 		//Get Next client from FreePool
  1478 		//Get Next client from FreePool
  1475 		LIST_POP(iClientPool, pC, iNextInList);
  1479 		LIST_POP(iClientPool, pC, iNextInList);
  1476 		TUint16 growBy = iUserSideClientList.GrowBy();
  1480 		TInt growBy = iUserSideClientList.GrowBy();
  1477 		if(!pC)
  1481 		if(!pC)
  1478 			{
  1482 			{
  1479 			//Free Pool is empty, so try to grow the pool.
  1483 			//Free Pool is empty, so try to grow the pool.
  1480 			SPowerResourceClient *pCL = (SPowerResourceClient*)Kern::Alloc(sizeof(SPowerResourceClient) * growBy);
  1484 			SPowerResourceClient *pCL = (SPowerResourceClient*)Kern::Alloc(sizeof(SPowerResourceClient) * growBy);
  1481 			if(!pCL)
  1485 			if(!pCL)
  1484 				}
  1488 				}
  1485 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1489 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1486 			iCleanList.Append(pCL);
  1490 			iCleanList.Append(pCL);
  1487 #endif
  1491 #endif
  1488 			Lock();
  1492 			Lock();
  1489 			TUint16 count;
  1493 			TInt count;
  1490 			for(count = 0; count < growBy - 1; count++)
  1494 			for(count = 0; count < growBy - 1; count++)
  1491 				LIST_PUSH(iClientPool, &pCL[count], iNextInList);
  1495 				LIST_PUSH(iClientPool, &pCL[count], iNextInList);
  1492 			UnLock();
  1496 			UnLock();
  1493 #ifdef PRM_INSTRUMENTATION_MACRO
  1497 #ifdef PRM_INSTRUMENTATION_MACRO
  1494 		TUint size = growBy * sizeof(SPowerResourceClient);
  1498 		TUint size = growBy * sizeof(SPowerResourceClient);
  1550     SPowerResourceClientLevel* pCLL = NULL;
  1554     SPowerResourceClientLevel* pCLL = NULL;
  1551 	while(pCL != NULL)
  1555 	while(pCL != NULL)
  1552 		{
  1556 		{
  1553         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client 0x%x has requirement on resource %d", pCL->iClientId, pCL->iResourceId));
  1557         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client 0x%x has requirement on resource %d", pCL->iClientId, pCL->iResourceId));
  1554 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1558 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1555 		switch((pCL->iResourceId >>RESOURCE_BIT_IN_ID_CHECK) & 0x3)													
  1559 		switch((pCL->iResourceId >>RESOURCE_BIT_IN_ID_CHECK) & 0x3)
  1556 		{																		
  1560 			{
  1557 		case PRM_STATIC_RESOURCE:												
  1561 			case PRM_STATIC_RESOURCE:
  1558 			pR = iStaticResourceArray[pCL->iResourceId - 1];								
  1562 			pR = iStaticResourceArray[pCL->iResourceId - 1];
  1559 			break;																
  1563 				break;
  1560 		case PRM_DYNAMIC_RESOURCE:												
  1564 			case PRM_DYNAMIC_RESOURCE:
  1561 			pR = (iDynamicResourceList[(TUint16)(pCL->iResourceId & ID_INDEX_BIT_MASK)]);			
  1565 			pR = (iDynamicResourceList[(pCL->iResourceId & ID_INDEX_BIT_MASK)]);
  1562 			break;																
  1566 				break;
  1563 		case PRM_STATIC_DEPENDENCY_RESOURCE:									
  1567 			case PRM_STATIC_DEPENDENCY_RESOURCE:
  1564 			pR = (iStaticResDependencyArray[(TUint16)(pCL->iResourceId & ID_INDEX_BIT_MASK) - 1]);						
  1568 			pR = (iStaticResDependencyArray[(pCL->iResourceId & ID_INDEX_BIT_MASK) - 1]);
  1565 			break;																
  1569 				break;
  1566 		case PRM_DYNAMIC_DEPENDENCY_RESOURCE:									
  1570 			case PRM_DYNAMIC_DEPENDENCY_RESOURCE:
  1567 			pR = (iDynamicResDependencyList[(TUint16)(pCL->iResourceId & ID_INDEX_BIT_MASK)]);		
  1571 			pR = (iDynamicResDependencyList[(pCL->iResourceId & ID_INDEX_BIT_MASK)]);
  1568 			break;																
  1572 				break;
  1569 		}
  1573 			}
  1570 #else
  1574 #else
  1571 		pR = iStaticResourceArray[pCL->iResourceId -1];
  1575 		pR = iStaticResourceArray[pCL->iResourceId - 1];
  1572 #endif
  1576 #endif
  1573 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1577 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1574 		if(((pR->Sense() == DStaticPowerResource::ECustom) || ((TInt)pCL->iClientId == pR->iLevelOwnerId)) && (!(pCL->iResourceId & KIdMaskDynamic) ||
  1578 		if(pR  &&  (((pR->Sense() == DStaticPowerResource::ECustom) || ((TInt)pCL->iClientId == pR->iLevelOwnerId)) && (!(pCL->iResourceId & KIdMaskDynamic) ||
  1575 			         ((pCL->iResourceId & KIdMaskDynamic) && (((DDynamicPowerResource*)pR)->LockCount() != 0))))
  1579 			         ((pCL->iResourceId & KIdMaskDynamic) && (((DDynamicPowerResource*)pR)->LockCount() != 0)))))
  1576 #else
  1580 #else
  1577 		if((pR->Sense() == DStaticPowerResource::ECustom) || ((TInt)pCL->iClientId == pR->iLevelOwnerId)) 
  1581 		if(pR  &&  ((pR->Sense() == DStaticPowerResource::ECustom) || ((TInt)pCL->iClientId == pR->iLevelOwnerId))) 
  1578 #endif
  1582 #endif
  1579 		    {
  1583 		    {
  1580             pReq->ReqType() = TPowerRequest::ESetDefaultLevel;
  1584             pReq->ReqType() = TPowerRequest::ESetDefaultLevel;
  1581             pReq->ResourceId() = pCL->iResourceId;
  1585             pReq->ResourceId() = pCL->iResourceId;
  1582             pReq->ClientId() = pCL->iClientId;
  1586             pReq->ClientId() = pCL->iClientId;
  1691 	CHECK_CONTEXT(thread)
  1695 	CHECK_CONTEXT(thread)
  1692 	if((aClientId & USER_SIDE_CLIENT_BIT_MASK) || (aClientId == iPowerControllerId))
  1696 	if((aClientId & USER_SIDE_CLIENT_BIT_MASK) || (aClientId == iPowerControllerId))
  1693 		return KErrArgument;
  1697 		return KErrArgument;
  1694 	//Get the index from client ID
  1698 	//Get the index from client ID
  1695 	Lock();
  1699 	Lock();
  1696 	SPowerResourceClient* pC = iClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)];
  1700 	SPowerResourceClient* pC = iClientList[(aClientId & ID_INDEX_BIT_MASK)];
  1697     if(!pC)
  1701     if(!pC)
  1698 	    {
  1702 	    {
  1699         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found"));
  1703         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found"));
  1700         UNLOCK_RETURN(KErrNotFound);
  1704         UNLOCK_RETURN(KErrNotFound);
  1701 		}
  1705 		}
  1735 	ResourceStateChangeOfClientLevels(pC);
  1739 	ResourceStateChangeOfClientLevels(pC);
  1736 	// Add reserved request to pool
  1740 	// Add reserved request to pool
  1737 	iRequestPoolCount = (TUint16)(iRequestPoolCount + (TUint16)pC->iReservedRm);
  1741 	iRequestPoolCount = (TUint16)(iRequestPoolCount + (TUint16)pC->iReservedRm);
  1738 	PRM_CLIENT_DEREGISTER_TRACE
  1742 	PRM_CLIENT_DEREGISTER_TRACE
  1739 	//Increment the free pool count for client level and request level.
  1743 	//Increment the free pool count for client level and request level.
  1740 	iClientList.Remove(pC, (TUint16)(pC->iClientId & ID_INDEX_BIT_MASK));
  1744 	iClientList.Remove(pC, (pC->iClientId & ID_INDEX_BIT_MASK));
  1741 	pC->iName = NULL;
  1745 	pC->iName = NULL;
  1742 	iClientCount--; //Decrement client count
  1746 	iClientCount--; //Decrement client count
  1743 	LIST_PUSH(iClientPool, pC, iNextInList);
  1747 	LIST_PUSH(iClientPool, pC, iNextInList);
  1744 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::DeRegisterClient"));
  1748 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::DeRegisterClient"));
  1745 	UNLOCK_RETURN(KErrNone);
  1749 	UNLOCK_RETURN(KErrNone);
  1872 	SPowerResourceClient* pC;
  1876 	SPowerResourceClient* pC;
  1873 	if(aResourceName.Length() > KMaxResourceNameLength)
  1877 	if(aResourceName.Length() > KMaxResourceNameLength)
  1874 		return KErrTooBig;
  1878 		return KErrTooBig;
  1875 	Lock();
  1879 	Lock();
  1876 	VALIDATE_CLIENT(thread);
  1880 	VALIDATE_CLIENT(thread);
  1877 	TUint count = 0;
  1881 	TInt count = 0;
  1878 	//Search in static resource with no dependencies array for specified resource name.
  1882 	//Search in static resource with no dependencies array for specified resource name.
  1879 	for(count = 0; count < iStaticResourceArrayEntries; count++)
  1883 	for(count = 0; count < iStaticResourceArray.Count(); count++)
  1880 		{
  1884 		{
  1881 		if((iStaticResourceArray[count]) && (!(aResourceName.Compare(*(const TDesC8*)iStaticResourceArray[count]->iName))))
  1885 		if((iStaticResourceArray[count]) && (!(aResourceName.Compare(*(const TDesC8*)iStaticResourceArray[count]->iName))))
  1882 			{
  1886 			{
  1883 			aResourceId = ++count;
  1887 			aResourceId = ++count;
  1884 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1888 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1894 		aResourceId = pDR->iResourceId;
  1898 		aResourceId = pDR->iResourceId;
  1895 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1899 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1896 		UNLOCK_RETURN(KErrNone);
  1900 		UNLOCK_RETURN(KErrNone);
  1897 		}
  1901 		}
  1898 	//Search in static resource with dependencies (if exists) for specified resource name
  1902 	//Search in static resource with dependencies (if exists) for specified resource name
  1899 	for(count = 0; count < iStaticResDependencyCount; count++)
  1903 	for(count = 0; count < iStaticResDependencyArray.Count(); count++)
  1900 		{
  1904 		{
  1901 		if(!(aResourceName.Compare(*(const TDesC8*)iStaticResDependencyArray[count]->iName)))
  1905 		if(!(aResourceName.Compare(*(const TDesC8*)iStaticResDependencyArray[count]->iName)))
  1902 			{
  1906 			{
  1903 			aResourceId = iStaticResDependencyArray[count]->iResourceId;
  1907 			aResourceId = iStaticResDependencyArray[count]->iResourceId;
  1904 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1908 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1963 	//Validate buffer size
  1967 	//Validate buffer size
  1964 	if((TUint)(buf->MaxLength() - buf->Length()) < sizeof(TPowerResourceInfoV01))
  1968 	if((TUint)(buf->MaxLength() - buf->Length()) < sizeof(TPowerResourceInfoV01))
  1965 	   UNLOCK_RETURN(KErrArgument);
  1969 	   UNLOCK_RETURN(KErrArgument);
  1966 
  1970 
  1967 #ifndef PRM_ENABLE_EXTENDED_VERSION
  1971 #ifndef PRM_ENABLE_EXTENDED_VERSION
  1968 	if((!aResourceId) || (aResourceId > iStaticResourceArrayEntries))
  1972 	if((!aResourceId) || (aResourceId > (TUint)iStaticResourceArray.Count()))
  1969 		UNLOCK_RETURN(KErrNotFound);
  1973 		UNLOCK_RETURN(KErrNotFound);
  1970 	//Get resource from static resource array. 0(1) operation.
  1974 	//Get resource from static resource array. 0(1) operation.
  1971 	pR = iStaticResourceArray[aResourceId-1];
  1975 	pR = iStaticResourceArray[aResourceId-1];
  1972 	if(!pR)
  1976 	if(!pR)
  1973 		{
  1977 		{
  2034 	VALIDATE_CLIENT(thread);
  2038 	VALIDATE_CLIENT(thread);
  2035 	//Special case, return number of resources registered resource controller.
  2039 	//Special case, return number of resources registered resource controller.
  2036 	if(!aTargetClientId)
  2040 	if(!aTargetClientId)
  2037 		{
  2041 		{
  2038 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2042 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2039 		aNumResource = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyCount + 
  2043 		aNumResource = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyArray.Count() + 
  2040 			                                                          iDynamicResDependencyCount; 
  2044 			                                                          iDynamicResDependencyCount; 
  2041 #else
  2045 #else
  2042 		aNumResource = iStaticResourceCount;
  2046 		aNumResource = iStaticResourceCount;
  2043 #endif
  2047 #endif
  2044 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetNumResourcesInUseByClient, numResources = %d", aNumResource));
  2048 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetNumResourcesInUseByClient, numResources = %d", aNumResource));
  2113     TDes8 *pInfo = (TDes8*)anInfo;
  2117     TDes8 *pInfo = (TDes8*)anInfo;
  2114     if((TUint)(pInfo->MaxLength() - pInfo->Length()) < (sizeof(TPowerResourceInfoV01) * aNumResources))
  2118     if((TUint)(pInfo->MaxLength() - pInfo->Length()) < (sizeof(TPowerResourceInfoV01) * aNumResources))
  2115          UNLOCK_RETURN(KErrArgument);
  2119          UNLOCK_RETURN(KErrArgument);
  2116     TPowerResourceInfoBuf01 buf;
  2120     TPowerResourceInfoBuf01 buf;
  2117 
  2121 
  2118 	TUint16 count = 0;
  2122 	TInt count = 0;
  2119 	TInt r = KErrNone;
  2123 	TInt r = KErrNone;
  2120 	//Special case, if aTargetClientId is 0 fill with all the resource
  2124 	//Special case, if aTargetClientId is 0 fill with all the resource
  2121 	if(!aTargetClientId)
  2125 	if(!aTargetClientId)
  2122 		{
  2126 		{
  2123 		TUint numResources = aNumResources;
  2127 		TInt numResources = aNumResources;
  2124 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2128 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2125 		aNumResources = iStaticResourceCount;
  2129 		aNumResources = iStaticResourceCount;
  2126 #else
  2130 #else
  2127 		aNumResources = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyCount + 
  2131 		aNumResources = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyArray.Count() + 
  2128 			                                                           iDynamicResDependencyCount;
  2132 			                                                           iDynamicResDependencyCount;
  2129 #endif
  2133 #endif
  2130 		UnLock();
  2134 		UnLock();
  2131 		while(count < iStaticResourceArrayEntries)
  2135 		while(count < iStaticResourceArray.Count())
  2132 			{
  2136 			{
  2133 			if(numResources <=0)
  2137 			if(numResources == 0)
  2134 				return KErrNone;
  2138 				return KErrNone;
  2135 			pR = iStaticResourceArray[count++];
  2139 			pR = iStaticResourceArray[count++];
  2136 			if(!pR)
  2140 			if(!pR)
  2137 				continue;
  2141 				continue;
  2138             r = pR->GetInfo((TDes8*)buf.Ptr());
  2142             r = pR->GetInfo((TDes8*)buf.Ptr());
  2143 			pInfo->Append(buf);
  2147 			pInfo->Append(buf);
  2144 			numResources--;
  2148 			numResources--;
  2145 			}	
  2149 			}	
  2146 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2150 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2147 		count = 0;
  2151 		count = 0;
  2148 		while(count < iStaticResDependencyCount)
  2152 		while(count < iStaticResDependencyArray.Count())
  2149 			{
  2153 			{
  2150 			if(count >= numResources)
  2154 			if(count >= numResources)
  2151 				return KErrNone;
  2155 				return KErrNone;
  2152 			pR = iStaticResDependencyArray[count++];
  2156 			pR = iStaticResDependencyArray[count++];
  2153 			r = pR->GetInfo((TDes8*)buf.Ptr());
  2157 			r = pR->GetInfo((TDes8*)buf.Ptr());
  2155 			((TPowerResourceInfoV01*)buf.Ptr())->iResourceId = ((DStaticPowerResourceD*)pR)->iResourceId;
  2159 			((TPowerResourceInfoV01*)buf.Ptr())->iResourceId = ((DStaticPowerResourceD*)pR)->iResourceId;
  2156 			if(r != KErrNone)
  2160 			if(r != KErrNone)
  2157 				return r;
  2161 				return r;
  2158 			pInfo->Append(buf);
  2162 			pInfo->Append(buf);
  2159 			}
  2163 			}
  2160 		numResources -= iStaticResDependencyCount;
  2164 		numResources -= iStaticResDependencyArray.Count();
  2161 		if((!numResources) || (!iDynamicResourceCount && !iDynamicResDependencyCount))
  2165 		if((!numResources) || (!iDynamicResourceCount && !iDynamicResDependencyCount))
  2162 			return r;
  2166 			return r;
  2163 		Lock();
  2167 		Lock();
  2164 		TUint resCount = 0;
  2168 		TInt resCount = 0;
  2165 		for(count = 0; count < iDynamicResourceList.Allocd(); count++)
  2169 		for(count = 0; count < iDynamicResourceList.Allocd(); count++)
  2166 			{
  2170 			{
  2167 			pR = iDynamicResourceList[count];
  2171 			pR = iDynamicResourceList[count];
  2168 			if(!pR)
  2172 			if(!pR)
  2169 				continue;
  2173 				continue;
  2176 			pInfo->Append(buf);
  2180 			pInfo->Append(buf);
  2177 			resCount++;
  2181 			resCount++;
  2178 			}
  2182 			}
  2179 		numResources -= resCount;
  2183 		numResources -= resCount;
  2180 		resCount = 0;
  2184 		resCount = 0;
  2181 		for(count = 0; count < iDynamicResDependencyList.Allocd(); count++) 
  2185 		for(count = 0; count < (TInt)iDynamicResDependencyList.Allocd(); count++) 
  2182 			{
  2186 			{
  2183 			pR = iDynamicResDependencyList[count];
  2187 			pR = iDynamicResDependencyList[count];
  2184 			if(!pR)
  2188 			if(!pR)
  2185 				continue;
  2189 				continue;
  2186 			if((resCount >= iDynamicResDependencyCount) || (resCount >= numResources))
  2190 			if((resCount >= iDynamicResDependencyCount) || (resCount >= numResources))
  2198 		}
  2202 		}
  2199 	GET_TARGET_CLIENT();
  2203 	GET_TARGET_CLIENT();
  2200 	SPowerResourceClientLevel* pCL = pC->iLevelList;
  2204 	SPowerResourceClientLevel* pCL = pC->iLevelList;
  2201 	for (count= 0; pCL; count++, pCL = pCL->iNextInList)
  2205 	for (count= 0; pCL; count++, pCL = pCL->iNextInList)
  2202 		{
  2206 		{
  2203 		if(count >= aNumResources)
  2207 		if(count >= (TInt)aNumResources)
  2204 			continue;
  2208 			continue;
  2205 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2209 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2206 		pR = iStaticResourceArray[pCL->iResourceId-1];
  2210 		pR = iStaticResourceArray[pCL->iResourceId-1];
  2207 #else
  2211 #else
  2208 		GET_RESOURCE_FROM_LIST(pCL->iResourceId, pR);
  2212 		GET_RESOURCE_FROM_LIST(pCL->iResourceId, pR);
  2265 		}
  2269 		}
  2266 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2270 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2267 	DStaticPowerResource* pR = NULL;
  2271 	DStaticPowerResource* pR = NULL;
  2268 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2272 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2269 #else
  2273 #else
  2270 	if(aResourceId > iStaticResourceArrayEntries)
  2274 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2271 		UNLOCK_RETURN(KErrNotFound);
  2275 		UNLOCK_RETURN(KErrNotFound);
  2272 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2276 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2273 	if(!pR)
  2277 	if(!pR)
  2274 		UNLOCK_RETURN(KErrNotFound);
  2278 		UNLOCK_RETURN(KErrNotFound);
  2275 #endif
  2279 #endif
  2369 		}
  2373 		}
  2370 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2374 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2371 	DStaticPowerResource* pR = NULL;
  2375 	DStaticPowerResource* pR = NULL;
  2372 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2376 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2373 #else
  2377 #else
  2374 	if(aResourceId > iStaticResourceArrayEntries)
  2378 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2375 		UNLOCK_RETURN(KErrNotFound);
  2379 		UNLOCK_RETURN(KErrNotFound);
  2376 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2380 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2377 	if(!pR)
  2381 	if(!pR)
  2378 		UNLOCK_RETURN(KErrNotFound);
  2382 		UNLOCK_RETURN(KErrNotFound);
  2379 #endif
  2383 #endif
  2383 		{
  2387 		{
  2384 		if(c >= aNumClients)
  2388 		if(c >= aNumClients)
  2385 			continue;
  2389 			continue;
  2386 		pCL = (SPowerResourceClientLevel*)pRC;
  2390 		pCL = (SPowerResourceClientLevel*)pRC;
  2387 		if(pCL->iClientId & USER_SIDE_CLIENT_BIT_MASK)
  2391 		if(pCL->iClientId & USER_SIDE_CLIENT_BIT_MASK)
  2388 			pC = iUserSideClientList[(TUint16)(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2392 			pC = iUserSideClientList[(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2389 		else
  2393 		else
  2390 			pC = iClientList[(TUint16)(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2394 			pC = iClientList[(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2391 		info.iClientId = pC->iClientId;
  2395 		info.iClientId = pC->iClientId;
  2392 		info.iClientName =  (TDesC8*)pC->iName;
  2396 		info.iClientName =  (TDesC8*)pC->iName;
  2393         pInfo->Append(TPckgC<TPowerClientInfoV01>(info));
  2397         pInfo->Append(TPckgC<TPowerClientInfoV01>(info));
  2394 		}
  2398 		}
  2395 	aNumClients = c;
  2399 	aNumClients = c;
  2403 
  2407 
  2404 Request changing the state of a resource
  2408 Request changing the state of a resource
  2405 NOTE: If a resource callback is specified for instantaneous resource, then callback
  2409 NOTE: If a resource callback is specified for instantaneous resource, then callback
  2406       will be called after resource change and will be executed in the context of the
  2410       will be called after resource change and will be executed in the context of the
  2407       client thread.
  2411       client thread.
  2408       If a resource callback is specified for long latency reosurces, then it will be
  2412       If a resource callback is specified for long latency resources, then it will be
  2409       executed asynchronously.When the request is accepted the API returns immediately
  2413       executed asynchronously.When the request is accepted the API returns immediately
  2410 	  and the calling thread is unblocked: the callback (called in the client's context) 
  2414 	  and the calling thread is unblocked: the callback (called in the client's context) 
  2411 	  will be invoked when the resource change finally takes place.
  2415 	  will be invoked when the resource change finally takes place.
  2412       If aCb is not specified (NULL by default) the API executes synchronously and will
  2416       If aCb is not specified (NULL by default) the API executes synchronously and will
  2413       only return when the resource change has taken place for long latency resource.
  2417       only return when the resource change has taken place for long latency resource.
  2422                    binary resource, an integer level for a multilevel resource or some
  2426                    binary resource, an integer level for a multilevel resource or some
  2423                    platform specific token for a multi-property resource.
  2427                    platform specific token for a multi-property resource.
  2424 @param aCb         For Long latency resource
  2428 @param aCb         For Long latency resource
  2425                        A pointer to a resource callback object which encapsulates a
  2429                        A pointer to a resource callback object which encapsulates a
  2426                        callback function to be called whenever the resource state change
  2430                        callback function to be called whenever the resource state change
  2427                        happens (if left NULL the API will execute synchrounously).
  2431                        happens (if left NULL the API will execute synchronously).
  2428                    For Instantaneous resource
  2432                    For Instantaneous resource
  2429                        A pointer to a resource callback object which encapsulates a callback
  2433                        A pointer to a resource callback object which encapsulates a callback
  2430                        function to be called after resource change. This executes in the
  2434                        function to be called after resource change. This executes in the
  2431                        context of the client thread.
  2435                        context of the client thread.
  2432 
  2436 
  2477 	VALIDATE_CLIENT(thread);
  2481 	VALIDATE_CLIENT(thread);
  2478 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2482 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2479 	DStaticPowerResource *pR = NULL;
  2483 	DStaticPowerResource *pR = NULL;
  2480 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2484 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2481 #else
  2485 #else
  2482 	if(aResourceId > iStaticResourceArrayEntries)
  2486 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2483 		UNLOCK_RETURN(KErrNotFound);
  2487 		UNLOCK_RETURN(KErrNotFound);
  2484 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2488 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2485 	if(!pR)
  2489 	if(!pR)
  2486 		UNLOCK_RETURN(KErrNotFound);
  2490 		UNLOCK_RETURN(KErrNotFound);
  2487 #endif
  2491 #endif
  2561 
  2565 
  2562 	TPowerRequest* req;
  2566 	TPowerRequest* req;
  2563 	SPowerRequest* pS=NULL;
  2567 	SPowerRequest* pS=NULL;
  2564 	if(pR->LatencySet() && aCb)
  2568 	if(pR->LatencySet() && aCb)
  2565 		{
  2569 		{
  2566 		// Get request object from free pool, as it is long latency reosurce as client
  2570 		// Get request object from free pool, as it is long latency resource as client
  2567 		// will be unblocked once message is sent to controller, so cant use thread message.
  2571 		// will be unblocked once message is sent to controller, so can't use thread message.
  2568 		if(pC->iReservedRm ==0 && !iRequestPoolCount)
  2572 		if(pC->iReservedRm ==0 && !iRequestPoolCount)
  2569 			{
  2573 			{
  2570             r = KErrUnderflow;
  2574             r = KErrUnderflow;
  2571             PRM_CLIENT_CHANGE_STATE_END_TRACE
  2575             PRM_CLIENT_CHANGE_STATE_END_TRACE
  2572 			UNLOCK_RETURN(r);
  2576 			UNLOCK_RETURN(r);
  2615 				return KErrNone;
  2619 				return KErrNone;
  2616 				}
  2620 				}
  2617 			else
  2621 			else
  2618 #endif
  2622 #endif
  2619 				{
  2623 				{
  2620 				req->Send(iMsgQ); // Send the request to Resource Controler thread.
  2624 				req->Send(iMsgQ); // Send the request to Resource Controller thread.
  2621 				return KErrNone;
  2625 				return KErrNone;
  2622 				}
  2626 				}
  2623 			}
  2627 			}
  2624 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2628 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2625 		if(aResourceId & KIdMaskResourceWithDependencies) //Dependency resource
  2629 		if(aResourceId & KIdMaskResourceWithDependencies) //Dependency resource
  2766 @param aCached     If ETrue, cached value will be updated in aState.
  2770 @param aCached     If ETrue, cached value will be updated in aState.
  2767                    If EFalse, aState will be updated after the resource
  2771                    If EFalse, aState will be updated after the resource
  2768                    state is read from resource.
  2772                    state is read from resource.
  2769 @param aState      Returns the resource state if operation was successful. This
  2773 @param aState      Returns the resource state if operation was successful. This
  2770                    could be a binary value for a binary resource, an integer level
  2774                    could be a binary value for a binary resource, an integer level
  2771                    for a multilevel resource or some platform specific tolen for a
  2775                    for a multilevel resource or some platform specific token for a
  2772                    multi-property resource.
  2776                    multi-property resource.
  2773 @param aLevelOwnerId Returns the Id of the client that is currently holding the resource.
  2777 @param aLevelOwnerId Returns the Id of the client that is currently holding the resource.
  2774 					 -1	is returned when no client is holding the resource.
  2778 					 -1	is returned when no client is holding the resource.
  2775 
  2779 
  2776 @return KErrNone   if operation was successful
  2780 @return KErrNone   if operation was successful
  2813 		{
  2817 		{
  2814 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2818 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2815 			UNLOCK_RETURN(KErrNotFound);
  2819 			UNLOCK_RETURN(KErrNotFound);
  2816 		}
  2820 		}
  2817 #else
  2821 #else
  2818 	if(aResourceId > iStaticResourceArrayEntries)
  2822 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2819 		UNLOCK_RETURN(KErrNotFound);
  2823 		UNLOCK_RETURN(KErrNotFound);
  2820 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2824 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2821 	if(!pR)
  2825 	if(!pR)
  2822 		UNLOCK_RETURN(KErrNotFound);
  2826 		UNLOCK_RETURN(KErrNotFound);
  2823 #endif
  2827 #endif
  2897 
  2901 
  2898 /**   
  2902 /**   
  2899 @publishedPartner
  2903 @publishedPartner
  2900 @prototype 9.5
  2904 @prototype 9.5
  2901 
  2905 
  2902 Request the state of the resource asynchrounously for long latency resource and
  2906 Request the state of the resource asynchronously for long latency resource and
  2903 synchronously for instantaneous resource
  2907 synchronously for instantaneous resource
  2904 
  2908 
  2905 @param aClientId  ID of the client which is requesting the resource state.
  2909 @param aClientId  ID of the client which is requesting the resource state.
  2906 @param aResourceId ID of the resource whose state is being requested.
  2910 @param aResourceId ID of the resource whose state is being requested.
  2907 @param aCached If ETrue, cached value will be updated in aState
  2911 @param aCached If ETrue, cached value will be updated in aState
  2959 		//Dynamic resource in process of deregistration
  2963 		//Dynamic resource in process of deregistration
  2960 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2964 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2961 			UNLOCK_RETURN(KErrNotFound);
  2965 			UNLOCK_RETURN(KErrNotFound);
  2962 		}
  2966 		}
  2963 #else
  2967 #else
  2964 	if(aResourceId > iStaticResourceArrayEntries)
  2968 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2965 		UNLOCK_RETURN(KErrNotFound);
  2969 		UNLOCK_RETURN(KErrNotFound);
  2966 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2970 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2967 	if(!pR)
  2971 	if(!pR)
  2968 		UNLOCK_RETURN(KErrNotFound);
  2972 		UNLOCK_RETURN(KErrNotFound);
  2969 #endif
  2973 #endif
  3096 @prototype 9.5
  3100 @prototype 9.5
  3097 
  3101 
  3098 Cancel an asynchronous request(or its callback).
  3102 Cancel an asynchronous request(or its callback).
  3099 
  3103 
  3100 @param aClientId       ID of the client which is requesting the cancellation of the request.
  3104 @param aClientId       ID of the client which is requesting the cancellation of the request.
  3101 @param aResourceId     ID for the resource which the request that is being cancelled operates
  3105 @param aResourceId     ID for the resource which the request that is being canceled operates
  3102                        upon.
  3106                        upon.
  3103 @param aCb             A reference to the resource callback object specified with the request
  3107 @param aCb             A reference to the resource callback object specified with the request
  3104                        that is being cancelled.
  3108                        that is being canceled.
  3105 
  3109 
  3106 @return KErrCancel if the request was cancelled.
  3110 @return KErrCancel if the request was canceled.
  3107         KErrNotFound if this resource ID could not be found in the current list of controllable
  3111         KErrNotFound if this resource ID could not be found in the current list of controllable
  3108                      resources.
  3112                      resources.
  3109         KErrCompletion if request is no longer pending.
  3113         KErrCompletion if request is no longer pending.
  3110         KErrAccessDenied if the client ID could not be found in the current list of registered
  3114         KErrAccessDenied if the client ID could not be found in the current list of registered
  3111 		clients or if the client was registered to be thread relative and this API is not called
  3115 		clients or if the client was registered to be thread relative and this API is not called
  3112 		from the same thread or if client is not the same that requested the resource state change.
  3116 		from the same thread or if client is not the same that requested the resource state change.
  3113 		KErrInUse if the request cannot be cancelled as processing of the request already started 
  3117 		KErrInUse if the request cannot be canceled as processing of the request already started 
  3114 		and will run to completion. 
  3118 		and will run to completion. 
  3115 
  3119 
  3116 @pre Interrupts must be enabled
  3120 @pre Interrupts must be enabled
  3117 @pre Kernel must be unlocked
  3121 @pre Kernel must be unlocked
  3118 @pre No fast mutex can be held
  3122 @pre No fast mutex can be held
  3228 						 thread relative and this API is not called from the same thread. 
  3232 						 thread relative and this API is not called from the same thread. 
  3229 		KErrInUse if the passed notification object is used already.
  3233 		KErrInUse if the passed notification object is used already.
  3230 NOTE: This API should return immediately; however the notification will
  3234 NOTE: This API should return immediately; however the notification will
  3231 only happen when a resource change occurs.Notification request is idempotent, 
  3235 only happen when a resource change occurs.Notification request is idempotent, 
  3232 if the same notification has already been requested for this resource ID, 
  3236 if the same notification has already been requested for this resource ID, 
  3233 the API returns with no further action.Notifications remain queued until they are cancelled.
  3237 the API returns with no further action.Notifications remain queued until they are canceled.
  3234 
  3238 
  3235 @pre Interrupts must be enabled
  3239 @pre Interrupts must be enabled
  3236 @pre Kernel must be unlocked
  3240 @pre Kernel must be unlocked
  3237 @pre No fast mutex can be held
  3241 @pre No fast mutex can be held
  3238 @pre Call in a thread context but not from null thread or DFC thread1
  3242 @pre Call in a thread context but not from null thread or DFC thread1
  3256 		}
  3260 		}
  3257 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3261 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3258 	DStaticPowerResource *pR = NULL;
  3262 	DStaticPowerResource *pR = NULL;
  3259 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3263 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3260 #else
  3264 #else
  3261 	if(aResourceId > iStaticResourceArrayEntries)
  3265 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  3262 		{
  3266 		{
  3263         r = KErrNotFound;
  3267         r = KErrNotFound;
  3264 		PRM_POSTNOTIFICATION_REGISTER_TRACE
  3268 		PRM_POSTNOTIFICATION_REGISTER_TRACE
  3265 		UNLOCK_RETURN(r);
  3269 		UNLOCK_RETURN(r);
  3266 		}
  3270 		}
  3320 
  3324 
  3321 
  3325 
  3322 
  3326 
  3323 @return KErrNone if the operation of requesting a notification was successful.
  3327 @return KErrNone if the operation of requesting a notification was successful.
  3324         KErrNotFound if this resource ID could not be found in the current list
  3328         KErrNotFound if this resource ID could not be found in the current list
  3325                      of controllable reosurces.
  3329                      of controllable resources.
  3326         KErrAccessDenied if the client ID could not be found in the list of
  3330         KErrAccessDenied if the client ID could not be found in the list of
  3327                          registered clients or if the client was registered to be thread
  3331                          registered clients or if the client was registered to be thread
  3328 						 relative and this API is not called from the same thread. 
  3332 						 relative and this API is not called from the same thread. 
  3329 		KErrInUse if the passed notification object is used already.
  3333 		KErrInUse if the passed notification object is used already.
  3330 		KErrArgument if the specified threshold is out of range.
  3334 		KErrArgument if the specified threshold is out of range.
  3331 NOTE: This API should return immediately; however the notification will only
  3335 NOTE: This API should return immediately; however the notification will only
  3332 happen when a resource change occurs. Notification request is idempotent, 
  3336 happen when a resource change occurs. Notification request is idempotent, 
  3333 if the same notification has already been requested for this resource ID, 
  3337 if the same notification has already been requested for this resource ID, 
  3334 the API returns with no further action. Notification remain queued until they are cancelled.
  3338 the API returns with no further action. Notification remain queued until they are canceled.
  3335 
  3339 
  3336 @pre Interrupts must be enabled
  3340 @pre Interrupts must be enabled
  3337 @pre Kernel must be unlocked
  3341 @pre Kernel must be unlocked
  3338 @pre No fast mutex can be held
  3342 @pre No fast mutex can be held
  3339 @pre Call in a thread context but not from null thread or DFC thread1
  3343 @pre Call in a thread context but not from null thread or DFC thread1
  3359 		}
  3363 		}
  3360 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3364 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3361 	DStaticPowerResource *pR = NULL;
  3365 	DStaticPowerResource *pR = NULL;
  3362 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3366 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3363 #else
  3367 #else
  3364 	if(aResourceId > iStaticResourceArrayEntries)
  3368 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  3365 		{
  3369 		{
  3366         r = KErrNotFound;
  3370         r = KErrNotFound;
  3367         PRM_POSTNOTIFICATION_REGISTER_TRACE
  3371         PRM_POSTNOTIFICATION_REGISTER_TRACE
  3368 		UNLOCK_RETURN(r);
  3372 		UNLOCK_RETURN(r);
  3369 		}
  3373 		}
  3423 Cancel and remove from queue a previously issued request for notification on a
  3427 Cancel and remove from queue a previously issued request for notification on a
  3424 resource state change.
  3428 resource state change.
  3425 
  3429 
  3426 @param aClientId ID of the client which is requesting to cancel the notification
  3430 @param aClientId ID of the client which is requesting to cancel the notification
  3427 @param aResourceId for the resource whose pending notification of state changes
  3431 @param aResourceId for the resource whose pending notification of state changes
  3428                    is being cancelled.
  3432                    is being canceled.
  3429 @param aN          A reference to the notification object that was associated with
  3433 @param aN          A reference to the notification object that was associated with
  3430                    the notification request that is being cancelled. This will be
  3434                    the notification request that is being canceled. This will be
  3431                    used to identify the notification that is being cancelled.
  3435                    used to identify the notification that is being canceled.
  3432 
  3436 
  3433 @return KErrCancel if the notification request was successfully cancelled.
  3437 @return KErrCancel if the notification request was successfully canceled.
  3434         KErrNotFound if the specified notification object is 
  3438         KErrNotFound if the specified notification object is 
  3435 					 not found in the current list of notification objects for the 
  3439 					 not found in the current list of notification objects for the 
  3436 					 specified resource.
  3440 					 specified resource.
  3437         KErrAccessDenied if the client requesting the cancellation is not the same
  3441         KErrAccessDenied if the client requesting the cancellation is not the same
  3438                          which registered the notification or if the resource id does not match or
  3442                          which registered the notification or if the resource id does not match or
  3582 	Lock();
  3586 	Lock();
  3583 	TInt clientPoolCount = iClientLevelPoolCount;
  3587 	TInt clientPoolCount = iClientLevelPoolCount;
  3584 	TInt requestPoolCount = iRequestPoolCount;
  3588 	TInt requestPoolCount = iRequestPoolCount;
  3585 	SPowerResourceClient* pC;
  3589 	SPowerResourceClient* pC;
  3586 	if(aRequest.ClientId() & USER_SIDE_CLIENT_BIT_MASK)
  3590 	if(aRequest.ClientId() & USER_SIDE_CLIENT_BIT_MASK)
  3587 		pC = iUserSideClientList[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3591 		pC = iUserSideClientList[(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3588 	else																				
  3592 	else																				
  3589 		pC = iClientList[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3593 		pC = iClientList[(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3590 	UnLock();
  3594 	UnLock();
  3591 
  3595 
  3592 	if(clientPoolCount < aRequest.ClientLevelCount())
  3596 	if(clientPoolCount < aRequest.ClientLevelCount())
  3593 		{
  3597 		{
  3594 		//Grow the client level pool
  3598 		//Grow the client level pool
  3683 	req->ReqType() = TPowerRequest::ERegisterUsersideClient;
  3687 	req->ReqType() = TPowerRequest::ERegisterUsersideClient;
  3684 	UnLock();
  3688 	UnLock();
  3685 	req->SendReceive(iMsgQ);
  3689 	req->SendReceive(iMsgQ);
  3686 	if(req->ReturnCode() == KErrNone)
  3690 	if(req->ReturnCode() == KErrNone)
  3687 		{
  3691 		{
  3688 		pC = iUserSideClientList[(TUint16)(req->ClientId() & ID_INDEX_BIT_MASK)];
  3692 		pC = iUserSideClientList[(req->ClientId() & ID_INDEX_BIT_MASK)];
  3689 		pC->iName=&aName;
  3693 		pC->iName=&aName;
  3690 		//Store the current thread Id;
  3694 		//Store the current thread Id;
  3691 		pC->iThreadId = t.iId;
  3695 		pC->iThreadId = t.iId;
  3692 		aClientId = pC->iClientId;
  3696 		aClientId = pC->iClientId;
  3693 		}
  3697 	    __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::RegisterProxyClient, clientId = 0x%x", aClientId));
  3694 	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::RegisterProxyClient, clientId = 0x%x", aClientId));
  3698 	    PRM_CLIENT_REGISTER_TRACE
  3695     PRM_CLIENT_REGISTER_TRACE
  3699 		}
  3696 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3700 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3697 	return KErrNone;
  3701 	return KErrNone;
  3698 	}
  3702 	}
  3699 
  3703 
  3700 /*  Deregister the specified user side client from resource controller.
  3704 /*  Deregister the specified user side client from resource controller.
  3708 	CHECK_CONTEXT(t)
  3712 	CHECK_CONTEXT(t)
  3709 	//Get the index from client ID
  3713 	//Get the index from client ID
  3710 	if(!(aClientId & USER_SIDE_CLIENT_BIT_MASK))
  3714 	if(!(aClientId & USER_SIDE_CLIENT_BIT_MASK))
  3711 		return KErrArgument;
  3715 		return KErrArgument;
  3712 	Lock();
  3716 	Lock();
  3713 	SPowerResourceClient* pC = iUserSideClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)];
  3717 	SPowerResourceClient* pC = iUserSideClientList[(aClientId & ID_INDEX_BIT_MASK)];
  3714 	if(!pC)
  3718 	if(!pC)
  3715 		{
  3719 		{
  3716 		UnLock();
  3720 		UnLock();
  3717 		LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3721 		LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3718 		return KErrNotFound;
  3722 		return KErrNotFound;
  3756 	ResourceStateChangeOfClientLevels(pC);
  3760 	ResourceStateChangeOfClientLevels(pC);
  3757 	//Add reserved request to pool
  3761 	//Add reserved request to pool
  3758 	iRequestPoolCount = (TUint16)(iRequestPoolCount + pC->iReservedRm);
  3762 	iRequestPoolCount = (TUint16)(iRequestPoolCount + pC->iReservedRm);
  3759 	PRM_CLIENT_DEREGISTER_TRACE
  3763 	PRM_CLIENT_DEREGISTER_TRACE
  3760 	//Increment the free pool count for client level and request level.
  3764 	//Increment the free pool count for client level and request level.
  3761 	iUserSideClientList.Remove(pC, (TUint16)(pC->iClientId & ID_INDEX_BIT_MASK));
  3765 	iUserSideClientList.Remove(pC, (pC->iClientId & ID_INDEX_BIT_MASK));
  3762 	pC->iName = NULL;
  3766 	pC->iName = NULL;
  3763 	iUserSideClientCount--; //Decrement client count
  3767 	iUserSideClientCount--; //Decrement client count
  3764 	LIST_PUSH(iClientPool, pC, iNextInList);
  3768 	LIST_PUSH(iClientPool, pC, iNextInList);
  3765 	UnLock();
  3769 	UnLock();
  3766 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3770 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3793 	TUint count=0;
  3797 	TUint count=0;
  3794 	TUint id=0;
  3798 	TUint id=0;
  3795 	for(count=0;count<aNumResources;count++) //Check for valid resource ID.
  3799 	for(count=0;count<aNumResources;count++) //Check for valid resource ID.
  3796 		{
  3800 		{
  3797 #ifndef PRM_ENABLE_EXTENDED_VERSION
  3801 #ifndef PRM_ENABLE_EXTENDED_VERSION
  3798 		if((!pS->iResourceId) || (pS->iResourceId > iStaticResourceArrayEntries) || (!iStaticResourceArray[pS->iResourceId-1]))
  3802 		if((!pS->iResourceId) || (pS->iResourceId > (TUint)iStaticResourceArray.Count()) || (!iStaticResourceArray[pS->iResourceId-1]))
  3799 			{
  3803 			{
  3800 			UnLock();
  3804 			UnLock();
  3801 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3805 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3802 			return KErrNotFound;
  3806 			return KErrNotFound;
  3803 			}
  3807 			}
  3807 			UnLock();
  3811 			UnLock();
  3808 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3812 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3809 			return KErrNotSupported;
  3813 			return KErrNotSupported;
  3810 			}
  3814 			}
  3811 		if((!pS->iResourceId) || ((pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3815 		if((!pS->iResourceId) || ((pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3812 			     (pS->iResourceId > iStaticResDependencyCount)) || (!(pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3816 			     (pS->iResourceId > (TUint)iStaticResDependencyArray.Count())) || (!(pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3813 					((pS->iResourceId > iStaticResourceArrayEntries) || (!iStaticResourceArray[pS->iResourceId-1]))))
  3817 					((pS->iResourceId > (TUint)iStaticResourceArray.Count()) || (!iStaticResourceArray[pS->iResourceId-1]))))
  3814 			{
  3818 			{
  3815 			UnLock();
  3819 			UnLock();
  3816 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3820 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3817 			return KErrNotFound;
  3821 			return KErrNotFound;
  3818 			}
  3822 			}
  3833 		pS->iCurrentLevel = pR->iCachedLevel;
  3837 		pS->iCurrentLevel = pR->iCachedLevel;
  3834 		pR->iIdleListEntry=pS;
  3838 		pR->iIdleListEntry=pS;
  3835 		pS++;
  3839 		pS++;
  3836 		}
  3840 		}
  3837 	iListForIdle=(SIdleResourceInfo*)aBuf->Ptr();
  3841 	iListForIdle=(SIdleResourceInfo*)aBuf->Ptr();
  3838 	pS = (SIdleResourceInfo*)aBuf->Ptr();
       
  3839 	UnLock();
  3842 	UnLock();
  3840 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3843 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3841 	return KErrNone;
  3844 	return KErrNone;
  3842 	}
  3845 	}
  3843 	
  3846 	
  3883 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3886 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3884 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3887 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3885 	if(aResourceId & KIdMaskDynamic)
  3888 	if(aResourceId & KIdMaskDynamic)
  3886 		((DDynamicPowerResource*)pR)->Lock();
  3889 		((DDynamicPowerResource*)pR)->Lock();
  3887 #else
  3890 #else
  3888 	if(aResourceId > iStaticResourceArrayEntries)
  3891 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  3889 		{
  3892 		{
  3890 		UNLOCK_RETURN(KErrNotFound);
  3893 		UNLOCK_RETURN(KErrNotFound);
  3891 		}
  3894 		}
  3892 	pR = iStaticResourceArray[aResourceId - 1];
  3895 	pR = iStaticResourceArray[aResourceId - 1];
  3893 	if(!pR)
  3896 	if(!pR)