|
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 : CStateModel.cpp |
|
15 // Part of : ConnectionMgr |
|
16 // Implementation |
|
17 // Version : SIP/4.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 #include "CStateModel.h" |
|
23 #include "TStateInit.h" |
|
24 #include "TStateInactiveMonitoring.h" |
|
25 #include "TStateInactiveConnecting.h" |
|
26 #include "TStateActiveResolving.h" |
|
27 #include "TStateActiveResolved.h" |
|
28 #include "TStateSuspended.h" |
|
29 #include "TStateUnavailable.h" |
|
30 #include "msipconnectioncontext.h" |
|
31 #include "SipLogs.h" |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // CStateModel::NewL |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 CStateModel* CStateModel::NewL( MSIPConnectionContext& aContext, |
|
38 MTimerManager& aTimer ) |
|
39 { |
|
40 CStateModel* self = new( ELeave ) CStateModel( aContext, aTimer ); |
|
41 |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CStateModel::~CStateModel |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 CStateModel::~CStateModel() |
|
54 { |
|
55 // Lets not call State() if we are not initialized properly |
|
56 if( iStates.Count() == EMaxStates ) |
|
57 { |
|
58 State().Exit(); |
|
59 } |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------------------------- |
|
63 // CStateModel::SendL |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 void CStateModel::SendL( const TSIPTransportParams& aParams, |
|
67 CSIPRequest& aRequest, |
|
68 TBool aForceUDP, |
|
69 const CUri8* aOutboundProxy, |
|
70 const TInetAddr& aRemoteAddr, |
|
71 TRequestStatus& aStatus ) |
|
72 { |
|
73 State().SendL( |
|
74 aParams, aRequest, aForceUDP, aOutboundProxy, aRemoteAddr, aStatus ); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CStateModel::SendL |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 void CStateModel::SendL( const TSIPTransportParams& aParams, |
|
82 CSIPResponse& aResponse, |
|
83 TTransactionId aId, |
|
84 TRequestStatus& aStatus ) |
|
85 { |
|
86 State().SendL( aParams, aResponse, aId, aStatus ); |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CStateModel::StateValue |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 MStateModel::TState CStateModel::StateValue() const |
|
94 { |
|
95 return iStateValue; |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // CStateModel::EnterState |
|
100 // ---------------------------------------------------------------------------- |
|
101 // |
|
102 void CStateModel::EnterState( MStateModel::TState aState, TInt aError ) |
|
103 { |
|
104 __SIP_INT_LOG2( "CStateModel::EnterState(state,error)", aState, aError ) |
|
105 |
|
106 // Exit the old state |
|
107 State().Exit(); |
|
108 |
|
109 // Select next state, notify context |
|
110 iStateValue = aState; |
|
111 iContext.StateModelChanged( aState ); |
|
112 |
|
113 // Enter the next state |
|
114 State().Enter( aError ); |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CStateModel::NetworkStateChanged |
|
119 // ---------------------------------------------------------------------------- |
|
120 // |
|
121 void CStateModel::NetworkStateChanged( |
|
122 MSIPNetworkObserver::TNetworkState aState, |
|
123 TInt aError ) |
|
124 { |
|
125 __SIP_INT_LOG2( "CStateModel::NetworkStateChanged(state,error)", |
|
126 aState, aError ) |
|
127 iError = aError; |
|
128 State().NetworkStateChanged( aState, aError ); |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------------------------------- |
|
132 // CStateModel::State |
|
133 // ---------------------------------------------------------------------------- |
|
134 // |
|
135 TStateBase& CStateModel::State() const |
|
136 { |
|
137 return const_cast< TStateBase& >( iStates.At( iStateValue ) ); |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // CStateModel::Error |
|
142 // ---------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CStateModel::Error() const |
|
145 { |
|
146 return iError; |
|
147 } |
|
148 |
|
149 // ---------------------------------------------------------------------------- |
|
150 // CStateModel::CStateModel |
|
151 // ---------------------------------------------------------------------------- |
|
152 // |
|
153 CStateModel::CStateModel( MSIPConnectionContext& aContext, |
|
154 MTimerManager& aTimer ) |
|
155 : iContext( aContext ), iTimer( aTimer ), iStates( EMaxStates ), |
|
156 iStateValue( MStateModel::EUnavailable ),iError(KErrNone) |
|
157 { |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CStateModel::ConstructL |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 void CStateModel::ConstructL() |
|
165 { |
|
166 iStates.AppendL( TStateInit( *this, iContext ), |
|
167 sizeof( TStateInit ) ); |
|
168 iStates.AppendL( TStateInactiveMonitoring( *this, iContext,iTimer ), |
|
169 sizeof( TStateInactiveMonitoring ) ); |
|
170 iStates.AppendL( TStateInactiveConnecting( *this, iContext, iTimer ), |
|
171 sizeof( TStateInactiveConnecting ) ); |
|
172 iStates.AppendL( TStateActiveResolving( *this, iContext, iTimer ), |
|
173 sizeof( TStateActiveResolving ) ); |
|
174 iStates.AppendL( TStateActiveResolved( *this, iContext ), |
|
175 sizeof( TStateActiveResolved ) ); |
|
176 iStates.AppendL( TStateSuspended( *this, iContext ), |
|
177 sizeof( TStateSuspended ) ); |
|
178 iStates.AppendL( TStateUnavailable( *this, iContext ), |
|
179 sizeof( TStateUnavailable ) ); |
|
180 } |