|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation of CBlidRouter class which provides access to blid router. Blid route can be modified and read using this class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <f32file.h> // RFs |
|
22 #include <e32math.h> |
|
23 #include <sysutil.h> |
|
24 #include <driveinfo.h> |
|
25 |
|
26 #include "CBlidRouter.h" |
|
27 #include "TNamedCoordinate.h" |
|
28 #include "blidengconsts.h" |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KBlidInvalidWaypointIndex( -1 ); |
|
32 |
|
33 //Forward declaration. Function for sorted ordering of waypoints |
|
34 TInt WaypointOrdering(const TNamedCoordinate& aCoordinate1, const TNamedCoordinate& aCoordinate2); |
|
35 |
|
36 _LIT(KPanicText, "CBlidRouter"); |
|
37 enum TPanicCode |
|
38 { |
|
39 EBlidReadOutOfRange = 1 |
|
40 }; |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS ============================== |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CBlidRouter::CBlidRouter |
|
45 // C++ default constructor can NOT contain any code, that |
|
46 // might leave. |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 CBlidRouter::CBlidRouter() |
|
50 { |
|
51 iWaypointIndex = -1; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // CBlidRouter::ConstructL |
|
56 // Symbian 2nd phase constructor can leave. |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 void CBlidRouter::ConstructL() |
|
60 { |
|
61 iLandmark = NULL; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CBlidRouter::NewL |
|
66 // Two-phased constructor. |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 CBlidRouter* CBlidRouter::NewL() |
|
70 { |
|
71 CBlidRouter* self = new( ELeave ) CBlidRouter; |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // CBlidRouter::~CBlidRouter |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 CBlidRouter::~CBlidRouter() |
|
83 { |
|
84 iRoute.ResetAndDestroy(); |
|
85 iRoute.Close(); |
|
86 if( iLandmark ) |
|
87 { |
|
88 delete iLandmark; |
|
89 } |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------------------------------- |
|
93 // CBlidRouter::At |
|
94 // ---------------------------------------------------------------------------- |
|
95 // |
|
96 TNamedCoordinate& CBlidRouter::At( TInt aIndex ) |
|
97 { |
|
98 __ASSERT_ALWAYS(aIndex >= 0 && aIndex < iRoute.Count(), |
|
99 User::Panic(KPanicText,EBlidReadOutOfRange)); |
|
100 return *iRoute[aIndex]; |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CBlidRouter::AppendL |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CBlidRouter::AppendL( TNamedCoordinate* aCoordinate, TBool aCheckForMemory ) |
|
108 { |
|
109 RFs fs; |
|
110 User::LeaveIfError(fs.Connect()); |
|
111 CleanupClosePushL( fs ); |
|
112 |
|
113 if(aCheckForMemory) |
|
114 { |
|
115 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &fs, sizeof(aCoordinate), DriveInfo::EDefaultPhoneMemory ) ) |
|
116 { |
|
117 CleanupStack::PopAndDestroy(); // fs |
|
118 return KErrDiskFull; |
|
119 } |
|
120 } |
|
121 CleanupStack::PopAndDestroy(); // fs |
|
122 TInt retVal; |
|
123 TLinearOrder<TNamedCoordinate> order(WaypointOrdering); |
|
124 retVal = iRoute.InsertInOrder(aCoordinate, order); |
|
125 return retVal; |
|
126 } |
|
127 |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CBlidRouter::RemoveL |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 TInt CBlidRouter::RemoveL( TInt aIndex ) |
|
134 { |
|
135 __ASSERT_ALWAYS(aIndex >= 0 && aIndex < iRoute.Count(), |
|
136 User::Panic(KPanicText,EBlidReadOutOfRange)); |
|
137 RFs fs; |
|
138 User::LeaveIfError(fs.Connect()); |
|
139 CleanupClosePushL( fs ); |
|
140 |
|
141 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &fs, 0, DriveInfo::EDefaultPhoneMemory ) ) |
|
142 { |
|
143 CleanupStack::PopAndDestroy(); // fs |
|
144 return KErrDiskFull; |
|
145 } |
|
146 CleanupStack::PopAndDestroy(); // fs |
|
147 TNamedCoordinate* plot = iRoute[aIndex]; |
|
148 iRoute.Remove( aIndex ); |
|
149 delete plot; |
|
150 return KErrNone; |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CBlidRouter::ResetAndDestroy |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 void CBlidRouter::ResetAndDestroy() |
|
158 { |
|
159 iRoute.ResetAndDestroy(); |
|
160 } |
|
161 |
|
162 // ---------------------------------------------------------------------------- |
|
163 // CBlidRouter::Count |
|
164 // ---------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CBlidRouter::Count() |
|
167 { |
|
168 return iRoute.Count(); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CBlidRouter::Waypoint() |
|
173 // Waypoint getter |
|
174 // ---------------------------------------------------------------------------- |
|
175 // |
|
176 TNamedCoordinate* CBlidRouter::Waypoint() |
|
177 { |
|
178 if(!iIsWaypoint || iWaypointIndex == KBlidInvalidWaypointIndex) |
|
179 { |
|
180 return NULL; |
|
181 } |
|
182 else if( iWaypointIndex == KManualWaypointIndex ) |
|
183 { |
|
184 return &iManualWaypoint; |
|
185 } |
|
186 else |
|
187 { |
|
188 return &iWaypoint; |
|
189 } |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------------------------- |
|
193 // CBlidRouter::IndexOfWaypoint |
|
194 // ---------------------------------------------------------------------------- |
|
195 // |
|
196 TInt CBlidRouter::IndexOfWaypoint() const |
|
197 { |
|
198 return iWaypointIndex; |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------------------------- |
|
202 // CBlidRouter::SetWaypoint( const TInt aIndex ) |
|
203 // Waypoint setter |
|
204 // ---------------------------------------------------------------------------- |
|
205 // |
|
206 void CBlidRouter::SetWaypoint( const TInt aIndex ) |
|
207 { |
|
208 iWaypoint = At( aIndex ); |
|
209 iWaypointIndex = aIndex; |
|
210 iIsWaypoint = ETrue; |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CBlidRouter::RemoveWaypoint() |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 void CBlidRouter::RemoveWaypoint() |
|
218 { |
|
219 iWaypointIndex = -1; |
|
220 } |
|
221 |
|
222 // ---------------------------------------------------------------------------- |
|
223 // CBlidRouter::ClearSetPoints() |
|
224 // ---------------------------------------------------------------------------- |
|
225 // |
|
226 void CBlidRouter::ClearSetPoints() |
|
227 { |
|
228 RemoveWaypoint(); |
|
229 if(iLandmark) |
|
230 { |
|
231 delete iLandmark; |
|
232 iLandmark = NULL; |
|
233 } |
|
234 } |
|
235 |
|
236 // ---------------------------------------------------------------------------- |
|
237 // CBlidRouter::ExternalizeL |
|
238 // ---------------------------------------------------------------------------- |
|
239 // |
|
240 void CBlidRouter::ExternalizeL( RWriteStream& aStream ) |
|
241 { |
|
242 TDesC *name; |
|
243 TInt count( Count() ); |
|
244 aStream.WriteInt32L( count ); |
|
245 for (TInt i = 0; i < count; i++ ) |
|
246 { |
|
247 name = At( i ).Name(); |
|
248 if ( name ) |
|
249 { |
|
250 CleanupStack::PushL( name ); |
|
251 aStream.WriteInt32L( name->Length() ); |
|
252 aStream.WriteL( *name ); |
|
253 CleanupStack::PopAndDestroy(); //name |
|
254 name = NULL; |
|
255 |
|
256 if ( !Math::IsNaN(At( i ).Latitude()) ) |
|
257 { |
|
258 aStream.WriteReal64L( At( i ).Latitude() ); |
|
259 } |
|
260 else |
|
261 { |
|
262 aStream.WriteReal64L( 0 ); |
|
263 } |
|
264 |
|
265 if ( !Math::IsNaN(At( i ).Longitude()) ) |
|
266 { |
|
267 aStream.WriteReal64L( At( i ).Longitude() ); |
|
268 } |
|
269 else |
|
270 { |
|
271 aStream.WriteReal64L( 0 ); |
|
272 } |
|
273 |
|
274 if ( !Math::IsNaN(At( i ).Altitude()) ) |
|
275 { |
|
276 aStream.WriteReal32L( At( i ).Altitude() ); |
|
277 } |
|
278 else |
|
279 { |
|
280 aStream.WriteReal32L( 0 ); |
|
281 } |
|
282 if ( !Math::IsNaN(At( i ).Accuracy()) ) |
|
283 { |
|
284 aStream.WriteReal32L( At( i ).Accuracy() ); |
|
285 } |
|
286 else |
|
287 { |
|
288 aStream.WriteReal32L( 0 ); |
|
289 } |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 // ---------------------------------------------------------------------------- |
|
295 // CBlidRouter::InternalizeV1L |
|
296 // ---------------------------------------------------------------------------- |
|
297 // |
|
298 void CBlidRouter::InternalizeV1L( RReadStream& aStream ) |
|
299 { |
|
300 TInt i; |
|
301 TInt count( aStream.ReadInt32L() ); |
|
302 TInt length(0); |
|
303 TBuf<KBlidWaypointNameMaxLen> name; |
|
304 for ( i = 0; i < count; i++ ) |
|
305 { |
|
306 length = aStream.ReadInt32L(); |
|
307 aStream.ReadL( name, length ); |
|
308 TReal64 latitude = aStream.ReadReal64L(); |
|
309 TReal64 longitude = aStream.ReadReal64L(); |
|
310 TReal32 altitude = aStream.ReadReal32L(); |
|
311 TReal32 accuracy = aStream.ReadReal32L(); |
|
312 TNamedCoordinate* plot = new(ELeave)TNamedCoordinate( |
|
313 latitude, |
|
314 longitude, |
|
315 altitude, |
|
316 name,accuracy); |
|
317 CleanupStack::PushL( plot ); |
|
318 //iRouter takes ownership of plot |
|
319 User::LeaveIfError( AppendL( plot, EFalse ) ); |
|
320 CleanupStack::Pop(); //plot |
|
321 name.Zero(); |
|
322 } |
|
323 } |
|
324 |
|
325 // ---------------------------------------------------------------------------- |
|
326 // CBlidRouter::Landmark |
|
327 // ---------------------------------------------------------------------------- |
|
328 // |
|
329 CPosLandmark* CBlidRouter::Landmark() const |
|
330 { |
|
331 if( iLandmark && !iIsWaypoint ) |
|
332 { |
|
333 return iLandmark; |
|
334 } |
|
335 else |
|
336 { |
|
337 return NULL; |
|
338 } |
|
339 } |
|
340 |
|
341 // ---------------------------------------------------------------------------- |
|
342 // CBlidRouter::SetLandmark |
|
343 // ---------------------------------------------------------------------------- |
|
344 // |
|
345 void CBlidRouter::SetLandmark(CPosLandmark* aLandmark) |
|
346 { |
|
347 if( iLandmark ) |
|
348 { |
|
349 delete iLandmark; |
|
350 } |
|
351 |
|
352 iLandmark = aLandmark; |
|
353 iIsWaypoint = EFalse; |
|
354 } |
|
355 |
|
356 // ---------------------------------------------------------------------------- |
|
357 // CBlidRouter::IsWaypointSet |
|
358 // ---------------------------------------------------------------------------- |
|
359 // |
|
360 TBool CBlidRouter::IsWaypointSet() |
|
361 { |
|
362 return iIsWaypoint; |
|
363 } |
|
364 |
|
365 // ---------------------------------------------------------------------------- |
|
366 // CBlidRouter::IsAnyPointSet |
|
367 // ---------------------------------------------------------------------------- |
|
368 // |
|
369 TBool CBlidRouter::IsAnyPointSet() |
|
370 { |
|
371 if( iLandmark || (iWaypointIndex != -1) ) |
|
372 { |
|
373 return ETrue; |
|
374 } |
|
375 else |
|
376 { |
|
377 return EFalse; |
|
378 } |
|
379 } |
|
380 // ---------------------------------------------------------------------------- |
|
381 // CBlidRouter::SetManualWaypoint |
|
382 // ---------------------------------------------------------------------------- |
|
383 // |
|
384 void CBlidRouter::SetManualWaypoint(TReal latitude, TReal longitude, TDesC& aName) |
|
385 { |
|
386 iWaypointIndex = KManualWaypointIndex; |
|
387 iIsWaypoint = ETrue; |
|
388 iManualWaypoint.SetCoordinate(latitude, longitude); |
|
389 iManualWaypoint.SetName(aName); |
|
390 } |
|
391 |
|
392 // ---------------------------------------------------------------------------- |
|
393 // CBlidRouter::FindWaypointIndex |
|
394 // ---------------------------------------------------------------------------- |
|
395 // |
|
396 TInt CBlidRouter::FindWaypointIndex( TNamedCoordinate* aCoordinate ) |
|
397 { |
|
398 TLinearOrder<TNamedCoordinate> order(WaypointOrdering); |
|
399 iRoute.Sort( order ); |
|
400 TInt lReturn = iRoute.Find( aCoordinate ); |
|
401 return lReturn; |
|
402 } |
|
403 // ---------------------------------------------------------------------------- |
|
404 // WaypointOrdering() : Function used for ordering of waypoints |
|
405 // ---------------------------------------------------------------------------- |
|
406 // |
|
407 TInt WaypointOrdering(const TNamedCoordinate& aCoordinate1, const TNamedCoordinate& aCoordinate2) |
|
408 { |
|
409 HBufC* name1 = aCoordinate1.Name(); |
|
410 HBufC* name2 = aCoordinate2.Name(); |
|
411 TInt retVal = name1->Compare(name2->Des()); |
|
412 delete name1; |
|
413 delete name2; |
|
414 return retVal; |
|
415 } |
|
416 // End of File |
|
417 |
|
418 |