syncmlfw/common/sosserver/src/NSmlSOSBackup.cpp
changeset 0 b497e44ab2fc
child 54 085438c28042
child 58 4af31167ea77
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Symbian OS Server source.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sbdefs.h>
       
    20 #include <d32dbms.h>
       
    21 #include <nsmldebug.h>
       
    22 #include "nsmlsosserver.h"
       
    23 #include "nsmlagentlog.h"
       
    24 // --------------------------------------------------------------------------
       
    25 // CNSmlSOSBackup* CNSmlSOSBackup::NewL( CNSmlSOSHandler* aHandler )
       
    26 // --------------------------------------------------------------------------
       
    27 //
       
    28 CNSmlSOSBackup* CNSmlSOSBackup::NewL( CNSmlSOSHandler* aHandler )
       
    29 	{
       
    30 	CNSmlSOSBackup* self = new (ELeave) CNSmlSOSBackup( aHandler );
       
    31 	CleanupStack::PushL(self);
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop(); // self
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 // --------------------------------------------------------------------------
       
    38 // CNSmlSOSBackup::CNSmlSOSBackup( CNSmlSOSHandler* aHandler )
       
    39 // --------------------------------------------------------------------------
       
    40 //
       
    41 CNSmlSOSBackup::CNSmlSOSBackup( CNSmlSOSHandler* aHandler ) :
       
    42     CActive( EPriorityNormal ),
       
    43     iHandler( aHandler ),
       
    44     iRestoring( EFalse )
       
    45 	{
       
    46     CActiveScheduler::Add(this);
       
    47 	}
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // void CNSmlSOSBackup::Subscribe()
       
    51 // --------------------------------------------------------------------------
       
    52 //
       
    53 void CNSmlSOSBackup::Subscribe()
       
    54     {
       
    55     if ( !IsActive() )
       
    56         {
       
    57         iProperty.Subscribe( iStatus );    
       
    58         SetActive();
       
    59         }
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // void CNSmlSOSBackup::ConstructL()
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 void CNSmlSOSBackup::ConstructL()
       
    67     {
       
    68     iProperty.Attach( KUidSystemCategory, conn::KUidBackupRestoreKey );
       
    69     Subscribe();    
       
    70     TInt currValue(0);
       
    71     iProperty.Get( currValue );
       
    72     
       
    73     if ( currValue && currValue != ( conn::EBURNormal | conn::ENoBackup ) )
       
    74         {
       
    75         iHandler->ServerSuspendedL( ETrue );
       
    76         }
       
    77 
       
    78    	BackUpModeL();
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CNSmlSOSBackup::~CNSmlSOSBackup()
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 CNSmlSOSBackup::~CNSmlSOSBackup()
       
    86 	{
       
    87     Cancel();
       
    88     iProperty.Close();
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // void CNSmlSOSBackup::RunL()
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 void CNSmlSOSBackup::RunL()
       
    96     {
       
    97     _DBG_FILE("CNSmlSOSBackup::RunL() : Begin");
       
    98     Subscribe();
       
    99 
       
   100     TInt value(0);
       
   101     iProperty.Get( value );
       
   102     
       
   103     const conn::TBURPartType partType =
       
   104             static_cast<conn::TBURPartType>( value & conn::KBURPartTypeMask );
       
   105     if ( partType && partType != ( conn::EBURUnset | conn::EBURNormal ) )
       
   106         {
       
   107         _DBG_FILE("CNSmlSOSBackup::RunL() :: Before BackUpModeL");
       
   108         BackUpModeL();
       
   109         iHandler->ServerSuspendedL( ETrue );
       
   110         _DBG_FILE("CNSmlSOSBackup::RunL() :: After BackUpModeL");
       
   111         }
       
   112     else
       
   113         {
       
   114         if ( iRestoring )
       
   115             {
       
   116             _DBG_FILE("Before : ->DeleteDataInRestoreL()");
       
   117     		TRAP_IGNORE( DeleteDataInRestoreL() );
       
   118     		_DBG_FILE("After  : ->DeleteDataInRestoreL()");
       
   119     		
       
   120     		_DBG_FILE("Ending restoring");
       
   121     		iRestoring = EFalse;
       
   122             }
       
   123         iHandler->ServerSuspendedL( EFalse );
       
   124         }
       
   125         
       
   126     _DBG_FILE("CNSmlSOSBackup::RunL() : End");
       
   127     }
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 // void CNSmlSOSBackup::DoCancel()
       
   131 // --------------------------------------------------------------------------
       
   132 //
       
   133 void CNSmlSOSBackup::DoCancel()
       
   134     {
       
   135     iProperty.Cancel();
       
   136     }
       
   137 
       
   138 // --------------------------------------------------------------------------
       
   139 // void CNSmlSOSBackup::BackUpModeL()
       
   140 // --------------------------------------------------------------------------
       
   141 //
       
   142 void CNSmlSOSBackup::BackUpModeL()
       
   143 	{
       
   144 	_DBG_FILE("CNSmlSOSBackup::BackUpModeL() : Begin");
       
   145 	
       
   146 	TInt value(0);
       
   147     iProperty.Get( value );
       
   148     
       
   149     //Get the type of current backup process
       
   150     const conn::TBURPartType partType =
       
   151             static_cast<conn::TBURPartType>( value & conn::KBURPartTypeMask );
       
   152 	    
       
   153 	conn::CActiveBackupClient* client = conn::CActiveBackupClient::NewL();
       
   154 	CleanupStack::PushL( client );
       
   155 	
       
   156 	_DBG_FILE("Before : ->ConfirmReadyForBURL()");
       
   157 	client->ConfirmReadyForBURL( KErrNone );
       
   158 	_DBG_FILE("After : ->ConfirmReadyForBURL()");
       
   159 	
       
   160 	if ( ( partType == conn::EBURRestoreFull ) ||
       
   161 	     ( partType == conn::EBURRestorePartial ) )
       
   162 		{
       
   163 		_DBG_FILE("Started restoring");
       
   164 		iRestoring = ETrue;
       
   165 		}
       
   166 		
       
   167 	CleanupStack::PopAndDestroy( client ); //client
       
   168 			
       
   169 	_DBG_FILE("CNSmlSOSBackup::BackUpModeL() : End");
       
   170 	}
       
   171 
       
   172 // --------------------------------------------------------------------------
       
   173 // void CNSmlSOSBackup::DeleteDataInRestoreL()
       
   174 // --------------------------------------------------------------------------
       
   175 //
       
   176 void CNSmlSOSBackup::DeleteDataInRestoreL()
       
   177 	{
       
   178 	_DBG_FILE("CNSmlSOSBackup::DeleteDataInRestore() : Begin");	
       
   179 
       
   180     RDbs database;
       
   181     User::LeaveIfError( database.Connect() );
       
   182     CleanupClosePushL( database );
       
   183     TParse name;
       
   184 
       
   185 #ifdef SYMBIAN_SECURE_DBMS
       
   186 	name.Set( KNSmlAgentLogDbName(), NULL, NULL );
       
   187 #else
       
   188     name.Set( KNSmlAgentLogDbName(), KNSmlDatabasesNonSecurePath, NULL );
       
   189 #endif
       
   190     
       
   191     TInt error = database.DeleteDatabase( name.FullName(), KNSmlSOSServerPolicyUID );
       
   192     CleanupStack::PopAndDestroy( &database ); // database
       
   193     
       
   194     if ( error != KErrNone && error != KErrNotFound )
       
   195         {
       
   196         _DBG_FILE("CNSmlSOSBackup::DeleteDataInRestore() : End with error");
       
   197         User::Leave( error );
       
   198         }
       
   199      // update the settings db
       
   200      CNSmlDSSettings* settings = CNSmlDSSettings::NewLC();
       
   201      settings->UpdateHiddenProfilesL();
       
   202      CleanupStack::PopAndDestroy(); //settings
       
   203      CNSmlDMSettings* dmsettings = CNSmlDMSettings::NewLC();
       
   204      dmsettings->ScanAndRepairRestoredProfilesL();
       
   205      CleanupStack::PopAndDestroy(); //dmsettings
       
   206 	
       
   207 	_DBG_FILE("CNSmlSOSBackup::DeleteDataInRestore() : End");			
       
   208 	}
       
   209 	
       
   210 
       
   211 //  End of File