|
1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "irdebug.h" |
|
20 #include "irnetworkobserver.h" |
|
21 #include "irnetworkcontroller.h" |
|
22 |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // CIRNetworkObserver::NewL |
|
26 // Creates an Instance of CIRNetworkObserver |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CIRNetworkObserver *CIRNetworkObserver::NewL( |
|
30 CIRNetworkController* aNetworkController ) |
|
31 { |
|
32 IRLOG_DEBUG( "CIRNetworkObserver::NewL - Entering" ); |
|
33 CIRNetworkObserver *self = NewLC( aNetworkController ); |
|
34 CleanupStack::Pop( self ); |
|
35 IRLOG_DEBUG( "CIRNetworkObserver::NewL - Exiting." ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CIRNetworkObserver::~CIRNetworkObserver() |
|
41 // Default Destructor |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CIRNetworkObserver::~CIRNetworkObserver() |
|
45 { |
|
46 IRLOG_DEBUG( "CIRNetworkObserver::~CIRNetworkObserver - Entering" ); |
|
47 Cancel(); |
|
48 iIRConnectionMonitor.CancelNotifications(); |
|
49 iIRConnectionMonitor.Close(); |
|
50 IRLOG_DEBUG( "CIRNetworkObserver::~CIRNetworkObserver - Exiting." ); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CIRNetworkObserver::InitializeNetworkObserver() |
|
55 // Initializes the Connection monitor |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CIRNetworkObserver::InitializeNetworkObserver() |
|
59 { |
|
60 IRLOG_DEBUG( "CIRNetworkObserver::InitializeNetworkObserver - Entering" ); |
|
61 iConnectionId = 0; |
|
62 if ( !IsActive() ) |
|
63 { |
|
64 iObserverState = EInitializing; |
|
65 iIRConnectionMonitor.GetConnectionCount( iConnectionCount,iStatus ); |
|
66 SetActive(); |
|
67 } |
|
68 IRLOG_DEBUG( "CIRNetworkObserver::InitializeNetworkObserver - Exiting." ); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CIRNetworkObserver::SetObserver( MIRNetworkController* aObserver ) |
|
73 // Set the observer used to communicate with the IRNetworkController |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CIRNetworkObserver::SetObserver( MIRNetworkController* aObserver ) |
|
77 { |
|
78 IRLOG_DEBUG( "CIRNetworkObserver::SetObserver - Entering" ); |
|
79 iMonitorObserver = aObserver; |
|
80 iMonitoringRequired = ETrue; |
|
81 IRLOG_DEBUG( "CIRNetworkObserver::SetObserver - Exiting." ); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CIRNetworkObserver::CIRNetworkObserver() |
|
86 // Default Constructor |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CIRNetworkObserver::CIRNetworkObserver( CIRNetworkController* aNetworkController ): |
|
90 CActive( CActive::EPriorityStandard ), iNetworkController( aNetworkController ) |
|
91 { |
|
92 IRLOG_DEBUG( "CIRNetworkObserver::CIRNetworkObserver - Entering" ); |
|
93 // Add the AO to the ActiveScheduler |
|
94 CActiveScheduler::Add( this ); |
|
95 IRLOG_DEBUG( "CIRNetworkObserver::CIRNetworkObserver - Exiting." ); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Creates an Instance of CIRNetworkObserver |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CIRNetworkObserver *CIRNetworkObserver::NewLC( |
|
103 CIRNetworkController* aNetworkController ) |
|
104 { |
|
105 IRLOG_DEBUG( "CIRNetworkObserver::NewLC - Entering " ); |
|
106 CIRNetworkObserver *self = new( ELeave )CIRNetworkObserver( |
|
107 aNetworkController ); |
|
108 CleanupStack::PushL( self ); |
|
109 self->ConstructL(); |
|
110 IRLOG_DEBUG( "CIRNetworkObserver::NewLC - Exiting." ); |
|
111 return self; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CIRNetworkObserver::ConstructL() |
|
116 // Second Phase construction. |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CIRNetworkObserver::ConstructL() |
|
120 { |
|
121 IRLOG_DEBUG( "CIRNetworkObserver::ConstructL - Entering" ); |
|
122 iIRConnectionMonitor.ConnectL(); |
|
123 iIRConnectionMonitor.NotifyEventL( *this ); |
|
124 iMonitoringRequired = EFalse; |
|
125 IRLOG_DEBUG( "CIRNetworkObserver::ConstructL - Exiting." ); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CIRNetworkObserver::RunL() |
|
130 // The function is called by the active scheduler when a request completion event occurs, |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CIRNetworkObserver::RunL() |
|
134 { |
|
135 IRLOG_DEBUG( "CIRNetworkObserver::RunL - Entering" ); |
|
136 IRNetworkObserverRunL(); |
|
137 IRLOG_DEBUG( "CIRNetworkObserver::RunL - Exiting" ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CIRNetworkObserver::DoCancel() |
|
142 // Cancels the pending requests on the CIRNetworkObserver Active object |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void CIRNetworkObserver::DoCancel() |
|
146 { |
|
147 IRLOG_DEBUG( "CIRNetworkObserver::DoCancel" ); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CIRNetworkObserver::RunError() |
|
152 // Handles a leave occurring in the request completion event handler RunL() |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CIRNetworkObserver::RunError( TInt /*aError*/ ) |
|
156 { |
|
157 IRLOG_DEBUG( "CIRNetworkObserver::RunError" ); |
|
158 iNetworkController->ResetHandingOverConnection(); |
|
159 return KErrNone; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CIRNetworkObserver::EventL( const CConnMonEventBase &aConnMonEvent ) |
|
164 // Derived from MConnectionMonitorObserver |
|
165 // Implements the EventL method which is called when there is a network event |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CIRNetworkObserver::EventL(const CConnMonEventBase &aConnMonEvent) |
|
169 { |
|
170 IRLOG_INFO4( "CIRNetworkObserver::EventL - Event type %d for connection %d, iConnectionId=%d", |
|
171 aConnMonEvent.EventType(), aConnMonEvent.ConnectionId(), iConnectionId ); |
|
172 switch(aConnMonEvent.EventType()) |
|
173 { |
|
174 case EConnMonCreateConnection: |
|
175 { |
|
176 //Triggered when a new connection has been been created |
|
177 // for future implementation |
|
178 } |
|
179 break; |
|
180 |
|
181 case EConnMonDeleteConnection: |
|
182 { |
|
183 //Triggered when a connection has been been deleted. |
|
184 if( aConnMonEvent.ConnectionId() == iConnectionId ) |
|
185 { |
|
186 if(iMonitoringRequired) |
|
187 { |
|
188 if (iMonitorObserver) |
|
189 { |
|
190 iMonitorObserver->IRNetworkEventL(ENetworkConnectionDisconnected); |
|
191 } |
|
192 else |
|
193 { |
|
194 iNetworkController->NotifyActiveNetworkObserversL(ENetworkConnectionDisconnected); |
|
195 } |
|
196 } |
|
197 } |
|
198 } |
|
199 break; |
|
200 |
|
201 case EConnMonCreateSubConnection: |
|
202 { |
|
203 //Triggered when a new subconnection has been been created |
|
204 // for future implementation |
|
205 } |
|
206 break; |
|
207 |
|
208 case EConnMonDeleteSubConnection: |
|
209 { |
|
210 //Triggered when a subconnection has been been deleted |
|
211 // for future implementation |
|
212 } |
|
213 break; |
|
214 |
|
215 case EConnMonDownlinkDataThreshold: |
|
216 { |
|
217 // for future implementation |
|
218 } |
|
219 break; |
|
220 |
|
221 case EConnMonUplinkDataThreshold: |
|
222 { |
|
223 // for future implementation |
|
224 } |
|
225 break; |
|
226 |
|
227 case EConnMonNetworkStatusChange: |
|
228 { |
|
229 // for future implementation |
|
230 } |
|
231 break; |
|
232 |
|
233 case EConnMonConnectionStatusChange: |
|
234 { |
|
235 //Triggered when the status of some connection changes. |
|
236 // for future implementation |
|
237 } |
|
238 break; |
|
239 |
|
240 case EConnMonConnectionActivityChange: |
|
241 { |
|
242 //Triggered when some connection changes from active to idle or vice versa |
|
243 // for future implementation |
|
244 } |
|
245 break; |
|
246 |
|
247 case EConnMonNetworkRegistrationChange: |
|
248 { |
|
249 // for future implementation |
|
250 } |
|
251 break; |
|
252 |
|
253 case EConnMonBearerChange: |
|
254 { |
|
255 //Triggered when bearer type (GPRS / Edge GPRS / WCDMA) changes |
|
256 // for future implementation |
|
257 } |
|
258 break; |
|
259 |
|
260 case EConnMonSignalStrengthChange: |
|
261 { |
|
262 // for future implementation |
|
263 } |
|
264 break; |
|
265 |
|
266 case EConnMonBearerAvailabilityChange: |
|
267 { |
|
268 //Triggered when the availability of some bearer changes |
|
269 // for future implementation |
|
270 } |
|
271 break; |
|
272 |
|
273 case EConnMonIapAvailabilityChange: |
|
274 { |
|
275 // for future implementation |
|
276 } |
|
277 break; |
|
278 |
|
279 case EConnMonTransmitPowerChange: |
|
280 { |
|
281 // for future implementation |
|
282 } |
|
283 break; |
|
284 default: |
|
285 { |
|
286 // no implementation |
|
287 } |
|
288 break; |
|
289 } |
|
290 IRLOG_DEBUG( "CIRNetworkObserver::EventL - Exiting." ); |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // CIRNetworkObserver::IdentifyConnection() |
|
295 // Identifies the type of connection we have used to get connected to network |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 void CIRNetworkObserver::IdentifyConnection() |
|
299 { |
|
300 IRLOG_DEBUG( "CIRNetworkObserver::IdentifyConnection - Entering" ); |
|
301 if ( !IsActive() ) |
|
302 { |
|
303 iObserverState = EGettingConnectionInfo; |
|
304 iIRConnectionMonitor.GetConnectionInfo( |
|
305 iConnectionCount,iConnectionId,iSubConnectionCount ); |
|
306 // O Indicates method applies to connection |
|
307 iIRConnectionMonitor.GetIntAttribute( |
|
308 iConnectionId,0,KBearer,iConnectionType,iStatus ); |
|
309 SetActive(); |
|
310 } |
|
311 IRLOG_DEBUG( "CIRNetworkObserver::IdentifyConnection - Exiting." ); |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // CIRNetworkObserver::GetIAPId() |
|
316 // Retrieves the IAP Id of the connection |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CIRNetworkObserver::GetAPId() |
|
320 { |
|
321 IRLOG_DEBUG( "CIRNetworkObserver::GetIAPId - Entering" ); |
|
322 if ( !IsActive() ) |
|
323 { |
|
324 iObserverState = EGettingIAPId; |
|
325 iIRConnectionMonitor.GetConnectionInfo( |
|
326 iConnectionCount, iConnectionId, iSubConnectionCount ); |
|
327 // O in RConnectionMonitor::GetIntAttribute indicates method applies to connection |
|
328 iIRConnectionMonitor.GetUintAttribute( |
|
329 iConnectionId, 0, KIAPId, iIAPId, iStatus ); |
|
330 SetActive(); |
|
331 } |
|
332 IRLOG_DEBUG( "CIRNetworkObserver::GetIAPId - Exiting." ); |
|
333 } |
|
334 |
|
335 // --------------------------------------------------------------------------- |
|
336 // CIRNetworkObserver::IRNetworkObserverRunL() |
|
337 // Utility function used just to keep RunL() small |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CIRNetworkObserver::IRNetworkObserverRunL() |
|
341 { |
|
342 IRLOG_DEBUG( "CIRNetworkObserver::IRNetworkObserverRunL - Entering" ); |
|
343 switch(iObserverState) |
|
344 { |
|
345 case EInitializing: |
|
346 { |
|
347 if( iStatus.Int() == KErrNone ) |
|
348 { |
|
349 // Initializing the Connection Monitor sucessful |
|
350 IdentifyConnection(); |
|
351 } |
|
352 else |
|
353 { |
|
354 // Error initializing the connection monitor |
|
355 iNetworkController->ResetHandingOverConnection(); |
|
356 } |
|
357 } |
|
358 break; |
|
359 |
|
360 case EGettingConnectionInfo: |
|
361 { |
|
362 if( iStatus.Int() == KErrNone ) |
|
363 { |
|
364 iIsIAPIdAvailable = EFalse; |
|
365 GetAPId(); |
|
366 } |
|
367 else |
|
368 { |
|
369 // Error initializing the connection monitor |
|
370 iNetworkController->ResetHandingOverConnection(); |
|
371 } |
|
372 } |
|
373 break; |
|
374 |
|
375 case EGettingIAPId: |
|
376 { |
|
377 iIsIAPIdAvailable = ETrue; |
|
378 switch(iConnectionType) |
|
379 { |
|
380 case EBearerGPRS: |
|
381 { |
|
382 iIRConnectionType = EGprs; |
|
383 } |
|
384 break; |
|
385 |
|
386 case EBearerEdgeGPRS: |
|
387 { |
|
388 iIRConnectionType = EEdge; |
|
389 } |
|
390 break; |
|
391 |
|
392 case EBearerWLAN: |
|
393 { |
|
394 iIRConnectionType = EWiFi; |
|
395 } |
|
396 break; |
|
397 |
|
398 case EBearerWCDMA: |
|
399 { |
|
400 iIRConnectionType = EWcdma; |
|
401 } |
|
402 break; |
|
403 |
|
404 case EBearerCDMA2000: |
|
405 { |
|
406 iIRConnectionType = ECdma2000; |
|
407 } |
|
408 break; |
|
409 |
|
410 default: |
|
411 { |
|
412 #ifdef __WINS__ |
|
413 iIRConnectionType = EGprs; |
|
414 #endif |
|
415 } |
|
416 break; |
|
417 } |
|
418 |
|
419 |
|
420 if (iMonitoringRequired) |
|
421 { |
|
422 if (iMonitorObserver) |
|
423 { |
|
424 // Intimate the connection established event |
|
425 iMonitorObserver->IRNetworkEventL(ENetworkConnectionEstablished); |
|
426 } |
|
427 else |
|
428 { |
|
429 iNetworkController->NotifyActiveNetworkObserversL(ENetworkConnectionEstablished); |
|
430 } |
|
431 } |
|
432 |
|
433 iNetworkController->ResetHandingOverConnection(); |
|
434 } |
|
435 break; |
|
436 |
|
437 default: |
|
438 { |
|
439 // no implementation |
|
440 } |
|
441 break; |
|
442 } |
|
443 IRLOG_DEBUG( "CIRNetworkObserver::IRNetworkObserverRunL - Exiting." ); |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // CIRNetworkObserver::SetNetworkMonitoring() |
|
448 // Sets network monitoring observer to decide whether network monitoring is required. |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 void CIRNetworkObserver::SetNetworkMonitoring( TBool aValue ) |
|
452 { |
|
453 IRLOG_DEBUG( "CIRNetworkObserver::SetNetworkMonitoring - Entering" ); |
|
454 |
|
455 iMonitoringRequired = aValue; |
|
456 |
|
457 IRLOG_DEBUG( "CIRNetworkObserver::SetNetworkMonitoring - Exiting" ); |
|
458 |
|
459 } |