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\dynamicresource.cpp
18 #include <drivers/resourcecontrol.h>
19 #include "dynamicresource.h"
21 const TUint KBinary = 0x0;
22 const TUint KMultiLevel = 0x1;
24 #define MAX_BLOCK_TIME 100 //Maximum block time
25 #define MIN_BLOCK_TIME 30 //Guaranteed minimum block
27 //Constructors for dynamic resources
28 _LIT(KDBIGISSPDynamicResource, "DynamicResource1");
29 DBIGISSPDynamicResource::DBIGISSPDynamicResource() : DDynamicPowerResource(KDBIGISSPDynamicResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
33 _LIT(KDMLIGLSSHNDynamicResource, "DynamicResource2");
34 DMLIGLSSHNDynamicResource::DMLIGLSSHNDynamicResource() : DDynamicPowerResource(KDMLIGLSSHNDynamicResource, -5), iMinLevel(-5), iMaxLevel(-10), iCurrentLevel(-5)
36 iFlags = KMultiLevel | KLongLatencySet | KShared | KSenseNegative;
38 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
39 NKern::UnlockSystem();
42 _LIT(KDBLGLSSHNDynamicResource, "DynamicResource3");
43 DBLGLSSHNDynamicResource::DBLGLSSHNDynamicResource() : DDynamicPowerResource(KDBLGLSSHNDynamicResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1)
45 iFlags = KBinary | KLongLatencySet | KLongLatencyGet | KShared | KSenseNegative;
47 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
48 NKern::UnlockSystem();
51 _LIT(KDMLLGLSSHPDynamicResource, "DynamicResource4");
52 DMLLGLSSHPDynamicResource::DMLLGLSSHPDynamicResource() : DDynamicPowerResource(KDMLLGLSSHPDynamicResource, 10), iMinLevel(10), iMaxLevel(20), iCurrentLevel(10)
54 iFlags = KMultiLevel | KLongLatencySet | KLongLatencyGet | KShared;
56 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
57 NKern::UnlockSystem();
60 //Constructors for dynamic dependent resources
61 _LIT(KDDynamicResourceD01, "DynamicDependResourceDH");
62 DDynamicResourceD01::DDynamicResourceD01() : DDynamicPowerResourceD(KDDynamicResourceD01, 75), iMinLevel(75), iMaxLevel(90), iCurrentLevel(75)
64 // Make it a Instantaneous Resource.
67 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
68 NKern::UnlockSystem();
71 _LIT(KDDynamicResourceD02, "DynamicDependResourceDI");
72 DDynamicResourceD02::DDynamicResourceD02() : DDynamicPowerResourceD(KDDynamicResourceD02, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
74 iFlags = KBinary | KLongLatencySet | KLongLatencyGet | KShared;
76 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
77 NKern::UnlockSystem();
80 _LIT(KDDynamicResourceD03, "DynamicDependResourceDJ");
81 DDynamicResourceD03::DDynamicResourceD03() : DDynamicPowerResourceD(KDDynamicResourceD03, 19), iMinLevel(19), iMaxLevel(9), iCurrentLevel(19)
83 iFlags = KMultiLevel | KLongLatencySet | KShared | KSenseNegative;
85 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
86 NKern::UnlockSystem();
89 _LIT(KDDynamicResourceD04, "DynamicDependResourceDK");
90 DDynamicResourceD04::DDynamicResourceD04() : DDynamicPowerResourceD(KDDynamicResourceD04, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
92 iFlags = KBinary | KLongLatencySet;
94 iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
95 NKern::UnlockSystem();
98 //Get info implementation for dynamic resources
99 TInt DBIGISSPDynamicResource::GetInfo(TDes8* info) const
101 DStaticPowerResource::GetInfo((TDes8*)info);
102 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
103 buf1->iMinLevel = iMinLevel;
104 buf1->iMaxLevel = iMaxLevel;
108 TInt DMLIGLSSHNDynamicResource::GetInfo(TDes8* info) const
110 DStaticPowerResource::GetInfo((TDes8*)info);
111 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
112 buf1->iMinLevel = iMinLevel;
113 buf1->iMaxLevel = iMaxLevel;
117 TInt DBLGLSSHNDynamicResource::GetInfo(TDes8* info) const
119 DStaticPowerResource::GetInfo((TDes8*)info);
120 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
121 buf1->iMinLevel = iMinLevel;
122 buf1->iMaxLevel = iMaxLevel;
126 TInt DMLLGLSSHPDynamicResource::GetInfo(TDes8* info) const
128 DStaticPowerResource::GetInfo((TDes8*)info);
129 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
130 buf1->iMinLevel = iMinLevel;
131 buf1->iMaxLevel = iMaxLevel;
135 //Get info implementation of dynamic dependent resources
136 TInt DDynamicResourceD01::GetInfo(TDes8* info) const
138 DStaticPowerResource::GetInfo((TDes8*)info);
139 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
140 buf1->iMinLevel = iMinLevel;
141 buf1->iMaxLevel = iMaxLevel;
145 TInt DDynamicResourceD02::GetInfo(TDes8* info) const
147 DStaticPowerResource::GetInfo((TDes8*)info);
148 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
149 buf1->iMinLevel = iMinLevel;
150 buf1->iMaxLevel = iMaxLevel;
154 TInt DDynamicResourceD03::GetInfo(TDes8* info) const
156 DStaticPowerResource::GetInfo((TDes8*)info);
157 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
158 buf1->iMinLevel = iMinLevel;
159 buf1->iMaxLevel = iMaxLevel;
163 TInt DDynamicResourceD04::GetInfo(TDes8* info) const
165 DStaticPowerResource::GetInfo((TDes8*)info);
166 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
167 buf1->iMinLevel = iMinLevel;
168 buf1->iMaxLevel = iMaxLevel;
172 /** Function used for polling resources. */
173 TBool PollingFunction(TAny* ptr)
175 static TInt count = 0;
176 if(++count == (TInt)ptr)
184 //Function to handle Do Request functionality of all dynamic resources
185 TInt RequestHandlingOfDynamicResources(TPowerRequest& req, TInt& aDefaultLevel, TInt& aCurrentLevel)
187 if(req.ReqType() == TPowerRequest::EGet)
189 req.Level() = aCurrentLevel;
191 else if(req.ReqType() == TPowerRequest::EChange)
193 aCurrentLevel = req.Level();
195 else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
197 req.Level() = aDefaultLevel;
198 aCurrentLevel = aDefaultLevel;
201 return KErrNotSupported;
205 //Do request implementation for dynamic resources
206 TInt DBIGISSPDynamicResource::DoRequest(TPowerRequest& req)
208 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
211 TInt DMLIGLSSHNDynamicResource::DoRequest(TPowerRequest& req)
213 if(req.ReqType() != TPowerRequest::EGet)
214 Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
215 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
218 TInt DBLGLSSHNDynamicResource::DoRequest(TPowerRequest& req)
220 Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
221 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
224 TInt DMLLGLSSHPDynamicResource::DoRequest(TPowerRequest& req)
226 Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
227 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
230 //Do request implementation for dynamic dependent resources
231 TInt DDynamicResourceD01::DoRequest(TPowerRequest& req)
233 if(req.ReqType() != TPowerRequest::EGet)
234 Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
235 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
238 TInt DDynamicResourceD02::DoRequest(TPowerRequest& req)
240 Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
241 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
244 TInt DDynamicResourceD03::DoRequest(TPowerRequest& req)
246 if(req.ReqType() != TPowerRequest::EGet)
247 Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
248 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
251 TInt DDynamicResourceD04::DoRequest(TPowerRequest& req)
253 if(req.ReqType() != TPowerRequest::EGet)
254 Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
255 return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
258 //PSL specific implementation of translate dependent state for dynamic dependent resources.
259 TChangePropagationStatus DDynamicResourceD01::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
263 aResState = iMinLevel;
266 if(iCurrentLevel >= 80)
272 TChangePropagationStatus DDynamicResourceD02::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
276 aResState = iMinLevel;
279 aResState = iMaxLevel;
283 TChangePropagationStatus DDynamicResourceD03::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
287 aResState = iMinLevel;
290 aResState = iCurrentLevel - 1;
291 if(aResState == iMaxLevel)
292 aResState = iMaxLevel;
296 TChangePropagationStatus DDynamicResourceD04::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
300 aResState = iMinLevel;
303 aResState = iMaxLevel;