1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Eclipse Public License v1.0" |
4 // under the terms of the License "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
24 #include <kernel/kern_priv.h> |
24 #include <kernel/kern_priv.h> |
25 #include <drivers/resourcecontrol_trace.h> |
25 #include <drivers/resourcecontrol_trace.h> |
26 #include <drivers/resource_category.h> |
26 #include <drivers/resource_category.h> |
27 |
27 |
28 //Definition for resource flag setting. Used by PSL. |
28 //Definition for resource flag setting. Used by PSL. |
29 static const TUint KTypeMask= 0x3; |
29 const TUint KTypeMask = 0x3; |
30 static const TUint KUsageOffset=0x1F; |
30 const TUint KUsageOffset = 0x1F; |
31 static const TUint KLongLatencySetOffset=0x1E; |
31 const TUint KLongLatencySetOffset = 0x1E; |
32 static const TUint KLongLatencyGetOffset=0x1D; |
32 const TUint KLongLatencyGetOffset = 0x1D; |
33 static const TUint KClassOffset=0x1C; |
33 const TUint KClassOffset = 0x1C; |
34 static const TUint KSenseOffset=0x1A; |
34 const TUint KSenseOffset = 0x1A; |
35 static const TUint KShared=0x1<<KUsageOffset; |
35 const TUint KShared = 0x1u << KUsageOffset; |
36 static const TUint KLongLatencySet=0x1<<KLongLatencySetOffset; |
36 const TUint KLongLatencySet = 0x1u << KLongLatencySetOffset; |
37 static const TUint KLongLatencyGet=0x1<<KLongLatencyGetOffset; |
37 const TUint KLongLatencyGet = 0x1u << KLongLatencyGetOffset; |
38 static const TUint KLogical=0x1<<KClassOffset; |
38 const TUint KLogical = 0x1u << KClassOffset; |
39 static const TUint KSenseNegative=0x01<<KSenseOffset; |
39 const TUint KSenseNegative = 0x1u << KSenseOffset; |
40 static const TUint KSenseCustom=0x2<<KSenseOffset; |
40 const TUint KSenseCustom = 0x2u << KSenseOffset; |
41 |
41 |
42 struct TPowerRequest; |
42 struct TPowerRequest; |
43 struct SIdleResourceInfo; |
43 struct SIdleResourceInfo; |
44 |
44 |
45 |
45 |
166 { |
166 { |
167 TPowerResourceCb* pCb = (TPowerResourceCb*) aPtr; |
167 TPowerResourceCb* pCb = (TPowerResourceCb*) aPtr; |
168 __KTRACE_OPT(KRESMANAGER, Kern::Printf(">TPowerResourceCb::DfcFunc ClientId = 0x%x, ResourceId = %d, Level = %d, \ |
168 __KTRACE_OPT(KRESMANAGER, Kern::Printf(">TPowerResourceCb::DfcFunc ClientId = 0x%x, ResourceId = %d, Level = %d, \ |
169 LevelOwnerId = %d, Result = %d", pCb->iClientId, pCb->iResourceId, pCb->iLevel, \ |
169 LevelOwnerId = %d, Result = %d", pCb->iClientId, pCb->iResourceId, pCb->iLevel, \ |
170 pCb->iLevelOwnerId, pCb->iResult)); |
170 pCb->iLevelOwnerId, pCb->iResult)); |
171 // Call the client specified callback function |
171 |
172 pCb->iCallback(pCb->iClientId, pCb->iResourceId, pCb->iLevel, pCb->iLevelOwnerId, pCb->iResult, pCb->iParam); |
172 pCb->Lock(); |
173 pCb->iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request. |
173 TUint ClientId = pCb->iClientId; |
|
174 TUint ResourceId = pCb->iResourceId; |
|
175 TInt Level = pCb->iLevel; |
|
176 TInt LevelOwnerId = pCb->iLevelOwnerId; |
|
177 TInt Result = pCb->iResult; |
|
178 TAny* Param = pCb->iParam; |
|
179 pCb->UnLock(); |
|
180 |
|
181 // Call the client specified callback function |
|
182 pCb->iCallback(ClientId, ResourceId, Level, LevelOwnerId, Result, Param); |
|
183 |
|
184 pCb->Lock(); |
|
185 pCb->iPendingRequestCount--; |
|
186 if(pCb->iPendingRequestCount == 0) |
|
187 pCb->iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request. |
|
188 pCb->UnLock(); |
174 PRM_CALLBACK_COMPLETION_TRACE |
189 PRM_CALLBACK_COMPLETION_TRACE |
175 } |
190 } |
176 private: |
191 private: |
|
192 void Lock() |
|
193 { |
|
194 __ASSERT_DEBUG(iMutex, Kern::Fault("TPowerResourceCb::Lock", __LINE__)); |
|
195 NKern::ThreadEnterCS(); |
|
196 Kern::MutexWait(*iMutex); |
|
197 } |
|
198 void UnLock() |
|
199 { |
|
200 __ASSERT_DEBUG(iMutex, Kern::Fault("TPowerResourceCb::UnLock", __LINE__)); |
|
201 Kern::MutexSignal(*iMutex); |
|
202 NKern::ThreadLeaveCS(); |
|
203 } |
177 TAny* iParam; //Stores the aPtr argument passed in the constructor, to be passed as 5th argument to the callback function |
204 TAny* iParam; //Stores the aPtr argument passed in the constructor, to be passed as 5th argument to the callback function |
178 TInt iResult; //Used to store the result aswell as binary usage count for the callback |
205 TInt iResult; //Used to store the result as well as binary usage count for the callback |
179 TInt iLevel; // Level of the resource |
206 TInt iLevel; // Level of the resource |
180 TInt iLevelOwnerId; // Stores owner of the resource for asynchronous get operation |
207 TInt iLevelOwnerId; // Stores owner of the resource for asynchronous get operation |
181 TUint iResourceId; //Stores the ID of the resource whose state is changed/read asynchronously |
208 TUint iResourceId; //Stores the ID of the resource whose state is changed/read asynchronously |
182 TUint iClientId; //Stores the ID of the client that requested the asynchronous operation |
209 TUint iClientId; //Stores the ID of the client that requested the asynchronous operation |
183 TPowerResourceCbFn iCallback; //Callback function object |
210 TPowerResourceCbFn iCallback; //Callback function object |
|
211 DMutex* iMutex; |
|
212 TInt iPendingRequestCount; |
184 #ifdef PRM_CONTROLLER |
213 #ifdef PRM_CONTROLLER |
185 friend class DPowerResourceController; |
214 friend class DPowerResourceController; |
186 #endif |
215 #endif |
187 }; |
216 }; |
188 |
217 |