|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : TStateInactiveMonitoring.cpp |
|
15 // Part of : ConnectionMgr |
|
16 // Implementation |
|
17 // Version : SIP/4.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 #include "TStateInactiveMonitoring.h" |
|
23 #include "msipconnectioncontext.h" |
|
24 #include "SipLogs.h" |
|
25 |
|
26 |
|
27 |
|
28 const TUint KTimerThreeHours (10800000);//180 minutes. |
|
29 const TUint KTimerFiveMinutes( 300000 ); // 5minutes |
|
30 const TUint KBaseInterval( 600000 ); //10minutes |
|
31 const TUint KTimerSixtyMinutes(3600000); // 60 minutes |
|
32 |
|
33 |
|
34 |
|
35 // ---------------------------------------------------------------------------- |
|
36 // TStateInactiveMonitoring::Enter |
|
37 // ---------------------------------------------------------------------------- |
|
38 // |
|
39 void TStateInactiveMonitoring::Enter( TInt aError ) |
|
40 { |
|
41 __SIP_LOG( "TStateInactiveMonitoring::Enter" ) |
|
42 |
|
43 iContext.ReleaseTransportResources( ETrue ); |
|
44 |
|
45 TRAPD( err, iContext.StartMonitoringL( aError ) ); |
|
46 if( err ) |
|
47 { |
|
48 EnterState( MStateModel::EUnavailable, err ); |
|
49 return; |
|
50 } |
|
51 |
|
52 if(aError && (iContext.ConnectionType()==MSIPConnectionContext::ELanBearer)) |
|
53 { |
|
54 __SIP_INT_LOG1( "TStateInactiveMonitoring::Enter, Retrying for WLAN Connection", aError) |
|
55 StartRecovery(aError); |
|
56 } |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // TStateInactiveMonitoring::NetworkStateChanged |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 void TStateInactiveMonitoring::NetworkStateChanged( |
|
64 MSIPNetworkObserver::TNetworkState aState, |
|
65 TInt aError ) |
|
66 { |
|
67 __SIP_INT_LOG2( "TStateInactiveMonitoring::NetworkStateChanged", aState, aError ) |
|
68 if( aError ) |
|
69 { |
|
70 if(iContext.ConnectionType()==MSIPConnectionContext::ELanBearer) |
|
71 { |
|
72 EnterState( MStateModel::EInactiveMonitoring, aError ); // For Any Error on WLAN, Enable Recovery Timers. |
|
73 } |
|
74 else |
|
75 { |
|
76 EnterState( MStateModel::EUnavailable, aError ); //For other bearers No recovery possible. |
|
77 } |
|
78 return; |
|
79 } |
|
80 |
|
81 if( aState == MSIPNetworkObserver::ENetworkActive ) |
|
82 { |
|
83 EnterState( MStateModel::EInactiveConnecting ); |
|
84 } |
|
85 if( aState == MSIPNetworkObserver::ENetworkConnected ) |
|
86 { |
|
87 ResetTimer(); |
|
88 EnterState( MStateModel::EActiveResolving ); |
|
89 } |
|
90 } |
|
91 |
|
92 void TStateInactiveMonitoring:: StartTimer( TInt aTimeout ) |
|
93 { __SIP_LOG( "TStateInactiveMonitoring::StartTimer" ) |
|
94 __SIP_INT_LOG1("TStateInactiveMonitoring::StartTimer: Value",aTimeout) |
|
95 iTimer.Stop( iTimerId ); |
|
96 |
|
97 TRAPD( err, iTimerId = iTimer.StartL( this, aTimeout ) ); |
|
98 if( err ) |
|
99 { |
|
100 EnterState( MStateModel::EUnavailable, err ); |
|
101 } |
|
102 |
|
103 } |
|
104 |
|
105 void TStateInactiveMonitoring:: TimerExpiredL( TTimerId /*aTimerId*/, |
|
106 TAny* /*aTimerParam */) |
|
107 { |
|
108 if(iLessFatal) |
|
109 { |
|
110 iRetryCount++; |
|
111 iLessFatal=EFalse; |
|
112 } |
|
113 |
|
114 __SIP_LOG( "TStateInactiveMonitoring::TimerExpiredL" ) |
|
115 TInt err = iContext.OpenConnection(); |
|
116 if( err ) |
|
117 { |
|
118 EnterState( MStateModel::EUnavailable, err ); |
|
119 } |
|
120 } |
|
121 |
|
122 void TStateInactiveMonitoring::Exit() |
|
123 { |
|
124 iTimer.Stop( iTimerId ); |
|
125 } |
|
126 |
|
127 void TStateInactiveMonitoring::StartRecovery(TInt aError) |
|
128 { |
|
129 if(iContext.ContinueMonitoring(aError)) |
|
130 { |
|
131 if(iRetryCount<3) |
|
132 { |
|
133 iLessFatal = ETrue; |
|
134 __SIP_INT_LOG2( "TStateInactiveMonitoring::Recovering For less Fatal", aError, iRetryCount ) |
|
135 StartTimer(KTimerFiveMinutes + (KBaseInterval *iRetryCount)); //Retry Timer in increasing interval for less Fatal Errors. |
|
136 } |
|
137 else |
|
138 { |
|
139 __SIP_LOG( "TStateInactiveMonitoring::Recovering For Less Fatal once every 60 mins...." ) |
|
140 StartTimer(KTimerSixtyMinutes);//Retry Timer for 60 minutes |
|
141 } |
|
142 } |
|
143 else |
|
144 { |
|
145 __SIP_LOG( "TStateInactiveMonitoring::Recovering for More Fatal" ) |
|
146 StartTimer(KTimerThreeHours); // Retry Timer for More Fatal Errors. |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 void TStateInactiveMonitoring::ResetTimer() |
|
152 {__SIP_LOG( "TStateInactiveMonitoring::ResetTimer" ) |
|
153 iRetryCount=0; |
|
154 iLessFatal = EFalse; |
|
155 __SIP_INT_LOG2( "TStateInactiveMonitoring::Reset Value...", iRetryCount, iLessFatal ) |
|
156 } |