|
1 /* |
|
2 * Copyright (c) 2010 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 "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: Client-Server communication |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "posindicatorhelper.h" |
|
19 #include "posindicatorhelperserver.h" |
|
20 #include "posindhelperclientrequester.h" |
|
21 #include "posindicatorhelpererrors.h" |
|
22 #include "posindinfochangeobserver.h" |
|
23 |
|
24 #include <e32std.h> |
|
25 #include <s32strm.h> |
|
26 #include <s32mem.h> |
|
27 |
|
28 #include <epos_poslandmarkserialization.h> |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // RPosIndicatorHelper::RPosIndicatorHelper() |
|
32 // |
|
33 // Default constructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 RPosIndicatorHelper::RPosIndicatorHelper() |
|
37 : iClientRequester(NULL), |
|
38 iLmkBuf(NULL), |
|
39 iLandmark(NULL), |
|
40 iCoordinateSettingValue( ELocCoordinatesNotHidden ) |
|
41 { |
|
42 FUNC("+ RPosIndicatorHelper::RPosIndicatorHelper"); |
|
43 FUNC("- RPosIndicatorHelper::RPosIndicatorHelper"); |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // RPosIndicatorHelper::~RPosIndicatorHelper |
|
48 // |
|
49 // Destructor. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 RPosIndicatorHelper::~RPosIndicatorHelper() |
|
53 { |
|
54 FUNC("+ RPosIndicatorHelper::~RPosIndicatorHelper"); |
|
55 |
|
56 if(iClientRequester) |
|
57 { |
|
58 delete iClientRequester; |
|
59 iClientRequester = NULL; |
|
60 } |
|
61 if(iLmkBuf) |
|
62 { |
|
63 delete iLmkBuf; |
|
64 iLmkBuf = NULL; |
|
65 } |
|
66 if(iLandmark) |
|
67 { |
|
68 delete iLandmark; |
|
69 iLandmark = NULL; |
|
70 } |
|
71 FUNC("- RPosIndicatorHelper::~RPosIndicatorHelper"); |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // RPosIndicatorHelper::ConstructL |
|
77 //Symbian 2nd phase constructor can leave. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void RPosIndicatorHelper::ConstructL() |
|
81 { |
|
82 FUNC("+ RPosIndicatorHelper::ConstructL"); |
|
83 iClientRequester = CPosIndHelperClientRequester::NewL(*this); |
|
84 iLandmark = NULL; |
|
85 CheckHideCoordinateL(); |
|
86 FUNC("- RPosIndicatorHelper::ConstructL"); |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // RPosIndicatorHelper::Open |
|
92 // |
|
93 // (other items were commented in a header). |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 TInt RPosIndicatorHelper::Open( RPosIndicatorHelperServer& aServer, |
|
97 MPosIndInfoChangeObserver* aPosIndInfoChangeObserver ) |
|
98 { |
|
99 FUNC("+ RPosIndicatorHelper::Open"); |
|
100 |
|
101 __ASSERT_ALWAYS( aPosIndInfoChangeObserver , User::Panic (KPosIndHelperClientPanicCategory, EPosIndicatorHelperServerBadHandle)); |
|
102 iPosIndInfoChangeObserver = aPosIndInfoChangeObserver; |
|
103 |
|
104 __ASSERT_ALWAYS(aServer.Handle() != 0, |
|
105 User::Panic(KPosIndHelperClientPanicCategory, EPosIndicatorHelperServerBadHandle)); |
|
106 |
|
107 __ASSERT_ALWAYS(! SubSessionHandle() , User::Panic (KPosIndHelperClientPanicCategory, EPosIndicatorHelperServerBadHandle)); |
|
108 TRAPD(ret, ConstructL()); |
|
109 if (ret == KErrNone) |
|
110 { |
|
111 ret = CreateSubSession(aServer, ESubSessionOpen, TIpcArgs()); |
|
112 } |
|
113 return ret; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------- |
|
117 // RPosIndicatorHelper::Close |
|
118 // |
|
119 // (other items were commented in a header). |
|
120 // --------------------------------------------------------- |
|
121 // |
|
122 void RPosIndicatorHelper:: Close() |
|
123 { |
|
124 FUNC("+ RPosIndicatorHelper::Close"); |
|
125 |
|
126 TBool isActive = iClientRequester->IsActive(); |
|
127 TInt status = iClientRequester->iStatus.Int(); |
|
128 |
|
129 if( isActive && status == KRequestPending ) |
|
130 { |
|
131 User::Panic(KPosIndHelperClientPanicCategory, EPosIndicatorHelperRequestsNotCancelled ); |
|
132 } |
|
133 |
|
134 if(SubSessionHandle()) |
|
135 { |
|
136 CloseSubSession(ESubSessionClose); |
|
137 } |
|
138 |
|
139 FUNC("- RPosIndicatorHelper::Close"); |
|
140 } |
|
141 |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // RPosIndicatorHelper::RequestPosInfo() |
|
145 // --------------------------------------------------------------------------- |
|
146 void RPosIndicatorHelper::RequestPosInfo() |
|
147 { |
|
148 FUNC("+ RPosIndicatorHelper::RequestPosInfo"); |
|
149 |
|
150 __ASSERT_ALWAYS(SubSessionHandle() , User::Panic (KPosIndHelperClientPanicCategory, EPosIndicatorHelperServerBadHandle)); |
|
151 |
|
152 if(iClientRequester->IsActive()) |
|
153 return; // If a previous request for position is alive, ignore this call |
|
154 |
|
155 TPckg<TPositionSatelliteInfo> posSatPckg( iPositionInfo ); |
|
156 TIpcArgs args; |
|
157 args.Set(KParamCurrentPosition, &posSatPckg); |
|
158 |
|
159 iClientRequester->iStatus = KRequestPending; |
|
160 SendReceive(EGetCurrentPosition, args , iClientRequester->iStatus); |
|
161 iClientRequester->Start(EGetCurrentPosition); |
|
162 FUNC("- RPosIndicatorHelper::RequestPosInfo"); |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // RPosIndicatorHelper::GetAddressInfoSizePrivate() |
|
167 // --------------------------------------------------------------------------- |
|
168 void RPosIndicatorHelper::GetAddressInfoSize() |
|
169 { |
|
170 FUNC("+ RPosIndicatorHelper::RPosIndicatorHelper"); |
|
171 |
|
172 // Create buffer and send message to resolve address |
|
173 TPckg<TInt> posSatPckg( iSize ); |
|
174 TIpcArgs args; |
|
175 args.Set(KParamCurrentAddressSize ,&posSatPckg); |
|
176 |
|
177 iClientRequester->iStatus = KRequestPending; |
|
178 SendReceive(EGetCurrentAddressInfoSize, args, iClientRequester->iStatus); |
|
179 iClientRequester->Start(EGetCurrentAddressInfoSize); |
|
180 |
|
181 FUNC("- RPosIndicatorHelper::GetAddressInfoSize"); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // RPosIndicatorHelper::GetAddressL() |
|
186 // --------------------------------------------------------------------------- |
|
187 void RPosIndicatorHelper::GetAddressL() |
|
188 { |
|
189 FUNC("+ RPosIndicatorHelper::RPosIndicatorHelper"); |
|
190 TIpcArgs args; |
|
191 FUNC(" TIpcArgs args"); |
|
192 iLmkBuf = HBufC8::NewL(iSize); // Need to check iStatus |
|
193 FUNC(" HBufC8::NewLC"); |
|
194 |
|
195 TPtr8 bufferPtr = iLmkBuf->Des(); |
|
196 FUNC(" iLmkBuf->Des()"); |
|
197 |
|
198 args.Set( KParamCurrentAddress , &bufferPtr); |
|
199 FUNC(" args.Set"); |
|
200 |
|
201 iClientRequester->iStatus = KRequestPending; |
|
202 SendReceive(EGetCurrentAddressInfo, args, iClientRequester->iStatus); |
|
203 iClientRequester->Start(EGetCurrentAddressInfo); |
|
204 |
|
205 FUNC("- RPosIndicatorHelper::GetAddressL"); |
|
206 |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // RPosIndicatorHelper::CancelCurrentRequest() |
|
211 // --------------------------------------------------------------------------- |
|
212 void RPosIndicatorHelper::CancelCurrentRequest() |
|
213 { |
|
214 FUNC("+ RPosIndicatorHelper::CancelCurrentRequest"); |
|
215 if (iClientRequester->IsActive()) |
|
216 { |
|
217 SendReceive(ECancelCurrentOperation); |
|
218 iClientRequester->Cancel(); |
|
219 } |
|
220 FUNC("- RPosIndicatorHelper::CancelCurrentRequest"); |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // RPosIndicatorHelper::NotifyServerRequestCompletion() |
|
225 // --------------------------------------------------------------------------- |
|
226 void RPosIndicatorHelper::NotifyServerRequestCompletion(TServiceIds aServiceId, TInt aErrCode ) |
|
227 { |
|
228 FUNC("+ RPosIndicatorHelper::NotifyServerRequestCompletion"); |
|
229 TInt err = aErrCode; |
|
230 switch( aServiceId ) |
|
231 { |
|
232 case EGetCurrentPosition: |
|
233 { |
|
234 FUNC("case EGetCurrentPosition"); |
|
235 |
|
236 //delete old landmark |
|
237 if(iLandmark) |
|
238 { |
|
239 delete iLandmark; |
|
240 iLandmark = NULL; |
|
241 } |
|
242 //if error in retrieval of coordinate info, notify client |
|
243 if( err!=KErrNone ) |
|
244 { |
|
245 LOG("Error in NotifyServerRequestCompletion : %d",err); |
|
246 //notify client about change in position information |
|
247 iPosIndInfoChangeObserver->NotifyPosInfoChange( iLandmark, err ); |
|
248 return; |
|
249 } |
|
250 if( iCoordinateSettingValue == ELocCoordinatesNotHidden ) |
|
251 { |
|
252 //add coordinate info to landmark object |
|
253 TRAP(err, |
|
254 iLandmark = CPosLandmark::NewL(); |
|
255 TPosition position; |
|
256 iPositionInfo.GetPosition( position ); |
|
257 iLandmark->SetPositionL( position ); |
|
258 ); |
|
259 |
|
260 if(err == KErrNone) |
|
261 { |
|
262 LOG("No error in NotifyServerRequestCompletion : %d",err); |
|
263 //notify client about change in position information |
|
264 iPosIndInfoChangeObserver->NotifyPosInfoChange( iLandmark, err ); |
|
265 } |
|
266 } |
|
267 GetAddressInfoSize(); |
|
268 break; |
|
269 } |
|
270 case EGetCurrentAddressInfoSize: |
|
271 { |
|
272 FUNC("case EGetCurrentAddressInfoSize"); |
|
273 |
|
274 //delete old landmark |
|
275 if(iLandmark) |
|
276 { |
|
277 delete iLandmark; |
|
278 iLandmark = NULL; |
|
279 } |
|
280 //if error in retrieval of coordinate info, notify client |
|
281 if( err!=KErrNone ) |
|
282 { |
|
283 //notify client about change in position information |
|
284 iPosIndInfoChangeObserver->NotifyPosInfoChange( iLandmark, err ); |
|
285 break; |
|
286 } |
|
287 GetAddressL(); |
|
288 break; |
|
289 } |
|
290 case EGetCurrentAddressInfo: |
|
291 { |
|
292 FUNC("case EGetCurrentAddressInfo"); |
|
293 |
|
294 //delete old landmark |
|
295 if(iLandmark) |
|
296 { |
|
297 delete iLandmark; |
|
298 iLandmark = NULL; |
|
299 } |
|
300 //if error in retrieval of coordinate info, notify client |
|
301 if( err!=KErrNone ) |
|
302 { |
|
303 //notify client about change in position information |
|
304 iPosIndInfoChangeObserver->NotifyPosInfoChange( iLandmark, err ); |
|
305 } |
|
306 |
|
307 //add coordinate info to landmark object |
|
308 TRAPD(err, |
|
309 iLandmark = CPosLandmark::NewL(); |
|
310 iLandmark = PosLandmarkSerialization::UnpackL(*iLmkBuf) |
|
311 ); |
|
312 |
|
313 if(err == KErrNone) |
|
314 { |
|
315 //notify client about change in position information |
|
316 iPosIndInfoChangeObserver->NotifyPosInfoChange( iLandmark, err ); |
|
317 } |
|
318 break; |
|
319 } |
|
320 default: |
|
321 { |
|
322 break; |
|
323 } |
|
324 } |
|
325 FUNC("- RPosIndicatorHelper::NotifyServerRequestCompletion"); |
|
326 } |
|
327 |
|
328 void RPosIndicatorHelper::CheckHideCoordinateL() |
|
329 { |
|
330 FUNC("+ RPosIndicatorHelper::CheckHideCoordinateL"); |
|
331 CRepository* repository = CRepository::NewL( TUid::Uid( KCRUidLocLocalVariation) ); |
|
332 CleanupStack::PushL( repository ); |
|
333 User::LeaveIfError( repository->Get( KLocHideCoordinates, |
|
334 iCoordinateSettingValue )); |
|
335 CleanupStack::PopAndDestroy( repository ); |
|
336 FUNC("+ RPosIndicatorHelper::CheckHideCoordinateL"); |
|
337 } |
|
338 |