sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <kernel/kernel.h>
|
sl@0
|
17 |
#include <drivers/resourceman.h>
|
sl@0
|
18 |
#include "d_prmacctst.h"
|
sl@0
|
19 |
#ifdef RESOURCE_MANAGER_SIMULATED_PSL
|
sl@0
|
20 |
#include "../resourceman_psl/rescontrol_psl.h"
|
sl@0
|
21 |
#endif // RESOURCE_MANAGER_SIMULATED_PSL
|
sl@0
|
22 |
|
sl@0
|
23 |
#define TEST_KERRNONE(x) { TInt _r = (x); if (_r != KErrNone) \
|
sl@0
|
24 |
Kern::Printf("Test failed: %s line %d error %d", __FILE__, __LINE__, _r); }
|
sl@0
|
25 |
#define TEST(x) { if (!(x)) Kern::Printf("Test failed: %s line %d", __FILE__, __LINE__); }
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT(KTestDfcQueBaseName, "PrmIfDfc");
|
sl@0
|
28 |
const TInt KTestDfcQuePrority = KMaxDfcPriority - 1;
|
sl@0
|
29 |
|
sl@0
|
30 |
//---------------------------------------------------------------------------
|
sl@0
|
31 |
|
sl@0
|
32 |
class DPrmIfDevice : public DLogicalDevice
|
sl@0
|
33 |
{
|
sl@0
|
34 |
public:
|
sl@0
|
35 |
DPrmIfDevice();
|
sl@0
|
36 |
virtual TInt Install();
|
sl@0
|
37 |
virtual void GetCaps(TDes8& aDes) const;
|
sl@0
|
38 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
sl@0
|
39 |
};
|
sl@0
|
40 |
|
sl@0
|
41 |
//---------------------------------------------------------------------------
|
sl@0
|
42 |
|
sl@0
|
43 |
class DPrmIfChannel : public DLogicalChannel
|
sl@0
|
44 |
{
|
sl@0
|
45 |
public:
|
sl@0
|
46 |
DPrmIfChannel();
|
sl@0
|
47 |
~DPrmIfChannel();
|
sl@0
|
48 |
protected:
|
sl@0
|
49 |
virtual void HandleMsg(TMessageBase* aMsg);
|
sl@0
|
50 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
sl@0
|
51 |
private:
|
sl@0
|
52 |
TInt DoControl(TInt aReqNo, TAny *a1, TAny *a2);
|
sl@0
|
53 |
TInt DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny *a1, TAny *a2);
|
sl@0
|
54 |
void Shutdown();
|
sl@0
|
55 |
|
sl@0
|
56 |
public:
|
sl@0
|
57 |
static TUint KernelExtensionClientId;
|
sl@0
|
58 |
private:
|
sl@0
|
59 |
DThread* iUserThread;
|
sl@0
|
60 |
TUint iClientId;
|
sl@0
|
61 |
HBuf* iClientName;
|
sl@0
|
62 |
};
|
sl@0
|
63 |
|
sl@0
|
64 |
TUint DPrmIfChannel::KernelExtensionClientId = 0;
|
sl@0
|
65 |
|
sl@0
|
66 |
void TestCallbackFunction(TUint /* aClientId */,
|
sl@0
|
67 |
TUint /* aResourceId */,
|
sl@0
|
68 |
TInt /* aLevel */,
|
sl@0
|
69 |
TInt /* aLevelOwnerId */,
|
sl@0
|
70 |
TInt /* aResult */,
|
sl@0
|
71 |
TAny* aSem);
|
sl@0
|
72 |
|
sl@0
|
73 |
//---------------------------------------------------------------------------
|
sl@0
|
74 |
|
sl@0
|
75 |
DPrmIfDevice::DPrmIfDevice()
|
sl@0
|
76 |
{
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
TInt DPrmIfDevice::Install()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
return SetName(&KPrmIfLddName);
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
void DPrmIfDevice::GetCaps(TDes8& /* aDes */) const
|
sl@0
|
85 |
{
|
sl@0
|
86 |
// Not used but required as DLogicalDevice::GetCaps is pure virtual
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
TInt DPrmIfDevice::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
aChannel = new DPrmIfChannel;
|
sl@0
|
92 |
return aChannel ? KErrNone : KErrNoMemory;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
//---------------------------------------------------------------------------
|
sl@0
|
96 |
|
sl@0
|
97 |
DPrmIfChannel::DPrmIfChannel()
|
sl@0
|
98 |
{
|
sl@0
|
99 |
iUserThread = &Kern::CurrentThread();
|
sl@0
|
100 |
((DObject*) iUserThread)->Open();
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
DPrmIfChannel::~DPrmIfChannel()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
if(iDfcQ)
|
sl@0
|
106 |
((TDynamicDfcQue*)iDfcQ)->Destroy();
|
sl@0
|
107 |
// Close our reference on the client thread
|
sl@0
|
108 |
Kern::SafeClose((DObject*&)iUserThread,NULL);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
void DPrmIfChannel::HandleMsg(TMessageBase *aMsg)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
TThreadMessage& m = *(TThreadMessage*) aMsg;
|
sl@0
|
114 |
TInt id = m.iValue;
|
sl@0
|
115 |
|
sl@0
|
116 |
if (id == (TInt) ECloseMsg)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
m.Complete(KErrNone, EFalse);
|
sl@0
|
119 |
return;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
else if (id == KMaxTInt)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
// DoCancel
|
sl@0
|
124 |
m.Complete(KErrNone, ETrue);
|
sl@0
|
125 |
return;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
else if (id < 0)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
// DoRequest
|
sl@0
|
130 |
TRequestStatus* pS = (TRequestStatus*) m.Ptr0();
|
sl@0
|
131 |
TInt r = DoRequest(~id, pS, m.Ptr1(), m.Ptr2());
|
sl@0
|
132 |
if (r != KErrNone)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
Kern::RequestComplete(iUserThread, pS, r);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
m.Complete(KErrNone, ETrue);
|
sl@0
|
137 |
}
|
sl@0
|
138 |
else
|
sl@0
|
139 |
{
|
sl@0
|
140 |
// DoControl
|
sl@0
|
141 |
TInt r = DoControl(id, m.Ptr0(), m.Ptr1());
|
sl@0
|
142 |
if(r != KErrCompletion)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
m.Complete(r, ETrue);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
}
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
TInt DPrmIfChannel::DoCreate(TInt /* aUnit */, const TDesC8* /* aInfo */, const TVersion& /* aVer */)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
TDynamicDfcQue* dfcQ;
|
sl@0
|
152 |
TInt r = Kern::DynamicDfcQCreate(dfcQ, KTestDfcQuePrority, KTestDfcQueBaseName);
|
sl@0
|
153 |
TEST_KERRNONE(r);
|
sl@0
|
154 |
iDfcQ = dfcQ;
|
sl@0
|
155 |
if (r != KErrNone)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
return r;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
SetDfcQ(iDfcQ);
|
sl@0
|
160 |
iMsgQ.Receive();
|
sl@0
|
161 |
return KErrNone;
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
TInt DPrmIfChannel::DoControl(TInt aReqNo, TAny *a1, TAny *a2)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
TInt r = KErrNotSupported;
|
sl@0
|
167 |
switch (aReqNo)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
case RPrmIf::EControlOpenClient:
|
sl@0
|
170 |
{
|
sl@0
|
171 |
if (iClientId)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
return KErrAlreadyExists;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
TBuf8<80> clientName;
|
sl@0
|
176 |
r = PowerResourceManager::GetClientName((TUint) a1, (TUint) a1, clientName);
|
sl@0
|
177 |
TEST_KERRNONE(r);
|
sl@0
|
178 |
if (r == KErrNone)
|
sl@0
|
179 |
iClientId = (TUint) a1;
|
sl@0
|
180 |
break;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
case RPrmIf::EControlGetKernelExtClientId:
|
sl@0
|
184 |
{
|
sl@0
|
185 |
r = Kern::ThreadRawWrite(iUserThread, a1, &KernelExtensionClientId, sizeof(TUint));
|
sl@0
|
186 |
TEST_KERRNONE(r);
|
sl@0
|
187 |
break;
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
case RPrmIf::EControlRegisterClient:
|
sl@0
|
191 |
{
|
sl@0
|
192 |
if (iClientId)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
return KErrAlreadyExists;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
iClientName = HBuf::New(KNameMaxLength);
|
sl@0
|
197 |
r = Kern::ThreadDesRead(iUserThread, a1, *iClientName, 0);
|
sl@0
|
198 |
TEST_KERRNONE(r);
|
sl@0
|
199 |
if (r)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
return r;
|
sl@0
|
202 |
}
|
sl@0
|
203 |
r = PowerResourceManager::RegisterClient(iClientId, *iClientName);
|
sl@0
|
204 |
TEST_KERRNONE(r);
|
sl@0
|
205 |
break;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
case RPrmIf::EControlDeRegisterClient:
|
sl@0
|
209 |
{
|
sl@0
|
210 |
if (!iClientId)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
return KErrNotReady;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
r = PowerResourceManager::DeRegisterClient(iClientId);
|
sl@0
|
215 |
if (r == KErrNone)
|
sl@0
|
216 |
{
|
sl@0
|
217 |
if (iClientId == KernelExtensionClientId)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
// Set it to 0 so it cannot be re-opened
|
sl@0
|
220 |
KernelExtensionClientId = 0;
|
sl@0
|
221 |
}
|
sl@0
|
222 |
delete iClientName;
|
sl@0
|
223 |
iClientId = 0;
|
sl@0
|
224 |
}
|
sl@0
|
225 |
break;
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
case RPrmIf::EControlGetInfoOnResourcesInUseByClient:
|
sl@0
|
229 |
{
|
sl@0
|
230 |
if (!iClientId)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
return KErrNotReady;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
TUint nores;
|
sl@0
|
235 |
r = PowerResourceManager::GetNumResourcesInUseByClient(iClientId, (TUint) a1, nores);
|
sl@0
|
236 |
TEST_KERRNONE(r);
|
sl@0
|
237 |
if (r)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
return r;
|
sl@0
|
240 |
}
|
sl@0
|
241 |
if (nores > 0)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
HBuf* resinfo;
|
sl@0
|
244 |
resinfo = HBuf::New(nores * sizeof(TResInfo));
|
sl@0
|
245 |
TEST(resinfo != NULL);
|
sl@0
|
246 |
if (resinfo == NULL)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
return KErrNoMemory;
|
sl@0
|
249 |
}
|
sl@0
|
250 |
r = PowerResourceManager::GetInfoOnResourcesInUseByClient(iClientId, (TUint) a1, nores, (TAny*) resinfo);
|
sl@0
|
251 |
TEST_KERRNONE(r);
|
sl@0
|
252 |
if (r)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
delete resinfo;
|
sl@0
|
255 |
return r;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
r = Kern::ThreadDesWrite(iUserThread, a2, *resinfo, 0);
|
sl@0
|
258 |
TEST_KERRNONE(r);
|
sl@0
|
259 |
delete resinfo;
|
sl@0
|
260 |
}
|
sl@0
|
261 |
break;
|
sl@0
|
262 |
}
|
sl@0
|
263 |
|
sl@0
|
264 |
case RPrmIf::EControlChangeResourceState:
|
sl@0
|
265 |
{
|
sl@0
|
266 |
if (!iClientId)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
return KErrNotReady;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
r = PowerResourceManager::ChangeResourceState(iClientId, (TUint) a1, (TInt) a2);
|
sl@0
|
271 |
break;
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
case RPrmIf::EControlGetResourceState:
|
sl@0
|
275 |
{
|
sl@0
|
276 |
if (!iClientId)
|
sl@0
|
277 |
{
|
sl@0
|
278 |
return KErrNotReady;
|
sl@0
|
279 |
}
|
sl@0
|
280 |
TInt state;
|
sl@0
|
281 |
TInt levelowner;
|
sl@0
|
282 |
r = PowerResourceManager::GetResourceState(iClientId, (TUint) a1, EFalse, state, levelowner);
|
sl@0
|
283 |
TEST_KERRNONE(r);
|
sl@0
|
284 |
if (r)
|
sl@0
|
285 |
{
|
sl@0
|
286 |
return r;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
r = Kern::ThreadRawWrite(iUserThread, a2, (TAny*) &state, sizeof(TInt));
|
sl@0
|
289 |
TEST_KERRNONE(r);
|
sl@0
|
290 |
break;
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
case RPrmIf::EControlGetResourceStateCached:
|
sl@0
|
294 |
{
|
sl@0
|
295 |
if (!iClientId)
|
sl@0
|
296 |
{
|
sl@0
|
297 |
return KErrNotReady;
|
sl@0
|
298 |
}
|
sl@0
|
299 |
TInt state;
|
sl@0
|
300 |
TInt levelowner;
|
sl@0
|
301 |
r = PowerResourceManager::GetResourceState(iClientId, (TUint) a1, ETrue, state, levelowner);
|
sl@0
|
302 |
TEST_KERRNONE(r);
|
sl@0
|
303 |
if (r)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
return r;
|
sl@0
|
306 |
}
|
sl@0
|
307 |
r = Kern::ThreadRawWrite(iUserThread, a2, (TAny*) &state, sizeof(TInt));
|
sl@0
|
308 |
TEST_KERRNONE(r);
|
sl@0
|
309 |
break;
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
case RPrmIf::EControlGetLevelOwner:
|
sl@0
|
313 |
{
|
sl@0
|
314 |
if (!iClientId)
|
sl@0
|
315 |
{
|
sl@0
|
316 |
return KErrNotReady;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
TInt state;
|
sl@0
|
319 |
TInt levelowner;
|
sl@0
|
320 |
r = PowerResourceManager::GetResourceState(iClientId, (TUint) a1, EFalse, state, levelowner);
|
sl@0
|
321 |
TEST_KERRNONE(r);
|
sl@0
|
322 |
if (r)
|
sl@0
|
323 |
{
|
sl@0
|
324 |
return r;
|
sl@0
|
325 |
}
|
sl@0
|
326 |
r = Kern::ThreadRawWrite(iUserThread, a2, (TAny*) &levelowner, sizeof(TInt));
|
sl@0
|
327 |
TEST_KERRNONE(r);
|
sl@0
|
328 |
break;
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
case RPrmIf::EControlGetTotalNumberOfResources:
|
sl@0
|
332 |
{
|
sl@0
|
333 |
if (!iClientId)
|
sl@0
|
334 |
{
|
sl@0
|
335 |
return KErrNotReady;
|
sl@0
|
336 |
}
|
sl@0
|
337 |
TUint nores;
|
sl@0
|
338 |
r = PowerResourceManager::GetNumResourcesInUseByClient(iClientId, 0, nores);
|
sl@0
|
339 |
TEST_KERRNONE(r);
|
sl@0
|
340 |
if (r)
|
sl@0
|
341 |
{
|
sl@0
|
342 |
return r;
|
sl@0
|
343 |
}
|
sl@0
|
344 |
r = Kern::ThreadRawWrite(iUserThread, a1, (TAny*) &nores, sizeof(TUint));
|
sl@0
|
345 |
TEST_KERRNONE(r);
|
sl@0
|
346 |
break;
|
sl@0
|
347 |
}
|
sl@0
|
348 |
|
sl@0
|
349 |
#ifdef PRM_ENABLE_EXTENDED_VERSION
|
sl@0
|
350 |
case RPrmIf::EControlGetResourceDependencies:
|
sl@0
|
351 |
{
|
sl@0
|
352 |
if (!iClientId)
|
sl@0
|
353 |
{
|
sl@0
|
354 |
return KErrNotReady;
|
sl@0
|
355 |
}
|
sl@0
|
356 |
// Get the resource information from the PRM
|
sl@0
|
357 |
TUint numres;
|
sl@0
|
358 |
r = PowerResourceManager::GetNumDependentsForResource(iClientId, (TUint) a1, numres);
|
sl@0
|
359 |
TEST_KERRNONE(r);
|
sl@0
|
360 |
if (r)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
return r;
|
sl@0
|
363 |
}
|
sl@0
|
364 |
|
sl@0
|
365 |
// Create a descriptor with the list of dependencies
|
sl@0
|
366 |
HBuf* depdes;
|
sl@0
|
367 |
depdes = HBuf::New(sizeof(SResourceDependencyInfo) * numres);
|
sl@0
|
368 |
TEST(depdes != NULL);
|
sl@0
|
369 |
if (depdes == NULL)
|
sl@0
|
370 |
{
|
sl@0
|
371 |
return KErrNoMemory;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
TUint numres2 = numres;
|
sl@0
|
375 |
r = PowerResourceManager::GetDependentsIdForResource(iClientId, (TUint) a1, (TAny*) depdes, numres2);
|
sl@0
|
376 |
TEST_KERRNONE(r);
|
sl@0
|
377 |
TEST(numres == numres2);
|
sl@0
|
378 |
|
sl@0
|
379 |
// Copy the descriptor contents to the user-side descriptor
|
sl@0
|
380 |
r = Kern::ThreadDesWrite(iUserThread, a2, *depdes, 0);
|
sl@0
|
381 |
TEST_KERRNONE(r);
|
sl@0
|
382 |
delete depdes;
|
sl@0
|
383 |
break;
|
sl@0
|
384 |
}
|
sl@0
|
385 |
#endif // PRM_ENABLE_EXTENDED_VERSION
|
sl@0
|
386 |
}
|
sl@0
|
387 |
return r;
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
TInt DPrmIfChannel::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny *a1, TAny *a2)
|
sl@0
|
391 |
{
|
sl@0
|
392 |
TInt r = KErrNotSupported;
|
sl@0
|
393 |
switch (aReqNo)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
case RPrmIf::ERequestChangeResourceStateAndGetState:
|
sl@0
|
396 |
{
|
sl@0
|
397 |
if (!iClientId)
|
sl@0
|
398 |
{
|
sl@0
|
399 |
return KErrNotReady;
|
sl@0
|
400 |
}
|
sl@0
|
401 |
TTestResourceStateBuf args;
|
sl@0
|
402 |
r = Kern::ThreadDesRead(iUserThread, a1, args, 0);
|
sl@0
|
403 |
TEST_KERRNONE(r);
|
sl@0
|
404 |
if (r)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
return r;
|
sl@0
|
407 |
}
|
sl@0
|
408 |
NFastSemaphore sem;
|
sl@0
|
409 |
NKern::FSSetOwner(&sem, (NThreadBase*) NKern::CurrentThread());
|
sl@0
|
410 |
TPowerResourceCb cbfn(&TestCallbackFunction, (TAny*) &sem, /*iDfcQ*/ Kern::DfcQue0(), KMaxDfcPriority - 2);
|
sl@0
|
411 |
// Change the state of the resource (asynchronous call)
|
sl@0
|
412 |
r = PowerResourceManager::ChangeResourceState(iClientId, args().iResourceId, args().iNewState, &cbfn);
|
sl@0
|
413 |
TEST_KERRNONE(r);
|
sl@0
|
414 |
if (r)
|
sl@0
|
415 |
{
|
sl@0
|
416 |
return r;
|
sl@0
|
417 |
}
|
sl@0
|
418 |
// Retrieve the intermediate state of the resource
|
sl@0
|
419 |
TInt state;
|
sl@0
|
420 |
TInt levelowner;
|
sl@0
|
421 |
r = PowerResourceManager::GetResourceState(iClientId, args().iResourceId, EFalse, state, levelowner);
|
sl@0
|
422 |
TEST_KERRNONE(r);
|
sl@0
|
423 |
if (r)
|
sl@0
|
424 |
{
|
sl@0
|
425 |
return r;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
r = Kern::ThreadRawWrite(iUserThread, a2, (TAny*) &state, sizeof(TInt));
|
sl@0
|
428 |
TEST_KERRNONE(r);
|
sl@0
|
429 |
if (r)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
return r;
|
sl@0
|
432 |
}
|
sl@0
|
433 |
// Wait for the callback function
|
sl@0
|
434 |
NKern::FSWait(&sem);
|
sl@0
|
435 |
Kern::RequestComplete(iUserThread, aStatus, r);
|
sl@0
|
436 |
break;
|
sl@0
|
437 |
}
|
sl@0
|
438 |
}
|
sl@0
|
439 |
return r;
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
//---------------------------------------------------------------------------
|
sl@0
|
443 |
|
sl@0
|
444 |
//
|
sl@0
|
445 |
// Callback function for Latency Tests
|
sl@0
|
446 |
//
|
sl@0
|
447 |
void TestCallbackFunction(TUint /* aClientId */,
|
sl@0
|
448 |
TUint /* aResourceId */,
|
sl@0
|
449 |
TInt /* aLevel */,
|
sl@0
|
450 |
TInt /* aLevelOwnerId */,
|
sl@0
|
451 |
TInt /* aResult */,
|
sl@0
|
452 |
TAny* aSem)
|
sl@0
|
453 |
{
|
sl@0
|
454 |
if (!aSem)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
return;
|
sl@0
|
457 |
}
|
sl@0
|
458 |
NKern::FSSignal((NFastSemaphore*) aSem);
|
sl@0
|
459 |
}
|
sl@0
|
460 |
|
sl@0
|
461 |
//
|
sl@0
|
462 |
// This function is called during kernel initialisation. It registers a client
|
sl@0
|
463 |
// on the PRM in order to take ownership of the Single-User resources before
|
sl@0
|
464 |
// anyone else does.
|
sl@0
|
465 |
//
|
sl@0
|
466 |
static void InitExtension(TAny*)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
TInt r;
|
sl@0
|
469 |
|
sl@0
|
470 |
// Get the overall number of resources
|
sl@0
|
471 |
TUint nores;
|
sl@0
|
472 |
r = PowerResourceManager::GetNumResourcesInUseByClient(DPrmIfChannel::KernelExtensionClientId, 0, nores);
|
sl@0
|
473 |
TEST_KERRNONE(r);
|
sl@0
|
474 |
if (r)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
return;
|
sl@0
|
477 |
}
|
sl@0
|
478 |
|
sl@0
|
479 |
// Get hold of all of the resources by setting their state to the default level
|
sl@0
|
480 |
TInt i;
|
sl@0
|
481 |
for (i = 0; i < (TInt) nores; i++)
|
sl@0
|
482 |
{
|
sl@0
|
483 |
TPowerResourceInfoBuf01 res;
|
sl@0
|
484 |
res.Zero();
|
sl@0
|
485 |
r = PowerResourceManager::GetResourceInfo(DPrmIfChannel::KernelExtensionClientId, i + 1, (TAny*) &res);
|
sl@0
|
486 |
TEST_KERRNONE(r);
|
sl@0
|
487 |
if (r)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
return;
|
sl@0
|
490 |
}
|
sl@0
|
491 |
r = PowerResourceManager::ChangeResourceState(DPrmIfChannel::KernelExtensionClientId, i + 1, res().iDefaultLevel);
|
sl@0
|
492 |
TEST_KERRNONE(r);
|
sl@0
|
493 |
if (r)
|
sl@0
|
494 |
{
|
sl@0
|
495 |
return;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
}
|
sl@0
|
498 |
TUint resinuse;
|
sl@0
|
499 |
r = PowerResourceManager::GetNumResourcesInUseByClient(DPrmIfChannel::KernelExtensionClientId, DPrmIfChannel::KernelExtensionClientId, resinuse);
|
sl@0
|
500 |
TEST_KERRNONE(r);
|
sl@0
|
501 |
TEST(resinuse == nores);
|
sl@0
|
502 |
}
|
sl@0
|
503 |
|
sl@0
|
504 |
static TDfc InitExtensionDfc(&InitExtension, NULL, Kern::SvMsgQue(), KMaxDfcPriority - 2); // Priority lower than the Resource Controller (KMaxDfcPriority - 1)
|
sl@0
|
505 |
|
sl@0
|
506 |
#ifndef RESOURCE_MANAGER_SIMULATED_PSL
|
sl@0
|
507 |
_LIT8(KTestKExtClientName, "KEXTC");
|
sl@0
|
508 |
DECLARE_STANDARD_EXTENSION()
|
sl@0
|
509 |
{
|
sl@0
|
510 |
// Register the initial PRM client (kernel will crash if this fails)
|
sl@0
|
511 |
TUint clientid;
|
sl@0
|
512 |
TInt r = PowerResourceManager::RegisterClient(clientid, KTestKExtClientName);
|
sl@0
|
513 |
TEST_KERRNONE(r);
|
sl@0
|
514 |
if (r)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
return r;
|
sl@0
|
517 |
}
|
sl@0
|
518 |
DPrmIfChannel::KernelExtensionClientId = clientid;
|
sl@0
|
519 |
// Queue the DFC call to take control of all the resources
|
sl@0
|
520 |
InitExtensionDfc.Enque();
|
sl@0
|
521 |
return KErrNone;
|
sl@0
|
522 |
}
|
sl@0
|
523 |
|
sl@0
|
524 |
DECLARE_EXTENSION_LDD()
|
sl@0
|
525 |
{
|
sl@0
|
526 |
return new DPrmIfDevice;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
#else
|
sl@0
|
529 |
DECLARE_STANDARD_LDD()
|
sl@0
|
530 |
{
|
sl@0
|
531 |
TInt r = DSimulatedPowerResourceController::CompleteResourceControllerInitialisation();
|
sl@0
|
532 |
if (r != KErrNone)
|
sl@0
|
533 |
{
|
sl@0
|
534 |
return NULL;
|
sl@0
|
535 |
}
|
sl@0
|
536 |
return new DPrmIfDevice;
|
sl@0
|
537 |
}
|
sl@0
|
538 |
#endif
|