os/kernelhwsrv/kerneltest/e32test/resourceman/resourceman_psl/rescontrol_extended_psl.cpp
Update contrib.
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_extended_psl.cpp
18 #include "rescontrol_psl.h"
19 #include "rescontrol_extended_psl.h"
22 This function creates all static resources which support dependencies and establishes
23 the dependencies between them. This is called by PIL.
24 Following is the dependency tree input
25 ResourceA <----------------> ResourceD <------------->ResourceE <--------------> ResourceC
34 TInt DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency(DStaticPowerResourceD**& aStaticResourceDArray, TUint16& aStaticResourceDCount)
36 Kern::Printf(">DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency");
37 aStaticResourceDArray = (DStaticPowerResourceD**)new(DStaticPowerResourceD*[MAX_DEPENDENT_RESOURCE_COUNT]);
38 if(!aStaticResourceDArray)
40 DStaticPowerResourceD* pR = NULL;
41 pR = new DMLSLGLSPDependResource();
43 CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
44 aStaticResourceDArray[iStaticResDependencyCount++] = pR;
46 pR = new DMLSIGLSNDependResource();
48 CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
49 aStaticResourceDArray[iStaticResDependencyCount++] = pR;
51 pR = new DBSIGLSPDependResource();
53 CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
54 aStaticResourceDArray[iStaticResDependencyCount++] = pR;
56 pR = new DMLSHIGLSPDependResource();
58 CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
59 aStaticResourceDArray[iStaticResDependencyCount++] = pR;
61 pR = new DBSHLGLSNDependResource();
63 CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
64 aStaticResourceDArray[iStaticResDependencyCount++] = pR;
66 pR = new DMLSHLGLSNDependResource();
68 CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
69 aStaticResourceDArray[iStaticResDependencyCount++] = pR;
71 //Establish resource dependencies
72 if(CreateResourceDependency(aStaticResourceDArray))
73 CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
75 iDependencyResources = aStaticResourceDArray;
77 aStaticResourceDCount = iStaticResDependencyCount;
82 // This function establishes above dependency between static dependent resource
83 TInt DSimulatedPowerResourceController::CreateResourceDependency(DStaticPowerResourceD** pResArray)
85 iNodeArray = new SNode[10];
92 //Create Dependency between Resource A and Resource D
93 pN1 = &iNodeArray[iNodeCount++];
94 pN2 = &iNodeArray[iNodeCount++];
95 CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[1], 1, 1)
97 //Create Dependency between Resource D and Resource F
98 //Trying to add with the same priority and check whether KErrAlreadyExists is returned.
99 pN1 = &iNodeArray[iNodeCount++];
100 pN2 = &iNodeArray[iNodeCount++];
102 pN1->iResource = pResArray[0];
103 pN1->iPropagatedLevel = 0;
104 pN1->iVisited = EFalse;
107 pN2->iResource = pResArray[2];
108 pN2->iPropagatedLevel = 0;
109 pN2->iVisited = EFalse;
110 pN2->iResource->AddNode(pN1);
112 TInt r = pN1->iResource->AddNode(pN2);
113 if(r != KErrAlreadyExists)
114 Kern::Fault("Power Resource Controller", __LINE__);
117 r = pN1->iResource->AddNode(pN2);
119 Kern::Fault("Power Resource Controller", __LINE__);
121 //Create Dependency between Resource D and Resource E
122 pN1 = &iNodeArray[iNodeCount++];
123 pN2 = &iNodeArray[iNodeCount++];
124 CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[3], 3, 2)
126 //Create Dependency between Resource E and Resource C
127 pN1 = &iNodeArray[iNodeCount++];
128 pN2 = &iNodeArray[iNodeCount++];
129 CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[4], 1, 1)
131 //Create Dependency between Resource E and Resource G
132 pN1 = &iNodeArray[iNodeCount++];
133 pN2 = &iNodeArray[iNodeCount++];
134 CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[5], 1, 2)
139 //Constructors of all resources
140 _LIT(KDMLSLGLSPDependResource, "StaticDependResourceD");
141 DMLSLGLSPDependResource::DMLSLGLSPDependResource() : DStaticPowerResourceD(KDMLSLGLSPDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
143 iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet;
145 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
146 NKern::UnlockSystem();
149 _LIT(KDMLSIGLSNDependResource, "StaticDependResourceA");
150 DMLSIGLSNDependResource::DMLSIGLSNDependResource() : DStaticPowerResourceD(KDMLSIGLSNDependResource, -10), iMinLevel(-10), iMaxLevel(-20), iCurrentLevel(-10)
152 iFlags = KMultiLevel | KLongLatencySet | KSenseNegative;
154 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
155 NKern::UnlockSystem();
158 _LIT(KDBSIGLSPDependResource, "StaticDependResourceF");
159 DBSIGLSPDependResource::DBSIGLSPDependResource() : DStaticPowerResourceD(KDBSIGLSPDependResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
161 iFlags = KBinary | KLongLatencySet;
163 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
164 NKern::UnlockSystem();
167 _LIT(KDMLSHIGLSPDependResource, "StaticDependResourceE");
168 DMLSHIGLSPDependResource::DMLSHIGLSPDependResource() : DStaticPowerResourceD(KDMLSHIGLSPDependResource, 10), iMinLevel(10), iMaxLevel(75), iCurrentLevel(10)
170 // Make it a Instantaneous Resource.
171 iFlags = KMultiLevel | KShared;
173 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
174 NKern::UnlockSystem();
177 _LIT(KDBSHLGLSNDependResource, "StaticDependResourceC");
178 DBSHLGLSNDependResource::DBSHLGLSNDependResource() : DStaticPowerResourceD(KDBSHLGLSNDependResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1)
180 iFlags = KBinary | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
182 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
183 NKern::UnlockSystem();
186 _LIT(KDMLSHLGLSNDependResource, "StaticDependResourceG");
187 DMLSHLGLSNDependResource::DMLSHLGLSNDependResource() : DStaticPowerResourceD(KDMLSHLGLSNDependResource, 75), iMinLevel(75), iMaxLevel(30), iCurrentLevel(75)
189 iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
191 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
192 NKern::UnlockSystem();
195 _LIT(KDMLSHLGLSCDependResource, "DMLSHLGLSCDependResource");
196 DMLSHLGLSCDependResource::DMLSHLGLSCDependResource() : DStaticPowerResourceD(KDMLSHLGLSCDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
198 iFlags = KMultiLevel;
200 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
201 NKern::UnlockSystem();
204 //Implementation of handle dependent state for all resources
205 TChangePropagationStatus DMLSLGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt /*aDepState*/, TInt& /*aResState*/)
207 //This resources changes only when the client asks to change
211 TChangePropagationStatus DMLSIGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
213 if(aDepState == -100)
215 aResState = iMinLevel;
220 aResState = iCurrentLevel > -15 ? iCurrentLevel-1 : -15;
221 if(aResState == iCurrentLevel)
225 aResState = iCurrentLevel > iMaxLevel ? iCurrentLevel-1 : iMaxLevel;
226 if(aResState == iCurrentLevel)
231 TChangePropagationStatus DBSIGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
233 if(aDepState == -100)
235 aResState = iMinLevel;
238 if(iCurrentLevel == E_ON)
240 aResState = iMaxLevel;
244 TChangePropagationStatus DMLSHIGLSPDependResource::TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState)
246 if((aDepId & ID_INDEX_BIT_MASK) != 0x1)
248 if(aDepState == -100)
250 aResState = iMinLevel;
253 aResState = iCurrentLevel + 3;
254 if(aResState == iMaxLevel)
259 TChangePropagationStatus DBSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
263 aResState = iMinLevel;
266 if(iCurrentLevel == iMaxLevel)
268 aResState = iMaxLevel;
272 TChangePropagationStatus DMLSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
276 aResState = iMinLevel;
279 aResState = iCurrentLevel - 2;
280 if(aResState == iMaxLevel)
285 TChangePropagationStatus DMLSHLGLSCDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
287 if((aDepState == 10) && (iCurrentLevel == -100))
295 aResState = iCurrentLevel + 20;
297 aResState = iCurrentLevel -20;
298 if(aResState > iMaxLevel)
299 aResState = iMaxLevel;
304 //Implementation of DoRequest functionality for all resource
305 TInt DMLSLGLSPDependResource::DoRequest(TPowerRequest& req)
307 return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
310 TInt DMLSIGLSNDependResource::DoRequest(TPowerRequest& req)
312 return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
315 TInt DBSIGLSPDependResource::DoRequest(TPowerRequest& req)
317 return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
320 TInt DMLSHIGLSPDependResource::DoRequest(TPowerRequest& req)
322 return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
325 TInt DBSHLGLSNDependResource::DoRequest(TPowerRequest& req)
327 return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
330 TInt DMLSHLGLSNDependResource::DoRequest(TPowerRequest& req)
332 return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
335 TInt DMLSHLGLSCDependResource::DoRequest(TPowerRequest& req)
337 return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
340 //Get info implementation of all resources.
341 TInt DMLSLGLSPDependResource::GetInfo(TDes8* info) const
343 DStaticPowerResource::GetInfo((TDes8*)info);
344 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
345 buf1->iMinLevel = iMinLevel;
346 buf1->iMaxLevel = iMaxLevel;
350 TInt DMLSIGLSNDependResource::GetInfo(TDes8* info) const
352 DStaticPowerResource::GetInfo((TDes8*)info);
353 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
354 buf1->iMinLevel = iMinLevel;
355 buf1->iMaxLevel = iMaxLevel;
359 TInt DBSIGLSPDependResource::GetInfo(TDes8* info) const
361 DStaticPowerResource::GetInfo((TDes8*)info);
362 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
363 buf1->iMinLevel = iMinLevel;
364 buf1->iMaxLevel = iMaxLevel;
368 TInt DMLSHIGLSPDependResource::GetInfo(TDes8* info) const
370 DStaticPowerResource::GetInfo((TDes8*)info);
371 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
372 buf1->iMinLevel = iMinLevel;
373 buf1->iMaxLevel = iMaxLevel;
377 TInt DBSHLGLSNDependResource::GetInfo(TDes8* info) const
379 DStaticPowerResource::GetInfo((TDes8*)info);
380 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
381 buf1->iMinLevel = iMinLevel;
382 buf1->iMaxLevel = iMaxLevel;
386 TInt DMLSHLGLSNDependResource::GetInfo(TDes8* info) const
388 DStaticPowerResource::GetInfo((TDes8*)info);
389 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
390 buf1->iMinLevel = iMinLevel;
391 buf1->iMaxLevel = iMaxLevel;
395 TInt DMLSHLGLSCDependResource::GetInfo(TDes8* info) const
397 DStaticPowerResource::GetInfo((TDes8*)info);
398 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
399 buf1->iMinLevel = iMinLevel;
400 buf1->iMaxLevel = iMaxLevel;