equal
deleted
inserted
replaced
232 |
232 |
233 iTargetFileSize = (TInt64)aSize; //keep a record for the target file size |
233 iTargetFileSize = (TInt64)aSize; //keep a record for the target file size |
234 |
234 |
235 iRemainingDataSize = (TInt64)aSize;//Current implemenation does not support file size with 2 x64 |
235 iRemainingDataSize = (TInt64)aSize;//Current implemenation does not support file size with 2 x64 |
236 |
236 |
237 if(iRemainingDataSize> KMTPFileChunkSizeForLargeFile) //512K |
237 CreateDoubleBufferL(iRemainingDataSize); |
238 { |
238 |
239 iBuffer1.CreateMaxL(KMTPFileChunkSizeForLargeFile); |
|
240 iBuffer2.CreateMaxL(KMTPFileChunkSizeForLargeFile); |
|
241 } |
|
242 else |
|
243 { |
|
244 iBuffer1.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
245 iBuffer2.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
246 } |
|
247 if(iRemainingDataSize> KMTPFileSetSizeChunk) |
239 if(iRemainingDataSize> KMTPFileSetSizeChunk) |
248 { |
240 { |
249 //split the setSize to multiple calling of 512M |
241 //split the setSize to multiple calling of 512M |
250 User::LeaveIfError(iFile.SetSize(KMTPFileSetSizeChunk)); |
242 User::LeaveIfError(iFile.SetSize(KMTPFileSetSizeChunk)); |
251 iCurrentFileSetSize = KMTPFileSetSizeChunk; |
243 iCurrentFileSetSize = KMTPFileSetSizeChunk; |
597 #endif |
589 #endif |
598 User::LeaveIfError(iFile.Size(size)); |
590 User::LeaveIfError(iFile.Size(size)); |
599 iRemainingDataSize = size; |
591 iRemainingDataSize = size; |
600 |
592 |
601 //For File reading, NO "SetSizeL()" will be called, therefore, create the buffer here. |
593 //For File reading, NO "SetSizeL()" will be called, therefore, create the buffer here. |
602 if (iRemainingDataSize > KMTPFileChunkSizeForLargeFile) //512K |
594 CreateDoubleBufferL(iRemainingDataSize); |
603 { |
|
604 iBuffer1.CreateMaxL(KMTPFileChunkSizeForLargeFile); |
|
605 iBuffer2.CreateMaxL(KMTPFileChunkSizeForLargeFile); |
|
606 } |
|
607 else |
|
608 { |
|
609 iBuffer1.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
610 iBuffer2.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
611 } |
|
612 } |
595 } |
613 } |
596 } |
614 |
597 |
615 void CMTPTypeFile::ConstructL(const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
598 void CMTPTypeFile::ConstructL(const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
616 { |
599 { |
645 iTargetFileSize = size - aOffSet; |
628 iTargetFileSize = size - aOffSet; |
646 } |
629 } |
647 iRemainingDataSize = iTargetFileSize; |
630 iRemainingDataSize = iTargetFileSize; |
648 |
631 |
649 //For File reading, NO "SetSizeL()" will be called, therefore, create the buffer here. |
632 //For File reading, NO "SetSizeL()" will be called, therefore, create the buffer here. |
650 if (iRemainingDataSize > KMTPFileChunkSizeForLargeFile) //512K |
633 CreateDoubleBufferL(iRemainingDataSize); |
651 { |
|
652 iBuffer1.CreateMaxL(KMTPFileChunkSizeForLargeFile); |
|
653 iBuffer2.CreateMaxL(KMTPFileChunkSizeForLargeFile); |
|
654 } |
|
655 else |
|
656 { |
|
657 iBuffer1.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
658 iBuffer2.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
659 } |
|
660 } |
634 } |
661 } |
635 } |
662 |
636 |
663 void CMTPTypeFile::DoCancel() |
637 void CMTPTypeFile::DoCancel() |
664 { |
638 { |
741 } |
715 } |
742 } |
716 } |
743 |
717 |
744 iBuffer1AvailForWrite = !iBuffer1AvailForWrite;//toggle the flag. |
718 iBuffer1AvailForWrite = !iBuffer1AvailForWrite;//toggle the flag. |
745 } |
719 } |
|
720 |
|
721 /** |
|
722 * Allocate double buffers to write to/read from file |
|
723 * @param aFileSize: the size of the file to be written to or read from |
|
724 * @return void |
|
725 * leave code: KErrNoMemory if there is insufficient memory |
|
726 */ |
|
727 void CMTPTypeFile::CreateDoubleBufferL(TInt64 aFileSize) |
|
728 { |
|
729 if(aFileSize > KMTPFileChunkSizeForLargeFile) //512KB |
|
730 { |
|
731 TInt err = iBuffer1.CreateMax(KMTPFileChunkSizeForLargeFile); |
|
732 TInt err2 = iBuffer2.CreateMax(KMTPFileChunkSizeForLargeFile); |
|
733 TInt bufferSize = KMTPFileChunkSizeForLargeFile; |
|
734 |
|
735 //if one of buffer allocation fails, decrease the buffer size by |
|
736 //a half of it until : |
|
737 //we finally succeed in the allocation Or |
|
738 //the smallest acceptable buffer size KMTPFileChunkSizeForSmallFile(64KB) reaches. |
|
739 while ((err != KErrNone || err2 != KErrNone) && bufferSize != KMTPFileChunkSizeForSmallFile) |
|
740 { |
|
741 iBuffer1.Close(); |
|
742 iBuffer2.Close(); |
|
743 |
|
744 bufferSize /= 2; |
|
745 err = iBuffer1.CreateMax(bufferSize); |
|
746 err2 = iBuffer2.CreateMax(bufferSize); |
|
747 } |
|
748 |
|
749 if ( err != KErrNone || err2 != KErrNone) |
|
750 { |
|
751 //We still can not allocate 2*64KB buffer, just leave under this case |
|
752 iBuffer1.Close(); |
|
753 iBuffer2.Close(); |
|
754 User::Leave(KErrNoMemory); |
|
755 } |
|
756 } |
|
757 else |
|
758 { |
|
759 iBuffer1.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
760 iBuffer2.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
|
761 } |
|
762 } |