23 #include "psmbackupstorage.h" |
23 #include "psmbackupstorage.h" |
24 #include "psmcenrepstorage.h" |
24 #include "psmcenrepstorage.h" |
25 #include "psmtrace.h" |
25 #include "psmtrace.h" |
26 |
26 |
27 // ----------------------------------------------------------------------------- |
27 // ----------------------------------------------------------------------------- |
28 // CloseHandler |
|
29 // closes the storage handler |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 void CleanupStorage(TAny* aPtr) |
|
33 { |
|
34 CPsmStorage* self = static_cast<CPsmStorage*> (aPtr); |
|
35 //Ignore the Trap as Cleanup can't leave. |
|
36 TRAP_IGNORE(self->CloseStorageL()); |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CloseHandler |
|
41 // closes the backup storage handler |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 void CleanupBackupStorage(TAny* aPtr) |
|
45 { |
|
46 CPsmBackupStorage* self = static_cast<CPsmBackupStorage*> (aPtr); |
|
47 //Ignore the Trap as Cleanup can't leave. |
|
48 TRAP_IGNORE(self->CloseStorageL()); |
|
49 } |
|
50 |
|
51 // CPsmSettingsHandler::NewL |
28 // CPsmSettingsHandler::NewL |
52 // Two-phased constructor. |
29 // Two-phased constructor. |
53 // ----------------------------------------------------------------------------- |
30 // ----------------------------------------------------------------------------- |
54 // |
31 // |
55 CPsmSettingsHandler* CPsmSettingsHandler::NewL( const TPsmsrvMode aMode ) |
32 CPsmSettingsHandler* CPsmSettingsHandler::NewL( const TPsmsrvMode aMode ) |
135 // |
112 // |
136 void CPsmSettingsHandler::BackupAndGetSettingsL( |
113 void CPsmSettingsHandler::BackupAndGetSettingsL( |
137 RConfigInfoArray& aPsmConfigArray, TUint32 aRepository ) |
114 RConfigInfoArray& aPsmConfigArray, TUint32 aRepository ) |
138 { |
115 { |
139 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::BackupAndGetSettingsL()" ) ) ); |
116 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::BackupAndGetSettingsL()" ) ) ); |
140 //Close config handle in case of any error |
|
141 CleanupStack::PushL(TCleanupItem(CleanupStorage, iConfigStorage)); |
|
142 // Change settings from normal config storage |
117 // Change settings from normal config storage |
143 iConfigStorage->InitStorageL( aRepository ); |
118 iConfigStorage->InitStorageL( aRepository ); |
144 ChangeSettingsL( aPsmConfigArray, aRepository, *iConfigStorage ); |
119 ChangeSettingsL( aPsmConfigArray, aRepository, *iConfigStorage ); |
145 iConfigStorage->CloseStorageL(); |
120 iConfigStorage->CloseStorageL(); |
146 CleanupStack::Pop(iConfigStorage); |
|
147 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::BackupAndGetSettingsL() - return" ) ) ); |
121 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::BackupAndGetSettingsL() - return" ) ) ); |
148 } |
122 } |
149 |
123 |
150 // ----------------------------------------------------------------------------- |
124 // ----------------------------------------------------------------------------- |
151 // CPsmSettingsHandler::GetCurrentSettingsL |
125 // CPsmSettingsHandler::GetCurrentSettingsL |
250 |
224 |
251 TInt err( KErrNone ); |
225 TInt err( KErrNone ); |
252 // First, get current settings |
226 // First, get current settings |
253 RConfigInfoArray currentSettings; |
227 RConfigInfoArray currentSettings; |
254 CleanupClosePushL( currentSettings ); |
228 CleanupClosePushL( currentSettings ); |
255 |
229 |
256 //Close backup handler in case of any error |
|
257 CleanupStack::PushL(TCleanupItem(CleanupBackupStorage, iBackupStorage)); |
|
258 iBackupStorage->InitStorageL( aRepository ); |
230 iBackupStorage->InitStorageL( aRepository ); |
259 iBackupStorage->ListCurrentSettingSetL( currentSettings ); |
231 iBackupStorage->ListCurrentSettingSetL( currentSettings ); |
260 |
232 |
261 // Check currently owned settings and compare those to the new ones |
233 // Check currently owned settings and compare those to the new ones |
262 RConfigInfoArray settingsToBackUp; |
234 RConfigInfoArray settingsToBackUp; |
271 } |
243 } |
272 |
244 |
273 if ( !found ) |
245 if ( !found ) |
274 { |
246 { |
275 // Add new settings to backup |
247 // Add new settings to backup |
276 settingsToBackUp.AppendL( aPsmConfigArray[ i ] ); |
248 settingsToBackUp.Append( aPsmConfigArray[ i ] ); |
277 currentSettings.AppendL( aPsmConfigArray[ i ] ); |
249 currentSettings.Append( aPsmConfigArray[ i ] ); |
278 } |
250 } |
279 } |
251 } |
280 |
252 |
281 // Get new values from config |
253 // Get new values from config |
282 if ( EPsmsrvModeNormal == iMode ) |
254 if ( EPsmsrvModeNormal == iMode ) |
298 |
270 |
299 // Check for missing values and get those from backup |
271 // Check for missing values and get those from backup |
300 RConfigInfoArray settingsFromBackUp; |
272 RConfigInfoArray settingsFromBackUp; |
301 CleanupClosePushL( settingsFromBackUp ); |
273 CleanupClosePushL( settingsFromBackUp ); |
302 |
274 |
303 for ( TInt i = 0; currentSettings.Count() != i; ++i ) |
275 for ( TInt i = 0; currentSettings.Count() != i; i++ ) |
304 { |
276 { |
305 TPsmsrvConfigInfo& currentInfo = currentSettings[ i ]; |
277 TPsmsrvConfigInfo& currentInfo = currentSettings[ i ]; |
306 TBool found = EFalse; |
278 TBool found = EFalse; |
307 TPsmsrvConfigInfo newInfo; |
279 TPsmsrvConfigInfo newInfo; |
308 for ( TInt index = 0; !found && aPsmConfigArray.Count() != index; index++ ) |
280 for ( TInt index = 0; !found && aPsmConfigArray.Count() != index; index++ ) |
313 |
285 |
314 // Check was setting found |
286 // Check was setting found |
315 if ( !found ) |
287 if ( !found ) |
316 { |
288 { |
317 // not found, get setting from backup |
289 // not found, get setting from backup |
318 settingsFromBackUp.AppendL( currentInfo ); |
290 settingsFromBackUp.Append( currentInfo ); |
319 currentSettings.Remove( i ); |
291 currentSettings.Remove( i ); |
320 --i; |
292 i--; |
321 } |
293 } |
322 else |
294 else |
323 { |
295 { |
324 // Setting found, update values |
296 // Setting found, update values |
325 currentInfo = newInfo; |
297 currentInfo = newInfo; |
338 iBackupStorage->CloseStorageL(); |
310 iBackupStorage->CloseStorageL(); |
339 |
311 |
340 // add settings from backup to settings |
312 // add settings from backup to settings |
341 for ( TInt i = 0; i < settingsFromBackUp.Count(); i++ ) |
313 for ( TInt i = 0; i < settingsFromBackUp.Count(); i++ ) |
342 { |
314 { |
343 //Ignore the error returned by Append |
315 aPsmConfigArray.Append( settingsFromBackUp[ i ] ); |
344 aPsmConfigArray.Append( settingsFromBackUp[ i ]); |
|
345 } |
316 } |
346 |
317 |
347 // Cleanup config arrays |
318 // Cleanup config arrays |
348 CleanupStack::PopAndDestroy( &settingsFromBackUp ); |
319 CleanupStack::PopAndDestroy( &settingsFromBackUp ); |
349 CleanupStack::PopAndDestroy( &settingsToBackUp ); |
320 CleanupStack::PopAndDestroy( &settingsToBackUp ); |
350 CleanupStack::Pop( iBackupStorage ); |
|
351 CleanupStack::PopAndDestroy( ¤tSettings ); |
321 CleanupStack::PopAndDestroy( ¤tSettings ); |
352 |
322 |
353 User::LeaveIfError( err ); |
323 User::LeaveIfError( err ); |
354 |
324 |
355 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::ChangeSettingsL() - return" ) ) ); |
325 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::ChangeSettingsL() - return" ) ) ); |
376 { |
346 { |
377 RConfigInfoArray psmConfigArray; |
347 RConfigInfoArray psmConfigArray; |
378 CleanupClosePushL( psmConfigArray ); |
348 CleanupClosePushL( psmConfigArray ); |
379 |
349 |
380 const TUint32 repository = passiveConfigs[i]; |
350 const TUint32 repository = passiveConfigs[i]; |
381 //Close Cenrep handler in case of any error |
351 |
382 CleanupStack::PushL(TCleanupItem(CleanupStorage, iCenRepStorage)); |
|
383 iCenRepStorage->InitStorageL( repository ); |
352 iCenRepStorage->InitStorageL( repository ); |
384 |
353 |
385 if ( EPsmsrvModeNormal == iMode ) |
354 if ( EPsmsrvModeNormal == iMode ) |
386 { |
355 { |
387 //Close Cenrep handler in case of any error |
|
388 CleanupStack::PushL(TCleanupItem(CleanupBackupStorage, iBackupStorage)); |
|
389 // Moving to normal mode, get passive config set from baskup storage |
356 // Moving to normal mode, get passive config set from baskup storage |
390 iBackupStorage->InitStorageL( repository ); |
357 iBackupStorage->InitStorageL( repository ); |
391 iBackupStorage->ListPassiveConfigSetL( psmConfigArray ); |
358 iBackupStorage->ListPassiveConfigSetL( psmConfigArray ); |
392 iBackupStorage->CloseStorageL(); |
359 iBackupStorage->CloseStorageL(); |
393 CleanupStack::Pop( iBackupStorage ); |
|
394 } |
360 } |
395 else |
361 else |
396 { |
362 { |
397 // Get configuration set |
363 // Get configuration set |
398 iCenRepStorage->ListPassiveConfigSetL( psmConfigArray ); |
364 iCenRepStorage->ListPassiveConfigSetL( psmConfigArray ); |
401 // Change values |
367 // Change values |
402 ChangeCenRepSettingsL( psmConfigArray, repository ); |
368 ChangeCenRepSettingsL( psmConfigArray, repository ); |
403 |
369 |
404 // close storage |
370 // close storage |
405 iCenRepStorage->CloseStorageL(); |
371 iCenRepStorage->CloseStorageL(); |
406 CleanupStack::Pop( iCenRepStorage ); |
|
407 CleanupStack::PopAndDestroy( &psmConfigArray ); |
372 CleanupStack::PopAndDestroy( &psmConfigArray ); |
408 } |
373 } |
409 |
374 |
410 CleanupStack::PopAndDestroy( &passiveConfigs ); |
375 CleanupStack::PopAndDestroy( &passiveConfigs ); |
411 |
376 |