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