|
1 /* |
|
2 * Copyright (c) 2008 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: Receiver for UDP data |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_RECEIVER_H |
|
20 #define C_RECEIVER_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <in_sock.h> |
|
24 #include "ikesocketdefs.h" |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class MIkeDebug; |
|
28 |
|
29 /** |
|
30 * Receiver callback interface. |
|
31 * |
|
32 * Callback interface for informing that data has been received or error |
|
33 * has occured. |
|
34 * |
|
35 * @lib ikesocket.lib |
|
36 */ |
|
37 NONSHARABLE_CLASS( MReceiverCallback ) |
|
38 { |
|
39 public: |
|
40 /** |
|
41 * Notifies that data has been received. Receiving is continued |
|
42 * automatically. |
|
43 * |
|
44 * @param aUdpData Received UDP data. Ownership transferred. |
|
45 * @param aSrcAddr Source address |
|
46 * @param aLocalPort Local port |
|
47 */ |
|
48 virtual void DataReceived( HBufC8* aUdpData, |
|
49 const TInetAddr& aSrcAddr, |
|
50 const TInt aLocalPort ) = 0; |
|
51 |
|
52 /** |
|
53 * Notifies about receive error. Receiving has been stopped. |
|
54 * |
|
55 * @param aStatus Error status |
|
56 */ |
|
57 virtual void ReceiveError( const TInt aStatus ) = 0; |
|
58 }; |
|
59 |
|
60 /** |
|
61 * Receiver of UDP data. |
|
62 * |
|
63 * This class provides functionality for receiving UDP data from specified |
|
64 * socket (RSocket). Notification that data has been received and unhandled |
|
65 * errors in receiving are notified via MReceiverCallback callback interface. |
|
66 * Received data will be ignored, if data does not correspond to specified |
|
67 * IKE major version. |
|
68 * |
|
69 * @lib ikesocket.lib |
|
70 */ |
|
71 NONSHARABLE_CLASS( CReceiver ) : private CActive |
|
72 { |
|
73 public: |
|
74 /** |
|
75 * Two-phased constructor. |
|
76 * @param aSocket Socket which is used for receiving |
|
77 * @param aCallback Callback interface |
|
78 * @param aDebug Debug trace interface |
|
79 */ |
|
80 static CReceiver* NewL( RSocket& aSocket, |
|
81 MReceiverCallback& aCallback, |
|
82 MIkeDebug& aDebug ); |
|
83 |
|
84 /** |
|
85 * Destructor. |
|
86 */ |
|
87 ~CReceiver(); |
|
88 |
|
89 /** |
|
90 * Sets IKE major version. |
|
91 * |
|
92 * @param aIkeMajorVersion IKE major version |
|
93 */ |
|
94 void SetIkeMajorVersion( const IkeSocket::TIkeMajorVersion aIkeMajorVersion ); |
|
95 |
|
96 /** |
|
97 * Starts receiving UDP data. Notification that data has been received or |
|
98 * notification about unhandled errors will be done via MReceiverCallback |
|
99 * callback interface. |
|
100 * |
|
101 * IKE major version must be set before receiving is started. Received data |
|
102 * will be ignored, if data does not correspond to specified IKE major |
|
103 * version. |
|
104 */ |
|
105 void Receive(); |
|
106 |
|
107 /** |
|
108 * Cancels receiving. |
|
109 */ |
|
110 void CancelReceive(); |
|
111 |
|
112 private: |
|
113 |
|
114 enum TReceiverState |
|
115 { |
|
116 EIdle, // Idle |
|
117 EWaitingData, // Waiting data to become available for reading |
|
118 EReceiving // Receiving data |
|
119 }; |
|
120 |
|
121 CReceiver( RSocket& aSocket, |
|
122 MReceiverCallback& aCallback, |
|
123 MIkeDebug& aDebug ); |
|
124 |
|
125 void ConstructL(); |
|
126 |
|
127 /** |
|
128 * Waits for data to become available for reading. |
|
129 */ |
|
130 void WaitDataAvailable(); |
|
131 |
|
132 /** |
|
133 * Receives data from socket. |
|
134 */ |
|
135 void ReceiveDataL(); |
|
136 |
|
137 /** |
|
138 * Handles received data. |
|
139 */ |
|
140 void HandleDataReceivedL(); |
|
141 |
|
142 /** |
|
143 * Handles error in receiving. |
|
144 */ |
|
145 void HandleError( const TInt aStatus ); |
|
146 |
|
147 /** |
|
148 * Notifies client that data has been received. |
|
149 */ |
|
150 void NotifyDataReceived(); |
|
151 |
|
152 |
|
153 // from base class CActive |
|
154 |
|
155 /** |
|
156 * From CActive. |
|
157 * Handles a leave occurring in RunL(). |
|
158 * |
|
159 * @param aError The leave code |
|
160 */ |
|
161 TInt RunError( TInt aError ); |
|
162 |
|
163 /** |
|
164 * From CActive. |
|
165 * Handles an active object's request completion event about available data |
|
166 * or received data. |
|
167 */ |
|
168 void RunL(); |
|
169 |
|
170 /** |
|
171 * From CActive. |
|
172 * Implements cancellation of an active request. |
|
173 */ |
|
174 void DoCancel(); |
|
175 |
|
176 private: // data |
|
177 |
|
178 /** |
|
179 * Receiver state. |
|
180 * Own. |
|
181 */ |
|
182 TReceiverState iState; |
|
183 |
|
184 /** |
|
185 * Message data. |
|
186 * Own. |
|
187 */ |
|
188 HBufC8* iMsg; |
|
189 |
|
190 /** |
|
191 * Message pointer. |
|
192 * Own. |
|
193 */ |
|
194 TPtr8 iMsgPtr; |
|
195 |
|
196 /** |
|
197 * Flags for Ioctl command. |
|
198 * Own. |
|
199 */ |
|
200 TPckgBuf< TUint > iFlags; |
|
201 |
|
202 /** |
|
203 * Source address. |
|
204 * Own. |
|
205 */ |
|
206 TInetAddr iSrcAddr; |
|
207 |
|
208 /** |
|
209 * IKE major version. |
|
210 * Own. |
|
211 */ |
|
212 TUint iIkeMajorVersion; |
|
213 |
|
214 /** |
|
215 * Socket. |
|
216 * Not own. |
|
217 */ |
|
218 RSocket& iSocket; |
|
219 |
|
220 /** |
|
221 * Callback for completing receiving. |
|
222 * Not own. |
|
223 */ |
|
224 MReceiverCallback& iCallback; |
|
225 |
|
226 /** |
|
227 * Debug trace interface. |
|
228 * Not own. |
|
229 */ |
|
230 MIkeDebug& iDebug; |
|
231 }; |
|
232 |
|
233 |
|
234 #endif // C_RECEIVER_H |
|
235 |