|
1 /* |
|
2 * Copyright (c) 2002-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: Helper class for handling out of disk space situations. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <lbs.h> |
|
21 #include <centralrepository.h> |
|
22 #include <UiklafInternalCRKeys.h> |
|
23 #include "EPos_CPosLmDiskUtilities.h" |
|
24 #include "EPos_CPosLmResourceReader.h" |
|
25 #include "EPos_LandmarksInternalServicesPanic.h" |
|
26 |
|
27 const TInt KEvaluatedMeanLmDiskSize = 1250; |
|
28 const TInt KEvaluatedMeanLmCatDiskSize = 1250; |
|
29 const TInt KEvaluatedMeanAddLmCatToLmDiskSize = 250; |
|
30 const TInt KEvaluatedMeanRemoveLmCatFromLmDiskSize = 100; |
|
31 const TInt KEmptyDatabaseSize = 8300; |
|
32 const TInt KIdIndexStartSize = 1100; |
|
33 const TInt KIdIndexGrowth = 9; |
|
34 const TInt KFatClusterSize = 2048; |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPosLmDiskUtilities::CPosLmDiskUtilities() : |
|
42 iCriticalDiskLevel(0) |
|
43 { |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CPosLmDiskUtilities::ConstructL() |
|
50 { |
|
51 User::LeaveIfError(iFs.Connect()); |
|
52 |
|
53 CRepository* repository = CRepository::NewLC(KCRUidUiklaf); |
|
54 User::LeaveIfError(repository->Get(KUikOODDiskCriticalThreshold, |
|
55 iCriticalDiskLevel)); |
|
56 |
|
57 CleanupStack::PopAndDestroy(repository); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CPosLmDiskUtilities* CPosLmDiskUtilities::NewL() |
|
64 { |
|
65 CPosLmDiskUtilities* self = new (ELeave) CPosLmDiskUtilities; |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop(self); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CPosLmDiskUtilities::~CPosLmDiskUtilities() |
|
76 { |
|
77 iFs.Close(); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 EXPORT_C void CPosLmDiskUtilities::DiskSpaceBelowCriticalLevelL( |
|
84 TInt aBytesToWrite, TChar aDrive ) |
|
85 { |
|
86 // RFs allocates by clusters. Calculate the actual bytes to write according to this. |
|
87 TInt clusterSize = KFatClusterSize; |
|
88 |
|
89 TInt drive; |
|
90 User::LeaveIfError( iFs.CharToDrive( aDrive, drive ) ); |
|
91 |
|
92 TVolumeIOParamInfo ioInfo; |
|
93 TInt err = iFs.VolumeIOParam( drive, ioInfo ); |
|
94 if ( !err ) |
|
95 { |
|
96 clusterSize = ioInfo.iClusterSize; |
|
97 } |
|
98 |
|
99 TInt bytesInLastCluster = aBytesToWrite % clusterSize; |
|
100 TInt paddedBytesToFillCluster = 0; |
|
101 if ( bytesInLastCluster > 0 ) |
|
102 { |
|
103 paddedBytesToFillCluster = clusterSize - bytesInLastCluster; |
|
104 } |
|
105 |
|
106 TInt64 neededSpace( aBytesToWrite + paddedBytesToFillCluster ); |
|
107 |
|
108 TVolumeInfo volumeInfo; |
|
109 User::LeaveIfError( iFs.Volume( volumeInfo, drive ) ); |
|
110 TInt64 available( volumeInfo.iFree - TInt64( iCriticalDiskLevel ) ); |
|
111 |
|
112 if ( available < neededSpace ) |
|
113 { |
|
114 User::Leave( KErrDiskFull ); |
|
115 } |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C TInt CPosLmDiskUtilities::EstimatedDiskSizeOfLmOperation( |
|
122 TLmOperation aOperation, |
|
123 const CPosLandmark& aLandmark) |
|
124 { |
|
125 __ASSERT_DEBUG(aOperation == EAddLandmarkOp || |
|
126 aOperation == EUpdateLandmarkOp, |
|
127 DebugPanic(EPosLandmarkInternalServicesInvalidArgument)); |
|
128 __ASSERT_DEBUG(&aLandmark, |
|
129 DebugPanic(EPosLandmarkInternalServicesInvalidArgument)); |
|
130 |
|
131 if (aOperation == EAddLandmarkOp) |
|
132 { |
|
133 return CalculateLandmarkDisksize(aLandmark); |
|
134 } |
|
135 |
|
136 return Max(CalculateLandmarkDisksize(aLandmark) - |
|
137 KEvaluatedMeanLmDiskSize, 0); |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C TInt CPosLmDiskUtilities::EstimatedDiskSizeOfLmOperation( |
|
144 TLmOperation aOperation, |
|
145 const CPosLandmarkCategory& aLmCategory) |
|
146 { |
|
147 __ASSERT_DEBUG(aOperation == EAddLmCategoryOp || |
|
148 aOperation == EUpdateLmCategoryOp || |
|
149 aOperation == ERemoveLmCategoryOp, |
|
150 DebugPanic(EPosLandmarkInternalServicesInvalidArgument)); |
|
151 __ASSERT_DEBUG(&aLmCategory, |
|
152 DebugPanic(EPosLandmarkInternalServicesInvalidArgument)); |
|
153 |
|
154 if (aOperation == EAddLmCategoryOp) |
|
155 { |
|
156 return CalculateLandmarkCategoryDisksize(aLmCategory); |
|
157 } |
|
158 |
|
159 // aOperation == EUpdateLmCategoryOp |
|
160 return Max(CalculateLandmarkCategoryDisksize(aLmCategory) - |
|
161 KEvaluatedMeanLmCatDiskSize, 0); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C TInt CPosLmDiskUtilities::EstimatedDiskSizeOfLmOperation( |
|
168 TLmOperation aOperation, |
|
169 const TPosLmItemId& /*aLandmarkId*/) |
|
170 { |
|
171 __ASSERT_DEBUG(aOperation == ERemoveLandmarkOp || |
|
172 aOperation == ERemoveLmCategoryOp, |
|
173 DebugPanic(EPosLandmarkInternalServicesInvalidArgument)); |
|
174 |
|
175 if (aOperation == ERemoveLandmarkOp) |
|
176 { |
|
177 return KEvaluatedMeanLmDiskSize; |
|
178 } |
|
179 |
|
180 // aOperation == ERemoveLmCategoryOp |
|
181 return KEvaluatedMeanLmCatDiskSize; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C TInt CPosLmDiskUtilities::EstimatedDiskSizeOfLmOperation( |
|
188 TLmOperation aOperation, |
|
189 const RArray<TPosLmItemId>& aLandmarkIdArray) |
|
190 { |
|
191 __ASSERT_DEBUG(aOperation == ERemoveLandmarksOp || |
|
192 aOperation == ERemoveLmCategoriesOp, |
|
193 DebugPanic(EPosLandmarkInternalServicesInvalidArgument)); |
|
194 |
|
195 if (aOperation == ERemoveLandmarksOp) |
|
196 { |
|
197 return aLandmarkIdArray.Count() * KEvaluatedMeanLmDiskSize; |
|
198 } |
|
199 |
|
200 // aOperation == ERemoveLmCategoriesOp |
|
201 return aLandmarkIdArray.Count() * KEvaluatedMeanLmCatDiskSize; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 EXPORT_C TInt CPosLmDiskUtilities::EstimatedDiskSizeOfLmCatOperation( |
|
208 TLmOperation aOperation, |
|
209 TPosLmItemId& /*aLandmarkId*/, |
|
210 const RArray<TPosLmItemId>& aLandmarkIdArray) |
|
211 { |
|
212 __ASSERT_DEBUG(aOperation == EAddLmCategoryToLmOp || |
|
213 aOperation == ERemoveLmCategoryFromLmOp, |
|
214 DebugPanic(EPosLandmarkInternalServicesInvalidArgument)); |
|
215 |
|
216 if (aOperation == EAddLmCategoryToLmOp) |
|
217 { |
|
218 return aLandmarkIdArray.Count() * KEvaluatedMeanAddLmCatToLmDiskSize; |
|
219 } |
|
220 |
|
221 // aOperation == ERemoveLmCategoryFromLmOp |
|
222 return aLandmarkIdArray.Count() * KEvaluatedMeanRemoveLmCatFromLmDiskSize; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 EXPORT_C TInt CPosLmDiskUtilities::EstimatedDiskSizeOfEmptyDatabase() |
|
229 { |
|
230 return KEmptyDatabaseSize; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 EXPORT_C TInt CPosLmDiskUtilities::EstimatedDiskSizeOfIndex( |
|
237 TLmOperation aOperation, |
|
238 TInt aCountOfRecords ) |
|
239 { |
|
240 __ASSERT_DEBUG( aOperation == ECreateFieldsLmIdIndex || |
|
241 aOperation == ECreateCategoriesLmIdIndex, |
|
242 DebugPanic( EPosLandmarkInternalServicesInvalidArgument ) ); |
|
243 |
|
244 return KIdIndexStartSize + aCountOfRecords * KIdIndexGrowth; |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 TInt CPosLmDiskUtilities::CalculateLandmarkDisksize( |
|
251 const CPosLandmark& aLandmark) |
|
252 { |
|
253 // Constant for estimating disk size |
|
254 const TReal bytesToDisk = 4.4; |
|
255 // A bare landmark takes 44 bytes on disk |
|
256 const TInt bareLm = 44; |
|
257 // Adding 73 bytes when landmark have an icon. |
|
258 const TInt iconIncluded = 73; |
|
259 |
|
260 // Method variables |
|
261 TInt err = KErrNone; |
|
262 TReal result = 0; |
|
263 |
|
264 // Bare landmark |
|
265 result += bareLm * bytesToDisk; |
|
266 |
|
267 // Estimate location |
|
268 TLocality loc; |
|
269 err = aLandmark.GetPosition(loc); |
|
270 if (!err) |
|
271 { |
|
272 if (!TRealX(loc.Latitude()).IsNaN()) |
|
273 { |
|
274 // TReal64 |
|
275 result += bytesToDisk * bytesToDisk * 4; |
|
276 } |
|
277 if (!TRealX(loc.Longitude()).IsNaN()) |
|
278 { |
|
279 // TReal64 |
|
280 result += bytesToDisk * bytesToDisk * 4; |
|
281 } |
|
282 if (!TRealX(loc.Altitude()).IsNaN()) |
|
283 { |
|
284 // TReal32 |
|
285 result += bytesToDisk * bytesToDisk * 2; |
|
286 } |
|
287 if (!TRealX(loc.HorizontalAccuracy()).IsNaN()) |
|
288 { |
|
289 // TReal32 |
|
290 result += bytesToDisk * bytesToDisk * 2; |
|
291 } |
|
292 if (!TRealX(loc.VerticalAccuracy()).IsNaN()) |
|
293 { |
|
294 // TReal32 |
|
295 result += bytesToDisk * bytesToDisk * 2; |
|
296 } |
|
297 } |
|
298 |
|
299 // Calculate landmark coverage radius |
|
300 TReal32 real; |
|
301 err = aLandmark.GetCoverageRadius(real); |
|
302 if (!err) |
|
303 { |
|
304 result += bytesToDisk * bytesToDisk * 2; |
|
305 } |
|
306 |
|
307 // Calculate landmark name |
|
308 TPtrC des; |
|
309 err = aLandmark.GetLandmarkName(des); |
|
310 if (!err) |
|
311 { |
|
312 result += des.Length() * bytesToDisk * 2; |
|
313 } |
|
314 |
|
315 // Calculate landmark description |
|
316 err = aLandmark.GetLandmarkDescription(des); |
|
317 if (!err) |
|
318 { |
|
319 result += des.Length() * bytesToDisk * 2; |
|
320 } |
|
321 |
|
322 // Icon |
|
323 // Constants for adding a icon |
|
324 TInt iconIndex; |
|
325 TInt maskIndex; |
|
326 err = aLandmark.GetIcon(des, iconIndex, maskIndex); |
|
327 if (!err) |
|
328 { |
|
329 result += iconIncluded; |
|
330 } |
|
331 |
|
332 // Calculating position fields |
|
333 TInt nrFields = aLandmark.NumOfAvailablePositionFields(); |
|
334 TPositionFieldId fid = aLandmark.FirstPositionFieldId(); |
|
335 for (TInt j = 0; j < nrFields; j++) |
|
336 { |
|
337 err = aLandmark.GetPositionField(fid, des); |
|
338 if (!err) |
|
339 { |
|
340 result += des.Length() * bytesToDisk; |
|
341 } |
|
342 |
|
343 fid = aLandmark.NextPositionFieldId(fid); |
|
344 } |
|
345 |
|
346 return static_cast<TInt> (result); |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // ----------------------------------------------------------------------------- |
|
351 // |
|
352 TInt CPosLmDiskUtilities::CalculateLandmarkCategoryDisksize( |
|
353 const CPosLandmarkCategory& /*aLandmark*/) |
|
354 { |
|
355 return KEvaluatedMeanLmCatDiskSize; |
|
356 } |
|
357 |