cbs/CbsServer/ServerSrc/CCbsBackupMonitor.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     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:  This module contains the implementation of CCbsBackupMonitor class 
       
    15 *                member functions.    
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CCbsBackupMonitor.h"
       
    22 #include <connect/sbdefs.h>
       
    23 #include "CbsLogger.h"
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KCbsBackupMask = 0xF;
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CCbsBackupMonitor::CCbsBackupMonitor
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CCbsBackupMonitor::CCbsBackupMonitor( CCbsDbImp& aDbImp )
       
    37     : CActive( EPriorityStandard ),
       
    38     iDbImp( aDbImp )
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CCbsBackupMonitor::ConstructL
       
    44 // Symbian 2nd phase constructor can leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 void CCbsBackupMonitor::ConstructL()
       
    48     {
       
    49     CBSLOGSTRING("CBSSERVER: >>> CCbsBackupMonitor::ConstructL()");
       
    50     
       
    51     CActiveScheduler::Add( this );
       
    52     
       
    53     // Attach to backup property    
       
    54     iProperty.Attach( KUidSystemCategory, conn::KUidBackupRestoreKey );    
       
    55     IssueRequest();
       
    56     
       
    57     CBSLOGSTRING("CBSSERVER: <<< CCbsBackupMonitor::ConstructL()");
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CCbsBackupMonitor::NewL
       
    62 // Two-phased constructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CCbsBackupMonitor* CCbsBackupMonitor::NewL( CCbsDbImp& aDbImp )
       
    66     {
       
    67     CCbsBackupMonitor* self = 
       
    68         new ( ELeave ) CCbsBackupMonitor( aDbImp );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop();
       
    72     return self;
       
    73     }
       
    74     
       
    75 // Destructor
       
    76 CCbsBackupMonitor::~CCbsBackupMonitor()
       
    77     {
       
    78     CBSLOGSTRING("CBSSERVER: >>> CCbsBackupMonitor::~CCbsBackupMonitor()");
       
    79     Cancel();
       
    80 	iProperty.Close();
       
    81 	CBSLOGSTRING("CBSSERVER: <<< CCbsBackupMonitor::~CCbsBackupMonitor()");
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCbsBackupMonitor::IssueRequest
       
    86 // Requests that we are notified when the system state changes.
       
    87 // (other items were commented in a header).
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CCbsBackupMonitor::IssueRequest() 
       
    91     {
       
    92     CBSLOGSTRING("CBSSERVER: >>> CCbsBackupMonitor::IssueRequest()");
       
    93     
       
    94     if ( !IsActive() )
       
    95         {
       
    96         // Subscribe again
       
    97     	iProperty.Subscribe( iStatus );
       
    98 	    SetActive();
       
    99 	    CBSLOGSTRING("CBSSERVER: CCbsBackupMonitor::IssueRequest(): New Subscribe() set active.");
       
   100         }
       
   101     CBSLOGSTRING("CBSSERVER: <<< CCbsBackupMonitor::IssueRequest()");
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CCbsBackupMonitor::RunL
       
   106 // Becomes active when the system state changes.
       
   107 // (other items were commented in a header).
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CCbsBackupMonitor::RunL()
       
   111     {
       
   112     CBSLOGSTRING("CBSSERVER: >>> CCbsBackupMonitor::RunL()");
       
   113     
       
   114     if ( iStatus == KErrNone )
       
   115         {        
       
   116         // Resubscribe before processing new value to prevent missing updates        
       
   117         IssueRequest();
       
   118         
       
   119         // Property updated, get new value
       
   120     	TInt state( 0 );
       
   121     	TInt backupState( 0 );
       
   122     	TInt error( KErrNone );
       
   123     	error = iProperty.Get( state );
       
   124     	CBSLOGSTRING2("CBSSERVER: CCbsBackupMonitor::RunL(): error: %d", error );
       
   125     	
       
   126     	if ( !error )
       
   127     	    {    	       	    
       
   128     	    backupState = ( state &= KCbsBackupMask );
       
   129     	    
       
   130         	// States are from sbdefs.h
       
   131         	switch ( backupState )
       
   132         	    {
       
   133         	    // No backup or restore ongoing
       
   134         	    case conn::EBURUnset:
       
   135         	    case conn::EBURNormal:
       
   136         	        {
       
   137         	        CBSLOGSTRING("CBSSERVER: CCbsBackupMonitor::RunL(): EBURUnset or EBURNormal" );
       
   138         	        iDbImp.ChangeFileLocksL( ECbsNoBackup );
       
   139         	        }    	        
       
   140         	        break;
       
   141         	    // Backup, release file locks
       
   142         	    case conn::EBURBackupFull:
       
   143         	    case conn::EBURBackupPartial:
       
   144         	        {
       
   145         	        CBSLOGSTRING("CBSSERVER: CCbsBackupMonitor::RunL(): EBURBackupFull or EBURBackupPartial" );
       
   146         	        iDbImp.ChangeFileLocksL( ECbsBackup );
       
   147         	        }    	        
       
   148         	        break;
       
   149         	    // Restore, release file locks
       
   150         	    case conn::EBURRestoreFull:
       
   151         	    case conn::EBURRestorePartial:
       
   152         	        {
       
   153         	        CBSLOGSTRING("CBSSERVER: CCbsBackupMonitor::RunL(): EBURRestoreFull or EBURRestorePartial" );
       
   154         	        iDbImp.ChangeFileLocksL( ECbsRestore );
       
   155         	        }
       
   156         	        break;
       
   157         	    default:
       
   158         	        CBSLOGSTRING("CBSSERVER: CCbsBackupMonitor::RunL(): Default" );
       
   159         	        break;
       
   160         	    }
       
   161     	    }
       
   162         }
       
   163     CBSLOGSTRING("CBSSERVER: <<< CCbsBackupMonitor::RunL()");
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CCbsBackupMonitor::DoCancel
       
   168 // Cancels an outstanding Subscribe request.  
       
   169 // (other items were commented in a header).
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CCbsBackupMonitor::DoCancel()
       
   173     {
       
   174     CBSLOGSTRING("CBSSERVER: >>> CCbsBackupMonitor::DoCancel()");
       
   175     iProperty.Cancel();   
       
   176     CBSLOGSTRING("CBSSERVER: <<< CCbsBackupMonitor::DoCancel()");
       
   177     }
       
   178 
       
   179 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   180 
       
   181 //  End of File