|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @publishedPartner |
|
19 @released |
|
20 */ |
|
21 |
|
22 #ifndef CMTPTYPEFILE_H |
|
23 #define CMTPTYPEFILE_H |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <f32file.h> |
|
27 #include <mtp/mmtptype.h> |
|
28 |
|
29 /** |
|
30 Defines the MTP file object data type. |
|
31 @publishedPartner |
|
32 @released |
|
33 */ |
|
34 class CMTPTypeFile : public CActive, public MMTPType |
|
35 { |
|
36 public: |
|
37 |
|
38 IMPORT_C static CMTPTypeFile* NewL(RFs& aFs, const TDesC& aFileName, TFileMode aFileMode); |
|
39 IMPORT_C static CMTPTypeFile* NewLC(RFs& aFs, const TDesC& aFileName, TFileMode aFileMode); |
|
40 IMPORT_C static CMTPTypeFile* NewL(RFs& aFs, const TDesC& aFileName, TFileMode aFileMode, TInt64 aRequiredSize, TInt64 aOffSet = 0); |
|
41 IMPORT_C static CMTPTypeFile* NewLC(RFs& aFs, const TDesC& aFileName, TFileMode aFileMode, TInt64 aRequiredSize, TInt64 aOffSet = 0); |
|
42 IMPORT_C ~CMTPTypeFile(); |
|
43 IMPORT_C void SetSizeL(TUint64 aSize); |
|
44 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
45 IMPORT_C RFile64& File(); |
|
46 #else |
|
47 IMPORT_C RFile& File(); |
|
48 #endif |
|
49 |
|
50 public: // From MMTPType |
|
51 IMPORT_C TInt FirstReadChunk(TPtrC8& aChunk) const; |
|
52 IMPORT_C TInt NextReadChunk(TPtrC8& aChunk) const; |
|
53 IMPORT_C TInt FirstWriteChunk(TPtr8& aChunk); |
|
54 IMPORT_C TInt NextWriteChunk(TPtr8& aChunk); |
|
55 IMPORT_C TUint64 Size() const; |
|
56 IMPORT_C TUint Type() const; |
|
57 IMPORT_C TBool CommitRequired() const; |
|
58 IMPORT_C MMTPType* CommitChunkL(TPtr8& aChunk); |
|
59 IMPORT_C TInt64 GetByteSent(); |
|
60 |
|
61 private: |
|
62 CMTPTypeFile(); |
|
63 void ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode); |
|
64 void ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet); |
|
65 void ToggleRdWrBuffer(); |
|
66 |
|
67 protected: // From CActive |
|
68 void DoCancel(); |
|
69 |
|
70 private: // From CActive |
|
71 |
|
72 TInt RunError(TInt aError); |
|
73 void RunL(); |
|
74 private: |
|
75 |
|
76 /** |
|
77 The read and write data stream states. |
|
78 */ |
|
79 enum TReadWriteSequenceState |
|
80 { |
|
81 /** |
|
82 Data stream is inactive. |
|
83 */ |
|
84 EIdle, |
|
85 |
|
86 /** |
|
87 Data stream is in progress. |
|
88 */ |
|
89 EInProgress |
|
90 }; |
|
91 |
|
92 /** |
|
93 The intermediate data buffer. Note that this is declared mutable to allow |
|
94 state updates while processing a read data stream. |
|
95 */ |
|
96 mutable RBuf8 iBuffer1; |
|
97 |
|
98 |
|
99 /** |
|
100 The intermediate data buffer. Note that this is declared mutable to allow |
|
101 state updates while processing a read data stream. |
|
102 Used for double-buffering, the 2 buffers(buffer1 and buffer2) will be switched between reading data |
|
103 from USB to buffer and writting data from Buffer into File System. |
|
104 */ |
|
105 mutable RBuf8 iBuffer2; |
|
106 |
|
107 /** |
|
108 The flag indicate if this buffer is avaiable for writting data into, if true, it is ready for |
|
109 USB-SIC to write file data into it, if false, it already contains file data, and is waiting |
|
110 for writting the file data into file system. |
|
111 The two buffer must be used in strict sequence, if both buffer is available, the buffer1 must |
|
112 be firstly used by USB driver. |
|
113 */ |
|
114 mutable TBool iBuffer1AvailForWrite; |
|
115 |
|
116 //If there occurs error during writting/reading data into/from this file, mark this flag as true, this will abort |
|
117 //all further writting/reading and set the file size to 0 if needed. |
|
118 mutable TBool iFileRdWrError; |
|
119 |
|
120 //This point to the current chunk which is waiting for being commit into File system. it might point to |
|
121 //either of the 2 buffers. |
|
122 mutable TPtr8 iCurrentCommitChunk; |
|
123 |
|
124 //true if the file is opened for reading; false if it is opened for Writting. |
|
125 TBool iFileOpenForRead; |
|
126 |
|
127 //For file reading, used to indicate how much bytes are waiting to be read, for file writting, indicate how much |
|
128 //byte are wating to be received by USB and writting to file. |
|
129 mutable TInt64 iRemainingDataSize; |
|
130 |
|
131 //The RFile::SetSize() method may take over 40 seconds if we create a file and set its size |
|
132 //to a very large value, and this will cause timeout in MTP protocol layer. To avoid this |
|
133 //timeout, when creating a large file(over 512MB), instead of setting its size directly to |
|
134 //the target size by one singile RFile::SetSize() call, we'll call RFile::SetSize() multiple |
|
135 //times and set the file size step by step acumulately. For example, for a 2GB file, its |
|
136 //size will be set to 0.5G first, and then 1G, 1.5G and at last 2G. |
|
137 |
|
138 //For file reading, used to indicate the target size to be transfered to initiator, for file writting, used to |
|
139 //incicate the target size for a file that being transfering to device. |
|
140 TInt64 iTargetFileSize; |
|
141 |
|
142 //This is the acumulated received size for the file represented by this object. |
|
143 TInt64 iTotalReceivedSize; |
|
144 |
|
145 //This represent the current size we call SetSize() to the file. |
|
146 TInt64 iCurrentFileSetSize; |
|
147 /** |
|
148 The data file. Note that this is declared mutable to allow state updates |
|
149 while processing a read data stream. |
|
150 */ |
|
151 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
152 mutable RFile64 iFile; |
|
153 #else |
|
154 mutable RFile iFile; |
|
155 #endif |
|
156 /** |
|
157 The read data stream state variable. Note that this is declared mutable |
|
158 to allow state updates while processing a read data stream. |
|
159 */ |
|
160 mutable TUint iReadSequenceState; |
|
161 |
|
162 /** |
|
163 The write data stream state variable. |
|
164 */ |
|
165 TUint iWriteSequenceState; |
|
166 |
|
167 TInt64 iOffSet; |
|
168 |
|
169 mutable TInt64 iByteSent; |
|
170 |
|
171 }; |
|
172 |
|
173 #endif // CMTPTYPEFILE_H |
|
174 |