|
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: CUpnpTcpSessionReader is a class responsible for |
|
15 * asynchronous reading from socket owned by CUpnpTcpSession. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef C_CUPNPTCPSESSIONREADER_H |
|
22 #define C_CUPNPTCPSESSIONREADER_H |
|
23 |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <in_sock.h> |
|
27 #include "upnpnotifytimer.h" |
|
28 |
|
29 class CUpnpTcpSession; |
|
30 |
|
31 /** |
|
32 * CUpnpTcpSessionReader is responsible for asynchronous reading. |
|
33 * Reader starta reading in asynchronous mode. Issues reading and then waits |
|
34 * for the operation to be completed. When it is completed then received |
|
35 * data is forwarded to upper layer - CUpnpTcpSession and the new read |
|
36 * operation is issues. This continues in loop until the Cancel() is invoked |
|
37 * or object is destroyed. |
|
38 * @lib DLNAWebServer.lib |
|
39 * @since Series60 2.6 |
|
40 */ |
|
41 NONSHARABLE_CLASS (CUpnpTcpSessionReader) : public CActive, MUpnpNotifyTimerObserver |
|
42 { |
|
43 |
|
44 public: // Constructors and destructors |
|
45 |
|
46 /** |
|
47 * CUpnpTcpSessionReader factory method. |
|
48 * @since Series60 2.6 |
|
49 * @param aSession session that runs and supervises reader. |
|
50 * @param aSocket socket from which data will be read. |
|
51 * @param aPriority priority with which the reader will be working. |
|
52 * @return new CUpnpTcpSessionReader object's instance. |
|
53 */ |
|
54 static CUpnpTcpSessionReader* NewL( CUpnpTcpSession& aSession, |
|
55 RSocket& aSocket, |
|
56 TThreadPriority aPriority, |
|
57 TInt aBufferSize ); |
|
58 |
|
59 /** |
|
60 * Virtual destructor. |
|
61 * @since Series60 2.6 |
|
62 */ |
|
63 virtual ~CUpnpTcpSessionReader(); |
|
64 |
|
65 public: // New functions |
|
66 |
|
67 /** |
|
68 * Starts reading in asynchronous mode. |
|
69 * @since Series60 2.6 |
|
70 */ |
|
71 void Start(); |
|
72 |
|
73 /** |
|
74 * Cancel the timers |
|
75 * @since Series60 3.2 |
|
76 */ |
|
77 void CancelTimers(); |
|
78 |
|
79 protected: // Functions from CActive |
|
80 |
|
81 /** |
|
82 * Cancels issued reading request. |
|
83 * Standard active object function |
|
84 * @since Series60 2.6 |
|
85 */ |
|
86 void DoCancel(); |
|
87 |
|
88 /** |
|
89 * Function called when the read request is finished. |
|
90 * Standard active object function |
|
91 * @since Series60 2.6 |
|
92 */ |
|
93 void RunL(); |
|
94 |
|
95 /** |
|
96 * Trap RunL leaves |
|
97 * Standard active object function |
|
98 * @since Series60 2.0 |
|
99 */ |
|
100 TInt RunError( TInt aError ); |
|
101 |
|
102 private: // Constructors and destructors |
|
103 |
|
104 /** |
|
105 * CUpnpTcpSessionReader constructor. |
|
106 * @since Series60 2.6 |
|
107 * @param aSession session that runs and supervises reader. |
|
108 * @param aSocket socket from which data will be read. |
|
109 * @param aPriority priority with which the reader will be working. |
|
110 */ |
|
111 CUpnpTcpSessionReader( CUpnpTcpSession& aSession, |
|
112 RSocket& aSocket, |
|
113 TThreadPriority aPriority, |
|
114 TInt aBufferSize ); |
|
115 |
|
116 /** |
|
117 * By default Symbian 2nd phase constructor is private. |
|
118 * @since Series60 2.6 |
|
119 */ |
|
120 void ConstructL(); |
|
121 |
|
122 private: // New functions |
|
123 |
|
124 /** |
|
125 * Issues reading in asynchronous mode. |
|
126 * @since Series60 2.6 |
|
127 */ |
|
128 void IssueRead(); |
|
129 |
|
130 /** |
|
131 * Callback function for timer expirations. |
|
132 * @since Series60 2.6 |
|
133 * @param aTimer Timer that has expired. |
|
134 **/ |
|
135 void TimerEventL( CUpnpNotifyTimer* /*aTimer*/ ); |
|
136 |
|
137 /** |
|
138 * Starts the cancel timer. |
|
139 * @since Series60 3.2 |
|
140 */ |
|
141 void StartCancelTimer(); |
|
142 |
|
143 private: |
|
144 |
|
145 /** |
|
146 * Socket from which the data will be read, not owned. |
|
147 */ |
|
148 RSocket& iSocket; |
|
149 |
|
150 /** |
|
151 * Reference to session that owns this reader. |
|
152 * Session is notified when reader read some data and when |
|
153 * errors occure, not owned. |
|
154 */ |
|
155 CUpnpTcpSession& iSession; |
|
156 |
|
157 /** |
|
158 * Buffer that is used to receive data to session. |
|
159 * Own. |
|
160 */ |
|
161 RBuf8 iReceiveBuffer; |
|
162 |
|
163 /** |
|
164 * Length of data that has been received. |
|
165 */ |
|
166 TSockXfrLength iLen; |
|
167 |
|
168 // Read buffer size |
|
169 TInt iBufferSize; |
|
170 |
|
171 /** |
|
172 * Timer used for retry process. |
|
173 */ |
|
174 CUpnpNotifyTimer *iRetryTimer; |
|
175 |
|
176 /** |
|
177 * Timer used for cancel reciving process. |
|
178 */ |
|
179 CUpnpNotifyTimer *iCancelTimer; |
|
180 |
|
181 /** |
|
182 * Variable indicating when the cancel was called from cancel timer. |
|
183 */ |
|
184 TBool iCancelFromTimer; |
|
185 |
|
186 /** |
|
187 * Count of reading errors. |
|
188 */ |
|
189 TInt iRetryErrorCount; |
|
190 |
|
191 }; |
|
192 |
|
193 |
|
194 #endif // C_CUPNPTCPSESSIONREADER_H |
|
195 |
|
196 // End Of File |