|
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: ECOM plugin to communicate over IP port |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CHTICONNECTIONMANAGER_H |
|
20 #define CHTICONNECTIONMANAGER_H |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include <HTICommPluginInterface.h> // defined in HtiFramework project |
|
25 #include <es_sock.h> |
|
26 #include <in_sock.h> |
|
27 #include <CommDbConnPref.h> |
|
28 |
|
29 #include "HtiIPCommServerCommon.h" |
|
30 #include "HtiSocketMonitor.h" |
|
31 #include "HtiIPCommServer.h" |
|
32 |
|
33 |
|
34 // FORWARD DECLARATIONS |
|
35 class CHtiIPCommServer; |
|
36 class CHtiCfg; |
|
37 |
|
38 // CLASS DECLARATION |
|
39 |
|
40 class MHtiTimerObserver |
|
41 { |
|
42 public: |
|
43 virtual void TimerExpiredL() = 0; |
|
44 }; |
|
45 |
|
46 |
|
47 class CHtiTimer : public CTimer |
|
48 { |
|
49 public: |
|
50 static CHtiTimer* NewL( MHtiTimerObserver& aObserver ); |
|
51 virtual ~CHtiTimer(); |
|
52 |
|
53 protected: // From CActive |
|
54 void RunL(); |
|
55 TInt RunError(TInt aError); |
|
56 |
|
57 private: |
|
58 CHtiTimer( MHtiTimerObserver& aObserver ); |
|
59 void ConstructL(); |
|
60 |
|
61 private: |
|
62 MHtiTimerObserver& iObserver; |
|
63 }; |
|
64 |
|
65 |
|
66 class CHtiConnectionManager : public CActive, |
|
67 public MHtiSocketObserver, |
|
68 public MHtiTimerObserver |
|
69 { |
|
70 public: |
|
71 enum TConnectionstate { |
|
72 EStartingIAP, |
|
73 EWaitingConnection, |
|
74 EConnecting, |
|
75 EConnected, |
|
76 EDisconnecting, |
|
77 EDisconnected |
|
78 }; |
|
79 |
|
80 static CHtiConnectionManager* NewL( CHtiIPCommServer* aServer ); |
|
81 ~CHtiConnectionManager(); |
|
82 |
|
83 void Receive( const RMessage2& aMessage ); |
|
84 void Send( const RMessage2& aMessage ); |
|
85 void CancelReceive(); |
|
86 void CancelSend(); |
|
87 |
|
88 private: |
|
89 CHtiConnectionManager( CHtiIPCommServer* aServer ); |
|
90 void ConstructL(); |
|
91 |
|
92 // Config file reading separated to 2 parts because |
|
93 // ReadConnectionConfigL might need dns resolver and |
|
94 // that should be done after the IAP is started... |
|
95 void ReadIAPConfigL(); |
|
96 void ReadConnectionConfigL(); |
|
97 |
|
98 void ReadSocket(); |
|
99 void WriteSocket(); |
|
100 |
|
101 void StartConnectingL(); |
|
102 void StartListeningL(); |
|
103 |
|
104 /* |
|
105 * Cancels all outstanding server session requests |
|
106 */ |
|
107 void CancelAllRequests(); |
|
108 |
|
109 void ShowErrorNotifierL( const TDesC& aText, TInt aErr = KErrGeneral ); |
|
110 |
|
111 protected: // From CActive |
|
112 void RunL(); |
|
113 void DoCancel(); |
|
114 TInt RunError(TInt aError); |
|
115 |
|
116 public: // MHtiTimerObserver |
|
117 void TimerExpiredL(); |
|
118 |
|
119 public: // MHtiSocketObserver |
|
120 void ReportComplete( MHtiSocketObserver::TRequestType aType, TInt aError ); |
|
121 |
|
122 |
|
123 |
|
124 private: |
|
125 CHtiIPCommServer* iServer; |
|
126 |
|
127 CHtiCfg* iCfg; |
|
128 TUint32 iIAPId; |
|
129 |
|
130 TInt iListenPort; |
|
131 TInetAddr iRemoteHost; |
|
132 |
|
133 RSocketServ iSocketServ; |
|
134 RConnection iConnection; |
|
135 RSocket iDataSocket; |
|
136 RSocket iListenSocket; |
|
137 TSockXfrLength iRecvLen; |
|
138 TConnectionstate iState; |
|
139 |
|
140 RMessage2 iReceiveRequest; |
|
141 RMessage2 iSendRequest; |
|
142 |
|
143 TBool iReceiveRequestComplete; |
|
144 TBool iSendRequestComplete; |
|
145 |
|
146 CHtiSocketMonitor* iSendMonitor; |
|
147 CHtiSocketMonitor* iReceiveMonitor; |
|
148 |
|
149 CHtiTimer* iConnectTimer; |
|
150 TInt iConnectTimeout; |
|
151 |
|
152 TBuf8<KIPCommServerReceiveBufferMaxSize> iReceiveBuffer; |
|
153 TBuf8<KIPCommServerSendBufferMaxSize> iSendBuffer; |
|
154 |
|
155 TCommDbConnPref iConnPref; |
|
156 }; |
|
157 |
|
158 #endif |