os/kernelhwsrv/kerneltest/e32test/resourceman/dynamicresource.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/resourceman/dynamicresource.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,305 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\resourceman\dynamicresource.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <drivers/resourcecontrol.h>
    1.22 +#include "dynamicresource.h"
    1.23 +
    1.24 +const TUint KBinary = 0x0;
    1.25 +const TUint KMultiLevel = 0x1;
    1.26 +
    1.27 +#define MAX_BLOCK_TIME 100 //Maximum block time
    1.28 +#define MIN_BLOCK_TIME 30 //Guaranteed minimum block
    1.29 +
    1.30 +//Constructors for dynamic resources
    1.31 +_LIT(KDBIGISSPDynamicResource, "DynamicResource1");
    1.32 +DBIGISSPDynamicResource::DBIGISSPDynamicResource() : DDynamicPowerResource(KDBIGISSPDynamicResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
    1.33 +	{
    1.34 +	}
    1.35 +
    1.36 +_LIT(KDMLIGLSSHNDynamicResource, "DynamicResource2");
    1.37 +DMLIGLSSHNDynamicResource::DMLIGLSSHNDynamicResource() : DDynamicPowerResource(KDMLIGLSSHNDynamicResource, -5), iMinLevel(-5), iMaxLevel(-10), iCurrentLevel(-5)
    1.38 +	{
    1.39 +	iFlags = KMultiLevel | KLongLatencySet | KShared | KSenseNegative;
    1.40 +	NKern::LockSystem();
    1.41 +	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
    1.42 +	NKern::UnlockSystem();
    1.43 +	}
    1.44 +
    1.45 +_LIT(KDBLGLSSHNDynamicResource, "DynamicResource3");
    1.46 +DBLGLSSHNDynamicResource::DBLGLSSHNDynamicResource() : DDynamicPowerResource(KDBLGLSSHNDynamicResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1)
    1.47 +	{
    1.48 +	iFlags = KBinary | KLongLatencySet | KLongLatencyGet | KShared | KSenseNegative;
    1.49 +	NKern::LockSystem();
    1.50 +	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
    1.51 +	NKern::UnlockSystem();
    1.52 +	}
    1.53 +
    1.54 +_LIT(KDMLLGLSSHPDynamicResource, "DynamicResource4");
    1.55 +DMLLGLSSHPDynamicResource::DMLLGLSSHPDynamicResource() : DDynamicPowerResource(KDMLLGLSSHPDynamicResource, 10), iMinLevel(10), iMaxLevel(20), iCurrentLevel(10)
    1.56 +	{
    1.57 +	iFlags = KMultiLevel | KLongLatencySet | KLongLatencyGet | KShared;
    1.58 +	NKern::LockSystem();
    1.59 +	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
    1.60 +	NKern::UnlockSystem();
    1.61 +	}
    1.62 +
    1.63 +//Constructors for dynamic dependent resources
    1.64 +_LIT(KDDynamicResourceD01, "DynamicDependResourceDH");
    1.65 +DDynamicResourceD01::DDynamicResourceD01() : DDynamicPowerResourceD(KDDynamicResourceD01, 75), iMinLevel(75), iMaxLevel(90), iCurrentLevel(75)
    1.66 +	{
    1.67 +	// Make it a Instantaneous Resource.
    1.68 +	iFlags = KMultiLevel;
    1.69 +	NKern::LockSystem();
    1.70 +	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
    1.71 +	NKern::UnlockSystem();
    1.72 +	}
    1.73 +
    1.74 +_LIT(KDDynamicResourceD02, "DynamicDependResourceDI");
    1.75 +DDynamicResourceD02::DDynamicResourceD02() : DDynamicPowerResourceD(KDDynamicResourceD02, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
    1.76 +	{
    1.77 +	iFlags = KBinary | KLongLatencySet | KLongLatencyGet | KShared;
    1.78 +	NKern::LockSystem();
    1.79 +	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
    1.80 +	NKern::UnlockSystem();
    1.81 +	}
    1.82 +
    1.83 +_LIT(KDDynamicResourceD03, "DynamicDependResourceDJ");
    1.84 +DDynamicResourceD03::DDynamicResourceD03() : DDynamicPowerResourceD(KDDynamicResourceD03, 19), iMinLevel(19), iMaxLevel(9), iCurrentLevel(19)
    1.85 +	{
    1.86 +	iFlags = KMultiLevel | KLongLatencySet | KShared | KSenseNegative;
    1.87 +	NKern::LockSystem();
    1.88 +	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
    1.89 +	NKern::UnlockSystem();
    1.90 +	}
    1.91 +
    1.92 +_LIT(KDDynamicResourceD04, "DynamicDependResourceDK");
    1.93 +DDynamicResourceD04::DDynamicResourceD04() : DDynamicPowerResourceD(KDDynamicResourceD04, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
    1.94 +	{
    1.95 +	iFlags = KBinary | KLongLatencySet;
    1.96 +	NKern::LockSystem();
    1.97 +	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
    1.98 +	NKern::UnlockSystem();
    1.99 +	}
   1.100 +
   1.101 +//Get info implementation for dynamic resources
   1.102 +TInt DBIGISSPDynamicResource::GetInfo(TDes8* info) const
   1.103 +	{
   1.104 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.105 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.106 +	buf1->iMinLevel = iMinLevel;
   1.107 +	buf1->iMaxLevel = iMaxLevel;
   1.108 +	return KErrNone;
   1.109 +	}
   1.110 +
   1.111 +TInt DMLIGLSSHNDynamicResource::GetInfo(TDes8* info) const
   1.112 +	{
   1.113 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.114 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.115 +	buf1->iMinLevel = iMinLevel;
   1.116 +	buf1->iMaxLevel = iMaxLevel;
   1.117 +	return KErrNone;
   1.118 +	}
   1.119 +
   1.120 +TInt DBLGLSSHNDynamicResource::GetInfo(TDes8* info) const
   1.121 +	{
   1.122 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.123 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.124 +	buf1->iMinLevel = iMinLevel;
   1.125 +	buf1->iMaxLevel = iMaxLevel;
   1.126 +	return KErrNone;
   1.127 +	}
   1.128 +
   1.129 +TInt DMLLGLSSHPDynamicResource::GetInfo(TDes8* info) const
   1.130 +	{
   1.131 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.132 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.133 +	buf1->iMinLevel = iMinLevel;
   1.134 +	buf1->iMaxLevel = iMaxLevel;
   1.135 +	return KErrNone;
   1.136 +	}
   1.137 +
   1.138 +//Get info implementation of dynamic dependent resources
   1.139 +TInt DDynamicResourceD01::GetInfo(TDes8* info) const
   1.140 +	{
   1.141 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.142 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.143 +	buf1->iMinLevel = iMinLevel;
   1.144 +	buf1->iMaxLevel = iMaxLevel;
   1.145 +	return KErrNone;
   1.146 +	}
   1.147 +
   1.148 +TInt DDynamicResourceD02::GetInfo(TDes8* info) const
   1.149 +	{
   1.150 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.151 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.152 +	buf1->iMinLevel = iMinLevel;
   1.153 +	buf1->iMaxLevel = iMaxLevel;
   1.154 +	return KErrNone;
   1.155 +	}
   1.156 +
   1.157 +TInt DDynamicResourceD03::GetInfo(TDes8* info) const
   1.158 +	{
   1.159 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.160 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.161 +	buf1->iMinLevel = iMinLevel;
   1.162 +	buf1->iMaxLevel = iMaxLevel;
   1.163 +	return KErrNone;
   1.164 +	}
   1.165 +
   1.166 +TInt DDynamicResourceD04::GetInfo(TDes8* info) const
   1.167 +	{
   1.168 +	DStaticPowerResource::GetInfo((TDes8*)info);
   1.169 +	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   1.170 +	buf1->iMinLevel = iMinLevel;
   1.171 +	buf1->iMaxLevel = iMaxLevel;
   1.172 +	return KErrNone;
   1.173 +	}
   1.174 +
   1.175 +/** Function used for polling resources. */
   1.176 +TBool PollingFunction(TAny* ptr)
   1.177 +	{
   1.178 +	static TInt count = 0;
   1.179 +	if(++count == (TInt)ptr)
   1.180 +		{
   1.181 +		count = 0;
   1.182 +		return ETrue;
   1.183 +		}
   1.184 +	return EFalse;
   1.185 +	}
   1.186 +
   1.187 +//Function to handle Do Request functionality of all dynamic resources
   1.188 +TInt RequestHandlingOfDynamicResources(TPowerRequest& req, TInt& aDefaultLevel, TInt& aCurrentLevel)
   1.189 +	{
   1.190 +	if(req.ReqType() == TPowerRequest::EGet)
   1.191 +		{
   1.192 +		req.Level() = aCurrentLevel;
   1.193 +		}
   1.194 +	else if(req.ReqType() == TPowerRequest::EChange)
   1.195 +		{
   1.196 +		aCurrentLevel = req.Level();
   1.197 +		}
   1.198 +	else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
   1.199 +		{
   1.200 +		req.Level() =  aDefaultLevel;
   1.201 +		aCurrentLevel = aDefaultLevel;
   1.202 +		}
   1.203 +	else
   1.204 +		return KErrNotSupported;
   1.205 +	return KErrNone;
   1.206 +	}
   1.207 +
   1.208 +//Do request implementation for dynamic resources
   1.209 +TInt DBIGISSPDynamicResource::DoRequest(TPowerRequest& req)
   1.210 +	{
   1.211 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.212 +	}
   1.213 +
   1.214 +TInt DMLIGLSSHNDynamicResource::DoRequest(TPowerRequest& req)
   1.215 +	{
   1.216 +	if(req.ReqType() != TPowerRequest::EGet)
   1.217 +		Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
   1.218 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.219 +	}
   1.220 +
   1.221 +TInt DBLGLSSHNDynamicResource::DoRequest(TPowerRequest& req)
   1.222 +	{
   1.223 +	Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
   1.224 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.225 +	}
   1.226 +
   1.227 +TInt DMLLGLSSHPDynamicResource::DoRequest(TPowerRequest& req)
   1.228 +	{
   1.229 +	Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
   1.230 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.231 +	}
   1.232 +
   1.233 +//Do request implementation for dynamic dependent resources
   1.234 +TInt DDynamicResourceD01::DoRequest(TPowerRequest& req)
   1.235 +	{
   1.236 +	if(req.ReqType() != TPowerRequest::EGet)
   1.237 +		Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
   1.238 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.239 +	}
   1.240 +
   1.241 +TInt DDynamicResourceD02::DoRequest(TPowerRequest& req)
   1.242 +	{
   1.243 +	Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
   1.244 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.245 +	}
   1.246 +
   1.247 +TInt DDynamicResourceD03::DoRequest(TPowerRequest& req)
   1.248 +	{
   1.249 +	if(req.ReqType() != TPowerRequest::EGet)
   1.250 +		Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
   1.251 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.252 +	}
   1.253 +
   1.254 +TInt DDynamicResourceD04::DoRequest(TPowerRequest& req)
   1.255 +	{
   1.256 +	if(req.ReqType() != TPowerRequest::EGet)
   1.257 +		Kern::PollingWait(PollingFunction, (TAny*)iBlockTime, 3, iBlockTime);
   1.258 +	return RequestHandlingOfDynamicResources(req, iDefaultLevel, iCurrentLevel);
   1.259 +	}
   1.260 +
   1.261 +//PSL specific implementation of translate dependent state for dynamic dependent resources.
   1.262 +TChangePropagationStatus DDynamicResourceD01::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
   1.263 +	{
   1.264 +	if(aDepState == 75)
   1.265 +		{
   1.266 +		aResState = iMinLevel;
   1.267 +		return EChange;
   1.268 +		}
   1.269 +	if(iCurrentLevel >= 80)
   1.270 +		return ENoChange;
   1.271 +	aResState = 80;
   1.272 +	return EChange;
   1.273 +	}
   1.274 +
   1.275 +TChangePropagationStatus DDynamicResourceD02::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
   1.276 +	{
   1.277 +	if(aDepState == 75)
   1.278 +		{
   1.279 +		aResState = iMinLevel;
   1.280 +		return EChange;
   1.281 +		}
   1.282 +	aResState = iMaxLevel;
   1.283 +	return EChange;
   1.284 +	}
   1.285 +
   1.286 +TChangePropagationStatus DDynamicResourceD03::TranslateDependentState(TInt /*aDepId */, TInt aDepState, TInt& aResState)
   1.287 +	{
   1.288 +	if(aDepState == 75)
   1.289 +		{
   1.290 +		aResState = iMinLevel;
   1.291 +		return EChange;
   1.292 +		}
   1.293 +	aResState = iCurrentLevel - 1;
   1.294 +	if(aResState == iMaxLevel)
   1.295 +		aResState = iMaxLevel;
   1.296 +	return EChange;
   1.297 +	}
   1.298 +
   1.299 +TChangePropagationStatus DDynamicResourceD04::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
   1.300 +	{
   1.301 +	if(aDepState == 19)
   1.302 +		{
   1.303 +		aResState = iMinLevel;
   1.304 +		return EChange;
   1.305 +		}
   1.306 +	aResState = iMaxLevel;
   1.307 +	return EChange;
   1.308 +	}