author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 19 | 989d2f495d90 |
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 |
#include <e32std.h> |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
20 |
#include <liwservicehandler.h> |
19 | 21 |
|
22 |
#include "tsysinfoprovidergeneraltests.h" |
|
23 |
#include "tuseractivitynotifier.h" |
|
24 |
#include "watchtimer.h" |
|
25 |
||
26 |
#include "entitykeys.h" |
|
27 |
#include "sysinfoaiwparams.hrh" |
|
28 |
||
29 |
using namespace LIW ; |
|
30 |
using namespace SysInfo; |
|
31 |
using namespace sysinfoaiwparams; |
|
32 |
||
33 |
CTestUserActivity* CTestUserActivity::NewL(CStifLogger* aLog,TInt aTimeOut,Test_Type aType) |
|
34 |
{ |
|
35 |
CTestUserActivity* self = new(ELeave) CTestUserActivity(aLog,aTimeOut,aType); |
|
36 |
self->ConstructL(); |
|
37 |
return self; |
|
38 |
} |
|
39 |
||
40 |
CTestUserActivity::~CTestUserActivity() |
|
41 |
{ |
|
42 |
Cancel(); |
|
43 |
if(iWaitSchedular->IsStarted()) |
|
44 |
iWaitSchedular->AsyncStop(); |
|
45 |
||
46 |
delete iTimer; |
|
47 |
iInParamList->Reset(); |
|
48 |
iOutParamList->Reset(); |
|
49 |
iInterface->Close(); |
|
50 |
delete iServiceHandler; |
|
51 |
delete iWaitSchedular; |
|
52 |
||
53 |
} |
|
54 |
||
55 |
void CTestUserActivity::ConstructL() |
|
56 |
{ |
|
57 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
58 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
59 |
CreateInterfaceL(); |
|
60 |
CActiveScheduler::Add(this); |
|
61 |
} |
|
62 |
||
63 |
CTestUserActivity::CTestUserActivity(CStifLogger* aLog,TInt aTimeOut, |
|
64 |
Test_Type aType) : |
|
65 |
CActive(EPriorityStandard), |
|
66 |
iInactivityTimeOut(aTimeOut), |
|
67 |
iLog(aLog), |
|
68 |
iTestType(aType) |
|
69 |
{ |
|
70 |
} |
|
71 |
||
72 |
void CTestUserActivity::DoCancel() |
|
73 |
{ |
|
74 |
} |
|
75 |
||
76 |
void CTestUserActivity::RunL() |
|
77 |
{ |
|
78 |
TestFuncL(); |
|
79 |
} |
|
80 |
||
81 |
void CTestUserActivity::Start() |
|
82 |
{ |
|
83 |
SetActive(); |
|
84 |
TRequestStatus* temp = &iStatus; |
|
85 |
User::RequestComplete(temp, KErrNone); |
|
86 |
iWaitSchedular->Start(); |
|
87 |
} |
|
88 |
||
89 |
TInt CTestUserActivity::Result() |
|
90 |
{ |
|
91 |
return iResult; |
|
92 |
} |
|
93 |
||
94 |
void CTestUserActivity::TestFuncL() |
|
95 |
{ |
|
96 |
const TInt OneSec(1000000); |
|
97 |
iTimer->After(OneSec*iInactivityTimeOut*30); |
|
98 |
||
99 |
// REGISTER FOR NOTIFICATION. |
|
100 |
//------------------------------------------------------------------------- |
|
101 |
{ |
|
102 |
iLog->Log( _L("Issueing Notification request ..")); |
|
103 |
TInt RetVal(PASS); |
|
104 |
TInt32 Err; |
|
105 |
||
106 |
iOutParamList->Reset(); |
|
107 |
iInParamList->Reset(); |
|
108 |
||
109 |
CLiwMap* inmap = CLiwDefaultMap::NewL(); |
|
110 |
||
111 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KDisplay))); |
|
112 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KUserInactivity))); |
|
113 |
||
114 |
inmap->InsertL(KStatus,TLiwVariant((TInt32)iInactivityTimeOut)); |
|
115 |
iInParamList->AppendL(TLiwGenericParam(KSysData,TLiwVariant(inmap))); |
|
116 |
||
117 |
iInterface->ExecuteCmdL(KGetNotification,*iInParamList,*iOutParamList,KLiwOptASyncronous,this); |
|
118 |
||
119 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
120 |
if ( Err ) |
|
121 |
{ |
|
122 |
iLog->Log( _L("GetNotification retured error : %d"),Err ); |
|
123 |
User::Leave(Err); |
|
124 |
} |
|
125 |
||
126 |
TInt index=0; |
|
127 |
const TLiwGenericParam* ret_val = iOutParamList->FindFirst(index,KTransactionId); |
|
128 |
if(!ret_val) |
|
129 |
{ |
|
130 |
iLog->Log( _L("Transaction ID not found")); |
|
131 |
User::Leave(FAIL); |
|
132 |
} |
|
133 |
else |
|
134 |
{ |
|
135 |
iTransID = ret_val->Value().AsTInt32(); |
|
136 |
iLog->Log( _L("TRANSACTION ID : %d"),iTransID ); |
|
137 |
} |
|
138 |
||
139 |
inmap->DecRef(); |
|
140 |
} |
|
141 |
||
142 |
iOutParamList->Reset(); |
|
143 |
iInParamList->Reset(); |
|
144 |
||
145 |
} |
|
146 |
||
147 |
TInt CTestUserActivity::HandleNotifyL( TInt aTransID, TInt aEventId, |
|
148 |
CLiwGenericParamList& aEventParamList, |
|
149 |
const CLiwGenericParamList& /*aInParamList*/) |
|
150 |
{ |
|
151 |
aEventId=aEventId; |
|
152 |
delete iTimer; |
|
153 |
iTimer = NULL; |
|
154 |
{ |
|
155 |
TInt index=0; |
|
156 |
TPtrC entity,key; |
|
157 |
TInt32 status; |
|
158 |
const TLiwGenericParam* ret_val = aEventParamList.FindFirst(index,KReturnValue); |
|
159 |
if(!ret_val) |
|
160 |
{ |
|
161 |
iLog->Log( _L("Return value parameter not found")); |
|
162 |
User::Leave(FAIL); |
|
163 |
} |
|
164 |
else |
|
165 |
{ |
|
166 |
const CLiwMap* outmap = ret_val->Value().AsMap(); |
|
167 |
TLiwVariant ventity,vkey,vstatus; |
|
168 |
if( !outmap->FindL(KEntity,ventity) ) |
|
169 |
{ |
|
170 |
iLog->Log( _L("Entity parameter not found")); |
|
171 |
User::Leave(FAIL); |
|
172 |
} |
|
173 |
if( !outmap->FindL(KKey,vkey) ) |
|
174 |
{ |
|
175 |
iLog->Log( _L("Key parameter not found")); |
|
176 |
User::Leave(FAIL); |
|
177 |
} |
|
178 |
||
179 |
if( !outmap->FindL(KStatus,vstatus) ) |
|
180 |
{ |
|
181 |
iLog->Log( _L("Key parameter not found")); |
|
182 |
User::Leave(FAIL); |
|
183 |
} |
|
184 |
ventity.Get(entity); |
|
185 |
vkey.Get(key); |
|
186 |
status = vstatus.AsTInt32(); |
|
187 |
||
188 |
// ((CLiwMap)outmap)->DecRef(); |
|
189 |
||
190 |
if( !(entity.Compare(KDisplay) || key.Compare(KUserInactivity)) ) |
|
191 |
{ |
|
192 |
if(!(aTransID == iTransID)) |
|
193 |
{ |
|
194 |
iLog->Log(_L("Incorrect TransactionID: %d"),aTransID); |
|
195 |
iResult |= FAIL; |
|
196 |
} |
|
197 |
||
198 |
iLog->Log(_L("UserActivity/Inactivity Notification..")); |
|
199 |
if(status) |
|
200 |
iLog->Log(_L("User Inactivity Detected..")); |
|
201 |
else |
|
202 |
iLog->Log(_L("User Activity Detected..")); |
|
203 |
||
204 |
iResult |= PASS; |
|
205 |
} |
|
206 |
||
207 |
ventity.Reset(); |
|
208 |
vkey.Reset(); |
|
209 |
||
210 |
if (ETESTACTIVITY == iTestType) |
|
211 |
{ |
|
212 |
if(status) |
|
213 |
{ |
|
214 |
iLog->Log(_L("Waiting for user activity")); |
|
215 |
return KErrNone; |
|
216 |
} |
|
217 |
else |
|
218 |
{ |
|
219 |
iLog->Log(_L("User Activity Detected..")); |
|
220 |
} |
|
221 |
iResult |= PASS; |
|
222 |
} |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
iResult |= PASS; |
|
227 |
iWaitSchedular->AsyncStop(); |
|
228 |
return KErrNone; |
|
229 |
} |
|
230 |
||
231 |
void CTestUserActivity::HandleTimeOut() |
|
232 |
{ |
|
233 |
iLog->Log(_L("TimeOut reached. Inactivity not detected..")); |
|
234 |
/* iSysInfoService->Cancel(1); |
|
235 |
*/ |
|
236 |
iResult = FAIL; |
|
237 |
iWaitSchedular->AsyncStop(); |
|
238 |
} |
|
239 |
||
240 |
void CTestUserActivity::CreateInterfaceL() |
|
241 |
{ |
|
242 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
243 |
CleanupStack::PushL(iServiceHandler); |
|
244 |
||
245 |
iInParamList = &(iServiceHandler->InParamListL()); |
|
246 |
iOutParamList = &(iServiceHandler->OutParamListL()); |
|
247 |
||
248 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1,KIDataSource,KService); |
|
249 |
CleanupStack::PushL(crit); |
|
250 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
251 |
RCriteriaArray a; |
|
252 |
CleanupClosePushL(a); |
|
253 |
a.AppendL(crit); |
|
254 |
iServiceHandler->AttachL(a); |
|
255 |
iServiceHandler->ExecuteServiceCmdL(*crit,*iInParamList,*iOutParamList); |
|
256 |
||
257 |
TInt Index = 0; |
|
258 |
const TLiwGenericParam* param = iOutParamList->FindFirst(Index,KIDataSource); |
|
259 |
if(!param) |
|
260 |
{ |
|
261 |
iLog->Log( _L("Interface Not found ")); |
|
262 |
User::Leave(KErrGeneral); |
|
263 |
} |
|
264 |
||
265 |
iInterface = param->Value().AsInterface(); |
|
266 |
CleanupStack::PopAndDestroy(&a); |
|
267 |
CleanupStack::PopAndDestroy (crit); |
|
268 |
||
269 |
CleanupStack::Pop (iServiceHandler); |
|
270 |
} |
|
271 |
||
272 |
TInt CTestUserActivity::CheckErrorCode( const CLiwGenericParamList& aOutList, TInt32 &aError ) |
|
273 |
{ |
|
274 |
TInt Index = 0; |
|
275 |
const TLiwGenericParam* errcode = aOutList.FindFirst(Index,KErrorCode); |
|
276 |
if ( KErrNotFound == Index ) |
|
277 |
{ |
|
278 |
iLog->Log( _L("ErrorCode not found in output ArgList") ); |
|
279 |
return FAIL; |
|
280 |
} |
|
281 |
else |
|
282 |
errcode->Value().Get(aError); |
|
283 |
return PASS; |
|
284 |
} |
|
285 |
//End of file. |