|
1 /* |
|
2 * Copyright (c) 2006 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 the License "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: Definition of CFileReader |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CFILEREADER_H |
|
19 #define CFILEREADER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 // MACROS |
|
28 |
|
29 // DATA TYPES |
|
30 enum TFileEvent |
|
31 { |
|
32 EGotResponseBodyData, |
|
33 ESucceeded, |
|
34 EFailed |
|
35 }; |
|
36 |
|
37 // FUNCTION PROTOTYPES |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 class FileConnection; |
|
41 |
|
42 // CLASS DECLARATION |
|
43 |
|
44 /** |
|
45 * This is a simple incremental file reader. |
|
46 * @lib resLoader.lib |
|
47 * @since 3.1 |
|
48 */ |
|
49 class CFileReader : public CActive |
|
50 { |
|
51 public: // Constructors and destructor |
|
52 |
|
53 /** |
|
54 * Two-phased constructor. |
|
55 * @since 3.1 |
|
56 * @param aFile File to read. |
|
57 * @param aChunkSize Chunk size to be read in one turn. |
|
58 * @param aFileReaderCallback Observer object-file transaction. |
|
59 * @return File reader object |
|
60 */ |
|
61 static CFileReader* NewL( RFile& aFile, TInt aChunkSize, FileConnection* aFileConnection ); |
|
62 |
|
63 /** |
|
64 * Destructor. |
|
65 */ |
|
66 virtual ~CFileReader(); |
|
67 |
|
68 public: // New functions |
|
69 |
|
70 /** |
|
71 * Start reading the file from the beginning. |
|
72 * @since 3.1 |
|
73 * @param |
|
74 * @return void |
|
75 */ |
|
76 void StartReading(); |
|
77 |
|
78 /** |
|
79 * Stop reading |
|
80 * @since 3.1 |
|
81 * @param |
|
82 * @return void |
|
83 */ |
|
84 void StopReading(); |
|
85 |
|
86 /** |
|
87 * Get partial body buffer. |
|
88 * @since 3.1 |
|
89 * @param aChunkBuffer Pointer to the partial body buffer |
|
90 * @return void |
|
91 */ |
|
92 void GetChunkBuffer( TPtrC8& aChunkBuffer ); |
|
93 |
|
94 /** |
|
95 * Purge the chunk buffer. |
|
96 * @since 3.1 |
|
97 * @param |
|
98 * @return void |
|
99 */ |
|
100 void ReleaseChunkBuffer(); |
|
101 |
|
102 public: // from CActive |
|
103 |
|
104 /** |
|
105 * Cancel active object |
|
106 * @since 3.1 |
|
107 * @param |
|
108 * @return void |
|
109 */ |
|
110 void DoCancel(); |
|
111 |
|
112 /** |
|
113 * Asynchronous handling of transaction events. |
|
114 * @since 3.1 |
|
115 * @param |
|
116 * @return void |
|
117 */ |
|
118 void RunL(); |
|
119 |
|
120 private: |
|
121 |
|
122 /** |
|
123 * Construct. |
|
124 * @since 3.1 |
|
125 * @param aFile File to read. |
|
126 * @param aChunkSize Chunk size to be read in one turn. |
|
127 * @param aFileReaderCallback Observer object-file transaction. |
|
128 * @return void |
|
129 */ |
|
130 CFileReader( RFile& aFile, TInt aChunkSize, FileConnection* aFileConnection ); |
|
131 |
|
132 /** |
|
133 * By default Symbian 2nd phase constructor is private. |
|
134 */ |
|
135 void ConstructL(); |
|
136 |
|
137 /** |
|
138 * Read from the file from the current position. |
|
139 * @since 3.1 |
|
140 * @param |
|
141 * @return void |
|
142 */ |
|
143 void ReadFile(); |
|
144 |
|
145 private: // Data |
|
146 |
|
147 // file to read |
|
148 RFile m_file; |
|
149 // actual file position |
|
150 TInt m_filePos; |
|
151 // chunk size to read in one turn |
|
152 TInt m_chunkSize; |
|
153 // chunk buffer |
|
154 HBufC8* m_chunkBuffer; |
|
155 // observer object |
|
156 FileConnection* m_fileConnection; |
|
157 // pointer to the chunk buffer |
|
158 TPtr8 m_chunkBufPtr; |
|
159 // ETrue if the file transaction is cancelled |
|
160 TBool m_stopReading; |
|
161 }; |
|
162 |
|
163 #endif // CFILEREADER_H |
|
164 |
|
165 // End of File |