1 /* |
|
2 * Copyright (c) 2009 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: Main class for IPProxyEngine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CIPPROXYENGINE_H |
|
21 #define CIPPROXYENGINE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <es_sock.h> |
|
26 #include "MIPProxyEngine.h" |
|
27 #include "Mhostconnectionobserver.h" |
|
28 #include "MLocalTCPConnectionObserver.h" |
|
29 #include "MTCPPortListenerObserver.h" |
|
30 #include "MSocketRouterObserver.h" |
|
31 |
|
32 |
|
33 // FORWARD DECLARATIONS |
|
34 class MHostConnection; |
|
35 class CTCPPortListener; |
|
36 class CSocketRouter; |
|
37 class MIPProxyEngineObserver; |
|
38 class CLocalTCPConnection; |
|
39 class MHostConnection; |
|
40 class MAbstractConnection; |
|
41 |
|
42 // CLASS DECLARATION |
|
43 |
|
44 /** |
|
45 * Main class for IPProxyEngine. |
|
46 */ |
|
47 NONSHARABLE_CLASS( CIPProxyEngine ) : public CActive, |
|
48 public MIPProxyEngine, |
|
49 public MTCPPortListenerObserver, |
|
50 public MHostConnectionObserver, |
|
51 public MLocalTCPConnectionObserver, |
|
52 public MSocketRouterObserver |
|
53 { |
|
54 public: // Constructors and destructor |
|
55 |
|
56 /** |
|
57 * Factory function. |
|
58 * @param aConnection pointer to host connection. |
|
59 */ |
|
60 static CIPProxyEngine* NewL( MAbstractConnection* aConnection ); |
|
61 |
|
62 /** |
|
63 * Factory function. |
|
64 * @param aConnection pointer to host connection. |
|
65 */ |
|
66 static CIPProxyEngine* NewLC( MAbstractConnection* aConnection ); |
|
67 |
|
68 /** |
|
69 * Destructor. |
|
70 */ |
|
71 ~CIPProxyEngine(); |
|
72 |
|
73 |
|
74 protected: // Functions from base classes |
|
75 |
|
76 /** |
|
77 * From CActive. Pending request has been completed. |
|
78 */ |
|
79 void RunL(); |
|
80 |
|
81 /** |
|
82 * From CActive. Pending request has been cancelled. |
|
83 */ |
|
84 void DoCancel(); |
|
85 |
|
86 |
|
87 public: // Functions from base classes |
|
88 |
|
89 /** |
|
90 * From MIPProxyEngine. |
|
91 * Set observer of IPProxyEngine. |
|
92 * @param aObserver Pointer to observer. |
|
93 */ |
|
94 void SetObserver( MIPProxyEngineObserver* aObserver ); |
|
95 |
|
96 /** |
|
97 * From MIPProxyEngine. |
|
98 * Add port to listen. |
|
99 * @param aPort Port to listen. |
|
100 */ |
|
101 void AddPeerListeningPortL( TInt aPort ); |
|
102 |
|
103 /** |
|
104 * From MIPProxyEngine. |
|
105 * Starts listening peers. |
|
106 */ |
|
107 void StartListening(); |
|
108 |
|
109 /** |
|
110 * From MIPProxyEngine. |
|
111 * Stops listening peers. |
|
112 */ |
|
113 void StopListening(); |
|
114 |
|
115 /** |
|
116 * From MIPProxyEngine. |
|
117 * Disconnects all peers and the host connection. |
|
118 */ |
|
119 void DisconnectAllConnections(); |
|
120 |
|
121 protected: // Functions from MTCPPortListenerObserver |
|
122 |
|
123 void ConnectionAcceptedL( RSocket* aSocket ); |
|
124 void ErrorL( TInt aErrorCode ); |
|
125 void ObserverLeaved( TInt aLeaveCode ); |
|
126 |
|
127 protected: // Functions from MHostConnectionObserver |
|
128 |
|
129 void ConnectionEstablishedL(); |
|
130 void HostConnectionErrorL( TInt aErrorCode ); |
|
131 void HostConnectionObserverLeaved( TInt aLeaveCode ); |
|
132 |
|
133 protected: // Functions from MLocalTCPConnectionObserver |
|
134 |
|
135 void LocalTCPConnectionEstablishedL( TUint aPort ); |
|
136 void LocalTCPConnectionErrorL( TInt aPort, TInt aErrorCode ); |
|
137 void LocalTCPConnectionObserverLeaved( TInt aPort, TInt aLeaveCode ); |
|
138 |
|
139 protected: // Functions from MSocketRouterObserver |
|
140 |
|
141 void SocketRouterErrorL( const MSocket* aSocket, TInt aErrorCode ); |
|
142 void ObserverLeaved( const MSocket* aSocket, TInt aLeaveCode ); |
|
143 void PeerDisconnectedL( const MSocket* aSocket ); |
|
144 void HostDisconnectedL( const MSocket* aSocket ); |
|
145 void OpenLocalTCPConnectionL( TUint aPort ); |
|
146 void OpenListeningTCPConnectionL( TUint aPort ); |
|
147 void CloseTCPConnection( TUint aPort ); |
|
148 void CloseAllTCPConnections(); |
|
149 void AssureConnectionL(); |
|
150 |
|
151 protected: |
|
152 |
|
153 /** |
|
154 * Default constructor. |
|
155 */ |
|
156 CIPProxyEngine( MAbstractConnection* aConnection ); |
|
157 |
|
158 /** |
|
159 * 2nd phase constructor. |
|
160 */ |
|
161 void ConstructL(); |
|
162 |
|
163 private: // New functions |
|
164 |
|
165 /** |
|
166 * Helper function to find the correct connection from the local |
|
167 * TCP connection -list. |
|
168 * @param aPort The remote port of the connection to find |
|
169 * @return index of the local conn in the iLocalConnArray |
|
170 */ |
|
171 TInt FindLocalTCPConn( TUint aPort ); |
|
172 |
|
173 private: // Owned data |
|
174 |
|
175 RSocketServ iSocketServ; |
|
176 CArrayPtr<CTCPPortListener>* iPeerListenerArray; |
|
177 CArrayPtr<CLocalTCPConnection>* iLocalConnArray; |
|
178 TBool iListening; |
|
179 CSocketRouter* iSocketRouter; |
|
180 RTimer iTimer; |
|
181 |
|
182 private: // Not owned data |
|
183 MAbstractConnection* iAbstractConnection; |
|
184 MHostConnection* iHostConnection; |
|
185 MIPProxyEngineObserver* iObserver; |
|
186 }; |
|
187 |
|
188 #endif // CIPPROXYENGINE_H |
|
189 |
|
190 // End of File |
|