os/kernelhwsrv/kernel/eka/drivers/resourceman/resourcecontrol_extended.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\drivers\resourceman\resourcecontrol_extended.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <drivers/resourcecontrol.h>
sl@0
    19
		
sl@0
    20
extern DPowerResourceController* PowerResourceController;
sl@0
    21
/**
sl@0
    22
@internalComponent
sl@0
    23
@prototype 9.5
sl@0
    24
sl@0
    25
Reserves the client level from pool to be used for updating resource client level in dependency resource.
sl@0
    26
sl@0
    27
@param aCount Number of client levels to reserve from pool
sl@0
    28
sl@0
    29
@return KErrNone On success 
sl@0
    30
@return KErrNoMemory Not enough memory to grow the pool
sl@0
    31
*/
sl@0
    32
TInt DPowerResourceController::ReserveClientLevelPoolCount(TUint16 aCount)
sl@0
    33
	{
sl@0
    34
	if(aCount < iResourceLevelPoolCount) 
sl@0
    35
		iResourceLevelPoolCount = (TUint16)(iResourceLevelPoolCount - aCount);
sl@0
    36
	else
sl@0
    37
		{
sl@0
    38
		TUint allocCount = (iStaticResDependencyCount / 2) + aCount;
sl@0
    39
		// coverity[alloc_fn]
sl@0
    40
		SPowerResourceClientLevel* pCL = new SPowerResourceClientLevel[allocCount];
sl@0
    41
		if(!pCL)
sl@0
    42
			return KErrNoMemory;
sl@0
    43
		for(TUint count = 0;count<(TUint)(allocCount);count++)
sl@0
    44
			LIST_PUSH(iResourceLevelPool, &pCL[count], iNextInList);
sl@0
    45
		iResourceLevelPoolCount= (TUint16)(iResourceLevelPoolCount + (iStaticResDependencyCount / 2));
sl@0
    46
#ifdef PRM_INSTRUMENTATION_MACRO
sl@0
    47
		TUint size = allocCount * sizeof(SPowerResourceClientLevel);
sl@0
    48
		PRM_MEMORY_USAGE_TRACE
sl@0
    49
#endif
sl@0
    50
		}
sl@0
    51
	return KErrNone;
sl@0
    52
	}
sl@0
    53
sl@0
    54
/**
sl@0
    55
@internalComponent
sl@0
    56
@prototype 9.5
sl@0
    57
sl@0
    58
Return a client level object from pool.
sl@0
    59
sl@0
    60
@param aLevelPtr Pointer to update the client level object.
sl@0
    61
sl@0
    62
@return None 
sl@0
    63
*/
sl@0
    64
void DPowerResourceController::RemoveClientLevelFromPool(SPowerResourceClientLevel *&aLevelPtr)
sl@0
    65
	{
sl@0
    66
	LIST_POP(iResourceLevelPool, aLevelPtr, iNextInList);
sl@0
    67
	return;
sl@0
    68
	}
sl@0
    69
sl@0
    70
/**
sl@0
    71
Update with number of dependent resources for the specified resource. 
sl@0
    72
*/
sl@0
    73
TInt DPowerResourceController::GetNumDependentsForResource(TUint aResourceId, TUint* aNumResources)
sl@0
    74
	{
sl@0
    75
	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::GetNumDependentsForResource"));
sl@0
    76
	
sl@0
    77
	if(!(aResourceId & KIdMaskResourceWithDependencies))
sl@0
    78
		return KErrNotSupported;
sl@0
    79
	SNode* pN;
sl@0
    80
	if(aResourceId & KIdMaskDynamic)
sl@0
    81
		{
sl@0
    82
		DDynamicPowerResourceD* pDR = iDynamicResDependencyList[(TUint16)(aResourceId & ID_INDEX_BIT_MASK)];		
sl@0
    83
		if(!pDR)														
sl@0
    84
			return KErrNotFound;
sl@0
    85
		pN = pDR->iDependencyList;
sl@0
    86
		}
sl@0
    87
	else
sl@0
    88
		{
sl@0
    89
		if((aResourceId & ID_INDEX_BIT_MASK) > iStaticResDependencyCount)
sl@0
    90
			return KErrNotFound;
sl@0
    91
		DStaticPowerResourceD* pDR = iStaticResDependencyArray[(TUint16)(aResourceId & ID_INDEX_BIT_MASK) - 1];
sl@0
    92
		pN = pDR->iDependencyList;
sl@0
    93
		}
sl@0
    94
	*aNumResources = 0;
sl@0
    95
	for(;pN != NULL; pN = pN->iNext)
sl@0
    96
		(*aNumResources)++;
sl@0
    97
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetNumDependentsForResource"));
sl@0
    98
	return KErrNone;
sl@0
    99
	}
sl@0
   100
sl@0
   101
/**
sl@0
   102
Update the specified array with dependent resource Id's of the specified resource. 
sl@0
   103
*/
sl@0
   104
TInt DPowerResourceController::GetDependentsIdForResource(TUint aResourceId, TAny* aInfo, TUint* aNumDepResources)
sl@0
   105
	{
sl@0
   106
	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::GetDependentsIdForResource"));
sl@0
   107
sl@0
   108
	if(!(aResourceId & KIdMaskResourceWithDependencies))
sl@0
   109
		return KErrNotSupported;
sl@0
   110
	
sl@0
   111
	if(!aInfo || !*aNumDepResources)
sl@0
   112
		{
sl@0
   113
		return KErrArgument;
sl@0
   114
		}
sl@0
   115
sl@0
   116
	TDes8 *pInfo = (TDes8*)aInfo;
sl@0
   117
	
sl@0
   118
	if((TUint)(pInfo->MaxLength() - pInfo->Length()) < (sizeof(SResourceDependencyInfo)*(*aNumDepResources)))
sl@0
   119
		return KErrArgument;
sl@0
   120
     
sl@0
   121
	SResourceDependencyInfo sResDepInfo;
sl@0
   122
	
sl@0
   123
	SNode* pN;
sl@0
   124
	if(aResourceId & KIdMaskDynamic)
sl@0
   125
		{
sl@0
   126
		DDynamicPowerResourceD* pDR = iDynamicResDependencyList[(TUint16)(aResourceId & ID_INDEX_BIT_MASK)];
sl@0
   127
		if(!pDR)
sl@0
   128
			return KErrNotFound;
sl@0
   129
		pN = pDR->iDependencyList;
sl@0
   130
		}
sl@0
   131
	else
sl@0
   132
		{
sl@0
   133
		if((aResourceId & ID_INDEX_BIT_MASK) > iStaticResDependencyCount)
sl@0
   134
			return KErrNotFound;
sl@0
   135
		DStaticPowerResourceD* pDR = iStaticResDependencyArray[(TUint16)(aResourceId & ID_INDEX_BIT_MASK) -1];
sl@0
   136
		pN = pDR->iDependencyList;
sl@0
   137
		}
sl@0
   138
	TUint count = 0;
sl@0
   139
	TUint resCount = 0;
sl@0
   140
sl@0
   141
	for(; pN != NULL; pN = pN->iNext)
sl@0
   142
		{
sl@0
   143
		resCount++;
sl@0
   144
		if(count == *aNumDepResources)
sl@0
   145
			continue;
sl@0
   146
		sResDepInfo.iResourceId = pN->iResource->iResourceId;
sl@0
   147
		sResDepInfo.iDependencyPriority = pN->iPriority;
sl@0
   148
		pInfo->Append(TPckgC<SResourceDependencyInfo>(sResDepInfo));
sl@0
   149
		}
sl@0
   150
	*aNumDepResources = resCount;
sl@0
   151
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::GetDependentsIdForResource"));
sl@0
   152
	return KErrNone;
sl@0
   153
	}
sl@0
   154
sl@0
   155
/**
sl@0
   156
Registers resource dependency. This could be between 2 dynamic resource or between
sl@0
   157
dynamic and static resource.
sl@0
   158
*/
sl@0
   159
TInt DPowerResourceController::RegisterResourceDependency(SPowerResourceClient* aClientPtr, SResourceDependencyInfo* aInfo1, 
sl@0
   160
														              SResourceDependencyInfo* aInfo2)
sl@0
   161
	{
sl@0
   162
	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DExtendedResourceController::RegisterResourceDependency"));
sl@0
   163
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("ClientId = 0x%x, ResourceId1 = 0x%x, ResourceId2 = 0x%x", 
sl@0
   164
		                             aClientPtr->iClientId, aInfo1->iResourceId, aInfo2->iResourceId));
sl@0
   165
		                             
sl@0
   166
	if(iDfcQDependencyLock)
sl@0
   167
		{
sl@0
   168
		__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::RegisterResourceDependency::Resource In Use"));
sl@0
   169
		return KErrInUse;
sl@0
   170
		}
sl@0
   171
	
sl@0
   172
	TInt r = KErrNone;
sl@0
   173
	//One of the resource must be dynamic resource
sl@0
   174
	if(!(aInfo1->iResourceId & KIdMaskDynamic) && !(aInfo2->iResourceId & KIdMaskDynamic))
sl@0
   175
		return KErrNotSupported;
sl@0
   176
	//Both the resources should have dependency resource bit set in its id. 
sl@0
   177
	if(!(aInfo1->iResourceId & KIdMaskResourceWithDependencies) || !(aInfo2->iResourceId & KIdMaskResourceWithDependencies))
sl@0
   178
		return KErrNotSupported;
sl@0
   179
	
sl@0
   180
	DDynamicPowerResourceD* pR1 = NULL;
sl@0
   181
	DDynamicPowerResourceD* pR2 = NULL;
sl@0
   182
	SNode* pN1 = NULL;
sl@0
   183
	SNode* pN2 = NULL;
sl@0
   184
	//Retrieve resource1 from the corresponding list.
sl@0
   185
	if(aInfo1->iResourceId & KIdMaskDynamic)
sl@0
   186
		{
sl@0
   187
		pR1 = iDynamicResDependencyList[(TUint16)(aInfo1->iResourceId & ID_INDEX_BIT_MASK)];
sl@0
   188
		if(!pR1)
sl@0
   189
			return KErrNotFound;
sl@0
   190
		pN1 = pR1->iDependencyList;
sl@0
   191
		}
sl@0
   192
	else 
sl@0
   193
		{
sl@0
   194
		if((aInfo1->iResourceId & ID_INDEX_BIT_MASK) > iStaticResDependencyCount)
sl@0
   195
			return KErrNotFound;
sl@0
   196
		pR1 = (DDynamicPowerResourceD*)iStaticResDependencyArray[(TUint16)(aInfo1->iResourceId & ID_INDEX_BIT_MASK) - 1];
sl@0
   197
		pN1 = ((DStaticPowerResourceD*)pR1)->iDependencyList;
sl@0
   198
		}
sl@0
   199
	//Retrieve resource2 from the corresponding list.
sl@0
   200
	if(aInfo2->iResourceId & KIdMaskDynamic)
sl@0
   201
		{
sl@0
   202
		pR2 = iDynamicResDependencyList[(TUint16)(aInfo2->iResourceId & ID_INDEX_BIT_MASK)];
sl@0
   203
		if(!pR2)
sl@0
   204
			return KErrNotFound;
sl@0
   205
		pN2 = pR2->iDependencyList;
sl@0
   206
		}
sl@0
   207
	else
sl@0
   208
		{
sl@0
   209
		if((aInfo2->iResourceId & ID_INDEX_BIT_MASK) > iStaticResDependencyCount)
sl@0
   210
			return KErrNotFound;
sl@0
   211
		pR2 = (DDynamicPowerResourceD*)iStaticResDependencyArray[(TUint16)(aInfo2->iResourceId & ID_INDEX_BIT_MASK) - 1];
sl@0
   212
		pN2 = ((DStaticPowerResourceD*)pR2)->iDependencyList;
sl@0
   213
		}
sl@0
   214
sl@0
   215
	//Only long latency resource is allowed to have dependents.
sl@0
   216
	if(!pR1->LatencySet())
sl@0
   217
		pR1->iFlags |= KLongLatencySet;
sl@0
   218
	if(!pR2->LatencySet())
sl@0
   219
		pR2->iFlags |= KLongLatencySet;
sl@0
   220
	
sl@0
   221
	//Check for closed loop
sl@0
   222
	//NOTE: Panics, if any closed loop is encountered
sl@0
   223
	if(pN1)
sl@0
   224
		CheckForDependencyLoop((DStaticPowerResourceD*)pR1, pR1->iResourceId, pR2->iResourceId);
sl@0
   225
sl@0
   226
	if(pN2)
sl@0
   227
		CheckForDependencyLoop((DStaticPowerResourceD*)pR2, pR2->iResourceId, pR1->iResourceId);
sl@0
   228
sl@0
   229
	//Check whether the passed priority already exists.Code will return with KErrAlreadyExists, if it exists.
sl@0
   230
	CHECK_IF_PRIORITY_ALREADY_EXISTS(pN1, aInfo2->iDependencyPriority)
sl@0
   231
	CHECK_IF_PRIORITY_ALREADY_EXISTS(pN2, aInfo1->iDependencyPriority)
sl@0
   232
	UnLock();
sl@0
   233
	//Allocate nodes
sl@0
   234
	// coverity[alloc_fn]
sl@0
   235
	SNode* pSN1 = new (SNode);
sl@0
   236
	// coverity[alloc_fn]
sl@0
   237
	SNode* pSN2 = new (SNode);
sl@0
   238
	Lock();
sl@0
   239
	if(!pSN1 || !pSN2)
sl@0
   240
		return KErrNoMemory;
sl@0
   241
	//Add the link
sl@0
   242
	pSN1->iResource = (DStaticPowerResourceD*)pR1;
sl@0
   243
	pSN1->iPropagatedLevel = 0;
sl@0
   244
	pSN1->iPriority = aInfo1->iDependencyPriority;
sl@0
   245
	pSN1->iVisited = EFalse;
sl@0
   246
	pSN1->iNext = NULL;
sl@0
   247
sl@0
   248
	pSN2->iResource = (DStaticPowerResourceD*)pR2;
sl@0
   249
	pSN2->iPropagatedLevel = 0;
sl@0
   250
	pSN2->iPriority = aInfo2->iDependencyPriority;
sl@0
   251
	pSN2->iVisited = EFalse;
sl@0
   252
	pSN2->iNext = NULL;
sl@0
   253
sl@0
   254
	if(aInfo1->iResourceId & KIdMaskDynamic) //Dynamic resource
sl@0
   255
		// coverity[memory_leak]
sl@0
   256
		ADD_DEPENDENCY_NODE(pSN2, ((DDynamicPowerResourceD*)pR1)->iDependencyList)
sl@0
   257
	else
sl@0
   258
		((DStaticPowerResourceD*)pR1)->AddNode(pSN2);
sl@0
   259
	
sl@0
   260
	//Add the second node
sl@0
   261
	if(aInfo2->iResourceId & KIdMaskDynamic) //Dynamic resource
sl@0
   262
		// coverity[memory_leak]
sl@0
   263
		ADD_DEPENDENCY_NODE(pSN1, ((DDynamicPowerResourceD*)pR2)->iDependencyList)
sl@0
   264
	else
sl@0
   265
		((DStaticPowerResourceD*)pR2)->AddNode(pSN1);
sl@0
   266
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DExtendedResourceController::RegisterResourceDependency"));
sl@0
   267
#ifdef PRM_INSTRUMENTATION_MACRO
sl@0
   268
	PRM_REGISTER_RESOURCE_DEPENDENCY_TRACE
sl@0
   269
#endif
sl@0
   270
	return r;
sl@0
   271
	}
sl@0
   272
sl@0
   273
/**
sl@0
   274
Registers dynamic resource. 
sl@0
   275
*/
sl@0
   276
TInt DPowerResourceController::RegisterDynamicResource(SPowerResourceClient* aClientPtr, DDynamicPowerResource* aPDRes, 
sl@0
   277
													                 TUint* aDynamicResourceId)
sl@0
   278
	{
sl@0
   279
	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DExtendedResourceController::RegisterDynamicResource"));
sl@0
   280
	TInt r = KErrNone;
sl@0
   281
	//Check for dynamic resource
sl@0
   282
	if(!(aPDRes->iResourceId & KIdMaskDynamic))
sl@0
   283
		return KErrNotSupported;
sl@0
   284
	//check for count
sl@0
   285
	else if(aPDRes->LockCount() != 0) 
sl@0
   286
		return KErrAlreadyExists;
sl@0
   287
	
sl@0
   288
	TPowerRequest* req = (TPowerRequest*)&TPowerRequest::Get();
sl@0
   289
	req->ReqType() = TPowerRequest::ERegisterDynamicResource;
sl@0
   290
	req->Resource() = (DStaticPowerResource*)aPDRes;
sl@0
   291
	UnLock();
sl@0
   292
	req->SendReceive(iMsgQ);
sl@0
   293
	Lock();
sl@0
   294
	if(req->ReturnCode() == KErrNone)
sl@0
   295
		{
sl@0
   296
		*aDynamicResourceId = req->ResourceId();
sl@0
   297
		aPDRes-> iOwnerId = aClientPtr->iClientId;
sl@0
   298
		aPDRes->Lock();
sl@0
   299
		//Increment dynamic resource count in client
sl@0
   300
		aClientPtr->iDynamicResCount++;
sl@0
   301
		}
sl@0
   302
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DExtendedResourceController::RegisterDynamicResource, resource ID = 0x%x", 
sl@0
   303
		                                                                                  *aDynamicResourceId));
sl@0
   304
#ifdef PRM_INSTRUMENTATION_MACRO
sl@0
   305
	PRM_REGISTER_DYNAMIC_RESOURCE_TRACE
sl@0
   306
#endif
sl@0
   307
	return r;
sl@0
   308
	}
sl@0
   309
sl@0
   310
/**
sl@0
   311
Deregisters dynamic resource.
sl@0
   312
*/
sl@0
   313
TInt DPowerResourceController::DeregisterDynamicResource(SPowerResourceClient* aClientPtr, TUint aResourceId, 
sl@0
   314
														 TInt* aPDefLevel)
sl@0
   315
	{
sl@0
   316
	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DExtendedResourceController::DeregisterDynamicResource"));
sl@0
   317
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("aClientId = 0x%x, aDynamicResourceId = 0x%x, Default Level = %d", 
sl@0
   318
		                               aClientPtr->iClientId, aResourceId, aPDefLevel ? *aPDefLevel : 0));
sl@0
   319
	TInt r = KErrNone;
sl@0
   320
	DDynamicPowerResource* pDR = NULL;
sl@0
   321
	//Check for dynamic resource bit
sl@0
   322
	if(!(aResourceId & KIdMaskDynamic))
sl@0
   323
		return KErrNotSupported;
sl@0
   324
sl@0
   325
	//Get the resource from appropriate container
sl@0
   326
	if(aResourceId & KIdMaskResourceWithDependencies)
sl@0
   327
		{
sl@0
   328
		pDR = iDynamicResDependencyList[(TUint16)(aResourceId & ID_INDEX_BIT_MASK)];		
sl@0
   329
		if(!pDR)														
sl@0
   330
			return KErrNotFound;
sl@0
   331
		}
sl@0
   332
	else
sl@0
   333
		{
sl@0
   334
		pDR = iDynamicResourceList[(TUint16)(aResourceId & ID_INDEX_BIT_MASK)];		
sl@0
   335
		if(!pDR)														
sl@0
   336
			return KErrNotFound;
sl@0
   337
		}
sl@0
   338
	//Client which registered the dynamic resource is only allowed to deregister. 
sl@0
   339
	if(aClientPtr->iClientId != pDR->iOwnerId)
sl@0
   340
		{
sl@0
   341
		__KTRACE_OPT(KRESMANAGER, Kern::Printf("Client attempting to deregister a dynamic resource which is not the owner!"));
sl@0
   342
		return KErrAccessDenied;
sl@0
   343
		}
sl@0
   344
	// Don't allow to deregister if the some other operation is in progress or if the resource is shared and
sl@0
   345
	// another client holds requirement on this resource
sl@0
   346
	if((pDR->LockCount() > RESOURCE_NOT_IN_OPERATION) || pDR->InUse())
sl@0
   347
		{
sl@0
   348
		return KErrInUse;
sl@0
   349
		}
sl@0
   350
	TPowerRequest* req = (TPowerRequest*)&TPowerRequest::Get();
sl@0
   351
	req->ResourceCb() = NULL;
sl@0
   352
	req->ReturnCode() = KErrNone;
sl@0
   353
	req->RequiresChange() = EFalse;
sl@0
   354
	pDR->UnLock(); //Marked as deleted so that no other operation will be taking place.
sl@0
   355
	req->ReqType() = TPowerRequest::ESetDefaultLevel;
sl@0
   356
	//Handle dynamic resource with dependencies
sl@0
   357
	if(aResourceId & KIdMaskResourceWithDependencies)
sl@0
   358
		{
sl@0
   359
		for(SNode* pNode = ((DDynamicPowerResourceD*)pDR)->iDependencyList; pNode != NULL; pNode = pNode->iNext)
sl@0
   360
			{
sl@0
   361
			if((TUint)pNode->iResource->iLevelOwnerId == aResourceId)
sl@0
   362
				{
sl@0
   363
				req->ResourceId() = pNode->iResource->iResourceId;
sl@0
   364
				req->ClientId() = aResourceId;
sl@0
   365
				req->Level() = pNode->iResource->iCachedLevel;
sl@0
   366
				req->Resource() = pNode->iResource; 
sl@0
   367
				((DDynamicPowerResourceD*)(pNode->iResource))->Lock();
sl@0
   368
				UnLock();
sl@0
   369
				req->SendReceive(iMsgQDependency);
sl@0
   370
				Lock();
sl@0
   371
				}
sl@0
   372
			//Remove entry from resource dependency list
sl@0
   373
			for(SNode* pSN = pNode->iResource->iDependencyList; pSN != NULL; pSN = pSN->iNext)
sl@0
   374
				{
sl@0
   375
				if(pSN->iResource->iResourceId == aResourceId)
sl@0
   376
					{
sl@0
   377
					LIST_REMOVE(pNode->iResource->iDependencyList, pSN, iNext, SNode);
sl@0
   378
					UnLock();
sl@0
   379
					delete pSN;
sl@0
   380
					Lock();
sl@0
   381
					break;
sl@0
   382
					}
sl@0
   383
				}
sl@0
   384
			//Remove from dependent resource "resource client level" list
sl@0
   385
			for(SPowerResourceClientLevel* pL = ((DDynamicPowerResourceD*)(pNode->iResource))->iResourceClientList; 
sl@0
   386
			                                                                pL != NULL; pL = pL->iNextInList)
sl@0
   387
				{
sl@0
   388
				if(pL->iClientId == aResourceId)
sl@0
   389
					{
sl@0
   390
					LIST_REMOVE(((DDynamicPowerResourceD*)(pNode->iResource))->iResourceClientList, pL, iNextInList, 
sl@0
   391
						                                                                SPowerResourceClientLevel);
sl@0
   392
					//Move to free pool
sl@0
   393
					LIST_PUSH(iResourceLevelPool, pL, iNextInList);
sl@0
   394
					iResourceLevelPoolCount++;
sl@0
   395
					}
sl@0
   396
				}
sl@0
   397
			((DDynamicPowerResource*)(pNode->iResource))->UnLock();
sl@0
   398
			}
sl@0
   399
		//Move the resource to default level
sl@0
   400
		req->ClientId() = -1;
sl@0
   401
		req->ResourceId() = aResourceId;
sl@0
   402
		req->Resource() = pDR;
sl@0
   403
		if(aPDefLevel)
sl@0
   404
			req->Level() = *aPDefLevel; //Set the resource to the passed level
sl@0
   405
		else
sl@0
   406
			req->Level() = pDR->iDefaultLevel; //Set the resource level to default level
sl@0
   407
		UnLock();
sl@0
   408
		req->SendReceive(iMsgQDependency);
sl@0
   409
		}
sl@0
   410
	else
sl@0
   411
		{
sl@0
   412
		UnLock();
sl@0
   413
		req->ResourceId() = aResourceId;
sl@0
   414
		req->ClientId() = KDynamicResourceDeRegistering;
sl@0
   415
		req->Resource() = pDR;
sl@0
   416
		req->ResourceCb() = NULL;
sl@0
   417
		if(aPDefLevel)
sl@0
   418
			req->Level() = *aPDefLevel; //Set the resource to the passed level
sl@0
   419
		else
sl@0
   420
			req->Level() = pDR->iDefaultLevel; //Set the resource level to default level
sl@0
   421
		if(pDR->LatencySet())
sl@0
   422
			{
sl@0
   423
			r = req->SendReceive(iMsgQ);
sl@0
   424
			}
sl@0
   425
		else
sl@0
   426
			{
sl@0
   427
			//Call custom function for custom sense resource
sl@0
   428
			if(pDR->Sense() == DStaticPowerResource::ECustom)
sl@0
   429
				{
sl@0
   430
				if(!pDR->iCustomFunction)
sl@0
   431
					Panic(ECustomFunctionNotSet);
sl@0
   432
				pDR->iCustomFunction(req->ClientId(), *(aClientPtr->iName), aResourceId,
sl@0
   433
				                     EDynamicResourceDeregister, req->Level(),
sl@0
   434
				                     (TAny*)&pDR->iClientList, NULL);
sl@0
   435
				}
sl@0
   436
			//Not checking for error condition as the resource needs to be moved to default state
sl@0
   437
			if(aPDefLevel)
sl@0
   438
				{
sl@0
   439
				//If the resource change to requested level fails trying to change it to default level.
sl@0
   440
				req->ReqType() = TPowerRequest::EChange;
sl@0
   441
				r = pDR->DoRequest(*req);
sl@0
   442
				if(r != KErrNone)
sl@0
   443
					{
sl@0
   444
					req->ReqType() = TPowerRequest::ESetDefaultLevel;
sl@0
   445
					req->Level() = pDR->iDefaultLevel;
sl@0
   446
					pDR->DoRequest(*req);
sl@0
   447
					}
sl@0
   448
				}
sl@0
   449
			else
sl@0
   450
				pDR->DoRequest(*req);
sl@0
   451
			//Send notifications. Passing -2 in clientId to indicate that this dynamic resource is deregistering
sl@0
   452
			CompleteNotifications(KDynamicResourceDeRegistering, pDR, req->Level(),KErrNone, req->ClientId());
sl@0
   453
			}
sl@0
   454
		}
sl@0
   455
	Lock();
sl@0
   456
	//Remove client level
sl@0
   457
	SPowerResourceClientLevel *pCL;
sl@0
   458
	SPowerResourceClient *pC;
sl@0
   459
	for(SDblQueLink* pRC = pDR->iClientList.First(); pRC != &pDR->iClientList.iA; pRC = pRC->iNext)
sl@0
   460
		{
sl@0
   461
		pCL = (SPowerResourceClientLevel*)pRC;
sl@0
   462
		if(pCL->iClientId & USER_SIDE_CLIENT_BIT_MASK)
sl@0
   463
			pC = iUserSideClientList[(TUint16)(pCL->iClientId & ID_INDEX_BIT_MASK)];								
sl@0
   464
		else																										
sl@0
   465
			pC = iClientList[(TUint16)(pCL->iClientId & ID_INDEX_BIT_MASK)];										
sl@0
   466
		LIST_REMOVE(pC->iLevelList, pCL, iNextInList, SPowerResourceClientLevel);
sl@0
   467
		LIST_PUSH(iClientLevelPool, pCL, iNextInList);
sl@0
   468
		if(pC->iUnderFlowClCount > 0)
sl@0
   469
			{
sl@0
   470
			pC->iUnderFlowClCount--;
sl@0
   471
			iClientLevelPoolCount++;
sl@0
   472
			}
sl@0
   473
		else
sl@0
   474
			pC->iReservedCl++;
sl@0
   475
		}
sl@0
   476
	//Decrement dynamic resource count in client
sl@0
   477
	aClientPtr->iDynamicResCount--;
sl@0
   478
	if(aResourceId & KIdMaskResourceWithDependencies)
sl@0
   479
		{
sl@0
   480
		iDynamicResDependencyList.Remove((DDynamicPowerResourceD*)pDR, (TUint16)(pDR->iResourceId & ID_INDEX_BIT_MASK));
sl@0
   481
		iDynamicResDependencyCount--;
sl@0
   482
		}
sl@0
   483
	else
sl@0
   484
		{
sl@0
   485
		iDynamicResourceList.Remove(pDR, (TUint16)(pDR->iResourceId & ID_INDEX_BIT_MASK));
sl@0
   486
		iDynamicResourceCount--;
sl@0
   487
		}
sl@0
   488
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DExtendedResourceController::DeregisterDynamicResource"));
sl@0
   489
#ifdef PRM_INSTRUMENTATION_MACRO
sl@0
   490
	TInt level = req->Level();
sl@0
   491
	PRM_DEREGISTER_DYNAMIC_RESOURCE_TRACE
sl@0
   492
#endif
sl@0
   493
	return r;
sl@0
   494
	}
sl@0
   495
sl@0
   496
/**
sl@0
   497
@publishedPartner
sl@0
   498
@prototype 9.6
sl@0
   499
Default implementation, PSL re-implements this if features supported.
sl@0
   500
*/
sl@0
   501
TInt DPowerResourceController::DoRegisterStaticResourcesDependency(DStaticPowerResourceD**& aStaticResourceDArray, 
sl@0
   502
																    TUint16& aStaticResourceDCount)
sl@0
   503
	{
sl@0
   504
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("DExtendedResourceController::DoRegisterStaticResourcesDependency default implementation"));
sl@0
   505
	aStaticResourceDArray = NULL;
sl@0
   506
	aStaticResourceDCount = 0;
sl@0
   507
	return KErrNone;
sl@0
   508
	}
sl@0
   509
sl@0
   510
/**
sl@0
   511
This function checks for any closed loop dependency, if so panics.
sl@0
   512
*/
sl@0
   513
void DPowerResourceController::CheckForDependencyLoop(DStaticPowerResourceD* pR, TUint aParentResId, TUint aTargetResId)
sl@0
   514
	{
sl@0
   515
	SNode *pN;
sl@0
   516
sl@0
   517
	if(pR->iResourceId & KIdMaskDynamic)
sl@0
   518
		pN = ((DDynamicPowerResourceD*)pR)->iDependencyList;
sl@0
   519
	else
sl@0
   520
		pN = pR->iDependencyList;
sl@0
   521
sl@0
   522
	for(; pN != NULL; pN = pN->iNext)
sl@0
   523
		{
sl@0
   524
		if(pN->iResource->iResourceId == aParentResId)
sl@0
   525
			continue;
sl@0
   526
		if(pN->iVisited || (pN->iResource->iResourceId == aTargetResId))
sl@0
   527
			{
sl@0
   528
			__KTRACE_OPT(KRESMANAGER, Kern::Printf("Loop encountered\n"));
sl@0
   529
			DPowerResourceController::Panic(DPowerResourceController::EClosedLoopDependencies);
sl@0
   530
			}
sl@0
   531
		pN->iVisited = ETrue;
sl@0
   532
		CheckForDependencyLoop(pN->iResource, pR->iResourceId, aTargetResId);
sl@0
   533
		pN->iVisited = EFalse;
sl@0
   534
		}
sl@0
   535
	}
sl@0
   536
sl@0
   537
/**
sl@0
   538
This is called from the controller thread to handle the dependency resource state change operation.
sl@0
   539
*/
sl@0
   540
TInt DPowerResourceController::HandleDependencyResourceStateChange(SPowerResourceClient* pC, TPowerRequest& aRequest)
sl@0
   541
	{
sl@0
   542
	DStaticPowerResourceD* pR = (DStaticPowerResourceD*)aRequest.Resource();
sl@0
   543
	if(aRequest.ReqType() == TPowerRequest::EChange) //Handle resource change operation
sl@0
   544
		{
sl@0
   545
		if(aRequest.Resource()->Usage()) //Shared resource
sl@0
   546
			{
sl@0
   547
			Lock();
sl@0
   548
			aRequest.ReturnCode() = CheckLevelAndAddClient(pC, &aRequest);
sl@0
   549
			UnLock();
sl@0
   550
			if((aRequest.ReturnCode()!= KErrNone) || (!aRequest.RequiresChange()))
sl@0
   551
				{
sl@0
   552
				aRequest.Level() = pR->iCachedLevel; //If no change then send the current level back.
sl@0
   553
				return aRequest.ReturnCode();
sl@0
   554
				}
sl@0
   555
			}
sl@0
   556
		else if(pR->iClientList.IsEmpty())
sl@0
   557
			{
sl@0
   558
			Lock();
sl@0
   559
			if(pC->iReservedCl==0 && !iClientLevelPoolCount)
sl@0
   560
				{
sl@0
   561
				__KTRACE_OPT(KRESMANAGER, Kern::Printf("Reserved Client Level exhausted and its free pool empty"));
sl@0
   562
                aRequest.ReturnCode() = KErrUnderflow;
sl@0
   563
				UNLOCK_RETURN(KErrUnderflow);
sl@0
   564
				}
sl@0
   565
			SPowerResourceClientLevel* pSCL=NULL;
sl@0
   566
			LIST_POP(iClientLevelPool, pSCL, iNextInList);
sl@0
   567
			pSCL->iClientId=pC->iClientId;
sl@0
   568
			pSCL->iResourceId=aRequest.ResourceId();
sl@0
   569
			pSCL->iLevel=aRequest.Level();
sl@0
   570
			LIST_PUSH(pC->iLevelList, pSCL, iNextInList); //Add to client
sl@0
   571
			pR->iClientList.Add(pSCL); //Add in resource
sl@0
   572
			if(pC->iReservedCl==0)
sl@0
   573
				{
sl@0
   574
				iClientLevelPoolCount--;
sl@0
   575
				pC->iUnderFlowClCount++;
sl@0
   576
				}
sl@0
   577
            else
sl@0
   578
			   pC->iReservedCl--;
sl@0
   579
			if(pR->iCachedLevel == aRequest.Level())
sl@0
   580
				{
sl@0
   581
				pR->iLevelOwnerId = aRequest.ClientId();
sl@0
   582
				if(pR->iIdleListEntry)
sl@0
   583
					pR->iIdleListEntry->iLevelOwnerId = aRequest.ClientId();
sl@0
   584
				aRequest.ReturnCode() = KErrNone;
sl@0
   585
				UNLOCK_RETURN(KErrNone);
sl@0
   586
				}
sl@0
   587
			UnLock();
sl@0
   588
			}
sl@0
   589
		else
sl@0
   590
			{
sl@0
   591
			//Update the level in the client list.
sl@0
   592
			SPowerResourceClientLevel* pSCL = (SPowerResourceClientLevel*)pR->iClientList.First();
sl@0
   593
			pSCL->iLevel = aRequest.Level();
sl@0
   594
			}
sl@0
   595
	//Call appropriate resource's handle change propagation function
sl@0
   596
	if(pR->iResourceId & KIdMaskDynamic)
sl@0
   597
		aRequest.ReturnCode() = ((DDynamicPowerResourceD*)pR)->HandleChangePropagation(aRequest, EChangeStart, pC->iClientId, *(pC->iName));
sl@0
   598
	else
sl@0
   599
		aRequest.ReturnCode() = pR->HandleChangePropagation(aRequest, EChangeStart,pC->iClientId, *(pC->iName));
sl@0
   600
	return aRequest.ReturnCode();
sl@0
   601
	}
sl@0
   602
	if(aRequest.ClientId() == -1) //Special where the resource needs to set to default level, when dynamic resource deregisters
sl@0
   603
		{
sl@0
   604
		//If resource is asked to change to certain value, instead of default then 
sl@0
   605
		//try to set it to that value. If not able to set then try to set it to default level.
sl@0
   606
		if(aRequest.Level() != pR->iDefaultLevel)
sl@0
   607
			aRequest.ReqType() = TPowerRequest::EChange;
sl@0
   608
		aRequest.ReturnCode() = pR->DoRequest(aRequest);
sl@0
   609
		if((aRequest.ReturnCode() != KErrNone) && (aRequest.ReqType() == TPowerRequest::EChange))
sl@0
   610
			{
sl@0
   611
			aRequest.ReqType() = TPowerRequest::ESetDefaultLevel;
sl@0
   612
			aRequest.Level() = pR->iDefaultLevel;
sl@0
   613
			pR->DoRequest(aRequest);
sl@0
   614
			}
sl@0
   615
		//Set clientId to -2, indicating that the resource is deregistered.
sl@0
   616
		CompleteNotifications(KDynamicResourceDeRegistering, pR, aRequest.Level(), KErrNone, aRequest.ClientId());
sl@0
   617
		return KErrNone;
sl@0
   618
		}
sl@0
   619
	//Handle custom sense resource
sl@0
   620
	if(aRequest.Resource()->Sense() == DStaticPowerResource::ECustom)
sl@0
   621
		{
sl@0
   622
		if(pR->iResourceId & KIdMaskDynamic)
sl@0
   623
		    {
sl@0
   624
			aRequest.RequiresChange() = ((DDynamicPowerResourceD*)pR)->iDepCustomFunction(aRequest.ClientId(), *(pC->iName), aRequest.ResourceId(), 
sl@0
   625
			                                                                              EClientRelinquishLevel, aRequest.Level(), (TAny*)&pR->iClientList,
sl@0
   626
			                                                                              (TAny*)&((DDynamicPowerResourceD*)pR)->iResourceClientList, NULL);
sl@0
   627
			}
sl@0
   628
		else
sl@0
   629
		    {
sl@0
   630
			aRequest.RequiresChange() = pR->iDepCustomFunction(aRequest.ClientId(), *(pC->iName), aRequest.ResourceId(),
sl@0
   631
			                                                   EClientRelinquishLevel, aRequest.Level(), (TAny*)&pR->iClientList,
sl@0
   632
			                                                   (TAny*)&pR->iResourceClientList, NULL);
sl@0
   633
		    }
sl@0
   634
		}
sl@0
   635
	else
sl@0
   636
		{
sl@0
   637
		SPowerResourceClientLevel* pL = NULL;
sl@0
   638
		SPowerResourceClientLevel* pMCL = NULL;
sl@0
   639
		TInt maxLevel = KMinTInt;
sl@0
   640
		//Find the maximum level from client
sl@0
   641
		for(SDblQueLink* pCL = pR->iClientList.First(); pCL != &pR->iClientList.iA; pCL = pCL->iNext)
sl@0
   642
			{
sl@0
   643
			pL = (SPowerResourceClientLevel*)pCL;
sl@0
   644
			if(pL->iClientId == (TUint)aRequest.ClientId())
sl@0
   645
				continue;
sl@0
   646
			if(pMCL == NULL)
sl@0
   647
				{	
sl@0
   648
				maxLevel = pL->iLevel;
sl@0
   649
				pMCL = pL;
sl@0
   650
				continue;
sl@0
   651
				}
sl@0
   652
			if(((pR->Sense() == DStaticPowerResource::ENegative) && (pL->iLevel < maxLevel)) || 
sl@0
   653
				                    ((pR->Sense() == DStaticPowerResource::EPositive) && (pL->iLevel > maxLevel)))
sl@0
   654
				{
sl@0
   655
				maxLevel = pL->iLevel;
sl@0
   656
				pMCL = pL;
sl@0
   657
				}
sl@0
   658
			}	
sl@0
   659
		//Find the maximum level from resource client level
sl@0
   660
		if(pR->iResourceId & KIdMaskDynamic)
sl@0
   661
			pL = ((DDynamicPowerResourceD*)pR)->iResourceClientList;
sl@0
   662
		else
sl@0
   663
			pL = pR->iResourceClientList;
sl@0
   664
		for(; pL != NULL; pL = pL->iNextInList)
sl@0
   665
			{
sl@0
   666
			if(pL->iClientId == (TUint)aRequest.ClientId())
sl@0
   667
				continue;
sl@0
   668
			if(pMCL == NULL)
sl@0
   669
					{
sl@0
   670
				maxLevel = pL->iLevel;
sl@0
   671
				pMCL = pL;
sl@0
   672
				continue;
sl@0
   673
				}
sl@0
   674
			if(((pR->Sense() == DStaticPowerResource::ENegative) && (pL->iLevel < maxLevel)) || 
sl@0
   675
				           ((pR->Sense() == DStaticPowerResource::EPositive) && (pL->iLevel > maxLevel)))
sl@0
   676
				{
sl@0
   677
				maxLevel = pL->iLevel;
sl@0
   678
				pMCL = pL;
sl@0
   679
				}
sl@0
   680
			}
sl@0
   681
		if(pMCL == NULL)
sl@0
   682
			{
sl@0
   683
			aRequest.ClientId() = -1;
sl@0
   684
			aRequest.Level() = pR->iDefaultLevel;
sl@0
   685
			}
sl@0
   686
		else
sl@0
   687
			{
sl@0
   688
			aRequest.ClientId() = pMCL->iClientId;
sl@0
   689
			aRequest.Level() = maxLevel;
sl@0
   690
			}
sl@0
   691
		}
sl@0
   692
	if((aRequest.Level() == pR->iCachedLevel) && !aRequest.RequiresChange()) //No need to change the resource just update the owner 
sl@0
   693
		{
sl@0
   694
		pR->iLevelOwnerId = aRequest.ClientId();
sl@0
   695
		if(pR->iIdleListEntry)
sl@0
   696
			pR->iIdleListEntry->iLevelOwnerId = aRequest.ClientId();
sl@0
   697
		aRequest.ReturnCode() = KErrNone;
sl@0
   698
		return KErrNone;
sl@0
   699
		}
sl@0
   700
	aRequest.ReqType() = TPowerRequest::EChange; //Make the change otherwise PSL set to default level
sl@0
   701
sl@0
   702
	const TDesC8 *name;
sl@0
   703
	if(aRequest.ClientId() == -1)
sl@0
   704
		name = &KNoClient;
sl@0
   705
	else
sl@0
   706
		{
sl@0
   707
		if(aRequest.ClientId() & (1 << RESOURCE_BIT_IN_ID_CHECK))										
sl@0
   708
			{																							
sl@0
   709
			DStaticPowerResourceD* pResource;												
sl@0
   710
			if(aRequest.ClientId() & KIdMaskDynamic)										
sl@0
   711
				pResource = (DStaticPowerResourceD*)iDynamicResDependencyList[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)];
sl@0
   712
			else																						
sl@0
   713
				pResource = iStaticResDependencyArray[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)  - 1];	
sl@0
   714
			name = pResource->iName;																	
sl@0
   715
			}																							
sl@0
   716
		else																							
sl@0
   717
			{																							
sl@0
   718
			SPowerResourceClient* pClient;																
sl@0
   719
			if(aRequest.ClientId() & USER_SIDE_CLIENT_BIT_MASK)										
sl@0
   720
				pClient = iUserSideClientList[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)];	
sl@0
   721
			else // coverity[returned_null]
sl@0
   722
				pClient = iClientList[(TUint16)(aRequest.ClientId() & ID_INDEX_BIT_MASK)];			
sl@0
   723
			name = pClient->iName;				
sl@0
   724
			}
sl@0
   725
		}
sl@0
   726
sl@0
   727
	if(pR->iResourceId & KIdMaskDynamic)
sl@0
   728
		aRequest.ReturnCode() = ((DDynamicPowerResourceD*)pR)->HandleChangePropagation(aRequest, EChangeStart, aRequest.ClientId(), *name);
sl@0
   729
	else
sl@0
   730
		aRequest.ReturnCode() = pR->HandleChangePropagation(aRequest, EChangeStart, aRequest.ClientId(), *name);
sl@0
   731
	if(aRequest.ReturnCode() == KErrPermissionDenied) //Update the ownerId alone
sl@0
   732
		{
sl@0
   733
		pR->iLevelOwnerId = aRequest.ClientId();
sl@0
   734
		if(pR->iIdleListEntry)
sl@0
   735
			pR->iIdleListEntry->iLevelOwnerId = aRequest.ClientId();
sl@0
   736
		}
sl@0
   737
	return KErrNone;
sl@0
   738
	}
sl@0
   739
sl@0
   740
/**
sl@0
   741
Deregisters resource dependency.
sl@0
   742
*/
sl@0
   743
TInt DPowerResourceController::DeregisterResourceDependency(SPowerResourceClient* aClientPtr, TUint aResId1, TUint aResId2)
sl@0
   744
	{
sl@0
   745
	__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::DeregisterResourceDependency"));
sl@0
   746
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("ClientId = 0x%x, ResourceId1 = 0x%x, ResourceId2 = 0x%x", 
sl@0
   747
		                                                                  aClientPtr->iClientId, aResId1, aResId2));
sl@0
   748
	if(iDfcQDependencyLock)
sl@0
   749
		{
sl@0
   750
		__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::RegisterResourceDependency::Resource In Use"));
sl@0
   751
		UNLOCK_RETURN(KErrInUse);
sl@0
   752
		}
sl@0
   753
	DDynamicPowerResourceD *pDR1 = NULL;
sl@0
   754
	DDynamicPowerResourceD *pDR2 = NULL;
sl@0
   755
	SNode* pN1 = NULL;
sl@0
   756
	SNode* pN2 = NULL;
sl@0
   757
	SPowerResourceClientLevel* pCL1 = NULL;
sl@0
   758
	SPowerResourceClientLevel* pCL2 = NULL;
sl@0
   759
	//Get first resource from list
sl@0
   760
	if(!(aResId1 & KIdMaskResourceWithDependencies) || !(aResId2 & KIdMaskResourceWithDependencies))
sl@0
   761
		UNLOCK_RETURN(KErrAccessDenied);
sl@0
   762
sl@0
   763
	if(aResId1 & KIdMaskDynamic)
sl@0
   764
		{
sl@0
   765
		pDR1 = iDynamicResDependencyList[(TUint16)(aResId1 & ID_INDEX_BIT_MASK)];	
sl@0
   766
		if(!pDR1)															
sl@0
   767
			UNLOCK_RETURN(KErrNotFound);
sl@0
   768
		pN1 = pDR1->iDependencyList;
sl@0
   769
		pCL1 = pDR1->iResourceClientList;
sl@0
   770
		}
sl@0
   771
	else
sl@0
   772
		{
sl@0
   773
		if((aResId1 & ID_INDEX_BIT_MASK) > iStaticResDependencyCount)			
sl@0
   774
			UNLOCK_RETURN(KErrNotFound);			
sl@0
   775
		pDR1 = (DDynamicPowerResourceD*)iStaticResDependencyArray[(aResId1 & ID_INDEX_BIT_MASK) - 1];
sl@0
   776
		pN1 = ((DStaticPowerResourceD*)pDR1)->iDependencyList;
sl@0
   777
		pCL1 = ((DStaticPowerResourceD*)pDR1)->iResourceClientList;
sl@0
   778
		}
sl@0
   779
sl@0
   780
	//Get second resource from list
sl@0
   781
	if(aResId2 & KIdMaskDynamic)
sl@0
   782
		{
sl@0
   783
		pDR2 = iDynamicResDependencyList[(TUint16)(aResId2 & ID_INDEX_BIT_MASK)];	
sl@0
   784
		if(!pDR2)															
sl@0
   785
			UNLOCK_RETURN(KErrNotFound);
sl@0
   786
		pN2 = pDR2->iDependencyList;
sl@0
   787
		pCL2 = pDR2->iResourceClientList;
sl@0
   788
		}
sl@0
   789
	else
sl@0
   790
		{
sl@0
   791
		if((aResId2 & ID_INDEX_BIT_MASK)> iStaticResDependencyCount)			
sl@0
   792
				UNLOCK_RETURN(KErrNotFound);			
sl@0
   793
		pDR2 = (DDynamicPowerResourceD*)iStaticResDependencyArray[(TUint16)(aResId2 & ID_INDEX_BIT_MASK) - 1];
sl@0
   794
		pN2 = ((DStaticPowerResourceD*)pDR2)->iDependencyList;
sl@0
   795
		pCL2 = ((DStaticPowerResourceD*)pDR2)->iResourceClientList;
sl@0
   796
		}
sl@0
   797
sl@0
   798
	//Check whether dependency exist between the two
sl@0
   799
	SNode* pN = NULL;
sl@0
   800
	for(pN = pN1; pN != NULL; pN = pN->iNext)
sl@0
   801
		{
sl@0
   802
		if(pN->iResource->iResourceId == pDR2->iResourceId)
sl@0
   803
			break;
sl@0
   804
		}
sl@0
   805
	if(pN == NULL)
sl@0
   806
		UNLOCK_RETURN(KErrNotFound);
sl@0
   807
	pN1 = pN; //Storing for later use.
sl@0
   808
	for(pN = pN2; pN != NULL; pN = pN->iNext)
sl@0
   809
		{
sl@0
   810
		if(pN->iResource->iResourceId == pDR1->iResourceId)
sl@0
   811
			break;
sl@0
   812
		}
sl@0
   813
	if(pN == NULL)
sl@0
   814
		return KErrNotFound;
sl@0
   815
	pN2 = pN; //Storing for later use
sl@0
   816
	//Remove the dependency link from both the resource
sl@0
   817
	if(aResId1 & KIdMaskDynamic)
sl@0
   818
		{
sl@0
   819
		LIST_REMOVE(pDR1->iDependencyList, pN1, iNext, SNode);
sl@0
   820
		}
sl@0
   821
	else
sl@0
   822
		{
sl@0
   823
		LIST_REMOVE(((DStaticPowerResourceD*)pDR1)->iDependencyList, pN1, iNext, SNode);
sl@0
   824
		}
sl@0
   825
sl@0
   826
	if(aResId2 & KIdMaskDynamic)
sl@0
   827
		{	
sl@0
   828
		LIST_REMOVE(pDR2->iDependencyList, pN2, iNext, SNode);
sl@0
   829
		}
sl@0
   830
	else
sl@0
   831
		{	
sl@0
   832
		LIST_REMOVE(((DStaticPowerResourceD*)pDR2)->iDependencyList, pN2, iNext, SNode);
sl@0
   833
		}
sl@0
   834
sl@0
   835
	//Remove the resource client level from each resource
sl@0
   836
	for(; pCL1 != NULL; pCL1 = pCL1->iNextInList)
sl@0
   837
		{
sl@0
   838
		if(pCL1->iClientId == pDR2->iResourceId)
sl@0
   839
			{
sl@0
   840
			if(aResId1 & KIdMaskDynamic)
sl@0
   841
				{	
sl@0
   842
				LIST_REMOVE(pDR1->iResourceClientList, pCL1, iNextInList, SPowerResourceClientLevel);
sl@0
   843
				}	
sl@0
   844
			else
sl@0
   845
				{
sl@0
   846
				LIST_REMOVE(((DStaticPowerResourceD*)pDR1)->iResourceClientList, pCL1, iNextInList, 
sl@0
   847
					                                            SPowerResourceClientLevel);
sl@0
   848
				}
sl@0
   849
			LIST_PUSH(iResourceLevelPool, pCL1, iNextInList);
sl@0
   850
			iResourceLevelPoolCount++;
sl@0
   851
			break;
sl@0
   852
			}
sl@0
   853
		}
sl@0
   854
	for(; pCL2 != NULL; pCL2 = pCL2->iNextInList)
sl@0
   855
		{
sl@0
   856
		if(pCL2->iClientId == pDR1->iResourceId)
sl@0
   857
			{
sl@0
   858
			if(aResId2 & KIdMaskDynamic)
sl@0
   859
				{	
sl@0
   860
				LIST_REMOVE(pDR2->iResourceClientList, pCL2, iNextInList, SPowerResourceClientLevel);
sl@0
   861
				}
sl@0
   862
			else
sl@0
   863
				{
sl@0
   864
				LIST_REMOVE(((DStaticPowerResourceD*)pDR2)->iResourceClientList, pCL2, iNextInList, 
sl@0
   865
					                                              SPowerResourceClientLevel);
sl@0
   866
				}
sl@0
   867
			LIST_PUSH(iResourceLevelPool, pCL2, iNextInList);
sl@0
   868
			iResourceLevelPoolCount++;
sl@0
   869
			break;
sl@0
   870
			}
sl@0
   871
		}
sl@0
   872
sl@0
   873
	TPowerRequest* req = (TPowerRequest*)&TPowerRequest::Get();
sl@0
   874
	req->ResourceCb() = NULL;
sl@0
   875
	req->ReqType() = TPowerRequest::ESetDefaultLevel;
sl@0
   876
	req->RequiresChange() = EFalse;
sl@0
   877
	req->ReturnCode() = KErrNone;
sl@0
   878
	if((TUint)pDR1->iLevelOwnerId == pDR2->iResourceId)
sl@0
   879
		{
sl@0
   880
		//Ask to change to default level. Process this in the RC thread;
sl@0
   881
		req->ResourceId() = pDR1->iResourceId;
sl@0
   882
		req->ClientId() = pDR2->iResourceId;
sl@0
   883
		req->Resource() = pDR1;
sl@0
   884
		req->Level() = pDR1->iDefaultLevel;
sl@0
   885
		if(aResId1 & KIdMaskDynamic)
sl@0
   886
			pDR1->Lock();
sl@0
   887
		UnLock();
sl@0
   888
		req->SendReceive(iMsgQDependency);
sl@0
   889
		Lock();
sl@0
   890
		if(aResId1 & KIdMaskDynamic)
sl@0
   891
			pDR1->UnLock();
sl@0
   892
		}
sl@0
   893
	if((TUint)pDR2->iLevelOwnerId == pDR1->iResourceId)
sl@0
   894
		{
sl@0
   895
		//Ask to change to default level. Process this in the RC thread.
sl@0
   896
		req->ResourceId() = pDR2->iResourceId;
sl@0
   897
		req->ClientId() = pDR1->iResourceId;
sl@0
   898
		req->Resource() = pDR2;
sl@0
   899
		req->Level() = pDR2->iDefaultLevel;
sl@0
   900
		if(aResId2 & KIdMaskDynamic)
sl@0
   901
			pDR2->Lock();
sl@0
   902
		UnLock();
sl@0
   903
		req->SendReceive(iMsgQDependency);
sl@0
   904
		Lock();
sl@0
   905
		if(aResId2 & KIdMaskDynamic)
sl@0
   906
			pDR2->UnLock();
sl@0
   907
		}
sl@0
   908
	__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::DeregisterResourceDependency"));
sl@0
   909
#ifdef PRM_INSTRUMENTATION_MACRO
sl@0
   910
	PRM_DEREGISTER_RESOURCE_DEPENDENCY_TRACE
sl@0
   911
#endif
sl@0
   912
	UnLock();
sl@0
   913
	delete pN1;
sl@0
   914
	delete pN2;
sl@0
   915
	return KErrNone;
sl@0
   916
	}
sl@0
   917
sl@0
   918
/**
sl@0
   919
This function takes care of resource state change of static dependency resource.
sl@0
   920
This propagates the change to all of its dependents.
sl@0
   921
This function takes Originator name and id as parameter as this needs to be passed for custom sense function.
sl@0
   922
*/
sl@0
   923
TInt DStaticPowerResourceD::HandleChangePropagation(TPowerRequest aRequest, TPropagation aProp, TUint aOriginatorId, const TDesC8& aOriginatorName)
sl@0
   924
	{
sl@0
   925
	TInt result = KErrNone;
sl@0
   926
	result = PowerResourceController->HandleResourceChange(aRequest, aProp, aOriginatorId, aOriginatorName, this);
sl@0
   927
	return result;
sl@0
   928
	}
sl@0
   929
//Function to change the resource state of dependency resource. 
sl@0
   930
TInt DPowerResourceController::HandleResourceChange(TPowerRequest &aRequest, TPropagation aProp, TUint aOriginatorId, 
sl@0
   931
													const TDesC8& aOriginatorName, DStaticPowerResourceD* aResource)
sl@0
   932
	{
sl@0
   933
	static TUint16 clientLevelCount = 0;
sl@0
   934
	DStaticPowerResourceD* pDR = (DStaticPowerResourceD*)aRequest.Resource();
sl@0
   935
	DStaticPowerResourceD* pDepRes = NULL;
sl@0
   936
	SNode* dependencyList = NULL;
sl@0
   937
	TPowerRequest depRequest;
sl@0
   938
	TInt result = KErrNone;
sl@0
   939
	TInt resState;
sl@0
   940
	depRequest.ReqType() = TPowerRequest::EChange;
sl@0
   941
	depRequest.ResourceCb() = NULL;
sl@0
   942
	depRequest.ReturnCode() = KErrNone;
sl@0
   943
	depRequest.RequiresChange() = EFalse;
sl@0
   944
sl@0
   945
	if(pDR->iResourceId & KIdMaskDynamic)
sl@0
   946
		dependencyList = ((DDynamicPowerResourceD*)pDR)->iDependencyList;
sl@0
   947
	else
sl@0
   948
		dependencyList = pDR->iDependencyList;
sl@0
   949
	switch(aProp)																									
sl@0
   950
		{																											
sl@0
   951
		case EChangeStart:																							
sl@0
   952
			{
sl@0
   953
			if(!dependencyList) /*No dependents so change state of the resource*/
sl@0
   954
				{																									
sl@0
   955
				aRequest.ReturnCode() = pDR->DoRequest(aRequest);													
sl@0
   956
				if(aRequest.ReturnCode() == KErrNone)																
sl@0
   957
					{																								
sl@0
   958
					aResource->iCachedLevel = aRequest.Level();																
sl@0
   959
					aResource->iLevelOwnerId = aRequest.ClientId();															
sl@0
   960
					if(aResource->iIdleListEntry)																				
sl@0
   961
						{																							
sl@0
   962
						aResource->iIdleListEntry->iCurrentLevel = aRequest.Level();											
sl@0
   963
						aResource->iIdleListEntry->iLevelOwnerId = aRequest.ClientId();										
sl@0
   964
						}			
sl@0
   965
					CompleteNotifications(aRequest.ClientId(), pDR,									
sl@0
   966
							aRequest.Level(), aRequest.ReturnCode(), aRequest.ClientId());							
sl@0
   967
					}																								
sl@0
   968
					break;																		
sl@0
   969
				}					
sl@0
   970
			depRequest.ResourceId() = aRequest.ResourceId();														
sl@0
   971
			depRequest.ClientId() = aRequest.ResourceId();															
sl@0
   972
			depRequest.Level() = aRequest.Level();																	
sl@0
   973
			depRequest.Resource() = pDR;
sl@0
   974
			result = pDR->HandleChangePropagation(depRequest, ECheckChangeAllowed, aOriginatorId, aOriginatorName);	
sl@0
   975
			if(result != KErrNone)																					
sl@0
   976
				return result;																						
sl@0
   977
			/*Adjust resource client level*/																		
sl@0
   978
			if(clientLevelCount)																					
sl@0
   979
				{					
sl@0
   980
				result = ReserveClientLevelPoolCount(clientLevelCount);								
sl@0
   981
				if(result != KErrNone)																				
sl@0
   982
					return result;																					
sl@0
   983
				}																									
sl@0
   984
			/*Resource change of dependents */																		
sl@0
   985
			pDR->HandleChangePropagation(aRequest, ERequestStateChange, aOriginatorId, aOriginatorName);				
sl@0
   986
			/*Notification to dependents */																			
sl@0
   987
			pDR->HandleChangePropagation(aRequest, EIssueNotifications, aOriginatorId, aOriginatorName);				
sl@0
   988
			break;																									
sl@0
   989
			}																										
sl@0
   990
		case ECheckChangeAllowed:																					
sl@0
   991
			{																										
sl@0
   992
			TChangePropagationStatus status;																		
sl@0
   993
			for(SNode* depNode = dependencyList; depNode != NULL; depNode = depNode->iNext)					
sl@0
   994
				{																									
sl@0
   995
				pDepRes = depNode->iResource;													
sl@0
   996
				if((aRequest.ClientId() & KIdMaskResourceWithDependencies) &&										
sl@0
   997
						(pDepRes->iResourceId == (TUint)aRequest.ClientId()))										
sl@0
   998
					continue;	
sl@0
   999
				/*Resource need not change if it is already in that state, so continue with							
sl@0
  1000
						another dependent state.*/																	
sl@0
  1001
				if(pDepRes->iResourceId & KIdMaskDynamic)															
sl@0
  1002
					status = ((DDynamicPowerResourceD*)pDepRes)->TranslateDependentState(aRequest.ResourceId(),		
sl@0
  1003
																				aRequest.Level(), resState);		
sl@0
  1004
				else																								
sl@0
  1005
					status = ((DStaticPowerResourceD*)pDepRes)->TranslateDependentState(aRequest.ResourceId(),		
sl@0
  1006
																					aRequest.Level(), resState);	
sl@0
  1007
				if((status == ENoChange) || (pDepRes->iCachedLevel == resState))									
sl@0
  1008
					{																								
sl@0
  1009
					depNode->iRequiresChange = EFalse;																
sl@0
  1010
					continue;																						
sl@0
  1011
					}																								
sl@0
  1012
				if(status == EChangeNotAccepted)																	
sl@0
  1013
					return KErrPermissionDenied;	
sl@0
  1014
				depRequest.ResourceId() = pDepRes->iResourceId;														
sl@0
  1015
				depRequest.ClientId() = aRequest.ResourceId(); /*ID of the dependent resource */					
sl@0
  1016
				depRequest.Level() = resState;																		
sl@0
  1017
				depRequest.Resource() = pDepRes;		
sl@0
  1018
				/*Check resource client list and resource list to see whether change is allowed.*/					
sl@0
  1019
				if(pDepRes->Sense() == DStaticPowerResource::ECustom)												
sl@0
  1020
					{																								
sl@0
  1021
					/*Call custom function to check whether change is allowed.*/									
sl@0
  1022
					if(pDepRes->iResourceId & KIdMaskDynamic)														
sl@0
  1023
						depRequest.RequiresChange() = ((DDynamicPowerResourceD*)pDepRes)->iDepCustomFunction(depRequest.ClientId(),	
sl@0
  1024
							aOriginatorName, depRequest.ResourceId(), EClientRequestLevel, depRequest.Level(), (TAny*)&pDepRes->iClientList,		
sl@0
  1025
									(TAny*)&((DDynamicPowerResourceD*)pDepRes)->iResourceClientList, NULL);				
sl@0
  1026
					else																							
sl@0
  1027
						depRequest.RequiresChange() = ((DStaticPowerResourceD*)pDepRes)->iDepCustomFunction(depRequest.ClientId(),		
sl@0
  1028
							aOriginatorName, depRequest.ResourceId(), EClientRequestLevel, depRequest.Level(), (TAny*)&pDepRes->iClientList,		
sl@0
  1029
									(TAny*)&((DStaticPowerResourceD*)pDepRes)->iResourceClientList, NULL);				
sl@0
  1030
					if(!depRequest.RequiresChange())																
sl@0
  1031
						return KErrPermissionDenied;																
sl@0
  1032
					}						
sl@0
  1033
				SPowerResourceClientLevel*pN=NULL;																	
sl@0
  1034
				for(SDblQueLink* pNL=pDepRes->iClientList.First();pNL!=&pDepRes->iClientList.iA; pNL=pNL->iNext)	
sl@0
  1035
					{																								
sl@0
  1036
					pN = (SPowerResourceClientLevel*)pNL;															
sl@0
  1037
					if(pDepRes->Sense() == DStaticPowerResource::EPositive)											
sl@0
  1038
						{																							
sl@0
  1039
						if(pN->iLevel > depRequest.Level())															
sl@0
  1040
							return KErrPermissionDenied;															
sl@0
  1041
						}																							
sl@0
  1042
					else if(pDepRes->Sense() == DStaticPowerResource::ENegative)									
sl@0
  1043
						{																							
sl@0
  1044
						if(pN->iLevel < depRequest.Level())															
sl@0
  1045
							return KErrPermissionDenied;															
sl@0
  1046
						}																							
sl@0
  1047
					}																								
sl@0
  1048
				/*check through the resource client level */														
sl@0
  1049
				SPowerResourceClientLevel*pCL = NULL;																
sl@0
  1050
				if(pDepRes->iResourceId & KIdMaskDynamic)															
sl@0
  1051
					pCL = ((DDynamicPowerResourceD*)pDepRes)->iResourceClientList;									
sl@0
  1052
				else																								
sl@0
  1053
					pCL = ((DStaticPowerResourceD*)pDepRes)->iResourceClientList;									
sl@0
  1054
				for(; pCL != NULL; pCL = pCL->iNextInList)															
sl@0
  1055
					{																								
sl@0
  1056
					if(pCL->iClientId == pDR->iResourceId)															
sl@0
  1057
						break;																						
sl@0
  1058
					}																								
sl@0
  1059
				if(!pCL)																							
sl@0
  1060
					clientLevelCount++;																				
sl@0
  1061
				/*check dependent resource client list & resource list to see whether change is allowed */			
sl@0
  1062
				if(pDepRes->iResourceId & KIdMaskDynamic)															
sl@0
  1063
					result = ((DDynamicPowerResourceD*)pDepRes)->HandleChangePropagation(depRequest,				
sl@0
  1064
																ECheckChangeAllowed, aOriginatorId, aOriginatorName);	
sl@0
  1065
				else																								
sl@0
  1066
					result = ((DStaticPowerResourceD*)pDepRes)->HandleChangePropagation(depRequest,					
sl@0
  1067
											ECheckChangeAllowed, aOriginatorId, aOriginatorName);						
sl@0
  1068
				if(result != KErrNone)																				
sl@0
  1069
					return result;																					
sl@0
  1070
				depNode->iPropagatedLevel = resState;																
sl@0
  1071
				depNode->iRequiresChange = ETrue;																	
sl@0
  1072
				}																									
sl@0
  1073
			break;																									
sl@0
  1074
			}																										
sl@0
  1075
		case ERequestStateChange:																					
sl@0
  1076
			{																										
sl@0
  1077
			SPowerResourceClientLevel* pCL = NULL;																	
sl@0
  1078
			for(SNode* depNode = dependencyList; depNode != NULL; depNode = depNode->iNext)					
sl@0
  1079
				{																									
sl@0
  1080
				pDepRes = depNode->iResource;													
sl@0
  1081
				if((!depNode->iRequiresChange) || (pDepRes->iResourceId == (TUint)aRequest.ClientId()))				
sl@0
  1082
					continue;																						
sl@0
  1083
				depRequest.ResourceId() = pDepRes->iResourceId;														
sl@0
  1084
				depRequest.ClientId() = aRequest.ResourceId();														
sl@0
  1085
				depRequest.Level() = depNode->iPropagatedLevel;														
sl@0
  1086
				depRequest.Resource() = pDepRes;									
sl@0
  1087
				if(pDepRes->iResourceId & KIdMaskDynamic)															
sl@0
  1088
					((DDynamicPowerResourceD*)pDepRes)->HandleChangePropagation(depRequest, ERequestStateChange,	
sl@0
  1089
																					aOriginatorId, aOriginatorName);	
sl@0
  1090
				else																								
sl@0
  1091
					((DStaticPowerResourceD*)pDepRes)->HandleChangePropagation(depRequest, ERequestStateChange,		
sl@0
  1092
																					aOriginatorId, aOriginatorName);	
sl@0
  1093
				/*Update level if resource client level is already present for this resource.*/						
sl@0
  1094
				if(pDepRes->iResourceId & KIdMaskDynamic)															
sl@0
  1095
					pCL = ((DDynamicPowerResourceD*)pDepRes)->iResourceClientList;									
sl@0
  1096
				else																								
sl@0
  1097
					pCL = ((DStaticPowerResourceD*)pDepRes)->iResourceClientList;									
sl@0
  1098
				for(; pCL != NULL; pCL = pCL->iNextInList)															
sl@0
  1099
					{																								
sl@0
  1100
					if(pCL->iClientId == pDR->iResourceId)															
sl@0
  1101
						{																							
sl@0
  1102
						pCL->iLevel = depNode->iPropagatedLevel;													
sl@0
  1103
						break;																						
sl@0
  1104
						}																							
sl@0
  1105
					}																								
sl@0
  1106
				if(!pCL) /*Create a new resource client level*/														
sl@0
  1107
					{																								
sl@0
  1108
					RemoveClientLevelFromPool(pCL);													
sl@0
  1109
					pCL->iClientId = pDR->iResourceId;																
sl@0
  1110
					pCL->iResourceId = pDepRes->iResourceId;														
sl@0
  1111
					pCL->iLevel = depNode->iPropagatedLevel;														
sl@0
  1112
					if(pDepRes->iResourceId & KIdMaskDynamic)														
sl@0
  1113
						{																							
sl@0
  1114
						LIST_PUSH(((DDynamicPowerResourceD*)pDepRes)->iResourceClientList, pCL, iNextInList);		
sl@0
  1115
						}																							
sl@0
  1116
					else																							
sl@0
  1117
						{																							
sl@0
  1118
						LIST_PUSH(((DStaticPowerResourceD*)pDepRes)->iResourceClientList, pCL, iNextInList);		
sl@0
  1119
						}																							
sl@0
  1120
					clientLevelCount--;																				
sl@0
  1121
					}																								
sl@0
  1122
				}	
sl@0
  1123
#ifdef PRM_INSTRUMENTATION_MACRO			
sl@0
  1124
			if(aRequest.ClientId() & KIdMaskResourceWithDependencies)								
sl@0
  1125
				{																									
sl@0
  1126
				SPowerResourceClient res;																			
sl@0
  1127
				SPowerResourceClient* pC = &res;																	
sl@0
  1128
				pC->iClientId = aRequest.ClientId();																
sl@0
  1129
				pC->iName = &KParentResource;																		
sl@0
  1130
				DStaticPowerResource*pR = (DStaticPowerResource*)pDR;												
sl@0
  1131
				TUint aResourceId = pDR->iResourceId;																
sl@0
  1132
				TInt aNewState = aRequest.Level();																	
sl@0
  1133
				PRM_CLIENT_CHANGE_STATE_START_TRACE																	
sl@0
  1134
				}																									
sl@0
  1135
#endif
sl@0
  1136
				aResource->DoRequest(aRequest);																				
sl@0
  1137
#ifdef PRM_INSTRUMENTATION_MACRO
sl@0
  1138
			if(aRequest.ClientId() & KIdMaskResourceWithDependencies)								
sl@0
  1139
				{																									
sl@0
  1140
				SPowerResourceClient res;																			
sl@0
  1141
				SPowerResourceClient* pC = &res;																	
sl@0
  1142
				pC->iClientId = aRequest.ClientId();																
sl@0
  1143
				pC->iName = &KParentResource;																		
sl@0
  1144
				DStaticPowerResource*pR = (DStaticPowerResource*)pDR;												
sl@0
  1145
				TUint aResourceId = pDR->iResourceId;																
sl@0
  1146
				TInt aNewState = aRequest.Level();																	
sl@0
  1147
				TInt r = KErrNone;																					
sl@0
  1148
				PRM_CLIENT_CHANGE_STATE_END_TRACE																	
sl@0
  1149
				}													
sl@0
  1150
#endif												
sl@0
  1151
			pDR->iCachedLevel = aRequest.Level();																	
sl@0
  1152
			pDR->iLevelOwnerId = aRequest.ClientId();																
sl@0
  1153
			if(pDR->iIdleListEntry)																					
sl@0
  1154
				{																									
sl@0
  1155
				pDR->iIdleListEntry->iCurrentLevel = aRequest.Level();												
sl@0
  1156
				pDR->iIdleListEntry->iLevelOwnerId = aRequest.ClientId();											
sl@0
  1157
				}									
sl@0
  1158
			break;																									
sl@0
  1159
			}																										
sl@0
  1160
		case EIssueNotifications:																					
sl@0
  1161
			{																										
sl@0
  1162
			for(SNode* depNode = dependencyList; depNode != NULL; depNode = depNode->iNext)					
sl@0
  1163
				{																									
sl@0
  1164
				pDepRes = depNode->iResource;													
sl@0
  1165
				if((!depNode->iRequiresChange) || (pDepRes->iResourceId == (TUint)aRequest.ClientId()))				
sl@0
  1166
					continue;																						
sl@0
  1167
				depRequest.ResourceId() = pDepRes->iResourceId;														
sl@0
  1168
				depRequest.ClientId() = pDepRes->iLevelOwnerId;														
sl@0
  1169
				depRequest.Level() = pDepRes->iCachedLevel;															
sl@0
  1170
				depRequest.Resource() = pDepRes;																	
sl@0
  1171
				if(pDepRes->iResourceId & KIdMaskDynamic)															
sl@0
  1172
					((DDynamicPowerResourceD*)pDepRes)->HandleChangePropagation(depRequest, EIssueNotifications,	
sl@0
  1173
																					aOriginatorId, aOriginatorName);	
sl@0
  1174
				else																								
sl@0
  1175
					((DStaticPowerResourceD*)pDepRes)->HandleChangePropagation(depRequest, EIssueNotifications,		
sl@0
  1176
																					aOriginatorId, aOriginatorName);	
sl@0
  1177
				}							
sl@0
  1178
			CompleteNotifications(aRequest.ClientId(), pDR, aRequest.Level(), KErrNone,				
sl@0
  1179
																					aRequest.ClientId());			
sl@0
  1180
			break;																									
sl@0
  1181
			}																										
sl@0
  1182
		default:																									
sl@0
  1183
			return KErrNotSupported;																				
sl@0
  1184
		}																											
sl@0
  1185
	return result;
sl@0
  1186
	}
sl@0
  1187
sl@0
  1188