|
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: Implements callback methods which is called my core dll call |
|
15 * callback methods. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <liwserviceifbase.h> |
|
20 #include <LiwCommon.h> |
|
21 #include "locationinterface.h" |
|
22 #include "locationservice.h" |
|
23 #include "locationcb.h" |
|
24 |
|
25 using namespace LIW; |
|
26 |
|
27 /** |
|
28 * Default constructor |
|
29 */ |
|
30 |
|
31 LocationInterfaceCB ::LocationInterfaceCB() |
|
32 { |
|
33 iCallBack = NULL ; |
|
34 iOutParmList = NULL ; |
|
35 iInParmList = NULL ; |
|
36 iTransactionId = 0 ; |
|
37 } |
|
38 |
|
39 /** |
|
40 * OverLoaded constructor which accepts the callback adderss |
|
41 * and registers it |
|
42 */ |
|
43 |
|
44 LocationInterfaceCB :: LocationInterfaceCB( MLiwNotifyCallback* aCallBack , |
|
45 const CLiwGenericParamList* aInParmList , |
|
46 TPositionModuleInfo* aPositionModuleInfo , |
|
47 TInt32 aTransactionId ) : iCallBack(aCallBack), |
|
48 iTransactionId(aTransactionId) |
|
49 { |
|
50 iModuleInfo = aPositionModuleInfo ; |
|
51 |
|
52 //Store the outparam and in param list |
|
53 |
|
54 iOutParmList = CLiwGenericParamList :: NewL(); //(*aOutParmList) ; |
|
55 |
|
56 |
|
57 //Currently we dont use inputparam list, but when need it has to be |
|
58 //initalised as done above for iOutParamList |
|
59 iInParmList = iOutParmList ; |
|
60 //Extract the location info category from inputparamlist |
|
61 TInt index = 0; |
|
62 const TLiwGenericParam *smapparam = aInParmList->FindFirst(index , KLocationInfoCategory) ; |
|
63 TPtrC argposInfoCategory(KLocationBasicinfo) ; |
|
64 |
|
65 if(index != KErrNotFound) |
|
66 { |
|
67 |
|
68 //posInfoCategory = (smapparam->Value()).AsDes() ; |
|
69 argposInfoCategory.Set( (smapparam->Value()).AsDes() ); |
|
70 } |
|
71 |
|
72 |
|
73 iLocinfoCategory = EBasicInfo; |
|
74 if ( argposInfoCategory == KLocationGenericInfo ) |
|
75 { |
|
76 iLocinfoCategory = EGenericInfo; |
|
77 } |
|
78 } |
|
79 |
|
80 /** |
|
81 * overloaded NewL function for creating local call back objects |
|
82 * as required by locationinterface.cpp |
|
83 */ |
|
84 |
|
85 LocationInterfaceCB *LocationInterfaceCB :: NewL(MLiwNotifyCallback* aCallBack , |
|
86 const CLiwGenericParamList* aInParmList , |
|
87 TPositionModuleInfo* aPositionModuleInfo, |
|
88 TInt32 aTransactionid ) |
|
89 { |
|
90 LocationInterfaceCB *self = new(ELeave) LocationInterfaceCB(aCallBack , aInParmList , |
|
91 aPositionModuleInfo, aTransactionid) ; |
|
92 |
|
93 return self ; |
|
94 } |
|
95 |
|
96 /** |
|
97 * implementation of HandleNotifyL function derived from LocationInterfaceCB |
|
98 */ |
|
99 |
|
100 TInt LocationInterfaceCB :: HandleNotifyL(HPositionGenericInfo* aGenericInfo , TInt aError) |
|
101 { |
|
102 |
|
103 iOutParmList->Reset() ; |
|
104 TInt err = CLocationInterface :: ConvertToSapiError(aError) ; |
|
105 |
|
106 TLiwGenericParam errorParm(KErrorCode , TLiwVariant((TInt32)err)) ; |
|
107 iOutParmList->AppendL(errorParm) ; |
|
108 |
|
109 if(aError) //if Error then return the error code to user |
|
110 { |
|
111 |
|
112 iCallBack->HandleNotifyL(iTransactionId , KLiwEventError , *iOutParmList , *iInParmList) ; |
|
113 iOutParmList = NULL ; |
|
114 //delete this ; |
|
115 return KErrGeneral ; |
|
116 } |
|
117 |
|
118 |
|
119 TRAPD(error , HandleL(aGenericInfo , aError)) |
|
120 |
|
121 if(error != KErrNone) |
|
122 { |
|
123 iCallBack->HandleNotifyL(iTransactionId , KLiwEventError , *iOutParmList , *iInParmList) ; |
|
124 iOutParmList = NULL ; |
|
125 //delete this ; |
|
126 return KErrGeneral ; |
|
127 } |
|
128 |
|
129 |
|
130 |
|
131 //For GetLocation notify user with EventCompleted Notification and for trace |
|
132 //Notify user with Event in progress notification |
|
133 if(iRequestType == KGetLocationCB) |
|
134 { |
|
135 iCallBack->HandleNotifyL(iTransactionId , KLiwEventCompleted , *iOutParmList , *iInParmList ) ; |
|
136 } |
|
137 else |
|
138 { |
|
139 iCallBack->HandleNotifyL(iTransactionId , KLiwEventInProgress , *iOutParmList , *iInParmList ) ; |
|
140 } |
|
141 |
|
142 |
|
143 |
|
144 return KErrNone ; |
|
145 } |
|
146 |
|
147 /** |
|
148 * LocationInterfaceCB :: HandleL(): An internal utility function that encapsulates |
|
149 * all the leaving methods. This function is called by HandleNotifyL method |
|
150 */ |
|
151 |
|
152 void LocationInterfaceCB :: HandleL(HPositionGenericInfo* aGenericInfo , TInt /*aError*/) |
|
153 { |
|
154 CLiwDefaultMap *result = CLiwDefaultMap::NewL() ; |
|
155 CleanupStack :: PushL(result) ; |
|
156 //Now insert the collected position informaiton(latitude, longitude , and altitude into a default map |
|
157 TPosition pos ; |
|
158 |
|
159 aGenericInfo->GetPosition(pos) ; |
|
160 |
|
161 TReal32 Val = pos.Longitude() ; |
|
162 |
|
163 result->InsertL(KLongitudeKey , TLiwVariant((TReal)Val)) ; //Inserting longitude |
|
164 |
|
165 |
|
166 Val = pos.Latitude() ; |
|
167 result->InsertL(KLatitudeKey , TLiwVariant((TReal)Val)) ; //Inserting latitude into map |
|
168 |
|
169 Val = pos.Altitude() ; |
|
170 |
|
171 result->InsertL(KAltitudeKey , TLiwVariant((TReal)Val)) ; //Inserting altitude into map |
|
172 //TLiwVariant resVar(result) ; |
|
173 |
|
174 |
|
175 TPositionModuleInfo :: TCapabilities currCapability = iModuleInfo->Capabilities() ; |
|
176 |
|
177 if ( iLocinfoCategory == EGenericInfo ) |
|
178 { |
|
179 if(currCapability & TPositionModuleInfo :: ECapabilitySpeed) //Populate output param with speed info |
|
180 { |
|
181 TReal32 speedinfo = 0 ; |
|
182 |
|
183 if(!aGenericInfo->GetValue(EPositionFieldHorizontalSpeed , speedinfo) ) //Extract speed |
|
184 { |
|
185 result->InsertL(KPositionFieldHorizontalSpeed,TLiwVariant((TReal)speedinfo)); |
|
186 |
|
187 } |
|
188 |
|
189 if(!aGenericInfo->GetValue(EPositionFieldHorizontalSpeedError , speedinfo)) |
|
190 { |
|
191 result->InsertL(KPositionFieldHorizontalSpeedError,TLiwVariant((TReal)speedinfo)); |
|
192 } |
|
193 |
|
194 |
|
195 |
|
196 } //End of EcapabilitySpeed |
|
197 |
|
198 |
|
199 if(currCapability & TPositionModuleInfo :: ECapabilitySatellite) //Extract satellitinfo if any and append it |
|
200 { //as part of out parm list |
|
201 TInt8 satinfo = 0; |
|
202 |
|
203 if(!aGenericInfo->GetValue(EPositionFieldSatelliteNumInView , satinfo)) |
|
204 { |
|
205 result->InsertL(KPositionFieldSatelliteNumInView,TLiwVariant((TReal)satinfo)); |
|
206 } |
|
207 if(!aGenericInfo->GetValue(EPositionFieldSatelliteNumUsed , satinfo)) |
|
208 { |
|
209 result->InsertL(KPositionFieldSatelliteNumUsed ,TLiwVariant((TReal) satinfo)) ; |
|
210 } |
|
211 |
|
212 |
|
213 } |
|
214 |
|
215 if(currCapability & TPositionModuleInfo :: ECapabilityDirection) //Extract direction info if any and append it |
|
216 { // as part of out parm list |
|
217 TReal direcinfo = 0; |
|
218 |
|
219 if(!aGenericInfo->GetValue(EPositionFieldTrueCourse , direcinfo) ) |
|
220 { |
|
221 result->InsertL(KPositionFieldTrueCourse,TLiwVariant((TReal)direcinfo)); |
|
222 //iOutParmList->AppendL(TLiwGenericParam(KPositionFieldTrueCourse , TLiwVariant((TInt32)direcinfo))) ; |
|
223 } |
|
224 |
|
225 |
|
226 if(!aGenericInfo->GetValue(EPositionFieldTrueCourseError , direcinfo) ) |
|
227 { |
|
228 result->InsertL(KPositionFieldTrueCourseError,TLiwVariant((TReal)direcinfo)); |
|
229 //iOutParmList->AppendL(TLiwGenericParam(KPositionFieldTrueCourseError , TLiwVariant((TInt32)direcinfo))) ; |
|
230 } |
|
231 |
|
232 |
|
233 if(!aGenericInfo->GetValue(EPositionFieldMagneticCourseError , direcinfo) ) |
|
234 { |
|
235 result->InsertL(KPositionFieldTrueCourseError,TLiwVariant((TReal)direcinfo)); |
|
236 //iOutParmList->AppendL(TLiwGenericParam(KPositionFieldMagneticCourseError , TLiwVariant((TInt32)direcinfo))) ; |
|
237 } |
|
238 |
|
239 if(!aGenericInfo->GetValue(EPositionFieldMagneticCourse , direcinfo) ) |
|
240 { |
|
241 result->InsertL(KPositionFieldMagneticCourse,TLiwVariant((TReal)direcinfo)); |
|
242 |
|
243 } |
|
244 |
|
245 } |
|
246 |
|
247 |
|
248 if(currCapability & TPositionModuleInfo :: ECapabilityCompass) //Extract compass info if any and append it |
|
249 { // as part of out parm list |
|
250 TReal compassinfo ; |
|
251 |
|
252 if(!aGenericInfo->GetValue(EPositionFieldHeading , compassinfo) ) |
|
253 { |
|
254 result->InsertL(KPositionFieldHeading,TLiwVariant((TReal)compassinfo)); |
|
255 ; |
|
256 } |
|
257 |
|
258 |
|
259 if(!aGenericInfo->GetValue(EPositionFieldHeadingError , compassinfo) ) |
|
260 { |
|
261 result->InsertL(KPositionFieldHeadingError,TLiwVariant((TReal)compassinfo)); |
|
262 |
|
263 } |
|
264 |
|
265 if(!aGenericInfo->GetValue(EPositionFieldMagneticHeading , compassinfo) ) |
|
266 { |
|
267 result->InsertL(KPositionFieldMagneticHeading,TLiwVariant((TReal)compassinfo)); |
|
268 |
|
269 } |
|
270 |
|
271 |
|
272 |
|
273 if(!aGenericInfo->GetValue(EPositionFieldMagneticHeadingError , compassinfo) ) |
|
274 { |
|
275 result->InsertL(KPositionFieldMagneticHeadingError,TLiwVariant((TReal)compassinfo)); |
|
276 |
|
277 } |
|
278 |
|
279 |
|
280 |
|
281 } |
|
282 |
|
283 /*if( currCapability & TPositionModuleInfo :: ECapabilityNmea ) //Extract Nmea info if any and append it |
|
284 { //as part of out param list |
|
285 TUint8 numSentences ; |
|
286 |
|
287 if(!aGenericInfo->GetValue(EPositionFieldNMEASentences , numSentences) ) |
|
288 { |
|
289 result->InsertL(KPositionFieldNMEASentences,TLiwVariant((TReal)numSentences)); |
|
290 |
|
291 } |
|
292 |
|
293 |
|
294 TBuf8 <20> nmeaSentences ; |
|
295 |
|
296 if(!aGenericInfo->GetValue(EPositionFieldNMEASentencesStart , nmeaSentences) ) |
|
297 { |
|
298 result->InsertL(KPositionFieldNMEASentencesStart,TLiwVariant(nmeaSentences)); |
|
299 |
|
300 } |
|
301 }*/ |
|
302 |
|
303 } |
|
304 TLiwGenericParam outParm(KLocationMap , TLiwVariant(result)) ; |
|
305 |
|
306 iOutParmList->AppendL(outParm) ; |
|
307 CleanupStack :: Pop(result) ; |
|
308 result->DecRef() ; |
|
309 |
|
310 |
|
311 } |
|
312 |
|
313 /** |
|
314 * Default destructor |
|
315 */ |
|
316 |
|
317 LocationInterfaceCB :: ~LocationInterfaceCB() |
|
318 { |
|
319 |
|
320 delete iOutParmList; |
|
321 |
|
322 } |