summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntsrv/inc/ccntbackuprestoreagent.h
blob: f7aa672800864e2d143be11fd70fccb0f66876a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#ifndef __CCNTBACKUPRESTOREAGENT_H__
#define __CCNTBACKUPRESTOREAGENT_H__


#include <e32base.h> // for cactive.
#include <e32property.h> // for rproperty.

#include <cntdbobs.h> // for tcontactdbobserverevent 


// Forward class references.
class CCntDbManagerController;


/**
	All interaction with the SBEngine component is through this class.  This
	class is owned by CCntDbManagerController primarily due to the need to
	propagate notification events from the SBEngine to all of the CCntDbManager.

	This class implements the behaviours required by the SBEngine component:

	- SBEngine Notification Observer
	- Registration File Management

	In addition the following behaviours are implemented:
		
	- Store/recall of Contacts Model initialisation file using CIniFileManager
	  at appropriate times during Backup/Restore

	@internalComponent
	@released
*/
class CCntBackupRestoreAgent : public CActive
	{
public:
	static CCntBackupRestoreAgent* NewL(RFs& aFs, CCntDbManagerController& aDbMgrCtrlr);
	~CCntBackupRestoreAgent();

	void StartL();
	
	TBool BackupInProgress() const;
	TBool RestoreInProgress() const;
	
	void CreateBackupRegistrationFileL(const TDesC& aFileName);
	void DeleteBackupRegistrationFileL(const TDesC& aFileName);
	HBufC* CreateBackupRegistrationFileNameLC(const TDesC& aFileName);
	
private:
	CCntBackupRestoreAgent(RFs& aFs, CCntDbManagerController& aDbMgrCtrlr);
	
	void RunL();
	TInt RunError(TInt aError);
	void DoCancel();

	void ReceivedNotificationL(TInt aNewState);
	void ProcessInitialStateL(TInt aNewState);

	void BackupBeginningL();
	void BackupCompletedL();
	void RestoreBeginningL();
	void RestoreCompletedL(TInt aRestoreResult);

		
private:
	RFs& iFs;
	
	/**
	Used to subscribe to the SBEngine P&S property KUidBackupRestoreKey.  The
	SBEngine uses the property KUidBackupRestoreKey to notify subscribers of
	Backup/Restore events.
	*/
	RProperty iBackupRestoreNotification;

	/**
	Current state of B&R.  Used to store the B&R flags supplied by the value
	of the property KUidBackupRestoreKey.
	*/
	TInt iCurrentState;

	/**
	Contacts database observer event.  The event type is changed depending on
	the notification received from the SBEngine before being forwarded to all
	Contacts Model clients (via the CCntDbManagerController singleton).
	*/
	TContactDbObserverEventV2 iEvent;
	
	/**
	Used to broadcast Backup/Restore events to all instances of CCntDbManager
	and to access CIniFileManager singleton owned by CCntDbManagerController
	singleton so that operations on Contacts Model initialisation file can
	be carried out as part of Backup/Restore activity.
	*/
	CCntDbManagerController& iDbMgrCtrlr;
	
private:
	static const TInt KMaxFileNameLength;
	};

	
#endif //__CCCNTBACKUPRESTOREAGENT_H__