|
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: Implements double buffering storage functionality for OMA downloads |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef COD_BUFFSTORAGE_H |
|
21 #define COD_BUFFSTORAGE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 class CFileSaver; |
|
29 |
|
30 |
|
31 // CLASS DECLARATION |
|
32 |
|
33 /** |
|
34 * ?one_line_short_description. |
|
35 * ?other_description_lines |
|
36 * |
|
37 * @lib ?library |
|
38 * @since Series 60 v2.8 |
|
39 */ |
|
40 |
|
41 |
|
42 NONSHARABLE_CLASS( CCodBuffStorage ) : public CActive |
|
43 { |
|
44 public: // Constructors and destructor |
|
45 |
|
46 |
|
47 /** |
|
48 * Two-phased constructor. |
|
49 */ |
|
50 static CCodBuffStorage* NewL( CFileSaver* aStorage ); |
|
51 |
|
52 /** |
|
53 * Destructor. |
|
54 */ |
|
55 ~CCodBuffStorage(); |
|
56 |
|
57 public: // Interface |
|
58 |
|
59 /** |
|
60 * Delets the storage buffers. |
|
61 * @param |
|
62 * @return |
|
63 */ |
|
64 void ResetBuffers(); |
|
65 |
|
66 /** |
|
67 * Persist received chunk |
|
68 * @since Series 60 v2.8 |
|
69 * @param aBuf new chunk to be added |
|
70 * @return EFalse if content-length had to be updated. |
|
71 */ |
|
72 TBool WriteOutNextBodyDataL( const TDesC8& aBuf ); |
|
73 |
|
74 /** |
|
75 * If buffering enabled, flush data to disk |
|
76 */ |
|
77 void FlushBuffersL(); |
|
78 |
|
79 /** |
|
80 * Returns buffer size |
|
81 * @since Series 60 v2.8 |
|
82 * @param |
|
83 * @return Buffer size. |
|
84 */ |
|
85 const TInt& CurrentBufferSize() { return iBufferSize; } |
|
86 |
|
87 /** |
|
88 * Clear the error encountered during writing to file |
|
89 * @since Series 60 v2.8 |
|
90 * @param |
|
91 * @return Buffer size. |
|
92 */ |
|
93 void ClearErrors() { iLastWriteErrorCode = KErrNone; } |
|
94 |
|
95 |
|
96 protected: // Functions from base classes |
|
97 |
|
98 |
|
99 private: // From CActive |
|
100 |
|
101 /** |
|
102 * Cancels the timer. |
|
103 * @param |
|
104 * @return |
|
105 */ |
|
106 void DoCancel(); |
|
107 |
|
108 /** |
|
109 * Handles an active object’s request completion event. |
|
110 * @param |
|
111 * @return |
|
112 */ |
|
113 void RunL(); |
|
114 |
|
115 /** |
|
116 * Persist received chunk |
|
117 * @since Series 60 v2.8 |
|
118 * @param aBuf new chunk to be added |
|
119 * @return EFalse if content-length had to be updated. |
|
120 */ |
|
121 void DoBufferingWriteL(const TDesC8& aBuf); |
|
122 //void DoNonbufferingWriteL(const TDesC8& aBuf); |
|
123 |
|
124 private: |
|
125 /** |
|
126 * C++ default constructor. |
|
127 */ |
|
128 CCodBuffStorage(CFileSaver*); |
|
129 |
|
130 /** |
|
131 * By default Symbian 2nd phase constructor is private. |
|
132 */ |
|
133 void ConstructL(); |
|
134 |
|
135 public: // Data |
|
136 |
|
137 |
|
138 protected: // Data |
|
139 |
|
140 |
|
141 private: |
|
142 |
|
143 // Double-buffering |
|
144 HBufC8* iBuff1, *iBuff2; |
|
145 HBufC8* iClientBuffer; |
|
146 TPtr8 *iWritePtr; |
|
147 TInt iBufferSize; |
|
148 |
|
149 // For stalling condition handling |
|
150 TInt iLastWriteErrorCode; |
|
151 CActiveSchedulerWait iWait; |
|
152 |
|
153 // References to CFileSaver data |
|
154 RFile* iFile; |
|
155 TInt& iDownloadedSize; // How much data actually written to finally |
|
156 TInt32& iBufferedSize; // How much data received over the air (but not necessarily all in file yet) |
|
157 |
|
158 TInt32& iHttpStorageBufferSize; //Storage buffer size 128kb(Non-progressive)/16kb(Progressive) |
|
159 TInt32& iHttpStorageLength; //Content Length |
|
160 TBool& iProgressiveDownload; //Flag to indicate Progressive play |
|
161 }; |
|
162 |
|
163 #endif // COD_BUFFSTORAGE_H |
|
164 |
|
165 // End of File |