First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\resourceman\resourceman_psl\rescontrol_psl.cpp
18 #include "rescontrol_psl.h"
19 TInt KSimulatedRCThreadPriority = 28;
20 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
21 static DSimulatedPowerResourceController TheController;
24 //Resource controller creation
25 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
26 DECLARE_STANDARD_PDD()
28 TInt r = DPowerResourceController::InitController();
30 return new DResConPddFactory;
35 /** ISR function invoked when the specified amount of time expires. This is used for event driven resources. */
36 void DSimulatedPowerResourceController::TimerIsrFunc(TAny *ptr)
38 DSimulatedPowerResourceController *pC = (DSimulatedPowerResourceController *)ptr;
39 //Queues a Dfc to signal fast semaphore.
43 /** DFC function to signal the fast semaphore. For event driven resources, the PIL is blocked until specified time (just
44 to simulate hardware event). */
45 void DSimulatedPowerResourceController::EventDfcFunc(TAny *ptr)
47 DSimulatedPowerResourceController *pC = (DSimulatedPowerResourceController *)ptr;
48 NKern::FSSignal((NFastSemaphore*)&pC->iEventFastSem);
51 /** Constructor for simulated resource controller. */
52 DSimulatedPowerResourceController::DSimulatedPowerResourceController():DPowerResourceController(),iStaticResourceCount(0), iEventDfc(EventDfcFunc, this)
54 Kern::Printf(">DSimulatedPowerResourceController");
57 /** Destructor for simulated resource controller. */
58 DSimulatedPowerResourceController::~DSimulatedPowerResourceController()
60 Kern::Printf("DSimulatedPowerResourceController::~DSimulatedPowerResourceController()\n");
61 ((TDynamicDfcQue*)iDfcQ)->Destroy();
62 DStaticPowerResource *pR;
64 for(c = 0; c < iStaticResourceCount; c++)
70 #ifdef PRM_ENABLE_EXTENDED_VERSION
71 DStaticPowerResourceD* pDR;
73 delete []iNodeArray; //Delete dependency nodes
74 for(c = 0; c < iStaticResDependencyCount; c++)
76 pDR = iDependencyResources[c];
79 delete []iDependencyResources;
83 #ifdef PRM_ENABLE_EXTENDED_VERSION
84 //Function to return the controller pointer to use in extended psl file
85 DSimulatedPowerResourceController* GetControllerPtr()
87 return &TheController;
91 /** This function is called from PIL, during resource controller creation phase.
92 It creates a DFC queue and then invokes setDfcQ function to PIL to set the queue.
93 It calls InitPools function of PIL to create the specified sizes of clients,
94 client levels and requests pools.
96 TInt DSimulatedPowerResourceController::DoInitController()
99 Kern::Printf(">DSimulatedPowerResourceController::DoInitController()");
101 r = Kern::DynamicDfcQCreate((TDynamicDfcQue*&)iDfcQ, KSimulatedRCThreadPriority, KResmanName);
104 Kern::Printf("DFC Queue creation failed");
108 #ifdef CPU_AFFINITY_ANY
109 NKern::ThreadSetCpuAffinity((NThread*)(iDfcQ->iThread), KCpuAffinityAny);
112 //Call the resource controller to set the DFCQ
115 #ifdef PRM_ENABLE_EXTENDED_VERSION
116 //Create a DFC Dependency Queue
117 r = Kern::DynamicDfcQCreate((TDynamicDfcQue*&)iDfcQDependency, KSimulatedRCThreadPriority,
121 Kern::Printf("DFC Dependency Queue creation failed");
124 //Call the resource controller to set the DFCQDependency
125 SetDfcQDependency(iDfcQDependency);
128 r = InitPools(KERNEL_CLIENTS, USER_CLIENTS, CLIENT_LEVELS, REQUESTS);
132 /** This function is used only for testing purpose to test the RegisterResorcesForIdle API
133 ideally will be used by Power controller to obtain the state of the resources will be interested
134 for idle power management.
136 EXPORT_C TInt DSimulatedPowerResourceController::CaptureIdleResourcesInfo(TUint aControllerId, TUint aNumResources, TPtr* aPtr)
138 Kern::Printf("DSimulatedPowerResourceController::CaptureIdleResourcesInfo\n");
139 TInt r = TheController.RegisterResourcesForIdle(aControllerId, aNumResources, aPtr);
143 /** This function is used only for testing purpose. This is complete the initialization of resource controller.
144 This is used to test the Postbootlevel and registration of static resource API's.
146 EXPORT_C TInt DSimulatedPowerResourceController::CompleteResourceControllerInitialisation()
148 Kern::Printf("DSimulatedPowerResourceController::CompleteResourceControllerInitialisation()\n");
149 return(TheController.InitResources());
152 /** This function changes the state of the resource to appropriate value */
153 TInt DSimulatedPowerResourceController::ChangeResource(TPowerRequest& req, TInt& aCurrentLevel, TInt aMaxLevel, TInt aMinLevel)
155 DStaticPowerResource* pR = req.Resource();
156 if(pR->Sense() == DStaticPowerResource::ECustom) //Custom sense set it to specified level
158 req.Level() = aCurrentLevel;
160 else if(pR->Sense() == DStaticPowerResource::EPositive)
162 //Set it to value specified if valid, otherwise minimum or maximum based on the value.
163 if(req.Level() > aMaxLevel)
164 req.Level() = aMaxLevel;
165 else if(req.Level() < aMinLevel)
166 req.Level() = aMinLevel;
167 aCurrentLevel = req.Level();
171 //Set it to value specified if valid, otherwise minimum or maximum based on the value.
172 if( req.Level() < aMaxLevel)
173 req.Level() = aMaxLevel;
174 else if(req.Level() > aMinLevel)
175 req.Level() = aMinLevel;
176 aCurrentLevel = req.Level();
181 /** This function processes all instantaneous resource types. Instantaneous resources should returned immediately, so
182 this function returns immediately after updating the value. */
183 TInt DSimulatedPowerResourceController::ProcessInstantaneousResources(TPowerRequest& req, TInt& aCurrentLevel, TInt aMaxLevel, TInt aMinLevel, TInt aDefaultLevel)
185 if(req.ReqType() == TPowerRequest::EGet)
187 req.Level() = aCurrentLevel;
189 else if(req.ReqType() == TPowerRequest::EChange)
191 return ChangeResource(req, aCurrentLevel, aMaxLevel, aMinLevel);
193 else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
195 req.Level() = aDefaultLevel;
196 aCurrentLevel = aDefaultLevel;
199 return KErrNotSupported;
203 /** Function used for polling resources. */
204 TBool PollingFunction(TAny* ptr)
206 static TInt count = 0;
207 if(++count == (TInt)ptr)
215 /** This function processes polled resources. It waits for specified time and then performs requested operation
216 if the specified operation is long latency operation.
218 TInt DSimulatedPowerResourceController::ProcessPolledResources(TPowerRequest& req, TInt&aCurrentLevel, TInt aMaxLevel, TInt aMinLevel, TInt aDefaultLevel, TInt aBlockTime)
220 DStaticPowerResource* pR = req.Resource();
221 if(req.ReqType() == TPowerRequest::EGet)
223 if(!pR->LatencyGet())
224 return ProcessInstantaneousResources(req, aCurrentLevel, aMaxLevel, aMinLevel, aDefaultLevel);
225 Kern::PollingWait(PollingFunction, (TAny*)aBlockTime, 3, aBlockTime);
226 req.Level() = aCurrentLevel;
228 else if(req.ReqType() == TPowerRequest::EChange)
230 if(!pR->LatencySet())
231 return ProcessInstantaneousResources(req, aCurrentLevel, aMaxLevel, aMinLevel, aDefaultLevel);
232 Kern::PollingWait(PollingFunction, (TAny*)aBlockTime, 3, aBlockTime);
233 return ChangeResource(req, aCurrentLevel, aMaxLevel, aMinLevel);
235 else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
237 if(!pR->LatencySet())
238 return ProcessInstantaneousResources(req, aCurrentLevel, aMaxLevel, aMinLevel, aDefaultLevel);
239 Kern::PollingWait(PollingFunction, (TAny*)aBlockTime, 3, aBlockTime);
240 req.Level() = aDefaultLevel;
241 aCurrentLevel = aDefaultLevel;
244 return KErrNotSupported;
248 /** This function processes event driven resources. It makes the calling function (PIL) to block on fast semaphore
249 and starts the timer.The PIL is blocked until the timer expires.
251 TInt DSimulatedPowerResourceController::ProcessEventResources(TPowerRequest& req, TInt& aCurrentLevel, TInt aMaxLevel, TInt aMinLevel, TInt aDefaultLevel, TInt aBlockTime)
253 DStaticPowerResource* pR = req.Resource();
254 if(((req.ReqType() == TPowerRequest::EGet) && (!pR->LatencyGet())) || ((req.ReqType() == TPowerRequest::EChange) && (!pR->LatencySet())) || ((req.ReqType() == TPowerRequest::ESetDefaultLevel) && (!pR->LatencySet())))
255 return ProcessInstantaneousResources(req, aCurrentLevel, aMaxLevel, aMinLevel, aDefaultLevel);
256 iEventFastSem.iOwningThread = (NThreadBase*)NKern::CurrentThread();
257 iEventFastSem.iCount = 0;
258 TInt timeout = NKern::TimerTicks(aBlockTime);
259 NTimer iEventTimer(TimerIsrFunc, this);
260 iEventTimer.OneShot(timeout);
261 NKern::FSWait(&iEventFastSem);
262 if(req.ReqType() == TPowerRequest::EGet)
263 req.Level() = aCurrentLevel;
264 else if(req.ReqType() == TPowerRequest::EChange)
265 return ChangeResource(req, aCurrentLevel, aMaxLevel, aMinLevel);
266 else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
268 req.Level() = aDefaultLevel;
269 aCurrentLevel = aDefaultLevel;
272 return KErrNotSupported;
276 //This registers all static resource with resource controller. This function is called by PIL
277 TInt DSimulatedPowerResourceController::DoRegisterStaticResources(DStaticPowerResource**& aStaticResourceArray, TUint16& aStaticResourceCount)
279 Kern::Printf(">DSimulatedPowerResourceController::DoRegisterStaticResources");
280 aStaticResourceArray = (DStaticPowerResource**)new(DStaticPowerResource*[MAX_RESOURCE_COUNT]);
281 if(!aStaticResourceArray)
283 DStaticPowerResource* pR = NULL;
285 //Create Binary Single Instantaneous Positive Resource
286 pR = new DBSIGISPResource();
288 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
289 aStaticResourceArray[iStaticResourceCount++] = pR;
291 //Create Multilevel Single Instantaneous Positive Resource
292 pR = new DMLSIGISPResource();
294 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
295 aStaticResourceArray[iStaticResourceCount++] = pR;
297 //Create Binary Single Instantaneous Negative Resource
298 pR = new DBSIGISNResource();
300 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
301 aStaticResourceArray[iStaticResourceCount++] = pR;
303 //Create Multilevel Single Instantaneous Negative Resource
304 pR = new DMLSIGISNResource();
306 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
307 aStaticResourceArray[iStaticResourceCount++] = pR;
309 //Create Binary Single Longlatency Positive Resource
310 pR = new DBSLGLSPResource();
312 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
313 aStaticResourceArray[iStaticResourceCount++] = pR;
315 //Create Multilevel Single Longlatency Positive Resource
316 pR = new DMLSLGLSPResource();
318 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
319 aStaticResourceArray[iStaticResourceCount++] = pR;
321 //Create Binary Single Longlatency Get & Instantaneous Set Negative Resource
322 pR = new DBSLGISNResource();
324 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
325 aStaticResourceArray[iStaticResourceCount++] = pR;
327 //Create Multilevel Single Longlatency Get & Instantaneous Set Negative Resource
328 pR = new DMLSLGISNResource();
330 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
331 aStaticResourceArray[iStaticResourceCount++] = pR;
333 //Create Binary Single Instantaneous Get & Longlatency Set Positive Resource
334 pR = new DBSIGLSPResource();
336 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
337 aStaticResourceArray[iStaticResourceCount++] = pR;
339 //Create Multilevel Single Instantaneous Get & Longlatency Set Positive Resource
340 pR = new DMLSIGLSPResource();
342 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
343 aStaticResourceArray[iStaticResourceCount++] = pR;
345 //Create Binary SHared Instantaneous Positive Resource
346 pR = new DBSHIGISPResource();
348 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
349 aStaticResourceArray[iStaticResourceCount++] = pR;
351 //Create Multilevel SHared Instantaneous Positive Resource
352 pR = new DMLSHIGISPResource();
354 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
355 aStaticResourceArray[iStaticResourceCount++] = pR;
357 //Create Binary SHared Instantaneous Negative Resource
358 pR = new DBSHIGISNResource();
360 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
361 aStaticResourceArray[iStaticResourceCount++] = pR;
363 //Create Multilevel SHared Instantaneous Negative Resource
364 pR = new DMLSHIGISNResource();
366 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
367 aStaticResourceArray[iStaticResourceCount++] = pR;
369 //Create Binary SHared Longlatency Positive Resource
370 pR = new DBSHLGLSPResource();
372 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
373 aStaticResourceArray[iStaticResourceCount++] = pR;
375 //Create Multilevel SHared Longlatency Positive Resource
376 pR = new DMLSHLGLSPResource();
378 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
379 aStaticResourceArray[iStaticResourceCount++] = pR;
381 //Create Binary SHared Longlatency Get & Instantaneous Set Negative Resource
382 pR = new DBSHLGISNResource();
384 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
385 aStaticResourceArray[iStaticResourceCount++] = pR;
387 //Create Multilevel SHared Longlatency Get & Instantaneous Set Negative Resource
388 pR = new DMLSHLGISNResource();
390 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
391 aStaticResourceArray[iStaticResourceCount++] = pR;
393 //Create holes in resource array
394 aStaticResourceArray[iStaticResourceCount++] = NULL;
395 aStaticResourceArray[iStaticResourceCount++] = NULL;
396 //Create Binary SHared Instantaneous Get & Longlatency Set Positive Resource
397 pR = new DBSHIGLSPResource();
399 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
400 aStaticResourceArray[iStaticResourceCount++] = pR;
402 //Create Multilevel SHared Instantaneous Get & Longlatency Set Positive Resource
403 pR = new DMLSHIGLSPResource();
405 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
406 aStaticResourceArray[iStaticResourceCount++] = pR;
408 //Create Binary shared Longlatency get and set Custom Resource
409 pR = new DBSHLGLSCResource();
411 CLEAN_AND_RETURN(iStaticResourceCount, aStaticResourceArray, KErrNoMemory)
412 aStaticResourceArray[iStaticResourceCount++] = pR;
414 iResources = aStaticResourceArray;
416 aStaticResourceCount = iStaticResourceCount;
420 //Constructors of all resources
421 _LIT(KDBSIGISPResource, "SymbianSimulResource");
422 DBSIGISPResource::DBSIGISPResource() : DStaticPowerResource(KDBSIGISPResource, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
427 _LIT(KDMLSIGISPResource, "DMLSIGISPResource");
428 DMLSIGISPResource::DMLSIGISPResource() : DStaticPowerResource(KDMLSIGISPResource, 12), iMinLevel(10), iMaxLevel(75), iCurrentLevel(12)
430 iFlags = KMultiLevel;
433 _LIT(KDBSIGISNResource, "DBSIGISNResource");
434 DBSIGISNResource::DBSIGISNResource() : DStaticPowerResource(KDBSIGISNResource, E_ON), iMinLevel(E_ON), iMaxLevel(E_OFF), iCurrentLevel(E_ON)
436 iFlags = KBinary | KSenseNegative;
439 _LIT(KDMLSIGISNResource, "DMLSIGISNResource");
440 DMLSIGISNResource::DMLSIGISNResource() : DStaticPowerResource(KDMLSIGISNResource, 75), iMinLevel(75), iMaxLevel(10), iCurrentLevel(75)
442 iFlags = KMultiLevel | KSenseNegative;
445 _LIT(KDBSLGLSPResource, "DBSLGLSPResource");
446 // change this state to OFF
447 DBSLGLSPResource::DBSLGLSPResource() : DStaticPowerResource(KDBSLGLSPResource, E_ON), iMinLevel(E_OFF), iMaxLevel(E_ON), iCurrentLevel(E_ON), iPolled(ETrue)
449 iFlags = KLongLatencyGet | KLongLatencySet;
452 NKern::UnlockSystem();
455 _LIT(KDMLSLGLSPResource, "DMLSLGLSPResource");
456 DMLSLGLSPResource::DMLSLGLSPResource() : DStaticPowerResource(KDMLSLGLSPResource, 75), iMinLevel(10), iMaxLevel(75), iCurrentLevel(75), iPolled(EFalse)
458 iFlags = KMultiLevel | KLongLatencySet | KLongLatencyGet;
460 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
461 NKern::UnlockSystem();
464 _LIT(KDBSLGISNResource, "DBSLGISNResource");
465 DBSLGISNResource::DBSLGISNResource() : DStaticPowerResource(KDBSLGISNResource, E_ON), iMinLevel(E_ON), iMaxLevel(E_OFF), iCurrentLevel(E_ON), iPolled(ETrue)
467 iFlags = KLongLatencyGet | KSenseNegative;
469 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
470 NKern::UnlockSystem();
473 _LIT(KDMLSLGISNResource, "DMLSLGISNResource");
474 DMLSLGISNResource::DMLSLGISNResource() : DStaticPowerResource(KDMLSLGISNResource, 75), iMinLevel(75), iMaxLevel(10), iCurrentLevel(75), iPolled(EFalse)
476 iFlags = KMultiLevel | KLongLatencyGet | KSenseNegative;
478 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
479 NKern::UnlockSystem();
482 _LIT(KDBSIGLSPResource, "DBSIGLSPResource");
483 DBSIGLSPResource::DBSIGLSPResource() : DStaticPowerResource(KDBSIGLSPResource, E_ON), iMinLevel(E_OFF), iMaxLevel(E_ON), iCurrentLevel(E_ON), iPolled(ETrue)
485 iFlags = KBinary | KLongLatencySet;
487 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
488 NKern::UnlockSystem();
491 _LIT(KDMLSIGLSPResource, "DMLSIGLSPResource");
492 DMLSIGLSPResource::DMLSIGLSPResource() : DStaticPowerResource(KDMLSIGLSPResource, 75), iMinLevel(10), iMaxLevel(100), iCurrentLevel(75), iPolled(EFalse)
494 iFlags = KMultiLevel | KLongLatencySet;
496 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
497 NKern::UnlockSystem();
500 _LIT(KDBSHIGISPResource, "DBSHIGISPResource");
501 DBSHIGISPResource::DBSHIGISPResource() : DStaticPowerResource(KDBSHIGISPResource, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
503 iFlags = KBinary | KShared;
506 _LIT(KDMLSHIGISPResource, "DMLSHIGISPResource");
507 DMLSHIGISPResource::DMLSHIGISPResource() : DStaticPowerResource(KDMLSHIGISPResource, 12), iMinLevel(10), iMaxLevel(75), iCurrentLevel(12)
509 iFlags = KMultiLevel | KShared;
512 _LIT(KDBSHIGISNResource, "DBSHIGISNResource");
513 DBSHIGISNResource::DBSHIGISNResource() : DStaticPowerResource(KDBSHIGISNResource, E_ON), iMinLevel(E_ON), iMaxLevel(E_OFF), iCurrentLevel(E_ON)
515 iFlags = KBinary | KShared | KSenseNegative;
518 _LIT(KDMLSHIGISNResource, "DMLSHIGISNResource");
519 DMLSHIGISNResource::DMLSHIGISNResource() : DStaticPowerResource(KDMLSHIGISNResource, 75), iMinLevel(75), iMaxLevel(10), iCurrentLevel(75)
521 iFlags = KMultiLevel | KShared | KSenseNegative;
524 _LIT(KDBSHLGLSPResource, "DBSHLGLSPResource");
525 DBSHLGLSPResource::DBSHLGLSPResource() : DStaticPowerResource(KDBSHLGLSPResource, E_ON), iMinLevel(E_OFF), iMaxLevel(E_ON), iCurrentLevel(E_ON), iPolled(ETrue)
527 iFlags = KBinary | KShared | KLongLatencySet | KLongLatencyGet;
529 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
530 NKern::UnlockSystem();
533 _LIT(KDMLSHLGLSPResource, "DMLSHLGLSPResource");
534 DMLSHLGLSPResource::DMLSHLGLSPResource() : DStaticPowerResource(KDMLSHLGLSPResource, 70), iMinLevel(5), iMaxLevel(70), iCurrentLevel(70), iPolled(EFalse)
536 iFlags = KMultiLevel | KShared | KLongLatencySet | KLongLatencyGet;
538 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
539 NKern::UnlockSystem();
542 _LIT(KDBSHLGISNResource, "DBSHLGISNResource");
543 DBSHLGISNResource::DBSHLGISNResource() : DStaticPowerResource(KDBSHLGISNResource, E_ON), iMinLevel(E_ON), iMaxLevel(E_OFF), iCurrentLevel(E_ON), iPolled(ETrue)
545 iFlags = KBinary | KShared | KLongLatencyGet | KSenseNegative;
547 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
548 NKern::UnlockSystem();
551 _LIT(KDMLSHLGISNResource, "DMLSHLGISNResource");
552 DMLSHLGISNResource::DMLSHLGISNResource() : DStaticPowerResource(KDMLSHLGISNResource, 75), iMinLevel(75), iMaxLevel(10), iCurrentLevel(75), iPolled(EFalse)
554 iFlags = KMultiLevel | KShared | KLongLatencySet | KSenseNegative;
556 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
557 NKern::UnlockSystem();
560 _LIT(KDBSHIGLSPResource, "DBSHIGLSPResource");
561 DBSHIGLSPResource::DBSHIGLSPResource() : DStaticPowerResource(KDBSHIGLSPResource, E_ON), iMinLevel(E_OFF), iMaxLevel(E_ON), iCurrentLevel(E_ON), iPolled(ETrue)
563 iFlags = KBinary | KShared | KLongLatencySet;
565 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
566 NKern::UnlockSystem();
569 _LIT(KDMLSHIGLSPResource, "DMLSHIGLSPResource");
570 DMLSHIGLSPResource::DMLSHIGLSPResource() : DStaticPowerResource(KDMLSHIGLSPResource, 75), iMinLevel(10), iMaxLevel(75), iCurrentLevel(75), iPolled(EFalse)
572 iFlags = KMultiLevel | KShared | KLongLatencySet;
574 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
575 NKern::UnlockSystem();
578 _LIT(KDBSHLGLSCResource, "KDBSHLGLSCResource");
579 DBSHLGLSCResource::DBSHLGLSCResource() : DStaticPowerResource(KDBSHLGLSCResource, E_ON), iMinLevel(E_OFF), iMaxLevel(E_ON), iCurrentLevel(E_ON), iPolled(EFalse)
581 iFlags = KMultiLevel | KShared | KLongLatencySet | KSenseCustom;
582 SetCustomFunction(CustomFunction);
584 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
585 NKern::UnlockSystem();
588 //DoRequest implementation of all functions
589 TInt DBSIGISPResource::DoRequest(TPowerRequest& req)
591 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
594 TInt DMLSIGISPResource::DoRequest(TPowerRequest& req)
596 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
599 TInt DBSIGISNResource::DoRequest(TPowerRequest& req)
601 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
604 TInt DMLSIGISNResource::DoRequest(TPowerRequest& req)
606 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
609 TInt DBSLGLSPResource::DoRequest(TPowerRequest& req)
611 return TheController.ProcessPolledResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
614 TInt DMLSLGLSPResource::DoRequest(TPowerRequest& req)
616 return TheController.ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
619 TInt DBSLGISNResource::DoRequest(TPowerRequest& req)
621 return TheController.ProcessPolledResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
624 TInt DMLSLGISNResource::DoRequest(TPowerRequest& req)
626 return TheController.ProcessPolledResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
629 TInt DBSIGLSPResource::DoRequest(TPowerRequest& req)
631 return TheController.ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
634 TInt DMLSIGLSPResource::DoRequest(TPowerRequest& req)
636 return TheController.ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
639 TInt DBSHIGISPResource::DoRequest(TPowerRequest& req)
641 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
644 TInt DMLSHIGISPResource::DoRequest(TPowerRequest& req)
646 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
649 TInt DBSHIGISNResource::DoRequest(TPowerRequest& req)
651 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
654 TInt DMLSHIGISNResource::DoRequest(TPowerRequest& req)
656 return TheController.ProcessInstantaneousResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel);
659 TInt DBSHLGLSPResource::DoRequest(TPowerRequest& req)
661 return TheController.ProcessPolledResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
664 TInt DMLSHLGLSPResource::DoRequest(TPowerRequest& req)
666 return TheController.ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
669 TInt DBSHLGISNResource::DoRequest(TPowerRequest& req)
671 return TheController.ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
674 TInt DMLSHLGISNResource::DoRequest(TPowerRequest& req)
676 return TheController.ProcessPolledResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
679 TInt DBSHIGLSPResource::DoRequest(TPowerRequest& req)
681 return TheController.ProcessPolledResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
684 TInt DMLSHIGLSPResource::DoRequest(TPowerRequest& req)
686 return TheController.ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
689 TInt DBSHLGLSCResource::DoRequest(TPowerRequest& req)
691 return TheController.ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
694 /** Custom function implemetation*/
695 TBool DBSHLGLSCResource::CustomFunction(TInt &aClientId, const TDesC8& aClientName,
696 TUint /*aResourceId*/,
697 TCustomOperation aCustomOperation, TInt &aLevel,
698 TAny* aLevelList, TAny* /*aReserved*/)
700 static TInt ClientId = -1;
702 Kern::Printf("CustomFunction Passed Clientname = %S\n", &aClientName);
704 //Allow first client to change the resource state
705 if(aCustomOperation == EClientRequestLevel && ClientId == -1)
707 ClientId = aClientId;
711 //If client deregisters then ask to set the value to next client level if present, else to default level.
712 if(aCustomOperation == EClientRelinquishLevel)
715 SPowerResourceClientLevel* pL = NULL;
716 SDblQue* pS = (SDblQue*)aLevelList;
717 for(SDblQueLink* pCL=pS->First();pCL!=&pS->iA;pCL=pCL->iNext)
720 pL=(SPowerResourceClientLevel*)pCL;
721 if((pL->iClientId != (TUint)aClientId))
723 aClientId = pL->iClientId;
725 ClientId = aClientId;
729 if((pL == NULL) || (count == 1))
733 ClientId = aClientId;
738 /*Allow if the current client is asking to state change to E_ON.
739 Also change is allowed if current client asks for E_OFF and no other
740 client is holding requirement for E_ON
742 if(aClientId == ClientId)
746 SPowerResourceClientLevel* pL = NULL;
747 SDblQue* pS = (SDblQue*)aLevelList;
748 for(SDblQueLink* pCL=pS->First();pCL!=&pS->iA;pCL=pCL->iNext)
750 pL=(SPowerResourceClientLevel*)pCL;
751 if(pL->iLevel == E_ON)
753 aClientId = pL->iClientId;
754 ClientId = pL->iClientId;
764 //Get info implementation of all resources.
765 TInt DBSIGISPResource::GetInfo(TDes8* info) const
767 DStaticPowerResource::GetInfo((TDes8*)info);
768 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
769 buf1->iMinLevel = iMinLevel;
770 buf1->iMaxLevel = iMaxLevel;
774 TInt DMLSIGISPResource::GetInfo(TDes8* info) const
776 DStaticPowerResource::GetInfo((TDes8*)info);
777 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
778 buf1->iMinLevel = iMinLevel;
779 buf1->iMaxLevel = iMaxLevel;
783 TInt DBSIGISNResource::GetInfo(TDes8* info) const
785 DStaticPowerResource::GetInfo((TDes8*)info);
786 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
787 buf1->iMinLevel = iMinLevel;
788 buf1->iMaxLevel = iMaxLevel;
792 TInt DMLSIGISNResource::GetInfo(TDes8* info) const
794 DStaticPowerResource::GetInfo((TDes8*)info);
795 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
796 buf1->iMinLevel = iMinLevel;
797 buf1->iMaxLevel = iMaxLevel;
801 TInt DBSLGLSPResource::GetInfo(TDes8* info) const
803 DStaticPowerResource::GetInfo((TDes8*)info);
804 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
805 buf1->iMinLevel = iMinLevel;
806 buf1->iMaxLevel = iMaxLevel;
810 TInt DMLSLGLSPResource::GetInfo(TDes8* info) const
812 DStaticPowerResource::GetInfo((TDes8*)info);
813 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
814 buf1->iMinLevel = iMinLevel;
815 buf1->iMaxLevel = iMaxLevel;
819 TInt DBSLGISNResource::GetInfo(TDes8* info) const
821 DStaticPowerResource::GetInfo((TDes8*)info);
822 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
823 buf1->iMinLevel = iMinLevel;
824 buf1->iMaxLevel = iMaxLevel;
828 TInt DMLSLGISNResource::GetInfo(TDes8* info) const
830 DStaticPowerResource::GetInfo((TDes8*)info);
831 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
832 buf1->iMinLevel = iMinLevel;
833 buf1->iMaxLevel = iMaxLevel;
837 TInt DBSIGLSPResource::GetInfo(TDes8* info) const
839 DStaticPowerResource::GetInfo((TDes8*)info);
840 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
841 buf1->iMinLevel = iMinLevel;
842 buf1->iMaxLevel = iMaxLevel;
846 TInt DMLSIGLSPResource::GetInfo(TDes8* info) const
848 DStaticPowerResource::GetInfo((TDes8*)info);
849 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
850 buf1->iMinLevel = iMinLevel;
851 buf1->iMaxLevel = iMaxLevel;
855 TInt DBSHIGISPResource::GetInfo(TDes8* info) const
857 DStaticPowerResource::GetInfo((TDes8*)info);
858 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
859 buf1->iMinLevel = iMinLevel;
860 buf1->iMaxLevel = iMaxLevel;
864 TInt DMLSHIGISPResource::GetInfo(TDes8* info) const
866 DStaticPowerResource::GetInfo((TDes8*)info);
867 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
868 buf1->iMinLevel = iMinLevel;
869 buf1->iMaxLevel = iMaxLevel;
873 TInt DBSHIGISNResource::GetInfo(TDes8* info) const
875 DStaticPowerResource::GetInfo((TDes8*)info);
876 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
877 buf1->iMinLevel = iMinLevel;
878 buf1->iMaxLevel = iMaxLevel;
882 TInt DMLSHIGISNResource::GetInfo(TDes8* info) const
884 DStaticPowerResource::GetInfo((TDes8*)info);
885 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
886 buf1->iMinLevel = iMinLevel;
887 buf1->iMaxLevel = iMaxLevel;
891 TInt DBSHLGLSPResource::GetInfo(TDes8* info) const
893 DStaticPowerResource::GetInfo((TDes8*)info);
894 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
895 buf1->iMinLevel = iMinLevel;
896 buf1->iMaxLevel = iMaxLevel;
900 TInt DMLSHLGLSPResource::GetInfo(TDes8* info) const
902 DStaticPowerResource::GetInfo((TDes8*)info);
903 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
904 buf1->iMinLevel = iMinLevel;
905 buf1->iMaxLevel = iMaxLevel;
909 TInt DBSHLGISNResource::GetInfo(TDes8* info) const
911 DStaticPowerResource::GetInfo((TDes8*)info);
912 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
913 buf1->iMinLevel = iMinLevel;
914 buf1->iMaxLevel = iMaxLevel;
918 TInt DMLSHLGISNResource::GetInfo(TDes8* info) const
920 DStaticPowerResource::GetInfo((TDes8*)info);
921 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
922 buf1->iMinLevel = iMinLevel;
923 buf1->iMaxLevel = iMaxLevel;
927 TInt DBSHIGLSPResource::GetInfo(TDes8* info) const
929 DStaticPowerResource::GetInfo((TDes8*)info);
930 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
931 buf1->iMinLevel = iMinLevel;
932 buf1->iMaxLevel = iMaxLevel;
936 TInt DMLSHIGLSPResource::GetInfo(TDes8* info) const
938 DStaticPowerResource::GetInfo((TDes8*)info);
939 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
940 buf1->iMinLevel = iMinLevel;
941 buf1->iMaxLevel = iMaxLevel;
945 TInt DBSHLGLSCResource::GetInfo(TDes8* info) const
947 DStaticPowerResource::GetInfo((TDes8*)info);
948 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
949 buf1->iMinLevel = iMinLevel;
950 buf1->iMaxLevel = iMaxLevel;