sl@0: /* sl@0: * Copyright (c) 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: * sl@0: */ sl@0: // Resmanus.h sl@0: // sl@0: // sl@0: sl@0: // Base classes for implementating power resource support (Kernel-side only) sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: #ifndef __RESMANUS_H__ sl@0: #define __RESMANUS_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #define USERSIDE_LDD sl@0: #include // For class DResourceController sl@0: sl@0: #include sl@0: #include // for HBufC8 sl@0: sl@0: // Use the following macro for debug output of request-tracking information sl@0: // #define _DUMP_TRACKERS sl@0: sl@0: const TInt KResManUsMajorVersionNumber = 1; sl@0: const TInt KResManUsMinorVersionNumber = 0; sl@0: const TInt KResManUsBuildVersionNumber = KE32BuildVersionNumber; sl@0: sl@0: const TInt KMaxNumChannels = 4; // Limit for the number of channels to be open sl@0: sl@0: const TInt KNumClientNamesResCtrl = 10; // Default number for kernel plus user side clients sl@0: const TInt KNumClientNamesUserSide = 10; // Sized as above (client may have PlatSec capabilities for access) sl@0: const TInt KNumResourceInfoResCtrl = 25; // To contain object types used by Resource Controller sl@0: const TInt KNumResourceInfoUserSide = 25; // To contain object types used by Client sl@0: const TInt KNumResourceDependencies = 5; // Default number of dependencies for a resource sl@0: sl@0: const TUint8 KAllResInfoStored = 0xff; sl@0: const TUint8 KAllClientInfoStored = 0xff; sl@0: sl@0: enum TAsyncOpType sl@0: { sl@0: EGetState, sl@0: ESetState, sl@0: ENotify sl@0: }; sl@0: sl@0: #define USER_SIDE_CLIENT_BIT_MASK 0x4000 //Bit 14 sl@0: sl@0: sl@0: class DChannelResManUs; sl@0: sl@0: /* sl@0: Classes used to track client usage sl@0: */ sl@0: sl@0: class TTrackingControl sl@0: { sl@0: public: sl@0: DChannelResManUs* iOwningChannel; sl@0: SDblQue* iFreeQue; sl@0: SDblQue* iBusyQue; sl@0: TAsyncOpType iType; sl@0: TUint8 iReserved1; // reserved for future expansion sl@0: TUint8 iReserved2; // reserved for future expansion sl@0: TUint8 iReserved3; // reserved for future expansion sl@0: }; sl@0: sl@0: class TTrackingBuffer : public SDblQueLink sl@0: { sl@0: public: sl@0: inline void SetTrackingControl(TTrackingControl* aControl){iTrackingControl=aControl;}; sl@0: inline TTrackingControl* GetTrackingControl(){return iTrackingControl;}; sl@0: inline TUint GetResourceId(){return iResourceId;}; sl@0: inline void SetResourceId(TUint aResourceId){iResourceId=aResourceId;}; sl@0: inline SDblQue* GetQue() {return iQue;}; sl@0: inline void SetQue(SDblQue* aQue) {iQue=aQue;}; sl@0: sl@0: private: sl@0: TTrackingControl* iTrackingControl; sl@0: SDblQue* iQue; sl@0: TUint iResourceId; sl@0: }; sl@0: sl@0: class TTrackGetStateBuf : public TTrackingBuffer sl@0: { sl@0: public: sl@0: TTrackGetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, sl@0: TDfcQue* aQue, TInt aPriority); sl@0: ~TTrackGetStateBuf(); sl@0: sl@0: public: sl@0: TPowerResourceCb iCtrlBlock; sl@0: TClientDataRequest2* iRequest; sl@0: }; sl@0: sl@0: class TTrackSetStateBuf : public TTrackingBuffer sl@0: { sl@0: public: sl@0: TTrackSetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, sl@0: TDfcQue* aQue, TInt aPriority); sl@0: ~TTrackSetStateBuf(); sl@0: public: sl@0: TPowerResourceCb iCtrlBlock; sl@0: TClientRequest* iRequest; sl@0: }; sl@0: sl@0: class TTrackNotifyBuf : public TTrackingBuffer sl@0: { sl@0: public: sl@0: TTrackNotifyBuf(TPowerResourceCbFn aFn, TAny* aPtr, sl@0: TDfcQue* aQue, TInt aPriority); sl@0: ~TTrackNotifyBuf(); sl@0: public: sl@0: DPowerResourceNotification iNotifyBlock; sl@0: TClientRequest* iRequest; sl@0: }; sl@0: sl@0: sl@0: /* sl@0: Power resource logical device sl@0: The class representing the power resource logical device sl@0: */ sl@0: class DDeviceResManUs : public DLogicalDevice sl@0: { sl@0: public: sl@0: /** sl@0: * The constructor sl@0: */ sl@0: DDeviceResManUs(); sl@0: /** sl@0: * The destructor sl@0: */ sl@0: ~DDeviceResManUs(); sl@0: /** sl@0: * Second stage constructor - install the device sl@0: */ sl@0: virtual TInt Install(); sl@0: /** sl@0: * Get the Capabilites of the device sl@0: * @param aDes descriptor that will contain the returned capibilites sl@0: */ sl@0: virtual void GetCaps(TDes8 &aDes) const; sl@0: /** sl@0: * Create a logical channel to the device sl@0: */ sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); sl@0: sl@0: public: sl@0: #ifndef RESOURCE_MANAGER_SIMULATED_PSL sl@0: TDfcQue* iSharedDfcQue; // To allow access from device entry point sl@0: #else sl@0: TDynamicDfcQue* iSharedDfcQue; // To allow LDD unload/re-load in testing sl@0: #endif sl@0: }; sl@0: sl@0: sl@0: sl@0: // The logical channel for power resource devices sl@0: class DChannelResManUs : public DLogicalChannel sl@0: { sl@0: public: sl@0: sl@0: /* sl@0: * The constructor sl@0: */ sl@0: DChannelResManUs(); sl@0: /* sl@0: * The destructor sl@0: */ sl@0: ~DChannelResManUs(); sl@0: sl@0: // Helper methods sl@0: TInt RequestUserHandle(DThread* aThread, TOwnerType aType); sl@0: void FreeTrackingBuffer(TTrackingBuffer*& aBuffer); sl@0: sl@0: inline TInt ClientHandle() {return iClientHandle;}; sl@0: sl@0: /** sl@0: * Create a logical power resource channel sl@0: * @param aUnit The channel number to create sl@0: * @param anInfo not used, can be NULL sl@0: * @param aVer The minimun driver version allowed sl@0: * @return KErrNone if channel created sl@0: */ sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer); sl@0: sl@0: protected: sl@0: /** sl@0: * Handle a message from the channels user sl@0: * @param aMsg The message to handle sl@0: */ sl@0: virtual void HandleMsg(TMessageBase* aMsg); // Note: this is a pure virtual in DLogicalChannel sl@0: sl@0: virtual TInt SendMsg(TMessageBase* aMsg); sl@0: sl@0: TInt SendControl(TMessageBase* aMsg); sl@0: sl@0: TInt SendRequest(TMessageBase* aMsg); sl@0: /** sl@0: * Cancel an outstanding request sl@0: * @param aMask A mask containing the requests to be canceled sl@0: */ sl@0: void DoCancel(TInt aMask); // Name for convenience! sl@0: /** sl@0: * Preform a control operation on the channel sl@0: * Control operations are: sl@0: * - Get the current configuration sl@0: * - Configure the channel sl@0: * - Set the MAC address for the channel sl@0: * - Get the capibilities of the channel sl@0: * @param aId The operation to preform sl@0: * @param a1 The data to use with the operation sl@0: * @param a2 can be NULL - not used sl@0: * @return KErrNone if operation done sl@0: */ sl@0: TInt DoControl(TInt aId, TAny* a1, TAny* a2); // Name for convenience! sl@0: /** sl@0: * Preform an asynchros operation on the channel sl@0: * Operations are: sl@0: * - Read data from the channel sl@0: * - Write data to the channel sl@0: * @param aId The operation to perform sl@0: * @param aStatus The status object to use when complete sl@0: * @param a1 The data to use sl@0: * @param a2 The length of the data to use sl@0: * @return KErrNone if operation started ok sl@0: * @see Complete() sl@0: */ sl@0: TInt DoRequest(TInt aId, TRequestStatus* aStatus, TAny* a1, TAny* a2); // Name for convenience! sl@0: sl@0: sl@0: inline void SetClientHandle(TInt aHandle) {iClientHandle=aHandle;}; sl@0: sl@0: TInt InitTrackingControl(TTrackingControl*& aTracker, TUint8 aType, TUint8 aNumBuffers); sl@0: #ifdef RESOURCE_MANAGER_SIMULATED_PSL sl@0: void GetNumCandidateAsyncResources(TUint& aNumResources); sl@0: TInt GetCandidateAsyncResourceId(TUint aIndex, TUint& aResourceId); sl@0: void GetNumCandidateSharedResources(TUint& aNumResources); sl@0: TInt GetCandidateSharedResourceId(TUint aIndex, TUint& aResourceId); sl@0: #endif sl@0: sl@0: private: sl@0: static void RegistrationDfcFunc(TAny* aChannel); sl@0: TInt RegisterWithResCtrlr(); sl@0: TInt GetValidName(const TDesC8* aInfo); sl@0: void RemoveTrackingControl(TTrackingControl*& aTracker); sl@0: TInt GetAndInitTrackingBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TRequestStatus* aStatus); sl@0: TInt GetStateBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TInt *aState, TInt* aLevelOwnerPtr, TPowerResourceCb*& aCb, TRequestStatus* aStatus); sl@0: TTrackingControl* MapRequestToTracker(TInt aRequestType); sl@0: TInt CancelTrackerRequests(TTrackingControl* aTracker,TBool aSingleRsrc, TUint aResourceId, TRequestStatus* aStatus); sl@0: TInt CancelRequestsOfType(TInt aRequestType, TRequestStatus* aStatus); sl@0: TInt EnsureSizeIsSufficient(HBuf*& aBuffer, TInt aMinSize); sl@0: TInt ExtractResourceInfo(const TPowerResourceInfoV01* aPwrResInfo, TResourceInfoBuf& aInfo); sl@0: #ifdef _DUMP_TRACKERS sl@0: TInt DumpResource(const TPowerResourceInfoV01* aResource); sl@0: TInt DumpTracker(TTrackingControl* aTracker); sl@0: #endif sl@0: #ifdef RESOURCE_MANAGER_SIMULATED_PSL sl@0: void CheckForCandidateAsyncResource(TPowerResourceInfoV01* aResource); sl@0: void CheckForCandidateSharedResource(TPowerResourceInfoV01* aResource); sl@0: #endif sl@0: typedef void ClientCopyFunc(TDes8*, const TPowerClientInfoV01*); sl@0: sl@0: // Registration and identification support sl@0: public: sl@0: DThread* iClient; sl@0: sl@0: DPowerResourceController* iPddPtr; sl@0: sl@0: private: sl@0: NFastMutex iBufferFastMutex; sl@0: NFastSemaphore *iFastSem; sl@0: TInt iClientHandle; sl@0: TUint iNameProvidedLength; sl@0: HBuf8* iUserNameUsed; sl@0: sl@0: // Support for usage tracking sl@0: TTrackingControl *iGetStateTracker; sl@0: TTrackingControl *iSetStateTracker; sl@0: TTrackingControl *iListenableTracker; sl@0: sl@0: // Buffers to support acquisition of resource and client information sl@0: HBuf8* iClientNamesResCtrl; // Stores client information sl@0: TUint iClientInfoStoredResId; // The ID of the resource for which the data is stored (none=0, all=KAllClientInfoStored) sl@0: TUint iClientInfoStoredNum; // The number of clients for which data is stored sl@0: sl@0: HBuf8* iResourceInfoResCtrl; // Stores resource information sl@0: TUint iResInfoStoredClientId; // The ID of the client for which the data is stored (none=0, all=KAllResInfoStored) sl@0: TUint iResInfoStoredNum; // The number of resources for which data is stored sl@0: sl@0: HBuf8* iResourceDependencyIds; // To contain the identifiers for resource dependencies sl@0: TUint iNumResDepsStored; sl@0: sl@0: #ifdef RESOURCE_MANAGER_SIMULATED_PSL sl@0: // Support for testing sl@0: TBool iHaveLongLatencyResource; sl@0: sl@0: // Array for candidate resources to use for testing sl@0: // Store a maximum of MAX_NUM_CANDIDATE_RESOURCES sl@0: #define MAX_NUM_CANDIDATE_RESOURCES 10 sl@0: TUint iNoCandidateAsyncRes; sl@0: TUint iCandidateAsyncResIds[MAX_NUM_CANDIDATE_RESOURCES]; sl@0: TUint iNoCandidateSharedRes; sl@0: TUint iCandidateSharedResIds[MAX_NUM_CANDIDATE_RESOURCES]; sl@0: #endif sl@0: sl@0: // 8-bit values, placed here to aid size management sl@0: TUint8 iClientInfoValid; // To indicate if a valid set of client data is stored sl@0: TUint8 iResInfoValid; // To indicate if a valid set of resource data is stored sl@0: TUint8 iResDepsValid; // Guard flag for the RArray sl@0: sl@0: TUint8 iReserved1; // reserved for future expansion sl@0: sl@0: }; sl@0: sl@0: sl@0: #endif