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\dynamicresource.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <drivers/resourcecontrol.h>
|
|
19 |
#include "dynamicresource.h"
|
|
20 |
|
|
21 |
const TUint KBinary = 0x0;
|
|
22 |
const TUint KMultiLevel = 0x1;
|
|
23 |
|
|
24 |
#define MAX_BLOCK_TIME 100 //Maximum block time
|
|
25 |
#define MIN_BLOCK_TIME 30 //Guaranteed minimum block
|
|
26 |
|
|
27 |
//Constructors for dynamic resources
|
|
28 |
_LIT(KDBIGISSPDynamicResource, "DynamicResource1");
|
|
29 |
DBIGISSPDynamicResource::DBIGISSPDynamicResource() : DDynamicPowerResource(KDBIGISSPDynamicResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
|
|
30 |
{
|
|
31 |
}
|
|
32 |
|
|
33 |
_LIT(KDMLIGLSSHNDynamicResource, "DynamicResource2");
|
|
34 |
DMLIGLSSHNDynamicResource::DMLIGLSSHNDynamicResource() : DDynamicPowerResource(KDMLIGLSSHNDynamicResource, -5), iMinLevel(-5), iMaxLevel(-10), iCurrentLevel(-5)
|
|
35 |
{
|
|
36 |
iFlags = KMultiLevel | KLongLatencySet | KShared | KSenseNegative;
|
|
37 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
38 |
}
|
|
39 |
|
|
40 |
_LIT(KDBLGLSSHNDynamicResource, "DynamicResource3");
|
|
41 |
DBLGLSSHNDynamicResource::DBLGLSSHNDynamicResource() : DDynamicPowerResource(KDBLGLSSHNDynamicResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1)
|
|
42 |
{
|
|
43 |
iFlags = KBinary | KLongLatencySet | KLongLatencyGet | KShared | KSenseNegative;
|
|
44 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
45 |
}
|
|
46 |
|
|
47 |
_LIT(KDMLLGLSSHPDynamicResource, "DynamicResource4");
|
|
48 |
DMLLGLSSHPDynamicResource::DMLLGLSSHPDynamicResource() : DDynamicPowerResource(KDMLLGLSSHPDynamicResource, 10), iMinLevel(10), iMaxLevel(20), iCurrentLevel(10)
|
|
49 |
{
|
|
50 |
iFlags = KMultiLevel | KLongLatencySet | KLongLatencyGet | KShared;
|
|
51 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
52 |
}
|
|
53 |
|
|
54 |
//Constructors for dynamic dependent resources
|
|
55 |
_LIT(KDDynamicResourceD01, "DynamicDependResourceDH");
|
|
56 |
DDynamicResourceD01::DDynamicResourceD01() : DDynamicPowerResourceD(KDDynamicResourceD01, 75), iMinLevel(75), iMaxLevel(90), iCurrentLevel(75)
|
|
57 |
{
|
|
58 |
// Make it a Instantaneous Resource.
|
|
59 |
iFlags = KMultiLevel;
|
|
60 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
61 |
}
|
|
62 |
|
|
63 |
_LIT(KDDynamicResourceD02, "DynamicDependResourceDI");
|
|
64 |
DDynamicResourceD02::DDynamicResourceD02() : DDynamicPowerResourceD(KDDynamicResourceD02, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
|
|
65 |
{
|
|
66 |
iFlags = KBinary | KLongLatencySet | KLongLatencyGet | KShared;
|
|
67 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
68 |
}
|
|
69 |
|
|
70 |
_LIT(KDDynamicResourceD03, "DynamicDependResourceDJ");
|
|
71 |
DDynamicResourceD03::DDynamicResourceD03() : DDynamicPowerResourceD(KDDynamicResourceD03, 19), iMinLevel(19), iMaxLevel(9), iCurrentLevel(19)
|
|
72 |
{
|
|
73 |
iFlags = KMultiLevel | KLongLatencySet | KShared | KSenseNegative;
|
|
74 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
75 |
}
|
|
76 |
|
|
77 |
_LIT(KDDynamicResourceD04, "DynamicDependResourceDK");
|
|
78 |
DDynamicResourceD04::DDynamicResourceD04() : DDynamicPowerResourceD(KDDynamicResourceD04, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
|
|
79 |
{
|
|
80 |
iFlags = KBinary | KLongLatencySet;
|
|
81 |
iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
|
|
82 |
}
|
|
83 |
|
|
84 |
//Get info implementation for dynamic resources
|
|
85 |
TInt DBIGISSPDynamicResource::GetInfo(TDes8* info) const
|
|
86 |
{
|
|
87 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
88 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
89 |
buf1->iMinLevel = iMinLevel;
|
|
90 |
buf1->iMaxLevel = iMaxLevel;
|
|
91 |
return KErrNone;
|
|
92 |
}
|
|
93 |
|
|
94 |
TInt DMLIGLSSHNDynamicResource::GetInfo(TDes8* info) const
|
|
95 |
{
|
|
96 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
97 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
98 |
buf1->iMinLevel = iMinLevel;
|
|
99 |
buf1->iMaxLevel = iMaxLevel;
|
|
100 |
return KErrNone;
|
|
101 |
}
|
|
102 |
|
|
103 |
TInt DBLGLSSHNDynamicResource::GetInfo(TDes8* info) const
|
|
104 |
{
|
|
105 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
106 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
107 |
buf1->iMinLevel = iMinLevel;
|
|
108 |
buf1->iMaxLevel = iMaxLevel;
|
|
109 |
return KErrNone;
|
|
110 |
}
|
|
111 |
|
|
112 |
TInt DMLLGLSSHPDynamicResource::GetInfo(TDes8* info) const
|
|
113 |
{
|
|
114 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
115 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
116 |
buf1->iMinLevel = iMinLevel;
|
|
117 |
buf1->iMaxLevel = iMaxLevel;
|
|
118 |
return KErrNone;
|
|
119 |
}
|
|
120 |
|
|
121 |
//Get info implementation of dynamic dependent resources
|
|
122 |
TInt DDynamicResourceD01::GetInfo(TDes8* info) const
|
|
123 |
{
|
|
124 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
125 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
126 |
buf1->iMinLevel = iMinLevel;
|
|
127 |
buf1->iMaxLevel = iMaxLevel;
|
|
128 |
return KErrNone;
|
|
129 |
}
|
|
130 |
|
|
131 |
TInt DDynamicResourceD02::GetInfo(TDes8* info) const
|
|
132 |
{
|
|
133 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
134 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
135 |
buf1->iMinLevel = iMinLevel;
|
|
136 |
buf1->iMaxLevel = iMaxLevel;
|
|
137 |
return KErrNone;
|
|
138 |
}
|
|
139 |
|
|
140 |
TInt DDynamicResourceD03::GetInfo(TDes8* info) const
|
|
141 |
{
|
|
142 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
143 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
144 |
buf1->iMinLevel = iMinLevel;
|
|
145 |
buf1->iMaxLevel = iMaxLevel;
|
|
146 |
return KErrNone;
|
|
147 |
}
|
|
148 |
|
|
149 |
TInt DDynamicResourceD04::GetInfo(TDes8* info) const
|
|
150 |
{
|
|
151 |
DStaticPowerResource::GetInfo((TDes8*)info);
|
|
152 |
TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
|
|
153 |
buf1->iMinLevel = iMinLevel;
|
|
154 |
buf1->iMaxLevel = iMaxLevel;
|
|
155 |
return KErrNone;
|
|
156 |
}
|
|
157 |
|
|
158 |
/** Function used for polling resources. */
|
|
159 |
TBool PollingFunction(TAny* ptr)
|
|
160 |
{
|
|
161 |
static TInt count = 0;
|
|
162 |
if(++count == (TInt)ptr)
|
|
163 |
{
|
|
164 |
count = 0;
|
|
165 |
return ETrue;
|
|
166 |
}
|
|
167 |
return EFalse;
|
|
168 |
}
|
|
169 |
|
|
170 |
//Function to handle Do Request functionality of all dynamic resources
|
|
171 |
TInt RequestHandlingOfDynamicResources(TPowerRequest& req, TInt& aDefaultLevel, TInt& aCurrentLevel)
|
|
172 |
{
|
|
173 |
if(req.ReqType() == TPowerRequest::EGet)
|
|
174 |
{
|
|
175 |
req.Level() = aCurrentLevel;
|
|
176 |
}
|
|
177 |
else if(req.ReqType() == TPowerRequest::EChange)
|
|
178 |
{
|
|
179 |
aCurrentLevel = req.Level();
|
|
180 |
}
|
|
181 |
else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
|
|
182 |
{
|
|
183 |
req.Level() = aDefaultLevel;
|
|
184 |
aCurrentLevel = aDefaultLevel;
|
|
185 |
}
|
|
186 |
else
|
|
187 |
return KErrNotSupported;
|
|
188 |
return KErrNone;
|
|
189 |
}
|
|
190 |
|
|
191 |
//Do request implementation for dynamic resources
|
|
192 |
TInt DBIGISSPDynamicResource::DoRequest(TPowerRequest& req)
|
|
193 |
{
|
|
194 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
195 |
}
|
|
196 |
|
|
197 |
TInt DMLIGLSSHNDynamicResource::DoRequest(TPowerRequest& req)
|
|
198 |
{
|
|
199 |
if(req.ReqType() != TPowerRequest::EGet)
|
|
200 |
Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
|
|
201 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
202 |
}
|
|
203 |
|
|
204 |
TInt DBLGLSSHNDynamicResource::DoRequest(TPowerRequest& req)
|
|
205 |
{
|
|
206 |
Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
|
|
207 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
208 |
}
|
|
209 |
|
|
210 |
TInt DMLLGLSSHPDynamicResource::DoRequest(TPowerRequest& req)
|
|
211 |
{
|
|
212 |
Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
|
|
213 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
214 |
}
|
|
215 |
|
|
216 |
//Do request implementation for dynamic dependent resources
|
|
217 |
TInt DDynamicResourceD01::DoRequest(TPowerRequest& req)
|
|
218 |
{
|
|
219 |
if(req.ReqType() != TPowerRequest::EGet)
|
|
220 |
Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
|
|
221 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
222 |
}
|
|
223 |
|
|
224 |
TInt DDynamicResourceD02::DoRequest(TPowerRequest& req)
|
|
225 |
{
|
|
226 |
Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
|
|
227 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
228 |
}
|
|
229 |
|
|
230 |
TInt DDynamicResourceD03::DoRequest(TPowerRequest& req)
|
|
231 |
{
|
|
232 |
if(req.ReqType() != TPowerRequest::EGet)
|
|
233 |
Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
|
|
234 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
235 |
}
|
|
236 |
|
|
237 |
TInt DDynamicResourceD04::DoRequest(TPowerRequest& req)
|
|
238 |
{
|
|
239 |
if(req.ReqType() != TPowerRequest::EGet)
|
|
240 |
Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
|
|
241 |
return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
|
|
242 |
}
|
|
243 |
|
|
244 |
//PSL specific implementation of translate dependent state for dynamic dependent resources.
|
|
245 |
TChangePropagationStatus DDynamicResourceD01::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
|
|
246 |
{
|
|
247 |
if(aDepState == 75)
|
|
248 |
{
|
|
249 |
aResState = iMinLevel;
|
|
250 |
return EChange;
|
|
251 |
}
|
|
252 |
if(iCurrentLevel >= 80)
|
|
253 |
return ENoChange;
|
|
254 |
aResState = 80;
|
|
255 |
return EChange;
|
|
256 |
}
|
|
257 |
|
|
258 |
TChangePropagationStatus DDynamicResourceD02::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
|
|
259 |
{
|
|
260 |
if(aDepState == 75)
|
|
261 |
{
|
|
262 |
aResState = iMinLevel;
|
|
263 |
return EChange;
|
|
264 |
}
|
|
265 |
aResState = iMaxLevel;
|
|
266 |
return EChange;
|
|
267 |
}
|
|
268 |
|
|
269 |
TChangePropagationStatus DDynamicResourceD03::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
|
|
270 |
{
|
|
271 |
if(aDepState == 75)
|
|
272 |
{
|
|
273 |
aResState = iMinLevel;
|
|
274 |
return EChange;
|
|
275 |
}
|
|
276 |
aResState = iCurrentLevel - 1;
|
|
277 |
if(aResState == iMaxLevel)
|
|
278 |
aResState = iMaxLevel;
|
|
279 |
return EChange;
|
|
280 |
}
|
|
281 |
|
|
282 |
TChangePropagationStatus DDynamicResourceD04::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
|
|
283 |
{
|
|
284 |
if(aDepState == 19)
|
|
285 |
{
|
|
286 |
aResState = iMinLevel;
|
|
287 |
return EChange;
|
|
288 |
}
|
|
289 |
aResState = iMaxLevel;
|
|
290 |
return EChange;
|
|
291 |
}
|