|
1 /* |
|
2 * Copyright (c) 2009-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 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: 2 % |
|
20 */ |
|
21 |
|
22 #ifndef WLANBGSCANSTATES_H |
|
23 #define WLANBGSCANSTATES_H |
|
24 |
|
25 //#include "wlanbgscan.h" |
|
26 #include "awsinterface.h" |
|
27 #include "awsenginebase.h" |
|
28 #include "wlanscanproviderinterface.h" |
|
29 #include "wlantimerserviceinterface.h" |
|
30 #include "wlanbgscanawscommsinterface.h" |
|
31 #include "wlanbgscancommandlistener.h" |
|
32 |
|
33 // forward declarations |
|
34 class CWlanBgScan; |
|
35 class CWlanTimer; |
|
36 |
|
37 /** |
|
38 * WLAN Background Scan States |
|
39 * This class implements WLAN Background Scan state machine. |
|
40 * |
|
41 * @since S60 S60 v5.2 |
|
42 */ |
|
43 NONSHARABLE_CLASS( CWlanBgScanStates ) |
|
44 { |
|
45 |
|
46 public: |
|
47 |
|
48 /** |
|
49 * States for WLAN Background Scan. |
|
50 */ |
|
51 enum TWlanBgScanState |
|
52 { |
|
53 EBgScanInit = 0, |
|
54 EBgScanOff, |
|
55 EBgScanOn, |
|
56 EBgScanAuto, |
|
57 EBgScanAutoAws, |
|
58 EBgScanSendingAwsCmd, |
|
59 EBgScanStateMax |
|
60 }; |
|
61 |
|
62 /** |
|
63 * Events for state machine. |
|
64 */ |
|
65 enum TWlanBgScanSmEvent |
|
66 { |
|
67 EBgScanEventAwsCmdComplete = 0, |
|
68 EBgScanEventIntervalChanged, |
|
69 EBgScanEventAwsStartupComplete, |
|
70 EBgScanEventAwsIntervalChanged |
|
71 }; |
|
72 |
|
73 /** |
|
74 * Constructor. |
|
75 */ |
|
76 CWlanBgScanStates( CWlanBgScan& aBgScan, MWlanScanResultProvider& aProvider, MWlanTimerServices& aTimerServices ); |
|
77 |
|
78 /** |
|
79 * Two-phased constructor. |
|
80 */ |
|
81 void ConstructL(); |
|
82 |
|
83 /** |
|
84 * Destructor. |
|
85 */ |
|
86 virtual ~CWlanBgScanStates(); |
|
87 |
|
88 /** |
|
89 * Start aggressive background scanning. |
|
90 * |
|
91 * @since S60 v5.2 |
|
92 * @param aInterval interval for aggressive BG scanning, in seconds |
|
93 * @param aDuration aggressive mode duration, in microseconds |
|
94 */ |
|
95 void StartAggressiveBgScan( TUint32& aInterval, TUint32& aDuration ); |
|
96 |
|
97 /** |
|
98 * Stop aggressive scanning. |
|
99 * |
|
100 * @since S60 v5.2 |
|
101 * @param aPtr pointer to CWlanBgScanStates instance |
|
102 * @return always KErrNone |
|
103 */ |
|
104 static TInt StopAggressiveBgScan( TAny* aPtr ); |
|
105 |
|
106 private: |
|
107 |
|
108 /** |
|
109 * Default constructor, no implementation. |
|
110 */ |
|
111 CWlanBgScanStates(); |
|
112 |
|
113 /** |
|
114 * State machine for Init state |
|
115 * |
|
116 * @since S60 v5.2 |
|
117 * @param aState reference to state |
|
118 * @param aEvent event to handle |
|
119 */ |
|
120 void InStateInit( TWlanBgScanState& aState, const CWlanBgScanStates::TWlanBgScanSmEvent& aEvent ); |
|
121 |
|
122 /** |
|
123 * State machine for Off state |
|
124 * |
|
125 * @since S60 v5.2 |
|
126 * @param aState reference to state |
|
127 * @param aEvent event to handle |
|
128 */ |
|
129 void InStateOff( TWlanBgScanState& aState, const CWlanBgScanStates::TWlanBgScanSmEvent& aEvent ); |
|
130 |
|
131 /** |
|
132 * State machine for On state |
|
133 * |
|
134 * @since S60 v5.2 |
|
135 * @param aState reference to state |
|
136 * @param aEvent event to handle |
|
137 */ |
|
138 void InStateOn( TWlanBgScanState& aState, const CWlanBgScanStates::TWlanBgScanSmEvent& aEvent ); |
|
139 |
|
140 /** |
|
141 * State machine for Auto state |
|
142 * |
|
143 * @since S60 v5.2 |
|
144 * @param aState reference to state |
|
145 * @param aEvent event to handle |
|
146 */ |
|
147 void InStateAuto( TWlanBgScanState& aState, const CWlanBgScanStates::TWlanBgScanSmEvent& aEvent ); |
|
148 |
|
149 /** |
|
150 * State machine for Auto with AWS state |
|
151 * |
|
152 * @since S60 v5.2 |
|
153 * @param aState reference to state |
|
154 * @param aEvent event to handle |
|
155 */ |
|
156 void InStateAutoAws( TWlanBgScanState& aState, const CWlanBgScanStates::TWlanBgScanSmEvent& aEvent ); |
|
157 |
|
158 /** |
|
159 * State machine for Sending AWS command state |
|
160 * |
|
161 * @since S60 v5.2 |
|
162 * @param aState reference to state |
|
163 * @param aEvent event to handle |
|
164 */ |
|
165 void InStateSendingAwsCmd( TWlanBgScanState& aState, const CWlanBgScanStates::TWlanBgScanSmEvent& aEvent ); |
|
166 |
|
167 /** |
|
168 * Handles state transition from SendingAwsCmd state to Off state. |
|
169 * |
|
170 * @since S60 v5.2 |
|
171 * @param aState reference to state |
|
172 */ |
|
173 void StateChangeSendingAwsCmdToOff( TWlanBgScanState& aState ); |
|
174 |
|
175 /** |
|
176 * Handles state transition from SendingAwsCmd state to On state. |
|
177 * |
|
178 * @since S60 v5.2 |
|
179 * @param aState reference to state |
|
180 */ |
|
181 void StateChangeSendingAwsCmdToOn( TWlanBgScanState& aState ); |
|
182 |
|
183 /** |
|
184 * Handles state transition from SendingAwsCmd state to Auto state. |
|
185 * |
|
186 * @since S60 v5.2 |
|
187 * @param aState reference to state |
|
188 */ |
|
189 void StateChangeSendingAwsCmdToAuto( TWlanBgScanState& aState ); |
|
190 |
|
191 /** |
|
192 * Handles state transition from SendingAwsCmd state to AutoAws state. |
|
193 * |
|
194 * @since S60 v5.2 |
|
195 * @param aState reference to state |
|
196 */ |
|
197 void StateChangeSendingAwsCmdToAutoAws( TWlanBgScanState& aState ); |
|
198 |
|
199 /** |
|
200 * Handles state transition from Init to Automatic state. |
|
201 * |
|
202 * @since S60 v5.2 |
|
203 * @param aState reference to state |
|
204 */ |
|
205 void StateChangeInitToAutoAws( TWlanBgScanState& aState ); |
|
206 |
|
207 /** |
|
208 * Handles state transition from AutoAws to On state. |
|
209 * |
|
210 * @since S60 v5.2 |
|
211 * @param aState reference to state |
|
212 */ |
|
213 void StateChangeAutoAwsToOn( TWlanBgScanState& aState ); |
|
214 |
|
215 /** |
|
216 * Handles state transition from AutoAws to Off state. |
|
217 * |
|
218 * @since S60 v5.2 |
|
219 * @param aState reference to state |
|
220 */ |
|
221 void StateChangeAutoAwsToOff( TWlanBgScanState& aState ); |
|
222 |
|
223 /** |
|
224 * Handles state transition from Auto to Off state. |
|
225 * |
|
226 * @since S60 v5.2 |
|
227 * @param aState reference to state |
|
228 */ |
|
229 void StateChangeAutoToOff( TWlanBgScanState& aState ); |
|
230 |
|
231 /** |
|
232 * Handles state transition from Auto to Auto state. |
|
233 * |
|
234 * @since S60 v5.2 |
|
235 * @param aState reference to state |
|
236 */ |
|
237 void StateChangeAutoToAuto( TWlanBgScanState& aState ); |
|
238 |
|
239 /** |
|
240 * Handles state transition from Auto to On state. |
|
241 * |
|
242 * @since S60 v5.2 |
|
243 * @param aState reference to state |
|
244 * @param aNewBgScanSetting new background scan setting to be taken into use |
|
245 */ |
|
246 void StateChangeAutoToOn( TWlanBgScanState& aState, TUint32 aNewBgScanSetting ); |
|
247 |
|
248 /** |
|
249 * Handles state transition from On to Off state. |
|
250 * |
|
251 * @since S60 v5.2 |
|
252 * @param aState reference to state |
|
253 */ |
|
254 void StateChangeOnToOff( TWlanBgScanState& aState ); |
|
255 |
|
256 /** |
|
257 * Handles state transition from On to Automatic state. |
|
258 * |
|
259 * @since S60 v5.2 |
|
260 * @param aState reference to state |
|
261 */ |
|
262 void StateChangeOnToAutomatic( TWlanBgScanState& aState ); |
|
263 |
|
264 /** |
|
265 * Handles state transition from On to On state. |
|
266 * |
|
267 * @since S60 v5.2 |
|
268 * @param aState reference to state |
|
269 * @param aNewBgScanSetting new background scan setting to be taken into use |
|
270 */ |
|
271 void StateChangeOnToOn( TWlanBgScanState& aState, TUint32 aNewBgScanSetting ); |
|
272 |
|
273 /** |
|
274 * Handles state transition from Off to Automatic state. |
|
275 * |
|
276 * @since S60 v5.2 |
|
277 * @param aState reference to state |
|
278 */ |
|
279 void StateChangeOffToAutomatic( TWlanBgScanState& aState ); |
|
280 |
|
281 /** |
|
282 * Handles state transition from Off to On state. |
|
283 * |
|
284 * @since S60 v5.2 |
|
285 * @param aState reference to state |
|
286 * @param aNewBgScanInterval new background scan interval to be taken into use |
|
287 */ |
|
288 void StateChangeOffToOn( TWlanBgScanState& aState, TUint32 aNewBgScanInterval ); |
|
289 |
|
290 /** |
|
291 * Handles state transition from Init to Auto state. |
|
292 * |
|
293 * @since S60 v5.2 |
|
294 * @param aState reference to state |
|
295 * @param aNewBgScanInterval new background scan interval to be taken into use |
|
296 */ |
|
297 void StateChangeInitToAuto( TWlanBgScanState& aState ); |
|
298 |
|
299 /** |
|
300 * Handles state transition from Init to Off state. |
|
301 * |
|
302 * @since S60 v5.2 |
|
303 * @param aState reference to state |
|
304 * @param aNewBgScanInterval new background scan interval to be taken into use |
|
305 */ |
|
306 void StateChangeInitToOff( TWlanBgScanState& aState ); |
|
307 |
|
308 /** |
|
309 * Handles state transition from Init to On state. |
|
310 * |
|
311 * @since S60 v5.2 |
|
312 * @param aState reference to state |
|
313 * @param aNewBgScanInterval new background scan interval to be taken into use |
|
314 */ |
|
315 void StateChangeInitToOn( TWlanBgScanState& aState ); |
|
316 |
|
317 /** |
|
318 * Getter for AwsStartupStatus. |
|
319 * |
|
320 * @since S60 v5.2 |
|
321 * @return AwsStartupStatus |
|
322 */ |
|
323 inline TInt AwsStartupStatus() const |
|
324 { |
|
325 return iAwsStartupStatus; |
|
326 } |
|
327 |
|
328 /** |
|
329 * Getter for AwsCmdStatus. |
|
330 * |
|
331 * @since S60 v5.2 |
|
332 * @return AwsCmdStatus |
|
333 */ |
|
334 inline TInt AwsCmdStatus() const |
|
335 { |
|
336 return iAwsCmdStatus; |
|
337 } |
|
338 |
|
339 /** |
|
340 * Getter for AwsCmd. |
|
341 * |
|
342 * @since S60 v5.2 |
|
343 * @return AwsCmd |
|
344 */ |
|
345 inline TInt AwsCmd() const |
|
346 { |
|
347 return iAwsCmd; |
|
348 } |
|
349 |
|
350 /** |
|
351 * Getter for AutoInterval. |
|
352 * |
|
353 * @since S60 v5.2 |
|
354 * @return AutoInterval |
|
355 */ |
|
356 inline TInt AutoInterval() const |
|
357 { |
|
358 return iAutoInterval; |
|
359 } |
|
360 |
|
361 /** |
|
362 * Sets background scan interval and refreshes the used |
|
363 * interval. |
|
364 * |
|
365 * @since S60 v5.2 |
|
366 * @param aInterval new background scan interval to be taken into use |
|
367 */ |
|
368 void SetInterval( TUint32 aInterval ); |
|
369 |
|
370 /** |
|
371 * Refreshes the used background scan interval. |
|
372 * |
|
373 * @since S60 v5.2 |
|
374 */ |
|
375 void RefreshUsedInterval(); |
|
376 |
|
377 protected: |
|
378 |
|
379 /** |
|
380 * Main state machine |
|
381 * |
|
382 * @since S60 v5.2 |
|
383 * @param aEvent event for state machine |
|
384 */ |
|
385 void NextState( const CWlanBgScanStates::TWlanBgScanSmEvent& aEvent ); |
|
386 |
|
387 /** |
|
388 * Get current interval. |
|
389 * |
|
390 * @since S60 v5.2 |
|
391 * @return current interval in use |
|
392 */ |
|
393 TUint32 GetBgInterval(); |
|
394 |
|
395 /** |
|
396 * Interval change is delivered to state machine |
|
397 * |
|
398 * @since S60 v5.2 |
|
399 */ |
|
400 void IntervalChanged(); |
|
401 |
|
402 /** |
|
403 * PSM server mode changed command is given to state |
|
404 * machine |
|
405 * |
|
406 * @since S60 v5.2 |
|
407 */ |
|
408 void DeliverPsmServerModeChange(); |
|
409 |
|
410 /** |
|
411 * Set AWS startup status. |
|
412 * |
|
413 * @param aStatus new status |
|
414 * @since S60 v5.2 |
|
415 */ |
|
416 inline void SetAwsStartupStatus( TInt aStatus ) |
|
417 { |
|
418 iAwsStartupStatus = aStatus; |
|
419 } |
|
420 |
|
421 /** |
|
422 * Set AWS command status. |
|
423 * |
|
424 * @param aCmd new command |
|
425 * @param aStatus new status |
|
426 * @since S60 v5.2 |
|
427 */ |
|
428 inline void SetAwsCmdStatus( MWlanBgScanAwsComms::TAwsCommand aCmd, TInt aStatus ) |
|
429 { |
|
430 iAwsCmd = aCmd; |
|
431 iAwsCmdStatus = aStatus; |
|
432 } |
|
433 |
|
434 /** |
|
435 * Set Auto interval. |
|
436 * |
|
437 * @param aAutoInterval new auto interval |
|
438 * @since S60 v5.2 |
|
439 */ |
|
440 inline void SetAutoInterval( TUint aAutoInterval ) |
|
441 { |
|
442 iAutoInterval = aAutoInterval; |
|
443 } |
|
444 |
|
445 private: // data |
|
446 |
|
447 /** |
|
448 * Reference to the Bg Scan |
|
449 */ |
|
450 CWlanBgScan& iBgScan; |
|
451 |
|
452 /** |
|
453 * Used background scan interval, in seconds. |
|
454 * This is the smaller one of iBgScanInterval |
|
455 * and iAggressiveBgScanInterval. |
|
456 */ |
|
457 TUint32 iUsedBgScanInterval; |
|
458 |
|
459 /** |
|
460 * Scan interval dictated by AWS component or |
|
461 * set (fixed interval) from UI. The value is |
|
462 * in seconds. |
|
463 */ |
|
464 TUint32 iBgScanInterval; |
|
465 |
|
466 /** |
|
467 * Aggressive background scan interval, in seconds. |
|
468 * Interval used for temporary aggressive BG scanning |
|
469 * when requested by the client or when activated by |
|
470 * WLAN Engine. |
|
471 */ |
|
472 TUint32 iAggressiveBgScanInterval; |
|
473 |
|
474 /** |
|
475 * Timer guarding when to drop out of aggressive BG scan mode |
|
476 */ |
|
477 CWlanTimer* iAggressiveBgScanTimer; |
|
478 |
|
479 /** |
|
480 * Next state to enter if AWS command delivery |
|
481 * is successful. |
|
482 */ |
|
483 TWlanBgScanState iNextState; |
|
484 |
|
485 /** |
|
486 * AWS startup status code. |
|
487 */ |
|
488 TInt iAwsStartupStatus; |
|
489 |
|
490 /** |
|
491 * AWS command. |
|
492 */ |
|
493 MWlanBgScanAwsComms::TAwsCommand iAwsCmd; |
|
494 |
|
495 /** |
|
496 * AWS command status. |
|
497 */ |
|
498 TInt iAwsCmdStatus; |
|
499 |
|
500 /** |
|
501 * Auto interval to be used in AutoAWS and Auto states |
|
502 */ |
|
503 TUint iAutoInterval; |
|
504 |
|
505 protected: // data |
|
506 |
|
507 /** |
|
508 * Reference to the Scan Result Provider |
|
509 */ |
|
510 MWlanScanResultProvider& iProvider; |
|
511 |
|
512 /** |
|
513 * Reference to WLAN Timer services. |
|
514 */ |
|
515 MWlanTimerServices& iTimerServices; |
|
516 |
|
517 /** |
|
518 * Current background scan state. |
|
519 */ |
|
520 TWlanBgScanState iBgScanState; |
|
521 |
|
522 /** |
|
523 * Received settings for background scan. |
|
524 */ |
|
525 MWlanBgScanProvider::TWlanBgScanSettings iBgScanSettings; |
|
526 |
|
527 /** |
|
528 * Id of the timer service request regarding |
|
529 * background scan interval change. |
|
530 */ |
|
531 TUint iIntervalChangeRequestId; |
|
532 |
|
533 /** |
|
534 * Completed AWS command. |
|
535 */ |
|
536 MWlanBgScanAwsComms::TAwsCommand iCompletedAwsCommand; |
|
537 |
|
538 /** |
|
539 * Status code of the completed AWS command. |
|
540 */ |
|
541 TInt iAwsCommandCompletionCode; |
|
542 }; |
|
543 |
|
544 #endif // WLANBGSCANSTATES_H |