|
1 /* |
|
2 * Copyright (c) 2009 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 the License "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: Class implementing WLAN background scan logic |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 7 % |
|
20 */ |
|
21 |
|
22 #ifndef WLANBGSCAN_H |
|
23 #define WLANBGSCAN_H |
|
24 |
|
25 #include "awsinterface.h" |
|
26 #include "awsenginebase.h" |
|
27 #include "wlanscanproviderinterface.h" |
|
28 #include "wlantimerservices.h" |
|
29 #include "wlanbgscanawscomms.h" |
|
30 |
|
31 /** |
|
32 * WLAN Background Scan |
|
33 * This class implements WLAN Background Scan logic. |
|
34 * |
|
35 * @since S60 S60 v5.2 |
|
36 */ |
|
37 NONSHARABLE_CLASS( CWlanBgScan ) : |
|
38 public MWlanBgScanProvider, |
|
39 public MWlanTimerServiceCallback, |
|
40 public MWlanBgScanCommandListener |
|
41 { |
|
42 |
|
43 public: |
|
44 |
|
45 /** |
|
46 * States for WLAN Background Scan. |
|
47 */ |
|
48 enum TWlanBgScanState |
|
49 { |
|
50 EBgScanOff = 0, |
|
51 EBgScanOn, |
|
52 EBgScanAuto, |
|
53 EBgScanAutoAws |
|
54 }; |
|
55 |
|
56 /** |
|
57 * States for Auto period. |
|
58 */ |
|
59 enum TWlanBgScanAutoPeriod |
|
60 { |
|
61 EAutoPeriodNone = 0, |
|
62 EAutoPeriodNight, |
|
63 EAutoPeriodDay |
|
64 }; |
|
65 |
|
66 /** |
|
67 * Describes relation of time to time range. |
|
68 */ |
|
69 enum TRelation |
|
70 { |
|
71 ESmaller, |
|
72 EInsideRange, |
|
73 EGreater |
|
74 }; |
|
75 |
|
76 /** |
|
77 * Two-phased constructor. |
|
78 */ |
|
79 static CWlanBgScan* NewL( MWlanScanResultProvider& aProvider, CWlanTimerServices& aTimerServices ); |
|
80 |
|
81 /** |
|
82 * Destructor. |
|
83 */ |
|
84 virtual ~CWlanBgScan(); |
|
85 |
|
86 /** |
|
87 * From MWlanBgScanProvider. |
|
88 * Called when Scan has been completed. |
|
89 * |
|
90 * \msc |
|
91 * ScanResultProvider,CWlanBgScan; |
|
92 * --- [label="Scan is done"]; |
|
93 * ScanResultProvider=>CWlanBgScan [label="ScanComplete()"]; |
|
94 * ScanResultProvider<=CWlanBgScan [label="Scan()"]; |
|
95 * --- [label="New scan request is placed to queue or"]; |
|
96 * --- [label="existing request's scan time is updated"]; |
|
97 * ScanResultProvider>>CWlanBgScan [label="return"]; |
|
98 * ScanResultProvider<<CWlanBgScan [label="return"]; |
|
99 * \endmsc |
|
100 * |
|
101 * |
|
102 * @since S60 v5.2 |
|
103 */ |
|
104 void ScanComplete(); |
|
105 |
|
106 /** |
|
107 * From MWlanBgScanProvider. |
|
108 * Issued when WLAN is disconnected. |
|
109 * |
|
110 * \msc |
|
111 * ScanResultProvider,CWlanBgScan; |
|
112 * --- [label="WLAN is disconnected"]; |
|
113 * ScanResultProvider=>CWlanBgScan [label="NotConnected()"]; |
|
114 * ScanResultProvider<=CWlanBgScan [label="Scan( aMaxDelay=0 )"]; |
|
115 * ScanResultProvider>>CWlanBgScan [label="return"]; |
|
116 * ScanResultProvider<<CWlanBgScan [label="return"]; |
|
117 * \endmsc |
|
118 * |
|
119 * @since S60 v5.2 |
|
120 */ |
|
121 void NotConnected(); |
|
122 |
|
123 /** |
|
124 * From MWlanBgScanProvider. |
|
125 * Whether background scan is enabled. |
|
126 * |
|
127 * @since S60 v5.2 |
|
128 * @return True if background scan is enabled, |
|
129 * False otherwise. |
|
130 */ |
|
131 TBool IsBgScanEnabled(); |
|
132 |
|
133 /** |
|
134 * From MWlanBgScanProvider. |
|
135 * Notification about changed settings. |
|
136 * |
|
137 * @since S60 v5.2 |
|
138 * |
|
139 * @param aSettings new settings to be taken into use |
|
140 */ |
|
141 void NotifyChangedSettings( MWlanBgScanProvider::TWlanBgScanSettings& aSettings ); |
|
142 |
|
143 /** |
|
144 * From MAwsBgScanProvider. |
|
145 * Set new background scan interval. |
|
146 * Asynchronous method to set new background scan interval, executed in |
|
147 * AWS thread. |
|
148 * |
|
149 * @since S60 v5.2 |
|
150 * @param aNewInterval new interval to be taken into use |
|
151 * @param aStatus Status of the calling active object. On successful |
|
152 * completion contains KErrNone, otherwise one of the |
|
153 * system-wide error codes. |
|
154 */ |
|
155 void SetInterval( TUint32 aNewInterval, TRequestStatus& aReportStatus ); |
|
156 |
|
157 /** |
|
158 * From MWlanTimerServiceCallback. |
|
159 * OnTimeout. |
|
160 * Requested time has elapsed. |
|
161 * |
|
162 * @since S60 v5.2 |
|
163 */ |
|
164 void OnTimeout(); |
|
165 |
|
166 /** |
|
167 * From MWlanBgScanCommandListener. |
|
168 * DoSetInterval. |
|
169 * This method is called by the command queue when |
|
170 * interval change request is processed. |
|
171 * @param aNewInterval new interval to be taken into use |
|
172 */ |
|
173 void DoSetInterval( TUint32 aNewInterval ); |
|
174 |
|
175 private: |
|
176 |
|
177 /** |
|
178 * Constructor. |
|
179 */ |
|
180 CWlanBgScan( MWlanScanResultProvider& aProvider, CWlanTimerServices& aTimerServices ); |
|
181 |
|
182 /** |
|
183 * Two-phased constructor. |
|
184 */ |
|
185 void ConstructL(); |
|
186 |
|
187 /** |
|
188 * Main state machine |
|
189 * |
|
190 * @since S60 v5.2 |
|
191 * @param aNewBgScanSetting new background scan setting to be taken into use |
|
192 */ |
|
193 void NextState( TUint32 aNewBgScanSetting ); |
|
194 |
|
195 /** |
|
196 * State machine for Off state |
|
197 * |
|
198 * @since S60 v5.2 |
|
199 * @param aState reference to state |
|
200 * @param aNewInterval new background scan setting to be taken into use |
|
201 */ |
|
202 void InStateOff( TWlanBgScanState& aState, TUint32 aNewBgScanSetting ); |
|
203 |
|
204 /** |
|
205 * State machine for On state |
|
206 * |
|
207 * @since S60 v5.2 |
|
208 * @param aState reference to state |
|
209 * @param aNewBgScanSetting new background scan setting to be taken into use |
|
210 */ |
|
211 void InStateOn( TWlanBgScanState& aState, TUint32 aNewBgScanSetting ); |
|
212 |
|
213 /** |
|
214 * State machine for Auto state |
|
215 * |
|
216 * @since S60 v5.2 |
|
217 * @param aState reference to state |
|
218 * @param aNewBgScanSetting new background scan setting to be taken into use |
|
219 */ |
|
220 void InStateAuto( TWlanBgScanState& aState, TUint32 aNewBgScanSetting ); |
|
221 |
|
222 /** |
|
223 * State machine for Auto with AWS state |
|
224 * |
|
225 * @since S60 v5.2 |
|
226 * @param aState reference to state |
|
227 * @param aNewBgScanSetting new background scan setting to be taken into use |
|
228 */ |
|
229 void InStateAutoAws( TWlanBgScanState& aState, TUint32 aNewBgScanSetting ); |
|
230 |
|
231 /** |
|
232 * Request callback when interval change should take place. |
|
233 * |
|
234 * @since S60 v5.2 |
|
235 */ |
|
236 void ScheduleAutoIntervalChange(); |
|
237 |
|
238 /** |
|
239 * Get current Auto Background Scan interval. |
|
240 * |
|
241 * @since S60 v5.2 |
|
242 * |
|
243 * @return interval |
|
244 */ |
|
245 TUint32 CurrentAutoInterval(); |
|
246 |
|
247 /** |
|
248 * Get current interval. |
|
249 * |
|
250 * @since S60 v5.2 |
|
251 * @return current interval in use |
|
252 */ |
|
253 TUint32 GetInterval(); |
|
254 |
|
255 /** |
|
256 * Set current interval. |
|
257 * |
|
258 * @param aInterval interval to take into use |
|
259 * @since S60 v5.2 |
|
260 */ |
|
261 void SetInterval( TUint32 aInterval ); |
|
262 |
|
263 /** |
|
264 * Get next time when to change Auto interval. |
|
265 * |
|
266 * @since S60 v5.2 |
|
267 * |
|
268 * @return time to change interval |
|
269 */ |
|
270 TTime AutoIntervalChangeAt(); |
|
271 |
|
272 /** |
|
273 * See how time is related to a time range. |
|
274 * |
|
275 * @param aTime time to be checked |
|
276 * @param aStart start of range |
|
277 * @param aEnd end of range |
|
278 * @return relation |
|
279 * @since S60 v5.2 |
|
280 */ |
|
281 TRelation TimeRelationToRange( const TTime& aTime, TUint aRangeStart, TUint aRangeEnd ) const; |
|
282 |
|
283 /** |
|
284 * Deliver new background interval. |
|
285 * |
|
286 * @since S60 v5.2 |
|
287 * |
|
288 * @param aNewInterval new interval to be taken into use |
|
289 */ |
|
290 void IntervalChanged( TUint32 aNewInterval ); |
|
291 |
|
292 /** |
|
293 * Is AWS present in system. |
|
294 * |
|
295 * @since S60 v5.2 |
|
296 * @return ETrue if background scan is enabled, |
|
297 * EFalse otherwise. |
|
298 */ |
|
299 TBool IsAwsPresent(); |
|
300 |
|
301 /** |
|
302 * Check the proposed settings are valid. |
|
303 * |
|
304 * @since S60 v5.2 |
|
305 * |
|
306 * @param aSettingsToUse settings that can be used [OUT] |
|
307 * @param aProposedSettings proposed settings [IN] |
|
308 */ |
|
309 void CheckSettings( |
|
310 MWlanBgScanProvider::TWlanBgScanSettings& aSettingsToUse, |
|
311 const MWlanBgScanProvider::TWlanBgScanSettings& aProposedSettings ) const; |
|
312 |
|
313 /** |
|
314 * Is interval change needed. |
|
315 * |
|
316 * @since S60 v5.2 |
|
317 * @return ETrue if interval change is needed, |
|
318 * EFalse otherwise. |
|
319 */ |
|
320 TBool IsIntervalChangeNeeded(); |
|
321 |
|
322 private: // data |
|
323 |
|
324 /** |
|
325 * Reference to the Scan Result Provider |
|
326 */ |
|
327 MWlanScanResultProvider& iProvider; |
|
328 |
|
329 /** |
|
330 * Actually used interval for backgroundscan. |
|
331 */ |
|
332 TUint32 iCurrentBgScanInterval; |
|
333 |
|
334 /** |
|
335 * Reference to BgScan <-> AWS communications object. |
|
336 */ |
|
337 CWlanBgScanAwsComms* iAwsComms; |
|
338 |
|
339 /** |
|
340 * Current background scan state. |
|
341 */ |
|
342 TWlanBgScanState iBgScanState; |
|
343 |
|
344 /** |
|
345 * Current Auto period. |
|
346 */ |
|
347 TWlanBgScanAutoPeriod iAutoPeriod; |
|
348 |
|
349 /** |
|
350 * Reference to WLAN Timer services. |
|
351 */ |
|
352 CWlanTimerServices& iTimerServices; |
|
353 |
|
354 /** |
|
355 * Id of the timer service request regarding |
|
356 * background scan interval change. |
|
357 */ |
|
358 TUint iIntervalChangeRequestId; |
|
359 |
|
360 /** |
|
361 * Background scan peak start time. |
|
362 */ |
|
363 TUint iBgScanPeakStartTime; |
|
364 |
|
365 /** |
|
366 * Background scan peak end time. |
|
367 */ |
|
368 TUint iBgScanPeakEndTime; |
|
369 |
|
370 /** |
|
371 * Peak time interval. |
|
372 */ |
|
373 TUint iBgScanIntervalPeak; |
|
374 |
|
375 /** |
|
376 * Off-peak time interval. |
|
377 */ |
|
378 TUint iBgScanIntervalOffPeak; |
|
379 |
|
380 }; |
|
381 |
|
382 #endif // WLANBGSCAN_H |