contentstorage/srvsrc/cabackupnotifier.cpp
author hgs
Fri, 06 Aug 2010 13:40:46 +0300
changeset 107 b34d53f6acdf
child 127 7b66bc3c6dc9
permissions -rw-r--r--
201031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
107
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description:  ?Description
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <e32base.h>
hgs
parents:
diff changeset
    19
#include <sacls.h>
hgs
parents:
diff changeset
    20
#include <connect/sbdefs.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include "cabackupnotifier.h"
hgs
parents:
diff changeset
    23
#include "castorageproxy.h"
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    26
//
hgs
parents:
diff changeset
    27
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    28
//
hgs
parents:
diff changeset
    29
CCaBackupNotifier* CCaBackupNotifier::NewL( CCaStorageProxy* aStorageProxy )
hgs
parents:
diff changeset
    30
    {
hgs
parents:
diff changeset
    31
    CCaBackupNotifier* self = new ( ELeave ) CCaBackupNotifier( aStorageProxy );
hgs
parents:
diff changeset
    32
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    33
    self->ConstructL( );
hgs
parents:
diff changeset
    34
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
    35
    return self;
hgs
parents:
diff changeset
    36
    }
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    39
//
hgs
parents:
diff changeset
    40
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    41
//
hgs
parents:
diff changeset
    42
CCaBackupNotifier::~CCaBackupNotifier()
hgs
parents:
diff changeset
    43
    {
hgs
parents:
diff changeset
    44
    Cancel();
hgs
parents:
diff changeset
    45
    iProperty.Close();
hgs
parents:
diff changeset
    46
    }
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    49
//
hgs
parents:
diff changeset
    50
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    51
//
hgs
parents:
diff changeset
    52
CCaBackupNotifier::CCaBackupNotifier( CCaStorageProxy* aStorageProxy ) :
hgs
parents:
diff changeset
    53
    CActive( EPriorityNormal ),
hgs
parents:
diff changeset
    54
    iStorageProxy( aStorageProxy ),
hgs
parents:
diff changeset
    55
    iLastState(0)
hgs
parents:
diff changeset
    56
    {
hgs
parents:
diff changeset
    57
    iProperty.Attach( KUidSystemCategory, KUidBackupRestoreKey );
hgs
parents:
diff changeset
    58
    CActiveScheduler::Add( this );
hgs
parents:
diff changeset
    59
    iStatus = KRequestPending;
hgs
parents:
diff changeset
    60
    iProperty.Subscribe( iStatus );
hgs
parents:
diff changeset
    61
    SetActive();
hgs
parents:
diff changeset
    62
    }
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    65
//
hgs
parents:
diff changeset
    66
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    67
//
hgs
parents:
diff changeset
    68
void CCaBackupNotifier::ConstructL(  )
hgs
parents:
diff changeset
    69
    {
hgs
parents:
diff changeset
    70
hgs
parents:
diff changeset
    71
    }
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    74
//
hgs
parents:
diff changeset
    75
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    76
//
hgs
parents:
diff changeset
    77
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
    78
#pragma CTC SKIP
hgs
parents:
diff changeset
    79
#endif //COVERAGE_MEASUREMENT (calls another method)
hgs
parents:
diff changeset
    80
void CCaBackupNotifier::DoCancel()
hgs
parents:
diff changeset
    81
    {
hgs
parents:
diff changeset
    82
    iProperty.Cancel();
hgs
parents:
diff changeset
    83
    }
hgs
parents:
diff changeset
    84
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
    85
#pragma CTC ENDSKIP
hgs
parents:
diff changeset
    86
#endif //COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
    87
hgs
parents:
diff changeset
    88
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    89
//
hgs
parents:
diff changeset
    90
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    91
//
hgs
parents:
diff changeset
    92
void CCaBackupNotifier::RunL()
hgs
parents:
diff changeset
    93
    {
hgs
parents:
diff changeset
    94
	TInt backupStateValue = 0;
hgs
parents:
diff changeset
    95
	iProperty.Get(backupStateValue);
hgs
parents:
diff changeset
    96
	// Resubscribe before dealing with the current notification 	
hgs
parents:
diff changeset
    97
    iProperty.Subscribe(iStatus);
hgs
parents:
diff changeset
    98
    SetActive();
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
    conn::TBURPartType type = static_cast< conn::TBURPartType >
hgs
parents:
diff changeset
   101
        ( backupStateValue & conn::KBURPartTypeMask );
hgs
parents:
diff changeset
   102
    
hgs
parents:
diff changeset
   103
    if( type == conn::EBURRestoreFull || type == conn::EBURRestorePartial  )
hgs
parents:
diff changeset
   104
    	{
hgs
parents:
diff changeset
   105
        // restore starting
hgs
parents:
diff changeset
   106
        iLastState = ECaRestore;
hgs
parents:
diff changeset
   107
    	}
hgs
parents:
diff changeset
   108
    else if( type == conn::EBURBackupFull || type == conn::EBURBackupPartial )
hgs
parents:
diff changeset
   109
    	{
hgs
parents:
diff changeset
   110
        // backup starting
hgs
parents:
diff changeset
   111
        iStorageProxy->SaveDatabaseL();
hgs
parents:
diff changeset
   112
        iLastState = ECaBackup;
hgs
parents:
diff changeset
   113
    	}
hgs
parents:
diff changeset
   114
    else if( ( type == conn::EBURNormal || type == conn::EBURUnset ) && iLastState == ECaRestore )
hgs
parents:
diff changeset
   115
    	{ // restore ends
hgs
parents:
diff changeset
   116
        iStorageProxy->RestoreDatabaseL();
hgs
parents:
diff changeset
   117
    	}
hgs
parents:
diff changeset
   118
    else if( ( type == conn::EBURNormal || type == conn::EBURUnset ) && iLastState == ECaBackup )
hgs
parents:
diff changeset
   119
    	{ // backup ends
hgs
parents:
diff changeset
   120
         // do nothing
hgs
parents:
diff changeset
   121
    	}
hgs
parents:
diff changeset
   122
    }
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
hgs
parents:
diff changeset
   125
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
   126
#pragma CTC SKIP
hgs
parents:
diff changeset
   127
#endif //COVERAGE_MEASUREMENT (calls another method)
hgs
parents:
diff changeset
   128
TInt CCaBackupNotifier::RunError( TInt /*aError*/)
hgs
parents:
diff changeset
   129
    {
hgs
parents:
diff changeset
   130
    // No need to do anything
hgs
parents:
diff changeset
   131
    return KErrNone;
hgs
parents:
diff changeset
   132
    }
hgs
parents:
diff changeset
   133
#ifdef COVERAGE_MEASUREMENT
hgs
parents:
diff changeset
   134
#pragma CTC ENDSKIP
hgs
parents:
diff changeset
   135
#endif //COVERAGE_MEASUREMENT