131 |
131 |
132 |
132 |
133 /* Macro to add dynamic resource to appropriate containers. Used only in extended version */ |
133 /* Macro to add dynamic resource to appropriate containers. Used only in extended version */ |
134 #define ADD_TO_RESOURCE_CONTAINER(list, res, resId, resIdCount) \ |
134 #define ADD_TO_RESOURCE_CONTAINER(list, res, resId, resIdCount) \ |
135 { \ |
135 { \ |
136 TUint16 growBy = (list).GrowBy(); \ |
136 TInt growBy = (list).GrowBy(); \ |
137 if(!growBy) \ |
137 if(!growBy) \ |
138 (list).Initialise((TUint16)PRM_DYNAMIC_RESOURCE_INITIAL_SIZE); \ |
138 (list).Initialise(PRM_DYNAMIC_RESOURCE_INITIAL_SIZE); \ |
139 if((list).Add(res, resId) == KErrNoMemory) \ |
139 if((list).Add(res, resId) == KErrNoMemory) \ |
140 { \ |
140 { \ |
141 TInt r = (list).ReSize(growBy); \ |
141 TInt r = (list).ReSize(growBy); \ |
142 if(r != KErrNone) \ |
142 if(r != KErrNone) \ |
143 return r; \ |
143 return r; \ |
152 #define GET_RESOURCE_FROM_LIST(resId, res) \ |
152 #define GET_RESOURCE_FROM_LIST(resId, res) \ |
153 { \ |
153 { \ |
154 switch((resId >> RESOURCE_BIT_IN_ID_CHECK) & 0x3) \ |
154 switch((resId >> RESOURCE_BIT_IN_ID_CHECK) & 0x3) \ |
155 { \ |
155 { \ |
156 case PRM_STATIC_RESOURCE: \ |
156 case PRM_STATIC_RESOURCE: \ |
157 if(resId > iStaticResourceArrayEntries) \ |
157 if((TInt)resId > iStaticResourceArray.Count()) \ |
158 UNLOCK_RETURN(KErrNotFound); \ |
158 UNLOCK_RETURN(KErrNotFound); \ |
159 res = iStaticResourceArray[resId - 1]; \ |
159 res = iStaticResourceArray[resId - 1]; \ |
160 if(!res) \ |
160 if(!res) \ |
161 UNLOCK_RETURN(KErrNotFound); \ |
161 UNLOCK_RETURN(KErrNotFound); \ |
162 break; \ |
162 break; \ |
163 case PRM_STATIC_DEPENDENCY_RESOURCE: \ |
163 case PRM_STATIC_DEPENDENCY_RESOURCE: \ |
164 if((TUint16)(resId & ID_INDEX_BIT_MASK) > iStaticResDependencyCount) \ |
164 if((TInt)(resId & ID_INDEX_BIT_MASK) > iStaticResDependencyArray.Count()) \ |
165 UNLOCK_RETURN(KErrNotFound); \ |
165 UNLOCK_RETURN(KErrNotFound); \ |
166 res = iStaticResDependencyArray[(TUint16)(resId & ID_INDEX_BIT_MASK) - 1]; \ |
166 res = iStaticResDependencyArray[(resId & ID_INDEX_BIT_MASK) - 1]; \ |
167 break; \ |
167 break; \ |
168 case PRM_DYNAMIC_RESOURCE: \ |
168 case PRM_DYNAMIC_RESOURCE: \ |
169 res = iDynamicResourceList[(TUint16)(resId & ID_INDEX_BIT_MASK)]; \ |
169 res = iDynamicResourceList[(resId & ID_INDEX_BIT_MASK)]; \ |
170 if(!res) \ |
170 if(!res) \ |
171 UNLOCK_RETURN(KErrNotFound); \ |
171 UNLOCK_RETURN(KErrNotFound); \ |
172 break; \ |
172 break; \ |
173 case PRM_DYNAMIC_DEPENDENCY_RESOURCE: \ |
173 case PRM_DYNAMIC_DEPENDENCY_RESOURCE: \ |
174 res = iDynamicResDependencyList[(TUint16)(resId & ID_INDEX_BIT_MASK)]; \ |
174 res = iDynamicResDependencyList[(resId & ID_INDEX_BIT_MASK)]; \ |
175 if(!res) \ |
175 if(!res) \ |
176 UNLOCK_RETURN(KErrNotFound); \ |
176 UNLOCK_RETURN(KErrNotFound); \ |
177 break; \ |
177 break; \ |
178 default: \ |
178 default: \ |
179 UNLOCK_RETURN(KErrArgument); \ |
179 UNLOCK_RETURN(KErrArgument); \ |
183 /**Macro to get the client from appropriate client list based on bit 14 of client ID. |
183 /**Macro to get the client from appropriate client list based on bit 14 of client ID. |
184 If the client is registered as thread relative, then check is made to make sure |
184 If the client is registered as thread relative, then check is made to make sure |
185 it is called from the same thread. */ |
185 it is called from the same thread. */ |
186 #define VALIDATE_CLIENT(t) \ |
186 #define VALIDATE_CLIENT(t) \ |
187 if(aClientId & USER_SIDE_CLIENT_BIT_MASK) \ |
187 if(aClientId & USER_SIDE_CLIENT_BIT_MASK) \ |
188 pC = iUserSideClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)]; \ |
188 pC = iUserSideClientList[(aClientId & ID_INDEX_BIT_MASK)]; \ |
189 else \ |
189 else \ |
190 pC = iClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)]; \ |
190 pC = iClientList[(aClientId & ID_INDEX_BIT_MASK)]; \ |
191 if(!pC) \ |
191 if(!pC) \ |
192 { \ |
192 { \ |
193 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found")); \ |
193 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found")); \ |
194 UNLOCK_RETURN(KErrAccessDenied); \ |
194 UNLOCK_RETURN(KErrAccessDenied); \ |
195 } \ |
195 } \ |
208 } |
208 } |
209 |
209 |
210 /** Macro to get the target client from appropriate client list based on bit 14 of client ID. */ |
210 /** Macro to get the target client from appropriate client list based on bit 14 of client ID. */ |
211 #define GET_TARGET_CLIENT() \ |
211 #define GET_TARGET_CLIENT() \ |
212 if(aTargetClientId & USER_SIDE_CLIENT_BIT_MASK) \ |
212 if(aTargetClientId & USER_SIDE_CLIENT_BIT_MASK) \ |
213 pC = iUserSideClientList[(TUint16)(aTargetClientId & ID_INDEX_BIT_MASK)]; \ |
213 pC = iUserSideClientList[(aTargetClientId & ID_INDEX_BIT_MASK)]; \ |
214 else \ |
214 else \ |
215 pC = iClientList[(TUint16)(aTargetClientId & ID_INDEX_BIT_MASK)]; \ |
215 pC = iClientList[(aTargetClientId & ID_INDEX_BIT_MASK)]; \ |
216 if(!pC) \ |
216 if(!pC) \ |
217 { \ |
217 { \ |
218 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Target Client ID not found")); \ |
218 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Target Client ID not found")); \ |
219 UNLOCK_RETURN(KErrNotFound); \ |
219 UNLOCK_RETURN(KErrNotFound); \ |
220 } \ |
220 } \ |
316 */ |
316 */ |
317 template <class T> |
317 template <class T> |
318 class DResourceCon : public DBase |
318 class DResourceCon : public DBase |
319 { |
319 { |
320 public: |
320 public: |
321 inline TInt Initialise(TUint16 aInitialSize); |
321 inline TInt Initialise(TInt aInitialSize); |
322 inline void Delete(); |
322 inline void Delete(); |
323 inline T* operator[](TUint16 aIndex); |
323 inline T* operator[](TInt aIndex); |
324 inline TInt Remove(T* aObj, TUint16 aIndex); |
324 inline TInt Remove(T* aObj, TInt aIndex); |
325 inline TInt Add(T* aObj, TUint &aId); |
325 inline TInt Add(T* aObj, TUint &aId); |
326 inline TInt Find(T*& anEntry, TDesC& aName); |
326 inline TInt Find(T*& anEntry, TDesC& aName); |
327 inline TInt ReSize(TUint16 aGrowBy); |
327 inline TInt ReSize(TInt aGrowBy); |
328 inline TUint16 Count() {return iCount;} |
328 inline TInt Count() {return iCount;} |
329 inline TUint16 Allocd() {return iAllocated;} |
329 inline TInt Allocd() {return iAllocated;} |
330 inline TUint16 GrowBy() {return iGrowBy;} |
330 inline TInt GrowBy() {return iGrowBy;} |
331 private: |
331 private: |
332 TUint16 iGrowBy; //Size to grow the size of the array. |
332 TUint16 iGrowBy; //Size to grow the size of the array. |
333 TUint16 iAllocated; //Size of the array |
333 TUint16 iAllocated; //Size of the array |
334 TUint16 iCount; //Valid entries in the array |
334 TUint16 iCount; //Valid entries in the array |
335 TUint16 iInstanceCount; //FreeCounter incremented whenever an entry is added. |
335 TUint16 iInstanceCount; //FreeCounter incremented whenever an entry is added. |
452 virtual TInt DeregisterProxyClient(TUint aClientId); |
452 virtual TInt DeregisterProxyClient(TUint aClientId); |
453 //register list of resources whose state matter to Idle |
453 //register list of resources whose state matter to Idle |
454 virtual TInt RegisterResourcesForIdle(TInt aPowerControllerId, TUint aNumResources, TPtr* aBuf); |
454 virtual TInt RegisterResourcesForIdle(TInt aPowerControllerId, TUint aNumResources, TPtr* aBuf); |
455 static void Panic(TUint8 aPanic); |
455 static void Panic(TUint8 aPanic); |
456 virtual TInt GetInterface(TUint aClientId, TUint aInterfaceId, TAny* aParam1, TAny* aParam2, TAny* aParam3); |
456 virtual TInt GetInterface(TUint aClientId, TUint aInterfaceId, TAny* aParam1, TAny* aParam2, TAny* aParam3); |
457 virtual ~DPowerResourceController(); |
|
458 /**@internalComponent*/ |
457 /**@internalComponent*/ |
459 void CompleteNotifications(TInt aClientId, DStaticPowerResource* aResource, TInt aState, TInt aReturnCode, TInt aLevelOwnerId, TBool aLock = ETrue); |
458 void CompleteNotifications(TInt aClientId, DStaticPowerResource* aResource, TInt aState, TInt aReturnCode, TInt aLevelOwnerId, TBool aLock = ETrue); |
460 #ifdef PRM_ENABLE_EXTENDED_VERSION |
459 #ifdef PRM_ENABLE_EXTENDED_VERSION |
461 /**@internalComponent*/ |
460 /**@internalComponent*/ |
462 TInt ReserveClientLevelPoolCount(TUint16 aCount); |
461 TInt ReserveClientLevelPoolCount(TUint16 aCount); |
479 Kern::MutexWait(*iResourceMutex); } |
478 Kern::MutexWait(*iResourceMutex); } |
480 inline void UnLock() { Kern::MutexSignal(*iResourceMutex); |
479 inline void UnLock() { Kern::MutexSignal(*iResourceMutex); |
481 NKern::ThreadLeaveCS();} |
480 NKern::ThreadLeaveCS();} |
482 #ifdef PRM_ENABLE_EXTENDED_VERSION |
481 #ifdef PRM_ENABLE_EXTENDED_VERSION |
483 //Default implementation, PSL re-implements these if features supported |
482 //Default implementation, PSL re-implements these if features supported |
484 virtual TInt DoRegisterStaticResourcesDependency(DStaticPowerResourceD**& aStaticResourceDArray, TUint16& aStaticResourceDCount); |
483 virtual TInt DoRegisterStaticResourcesDependency(RPointerArray <DStaticPowerResourceD> & aStaticResourceDArray); |
485 #endif |
484 #endif |
486 private: |
485 private: |
487 // pure virtual implemented by PSL - to be called by PIL |
486 // pure virtual implemented by PSL - to be called by PIL |
488 virtual TInt DoInitController()=0; |
487 virtual TInt DoInitController()=0; |
489 virtual TInt DoRegisterStaticResources(DStaticPowerResource**& aStaticResourceArray, TUint16& aStaticResourceCount)=0; |
488 virtual TInt DoRegisterStaticResources(RPointerArray <DStaticPowerResource> & aStaticResourceArray)=0; |
490 /**@internalComponent*/ |
489 /**@internalComponent*/ |
491 TInt CheckLevelAndAddClient(SPowerResourceClient* pC, TPowerRequest* Request); |
490 TInt CheckLevelAndAddClient(SPowerResourceClient* pC, TPowerRequest* Request); |
492 static void MsgQFunc(TAny* aPtr); |
491 static void MsgQFunc(TAny* aPtr); |
493 #ifdef PRM_ENABLE_EXTENDED_VERSION |
492 #ifdef PRM_ENABLE_EXTENDED_VERSION |
494 static void MsgQDependencyFunc(TAny* aPtr); |
493 static void MsgQDependencyFunc(TAny* aPtr); |
521 TInt HandleDependencyResourceStateChange(SPowerResourceClient* pC, TPowerRequest& aRequest); |
520 TInt HandleDependencyResourceStateChange(SPowerResourceClient* pC, TPowerRequest& aRequest); |
522 TInt GetNumDependentsForResource(TUint aResourceId, TUint* aNumResources); |
521 TInt GetNumDependentsForResource(TUint aResourceId, TUint* aNumResources); |
523 TInt GetDependentsIdForResource(TUint aResourceId, TAny* aInfo, TUint* aNumDepResources); |
522 TInt GetDependentsIdForResource(TUint aResourceId, TAny* aInfo, TUint* aNumDepResources); |
524 TInt HandleResourceRegistration(TPowerRequest& aReq); |
523 TInt HandleResourceRegistration(TPowerRequest& aReq); |
525 #endif |
524 #endif |
526 public: |
525 protected: |
527 DMutex* iResourceMutex; |
526 DMutex* iResourceMutex; |
528 protected: |
527 TDfcQue* iDfcQ; |
529 TDfcQue* iDfcQ; |
|
530 TMessageQue *iMsgQ; |
528 TMessageQue *iMsgQ; |
531 #ifdef PRM_ENABLE_EXTENDED_VERSION |
529 #ifdef PRM_ENABLE_EXTENDED_VERSION |
532 TDfcQue* iDfcQDependency; |
530 TDfcQue* iDfcQDependency; |
533 TMessageQue* iMsgQDependency; |
531 TMessageQue* iMsgQDependency; |
534 TBool iDfcQDependencyLock; |
532 TBool iDfcQDependencyLock; |
535 #endif |
533 #endif |
536 private: |
534 RPointerArray <DStaticPowerResource> iStaticResourceArray; |
537 DStaticPowerResource** iStaticResourceArray; |
|
538 DResourceCon<SPowerResourceClient> iClientList; |
535 DResourceCon<SPowerResourceClient> iClientList; |
539 DResourceCon<SPowerResourceClient> iUserSideClientList; |
536 DResourceCon<SPowerResourceClient> iUserSideClientList; |
540 #ifdef RESOURCE_MANAGER_SIMULATED_PSL |
537 #ifdef RESOURCE_MANAGER_SIMULATED_PSL |
541 RPointerArray<SPowerResourceClient> iCleanList; |
538 RPointerArray<SPowerResourceClient> iCleanList; |
542 #endif |
539 #endif |
550 TUint16 iUserSideClientCount; |
547 TUint16 iUserSideClientCount; |
551 TUint16 iClientLevelPoolCount; |
548 TUint16 iClientLevelPoolCount; |
552 TUint16 iClientLevelPoolGrowBy; |
549 TUint16 iClientLevelPoolGrowBy; |
553 TUint16 iRequestPoolCount; |
550 TUint16 iRequestPoolCount; |
554 TUint16 iRequestPoolGrowBy; |
551 TUint16 iRequestPoolGrowBy; |
555 TUint16 iStaticResourceArrayEntries; //Number of entries in the array including holes if any. |
|
556 TUint16 iStaticResourceCount; //Actual number of static resources registered (valid entries). |
552 TUint16 iStaticResourceCount; //Actual number of static resources registered (valid entries). |
557 TUint iReserved2; //Reserved for future use |
553 TUint iReserved2; //Reserved for future use |
558 #ifdef PRM_ENABLE_EXTENDED_VERSION |
554 #ifdef PRM_ENABLE_EXTENDED_VERSION |
559 DResourceCon<DDynamicPowerResource> iDynamicResourceList; |
555 DResourceCon<DDynamicPowerResource> iDynamicResourceList; |
560 DResourceCon<DDynamicPowerResourceD> iDynamicResDependencyList; |
556 DResourceCon<DDynamicPowerResourceD> iDynamicResDependencyList; |
561 DStaticPowerResourceD** iStaticResDependencyArray; |
557 RPointerArray <DStaticPowerResourceD> iStaticResDependencyArray; |
562 SPowerResourceClientLevel* iResourceLevelPool; |
558 SPowerResourceClientLevel* iResourceLevelPool; |
563 TUint16 iResourceLevelPoolCount; |
559 TUint16 iResourceLevelPoolCount; |
564 TUint16 iStaticResDependencyCount; |
|
565 TUint16 iDynamicResourceCount; |
560 TUint16 iDynamicResourceCount; |
566 TUint8 iDynamicResDependencyCount; |
561 TUint8 iDynamicResDependencyCount; |
567 TUint8 iSpare2; |
562 TUint8 iSpare1; |
|
563 TUint16 iSpare2; |
568 TUint iReserved3; //Reserved for future use. |
564 TUint iReserved3; //Reserved for future use. |
569 #endif |
565 #endif |
570 }; |
566 }; |
571 |
567 |
572 /** |
568 /** |