sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\resourceman\resourceman_psl\rescontrol_extended_psl.cpp sl@0: // sl@0: // sl@0: sl@0: #include "rescontrol_psl.h" sl@0: #include "rescontrol_extended_psl.h" sl@0: sl@0: /** sl@0: This function creates all static resources which support dependencies and establishes sl@0: the dependencies between them. This is called by PIL. sl@0: Following is the dependency tree input sl@0: ResourceA <----------------> ResourceD <------------->ResourceE <--------------> ResourceC sl@0: | | sl@0: | | sl@0: | | sl@0: | | sl@0: | | sl@0: | | sl@0: ResourceF ResourceG sl@0: */ sl@0: TInt DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency(DStaticPowerResourceD**& aStaticResourceDArray, TUint16& aStaticResourceDCount) sl@0: { sl@0: Kern::Printf(">DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency"); sl@0: aStaticResourceDArray = (DStaticPowerResourceD**)new(DStaticPowerResourceD*[MAX_DEPENDENT_RESOURCE_COUNT]); sl@0: if(!aStaticResourceDArray) sl@0: return KErrNoMemory; sl@0: DStaticPowerResourceD* pR = NULL; sl@0: pR = new DMLSLGLSPDependResource(); sl@0: if(!pR) sl@0: CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory) sl@0: aStaticResourceDArray[iStaticResDependencyCount++] = pR; sl@0: sl@0: pR = new DMLSIGLSNDependResource(); sl@0: if(!pR) sl@0: CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory) sl@0: aStaticResourceDArray[iStaticResDependencyCount++] = pR; sl@0: sl@0: pR = new DBSIGLSPDependResource(); sl@0: if(!pR) sl@0: CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory) sl@0: aStaticResourceDArray[iStaticResDependencyCount++] = pR; sl@0: sl@0: pR = new DMLSHIGLSPDependResource(); sl@0: if(!pR) sl@0: CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory) sl@0: aStaticResourceDArray[iStaticResDependencyCount++] = pR; sl@0: sl@0: pR = new DBSHLGLSNDependResource(); sl@0: if(!pR) sl@0: CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory) sl@0: aStaticResourceDArray[iStaticResDependencyCount++] = pR; sl@0: sl@0: pR = new DMLSHLGLSNDependResource(); sl@0: if(!pR) sl@0: CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory) sl@0: aStaticResourceDArray[iStaticResDependencyCount++] = pR; sl@0: sl@0: //Establish resource dependencies sl@0: if(CreateResourceDependency(aStaticResourceDArray)) sl@0: CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory) sl@0: sl@0: iDependencyResources = aStaticResourceDArray; sl@0: sl@0: aStaticResourceDCount = iStaticResDependencyCount; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: // This function establishes above dependency between static dependent resource sl@0: TInt DSimulatedPowerResourceController::CreateResourceDependency(DStaticPowerResourceD** pResArray) sl@0: { sl@0: iNodeArray = new SNode[10]; sl@0: SNode* pN1; sl@0: SNode* pN2; sl@0: iNodeCount = 0; sl@0: sl@0: if(!iNodeArray) sl@0: return KErrNoMemory; sl@0: //Create Dependency between Resource A and Resource D sl@0: pN1 = &iNodeArray[iNodeCount++]; sl@0: pN2 = &iNodeArray[iNodeCount++]; sl@0: CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[1], 1, 1) sl@0: sl@0: //Create Dependency between Resource D and Resource F sl@0: //Trying to add with the same priority and check whether KErrAlreadyExists is returned. sl@0: pN1 = &iNodeArray[iNodeCount++]; sl@0: pN2 = &iNodeArray[iNodeCount++]; sl@0: pN1->iPriority = 1; sl@0: pN1->iResource = pResArray[0]; sl@0: pN1->iPropagatedLevel = 0; sl@0: pN1->iVisited = EFalse; sl@0: sl@0: pN2->iPriority = 1; sl@0: pN2->iResource = pResArray[2]; sl@0: pN2->iPropagatedLevel = 0; sl@0: pN2->iVisited = EFalse; sl@0: pN2->iResource->AddNode(pN1); sl@0: sl@0: TInt r = pN1->iResource->AddNode(pN2); sl@0: if(r != KErrAlreadyExists) sl@0: Kern::Fault("Power Resource Controller", __LINE__); sl@0: sl@0: pN2->iPriority = 3; sl@0: r = pN1->iResource->AddNode(pN2); sl@0: if(r != KErrNone) sl@0: Kern::Fault("Power Resource Controller", __LINE__); sl@0: sl@0: //Create Dependency between Resource D and Resource E sl@0: pN1 = &iNodeArray[iNodeCount++]; sl@0: pN2 = &iNodeArray[iNodeCount++]; sl@0: CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[3], 3, 2) sl@0: sl@0: //Create Dependency between Resource E and Resource C sl@0: pN1 = &iNodeArray[iNodeCount++]; sl@0: pN2 = &iNodeArray[iNodeCount++]; sl@0: CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[4], 1, 1) sl@0: sl@0: //Create Dependency between Resource E and Resource G sl@0: pN1 = &iNodeArray[iNodeCount++]; sl@0: pN2 = &iNodeArray[iNodeCount++]; sl@0: CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[5], 1, 2) sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: //Constructors of all resources sl@0: _LIT(KDMLSLGLSPDependResource, "StaticDependResourceD"); sl@0: DMLSLGLSPDependResource::DMLSLGLSPDependResource() : DStaticPowerResourceD(KDMLSLGLSPDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100) sl@0: { sl@0: iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet; sl@0: NKern::LockSystem(); sl@0: iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME; sl@0: NKern::UnlockSystem(); sl@0: } sl@0: sl@0: _LIT(KDMLSIGLSNDependResource, "StaticDependResourceA"); sl@0: DMLSIGLSNDependResource::DMLSIGLSNDependResource() : DStaticPowerResourceD(KDMLSIGLSNDependResource, -10), iMinLevel(-10), iMaxLevel(-20), iCurrentLevel(-10) sl@0: { sl@0: iFlags = KMultiLevel | KLongLatencySet | KSenseNegative; sl@0: NKern::LockSystem(); sl@0: iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME; sl@0: NKern::UnlockSystem(); sl@0: } sl@0: sl@0: _LIT(KDBSIGLSPDependResource, "StaticDependResourceF"); sl@0: DBSIGLSPDependResource::DBSIGLSPDependResource() : DStaticPowerResourceD(KDBSIGLSPDependResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0) sl@0: { sl@0: iFlags = KBinary | KLongLatencySet; sl@0: NKern::LockSystem(); sl@0: iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME; sl@0: NKern::UnlockSystem(); sl@0: } sl@0: sl@0: _LIT(KDMLSHIGLSPDependResource, "StaticDependResourceE"); sl@0: DMLSHIGLSPDependResource::DMLSHIGLSPDependResource() : DStaticPowerResourceD(KDMLSHIGLSPDependResource, 10), iMinLevel(10), iMaxLevel(75), iCurrentLevel(10) sl@0: { sl@0: // Make it a Instantaneous Resource. sl@0: iFlags = KMultiLevel | KShared; sl@0: NKern::LockSystem(); sl@0: iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME; sl@0: NKern::UnlockSystem(); sl@0: } sl@0: sl@0: _LIT(KDBSHLGLSNDependResource, "StaticDependResourceC"); sl@0: DBSHLGLSNDependResource::DBSHLGLSNDependResource() : DStaticPowerResourceD(KDBSHLGLSNDependResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1) sl@0: { sl@0: iFlags = KBinary | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative; sl@0: NKern::LockSystem(); sl@0: iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME; sl@0: NKern::UnlockSystem(); sl@0: } sl@0: sl@0: _LIT(KDMLSHLGLSNDependResource, "StaticDependResourceG"); sl@0: DMLSHLGLSNDependResource::DMLSHLGLSNDependResource() : DStaticPowerResourceD(KDMLSHLGLSNDependResource, 75), iMinLevel(75), iMaxLevel(30), iCurrentLevel(75) sl@0: { sl@0: iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative; sl@0: NKern::LockSystem(); sl@0: iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME; sl@0: NKern::UnlockSystem(); sl@0: } sl@0: sl@0: _LIT(KDMLSHLGLSCDependResource, "DMLSHLGLSCDependResource"); sl@0: DMLSHLGLSCDependResource::DMLSHLGLSCDependResource() : DStaticPowerResourceD(KDMLSHLGLSCDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100) sl@0: { sl@0: iFlags = KMultiLevel; sl@0: NKern::LockSystem(); sl@0: iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME; sl@0: NKern::UnlockSystem(); sl@0: } sl@0: sl@0: //Implementation of handle dependent state for all resources sl@0: TChangePropagationStatus DMLSLGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt /*aDepState*/, TInt& /*aResState*/) sl@0: { sl@0: //This resources changes only when the client asks to change sl@0: return ENoChange; sl@0: } sl@0: sl@0: TChangePropagationStatus DMLSIGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState) sl@0: { sl@0: if(aDepState == -100) sl@0: { sl@0: aResState = iMinLevel; sl@0: return EChange; sl@0: } sl@0: if(aDepState < 0) sl@0: { sl@0: aResState = iCurrentLevel > -15 ? iCurrentLevel-1 : -15; sl@0: if(aResState == iCurrentLevel) sl@0: return ENoChange; sl@0: return EChange; sl@0: } sl@0: aResState = iCurrentLevel > iMaxLevel ? iCurrentLevel-1 : iMaxLevel; sl@0: if(aResState == iCurrentLevel) sl@0: return ENoChange; sl@0: return EChange; sl@0: } sl@0: sl@0: TChangePropagationStatus DBSIGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState) sl@0: { sl@0: if(aDepState == -100) sl@0: { sl@0: aResState = iMinLevel; sl@0: return EChange; sl@0: } sl@0: if(iCurrentLevel == E_ON) sl@0: return ENoChange; sl@0: aResState = iMaxLevel; sl@0: return EChange; sl@0: } sl@0: sl@0: TChangePropagationStatus DMLSHIGLSPDependResource::TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState) sl@0: { sl@0: if((aDepId & ID_INDEX_BIT_MASK) != 0x1) sl@0: return ENoChange; sl@0: if(aDepState == -100) sl@0: { sl@0: aResState = iMinLevel; sl@0: return EChange; sl@0: } sl@0: aResState = iCurrentLevel + 3; sl@0: if(aResState == iMaxLevel) sl@0: return ENoChange; sl@0: return EChange; sl@0: } sl@0: sl@0: TChangePropagationStatus DBSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState) sl@0: { sl@0: if(aDepState == 10) sl@0: { sl@0: aResState = iMinLevel; sl@0: return EChange; sl@0: } sl@0: if(iCurrentLevel == iMaxLevel) sl@0: return ENoChange; sl@0: aResState = iMaxLevel; sl@0: return EChange; sl@0: } sl@0: sl@0: TChangePropagationStatus DMLSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState) sl@0: { sl@0: if(aDepState == 10) sl@0: { sl@0: aResState = iMinLevel; sl@0: return EChange; sl@0: } sl@0: aResState = iCurrentLevel - 2; sl@0: if(aResState == iMaxLevel) sl@0: return ENoChange; sl@0: return EChange; sl@0: } sl@0: sl@0: TChangePropagationStatus DMLSHLGLSCDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState) sl@0: { sl@0: if((aDepState == 10) && (iCurrentLevel == -100)) sl@0: return ENoChange; sl@0: if(aDepState == 10) sl@0: { sl@0: aResState = -100; sl@0: return EChange; sl@0: } sl@0: if(iCurrentLevel) sl@0: aResState = iCurrentLevel + 20; sl@0: else sl@0: aResState = iCurrentLevel -20; sl@0: if(aResState > iMaxLevel) sl@0: aResState = iMaxLevel; sl@0: return EChange; sl@0: } sl@0: sl@0: sl@0: //Implementation of DoRequest functionality for all resource sl@0: TInt DMLSLGLSPDependResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime); sl@0: } sl@0: sl@0: TInt DMLSIGLSNDependResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime); sl@0: } sl@0: sl@0: TInt DBSIGLSPDependResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime); sl@0: } sl@0: sl@0: TInt DMLSHIGLSPDependResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime); sl@0: } sl@0: sl@0: TInt DBSHLGLSNDependResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime); sl@0: } sl@0: sl@0: TInt DMLSHLGLSNDependResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime); sl@0: } sl@0: sl@0: TInt DMLSHLGLSCDependResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime); sl@0: } sl@0: sl@0: //Get info implementation of all resources. sl@0: TInt DMLSLGLSPDependResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DMLSIGLSNDependResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DBSIGLSPDependResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DMLSHIGLSPDependResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DBSHLGLSNDependResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DMLSHLGLSNDependResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DMLSHLGLSCDependResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: }