|
1 // Copyright (c) 2004-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 "CBackupRestoreNotification.h" |
|
17 |
|
18 |
|
19 /** Default constructor. |
|
20 * @param aCallback reference to observer class object. |
|
21 */ |
|
22 CBackupRestoreNotification::CBackupRestoreNotification(MBackupRestoreNotificationObserver& aCallback) |
|
23 : |
|
24 CActive(CActive::EPriorityStandard), |
|
25 iObserver(aCallback) |
|
26 { |
|
27 |
|
28 CActiveScheduler::Add(this); |
|
29 } |
|
30 |
|
31 |
|
32 /** Destructor. |
|
33 */ |
|
34 EXPORT_C CBackupRestoreNotification::~CBackupRestoreNotification() |
|
35 { |
|
36 Cancel(); |
|
37 iBackupNotification.Close(); |
|
38 } |
|
39 |
|
40 /** |
|
41 * A class wishing to be notified of a Backup/Restore shoud be derived from |
|
42 * MBackupRestoreNotificationObserver and pass a self reference. |
|
43 * @param aFilename full filename of the file which needs monitoring. |
|
44 * @param aCallback should usually be a pointer to the class calling this function. |
|
45 */ |
|
46 EXPORT_C CBackupRestoreNotification* CBackupRestoreNotification::NewL(const TDesC& aFilename, |
|
47 MBackupRestoreNotificationObserver& aCallback) |
|
48 { |
|
49 CBackupRestoreNotification* self = new(ELeave) CBackupRestoreNotification(aCallback); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aFilename); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 /** |
|
57 * Indicates if a Backup operation is currently taking place. |
|
58 * @return ETrue if operation in progress else EFalse. |
|
59 */ |
|
60 EXPORT_C TBool CBackupRestoreNotification::BackupInProgress() const |
|
61 { |
|
62 return (iCurrentState & (conn::EBURBackupPartial | conn::EBURBackupFull)); |
|
63 } |
|
64 |
|
65 /** |
|
66 * Indicates if a Restore operation is currently taking place. |
|
67 * @return ETrue if operation in progress else EFalse. |
|
68 */ |
|
69 EXPORT_C TBool CBackupRestoreNotification::RestoreInProgress() const |
|
70 { |
|
71 return (iCurrentState & (conn::EBURRestorePartial | conn::EBURRestoreFull)); |
|
72 } |
|
73 |
|
74 |
|
75 |
|
76 /** |
|
77 * Initial registration with Publish&Subscribe for KUidBackupRestoreKey. |
|
78 * @param full filename of the file being backed and which needs monitoring. |
|
79 */ |
|
80 void CBackupRestoreNotification::ConstructL(const TDesC& /*aFilename*/) |
|
81 { |
|
82 // Initial subscribe to the Backup and Restore Flag. |
|
83 // The first ID indicates the type of flag being subscribed to. |
|
84 // The second ID is the actual Backup/Restore flag. |
|
85 iBackupNotification.Attach(KUidSystemCategory, conn::KUidBackupRestoreKey); |
|
86 iBackupNotification.Subscribe(iStatus); |
|
87 |
|
88 // Check to see if a Backup/Restore is currently underway. |
|
89 TInt newState=0; |
|
90 if (iBackupNotification.Get(newState)!=KErrNotFound) |
|
91 { |
|
92 ProcessInitialStateL(newState); |
|
93 } |
|
94 |
|
95 SetActive(); |
|
96 } |
|
97 |
|
98 |
|
99 /** |
|
100 * Have been notifed of a change in the backup/restore falg value. |
|
101 * Re-register for changes to the backup flag. Then evaluate which observer |
|
102 * function need to be called. |
|
103 * @see CActive |
|
104 */ |
|
105 void CBackupRestoreNotification::RunL() |
|
106 { |
|
107 // Resubscribe before dealing with the current notification. |
|
108 iBackupNotification.Subscribe(iStatus); |
|
109 SetActive(); |
|
110 |
|
111 // Flag updated. What to do.. |
|
112 TInt newState=0; |
|
113 if (iBackupNotification.Get(newState)!=KErrNotFound) |
|
114 { |
|
115 ReceivedNotificationL(newState); |
|
116 } |
|
117 } |
|
118 |
|
119 |
|
120 TInt CBackupRestoreNotification::RunError(TInt /* aError */) |
|
121 { // recover after handler for notification left |
|
122 return (KErrNone); |
|
123 } |
|
124 |
|
125 |
|
126 /** |
|
127 * @see CActive |
|
128 */ |
|
129 void CBackupRestoreNotification::DoCancel() |
|
130 { |
|
131 iBackupNotification.Cancel(); |
|
132 } |
|
133 |
|
134 |
|
135 /** |
|
136 * Determines what operation is starting or has completed |
|
137 * and calls the relevant observer function. |
|
138 * @param aNewState flags indicating what the new backup/restore state is: |
|
139 * ENoBackup or EBackupBase or EBackupIncremetal. Only interesed in BaseBackup. |
|
140 * EBUR (Unset, Normal, BackupFull, BackupPartial, RestoreFull, RestorePartial) |
|
141 * |
|
142 * 1. No backup/restore is taking place = EBURNormal | ENoBackup |
|
143 * 2. Backup operation starting = (EBURBackupFull || EBURBackupPartial) && EBackupBase |
|
144 * 3. Restore operation starting = (EBURRestoreFull || EBURRestorePartial) && EBackupBase |
|
145 * |
|
146 */ |
|
147 void CBackupRestoreNotification::ReceivedNotificationL(TInt aNewState) |
|
148 { |
|
149 // We are starting a a new operation... |
|
150 // Was there a previous Restore which failed to complete ? |
|
151 if (!(aNewState & (conn::EBURNormal | conn::EBURUnset)) && RestoreInProgress()) |
|
152 { |
|
153 iCurrentState=aNewState; |
|
154 iObserver.RestoreCompletedL(KErrAbort); |
|
155 } |
|
156 |
|
157 // A Backup or Restore taking place. |
|
158 if (aNewState & (conn::EBURBackupPartial | conn::EBURBackupFull) ) |
|
159 { |
|
160 // Backup is taking place (either partial or full) |
|
161 iCurrentState=aNewState; |
|
162 iObserver.BackupBeginningL(); |
|
163 } |
|
164 else if (aNewState & (conn::EBURRestorePartial | conn::EBURRestoreFull)) |
|
165 { |
|
166 // Restore is taking place (either partial or full) |
|
167 iCurrentState=aNewState; |
|
168 iObserver.RestoreBeginningL(); |
|
169 } |
|
170 else if (aNewState & (conn::EBURNormal | conn::EBURUnset)) |
|
171 { |
|
172 // The state has changed to no backup/restore |
|
173 // Decide which operation has just completed. |
|
174 if (BackupInProgress()) |
|
175 { |
|
176 iCurrentState=aNewState; |
|
177 iObserver.BackupCompletedL(); |
|
178 } |
|
179 else if (RestoreInProgress()) |
|
180 { |
|
181 iCurrentState=aNewState; |
|
182 iObserver.RestoreCompletedL(KErrNone); |
|
183 } |
|
184 } |
|
185 } |
|
186 |
|
187 void CBackupRestoreNotification::ProcessInitialStateL(TInt aNewState) |
|
188 { |
|
189 // A Backup or Restore is taking place. |
|
190 if (aNewState & (conn::EBURBackupPartial | conn::EBURBackupFull) ) |
|
191 { |
|
192 // Backup is taking place (either partial or full) |
|
193 iObserver.BackupBeginningL(); |
|
194 } |
|
195 else if (aNewState & (conn::EBURRestorePartial | conn::EBURRestoreFull)) |
|
196 { |
|
197 // Restore is taking place (either partial or full) |
|
198 iObserver.RestoreBeginningL(); |
|
199 } |
|
200 iCurrentState=aNewState; |
|
201 } |
|
202 |