os/kernelhwsrv/kerneltest/e32test/resourceman/resourceman_psl/rescontrol_extended_psl.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\resourceman\resourceman_psl\rescontrol_extended_psl.cpp
    15 // 
    16 //
    17 
    18 #include "rescontrol_psl.h"
    19 #include "rescontrol_extended_psl.h"
    20 
    21 /** 
    22 	This function creates all static resources which support dependencies and establishes
    23 	the dependencies between them. This is called by PIL.
    24 	Following is the dependency tree input
    25 	ResourceA <----------------> ResourceD <------------->ResourceE <--------------> ResourceC
    26 									|						  |
    27 									|						  |
    28 									|						  |	
    29 									|						  |	
    30 									|						  |
    31 									|						  |
    32 								ResourceF				   ResourceG	
    33 	*/
    34 TInt DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency(DStaticPowerResourceD**& aStaticResourceDArray, TUint16& aStaticResourceDCount)
    35 	{
    36 	Kern::Printf(">DSimulatedPowerResourceController::DoRegisterStaticResourcesDependency");
    37 	aStaticResourceDArray = (DStaticPowerResourceD**)new(DStaticPowerResourceD*[MAX_DEPENDENT_RESOURCE_COUNT]);
    38 	if(!aStaticResourceDArray)
    39 		return KErrNoMemory;
    40 	DStaticPowerResourceD* pR = NULL;
    41 	pR = new DMLSLGLSPDependResource();
    42 	if(!pR)
    43 		CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
    44 	aStaticResourceDArray[iStaticResDependencyCount++] = pR;
    45 
    46 	pR = new DMLSIGLSNDependResource();
    47 	if(!pR)
    48 		CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
    49 	aStaticResourceDArray[iStaticResDependencyCount++] = pR;
    50 	
    51 	pR = new DBSIGLSPDependResource();
    52 	if(!pR)
    53 		CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
    54 	aStaticResourceDArray[iStaticResDependencyCount++] = pR;
    55 
    56 	pR = new DMLSHIGLSPDependResource();
    57 	if(!pR)
    58 		CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
    59 	aStaticResourceDArray[iStaticResDependencyCount++] = pR;
    60 
    61 	pR = new DBSHLGLSNDependResource();
    62 	if(!pR)
    63 		CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
    64 	aStaticResourceDArray[iStaticResDependencyCount++] = pR;
    65 
    66 	pR = new DMLSHLGLSNDependResource();
    67 	if(!pR)
    68 		CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
    69 	aStaticResourceDArray[iStaticResDependencyCount++] = pR;
    70 
    71 	//Establish resource dependencies
    72 	if(CreateResourceDependency(aStaticResourceDArray))
    73 		CLEAN_AND_RETURN(iStaticResDependencyCount, aStaticResourceDArray, KErrNoMemory)
    74 
    75 	iDependencyResources = aStaticResourceDArray;
    76 
    77 	aStaticResourceDCount = iStaticResDependencyCount;
    78 	return KErrNone;
    79 	}
    80 
    81 
    82 // This function establishes above dependency between static dependent resource
    83 TInt DSimulatedPowerResourceController::CreateResourceDependency(DStaticPowerResourceD** pResArray)
    84 	{
    85 	iNodeArray = new SNode[10];
    86 	SNode* pN1;
    87 	SNode* pN2;
    88 	iNodeCount = 0;
    89 
    90 	if(!iNodeArray)
    91 		return KErrNoMemory;
    92 	//Create Dependency between Resource A and Resource D 
    93 	pN1 = &iNodeArray[iNodeCount++];
    94 	pN2 = &iNodeArray[iNodeCount++];
    95 	CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[1], 1, 1)
    96 
    97 	//Create Dependency between Resource D and Resource F
    98 	//Trying to add with the same priority and check whether KErrAlreadyExists is returned.
    99 	pN1 = &iNodeArray[iNodeCount++];
   100 	pN2 = &iNodeArray[iNodeCount++];
   101 	pN1->iPriority = 1;																
   102 	pN1->iResource = pResArray[0];															
   103 	pN1->iPropagatedLevel = 0;																
   104 	pN1->iVisited = EFalse;															
   105 	
   106 	pN2->iPriority = 1;																
   107 	pN2->iResource = pResArray[2];																
   108 	pN2->iPropagatedLevel = 0;																
   109 	pN2->iVisited = EFalse;																	
   110 	pN2->iResource->AddNode(pN1);
   111 
   112 	TInt r = pN1->iResource->AddNode(pN2);
   113 	if(r != KErrAlreadyExists)
   114 		Kern::Fault("Power Resource Controller", __LINE__);
   115 
   116 	pN2->iPriority = 3;
   117 	r = pN1->iResource->AddNode(pN2);
   118 	if(r != KErrNone)
   119 		Kern::Fault("Power Resource Controller", __LINE__);
   120 
   121 	//Create Dependency between Resource D and Resource E
   122 	pN1 = &iNodeArray[iNodeCount++];
   123 	pN2 = &iNodeArray[iNodeCount++];
   124 	CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[0], pResArray[3], 3, 2)
   125 
   126 	//Create Dependency between Resource E and Resource C
   127 	pN1 = &iNodeArray[iNodeCount++];
   128 	pN2 = &iNodeArray[iNodeCount++];
   129 	CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[4], 1, 1)
   130 
   131 	//Create Dependency between Resource E and Resource G
   132 	pN1 = &iNodeArray[iNodeCount++];
   133 	pN2 = &iNodeArray[iNodeCount++];
   134 	CREATE_DEPENDENCY_BETWEEN_NODES(pN1, pN2, pResArray[3], pResArray[5], 1, 2)
   135 
   136 	return KErrNone;
   137 	}
   138 
   139 //Constructors of all resources
   140 _LIT(KDMLSLGLSPDependResource, "StaticDependResourceD");
   141 DMLSLGLSPDependResource::DMLSLGLSPDependResource() : DStaticPowerResourceD(KDMLSLGLSPDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
   142 	{
   143 	iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet;
   144 	NKern::LockSystem();
   145 	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
   146 	NKern::UnlockSystem();
   147 	}
   148 
   149 _LIT(KDMLSIGLSNDependResource, "StaticDependResourceA");
   150 DMLSIGLSNDependResource::DMLSIGLSNDependResource() : DStaticPowerResourceD(KDMLSIGLSNDependResource, -10), iMinLevel(-10), iMaxLevel(-20), iCurrentLevel(-10)
   151 	{
   152 	iFlags = KMultiLevel | KLongLatencySet | KSenseNegative;
   153 	NKern::LockSystem();
   154 	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
   155 	NKern::UnlockSystem();
   156 	}
   157 
   158 _LIT(KDBSIGLSPDependResource, "StaticDependResourceF");
   159 DBSIGLSPDependResource::DBSIGLSPDependResource() : DStaticPowerResourceD(KDBSIGLSPDependResource, 0), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
   160 	{
   161 	iFlags = KBinary | KLongLatencySet;
   162 	NKern::LockSystem();
   163 	iBlockTime = MIN_BLOCK_TIME  + Kern::Random() % MAX_BLOCK_TIME;
   164 	NKern::UnlockSystem();
   165 	}
   166 
   167 _LIT(KDMLSHIGLSPDependResource, "StaticDependResourceE");
   168 DMLSHIGLSPDependResource::DMLSHIGLSPDependResource() : DStaticPowerResourceD(KDMLSHIGLSPDependResource, 10), iMinLevel(10), iMaxLevel(75), iCurrentLevel(10)
   169 	{
   170 	// Make it a Instantaneous Resource.
   171 	iFlags = KMultiLevel | KShared;
   172 	NKern::LockSystem();
   173 	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
   174 	NKern::UnlockSystem();
   175 	}
   176 
   177 _LIT(KDBSHLGLSNDependResource, "StaticDependResourceC");
   178 DBSHLGLSNDependResource::DBSHLGLSNDependResource() : DStaticPowerResourceD(KDBSHLGLSNDependResource, 1), iMinLevel(1), iMaxLevel(0), iCurrentLevel(1)
   179 	{
   180 	iFlags = KBinary | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
   181 	NKern::LockSystem();
   182 	iBlockTime = MIN_BLOCK_TIME  + Kern::Random() % MAX_BLOCK_TIME;
   183 	NKern::UnlockSystem();
   184 	}
   185 
   186 _LIT(KDMLSHLGLSNDependResource, "StaticDependResourceG");
   187 DMLSHLGLSNDependResource::DMLSHLGLSNDependResource() : DStaticPowerResourceD(KDMLSHLGLSNDependResource, 75), iMinLevel(75), iMaxLevel(30), iCurrentLevel(75)
   188 	{
   189 	iFlags = KMultiLevel | KLongLatencyGet | KLongLatencySet | KShared | KSenseNegative;
   190 	NKern::LockSystem();
   191 	iBlockTime = MIN_BLOCK_TIME  + Kern::Random() % MAX_BLOCK_TIME;
   192 	NKern::UnlockSystem();
   193 	}
   194 
   195 _LIT(KDMLSHLGLSCDependResource, "DMLSHLGLSCDependResource");
   196 DMLSHLGLSCDependResource::DMLSHLGLSCDependResource() : DStaticPowerResourceD(KDMLSHLGLSCDependResource, -100), iMinLevel(-100), iMaxLevel(100), iCurrentLevel(-100)
   197 	{
   198 	iFlags = KMultiLevel;
   199 	NKern::LockSystem();
   200 	iBlockTime = MIN_BLOCK_TIME + Kern::Random() % MAX_BLOCK_TIME;
   201 	NKern::UnlockSystem();
   202 	}
   203 
   204 //Implementation of handle dependent state for all resources
   205 TChangePropagationStatus DMLSLGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt /*aDepState*/, TInt& /*aResState*/)
   206 	{
   207 	//This resources changes only when the client asks to change
   208 	return ENoChange;
   209 	}
   210 
   211 TChangePropagationStatus DMLSIGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
   212 	{
   213 	if(aDepState == -100)
   214 		{
   215 		aResState = iMinLevel;
   216 		return EChange;
   217 		}
   218 	if(aDepState < 0)
   219 		{
   220 		aResState = iCurrentLevel > -15 ? iCurrentLevel-1 : -15;
   221 		if(aResState == iCurrentLevel)
   222 			return ENoChange;
   223 		return EChange;
   224 		}
   225 	aResState = iCurrentLevel > iMaxLevel ? iCurrentLevel-1 : iMaxLevel;
   226 	if(aResState == iCurrentLevel)
   227 		return ENoChange;
   228 	return EChange;
   229 	}
   230 
   231 TChangePropagationStatus DBSIGLSPDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
   232 	{
   233 	if(aDepState == -100)
   234 		{
   235 		aResState = iMinLevel;
   236 		return EChange;
   237 		}
   238 	if(iCurrentLevel == E_ON)
   239 		return ENoChange;
   240 	aResState = iMaxLevel;
   241 	return EChange;
   242 	}
   243 
   244 TChangePropagationStatus DMLSHIGLSPDependResource::TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState)
   245 	{
   246 	if((aDepId & ID_INDEX_BIT_MASK) != 0x1)
   247 		return ENoChange;
   248 	if(aDepState == -100)
   249 		{
   250 		aResState = iMinLevel;
   251 		return EChange;
   252 		}
   253 	aResState = iCurrentLevel + 3;
   254 	if(aResState == iMaxLevel)
   255 		return ENoChange;
   256 	return EChange;
   257 	}
   258 
   259 TChangePropagationStatus DBSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
   260 	{
   261 	if(aDepState == 10)
   262 		{
   263 		aResState = iMinLevel;
   264 		return EChange;
   265 		}
   266 	if(iCurrentLevel == iMaxLevel)
   267 		return ENoChange;
   268 	aResState = iMaxLevel;
   269 	return EChange;
   270 	}
   271 
   272 TChangePropagationStatus DMLSHLGLSNDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
   273 	{
   274 	if(aDepState == 10)
   275 		{
   276 		aResState = iMinLevel;
   277 		return EChange;
   278 		}
   279 	aResState = iCurrentLevel - 2;
   280 	if(aResState == iMaxLevel)
   281 		return ENoChange;
   282 	return EChange;
   283 	}
   284 
   285 TChangePropagationStatus DMLSHLGLSCDependResource::TranslateDependentState(TInt /*aDepId*/, TInt aDepState, TInt& aResState)
   286 	{
   287 	if((aDepState == 10) && (iCurrentLevel == -100))
   288 		return ENoChange;
   289 	if(aDepState == 10)
   290 		{
   291 		aResState = -100;
   292 		return EChange;
   293 		}
   294 	if(iCurrentLevel)
   295 		aResState = iCurrentLevel + 20;
   296 	else
   297 		aResState = iCurrentLevel -20;
   298 	if(aResState > iMaxLevel)
   299 		aResState = iMaxLevel;
   300 	return EChange;
   301 	}
   302 
   303 	
   304 //Implementation of DoRequest functionality for all resource
   305 TInt DMLSLGLSPDependResource::DoRequest(TPowerRequest& req)
   306 	{
   307 	return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
   308 	}
   309 
   310 TInt DMLSIGLSNDependResource::DoRequest(TPowerRequest& req)
   311 	{
   312 	return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
   313 	}
   314 
   315 TInt DBSIGLSPDependResource::DoRequest(TPowerRequest& req)
   316 	{
   317 	return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
   318 	}
   319 
   320 TInt DMLSHIGLSPDependResource::DoRequest(TPowerRequest& req)
   321 	{
   322 	return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
   323 	}
   324 
   325 TInt DBSHLGLSNDependResource::DoRequest(TPowerRequest& req)
   326 	{
   327 	return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
   328 	}
   329 
   330 TInt DMLSHLGLSNDependResource::DoRequest(TPowerRequest& req)
   331 	{
   332 	return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
   333 	}
   334 
   335 TInt DMLSHLGLSCDependResource::DoRequest(TPowerRequest& req)
   336 	{
   337 	return GetControllerPtr()->ProcessEventResources(req, iCurrentLevel, iMaxLevel, iMinLevel, iDefaultLevel, iBlockTime);
   338 	}
   339 
   340 //Get info implementation of all resources.
   341 TInt DMLSLGLSPDependResource::GetInfo(TDes8* info) const
   342 	{
   343 	DStaticPowerResource::GetInfo((TDes8*)info);
   344 	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   345 	buf1->iMinLevel = iMinLevel;
   346 	buf1->iMaxLevel = iMaxLevel;
   347 	return KErrNone;
   348 	}
   349 
   350 TInt DMLSIGLSNDependResource::GetInfo(TDes8* info) const
   351 	{
   352 	DStaticPowerResource::GetInfo((TDes8*)info);
   353 	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   354 	buf1->iMinLevel = iMinLevel;
   355 	buf1->iMaxLevel = iMaxLevel;
   356 	return KErrNone;
   357 	}
   358 
   359 TInt DBSIGLSPDependResource::GetInfo(TDes8* info) const
   360 	{
   361 	DStaticPowerResource::GetInfo((TDes8*)info);
   362 	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   363 	buf1->iMinLevel = iMinLevel;
   364 	buf1->iMaxLevel = iMaxLevel;
   365 	return KErrNone;
   366 	}
   367 
   368 TInt DMLSHIGLSPDependResource::GetInfo(TDes8* info) const
   369 	{
   370 	DStaticPowerResource::GetInfo((TDes8*)info);
   371 	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   372 	buf1->iMinLevel = iMinLevel;
   373 	buf1->iMaxLevel = iMaxLevel;
   374 	return KErrNone;
   375 	}
   376 
   377 TInt DBSHLGLSNDependResource::GetInfo(TDes8* info) const
   378 	{
   379 	DStaticPowerResource::GetInfo((TDes8*)info);
   380 	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   381 	buf1->iMinLevel = iMinLevel;
   382 	buf1->iMaxLevel = iMaxLevel;
   383 	return KErrNone;
   384 	}
   385 
   386 TInt DMLSHLGLSNDependResource::GetInfo(TDes8* info) const
   387 	{
   388 	DStaticPowerResource::GetInfo((TDes8*)info);
   389 	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   390 	buf1->iMinLevel = iMinLevel;
   391 	buf1->iMaxLevel = iMaxLevel;
   392 	return KErrNone;
   393 	}
   394 
   395 TInt DMLSHLGLSCDependResource::GetInfo(TDes8* info) const
   396 	{
   397 	DStaticPowerResource::GetInfo((TDes8*)info);
   398 	TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
   399 	buf1->iMinLevel = iMinLevel;
   400 	buf1->iMaxLevel = iMaxLevel;
   401 	return KErrNone;
   402 	}