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