Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __FILEWRITER_H
17 #define __FILEWRITER_H
24 const TInt KFileWriterBufferSizeSmall = 65536;
25 const TInt KFileWriterBufferSizeLarge = (4*65536);
26 const TInt KFileWriterSoftBufLimit = 12;
27 const TInt KFileWriterHardBufLimit = 16;
28 const TInt KFileWriterMinBufferCount = 4; // shouldn't be less than 4
30 // FORWARD DECLARATIONS
36 * Async buffering file writer.
38 NONSHARABLE_CLASS(CFileWriter) : public CActive
41 enum TOutputBufferSize
48 public: // Constructors and destructor
51 * Two-phased constructor.
53 static CFileWriter* NewL( RFile64& aFile, TInt aInitSetSize = 0, TInt aOutputBufferSizeSmall = KFileWriterBufferSizeSmall, TInt aOutputBufferSizeLarge = KFileWriterBufferSizeLarge );
60 public: // New functions
63 * Writes incoming buffer data to internal buffers for writing to disk.
65 * @param aBuf Data to be written
66 * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
68 TInt Write( const TDesC8& aBuf );
71 * Flush internal buffers to disk.
73 * @param aBuf Additional data to be written before flush.
74 * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
76 TInt Flush( const TDesC8& aBuf );
79 * Set file output buffer size
81 * @param aBufferSize Size of buffer.
82 * @param aHandle MP4Handle.
83 * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
85 TInt SetOutputBufferSize( TOutputBufferSize aBufferSize, MP4Handle aHandle );
88 * Set file output buffer count
90 * @param aHandle MP4Handle.
92 void SetOutputBufferCount( MP4Handle aHandle );
94 inline TInt64 OutputFileSize() const
96 return iOutputFileSize;
99 protected: // Functions from base classes
102 * From CActive Cancels async request.
107 * From CActive Called when async request completes.
114 * C++ default constructor.
116 CFileWriter( TInt aInitSetSize, TInt aOutputBufferSizeSmall, TInt aOutputBufferSizeLarge );
119 * By default Symbian 2nd phase constructor is private.
121 void ConstructL( RFile64& aFile );
124 * Writes incoming data to internal buffers and buffer queues..
126 * @param aBuf Data to be added to buffers..
127 * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
129 TInt AddDataToBuffer( const TDesC8& aBuf );
132 * Allocates input and output buffers.
135 void AllocateBuffersL();
138 * Updates output file size and reserves extra space for following writing if iSetSize is set.
139 * Takes into account if the position in the file was changed.
141 void UpdateOutputFileSize();
144 // Whether we are flushing after async write.
146 // Flag whether there is async writing going.
147 TBool iAsyncWritingOngoing;
148 // Flag whether we have received any data.
149 TBool iWritingStarted;
150 // Flag whether init has been done
151 TBool iMemReadyForWriting;
156 // Current set file size
158 // Current output file size
159 TInt64 iOutputFileSize;
161 TInt iOutputBufferSizeSmall;
162 TInt iOutputBufferSizeLarge;
164 // Output buffer size.
165 TInt iOutputBufferSize;
166 // Hard limit for max output buffers
167 TInt iMaxOutputBufHardLimit;
168 // Soft limit for max output buffers
169 TInt iMaxOutputBufSoftLimit;
172 // Output file for writes.
173 RFile64* iOutputFile;
174 // Queue of empty write buffers.
175 RPointerArray<HBufC8> iEmptyBufferQueue;
176 // Queue of full write buffers.
177 RPointerArray<HBufC8> iFullBufferQueue;
179 // Current input buffers for incoming data.
183 #endif //__FILEWRITER_H