author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 22 | fc9cf246af83 |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2006-2007 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: contains test case implementation for CancelOngoingService location-SAPI |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
15 |
* V ersion : %version: 6 % << Don't touch! Updated by Synergy at check-out. |
19 | 16 |
* |
17 |
*/ |
|
18 |
||
19 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
20 |
#include "tloctest.h" |
19 | 21 |
#include "locationservice.h" |
22 |
#include <f32file.h> |
|
23 |
#include <e32const.h> |
|
24 |
class CGetLoc ; //Forward declaration |
|
25 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
26 |
#define GETLOCATION 0 |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
27 |
#define TRACE 1 |
19 | 28 |
|
29 |
_LIT(LogFileName , "C:\\Notificationscan.txt") ; |
|
30 |
_LIT(KRequestor,"testapp"); |
|
31 |
||
32 |
// INCLUDE FILES |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
33 |
#include "tloctest.h" |
19 | 34 |
|
35 |
#include <e32svr.h> |
|
36 |
#include <StifParser.h> |
|
37 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
38 |
#include <StifTestInterface.h> |
19 | 39 |
|
40 |
//#include <S60LocCoreImpl.h> |
|
41 |
#include <AiwCommon.h> |
|
42 |
||
43 |
||
44 |
||
45 |
enum ServiceType |
|
46 |
{ |
|
47 |
Trace = 0, |
|
48 |
GetLocation = 1 |
|
49 |
}; |
|
50 |
class CancelLocUpdateCallBack : public MLocationCallBack |
|
51 |
{ |
|
52 |
TInt iCount ; |
|
53 |
TInt iRetStatus ; |
|
54 |
TInt iServiceId; |
|
55 |
CLocationService* iServicePtr; |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
56 |
TInt iTransactionId; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
57 |
TInt iRequestType; |
19 | 58 |
public : |
59 |
TInt HandleNotifyL(HPositionGenericInfo *aInfo , TInt aError) ; |
|
60 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
61 |
CancelLocUpdateCallBack(TInt trans,TInt req,CLocationService *CoreObj) :iCount(0) , iRetStatus(KErrGeneral),iServicePtr(CoreObj) //Default constructor |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
62 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
63 |
iTransactionId = trans; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
64 |
iRequestType = req; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
65 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
66 |
inline TUint GetRequestType(void) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
67 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
68 |
return iRequestType ; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
69 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
70 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
71 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
72 |
/** |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
73 |
* GetTransactionId function returns transcation id associated with current async object |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
74 |
* |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
75 |
*/ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
76 |
inline TInt32 GetTransactionId(void) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
77 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
78 |
return iTransactionId ; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
79 |
} |
19 | 80 |
}; |
81 |
||
82 |
||
83 |
TInt CancelLocUpdateCallBack :: HandleNotifyL(HPositionGenericInfo *aInfo , TInt aError) |
|
84 |
{ |
|
85 |
||
86 |
if(iCount > 2) |
|
87 |
{ |
|
88 |
iRetStatus = KErrNone ; |
|
89 |
iServicePtr->CancelOnGoingService(ECancelTrace); |
|
90 |
||
91 |
CActiveScheduler *Current = CActiveScheduler :: Current() ; |
|
92 |
Current->Stop() ; |
|
93 |
return KErrNone ; |
|
94 |
} |
|
95 |
||
96 |
RFile LogFile ; |
|
97 |
RFs LogSession ; |
|
98 |
TBuf8<50> Buffer(_L8("Latitude = ")) ; |
|
99 |
||
100 |
||
101 |
||
102 |
||
103 |
||
104 |
LogSession.Connect() ; |
|
105 |
||
106 |
if(LogFile.Open(LogSession ,LogFileName , EFileWrite | EFileShareAny ) == KErrNotFound) |
|
107 |
{ |
|
108 |
LogFile.Create(LogSession ,LogFileName , EFileWrite | EFileShareAny ) ; |
|
109 |
||
110 |
} |
|
111 |
||
112 |
TInt End = 0 ; |
|
113 |
||
114 |
LogFile.Seek(ESeekEnd , End) ; //Seek to end of the file before writing |
|
115 |
||
116 |
TBuf8<50> num ; |
|
117 |
TRealFormat format ; |
|
118 |
||
119 |
TPosition aOutPos ; |
|
120 |
||
121 |
aInfo->GetPosition(aOutPos) ; |
|
122 |
TReal64 Val = aOutPos.Latitude() ; |
|
123 |
num.Num(Val , format) ; |
|
124 |
||
125 |
//Logging Latitude |
|
126 |
LogFile.Write(_L8("Latitude = ")); |
|
127 |
LogFile.Write(num) ; |
|
128 |
LogFile.Write(_L8("\n")) ; |
|
129 |
||
130 |
Val = aOutPos.Longitude() ; |
|
131 |
num.Num(Val , format) ; |
|
132 |
||
133 |
//Logging Longitude |
|
134 |
||
135 |
LogFile.Write(_L8("Longitude = ")); |
|
136 |
LogFile.Write(num) ; |
|
137 |
LogFile.Write(_L8("\n")) ; |
|
138 |
||
139 |
//Logging Altitude |
|
140 |
Val = aOutPos.Altitude() ; |
|
141 |
num.Num(Val , format) ; |
|
142 |
LogFile.Write(_L8("Altitude = ")); |
|
143 |
LogFile.Write(num) ; |
|
144 |
LogFile.Write(_L8("\n")) ; |
|
145 |
LogFile.Close() ; |
|
146 |
LogSession.Close() ; |
|
147 |
iCount++ ; |
|
148 |
return KErrNone ; |
|
149 |
} |
|
150 |
||
151 |
/*Cancel Trace when a request is pending*/ |
|
152 |
||
153 |
TInt CancelLocFunctionAL() |
|
154 |
{ |
|
155 |
||
156 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
157 |
__UHEAP_MARK ; |
19 | 158 |
|
159 |
CActiveScheduler *Scheduler = new CActiveScheduler ; |
|
160 |
||
161 |
CActiveScheduler :: Install(Scheduler) ; |
|
162 |
CLocationService *CoreObj = CLocationService ::NewL() ; |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
163 |
CancelLocUpdateCallBack MyUpdates(10,TRACE,CoreObj) ; |
19 | 164 |
|
165 |
||
166 |
CoreObj->TraceL((&MyUpdates),EBasicInfo) ; |
|
167 |
CoreObj->CancelOnGoingService(ECancelTrace); |
|
168 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
169 |
delete CoreObj; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
170 |
delete Scheduler; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
171 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
172 |
__UHEAP_MARKEND ; |
19 | 173 |
return 0 ; |
174 |
} |
|
175 |
TInt CancelLocUpdatesA(TAny */*Arg*/) |
|
176 |
{ |
|
177 |
CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
178 |
//Install a new active scheduler to this thread |
|
179 |
TRAPD(err , CancelLocFunctionAL()) ; |
|
180 |
delete cleanup ; |
|
181 |
return 0 ; |
|
182 |
} |
|
183 |
||
184 |
||
185 |
TInt CTLocTest :: CancelLocationUpdatesA(CStifItemParser& /*aItem*/) |
|
186 |
{ |
|
187 |
_LIT(KTLocTest ,"TLocTest"); |
|
188 |
iLog->Log(KTLocTest) ; |
|
189 |
||
190 |
TRequestStatus Status = KRequestPending ; |
|
191 |
RThread FunctionThread ; |
|
192 |
||
193 |
TInt ret = FunctionThread.Create(_L(" LocationUpdates Thread") , CancelLocUpdatesA ,KDefaultStackSize , |
|
194 |
KMinHeapSize , KDefaultStackSize ,(TAny *) NULL); |
|
195 |
||
196 |
if(!ret) |
|
197 |
{ |
|
198 |
FunctionThread.Logon(Status) ; |
|
199 |
FunctionThread.Resume() ; |
|
200 |
||
201 |
User :: WaitForRequest (Status) ; |
|
202 |
FunctionThread.Close(); |
|
203 |
||
204 |
ret = Status.Int() ; |
|
205 |
} |
|
206 |
return ret; |
|
207 |
} |
|
208 |
||
209 |
/*Cancel Update when request has been served*/ |
|
210 |
||
211 |
TInt CancelLocFunctionBL() |
|
212 |
{ |
|
213 |
||
214 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
215 |
__UHEAP_MARK ; |
19 | 216 |
|
217 |
CActiveScheduler *Scheduler = new CActiveScheduler ; |
|
218 |
||
219 |
CActiveScheduler :: Install(Scheduler) ; |
|
220 |
CLocationService *CoreObj = CLocationService ::NewL() ; |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
221 |
CancelLocUpdateCallBack MyUpdates(11,TRACE,CoreObj) ; |
19 | 222 |
|
223 |
||
224 |
CoreObj->TraceL((&MyUpdates),EBasicInfo) ; |
|
225 |
||
226 |
CActiveScheduler :: Start() ; |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
227 |
delete CoreObj; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
228 |
delete Scheduler; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
229 |
__UHEAP_MARKEND ; |
19 | 230 |
|
231 |
||
232 |
return 0 ; |
|
233 |
} |
|
234 |
TInt CancelLocUpdatesB(TAny */*Arg*/) |
|
235 |
{ |
|
236 |
CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
237 |
//Install a new active scheduler to this thread |
|
238 |
TRAPD(err , CancelLocFunctionBL()) ; |
|
239 |
delete cleanup ; |
|
240 |
return 0 ; |
|
241 |
} |
|
242 |
||
243 |
TInt CTLocTest :: CancelLocationUpdatesB(CStifItemParser& /*aItem*/) |
|
244 |
{ |
|
245 |
_LIT(KTLocTest ,"TLocTest"); |
|
246 |
iLog->Log(KTLocTest) ; |
|
247 |
||
248 |
TRequestStatus Status = KRequestPending ; |
|
249 |
RThread FunctionThread ; |
|
250 |
||
251 |
TInt ret = FunctionThread.Create(_L(" LocationUpdates Thread") , CancelLocUpdatesB ,KDefaultStackSize , |
|
252 |
KMinHeapSize , KDefaultStackSize ,(TAny *) NULL); |
|
253 |
||
254 |
if(!ret) |
|
255 |
{ |
|
256 |
FunctionThread.Logon(Status) ; |
|
257 |
FunctionThread.Resume() ; |
|
258 |
||
259 |
User :: WaitForRequest (Status) ; |
|
260 |
FunctionThread.Close(); |
|
261 |
||
262 |
ret = Status.Int() ; |
|
263 |
} |
|
264 |
return ret; |
|
265 |
} |
|
266 |
/*Location cancel test*/ |
|
267 |
||
268 |
TInt CancelLocAsynchFunctionL() |
|
269 |
{ |
|
270 |
||
271 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
272 |
__UHEAP_MARK ; |
19 | 273 |
|
274 |
CActiveScheduler *Scheduler = new CActiveScheduler ; |
|
275 |
||
276 |
CActiveScheduler :: Install(Scheduler) ; |
|
277 |
CLocationService *CoreObj = CLocationService ::NewL() ; |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
278 |
CancelLocUpdateCallBack MyUpdates(12,GETLOCATION,CoreObj) ; |
19 | 279 |
|
280 |
CoreObj->GetLocationL((&MyUpdates),EBasicInfo) ; |
|
281 |
CoreObj->CancelOnGoingService(ECancelGetLocation); |
|
282 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
283 |
delete CoreObj; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
284 |
delete Scheduler; |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
285 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
286 |
__UHEAP_MARKEND ; |
19 | 287 |
return 0 ; |
288 |
} |
|
289 |
TInt CancelLocAsynch(TAny */*Arg*/) |
|
290 |
{ |
|
291 |
CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
292 |
//Install a new active scheduler to this thread |
|
293 |
TRAPD(err , CancelLocAsynchFunctionL()) ; |
|
294 |
delete cleanup ; |
|
295 |
return 0 ; |
|
296 |
} |
|
297 |
||
298 |
||
299 |
TInt CTLocTest :: CancelLocationAsynch(CStifItemParser& /*aItem*/) |
|
300 |
{ |
|
301 |
_LIT(KTLocTest ,"TLocTest"); |
|
302 |
iLog->Log(KTLocTest) ; |
|
303 |
||
304 |
TRequestStatus Status = KRequestPending ; |
|
305 |
RThread FunctionThread ; |
|
306 |
||
307 |
TInt ret = FunctionThread.Create(_L(" LocationUpdates Thread") , CancelLocAsynch ,KDefaultStackSize , |
|
308 |
KMinHeapSize , KDefaultStackSize ,(TAny *) NULL); |
|
309 |
||
310 |
if(!ret) |
|
311 |
{ |
|
312 |
FunctionThread.Logon(Status) ; |
|
313 |
FunctionThread.Resume() ; |
|
314 |
||
315 |
User :: WaitForRequest (Status) ; |
|
316 |
FunctionThread.Close(); |
|
317 |
||
318 |
ret = Status.Int() ; |
|
319 |
} |
|
320 |
return ret; |
|
321 |
} |
|
322 |
||
323 |