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