author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:01:36 +0300 | |
branch | RCL_3 |
changeset 58 | ea43c23d28d2 |
parent 33 | 50974a8b132e |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: ?Description |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
#include <e32std.h> |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
21 |
#include <liwservicehandler.h> |
19 | 22 |
|
23 |
#include "tsysinfoprovidertests.h" |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
24 |
#include "tautolocknotifier.h" |
19 | 25 |
#include "watchtimer.h" |
26 |
#include "entitykeys.h" |
|
27 |
#include "sysinfoaiwparams.hrh" |
|
28 |
||
29 |
using namespace LIW ; |
|
30 |
using namespace SysInfo; |
|
31 |
using namespace sysinfoaiwparams; |
|
32 |
||
33 |
CAutoLockNotifier* CAutoLockNotifier::NewL(CStifLogger* aLog,TInt aDrvNo) |
|
34 |
{ |
|
35 |
CAutoLockNotifier* self = new(ELeave) CAutoLockNotifier(aLog,aDrvNo); |
|
36 |
self->ConstructL(); |
|
37 |
return self; |
|
38 |
} |
|
39 |
||
40 |
CAutoLockNotifier::~CAutoLockNotifier() |
|
41 |
{ |
|
42 |
Cancel(); |
|
43 |
if(iWaitSchedular->IsStarted()) |
|
44 |
iWaitSchedular->AsyncStop(); |
|
45 |
||
46 |
delete iTimer; |
|
47 |
||
48 |
iInParamList->Reset(); |
|
49 |
iOutParamList->Reset(); |
|
50 |
iInterface->Close(); |
|
51 |
delete iServiceHandler; |
|
52 |
||
53 |
delete iWaitSchedular; |
|
54 |
} |
|
55 |
||
56 |
void CAutoLockNotifier::ConstructL() |
|
57 |
{ |
|
58 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
59 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
60 |
CreateInterfaceL(); |
|
61 |
CActiveScheduler::Add(this); |
|
62 |
} |
|
63 |
||
64 |
CAutoLockNotifier::CAutoLockNotifier(CStifLogger* aLog,TInt aAutoLockTime) : |
|
65 |
CActive(EPriorityStandard), |
|
66 |
iAutoLockTime(aAutoLockTime), |
|
67 |
iRestoreAutoLockTime(15), |
|
68 |
iLog(aLog) |
|
69 |
{ |
|
70 |
} |
|
71 |
||
72 |
void CAutoLockNotifier::DoCancel() |
|
73 |
{ |
|
74 |
//TRAPD(err1,iSysInfoService->GetInfoL(req1)); |
|
75 |
} |
|
76 |
||
77 |
void CAutoLockNotifier::RunL() |
|
78 |
{ |
|
79 |
TestFuncL(); |
|
80 |
} |
|
81 |
||
82 |
void CAutoLockNotifier::Start() |
|
83 |
{ |
|
84 |
SetActive(); |
|
85 |
TRequestStatus* temp = &iStatus; |
|
86 |
User::RequestComplete(temp, KErrNone); |
|
87 |
iWaitSchedular->Start(); |
|
88 |
} |
|
89 |
||
90 |
TInt CAutoLockNotifier::Result() |
|
91 |
{ |
|
92 |
return iResult; |
|
93 |
} |
|
94 |
||
95 |
void CAutoLockNotifier::TestFuncL() |
|
96 |
{ |
|
97 |
TInt RetVal(PASS); |
|
98 |
TInt32 Err; |
|
99 |
||
100 |
// Get autolocktime val |
|
101 |
//------------------------------------------------------------------------- |
|
102 |
{ |
|
103 |
iLog->Log( _L("Reading initial autolocktime value ..")); |
|
104 |
||
105 |
iOutParamList->Reset(); |
|
106 |
iInParamList->Reset(); |
|
107 |
||
108 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KDisplay))); |
|
109 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KAutoLockTime))); |
|
110 |
||
111 |
iInterface->ExecuteCmdL(KGetInfo,*iInParamList,*iOutParamList); |
|
112 |
||
113 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
114 |
if ( Err ) |
|
115 |
{ |
|
116 |
iLog->Log( _L("GetInfo retured error : %d"),Err ); |
|
117 |
User::Leave(Err); |
|
118 |
} |
|
119 |
||
120 |
TInt index=0; |
|
121 |
const TLiwGenericParam* ret_val = iOutParamList->FindFirst(index,KReturnValue); |
|
122 |
if(!ret_val) |
|
123 |
{ |
|
124 |
iLog->Log( _L("Return value parameter not found")); |
|
125 |
User::Leave(FAIL); |
|
126 |
} |
|
127 |
else |
|
128 |
{ |
|
129 |
const CLiwMap* outmap = ret_val->Value().AsMap(); |
|
130 |
TLiwVariant autolocktime; |
|
131 |
if( outmap->FindL(KStatus,autolocktime) ) |
|
132 |
iRestoreAutoLockTime = autolocktime.AsTInt32(); |
|
133 |
((CLiwMap*)outmap)->DecRef(); |
|
134 |
} |
|
135 |
iLog->Log( _L("Inital autolocktime to be restored to: %d"),iRestoreAutoLockTime); |
|
136 |
} |
|
137 |
||
138 |
||
139 |
// SET AUTOLOCK TIME. |
|
140 |
//------------------------------------------------------------------------- |
|
141 |
{ |
|
142 |
CLiwMap* inmap = CLiwDefaultMap::NewL(); |
|
143 |
iLog->Log( _L("Seting Autolock time ..")); |
|
144 |
||
145 |
iOutParamList->Reset(); |
|
146 |
iInParamList->Reset(); |
|
147 |
||
148 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KDisplay))); |
|
149 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KAutoLockTime))); |
|
150 |
||
151 |
inmap->InsertL(KStatus,TLiwVariant((TInt32)iAutoLockTime)); |
|
152 |
iInParamList->AppendL(TLiwGenericParam(KSysData,TLiwVariant(inmap))); |
|
153 |
||
154 |
iInterface->ExecuteCmdL(KSetInfo,*iInParamList,*iOutParamList); |
|
155 |
inmap->Remove(KStatus); |
|
156 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
157 |
if ( Err ) |
|
158 |
{ |
|
159 |
iLog->Log( _L("SetInfo retured error : %d"),Err ); |
|
160 |
User::Leave(Err); |
|
161 |
} |
|
162 |
inmap->DecRef(); |
|
163 |
} |
|
164 |
||
165 |
// REGISTER FOR NOTIFICATION. |
|
166 |
//------------------------------------------------------------------------- |
|
167 |
{ |
|
168 |
iLog->Log( _L("Issueing Notification request ..")); |
|
169 |
TInt RetVal(PASS); |
|
170 |
TInt32 Err; |
|
171 |
||
172 |
iOutParamList->Reset(); |
|
173 |
iInParamList->Reset(); |
|
174 |
||
175 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KDisplay))); |
|
176 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KAutoLockStatus))); |
|
177 |
||
178 |
iInterface->ExecuteCmdL(KGetNotification,*iInParamList,*iOutParamList,KLiwOptASyncronous,this); |
|
179 |
||
180 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
181 |
if ( Err ) |
|
182 |
{ |
|
183 |
iLog->Log( _L("GetNotification retured error : %d"),Err ); |
|
184 |
User::Leave(Err); |
|
185 |
} |
|
186 |
||
187 |
TInt index=0; |
|
188 |
const TLiwGenericParam* ret_val = iOutParamList->FindFirst(index,KTransactionId); |
|
189 |
if(!ret_val) |
|
190 |
{ |
|
191 |
iLog->Log( _L("Transaction ID not found")); |
|
192 |
User::Leave(FAIL); |
|
193 |
} |
|
194 |
else |
|
195 |
{ |
|
196 |
iTransID = ret_val->Value().AsTInt32(); |
|
197 |
iLog->Log( _L("TRANSACTION ID : %d"),iTransID ); |
|
198 |
} |
|
199 |
||
200 |
} |
|
201 |
||
202 |
iOutParamList->Reset(); |
|
203 |
iInParamList->Reset(); |
|
204 |
||
205 |
const TInt OneMin(60000000); |
|
206 |
iTimer->After(OneMin*iAutoLockTime*2); |
|
207 |
||
208 |
} |
|
209 |
||
210 |
TInt CAutoLockNotifier::HandleNotifyL( TInt aTransID, TInt aEventId, |
|
211 |
CLiwGenericParamList& aEventParamList, |
|
212 |
const CLiwGenericParamList& ) |
|
213 |
{ |
|
214 |
aEventId=aEventId; |
|
215 |
delete iTimer; |
|
216 |
iTimer = NULL; |
|
217 |
||
218 |
// RESTORE AUTOLOCK TIME. |
|
219 |
//------------------------------------------------------------------------- |
|
220 |
{ |
|
221 |
TInt RetVal(PASS); |
|
222 |
TInt32 Err(PASS); |
|
223 |
||
224 |
CLiwMap* inmap = CLiwDefaultMap::NewL(); |
|
225 |
iLog->Log( _L("Restoring Autolock time to %d"),iRestoreAutoLockTime); |
|
226 |
||
227 |
iOutParamList->Reset(); |
|
228 |
iInParamList->Reset(); |
|
229 |
||
230 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KDisplay))); |
|
231 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KAutoLockTime))); |
|
232 |
||
233 |
inmap->InsertL(KStatus,TLiwVariant((TInt32)iRestoreAutoLockTime)); |
|
234 |
iInParamList->AppendL(TLiwGenericParam(KSysData,TLiwVariant(inmap))); |
|
235 |
||
236 |
iInterface->ExecuteCmdL(KSetInfo,*iInParamList,*iOutParamList); |
|
237 |
inmap->Remove(KStatus); |
|
238 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
239 |
if ( Err ) |
|
240 |
{ |
|
241 |
iLog->Log( _L("SetInfo retured error : %d"),Err ); |
|
242 |
User::Leave(Err); |
|
243 |
} |
|
244 |
inmap->DecRef(); |
|
245 |
} |
|
246 |
||
247 |
// CHECK AUTOLOCK NOTIFICATION. |
|
248 |
//------------------------------------------------------------------------- |
|
249 |
{ |
|
250 |
TInt index=0; |
|
251 |
TPtrC entity,key; |
|
252 |
TInt32 status; |
|
253 |
const TLiwGenericParam* ret_val = aEventParamList.FindFirst(index,KReturnValue); |
|
254 |
if(!ret_val) |
|
255 |
{ |
|
256 |
iLog->Log( _L("Return value parameter not found")); |
|
257 |
User::Leave(FAIL); |
|
258 |
} |
|
259 |
else |
|
260 |
{ |
|
261 |
const CLiwMap* outmap = ret_val->Value().AsMap(); |
|
262 |
TLiwVariant ventity,vkey,vstatus; |
|
263 |
if( !outmap->FindL(KEntity,ventity) ) |
|
264 |
{ |
|
265 |
iLog->Log( _L("Entity parameter not found")); |
|
266 |
User::Leave(FAIL); |
|
267 |
} |
|
268 |
if( !outmap->FindL(KKey,vkey) ) |
|
269 |
{ |
|
270 |
iLog->Log( _L("Key parameter not found")); |
|
271 |
User::Leave(FAIL); |
|
272 |
} |
|
273 |
||
274 |
if( !outmap->FindL(KStatus,vstatus) ) |
|
275 |
{ |
|
276 |
iLog->Log( _L("Status parameter not found")); |
|
277 |
User::Leave(FAIL); |
|
278 |
} |
|
279 |
ventity.Get(entity); |
|
280 |
vkey.Get(key); |
|
281 |
status = vstatus.AsTInt32(); |
|
282 |
||
283 |
// ((CLiwMap)outmap)->DecRef(); |
|
284 |
||
285 |
if( !(entity.Compare(KDisplay) || key.Compare(KAutoLockStatus)) ) |
|
286 |
{ |
|
287 |
if(!(aTransID == iTransID)) |
|
288 |
{ |
|
289 |
iLog->Log(_L("Incorrect TransactionID: %d"),aTransID); |
|
290 |
iResult |= FAIL; |
|
291 |
} |
|
292 |
||
293 |
iLog->Log(_L("Autolock Notification..")); |
|
294 |
if(status) |
|
295 |
iLog->Log(_L("AutoLock ENABLED")); |
|
296 |
else |
|
297 |
iLog->Log(_L("AutoLock DISABLED")); |
|
298 |
||
299 |
iResult |= PASS; |
|
300 |
} |
|
301 |
||
302 |
ventity.Reset(); |
|
303 |
vkey.Reset(); |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
iWaitSchedular->AsyncStop(); |
|
308 |
return KErrNone; |
|
309 |
} |
|
310 |
||
311 |
void CAutoLockNotifier::HandleTimeOut() |
|
312 |
{ |
|
313 |
iLog->Log(_L("TimeOut reached. Auto Lock Not Enabled..")); |
|
314 |
// iSysInfoService->Cancel(1); |
|
315 |
// RESTORE AUTOLOCK TIME. |
|
316 |
//------------------------------------------------------------------------- |
|
317 |
{ |
|
318 |
TInt RetVal(PASS); |
|
319 |
TInt32 Err(PASS); |
|
320 |
||
321 |
CLiwMap* inmap = CLiwDefaultMap::NewL(); |
|
322 |
iLog->Log( _L("Restoring Autolock time to %d"),iRestoreAutoLockTime); |
|
323 |
||
324 |
iOutParamList->Reset(); |
|
325 |
iInParamList->Reset(); |
|
326 |
||
327 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KDisplay))); |
|
328 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KAutoLockTime))); |
|
329 |
||
330 |
inmap->InsertL(KStatus,TLiwVariant((TInt32)iRestoreAutoLockTime)); |
|
331 |
iInParamList->AppendL(TLiwGenericParam(KSysData,TLiwVariant(inmap))); |
|
332 |
||
333 |
iInterface->ExecuteCmdL(KSetInfo,*iInParamList,*iOutParamList); |
|
334 |
inmap->Remove(KStatus); |
|
335 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
336 |
if ( Err ) |
|
337 |
{ |
|
338 |
iLog->Log( _L("SetInfo retured error : %d"),Err ); |
|
339 |
User::Leave(Err); |
|
340 |
} |
|
341 |
inmap->DecRef(); |
|
342 |
} |
|
343 |
||
344 |
iResult = FAIL; |
|
345 |
iWaitSchedular->AsyncStop(); |
|
346 |
} |
|
347 |
||
348 |
void CAutoLockNotifier::CreateInterfaceL() |
|
349 |
{ |
|
350 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
351 |
CleanupStack::PushL(iServiceHandler); |
|
352 |
||
353 |
iInParamList = &(iServiceHandler->InParamListL()); |
|
354 |
iOutParamList = &(iServiceHandler->OutParamListL()); |
|
355 |
||
356 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1,KIDataSource,KService); |
|
357 |
CleanupStack::PushL(crit); |
|
358 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
359 |
RCriteriaArray a; |
|
360 |
CleanupClosePushL(a); |
|
361 |
a.AppendL(crit); |
|
362 |
iServiceHandler->AttachL(a); |
|
363 |
iServiceHandler->ExecuteServiceCmdL(*crit,*iInParamList,*iOutParamList); |
|
364 |
||
365 |
TInt Index = 0; |
|
366 |
const TLiwGenericParam* param = iOutParamList->FindFirst(Index,KIDataSource); |
|
367 |
if(!param) |
|
368 |
{ |
|
369 |
iLog->Log( _L("Interface Not found ")); |
|
370 |
User::Leave(KErrGeneral); |
|
371 |
} |
|
372 |
||
373 |
iInterface = param->Value().AsInterface(); |
|
374 |
CleanupStack::PopAndDestroy(&a); |
|
375 |
CleanupStack::PopAndDestroy (crit); |
|
376 |
||
377 |
CleanupStack::Pop (iServiceHandler); |
|
378 |
} |
|
379 |
||
380 |
TInt CAutoLockNotifier::CheckErrorCode( const CLiwGenericParamList& aOutList, TInt32 &aError ) |
|
381 |
{ |
|
382 |
TInt Index = 0; |
|
383 |
const TLiwGenericParam* errcode = aOutList.FindFirst(Index,KErrorCode); |
|
384 |
if ( KErrNotFound == Index ) |
|
385 |
{ |
|
386 |
iLog->Log( _L("ErrorCode not found in output ArgList") ); |
|
387 |
return FAIL; |
|
388 |
} |
|
389 |
else |
|
390 |
errcode->Value().Get(aError); |
|
391 |
return PASS; |
|
392 |
} |
|
393 |
//End of file. |
|
394 |