srsf/sisrscontrollerplugin/src/nssbackupobserver.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Watches changes of the PC-Suite data sync state
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "nssbackupobserver.h"
       
    20 #include "rubydebug.h"
       
    21 
       
    22 #include <sbdefs.h>
       
    23 
       
    24 // ---------------------------------------------------------
       
    25 // CNssTag::NewL
       
    26 // NewL
       
    27 // ---------------------------------------------------------
       
    28 //
       
    29 CNssBackupObserver* CNssBackupObserver::NewL( CSIDatabase& aDb )
       
    30     {
       
    31     CNssBackupObserver* self = new (ELeave) CNssBackupObserver( aDb );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37     
       
    38 // ---------------------------------------------------------
       
    39 // CNssBackupObserver::CNssBackupObserver
       
    40 // C++ constructor can NOT contain any code, that might leave.
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 CNssBackupObserver::CNssBackupObserver( CSIDatabase& aDb ) :
       
    44     CActive( CActive::EPriorityHigh ),
       
    45     iDb( aDb )
       
    46     {
       
    47     // Nothing
       
    48     }
       
    49     
       
    50 // ---------------------------------------------------------
       
    51 // CNssBackupObserver::ConstructL
       
    52 // C++ constructor can NOT contain any code, that might leave.
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 void CNssBackupObserver::ConstructL() 
       
    56     {
       
    57     RUBY_DEBUG_BLOCK( "CNssBackupObserver::ConstructL" );
       
    58     User::LeaveIfError( iProperty.Attach( KUidSystemCategory, conn::KUidBackupRestoreKey ) );
       
    59     
       
    60     // check the current value
       
    61     TInt backupFlag( conn::EBURUnset ); 
       
    62 	User::LeaveIfError( iProperty.Get( backupFlag ) );
       
    63 	
       
    64     switch ( backupFlag & conn::KBURPartTypeMask )
       
    65 	    {
       
    66 	    case conn::EBURNormal:
       
    67 	        // normal nothing to do
       
    68 	        break;
       
    69 	        
       
    70 	    case conn::EBURBackupFull:
       
    71 	    case conn::EBURBackupPartial:
       
    72 	    case conn::EBURRestoreFull:
       
    73 	    case conn::EBURRestorePartial:
       
    74 	        // Lock the use of database
       
    75 	        RUBY_DEBUG0( "CNssBackupObserver::ConstructL Lock transactions" );
       
    76 	        iDb.LockTransactionsL();
       
    77 	        break;
       
    78 	        
       
    79 	    case conn::EBURUnset:
       
    80 	    default:
       
    81 	        RUBY_DEBUG0( "CNssBackupObserver::ConstructL unknown value" );
       
    82 	    }   
       
    83 	     
       
    84     // initial subscription and process current property value
       
    85     iProperty.Subscribe( iStatus );
       
    86     
       
    87     CActiveScheduler::Add( this ); 
       
    88     SetActive();   
       
    89     }
       
    90     
       
    91 // ---------------------------------------------------------
       
    92 // CNssBackupObserver::~CNssBackupObserver
       
    93 // Destructor
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 CNssBackupObserver::~CNssBackupObserver()
       
    97     {
       
    98     Cancel();
       
    99     iProperty.Close();
       
   100     }
       
   101 // ---------------------------------------------------------
       
   102 // CNssBackupObserver::DoCancel
       
   103 // Cancel listening now
       
   104 // ---------------------------------------------------------
       
   105 //    
       
   106 void CNssBackupObserver::DoCancel() 
       
   107     {
       
   108     iProperty.Cancel();
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CNssBackupObserver::RunL
       
   113 // Is called, when property changed
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 void CNssBackupObserver::RunL()
       
   117     {
       
   118     RUBY_DEBUG_BLOCK( "CNssBackupObserver::RunL" );
       
   119     
       
   120     if( iStatus != KErrNone ) 
       
   121         {
       
   122         // At least report the error
       
   123         RUBY_ERROR1( "CNssBackupObserver::RunL iStatus is [%d]", iStatus.Int() );
       
   124         }
       
   125         
       
   126     // resubscribe before processing new value to prevent missing updates
       
   127     // even if some error happened
       
   128     iProperty.Subscribe( iStatus );
       
   129     SetActive();
       
   130     // property updated, get new value
       
   131 	TInt backupFlag;
       
   132 	User::LeaveIfError( iProperty.Get( backupFlag ) );
       
   133 	switch ( backupFlag & conn::KBURPartTypeMask )
       
   134 	    {
       
   135 	    case conn::EBURNormal:
       
   136 	        // Database can be used again
       
   137 	        RUBY_DEBUG0( "CNssBackupObserver::RunL Unlock transactions" );
       
   138 	        iDb.UnlockTransactionsL();
       
   139 	        break;
       
   140 	        
       
   141 	    case conn::EBURBackupFull:
       
   142 	    case conn::EBURBackupPartial:
       
   143 	    case conn::EBURRestoreFull:
       
   144 	    case conn::EBURRestorePartial:
       
   145 	        // Lock the use of database
       
   146 	        RUBY_DEBUG0( "CNssBackupObserver::RunL Lock transactions" );
       
   147 	        iDb.LockTransactionsL();
       
   148 	        break;
       
   149 	        
       
   150 	    case conn::EBURUnset:
       
   151 	    default:
       
   152 	        RUBY_ERROR1( "CNssBackupObserver::RunL backup flag unknown %h ", backupFlag );
       
   153 	    }
       
   154     }
       
   155 
       
   156 //  End of File