36 // CFileWriter::CFileWriter |
36 // CFileWriter::CFileWriter |
37 // C++ default constructor can NOT contain any code, that |
37 // C++ default constructor can NOT contain any code, that |
38 // might leave. |
38 // might leave. |
39 // ----------------------------------------------------------------------------- |
39 // ----------------------------------------------------------------------------- |
40 // |
40 // |
41 CFileWriter::CFileWriter() : CActive( EPriorityHigh ) |
41 CFileWriter::CFileWriter( TInt aInitSetSize, TInt aOutputBufferSizeSmall, TInt aOutputBufferSizeLarge ): |
|
42 CActive( EPriorityHigh ), |
|
43 iSetSize( aInitSetSize ), |
|
44 iOutputBufferSizeSmall( aOutputBufferSizeSmall ), |
|
45 iOutputBufferSizeLarge( aOutputBufferSizeLarge ) |
42 { |
46 { |
43 } |
47 } |
44 |
48 |
45 // ----------------------------------------------------------------------------- |
49 // ----------------------------------------------------------------------------- |
46 // CFileWriter::ConstructL |
50 // CFileWriter::ConstructL |
50 void CFileWriter::ConstructL( RFile64& aFile ) |
54 void CFileWriter::ConstructL( RFile64& aFile ) |
51 { |
55 { |
52 PRINT((_L("CFileWriter::ConstructL() in"))); |
56 PRINT((_L("CFileWriter::ConstructL() in"))); |
53 iFlush = EFalse; |
57 iFlush = EFalse; |
54 iError = KErrNone; |
58 iError = KErrNone; |
|
59 |
55 iOutputFile = &aFile; |
60 iOutputFile = &aFile; |
56 iWritingStarted = EFalse; |
61 iWritingStarted = EFalse; |
57 iOutputBufferSize = KFileWriterBufferSizeSmall; |
62 iOutputBufferSize = KFileWriterBufferSizeSmall; |
58 iMaxOutputBufHardLimit = KFileWriterHardBufLimit; |
63 iMaxOutputBufHardLimit = KFileWriterHardBufLimit; |
59 iMaxOutputBufSoftLimit = KFileWriterSoftBufLimit; |
64 iMaxOutputBufSoftLimit = KFileWriterSoftBufLimit; |
71 // ----------------------------------------------------------------------------- |
76 // ----------------------------------------------------------------------------- |
72 // CFileWriter::NewL |
77 // CFileWriter::NewL |
73 // Two-phased constructor. |
78 // Two-phased constructor. |
74 // ----------------------------------------------------------------------------- |
79 // ----------------------------------------------------------------------------- |
75 // |
80 // |
76 CFileWriter* CFileWriter::NewL( RFile64& aFile ) |
81 CFileWriter* CFileWriter::NewL( RFile64& aFile, TInt aInitSetSize, TInt aOutputBufferSizeSmall, TInt aOutputBufferSizeLarge ) |
77 { |
82 { |
78 CFileWriter* self = new(ELeave) CFileWriter; |
83 CFileWriter* self = new(ELeave) CFileWriter( aInitSetSize, aOutputBufferSizeSmall, aOutputBufferSizeLarge ); |
79 CleanupStack::PushL(self); |
84 CleanupStack::PushL(self); |
80 self->ConstructL( aFile ); |
85 self->ConstructL( aFile ); |
81 CleanupStack::Pop(self); |
86 CleanupStack::Pop(self); |
82 return self; |
87 return self; |
83 } |
88 } |
109 iEmptyBufferQueue.ResetAndDestroy(); |
114 iEmptyBufferQueue.ResetAndDestroy(); |
110 iFullBufferQueue.ResetAndDestroy(); |
115 iFullBufferQueue.ResetAndDestroy(); |
111 PRINT((_L("CFileWriter::~CFileWriter() out"))); |
116 PRINT((_L("CFileWriter::~CFileWriter() out"))); |
112 } |
117 } |
113 |
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CFileWriter::UpdateOutputFileSize() |
|
121 // Updates output file size and reserves extra space for following writing |
|
122 // if iSetSize is set. |
|
123 // Takes into account if the position in the file was changed. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CFileWriter::UpdateOutputFileSize() |
|
127 { |
|
128 TInt64 pos = 0; |
|
129 PRINT((_L("e_cfilewriter_write_updateoutputfilesize_seek 1"))); |
|
130 iOutputFile->Seek(ESeekCurrent, pos); |
|
131 PRINT((_L("e_cfilewriter_write_updateoutputfilesize_seek 0"))); |
|
132 |
|
133 PRINT((_L("CFileWriter::UpdateOutputFileSize() pos: %Ld"), pos)); |
|
134 PRINT((_L("CFileWriter::UpdateOutputFileSize() iOutputFileSize: %Ld"), iOutputFileSize)); |
|
135 PRINT((_L("CFileWriter::UpdateOutputFileSize() iSetSize: %Ld"), iSetSize)); |
|
136 |
|
137 if (pos > iOutputFileSize) |
|
138 { |
|
139 iOutputFileSize = pos; |
|
140 } |
|
141 |
|
142 while (iOutputFileSize >= iSetSize) |
|
143 { |
|
144 iSetSize += static_cast<TInt64>(iOutputBufferSize) * (static_cast<TInt64>(iMaxOutputBufHardLimit) >> 1); |
|
145 PRINT((_L("e_cfilewriter_updateoutputfilesize_setsize 1"))); |
|
146 iOutputFile->SetSize( iSetSize ); |
|
147 PRINT((_L("e_cfilewriter_updateoutputfilesize_setsize 0"))); |
|
148 } |
|
149 } |
114 |
150 |
115 // ----------------------------------------------------------------------------- |
151 // ----------------------------------------------------------------------------- |
116 // CFileWriter::Write( const TDesC8& aBuf ) |
152 // CFileWriter::Write( const TDesC8& aBuf ) |
117 // Writes incoming buffer data to internal buffers for writing to disk. |
153 // Writes incoming buffer data to internal buffers for writing to disk. |
118 // (other items were commented in a header). |
154 // (other items were commented in a header). |
231 error = iOutputFile->Write( *iFullBufferQueue[0] ); |
267 error = iOutputFile->Write( *iFullBufferQueue[0] ); |
232 PRINT((_L("e_cfilewriter_flush_writequeue_sync 0"))); |
268 PRINT((_L("e_cfilewriter_flush_writequeue_sync 0"))); |
233 PRINT((_L("e_cfilewriter_flush_remove_buf 1"))); |
269 PRINT((_L("e_cfilewriter_flush_remove_buf 1"))); |
234 if ( error == KErrNone ) |
270 if ( error == KErrNone ) |
235 { |
271 { |
|
272 UpdateOutputFileSize(); |
236 iFullBufferQueue[0]->Des().Zero(); |
273 iFullBufferQueue[0]->Des().Zero(); |
237 if ( iEmptyBufferQueue.Append( iFullBufferQueue[0] ) ) |
274 if ( iEmptyBufferQueue.Append( iFullBufferQueue[0] ) ) |
238 { |
275 { |
239 PRINT(_L("CFileWriter::Flush() Append failed")); |
276 PRINT(_L("CFileWriter::Flush() Append failed")); |
240 delete ( iFullBufferQueue[0] ); |
277 delete ( iFullBufferQueue[0] ); |
255 PRINT((_L("e_cfilewriter_flush_writeinput_sync 1"))); |
292 PRINT((_L("e_cfilewriter_flush_writeinput_sync 1"))); |
256 error = iOutputFile->Write( *iInputBuf ); |
293 error = iOutputFile->Write( *iInputBuf ); |
257 PRINT((_L("e_cfilewriter_flush_writeinput_sync 0"))); |
294 PRINT((_L("e_cfilewriter_flush_writeinput_sync 0"))); |
258 if ( error == KErrNone ) |
295 if ( error == KErrNone ) |
259 { |
296 { |
|
297 UpdateOutputFileSize(); |
260 iInputBuf->Des().Zero(); |
298 iInputBuf->Des().Zero(); |
261 } |
299 } |
262 else |
300 else |
263 { |
301 { |
264 PRINT((_L("CFileWriter::Flush() inputbuf write failed, error: %d"), error)); |
302 PRINT((_L("CFileWriter::Flush() inputbuf write failed, error: %d"), error)); |
291 return KErrNotReady; |
329 return KErrNotReady; |
292 } |
330 } |
293 |
331 |
294 if ( aBufferSize == EBufferSizeSmall ) |
332 if ( aBufferSize == EBufferSizeSmall ) |
295 { |
333 { |
296 size = KFileWriterBufferSizeSmall; |
334 size = iOutputBufferSizeSmall; |
297 } |
335 } |
298 else if ( aBufferSize == EBufferSizeLarge ) |
336 else if ( aBufferSize == EBufferSizeLarge ) |
299 { |
337 { |
300 size = KFileWriterBufferSizeLarge; |
338 size = iOutputBufferSizeLarge; |
301 } |
339 } |
302 else if ( aBufferSize == EBufferSizeCustom ) |
340 else if ( aBufferSize == EBufferSizeCustom ) |
303 { |
341 { |
304 size = handle->mediaWriteBufferSize; |
342 size = handle->mediaWriteBufferSize; |
305 } |
343 } |
466 PRINT((_L("e_cfilewriter_runl 1"))); |
504 PRINT((_L("e_cfilewriter_runl 1"))); |
467 iAsyncWritingOngoing = EFalse; |
505 iAsyncWritingOngoing = EFalse; |
468 |
506 |
469 if ( iStatus == KErrNone ) |
507 if ( iStatus == KErrNone ) |
470 { |
508 { |
471 iOutputFileSize += iFullBufferQueue[0]->Des().Length(); |
509 UpdateOutputFileSize(); |
472 iFullBufferQueue[0]->Des().Zero(); |
510 iFullBufferQueue[0]->Des().Zero(); |
473 iError = iEmptyBufferQueue.Append( iFullBufferQueue[0] ); |
511 iError = iEmptyBufferQueue.Append( iFullBufferQueue[0] ); |
474 if ( iError ) |
512 if ( iError ) |
475 { |
513 { |
476 PRINT((_L("CFileWriter::RunL() Append failed 1 %d"), iError )); |
514 PRINT((_L("CFileWriter::RunL() Append failed 1 %d"), iError )); |
485 PRINT((_L("CFileWriter::RunL() Write error in previous async: %d "), iStatus.Int() )); |
523 PRINT((_L("CFileWriter::RunL() Write error in previous async: %d "), iStatus.Int() )); |
486 iError = iStatus.Int(); |
524 iError = iStatus.Int(); |
487 return; |
525 return; |
488 } |
526 } |
489 |
527 |
490 PRINT((_L("CFileWriter::RunL() Buffer written, Status: Full:%d Empty:%d Filesize:%d"), iFullBufferQueue.Count(), iEmptyBufferQueue.Count(), iOutputFileSize )); |
528 PRINT((_L("CFileWriter::RunL() Buffer written, Status: Full:%d Empty:%d Filesize:%Ld"), iFullBufferQueue.Count(), iEmptyBufferQueue.Count(), iOutputFileSize )); |
491 |
529 |
492 if ( iFlush ) |
530 if ( iFlush ) |
493 { |
531 { |
494 PRINT(_L("CFileWriter::RunL() out, flushing")); |
532 PRINT(_L("CFileWriter::RunL() out, flushing")); |
495 PRINT((_L("e_cfilewriter_runl 0"))); |
533 PRINT((_L("e_cfilewriter_runl 0"))); |
503 PRINT((_L("e_cfilewriter_runl_write 1"))); |
541 PRINT((_L("e_cfilewriter_runl_write 1"))); |
504 iError = iOutputFile->Write( *iFullBufferQueue[0]); |
542 iError = iOutputFile->Write( *iFullBufferQueue[0]); |
505 PRINT((_L("e_cfilewriter_runl_write 0"))); |
543 PRINT((_L("e_cfilewriter_runl_write 0"))); |
506 if ( iError == KErrNone ) |
544 if ( iError == KErrNone ) |
507 { |
545 { |
508 iOutputFileSize += iFullBufferQueue[0]->Des().Length(); |
546 UpdateOutputFileSize(); |
509 iFullBufferQueue[0]->Des().Zero(); |
547 iFullBufferQueue[0]->Des().Zero(); |
510 iError = iEmptyBufferQueue.Append( iFullBufferQueue[0] ); |
548 iError = iEmptyBufferQueue.Append( iFullBufferQueue[0] ); |
511 if ( iError ) |
549 if ( iError ) |
512 { |
550 { |
513 PRINT((_L("CFileWriter::RunL() Append failed 2 %d"), iError)); |
551 PRINT((_L("CFileWriter::RunL() Append failed 2 %d"), iError)); |
514 delete ( iFullBufferQueue[0] ); |
552 delete ( iFullBufferQueue[0] ); |
515 iFullBufferQueue.Remove( 0 ); |
553 iFullBufferQueue.Remove( 0 ); |
516 return; |
554 return; |
517 } |
555 } |
518 iFullBufferQueue.Remove( 0 ); |
556 iFullBufferQueue.Remove( 0 ); |
519 PRINT((_L("CFileWriter::RunL() Hardlimit : Buffer sync written, Status: Full:%d Empty:%d Filesize:%d"), iFullBufferQueue.Count(), iEmptyBufferQueue.Count(), iOutputFileSize )); |
557 PRINT((_L("CFileWriter::RunL() Hardlimit : Buffer sync written, Status: Full:%d Empty:%d Filesize:%Ld"), iFullBufferQueue.Count(), iEmptyBufferQueue.Count(), iOutputFileSize )); |
520 } |
558 } |
521 else |
559 else |
522 { |
560 { |
523 PRINT((_L("CFileWriter::RunL() Write error: %d "), iError)); |
561 PRINT((_L("CFileWriter::RunL() Write error: %d "), iError)); |
524 return; |
562 return; |
531 PRINT((_L("e_cfilewriter_runl_outfile_write 1"))); |
569 PRINT((_L("e_cfilewriter_runl_outfile_write 1"))); |
532 iError = iOutputFile->Write( *iFullBufferQueue[0]); |
570 iError = iOutputFile->Write( *iFullBufferQueue[0]); |
533 PRINT((_L("e_cfilewriter_runl_outfile_write 0"))); |
571 PRINT((_L("e_cfilewriter_runl_outfile_write 0"))); |
534 if ( iError == KErrNone ) |
572 if ( iError == KErrNone ) |
535 { |
573 { |
536 iOutputFileSize += iFullBufferQueue[0]->Des().Length(); |
574 UpdateOutputFileSize(); |
537 iFullBufferQueue[0]->Des().Zero(); |
575 iFullBufferQueue[0]->Des().Zero(); |
538 iError = iEmptyBufferQueue.Append( iFullBufferQueue[0] ); |
576 iError = iEmptyBufferQueue.Append( iFullBufferQueue[0] ); |
539 if ( iError ) |
577 if ( iError ) |
540 { |
578 { |
541 PRINT((_L("CFileWriter::RunL() Append failed 3 %d"), iError)); |
579 PRINT((_L("CFileWriter::RunL() Append failed 3 %d"), iError)); |
542 delete ( iFullBufferQueue[0] ); |
580 delete ( iFullBufferQueue[0] ); |
543 iFullBufferQueue.Remove( 0 ); |
581 iFullBufferQueue.Remove( 0 ); |
544 return; |
582 return; |
545 } |
583 } |
546 iFullBufferQueue.Remove( 0 ); |
584 iFullBufferQueue.Remove( 0 ); |
547 PRINT((_L("CFileWriter::RunL() Softlimit : Buffer sync written, Status: Full:%d Empty:%d Filesize:%d"), iFullBufferQueue.Count(), iEmptyBufferQueue.Count(), iOutputFileSize )); |
585 PRINT((_L("CFileWriter::RunL() Softlimit : Buffer sync written, Status: Full:%d Empty:%d Filesize:%Ld"), iFullBufferQueue.Count(), iEmptyBufferQueue.Count(), iOutputFileSize )); |
548 } |
586 } |
549 else |
587 else |
550 { |
588 { |
551 PRINT((_L("CFileWriter::RunL() Write error: %d "), iError)); |
589 PRINT((_L("CFileWriter::RunL() Write error: %d "), iError)); |
552 return; |
590 return; |