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 |
*/ |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
17 |
#include <liwcommon.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
18 |
#include<liwservicehandler.h> |
19 | 19 |
|
20 |
#include"tsysinfoprovidertests.h" |
|
21 |
#include "sysinfointerface.h" |
|
22 |
#include"entitykeys.h" |
|
23 |
#include "sysinfoaiwparams.hrh" |
|
24 |
#include "serviceerrno.h" |
|
25 |
#include"watchtimer.h" |
|
26 |
||
27 |
using namespace LIW ; |
|
28 |
using namespace SysInfo; |
|
29 |
using namespace sysinfoaiwparams; |
|
30 |
||
31 |
||
32 |
class CTestAsync2 : public CActive ,public MLiwNotifyCallback, public MTimeOutCallBack |
|
33 |
{ |
|
34 |
public: |
|
35 |
static CTestAsync2* NewL(CStifLogger* aLog); |
|
36 |
~CTestAsync2(); |
|
37 |
void Start(); |
|
38 |
TInt Result(); |
|
39 |
||
40 |
TInt HandleNotifyL(TInt aCmdId, |
|
41 |
TInt aEventId, |
|
42 |
CLiwGenericParamList& aEventParamList, |
|
43 |
const CLiwGenericParamList& aInParamList); |
|
44 |
||
45 |
IMPORT_C static TInt32 GetTransactionID(); |
|
46 |
void HandleTimeOut (); |
|
47 |
private: |
|
48 |
void ConstructL(); |
|
49 |
CTestAsync2(CStifLogger* aLog); |
|
50 |
||
51 |
virtual void DoCancel(); |
|
52 |
virtual void RunL(); |
|
53 |
||
54 |
void TestFunc(); |
|
55 |
||
56 |
private: |
|
57 |
CActiveSchedulerWait* iWaitSchedular; |
|
58 |
CLiwServiceHandler* iServiceHandler; |
|
59 |
MLiwInterface* interface ; |
|
60 |
TInt32 btstatus ; |
|
61 |
TInt iResult; |
|
62 |
CStifLogger* iLog; |
|
63 |
CWatchTimer* iTimer; |
|
64 |
}; |
|
65 |
||
66 |
CTestAsync2* CTestAsync2::NewL(CStifLogger* aLog) |
|
67 |
{ |
|
68 |
CTestAsync2* self = new(ELeave) CTestAsync2(aLog); |
|
69 |
self->ConstructL(); |
|
70 |
return self; |
|
71 |
} |
|
72 |
||
73 |
CTestAsync2::~CTestAsync2() |
|
74 |
{ |
|
75 |
Cancel(); |
|
76 |
||
77 |
interface->Close(); |
|
78 |
||
79 |
delete iServiceHandler; |
|
80 |
||
81 |
if(iWaitSchedular->IsStarted()) |
|
82 |
iWaitSchedular->AsyncStop(); |
|
83 |
||
84 |
if(iWaitSchedular) |
|
85 |
delete iWaitSchedular; |
|
86 |
||
87 |
delete iTimer; |
|
88 |
||
89 |
} |
|
90 |
||
91 |
void CTestAsync2::ConstructL() |
|
92 |
{ |
|
93 |
CActiveScheduler::Add(this); |
|
94 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
95 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
96 |
} |
|
97 |
||
98 |
CTestAsync2::CTestAsync2(CStifLogger* aLog) : |
|
99 |
CActive(EPriorityStandard),iResult(-1),iLog(aLog) |
|
100 |
{ |
|
101 |
} |
|
102 |
||
103 |
void CTestAsync2::DoCancel() |
|
104 |
{ |
|
105 |
||
106 |
//TRAPD(err1,iSysInfoService->GetInfoL(req1)); |
|
107 |
||
108 |
} |
|
109 |
||
110 |
void CTestAsync2::RunL() |
|
111 |
{ |
|
112 |
TestFunc(); |
|
113 |
} |
|
114 |
||
115 |
void CTestAsync2::Start() |
|
116 |
{ |
|
117 |
||
118 |
SetActive(); |
|
119 |
TRequestStatus* temp = &iStatus; |
|
120 |
User::RequestComplete(temp, KErrNone); |
|
121 |
iWaitSchedular->Start(); |
|
122 |
} |
|
123 |
||
124 |
TInt CTestAsync2::Result() |
|
125 |
{ |
|
126 |
return iResult; |
|
127 |
} |
|
128 |
||
129 |
void CTestAsync2::TestFunc() |
|
130 |
{ |
|
131 |
const TTimeIntervalMicroSeconds32 OneMinute(60000); |
|
132 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
133 |
CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
134 |
CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
135 |
||
136 |
TInt err = KErrNone; |
|
137 |
||
138 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KIDataSource,KService); |
|
139 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
140 |
||
141 |
RCriteriaArray a; |
|
142 |
a.AppendL(crit); |
|
143 |
||
144 |
iServiceHandler->AttachL(a); |
|
145 |
||
146 |
iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
147 |
||
148 |
delete crit; |
|
149 |
a.Reset(); |
|
150 |
||
151 |
TInt pos = 0; |
|
152 |
||
153 |
outparam->FindFirst( pos, KIDataSource ); |
|
154 |
if(pos != KErrNotFound) |
|
155 |
{ |
|
156 |
//getting the interface handle |
|
157 |
interface = (*outparam)[pos].Value().AsInterface(); |
|
158 |
} |
|
159 |
||
160 |
outparam->Reset(); |
|
161 |
inparam->Reset(); |
|
162 |
||
163 |
if(interface) |
|
164 |
{ |
|
165 |
TLiwGenericParam entity; |
|
166 |
TLiwVariant entityname; |
|
167 |
TLiwGenericParam key; |
|
168 |
TLiwVariant keyname; |
|
169 |
||
170 |
entityname.Set(KConnectivity); |
|
171 |
entity.SetNameAndValueL(KEntity,entityname); |
|
172 |
||
173 |
keyname.Set(KActiveConnections); |
|
174 |
key.SetNameAndValueL(KKey,keyname); |
|
175 |
||
176 |
inparam->AppendL(entity); |
|
177 |
||
178 |
inparam->AppendL(key); |
|
179 |
||
180 |
entity.Reset(); |
|
181 |
entityname.Reset(); |
|
182 |
key.Reset(); |
|
183 |
keyname.Reset(); |
|
184 |
||
185 |
//get notification vibra Active |
|
186 |
TRAPD(err1, interface->ExecuteCmdL(KGetInfo,*inparam,*outparam,NULL,NULL)); |
|
187 |
iTimer->After(OneMinute); |
|
188 |
||
189 |
iResult = err1; |
|
190 |
if(err1 == KErrNone) |
|
191 |
{ |
|
192 |
pos = 0 ; |
|
193 |
outparam->FindFirst( pos, KErrorCode ); |
|
194 |
if(pos != KErrNotFound) |
|
195 |
{ |
|
196 |
iResult = (TInt)((*outparam)[pos].Value().AsTInt32()); |
|
197 |
} |
|
198 |
if(iResult == SErrNotFound) |
|
199 |
{ |
|
200 |
iLog->Log(_L("after KCancel SErrBadArgumentType:")); |
|
201 |
iResult = 0; |
|
202 |
} |
|
203 |
else |
|
204 |
{ |
|
205 |
iResult = -1; |
|
206 |
} |
|
207 |
}//err1 |
|
208 |
outparam->Reset(); |
|
209 |
inparam->Reset(); |
|
210 |
||
211 |
}//interface |
|
212 |
else |
|
213 |
{ |
|
214 |
iLog->Log( _L("API returned error") ); |
|
215 |
iResult = err; |
|
216 |
iWaitSchedular->AsyncStop(); |
|
217 |
} |
|
218 |
||
219 |
return ; |
|
220 |
} |
|
221 |
||
222 |
TInt CTestAsync2::HandleNotifyL(TInt /*aCmdId*/, |
|
223 |
TInt /*aEventId*/, |
|
224 |
CLiwGenericParamList& aEventParamList, |
|
225 |
const CLiwGenericParamList& /*aInParamList*/) |
|
226 |
{ |
|
227 |
||
228 |
TInt pos = 0; |
|
229 |
aEventParamList.FindFirst( pos, KErrorCode ); |
|
230 |
if(pos != KErrNotFound) |
|
231 |
{ |
|
232 |
if( (aEventParamList)[pos].Value().AsTInt32() != KErrNone ) |
|
233 |
iResult = (TInt)((aEventParamList)[pos].Value().AsTInt32()); |
|
234 |
} |
|
235 |
||
236 |
pos = 0 ; |
|
237 |
const TLiwGenericParam* output2 = aEventParamList.FindFirst( pos,KReturnValue ); |
|
238 |
if(output2) |
|
239 |
{ |
|
240 |
const CLiwMap* Map = output2->Value().AsMap(); |
|
241 |
if ( Map ) |
|
242 |
{ |
|
243 |
||
244 |
TLiwVariant data; |
|
245 |
||
246 |
Map->FindL(KConnectionList,data); |
|
247 |
CLiwIterable* iterlist=data.AsIterable(); |
|
248 |
||
249 |
if(iterlist) |
|
250 |
{ |
|
251 |
TLiwVariant iterdata; |
|
252 |
if(iterlist->NextL(iterdata)) |
|
253 |
{ |
|
254 |
const CLiwMap* Map = iterdata.AsMap(); |
|
255 |
if ( Map ) |
|
256 |
{ |
|
257 |
TLiwVariant iapidVar; |
|
258 |
Map->FindL(KIAPID,iapidVar); |
|
259 |
TUint iapid = iapidVar.AsTUint(); |
|
260 |
TBuf<50> buf; |
|
261 |
buf.AppendNum(iapid); |
|
262 |
iLog->Log(_L("IAPID")); |
|
263 |
iLog->Log(buf); |
|
264 |
iapidVar.Reset(); |
|
265 |
||
266 |
||
267 |
TLiwVariant bearerTypeVar; |
|
268 |
Map->FindL(KConnectionType,bearerTypeVar); |
|
269 |
TInt32 bearerType = bearerTypeVar.AsTInt32(); |
|
270 |
buf.Zero(); |
|
271 |
buf.AppendNum(bearerType); |
|
272 |
iLog->Log(_L("Bearer Type:")); |
|
273 |
iLog->Log(buf); |
|
274 |
bearerTypeVar.Reset(); |
|
275 |
||
276 |
TLiwVariant iapNameVar; |
|
277 |
Map->FindL(KIAPName,iapNameVar); |
|
278 |
TPtrC iapName = iapNameVar.AsDes(); |
|
279 |
buf.Zero(); |
|
280 |
buf.Copy(iapName); |
|
281 |
iLog->Log(_L("IAP Name:")); |
|
282 |
iLog->Log(buf); |
|
283 |
iapNameVar.Reset(); |
|
284 |
||
285 |
TLiwVariant netNameVar; |
|
286 |
Map->FindL(KNetworkName,netNameVar); |
|
287 |
TPtrC netName = netNameVar.AsDes(); |
|
288 |
buf.Zero(); |
|
289 |
buf.Copy(netName); |
|
290 |
iLog->Log(_L("network Name:")); |
|
291 |
iLog->Log(buf); |
|
292 |
netNameVar.Reset(); |
|
293 |
||
294 |
TLiwVariant connNameVar; |
|
295 |
Map->FindL(KIAPConnectionName,connNameVar); |
|
296 |
TPtrC connName = connNameVar.AsDes(); |
|
297 |
buf.Zero(); |
|
298 |
buf.Copy(connName); |
|
299 |
iLog->Log(_L("Connection Name:")); |
|
300 |
iLog->Log(buf); |
|
301 |
connNameVar.Reset(); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
}//map |
|
306 |
}//output |
|
307 |
iWaitSchedular->AsyncStop(); |
|
308 |
return KErrNone; |
|
309 |
} |
|
310 |
void CTestAsync2::HandleTimeOut() |
|
311 |
{ |
|
312 |
iWaitSchedular->AsyncStop(); |
|
313 |
} |
|
314 |
||
315 |
||
316 |
int ActiveConnection(CStifLogger* aLog) |
|
317 |
{ |
|
318 |
__UHEAP_MARK; |
|
319 |
||
320 |
CTestAsync2* test = CTestAsync2::NewL(aLog); |
|
321 |
||
322 |
test->Start(); |
|
323 |
TInt retval = test->Result(); |
|
324 |
delete test; |
|
325 |
__UHEAP_MARKEND; |
|
326 |
||
327 |
return retval; |
|
328 |
} |
|
329 |