|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Implementation of CWsfWlanSettingsAccessor |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // EXTERNAL INCLUDES |
|
20 #include <d32dbms.h> |
|
21 #include <WlanCdbCols.h> |
|
22 #include <wlancontainer.h> |
|
23 |
|
24 #include <centralrepository.h> |
|
25 #include <wlandevicesettingsinternalcrkeys.h> |
|
26 #include <featmgr.h> |
|
27 |
|
28 // CLASS HEADER |
|
29 #include "wsfwlansettingsaccessor.h" |
|
30 |
|
31 // INTERNAL INCLUDES |
|
32 #include "wsfwlanscanintervalchangeobserver.h" |
|
33 #include "wsflogger.h" |
|
34 |
|
35 |
|
36 using namespace CommsDat; |
|
37 |
|
38 // background scan disabled value |
|
39 static const TUint KWlanBgScanIntervalNever = 0; |
|
40 |
|
41 // background scan automatic scanning value |
|
42 static const TUint KWlanBgScanIntervalAuto = 0xffffffff; |
|
43 |
|
44 // default background scan interval in seconds |
|
45 static const TUint KWlanBgScanIntervalDefault = 300; |
|
46 |
|
47 // hold-up time after first DB notification to prevent bursts (in microseconds) |
|
48 static const TUint KDbNotificationHoldupTime = 1000 * 1000; |
|
49 |
|
50 |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CWsfWlanSettingsAccessor::NewL |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 CWsfWlanSettingsAccessor* CWsfWlanSettingsAccessor::NewL( |
|
57 CMDBSession& aDbSession ) |
|
58 { |
|
59 CWsfWlanSettingsAccessor *thisPtr = NewLC( aDbSession ); |
|
60 CleanupStack::Pop( thisPtr ); |
|
61 return thisPtr; |
|
62 } |
|
63 |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // CWsfWlanSettingsAccessor::NewLC |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 CWsfWlanSettingsAccessor* CWsfWlanSettingsAccessor::NewLC( |
|
70 CMDBSession& aDbSession ) |
|
71 { |
|
72 CWsfWlanSettingsAccessor *thisPtr = |
|
73 new (ELeave) CWsfWlanSettingsAccessor( aDbSession ); |
|
74 CleanupStack::PushL( thisPtr ); |
|
75 thisPtr->ConstructL(); |
|
76 return thisPtr; |
|
77 } |
|
78 |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CWsfWlanSettingsAccessor::CWsfWlanSettingsAccessor |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 CWsfWlanSettingsAccessor::CWsfWlanSettingsAccessor( CMDBSession& aDbSession ): |
|
85 CActive( CActive::EPriorityStandard ), |
|
86 iDbSession( &aDbSession ), |
|
87 iBeingHeldUp( EFalse ) |
|
88 { |
|
89 } |
|
90 |
|
91 |
|
92 // ---------------------------------------------------------------------------- |
|
93 // CWsfWlanSettingsAccessor::ConstructL |
|
94 // ---------------------------------------------------------------------------- |
|
95 // |
|
96 void CWsfWlanSettingsAccessor::ConstructL() |
|
97 { |
|
98 CActiveScheduler::Add( this ); |
|
99 |
|
100 // get WLAN table id |
|
101 TRAP_IGNORE( iTableId = CCDWlanDeviceSettingsRecord::TableIdL( |
|
102 *iDbSession ) ); |
|
103 |
|
104 if ( !iTableId ) |
|
105 { |
|
106 iTableId = CCDWlanDeviceSettingsRecord::CreateTableL( *iDbSession ); |
|
107 } |
|
108 |
|
109 iWlanSettingsRecord = new (ELeave) CCDWlanDeviceSettingsRecord( iTableId ); |
|
110 iWlanSettingsRecord->iWlanDeviceSettingsType = KWlanUserSettings; |
|
111 |
|
112 if ( !iWlanSettingsRecord->FindL( *iDbSession ) ) |
|
113 { |
|
114 User::Leave( KErrNotFound ); |
|
115 } |
|
116 |
|
117 User::LeaveIfError( iTimer.CreateLocal() ); |
|
118 |
|
119 DoCheckSettingL( iScanInterval, iShowAvailability ); |
|
120 } |
|
121 |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // CWsfWlanSettingsAccessor::~CWsfWlanSettingsAccessor |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 CWsfWlanSettingsAccessor::~CWsfWlanSettingsAccessor() |
|
128 { |
|
129 Cancel(); |
|
130 iTimer.Close(); |
|
131 iDbSession = NULL; // not owning |
|
132 iChangeObserver = NULL; // not owning |
|
133 delete iWlanSettingsRecord; // own |
|
134 iWlanSettingsRecord = NULL; |
|
135 } |
|
136 |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // CWsfWlanSettingsAccessor::ScanInterval |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 TUint CWsfWlanSettingsAccessor::ScanInterval() const |
|
143 { |
|
144 LOG_ENTERFN( "CWsfWlanSettingsAccessor::ScanInterval" ); |
|
145 return iScanInterval; |
|
146 } |
|
147 |
|
148 |
|
149 // ---------------------------------------------------------------------------- |
|
150 // CWsfWlanSettingsAccessor::ShowAvailability |
|
151 // ---------------------------------------------------------------------------- |
|
152 // |
|
153 TBool CWsfWlanSettingsAccessor::ShowAvailability() const |
|
154 { |
|
155 LOG_ENTERFN( "CWsfWlanSettingsAccessor::ShowAvailability" ); |
|
156 return iShowAvailability; |
|
157 } |
|
158 |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CWsfWlanSettingsAccessor::RequestNotificationL |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 void CWsfWlanSettingsAccessor::RequestNotificationL( |
|
165 MWsfWlanScanIntervalChangeObserver& aObserver ) |
|
166 { |
|
167 LOG_ENTERFN( "CWsfWlanSettingsAccessor::RequestNotificationL" ); |
|
168 iChangeObserver = &aObserver; |
|
169 IssueNotificationRequestL(); |
|
170 } |
|
171 |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // CWsfWlanSettingsAccessor::IssueNotificationRequestL |
|
175 // ---------------------------------------------------------------------------- |
|
176 // |
|
177 void CWsfWlanSettingsAccessor::IssueNotificationRequestL() |
|
178 { |
|
179 LOG_ENTERFN( "CWsfWlanSettingsAccessor::IssueNotificationRequestL" ); |
|
180 if ( iChangeObserver ) |
|
181 { |
|
182 if ( !IsActive() ) |
|
183 { |
|
184 LOG_WRITE( "issuing..." ); |
|
185 User::LeaveIfError( iWlanSettingsRecord->RequestNotification( |
|
186 *iDbSession, iStatus ) ); |
|
187 SetActive(); |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 // ---------------------------------------------------------------------------- |
|
194 // CWsfWlanSettingsAccessor::CancelNotifications |
|
195 // ---------------------------------------------------------------------------- |
|
196 // |
|
197 void CWsfWlanSettingsAccessor::CancelNotifications() |
|
198 { |
|
199 LOG_ENTERFN( "CWsfWlanSettingsAccessor::CancelNotifications" ); |
|
200 Cancel(); |
|
201 iChangeObserver = NULL; |
|
202 } |
|
203 |
|
204 |
|
205 // ---------------------------------------------------------------------------- |
|
206 // CWsfWlanSettingsAccessor::DoCheckSettingL |
|
207 // ---------------------------------------------------------------------------- |
|
208 // |
|
209 void CWsfWlanSettingsAccessor::DoCheckSettingL( TUint& aBgScanInterval, |
|
210 TBool& aShowAvailability ) |
|
211 { |
|
212 LOG_ENTERFN( "CWsfWlanSettingsAccessor::DoCheckSettingL" ); |
|
213 // open the wlan settings table |
|
214 |
|
215 iWlanSettingsRecord->RefreshL( *iDbSession ); |
|
216 FeatureManager::InitializeLibL(); |
|
217 |
|
218 aShowAvailability = ( iWlanSettingsRecord->iBgScanInterval != |
|
219 KWlanBgScanIntervalNever ); |
|
220 |
|
221 // read the common value |
|
222 if ( iWlanSettingsRecord->iBgScanInterval == KWlanBgScanIntervalNever ) |
|
223 { |
|
224 if ( iWlanSettingsRecord->iSavedBgScanInterval == |
|
225 KWlanBgScanIntervalNever ) |
|
226 { |
|
227 TInt defaultScanInterval( KWlanBgScanIntervalDefault ); |
|
228 |
|
229 if (FeatureManager::FeatureSupported( KFeatureIdPowerSave )) |
|
230 { |
|
231 // Read the default value from CenRep (different in PSM mode) |
|
232 CRepository* cenrep = CRepository::NewL( |
|
233 KCRUidWlanDeviceSettingsRegistryId ); |
|
234 cenrep->Get( KWlanDefaultBGScanInterval, defaultScanInterval ); |
|
235 delete cenrep; |
|
236 } |
|
237 |
|
238 aBgScanInterval = TUint( defaultScanInterval ); |
|
239 } |
|
240 else |
|
241 { |
|
242 aBgScanInterval = iWlanSettingsRecord->iSavedBgScanInterval; |
|
243 } |
|
244 } |
|
245 else |
|
246 { |
|
247 aBgScanInterval = iWlanSettingsRecord->iBgScanInterval; |
|
248 } |
|
249 |
|
250 // Set scan interval to default value if adaptive scanning value is |
|
251 // found from db |
|
252 if (aBgScanInterval == KWlanBgScanIntervalAuto ) |
|
253 { |
|
254 TInt defaultScanInterval( KWlanBgScanIntervalDefault ); |
|
255 aBgScanInterval = TUint( defaultScanInterval ); |
|
256 } |
|
257 |
|
258 FeatureManager::UnInitializeLib(); |
|
259 LOG_WRITEF( "current bgScanInterval = %d sec", aBgScanInterval ); |
|
260 LOG_WRITEF( "current showAvailability = %d", aShowAvailability ); |
|
261 } |
|
262 |
|
263 |
|
264 // ---------------------------------------------------------------------------- |
|
265 // CWsfWlanSettingsAccessor::CheckIfSettingChangedL |
|
266 // ---------------------------------------------------------------------------- |
|
267 // |
|
268 TBool CWsfWlanSettingsAccessor::CheckIfSettingChangedL() |
|
269 { |
|
270 LOG_ENTERFN( "CWsfWlanSettingsAccessor::CheckIfSettingChangedL" ); |
|
271 LOG_WRITEF( "previous bgScanInterval = %d", iScanInterval ); |
|
272 LOG_WRITEF( "previous showAvailability = %d", iShowAvailability ); |
|
273 TUint newBgsi( 0 ); |
|
274 TBool newSaf( EFalse ); |
|
275 |
|
276 DoCheckSettingL( newBgsi, newSaf ); |
|
277 |
|
278 TBool retval( newBgsi != iScanInterval || newSaf != iShowAvailability ); |
|
279 iScanInterval = newBgsi; |
|
280 iShowAvailability = newSaf; |
|
281 |
|
282 return retval; |
|
283 } |
|
284 |
|
285 |
|
286 // ---------------------------------------------------------------------------- |
|
287 // CWsfWlanSettingsAccessor::RunL |
|
288 // ---------------------------------------------------------------------------- |
|
289 // |
|
290 void CWsfWlanSettingsAccessor::RunL() |
|
291 { |
|
292 LOG_ENTERFN( "CWsfWlanSettingsAccessor::RunL" ); |
|
293 LOG_WRITEF( "iStatus.Int() = %d", iStatus.Int() ); |
|
294 |
|
295 // Symbian DB notifiers are triggered by everything that may happen in |
|
296 // commsdat, so it would be very resource-consuming to check the value on |
|
297 // each database event |
|
298 // Workaround: 1-sec delay when first callback is received |
|
299 |
|
300 if ( !iBeingHeldUp ) |
|
301 { |
|
302 LOG_WRITE( "starting anti-burst delay" ); |
|
303 iBeingHeldUp = ETrue; |
|
304 iTimer.After( iStatus, TTimeIntervalMicroSeconds32( |
|
305 KDbNotificationHoldupTime ) ); |
|
306 SetActive(); |
|
307 } |
|
308 else |
|
309 { |
|
310 LOG_WRITE( "checking changes" ); |
|
311 iBeingHeldUp = EFalse; |
|
312 if ( CheckIfSettingChangedL() ) |
|
313 { |
|
314 LOG_WRITE( "setting changed, notifying observer" ); |
|
315 iChangeObserver->WlanScanIntervalChangedL( iScanInterval, |
|
316 iShowAvailability ); |
|
317 } |
|
318 |
|
319 IssueNotificationRequestL(); |
|
320 } |
|
321 |
|
322 } |
|
323 |
|
324 |
|
325 // ---------------------------------------------------------------------------- |
|
326 // CWsfWlanSettingsAccessor::DoCancel |
|
327 // ---------------------------------------------------------------------------- |
|
328 // |
|
329 void CWsfWlanSettingsAccessor::DoCancel() |
|
330 { |
|
331 iTimer.Cancel(); |
|
332 iBeingHeldUp = EFalse; |
|
333 |
|
334 if ( iWlanSettingsRecord ) |
|
335 { |
|
336 iWlanSettingsRecord->CancelNotification( *iDbSession, iStatus ); |
|
337 } |
|
338 } |
|
339 |
|
340 |
|
341 // ---------------------------------------------------------------------------- |
|
342 // CWsfWlanSettingsAccessor::RunError |
|
343 // ---------------------------------------------------------------------------- |
|
344 // |
|
345 TInt CWsfWlanSettingsAccessor::RunError( TInt /*aError*/ ) |
|
346 { |
|
347 TRAP_IGNORE( IssueNotificationRequestL() ); |
|
348 return KErrNone; |
|
349 } |
|
350 |