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) 2009 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
18 |
#include <liwcommon.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
19 |
#include<liwservicehandler.h> |
19 | 20 |
|
21 |
#include"tsysinfoprovidertests.h" |
|
22 |
#include "sysinfointerface.h" |
|
23 |
#include"entitykeys.h" |
|
24 |
#include "sysinfoaiwparams.hrh" |
|
25 |
#include "serviceerrno.h" |
|
26 |
#include"watchtimer.h" |
|
27 |
||
28 |
using namespace LIW ; |
|
29 |
using namespace SysInfo; |
|
30 |
using namespace sysinfoaiwparams; |
|
31 |
||
32 |
||
33 |
class CUserInactivity : public CActive ,public MLiwNotifyCallback, public MTimeOutCallBack |
|
34 |
{ |
|
35 |
public: |
|
36 |
static CUserInactivity* NewL(CStifLogger* aLog); |
|
37 |
~CUserInactivity(); |
|
38 |
void Start(); |
|
39 |
TInt Result(); |
|
40 |
||
41 |
TInt HandleNotifyL(TInt aCmdId, |
|
42 |
TInt aEventId, |
|
43 |
CLiwGenericParamList& aEventParamList, |
|
44 |
const CLiwGenericParamList& aInParamList); |
|
45 |
||
46 |
IMPORT_C static TInt32 GetTransactionID(); |
|
47 |
void HandleTimeOut (); |
|
48 |
private: |
|
49 |
void ConstructL(); |
|
50 |
CUserInactivity(CStifLogger* aLog); |
|
51 |
||
52 |
virtual void DoCancel(); |
|
53 |
virtual void RunL(); |
|
54 |
||
55 |
void TestFunc(); |
|
56 |
||
57 |
private: |
|
58 |
CActiveSchedulerWait* iWaitSchedular; |
|
59 |
CLiwServiceHandler* iServiceHandler; |
|
60 |
MLiwInterface* interface ; |
|
61 |
TInt32 btstatus ; |
|
62 |
TInt iResult; |
|
63 |
CStifLogger* iLog; |
|
64 |
CWatchTimer* iTimer; |
|
65 |
}; |
|
66 |
||
67 |
CUserInactivity* CUserInactivity::NewL(CStifLogger* aLog) |
|
68 |
{ |
|
69 |
CUserInactivity* self = new(ELeave) CUserInactivity(aLog); |
|
70 |
self->ConstructL(); |
|
71 |
return self; |
|
72 |
} |
|
73 |
||
74 |
CUserInactivity::~CUserInactivity() |
|
75 |
{ |
|
76 |
Cancel(); |
|
77 |
||
78 |
interface->Close(); |
|
79 |
||
80 |
delete iServiceHandler; |
|
81 |
||
82 |
if(iWaitSchedular->IsStarted()) |
|
83 |
iWaitSchedular->AsyncStop(); |
|
84 |
||
85 |
if(iWaitSchedular) |
|
86 |
delete iWaitSchedular; |
|
87 |
||
88 |
delete iTimer; |
|
89 |
||
90 |
} |
|
91 |
||
92 |
void CUserInactivity::ConstructL() |
|
93 |
{ |
|
94 |
CActiveScheduler::Add(this); |
|
95 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
96 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
97 |
} |
|
98 |
||
99 |
CUserInactivity::CUserInactivity(CStifLogger* aLog) : |
|
100 |
CActive(EPriorityStandard),iResult(-1),iLog(aLog) |
|
101 |
{ |
|
102 |
} |
|
103 |
||
104 |
void CUserInactivity::DoCancel() |
|
105 |
{ |
|
106 |
||
107 |
//TRAPD(err1,iSysInfoService->GetInfoL(req1)); |
|
108 |
||
109 |
} |
|
110 |
||
111 |
void CUserInactivity::RunL() |
|
112 |
{ |
|
113 |
TestFunc(); |
|
114 |
} |
|
115 |
||
116 |
void CUserInactivity::Start() |
|
117 |
{ |
|
118 |
||
119 |
SetActive(); |
|
120 |
TRequestStatus* temp = &iStatus; |
|
121 |
User::RequestComplete(temp, KErrNone); |
|
122 |
iWaitSchedular->Start(); |
|
123 |
} |
|
124 |
||
125 |
TInt CUserInactivity::Result() |
|
126 |
{ |
|
127 |
return iResult; |
|
128 |
} |
|
129 |
||
130 |
void CUserInactivity::TestFunc() |
|
131 |
{ |
|
132 |
const TTimeIntervalMicroSeconds32 OneMinute(60000); |
|
133 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
134 |
CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
135 |
CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
136 |
||
137 |
TInt err = KErrNone; |
|
138 |
||
139 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KIDataSource,KService); |
|
140 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
141 |
||
142 |
RCriteriaArray a; |
|
143 |
a.AppendL(crit); |
|
144 |
||
145 |
iServiceHandler->AttachL(a); |
|
146 |
||
147 |
iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
148 |
||
149 |
delete crit; |
|
150 |
a.Reset(); |
|
151 |
||
152 |
TInt pos = 0; |
|
153 |
||
154 |
outparam->FindFirst( pos, KIDataSource ); |
|
155 |
if(pos != KErrNotFound) |
|
156 |
{ |
|
157 |
//getting the interface handle |
|
158 |
interface = (*outparam)[pos].Value().AsInterface(); |
|
159 |
} |
|
160 |
||
161 |
outparam->Reset(); |
|
162 |
inparam->Reset(); |
|
163 |
||
164 |
if(interface) |
|
165 |
{ |
|
166 |
TLiwGenericParam entity; |
|
167 |
TLiwVariant entityname; |
|
168 |
TLiwGenericParam key; |
|
169 |
TLiwVariant keyname; |
|
170 |
||
171 |
entityname.Set(KDisplay); |
|
172 |
entity.SetNameAndValueL(KEntity,entityname); |
|
173 |
||
174 |
keyname.Set(KUserInactivity); |
|
175 |
key.SetNameAndValueL(KKey,keyname); |
|
176 |
||
177 |
//sysdata as map |
|
178 |
CLiwDefaultMap* map = CLiwDefaultMap::NewL(); |
|
179 |
CleanupStack::PushL(map); |
|
180 |
||
181 |
TLiwVariant sysdata((TInt32)-5); |
|
182 |
map->InsertL(KStatus,sysdata); |
|
183 |
sysdata.Reset(); |
|
184 |
||
185 |
TLiwVariant sysparam(map); |
|
186 |
TLiwGenericParam element ; |
|
187 |
element.SetNameAndValueL(KSysData,sysparam); |
|
188 |
sysparam.Reset(); |
|
189 |
||
190 |
inparam->AppendL(entity); |
|
191 |
||
192 |
inparam->AppendL(key); |
|
193 |
inparam->AppendL(element); |
|
194 |
||
195 |
element.Reset(); |
|
196 |
||
197 |
map->DecRef(); |
|
198 |
CleanupStack::Pop(map); |
|
199 |
||
200 |
entity.Reset(); |
|
201 |
entityname.Reset(); |
|
202 |
key.Reset(); |
|
203 |
keyname.Reset(); |
|
204 |
sysdata.Reset(); |
|
205 |
||
206 |
//get notification vibra Active |
|
207 |
TRAPD(err1, interface->ExecuteCmdL(KGetNotification,*inparam,*outparam,KLiwOptASyncronous,this)); |
|
208 |
iTimer->After(OneMinute); |
|
209 |
||
210 |
iResult = err1; |
|
211 |
if(err1 == KErrNone) |
|
212 |
{ |
|
213 |
pos = 0 ; |
|
214 |
outparam->FindFirst( pos, KErrorCode ); |
|
215 |
if(pos != KErrNotFound) |
|
216 |
{ |
|
217 |
iResult = (TInt)((*outparam)[pos].Value().AsTInt32()); |
|
218 |
} |
|
219 |
if(iResult != SErrNone) |
|
220 |
{ |
|
221 |
iLog->Log(_L("after KGetNotification Error: %d"),iResult); |
|
222 |
iResult = 0; |
|
223 |
iWaitSchedular->AsyncStop(); |
|
224 |
} |
|
225 |
else |
|
226 |
{ |
|
227 |
iLog->Log(_L("after KGetNotification :")); |
|
228 |
iResult = -1; |
|
229 |
} |
|
230 |
}//err1 |
|
231 |
outparam->Reset(); |
|
232 |
inparam->Reset(); |
|
233 |
||
234 |
}//interface |
|
235 |
else |
|
236 |
{ |
|
237 |
iLog->Log( _L("API returned error") ); |
|
238 |
iResult = err; |
|
239 |
iWaitSchedular->AsyncStop(); |
|
240 |
} |
|
241 |
||
242 |
return ; |
|
243 |
} |
|
244 |
||
245 |
TInt CUserInactivity::HandleNotifyL(TInt /*aCmdId*/, |
|
246 |
TInt aEventId, |
|
247 |
CLiwGenericParamList& aEventParamList, |
|
248 |
const CLiwGenericParamList& /*aInParamList*/) |
|
249 |
{ |
|
250 |
iLog->Log(_L("In HandleNotifyL Event ID: %d"),aEventId); |
|
251 |
if(aEventId == KLiwEventCanceled) |
|
252 |
{ |
|
253 |
iLog->Log(_L("EventID: KLiwEventCanceled")); |
|
254 |
iResult =KErrNone; |
|
255 |
} |
|
256 |
else |
|
257 |
{ |
|
258 |
iResult =-1; |
|
259 |
} |
|
260 |
||
261 |
iWaitSchedular->AsyncStop(); |
|
262 |
return KErrNone; |
|
263 |
} |
|
264 |
||
265 |
void CUserInactivity::HandleTimeOut() |
|
266 |
{ |
|
267 |
iLog->Log(_L("In HandleTimeOut")); |
|
268 |
iWaitSchedular->AsyncStop(); |
|
269 |
} |
|
270 |
||
271 |
||
272 |
int UserInactivity(CStifLogger* aLog) |
|
273 |
{ |
|
274 |
__UHEAP_MARK; |
|
275 |
||
276 |
CUserInactivity* test = CUserInactivity::NewL(aLog); |
|
277 |
||
278 |
test->Start(); |
|
279 |
TInt retval = test->Result(); |
|
280 |
delete test; |
|
281 |
__UHEAP_MARKEND; |
|
282 |
||
283 |
return retval; |
|
284 |
} |
|
285 |