|
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 #ifndef ASYNCFILEWRITER_H |
|
17 |
|
18 #include <e32base.h> |
|
19 |
|
20 #define ASYNCFILEWRITER_H |
|
21 /** |
|
22 @file |
|
23 @internalComponent |
|
24 */ |
|
25 |
|
26 #if defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES) |
|
27 |
|
28 /** |
|
29 Callback interface which is used to notify a client that a buffer has been |
|
30 written |
|
31 */ |
|
32 class MBufferWrittenObserver |
|
33 { |
|
34 public: |
|
35 virtual void BufferWritten(const TPtrC8& aWritten, TInt aErrorCode)=0; |
|
36 }; |
|
37 |
|
38 class CBufferPool; |
|
39 class RFile; |
|
40 |
|
41 // can be used to emulate slow media on emulator |
|
42 // for debugging/unittest purpose |
|
43 #if ( defined(__WINS__) || defined(_DEBUG) ) |
|
44 # define WRITER_EMULATE_SLOW_MEDIA |
|
45 #endif |
|
46 |
|
47 #ifdef WRITER_EMULATE_SLOW_MEDIA |
|
48 const TUid KUidIclTestEmulateSlowMedia = { 0x10273823 }; |
|
49 class CCallbackTimer; |
|
50 #endif |
|
51 |
|
52 /** |
|
53 Asynchronous file writer which manages memory buffers and provides with |
|
54 asynchronous file writing service, which gives performance increase |
|
55 in case of writing large files (> 64K) onto slow/high latency media |
|
56 */ |
|
57 class CAsyncFileWriter; //declared here |
|
58 NONSHARABLE_CLASS( CAsyncFileWriter ): public CActive |
|
59 { |
|
60 private: |
|
61 enum |
|
62 { |
|
63 // defines maximum number of pending buffers which can be held in the Q, must be power of 2 |
|
64 KMaxNumOfBuffers = 4, |
|
65 }; |
|
66 public: |
|
67 |
|
68 static CAsyncFileWriter* NewL(MBufferWrittenObserver& aObserver, RFile& aFile, TInt aBufferSize); |
|
69 |
|
70 ~CAsyncFileWriter(); |
|
71 |
|
72 /** |
|
73 To check a buffer out of the buffer pool, |
|
74 @return buffer pointer |
|
75 */ |
|
76 void CheckBufferOut(TPtr8& aBuffer); |
|
77 /** |
|
78 To return a buffer back to the buffer pool, |
|
79 @param buffer pointer |
|
80 */ |
|
81 void CheckBufferIn(const TPtrC8& aBuffer); |
|
82 |
|
83 /** |
|
84 To put a buffer into file writing Q |
|
85 */ |
|
86 void WriteBufferL(const TDesC8& aBuf, TInt aFilePos); |
|
87 /** |
|
88 To write all the pending buffers synchronously |
|
89 */ |
|
90 TInt FlushBuffers(); |
|
91 |
|
92 private: |
|
93 CAsyncFileWriter(MBufferWrittenObserver& aObserver, RFile& aFile); |
|
94 |
|
95 void ConstructL(TInt aBufferSize); |
|
96 |
|
97 void RunL(); |
|
98 void DoCancel(); |
|
99 TInt WriteNextBuffer(); |
|
100 TInt WaitForCurrentBuffer(); |
|
101 void HandleBufferCompletion(TInt aError); |
|
102 |
|
103 TPtrC8 iBufPtr[KMaxNumOfBuffers]; // array of pending buffer pointers |
|
104 TInt iFilePos[KMaxNumOfBuffers]; // array of positions within the destination file |
|
105 TInt iCurrentBuf; // index of the current buffer being written |
|
106 TInt iNumOfPendingBuffs; // number of buffer pointer in the Q |
|
107 MBufferWrittenObserver& iObserver; // observer interface pointer |
|
108 RFile* const iFile; // destination file handle |
|
109 CBufferPool* iBufferPool; // memory buffer manager |
|
110 |
|
111 #ifdef WRITER_EMULATE_SLOW_MEDIA // can be used to emulate slow media (for testing) |
|
112 static TInt TimerGate(TAny* aPtr); |
|
113 CCallbackTimer* iCallbackTimer; |
|
114 TBool iDelayOff; |
|
115 public: |
|
116 TBool iEmulateSlowMedia; |
|
117 #endif |
|
118 }; |
|
119 |
|
120 #endif // defined(SYMBIAN_ENABLE_ENCODER_ASYNC_WRITES) |
|
121 |
|
122 #endif // ndef ASYNCFILEWRITER_H |
|
123 |