|
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 : TStateInactiveConnecting.cpp |
|
15 // Part of : ConnectionMgr |
|
16 // Implementation |
|
17 // Version : SIP/4.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 #include "TStateInactiveConnecting.h" |
|
23 #include "msipconnectioncontext.h" |
|
24 #include "SipLogs.h" |
|
25 |
|
26 // 20000 ms = twenty seconds |
|
27 const TUint KTimerTwentySeconds( 20000 ); |
|
28 |
|
29 // 4000 ms = four seconds |
|
30 const TUint KTimerFourSeconds( 4000 ); |
|
31 |
|
32 // ---------------------------------------------------------------------------- |
|
33 // TStateInactiveConnecting::Enter |
|
34 // ---------------------------------------------------------------------------- |
|
35 // |
|
36 void TStateInactiveConnecting::Enter( TInt /*aError*/ ) |
|
37 { |
|
38 |
|
39 __SIP_LOG( "TStateInactiveConnecting::Enter" ) |
|
40 // Don't release all resources since we have to monitor connection's |
|
41 // total closure. |
|
42 iContext.ReleaseTransportResources( EFalse ); |
|
43 |
|
44 // Start waiting for total RConnection closure. If connection is tried to |
|
45 // be started right after it started going down, restarting may |
|
46 // fail unintentionally. |
|
47 TInt err = iContext.MonitorConnectionClosure(); |
|
48 if( err ) |
|
49 { |
|
50 EnterState( MStateModel::EUnavailable, err ); |
|
51 return; |
|
52 } |
|
53 |
|
54 // Start also guard timer which will cause connection attempt after |
|
55 // long waiting (i.e. connection closure event wasn't never received). |
|
56 StartTimer( KTimerTwentySeconds ); |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // TStateInactiveConnecting::Exit |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 void TStateInactiveConnecting::Exit() |
|
64 { |
|
65 iTimer.Stop( iTimerId ); |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // TStateInactiveConnecting::NetworkStateChanged |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 void TStateInactiveConnecting::NetworkStateChanged( |
|
73 MSIPNetworkObserver::TNetworkState aState, |
|
74 TInt aError ) |
|
75 { |
|
76 __SIP_INT_LOG2( "TStateInactiveConnecting::NetworkStateChanged", aState, aError ) |
|
77 // Some connection types might not want to try anymore monitoring at this |
|
78 // point, instead they go straight to unavailable state if error occured |
|
79 if ( aError && !iContext.ContinueMonitoring( aError ) && (iContext.ConnectionType()!=MSIPConnectionContext::ELanBearer) ) |
|
80 { |
|
81 EnterState( MStateModel::EUnavailable, aError ); |
|
82 return; |
|
83 } |
|
84 |
|
85 // Some connection types will continue monitoring even if error occured |
|
86 if( aError || |
|
87 aState == MSIPNetworkObserver::ENetworkInactive || |
|
88 aState == MSIPNetworkObserver::ENetworkSuspended ) |
|
89 { |
|
90 // Needed to recover from offline mode: |
|
91 EnterState( MStateModel::EInactiveMonitoring, aError ); |
|
92 } |
|
93 else if ( aState == MSIPNetworkObserver::EConnectionLost ) |
|
94 { |
|
95 // Connection should be ready to be started. Wait still a bit. |
|
96 StartTimer( KTimerFourSeconds ); |
|
97 } |
|
98 else if( aState == MSIPNetworkObserver::ENetworkConnected ) |
|
99 { |
|
100 EnterState( MStateModel::EActiveResolving ); |
|
101 } |
|
102 else |
|
103 { |
|
104 // do nothing, "else" required by PC-Lint.. |
|
105 } |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // TStateInactiveConnecting::TimerExpiredL |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 void TStateInactiveConnecting::TimerExpiredL( TTimerId /*aTimerId*/, |
|
113 TAny* /*aTimerParam*/ ) |
|
114 { |
|
115 |
|
116 __SIP_LOG( "TStateInactiveConnecting::TimerExpiredL" ) |
|
117 OpenConnection(); |
|
118 } |
|
119 |
|
120 // ---------------------------------------------------------------------------- |
|
121 // TStateInactiveConnecting::OpenConnection |
|
122 // ---------------------------------------------------------------------------- |
|
123 // |
|
124 void TStateInactiveConnecting::OpenConnection() |
|
125 { |
|
126 TInt err = iContext.OpenConnection(); |
|
127 if( err ) |
|
128 { |
|
129 EnterState( MStateModel::EUnavailable, err ); |
|
130 } |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // TStateInactiveConnecting::StartTimer |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 void TStateInactiveConnecting::StartTimer( TInt aTimeout ) |
|
138 { |
|
139 iTimer.Stop( iTimerId ); |
|
140 |
|
141 TRAPD( err, iTimerId = iTimer.StartL( this, aTimeout ) ); |
|
142 if( err ) |
|
143 { |
|
144 EnterState( MStateModel::EUnavailable, err ); |
|
145 } |
|
146 } |