kernel/eka/drivers/resourceman/resourcecontrol.cpp
changeset 244 a77889bee936
parent 199 189ece41fa29
child 252 0a40b8675b23
equal deleted inserted replaced
243:c7a0ce20c48c 244:a77889bee936
    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 		pC->iName = pDRes->iName;
   765 		}
   738 		}
   766 	else if((aReq->ClientId() == -1) || (aReq->ClientId() == KDynamicResourceDeRegistering))
   739 	else if((aReq->ClientId() == -1) || (aReq->ClientId() == KDynamicResourceDeRegistering))
   785 		{
   758 		{
   786 		TInt aNewState = aReq->Level();
   759 		TInt aNewState = aReq->Level();
   787 		PRM_CLIENT_CHANGE_STATE_END_TRACE
   760 		PRM_CLIENT_CHANGE_STATE_END_TRACE
   788 		}
   761 		}
   789 #endif
   762 #endif
   790 	//Check whether callback is cancelled and if not queue the DFC.
   763 	//Check whether callback is canceled and if not queue the DFC.
   791     TPowerResourceCb* pCb = aReq->ResourceCb();
   764     TPowerResourceCb* pCb = aReq->ResourceCb();
   792     if(pCb)
   765     if(pCb)
   793 		{
   766 		{
   794         pCb->iMutex = pRC->iResourceMutex;
   767         pCb->iMutex = pRC->iResourceMutex;
   795         pCb->iPendingRequestCount++;       
   768         pCb->iPendingRequestCount++;       
   854    Finally mark resource controller as fully initialised (ready to accept state change and get request)
   827    Finally mark resource controller as fully initialised (ready to accept state change and get request)
   855    and start the message queue if exists. */
   828    and start the message queue if exists. */
   856 TInt DPowerResourceController::InitResources()
   829 TInt DPowerResourceController::InitResources()
   857 	{
   830 	{
   858     __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::InitResources()"));
   831     __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::InitResources()"));
   859 	TUint16 count;
   832 	TInt count;
   860 	//Create a Kernel client object for Power Controller
   833 	//Create a Kernel client object for Power Controller
   861 	Lock();
   834 	Lock();
   862 	SPowerResourceClient * pC = NULL;
   835 	SPowerResourceClient * pC = NULL;
   863 	// By now client pool should be created
   836 	// By now client pool should be created
   864 	LIST_POP(iClientPool, pC, iNextInList);
   837 	LIST_POP(iClientPool, pC, iNextInList);
   865 	TUint16 growBy = iClientList.GrowBy();
   838 	TInt growBy = iClientList.GrowBy();
   866 	if(!pC)
   839 	if(!pC)
   867 		{
   840 		{
   868 		UnLock();
   841 		UnLock();
   869 		// coverity[alloc_fn]
   842 		// coverity[alloc_fn]
   870 		SPowerResourceClient *pCL = new SPowerResourceClient[growBy];
   843 		SPowerResourceClient *pCL = new SPowerResourceClient[growBy];
   898 	iClientList.Add(pC, iPowerControllerId);
   871 	iClientList.Add(pC, iPowerControllerId);
   899 	pC->iClientId = iPowerControllerId | CLIENT_POWER_CONTROLLER_BIT_MASK;
   872 	pC->iClientId = iPowerControllerId | CLIENT_POWER_CONTROLLER_BIT_MASK;
   900 	iPowerControllerId = pC->iClientId;
   873 	iPowerControllerId = pC->iClientId;
   901     iClientCount++;
   874     iClientCount++;
   902     if(TPowerController::PowerController())
   875     if(TPowerController::PowerController())
   903        TPowerController::PowerController()->RegisterResourceController(this, iPowerControllerId);
   876 		{
       
   877 		if(TPowerController::PowerController()->RegisterResourceController(this, iPowerControllerId))
       
   878 			{
       
   879 #ifndef RESOURCE_MANAGER_SIMULATED_PSL
       
   880 			Panic(EControllerAlreadyExists);	//	Panic with this error for any error returned by RegisterResourceController
       
   881 #endif
       
   882 			}
       
   883 		}
       
   884 
   904 	iInitialised =EResConStartupCompleted;
   885 	iInitialised =EResConStartupCompleted;
   905 	UnLock();
   886 	UnLock();
   906 	//Check the resource for postboot level and send notifications to clients registered for it.
   887 	//Check the resource for postboot level and send notifications to clients registered for it.
   907 	DStaticPowerResource *pR = NULL;
   888 	DStaticPowerResource *pR = NULL;
   908 	TInt r;
   889 	TInt r;
   909 	TPowerRequest req = TPowerRequest::Get();
   890 	TPowerRequest req = TPowerRequest::Get();
   910 	//For Static resource with no dependencies
   891 	//For Static resource with no dependencies
   911     for(count = 0; count< iStaticResourceArrayEntries; count++)
   892     for(count = 0; count < iStaticResourceArray.Count(); count++)
   912 		{
   893 		{
   913 		pR = iStaticResourceArray[count];
   894 		pR = iStaticResourceArray[count];
   914 		if(pR && (pR->iFlags & SET_VALID_POST_BOOT_LEVEL))
   895 		if(pR && (pR->iFlags & SET_VALID_POST_BOOT_LEVEL))
   915 			{
   896 			{
   916             //Form the request message
   897             //Form the request message
   929 				}
   910 				}
   930 			}
   911 			}
   931 		}
   912 		}
   932 #ifdef PRM_ENABLE_EXTENDED_VERSION
   913 #ifdef PRM_ENABLE_EXTENDED_VERSION
   933 	//For Static resource with dependencies 
   914 	//For Static resource with dependencies 
   934 	for(count = 0; count < iStaticResDependencyCount; count++)
   915 	for(count = 0; count < iStaticResDependencyArray.Count(); count++)
   935 		{
   916 		{
   936 		pR = iStaticResDependencyArray[count];
   917 		pR = iStaticResDependencyArray[count];
   937 		if(pR->iFlags & SET_VALID_POST_BOOT_LEVEL)
   918 		if(pR->iFlags & SET_VALID_POST_BOOT_LEVEL)
   938 			{
   919 			{
   939 			req.ReqType() = TPowerRequest::EChange;
   920 			req.ReqType() = TPowerRequest::EChange;
   944 			req.ResourceCb() = NULL;
   925 			req.ResourceCb() = NULL;
   945 			req.RequiresChange() = ETrue;
   926 			req.RequiresChange() = ETrue;
   946 			//Form the request message
   927 			//Form the request message
   947 			((DStaticPowerResourceD*)pR)->HandleChangePropagation(req, EChangeStart, req.ClientId(), KNoClient);
   928 			((DStaticPowerResourceD*)pR)->HandleChangePropagation(req, EChangeStart, req.ClientId(), KNoClient);
   948 			}
   929 			}
       
   930 		}
       
   931 #endif
       
   932 	
       
   933 	// delete the temporary copy of static resource array used during initialization.
       
   934 	if(StaticResourceArrayPtr)
       
   935 		{
       
   936 		delete StaticResourceArrayPtr;
       
   937 		StaticResourceArrayPtr = NULL;
       
   938 		}
       
   939 #ifdef PRM_ENABLE_EXTENDED_VERSION
       
   940 	// the same applies to dependency resources array for extended version.
       
   941 	if(StaticResourceDependencyArrayPtr)
       
   942 		{
       
   943 		delete StaticResourceDependencyArrayPtr;
       
   944 		StaticResourceDependencyArrayPtr = NULL;
   949 		}
   945 		}
   950 #endif
   946 #endif
   951 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::InitResources()"));
   947 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::InitResources()"));
   952     return KErrNone;
   948     return KErrNone;
   953 	}
   949 	}
  1259         iClientList.Delete();
  1255         iClientList.Delete();
  1260 		return KErrNoMemory;
  1256 		return KErrNoMemory;
  1261 		}
  1257 		}
  1262 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1258 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1263 	SPowerResourceClientLevel* pRL = NULL;
  1259 	SPowerResourceClientLevel* pRL = NULL;
  1264 	if(iStaticResDependencyCount)
  1260 	if(iStaticResDependencyArray.Count())
  1265 		{
  1261 		{
  1266 		pRL = new SPowerResourceClientLevel[iStaticResDependencyCount];
  1262 		pRL = new SPowerResourceClientLevel[iStaticResDependencyArray.Count()];
  1267 		if(!pRL)
  1263 		if(!pRL)
  1268 			{
  1264 			{
  1269 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Resource level Pool Allocation Failed"));
  1265 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Resource level Pool Allocation Failed"));
  1270 			delete []pC;
  1266 			delete []pC;
  1271 			delete []pCL;
  1267 			delete []pCL;
  1277 		}
  1273 		}
  1278 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1274 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1279 	iCleanList.Append(pC);
  1275 	iCleanList.Append(pC);
  1280 #endif
  1276 #endif
  1281 	Lock();
  1277 	Lock();
  1282 	TUint16 c;
  1278 	TInt c;
  1283 	for(c = 0; c < iStaticResDependencyCount; c++)
  1279 	for(c = 0; c < iStaticResDependencyArray.Count(); c++)
  1284 		{
  1280 		{
  1285 		LIST_PUSH(iResourceLevelPool, &pRL[c], iNextInList);
  1281 		LIST_PUSH(iResourceLevelPool, &pRL[c], iNextInList);
  1286 		}
  1282 		}
  1287 	iResourceLevelPoolCount = iStaticResDependencyCount;
  1283 	iResourceLevelPoolCount = (TUint16)iStaticResDependencyArray.Count();
  1288 #else
  1284 #else
  1289 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1285 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1290     iCleanList.Append(pC);
  1286     iCleanList.Append(pC);
  1291 #endif
  1287 #endif
  1292     Lock();
  1288     Lock();
  1293     TUint16 c;
  1289     TUint16 c;
  1294 #endif
  1290 #endif
  1295     // Create Client pool list
  1291     // Create Client pool list
  1296     for(c = 0; c< (aKClients + aUClients); c++)
  1292     for(c = 0; c < TUint16(aKClients + aUClients); c++)
  1297 		{
  1293 		{
  1298         LIST_PUSH(iClientPool, &pC[c], iNextInList);
  1294         LIST_PUSH(iClientPool, &pC[c], iNextInList);
  1299 		}
  1295 		}
  1300     // Create client level pool list
  1296     // Create client level pool list
  1301     for(c = 0; c < aNClientLevels; c++)
  1297     for(c = 0; c < aNClientLevels; c++)
  1377 	req->ReqType() = TPowerRequest::ERegisterKernelClient;
  1373 	req->ReqType() = TPowerRequest::ERegisterKernelClient;
  1378 	UnLock();
  1374 	UnLock();
  1379 	req->SendReceive(iMsgQ);
  1375 	req->SendReceive(iMsgQ);
  1380 	if(req->ReturnCode() == KErrNone)
  1376 	if(req->ReturnCode() == KErrNone)
  1381 		{
  1377 		{
  1382 		pC = iClientList[(TUint16)(req->ClientId() & ID_INDEX_BIT_MASK)];
  1378 		pC = iClientList[(req->ClientId() & ID_INDEX_BIT_MASK)];
  1383 		if(aType == EOwnerThread)
  1379 		if(aType == EOwnerThread)
  1384 			{
  1380 			{
  1385 			pC->iClientId |= CLIENT_THREAD_RELATIVE_BIT_MASK; //Set 31st bit;
  1381 			pC->iClientId |= CLIENT_THREAD_RELATIVE_BIT_MASK; //Set 31st bit;
  1386 			//Store the current thread Id;
  1382 			//Store the current thread Id;
  1387 			pC->iThreadId = thread.iId;
  1383 			pC->iThreadId = thread.iId;
  1426 	if(aRequest.ReqType() == TPowerRequest::ERegisterKernelClient)
  1422 	if(aRequest.ReqType() == TPowerRequest::ERegisterKernelClient)
  1427 		{
  1423 		{
  1428 		//Get Next client from FreePool
  1424 		//Get Next client from FreePool
  1429 		LIST_POP(iClientPool, pC, iNextInList);
  1425 		LIST_POP(iClientPool, pC, iNextInList);
  1430 
  1426 
  1431 		TUint16 growBy = iClientList.GrowBy();
  1427 		TInt growBy = iClientList.GrowBy();
  1432 		if(!pC)
  1428 		if(!pC)
  1433 			{
  1429 			{
  1434 			//Free Pool is empty, so try to grow the pool.
  1430 			//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));
  1431 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Client pool exhausted so growing client Pool by %d", growBy));
  1436 			// coverity[alloc_fn]
  1432 			// coverity[alloc_fn]
  1471 		}
  1467 		}
  1472 	else // Request is registration of user side client
  1468 	else // Request is registration of user side client
  1473 		{
  1469 		{
  1474 		//Get Next client from FreePool
  1470 		//Get Next client from FreePool
  1475 		LIST_POP(iClientPool, pC, iNextInList);
  1471 		LIST_POP(iClientPool, pC, iNextInList);
  1476 		TUint16 growBy = iUserSideClientList.GrowBy();
  1472 		TInt growBy = iUserSideClientList.GrowBy();
  1477 		if(!pC)
  1473 		if(!pC)
  1478 			{
  1474 			{
  1479 			//Free Pool is empty, so try to grow the pool.
  1475 			//Free Pool is empty, so try to grow the pool.
  1480 			SPowerResourceClient *pCL = (SPowerResourceClient*)Kern::Alloc(sizeof(SPowerResourceClient) * growBy);
  1476 			SPowerResourceClient *pCL = (SPowerResourceClient*)Kern::Alloc(sizeof(SPowerResourceClient) * growBy);
  1481 			if(!pCL)
  1477 			if(!pCL)
  1484 				}
  1480 				}
  1485 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1481 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
  1486 			iCleanList.Append(pCL);
  1482 			iCleanList.Append(pCL);
  1487 #endif
  1483 #endif
  1488 			Lock();
  1484 			Lock();
  1489 			TUint16 count;
  1485 			TInt count;
  1490 			for(count = 0; count < growBy - 1; count++)
  1486 			for(count = 0; count < growBy - 1; count++)
  1491 				LIST_PUSH(iClientPool, &pCL[count], iNextInList);
  1487 				LIST_PUSH(iClientPool, &pCL[count], iNextInList);
  1492 			UnLock();
  1488 			UnLock();
  1493 #ifdef PRM_INSTRUMENTATION_MACRO
  1489 #ifdef PRM_INSTRUMENTATION_MACRO
  1494 		TUint size = growBy * sizeof(SPowerResourceClient);
  1490 		TUint size = growBy * sizeof(SPowerResourceClient);
  1550     SPowerResourceClientLevel* pCLL = NULL;
  1546     SPowerResourceClientLevel* pCLL = NULL;
  1551 	while(pCL != NULL)
  1547 	while(pCL != NULL)
  1552 		{
  1548 		{
  1553         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client 0x%x has requirement on resource %d", pCL->iClientId, pCL->iResourceId));
  1549         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client 0x%x has requirement on resource %d", pCL->iClientId, pCL->iResourceId));
  1554 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1550 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1555 		switch((pCL->iResourceId >>RESOURCE_BIT_IN_ID_CHECK) & 0x3)													
  1551 		switch((pCL->iResourceId >>RESOURCE_BIT_IN_ID_CHECK) & 0x3)
  1556 		{																		
  1552 			{
  1557 		case PRM_STATIC_RESOURCE:												
  1553 			case PRM_STATIC_RESOURCE:
  1558 			pR = iStaticResourceArray[pCL->iResourceId - 1];								
  1554 			pR = iStaticResourceArray[pCL->iResourceId - 1];
  1559 			break;																
  1555 				break;
  1560 		case PRM_DYNAMIC_RESOURCE:												
  1556 			case PRM_DYNAMIC_RESOURCE:
  1561 			pR = (iDynamicResourceList[(TUint16)(pCL->iResourceId & ID_INDEX_BIT_MASK)]);			
  1557 			pR = (iDynamicResourceList[(pCL->iResourceId & ID_INDEX_BIT_MASK)]);
  1562 			break;																
  1558 				break;
  1563 		case PRM_STATIC_DEPENDENCY_RESOURCE:									
  1559 			case PRM_STATIC_DEPENDENCY_RESOURCE:
  1564 			pR = (iStaticResDependencyArray[(TUint16)(pCL->iResourceId & ID_INDEX_BIT_MASK) - 1]);						
  1560 			pR = (iStaticResDependencyArray[(pCL->iResourceId & ID_INDEX_BIT_MASK) - 1]);
  1565 			break;																
  1561 				break;
  1566 		case PRM_DYNAMIC_DEPENDENCY_RESOURCE:									
  1562 			case PRM_DYNAMIC_DEPENDENCY_RESOURCE:
  1567 			pR = (iDynamicResDependencyList[(TUint16)(pCL->iResourceId & ID_INDEX_BIT_MASK)]);		
  1563 			pR = (iDynamicResDependencyList[(pCL->iResourceId & ID_INDEX_BIT_MASK)]);
  1568 			break;																
  1564 				break;
  1569 		}
  1565 			}
  1570 #else
  1566 #else
  1571 		pR = iStaticResourceArray[pCL->iResourceId -1];
  1567 		pR = iStaticResourceArray[pCL->iResourceId - 1];
  1572 #endif
  1568 #endif
  1573 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1569 #ifdef PRM_ENABLE_EXTENDED_VERSION
  1574 		if(((pR->Sense() == DStaticPowerResource::ECustom) || ((TInt)pCL->iClientId == pR->iLevelOwnerId)) && (!(pCL->iResourceId & KIdMaskDynamic) ||
  1570 		if(((pR->Sense() == DStaticPowerResource::ECustom) || ((TInt)pCL->iClientId == pR->iLevelOwnerId)) && (!(pCL->iResourceId & KIdMaskDynamic) ||
  1575 			         ((pCL->iResourceId & KIdMaskDynamic) && (((DDynamicPowerResource*)pR)->LockCount() != 0))))
  1571 			         ((pCL->iResourceId & KIdMaskDynamic) && (((DDynamicPowerResource*)pR)->LockCount() != 0))))
  1576 #else
  1572 #else
  1691 	CHECK_CONTEXT(thread)
  1687 	CHECK_CONTEXT(thread)
  1692 	if((aClientId & USER_SIDE_CLIENT_BIT_MASK) || (aClientId == iPowerControllerId))
  1688 	if((aClientId & USER_SIDE_CLIENT_BIT_MASK) || (aClientId == iPowerControllerId))
  1693 		return KErrArgument;
  1689 		return KErrArgument;
  1694 	//Get the index from client ID
  1690 	//Get the index from client ID
  1695 	Lock();
  1691 	Lock();
  1696 	SPowerResourceClient* pC = iClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)];
  1692 	SPowerResourceClient* pC = iClientList[(aClientId & ID_INDEX_BIT_MASK)];
  1697     if(!pC)
  1693     if(!pC)
  1698 	    {
  1694 	    {
  1699         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found"));
  1695         __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found"));
  1700         UNLOCK_RETURN(KErrNotFound);
  1696         UNLOCK_RETURN(KErrNotFound);
  1701 		}
  1697 		}
  1735 	ResourceStateChangeOfClientLevels(pC);
  1731 	ResourceStateChangeOfClientLevels(pC);
  1736 	// Add reserved request to pool
  1732 	// Add reserved request to pool
  1737 	iRequestPoolCount = (TUint16)(iRequestPoolCount + (TUint16)pC->iReservedRm);
  1733 	iRequestPoolCount = (TUint16)(iRequestPoolCount + (TUint16)pC->iReservedRm);
  1738 	PRM_CLIENT_DEREGISTER_TRACE
  1734 	PRM_CLIENT_DEREGISTER_TRACE
  1739 	//Increment the free pool count for client level and request level.
  1735 	//Increment the free pool count for client level and request level.
  1740 	iClientList.Remove(pC, (TUint16)(pC->iClientId & ID_INDEX_BIT_MASK));
  1736 	iClientList.Remove(pC, (pC->iClientId & ID_INDEX_BIT_MASK));
  1741 	pC->iName = NULL;
  1737 	pC->iName = NULL;
  1742 	iClientCount--; //Decrement client count
  1738 	iClientCount--; //Decrement client count
  1743 	LIST_PUSH(iClientPool, pC, iNextInList);
  1739 	LIST_PUSH(iClientPool, pC, iNextInList);
  1744 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::DeRegisterClient"));
  1740 	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::DeRegisterClient"));
  1745 	UNLOCK_RETURN(KErrNone);
  1741 	UNLOCK_RETURN(KErrNone);
  1872 	SPowerResourceClient* pC;
  1868 	SPowerResourceClient* pC;
  1873 	if(aResourceName.Length() > KMaxResourceNameLength)
  1869 	if(aResourceName.Length() > KMaxResourceNameLength)
  1874 		return KErrTooBig;
  1870 		return KErrTooBig;
  1875 	Lock();
  1871 	Lock();
  1876 	VALIDATE_CLIENT(thread);
  1872 	VALIDATE_CLIENT(thread);
  1877 	TUint count = 0;
  1873 	TInt count = 0;
  1878 	//Search in static resource with no dependencies array for specified resource name.
  1874 	//Search in static resource with no dependencies array for specified resource name.
  1879 	for(count = 0; count < iStaticResourceArrayEntries; count++)
  1875 	for(count = 0; count < iStaticResourceArray.Count(); count++)
  1880 		{
  1876 		{
  1881 		if((iStaticResourceArray[count]) && (!(aResourceName.Compare(*(const TDesC8*)iStaticResourceArray[count]->iName))))
  1877 		if((iStaticResourceArray[count]) && (!(aResourceName.Compare(*(const TDesC8*)iStaticResourceArray[count]->iName))))
  1882 			{
  1878 			{
  1883 			aResourceId = ++count;
  1879 			aResourceId = ++count;
  1884 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1880 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1894 		aResourceId = pDR->iResourceId;
  1890 		aResourceId = pDR->iResourceId;
  1895 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1891 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1896 		UNLOCK_RETURN(KErrNone);
  1892 		UNLOCK_RETURN(KErrNone);
  1897 		}
  1893 		}
  1898 	//Search in static resource with dependencies (if exists) for specified resource name
  1894 	//Search in static resource with dependencies (if exists) for specified resource name
  1899 	for(count = 0; count < iStaticResDependencyCount; count++)
  1895 	for(count = 0; count < iStaticResDependencyArray.Count(); count++)
  1900 		{
  1896 		{
  1901 		if(!(aResourceName.Compare(*(const TDesC8*)iStaticResDependencyArray[count]->iName)))
  1897 		if(!(aResourceName.Compare(*(const TDesC8*)iStaticResDependencyArray[count]->iName)))
  1902 			{
  1898 			{
  1903 			aResourceId = iStaticResDependencyArray[count]->iResourceId;
  1899 			aResourceId = iStaticResDependencyArray[count]->iResourceId;
  1904 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1900 			__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetResourceId, ResourceId = 0x%x", aResourceId));
  1963 	//Validate buffer size
  1959 	//Validate buffer size
  1964 	if((TUint)(buf->MaxLength() - buf->Length()) < sizeof(TPowerResourceInfoV01))
  1960 	if((TUint)(buf->MaxLength() - buf->Length()) < sizeof(TPowerResourceInfoV01))
  1965 	   UNLOCK_RETURN(KErrArgument);
  1961 	   UNLOCK_RETURN(KErrArgument);
  1966 
  1962 
  1967 #ifndef PRM_ENABLE_EXTENDED_VERSION
  1963 #ifndef PRM_ENABLE_EXTENDED_VERSION
  1968 	if((!aResourceId) || (aResourceId > iStaticResourceArrayEntries))
  1964 	if((!aResourceId) || (aResourceId > (TUint)iStaticResourceArray.Count()))
  1969 		UNLOCK_RETURN(KErrNotFound);
  1965 		UNLOCK_RETURN(KErrNotFound);
  1970 	//Get resource from static resource array. 0(1) operation.
  1966 	//Get resource from static resource array. 0(1) operation.
  1971 	pR = iStaticResourceArray[aResourceId-1];
  1967 	pR = iStaticResourceArray[aResourceId-1];
  1972 	if(!pR)
  1968 	if(!pR)
  1973 		{
  1969 		{
  2034 	VALIDATE_CLIENT(thread);
  2030 	VALIDATE_CLIENT(thread);
  2035 	//Special case, return number of resources registered resource controller.
  2031 	//Special case, return number of resources registered resource controller.
  2036 	if(!aTargetClientId)
  2032 	if(!aTargetClientId)
  2037 		{
  2033 		{
  2038 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2034 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2039 		aNumResource = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyCount + 
  2035 		aNumResource = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyArray.Count() + 
  2040 			                                                          iDynamicResDependencyCount; 
  2036 			                                                          iDynamicResDependencyCount; 
  2041 #else
  2037 #else
  2042 		aNumResource = iStaticResourceCount;
  2038 		aNumResource = iStaticResourceCount;
  2043 #endif
  2039 #endif
  2044 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetNumResourcesInUseByClient, numResources = %d", aNumResource));
  2040 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetNumResourcesInUseByClient, numResources = %d", aNumResource));
  2113     TDes8 *pInfo = (TDes8*)anInfo;
  2109     TDes8 *pInfo = (TDes8*)anInfo;
  2114     if((TUint)(pInfo->MaxLength() - pInfo->Length()) < (sizeof(TPowerResourceInfoV01) * aNumResources))
  2110     if((TUint)(pInfo->MaxLength() - pInfo->Length()) < (sizeof(TPowerResourceInfoV01) * aNumResources))
  2115          UNLOCK_RETURN(KErrArgument);
  2111          UNLOCK_RETURN(KErrArgument);
  2116     TPowerResourceInfoBuf01 buf;
  2112     TPowerResourceInfoBuf01 buf;
  2117 
  2113 
  2118 	TUint16 count = 0;
  2114 	TInt count = 0;
  2119 	TInt r = KErrNone;
  2115 	TInt r = KErrNone;
  2120 	//Special case, if aTargetClientId is 0 fill with all the resource
  2116 	//Special case, if aTargetClientId is 0 fill with all the resource
  2121 	if(!aTargetClientId)
  2117 	if(!aTargetClientId)
  2122 		{
  2118 		{
  2123 		TUint numResources = aNumResources;
  2119 		TInt numResources = aNumResources;
  2124 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2120 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2125 		aNumResources = iStaticResourceCount;
  2121 		aNumResources = iStaticResourceCount;
  2126 #else
  2122 #else
  2127 		aNumResources = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyCount + 
  2123 		aNumResources = iStaticResourceCount + iDynamicResourceCount + iStaticResDependencyArray.Count() + 
  2128 			                                                           iDynamicResDependencyCount;
  2124 			                                                           iDynamicResDependencyCount;
  2129 #endif
  2125 #endif
  2130 		UnLock();
  2126 		UnLock();
  2131 		while(count < iStaticResourceArrayEntries)
  2127 		while(count < iStaticResourceArray.Count())
  2132 			{
  2128 			{
  2133 			if(numResources <=0)
  2129 			if(numResources == 0)
  2134 				return KErrNone;
  2130 				return KErrNone;
  2135 			pR = iStaticResourceArray[count++];
  2131 			pR = iStaticResourceArray[count++];
  2136 			if(!pR)
  2132 			if(!pR)
  2137 				continue;
  2133 				continue;
  2138             r = pR->GetInfo((TDes8*)buf.Ptr());
  2134             r = pR->GetInfo((TDes8*)buf.Ptr());
  2143 			pInfo->Append(buf);
  2139 			pInfo->Append(buf);
  2144 			numResources--;
  2140 			numResources--;
  2145 			}	
  2141 			}	
  2146 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2142 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2147 		count = 0;
  2143 		count = 0;
  2148 		while(count < iStaticResDependencyCount)
  2144 		while(count < iStaticResDependencyArray.Count())
  2149 			{
  2145 			{
  2150 			if(count >= numResources)
  2146 			if(count >= numResources)
  2151 				return KErrNone;
  2147 				return KErrNone;
  2152 			pR = iStaticResDependencyArray[count++];
  2148 			pR = iStaticResDependencyArray[count++];
  2153 			r = pR->GetInfo((TDes8*)buf.Ptr());
  2149 			r = pR->GetInfo((TDes8*)buf.Ptr());
  2155 			((TPowerResourceInfoV01*)buf.Ptr())->iResourceId = ((DStaticPowerResourceD*)pR)->iResourceId;
  2151 			((TPowerResourceInfoV01*)buf.Ptr())->iResourceId = ((DStaticPowerResourceD*)pR)->iResourceId;
  2156 			if(r != KErrNone)
  2152 			if(r != KErrNone)
  2157 				return r;
  2153 				return r;
  2158 			pInfo->Append(buf);
  2154 			pInfo->Append(buf);
  2159 			}
  2155 			}
  2160 		numResources -= iStaticResDependencyCount;
  2156 		numResources -= iStaticResDependencyArray.Count();
  2161 		if((!numResources) || (!iDynamicResourceCount && !iDynamicResDependencyCount))
  2157 		if((!numResources) || (!iDynamicResourceCount && !iDynamicResDependencyCount))
  2162 			return r;
  2158 			return r;
  2163 		Lock();
  2159 		Lock();
  2164 		TUint resCount = 0;
  2160 		TInt resCount = 0;
  2165 		for(count = 0; count < iDynamicResourceList.Allocd(); count++)
  2161 		for(count = 0; count < iDynamicResourceList.Allocd(); count++)
  2166 			{
  2162 			{
  2167 			pR = iDynamicResourceList[count];
  2163 			pR = iDynamicResourceList[count];
  2168 			if(!pR)
  2164 			if(!pR)
  2169 				continue;
  2165 				continue;
  2176 			pInfo->Append(buf);
  2172 			pInfo->Append(buf);
  2177 			resCount++;
  2173 			resCount++;
  2178 			}
  2174 			}
  2179 		numResources -= resCount;
  2175 		numResources -= resCount;
  2180 		resCount = 0;
  2176 		resCount = 0;
  2181 		for(count = 0; count < iDynamicResDependencyList.Allocd(); count++) 
  2177 		for(count = 0; count < (TInt)iDynamicResDependencyList.Allocd(); count++) 
  2182 			{
  2178 			{
  2183 			pR = iDynamicResDependencyList[count];
  2179 			pR = iDynamicResDependencyList[count];
  2184 			if(!pR)
  2180 			if(!pR)
  2185 				continue;
  2181 				continue;
  2186 			if((resCount >= iDynamicResDependencyCount) || (resCount >= numResources))
  2182 			if((resCount >= iDynamicResDependencyCount) || (resCount >= numResources))
  2198 		}
  2194 		}
  2199 	GET_TARGET_CLIENT();
  2195 	GET_TARGET_CLIENT();
  2200 	SPowerResourceClientLevel* pCL = pC->iLevelList;
  2196 	SPowerResourceClientLevel* pCL = pC->iLevelList;
  2201 	for (count= 0; pCL; count++, pCL = pCL->iNextInList)
  2197 	for (count= 0; pCL; count++, pCL = pCL->iNextInList)
  2202 		{
  2198 		{
  2203 		if(count >= aNumResources)
  2199 		if(count >= (TInt)aNumResources)
  2204 			continue;
  2200 			continue;
  2205 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2201 #ifndef PRM_ENABLE_EXTENDED_VERSION
  2206 		pR = iStaticResourceArray[pCL->iResourceId-1];
  2202 		pR = iStaticResourceArray[pCL->iResourceId-1];
  2207 #else
  2203 #else
  2208 		GET_RESOURCE_FROM_LIST(pCL->iResourceId, pR);
  2204 		GET_RESOURCE_FROM_LIST(pCL->iResourceId, pR);
  2265 		}
  2261 		}
  2266 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2262 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2267 	DStaticPowerResource* pR = NULL;
  2263 	DStaticPowerResource* pR = NULL;
  2268 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2264 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2269 #else
  2265 #else
  2270 	if(aResourceId > iStaticResourceArrayEntries)
  2266 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2271 		UNLOCK_RETURN(KErrNotFound);
  2267 		UNLOCK_RETURN(KErrNotFound);
  2272 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2268 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2273 	if(!pR)
  2269 	if(!pR)
  2274 		UNLOCK_RETURN(KErrNotFound);
  2270 		UNLOCK_RETURN(KErrNotFound);
  2275 #endif
  2271 #endif
  2369 		}
  2365 		}
  2370 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2366 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2371 	DStaticPowerResource* pR = NULL;
  2367 	DStaticPowerResource* pR = NULL;
  2372 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2368 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2373 #else
  2369 #else
  2374 	if(aResourceId > iStaticResourceArrayEntries)
  2370 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2375 		UNLOCK_RETURN(KErrNotFound);
  2371 		UNLOCK_RETURN(KErrNotFound);
  2376 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2372 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2377 	if(!pR)
  2373 	if(!pR)
  2378 		UNLOCK_RETURN(KErrNotFound);
  2374 		UNLOCK_RETURN(KErrNotFound);
  2379 #endif
  2375 #endif
  2383 		{
  2379 		{
  2384 		if(c >= aNumClients)
  2380 		if(c >= aNumClients)
  2385 			continue;
  2381 			continue;
  2386 		pCL = (SPowerResourceClientLevel*)pRC;
  2382 		pCL = (SPowerResourceClientLevel*)pRC;
  2387 		if(pCL->iClientId & USER_SIDE_CLIENT_BIT_MASK)
  2383 		if(pCL->iClientId & USER_SIDE_CLIENT_BIT_MASK)
  2388 			pC = iUserSideClientList[(TUint16)(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2384 			pC = iUserSideClientList[(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2389 		else
  2385 		else
  2390 			pC = iClientList[(TUint16)(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2386 			pC = iClientList[(pCL->iClientId & ID_INDEX_BIT_MASK)];
  2391 		info.iClientId = pC->iClientId;
  2387 		info.iClientId = pC->iClientId;
  2392 		info.iClientName =  (TDesC8*)pC->iName;
  2388 		info.iClientName =  (TDesC8*)pC->iName;
  2393         pInfo->Append(TPckgC<TPowerClientInfoV01>(info));
  2389         pInfo->Append(TPckgC<TPowerClientInfoV01>(info));
  2394 		}
  2390 		}
  2395 	aNumClients = c;
  2391 	aNumClients = c;
  2403 
  2399 
  2404 Request changing the state of a resource
  2400 Request changing the state of a resource
  2405 NOTE: If a resource callback is specified for instantaneous resource, then callback
  2401 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
  2402       will be called after resource change and will be executed in the context of the
  2407       client thread.
  2403       client thread.
  2408       If a resource callback is specified for long latency reosurces, then it will be
  2404       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
  2405       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) 
  2406 	  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.
  2407 	  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
  2408       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.
  2409       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
  2418                    binary resource, an integer level for a multilevel resource or some
  2423                    platform specific token for a multi-property resource.
  2419                    platform specific token for a multi-property resource.
  2424 @param aCb         For Long latency resource
  2420 @param aCb         For Long latency resource
  2425                        A pointer to a resource callback object which encapsulates a
  2421                        A pointer to a resource callback object which encapsulates a
  2426                        callback function to be called whenever the resource state change
  2422                        callback function to be called whenever the resource state change
  2427                        happens (if left NULL the API will execute synchrounously).
  2423                        happens (if left NULL the API will execute synchronously).
  2428                    For Instantaneous resource
  2424                    For Instantaneous resource
  2429                        A pointer to a resource callback object which encapsulates a callback
  2425                        A pointer to a resource callback object which encapsulates a callback
  2430                        function to be called after resource change. This executes in the
  2426                        function to be called after resource change. This executes in the
  2431                        context of the client thread.
  2427                        context of the client thread.
  2432 
  2428 
  2477 	VALIDATE_CLIENT(thread);
  2473 	VALIDATE_CLIENT(thread);
  2478 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2474 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2479 	DStaticPowerResource *pR = NULL;
  2475 	DStaticPowerResource *pR = NULL;
  2480 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2476 	GET_RESOURCE_FROM_LIST(aResourceId, pR) 
  2481 #else
  2477 #else
  2482 	if(aResourceId > iStaticResourceArrayEntries)
  2478 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2483 		UNLOCK_RETURN(KErrNotFound);
  2479 		UNLOCK_RETURN(KErrNotFound);
  2484 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2480 	DStaticPowerResource* pR = iStaticResourceArray[aResourceId-1];
  2485 	if(!pR)
  2481 	if(!pR)
  2486 		UNLOCK_RETURN(KErrNotFound);
  2482 		UNLOCK_RETURN(KErrNotFound);
  2487 #endif
  2483 #endif
  2561 
  2557 
  2562 	TPowerRequest* req;
  2558 	TPowerRequest* req;
  2563 	SPowerRequest* pS=NULL;
  2559 	SPowerRequest* pS=NULL;
  2564 	if(pR->LatencySet() && aCb)
  2560 	if(pR->LatencySet() && aCb)
  2565 		{
  2561 		{
  2566 		// Get request object from free pool, as it is long latency reosurce as client
  2562 		// 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.
  2563 		// will be unblocked once message is sent to controller, so can't use thread message.
  2568 		if(pC->iReservedRm ==0 && !iRequestPoolCount)
  2564 		if(pC->iReservedRm ==0 && !iRequestPoolCount)
  2569 			{
  2565 			{
  2570             r = KErrUnderflow;
  2566             r = KErrUnderflow;
  2571             PRM_CLIENT_CHANGE_STATE_END_TRACE
  2567             PRM_CLIENT_CHANGE_STATE_END_TRACE
  2572 			UNLOCK_RETURN(r);
  2568 			UNLOCK_RETURN(r);
  2615 				return KErrNone;
  2611 				return KErrNone;
  2616 				}
  2612 				}
  2617 			else
  2613 			else
  2618 #endif
  2614 #endif
  2619 				{
  2615 				{
  2620 				req->Send(iMsgQ); // Send the request to Resource Controler thread.
  2616 				req->Send(iMsgQ); // Send the request to Resource Controller thread.
  2621 				return KErrNone;
  2617 				return KErrNone;
  2622 				}
  2618 				}
  2623 			}
  2619 			}
  2624 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2620 #ifdef PRM_ENABLE_EXTENDED_VERSION
  2625 		if(aResourceId & KIdMaskResourceWithDependencies) //Dependency resource
  2621 		if(aResourceId & KIdMaskResourceWithDependencies) //Dependency resource
  2766 @param aCached     If ETrue, cached value will be updated in aState.
  2762 @param aCached     If ETrue, cached value will be updated in aState.
  2767                    If EFalse, aState will be updated after the resource
  2763                    If EFalse, aState will be updated after the resource
  2768                    state is read from resource.
  2764                    state is read from resource.
  2769 @param aState      Returns the resource state if operation was successful. This
  2765 @param aState      Returns the resource state if operation was successful. This
  2770                    could be a binary value for a binary resource, an integer level
  2766                    could be a binary value for a binary resource, an integer level
  2771                    for a multilevel resource or some platform specific tolen for a
  2767                    for a multilevel resource or some platform specific token for a
  2772                    multi-property resource.
  2768                    multi-property resource.
  2773 @param aLevelOwnerId Returns the Id of the client that is currently holding the resource.
  2769 @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.
  2770 					 -1	is returned when no client is holding the resource.
  2775 
  2771 
  2776 @return KErrNone   if operation was successful
  2772 @return KErrNone   if operation was successful
  2813 		{
  2809 		{
  2814 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2810 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2815 			UNLOCK_RETURN(KErrNotFound);
  2811 			UNLOCK_RETURN(KErrNotFound);
  2816 		}
  2812 		}
  2817 #else
  2813 #else
  2818 	if(aResourceId > iStaticResourceArrayEntries)
  2814 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2819 		UNLOCK_RETURN(KErrNotFound);
  2815 		UNLOCK_RETURN(KErrNotFound);
  2820 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2816 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2821 	if(!pR)
  2817 	if(!pR)
  2822 		UNLOCK_RETURN(KErrNotFound);
  2818 		UNLOCK_RETURN(KErrNotFound);
  2823 #endif
  2819 #endif
  2897 
  2893 
  2898 /**   
  2894 /**   
  2899 @publishedPartner
  2895 @publishedPartner
  2900 @prototype 9.5
  2896 @prototype 9.5
  2901 
  2897 
  2902 Request the state of the resource asynchrounously for long latency resource and
  2898 Request the state of the resource asynchronously for long latency resource and
  2903 synchronously for instantaneous resource
  2899 synchronously for instantaneous resource
  2904 
  2900 
  2905 @param aClientId  ID of the client which is requesting the resource state.
  2901 @param aClientId  ID of the client which is requesting the resource state.
  2906 @param aResourceId ID of the resource whose state is being requested.
  2902 @param aResourceId ID of the resource whose state is being requested.
  2907 @param aCached If ETrue, cached value will be updated in aState
  2903 @param aCached If ETrue, cached value will be updated in aState
  2959 		//Dynamic resource in process of deregistration
  2955 		//Dynamic resource in process of deregistration
  2960 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2956 		if(((DDynamicPowerResource*)pR)->LockCount() == 0)
  2961 			UNLOCK_RETURN(KErrNotFound);
  2957 			UNLOCK_RETURN(KErrNotFound);
  2962 		}
  2958 		}
  2963 #else
  2959 #else
  2964 	if(aResourceId > iStaticResourceArrayEntries)
  2960 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  2965 		UNLOCK_RETURN(KErrNotFound);
  2961 		UNLOCK_RETURN(KErrNotFound);
  2966 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2962 	DStaticPowerResource *pR = iStaticResourceArray[aResourceId-1];
  2967 	if(!pR)
  2963 	if(!pR)
  2968 		UNLOCK_RETURN(KErrNotFound);
  2964 		UNLOCK_RETURN(KErrNotFound);
  2969 #endif
  2965 #endif
  3096 @prototype 9.5
  3092 @prototype 9.5
  3097 
  3093 
  3098 Cancel an asynchronous request(or its callback).
  3094 Cancel an asynchronous request(or its callback).
  3099 
  3095 
  3100 @param aClientId       ID of the client which is requesting the cancellation of the request.
  3096 @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
  3097 @param aResourceId     ID for the resource which the request that is being canceled operates
  3102                        upon.
  3098                        upon.
  3103 @param aCb             A reference to the resource callback object specified with the request
  3099 @param aCb             A reference to the resource callback object specified with the request
  3104                        that is being cancelled.
  3100                        that is being canceled.
  3105 
  3101 
  3106 @return KErrCancel if the request was cancelled.
  3102 @return KErrCancel if the request was canceled.
  3107         KErrNotFound if this resource ID could not be found in the current list of controllable
  3103         KErrNotFound if this resource ID could not be found in the current list of controllable
  3108                      resources.
  3104                      resources.
  3109         KErrCompletion if request is no longer pending.
  3105         KErrCompletion if request is no longer pending.
  3110         KErrAccessDenied if the client ID could not be found in the current list of registered
  3106         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
  3107 		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.
  3108 		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 
  3109 		KErrInUse if the request cannot be canceled as processing of the request already started 
  3114 		and will run to completion. 
  3110 		and will run to completion. 
  3115 
  3111 
  3116 @pre Interrupts must be enabled
  3112 @pre Interrupts must be enabled
  3117 @pre Kernel must be unlocked
  3113 @pre Kernel must be unlocked
  3118 @pre No fast mutex can be held
  3114 @pre No fast mutex can be held
  3228 						 thread relative and this API is not called from the same thread. 
  3224 						 thread relative and this API is not called from the same thread. 
  3229 		KErrInUse if the passed notification object is used already.
  3225 		KErrInUse if the passed notification object is used already.
  3230 NOTE: This API should return immediately; however the notification will
  3226 NOTE: This API should return immediately; however the notification will
  3231 only happen when a resource change occurs.Notification request is idempotent, 
  3227 only happen when a resource change occurs.Notification request is idempotent, 
  3232 if the same notification has already been requested for this resource ID, 
  3228 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.
  3229 the API returns with no further action.Notifications remain queued until they are canceled.
  3234 
  3230 
  3235 @pre Interrupts must be enabled
  3231 @pre Interrupts must be enabled
  3236 @pre Kernel must be unlocked
  3232 @pre Kernel must be unlocked
  3237 @pre No fast mutex can be held
  3233 @pre No fast mutex can be held
  3238 @pre Call in a thread context but not from null thread or DFC thread1
  3234 @pre Call in a thread context but not from null thread or DFC thread1
  3256 		}
  3252 		}
  3257 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3253 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3258 	DStaticPowerResource *pR = NULL;
  3254 	DStaticPowerResource *pR = NULL;
  3259 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3255 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3260 #else
  3256 #else
  3261 	if(aResourceId > iStaticResourceArrayEntries)
  3257 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  3262 		{
  3258 		{
  3263         r = KErrNotFound;
  3259         r = KErrNotFound;
  3264 		PRM_POSTNOTIFICATION_REGISTER_TRACE
  3260 		PRM_POSTNOTIFICATION_REGISTER_TRACE
  3265 		UNLOCK_RETURN(r);
  3261 		UNLOCK_RETURN(r);
  3266 		}
  3262 		}
  3320 
  3316 
  3321 
  3317 
  3322 
  3318 
  3323 @return KErrNone if the operation of requesting a notification was successful.
  3319 @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
  3320         KErrNotFound if this resource ID could not be found in the current list
  3325                      of controllable reosurces.
  3321                      of controllable resources.
  3326         KErrAccessDenied if the client ID could not be found in the list of
  3322         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
  3323                          registered clients or if the client was registered to be thread
  3328 						 relative and this API is not called from the same thread. 
  3324 						 relative and this API is not called from the same thread. 
  3329 		KErrInUse if the passed notification object is used already.
  3325 		KErrInUse if the passed notification object is used already.
  3330 		KErrArgument if the specified threshold is out of range.
  3326 		KErrArgument if the specified threshold is out of range.
  3331 NOTE: This API should return immediately; however the notification will only
  3327 NOTE: This API should return immediately; however the notification will only
  3332 happen when a resource change occurs. Notification request is idempotent, 
  3328 happen when a resource change occurs. Notification request is idempotent, 
  3333 if the same notification has already been requested for this resource ID, 
  3329 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.
  3330 the API returns with no further action. Notification remain queued until they are canceled.
  3335 
  3331 
  3336 @pre Interrupts must be enabled
  3332 @pre Interrupts must be enabled
  3337 @pre Kernel must be unlocked
  3333 @pre Kernel must be unlocked
  3338 @pre No fast mutex can be held
  3334 @pre No fast mutex can be held
  3339 @pre Call in a thread context but not from null thread or DFC thread1
  3335 @pre Call in a thread context but not from null thread or DFC thread1
  3359 		}
  3355 		}
  3360 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3356 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3361 	DStaticPowerResource *pR = NULL;
  3357 	DStaticPowerResource *pR = NULL;
  3362 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3358 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3363 #else
  3359 #else
  3364 	if(aResourceId > iStaticResourceArrayEntries)
  3360 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  3365 		{
  3361 		{
  3366         r = KErrNotFound;
  3362         r = KErrNotFound;
  3367         PRM_POSTNOTIFICATION_REGISTER_TRACE
  3363         PRM_POSTNOTIFICATION_REGISTER_TRACE
  3368 		UNLOCK_RETURN(r);
  3364 		UNLOCK_RETURN(r);
  3369 		}
  3365 		}
  3423 Cancel and remove from queue a previously issued request for notification on a
  3419 Cancel and remove from queue a previously issued request for notification on a
  3424 resource state change.
  3420 resource state change.
  3425 
  3421 
  3426 @param aClientId ID of the client which is requesting to cancel the notification
  3422 @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
  3423 @param aResourceId for the resource whose pending notification of state changes
  3428                    is being cancelled.
  3424                    is being canceled.
  3429 @param aN          A reference to the notification object that was associated with
  3425 @param aN          A reference to the notification object that was associated with
  3430                    the notification request that is being cancelled. This will be
  3426                    the notification request that is being canceled. This will be
  3431                    used to identify the notification that is being cancelled.
  3427                    used to identify the notification that is being canceled.
  3432 
  3428 
  3433 @return KErrCancel if the notification request was successfully cancelled.
  3429 @return KErrCancel if the notification request was successfully canceled.
  3434         KErrNotFound if the specified notification object is 
  3430         KErrNotFound if the specified notification object is 
  3435 					 not found in the current list of notification objects for the 
  3431 					 not found in the current list of notification objects for the 
  3436 					 specified resource.
  3432 					 specified resource.
  3437         KErrAccessDenied if the client requesting the cancellation is not the same
  3433         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
  3434                          which registered the notification or if the resource id does not match or
  3582 	Lock();
  3578 	Lock();
  3583 	TInt clientPoolCount = iClientLevelPoolCount;
  3579 	TInt clientPoolCount = iClientLevelPoolCount;
  3584 	TInt requestPoolCount = iRequestPoolCount;
  3580 	TInt requestPoolCount = iRequestPoolCount;
  3585 	SPowerResourceClient* pC;
  3581 	SPowerResourceClient* pC;
  3586 	if(aRequest.ClientId() & USER_SIDE_CLIENT_BIT_MASK)
  3582 	if(aRequest.ClientId() & USER_SIDE_CLIENT_BIT_MASK)
  3587 		pC = iUserSideClientList[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3583 		pC = iUserSideClientList[(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3588 	else																				
  3584 	else																				
  3589 		pC = iClientList[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3585 		pC = iClientList[(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
  3590 	UnLock();
  3586 	UnLock();
  3591 
  3587 
  3592 	if(clientPoolCount < aRequest.ClientLevelCount())
  3588 	if(clientPoolCount < aRequest.ClientLevelCount())
  3593 		{
  3589 		{
  3594 		//Grow the client level pool
  3590 		//Grow the client level pool
  3683 	req->ReqType() = TPowerRequest::ERegisterUsersideClient;
  3679 	req->ReqType() = TPowerRequest::ERegisterUsersideClient;
  3684 	UnLock();
  3680 	UnLock();
  3685 	req->SendReceive(iMsgQ);
  3681 	req->SendReceive(iMsgQ);
  3686 	if(req->ReturnCode() == KErrNone)
  3682 	if(req->ReturnCode() == KErrNone)
  3687 		{
  3683 		{
  3688 		pC = iUserSideClientList[(TUint16)(req->ClientId() & ID_INDEX_BIT_MASK)];
  3684 		pC = iUserSideClientList[(req->ClientId() & ID_INDEX_BIT_MASK)];
  3689 		pC->iName=&aName;
  3685 		pC->iName=&aName;
  3690 		//Store the current thread Id;
  3686 		//Store the current thread Id;
  3691 		pC->iThreadId = t.iId;
  3687 		pC->iThreadId = t.iId;
  3692 		aClientId = pC->iClientId;
  3688 		aClientId = pC->iClientId;
  3693 		}
  3689 		}
  3708 	CHECK_CONTEXT(t)
  3704 	CHECK_CONTEXT(t)
  3709 	//Get the index from client ID
  3705 	//Get the index from client ID
  3710 	if(!(aClientId & USER_SIDE_CLIENT_BIT_MASK))
  3706 	if(!(aClientId & USER_SIDE_CLIENT_BIT_MASK))
  3711 		return KErrArgument;
  3707 		return KErrArgument;
  3712 	Lock();
  3708 	Lock();
  3713 	SPowerResourceClient* pC = iUserSideClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)];
  3709 	SPowerResourceClient* pC = iUserSideClientList[(aClientId & ID_INDEX_BIT_MASK)];
  3714 	if(!pC)
  3710 	if(!pC)
  3715 		{
  3711 		{
  3716 		UnLock();
  3712 		UnLock();
  3717 		LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3713 		LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3718 		return KErrNotFound;
  3714 		return KErrNotFound;
  3756 	ResourceStateChangeOfClientLevels(pC);
  3752 	ResourceStateChangeOfClientLevels(pC);
  3757 	//Add reserved request to pool
  3753 	//Add reserved request to pool
  3758 	iRequestPoolCount = (TUint16)(iRequestPoolCount + pC->iReservedRm);
  3754 	iRequestPoolCount = (TUint16)(iRequestPoolCount + pC->iReservedRm);
  3759 	PRM_CLIENT_DEREGISTER_TRACE
  3755 	PRM_CLIENT_DEREGISTER_TRACE
  3760 	//Increment the free pool count for client level and request level.
  3756 	//Increment the free pool count for client level and request level.
  3761 	iUserSideClientList.Remove(pC, (TUint16)(pC->iClientId & ID_INDEX_BIT_MASK));
  3757 	iUserSideClientList.Remove(pC, (pC->iClientId & ID_INDEX_BIT_MASK));
  3762 	pC->iName = NULL;
  3758 	pC->iName = NULL;
  3763 	iUserSideClientCount--; //Decrement client count
  3759 	iUserSideClientCount--; //Decrement client count
  3764 	LIST_PUSH(iClientPool, pC, iNextInList);
  3760 	LIST_PUSH(iClientPool, pC, iNextInList);
  3765 	UnLock();
  3761 	UnLock();
  3766 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3762 	LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3793 	TUint count=0;
  3789 	TUint count=0;
  3794 	TUint id=0;
  3790 	TUint id=0;
  3795 	for(count=0;count<aNumResources;count++) //Check for valid resource ID.
  3791 	for(count=0;count<aNumResources;count++) //Check for valid resource ID.
  3796 		{
  3792 		{
  3797 #ifndef PRM_ENABLE_EXTENDED_VERSION
  3793 #ifndef PRM_ENABLE_EXTENDED_VERSION
  3798 		if((!pS->iResourceId) || (pS->iResourceId > iStaticResourceArrayEntries) || (!iStaticResourceArray[pS->iResourceId-1]))
  3794 		if((!pS->iResourceId) || (pS->iResourceId > (TUint)iStaticResourceArray.Count()) || (!iStaticResourceArray[pS->iResourceId-1]))
  3799 			{
  3795 			{
  3800 			UnLock();
  3796 			UnLock();
  3801 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3797 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3802 			return KErrNotFound;
  3798 			return KErrNotFound;
  3803 			}
  3799 			}
  3807 			UnLock();
  3803 			UnLock();
  3808 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3804 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3809 			return KErrNotSupported;
  3805 			return KErrNotSupported;
  3810 			}
  3806 			}
  3811 		if((!pS->iResourceId) || ((pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3807 		if((!pS->iResourceId) || ((pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3812 			     (pS->iResourceId > iStaticResDependencyCount)) || (!(pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3808 			     (pS->iResourceId > (TUint)iStaticResDependencyArray.Count())) || (!(pS->iResourceId & KIdMaskResourceWithDependencies) && 
  3813 					((pS->iResourceId > iStaticResourceArrayEntries) || (!iStaticResourceArray[pS->iResourceId-1]))))
  3809 					((pS->iResourceId > (TUint)iStaticResourceArray.Count()) || (!iStaticResourceArray[pS->iResourceId-1]))))
  3814 			{
  3810 			{
  3815 			UnLock();
  3811 			UnLock();
  3816 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3812 			LOCK_AND_CRITICAL_SECTION_COUNT_CHECK
  3817 			return KErrNotFound;
  3813 			return KErrNotFound;
  3818 			}
  3814 			}
  3883 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3879 #ifdef PRM_ENABLE_EXTENDED_VERSION
  3884 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3880 	GET_RESOURCE_FROM_LIST(aResourceId, pR)
  3885 	if(aResourceId & KIdMaskDynamic)
  3881 	if(aResourceId & KIdMaskDynamic)
  3886 		((DDynamicPowerResource*)pR)->Lock();
  3882 		((DDynamicPowerResource*)pR)->Lock();
  3887 #else
  3883 #else
  3888 	if(aResourceId > iStaticResourceArrayEntries)
  3884 	if(aResourceId > (TUint)iStaticResourceArray.Count())
  3889 		{
  3885 		{
  3890 		UNLOCK_RETURN(KErrNotFound);
  3886 		UNLOCK_RETURN(KErrNotFound);
  3891 		}
  3887 		}
  3892 	pR = iStaticResourceArray[aResourceId - 1];
  3888 	pR = iStaticResourceArray[aResourceId - 1];
  3893 	if(!pR)
  3889 	if(!pR)