|
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: UPnP Connection Monitor class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <nifvar.h> |
|
21 |
|
22 #include "upnpconnectionmonitor.h" |
|
23 |
|
24 // logging |
|
25 _LIT( KComponentLogfile, "upnputilities.txt"); |
|
26 #include "upnplog.h" |
|
27 |
|
28 // CONSTANTS |
|
29 #ifdef __UPNP_CONSOLE_MT__ |
|
30 _LIT( KConnectionBreakdownSimulationFile, "C:\\Data\\Wlan" ); |
|
31 #endif // __UPNP_CONSOLE_MT__ |
|
32 |
|
33 |
|
34 |
|
35 // ========================== MEMBER FUNCTIONS =============================== |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CUPnPConnectionMonitor::CUPnPConnectionMonitor |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CUPnPConnectionMonitor::CUPnPConnectionMonitor( |
|
45 MUPnPConnectionMonitorObserver& aObserver, TInt aAccessPoint ) : |
|
46 CActive( EPriorityStandard ), |
|
47 iObserver( aObserver ), |
|
48 iAccessPoint( aAccessPoint ) |
|
49 { |
|
50 } |
|
51 |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CUPnPConnectionMonitor::NewL |
|
55 // Two-phased constructor. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C CUPnPConnectionMonitor* CUPnPConnectionMonitor::NewL( |
|
59 MUPnPConnectionMonitorObserver& aObserver, TInt aAccessPoint ) |
|
60 { |
|
61 CUPnPConnectionMonitor* self = new(ELeave) CUPnPConnectionMonitor( |
|
62 aObserver, aAccessPoint ); |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CUPnPConnectionMonitor::ConstructL |
|
72 // Symbian 2nd phase constructor can leave. |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CUPnPConnectionMonitor::ConstructL() |
|
76 { |
|
77 __LOG( "CUPnPConnectionMonitor::ConstructL" ); |
|
78 |
|
79 #ifdef __UPNP_CONSOLE_MT__ |
|
80 |
|
81 // monitor filesystem for connection breakdown simulation |
|
82 CActiveScheduler::Add( this ); |
|
83 User::LeaveIfError( iFs.Connect() ); |
|
84 iFs.NotifyChange( ENotifyFile, iStatus, |
|
85 KConnectionBreakdownSimulationFile ); |
|
86 SetActive(); |
|
87 |
|
88 #endif // __UPNP_CONSOLE_MT__ |
|
89 |
|
90 iConnectionMonitor.ConnectL(); |
|
91 iConnectionMonitor.NotifyEventL( *this ); |
|
92 |
|
93 ParseCurrentConnections(); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CUPnPConnectionMonitor::ParseCurrentConnections() |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 void CUPnPConnectionMonitor::ParseCurrentConnections() |
|
101 { |
|
102 // Get the count of connections |
|
103 TRequestStatus status = KRequestPending; |
|
104 TUint connectionCount = 0; |
|
105 iConnectionMonitor.GetConnectionCount(connectionCount, status); |
|
106 User::WaitForRequest( status ); |
|
107 // Go through available connections and check to see |
|
108 // WLAN connection is already running |
|
109 if( !status.Int() ) |
|
110 { |
|
111 for( TUint i=1; i < connectionCount+1; i++ ) |
|
112 { |
|
113 TUint connectionId; |
|
114 TUint subConnectionCount; |
|
115 |
|
116 iConnectionMonitor.GetConnectionInfo( |
|
117 i, |
|
118 connectionId, |
|
119 subConnectionCount); |
|
120 |
|
121 if( IsWlanConnection( connectionId ) ) |
|
122 { |
|
123 __LOG( "CUPnPConnectionMonitor - Found WLAN connection" ); |
|
124 iConnectionId = connectionId; |
|
125 } |
|
126 } |
|
127 } |
|
128 __LOG2( "CUPnPConnectionMonitor::ParseCurrentConnections() \ |
|
129 wlanId = %d connectionCount = %d ", iConnectionId , connectionCount ); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CUPnPConnectionMonitor::~CUPnPConnectionMonitor() |
|
134 // Destructor |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 CUPnPConnectionMonitor::~CUPnPConnectionMonitor() |
|
138 { |
|
139 #ifdef __UPNP_CONSOLE_MT__ |
|
140 |
|
141 // stop monitoring filesystem |
|
142 Cancel(); |
|
143 iFs.Close(); |
|
144 |
|
145 #endif // __UPNP_CONSOLE_MT__ |
|
146 |
|
147 // Disconnect from CM server |
|
148 iConnectionMonitor.CancelNotifications(); |
|
149 iConnectionMonitor.Close(); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CUPnPConnectionMonitor::EventL() |
|
154 // Receives event from connection monitor |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CUPnPConnectionMonitor::EventL( const CConnMonEventBase& aConnMonEvent ) |
|
158 { |
|
159 __LOG1( "CUPnPConnectionMonitor::EventL type %d", aConnMonEvent.EventType() ); |
|
160 TUint connectionId = 0; |
|
161 |
|
162 switch ( aConnMonEvent.EventType() ) |
|
163 { |
|
164 case EConnMonCreateConnection: |
|
165 { |
|
166 const CConnMonCreateConnection* eventCreate; |
|
167 eventCreate = (const CConnMonCreateConnection*)&aConnMonEvent; |
|
168 connectionId = eventCreate->ConnectionId(); |
|
169 |
|
170 // Save connectionId if type is WLAN |
|
171 if( IsWlanConnection( connectionId )) |
|
172 { |
|
173 __LOG( "CUPnPConnectionMonitor::EventL EConnMonCreateConnection \ |
|
174 WLAN connection found" ); |
|
175 iConnectionId = connectionId; |
|
176 } |
|
177 |
|
178 break; |
|
179 } |
|
180 |
|
181 // Connection is deleted |
|
182 case EConnMonDeleteConnection: |
|
183 { |
|
184 const CConnMonDeleteConnection* eventDelete; |
|
185 eventDelete = |
|
186 ( const CConnMonDeleteConnection* ) &aConnMonEvent; |
|
187 connectionId = eventDelete->ConnectionId(); |
|
188 |
|
189 // If there is new id for wlan we will pass if statement |
|
190 // because then the current is invalid then |
|
191 ParseCurrentConnections(); |
|
192 if( connectionId == iConnectionId ) |
|
193 { |
|
194 __LOG( "CUPnPConnectionMonitor::EventL EConnMonDeleteConnection \ |
|
195 WLAN connection found" ); |
|
196 iObserver.ConnectionLost(); |
|
197 } |
|
198 break; |
|
199 } |
|
200 default: |
|
201 { |
|
202 break; |
|
203 } |
|
204 } |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // CUPnPConnectionMonitor::IsWlanConnection() |
|
209 // Checks if connection type is WLAN |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 TBool CUPnPConnectionMonitor::IsWlanConnection( TInt aConnectionId) |
|
213 { |
|
214 __LOG( "CUPnPConnectionMonitor::IsWlanConnection" ); |
|
215 TBool ret = EFalse; |
|
216 TInt bearer = 0; |
|
217 TInt bearerinfo = 0; |
|
218 |
|
219 TRequestStatus status = KRequestPending; |
|
220 iConnectionMonitor.GetIntAttribute( |
|
221 aConnectionId, |
|
222 0, |
|
223 KBearer, |
|
224 (TInt &) bearer, |
|
225 status ); |
|
226 User::WaitForRequest( status ); |
|
227 |
|
228 TRequestStatus status2 = KRequestPending; |
|
229 iConnectionMonitor.GetIntAttribute( |
|
230 aConnectionId, |
|
231 0, |
|
232 KBearerInfo, |
|
233 (TInt &) bearerinfo, |
|
234 status2 ); |
|
235 User::WaitForRequest( status2 ); |
|
236 |
|
237 if( bearer == EBearerWLAN && bearerinfo == EBearerWLAN ) |
|
238 { |
|
239 ret = ETrue; |
|
240 } |
|
241 |
|
242 return ret; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // CUPnPConnectionMonitor::RunL() |
|
247 // Active object run loop |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CUPnPConnectionMonitor::RunL() |
|
251 { |
|
252 #ifdef __UPNP_CONSOLE_MT__ |
|
253 // simulated connection break has been activated |
|
254 iObserver.ConnectionLost(); |
|
255 iFs.Delete( KConnectionBreakdownSimulationFile ); |
|
256 #endif // __UPNP_CONSOLE_MT__ |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CUPnPConnectionMonitor::DoCancel() |
|
261 // Active object cancel implementation |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 void CUPnPConnectionMonitor::DoCancel() |
|
265 { |
|
266 #ifdef __UPNP_CONSOLE_MT__ |
|
267 // cancel notifications from FS |
|
268 iFs.NotifyChangeCancel(); |
|
269 #endif // __UPNP_CONSOLE_MT__ |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CUPnPConnectionMonitor::DebugSimulateConnectionLostL() |
|
274 // Simulate connection lost case. |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 EXPORT_C void CUPnPConnectionMonitor::DebugSimulateConnectionLostL() |
|
278 { |
|
279 #ifdef __UPNP_CONSOLE_MT__ |
|
280 // signal connection breakdown via filesystem |
|
281 RFs fs; |
|
282 CleanupClosePushL( fs ); |
|
283 User::LeaveIfError( fs.Connect() ); |
|
284 TInt err = fs.Delete( KConnectionBreakdownSimulationFile ); |
|
285 if ( err != KErrNone && |
|
286 err != KErrNotFound ) |
|
287 { |
|
288 User::Leave( err ); |
|
289 } |
|
290 |
|
291 RFile file; |
|
292 CleanupClosePushL( file ); |
|
293 User::LeaveIfError( file.Create( fs, |
|
294 KConnectionBreakdownSimulationFile, EFileWrite ) ); |
|
295 |
|
296 CleanupStack::PopAndDestroy( &file ); |
|
297 CleanupStack::PopAndDestroy( &fs ); |
|
298 |
|
299 #else // __UPNP_CONSOLE_MT__ |
|
300 // connection simulation method called, but feature is not active ! |
|
301 __PANICD( __FILE__, __LINE__ ); |
|
302 #endif // __UPNP_CONSOLE_MT__ |
|
303 } |
|
304 |
|
305 // end of file |