|
1 /** @file |
|
2 * Copyright (c) 2005-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 "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: CUpnpHttpFileTransferWriter is a class responsible for |
|
15 * asynchronous writing to a socket owned by CUpnpTcpSession. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef C_UPNPHTTPFILETRANSFERWRITER_H |
|
22 #define C_UPNPHTTPFILETRANSFERWRITER_H |
|
23 |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <in_sock.h> |
|
27 #include "upnpretrywrite.h" |
|
28 |
|
29 class CUpnpTcpSession; |
|
30 class CUpnpHttpFileAccess; |
|
31 |
|
32 /** |
|
33 * CUpnpHttpFileTransferWriter is responsible for asynchronous writing. |
|
34 * Writer class is owned by CUpnpTcpSession which request asynchronous |
|
35 * writing from it and is notified by writer when the write request |
|
36 * is completed or an error occured. |
|
37 * When writer receives data to send it checks if it can be sent to the socket |
|
38 * right away and if session is not yet connected or writer already sends data |
|
39 * then it queues incoming data. When writing to the socket ends, writer checks |
|
40 * if there is data in queue waiting for sending. If thereis then it issues writing it |
|
41 * until the queue is empty. After writing all data, the writer notifies session about |
|
42 * completion of the writing taska and switches to waiting state until it receives |
|
43 * another write request. |
|
44 * @lib DLNAWebServer.lib |
|
45 * @since Series60 3.2 |
|
46 */ |
|
47 NONSHARABLE_CLASS (CUpnpHttpFileTransferWriter) : public CActive, MUpnpRetryWriteObserver |
|
48 { |
|
49 public: |
|
50 |
|
51 /** |
|
52 * CUpnpHttpFileTransferWriter factory method. |
|
53 * @since Series60 3.2 |
|
54 * @param aSession session that runs and supervises reader. |
|
55 * @param aSocket socket from which data will be read. |
|
56 * @param aPriority priority with which the reader will be working. |
|
57 */ |
|
58 static CUpnpHttpFileTransferWriter* NewL( CUpnpTcpSession& aSession, |
|
59 RSocket& aSocket, |
|
60 TThreadPriority aPriority, |
|
61 TInt aWriteSize); |
|
62 |
|
63 /** |
|
64 * Virtual destructor. |
|
65 * @since Series60 3.2 |
|
66 */ |
|
67 virtual ~CUpnpHttpFileTransferWriter(); |
|
68 |
|
69 public: // New functions |
|
70 |
|
71 |
|
72 /** |
|
73 * Passes control to the reader |
|
74 * @since series60 3.2 |
|
75 */ |
|
76 void StartL(); |
|
77 |
|
78 /** |
|
79 * Resets state of the writer |
|
80 * @since series60 3.2 |
|
81 */ |
|
82 void Reset(); |
|
83 |
|
84 /** |
|
85 * Indicates it writer is waiting for connection |
|
86 * @since series60 3.2 |
|
87 */ |
|
88 TBool IsWaiting(); |
|
89 |
|
90 /** |
|
91 * Indicates it writer is in use |
|
92 * @since series60 3.2 |
|
93 */ |
|
94 TBool IsActivated(); |
|
95 |
|
96 /** |
|
97 * Indicates it iRetryWrite object is waiting to rewrite |
|
98 * @since series60 3.2 |
|
99 */ |
|
100 TBool IsRetrying(); |
|
101 |
|
102 /** |
|
103 * Indicates it file download is cancelled |
|
104 * @since series60 3.2 |
|
105 */ |
|
106 TBool IsCancelled(); |
|
107 |
|
108 /** |
|
109 * Sets that post notification is need |
|
110 * @since series60 3.2 |
|
111 */ |
|
112 void SetPostNotify(); |
|
113 |
|
114 private: // from MUpnpRetryWriteObserver |
|
115 |
|
116 /** |
|
117 * Called when retrying of writing was succesed. |
|
118 * @since Series60 3.2 |
|
119 */ |
|
120 void RetryWriteSucceed(); |
|
121 |
|
122 /** |
|
123 * Called when retrying of writing fail. |
|
124 * @since Series60 3.2 |
|
125 */ |
|
126 void RetryWriteFailL( TInt aError ); |
|
127 |
|
128 |
|
129 protected: // Functions from base CActive |
|
130 |
|
131 /** |
|
132 * Cancels issued writing request. |
|
133 * Standard active object function |
|
134 * @since Series60 3.2 |
|
135 */ |
|
136 void DoCancel(); |
|
137 |
|
138 /** |
|
139 * Function called when the write request is finished. |
|
140 * Standard active object function |
|
141 * @since Series60 3.2 |
|
142 */ |
|
143 void RunL(); |
|
144 |
|
145 /** |
|
146 * Trap RunL leaves |
|
147 * Standard active object function |
|
148 * @since Series60 3.2 |
|
149 */ |
|
150 TInt RunError( TInt aError ); |
|
151 |
|
152 private: // Constructors and destructors |
|
153 |
|
154 /** |
|
155 * CUpnpHttpFileTransferWriter constructor. |
|
156 * @since Series60 3.2 |
|
157 * @param aSession session that runs and supervises reader. |
|
158 * @param aSocket socket from which data will be read. |
|
159 * @param aPriority priority with which the reader will be working. |
|
160 * @param aWriteSize |
|
161 */ |
|
162 CUpnpHttpFileTransferWriter( CUpnpTcpSession& aSession, |
|
163 RSocket& aSocket, |
|
164 TThreadPriority aPriority, |
|
165 TInt aWriteSize); |
|
166 |
|
167 /** |
|
168 * By default Symbian 2nd phase constructor is private. |
|
169 * @since Series60 3.2 |
|
170 */ |
|
171 void ConstructL(); |
|
172 |
|
173 /** |
|
174 * Sends next queued write request if such exists. |
|
175 * @since Series60 3.2 |
|
176 */ |
|
177 void SendNextPortionL(); |
|
178 |
|
179 /** |
|
180 * Sends HTTP headers |
|
181 * @since Series60 3.2 |
|
182 */ |
|
183 void SendHeadersL(); |
|
184 |
|
185 |
|
186 /** |
|
187 * Writes to the socket |
|
188 * @since Series60 3.2 |
|
189 */ |
|
190 void WriteToSocket(); |
|
191 |
|
192 /** |
|
193 * Finishes downloading |
|
194 * @since Series60 3.2 |
|
195 */ |
|
196 void FinishL(); |
|
197 |
|
198 /** |
|
199 * Handles RunL error |
|
200 * @since Series60 3.2 |
|
201 */ |
|
202 void HandleErrorL(); |
|
203 |
|
204 private: // Enumerations |
|
205 |
|
206 /** |
|
207 * TWriteState, records whether a write request is pending. |
|
208 * - EUnknown Initial state |
|
209 * - EHeaders Sending headers |
|
210 * - EContent Sending content |
|
211 * - ECancelled Writing to the socket is cancelled |
|
212 */ |
|
213 |
|
214 enum TFileTransferWriterState |
|
215 { |
|
216 EUnknown, |
|
217 EHeaders, |
|
218 EContent, |
|
219 EFinished, |
|
220 ECancelled |
|
221 }; |
|
222 |
|
223 private: // Data |
|
224 |
|
225 /** |
|
226 * Socket used for writing data, not owned. |
|
227 */ |
|
228 RSocket& iSocket; |
|
229 |
|
230 /** |
|
231 * Reference to session that owns the writer. |
|
232 * Session is request writing and is notified when it's finished or |
|
233 * errors occure, not owned. |
|
234 */ |
|
235 CUpnpTcpSession& iSession; |
|
236 |
|
237 /** |
|
238 * State of the writer. |
|
239 */ |
|
240 TFileTransferWriterState iState; |
|
241 |
|
242 /** |
|
243 * Buffer that is used to send data. |
|
244 */ |
|
245 RBuf8 iSendBuffer; |
|
246 |
|
247 /** |
|
248 * Pointer to data to be sent |
|
249 */ |
|
250 TPtr8 iSendPointer; |
|
251 |
|
252 |
|
253 /** |
|
254 * Size of the write buffer |
|
255 */ |
|
256 TInt iWriteSize; |
|
257 |
|
258 /** |
|
259 * Indicates when writed needs to wait for connecting to the remote host |
|
260 */ |
|
261 TBool iWaiting; |
|
262 |
|
263 /** |
|
264 * Indicates when POST is being sent |
|
265 */ |
|
266 TBool iHttpPostStarted; |
|
267 |
|
268 /** |
|
269 * Implementation of retrying write to the socket |
|
270 */ |
|
271 CUpnpRetryWrite* iRetryWrite; |
|
272 |
|
273 }; |
|
274 |
|
275 #endif // C_UPNPHTTPFILETRANSFERWRITER_H |
|
276 |
|
277 // End Of File |