19 */ |
19 */ |
20 #include <centralrepository.h> |
20 #include <centralrepository.h> |
21 #include <mtp/cmtptypefile.h> |
21 #include <mtp/cmtptypefile.h> |
22 #include <mtp/mtpdatatypeconstants.h> |
22 #include <mtp/mtpdatatypeconstants.h> |
23 |
23 |
24 #include "mtpframeworkconst.h" |
|
25 |
|
26 //This file is exported from s60 sdk, now just copy it |
24 //This file is exported from s60 sdk, now just copy it |
27 //to make sure onb can run |
25 //to make sure onb can run |
28 #include "UiklafInternalCRKeys.h" |
26 #include "UiklafInternalCRKeys.h" |
29 |
27 |
30 // File type constants. |
28 // File type constants. |
139 @leave One of the system wide error codes, if a processing failure occurs. |
137 @leave One of the system wide error codes, if a processing failure occurs. |
140 @see TFileMode |
138 @see TFileMode |
141 */ |
139 */ |
142 EXPORT_C CMTPTypeFile* CMTPTypeFile::NewLC(RFs& aFs, const TDesC& aName, TFileMode aMode) |
140 EXPORT_C CMTPTypeFile* CMTPTypeFile::NewLC(RFs& aFs, const TDesC& aName, TFileMode aMode) |
143 { |
141 { |
144 CMTPTypeFile* self = new(ELeave) CMTPTypeFile; |
142 CMTPTypeFile* self = new(ELeave) CMTPTypeFile(aFs); |
145 CleanupStack::PushL(self); |
143 CleanupStack::PushL(self); |
146 self->ConstructL(aFs, aName, aMode); |
144 self->ConstructL(aName, aMode); |
147 return self; |
145 return self; |
148 } |
146 } |
149 |
147 |
150 EXPORT_C CMTPTypeFile* CMTPTypeFile::NewL(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
148 EXPORT_C CMTPTypeFile* CMTPTypeFile::NewL(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
151 { |
149 { |
154 return self; |
152 return self; |
155 } |
153 } |
156 |
154 |
157 EXPORT_C CMTPTypeFile* CMTPTypeFile::NewLC(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
155 EXPORT_C CMTPTypeFile* CMTPTypeFile::NewLC(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
158 { |
156 { |
159 CMTPTypeFile* self = new(ELeave) CMTPTypeFile; |
157 CMTPTypeFile* self = new(ELeave) CMTPTypeFile(aFs); |
160 CleanupStack::PushL(self); |
158 CleanupStack::PushL(self); |
161 self->ConstructL(aFs, aName, aMode, aRequiredSize, aOffSet); |
159 self->ConstructL(aName, aMode, aRequiredSize, aOffSet); |
162 return self; |
160 return self; |
163 } |
161 } |
164 |
162 |
165 /** |
163 /** |
166 Destructor |
164 Destructor |
186 //Firstly, check the disk free space, at anytime, we must make sure |
184 //Firstly, check the disk free space, at anytime, we must make sure |
187 //the free space can not be lower than the threshold value after this |
185 //the free space can not be lower than the threshold value after this |
188 //file syncing |
186 //file syncing |
189 TInt driveNo; |
187 TInt driveNo; |
190 TDriveInfo driveInfo; |
188 TDriveInfo driveInfo; |
191 iFile.Drive(driveNo,driveInfo); |
189 User::LeaveIfError(iFile.Drive(driveNo,driveInfo)); |
192 RFs fs; |
190 |
193 TVolumeInfo volumeInfo; |
191 TVolumeInfo volumeInfo; |
194 fs.Connect(); |
192 User::LeaveIfError(iFs.Volume(volumeInfo,driveNo)); |
195 fs.Volume(volumeInfo,driveNo); |
|
196 fs.Close(); |
|
197 |
193 |
198 //Read the threshold value from Central Repository and check against it |
194 //Read the threshold value from Central Repository and check against it |
199 CRepository* repository(NULL); |
195 CRepository* repository(NULL); |
200 TInt64 thresholdValue(0); |
196 TInt64 thresholdValue(0); |
201 TRAPD(err,repository = CRepository::NewL(KCRUidUiklaf)); |
197 TRAPD(err,repository = CRepository::NewL(KCRUidUiklaf)); |
569 EXPORT_C Int64 CMTPTypeFile::GetByteSent() |
565 EXPORT_C Int64 CMTPTypeFile::GetByteSent() |
570 { |
566 { |
571 return iByteSent; |
567 return iByteSent; |
572 } |
568 } |
573 |
569 |
574 CMTPTypeFile::CMTPTypeFile() : |
570 CMTPTypeFile::CMTPTypeFile(RFs& aFs) : |
575 CActive(EPriorityUserInput), iBuffer1AvailForWrite(ETrue), |
571 CActive(EPriorityUserInput), iBuffer1AvailForWrite(ETrue), |
576 iFileRdWrError(EFalse), iCurrentCommitChunk(NULL, 0) |
572 iFileRdWrError(EFalse), iCurrentCommitChunk(NULL, 0), |
|
573 iFs(aFs) |
577 { |
574 { |
578 CActiveScheduler::Add(this); |
575 CActiveScheduler::Add(this); |
579 } |
576 } |
580 |
577 |
581 void CMTPTypeFile::ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode) |
578 void CMTPTypeFile::ConstructL(const TDesC& aName, TFileMode aMode) |
582 { |
579 { |
583 if (aMode & EFileWrite) |
580 if (aMode & EFileWrite) |
584 { |
581 { |
585 iFileOpenForRead = EFalse; |
582 iFileOpenForRead = EFalse; |
586 TInt err = iFile.Create(aFs, aName, aMode|EFileWriteDirectIO); |
583 TInt err = iFile.Create(iFs, aName, aMode|EFileWriteDirectIO); |
587 if (err != KErrNone) |
584 if (err != KErrNone) |
588 { |
585 { |
589 User::LeaveIfError(iFile.Replace(aFs, aName, aMode|EFileWriteDirectIO)); |
586 User::LeaveIfError(iFile.Replace(iFs, aName, aMode|EFileWriteDirectIO)); |
590 } |
587 } |
591 } |
588 } |
592 else |
589 else |
593 { |
590 { |
594 iFileOpenForRead = ETrue; |
591 iFileOpenForRead = ETrue; |
595 User::LeaveIfError(iFile.Open(aFs, aName, aMode|EFileReadDirectIO|EFileShareReadersOnly)); |
592 User::LeaveIfError(iFile.Open(iFs, aName, aMode|EFileReadDirectIO|EFileShareReadersOnly)); |
596 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
593 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
597 TInt64 size = 0; |
594 TInt64 size = 0; |
598 #else |
595 #else |
599 TInt size = 0; |
596 TInt size = 0; |
600 #endif |
597 #endif |
613 iBuffer2.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
610 iBuffer2.CreateMaxL(KMTPFileChunkSizeForSmallFile); |
614 } |
611 } |
615 } |
612 } |
616 } |
613 } |
617 |
614 |
618 void CMTPTypeFile::ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
615 void CMTPTypeFile::ConstructL(const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
619 { |
616 { |
620 if (aMode & EFileWrite) |
617 if (aMode & EFileWrite) |
621 { |
618 { |
622 iFileOpenForRead = EFalse; |
619 iFileOpenForRead = EFalse; |
623 TInt err = iFile.Create(aFs, aName, aMode|EFileWriteDirectIO); |
620 TInt err = iFile.Create(iFs, aName, aMode|EFileWriteDirectIO); |
624 if (err != KErrNone) |
621 if (err != KErrNone) |
625 { |
622 { |
626 User::LeaveIfError(iFile.Replace(aFs, aName, aMode|EFileWriteDirectIO)); |
623 User::LeaveIfError(iFile.Replace(iFs, aName, aMode|EFileWriteDirectIO)); |
627 } |
624 } |
628 } |
625 } |
629 else |
626 else |
630 { |
627 { |
631 iFileOpenForRead = ETrue; |
628 iFileOpenForRead = ETrue; |
632 iOffSet = aOffSet; |
629 iOffSet = aOffSet; |
633 User::LeaveIfError(iFile.Open(aFs, aName, aMode|EFileReadDirectIO|EFileShareReadersOnly)); |
630 User::LeaveIfError(iFile.Open(iFs, aName, aMode|EFileReadDirectIO|EFileShareReadersOnly)); |
634 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
631 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
635 TInt64 size = 0; |
632 TInt64 size = 0; |
636 #else |
633 #else |
637 TInt size = 0; |
634 TInt size = 0; |
638 #endif |
635 #endif |