1 /* |
|
2 * Copyright (c) 2005-2008 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 "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: CMMCScBkupStateArchiveOpDataOwners implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupStateArchiveOpDataOwners.h" |
|
20 |
|
21 // System includes |
|
22 #include <e32std.h> |
|
23 #include <s32strm.h> |
|
24 #include <s32mem.h> |
|
25 |
|
26 // User includes |
|
27 #include "MMCScBkupLogger.h" |
|
28 #include "CMMCScBkupArchive.h" |
|
29 #include "RMMCScBkupProgressSizer.h" |
|
30 #include "CMMCScBkupArchiveFooter.h" |
|
31 #include "CMMCScBkupDataOwnerInfo.h" |
|
32 #include "CMMCScBkupIndexDataOwners.h" |
|
33 #include "MMMCScBkupProgressObserver.h" |
|
34 #include "CMMCScBkupDataOwnerCollection.h" |
|
35 #include "MMMCScBkupArchiveDataInterface.h" |
|
36 |
|
37 |
|
38 |
|
39 // ========================= MEMBER FUNCTIONS ================================ |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CMMCScBkupStateArchiveOpDataOwners::CMMCScBkupStateArchiveOpDataOwners() |
|
43 // |
|
44 // C++ constructor. |
|
45 // --------------------------------------------------------------------------- |
|
46 CMMCScBkupStateArchiveOpDataOwners::CMMCScBkupStateArchiveOpDataOwners( MMMCScBkupDriver& aDriver ) |
|
47 : CMMCScBkupStateOpAware( aDriver ), iIndexValueCurrent( -1 ) |
|
48 { |
|
49 __LOG1("CMMCScBkupStateArchiveOpDataOwners::CMMCScBkupStateArchiveOpDataOwners() - 0x%08x", StateId().iUid ); |
|
50 } |
|
51 |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CMMCScBkupStateArchiveOpDataOwners::~CMMCScBkupStateArchiveOpDataOwners() |
|
55 // |
|
56 // Destructor. |
|
57 // --------------------------------------------------------------------------- |
|
58 CMMCScBkupStateArchiveOpDataOwners::~CMMCScBkupStateArchiveOpDataOwners() |
|
59 { |
|
60 Cancel(); |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CMMCScBkupStateArchiveOpDataOwners::NewL() |
|
66 // |
|
67 // |
|
68 // --------------------------------------------------------------------------- |
|
69 CMMCScBkupStateArchiveOpDataOwners* CMMCScBkupStateArchiveOpDataOwners::NewL( MMMCScBkupDriver& aDriver ) |
|
70 { |
|
71 CMMCScBkupStateArchiveOpDataOwners* self = new(ELeave) CMMCScBkupStateArchiveOpDataOwners( aDriver ); |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CMMCScBkupStateArchiveOpDataOwners::StateId() |
|
78 // |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 TMMCScBkupStateId CMMCScBkupStateArchiveOpDataOwners::StateId() const |
|
82 { |
|
83 return KMMCScBkupStateIdArchiveOpDataOwners; |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // CMMCScBkupStateArchiveOpDataOwners::NextStateBackupId() |
|
89 // |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 TMMCScBkupStateId CMMCScBkupStateArchiveOpDataOwners::NextStateBackupId( TBool /*aPartial*/ ) const |
|
93 { |
|
94 return KMMCScBkupStateIdArchiveOpArchiveFooter; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CMMCScBkupStateArchiveOpDataOwners::NextStateRestoreId() |
|
100 // |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 TMMCScBkupStateId CMMCScBkupStateArchiveOpDataOwners::NextStateRestoreId( TBool /*aPartial*/ ) const |
|
104 { |
|
105 return KMMCScBkupStateIdValidateDiskSpace; |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CMMCScBkupStateArchiveOpDataOwners::PerformStateInitBackupL() |
|
111 // |
|
112 // |
|
113 // --------------------------------------------------------------------------- |
|
114 void CMMCScBkupStateArchiveOpDataOwners::PerformStateInitBackupL( TBool /*aPartial*/ ) |
|
115 { |
|
116 // Work is carried out inside asynchronous step |
|
117 CompleteSelf(); |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CMMCScBkupStateArchiveOpDataOwners::PerformStateInitRestoreL() |
|
123 // |
|
124 // |
|
125 // --------------------------------------------------------------------------- |
|
126 void CMMCScBkupStateArchiveOpDataOwners::PerformStateInitRestoreL( TBool /*aPartial*/ ) |
|
127 { |
|
128 // Restore each data owner asynchronously |
|
129 CompleteSelf(); |
|
130 } |
|
131 |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousStateStepBackupL() |
|
135 // |
|
136 // |
|
137 // --------------------------------------------------------------------------- |
|
138 void CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousStateStepBackupL( TBool /*aPartial*/ ) |
|
139 { |
|
140 CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners(); |
|
141 CMMCScBkupArchiveFooter& footer = Driver().DrvArchive().Footer(); |
|
142 CMMCScBkupIndexBase& indexBase = footer.IndexByType(EMMCScBkupOwnerDataTypeDataOwner); |
|
143 CMMCScBkupIndexDataOwners& index = static_cast< CMMCScBkupIndexDataOwners& >( indexBase ); |
|
144 const TInt count = dataOwners.Count(); |
|
145 // |
|
146 if ( ++iIndexValueCurrent < count ) |
|
147 { |
|
148 CMMCScBkupDataOwnerInfo& owner = dataOwners.Owner( iIndexValueCurrent ); |
|
149 |
|
150 // Externalise |
|
151 MMMCScBkupArchiveDataInterface& archiveDataInterface = ADI(); |
|
152 RWriteStream stream( archiveDataInterface.ADIWriteStreamUncompressedLC() ); |
|
153 stream << owner; |
|
154 stream.CommitL(); |
|
155 CleanupStack::PopAndDestroy(); // stream |
|
156 |
|
157 |
|
158 // Save the offset of the data owner |
|
159 const TMMCScBkupArchiveVector& info = archiveDataInterface.ADICurrentArchiveVectorInfo(); |
|
160 index.AddIndexRecordL( info ); |
|
161 |
|
162 // Now move on to the next data owner |
|
163 CompleteSelf(); |
|
164 } |
|
165 } |
|
166 |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousStateStepRestoreL() |
|
170 // |
|
171 // |
|
172 // --------------------------------------------------------------------------- |
|
173 void CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousStateStepRestoreL( TBool /*aPartial*/ ) |
|
174 { |
|
175 CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners(); |
|
176 CMMCScBkupArchiveFooter& footer = Driver().DrvArchive().Footer(); |
|
177 CMMCScBkupIndexBase& indexBase = footer.IndexByType( EMMCScBkupOwnerDataTypeDataOwner ); |
|
178 CMMCScBkupIndexDataOwners& index = static_cast< CMMCScBkupIndexDataOwners& >( indexBase ); |
|
179 const TInt count = index.Count(); |
|
180 __LOG1( "CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousStateStepRestoreL() - %d data owner index records...", count ); |
|
181 // |
|
182 if ( ++iIndexValueCurrent < count ) |
|
183 { |
|
184 const TMMCScBkupArchiveVector& entry = index.At( iIndexValueCurrent ); |
|
185 __LOG3( "CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousStateStepRestoreL() - entry[%03d] at offset: 0x%08x, length: %4d", iIndexValueCurrent, entry.Offset(), entry.Length() ); |
|
186 |
|
187 MMMCScBkupArchiveDataInterface& archiveDataInterface = ADI(); |
|
188 RReadStream stream( archiveDataInterface.ADIReadStreamUncompressedLC( entry.Offset() ) ); |
|
189 |
|
190 // Internalize a new entry and add it to the data owner collection |
|
191 CMMCScBkupDataOwnerInfo* dataOwner = CMMCScBkupDataOwnerInfo::NewLC( stream ); |
|
192 dataOwners.AppendL( dataOwner ); |
|
193 CleanupStack::Pop( dataOwner ); |
|
194 |
|
195 // Tidy up & check that we didn't read too much - oops |
|
196 const TMMCScBkupArchiveVector& readInfo = archiveDataInterface.ADICurrentArchiveVectorInfo(); |
|
197 if ( readInfo.Length() > entry.Length() ) |
|
198 { |
|
199 __LOG( "CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousStateStepRestoreL() - ERROR - Read too much data! -> leave with KErrCorrupt" ); |
|
200 User::Leave( KErrCorrupt ); |
|
201 } |
|
202 CleanupStack::PopAndDestroy(); // stream |
|
203 |
|
204 // Continue to next entry |
|
205 CompleteSelf(); |
|
206 } |
|
207 } |
|
208 |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CMMCScBkupStateArchiveOpDataOwners::PerformLastRightsBackupL() |
|
212 // |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 void CMMCScBkupStateArchiveOpDataOwners::PerformLastRightsBackupL( TBool /*aPartial*/ ) |
|
216 { |
|
217 CMMCScBkupIndexBase& index = Driver().DrvArchive().Footer().IndexByType( EMMCScBkupOwnerDataTypeDataOwner ); |
|
218 index.StoreL( Driver() ); |
|
219 } |
|
220 |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CMMCScBkupStateArchiveOpDataOwners::PerformLastRightsRestoreL() |
|
224 // |
|
225 // |
|
226 // --------------------------------------------------------------------------- |
|
227 void CMMCScBkupStateArchiveOpDataOwners::PerformLastRightsRestoreL( TBool /*aPartial*/ ) |
|
228 { |
|
229 // Calculate restore byte size (for all drives) |
|
230 CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners(); |
|
231 const TInt64 totalDataRestoreSize = dataOwners.TotalOperationalSizeL(); |
|
232 |
|
233 // Inform progress manager |
|
234 if(Driver().DrvLastCategory()) |
|
235 { |
|
236 __LOG2("CMMCScBkupStateArchiveOpDataOwners::PerformLastRightsRestoreL() - report progress understood (%Ld + %Ld)", |
|
237 totalDataRestoreSize, Driver().DrvTotalProgress()); |
|
238 Driver().DrvProgressHandler().MMCScBkupHandleProgressDomainUnderstood( totalDataRestoreSize + Driver().DrvTotalProgress()); |
|
239 } |
|
240 else |
|
241 { |
|
242 __LOG2("CMMCScBkupStateArchiveOpDataOwners::PerformLastRightsRestoreL() - adding progress amount %Ld to existing %Ld)", |
|
243 totalDataRestoreSize, Driver().DrvTotalProgress()); |
|
244 Driver().DrvStoreTotalProgress( totalDataRestoreSize ); |
|
245 } |
|
246 } |
|
247 |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousErrorCleanupRestore() |
|
251 // |
|
252 // |
|
253 // --------------------------------------------------------------------------- |
|
254 TBool CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousErrorCleanupRestore( TBool /*aPartial*/, TInt aError ) |
|
255 { |
|
256 (void) aError; |
|
257 __LOGFILE1("CMMCScBkupStateArchiveOpDataOwners::PerformAsynchronousErrorCleanupRestore() - **** - error: %d", aError ); |
|
258 |
|
259 // Just try to skip the data owner. |
|
260 CompleteSelf(); |
|
261 return ETrue; |
|
262 } |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|