|
1 /* |
|
2 * Copyright (c) 2005 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: CMMCScBkupBufferManagerBase implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupBufferManagers.h" |
|
20 |
|
21 // System includes |
|
22 #include <ezstream.h> |
|
23 |
|
24 // User includes |
|
25 #include "MMCScBkupLogger.h" |
|
26 #include "CMMCScBkupDataStrategies.h" |
|
27 #include "MMMCScBkupArchiveDataInterface.h" |
|
28 #include "MMMCScBkupProgressObserver.h" |
|
29 |
|
30 |
|
31 // ========================= MEMBER FUNCTIONS ================================ |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // CMMCScBkupBufferManagerBase::CMMCScBkupBufferManagerBase() |
|
35 // |
|
36 // C++ constructor. |
|
37 // --------------------------------------------------------------------------- |
|
38 CMMCScBkupBufferManagerBase::CMMCScBkupBufferManagerBase(MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI, TType aType ) |
|
39 : iType( aType ), iBufferPointer( NULL, 0, 0 ), iProgressManager( aProgressManager ), iADI( aADI ) |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CMMCScBkupBufferManagerBase::~CMMCScBkupBufferManagerBase() |
|
46 // |
|
47 // C++ constructor. |
|
48 // --------------------------------------------------------------------------- |
|
49 CMMCScBkupBufferManagerBase::~CMMCScBkupBufferManagerBase() |
|
50 { |
|
51 delete iBuffer; |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CMMCScBkupBufferManagerBase::ConstructL() |
|
57 // |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 void CMMCScBkupBufferManagerBase::ConstructL(TInt aBufferSize) |
|
61 { |
|
62 HBufC8* buffer = HBufC8::NewL(aBufferSize); |
|
63 delete iBuffer; |
|
64 iBuffer = buffer; |
|
65 iBufferPointer.Set(iBuffer->Des()); |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CMMCScBkupBufferManagerBase::NewByTypeL() |
|
71 // |
|
72 // Factory |
|
73 // --------------------------------------------------------------------------- |
|
74 CMMCScBkupBufferManagerBase* CMMCScBkupBufferManagerBase::NewByTypeL(TType aType, MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI, TAny* aParam1, TAny* aParam2) |
|
75 { |
|
76 CMMCScBkupBufferManagerBase* ret = NULL; |
|
77 // |
|
78 switch(aType) |
|
79 { |
|
80 case ETypeDescriptorToArchive: |
|
81 ret = CMMCScBkupBufferManagerDescriptorToArchive::NewL( aProgressManager, aADI ); |
|
82 break; |
|
83 case ETypeFileToArchive: |
|
84 ret = CMMCScBkupBufferManagerFileToArchive::NewL( aProgressManager, aADI ); |
|
85 break; |
|
86 case ETypeArchiveToDescriptor: |
|
87 ret = CMMCScBkupBufferManagerArchiveToDescriptor::NewL( aProgressManager, aADI ); |
|
88 break; |
|
89 case ETypeArchiveToFile: |
|
90 ret = CMMCScBkupBufferManagerArchiveToFile::NewL( aProgressManager, aADI ); |
|
91 break; |
|
92 default: |
|
93 User::Leave(KErrNotSupported); |
|
94 break; |
|
95 } |
|
96 // |
|
97 CleanupStack::PushL(ret); |
|
98 ret->InitializeL(aParam1, aParam2); |
|
99 CleanupStack::Pop(ret); |
|
100 // |
|
101 return ret; |
|
102 } |
|
103 |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CMMCScBkupBufferManagerBase::WriteToArchiveAndUpdateStatsL() |
|
107 // |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 void CMMCScBkupBufferManagerBase::WriteToArchiveAndUpdateStatsL( const TDesC8& aData ) |
|
111 { |
|
112 // Write the data we currently have to file. This reset |
|
113 const TMMCScBkupArchiveVector& writtenInfo = ADI().ADIWriteL( aData ); |
|
114 |
|
115 // Update our stats. We combined what we've already written with |
|
116 // the amount of data we just wrote. |
|
117 if ( Info().Offset() == 0 ) |
|
118 { |
|
119 // Possibly never updated the offset before... |
|
120 Info().SetOffset( writtenInfo.Offset() ); |
|
121 } |
|
122 // |
|
123 const TInt existingLength = Info().Length(); |
|
124 Info().SetLength( existingLength + writtenInfo.Length() ); |
|
125 } |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 // ========================= MEMBER FUNCTIONS ================================ |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CMMCScBkupBufferManagerDescriptorToArchive::CMMCScBkupBufferManagerDescriptorToArchive() |
|
148 // |
|
149 // C++ constructor. |
|
150 // --------------------------------------------------------------------------- |
|
151 CMMCScBkupBufferManagerDescriptorToArchive::CMMCScBkupBufferManagerDescriptorToArchive( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
152 : CMMCScBkupBufferManagerBase( aProgressManager, aADI, ETypeDescriptorToArchive ), iSource( KNullDesC8 ) |
|
153 { |
|
154 } |
|
155 |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CMMCScBkupBufferManagerDescriptorToArchive::CMMCScBkupBufferManagerDescriptorToArchive() |
|
159 // |
|
160 // C++ constructor. |
|
161 // --------------------------------------------------------------------------- |
|
162 CMMCScBkupBufferManagerDescriptorToArchive* CMMCScBkupBufferManagerDescriptorToArchive::NewL( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
163 { |
|
164 CMMCScBkupBufferManagerDescriptorToArchive* self = new(ELeave) CMMCScBkupBufferManagerDescriptorToArchive( aProgressManager, aADI ); |
|
165 CleanupStack::PushL(self); |
|
166 self->ConstructL(); |
|
167 CleanupStack::Pop(self); |
|
168 return self; |
|
169 } |
|
170 |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CMMCScBkupBufferManagerDescriptorToArchive::InitializeL() |
|
174 // |
|
175 // |
|
176 // --------------------------------------------------------------------------- |
|
177 void CMMCScBkupBufferManagerDescriptorToArchive::InitializeL(TAny* aParam1, TAny* /*aParam2*/) |
|
178 { |
|
179 const TDesC8* pData = reinterpret_cast<const TDesC8*>(aParam1); |
|
180 iSource.Set(*pData); |
|
181 } |
|
182 |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // CMMCScBkupBufferManagerDescriptorToArchive::InitializeL() |
|
186 // |
|
187 // |
|
188 // --------------------------------------------------------------------------- |
|
189 void CMMCScBkupBufferManagerDescriptorToArchive::InitializeL( CEZZStream& aZStream ) |
|
190 { |
|
191 // We use the source object as the input buffer. Therefore the |
|
192 // dynamic buffer is used as an intermediate storage depot for compressed |
|
193 // data before it is flushed to disk |
|
194 aZStream.SetInput( iSource ); |
|
195 aZStream.SetOutput( WriteBuffer() ); |
|
196 } |
|
197 |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CMMCScBkupBufferManagerDescriptorToArchive::NeedInputL() |
|
201 // |
|
202 // |
|
203 // --------------------------------------------------------------------------- |
|
204 void CMMCScBkupBufferManagerDescriptorToArchive::NeedInputL(CEZZStream& /*aZStream*/) |
|
205 { |
|
206 // Nothing to do here - we have provided all our input in one go |
|
207 } |
|
208 |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CMMCScBkupBufferManagerDescriptorToArchive::NeedOutputL() |
|
212 // |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 void CMMCScBkupBufferManagerDescriptorToArchive::NeedOutputL( CEZZStream& aZStream ) |
|
216 { |
|
217 const TPtrC8 output(aZStream.OutputDescriptor()); |
|
218 WriteToArchiveAndUpdateStatsL( output ); |
|
219 |
|
220 // Reset ready for more writing |
|
221 WriteBuffer().Zero(); |
|
222 aZStream.SetOutput( WriteBuffer() ); |
|
223 } |
|
224 |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CMMCScBkupBufferManagerDescriptorToArchive::FinalizeL() |
|
228 // |
|
229 // |
|
230 // --------------------------------------------------------------------------- |
|
231 void CMMCScBkupBufferManagerDescriptorToArchive::FinalizeL( CEZZStream& aZStream ) |
|
232 { |
|
233 // Write any remaining data... |
|
234 const TPtrC8 output(aZStream.OutputDescriptor()); |
|
235 WriteToArchiveAndUpdateStatsL( output ); |
|
236 } |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 // ========================= MEMBER FUNCTIONS ================================ |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CMMCScBkupBufferManagerFileToArchive::CMMCScBkupBufferManagerFileToArchive() |
|
270 // |
|
271 // C++ constructor. |
|
272 // --------------------------------------------------------------------------- |
|
273 CMMCScBkupBufferManagerFileToArchive::CMMCScBkupBufferManagerFileToArchive( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
274 : CMMCScBkupBufferManagerBase( aProgressManager, aADI, ETypeDescriptorToArchive ), iOutputPointer( NULL, 0, 0 ) |
|
275 { |
|
276 } |
|
277 |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // CMMCScBkupBufferManagerFileToArchive::~CMMCScBkupBufferManagerFileToArchive() |
|
281 // |
|
282 // C++ constructor. |
|
283 // --------------------------------------------------------------------------- |
|
284 CMMCScBkupBufferManagerFileToArchive::~CMMCScBkupBufferManagerFileToArchive() |
|
285 { |
|
286 delete iReadStrategy; |
|
287 delete iOutput; |
|
288 } |
|
289 |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CMMCScBkupBufferManagerFileToArchive::ConstructL() |
|
293 // |
|
294 // |
|
295 // --------------------------------------------------------------------------- |
|
296 void CMMCScBkupBufferManagerFileToArchive::ConstructL( const TDesC& aFileName ) |
|
297 { |
|
298 CMMCScBkupBufferManagerBase::ConstructL(); |
|
299 // |
|
300 CMMCScBkupDataStrategy* strategy = CMMCScBkupDataStrategy::ReadStrategyLC(aFileName, ADI().ADIFsSession()); |
|
301 delete iReadStrategy; |
|
302 iReadStrategy = strategy; |
|
303 CleanupStack::Pop(strategy); |
|
304 // |
|
305 HBufC8* output = HBufC8::NewL(KScBkupDefaultBufferSize); |
|
306 delete iOutput; |
|
307 iOutput = output; |
|
308 iOutputPointer.Set(iOutput->Des()); |
|
309 // |
|
310 iFileName.Set(aFileName); |
|
311 } |
|
312 |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // CMMCScBkupBufferManagerFileToArchive::CMMCScBkupBufferManagerFileToArchive() |
|
316 // |
|
317 // C++ constructor. |
|
318 // --------------------------------------------------------------------------- |
|
319 CMMCScBkupBufferManagerFileToArchive* CMMCScBkupBufferManagerFileToArchive::NewL( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
320 { |
|
321 CMMCScBkupBufferManagerFileToArchive* self = new(ELeave) CMMCScBkupBufferManagerFileToArchive( aProgressManager, aADI ); |
|
322 return self; |
|
323 } |
|
324 |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // CMMCScBkupBufferManagerFileToArchive::InitializeL() |
|
328 // |
|
329 // |
|
330 // --------------------------------------------------------------------------- |
|
331 void CMMCScBkupBufferManagerFileToArchive::InitializeL(TAny* aParam1, TAny* /*aParam2*/) |
|
332 { |
|
333 const TDesC* pFileName = reinterpret_cast<const TDesC*>(aParam1); |
|
334 const TPtrC fileName(*pFileName); |
|
335 ConstructL(fileName); |
|
336 } |
|
337 |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // CMMCScBkupBufferManagerFileToArchive::InitializeL() |
|
341 // |
|
342 // |
|
343 // --------------------------------------------------------------------------- |
|
344 void CMMCScBkupBufferManagerFileToArchive::InitializeL( CEZZStream& aZStream ) |
|
345 { |
|
346 // Seed input buffer |
|
347 TPtr8 pWriteBuffer( WriteBuffer() ); |
|
348 iReadStrategy->Read( pWriteBuffer ); |
|
349 aZStream.SetInput( pWriteBuffer ); |
|
350 |
|
351 // Progress during a backup is calculated based upon the amount of the |
|
352 // source file that has been read. |
|
353 ProgressManager().MMCScBkupHandleProgress( pWriteBuffer.Length() ); |
|
354 |
|
355 // Make ready for output |
|
356 aZStream.SetOutput( iOutputPointer ); |
|
357 } |
|
358 |
|
359 |
|
360 // --------------------------------------------------------------------------- |
|
361 // CMMCScBkupBufferManagerFileToArchive::NeedInputL() |
|
362 // |
|
363 // |
|
364 // --------------------------------------------------------------------------- |
|
365 void CMMCScBkupBufferManagerFileToArchive::NeedInputL( CEZZStream& aZStream ) |
|
366 { |
|
367 // Read some data from the file |
|
368 TPtr8 pWriteBuffer( WriteBuffer() ); |
|
369 iReadStrategy->Read( pWriteBuffer ); |
|
370 |
|
371 // Progress during a backup is calculated based upon the amount of the |
|
372 // source file that has been read. |
|
373 ProgressManager().MMCScBkupHandleProgress( pWriteBuffer.Length() ); |
|
374 |
|
375 aZStream.SetInput( pWriteBuffer ); |
|
376 } |
|
377 |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // CMMCScBkupBufferManagerFileToArchive::NeedOutputL() |
|
381 // |
|
382 // |
|
383 // --------------------------------------------------------------------------- |
|
384 void CMMCScBkupBufferManagerFileToArchive::NeedOutputL( CEZZStream& aZStream ) |
|
385 { |
|
386 const TPtrC8 output(aZStream.OutputDescriptor()); |
|
387 WriteToArchiveAndUpdateStatsL( output ); |
|
388 |
|
389 // Reset ready for more writing |
|
390 iOutputPointer.Zero(); |
|
391 aZStream.SetOutput( iOutputPointer ); |
|
392 } |
|
393 |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // CMMCScBkupBufferManagerFileToArchive::FinalizeL() |
|
397 // |
|
398 // |
|
399 // --------------------------------------------------------------------------- |
|
400 void CMMCScBkupBufferManagerFileToArchive::FinalizeL( CEZZStream& aZStream ) |
|
401 { |
|
402 const TPtrC8 output(aZStream.OutputDescriptor()); |
|
403 |
|
404 #if defined(__MMCSCBKUPLOGGING_ENABLED__) |
|
405 const TInt compressedSize = output.Size() + Info().Length(); |
|
406 TEntry entry; |
|
407 const TInt error = ADI().ADIFsSession().Entry(iFileName, entry); |
|
408 if (error == KErrNone) |
|
409 { |
|
410 const TReal ratio = (TReal) entry.iSize / (TReal) compressedSize; |
|
411 __LOG4("CMMCScBkupBufferManagerFileToArchive::FinalizeL() - compressing %S - original: %d, compressed: %d, ratio: %f", &iFileName, entry.iSize, compressedSize, ratio); |
|
412 if (compressedSize > entry.iSize) |
|
413 { |
|
414 // We've made this file bigger |
|
415 __LOG3("CMMCScBkupBufferManagerFileToArchive::FinalizeL() - compressing %S had negative effect - originalSize: %d vs compressed: %d", &iFileName, entry.iSize, compressedSize); |
|
416 } |
|
417 } |
|
418 #endif |
|
419 |
|
420 WriteToArchiveAndUpdateStatsL( output ); |
|
421 } |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 // ========================= MEMBER FUNCTIONS ================================ |
|
480 |
|
481 // --------------------------------------------------------------------------- |
|
482 // CMMCScBkupBufferManagerArchiveToDescriptor::CMMCScBkupBufferManagerArchiveToDescriptor() |
|
483 // |
|
484 // C++ constructor. |
|
485 // --------------------------------------------------------------------------- |
|
486 CMMCScBkupBufferManagerArchiveToDescriptor::CMMCScBkupBufferManagerArchiveToDescriptor( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
487 : CMMCScBkupBufferManagerBase( aProgressManager, aADI, ETypeArchiveToDescriptor ), iOutputPointer( NULL, 0, 0 ) |
|
488 { |
|
489 } |
|
490 |
|
491 |
|
492 // --------------------------------------------------------------------------- |
|
493 // CMMCScBkupBufferManagerArchiveToDescriptor::~CMMCScBkupBufferManagerArchiveToDescriptor() |
|
494 // |
|
495 // C++ constructor. |
|
496 // --------------------------------------------------------------------------- |
|
497 CMMCScBkupBufferManagerArchiveToDescriptor::~CMMCScBkupBufferManagerArchiveToDescriptor() |
|
498 { |
|
499 } |
|
500 |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // CMMCScBkupBufferManagerArchiveToDescriptor::CMMCScBkupBufferManagerArchiveToDescriptor() |
|
504 // |
|
505 // C++ constructor. |
|
506 // --------------------------------------------------------------------------- |
|
507 CMMCScBkupBufferManagerArchiveToDescriptor* CMMCScBkupBufferManagerArchiveToDescriptor::NewL( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
508 { |
|
509 CMMCScBkupBufferManagerArchiveToDescriptor* self = new(ELeave) CMMCScBkupBufferManagerArchiveToDescriptor( aProgressManager, aADI ); |
|
510 CleanupStack::PushL(self); |
|
511 self->ConstructL(); |
|
512 CleanupStack::Pop(self); |
|
513 return self; |
|
514 } |
|
515 |
|
516 |
|
517 // --------------------------------------------------------------------------- |
|
518 // CMMCScBkupBufferManagerArchiveToDescriptor::InitializeL() |
|
519 // |
|
520 // |
|
521 // --------------------------------------------------------------------------- |
|
522 void CMMCScBkupBufferManagerArchiveToDescriptor::InitializeL( TAny* aParam1, TAny* aParam2 ) |
|
523 { |
|
524 // Setup sink |
|
525 TDes8* pDataSink = (TDes8*) aParam1; |
|
526 iOutputPointer.Set( const_cast<TUint8*>( pDataSink->Ptr() ), pDataSink->Length(), pDataSink->MaxLength() ); |
|
527 |
|
528 // Setup max read info |
|
529 const TMMCScBkupArchiveVector* readInfo = (const TMMCScBkupArchiveVector*) aParam2; |
|
530 Info() = *readInfo; |
|
531 } |
|
532 |
|
533 |
|
534 // --------------------------------------------------------------------------- |
|
535 // CMMCScBkupBufferManagerArchiveToDescriptor::InitializeL() |
|
536 // |
|
537 // |
|
538 // --------------------------------------------------------------------------- |
|
539 void CMMCScBkupBufferManagerArchiveToDescriptor::InitializeL( CEZZStream& aZStream ) |
|
540 { |
|
541 // Try to read some data |
|
542 TryToReadMoreSourceDataL(); |
|
543 |
|
544 // We use the source object as the input buffer. Therefore the |
|
545 // dynamic buffer is used as an intermediate storage depot for compressed |
|
546 // data before it is flushed to disk |
|
547 aZStream.SetInput( DataView() ); |
|
548 aZStream.SetOutput( iOutputPointer ); |
|
549 } |
|
550 |
|
551 |
|
552 // --------------------------------------------------------------------------- |
|
553 // CMMCScBkupBufferManagerArchiveToDescriptor::NeedInputL() |
|
554 // |
|
555 // |
|
556 // --------------------------------------------------------------------------- |
|
557 void CMMCScBkupBufferManagerArchiveToDescriptor::NeedInputL(CEZZStream& aZStream) |
|
558 { |
|
559 // Try to read some more data |
|
560 TryToReadMoreSourceDataL(); |
|
561 aZStream.SetInput( DataView() ); |
|
562 } |
|
563 |
|
564 |
|
565 // --------------------------------------------------------------------------- |
|
566 // CMMCScBkupBufferManagerArchiveToDescriptor::NeedOutputL() |
|
567 // |
|
568 // |
|
569 // --------------------------------------------------------------------------- |
|
570 void CMMCScBkupBufferManagerArchiveToDescriptor::NeedOutputL( CEZZStream& /*aZStream*/ ) |
|
571 { |
|
572 // Nothing to do here, we've got no more space if the sink is full |
|
573 ASSERT( EFalse ); |
|
574 } |
|
575 |
|
576 |
|
577 // --------------------------------------------------------------------------- |
|
578 // CMMCScBkupBufferManagerArchiveToDescriptor::FinalizeL() |
|
579 // |
|
580 // |
|
581 // --------------------------------------------------------------------------- |
|
582 void CMMCScBkupBufferManagerArchiveToDescriptor::FinalizeL( CEZZStream& /*aZStream*/ ) |
|
583 { |
|
584 // Nothing to do here, we've writing straight to the client's descriptor |
|
585 } |
|
586 |
|
587 |
|
588 // --------------------------------------------------------------------------- |
|
589 // CMMCScBkupBufferManagerArchiveToDescriptor::TryToReadMoreSourceDataL() |
|
590 // |
|
591 // |
|
592 // --------------------------------------------------------------------------- |
|
593 void CMMCScBkupBufferManagerArchiveToDescriptor::TryToReadMoreSourceDataL() |
|
594 { |
|
595 if ( Info().Length() > 0 ) |
|
596 { |
|
597 // Try to read some source data, but don't read beyond the limits |
|
598 const TMMCScBkupArchiveVector& readInfoResult = ADI().ADIReadL( WriteBuffer(), Info() ); |
|
599 |
|
600 // Update remaining read info so that we know where from and how much data |
|
601 // to read next time around |
|
602 const TInt newStartingOffset = readInfoResult.Offset() + readInfoResult.Length(); |
|
603 const TInt remainingToBeRead = Info().Length() - readInfoResult.Length(); |
|
604 // |
|
605 Info().SetOffset( newStartingOffset ); |
|
606 Info().SetLength( remainingToBeRead ); |
|
607 // |
|
608 __LOG1("CMMCScBkupBufferManagerArchiveToDescriptor::TryToReadMoreSourceDataL() - read: %d bytes from archive", readInfoResult.Length()); |
|
609 // |
|
610 ProgressManager().MMCScBkupHandleProgress( readInfoResult.Length() ); |
|
611 } |
|
612 } |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 // ========================= MEMBER FUNCTIONS ================================ |
|
663 |
|
664 // --------------------------------------------------------------------------- |
|
665 // CMMCScBkupBufferManagerArchiveToFile::CMMCScBkupBufferManagerArchiveToFile() |
|
666 // |
|
667 // C++ constructor. |
|
668 // --------------------------------------------------------------------------- |
|
669 CMMCScBkupBufferManagerArchiveToFile::CMMCScBkupBufferManagerArchiveToFile( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
670 : CMMCScBkupBufferManagerBase( aProgressManager, aADI, ETypeArchiveToFile ), iOutputPointer( NULL, 0, 0 ) |
|
671 { |
|
672 } |
|
673 |
|
674 |
|
675 // --------------------------------------------------------------------------- |
|
676 // CMMCScBkupBufferManagerArchiveToFile::~CMMCScBkupBufferManagerArchiveToFile() |
|
677 // |
|
678 // C++ constructor. |
|
679 // --------------------------------------------------------------------------- |
|
680 CMMCScBkupBufferManagerArchiveToFile::~CMMCScBkupBufferManagerArchiveToFile() |
|
681 { |
|
682 delete iWriteStrategy; |
|
683 delete iOutput; |
|
684 } |
|
685 |
|
686 |
|
687 // --------------------------------------------------------------------------- |
|
688 // CMMCScBkupBufferManagerArchiveToFile::ConstructL() |
|
689 // |
|
690 // |
|
691 // --------------------------------------------------------------------------- |
|
692 void CMMCScBkupBufferManagerArchiveToFile::ConstructL( const TDesC& aFileName ) |
|
693 { |
|
694 CMMCScBkupBufferManagerBase::ConstructL(); |
|
695 |
|
696 // Create a write strategy that ultimately writes to a temp file in our |
|
697 // private data cage. When the file has been successfully extracted, |
|
698 // we then replace the original. -> see FinalizeL() |
|
699 CMMCScBkupDataStrategy* strategy = CMMCScBkupDataStrategy::WriteStrategyLC( aFileName, ADI().ADIFsSession(), KMMCScBkupUseTempFile ); |
|
700 delete iWriteStrategy; |
|
701 iWriteStrategy = strategy; |
|
702 CleanupStack::Pop( strategy ); |
|
703 // |
|
704 HBufC8* output = HBufC8::NewL(KScBkupDefaultBufferSize); |
|
705 delete iOutput; |
|
706 iOutput = output; |
|
707 iOutputPointer.Set(iOutput->Des()); |
|
708 // |
|
709 iFileName.Set(aFileName); |
|
710 } |
|
711 |
|
712 |
|
713 // --------------------------------------------------------------------------- |
|
714 // CMMCScBkupBufferManagerArchiveToFile::CMMCScBkupBufferManagerArchiveToFile() |
|
715 // |
|
716 // C++ constructor. |
|
717 // --------------------------------------------------------------------------- |
|
718 CMMCScBkupBufferManagerArchiveToFile* CMMCScBkupBufferManagerArchiveToFile::NewL( MMMCScBkupProgressObserver& aProgressManager, MMMCScBkupArchiveDataInterface& aADI ) |
|
719 { |
|
720 CMMCScBkupBufferManagerArchiveToFile* self = new(ELeave) CMMCScBkupBufferManagerArchiveToFile( aProgressManager, aADI ); |
|
721 return self; |
|
722 } |
|
723 |
|
724 |
|
725 // --------------------------------------------------------------------------- |
|
726 // CMMCScBkupBufferManagerArchiveToFile::InitializeL() |
|
727 // |
|
728 // |
|
729 // --------------------------------------------------------------------------- |
|
730 void CMMCScBkupBufferManagerArchiveToFile::InitializeL(TAny* aParam1, TAny* aParam2) |
|
731 { |
|
732 // Param 1 is the destination file name |
|
733 const TDesC* pFileName = reinterpret_cast<const TDesC*>(aParam1); |
|
734 const TPtrC fileName(*pFileName); |
|
735 ConstructL(fileName); |
|
736 |
|
737 // Param 2 defines where we should read archive data from (and how much we should read) |
|
738 const TMMCScBkupArchiveVector* readInfo = (const TMMCScBkupArchiveVector*) aParam2; |
|
739 Info() = *readInfo; |
|
740 } |
|
741 |
|
742 |
|
743 // --------------------------------------------------------------------------- |
|
744 // CMMCScBkupBufferManagerArchiveToFile::InitializeL() |
|
745 // |
|
746 // |
|
747 // --------------------------------------------------------------------------- |
|
748 void CMMCScBkupBufferManagerArchiveToFile::InitializeL( CEZZStream& aZStream ) |
|
749 { |
|
750 // Try to read some data |
|
751 TryToReadMoreSourceDataL(); |
|
752 |
|
753 // Input comes from the base class buffer. Its effectively the |
|
754 // data from the archive. |
|
755 aZStream.SetInput( WriteBuffer() ); |
|
756 |
|
757 // Output goes to our secondary buffer - we'll eventually |
|
758 // write this to the destination file. |
|
759 aZStream.SetOutput( iOutputPointer ); |
|
760 } |
|
761 |
|
762 |
|
763 // --------------------------------------------------------------------------- |
|
764 // CMMCScBkupBufferManagerArchiveToFile::NeedInputL() |
|
765 // |
|
766 // |
|
767 // --------------------------------------------------------------------------- |
|
768 void CMMCScBkupBufferManagerArchiveToFile::NeedInputL( CEZZStream& aZStream ) |
|
769 { |
|
770 // Try to read some more data |
|
771 TryToReadMoreSourceDataL(); |
|
772 aZStream.SetInput( DataView() ); |
|
773 } |
|
774 |
|
775 |
|
776 // --------------------------------------------------------------------------- |
|
777 // CMMCScBkupBufferManagerArchiveToFile::NeedOutputL() |
|
778 // |
|
779 // |
|
780 // --------------------------------------------------------------------------- |
|
781 void CMMCScBkupBufferManagerArchiveToFile::NeedOutputL( CEZZStream& aZStream ) |
|
782 { |
|
783 // Flush output to oure write strategy |
|
784 const TPtrC8 output(aZStream.OutputDescriptor()); |
|
785 const TInt error = iWriteStrategy->Write( output ); |
|
786 User::LeaveIfError( error ); |
|
787 |
|
788 // Reset ready for more writing |
|
789 iOutputPointer.Zero(); |
|
790 aZStream.SetOutput( iOutputPointer ); |
|
791 } |
|
792 |
|
793 |
|
794 // --------------------------------------------------------------------------- |
|
795 // CMMCScBkupBufferManagerArchiveToFile::FinalizeL() |
|
796 // |
|
797 // |
|
798 // --------------------------------------------------------------------------- |
|
799 void CMMCScBkupBufferManagerArchiveToFile::FinalizeL( CEZZStream& aZStream ) |
|
800 { |
|
801 const TPtrC8 output(aZStream.OutputDescriptor()); |
|
802 TInt error = iWriteStrategy->Write( output ); |
|
803 User::LeaveIfError( error ); |
|
804 |
|
805 // No errors writing to temp file, try to finalise write strategy - |
|
806 // essentially this replaces the original file. |
|
807 error = iWriteStrategy->Finalize(); |
|
808 User::LeaveIfError( error ); |
|
809 } |
|
810 |
|
811 |
|
812 // --------------------------------------------------------------------------- |
|
813 // CMMCScBkupBufferManagerArchiveToFile::TryToReadMoreSourceDataL() |
|
814 // |
|
815 // |
|
816 // --------------------------------------------------------------------------- |
|
817 void CMMCScBkupBufferManagerArchiveToFile::TryToReadMoreSourceDataL() |
|
818 { |
|
819 if ( Info().Length() > 0 ) |
|
820 { |
|
821 // Try to read some source data, but don't read beyond the limits |
|
822 const TMMCScBkupArchiveVector& readInfoResult = ADI().ADIReadL( WriteBuffer(), Info() ); |
|
823 |
|
824 // Update remaining read info so that we know where from and how much data |
|
825 // to read next time around |
|
826 const TInt newStartingOffset = readInfoResult.Offset() + readInfoResult.Length(); |
|
827 const TInt remainingToBeRead = Info().Length() - readInfoResult.Length(); |
|
828 // |
|
829 Info().SetOffset( newStartingOffset ); |
|
830 Info().SetLength( remainingToBeRead ); |
|
831 // |
|
832 __LOG2("CMMCScBkupBufferManagerArchiveToFile::TryToReadMoreSourceDataL() - read: %d bytes from archive when reconstructing: %S", readInfoResult.Length(), &iFileName ); |
|
833 // |
|
834 ProgressManager().MMCScBkupHandleProgress( readInfoResult.Length() ); |
|
835 } |
|
836 } |
|
837 |