psmservices/psmserver/src/engine/psmsettingshandler.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 0 4e1aa6a622a0
child 22 8cb079868133
--- a/psmservices/psmserver/src/engine/psmsettingshandler.cpp	Thu Aug 19 11:09:10 2010 +0300
+++ b/psmservices/psmserver/src/engine/psmsettingshandler.cpp	Tue Aug 31 16:29:05 2010 +0300
@@ -25,6 +25,29 @@
 #include "psmtrace.h"
 
 // -----------------------------------------------------------------------------
+// CloseHandler
+// closes the storage handler
+// -----------------------------------------------------------------------------
+//
+void CleanupStorage(TAny* aPtr)
+    {
+    CPsmStorage* self = static_cast<CPsmStorage*> (aPtr);
+    //Ignore the Trap as Cleanup can't leave.
+    TRAP_IGNORE(self->CloseStorageL());
+    }
+
+// -----------------------------------------------------------------------------
+// CloseHandler
+// closes the backup storage handler
+// -----------------------------------------------------------------------------
+//
+void CleanupBackupStorage(TAny* aPtr)
+    {
+    CPsmBackupStorage* self = static_cast<CPsmBackupStorage*> (aPtr);
+    //Ignore the Trap as Cleanup can't leave.
+    TRAP_IGNORE(self->CloseStorageL());
+    }
+	
 // CPsmSettingsHandler::NewL
 // Two-phased constructor.
 // -----------------------------------------------------------------------------
@@ -114,10 +137,13 @@
     RConfigInfoArray& aPsmConfigArray, TUint32 aRepository )
     {
     COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::BackupAndGetSettingsL()" ) ) );
+    //Close config handle in case of any error
+    CleanupStack::PushL(TCleanupItem(CleanupStorage, iConfigStorage));
     // Change settings from normal config storage
     iConfigStorage->InitStorageL( aRepository );
     ChangeSettingsL( aPsmConfigArray, aRepository, *iConfigStorage );
     iConfigStorage->CloseStorageL();
+    CleanupStack::Pop(iConfigStorage);
     COMPONENT_TRACE( ( _L( "PSM Server - CPsmSettingsHandler::BackupAndGetSettingsL() - return" ) ) );
     }
 
@@ -226,7 +252,9 @@
     // First, get current settings
     RConfigInfoArray currentSettings;
     CleanupClosePushL( currentSettings );
-
+    
+    //Close backup handler in case of any error
+    CleanupStack::PushL(TCleanupItem(CleanupBackupStorage, iBackupStorage));
     iBackupStorage->InitStorageL( aRepository );
     iBackupStorage->ListCurrentSettingSetL( currentSettings );
 
@@ -245,8 +273,8 @@
         if ( !found )
             {
             // Add new settings to backup
-            settingsToBackUp.Append( aPsmConfigArray[ i ] );
-            currentSettings.Append( aPsmConfigArray[ i ] );
+            settingsToBackUp.AppendL( aPsmConfigArray[ i ] );
+            currentSettings.AppendL( aPsmConfigArray[ i ] );
             }
         }
 
@@ -272,7 +300,7 @@
     RConfigInfoArray settingsFromBackUp;
     CleanupClosePushL( settingsFromBackUp );
 
-    for ( TInt i = 0; currentSettings.Count() != i; i++ )
+    for ( TInt i = 0; currentSettings.Count() != i; ++i )
         {
         TPsmsrvConfigInfo& currentInfo = currentSettings[ i ];
         TBool found = EFalse;
@@ -287,9 +315,9 @@
         if ( !found )
             {
             // not found, get setting from backup
-            settingsFromBackUp.Append( currentInfo );
+            settingsFromBackUp.AppendL( currentInfo );
             currentSettings.Remove( i );
-            i--;
+            --i;
             }
         else
             {
@@ -312,12 +340,14 @@
     // add settings from backup to settings
     for ( TInt i = 0; i < settingsFromBackUp.Count(); i++ )
         {
-        aPsmConfigArray.Append( settingsFromBackUp[ i ] );
+        //Ignore the error returned by Append  
+        aPsmConfigArray.Append( settingsFromBackUp[ i ]);
         }
 
     // Cleanup config arrays
     CleanupStack::PopAndDestroy( &settingsFromBackUp );
     CleanupStack::PopAndDestroy( &settingsToBackUp );
+    CleanupStack::Pop( iBackupStorage );
     CleanupStack::PopAndDestroy( &currentSettings );
 
     User::LeaveIfError( err );
@@ -348,15 +378,19 @@
         CleanupClosePushL( psmConfigArray );
 
         const TUint32 repository = passiveConfigs[i];
-
+        //Close Cenrep handler in case of any error
+        CleanupStack::PushL(TCleanupItem(CleanupStorage, iCenRepStorage));
         iCenRepStorage->InitStorageL( repository );
 
         if ( EPsmsrvModeNormal == iMode )
             {
+            //Close Cenrep handler in case of any error
+    		CleanupStack::PushL(TCleanupItem(CleanupBackupStorage, iBackupStorage));	
             // Moving to normal mode, get passive config set from baskup storage
             iBackupStorage->InitStorageL( repository );
             iBackupStorage->ListPassiveConfigSetL( psmConfigArray );
             iBackupStorage->CloseStorageL();
+            CleanupStack::Pop( iBackupStorage );
             }
         else
             {
@@ -369,6 +403,7 @@
 
         // close storage
         iCenRepStorage->CloseStorageL();
+        CleanupStack::Pop( iCenRepStorage );
         CleanupStack::PopAndDestroy( &psmConfigArray );
         }