|
1 /* |
|
2 * Copyright (c) 2010 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 : P&S key monitor for communication between SIP Profile |
|
15 * server and VPN client |
|
16 * Name : sipvpnmonitorao.cpp |
|
17 * Part of : Sip System State Monitor |
|
18 * Version : 1.0 |
|
19 * |
|
20 */ |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "sipvpnmonitorao.h" |
|
24 #include <vpnsipobserverpskeys.h> |
|
25 #include <sipsystemstateobserver.h> |
|
26 |
|
27 _LIT_SECURITY_POLICY_PASS( KSIPVpnAlwaysPass ); |
|
28 |
|
29 static const TInt KMicroSecondsInSecond = 1000000; |
|
30 static const TInt KGuardTimerSeconds = 10; |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CSipVpnMonitorAo::NewL |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CSipVpnMonitorAo* CSipVpnMonitorAo::NewL() |
|
37 { |
|
38 CSipVpnMonitorAo* self = new( ELeave )CSipVpnMonitorAo(); |
|
39 |
|
40 CleanupStack::PushL ( self ); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop( self ); |
|
43 |
|
44 return self; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CSipVpnMonitorAo::ConstructL |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CSipVpnMonitorAo::ConstructL() |
|
52 { |
|
53 iGuardTimer = CPeriodic::NewL( EPriorityNormal ); |
|
54 |
|
55 // Define a P&S key for communication between SIP Profile Server and VPN client. |
|
56 TInt err = iProperty.Define( KPSVpnSipUid, KVpnSipState, RProperty::EInt, |
|
57 KSIPVpnAlwaysPass, KSIPVpnAlwaysPass ); |
|
58 if ( KErrNone != err && KErrAlreadyExists != err && |
|
59 KErrPermissionDenied != err ) |
|
60 { |
|
61 User::Leave( err ); |
|
62 } |
|
63 |
|
64 User::LeaveIfError( iProperty.Attach( KPSVpnSipUid, KVpnSipState ) ); |
|
65 |
|
66 iProperty.Subscribe( iStatus ); |
|
67 SetActive(); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CSipVpnMonitorAo::CSipVpnMonitorAo |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CSipVpnMonitorAo::CSipVpnMonitorAo(): |
|
75 CActive(EPriorityStandard) |
|
76 { |
|
77 CActiveScheduler::Add( this ); |
|
78 iCount = 0; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CSipVpnMonitorAo::~CSipVpnMonitorAo |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CSipVpnMonitorAo::~CSipVpnMonitorAo() |
|
86 { |
|
87 if ( iGuardTimer ) |
|
88 { |
|
89 iGuardTimer->Cancel(); |
|
90 delete iGuardTimer; |
|
91 iGuardTimer = NULL; |
|
92 } |
|
93 |
|
94 CActive::Cancel(); |
|
95 |
|
96 iProperty.Close(); |
|
97 iProperty.Delete( KPSVpnSipUid, KVpnSipState ); |
|
98 |
|
99 iObservers.Close(); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CSipVpnMonitorAo::AddObserverL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CSipVpnMonitorAo::AddObserverL( |
|
107 MSipSystemStateObserver& aObserver ) |
|
108 { |
|
109 iObservers.InsertInAddressOrderL( &aObserver ); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CSipVpnMonitorAo::RemoveObserver |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CSipVpnMonitorAo::RemoveObserver( |
|
117 MSipSystemStateObserver& aObserver ) |
|
118 { |
|
119 TInt index = iObservers.Find( &aObserver ); |
|
120 if ( index >= 0 ) |
|
121 { |
|
122 iObservers.Remove( index ); |
|
123 } |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CSipVpnMonitorAo::NotifyObservers |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CSipVpnMonitorAo::NotifyObservers() |
|
131 { |
|
132 // Notify observers (SIP Profile Server) about the P&S key change. |
|
133 for ( TInt i = iObservers.Count()-1; i >= 0; i-- ) |
|
134 { |
|
135 iObservers[i]->SystemVariableUpdated( |
|
136 CSipSystemStateMonitor::EVpnState, |
|
137 0, |
|
138 iState); |
|
139 } |
|
140 |
|
141 // Start a guard timer so that VPN client don't wait forever for completion |
|
142 // of deregistration. |
|
143 if ( iObservers.Count() && iState == CSipSystemStateMonitor::EVpnInitiating ) |
|
144 { |
|
145 iGuardTimer->Cancel(); |
|
146 iGuardTimer->Start( |
|
147 TTimeIntervalMicroSeconds32( KGuardTimerSeconds * KMicroSecondsInSecond ), |
|
148 TTimeIntervalMicroSeconds32( KGuardTimerSeconds * KMicroSecondsInSecond ), |
|
149 TCallBack( TimerExpired, this ) ); |
|
150 } |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CSipVpnMonitorAo::State |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 CSipSystemStateMonitor::TVpnState CSipVpnMonitorAo::State() const |
|
158 { |
|
159 return iState; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CSipVpnMonitorAo::EventProcessingCompleted |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CSipVpnMonitorAo::EventProcessingCompleted( |
|
167 MSipSystemStateObserver& aObserver ) |
|
168 { |
|
169 if (iState == CSipSystemStateMonitor::EVpnInitiating) |
|
170 { |
|
171 TInt index = iObservers.Find( &aObserver ); |
|
172 if ( index >= 0 ) |
|
173 { |
|
174 iCount++; |
|
175 if( iObservers.Count() == iCount) |
|
176 { |
|
177 iGuardTimer->Cancel(); |
|
178 iProperty.Set(KPSVpnSipUid, KVpnSipState, ESipDeregisterCompleted ); |
|
179 iCount = 0; |
|
180 } |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CSipVpnMonitorAo::EventProcessingCompleted |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CSipVpnMonitorAo::EventProcessingCompleted() |
|
190 { |
|
191 // SIP deregistration has been completed. Stop the guard timer and tell |
|
192 // the VPN client about it. |
|
193 iGuardTimer->Cancel(); |
|
194 |
|
195 iProperty.Set( KPSVpnSipUid, KVpnSipState, ESipDeregisterCompleted ); |
|
196 iCount = 0; |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CSipVpnMonitorAo::TimerExpired |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CSipVpnMonitorAo::TimerExpired(TAny* aSelf) |
|
204 { |
|
205 // Guard timer expired. Tell VPN client to proceed its work without |
|
206 // further waiting. |
|
207 CSipVpnMonitorAo* self = reinterpret_cast<CSipVpnMonitorAo*>(aSelf); |
|
208 self->EventProcessingCompleted(); |
|
209 |
|
210 return ETrue; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CSipVpnMonitorAo::RunL |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CSipVpnMonitorAo::RunL() |
|
218 { |
|
219 TInt state( 0 ); |
|
220 |
|
221 // VPN client notifies that it has started a VPN session. |
|
222 if ( KErrNone == iProperty.Get( state ) ) |
|
223 { |
|
224 if ( MappedState( state ) ) |
|
225 { |
|
226 NotifyObservers(); |
|
227 } |
|
228 } |
|
229 |
|
230 iProperty.Subscribe( iStatus ); |
|
231 SetActive(); |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CSipVpnMonitorAo::RunError |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 TInt CSipVpnMonitorAo::RunError( TInt /*aError*/ ) |
|
239 { |
|
240 return KErrNone; // RunL cannot leave at the moment |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CSipVpnMonitorAo::DoCancel |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CSipVpnMonitorAo::DoCancel() |
|
248 { |
|
249 iProperty.Cancel(); |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CSipVpnMonitorAo::MappedState |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 TBool CSipVpnMonitorAo::MappedState( TInt aState ) |
|
257 { |
|
258 TBool ret = ETrue; |
|
259 // Maps P&S key value to VPN state. |
|
260 switch( aState ) |
|
261 { |
|
262 case EVpnInitiating: |
|
263 iState = CSipSystemStateMonitor::EVpnInitiating; |
|
264 break; |
|
265 case EVpnTerminated: |
|
266 iState = CSipSystemStateMonitor::EVpnTerminated; |
|
267 break; |
|
268 // Other P&S key values are not mapped to VPN state. |
|
269 // Not an error situation. |
|
270 default: |
|
271 ret = EFalse; |
|
272 } |
|
273 |
|
274 return ret; |
|
275 } |