pimappservices/calendar/server/src/agsbackuprestoreagent.cpp
changeset 0 f979ecb2b13e
child 31 97232defd20e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "agsbackuprestoreagent.h"
       
    17 #include <connect/sbdefs.h> // For conn::EBURNormal etc.
       
    18 
       
    19 CAgnServBackupRestoreAgent* CAgnServBackupRestoreAgent::NewL(CAgnServFileMgr& aFileMgr)
       
    20 	{
       
    21 	CAgnServBackupRestoreAgent* self = new(ELeave) CAgnServBackupRestoreAgent(aFileMgr);
       
    22 	return self;
       
    23 	}
       
    24 
       
    25 CAgnServBackupRestoreAgent::~CAgnServBackupRestoreAgent()
       
    26 	{
       
    27 	Cancel();
       
    28 	iBackupRestoreNotification.Close();
       
    29 	}
       
    30 
       
    31 CAgnServBackupRestoreAgent::CAgnServBackupRestoreAgent(CAgnServFileMgr& aFileMgr)
       
    32 	: CActive(CActive::EPriorityStandard), iFileMgr(aFileMgr)
       
    33 	{
       
    34 	CActiveScheduler::Add(this);
       
    35 	
       
    36 	// Attach and subscribe to the Backup/Restore property used by the SBEngine
       
    37 	// component.
       
    38 	iBackupRestoreNotification.Attach(KUidSystemCategory, conn::KUidBackupRestoreKey);
       
    39 	iBackupRestoreNotification.Subscribe(iStatus);
       
    40 	}
       
    41 
       
    42 /** Indicates if a Backup operation is currently in progress.
       
    43 @return ETrue if operation in progress else EFalse.
       
    44 */
       
    45 TBool CAgnServBackupRestoreAgent::BackupInProgress() const
       
    46 	{
       
    47 	return (iCurrentState & (conn::EBURBackupPartial | conn::EBURBackupFull));
       
    48 	}
       
    49 
       
    50 /** Indicates if a Restore operation is currently in progress.
       
    51 @return	ETrue if operation in progress else EFalse.
       
    52 */
       
    53 TBool CAgnServBackupRestoreAgent::RestoreInProgress() const
       
    54 	{
       
    55 	return (iCurrentState & (conn::EBURRestorePartial | conn::EBURRestoreFull));
       
    56 	}
       
    57 
       
    58 /** Instructs the agent to listen for backup or restore events. */
       
    59 void CAgnServBackupRestoreAgent::Start()
       
    60 	{
       
    61 	// Check to see if a Backup/Restore is currently in progress.
       
    62 	TInt newState = 0;
       
    63 	if (iBackupRestoreNotification.Get(newState) != KErrNotFound)
       
    64 		{
       
    65 		iCurrentState = newState;
       
    66 		}
       
    67 	SetActive();
       
    68 	}
       
    69 
       
    70 /**
       
    71 Called when a backup or restore event is received.
       
    72 
       
    73 When a backup or restore event is received we change the state so that BackupInProgress() and
       
    74 RestoreInProgress() return the correct state. These functions will be queried when a file is being closed
       
    75 to check if they should be closed immediately or after a small delay.
       
    76 
       
    77 In addition to this we also call CloseScheduledFilesNow() on the file manager to close all files that have
       
    78 been scheduled for close so they are closed immediately.
       
    79 */
       
    80 void CAgnServBackupRestoreAgent::RunL()
       
    81 	{
       
    82 	// Resubscribe before dealing with the current notification.
       
    83 	iBackupRestoreNotification.Subscribe(iStatus);
       
    84 	SetActive();
       
    85 
       
    86 	TInt newState = 0;
       
    87 	
       
    88 	// Flag updated.
       
    89 	if (iBackupRestoreNotification.Get(newState) != KErrNotFound)
       
    90 		{
       
    91 		if ( newState& (conn::EBURBackupPartial | conn::EBURBackupFull) && !BackupInProgress())
       
    92             {
       
    93             iFileMgr.CloseScheduledFilesImmediately();
       
    94             iFileMgr.BackupReStoreChanged(MCalChangeCallBack2::EBackupStart);
       
    95             }
       
    96         else if (newState & (conn::EBURRestoreFull | conn::EBURRestorePartial)&& !RestoreInProgress())
       
    97             {
       
    98             iFileMgr.CloseScheduledFilesImmediately();
       
    99             iFileMgr.BackupReStoreChanged(MCalChangeCallBack2::ERestoreStart);      
       
   100             }
       
   101         else if (newState & (conn::EBURNormal | conn::EBURUnset) && BackupInProgress())
       
   102             {
       
   103             iFileMgr.BackupReStoreChanged(MCalChangeCallBack2::EBackupEnd); 
       
   104             }
       
   105         else if (newState & (conn::EBURNormal | conn::EBURUnset) && RestoreInProgress())
       
   106             {
       
   107             iFileMgr.BackupReStoreChanged(MCalChangeCallBack2::ERestoreEnd); 
       
   108             }
       
   109 		iCurrentState = newState;
       
   110 		}
       
   111 	}
       
   112 
       
   113 /** Called when an error occurs. If an error occurs we will not be notified of backup or restore 
       
   114 events. This may cause problems during backup and restore but terminating the server is excessive as
       
   115 it can continue normal operation. */
       
   116 TInt CAgnServBackupRestoreAgent::RunError(TInt /*aError*/)
       
   117 	{
       
   118 	return KErrNone;
       
   119 	}
       
   120 
       
   121 void CAgnServBackupRestoreAgent::DoCancel()
       
   122 	{
       
   123 	iBackupRestoreNotification.Cancel();
       
   124 	}