|
1 /* |
|
2 * Copyright (c) 2006-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: Connection multiplexer session abstraction. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef C_CNCMSESSION_H |
|
22 #define C_CNCMSESSION_H |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <in_sock.h> |
|
26 #include <commdbconnpref.h> |
|
27 |
|
28 #include "mncmicmpobserver.h" |
|
29 |
|
30 class CNcmStream; |
|
31 class MNcmConnectionMultiplexerObserver; |
|
32 class MNcmSessionObserver; |
|
33 class CNcmPortStore; |
|
34 class CNcmIcmpV4Receiver; |
|
35 class CNcmIcmpV6Receiver; |
|
36 |
|
37 /** |
|
38 * Connection multiplexer session abstraction. |
|
39 * |
|
40 * @lib connectionmux.lib |
|
41 * @since S60 v3.2 |
|
42 */ |
|
43 NONSHARABLE_CLASS( CNcmSession ) : public CActive, |
|
44 public MNcmIcmpObserver |
|
45 { |
|
46 |
|
47 public: |
|
48 |
|
49 /** |
|
50 * Two-phased constructor |
|
51 * |
|
52 * @param aSessionId The ID identifying session |
|
53 * @param aIapId IAP id |
|
54 * @param aPortRangeStart Port range start for session |
|
55 * @param aPortRangeStop Port range stop for session |
|
56 * @param aObserver Observer |
|
57 * @param aSessionObserver Session observer |
|
58 */ |
|
59 static CNcmSession* NewL( TUint aSessionId, TUint32 aIapId, |
|
60 TUint aPortRangeStart, TUint aPortRangeStop, |
|
61 MNcmConnectionMultiplexerObserver& aObserver, |
|
62 MNcmSessionObserver& aSessionObserver ); |
|
63 |
|
64 /** |
|
65 * Two-phased constructor |
|
66 * |
|
67 * @param aSessionId The ID identifying session |
|
68 * @param aIapId IAP id |
|
69 * @param aPortRangeStart Port range start for session |
|
70 * @param aPortRangeStop Port range stop for session |
|
71 * @param aObserver Observer |
|
72 * @param aSessionObserver Session observer |
|
73 */ |
|
74 static CNcmSession* NewLC( TUint aSessionId, TUint32 aIapId, |
|
75 TUint aPortRangeStart, TUint aPortRangeStop, |
|
76 MNcmConnectionMultiplexerObserver& aObserver, |
|
77 MNcmSessionObserver& aSessionObserver ); |
|
78 |
|
79 /** |
|
80 * Destructor |
|
81 */ |
|
82 virtual ~CNcmSession(); |
|
83 |
|
84 /** |
|
85 * Creates a new stream. On return the client receives a |
|
86 * stream ID. |
|
87 * |
|
88 * @since S60 3.2 |
|
89 * @param aQos The desired quality of service. |
|
90 * @param aProtocol KProtocolInetUdp / KProtocolInetTcp |
|
91 * @return The ID for the created stream |
|
92 */ |
|
93 TUint CreateStreamL( TInt aQos, TUint aProtocol ); |
|
94 |
|
95 /** |
|
96 * Removes stream and all its connections. |
|
97 * |
|
98 * @since S60 3.2 |
|
99 * @param aStreamId The ID identifying stream |
|
100 * @return void |
|
101 */ |
|
102 void RemoveStreamL( TUint aStreamId ); |
|
103 |
|
104 /** |
|
105 * Get session Id |
|
106 * |
|
107 * @since S60 v3.2 |
|
108 * @return Session ID |
|
109 */ |
|
110 TUint SessionId() const; |
|
111 |
|
112 /** |
|
113 * Get IAP Id |
|
114 * |
|
115 * @since S60 v3.2 |
|
116 * @return IAP ID |
|
117 */ |
|
118 TUint32 IapId() const; |
|
119 |
|
120 /** |
|
121 * Gets RSocketServ used on this session |
|
122 * |
|
123 * @since S60 v3.2 |
|
124 * @return RSocketServ used by this session |
|
125 */ |
|
126 RSocketServ& SocketServer(); |
|
127 |
|
128 /** |
|
129 * Gets RConnection used on this session |
|
130 * |
|
131 * @since S60 v3.2 |
|
132 * @return RConnection used by this session |
|
133 */ |
|
134 RConnection& Connection(); |
|
135 |
|
136 /** |
|
137 * Gets the unique name of an RConnection used on this session |
|
138 * |
|
139 * @since S60 v3.2 |
|
140 * @param aConnectionName The unique name of an RConnection |
|
141 * @return system-wide error code |
|
142 */ |
|
143 TInt GetConnectionName( TName& aConnectionName ); |
|
144 |
|
145 /** |
|
146 * Returns stream by identifier. Leaves with KErrNotFound if stream |
|
147 * isn't found. |
|
148 * |
|
149 * @since S60 3.2 |
|
150 * @param aStreamId The ID identifying stream |
|
151 * @return Stream |
|
152 */ |
|
153 CNcmStream* StreamByIdL( TUint aStreamId ); |
|
154 |
|
155 /** |
|
156 * Receives port store |
|
157 * |
|
158 * @since S60 v3.2 |
|
159 * @return port store used on this session |
|
160 */ |
|
161 CNcmPortStore& PortStore() const; |
|
162 |
|
163 /** |
|
164 * Return session initialization status |
|
165 * |
|
166 * @since S60 v3.2 |
|
167 * @return Initialization state ETrue if initialized, |
|
168 * EFalse if not initialized |
|
169 */ |
|
170 TBool Initialized() const; |
|
171 |
|
172 /** |
|
173 * Resolve the destination IP address from FQDN. |
|
174 * ( Address and port ) |
|
175 * |
|
176 * @since S60 v3.2 |
|
177 * @param aAddress The Destination FQDN |
|
178 * @param aPort The Destination port |
|
179 * @param aResult On return contains the resolved IP address |
|
180 * @return void |
|
181 */ |
|
182 void ResolveDestinationAddressL( const TDesC8& aAddress, TUint aPort, |
|
183 TInetAddr& aResult ); |
|
184 |
|
185 /** |
|
186 * Gets the local IPv4 address. |
|
187 * |
|
188 * @since S60 v3.2 |
|
189 * @return Local IPv4 address |
|
190 */ |
|
191 TInetAddr& LocalIPv4Address(); |
|
192 |
|
193 /** |
|
194 * Gets the local IPv6 address. |
|
195 * |
|
196 * @since S60 v3.2 |
|
197 * @return Local IPv6 address |
|
198 */ |
|
199 TInetAddr& LocalIPv6Address(); |
|
200 |
|
201 /** |
|
202 * From MNcmIcmpObserver |
|
203 * |
|
204 * Notifies that an ICMP error is occurred using |
|
205 * the specified remote address. Gets a local address and |
|
206 * a remote address to be used in the creation of the ICMP message. |
|
207 * |
|
208 * @since S60 v3.2 |
|
209 * @param aAddress Remote address on which the error occurred |
|
210 * @param aLocalAddress Reference to local address |
|
211 * @param aRemoteAddress Reference to remote address |
|
212 * @return void |
|
213 */ |
|
214 void IcmpError( const TInetAddr& aAddress, TInetAddr& aLocalAddress, |
|
215 TInetAddr& aRemoteAddress ); |
|
216 |
|
217 protected: |
|
218 |
|
219 // from base class CActive |
|
220 |
|
221 void RunL(); |
|
222 |
|
223 void DoCancel(); |
|
224 |
|
225 TInt RunError( TInt aError ); |
|
226 |
|
227 private: |
|
228 |
|
229 CNcmSession( TUint aSessionId, TUint32 aIapId, |
|
230 MNcmConnectionMultiplexerObserver& aObserver, |
|
231 MNcmSessionObserver& aSessionObserver ); |
|
232 |
|
233 void ConstructL( TUint aPortRangeStart, TUint aPortRangeStop ); |
|
234 |
|
235 TUint StreamIndexL( TUint aStreamId ); |
|
236 |
|
237 TUint GenerateStreamId() const; |
|
238 |
|
239 void HandleIcmpErrorL( const TInetAddr& aAddress, |
|
240 TInetAddr& aLocalAddress, TInetAddr& aRemoteAddress ); |
|
241 |
|
242 private: // data |
|
243 |
|
244 /** |
|
245 * Unique session identifier |
|
246 */ |
|
247 TUint iSessionId; |
|
248 |
|
249 /** |
|
250 * Internet access point identifier |
|
251 */ |
|
252 TUint32 iIapId; |
|
253 |
|
254 /** |
|
255 * Connection for socket |
|
256 * Own. |
|
257 */ |
|
258 RConnection iConnection; |
|
259 |
|
260 /** |
|
261 * Socket server for this connection |
|
262 * Own. |
|
263 */ |
|
264 RSocketServ iSocketServ; |
|
265 |
|
266 /** |
|
267 * Streams created into the session |
|
268 * Own. |
|
269 */ |
|
270 RPointerArray<CNcmStream> iStreams; |
|
271 |
|
272 /** |
|
273 * Handler for connection multiplexer observer |
|
274 */ |
|
275 MNcmConnectionMultiplexerObserver& iObserver; |
|
276 |
|
277 /** |
|
278 * Handler for multiplexer session observer |
|
279 */ |
|
280 MNcmSessionObserver& iSessionObserver; |
|
281 |
|
282 /** |
|
283 * Store where local ports are obtained |
|
284 * Own. |
|
285 */ |
|
286 CNcmPortStore* iPortStore; |
|
287 |
|
288 /** |
|
289 * Flag to indicate whether session is initilized |
|
290 */ |
|
291 TBool iInitialized; |
|
292 |
|
293 /** |
|
294 * Local IPv4 address |
|
295 */ |
|
296 TInetAddr iIpv4Addr; |
|
297 |
|
298 /** |
|
299 * Local IPv6 address |
|
300 */ |
|
301 TInetAddr iIpv6Addr; |
|
302 |
|
303 /** |
|
304 * Connection preferences |
|
305 */ |
|
306 TCommDbConnPref iConnPref; |
|
307 |
|
308 /** |
|
309 * Receives and handles ICMPv4 errors. |
|
310 * Not own. |
|
311 */ |
|
312 CNcmIcmpV4Receiver* iIcmpV4receiver; |
|
313 |
|
314 /** |
|
315 * Receives and handles ICMPv6 errors. |
|
316 * Not own. |
|
317 */ |
|
318 CNcmIcmpV6Receiver* iIcmpV6receiver; |
|
319 }; |
|
320 |
|
321 |
|
322 #endif // C_CNCMSESSION_H |
|
323 |