|
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 |
|
18 /* |
|
19 * Stray signal test function |
|
20 */ |
|
21 #include <e32svr.h> |
|
22 #include <StifParser.h> |
|
23 #include <Stiftestinterface.h> |
|
24 #include <LbsRequestor.h> |
|
25 #include <liwServiceHandler.h> |
|
26 #include <LiwCommon.h> |
|
27 |
|
28 #include "tcomplugin.h" |
|
29 |
|
30 #define TRACE 0 |
|
31 #define GETLOCATION 1 |
|
32 |
|
33 class ASyncCB : public MLiwNotifyCallback |
|
34 { |
|
35 TInt iCount ; |
|
36 TInt iCmd ; |
|
37 MLiwInterface *iLocationInterface ; |
|
38 CLiwGenericParamList *iInputList ; |
|
39 |
|
40 public : |
|
41 TInt iRetStatus ; |
|
42 |
|
43 TInt HandleNotifyL( |
|
44 TInt aCmdId, |
|
45 TInt aEventId, |
|
46 CLiwGenericParamList& aEventParamList, |
|
47 const CLiwGenericParamList& aInParamList) ; |
|
48 |
|
49 ASyncCB() : iRetStatus(KErrGeneral) , iCount(0) ,iCmd(0)//Default constructor |
|
50 { |
|
51 ; |
|
52 } |
|
53 ASyncCB(TInt aCmd , MLiwInterface *aInterface , CLiwGenericParamList *aInputList) ; |
|
54 }; |
|
55 |
|
56 |
|
57 ASyncCB :: ASyncCB(TInt aCmd ,MLiwInterface *aInterface , CLiwGenericParamList *aInputList):iCount(0) |
|
58 { |
|
59 iCmd = aCmd ; |
|
60 iLocationInterface = aInterface ; |
|
61 iInputList = aInputList ; |
|
62 |
|
63 } |
|
64 |
|
65 |
|
66 TInt ASyncCB :: HandleNotifyL( |
|
67 TInt aCmdId, |
|
68 TInt aEventId, |
|
69 CLiwGenericParamList& aEventParamList, |
|
70 const CLiwGenericParamList& aInParamList) |
|
71 { |
|
72 |
|
73 //DeRefrence Allocated Map first |
|
74 TInt index = 0 ; |
|
75 |
|
76 _LIT(KTraceFile , "C:\\Trace.txt") ; |
|
77 |
|
78 RFile TraceFile ; |
|
79 RFs TraceSession ; |
|
80 |
|
81 TraceSession.Connect() ; |
|
82 |
|
83 if(TraceFile.Open(TraceSession ,KTraceFile , EFileWrite | EFileShareAny ) == KErrNotFound) |
|
84 { |
|
85 if(TraceFile.Create(TraceSession ,KTraceFile , EFileWrite | EFileShareAny ) != KErrNone) |
|
86 { |
|
87 return KErrGeneral ; |
|
88 } |
|
89 |
|
90 } |
|
91 |
|
92 TInt pos = 0 ; |
|
93 TraceFile.Seek(ESeekEnd , pos) ; |
|
94 |
|
95 // const TLiwGenericParam *Notifyparm = aEventParamList.FindFirst(index ,KLocationMap) ; |
|
96 /* |
|
97 if(Notifyparm) |
|
98 { |
|
99 TLiwVariant mapVar = Notifyparm->Value() ; |
|
100 const CLiwMap *map = mapVar.AsMap() ; |
|
101 //map->DecRef() ; |
|
102 } |
|
103 |
|
104 */ iCount++ ; |
|
105 |
|
106 |
|
107 |
|
108 if(iCount > 2) |
|
109 { |
|
110 CActiveScheduler *current = CActiveScheduler :: Current() ; |
|
111 TraceFile.Write(_L8("Active Scheduler stopped\n")) ; |
|
112 current->Stop() ; |
|
113 return KErrNone ; |
|
114 } |
|
115 |
|
116 if(iCmd == TRACE) |
|
117 { |
|
118 TBuf8<20>CmdBuf(KCmdCancelRequest) ; |
|
119 TLiwVariant CancelType(KCmdTraceLocation) ; |
|
120 |
|
121 TLiwGenericParam CancelParm(KCancelType , TLiwVariant (KRequestTrace)) ; |
|
122 iInputList->AppendL(CancelParm) ; |
|
123 CLiwGenericParamList *outlist1 = CLiwGenericParamList :: NewL() ; |
|
124 |
|
125 TraceFile.Write(_L8("Trace Command Cancelled Submitted \n")) ; |
|
126 |
|
127 iLocationInterface->ExecuteCmdL(CmdBuf , *iInputList , *outlist1 ) ; |
|
128 TraceFile.Write(_L8("Trace Command Cancelled Executed \n")) ; |
|
129 iInputList->Reset() ; |
|
130 TraceFile.Write(_L8("Input list reset \n")) ; |
|
131 delete outlist1 ; |
|
132 TraceFile.Write(_L8("outlist deleted \n")) ; |
|
133 return 0; |
|
134 } |
|
135 |
|
136 else if(iCmd == GETLOCATION) |
|
137 { |
|
138 |
|
139 TraceFile.Write(_L8("GetLoc Notification \n")) ; |
|
140 TraceFile.Flush() ; |
|
141 |
|
142 TBuf8<20>CmdBuf(KCmdGetLocation) ; |
|
143 CLiwGenericParamList *outlist2 = CLiwGenericParamList :: NewL() ; |
|
144 |
|
145 |
|
146 iInputList->Reset() ; |
|
147 |
|
148 TraceFile.Write(_L8("input for GetLoc List reset \n")) ; |
|
149 TraceFile.Flush() ; |
|
150 TraceFile.Write(_L8("GetLocation Cmd submitted \n")) ; |
|
151 TraceFile.Flush() ; |
|
152 |
|
153 iLocationInterface->ExecuteCmdL(CmdBuf , *iInputList , *outlist2 , 0 , this ); |
|
154 TraceFile.Write(_L8("GetLocation Command Executed \n")) ; |
|
155 outlist2->Reset() ; |
|
156 TraceFile.Write(_L8("Out List GetLocation reset \n")) ; |
|
157 delete outlist2 ; |
|
158 |
|
159 |
|
160 } |
|
161 |
|
162 |
|
163 iRetStatus = KErrNone ; |
|
164 return iRetStatus ; |
|
165 } |
|
166 |
|
167 |
|
168 TInt StrayTestL() |
|
169 { |
|
170 |
|
171 |
|
172 _LIT(KTraceFile , "C:\\Trace.txt") ; |
|
173 |
|
174 RFile TraceFile ; |
|
175 RFs TraceSession ; |
|
176 |
|
177 TraceSession.Connect() ; |
|
178 |
|
179 if(TraceFile.Open(TraceSession ,KTraceFile , EFileWrite | EFileShareAny ) == KErrNotFound) |
|
180 { |
|
181 if(TraceFile.Create(TraceSession ,KTraceFile , EFileWrite | EFileShareAny ) != KErrNone) |
|
182 { |
|
183 return KErrGeneral ; |
|
184 } |
|
185 |
|
186 } |
|
187 |
|
188 CActiveScheduler *Scheduler = new CActiveScheduler ; |
|
189 |
|
190 CActiveScheduler :: Install(Scheduler) ; |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL(); |
|
196 |
|
197 // Input and output parameter list |
|
198 CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL()); |
|
199 CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL()); |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KContents, KService); |
|
205 |
|
206 |
|
207 crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
208 |
|
209 RCriteriaArray a; |
|
210 a.AppendL(crit); |
|
211 |
|
212 ServiceHandler->AttachL(a) ; |
|
213 ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist); |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 TInt pos = 0; |
|
219 |
|
220 const TLiwGenericParam *errorprm = outputlist->FindFirst(pos , KErrorCode) ; |
|
221 |
|
222 if(!errorprm) |
|
223 { |
|
224 return KErrGeneral ; |
|
225 } |
|
226 |
|
227 pos = 0 ; |
|
228 const TLiwGenericParam *genericparm = outputlist->FindFirst(pos, KLsInterfaceName ); |
|
229 |
|
230 if(!genericparm) |
|
231 { |
|
232 |
|
233 return KErrGeneral ; |
|
234 } |
|
235 |
|
236 MLiwInterface* locinterface = (genericparm->Value()).AsInterface(); |
|
237 |
|
238 |
|
239 |
|
240 TBuf8<20>CmdBuf(KCmdTraceLocation) ; |
|
241 |
|
242 CLiwGenericParamList *InputList = CLiwGenericParamList :: NewL() ; |
|
243 CLiwGenericParamList *OutParmList = CLiwGenericParamList :: NewL() ; |
|
244 |
|
245 |
|
246 ASyncCB Updates(TRACE , locinterface , InputList) ; |
|
247 ASyncCB GetLoc(GETLOCATION , locinterface , InputList) ; |
|
248 |
|
249 locinterface->ExecuteCmdL(CmdBuf , *InputList , *OutParmList ,KLiwOptASyncronous , &Updates); |
|
250 |
|
251 CmdBuf = KCmdGetLocation ; |
|
252 locinterface->ExecuteCmdL(CmdBuf , *InputList , *OutParmList ,KLiwOptASyncronous , &GetLoc); |
|
253 |
|
254 CActiveScheduler :: Start() ; |
|
255 |
|
256 TInt skpos = 0 ; |
|
257 |
|
258 TraceFile.Seek(ESeekEnd , skpos) ; |
|
259 |
|
260 TraceFile.Write(_L8("Trace stray signal executed \n")) ; |
|
261 |
|
262 |
|
263 a.ResetAndDestroy() ; |
|
264 locinterface->Close() ; |
|
265 |
|
266 TraceFile.Write(_L8("Interface closed \n")) ; |
|
267 |
|
268 delete ServiceHandler ; |
|
269 |
|
270 TraceFile.Write(_L8("ServiceHandler deleted\n")) ; |
|
271 delete InputList ; |
|
272 delete OutParmList ; |
|
273 delete Scheduler ; |
|
274 |
|
275 TraceFile.Write(_L8("Scheduler deleted\n")) ; |
|
276 return 0 ; // Controll never reaches here |
|
277 } |
|
278 |
|
279 |
|
280 TInt StrayTest(TAny */*Arg*/) |
|
281 { |
|
282 // __UHEAP_MARK ; |
|
283 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
284 TInt val = 0 ; |
|
285 //Install a new active scheduler to this thread |
|
286 TRAPD(err , (val =StrayTestL())) ; |
|
287 delete cleanup ; |
|
288 |
|
289 if(err) |
|
290 { |
|
291 return err ; |
|
292 } |
|
293 |
|
294 return val ; |
|
295 return 0 ; |
|
296 } |
|
297 |
|
298 |