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: // e32\include\drivers\resource_extend.h sl@0: // sl@0: // WARNING: This file contains some APIs which are internal and are subject sl@0: // to change without notice. Such APIs should therefore not be used sl@0: // outside the Kernel and Hardware Services package. sl@0: // sl@0: sl@0: #ifndef __RESOURCE_EXTEND_H__ sl@0: #define __RESOURCE_EXTEND_H__ sl@0: sl@0: #include sl@0: sl@0: #define ADD_DEPENDENCY_NODE(aNode, aDependencyList) \ sl@0: { \ sl@0: SNode* pDL = aDependencyList; \ sl@0: SNode* prev = NULL; \ sl@0: if(pDL == NULL) \ sl@0: { \ sl@0: aDependencyList = aNode; \ sl@0: aNode->iNext = NULL; \ sl@0: } \ sl@0: else \ sl@0: { \ sl@0: while(pDL != NULL) \ sl@0: { \ sl@0: if(aNode->iPriority == pDL->iPriority) \ sl@0: return KErrAlreadyExists; \ sl@0: if(aNode->iPriority < pDL->iPriority) \ sl@0: { \ sl@0: if(prev == NULL) /*Add it to the head */ \ sl@0: { \ sl@0: aDependencyList = aNode; \ sl@0: aNode->iNext = pDL; \ sl@0: break; \ sl@0: } \ sl@0: prev->iNext = aNode; \ sl@0: aNode->iNext = pDL; \ sl@0: break; \ sl@0: } \ sl@0: if(pDL->iNext == NULL) /* Add it to the end */ \ sl@0: { \ sl@0: pDL->iNext = aNode; \ sl@0: aNode->iNext = NULL; \ sl@0: break; \ sl@0: } \ sl@0: prev = pDL; \ sl@0: pDL = pDL->iNext; \ sl@0: } \ sl@0: } \ sl@0: } sl@0: sl@0: //Check whether the priority already exists sl@0: #define CHECK_IF_PRIORITY_ALREADY_EXISTS(aDependencyList, aPriority) \ sl@0: { \ sl@0: for(SNode* node = aDependencyList; node != NULL; node = node->iNext) \ sl@0: { \ sl@0: if(node->iPriority == aPriority) \ sl@0: return KErrAlreadyExists; \ sl@0: } \ sl@0: } sl@0: sl@0: sl@0: static const TUint KIdMaskStaticWithDependencies = 0x00010000; sl@0: static const TUint KIdMaskDynamic = 0x00020000; sl@0: static const TUint KIdMaskDynamicWithDependencies = 0x00030000; sl@0: static const TUint KIdMaskResourceWithDependencies = 0x00010000; sl@0: static const TInt KDynamicResourceDeRegistering = -2; sl@0: sl@0: struct SNode; sl@0: struct SPowerResourceClientLevel; sl@0: sl@0: //Various stages of resource dependency state change operation. sl@0: enum TPropagation sl@0: { sl@0: EChangeStart, sl@0: ECheckChangeAllowed, sl@0: ERequestStateChange, sl@0: EIssueNotifications sl@0: }; sl@0: sl@0: //Return value of translate dependency state function. This is implemented by PSL for each resource. sl@0: enum TChangePropagationStatus {EChange, ENoChange, EChangeNotAccepted}; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype 9.5 sl@0: class to represent dynamic resources sl@0: */ sl@0: class DDynamicPowerResource : public DStaticPowerResource sl@0: { sl@0: public: sl@0: IMPORT_C DDynamicPowerResource(const TDesC8& aName, TInt aDefaultLevel); sl@0: IMPORT_C ~DDynamicPowerResource(); sl@0: public: sl@0: TBool InUse(); //Used by RC on deregistration to see if another client is having requirement on this resource sl@0: inline void Lock() {++iCount;} //Resource is locked whenever operation is scheduled in RC thread. sl@0: inline void UnLock() {--iCount;} sl@0: inline TUint LockCount() { return iCount;} sl@0: protected: sl@0: TUint iCount; sl@0: TUint iOwnerId; //Stores the ID of the client that registers the resource sl@0: friend class DPowerResourceController; sl@0: }; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype 9.5 sl@0: */ sl@0: typedef TBool (*TDependencyCustomFunction) (TInt& /*aClientId*/, sl@0: const TDesC8& /*aClientName*/, sl@0: TUint /*aResourceId*/, sl@0: TCustomOperation /*aCustomOperation*/, sl@0: TInt& /*aLevel*/, sl@0: TAny* /*aLevelList*/, sl@0: TAny* /*aResourceLevelList */, sl@0: TAny* /*aReserved*/); // For future use sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype 9.5 sl@0: class to represent static resource with dependency sl@0: */ sl@0: class DStaticPowerResourceD : public DStaticPowerResource sl@0: { sl@0: public: sl@0: DStaticPowerResourceD(const TDesC8& aName, TInt aDefaultLevel); sl@0: TInt AddNode(SNode* aNode); sl@0: virtual TInt HandleChangePropagation(TPowerRequest aRequest, TPropagation aProp, TUint aOriginatorId, const TDesC8& aOriginatorName); sl@0: virtual TChangePropagationStatus TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState) = 0; sl@0: public: sl@0: SPowerResourceClientLevel* iResourceClientList; //To capture the dependent resource requirement on this resource sl@0: TDependencyCustomFunction iDepCustomFunction; sl@0: private: sl@0: SNode* iDependencyList; //Dependency resource list sl@0: friend class DPowerResourceController; sl@0: }; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype 9.5 sl@0: class to represent dynamic resource with dependency sl@0: */ sl@0: class DDynamicPowerResourceD : public DDynamicPowerResource sl@0: { sl@0: public: sl@0: IMPORT_C DDynamicPowerResourceD(const TDesC8& aName, TInt aDefaultLevel); sl@0: IMPORT_C ~DDynamicPowerResourceD(); sl@0: IMPORT_C virtual TInt HandleChangePropagation(TPowerRequest aRequest, TPropagation aProp, TUint aOriginatorId, const TDesC8& aOriginatorName); sl@0: virtual TChangePropagationStatus TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState) = 0; sl@0: public: sl@0: SPowerResourceClientLevel* iResourceClientList; //To capture the dependent resource requirement on this resource sl@0: TDependencyCustomFunction iDepCustomFunction; sl@0: private: sl@0: SNode* iDependencyList; //Dependency resource list sl@0: friend class DPowerResourceController; sl@0: }; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype 9.5 sl@0: structure to represent resource dependency information. This is used when registering resource dependency sl@0: */ sl@0: struct SResourceDependencyInfo sl@0: { sl@0: TUint iResourceId; sl@0: TUint8 iDependencyPriority; sl@0: }; sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @prototype 9.5 sl@0: structure to encapsulate dependent resource information. sl@0: */ sl@0: struct SNode sl@0: { sl@0: DStaticPowerResourceD* iResource; sl@0: TInt iPropagatedLevel; sl@0: TUint8 iRequiresChange; sl@0: TUint8 iVisited; sl@0: TUint8 iPriority; sl@0: TUint8 iSpare; sl@0: SNode* iNext; sl@0: }; sl@0: sl@0: #endif