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