0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\resourceman\resourceman_psl\rescontrol_extended_psl.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "rescontrol_psl.h"
|
|
19 |
#include "rescontrol_extended_psl.h"
|
|
20 |
|
|
21 |
/**
|
|
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
|
|
26 |
| |
|
|
27 |
| |
|
|
28 |
| |
|
|
29 |
| |
|
|
30 |
| |
|
|
31 |
| |
|
|
32 |
ResourceF ResourceG
|
|
33 |
*/
|
244
|
34 |
|
|
35 |
TInt DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency(RPointerArray <DStaticPowerResourceD> & aStaticResourceDArray)
|
0
|
36 |
{
|
|
37 |
Kern::Printf(">DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency");
|
244
|
38 |
|
|
39 |
// this is just for testing purposes - try to call base-class implementation, which by default resets the values and returns KErrNone
|
|
40 |
TInt r = DPowerResourceController::DoRegisterStaticResourcesDependency(aStaticResourceDArray);
|
|
41 |
if(r != KErrNone || aStaticResourceDArray.Count())
|
|
42 |
{
|
|
43 |
Kern::Printf("DPowerResourceController::DoRegisterStaticResourcesDependency() default base class implementation has failed?");
|
|
44 |
return KErrGeneral;
|
|
45 |
}
|
|
46 |
|
0
|
47 |
DStaticPowerResourceD* pR = NULL;
|
244
|
48 |
TBool error_occured = EFalse;
|
|
49 |
|
0
|
50 |
pR = new DMLSLGLSPDependResource();
|
244
|
51 |
if(!SafeAppend(aStaticResourceDArray, pR))
|
|
52 |
error_occured = ETrue;
|
0
|
53 |
|
|
54 |
pR = new DMLSIGLSNDependResource();
|
244
|
55 |
if(!SafeAppend(aStaticResourceDArray, pR))
|
|
56 |
error_occured = ETrue;
|
|
57 |
|
0
|
58 |
pR = new DBSIGLSPDependResource();
|
244
|
59 |
if(!SafeAppend(aStaticResourceDArray, pR))
|
|
60 |
error_occured = ETrue;
|
|
61 |
|
0
|
62 |
pR = new DMLSHIGLSPDependResource();
|
244
|
63 |
if(!SafeAppend(aStaticResourceDArray, pR))
|
|
64 |
error_occured = ETrue;
|
0
|
65 |
|
|
66 |
pR = new DBSHLGLSNDependResource();
|
244
|
67 |
if(!SafeAppend(aStaticResourceDArray, pR))
|
|
68 |
error_occured = ETrue;
|
0
|
69 |
|
|
70 |
pR = new DMLSHLGLSNDependResource();
|
244
|
71 |
if(!SafeAppend(aStaticResourceDArray, pR))
|
|
72 |
error_occured = ETrue;
|
0
|
73 |
|
|
74 |
//Establish resource dependencies
|
244
|
75 |
r = CreateResourceDependency(aStaticResourceDArray);
|
|
76 |
if(r != KErrNone)
|
|
77 |
error_occured = ETrue;
|
0
|
78 |
|
244
|
79 |
// the only error that could occur here is KErrNoMemory (also from calling CreateResourceDependency)
|
|
80 |
// clean-up if the error did occur
|
|
81 |
if(error_occured)
|
|
82 |
{
|
|
83 |
aStaticResourceDArray.ResetAndDestroy();
|
|
84 |
r = KErrNoMemory;
|
|
85 |
}
|
0
|
86 |
|
244
|
87 |
return r;
|
0
|
88 |
}
|
|
89 |
|
|
90 |
|
|
91 |
// This function establishes above dependency between static dependent resource
|
244
|
92 |
TInt DSimulatedPowerResourceController::CreateResourceDependency(RPointerArray <DStaticPowerResourceD> & pResArray)
|
0
|
93 |
{
|
|
94 |
iNodeArray = new SNode[10];
|
|
95 |
SNode* pN1;
|
|
96 |
SNode* pN2;
|
|
97 |
iNodeCount = 0;
|
|
98 |
|
|
99 |
if(!iNodeArray)
|
|
100 |
return KErrNoMemory;
|
|
101 |
//Create Dependency between Resource A and Resource D
|
|
102 |
pN1 = &iNodeArray[iNodeCount++];
|
|
103 |
pN2 = &iNodeArray[iNodeCount++];
|
|
104 |
CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[1], 1, 1)
|
|
105 |
|
|
106 |
//Create Dependency between Resource D and Resource F
|
|
107 |
//Trying to add with the same priority and check whether KErrAlreadyExists is returned.
|
|
108 |
pN1 = &iNodeArray[iNodeCount++];
|
|
109 |
pN2 = &iNodeArray[iNodeCount++];
|
|
110 |
pN1->iPriority = 1;
|
|
111 |
pN1->iResource = pResArray[0];
|
|
112 |
pN1->iPropagatedLevel = 0;
|
|
113 |
pN1->iVisited = EFalse;
|
|
114 |
|
|
115 |
pN2->iPriority = 1;
|
|
116 |
pN2->iResource = pResArray[2];
|
|
117 |
pN2->iPropagatedLevel = 0;
|
|
118 |
pN2->iVisited = EFalse;
|
|
119 |
pN2->iResource->AddNode(pN1);
|
|
120 |
|
|
121 |
TInt r = pN1->iResource->AddNode(pN2);
|
|
122 |
if(r != KErrAlreadyExists)
|
|
123 |
Kern::Fault("Power Resource Controller", __LINE__);
|
|
124 |
|
|
125 |
pN2->iPriority = 3;
|
|
126 |
r = pN1->iResource->AddNode(pN2);
|
|
127 |
if(r != KErrNone)
|
|
128 |
Kern::Fault("Power Resource Controller", __LINE__);
|
|
129 |
|
|
130 |
//Create Dependency between Resource D and Resource E
|
|
131 |
pN1 = &iNodeArray[iNodeCount++];
|
|
132 |
pN2 = &iNodeArray[iNodeCount++];
|
|
133 |
CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[3], 3, 2)
|
|
134 |
|
|
135 |
//Create Dependency between Resource E and Resource C
|
|
136 |
pN1 = &iNodeArray[iNodeCount++];
|
|
137 |
pN2 = &iNodeArray[iNodeCount++];
|
|
138 |
CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[4], 1, 1)
|
|
139 |
|
|
140 |
//Create Dependency between Resource E and Resource G
|
|
141 |
pN1 = &iNodeArray[iNodeCount++];
|
|
142 |
pN2 = &iNodeArray[iNodeCount++];
|
|
143 |
CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[5], 1, 2)
|
|
144 |
|
|
145 |
return KErrNone;
|
|
146 |
}
|
|
147 |
|
|
148 |
//Constructors of all resources
|
|
149 |
_LIT(KDMLSLGLSPDependResource, "StaticDependResourceD");
|
|
150 |
DMLSLGLSPDependResource::DMLSLGLSPDependResource() : DStaticPowerResourceD(KDMLSLGLSPDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
|
|
151 |
{
|
|
152 |
iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet;
|
|
153 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
154 |
}
|
|
155 |
|
|
156 |
_LIT(KDMLSIGLSNDependResource, "StaticDependResourceA");
|
|
157 |
DMLSIGLSNDependResource::DMLSIGLSNDependResource() : DStaticPowerResourceD(KDMLSIGLSNDependResource, -10), iMinLevel(-10), iMaxLevel(-20), iCurrentLevel(-10)
|
|
158 |
{
|
|
159 |
iFlags = KMultiLevel | KLongLatencySet | KSenseNegative;
|
|
160 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
161 |
}
|
|
162 |
|
|
163 |
_LIT(KDBSIGLSPDependResource, "StaticDependResourceF");
|
|
164 |
DBSIGLSPDependResource::DBSIGLSPDependResource() : DStaticPowerResourceD(KDBSIGLSPDependResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
|
|
165 |
{
|
|
166 |
iFlags = KBinary | KLongLatencySet;
|
|
167 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
168 |
}
|
|
169 |
|
|
170 |
_LIT(KDMLSHIGLSPDependResource, "StaticDependResourceE");
|
|
171 |
DMLSHIGLSPDependResource::DMLSHIGLSPDependResource() : DStaticPowerResourceD(KDMLSHIGLSPDependResource, 10), iMinLevel(10), iMaxLevel(75), iCurrentLevel(10)
|
|
172 |
{
|
|
173 |
// Make it a Instantaneous Resource.
|
|
174 |
iFlags = KMultiLevel | KShared;
|
|
175 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
176 |
}
|
|
177 |
|
|
178 |
_LIT(KDBSHLGLSNDependResource, "StaticDependResourceC");
|
|
179 |
DBSHLGLSNDependResource::DBSHLGLSNDependResource() : DStaticPowerResourceD(KDBSHLGLSNDependResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1)
|
|
180 |
{
|
|
181 |
iFlags = KBinary | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
|
|
182 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
183 |
}
|
|
184 |
|
|
185 |
_LIT(KDMLSHLGLSNDependResource, "StaticDependResourceG");
|
|
186 |
DMLSHLGLSNDependResource::DMLSHLGLSNDependResource() : DStaticPowerResourceD(KDMLSHLGLSNDependResource, 75), iMinLevel(75), iMaxLevel(30), iCurrentLevel(75)
|
|
187 |
{
|
|
188 |
iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
|
|
189 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
190 |
}
|
|
191 |
|
|
192 |
_LIT(KDMLSHLGLSCDependResource, "DMLSHLGLSCDependResource");
|
|
193 |
DMLSHLGLSCDependResource::DMLSHLGLSCDependResource() : DStaticPowerResourceD(KDMLSHLGLSCDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
|
|
194 |
{
|
|
195 |
iFlags = KMultiLevel;
|
|
196 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
197 |
}
|
|
198 |
|
|
199 |
//Implementation of handle dependent state for all resources
|
|
200 |
TChangePropagationStatus DMLSLGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt /*aDepState*/, TInt& /*aResState*/)
|
|
201 |
{
|
|
202 |
//This resources changes only when the client asks to change
|
|
203 |
return ENoChange;
|
|
204 |
}
|
|
205 |
|
|
206 |
TChangePropagationStatus DMLSIGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
|
|
207 |
{
|
|
208 |
if(aDepState == -100)
|
|
209 |
{
|
|
210 |
aResState = iMinLevel;
|
|
211 |
return EChange;
|
|
212 |
}
|
|
213 |
if(aDepState < 0)
|
|
214 |
{
|
|
215 |
aResState = iCurrentLevel > -15 ? iCurrentLevel-1 : -15;
|
|
216 |
if(aResState == iCurrentLevel)
|
|
217 |
return ENoChange;
|
|
218 |
return EChange;
|
|
219 |
}
|
|
220 |
aResState = iCurrentLevel > iMaxLevel ? iCurrentLevel-1 : iMaxLevel;
|
|
221 |
if(aResState == iCurrentLevel)
|
|
222 |
return ENoChange;
|
|
223 |
return EChange;
|
|
224 |
}
|
|
225 |
|
|
226 |
TChangePropagationStatus DBSIGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
|
|
227 |
{
|
|
228 |
if(aDepState == -100)
|
|
229 |
{
|
|
230 |
aResState = iMinLevel;
|
|
231 |
return EChange;
|
|
232 |
}
|
|
233 |
if(iCurrentLevel == E_ON)
|
|
234 |
return ENoChange;
|
|
235 |
aResState = iMaxLevel;
|
|
236 |
return EChange;
|
|
237 |
}
|
|
238 |
|
|
239 |
TChangePropagationStatus DMLSHIGLSPDependResource::TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState)
|
|
240 |
{
|
|
241 |
if((aDepId & ID_INDEX_BIT_MASK) != 0x1)
|
|
242 |
return ENoChange;
|
|
243 |
if(aDepState == -100)
|
|
244 |
{
|
|
245 |
aResState = iMinLevel;
|
|
246 |
return EChange;
|
|
247 |
}
|
|
248 |
aResState = iCurrentLevel + 3;
|
|
249 |
if(aResState == iMaxLevel)
|
|
250 |
return ENoChange;
|
|
251 |
return EChange;
|
|
252 |
}
|
|
253 |
|
|
254 |
TChangePropagationStatus DBSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
|
|
255 |
{
|
|
256 |
if(aDepState == 10)
|
|
257 |
{
|
|
258 |
aResState = iMinLevel;
|
|
259 |
return EChange;
|
|
260 |
}
|
|
261 |
if(iCurrentLevel == iMaxLevel)
|
|
262 |
return ENoChange;
|
|
263 |
aResState = iMaxLevel;
|
|
264 |
return EChange;
|
|
265 |
}
|
|
266 |
|
|
267 |
TChangePropagationStatus DMLSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
|
|
268 |
{
|
|
269 |
if(aDepState == 10)
|
|
270 |
{
|
|
271 |
aResState = iMinLevel;
|
|
272 |
return EChange;
|
|
273 |
}
|
|
274 |
aResState = iCurrentLevel - 2;
|
|
275 |
if(aResState == iMaxLevel)
|
|
276 |
return ENoChange;
|
|
277 |
return EChange;
|
|
278 |
}
|
|
279 |
|
|
280 |
TChangePropagationStatus DMLSHLGLSCDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
|
|
281 |
{
|
|
282 |
if((aDepState == 10) && (iCurrentLevel == -100))
|
|
283 |
return ENoChange;
|
|
284 |
if(aDepState == 10)
|
|
285 |
{
|
|
286 |
aResState = -100;
|
|
287 |
return EChange;
|
|
288 |
}
|
|
289 |
if(iCurrentLevel)
|
|
290 |
aResState = iCurrentLevel + 20;
|
|
291 |
else
|
|
292 |
aResState = iCurrentLevel -20;
|
|
293 |
if(aResState > iMaxLevel)
|
|
294 |
aResState = iMaxLevel;
|
|
295 |
return EChange;
|
|
296 |
}
|
|
297 |
|
|
298 |
|
|
299 |
//Implementation of DoRequest functionality for all resource
|
|
300 |
TInt DMLSLGLSPDependResource::DoRequest(TPowerRequest& req)
|
|
301 |
{
|
|
302 |
return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
|
|
303 |
}
|
|
304 |
|
|
305 |
TInt DMLSIGLSNDependResource::DoRequest(TPowerRequest& req)
|
|
306 |
{
|
|
307 |
return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
|
|
308 |
}
|
|
309 |
|
|
310 |
TInt DBSIGLSPDependResource::DoRequest(TPowerRequest& req)
|
|
311 |
{
|
|
312 |
return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
|
|
313 |
}
|
|
314 |
|
|
315 |
TInt DMLSHIGLSPDependResource::DoRequest(TPowerRequest& req)
|
|
316 |
{
|
|
317 |
return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
|
|
318 |
}
|
|
319 |
|
|
320 |
TInt DBSHLGLSNDependResource::DoRequest(TPowerRequest& req)
|
|
321 |
{
|
|
322 |
return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
|
|
323 |
}
|
|
324 |
|
|
325 |
TInt DMLSHLGLSNDependResource::DoRequest(TPowerRequest& req)
|
|
326 |
{
|
|
327 |
return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
|
|
328 |
}
|
|
329 |
|
|
330 |
TInt DMLSHLGLSCDependResource::DoRequest(TPowerRequest& req)
|
|
331 |
{
|
|
332 |
return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
|
|
333 |
}
|
|
334 |
|
|
335 |
//Get info implementation of all resources.
|
|
336 |
TInt DMLSLGLSPDependResource::GetInfo(TDes8* info) const
|
|
337 |
{
|
|
338 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
339 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
340 |
buf1->iMinLevel = iMinLevel;
|
|
341 |
buf1->iMaxLevel = iMaxLevel;
|
|
342 |
return KErrNone;
|
|
343 |
}
|
|
344 |
|
|
345 |
TInt DMLSIGLSNDependResource::GetInfo(TDes8* info) const
|
|
346 |
{
|
|
347 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
348 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
349 |
buf1->iMinLevel = iMinLevel;
|
|
350 |
buf1->iMaxLevel = iMaxLevel;
|
|
351 |
return KErrNone;
|
|
352 |
}
|
|
353 |
|
|
354 |
TInt DBSIGLSPDependResource::GetInfo(TDes8* info) const
|
|
355 |
{
|
|
356 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
357 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
358 |
buf1->iMinLevel = iMinLevel;
|
|
359 |
buf1->iMaxLevel = iMaxLevel;
|
|
360 |
return KErrNone;
|
|
361 |
}
|
|
362 |
|
|
363 |
TInt DMLSHIGLSPDependResource::GetInfo(TDes8* info) const
|
|
364 |
{
|
|
365 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
366 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
367 |
buf1->iMinLevel = iMinLevel;
|
|
368 |
buf1->iMaxLevel = iMaxLevel;
|
|
369 |
return KErrNone;
|
|
370 |
}
|
|
371 |
|
|
372 |
TInt DBSHLGLSNDependResource::GetInfo(TDes8* info) const
|
|
373 |
{
|
|
374 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
375 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
376 |
buf1->iMinLevel = iMinLevel;
|
|
377 |
buf1->iMaxLevel = iMaxLevel;
|
|
378 |
return KErrNone;
|
|
379 |
}
|
|
380 |
|
|
381 |
TInt DMLSHLGLSNDependResource::GetInfo(TDes8* info) const
|
|
382 |
{
|
|
383 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
384 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
385 |
buf1->iMinLevel = iMinLevel;
|
|
386 |
buf1->iMaxLevel = iMaxLevel;
|
|
387 |
return KErrNone;
|
|
388 |
}
|
|
389 |
|
|
390 |
TInt DMLSHLGLSCDependResource::GetInfo(TDes8* info) const
|
|
391 |
{
|
|
392 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
393 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
394 |
buf1->iMinLevel = iMinLevel;
|
|
395 |
buf1->iMaxLevel = iMaxLevel;
|
|
396 |
return KErrNone;
|
|
397 |
}
|