kernel/eka/include/drivers/resource_extend.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 // e32\include\drivers\resource_extend.h
       
    15 // 
       
    16 // WARNING: This file contains some APIs which are internal and are subject
       
    17 //          to change without notice. Such APIs should therefore not be used
       
    18 //          outside the Kernel and Hardware Services package.
       
    19 //
       
    20 
       
    21 #ifndef __RESOURCE_EXTEND_H__
       
    22 #define __RESOURCE_EXTEND_H__
       
    23 
       
    24 #include <drivers/resource.h>
       
    25 
       
    26 #define ADD_DEPENDENCY_NODE(aNode, aDependencyList)																	\
       
    27 	{																												\
       
    28 	SNode* pDL = aDependencyList;																					\
       
    29 	SNode* prev = NULL;																								\
       
    30 	if(pDL == NULL)																									\
       
    31 		{																											\
       
    32 		aDependencyList = aNode;																					\
       
    33 		aNode->iNext = NULL;																						\
       
    34 		}																											\
       
    35 	else																											\
       
    36 		{																											\
       
    37 		while(pDL != NULL)																							\
       
    38 			{																										\
       
    39 			if(aNode->iPriority == pDL->iPriority)																	\
       
    40 				return KErrAlreadyExists;																			\
       
    41 			if(aNode->iPriority < pDL->iPriority)																	\
       
    42 				{																									\
       
    43 				if(prev == NULL) /*Add it to the head	*/															\
       
    44 					{																								\
       
    45 					aDependencyList = aNode;																		\
       
    46 					aNode->iNext = pDL;																				\
       
    47 					break;																							\
       
    48 					}																								\
       
    49 				prev->iNext = aNode;																				\
       
    50 				aNode->iNext = pDL;																					\
       
    51 				break;																								\
       
    52 				}																									\
       
    53 			if(pDL->iNext == NULL) /* Add it to the end	*/															\
       
    54 				{																									\
       
    55 				pDL->iNext = aNode;																					\
       
    56 				aNode->iNext = NULL;																				\
       
    57 				break;																								\
       
    58 				}																									\
       
    59 			prev = pDL;																								\
       
    60 			pDL = pDL->iNext;																						\
       
    61 			}																										\
       
    62 		}																											\
       
    63 	}
       
    64 
       
    65 //Check whether the priority already exists
       
    66 #define CHECK_IF_PRIORITY_ALREADY_EXISTS(aDependencyList, aPriority)			\
       
    67 	{																			\
       
    68 	for(SNode* node = aDependencyList; node != NULL; node = node->iNext)		\
       
    69 		{																		\
       
    70 		if(node->iPriority == aPriority)										\
       
    71 			return KErrAlreadyExists;											\
       
    72 		}																		\
       
    73 	}
       
    74 
       
    75 
       
    76 static const TUint KIdMaskStaticWithDependencies	= 0x00010000;
       
    77 static const TUint KIdMaskDynamic					= 0x00020000;
       
    78 static const TUint KIdMaskDynamicWithDependencies	= 0x00030000;
       
    79 static const TUint KIdMaskResourceWithDependencies = 0x00010000;
       
    80 static const TInt KDynamicResourceDeRegistering = -2; 
       
    81 
       
    82 struct SNode;
       
    83 struct SPowerResourceClientLevel;
       
    84 
       
    85 //Various stages of resource dependency state change operation.
       
    86 enum TPropagation
       
    87 	{
       
    88 	EChangeStart,
       
    89 	ECheckChangeAllowed,
       
    90 	ERequestStateChange,
       
    91 	EIssueNotifications
       
    92 	};
       
    93 
       
    94 //Return value of translate dependency state function. This is implemented by PSL for each resource.
       
    95 enum TChangePropagationStatus {EChange, ENoChange, EChangeNotAccepted};
       
    96 
       
    97 /**
       
    98 @publishedPartner
       
    99 @prototype 9.5
       
   100 class to represent dynamic resources
       
   101 */
       
   102 class DDynamicPowerResource : public DStaticPowerResource
       
   103 	{
       
   104 public:
       
   105 	IMPORT_C DDynamicPowerResource(const TDesC8& aName, TInt aDefaultLevel);
       
   106 	IMPORT_C ~DDynamicPowerResource();
       
   107 public:
       
   108 	TBool InUse(); //Used by RC on deregistration to see if another client is having requirement on this resource
       
   109 	inline void Lock() {++iCount;} //Resource is locked whenever operation is scheduled in RC thread. 
       
   110 	inline void UnLock() {--iCount;}
       
   111 	inline TUint LockCount() { return iCount;}
       
   112 protected:
       
   113 	TUint iCount;
       
   114 	TUint iOwnerId; //Stores the ID of the client that registers the resource
       
   115 	friend class DPowerResourceController;
       
   116 	};
       
   117 
       
   118 /**
       
   119 @publishedPartner
       
   120 @prototype 9.5
       
   121 */
       
   122 typedef TBool (*TDependencyCustomFunction) (TInt& /*aClientId*/,
       
   123                                             const TDesC8& /*aClientName*/,
       
   124                                             TUint /*aResourceId*/,
       
   125                                             TCustomOperation /*aCustomOperation*/,
       
   126                                             TInt& /*aLevel*/,
       
   127                                             TAny* /*aLevelList*/,
       
   128                                             TAny* /*aResourceLevelList */,
       
   129                                             TAny* /*aReserved*/); // For future use
       
   130 
       
   131 /**
       
   132 @publishedPartner
       
   133 @prototype 9.5
       
   134 class to represent static resource with dependency
       
   135 */
       
   136 class DStaticPowerResourceD : public DStaticPowerResource
       
   137 	{
       
   138 public:
       
   139 	DStaticPowerResourceD(const TDesC8& aName, TInt aDefaultLevel);
       
   140 	TInt AddNode(SNode* aNode);
       
   141 	virtual TInt HandleChangePropagation(TPowerRequest aRequest, TPropagation aProp, TUint aOriginatorId, const TDesC8& aOriginatorName);
       
   142 	virtual TChangePropagationStatus TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState) = 0;
       
   143 public:
       
   144 	SPowerResourceClientLevel* iResourceClientList; //To capture the dependent resource requirement on this resource
       
   145 	TDependencyCustomFunction iDepCustomFunction;
       
   146 private:
       
   147 	SNode* iDependencyList; //Dependency resource list
       
   148 	friend class DPowerResourceController;
       
   149 	};
       
   150 
       
   151 /**
       
   152 @publishedPartner
       
   153 @prototype 9.5
       
   154 class to represent dynamic resource with dependency
       
   155 */
       
   156 class DDynamicPowerResourceD : public DDynamicPowerResource
       
   157 	{
       
   158 public:
       
   159 	IMPORT_C DDynamicPowerResourceD(const TDesC8& aName, TInt aDefaultLevel);
       
   160 	IMPORT_C ~DDynamicPowerResourceD();
       
   161 	IMPORT_C virtual TInt HandleChangePropagation(TPowerRequest aRequest, TPropagation aProp, TUint aOriginatorId, const TDesC8& aOriginatorName);
       
   162 	virtual TChangePropagationStatus TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState) = 0;
       
   163 public:
       
   164 	SPowerResourceClientLevel* iResourceClientList; //To capture the dependent resource requirement on this resource
       
   165 	TDependencyCustomFunction iDepCustomFunction;
       
   166 private:
       
   167 	SNode* iDependencyList; //Dependency resource list
       
   168 	friend class DPowerResourceController;
       
   169 	};
       
   170 
       
   171 /**
       
   172 @publishedPartner
       
   173 @prototype 9.5
       
   174 structure to represent resource dependency information. This is used when registering resource dependency
       
   175 */
       
   176 struct SResourceDependencyInfo
       
   177 	{
       
   178 	TUint iResourceId;
       
   179 	TUint8 iDependencyPriority;
       
   180 	};
       
   181 
       
   182 /**
       
   183 @publishedPartner
       
   184 @prototype 9.5
       
   185 structure to encapsulate dependent resource information. 
       
   186 */
       
   187 struct SNode
       
   188 	{
       
   189 	DStaticPowerResourceD* iResource;
       
   190 	TInt iPropagatedLevel;
       
   191 	TUint8 iRequiresChange;
       
   192 	TUint8 iVisited;
       
   193 	TUint8 iPriority;
       
   194 	TUint8 iSpare;
       
   195 	SNode* iNext;
       
   196 	};
       
   197 
       
   198 #endif