os/kernelhwsrv/kerneltest/e32test/resourceman/resourceman_psl/rescontrol_extended_psl.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/resourceman/resourceman_psl/rescontrol_extended_psl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,402 @@
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\resourceman_psl\rescontrol_extended_psl.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "rescontrol_psl.h"
1.22 +#include "rescontrol_extended_psl.h"
1.23 +
1.24 +/**
1.25 + This function creates all static resources which support dependencies and establishes
1.26 + the dependencies between them. This is called by PIL.
1.27 + Following is the dependency tree input
1.28 + ResourceA <----------------> ResourceD <------------->ResourceE <--------------> ResourceC
1.29 + | |
1.30 + | |
1.31 + | |
1.32 + | |
1.33 + | |
1.34 + | |
1.35 + ResourceF ResourceG
1.36 + */
1.37 +TInt DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency(DStaticPowerResourceD**& aStaticResourceDArray, TUint16& aStaticResourceDCount)
1.38 + {
1.39 + Kern::Printf(">DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency");
1.40 + aStaticResourceDArray = (DStaticPowerResourceD**)new(DStaticPowerResourceD*[MAX_DEPENDENT_RESOURCE_COUNT]);
1.41 + if(!aStaticResourceDArray)
1.42 + return KErrNoMemory;
1.43 + DStaticPowerResourceD* pR = NULL;
1.44 + pR = new DMLSLGLSPDependResource();
1.45 + if(!pR)
1.46 + CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
1.47 + aStaticResourceDArray[iStaticResDependencyCount++] = pR;
1.48 +
1.49 + pR = new DMLSIGLSNDependResource();
1.50 + if(!pR)
1.51 + CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
1.52 + aStaticResourceDArray[iStaticResDependencyCount++] = pR;
1.53 +
1.54 + pR = new DBSIGLSPDependResource();
1.55 + if(!pR)
1.56 + CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
1.57 + aStaticResourceDArray[iStaticResDependencyCount++] = pR;
1.58 +
1.59 + pR = new DMLSHIGLSPDependResource();
1.60 + if(!pR)
1.61 + CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
1.62 + aStaticResourceDArray[iStaticResDependencyCount++] = pR;
1.63 +
1.64 + pR = new DBSHLGLSNDependResource();
1.65 + if(!pR)
1.66 + CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
1.67 + aStaticResourceDArray[iStaticResDependencyCount++] = pR;
1.68 +
1.69 + pR = new DMLSHLGLSNDependResource();
1.70 + if(!pR)
1.71 + CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
1.72 + aStaticResourceDArray[iStaticResDependencyCount++] = pR;
1.73 +
1.74 + //Establish resource dependencies
1.75 + if(CreateResourceDependency(aStaticResourceDArray))
1.76 + CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
1.77 +
1.78 + iDependencyResources = aStaticResourceDArray;
1.79 +
1.80 + aStaticResourceDCount = iStaticResDependencyCount;
1.81 + return KErrNone;
1.82 + }
1.83 +
1.84 +
1.85 +// This function establishes above dependency between static dependent resource
1.86 +TInt DSimulatedPowerResourceController::CreateResourceDependency(DStaticPowerResourceD** pResArray)
1.87 + {
1.88 + iNodeArray = new SNode[10];
1.89 + SNode* pN1;
1.90 + SNode* pN2;
1.91 + iNodeCount = 0;
1.92 +
1.93 + if(!iNodeArray)
1.94 + return KErrNoMemory;
1.95 + //Create Dependency between Resource A and Resource D
1.96 + pN1 = &iNodeArray[iNodeCount++];
1.97 + pN2 = &iNodeArray[iNodeCount++];
1.98 + CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[1], 1, 1)
1.99 +
1.100 + //Create Dependency between Resource D and Resource F
1.101 + //Trying to add with the same priority and check whether KErrAlreadyExists is returned.
1.102 + pN1 = &iNodeArray[iNodeCount++];
1.103 + pN2 = &iNodeArray[iNodeCount++];
1.104 + pN1->iPriority = 1;
1.105 + pN1->iResource = pResArray[0];
1.106 + pN1->iPropagatedLevel = 0;
1.107 + pN1->iVisited = EFalse;
1.108 +
1.109 + pN2->iPriority = 1;
1.110 + pN2->iResource = pResArray[2];
1.111 + pN2->iPropagatedLevel = 0;
1.112 + pN2->iVisited = EFalse;
1.113 + pN2->iResource->AddNode(pN1);
1.114 +
1.115 + TInt r = pN1->iResource->AddNode(pN2);
1.116 + if(r != KErrAlreadyExists)
1.117 + Kern::Fault("Power Resource Controller", __LINE__);
1.118 +
1.119 + pN2->iPriority = 3;
1.120 + r = pN1->iResource->AddNode(pN2);
1.121 + if(r != KErrNone)
1.122 + Kern::Fault("Power Resource Controller", __LINE__);
1.123 +
1.124 + //Create Dependency between Resource D and Resource E
1.125 + pN1 = &iNodeArray[iNodeCount++];
1.126 + pN2 = &iNodeArray[iNodeCount++];
1.127 + CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[3], 3, 2)
1.128 +
1.129 + //Create Dependency between Resource E and Resource C
1.130 + pN1 = &iNodeArray[iNodeCount++];
1.131 + pN2 = &iNodeArray[iNodeCount++];
1.132 + CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[4], 1, 1)
1.133 +
1.134 + //Create Dependency between Resource E and Resource G
1.135 + pN1 = &iNodeArray[iNodeCount++];
1.136 + pN2 = &iNodeArray[iNodeCount++];
1.137 + CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[5], 1, 2)
1.138 +
1.139 + return KErrNone;
1.140 + }
1.141 +
1.142 +//Constructors of all resources
1.143 +_LIT(KDMLSLGLSPDependResource, "StaticDependResourceD");
1.144 +DMLSLGLSPDependResource::DMLSLGLSPDependResource() : DStaticPowerResourceD(KDMLSLGLSPDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
1.145 + {
1.146 + iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet;
1.147 + NKern::LockSystem();
1.148 + iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
1.149 + NKern::UnlockSystem();
1.150 + }
1.151 +
1.152 +_LIT(KDMLSIGLSNDependResource, "StaticDependResourceA");
1.153 +DMLSIGLSNDependResource::DMLSIGLSNDependResource() : DStaticPowerResourceD(KDMLSIGLSNDependResource, -10), iMinLevel(-10), iMaxLevel(-20), iCurrentLevel(-10)
1.154 + {
1.155 + iFlags = KMultiLevel | KLongLatencySet | KSenseNegative;
1.156 + NKern::LockSystem();
1.157 + iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
1.158 + NKern::UnlockSystem();
1.159 + }
1.160 +
1.161 +_LIT(KDBSIGLSPDependResource, "StaticDependResourceF");
1.162 +DBSIGLSPDependResource::DBSIGLSPDependResource() : DStaticPowerResourceD(KDBSIGLSPDependResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
1.163 + {
1.164 + iFlags = KBinary | KLongLatencySet;
1.165 + NKern::LockSystem();
1.166 + iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
1.167 + NKern::UnlockSystem();
1.168 + }
1.169 +
1.170 +_LIT(KDMLSHIGLSPDependResource, "StaticDependResourceE");
1.171 +DMLSHIGLSPDependResource::DMLSHIGLSPDependResource() : DStaticPowerResourceD(KDMLSHIGLSPDependResource, 10), iMinLevel(10), iMaxLevel(75), iCurrentLevel(10)
1.172 + {
1.173 + // Make it a Instantaneous Resource.
1.174 + iFlags = KMultiLevel | KShared;
1.175 + NKern::LockSystem();
1.176 + iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
1.177 + NKern::UnlockSystem();
1.178 + }
1.179 +
1.180 +_LIT(KDBSHLGLSNDependResource, "StaticDependResourceC");
1.181 +DBSHLGLSNDependResource::DBSHLGLSNDependResource() : DStaticPowerResourceD(KDBSHLGLSNDependResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1)
1.182 + {
1.183 + iFlags = KBinary | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
1.184 + NKern::LockSystem();
1.185 + iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
1.186 + NKern::UnlockSystem();
1.187 + }
1.188 +
1.189 +_LIT(KDMLSHLGLSNDependResource, "StaticDependResourceG");
1.190 +DMLSHLGLSNDependResource::DMLSHLGLSNDependResource() : DStaticPowerResourceD(KDMLSHLGLSNDependResource, 75), iMinLevel(75), iMaxLevel(30), iCurrentLevel(75)
1.191 + {
1.192 + iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
1.193 + NKern::LockSystem();
1.194 + iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
1.195 + NKern::UnlockSystem();
1.196 + }
1.197 +
1.198 +_LIT(KDMLSHLGLSCDependResource, "DMLSHLGLSCDependResource");
1.199 +DMLSHLGLSCDependResource::DMLSHLGLSCDependResource() : DStaticPowerResourceD(KDMLSHLGLSCDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
1.200 + {
1.201 + iFlags = KMultiLevel;
1.202 + NKern::LockSystem();
1.203 + iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
1.204 + NKern::UnlockSystem();
1.205 + }
1.206 +
1.207 +//Implementation of handle dependent state for all resources
1.208 +TChangePropagationStatus DMLSLGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt /*aDepState*/, TInt& /*aResState*/)
1.209 + {
1.210 + //This resources changes only when the client asks to change
1.211 + return ENoChange;
1.212 + }
1.213 +
1.214 +TChangePropagationStatus DMLSIGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
1.215 + {
1.216 + if(aDepState == -100)
1.217 + {
1.218 + aResState = iMinLevel;
1.219 + return EChange;
1.220 + }
1.221 + if(aDepState < 0)
1.222 + {
1.223 + aResState = iCurrentLevel > -15 ? iCurrentLevel-1 : -15;
1.224 + if(aResState == iCurrentLevel)
1.225 + return ENoChange;
1.226 + return EChange;
1.227 + }
1.228 + aResState = iCurrentLevel > iMaxLevel ? iCurrentLevel-1 : iMaxLevel;
1.229 + if(aResState == iCurrentLevel)
1.230 + return ENoChange;
1.231 + return EChange;
1.232 + }
1.233 +
1.234 +TChangePropagationStatus DBSIGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
1.235 + {
1.236 + if(aDepState == -100)
1.237 + {
1.238 + aResState = iMinLevel;
1.239 + return EChange;
1.240 + }
1.241 + if(iCurrentLevel == E_ON)
1.242 + return ENoChange;
1.243 + aResState = iMaxLevel;
1.244 + return EChange;
1.245 + }
1.246 +
1.247 +TChangePropagationStatus DMLSHIGLSPDependResource::TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState)
1.248 + {
1.249 + if((aDepId & ID_INDEX_BIT_MASK) != 0x1)
1.250 + return ENoChange;
1.251 + if(aDepState == -100)
1.252 + {
1.253 + aResState = iMinLevel;
1.254 + return EChange;
1.255 + }
1.256 + aResState = iCurrentLevel + 3;
1.257 + if(aResState == iMaxLevel)
1.258 + return ENoChange;
1.259 + return EChange;
1.260 + }
1.261 +
1.262 +TChangePropagationStatus DBSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
1.263 + {
1.264 + if(aDepState == 10)
1.265 + {
1.266 + aResState = iMinLevel;
1.267 + return EChange;
1.268 + }
1.269 + if(iCurrentLevel == iMaxLevel)
1.270 + return ENoChange;
1.271 + aResState = iMaxLevel;
1.272 + return EChange;
1.273 + }
1.274 +
1.275 +TChangePropagationStatus DMLSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
1.276 + {
1.277 + if(aDepState == 10)
1.278 + {
1.279 + aResState = iMinLevel;
1.280 + return EChange;
1.281 + }
1.282 + aResState = iCurrentLevel - 2;
1.283 + if(aResState == iMaxLevel)
1.284 + return ENoChange;
1.285 + return EChange;
1.286 + }
1.287 +
1.288 +TChangePropagationStatus DMLSHLGLSCDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
1.289 + {
1.290 + if((aDepState == 10) && (iCurrentLevel == -100))
1.291 + return ENoChange;
1.292 + if(aDepState == 10)
1.293 + {
1.294 + aResState = -100;
1.295 + return EChange;
1.296 + }
1.297 + if(iCurrentLevel)
1.298 + aResState = iCurrentLevel + 20;
1.299 + else
1.300 + aResState = iCurrentLevel -20;
1.301 + if(aResState > iMaxLevel)
1.302 + aResState = iMaxLevel;
1.303 + return EChange;
1.304 + }
1.305 +
1.306 +
1.307 +//Implementation of DoRequest functionality for all resource
1.308 +TInt DMLSLGLSPDependResource::DoRequest(TPowerRequest& req)
1.309 + {
1.310 + return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
1.311 + }
1.312 +
1.313 +TInt DMLSIGLSNDependResource::DoRequest(TPowerRequest& req)
1.314 + {
1.315 + return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
1.316 + }
1.317 +
1.318 +TInt DBSIGLSPDependResource::DoRequest(TPowerRequest& req)
1.319 + {
1.320 + return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
1.321 + }
1.322 +
1.323 +TInt DMLSHIGLSPDependResource::DoRequest(TPowerRequest& req)
1.324 + {
1.325 + return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
1.326 + }
1.327 +
1.328 +TInt DBSHLGLSNDependResource::DoRequest(TPowerRequest& req)
1.329 + {
1.330 + return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
1.331 + }
1.332 +
1.333 +TInt DMLSHLGLSNDependResource::DoRequest(TPowerRequest& req)
1.334 + {
1.335 + return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
1.336 + }
1.337 +
1.338 +TInt DMLSHLGLSCDependResource::DoRequest(TPowerRequest& req)
1.339 + {
1.340 + return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
1.341 + }
1.342 +
1.343 +//Get info implementation of all resources.
1.344 +TInt DMLSLGLSPDependResource::GetInfo(TDes8* info) const
1.345 + {
1.346 + DStaticPowerResource::GetInfo((TDes8*)info);
1.347 + TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
1.348 + buf1->iMinLevel = iMinLevel;
1.349 + buf1->iMaxLevel = iMaxLevel;
1.350 + return KErrNone;
1.351 + }
1.352 +
1.353 +TInt DMLSIGLSNDependResource::GetInfo(TDes8* info) const
1.354 + {
1.355 + DStaticPowerResource::GetInfo((TDes8*)info);
1.356 + TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
1.357 + buf1->iMinLevel = iMinLevel;
1.358 + buf1->iMaxLevel = iMaxLevel;
1.359 + return KErrNone;
1.360 + }
1.361 +
1.362 +TInt DBSIGLSPDependResource::GetInfo(TDes8* info) const
1.363 + {
1.364 + DStaticPowerResource::GetInfo((TDes8*)info);
1.365 + TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
1.366 + buf1->iMinLevel = iMinLevel;
1.367 + buf1->iMaxLevel = iMaxLevel;
1.368 + return KErrNone;
1.369 + }
1.370 +
1.371 +TInt DMLSHIGLSPDependResource::GetInfo(TDes8* info) const
1.372 + {
1.373 + DStaticPowerResource::GetInfo((TDes8*)info);
1.374 + TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
1.375 + buf1->iMinLevel = iMinLevel;
1.376 + buf1->iMaxLevel = iMaxLevel;
1.377 + return KErrNone;
1.378 + }
1.379 +
1.380 +TInt DBSHLGLSNDependResource::GetInfo(TDes8* info) const
1.381 + {
1.382 + DStaticPowerResource::GetInfo((TDes8*)info);
1.383 + TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
1.384 + buf1->iMinLevel = iMinLevel;
1.385 + buf1->iMaxLevel = iMaxLevel;
1.386 + return KErrNone;
1.387 + }
1.388 +
1.389 +TInt DMLSHLGLSNDependResource::GetInfo(TDes8* info) const
1.390 + {
1.391 + DStaticPowerResource::GetInfo((TDes8*)info);
1.392 + TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
1.393 + buf1->iMinLevel = iMinLevel;
1.394 + buf1->iMaxLevel = iMaxLevel;
1.395 + return KErrNone;
1.396 + }
1.397 +
1.398 +TInt DMLSHLGLSCDependResource::GetInfo(TDes8* info) const
1.399 + {
1.400 + DStaticPowerResource::GetInfo((TDes8*)info);
1.401 + TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
1.402 + buf1->iMinLevel = iMinLevel;
1.403 + buf1->iMaxLevel = iMaxLevel;
1.404 + return KErrNone;
1.405 + }