1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
26 // |
26 // |
27 CMpmVpnToggleWatcher::CMpmVpnToggleWatcher( MMpmVpnToggleWatcherNotify& aNotify ) |
27 CMpmVpnToggleWatcher::CMpmVpnToggleWatcher( MMpmVpnToggleWatcherNotify& aNotify ) |
28 : CActive( EPriorityStandard ), |
28 : CActive( EPriorityStandard ), |
29 iNotify( aNotify ) |
29 iNotify( aNotify ) |
30 { |
30 { |
31 CActiveScheduler::Add( this ); |
31 CActiveScheduler::Add( this ); |
32 } |
32 } |
33 |
33 |
34 |
34 |
35 // --------------------------------------------------------------------------- |
35 // --------------------------------------------------------------------------- |
36 // Creates central repositor object |
36 // Creates central repositor object |
61 // --------------------------------------------------------------------------- |
61 // --------------------------------------------------------------------------- |
62 // Destructor |
62 // Destructor |
63 // --------------------------------------------------------------------------- |
63 // --------------------------------------------------------------------------- |
64 // |
64 // |
65 CMpmVpnToggleWatcher::~CMpmVpnToggleWatcher() |
65 CMpmVpnToggleWatcher::~CMpmVpnToggleWatcher() |
66 { |
66 { |
67 Cancel(); |
67 Cancel(); |
68 delete iRepository; |
68 delete iRepository; |
69 } |
69 } |
70 |
70 |
71 // --------------------------------------------------------------------------- |
71 // --------------------------------------------------------------------------- |
73 // --------------------------------------------------------------------------- |
73 // --------------------------------------------------------------------------- |
74 // |
74 // |
75 void CMpmVpnToggleWatcher::StartL() |
75 void CMpmVpnToggleWatcher::StartL() |
76 { |
76 { |
77 MPMLOGSTRING( "CMpmVpnToggleWatcher::StartL" ) |
77 MPMLOGSTRING( "CMpmVpnToggleWatcher::StartL" ) |
78 |
78 |
79 // Get the initial Connect screen ID from repository. |
79 // Get the initial Connect screen ID from repository. |
80 User::LeaveIfError( GetVpnToggleValues() ); |
80 User::LeaveIfError( GetVpnToggleValues() ); |
81 |
81 |
82 // Request for notifications. |
82 // Request for notifications. |
83 User::LeaveIfError( RequestNotifications() ); |
83 User::LeaveIfError( RequestNotifications() ); |
90 TInt CMpmVpnToggleWatcher::RequestNotifications() |
90 TInt CMpmVpnToggleWatcher::RequestNotifications() |
91 { |
91 { |
92 MPMLOGSTRING( "CMpmVpnToggleWatcher::RequestNotifications" ) |
92 MPMLOGSTRING( "CMpmVpnToggleWatcher::RequestNotifications" ) |
93 |
93 |
94 TInt err = iRepository->NotifyRequest( KMpmVpnTogglePreferVpn, iStatus ); |
94 TInt err = iRepository->NotifyRequest( KMpmVpnTogglePreferVpn, iStatus ); |
95 |
95 |
96 if ( err == KErrNone ) |
96 if ( err == KErrNone ) |
97 { |
97 { |
98 SetActive(); |
98 SetActive(); |
99 } |
99 } |
100 else |
100 else |
109 // --------------------------------------------------------------------------- |
109 // --------------------------------------------------------------------------- |
110 // |
110 // |
111 TInt CMpmVpnToggleWatcher::GetVpnToggleValues() |
111 TInt CMpmVpnToggleWatcher::GetVpnToggleValues() |
112 { |
112 { |
113 MPMLOGSTRING( "CMpmVpnToggleWatcher::GetVpnToggleValues" ) |
113 MPMLOGSTRING( "CMpmVpnToggleWatcher::GetVpnToggleValues" ) |
114 |
114 |
115 // Get values from central repository |
115 // Get values from central repository |
116 TInt err = iRepository->Get( KMpmVpnTogglePreferVpn, iVpnConnectionPreferred ); |
116 TInt err = iRepository->Get( KMpmVpnTogglePreferVpn, iVpnConnectionPreferred ); |
117 if ( err != KErrNone ) |
117 if ( err != KErrNone ) |
118 { |
118 { |
119 MPMLOGSTRING2( "CMpmVpnToggleWatcher::GetVpnToggleValues, preferred value, ERROR: %d", err ) |
119 MPMLOGSTRING2( "CMpmVpnToggleWatcher::GetVpnToggleValues, preferred value, ERROR: %d", err ) |
120 return err; |
120 return err; |
121 } |
121 } |
122 TInt value(0); |
122 TInt value(0); |
123 err = iRepository->Get( KMpmVpnToggleIapId, value ); |
123 err = iRepository->Get( KMpmVpnToggleIapId, value ); |
124 if ( err != KErrNone ) |
124 if ( err != KErrNone ) |
125 { |
125 { |
126 MPMLOGSTRING2( "CMpmVpnToggleWatcher::GetVpnToggleValues, IAP Id value, ERROR: %d", err ) |
126 MPMLOGSTRING2( "CMpmVpnToggleWatcher::GetVpnToggleValues, IAP Id value, ERROR: %d", err ) |
127 return err; |
127 return err; |
128 } |
128 } |
129 iVpnIapId = value; |
129 iVpnIapId = value; |
130 err = iRepository->Get( KMpmVpnToggleSnapId, value ); |
130 err = iRepository->Get( KMpmVpnToggleSnapId, value ); |
131 if ( err != KErrNone ) |
131 if ( err != KErrNone ) |
132 { |
132 { |
133 MPMLOGSTRING2( "CMpmVpnToggleWatcher::GetVpnToggleValues, SNAP Id value, ERROR: %d", err ) |
133 MPMLOGSTRING2( "CMpmVpnToggleWatcher::GetVpnToggleValues, SNAP Id value, ERROR: %d", err ) |
134 return err; |
134 return err; |
135 } |
135 } |
136 iSnapId = value; |
136 iSnapId = value; |
137 return KErrNone; |
137 return KErrNone; |
138 } |
138 } |
139 |
139 |
140 // --------------------------------------------------------------------------- |
140 // --------------------------------------------------------------------------- |
141 // Return VPN toggle value. |
141 // Return VPN toggle value. |
175 |
175 |
176 // Reset values. |
176 // Reset values. |
177 iVpnConnectionPreferred = EFalse; |
177 iVpnConnectionPreferred = EFalse; |
178 iVpnIapId = 0; |
178 iVpnIapId = 0; |
179 iSnapId = 0; |
179 iSnapId = 0; |
180 |
180 |
181 TInt err = iRepository->Set( KMpmVpnTogglePreferVpn, 0 ); |
181 TInt err = iRepository->Set( KMpmVpnTogglePreferVpn, 0 ); |
182 if ( err == KErrNone ) |
182 if ( err == KErrNone ) |
183 { |
183 { |
184 err = iRepository->Set( KMpmVpnToggleIapId, 0 ); |
184 err = iRepository->Set( KMpmVpnToggleIapId, 0 ); |
185 } |
185 } |
186 if ( err == KErrNone ) |
186 if ( err == KErrNone ) |
187 { |
187 { |
188 err = iRepository->Set( KMpmVpnToggleSnapId, 0 ); |
188 err = iRepository->Set( KMpmVpnToggleSnapId, 0 ); |
189 } |
189 } |
190 |
190 |
191 MPMLOGSTRING2( "CMpmVpnToggleWatcher::ResetVpnToggleValues, ERROR: %d", err ) |
191 MPMLOGSTRING2( "CMpmVpnToggleWatcher::ResetVpnToggleValues, ERROR: %d", err ) |
192 |
192 |
193 // Restart listening VPN toggle value change |
193 // Restart listening VPN toggle value change |
194 RequestNotifications(); |
194 RequestNotifications(); |
195 } |
195 } |
196 |
196 |
197 // --------------------------------------------------------------------------- |
197 // --------------------------------------------------------------------------- |
198 // From class CActive. |
198 // From class CActive. |
199 // When there is a change in VPN toggle key value, event is received in here |
199 // When there is a change in VPN toggle key value, event is received in here |
200 // --------------------------------------------------------------------------- |
200 // --------------------------------------------------------------------------- |
201 // |
201 // |
202 void CMpmVpnToggleWatcher::RunL() |
202 void CMpmVpnToggleWatcher::RunL() |
203 { |
203 { |
204 if ( iStatus.Int() < KErrNone ) |
204 if ( iStatus.Int() < KErrNone ) |
205 { |
205 { |
206 MPMLOGSTRING2("CMpmVpnToggleWatcher::RunL, status: 0x%08X", iStatus.Int()) |
206 MPMLOGSTRING2("CMpmVpnToggleWatcher::RunL, status: 0x%08X", iStatus.Int()) |
207 iErrorCounter++; |
207 iErrorCounter++; |
208 if ( iErrorCounter > KMpmVpnToggleWatcherCenRepErrorThreshold ) |
208 if ( iErrorCounter > KMpmVpnToggleWatcherCenRepErrorThreshold ) |
216 } |
216 } |
217 else |
217 else |
218 { |
218 { |
219 // Notification is received ok => Reset the counter. |
219 // Notification is received ok => Reset the counter. |
220 iErrorCounter = 0; |
220 iErrorCounter = 0; |
221 |
221 |
222 RequestNotifications(); |
222 RequestNotifications(); |
223 |
223 |
224 // Get values from central repository |
224 // Get values from central repository |
225 GetVpnToggleValues(); |
225 GetVpnToggleValues(); |
226 |
226 |
227 // Notify values. |
227 // Notify values. |
228 TRAP_IGNORE( iNotify.SetVpnToggleValuesL( iVpnConnectionPreferred, |
228 TRAP_IGNORE( iNotify.SetVpnToggleValuesL( iVpnConnectionPreferred, |
229 iVpnIapId, |
229 iVpnIapId, |
230 iSnapId ) ); |
230 iSnapId ) ); |
231 } |
231 } |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // From class CActive. |
|
236 // Handles any leave from RunL. |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 TInt CMpmVpnToggleWatcher::RunError( TInt aError ) |
|
240 { |
|
241 MPMLOGSTRING2( "CMpmVpnToggleWatcher::RunError, ERROR: %d", aError ); |
|
242 aError = aError; |
|
243 iErrorCounter++; |
|
244 if ( !IsActive() ) |
|
245 { |
|
246 RequestNotifications(); |
|
247 } |
|
248 return KErrNone; |
232 } |
249 } |
233 |
250 |
234 // --------------------------------------------------------------------------- |
251 // --------------------------------------------------------------------------- |
235 // From class CActive. |
252 // From class CActive. |
236 // Cancel outstanding request |
253 // Cancel outstanding request |