|
1 /* |
|
2 * Copyright (c) 2007 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 the License "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: Widget's active data owner in backup/restore. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <abclient.h> |
|
20 #include <e32property.h> |
|
21 #include "widgetbackuprestore.h" |
|
22 #include "WidgetActiveCallback.h" |
|
23 |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 // --------------------------------------------------------------------------- |
|
30 // Constructor. |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CWidgetBackupRestore* CWidgetBackupRestore::NewL() |
|
34 { |
|
35 CWidgetBackupRestore* self = |
|
36 new ( ELeave ) CWidgetBackupRestore(); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Destructor |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CWidgetBackupRestore::~CWidgetBackupRestore() |
|
49 { |
|
50 Cancel(); |
|
51 |
|
52 iBackupProperty.Close(); |
|
53 delete iCallBack; |
|
54 delete iActiveBackupClient; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Active object's request handling. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CWidgetBackupRestore::RunL() |
|
62 { |
|
63 if ( iStatus.Int() == KErrNone ) |
|
64 { |
|
65 TInt currentValue = KErrNone; |
|
66 iBackupProperty.Get( currentValue ); |
|
67 |
|
68 HandleBackupStateL( currentValue ); |
|
69 } |
|
70 else |
|
71 { |
|
72 //RunError( iStatus.Int() ); |
|
73 } |
|
74 |
|
75 // Re-subscribe notifications. |
|
76 SubscribePSKey(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Active object's request error handling. |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CWidgetBackupRestore::RunError( TInt /*aError*/ ) |
|
84 { |
|
85 return KErrNone; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Cancel the request. |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CWidgetBackupRestore::DoCancel() |
|
93 { |
|
94 iBackupProperty.Cancel(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // C++ constructor. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CWidgetBackupRestore::CWidgetBackupRestore() : |
|
102 CActive( EPriorityNormal ) |
|
103 { |
|
104 // Add to active scheduler. |
|
105 CActiveScheduler::Add( this ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // 2nd phase constructor. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CWidgetBackupRestore::ConstructL() |
|
113 { |
|
114 #ifdef _DEBUG |
|
115 _LIT(KDir, "WidgetBUR"); |
|
116 _LIT(KFile, "WidgetBUR.log"); |
|
117 TInt err( 0 ); |
|
118 |
|
119 err = iFileLogger.Connect(); |
|
120 if ( err == KErrNone ) |
|
121 { |
|
122 iFileLogger.CreateLog( KDir(), KFile(), EFileLoggingModeOverwrite ); |
|
123 iCanLog = ETrue; |
|
124 } |
|
125 #endif |
|
126 iLastType = conn::EBURUnset; |
|
127 |
|
128 // Attach to backup key. |
|
129 iBackupProperty.Attach( KUidSystemCategory, conn::KUidBackupRestoreKey ); |
|
130 |
|
131 // Handle initial B&R key value, then start listening for further changes. |
|
132 RunL(); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Handles changes in backup state. |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CWidgetBackupRestore::HandleBackupStateL( const TInt aValue ) |
|
140 { |
|
141 const TInt type = aValue & conn::KBURPartTypeMask; |
|
142 |
|
143 // Test if the device is going into backup or restore mode, and we are |
|
144 // required to participate. |
|
145 if ( ( type == conn::EBURBackupFull || type == conn::EBURRestoreFull ) || |
|
146 ( type == conn::EBURBackupPartial || type == conn::EBURRestorePartial ) ) |
|
147 { |
|
148 if ( !iCallBack ) |
|
149 { |
|
150 iCallBack = CWidgetActiveCallback::NewL(); |
|
151 } |
|
152 |
|
153 if ( !iActiveBackupClient ) |
|
154 { |
|
155 iActiveBackupClient = conn::CActiveBackupClient::NewL( iCallBack ); |
|
156 |
|
157 if ( ( type == conn::EBURBackupPartial || |
|
158 type == conn::EBURRestorePartial ) && |
|
159 !iActiveBackupClient->DoesPartialBURAffectMeL() ) |
|
160 { |
|
161 delete iCallBack; |
|
162 iCallBack = NULL; |
|
163 delete iActiveBackupClient; |
|
164 iActiveBackupClient = NULL; |
|
165 return; |
|
166 } |
|
167 } |
|
168 |
|
169 iActiveBackupClient->ConfirmReadyForBURL( KErrNone ); |
|
170 } |
|
171 else |
|
172 { |
|
173 if ( type == conn::EBURNormal ) |
|
174 { |
|
175 if ( iLastType == conn::EBURBackupFull || iLastType == conn::EBURBackupPartial ) |
|
176 { |
|
177 iCallBack->CleanupBackupDataL(); |
|
178 } |
|
179 |
|
180 // delete once back to normal. |
|
181 delete iCallBack; |
|
182 iCallBack = NULL; |
|
183 delete iActiveBackupClient; |
|
184 iActiveBackupClient = NULL; |
|
185 |
|
186 // Stop the scheduler, which will allow |
|
187 // the process to exit. |
|
188 CActiveScheduler::Stop(); |
|
189 } |
|
190 } |
|
191 |
|
192 iLastType = type; |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // Subsribes notifications of backup/restore p&s key. |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CWidgetBackupRestore::SubscribePSKey() |
|
200 { |
|
201 Cancel(); |
|
202 |
|
203 iBackupProperty.Subscribe( iStatus ); |
|
204 SetActive(); |
|
205 } |
|
206 |
|
207 void MainL() |
|
208 { |
|
209 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); |
|
210 CActiveScheduler::Install( scheduler ); |
|
211 CleanupStack::PushL( scheduler ); |
|
212 // |
|
213 CWidgetBackupRestore* widBUR = CWidgetBackupRestore::NewL(); |
|
214 CleanupStack::PushL( widBUR ); |
|
215 CActiveScheduler::Start(); |
|
216 // |
|
217 CleanupStack::PopAndDestroy( 2, scheduler ); |
|
218 } |
|
219 |
|
220 TInt E32Main() |
|
221 { |
|
222 TInt err = KErrNoMemory; |
|
223 // |
|
224 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
225 if ( cleanupStack ) |
|
226 { |
|
227 TRAP( err, MainL() ); |
|
228 } |
|
229 // |
|
230 delete cleanupStack; |
|
231 return err; |
|
232 } |