author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 2 |
// All rights reserved. |
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\drivers\resmanus\d_resmanus.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
// LDD for Resource Manager user side API |
|
19 |
#include "resmanus.h" |
|
20 |
#include <kernel/kern_priv.h> |
|
21 |
#include <kernel/kernel.h> |
|
22 |
#include <e32hal.h> |
|
23 |
#include <e32uid.h> |
|
24 |
#include <e32cmn.h> |
|
25 |
#include <e32cmn_private.h> |
|
26 |
#include <e32def_private.h> |
|
27 |
#include <drivers/resource_extend.h> |
|
28 |
||
29 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
30 |
#include "rescontrol_psl.h" |
|
31 |
#endif |
|
32 |
||
33 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
34 |
#include <drivers/resmanus_trace.h> |
|
35 |
#endif |
|
36 |
||
37 |
#ifdef PRM_ENABLE_EXTENDED_VERSION2 |
|
38 |
_LIT(KResManUsThreadName,"ResManUsExtendedCoreLddThread"); |
|
39 |
#elif defined (PRM_ENABLE_EXTENDED_VERSION) |
|
40 |
_LIT(KResManUsThreadName,"ResManUsExtendedLddThread"); |
|
41 |
#else |
|
42 |
_LIT(KResManUsThreadName,"ResManUsLddThread"); |
|
43 |
#endif |
|
44 |
||
45 |
#define RESMANUS_FAULT() Kern::Fault("RESMANUS",__LINE__) |
|
46 |
||
47 |
const TInt KResManUsThreadPriority = 24; |
|
48 |
const TInt KResManUsRegistrationPriority = 5; // Arbitrary! Can be 0-7, 7 is highest |
|
49 |
const TInt KResManCallBackPriority = 5; // Arbitrary! Can be 0-7, 7 is highest |
|
50 |
||
51 |
//Macro to return appropriate request type. |
|
52 |
#define GET_USER_REQUEST(request, buffer, type) \ |
|
53 |
{ \ |
|
54 |
if(type == EGetState) \ |
|
55 |
request = ((TTrackGetStateBuf*)buffer)->iRequest; \ |
|
56 |
else if(type == ESetState) \ |
|
57 |
request = ((TTrackSetStateBuf*)buffer)->iRequest; \ |
|
58 |
else \ |
|
59 |
request = ((TTrackNotifyBuf*)buffer)->iRequest; \ |
|
60 |
} |
|
61 |
||
62 |
/*************************************************************************************** |
|
63 |
class TTrackGetStateBuf |
|
64 |
***************************************************************************************/ |
|
65 |
TTrackGetStateBuf::TTrackGetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, |
|
66 |
TDfcQue* aQue, TInt aPriority) |
|
67 |
: iCtrlBlock(aFn, aPtr, aQue, aPriority) |
|
68 |
{ |
|
69 |
iRequest = NULL; |
|
70 |
} |
|
71 |
||
72 |
/*************************************************************************************** |
|
73 |
class TTrackSetStateBuf |
|
74 |
***************************************************************************************/ |
|
75 |
TTrackSetStateBuf::TTrackSetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, |
|
76 |
TDfcQue* aQue, TInt aPriority) |
|
77 |
: iCtrlBlock(aFn, aPtr, aQue, aPriority) |
|
78 |
{ |
|
79 |
iRequest = NULL; |
|
80 |
} |
|
81 |
||
82 |
/*************************************************************************************** |
|
83 |
class TTrackNotifyBuf |
|
84 |
***************************************************************************************/ |
|
85 |
TTrackNotifyBuf::TTrackNotifyBuf(TPowerResourceCbFn aFn, TAny* aPtr, |
|
86 |
TDfcQue* aQue, TInt aPriority) |
|
87 |
: iNotifyBlock(aFn, aPtr, aQue, aPriority) |
|
88 |
{ |
|
89 |
iRequest = NULL; |
|
90 |
} |
|
91 |
||
92 |
TTrackNotifyBuf::~TTrackNotifyBuf() |
|
93 |
{ |
|
94 |
if(iRequest) |
|
95 |
Kern::DestroyClientRequest(iRequest); |
|
96 |
} |
|
97 |
||
98 |
TTrackSetStateBuf::~TTrackSetStateBuf() |
|
99 |
{ |
|
100 |
if(iRequest) |
|
101 |
Kern::DestroyClientRequest(iRequest); |
|
102 |
} |
|
103 |
||
104 |
TTrackGetStateBuf::~TTrackGetStateBuf() |
|
105 |
{ |
|
106 |
if(iRequest) |
|
107 |
Kern::DestroyClientRequest(iRequest); |
|
108 |
} |
|
109 |
||
110 |
/*************************************************************************************** |
|
111 |
class DDeviceResManUs |
|
112 |
***************************************************************************************/ |
|
113 |
DDeviceResManUs::DDeviceResManUs() |
|
114 |
// Constructor |
|
115 |
{ |
|
116 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DDeviceResManUs::DDeviceResManUs()")); |
|
117 |
iParseMask=KDeviceAllowAll&~KDeviceAllowUnit; // Allow info and pdd, but not units |
|
118 |
iUnitsMask=0; |
|
119 |
iVersion=TVersion(KResManUsMajorVersionNumber, |
|
120 |
KResManUsMinorVersionNumber, |
|
121 |
KResManUsBuildVersionNumber); |
|
122 |
} |
|
123 |
||
124 |
DDeviceResManUs::~DDeviceResManUs() |
|
125 |
// Destructor |
|
126 |
{ |
|
127 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DDeviceResManUs::~DDeviceResManUs()")); |
|
128 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
129 |
iSharedDfcQue->Destroy(); |
|
130 |
#else |
|
131 |
delete iSharedDfcQue; |
|
132 |
#endif |
|
133 |
} |
|
134 |
||
135 |
TInt DDeviceResManUs::Install() |
|
136 |
// Install the device driver. |
|
137 |
{ |
|
138 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DDeviceResManUs::Install()")); |
|
139 |
// Create the message queue and initialise the DFC queue pointer |
|
140 |
#ifndef RESOURCE_MANAGER_SIMULATED_PSL |
|
141 |
TInt r=Kern::DfcQInit(iSharedDfcQue,KResManUsThreadPriority,&KResManUsThreadName); |
|
142 |
#else |
|
143 |
TInt r = Kern::DynamicDfcQCreate(iSharedDfcQue,KResManUsThreadPriority,KResManUsThreadName); |
|
144 |
#endif |
|
145 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DfcQCreate r = %d", r)); |
|
146 |
if(r!=KErrNone) |
|
147 |
return r; |
|
148 |
||
149 |
#ifdef CPU_AFFINITY_ANY |
|
150 |
NKern::ThreadSetCpuAffinity((NThread*)(iSharedDfcQue->iThread), KCpuAffinityAny); |
|
151 |
#endif |
|
152 |
r = SetName(&KLddRootName); |
|
153 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> SetName, r = %d", r)); |
|
154 |
return r; |
|
155 |
} |
|
156 |
||
157 |
||
158 |
void DDeviceResManUs::GetCaps(TDes8& aDes) const |
|
159 |
// Return the ResManUs capabilities. |
|
160 |
{ |
|
161 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DDeviceResManUs::GetCaps(TDes8& aDes) const")); |
|
162 |
TPckgBuf<TCapsDevResManUs> b; |
|
163 |
b().version=TVersion(KResManUsMajorVersionNumber, |
|
164 |
KResManUsMinorVersionNumber, |
|
165 |
KResManUsBuildVersionNumber); |
|
166 |
Kern::InfoCopy(aDes,b); |
|
167 |
} |
|
168 |
||
169 |
||
170 |
TInt DDeviceResManUs::Create(DLogicalChannelBase*& aChannel) |
|
171 |
// Create a channel on the device. |
|
172 |
{ |
|
173 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DDeviceResManUs::Create(DLogicalChannelBase*& aChannel)")); |
|
174 |
if(iOpenChannels>=KMaxNumChannels) |
|
175 |
return KErrOverflow; |
|
176 |
aChannel=new DChannelResManUs; |
|
177 |
return aChannel?KErrNone:KErrNoMemory; |
|
178 |
} |
|
179 |
||
180 |
||
181 |
/*************************************************************************************** |
|
182 |
class DChannelResManUs |
|
183 |
***************************************************************************************/ |
|
184 |
DChannelResManUs::DChannelResManUs() |
|
185 |
// Constructor |
|
186 |
{ |
|
187 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::DChannelResManUs()")); |
|
188 |
iClient=&Kern::CurrentThread(); |
|
189 |
// Increase the DThread's ref count so that it does not close without us |
|
190 |
iClient->Open(); |
|
191 |
} |
|
192 |
||
193 |
||
194 |
DChannelResManUs::~DChannelResManUs() |
|
195 |
// Destructor |
|
196 |
{ |
|
197 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::~DChannelResManUs()")); |
|
198 |
||
199 |
// Cancel any outstanding requests |
|
200 |
// |
|
201 |
// For each tracker (Get, Set and notify) |
|
202 |
// |
|
203 |
if(iGetStateTracker != NULL) |
|
204 |
{ |
|
205 |
CancelTrackerRequests(iGetStateTracker,EFalse,0,NULL); // EFalse,0, to ignore resource IDs |
|
206 |
RemoveTrackingControl(iGetStateTracker); |
|
207 |
} |
|
208 |
if(iSetStateTracker != NULL) |
|
209 |
{ |
|
210 |
CancelTrackerRequests(iSetStateTracker,EFalse,0,NULL); // EFalse,0, to ignore resource IDs |
|
211 |
RemoveTrackingControl(iSetStateTracker); |
|
212 |
} |
|
213 |
if(iListenableTracker != NULL) |
|
214 |
{ |
|
215 |
CancelTrackerRequests(iListenableTracker,EFalse,0,NULL); // EFalse,0, to ignore resource IDs |
|
216 |
RemoveTrackingControl(iListenableTracker); |
|
217 |
} |
|
218 |
||
219 |
delete iUserNameUsed; |
|
220 |
delete iResourceDependencyIds; |
|
221 |
delete iClientNamesResCtrl; |
|
222 |
delete iResourceInfoResCtrl; |
|
223 |
||
224 |
// decrement the DThread's reference count |
|
225 |
Kern::SafeClose((DObject*&)iClient, NULL); |
|
226 |
} |
|
227 |
||
228 |
||
229 |
static void AsyncCallBackFn(TUint aClient, TUint aResourceId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aTrackingBuffer) |
|
230 |
{ |
|
231 |
// Callback function for asynchronous requests |
|
232 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> AsyncCallBackFn aClient=0x%x aResourceId=0x%x, aLevel=0x%x, aResult=0x%x, aTrackingBuffer=0x%x\n",aClient, aResourceId, aLevel, aResult, aTrackingBuffer)); |
|
233 |
TTrackingBuffer* buffer = ((TTrackingBuffer*)aTrackingBuffer); |
|
234 |
TTrackingControl* tracker = buffer->GetTrackingControl(); |
|
235 |
__ASSERT_ALWAYS((tracker!=NULL),RESMANUS_FAULT()); |
|
236 |
DChannelResManUs* channel = tracker->iOwningChannel; |
|
237 |
||
238 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
239 |
if(tracker->iType==EGetState) |
|
240 |
{ |
|
241 |
PRM_US_GET_RESOURCE_STATE_END_TRACE; |
|
242 |
} |
|
243 |
else if(tracker->iType==ESetState) |
|
244 |
{ |
|
245 |
PRM_US_SET_RESOURCE_STATE_END_TRACE; |
|
246 |
} |
|
247 |
#endif |
|
248 |
if(tracker->iType == EGetState) |
|
249 |
{ |
|
250 |
TTrackGetStateBuf* stateBuf = (TTrackGetStateBuf*)aTrackingBuffer; |
|
251 |
if(aResult==KErrNone) |
|
252 |
{ |
|
253 |
// Write the state value to the user-supplied variable |
|
254 |
stateBuf->iRequest->Data1() = aLevel; |
|
255 |
stateBuf->iRequest->Data2() = aLevelOwnerId; |
|
256 |
} |
|
257 |
Kern::QueueRequestComplete(channel->iClient, ((TTrackGetStateBuf*)buffer)->iRequest, aResult); |
|
258 |
} |
|
259 |
else if(tracker->iType == ESetState) |
|
260 |
{ |
|
261 |
Kern::QueueRequestComplete(channel->iClient, ((TTrackSetStateBuf*)buffer)->iRequest, aResult); |
|
262 |
} |
|
263 |
// Once notified of a change in a resource state, must cancel the notification |
|
264 |
// request in the Resource Controller to give the client the appearance of a |
|
265 |
// 'one'shot' type of operation. |
|
266 |
else if(tracker->iType==ENotify) |
|
267 |
{ |
|
268 |
#ifdef PRM_ENABLE_EXTENDED_VERSION |
|
269 |
if(((TInt)aClient==KDynamicResourceDeRegistering)&&(aResourceId&KIdMaskDynamic)) |
|
270 |
{ |
|
271 |
// Resource has de-registered from Resource Controller, so can't expect any more notifications |
|
272 |
// of this type. Cancellation of notifications (i.e. invoke Resource Controller) and transfer of |
|
273 |
// buffers to free queue (for both conditional and unconditional notifications) is already done. |
|
274 |
// To distinguish removal of a dynamic resource, hijack aResult (the value used when completing |
|
275 |
// the user-side TRequestStatus object) and set it to KErrDisconnected. |
|
276 |
aResult = KErrDisconnected; |
|
277 |
} |
|
278 |
||
279 |
#endif |
|
280 |
TInt r = (channel->iPddPtr)->CancelNotification(channel->ClientHandle(),aResourceId, |
|
281 |
((TTrackNotifyBuf*)buffer)->iNotifyBlock); |
|
282 |
__ASSERT_ALWAYS((r == KErrCancel),RESMANUS_FAULT()); |
|
283 |
Kern::QueueRequestComplete(channel->iClient, ((TTrackNotifyBuf*)buffer)->iRequest, aResult); |
|
284 |
} |
|
285 |
||
286 |
// Return the tracking buffer to the free queue |
|
287 |
channel->FreeTrackingBuffer(buffer); |
|
288 |
} |
|
289 |
||
290 |
TInt DChannelResManUs::GetValidName(const TDesC8* aInfo) |
|
291 |
{ |
|
292 |
// Extract a usable name from that supplied by the client |
|
293 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DChannelResManUs::GetValidName")); |
|
294 |
TInt err=KErrNone; |
|
295 |
if(aInfo) |
|
296 |
{ |
|
297 |
DThread* thread = &Kern::CurrentThread(); |
|
298 |
TInt nameLen = Kern::ThreadGetDesLength(thread, aInfo); |
|
299 |
if(nameLen<0) |
|
300 |
return nameLen; // return error code |
|
301 |
iNameProvidedLength = nameLen; |
|
302 |
if(nameLen > MAX_CLIENT_NAME_LENGTH) |
|
303 |
err=KErrBadName; |
|
304 |
else |
|
305 |
{ |
|
306 |
nameLen = (nameLen<=MAX_NAME_LENGTH_IN_RESMAN) ? nameLen : MAX_NAME_LENGTH_IN_RESMAN; |
|
307 |
if((iUserNameUsed = HBuf8::New(nameLen))==NULL) |
|
308 |
return KErrNoMemory; |
|
309 |
err = Kern::ThreadDesRead(thread,aInfo,*iUserNameUsed,0); |
|
310 |
if(err!=KErrNone) |
|
311 |
return err; |
|
312 |
} |
|
313 |
} |
|
314 |
else |
|
315 |
err=KErrBadName; |
|
316 |
return err; |
|
317 |
} |
|
318 |
||
319 |
TInt DChannelResManUs::RequestUserHandle(DThread* aThread, TOwnerType aType) |
|
320 |
// Called when a user thread requests a handle to this channel |
|
321 |
{ |
|
322 |
// Make sure that only our client can get a handle |
|
323 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DChannelResManUs::RequestUserHandle")); |
|
324 |
if (aType!=EOwnerThread || aThread!=iClient) |
|
325 |
return KErrAccessDenied; |
|
326 |
return KErrNone; |
|
327 |
} |
|
328 |
||
329 |
void DChannelResManUs::RegistrationDfcFunc(TAny* aChannel) |
|
330 |
{ |
|
331 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DChannelResManUs::RegistrationDfcFunc")); |
|
332 |
// DFC function invoked for registration with Resource Controller |
|
333 |
DChannelResManUs* channel = (DChannelResManUs*)aChannel; |
|
334 |
// RegisterProxyClient(TUint& aProxyId, const TDesC& aName); |
|
335 |
TUint uintVal=0; |
|
336 |
TInt r = KErrNone; |
|
337 |
__ASSERT_ALWAYS((r==KErrNone),RESMANUS_FAULT()); |
|
338 |
||
339 |
r=(channel->iPddPtr)->RegisterProxyClient(uintVal,*((TDesC8*)(channel->iUserNameUsed))); |
|
340 |
if(r!=KErrNone) |
|
341 |
{ |
|
342 |
// Registration failed |
|
343 |
// Ensure that the client-side flag is cleared in uintVal |
|
344 |
// so the failure can be detected in DoCreate |
|
345 |
uintVal &= ~USER_SIDE_CLIENT_BIT_MASK; // Copied from rescontrol_export |
|
346 |
} |
|
347 |
channel->SetClientHandle((TInt)uintVal); |
|
348 |
NKern::FSSignal(channel->iFastSem); |
|
349 |
} |
|
350 |
||
351 |
||
352 |
TInt DChannelResManUs::RegisterWithResCtrlr() |
|
353 |
{ |
|
354 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DChannelResManUs::RegisterWithResCtrlr")); |
|
355 |
TInt r = KErrNone; |
|
356 |
// Initialise the channel's fast semaphore |
|
357 |
iFastSem = new NFastSemaphore(); |
|
358 |
if(iFastSem == NULL) |
|
359 |
r = KErrNoMemory; |
|
360 |
else |
|
361 |
{ |
|
362 |
iFastSem->iOwningThread = (NThreadBase*)NKern::CurrentThread(); |
|
363 |
||
364 |
// Attempt to perform registration with the Resource Controller on behalf of the client. |
|
365 |
SetDfcQ(((DDeviceResManUs*)(iDevice))->iSharedDfcQue); |
|
366 |
TDfc tempDfc(RegistrationDfcFunc, this, iDfcQ, KResManUsRegistrationPriority); |
|
367 |
||
368 |
// Block this thread until the DFC has executed |
|
369 |
tempDfc.Enque(); |
|
370 |
NKern::FSWait(iFastSem); |
|
371 |
// Have finished with iFastSem |
|
372 |
delete iFastSem; |
|
373 |
||
374 |
// Registration complete - check success |
|
375 |
if(!(USER_SIDE_CLIENT_BIT_MASK & ClientHandle())) |
|
376 |
{ |
|
377 |
// Registration failed |
|
378 |
r = KErrCouldNotConnect; |
|
379 |
} |
|
380 |
// Start receiving messages ... |
|
381 |
iMsgQ.Receive(); |
|
382 |
} |
|
383 |
return r; |
|
384 |
} |
|
385 |
||
386 |
TInt DChannelResManUs::DoCreate(TInt /*aUnit*/, |
|
387 |
const TDesC8* aInfo, |
|
388 |
const TVersion &aVer) |
|
389 |
// Create the channel from the passed info. |
|
390 |
{ |
|
391 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer)")); |
|
392 |
||
393 |
TInt r = KErrNone; |
|
394 |
iPddPtr = ((DUserSideProxyInterface*)iPdd)->iController; |
|
395 |
// Check client has appropriate capabilities |
|
396 |
if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by DDevicePowerRsrc::Create"))) |
|
397 |
return KErrPermissionDenied; |
|
398 |
||
399 |
// Check software version |
|
400 |
if (!Kern::QueryVersionSupported(TVersion(KResManUsMajorVersionNumber, |
|
401 |
KResManUsMinorVersionNumber, |
|
402 |
KResManUsBuildVersionNumber), |
|
403 |
aVer)) |
|
404 |
return KErrNotSupported; |
|
405 |
||
406 |
// Implementation note: if this method fails, the destructor will be invoked |
|
407 |
// as part of which all successfully-allocated memory will be freed. Therefore, |
|
408 |
// no memory will be explicitly freed in the event of failure in the code which follows. |
|
409 |
||
410 |
// Allocate the arrays used for acquiring client, resource and dependency information |
|
411 |
if((iClientNamesResCtrl = HBuf8::New(KNumClientNamesResCtrl * sizeof(TPowerClientInfoV01)))==NULL) |
|
412 |
return KErrNoMemory; |
|
413 |
if((iResourceInfoResCtrl = HBuf8::New(KNumResourceInfoResCtrl * sizeof(TPowerResourceInfoV01)))==NULL) |
|
414 |
return KErrNoMemory; |
|
415 |
if((iResourceDependencyIds = HBuf8::New(KNumResourceDependencies * sizeof(SResourceDependencyInfo)))==NULL) |
|
416 |
return KErrNoMemory; |
|
417 |
// Obtain the channel name to use |
|
418 |
if((r=GetValidName(aInfo))!=KErrNone) |
|
419 |
return r; |
|
420 |
#ifdef PRM_ENABLE_EXTENDED_VERSION |
|
421 |
iResDepsValid = 0; |
|
422 |
#endif |
|
423 |
||
424 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
425 |
PRM_US_OPEN_CHANNEL_START_TRACE; |
|
426 |
#endif |
|
427 |
||
428 |
// Set up the request tracking support |
|
429 |
iGetStateTracker = new TTrackingControl(); |
|
430 |
iSetStateTracker = new TTrackingControl();; |
|
431 |
iListenableTracker = new TTrackingControl(); |
|
432 |
if((iGetStateTracker==NULL) || (iSetStateTracker==NULL) || (iListenableTracker==NULL)) |
|
433 |
return KErrNoMemory; |
|
434 |
||
435 |
// Register with the Resource Controller |
|
436 |
r = RegisterWithResCtrlr(); |
|
437 |
||
438 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
439 |
PRM_US_OPEN_CHANNEL_END_TRACE; |
|
440 |
#endif |
|
441 |
||
442 |
return r; |
|
443 |
} |
|
444 |
||
445 |
//Override sendMsg to allow data copy in the context of client thread for WDP. |
|
446 |
TInt DChannelResManUs::SendMsg(TMessageBase* aMsg) |
|
447 |
{ |
|
448 |
TThreadMessage& m = *(TThreadMessage*)aMsg; |
|
449 |
TInt id = m.iValue; |
|
450 |
TInt r = KErrNone; |
|
451 |
if (id != (TInt)ECloseMsg && id != KMaxTInt) |
|
452 |
{ |
|
453 |
if (id<0) |
|
454 |
{ |
|
455 |
TRequestStatus* pS=(TRequestStatus*)m.Ptr0(); |
|
456 |
r = SendRequest(aMsg); |
|
457 |
if (r != KErrNone) |
|
458 |
Kern::RequestComplete(pS,r); |
|
459 |
} |
|
460 |
else |
|
461 |
r = SendControl(aMsg); |
|
462 |
} |
|
463 |
else |
|
464 |
r = DLogicalChannel::SendMsg(aMsg); |
|
465 |
return r; |
|
466 |
} |
|
467 |
||
468 |
TInt DChannelResManUs::SendRequest(TMessageBase* aMsg) |
|
469 |
{ |
|
470 |
TThreadMessage& m = *(TThreadMessage*)aMsg; |
|
471 |
TInt id = ~m.iValue; |
|
472 |
TRequestStatus* pS = (TRequestStatus*)m.Ptr0(); |
|
473 |
TInt r = KErrNone; |
|
474 |
TTrackingBuffer *trackBuf = NULL; |
|
475 |
TUint parms[4]; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
TPowerResourceCb *callBack = NULL; |
0 | 477 |
DPowerResourceNotification *prn; |
478 |
||
479 |
switch(id) |
|
480 |
{ |
|
481 |
case RBusDevResManUs::EChangeResourceState: |
|
482 |
{ |
|
483 |
__ASSERT_ALWAYS(m.Ptr2() != NULL, RESMANUS_FAULT()); |
|
484 |
#ifdef _DUMP_TRACKERS |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
DumpTracker(iSetStateTracker); |
0 | 486 |
#endif |
487 |
r = GetAndInitTrackingBuffer(iSetStateTracker, trackBuf, (TUint)m.Ptr1(), pS); |
|
488 |
if( r != KErrNone) |
|
489 |
return r; |
|
490 |
callBack = &(((TTrackSetStateBuf*)trackBuf)->iCtrlBlock); |
|
491 |
new (callBack) TPowerResourceCb(&AsyncCallBackFn, (TAny*)trackBuf, iDfcQ, KResManCallBackPriority); |
|
492 |
parms[0] = (TUint)m.Ptr2(); |
|
493 |
parms[1] = (TUint)callBack; |
|
494 |
m.iArg[2] = &(parms[0]); |
|
495 |
break; |
|
496 |
} |
|
497 |
case RBusDevResManUs::EGetResourceState: |
|
498 |
{ |
|
499 |
__ASSERT_ALWAYS(m.Ptr2() != NULL, RESMANUS_FAULT()); |
|
500 |
umemget32(&(parms[0]), m.Ptr2(), 3*sizeof(TInt)); |
|
501 |
#ifdef _DUMP_TRACKERS |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
DumpTracker(iGetStateTracker); |
0 | 503 |
#endif |
504 |
r = GetStateBuffer(iGetStateTracker, trackBuf, (TUint)m.Ptr1(), (TInt*)parms[1], (TInt*)parms[2], callBack, pS); |
|
505 |
if(r != KErrNone) |
|
506 |
return r; |
|
507 |
parms[3] = (TUint)callBack; |
|
508 |
m.iArg[2] = &(parms[0]); |
|
509 |
break; |
|
510 |
} |
|
511 |
case RBusDevResManUs::ERequestChangeNotification: |
|
512 |
{ |
|
513 |
__ASSERT_ALWAYS(m.Ptr1() != NULL, RESMANUS_FAULT()); |
|
514 |
r = GetAndInitTrackingBuffer(iListenableTracker, trackBuf, (TUint)m.Ptr1(), pS); |
|
515 |
if(r != KErrNone) |
|
516 |
return r; |
|
517 |
prn = &(((TTrackNotifyBuf*)trackBuf)->iNotifyBlock); |
|
518 |
new (prn) DPowerResourceNotification(&AsyncCallBackFn, (TAny*)trackBuf, iDfcQ, KResManCallBackPriority); |
|
519 |
m.iArg[2] = (TAny*)prn; |
|
520 |
break; |
|
521 |
} |
|
522 |
case RBusDevResManUs::ERequestQualifiedChangeNotification: |
|
523 |
{ |
|
524 |
__ASSERT_ALWAYS(m.Ptr1() != NULL, RESMANUS_FAULT()); |
|
525 |
__ASSERT_ALWAYS(m.Ptr2() != NULL, RESMANUS_FAULT()); |
|
526 |
umemget32(&(parms[0]), m.Ptr2(), 2*sizeof(TUint)); |
|
527 |
m.iArg[2] = &parms[0]; |
|
528 |
r = GetAndInitTrackingBuffer(iListenableTracker, trackBuf, (TUint)parms[0], pS); |
|
529 |
if(r != KErrNone) |
|
530 |
return r; |
|
531 |
prn = &(((TTrackNotifyBuf*)trackBuf)->iNotifyBlock); |
|
532 |
new (prn) DPowerResourceNotification(&AsyncCallBackFn, (TAny*)trackBuf, iDfcQ, KResManCallBackPriority); |
|
533 |
parms[2] = (TUint)prn; |
|
534 |
break; |
|
535 |
} |
|
536 |
default: |
|
537 |
{ |
|
538 |
return KErrNotSupported; |
|
539 |
} |
|
540 |
} |
|
541 |
||
542 |
if(r == KErrNone) |
|
543 |
r = DLogicalChannel::SendMsg(aMsg); |
|
544 |
if(r != KErrNone) |
|
545 |
FreeTrackingBuffer(trackBuf); |
|
546 |
return r; |
|
547 |
} |
|
548 |
||
549 |
||
550 |
TInt DChannelResManUs::SendControl(TMessageBase* aMsg) |
|
551 |
{ |
|
552 |
TThreadMessage& m = *(TThreadMessage*)aMsg; |
|
553 |
TInt id = m.iValue; |
|
554 |
TInt param1 = 0; |
|
555 |
TUint parms[4]; |
|
556 |
TAny* a1 = m.Ptr0(); |
|
557 |
TAny* a2 = m.Ptr1(); |
|
558 |
TAny* ptr1 = NULL; |
|
559 |
switch(id) |
|
560 |
{ |
|
561 |
case RBusDevResManUs::EInitialise: |
|
562 |
{ |
|
563 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
564 |
TUint8 stateRes[3]; |
|
565 |
umemget(&(stateRes[0]), a1, 3*sizeof(TUint8)); |
|
566 |
m.iArg[0] = &(stateRes[0]); |
|
567 |
break; |
|
568 |
} |
|
569 |
case RBusDevResManUs::EGetNoOfResources: |
|
570 |
case RBusDevResManUs::EGetResourceControllerVersion: |
|
571 |
{ |
|
572 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
573 |
m.iArg[0] = ¶m1; |
|
574 |
break; |
|
575 |
} |
|
576 |
case RBusDevResManUs::EGetNoOfClients: |
|
577 |
case RBusDevResManUs::EGetNumClientsUsingResource: |
|
578 |
{ |
|
579 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
580 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
581 |
umemget32(&(parms[0]), a2, 3*sizeof(TUint)); |
|
582 |
m.iArg[1] = &(parms[0]); |
|
583 |
m.iArg[0] = ¶m1; |
|
584 |
break; |
|
585 |
} |
|
586 |
case RBusDevResManUs::EGetNumResourcesInUseByClient: |
|
587 |
{ |
|
588 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
589 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
590 |
TBuf8 <MAX_NAME_LENGTH_IN_RESMAN> clientName; |
|
591 |
Kern::KUDesGet(clientName, *(TDesC8*)m.Ptr0()); |
|
592 |
m.iArg[0] = (TAny*)&clientName; |
|
593 |
umemget32(&(parms[0]), m.Ptr1(), 2*sizeof(TUint)); |
|
594 |
param1 = parms[1]; |
|
595 |
m.iArg[1] = ¶m1; |
|
596 |
break; |
|
597 |
} |
|
598 |
case RBusDevResManUs::EGetResourceIdByName: |
|
599 |
{ |
|
600 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
601 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
602 |
TBuf8 <MAX_NAME_LENGTH_IN_RESMAN> resourceName; |
|
603 |
Kern::KUDesGet(resourceName, *(TDesC8*)m.Ptr0()); |
|
604 |
m.iArg[0] = (TAny*)&resourceName; |
|
605 |
m.iArg[1] = ¶m1; |
|
606 |
break; |
|
607 |
} |
|
608 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
609 |
case RBusDevResManUs::EGetNumCandidateAsyncResources: |
|
610 |
case RBusDevResManUs::EGetNumCandidateSharedResources: |
|
611 |
{ |
|
612 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
613 |
m.iArg[0] = ¶m1; |
|
614 |
break; |
|
615 |
} |
|
616 |
case RBusDevResManUs::EGetCandidateAsyncResourceId: |
|
617 |
case RBusDevResManUs::EGetCandidateSharedResourceId: |
|
618 |
{ |
|
619 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
620 |
m.iArg[1] = ¶m1; |
|
621 |
break; |
|
622 |
} |
|
623 |
#endif |
|
624 |
case RBusDevResManUs::EGetNumDependentsForResource: |
|
625 |
{ |
|
626 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
627 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
628 |
umemget32(&(parms[0]), m.Ptr1(), 2*sizeof(TUint)); |
|
629 |
m.iArg[1] = &(parms[0]); |
|
630 |
m.iArg[0] = ¶m1; |
|
631 |
break; |
|
632 |
} |
|
633 |
case RBusDevResManUs::EGetDependentsIdForResource: |
|
634 |
{ |
|
635 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
636 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
637 |
umemget32(&(parms[0]), m.Ptr1(), 3*sizeof(TUint)); |
|
638 |
TInt len, maxLen; |
|
639 |
ptr1 = (TAny*)parms[1]; |
|
640 |
Kern::KUDesInfo(*(const TDesC8*)parms[1], len, maxLen); |
|
641 |
umemget32(¶m1, m.Ptr0(), sizeof(TUint)); |
|
642 |
if((maxLen - len) < (TInt)(param1 * sizeof(SResourceDependencyInfo))) |
|
643 |
{ |
|
644 |
return KErrArgument; |
|
645 |
} |
|
646 |
m.iArg[0] = ¶m1; |
|
647 |
m.iArg[1] = &(parms[0]); |
|
648 |
break; |
|
649 |
} |
|
650 |
case RBusDevResManUs::EGetResourceInfo: |
|
651 |
{ |
|
652 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
653 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
654 |
TResourceInfoBuf buf; |
|
655 |
m.iArg[1] = &buf; |
|
656 |
break; |
|
657 |
} |
|
658 |
case RBusDevResManUs::EGetAllResourcesInfo: |
|
659 |
{ |
|
660 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
661 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
662 |
umemget32(&(parms[0]), m.Ptr1(), 2*sizeof(TUint)); |
|
663 |
ptr1 = (TAny*)parms[0]; |
|
664 |
umemget32(¶m1, (TAny*)parms[0], sizeof(TUint)); |
|
665 |
parms[0] =(TUint)¶m1; |
|
666 |
RSimplePointerArray<TResourceInfoBuf> infoPtrs; |
|
667 |
umemget(&infoPtrs, m.Ptr0(), sizeof(RSimplePointerArray<TResourceInfoBuf>)); |
|
668 |
if((infoPtrs.Count() < 0) || (infoPtrs.Count() < param1)) |
|
669 |
return KErrArgument; |
|
670 |
m.iArg[1] = &(parms[0]); |
|
671 |
break; |
|
672 |
} |
|
673 |
case RBusDevResManUs::EGetInfoOnClientsUsingResource: |
|
674 |
{ |
|
675 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
676 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
677 |
umemget32(&parms[0], m.Ptr1(), 4*sizeof(TUint)); |
|
678 |
ptr1 = (TAny*)parms[0]; |
|
679 |
umemget32(¶m1, (TAny*)parms[0], sizeof(TUint)); |
|
680 |
parms[0] = (TUint)¶m1; |
|
681 |
RSimplePointerArray<TClientInfoBuf>infoPtrs; |
|
682 |
umemget(&infoPtrs, m.Ptr0(), sizeof(RSimplePointerArray<TClientInfoBuf>)); |
|
683 |
if((infoPtrs.Count() < 0) || (infoPtrs.Count() < param1)) |
|
684 |
return KErrArgument; |
|
685 |
m.iArg[1] = &(parms[0]); |
|
686 |
break; |
|
687 |
} |
|
688 |
case RBusDevResManUs::EGetNamesAllClients: |
|
689 |
{ |
|
690 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
691 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
692 |
umemget32(&parms[0], m.Ptr1(), 4*sizeof(TUint)); |
|
693 |
ptr1 = (TAny*)parms[0]; |
|
694 |
umemget32(¶m1, (TAny*)parms[0], sizeof(TUint)); |
|
695 |
parms[0] = (TUint)¶m1; |
|
696 |
RSimplePointerArray<TClientName> infoPtrs; |
|
697 |
umemget(&infoPtrs, m.Ptr0(), sizeof(RSimplePointerArray<TClientName>)); |
|
698 |
if((infoPtrs.Count() < 0) || (infoPtrs.Count() < param1)) |
|
699 |
return KErrArgument; |
|
700 |
m.iArg[1] = &(parms[0]); |
|
701 |
break; |
|
702 |
} |
|
703 |
case RBusDevResManUs::EGetInfoOnResourcesInUseByClient: |
|
704 |
{ |
|
705 |
__ASSERT_ALWAYS(a1 != NULL, RESMANUS_FAULT()); |
|
706 |
__ASSERT_ALWAYS(a2 != NULL, RESMANUS_FAULT()); |
|
707 |
TBuf8 <MAX_NAME_LENGTH_IN_RESMAN> clientName; |
|
708 |
Kern::KUDesGet(clientName, *(TDesC8*)m.Ptr0()); |
|
709 |
m.iArg[0] = (TAny*)&clientName; |
|
710 |
umemget32(&parms[0], m.Ptr1(), 3*sizeof(TUint)); |
|
711 |
ptr1 = (TAny*)parms[0]; |
|
712 |
umemget32(¶m1, (TAny*)parms[0], sizeof(TUint)); |
|
713 |
parms[0] = (TUint)¶m1; |
|
714 |
RSimplePointerArray<TResourceInfoBuf> infoPtrs; |
|
715 |
umemget(&infoPtrs, (TAny*)parms[1], sizeof(RSimplePointerArray<TResourceInfoBuf>)); |
|
716 |
if((infoPtrs.Count() < 0) || (infoPtrs.Count() < param1)) |
|
717 |
return KErrArgument; |
|
718 |
m.iArg[1] = &(parms[0]); |
|
719 |
break; |
|
720 |
} |
|
721 |
} |
|
722 |
||
723 |
TInt r = DLogicalChannel::SendMsg(aMsg); |
|
724 |
if(r != KErrNone) |
|
725 |
return r; |
|
726 |
||
727 |
switch(id) |
|
728 |
{ |
|
729 |
case RBusDevResManUs::EGetNoOfResources: |
|
730 |
case RBusDevResManUs::EGetNoOfClients: |
|
731 |
case RBusDevResManUs::EGetNumClientsUsingResource: |
|
732 |
case RBusDevResManUs::EGetResourceControllerVersion: |
|
733 |
case RBusDevResManUs::EGetNumDependentsForResource: |
|
734 |
{ |
|
735 |
umemput32(a1, (TAny*)¶m1, sizeof(TUint)); |
|
736 |
break; |
|
737 |
} |
|
738 |
case RBusDevResManUs::EGetNumResourcesInUseByClient: |
|
739 |
{ |
|
740 |
umemput32((TAny*)parms[0], (TAny*)¶m1, sizeof(TUint)); |
|
741 |
break; |
|
742 |
} |
|
743 |
case RBusDevResManUs::EGetResourceIdByName: |
|
744 |
{ |
|
745 |
umemput32(a2, (TAny*)¶m1, sizeof(TUint)); |
|
746 |
break; |
|
747 |
} |
|
748 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
749 |
case RBusDevResManUs::EGetNumCandidateAsyncResources: |
|
750 |
case RBusDevResManUs::EGetNumCandidateSharedResources: |
|
751 |
{ |
|
752 |
umemput32(a1, (TAny*)¶m1, sizeof(TUint)); |
|
753 |
break; |
|
754 |
} |
|
755 |
case RBusDevResManUs::EGetCandidateAsyncResourceId: |
|
756 |
case RBusDevResManUs::EGetCandidateSharedResourceId: |
|
757 |
{ |
|
758 |
umemput32(a2, (TAny*)¶m1, sizeof(TUint)); |
|
759 |
break; |
|
760 |
} |
|
761 |
#endif |
|
762 |
case RBusDevResManUs::EGetDependentsIdForResource: |
|
763 |
{ |
|
764 |
r = Kern::ThreadDesWrite(iClient,(TAny*)ptr1, (const TDesC8&)*(SResourceDependencyInfo*)parms[1], 0); |
|
765 |
if(r == KErrOverflow) //This is done to retain the error as per API spec |
|
766 |
r = KErrArgument; |
|
767 |
break; |
|
768 |
} |
|
769 |
case RBusDevResManUs::EGetResourceInfo: |
|
770 |
{ |
|
771 |
Kern::KUDesPut(*(TDes8*)a2, (const TDesC8&)*(TResourceInfoBuf*)m.Ptr1()); |
|
772 |
break; |
|
773 |
} |
|
774 |
case RBusDevResManUs::EGetAllResourcesInfo: |
|
775 |
{ |
|
776 |
TUint numToCopy; |
|
777 |
RSimplePointerArray<TResourceInfoBuf> infoPtrs; |
|
778 |
umemget(&infoPtrs, a1, sizeof(RSimplePointerArray<TResourceInfoBuf>)); |
|
779 |
numToCopy = (infoPtrs.Count() < param1) ? infoPtrs.Count() : param1; |
|
780 |
umemput32(ptr1, (TAny*)¶m1, sizeof(TUint)); |
|
781 |
TResourceInfoBuf** entriesAddr = infoPtrs.Entries(); |
|
782 |
TInt* entryPtr = (TInt*)entriesAddr; |
|
783 |
TPowerResourceInfoV01 *currRes = (TPowerResourceInfoV01*)iResourceInfoResCtrl->Ptr(); |
|
784 |
TResourceInfoBuf* clientAddr; |
|
785 |
TResourceInfoBuf tempInfo; |
|
786 |
for(TUint index = 0; index < numToCopy; index++) |
|
787 |
{ |
|
788 |
umemget32(&clientAddr, entryPtr, sizeof(TResourceInfoBuf*)); |
|
789 |
entryPtr++; |
|
790 |
r = ExtractResourceInfo(currRes, tempInfo); |
|
791 |
if(r != KErrNone) |
|
792 |
return r; |
|
793 |
umemput((TAny*)clientAddr, (TAny*)&(tempInfo), tempInfo.Length()); |
|
794 |
currRes++; |
|
795 |
} |
|
796 |
break; |
|
797 |
} |
|
798 |
case RBusDevResManUs::EGetInfoOnClientsUsingResource: |
|
799 |
{ |
|
800 |
TUint numToCopy; |
|
801 |
RSimplePointerArray<TClientInfoBuf> infoPtrs; |
|
802 |
umemget(&infoPtrs, a1, sizeof(RSimplePointerArray<TClientName>)); |
|
803 |
numToCopy = infoPtrs.Count(); |
|
804 |
TClientInfoBuf** entriesAddr = infoPtrs.Entries(); |
|
805 |
TInt* entryPtr = (TInt*)entriesAddr; |
|
806 |
TPowerClientInfoV01* rcDataPtr = (TPowerClientInfoV01*)iClientNamesResCtrl->Ptr(); |
|
807 |
TClientInfoBuf* clientAddr; |
|
808 |
TUint userSideClients = 0; |
|
809 |
TClientInfoBuf tempInfo; |
|
810 |
for(TInt index = 0; index < param1; index++) |
|
811 |
{ |
|
812 |
if((!parms[1]) && !(rcDataPtr->iClientId & USER_SIDE_CLIENT_BIT_MASK)) |
|
813 |
{ |
|
814 |
rcDataPtr++; |
|
815 |
continue; |
|
816 |
} |
|
817 |
if(numToCopy == 0) |
|
818 |
{ |
|
819 |
userSideClients++; |
|
820 |
continue; |
|
821 |
} |
|
822 |
umemget32(&clientAddr, entryPtr, sizeof(TClientName*)); |
|
823 |
entryPtr++; |
|
824 |
tempInfo().iId = rcDataPtr->iClientId; |
|
825 |
tempInfo().iName = *rcDataPtr->iClientName; |
|
826 |
Kern::InfoCopy(*clientAddr, tempInfo); |
|
827 |
rcDataPtr++; |
|
828 |
numToCopy--; |
|
829 |
userSideClients++; |
|
830 |
} |
|
831 |
if(parms[1]) |
|
832 |
umemput32(ptr1, (TAny*)¶m1, sizeof(TUint)); |
|
833 |
else |
|
834 |
umemput32(ptr1, (TAny*)&userSideClients, sizeof(TUint)); |
|
835 |
break; |
|
836 |
} |
|
837 |
case RBusDevResManUs::EGetNamesAllClients: |
|
838 |
{ |
|
839 |
TUint numToCopy; |
|
840 |
RSimplePointerArray<TClientName> infoPtrs; |
|
841 |
umemget(&infoPtrs, a1, sizeof(RSimplePointerArray<TClientName>)); |
|
842 |
numToCopy = infoPtrs.Count(); |
|
843 |
TClientName** entriesAddr = infoPtrs.Entries(); |
|
844 |
TInt* entryPtr = (TInt*)entriesAddr; |
|
845 |
TPowerClientInfoV01* rcDataPtr = (TPowerClientInfoV01*)iClientNamesResCtrl->Ptr(); |
|
846 |
TClientName* clientAddr; |
|
847 |
TUint userSideClients = 0; |
|
848 |
for(TInt index = 0; index < param1; index++) |
|
849 |
{ |
|
850 |
if((!parms[1]) && !(rcDataPtr->iClientId & USER_SIDE_CLIENT_BIT_MASK)) |
|
851 |
{ |
|
852 |
rcDataPtr++; |
|
853 |
continue; |
|
854 |
} |
|
855 |
if(numToCopy == 0) |
|
856 |
{ |
|
857 |
userSideClients++; |
|
858 |
continue; |
|
859 |
} |
|
860 |
umemget32(&clientAddr, entryPtr, sizeof(TClientName*)); |
|
861 |
entryPtr++; |
|
862 |
Kern::KUDesPut(*((TDes8*)clientAddr), *(const TDesC8*)rcDataPtr->iClientName); |
|
863 |
rcDataPtr++; |
|
864 |
numToCopy--; |
|
865 |
userSideClients++; |
|
866 |
} |
|
867 |
if(parms[1]) |
|
868 |
umemput32(ptr1, (TAny*)¶m1, sizeof(TUint)); |
|
869 |
else |
|
870 |
umemput32(ptr1, (TAny*)&userSideClients, sizeof(TUint)); |
|
871 |
break; |
|
872 |
} |
|
873 |
case RBusDevResManUs::EGetInfoOnResourcesInUseByClient: |
|
874 |
{ |
|
875 |
TUint numToCopy; |
|
876 |
RSimplePointerArray<TResourceInfoBuf> infoPtrs; |
|
877 |
umemget(&infoPtrs, (TAny*)parms[1], sizeof(RSimplePointerArray<TResourceInfoBuf>)); |
|
878 |
numToCopy = (infoPtrs.Count() < param1) ? infoPtrs.Count() : param1; |
|
879 |
umemput32(ptr1, (TAny*)¶m1, sizeof(TUint)); |
|
880 |
TResourceInfoBuf** entriesAddr = infoPtrs.Entries(); |
|
881 |
TInt* entryPtr = (TInt*)entriesAddr; |
|
882 |
TPowerResourceInfoV01* currRes = (TPowerResourceInfoV01*)iResourceInfoResCtrl->Ptr(); |
|
883 |
TResourceInfoBuf* clientAddr; |
|
884 |
TResourceInfoBuf tempInfo; |
|
885 |
for(TUint index = 0; index < numToCopy; index++) |
|
886 |
{ |
|
887 |
umemget32(&clientAddr, entryPtr, sizeof(TResourceInfoBuf*)); |
|
888 |
entryPtr++; |
|
889 |
r = ExtractResourceInfo(currRes, tempInfo); |
|
890 |
if(r != KErrNone) |
|
891 |
return r; |
|
892 |
umemput((TAny*)clientAddr, (TAny*)&(tempInfo), tempInfo.Length()); |
|
893 |
currRes++; |
|
894 |
} |
|
895 |
break; |
|
896 |
} |
|
897 |
} |
|
898 |
return r; |
|
899 |
} |
|
900 |
||
901 |
void DChannelResManUs::HandleMsg(TMessageBase* aMsg) |
|
902 |
{ |
|
903 |
TThreadMessage& m=*(TThreadMessage*)aMsg; |
|
904 |
TInt id=m.iValue; |
|
905 |
||
906 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(" >ldd: DChannelResManUs::HandleMsg(TMessageBase* aMsg) id=%d\n", id)); |
|
907 |
||
908 |
if (id==(TInt)ECloseMsg) |
|
909 |
{ |
|
910 |
// Deregister here to ensure the correct thread ID is read |
|
911 |
if(ClientHandle() != 0) |
|
912 |
{ |
|
913 |
// Must de-register from Resource Controller before closing down |
|
914 |
// Not checking return value - still need to delete allocated buffers |
|
915 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
916 |
PRM_US_DEREGISTER_CLIENT_START_TRACE; |
|
917 |
#endif |
|
918 |
((DPowerResourceController*)iPddPtr)->DeregisterProxyClient(ClientHandle()); |
|
919 |
||
920 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
921 |
PRM_US_DEREGISTER_CLIENT_END_TRACE; |
|
922 |
#endif |
|
923 |
SetClientHandle(0); |
|
924 |
} |
|
925 |
iMsgQ.iMessage->Complete(KErrNone,EFalse); |
|
926 |
return; |
|
927 |
} |
|
928 |
else if (id==KMaxTInt) |
|
929 |
{ |
|
930 |
// DoCancel |
|
931 |
DoCancel(m.Int0()); |
|
932 |
m.Complete(KErrNone,ETrue); |
|
933 |
return; |
|
934 |
} |
|
935 |
||
936 |
if (id<0) |
|
937 |
{ |
|
938 |
// DoRequest |
|
939 |
TRequestStatus* pS=(TRequestStatus*)m.Ptr0(); |
|
940 |
TInt r=DoRequest(~id, pS, m.Ptr1(), m.Ptr2()); |
|
941 |
m.Complete(r,ETrue); |
|
942 |
} |
|
943 |
else |
|
944 |
{ |
|
945 |
// DoControl |
|
946 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(" >ldd: do control id=%d...\n", id)); |
|
947 |
TInt r=DoControl(id,m.Ptr0(),m.Ptr1()); |
|
948 |
m.Complete(r,ETrue); |
|
949 |
} |
|
950 |
} |
|
951 |
||
952 |
TInt DChannelResManUs::CancelTrackerRequests(TTrackingControl* aTracker, TBool aSingleRsrc, TUint aResourceId, TRequestStatus* aStatus) |
|
953 |
{ |
|
954 |
// Cancel all outstanding requests from this client for a specified operation on |
|
955 |
// a specified resource |
|
956 |
||
957 |
// Loop all entries in the iBusyQue of requests to locate a match for the |
|
958 |
// operation type and resource ID |
|
959 |
// |
|
960 |
// For each match, remove the buffer from the busy queue and return to the free queue |
|
961 |
// If the request is already being processed, and so the callback function will be called |
|
962 |
// later, then the callback will exit gracefully. |
|
963 |
// |
|
964 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(" > DChannelResManUs::CancelTrackerRequests")); |
|
965 |
TInt returnVal = KErrNone; |
|
966 |
TBool statusMatched=EFalse; |
|
967 |
TTrackingBuffer* firstLink = NULL; |
|
968 |
TTrackingBuffer* lastLink = NULL; |
|
969 |
TInt type = aTracker->iType; |
|
970 |
||
971 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
972 |
if(type==EGetState) |
|
973 |
{ |
|
974 |
PRM_US_CANCEL_GET_RESOURCE_STATE_START_TRACE; |
|
975 |
} |
|
976 |
else if(type==ESetState) |
|
977 |
{ |
|
978 |
PRM_US_CANCEL_SET_RESOURCE_STATE_START_TRACE; |
|
979 |
} |
|
980 |
#endif |
|
981 |
||
982 |
if(aTracker->iBusyQue != NULL) |
|
983 |
{ |
|
984 |
firstLink = (TTrackingBuffer*)(aTracker->iBusyQue->iA.iNext); |
|
985 |
lastLink = (TTrackingBuffer*)(&(aTracker->iBusyQue->iA)); |
|
986 |
} |
|
987 |
while(( firstLink!=lastLink )&&(!statusMatched)) |
|
988 |
{ |
|
989 |
TTrackingBuffer* buffer = firstLink; |
|
990 |
TUint resourceId = buffer->GetResourceId(); |
|
991 |
if(aSingleRsrc) |
|
992 |
if(resourceId != aResourceId) // Required resource? |
|
993 |
{ |
|
994 |
firstLink=(TTrackingBuffer*)(firstLink->iNext); |
|
995 |
continue; |
|
996 |
} |
|
997 |
if(aStatus!=NULL) |
|
998 |
{ |
|
999 |
TClientRequest *request; |
|
1000 |
GET_USER_REQUEST(request, buffer, type) |
|
1001 |
if(request->StatusPtr() == aStatus) |
|
1002 |
{ |
|
1003 |
statusMatched = ETrue; |
|
1004 |
} |
|
1005 |
else |
|
1006 |
{ |
|
1007 |
firstLink=(TTrackingBuffer*)(firstLink->iNext); |
|
1008 |
continue; |
|
1009 |
} |
|
1010 |
} |
|
1011 |
TInt r = KErrNone; |
|
1012 |
if(type==EGetState) |
|
1013 |
{ |
|
1014 |
TTrackGetStateBuf* stateBuf = (TTrackGetStateBuf*)firstLink; |
|
1015 |
r=((DPowerResourceController*)iPddPtr)->CancelAsyncRequestCallBack(ClientHandle(), |
|
1016 |
resourceId, (stateBuf->iCtrlBlock)); |
|
1017 |
} |
|
1018 |
else if(type==ESetState) |
|
1019 |
{ |
|
1020 |
TTrackSetStateBuf* stateBuf = (TTrackSetStateBuf*)firstLink; |
|
1021 |
r = ((DPowerResourceController*)iPddPtr)->CancelAsyncRequestCallBack(ClientHandle(), |
|
1022 |
resourceId, (stateBuf->iCtrlBlock)); |
|
1023 |
} |
|
1024 |
else if(type==ENotify) |
|
1025 |
{ |
|
1026 |
TTrackNotifyBuf* notifyBuf = (TTrackNotifyBuf*)firstLink; |
|
1027 |
r=((DPowerResourceController*)iPddPtr)->CancelNotification(ClientHandle(), resourceId, |
|
1028 |
notifyBuf->iNotifyBlock); |
|
1029 |
} |
|
1030 |
||
1031 |
// Process the accumulated return value |
|
1032 |
if((r==KErrCompletion)&&((returnVal==KErrNone)||(returnVal==KErrCancel))) |
|
1033 |
{ |
|
1034 |
returnVal=KErrCompletion; |
|
1035 |
} |
|
1036 |
else if((r==KErrInUse)&& |
|
1037 |
((returnVal==KErrNone)||(returnVal==KErrCompletion)||(returnVal==KErrCancel))) |
|
1038 |
{ |
|
1039 |
returnVal=KErrInUse; |
|
1040 |
} |
|
1041 |
else if(r!=KErrCancel) |
|
1042 |
{ |
|
1043 |
returnVal=r; |
|
1044 |
} |
|
1045 |
||
1046 |
// Return the tracking buffer to the free queue |
|
1047 |
TTrackingBuffer* tempLink = (TTrackingBuffer*)(firstLink->iNext); |
|
1048 |
FreeTrackingBuffer(firstLink); |
|
1049 |
firstLink = tempLink; |
|
1050 |
||
1051 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
1052 |
if(type==EGetState) |
|
1053 |
{ |
|
1054 |
PRM_US_CANCEL_GET_RESOURCE_STATE_END_TRACE; |
|
1055 |
} |
|
1056 |
else if(type==ESetState) |
|
1057 |
{ |
|
1058 |
PRM_US_CANCEL_SET_RESOURCE_STATE_END_TRACE; |
|
1059 |
} |
|
1060 |
#endif |
|
1061 |
// Complete the TRequestStatus object |
|
1062 |
if((r!=KErrCompletion)&&(r!=KErrInUse)) |
|
1063 |
{ |
|
1064 |
TClientRequest* request; |
|
1065 |
GET_USER_REQUEST(request, buffer, type) |
|
1066 |
Kern::QueueRequestComplete(iClient, request, r); |
|
1067 |
} |
|
1068 |
||
1069 |
} // while |
|
1070 |
return returnVal; |
|
1071 |
} |
|
1072 |
||
1073 |
||
1074 |
TTrackingControl* DChannelResManUs::MapRequestToTracker(TInt aRequestType) |
|
1075 |
// Utility function to map identifiers for cancel commands to request types. |
|
1076 |
{ |
|
1077 |
TTrackingControl *tracker=NULL; |
|
1078 |
switch(aRequestType) |
|
1079 |
{ |
|
1080 |
case RBusDevResManUs::ECancelChangeResourceStateRequests: |
|
1081 |
case RBusDevResManUs::ECancelChangeResourceState: |
|
1082 |
{ |
|
1083 |
tracker=iSetStateTracker; |
|
1084 |
break; |
|
1085 |
} |
|
1086 |
case RBusDevResManUs::ECancelGetResourceStateRequests: |
|
1087 |
case RBusDevResManUs::ECancelGetResourceState: |
|
1088 |
{ |
|
1089 |
tracker=iGetStateTracker; |
|
1090 |
break; |
|
1091 |
} |
|
1092 |
case RBusDevResManUs::ECancelChangeNotificationRequests: |
|
1093 |
case RBusDevResManUs::ECancelRequestChangeNotification: |
|
1094 |
{ |
|
1095 |
tracker=iListenableTracker; |
|
1096 |
break; |
|
1097 |
} |
|
1098 |
default: |
|
1099 |
{ |
|
1100 |
__ASSERT_ALWAYS(0,RESMANUS_FAULT()); |
|
1101 |
} |
|
1102 |
} |
|
1103 |
return tracker; |
|
1104 |
} |
|
1105 |
||
1106 |
||
1107 |
TInt DChannelResManUs::CancelRequestsOfType(TInt aRequestType, TRequestStatus* aStatus) |
|
1108 |
// Cancel a particular request. This may be qualified by the type of operation |
|
1109 |
{ |
|
1110 |
__ASSERT_ALWAYS(((aRequestType==RBusDevResManUs::ECancelChangeResourceState)|| |
|
1111 |
(aRequestType==RBusDevResManUs::ECancelGetResourceState)|| |
|
1112 |
(aRequestType==RBusDevResManUs::ECancelRequestChangeNotification)|| |
|
1113 |
(KMaxTInt)), |
|
1114 |
RESMANUS_FAULT()); |
|
1115 |
// For the KMaxTInt case, the type of the request is not known and so all trackers |
|
1116 |
// must be considered before the request is found. |
|
1117 |
// For all other cases, only the relevant tracker is searched. |
|
1118 |
TInt r=KErrNone; |
|
1119 |
if(aRequestType!=KMaxTInt) |
|
1120 |
{ |
|
1121 |
TTrackingControl*tracker=MapRequestToTracker(aRequestType); |
|
1122 |
r=CancelTrackerRequests(tracker, EFalse, 0, aStatus); |
|
1123 |
} |
|
1124 |
else |
|
1125 |
{ |
|
1126 |
TTrackingControl* tracker[3] = {iGetStateTracker, iSetStateTracker, iListenableTracker}; |
|
1127 |
TUint8 index=0; |
|
1128 |
while((index<3) && (r==KErrNone)) |
|
1129 |
{ |
|
1130 |
r=CancelTrackerRequests(tracker[index], EFalse, 0, aStatus); |
|
1131 |
++index; |
|
1132 |
} |
|
1133 |
} |
|
1134 |
if(r==KErrCancel) |
|
1135 |
r=KErrNone; // All cancellations were successful |
|
1136 |
||
1137 |
return r; |
|
1138 |
} |
|
1139 |
||
1140 |
||
1141 |
void DChannelResManUs::DoCancel(TInt aMask) |
|
1142 |
// Cancel an outstanding request. |
|
1143 |
{ |
|
1144 |
TRequestStatus* status = (TRequestStatus*)aMask; |
|
1145 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoCancel, TRequestStatus addr = 0x%x",(TInt)status)); |
|
1146 |
||
1147 |
CancelRequestsOfType(KMaxTInt, status); // Ignore return value |
|
1148 |
return; |
|
1149 |
} |
|
1150 |
||
1151 |
TInt DChannelResManUs::DoRequest(TInt aReqNo, TRequestStatus* /*aStatus*/, TAny* a1, TAny* a2) |
|
1152 |
// Asynchronous requests. |
|
1153 |
{ |
|
1154 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2)")); |
|
1155 |
||
1156 |
TInt r=KErrNone; |
|
1157 |
switch (aReqNo) |
|
1158 |
{ |
|
1159 |
case RBusDevResManUs::EChangeResourceState: |
|
1160 |
{ |
|
1161 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoRequest case EChangeResourceState")); |
|
1162 |
// a1 specifies the identifier of the required resource |
|
1163 |
// a2 specifies the required state for the resource |
|
1164 |
// |
|
1165 |
TUint *param = (TUint*)a2; |
|
1166 |
TUint resourceId = (TUint)a1; |
|
1167 |
TInt newState = (TInt)param[0]; |
|
1168 |
||
1169 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
1170 |
PRM_US_SET_RESOURCE_STATE_START_TRACE; |
|
1171 |
#endif |
|
1172 |
// Invoke the API |
|
1173 |
r=((DPowerResourceController*)iPddPtr)->ChangeResourceState(ClientHandle(), |
|
1174 |
resourceId, newState, (TPowerResourceCb*)param[1]); |
|
1175 |
break; |
|
1176 |
} |
|
1177 |
||
1178 |
case RBusDevResManUs::EGetResourceState: |
|
1179 |
{ |
|
1180 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoRequest case EGetResourceState")); |
|
1181 |
// a1 specifies the resource ID |
|
1182 |
// a2 specifies the container stating if a cached value is required, the address of the variable |
|
1183 |
// to be update with the state value and the address of the level owner ID |
|
1184 |
// |
|
1185 |
TUint resourceId = (TUint)a1; |
|
1186 |
TUint *parms = (TUint*)a2; |
|
1187 |
TBool cached = (TBool)(parms[0]); |
|
1188 |
||
1189 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
1190 |
PRM_US_GET_RESOURCE_STATE_START_TRACE; |
|
1191 |
#endif |
|
1192 |
// Always invoke the asynchronous version of the API |
|
1193 |
r=((DPowerResourceController*)iPddPtr)->GetResourceState(ClientHandle(), |
|
1194 |
resourceId, cached, *((TPowerResourceCb*)parms[3])); |
|
1195 |
break; |
|
1196 |
} |
|
1197 |
||
1198 |
||
1199 |
case RBusDevResManUs::ERequestChangeNotification: |
|
1200 |
{ |
|
1201 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoRequest case ERequestChangeNotification")); |
|
1202 |
// a1 specifies the resource ID |
|
1203 |
r=((DPowerResourceController*)iPddPtr)->RequestNotification(ClientHandle(), |
|
1204 |
(TUint)a1, *((DPowerResourceNotification*)a2)); |
|
1205 |
break; |
|
1206 |
} |
|
1207 |
||
1208 |
case RBusDevResManUs::ERequestQualifiedChangeNotification: |
|
1209 |
{ |
|
1210 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoRequest case ERequestQualifiedChangeNotification")); |
|
1211 |
// a1 specifies the threshold value that the state is to change by |
|
1212 |
// a2 specifies the address of the container holding the resourceID and the required direction |
|
1213 |
TInt threshold = (TInt)a1; |
|
1214 |
TUint *parms = (TUint*)a2; |
|
1215 |
TUint resourceId = parms[0]; |
|
1216 |
TBool direction = (TBool)(parms[1]); |
|
1217 |
r=((DPowerResourceController*)iPddPtr)->RequestNotification(ClientHandle(), |
|
1218 |
resourceId, *((DPowerResourceNotification*)parms[2]), threshold, direction); |
|
1219 |
break; |
|
1220 |
} |
|
1221 |
||
1222 |
default: |
|
1223 |
return KErrNotSupported; |
|
1224 |
} |
|
1225 |
return r; |
|
1226 |
} |
|
1227 |
||
1228 |
TInt DChannelResManUs::DoControl(TInt aFunction, TAny* a1, TAny* a2) |
|
1229 |
// Synchronous requests. |
|
1230 |
{ |
|
1231 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::DoControl(TInt aFunction, TAny* a1, TAny* a2)") ); |
|
1232 |
||
1233 |
TInt r=KErrNone; |
|
1234 |
switch (aFunction) |
|
1235 |
{ |
|
1236 |
case RBusDevResManUs::EInitialise: |
|
1237 |
{ |
|
1238 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EInitialise")); |
|
1239 |
// a1 specifies the array describing the number of 'gettable' and 'settable' state resources |
|
1240 |
// and the number of 'listenable' resources |
|
1241 |
// |
|
1242 |
TUint8 *stateRes = (TUint8*)a1; |
|
1243 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
1244 |
PRM_US_REGISTER_CLIENT_START_TRACE; |
|
1245 |
#endif |
|
1246 |
// The call to the Resource Controller's AllocReserve method requires two parameters: |
|
1247 |
// the number of client level objects and the number of request message objects |
|
1248 |
// Each 'settable' state resource requires a client level object and a request message object |
|
1249 |
// Each 'gettable' state resource requires a request message object, only. |
|
1250 |
// Call Resource Control to make allocations |
|
1251 |
r=((DPowerResourceController*)iPddPtr)->AllocReserve(ClientHandle(), |
|
1252 |
stateRes[1], // Number of settable |
|
1253 |
(TUint8)(stateRes[1] + stateRes[0])); // Number of (settable + gettable) |
|
1254 |
#ifdef PRM_US_INSTRUMENTATION_MACRO |
|
1255 |
PRM_US_REGISTER_CLIENT_END_TRACE; |
|
1256 |
#endif |
|
1257 |
if(r==KErrNone) |
|
1258 |
{ |
|
1259 |
// Require 1 TPowerResourceCb object per gettable resource state |
|
1260 |
// Require 1 TPowerResourceCb object per settable resource state |
|
1261 |
// Require 1 DPowerResourceNotification object per listenable resource |
|
1262 |
// |
|
1263 |
if(stateRes[0]>0) |
|
1264 |
r=InitTrackingControl(iGetStateTracker,EGetState,stateRes[0]); |
|
1265 |
if((r==KErrNone) && (stateRes[1]>0)) |
|
1266 |
r=InitTrackingControl(iSetStateTracker,ESetState,stateRes[1]); |
|
1267 |
if((r==KErrNone) && (stateRes[2]>0)) |
|
1268 |
r=InitTrackingControl(iListenableTracker,ENotify,stateRes[2]); |
|
1269 |
#ifdef _DUMP_TRACKERS |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1270 |
DumpTracker(iGetStateTracker); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
DumpTracker(iSetStateTracker); |
0 | 1272 |
#endif |
1273 |
} |
|
1274 |
break; |
|
1275 |
} |
|
1276 |
||
1277 |
case RBusDevResManUs::EGetNoOfResources: |
|
1278 |
{ |
|
1279 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetNoOfResources")); |
|
1280 |
TUint numResources; |
|
1281 |
r=((DPowerResourceController*)iPddPtr)->GetNumResourcesInUseByClient(ClientHandle(),0,numResources); |
|
1282 |
iResInfoValid = 0; // New numResources invalidates the iResInfoXXXX information |
|
1283 |
iResInfoStoredClientId = 0; |
|
1284 |
iResInfoStoredNum = 0; |
|
1285 |
if(r!=KErrNone) |
|
1286 |
return r; |
|
1287 |
// a2 specifies whether the resource information should be loaded |
|
1288 |
if((r==KErrNone)&&(a2!=NULL)) |
|
1289 |
{ |
|
1290 |
TUint prevNumRes = 0; |
|
1291 |
while((numResources != prevNumRes)&&(r==KErrNone)) |
|
1292 |
{ |
|
1293 |
// if the number of resources is greater than can be accommodated by the array, |
|
1294 |
// re-size it |
|
1295 |
if((r=EnsureSizeIsSufficient(iResourceInfoResCtrl, (TInt)(numResources*sizeof(TPowerResourceInfoV01))))!=KErrNone) |
|
1296 |
break; |
|
1297 |
prevNumRes = numResources; |
|
1298 |
// Get the resource info from the Resource Controller |
|
1299 |
// Specify 'aTargetClientId' as zero to access all resources |
|
1300 |
iResourceInfoResCtrl->SetLength(0); |
|
1301 |
r=((DPowerResourceController*)iPddPtr)->GetInfoOnResourcesInUseByClient( |
|
1302 |
ClientHandle(),0,numResources,iResourceInfoResCtrl); |
|
1303 |
} |
|
1304 |
if(r==KErrNone) |
|
1305 |
{ |
|
1306 |
iResInfoValid = 1; |
|
1307 |
iResInfoStoredClientId = KAllResInfoStored; |
|
1308 |
iResInfoStoredNum = numResources; |
|
1309 |
} |
|
1310 |
} |
|
1311 |
if(r==KErrNone) |
|
1312 |
*(TUint*)a1 = numResources; |
|
1313 |
break; |
|
1314 |
} |
|
1315 |
||
1316 |
case RBusDevResManUs::EGetAllResourcesInfo: |
|
1317 |
{ |
|
1318 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetAllResourcesInfo")); |
|
1319 |
// Parameters are passed in TUint* parms[2] |
|
1320 |
// The address of the number of resources is at element 0 |
|
1321 |
// The flag to indicate if the resource info stored is to be refreshed is at element 1 |
|
1322 |
TUint* parms = (TUint*)a2; |
|
1323 |
TUint numResources = *(TUint*)parms[0]; |
|
1324 |
TBool refresh=(TBool)(parms[1]); |
|
1325 |
||
1326 |
// The results are to be written to an RSimplePointerArray, the address is in a1 |
|
1327 |
// Check that the array has enough elements |
|
1328 |
if(refresh) |
|
1329 |
{ |
|
1330 |
// For the refresh option, invoke Resource Controller API once, only (do not recurse) |
|
1331 |
// If the number of requested resources is greater than can be accommodated by the array, |
|
1332 |
// re-size it |
|
1333 |
if((r=EnsureSizeIsSufficient(iResourceInfoResCtrl, (TInt)(numResources*sizeof(TPowerResourceInfoV01))))!=KErrNone) |
|
1334 |
break; |
|
1335 |
// Get the resource info from the Resource Controller |
|
1336 |
// Specify 'aTargetClientId' as zero to access all resources |
|
1337 |
iResourceInfoResCtrl->SetLength(0); |
|
1338 |
r=((DPowerResourceController*)iPddPtr)->GetInfoOnResourcesInUseByClient( |
|
1339 |
ClientHandle(),0,numResources,iResourceInfoResCtrl); |
|
1340 |
if(numResources != iResInfoStoredNum) |
|
1341 |
{ |
|
1342 |
iResInfoValid = 0; // Assume cohesion is now lost |
|
1343 |
iResInfoStoredClientId = 0; |
|
1344 |
iResInfoStoredNum = 0; |
|
1345 |
} |
|
1346 |
} |
|
1347 |
else |
|
1348 |
{ |
|
1349 |
// If the information stored is not valid or is not for all resources return KErrNotReady |
|
1350 |
if((iResInfoValid != 1)||(iResInfoStoredClientId != KAllResInfoStored)) |
|
1351 |
{ |
|
1352 |
r=KErrNotReady; |
|
1353 |
break; |
|
1354 |
} |
|
1355 |
// The number of resources for which information is available in this case is iResInfoStoredNum |
|
1356 |
numResources = iResInfoStoredNum; |
|
1357 |
} |
|
1358 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
1359 |
TPowerResourceInfoV01* currRes = (TPowerResourceInfoV01*)iResourceInfoResCtrl->Ptr(); |
|
1360 |
for(TUint index = 0; index < numResources; index++) |
|
1361 |
{ |
|
1362 |
CheckForCandidateAsyncResource(currRes); |
|
1363 |
CheckForCandidateSharedResource(currRes); |
|
1364 |
currRes++; |
|
1365 |
} |
|
1366 |
#endif |
|
1367 |
*(TUint*)(parms[0]) = numResources; |
|
1368 |
||
1369 |
break; |
|
1370 |
} |
|
1371 |
||
1372 |
case RBusDevResManUs::EGetNoOfClients: |
|
1373 |
case RBusDevResManUs::EGetNumClientsUsingResource: |
|
1374 |
{ |
|
1375 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetNoOfClients")); |
|
1376 |
// Parameters are passed in TUint parms[3] |
|
1377 |
// The flag to indicate if kernel-side clients are to be included is at element 0 |
|
1378 |
// The ID of the resource of interest (0 is expected for EGetNoOfClients) |
|
1379 |
// The flag to indicate if the client info is to be read now is at element 1 |
|
1380 |
TUint *parms = (TUint*)a2; |
|
1381 |
TUint includeKern = parms[0]; |
|
1382 |
TUint resourceId = parms[1]; |
|
1383 |
TUint infoRead = parms[2]; |
|
1384 |
TUint requiredId = resourceId; |
|
1385 |
if(aFunction == RBusDevResManUs::EGetNoOfClients) |
|
1386 |
{ |
|
1387 |
__ASSERT_ALWAYS(resourceId==0,RESMANUS_FAULT()); |
|
1388 |
requiredId = KAllClientInfoStored; |
|
1389 |
} |
|
1390 |
TUint numClients = 0; |
|
1391 |
if(includeKern==1) |
|
1392 |
{ |
|
1393 |
// Client must exhibit PlatSec capability ReadDeviceData |
|
1394 |
if(!iClient->HasCapability(ECapabilityReadDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Resource Manager user-side API function EGetNoOfClients"))) |
|
1395 |
{ |
|
1396 |
r = KErrPermissionDenied; |
|
1397 |
break; |
|
1398 |
} |
|
1399 |
if(r==KErrNone) |
|
1400 |
r=((DPowerResourceController*)iPddPtr)->GetNumClientsUsingResource(ClientHandle(),resourceId,numClients); |
|
1401 |
} |
|
1402 |
else |
|
1403 |
numClients = (TUint)(iDevice->iOpenChannels); |
|
1404 |
||
1405 |
// New numClients invalidates the iClientInfoXXXX information |
|
1406 |
iClientInfoValid = 0; |
|
1407 |
iClientInfoStoredResId = 0; |
|
1408 |
iClientInfoStoredNum= 0; |
|
1409 |
||
1410 |
if((r==KErrNone)&&(infoRead==1)) |
|
1411 |
{ |
|
1412 |
// Capability check already performed, so no need to repeat ... |
|
1413 |
TUint prevNumClients = 0; |
|
1414 |
while((numClients != prevNumClients)&&(r == KErrNone)) |
|
1415 |
{ |
|
1416 |
// Ensure buffer is large enough to store the information |
|
1417 |
if((r=EnsureSizeIsSufficient(iClientNamesResCtrl, (TInt)(numClients*sizeof(TPowerClientInfoV01))))!=KErrNone) |
|
1418 |
break; |
|
1419 |
prevNumClients = numClients; |
|
1420 |
// Invoke the API |
|
1421 |
r=((DPowerResourceController*)iPddPtr)->GetInfoOnClientsUsingResource(ClientHandle(), |
|
1422 |
resourceId,numClients,iClientNamesResCtrl); |
|
1423 |
}; |
|
1424 |
||
1425 |
if(r==KErrNone) |
|
1426 |
{ |
|
1427 |
iClientInfoValid = 1; |
|
1428 |
iClientInfoStoredResId = requiredId; |
|
1429 |
iClientInfoStoredNum = numClients; |
|
1430 |
if(includeKern!=1) |
|
1431 |
{ |
|
1432 |
TUint numAllClients = numClients; |
|
1433 |
numClients = 0; |
|
1434 |
TPowerClientInfoV01* rcDataPtr = (TPowerClientInfoV01*)(iClientNamesResCtrl->Ptr()); |
|
1435 |
for(TUint i=0; i<numAllClients; i++) |
|
1436 |
{ |
|
1437 |
if( rcDataPtr->iClientId & USER_SIDE_CLIENT_BIT_MASK) |
|
1438 |
++numClients; |
|
1439 |
++rcDataPtr; |
|
1440 |
} |
|
1441 |
} |
|
1442 |
} |
|
1443 |
} |
|
1444 |
if(r==KErrNone) |
|
1445 |
*(TUint*)a1 = numClients; |
|
1446 |
break; |
|
1447 |
} |
|
1448 |
||
1449 |
case RBusDevResManUs::EGetNamesAllClients: |
|
1450 |
case RBusDevResManUs::EGetInfoOnClientsUsingResource: |
|
1451 |
{ |
|
1452 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetNamesAllClients-EGetInfoOnClientsUsingResource")); |
|
1453 |
// Parameters are passed in TUint* parms[4] |
|
1454 |
// The address of the number of clients is at element 0 |
|
1455 |
// The flag to indicate if kernel-side info is requested is at element 1 |
|
1456 |
// The resource ID is at element 2 |
|
1457 |
// The flag to indicate if the client information stored is to be refreshed is at element 3 |
|
1458 |
TUint* parms = (TUint*)a2; |
|
1459 |
TUint numClients = *(TUint*)parms[0]; |
|
1460 |
TBool includeKern=(TBool)(parms[1]); |
|
1461 |
TUint resourceId=(TUint)(parms[2]); |
|
1462 |
TBool refresh=(TBool)(parms[3]); |
|
1463 |
||
1464 |
TUint numClientsAvailable = 0; |
|
1465 |
iClientNamesResCtrl->SetLength(0); |
|
1466 |
||
1467 |
if(includeKern) |
|
1468 |
{ |
|
1469 |
// Client must exhibit PlatSec capability ReadDeviceData |
|
1470 |
if(!iClient->HasCapability(ECapabilityReadDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Resource Manager user-side API function EGetNamesAllClients-EGetInfoOnClientsUsingResource"))) |
|
1471 |
{ |
|
1472 |
r = KErrPermissionDenied; |
|
1473 |
break; // Early exit in event of error |
|
1474 |
} |
|
1475 |
TUint requiredId = (resourceId==0)?(TUint)KAllClientInfoStored:resourceId; |
|
1476 |
if(refresh) |
|
1477 |
{ |
|
1478 |
// For the refresh option, invoke Resource Controller API once, only (do not recurse) |
|
1479 |
// If the number of clients is greater than can be accommodated by the array, |
|
1480 |
// re-size it |
|
1481 |
if((r=EnsureSizeIsSufficient(iClientNamesResCtrl, (TInt)(numClients*sizeof(TPowerClientInfoV01))))!=KErrNone) |
|
1482 |
break; |
|
1483 |
// Invoke the API |
|
1484 |
numClientsAvailable = numClients; // Arbitrary initialisation (to silence compiler warning) |
|
1485 |
r=((DPowerResourceController*)iPddPtr)->GetInfoOnClientsUsingResource(ClientHandle(), |
|
1486 |
resourceId,numClientsAvailable,iClientNamesResCtrl); |
|
1487 |
if((r!=KErrNone)||(numClientsAvailable != iClientInfoStoredNum)||(iClientInfoStoredResId != requiredId)) |
|
1488 |
{ |
|
1489 |
iClientInfoValid = 0; // Assume cohesion is now lost |
|
1490 |
iClientInfoStoredResId = 0; |
|
1491 |
iClientInfoStoredNum = 0; |
|
1492 |
} |
|
1493 |
} |
|
1494 |
else |
|
1495 |
{ |
|
1496 |
// If the information stored is not valid, is not for the required resources return KErrNotReady |
|
1497 |
if((iClientInfoValid != 1)||(iClientInfoStoredResId != requiredId)) |
|
1498 |
r=KErrNotReady; |
|
1499 |
// The number of clients for which information is available in this case is iClientInfoStoredNum |
|
1500 |
numClientsAvailable = iClientInfoStoredNum; |
|
1501 |
} |
|
1502 |
} |
|
1503 |
else |
|
1504 |
{ |
|
1505 |
// Resource Controller will return information for the number of clients requested, |
|
1506 |
// taken in order from its internal storage - but this will be regardless of whether |
|
1507 |
// they are kernel-side or user-side; the USER_SIDE_CLIENT_BIT_MASK bit must be |
|
1508 |
// interrogated to determine this. |
|
1509 |
// |
|
1510 |
// Therefore, need to read all the clients - but to do this, must find out how many |
|
1511 |
// clients there are first. |
|
1512 |
TUint numAllClients; |
|
1513 |
r=((DPowerResourceController*)iPddPtr)->GetNumClientsUsingResource(ClientHandle(),resourceId,numAllClients); |
|
1514 |
if(r!=KErrNone) |
|
1515 |
break; // Early exit in event of error |
|
1516 |
if(numAllClients > 0) |
|
1517 |
{ |
|
1518 |
if(refresh) |
|
1519 |
{ |
|
1520 |
// For the refresh option, invoke Resource Controller API once, only (do not recurse) |
|
1521 |
// If the number of clients is greater than can be accommodated by the array, |
|
1522 |
// re-size it |
|
1523 |
if((r=EnsureSizeIsSufficient(iClientNamesResCtrl, (TInt)(numAllClients*sizeof(TPowerClientInfoV01))))!=KErrNone) |
|
1524 |
break; |
|
1525 |
// Invoke the API |
|
1526 |
r=((DPowerResourceController*)iPddPtr)->GetInfoOnClientsUsingResource(ClientHandle(), |
|
1527 |
resourceId,numAllClients,iClientNamesResCtrl); |
|
1528 |
TUint requiredId = (resourceId==0)?(TUint)KAllClientInfoStored:resourceId; |
|
1529 |
if((r!=KErrNone)||(numClientsAvailable != iClientInfoStoredNum)||(iClientInfoStoredResId != requiredId)) |
|
1530 |
{ |
|
1531 |
iClientInfoValid = 0; // Assume cohesion is now lost |
|
1532 |
iClientInfoStoredResId = 0; |
|
1533 |
iClientInfoStoredNum = 0; |
|
1534 |
break; |
|
1535 |
} |
|
1536 |
else |
|
1537 |
{ |
|
1538 |
iClientInfoValid = 1; |
|
1539 |
iClientInfoStoredResId = requiredId; |
|
1540 |
iClientInfoStoredNum = numAllClients; |
|
1541 |
} |
|
1542 |
} |
|
1543 |
else |
|
1544 |
{ |
|
1545 |
// If the information stored is not valid, is not for the required resources return KErrNotReady |
|
1546 |
TUint requiredId = (resourceId==0)?(TUint)KAllClientInfoStored:resourceId; |
|
1547 |
if((iClientInfoValid != 1)||(iClientInfoStoredResId != requiredId)) |
|
1548 |
{ |
|
1549 |
r=KErrNotReady; |
|
1550 |
break; |
|
1551 |
} |
|
1552 |
// The number of clients for which information is available in this case is iClientInfoStoredNum |
|
1553 |
numAllClients = iClientInfoStoredNum; |
|
1554 |
} |
|
1555 |
numClientsAvailable = numAllClients; |
|
1556 |
} // if(numAllClients > 0) |
|
1557 |
} |
|
1558 |
// Write the total number of user side cients available |
|
1559 |
*(TUint*)parms[0] = numClientsAvailable; |
|
1560 |
break; |
|
1561 |
} |
|
1562 |
case RBusDevResManUs::EGetNumResourcesInUseByClient: |
|
1563 |
{ |
|
1564 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetNumResourcesInUseByClient")); |
|
1565 |
// a1 specifies the container holding the client name |
|
1566 |
// |
|
1567 |
||
1568 |
// If client doesn't exist, return KErrNotFound |
|
1569 |
// If client has appropriate capabilities, or if the client for which the information is sought |
|
1570 |
// is user-side, invoke the Resource Controller API directly |
|
1571 |
// Otherwise, return KErrPermissionDenied |
|
1572 |
TUint clientId=0; |
|
1573 |
r=((DPowerResourceController*)iPddPtr)->GetClientId(ClientHandle(), |
|
1574 |
*(TDesC8*)a1,clientId); |
|
1575 |
if(r!=KErrNone) |
|
1576 |
return KErrNotFound; |
|
1577 |
// Perform capability check |
|
1578 |
if(!iClient->HasCapability(ECapabilityReadDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Resource Manager user-side API function EGetNoOfClients"))) |
|
1579 |
{ |
|
1580 |
if(!(clientId & USER_SIDE_CLIENT_BIT_MASK)) |
|
1581 |
return KErrPermissionDenied; |
|
1582 |
} |
|
1583 |
TUint numResources=0; |
|
1584 |
if(r==KErrNone) |
|
1585 |
r=((DPowerResourceController*)iPddPtr)->GetNumResourcesInUseByClient(ClientHandle(), |
|
1586 |
clientId,numResources); |
|
1587 |
// New numResources invalidates the iResXXXX information |
|
1588 |
iResInfoValid = 0; |
|
1589 |
iResInfoStoredClientId = 0; |
|
1590 |
iResInfoStoredNum= 0; |
|
1591 |
||
1592 |
// parms[1] specifies whether the resource information should be loaded |
|
1593 |
if((r==KErrNone)&&(*(TUint*)a2 != NULL)) |
|
1594 |
{ |
|
1595 |
TUint prevNumRes = 0; |
|
1596 |
while((numResources != prevNumRes)&&(r==KErrNone)) |
|
1597 |
{ |
|
1598 |
// if the number of resources is greater than can be accommodated by the array, |
|
1599 |
// re-size it |
|
1600 |
if((r=EnsureSizeIsSufficient(iResourceInfoResCtrl, (TInt)(numResources*sizeof(TPowerResourceInfoV01))))!=KErrNone) |
|
1601 |
break; |
|
1602 |
prevNumRes = numResources; |
|
1603 |
// Get the resource info from the Resource Controller |
|
1604 |
// Specify 'aTargetClientId' as zero to access all resources |
|
1605 |
iResourceInfoResCtrl->SetLength(0); |
|
1606 |
r=((DPowerResourceController*)iPddPtr)->GetInfoOnResourcesInUseByClient( |
|
1607 |
ClientHandle(),clientId,numResources,iResourceInfoResCtrl); |
|
1608 |
} |
|
1609 |
if(r==KErrNone) |
|
1610 |
{ |
|
1611 |
iResInfoValid = 1; |
|
1612 |
iResInfoStoredClientId = clientId; |
|
1613 |
iResInfoStoredNum = numResources; |
|
1614 |
} |
|
1615 |
} |
|
1616 |
if(r==KErrNone) |
|
1617 |
*(TUint*)a2 = numResources; |
|
1618 |
break; |
|
1619 |
} |
|
1620 |
||
1621 |
case RBusDevResManUs::EGetInfoOnResourcesInUseByClient: |
|
1622 |
{ |
|
1623 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetInfoOnResourcesInUseByClient")); |
|
1624 |
// a1 specifies the container holding the client name |
|
1625 |
// a2 specifies an array TUint* parms[3] which contains: |
|
1626 |
// - the address of the variable to write the number of reasources to |
|
1627 |
// - a pointer to the container to hold the resources' information |
|
1628 |
// - the flag to indicate whether the resource info should be (re-)read here |
|
1629 |
||
1630 |
TUint clientId=0; |
|
1631 |
TUint *parms = (TUint*)a2; |
|
1632 |
TUint numResources = *(TUint*)parms[0]; |
|
1633 |
// The results are to be written to an RSimplePointerArray, the address is in parms[1] |
|
1634 |
// Check that the array has enough elements |
|
1635 |
// If client doesn't exist, return KErrNotFound |
|
1636 |
// If client has appropriate capabilities, or if the client for which the information is sought |
|
1637 |
// is user-side, invoke the Resource Controller API directly |
|
1638 |
// Otherwise, return KErrPermissionDenied |
|
1639 |
r=((DPowerResourceController*)iPddPtr)->GetClientId(ClientHandle(), |
|
1640 |
*(TDesC8*)a1,clientId); |
|
1641 |
if(r!=KErrNone) |
|
1642 |
return KErrNotFound; |
|
1643 |
// Perform capability check |
|
1644 |
if(!iClient->HasCapability(ECapabilityReadDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Resource Manager user-side API function EGetNoOfClients"))) |
|
1645 |
{ |
|
1646 |
if(!(clientId & USER_SIDE_CLIENT_BIT_MASK)) |
|
1647 |
return KErrPermissionDenied; |
|
1648 |
} |
|
1649 |
||
1650 |
TUint updatedNumResources = numResources; |
|
1651 |
r=((DPowerResourceController*)iPddPtr)->GetNumResourcesInUseByClient(ClientHandle(),clientId,updatedNumResources); |
|
1652 |
if(r!=KErrNone) |
|
1653 |
break; |
|
1654 |
||
1655 |
if(updatedNumResources>0) |
|
1656 |
{ |
|
1657 |
if((TUint)(parms[2] != 0)) |
|
1658 |
{ |
|
1659 |
// For the refresh option, invoke Resource Controller API once, only (do not recurse) |
|
1660 |
// If the number of requested resources is greater than can be accommodated by the array, |
|
1661 |
// re-size it |
|
1662 |
if((r=EnsureSizeIsSufficient(iResourceInfoResCtrl, (TInt)(numResources*sizeof(TPowerResourceInfoV01))))!=KErrNone) |
|
1663 |
break; |
|
1664 |
// Get the resource info from the Resource Controller |
|
1665 |
// Specify 'aTargetClientId' as zero to access all resources |
|
1666 |
iResourceInfoResCtrl->SetLength(0); |
|
1667 |
r=((DPowerResourceController*)iPddPtr)->GetInfoOnResourcesInUseByClient( |
|
1668 |
ClientHandle(),clientId,numResources,iResourceInfoResCtrl); |
|
1669 |
if((numResources != iResInfoStoredNum)||(iResInfoStoredClientId != clientId)) |
|
1670 |
{ |
|
1671 |
iResInfoValid = 0; // Assume cohesion is now lost |
|
1672 |
iResInfoStoredClientId = 0; |
|
1673 |
iResInfoStoredNum = 0; |
|
1674 |
} |
|
1675 |
} |
|
1676 |
else |
|
1677 |
{ |
|
1678 |
// If the information stored is not valid or is not for the required clientId return KErrNotReady |
|
1679 |
if((iResInfoValid != 1)||(iResInfoStoredClientId != clientId)) |
|
1680 |
r=KErrNotReady; |
|
1681 |
// The number of resources for which information is available in this case is iResInfoStoredNum |
|
1682 |
numResources = iResInfoStoredNum; |
|
1683 |
} |
|
1684 |
} |
|
1685 |
if(r==KErrNone) |
|
1686 |
*(TUint*)parms[0] = updatedNumResources; |
|
1687 |
||
1688 |
break; |
|
1689 |
} |
|
1690 |
||
1691 |
case RBusDevResManUs::EGetResourceIdByName: |
|
1692 |
{ |
|
1693 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetResourceIdByName")); |
|
1694 |
// a1 specifies the container holding the resource name |
|
1695 |
// a2 specifies the variable to be update with the ID |
|
1696 |
TUint resourceId; |
|
1697 |
r=((DPowerResourceController*)iPddPtr)->GetResourceId(ClientHandle(), *(TDesC8*)a1, resourceId); |
|
1698 |
if(r==KErrNone) |
|
1699 |
*(TUint *)a2 = resourceId; |
|
1700 |
break; |
|
1701 |
} |
|
1702 |
||
1703 |
case RBusDevResManUs::EGetResourceInfo: |
|
1704 |
{ |
|
1705 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetResourceInfo")); |
|
1706 |
// a1 specifies the container holding the resource ID |
|
1707 |
// a2 specifies the address of the container to be written to |
|
1708 |
||
1709 |
TUint resourceId= (TUint)a1; |
|
1710 |
TPowerResourceInfoBuf01 resCtrlInfo; |
|
1711 |
resCtrlInfo.SetLength(0); |
|
1712 |
TResourceInfoBuf tempInfo; |
|
1713 |
r=((DPowerResourceController*)iPddPtr)->GetResourceInfo(ClientHandle(),resourceId,&resCtrlInfo); |
|
1714 |
if(r==KErrNone) |
|
1715 |
{ |
|
1716 |
// Copy the client buffer to tempInfo so that its size can be determined |
|
1717 |
// by ExtractResourceInfo |
|
1718 |
r=ExtractResourceInfo(&(resCtrlInfo()), tempInfo); |
|
1719 |
} |
|
1720 |
if(r==KErrNone) |
|
1721 |
{ |
|
1722 |
// Write the resources' info to the client thread |
|
1723 |
*(TResourceInfoBuf*)a2 = tempInfo; |
|
1724 |
} |
|
1725 |
break; |
|
1726 |
} |
|
1727 |
||
1728 |
||
1729 |
case RBusDevResManUs::ECancelChangeResourceStateRequests: |
|
1730 |
case RBusDevResManUs::ECancelGetResourceStateRequests: |
|
1731 |
case RBusDevResManUs::ECancelChangeNotificationRequests: |
|
1732 |
{ |
|
1733 |
TUint resourceId = (TUint)a1; |
|
1734 |
TTrackingControl*tracker=MapRequestToTracker(aFunction); |
|
1735 |
r=CancelTrackerRequests(tracker, ETrue, resourceId, NULL); |
|
1736 |
if(r==KErrCancel) |
|
1737 |
r=KErrNone; // All cancellations were successful |
|
1738 |
break; |
|
1739 |
} |
|
1740 |
||
1741 |
case RBusDevResManUs::ECancelChangeResourceState: |
|
1742 |
case RBusDevResManUs::ECancelGetResourceState: |
|
1743 |
case RBusDevResManUs::ECancelRequestChangeNotification: |
|
1744 |
{ |
|
1745 |
TRequestStatus* status = (TRequestStatus*)a1; |
|
1746 |
r=CancelRequestsOfType(aFunction, status); |
|
1747 |
break; |
|
1748 |
} |
|
1749 |
||
1750 |
||
1751 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
1752 |
case RBusDevResManUs::EGetNumCandidateAsyncResources: |
|
1753 |
{ |
|
1754 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetNumCandidateAsyncResources")); |
|
1755 |
TUint numResources; |
|
1756 |
GetNumCandidateAsyncResources(numResources); |
|
1757 |
// Write the result to the client thread |
|
1758 |
*(TUint*)a1 = numResources; |
|
1759 |
break; |
|
1760 |
} |
|
1761 |
case RBusDevResManUs::EGetCandidateAsyncResourceId: |
|
1762 |
{ |
|
1763 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetCandidateAsyncResourceId")); |
|
1764 |
// Get the index to use |
|
1765 |
TUint index = (TUint)a1; |
|
1766 |
TUint resourceId = 0; |
|
1767 |
r=GetCandidateAsyncResourceId(index, resourceId); |
|
1768 |
if(r==KErrNone) // Write the result to the client thread |
|
1769 |
*(TUint*)a2 = resourceId; |
|
1770 |
break; |
|
1771 |
} |
|
1772 |
||
1773 |
case RBusDevResManUs::EGetNumCandidateSharedResources: |
|
1774 |
{ |
|
1775 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetNumCandidateSharedResources")); |
|
1776 |
TUint numResources; |
|
1777 |
GetNumCandidateSharedResources(numResources); |
|
1778 |
// Write the result to the client thread |
|
1779 |
*(TUint*)a1 = numResources; |
|
1780 |
break; |
|
1781 |
} |
|
1782 |
case RBusDevResManUs::EGetCandidateSharedResourceId: |
|
1783 |
{ |
|
1784 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetCandidateSharedResourceId")); |
|
1785 |
// Get the index to use |
|
1786 |
TUint index = (TUint)a1; |
|
1787 |
TUint resourceId = 0; |
|
1788 |
r=GetCandidateSharedResourceId(index, resourceId); |
|
1789 |
if(r==KErrNone) // Write the result to the client thread |
|
1790 |
*(TUint*)a2 = resourceId; |
|
1791 |
break; |
|
1792 |
} |
|
1793 |
#endif |
|
1794 |
||
1795 |
case RBusDevResManUs::EGetResourceControllerVersion: |
|
1796 |
{ |
|
1797 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetResourceControllerVersion")); |
|
1798 |
// a1 specifies the address of the TVersion variable to be written to |
|
1799 |
// a2 is not used |
|
1800 |
TUint version; |
|
1801 |
if((r=((DPowerResourceController*)iPddPtr)->GetInterface(ClientHandle(), |
|
1802 |
KResManControlIoGetVersion, |
|
1803 |
(TAny*)&version, |
|
1804 |
NULL, |
|
1805 |
NULL))!=KErrNone) |
|
1806 |
return r; |
|
1807 |
// Write the required information |
|
1808 |
*(TUint*)a1 = version; |
|
1809 |
break; |
|
1810 |
} |
|
1811 |
||
1812 |
case RBusDevResManUs::EGetNumDependentsForResource: |
|
1813 |
{ |
|
1814 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetNumDependentsForResource")); |
|
1815 |
// a1 specifies a pointer to the variable to be written to |
|
1816 |
// a2 specifies an array TUint parms[2] which contains: |
|
1817 |
// - the resource ID |
|
1818 |
// - flag to indicate if dependency information is to be loaded as part of this call |
|
1819 |
TUint *parms = (TUint*)a2; |
|
1820 |
TUint numDependents = 0; |
|
1821 |
r=((DPowerResourceController*)iPddPtr)->GetInterface(ClientHandle(), |
|
1822 |
KResManControlIoGetNumDependents, |
|
1823 |
(TAny*)(parms[0]), // Resource ID |
|
1824 |
&numDependents, |
|
1825 |
NULL); |
|
1826 |
iResDepsValid=EFalse; // The number of dependents may differ from the dependency information stored |
|
1827 |
if(r!=KErrNone) |
|
1828 |
return r; |
|
1829 |
||
1830 |
// Load the dependency information, if required. |
|
1831 |
if(parms[1]) |
|
1832 |
{ |
|
1833 |
// The dependency information may be updated subsequent to the request for the number of dependents. In order |
|
1834 |
// to provide a coherent number and array of dependents, the requests for dependency information will be |
|
1835 |
// re-issued if the (new) number of dependents differs from that previously read. |
|
1836 |
TUint prevNumDeps = 0; |
|
1837 |
TUint newNumDeps = numDependents; |
|
1838 |
while((newNumDeps != prevNumDeps)&&(r == KErrNone)) |
|
1839 |
{ |
|
1840 |
if((r=EnsureSizeIsSufficient(iResourceDependencyIds, (TInt)(newNumDeps*sizeof(SResourceDependencyInfo))))!=KErrNone) |
|
1841 |
return r; |
|
1842 |
prevNumDeps = newNumDeps; |
|
1843 |
if((r=((DPowerResourceController*)iPddPtr)->GetInterface(ClientHandle(), |
|
1844 |
KResManControlIoGetDependentsId, |
|
1845 |
(TAny*)(parms[0]), // Resource ID |
|
1846 |
(TAny*)(iResourceDependencyIds), |
|
1847 |
(TAny*)&newNumDeps))!=KErrNone) |
|
1848 |
return r; |
|
1849 |
}; |
|
1850 |
// Dependency information now in synch with number reported |
|
1851 |
numDependents = newNumDeps; |
|
1852 |
iNumResDepsStored = newNumDeps; |
|
1853 |
iResDepsValid = ETrue; |
|
1854 |
} |
|
1855 |
// Write the number of dependents to the client thread |
|
1856 |
*(TUint*)a1 = numDependents; |
|
1857 |
break; |
|
1858 |
} |
|
1859 |
||
1860 |
||
1861 |
case RBusDevResManUs::EGetDependentsIdForResource: |
|
1862 |
{ |
|
1863 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl case EGetDependentsIdForResource")); |
|
1864 |
// a1 specifies a pointer to the variable to hold the number of dependencies |
|
1865 |
// a2 specifies an array TUint parms[4] which contains: |
|
1866 |
// - the resource ID |
|
1867 |
// - the address of the array to write the required IDs to |
|
1868 |
// - flag to indicate if dependency information is to be (re-)loaded as part of this call |
|
1869 |
TUint *parms = (TUint*)a2; |
|
1870 |
TUint numDependents = 0; |
|
1871 |
||
1872 |
// (Re-)Load the dependency information, if required. |
|
1873 |
if(parms[2]) |
|
1874 |
{ |
|
1875 |
if((r=((DPowerResourceController*)iPddPtr)->GetInterface(ClientHandle(), |
|
1876 |
KResManControlIoGetNumDependents, |
|
1877 |
(TAny*)(parms[0]), |
|
1878 |
(TAny*)&numDependents, |
|
1879 |
NULL))!=KErrNone) |
|
1880 |
return r; |
|
1881 |
||
1882 |
iResDepsValid=EFalse; // The number of dependents may differ from the dependency information stored |
|
1883 |
// In order to provide a coherent number and array of dependents, the requests for dependency information |
|
1884 |
// will be re-issued if the (new) number of dependents differs from that previously read. |
|
1885 |
TUint prevNumDeps = 0; |
|
1886 |
TUint newNumDeps = numDependents; |
|
1887 |
while(newNumDeps != prevNumDeps) |
|
1888 |
{ |
|
1889 |
if((r=EnsureSizeIsSufficient(iResourceDependencyIds, (TInt)(newNumDeps*sizeof(SResourceDependencyInfo))))!=KErrNone) |
|
1890 |
return r; |
|
1891 |
prevNumDeps = newNumDeps; |
|
1892 |
if((r=((DPowerResourceController*)iPddPtr)->GetInterface(ClientHandle(), |
|
1893 |
KResManControlIoGetDependentsId, |
|
1894 |
(TAny*)(parms[0]), // Resource ID |
|
1895 |
(TAny*)(iResourceDependencyIds), |
|
1896 |
(TAny*)&newNumDeps))!=KErrNone) |
|
1897 |
return r; |
|
1898 |
}; |
|
1899 |
||
1900 |
// Dependency information now in synch with number reported |
|
1901 |
numDependents = newNumDeps; |
|
1902 |
iNumResDepsStored = newNumDeps; |
|
1903 |
iResDepsValid = ETrue; |
|
1904 |
} |
|
1905 |
||
1906 |
// If iResDepsValid equals zero, the results are invalid - so return KErrNotReady. |
|
1907 |
if(iResDepsValid==0) |
|
1908 |
return KErrNotReady; |
|
1909 |
||
1910 |
// Write the number of dependencies available to the client |
|
1911 |
*(TUint*)a1 = iNumResDepsStored; |
|
1912 |
// Write the dependencies to the client array if it is of sufficient size |
|
1913 |
// Copy the required dependency information to the user-supplied container. |
|
1914 |
parms[1] = (TUint)iResourceDependencyIds; |
|
1915 |
break; |
|
1916 |
} |
|
1917 |
||
1918 |
default: |
|
1919 |
{ |
|
1920 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::DoControl default 0x%x", aFunction)); |
|
1921 |
r=KErrNotSupported; |
|
1922 |
} |
|
1923 |
} |
|
1924 |
return(r); |
|
1925 |
} |
|
1926 |
||
1927 |
||
1928 |
TInt DChannelResManUs::EnsureSizeIsSufficient(HBuf*& aBuffer, TInt aMinSize) |
|
1929 |
{ |
|
1930 |
// Utility function to ensure a buffer is of at least the minimum required size |
|
1931 |
// If the buffer is to small, an attempt is made to increase its size. |
|
1932 |
// If the re-sizing fails, KErrNoMemory is returned; otherwise KErrNone. |
|
1933 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::EnsureSizeIsSufficient")); |
|
1934 |
||
1935 |
if(aBuffer->MaxLength() < aMinSize) |
|
1936 |
{ |
|
1937 |
aBuffer = aBuffer->ReAlloc(aMinSize); |
|
1938 |
if(aBuffer->MaxLength() < aMinSize) |
|
1939 |
return KErrNoMemory; // ReAlloc failed - aBuffer is unchanged |
|
1940 |
} |
|
1941 |
aBuffer->SetLength(0); |
|
1942 |
return KErrNone; |
|
1943 |
} |
|
1944 |
||
1945 |
void DChannelResManUs::FreeTrackingBuffer(TTrackingBuffer*& aBuffer) |
|
1946 |
{ |
|
1947 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DChannelResManUs::FreeTrackingBuffer")); |
|
1948 |
// Function invoked for to free tracking buffers from the busy to free queue of a tracking control |
|
1949 |
__ASSERT_ALWAYS((aBuffer!=NULL),RESMANUS_FAULT()); |
|
1950 |
NKern::FMWait(&iBufferFastMutex); |
|
1951 |
TTrackingControl* tracker = aBuffer->GetTrackingControl(); |
|
1952 |
SDblQue* bufQue = aBuffer->GetQue(); |
|
1953 |
||
1954 |
__ASSERT_ALWAYS(((tracker!=NULL)&&(bufQue!=NULL)),RESMANUS_FAULT()); |
|
1955 |
||
1956 |
// Check that the buffer is still in the busy queue of the tracker - exit if not |
|
1957 |
if(bufQue == tracker->iBusyQue) |
|
1958 |
{ |
|
1959 |
aBuffer->Deque(); |
|
1960 |
tracker->iFreeQue->Add(aBuffer); |
|
1961 |
aBuffer->SetQue(tracker->iFreeQue); |
|
1962 |
} |
|
1963 |
NKern::FMSignal(&iBufferFastMutex); |
|
1964 |
} |
|
1965 |
||
1966 |
||
1967 |
TInt DChannelResManUs::GetAndInitTrackingBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TRequestStatus* aStatus) |
|
1968 |
{ |
|
1969 |
// Utility function - perform the necessary processing to get a buffer to support |
|
1970 |
// asynchronous requests to change the state of a resource |
|
1971 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::GetAndInitTrackingBuffer")); |
|
1972 |
TInt r=KErrNone; |
|
1973 |
NKern::FMWait(&iBufferFastMutex); |
|
1974 |
if(aTracker->iFreeQue->IsEmpty()) |
|
1975 |
r = KErrUnderflow; |
|
1976 |
else |
|
1977 |
{ |
|
1978 |
// Need intermediate cast from SDblQueLink* to TAny* before TTrackingBuffer* |
|
1979 |
TAny* ptr = (TAny*)(aTracker->iFreeQue->GetFirst()); |
|
1980 |
aBuffer = (TTrackingBuffer*)ptr; |
|
1981 |
aTracker->iBusyQue->Add((SDblQueLink*)ptr); |
|
1982 |
aBuffer->SetQue(aTracker->iBusyQue); |
|
1983 |
aBuffer->SetResourceId(aResourceId); |
|
1984 |
TClientRequest* request; |
|
1985 |
TTrackingControl* tracker = aBuffer->GetTrackingControl(); |
|
1986 |
GET_USER_REQUEST(request, aBuffer, tracker->iType); |
|
1987 |
request->Reset(); |
|
1988 |
request->SetStatus(aStatus); |
|
1989 |
} |
|
1990 |
NKern::FMSignal(&iBufferFastMutex); |
|
1991 |
return r; |
|
1992 |
} |
|
1993 |
||
1994 |
TInt DChannelResManUs::GetStateBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TInt* aState, TInt* aLevelOwnerPtr, TPowerResourceCb*& aCb, TRequestStatus* aStatus) |
|
1995 |
{ |
|
1996 |
// Utility function - perform the necessary processing to get a buffer and control block |
|
1997 |
// to support asynchronous requests to change the state of a resource |
|
1998 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::GetStateBuffer")); |
|
1999 |
||
2000 |
TInt r=GetAndInitTrackingBuffer(aTracker, aBuffer, aResourceId, aStatus); |
|
2001 |
if(r==KErrNone) |
|
2002 |
{ |
|
2003 |
TTrackGetStateBuf* stateBuf = (TTrackGetStateBuf*)aBuffer; |
|
2004 |
stateBuf->iRequest->SetDestPtr1(aState); |
|
2005 |
stateBuf->iRequest->SetDestPtr2(aLevelOwnerPtr); |
|
2006 |
// Use placement new to update the content of the TPowerResourceCb |
|
2007 |
aCb = &(stateBuf->iCtrlBlock); |
|
2008 |
new (aCb) TPowerResourceCb(&AsyncCallBackFn,(TAny*)aBuffer,iDfcQ,KResManCallBackPriority); |
|
2009 |
} |
|
2010 |
return r; |
|
2011 |
} |
|
2012 |
||
2013 |
#ifdef _DUMP_TRACKERS |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2014 |
void DChannelResManUs::DumpTracker(TTrackingControl* aTracker) |
0 | 2015 |
{ |
2016 |
Kern::Printf("\nDChannelResManUs::DumpTracker"); |
|
2017 |
Kern::Printf("Tracker at 0x%x\n",aTracker); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2018 |
if(!aTracker) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2019 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2020 |
Kern::Printf("Nothing to dump.."); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2021 |
return; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2022 |
} |
0 | 2023 |
Kern::Printf("iType=%d",aTracker->iType); |
2024 |
switch(aTracker->iType) |
|
2025 |
{ |
|
2026 |
case 0: |
|
2027 |
Kern::Printf("= GetState tracker\n"); |
|
2028 |
break; |
|
2029 |
case 1: |
|
2030 |
Kern::Printf("= SetState tracker\n"); |
|
2031 |
break; |
|
2032 |
case 2: |
|
2033 |
Kern::Printf("= Notify tracker\n"); |
|
2034 |
break; |
|
2035 |
} |
|
2036 |
Kern::Printf("iOwningChannel at 0x%x\n",aTracker->iOwningChannel); |
|
2037 |
Kern::Printf("iFreeQue at 0x%x\n",aTracker->iFreeQue); |
|
2038 |
SDblQueLink* buf; |
|
2039 |
if(aTracker->iFreeQue!=NULL) |
|
2040 |
{ |
|
2041 |
buf=aTracker->iFreeQue->First(); |
|
2042 |
while(buf!=aTracker->iFreeQue->Last()) |
|
2043 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2044 |
Kern::Printf("iFreeQue first buffer at 0x%x\n",buf); |
0 | 2045 |
TAny* intermediatePtr = (TAny*)buf; |
2046 |
if((aTracker->iType == EGetState)||(aTracker->iType == ESetState)) |
|
2047 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2048 |
TTrackSetStateBuf* tempBuf =(TTrackSetStateBuf*)intermediatePtr; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2049 |
Kern::Printf("buffer control block at 0x%x\n",(TInt)&tempBuf->iCtrlBlock); |
0 | 2050 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2051 |
buf = buf->iNext; |
0 | 2052 |
}; |
2053 |
} |
|
2054 |
Kern::Printf("iBusyQue at 0x%x\n",aTracker->iBusyQue); |
|
2055 |
if(aTracker->iBusyQue!=NULL) |
|
2056 |
{ |
|
2057 |
buf=aTracker->iBusyQue->First(); |
|
2058 |
while(buf!=aTracker->iBusyQue->Last()) |
|
2059 |
{ |
|
2060 |
Kern::Printf("iBusyQue buffer at 0x%x\n",buf); |
|
2061 |
TAny* intermediatePtr = (TAny*)buf; |
|
2062 |
if((aTracker->iType == EGetState)||(aTracker->iType == ESetState)) |
|
2063 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2064 |
TTrackSetStateBuf* tempBuf =(TTrackSetStateBuf*)intermediatePtr; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2065 |
Kern::Printf("buffer control block at 0x%x\n", (TInt)&tempBuf->iCtrlBlock); |
0 | 2066 |
} |
2067 |
buf= buf->iNext; |
|
2068 |
}; |
|
2069 |
} |
|
2070 |
} |
|
2071 |
#endif |
|
2072 |
||
2073 |
TInt DChannelResManUs::InitTrackingControl(TTrackingControl*& aTracker, TUint8 aType, TUint8 aNumBuffers) |
|
2074 |
{ |
|
2075 |
// Set the tracker type, create the tracking queues and required tracking buffers. |
|
2076 |
// Assign all the tracking buffers to the free queue. |
|
2077 |
// |
|
2078 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::InitTrackingControl()")); |
|
2079 |
||
2080 |
TInt r = KErrNone; |
|
2081 |
aTracker->iType = (TAsyncOpType)aType; |
|
2082 |
aTracker->iOwningChannel = this; |
|
2083 |
aTracker->iFreeQue = new SDblQue(); |
|
2084 |
__ASSERT_DEBUG(aTracker->iFreeQue != NULL, RESMANUS_FAULT()); |
|
2085 |
if(aTracker->iFreeQue == NULL) |
|
2086 |
r = KErrNoMemory; |
|
2087 |
if(r==KErrNone) |
|
2088 |
{ |
|
2089 |
aTracker->iBusyQue = new SDblQue(); |
|
2090 |
__ASSERT_DEBUG(aTracker->iBusyQue != NULL, RESMANUS_FAULT()); |
|
2091 |
if(aTracker->iBusyQue == NULL) |
|
2092 |
{ |
|
2093 |
delete aTracker->iFreeQue; |
|
2094 |
r = KErrNoMemory; |
|
2095 |
} |
|
2096 |
} |
|
2097 |
if(r==KErrNone) |
|
2098 |
{ |
|
2099 |
for(TUint8 i=0; (i<aNumBuffers) && (r==KErrNone) ;i++) |
|
2100 |
{ |
|
2101 |
TAny* buf = NULL; |
|
2102 |
TAny* ptr=NULL; // To be assigned to non-NULL value later |
|
2103 |
switch(aTracker->iType) |
|
2104 |
{ |
|
2105 |
case EGetState: |
|
2106 |
{ |
|
2107 |
buf = (TAny*)(new TTrackGetStateBuf(&AsyncCallBackFn,ptr,iDfcQ,KResManCallBackPriority)); |
|
2108 |
r = Kern::CreateClientDataRequest2(((TTrackGetStateBuf*)buf)->iRequest); |
|
2109 |
break; |
|
2110 |
} |
|
2111 |
case ESetState: |
|
2112 |
{ |
|
2113 |
buf = (TAny*)(new TTrackSetStateBuf(&AsyncCallBackFn, ptr, iDfcQ, KResManCallBackPriority)); |
|
2114 |
r = Kern::CreateClientRequest(((TTrackSetStateBuf*)buf)->iRequest); |
|
2115 |
break; |
|
2116 |
} |
|
2117 |
case ENotify: |
|
2118 |
{ |
|
2119 |
buf = (TAny*)(new TTrackNotifyBuf(&AsyncCallBackFn,ptr,iDfcQ,KResManCallBackPriority)); |
|
2120 |
r = Kern::CreateClientRequest(((TTrackNotifyBuf*)buf)->iRequest); |
|
2121 |
break; |
|
2122 |
} |
|
2123 |
default: |
|
2124 |
__ASSERT_ALWAYS(0,RESMANUS_FAULT()); |
|
2125 |
} |
|
2126 |
__ASSERT_DEBUG(buf!=NULL, RESMANUS_FAULT()); |
|
2127 |
if((buf == NULL) || (r == KErrNoMemory)) |
|
2128 |
{ |
|
2129 |
r = KErrNoMemory; |
|
2130 |
break; |
|
2131 |
} |
|
2132 |
else |
|
2133 |
{ |
|
2134 |
((TTrackingBuffer*)buf)->SetTrackingControl(aTracker); |
|
2135 |
(aTracker->iFreeQue)->Add((SDblQueLink*)buf); |
|
2136 |
((TTrackingBuffer*)buf)->SetQue(aTracker->iFreeQue); |
|
2137 |
} |
|
2138 |
} |
|
2139 |
// If buffer allocation failed, need to remove all previously-allocated buffers and the queues |
|
2140 |
if(r!=KErrNone) |
|
2141 |
{ |
|
2142 |
SDblQueLink* ptr = (aTracker->iFreeQue)->First(); |
|
2143 |
do |
|
2144 |
{ |
|
2145 |
SDblQueLink* next = NULL; |
|
2146 |
if(ptr !=NULL) |
|
2147 |
next = ptr->iNext; |
|
2148 |
delete ptr; |
|
2149 |
ptr = next; |
|
2150 |
} while ((ptr!=NULL)&&(ptr!=(aTracker->iFreeQue)->Last())); |
|
2151 |
delete aTracker->iFreeQue; |
|
2152 |
delete aTracker->iBusyQue; |
|
2153 |
} |
|
2154 |
} |
|
2155 |
return r; |
|
2156 |
} |
|
2157 |
||
2158 |
||
2159 |
void DChannelResManUs::RemoveTrackingControl(TTrackingControl*& aTracker) |
|
2160 |
{ |
|
2161 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DChannelResManUs::RemoveTrackingControl()")); |
|
2162 |
||
2163 |
// Free the resource-tracking links and their respective queues |
|
2164 |
if(aTracker->iFreeQue!=NULL) |
|
2165 |
{ |
|
2166 |
while(!aTracker->iFreeQue->IsEmpty()) |
|
2167 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2168 |
delete aTracker->iFreeQue->GetFirst(); // Dequeues the element; |
0 | 2169 |
} |
2170 |
delete aTracker->iFreeQue; |
|
2171 |
} |
|
2172 |
||
2173 |
if(aTracker->iBusyQue!=NULL) |
|
2174 |
{ |
|
2175 |
while(!aTracker->iBusyQue->IsEmpty()) |
|
2176 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2177 |
delete aTracker->iBusyQue->GetFirst(); // Dequeues the element; |
0 | 2178 |
} |
2179 |
delete aTracker->iBusyQue; |
|
2180 |
} |
|
2181 |
delete aTracker; |
|
2182 |
} |
|
2183 |
||
2184 |
||
2185 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL |
|
2186 |
void DChannelResManUs::CheckForCandidateAsyncResource(TPowerResourceInfoV01* aResource) |
|
2187 |
{ |
|
2188 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::CheckForCandidateAsyncResource")); |
|
2189 |
// Proceed only if we already have less that the maximum number of candidate resources |
|
2190 |
if(iNoCandidateAsyncRes >= MAX_NUM_CANDIDATE_RESOURCES) |
|
2191 |
return; |
|
2192 |
// For the purposes of asynchronous testing, we need a long latency resource |
|
2193 |
if(((TInt)(aResource->iLatencyGet)==(TInt)(EResLongLatency)) && |
|
2194 |
((TInt)(aResource->iLatencySet)==(TInt)(EResLongLatency))) |
|
2195 |
{ |
|
2196 |
// An additional requirement is that the level of the resource can be |
|
2197 |
// updated a sufficient amount of times to support the required testing. |
|
2198 |
if(((aResource->iMaxLevel - aResource->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_ASYNC_TESTING) && |
|
2199 |
((TInt)(aResource->iSense) == (TInt)(EResPositive)) ) |
|
2200 |
{ |
|
2201 |
TInt r=((DPowerResourceController*)iPddPtr)->GetResourceId(ClientHandle(), *(aResource->iResourceName), iCandidateAsyncResIds[iNoCandidateAsyncRes]); |
|
2202 |
if(r!=KErrNone) |
|
2203 |
{ |
|
2204 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("Failed to identify long latency resource\n")); |
|
2205 |
} |
|
2206 |
else |
|
2207 |
{ |
|
2208 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("Potential async resource ID = %d\n",iCandidateAsyncResIds[iNoCandidateAsyncRes])); |
|
2209 |
iHaveLongLatencyResource = ETrue; |
|
2210 |
++iNoCandidateAsyncRes; |
|
2211 |
} |
|
2212 |
} |
|
2213 |
} |
|
2214 |
} |
|
2215 |
||
2216 |
||
2217 |
void DChannelResManUs::GetNumCandidateAsyncResources(TUint& aNumResources) |
|
2218 |
{ |
|
2219 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::GetNumCandidateAsyncResources")); |
|
2220 |
||
2221 |
aNumResources = iNoCandidateAsyncRes; |
|
2222 |
} |
|
2223 |
||
2224 |
TInt DChannelResManUs::GetCandidateAsyncResourceId(TUint aIndex, TUint& aResourceId) |
|
2225 |
{ |
|
2226 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::GetCandidateAsyncResourceId")); |
|
2227 |
TInt r = KErrNone; |
|
2228 |
if(aIndex>=iNoCandidateAsyncRes) |
|
2229 |
r = KErrNotFound; |
|
2230 |
else |
|
2231 |
aResourceId = iCandidateAsyncResIds[aIndex]; |
|
2232 |
return r; |
|
2233 |
} |
|
2234 |
||
2235 |
void DChannelResManUs::CheckForCandidateSharedResource(TPowerResourceInfoV01* aResource) |
|
2236 |
{ |
|
2237 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::CheckForCandidateSharedResource")); |
|
2238 |
||
2239 |
// Proceed only if we already have less that the maximum number of candidate resources |
|
2240 |
if(iNoCandidateSharedRes >= MAX_NUM_CANDIDATE_RESOURCES) |
|
2241 |
return; |
|
2242 |
||
2243 |
// For the purposes of testing shared usgae of resources, we need a shareable resource |
|
2244 |
if((TInt)(aResource->iUsage)==(TInt)(EResShared)) |
|
2245 |
{ |
|
2246 |
// An additional requirement is that the level of the resource can be |
|
2247 |
// updated a sufficient amount of times to support the required testing. |
|
2248 |
if(((aResource->iMaxLevel - aResource->iMinLevel) > LEVEL_GAP_REQUIRED_FOR_SHARED_TESTING) && |
|
2249 |
((TInt)(aResource->iSense) == (TInt)(EResPositive)) ) |
|
2250 |
{ |
|
2251 |
TInt r=((DPowerResourceController*)iPddPtr)->GetResourceId(ClientHandle(), *(aResource->iResourceName), iCandidateSharedResIds[iNoCandidateSharedRes]); |
|
2252 |
if(r!=KErrNone) |
|
2253 |
{ |
|
2254 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("Failed to identify shared resource\n")); |
|
2255 |
} |
|
2256 |
else |
|
2257 |
{ |
|
2258 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("Potential shared resource ID = %d\n",iCandidateSharedResIds[iNoCandidateAsyncRes])); |
|
2259 |
iHaveLongLatencyResource = ETrue; |
|
2260 |
++iNoCandidateSharedRes; |
|
2261 |
} |
|
2262 |
} |
|
2263 |
} |
|
2264 |
} |
|
2265 |
||
2266 |
void DChannelResManUs::GetNumCandidateSharedResources(TUint& aNumResources) |
|
2267 |
{ |
|
2268 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::GetNumCandidateSharedResources")); |
|
2269 |
||
2270 |
aNumResources = iNoCandidateSharedRes; |
|
2271 |
} |
|
2272 |
||
2273 |
TInt DChannelResManUs::GetCandidateSharedResourceId(TUint aIndex, TUint& aResourceId) |
|
2274 |
{ |
|
2275 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::GetCandidateSharedResourceId")); |
|
2276 |
TInt r = KErrNone; |
|
2277 |
if(aIndex>=iNoCandidateSharedRes) |
|
2278 |
r = KErrNotFound; |
|
2279 |
else |
|
2280 |
aResourceId = iCandidateSharedResIds[aIndex]; |
|
2281 |
return r; |
|
2282 |
} |
|
2283 |
||
2284 |
#endif |
|
2285 |
||
2286 |
TInt DChannelResManUs::ExtractResourceInfo(const TPowerResourceInfoV01* aPwrResInfo, TResourceInfoBuf& aInfo) |
|
2287 |
{ |
|
2288 |
// Extract data from a TPowerResourceInfoV01 object to a TResourceInfo instance |
|
2289 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::ExtractResourceInfo")); |
|
2290 |
||
2291 |
TInt r=KErrNone; |
|
2292 |
TInt copyLength=(((aInfo().iName).MaxLength())<((aPwrResInfo->iResourceName)->Length()))? |
|
2293 |
(aInfo().iName).MaxLength(): |
|
2294 |
(aPwrResInfo->iResourceName)->Length(); |
|
2295 |
(aInfo().iName).Copy((aPwrResInfo->iResourceName)->Ptr(),copyLength); |
|
2296 |
aInfo().iId = aPwrResInfo->iResourceId; |
|
2297 |
aInfo().iClass = (TResourceClass)aPwrResInfo->iClass; |
|
2298 |
aInfo().iType = (TResourceType)aPwrResInfo->iType; |
|
2299 |
aInfo().iUsage = (TResourceUsage)aPwrResInfo->iUsage; |
|
2300 |
aInfo().iSense = (TResourceSense)aPwrResInfo->iSense; |
|
2301 |
aInfo().iMinLevel = aPwrResInfo->iMinLevel; |
|
2302 |
aInfo().iMaxLevel = aPwrResInfo->iMaxLevel; |
|
2303 |
||
2304 |
#ifdef _DUMP_TRACKERS |
|
2305 |
r=DumpResource(aPwrResInfo); |
|
2306 |
#endif |
|
2307 |
return r; |
|
2308 |
} |
|
2309 |
||
2310 |
#ifdef _DUMP_TRACKERS |
|
2311 |
TInt DChannelResManUs::DumpResource(const TPowerResourceInfoV01* aResource) |
|
2312 |
{ |
|
2313 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("> DChannelResManUs::DumpResource")); |
|
2314 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("Resource name = %S \n",aResource->iResourceName)); |
|
2315 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("Resource ID = 0x%d \n",aResource->iResourceId)); |
|
2316 |
switch(aResource->iClass) |
|
2317 |
{ |
|
2318 |
case DStaticPowerResource::EPhysical: |
|
2319 |
{ |
|
2320 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("class = EPhysical\n")); |
|
2321 |
break; |
|
2322 |
} |
|
2323 |
case DStaticPowerResource::ELogical: |
|
2324 |
{ |
|
2325 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("class = ELogical\n")); |
|
2326 |
break; |
|
2327 |
} |
|
2328 |
default: |
|
2329 |
{ |
|
2330 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("class = % is UNKNOWN!\n")); |
|
2331 |
return KErrGeneral; |
|
2332 |
} |
|
2333 |
} |
|
2334 |
switch(aResource->iType) |
|
2335 |
{ |
|
2336 |
case DStaticPowerResource::EBinary: |
|
2337 |
{ |
|
2338 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("type = EBinary\n")); |
|
2339 |
break; |
|
2340 |
} |
|
2341 |
case DStaticPowerResource::EMultilevel: |
|
2342 |
{ |
|
2343 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("type = EMultilevel\n")); |
|
2344 |
break; |
|
2345 |
} |
|
2346 |
case DStaticPowerResource::EMultiProperty: |
|
2347 |
{ |
|
2348 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("type = EMultiProperty\n")); |
|
2349 |
break; |
|
2350 |
} |
|
2351 |
default: |
|
2352 |
{ |
|
2353 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("type = % is UNKNOWN!\n")); |
|
2354 |
return KErrGeneral; |
|
2355 |
} |
|
2356 |
} |
|
2357 |
switch(aResource->iUsage) |
|
2358 |
{ |
|
2359 |
case DStaticPowerResource::ESingleUse: |
|
2360 |
{ |
|
2361 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("usage = ESingleUse\n")); |
|
2362 |
break; |
|
2363 |
} |
|
2364 |
case DStaticPowerResource::EShared: |
|
2365 |
{ |
|
2366 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("usage = EShared\n")); |
|
2367 |
break; |
|
2368 |
} |
|
2369 |
default: |
|
2370 |
{ |
|
2371 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("usage = % is UNKNOWN!\n")); |
|
2372 |
return KErrGeneral; |
|
2373 |
} |
|
2374 |
} |
|
2375 |
switch(aResource->iSense) |
|
2376 |
{ |
|
2377 |
case DStaticPowerResource::EPositive: |
|
2378 |
{ |
|
2379 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("sense = EPositive\n")); |
|
2380 |
break; |
|
2381 |
} |
|
2382 |
case DStaticPowerResource::ENegative: |
|
2383 |
{ |
|
2384 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("sense = ENegative\n")); |
|
2385 |
break; |
|
2386 |
} |
|
2387 |
case DStaticPowerResource::ECustom: |
|
2388 |
{ |
|
2389 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("sense = ECustom\n")); |
|
2390 |
break; |
|
2391 |
} |
|
2392 |
default: |
|
2393 |
{ |
|
2394 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("sense = % is UNKNOWN!\n")); |
|
2395 |
return KErrGeneral; |
|
2396 |
} |
|
2397 |
} |
|
2398 |
switch(aResource->iLatencyGet) |
|
2399 |
{ |
|
2400 |
case DStaticPowerResource::EInstantaneous: |
|
2401 |
{ |
|
2402 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("latency get = EInstantaneous\n")); |
|
2403 |
break; |
|
2404 |
} |
|
2405 |
case DStaticPowerResource::ENegative: |
|
2406 |
{ |
|
2407 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("latency get = ELongLatency\n")); |
|
2408 |
break; |
|
2409 |
} |
|
2410 |
default: |
|
2411 |
{ |
|
2412 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("latency get = % is UNKNOWN!\n")); |
|
2413 |
return KErrGeneral; |
|
2414 |
} |
|
2415 |
} |
|
2416 |
switch(aResource->iLatencySet) |
|
2417 |
{ |
|
2418 |
case DStaticPowerResource::EInstantaneous: |
|
2419 |
{ |
|
2420 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("latency set = EInstantaneous\n")); |
|
2421 |
break; |
|
2422 |
} |
|
2423 |
case DStaticPowerResource::ENegative: |
|
2424 |
{ |
|
2425 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("latency set = ELongLatency\n")); |
|
2426 |
break; |
|
2427 |
} |
|
2428 |
default: |
|
2429 |
{ |
|
2430 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("latency set = % is UNKNOWN!\n")); |
|
2431 |
return KErrGeneral; |
|
2432 |
} |
|
2433 |
} |
|
2434 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DefaultLevel = %d\n",aResource->iDefaultLevel)); |
|
2435 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("MinLevel = %d\n",aResource->iMinLevel)); |
|
2436 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("MaxLevel = %d\n",aResource->iMaxLevel)); |
|
2437 |
||
2438 |
return KErrNone; |
|
2439 |
} |
|
2440 |
#endif |
|
2441 |
||
2442 |
#ifndef RESOURCE_MANAGER_SIMULATED_PSL |
|
2443 |
DECLARE_EXTENSION_LDD() |
|
2444 |
{ |
|
2445 |
return new DDeviceResManUs; |
|
2446 |
} |
|
2447 |
||
2448 |
||
2449 |
DECLARE_STANDARD_EXTENSION() |
|
2450 |
{ |
|
2451 |
DDeviceResManUs* device = new DDeviceResManUs; |
|
2452 |
__KTRACE_OPT(KBOOT, Kern::Printf("DECLARE_STANDARD_EXTENSION, device = 0x%x\n",device)); |
|
2453 |
||
2454 |
if(device == NULL) |
|
2455 |
return KErrNoMemory; |
|
2456 |
else |
|
2457 |
{ |
|
2458 |
device->iSharedDfcQue = new TDfcQue(); |
|
2459 |
if(device->iSharedDfcQue==NULL) |
|
2460 |
return KErrNoMemory; |
|
2461 |
||
2462 |
return (Kern::InstallLogicalDevice(device)); |
|
2463 |
} |
|
2464 |
} |
|
2465 |
#else |
|
2466 |
DECLARE_STANDARD_LDD() |
|
2467 |
{ |
|
2468 |
TInt r = DSimulatedPowerResourceController::CompleteResourceControllerInitialisation(); |
|
2469 |
if(r != KErrNone) |
|
2470 |
{ |
|
2471 |
// Unconditionally print message |
|
2472 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("DECLARE_STANDARD_LDD: initialise Resource Controller failed with %d\n",r)); |
|
2473 |
return NULL; |
|
2474 |
} |
|
2475 |
DDeviceResManUs* device = new DDeviceResManUs; |
|
2476 |
return device; |
|
2477 |
} |
|
2478 |
#endif |