|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 #include <bautils.h> |
|
21 #include <barsc.h> |
|
22 #include <centralrepository.h> |
|
23 |
|
24 #include "BTGPSConstantsManager.h" |
|
25 #include "BtGpsPsyPrivateCRKeys.h" |
|
26 |
|
27 //Resource definitions |
|
28 #include <nlabtgpspsyconstants.rsg> |
|
29 |
|
30 // EXTERNAL DATA STRUCTURES |
|
31 |
|
32 // EXTERNAL FUNCTION PROTOTYPES |
|
33 |
|
34 // CONSTANTS |
|
35 // Resource file name |
|
36 _LIT(KResourceFileName, "\\resource\\nlabtgpspsyconstants.*"); |
|
37 |
|
38 // Minimum send delay |
|
39 const TInt KMinimumSendDelay = 0; |
|
40 |
|
41 // Maximum send delay |
|
42 const TInt KMaximumSendDealy = 60000000; //1min |
|
43 |
|
44 // Minimum user eqivalent range error |
|
45 const TReal KMinimumUserEquivalentRangeError = 0.0; |
|
46 |
|
47 // Maximum user eqivalent range error |
|
48 const TReal KMaximumUserEquivalentRangeError = 1000.0; |
|
49 |
|
50 // Minimum Number Of Test Nmea Sentences |
|
51 const TInt KMinimumNumberOfTestNmeaSentences = 0; |
|
52 |
|
53 // Maximum Number of Test Nmea Sentences |
|
54 const TInt KMaximumNumberOfTestNmeaSentences = 100000; |
|
55 |
|
56 // Minimum Delay Between Gps Init Messages |
|
57 const TInt KMinimumDelayBetweenGpsInitMessages = 0; |
|
58 |
|
59 // Maximum Delay Between Gps Init Messages |
|
60 const TInt KMaximumDelayBetweenGpsInitMessages = 600000000; //10min |
|
61 |
|
62 // Minimum Number Of Set Full Power Message |
|
63 const TInt KMinimumNumberOfSetFullPowerMessage = 0; |
|
64 |
|
65 // Maximum Number Of Set Full Power Message |
|
66 const TInt KMaximumNumberOfSetFullPowerMessage = 100000; |
|
67 |
|
68 // Minimum Delay For PNok Gps Detect |
|
69 const TInt KMinimumDelayForPNokGpsDetect = 0; |
|
70 |
|
71 // Maximum Delay For PNok Gps Detect |
|
72 const TInt KMaximumDelayForPNokGpsDetect = 600000000; //10min |
|
73 |
|
74 // Minimum Inactivity Delay |
|
75 const TInt KMinimumInactivityDelay = 0; |
|
76 |
|
77 // Maximum Inactivity Delay |
|
78 const TInt KMaximumInactivityDelay = 600000000; //10min |
|
79 |
|
80 // Minimum Satellite Info Life Time |
|
81 const TInt KMinimumSatelliteInfoLifeTime = 0; |
|
82 |
|
83 // Maximum Satellite Info Life Time |
|
84 const TInt KMaximumSatelliteInfoLifeTime = 600000000; //10min |
|
85 |
|
86 // Minimum NMEA data buffer |
|
87 const TInt KMinimumNmeaDataBuffer = 0; |
|
88 |
|
89 // Maximum NMEA data buffer |
|
90 const TInt KMaximumNmeaDataBuffer = 50*1024; //50k |
|
91 |
|
92 |
|
93 // MACROS |
|
94 |
|
95 // LOCAL CONSTANTS AND MACROS |
|
96 |
|
97 // MODULE DATA STRUCTURES |
|
98 |
|
99 // LOCAL FUNCTION PROTOTYPES |
|
100 |
|
101 // FORWARD DECLARATIONS |
|
102 |
|
103 // ============================= LOCAL FUNCTIONS =============================== |
|
104 |
|
105 // ============================ MEMBER FUNCTIONS =============================== |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CBTGPSConstantsManager::NewL |
|
110 // ----------------------------------------------------------------------------- |
|
111 CBTGPSConstantsManager* CBTGPSConstantsManager::NewL() |
|
112 { |
|
113 CBTGPSConstantsManager* self = new (ELeave) CBTGPSConstantsManager(); |
|
114 CleanupStack::PushL(self); |
|
115 self->ConstructL(); |
|
116 CleanupStack::Pop(); |
|
117 return self; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CBTGPSConstantsManager::~CBTGPSConstantsManager |
|
122 // ----------------------------------------------------------------------------- |
|
123 CBTGPSConstantsManager::~CBTGPSConstantsManager() |
|
124 { |
|
125 delete iBatteryLowDialogText; |
|
126 delete iBatteryFullDialogText; |
|
127 delete iExtAntennaConnectedDialogText; |
|
128 delete iExtAntennaDisconnectedDialogText; |
|
129 delete iExtPowerConnectedDialogText; |
|
130 delete iExtPowerDisconnectedDialogText; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CBTGPSConstantsManager::ConstructL |
|
135 // ----------------------------------------------------------------------------- |
|
136 void CBTGPSConstantsManager::ConstructL() |
|
137 { |
|
138 //File session for resource file |
|
139 RFs fileSession; |
|
140 |
|
141 //Open file session |
|
142 User::LeaveIfError(fileSession.Connect()); |
|
143 CleanupClosePushL(fileSession); |
|
144 |
|
145 TFileName* localisedRscName = GetLocalisableResourceNameL(fileSession); |
|
146 CleanupStack::PushL(localisedRscName); |
|
147 |
|
148 //Construct RResourceFile |
|
149 RResourceFile localisationResourceFile; |
|
150 localisationResourceFile.OpenL(fileSession, *localisedRscName); |
|
151 CleanupClosePushL(localisationResourceFile); |
|
152 |
|
153 //Check the signature |
|
154 localisationResourceFile.ConfirmSignatureL(0); |
|
155 |
|
156 //Read constants from resource file |
|
157 iBatteryLowDialogText = GetTextL( |
|
158 localisationResourceFile, |
|
159 R_BATTERY_LOW); |
|
160 |
|
161 iBatteryFullDialogText = GetTextL( |
|
162 localisationResourceFile, |
|
163 R_BATTERY_FULL); |
|
164 |
|
165 iExtAntennaConnectedDialogText = GetTextL( |
|
166 localisationResourceFile, |
|
167 R_EXT_ANTENNA_CONNECTED); |
|
168 |
|
169 iExtAntennaDisconnectedDialogText = GetTextL( |
|
170 localisationResourceFile, |
|
171 R_EXT_ANTENNA_DISCONNECTED); |
|
172 |
|
173 iExtPowerConnectedDialogText = GetTextL( |
|
174 localisationResourceFile, |
|
175 R_EXT_POWER_CONNECTED); |
|
176 |
|
177 iExtPowerDisconnectedDialogText = GetTextL( |
|
178 localisationResourceFile, |
|
179 R_EXT_POWER_DISCONNECTED); |
|
180 |
|
181 //Get int constant |
|
182 GetIntL(); |
|
183 |
|
184 CleanupStack::PopAndDestroy(&localisationResourceFile); |
|
185 CleanupStack::PopAndDestroy(localisedRscName); |
|
186 CleanupStack::PopAndDestroy(&fileSession); |
|
187 |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CBTGPSConstantsManager::CBTGPSConstantsManager |
|
192 // C++ default constructor can NOT contain any code, that |
|
193 // might leave. |
|
194 // ----------------------------------------------------------------------------- |
|
195 CBTGPSConstantsManager::CBTGPSConstantsManager() |
|
196 { |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CBTGPSConstantsManager::GetLocalisableResourceNameL |
|
201 // ----------------------------------------------------------------------------- |
|
202 TFileName* CBTGPSConstantsManager::GetLocalisableResourceNameL(RFs& aFs) |
|
203 { |
|
204 TFileName* fileName = new (ELeave) TFileName; |
|
205 CleanupStack::PushL(fileName); |
|
206 |
|
207 TFindFile findFile(aFs); |
|
208 CDir* dir; |
|
209 User::LeaveIfError(findFile.FindWildByDir( |
|
210 KResourceFileName, |
|
211 KNullDesC(), |
|
212 dir)); |
|
213 CleanupStack::PushL(dir); |
|
214 TParse fileNameParser; |
|
215 fileNameParser.Set(findFile.File(), NULL, NULL); |
|
216 |
|
217 fileName->Copy(fileNameParser.DriveAndPath()); |
|
218 fileName->Append((*dir)[0].iName); |
|
219 CleanupStack::PopAndDestroy(dir); |
|
220 |
|
221 BaflUtils::NearestLanguageFile(aFs, *fileName); |
|
222 |
|
223 CleanupStack::Pop(fileName); |
|
224 return fileName; |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CBTGPSConstantsManager::GetIntL |
|
229 // ----------------------------------------------------------------------------- |
|
230 void CBTGPSConstantsManager::GetIntL() |
|
231 { |
|
232 //Read constants from CenRep |
|
233 CRepository* settings = CRepository::NewL(KCRUidBtGpsPsy ); |
|
234 CleanupStack::PushL(settings); |
|
235 |
|
236 User::LeaveIfError(settings->Get( |
|
237 KBluetoothGpsPsyMsgSendDelay, |
|
238 iSendDelay)); |
|
239 CheckRangeL(iSendDelay,KMinimumSendDelay,KMaximumSendDealy); |
|
240 |
|
241 User::LeaveIfError(settings->Get( |
|
242 KBluetoothGpsPsyUserEquivalentRangeError, |
|
243 iUserEquivalentRangeError)); |
|
244 CheckRangeL( |
|
245 iUserEquivalentRangeError, |
|
246 KMinimumUserEquivalentRangeError, |
|
247 KMaximumUserEquivalentRangeError); |
|
248 |
|
249 User::LeaveIfError(settings->Get( |
|
250 KBluetoothGpsPsyNumTestNmeaSentences, |
|
251 iNumberOfTestNmeaSentences)); |
|
252 CheckRangeL( |
|
253 iNumberOfTestNmeaSentences, |
|
254 KMinimumNumberOfTestNmeaSentences, |
|
255 KMaximumNumberOfTestNmeaSentences); |
|
256 |
|
257 User::LeaveIfError(settings->Get( |
|
258 KBluetoothGpsPsyNormalGpsInitMsgDelay, |
|
259 iDelayBetweenGpsInitMessages)); |
|
260 CheckRangeL(iDelayBetweenGpsInitMessages, |
|
261 KMinimumDelayBetweenGpsInitMessages, |
|
262 KMaximumDelayBetweenGpsInitMessages); |
|
263 |
|
264 User::LeaveIfError(settings->Get( |
|
265 KBluetoothGpsPsyNumSetFullPowerMsg, |
|
266 iNumberOfSetFullPowerMessage)); |
|
267 CheckRangeL(iNumberOfSetFullPowerMessage, |
|
268 KMinimumNumberOfSetFullPowerMessage, |
|
269 KMaximumNumberOfSetFullPowerMessage); |
|
270 |
|
271 User::LeaveIfError(settings->Get( |
|
272 KBluetoothGpsPsyPnokPollingDelay, |
|
273 iDelayForPNokGpsDetect)); |
|
274 CheckRangeL(iDelayForPNokGpsDetect, |
|
275 KMinimumDelayForPNokGpsDetect, |
|
276 KMaximumDelayForPNokGpsDetect); |
|
277 |
|
278 User::LeaveIfError(settings->Get( |
|
279 KBluetoothGpsPsyInactiveDealy, |
|
280 iInactivityDelay)); |
|
281 CheckRangeL(iInactivityDelay, |
|
282 KMinimumInactivityDelay, |
|
283 KMaximumInactivityDelay); |
|
284 |
|
285 User::LeaveIfError(settings->Get( |
|
286 KBluetoothGpsPsyUtilisePowerSaving, |
|
287 iUtilisePowerSaving)); |
|
288 CheckRangeL(iUtilisePowerSaving, 0, 1); |
|
289 |
|
290 User::LeaveIfError(settings->Get( |
|
291 KBluetoothGpsPsySateInfoLifeTime, |
|
292 iSatelliteInfoLifeTime)); |
|
293 CheckRangeL(iSatelliteInfoLifeTime, |
|
294 KMinimumSatelliteInfoLifeTime, |
|
295 KMaximumSatelliteInfoLifeTime); |
|
296 |
|
297 User::LeaveIfError(settings->Get( |
|
298 KBluetoothGpsPsyNmeaBufferSize, |
|
299 iNmeaBufferSize)); |
|
300 CheckRangeL(iNmeaBufferSize, |
|
301 KMinimumNmeaDataBuffer, |
|
302 KMaximumNmeaDataBuffer); |
|
303 |
|
304 CleanupStack::PopAndDestroy(settings); |
|
305 |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CBTGPSConstantsManager::GetTextL |
|
310 // ----------------------------------------------------------------------------- |
|
311 HBufC* CBTGPSConstantsManager::GetTextL( |
|
312 RResourceFile& aResourceFile, |
|
313 TInt aId) |
|
314 { |
|
315 HBufC8* buffer = aResourceFile.AllocReadLC(aId); |
|
316 HBufC* retBuf; |
|
317 |
|
318 //Resource parser |
|
319 TResourceReader resourceReader; |
|
320 resourceReader.SetBuffer(buffer); |
|
321 |
|
322 retBuf = resourceReader.ReadHBufCL(); |
|
323 User::LeaveIfNull(retBuf); |
|
324 |
|
325 CleanupStack::PopAndDestroy(buffer); |
|
326 |
|
327 return retBuf; |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CBTGPSConstantsManager::CheckRangeL |
|
332 // Checks that the aValue is in range [aMin,aMax] |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 template<class T> |
|
336 void CBTGPSConstantsManager::CheckRangeL(T aValue, T aMin, T aMax) |
|
337 { |
|
338 if ( aValue < aMin ) |
|
339 { |
|
340 User::Leave(KErrUnderflow); |
|
341 } |
|
342 |
|
343 if ( aValue > aMax ) |
|
344 { |
|
345 User::Leave(KErrOverflow); |
|
346 } |
|
347 } |
|
348 |
|
349 |
|
350 // End of File |
|
351 |
|
352 |
|
353 |