|
1 /* |
|
2 * Copyright (c) 2002-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: Active object to get notification of system time change. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 3 % |
|
20 */ |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <e32std.h> |
|
24 #include "wlansystemtimehandler.h" |
|
25 #include "am_debug.h" |
|
26 |
|
27 /** |
|
28 * Region cache should expire after 5 hours and therefore |
|
29 * 30 min timer is set 10 times |
|
30 */ |
|
31 const TInt KRegionCacheClearingTimer = 1800*1000000; // 30 min |
|
32 const TInt KRegionCacheClearingTimerCount = 10; |
|
33 /** |
|
34 * Two year timeout used to receive notification about system time change |
|
35 */ |
|
36 const TInt KWlanSystemTimeHandlerTimeoutTwoYears = 2; |
|
37 |
|
38 #ifdef _DEBUG |
|
39 /** |
|
40 * Formatting of date time debug string. |
|
41 */ |
|
42 _LIT( KWlanSystemTimeHandlerDateTimeFormat, "%F %*E %*N %Y %H:%T:%S" ); |
|
43 |
|
44 /** |
|
45 * Maximun length for date time debug string. |
|
46 */ |
|
47 const TInt KWlanSystemTimeHandlerMaxDateTimeStrLen = 50; |
|
48 #endif |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. |
|
54 // |
|
55 CWlanSystemTimeHandler::CWlanSystemTimeHandler( |
|
56 MWlanSystemTimeCallback& aClient ) : |
|
57 CActive( CActive::EPriorityStandard ), |
|
58 iClient( aClient ) |
|
59 { |
|
60 DEBUG( "CWlanSystemTimeHandler::CWlanSystemTimeHandler()" ); |
|
61 } |
|
62 |
|
63 // Static constructor. |
|
64 CWlanSystemTimeHandler* CWlanSystemTimeHandler::NewL( |
|
65 MWlanSystemTimeCallback& aClient) |
|
66 { |
|
67 DEBUG( "CWlanSystemTimeHandler::NewL()" ); |
|
68 CWlanSystemTimeHandler* self = |
|
69 new (ELeave) CWlanSystemTimeHandler( aClient ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // Symbian 2nd phase constructor can leave. |
|
77 void CWlanSystemTimeHandler::ConstructL() |
|
78 { |
|
79 DEBUG( "CWlanSystemTimeHandler::ConstructL()" ); |
|
80 |
|
81 CActiveScheduler::Add( this ); |
|
82 User::LeaveIfError( iTimer.CreateLocal() ); |
|
83 } |
|
84 |
|
85 // Destructor |
|
86 CWlanSystemTimeHandler::~CWlanSystemTimeHandler() |
|
87 { |
|
88 DEBUG( "CWlanSystemTimeHandler::~CWlanSystemTimeHandler()" ); |
|
89 |
|
90 Cancel(); |
|
91 iTimer.Close(); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CWlanSystemTimeHandler::DoCancel |
|
96 // Release synchronise call. Is called by CActive::Cancel() |
|
97 // --------------------------------------------------------- |
|
98 // |
|
99 void CWlanSystemTimeHandler::DoCancel() |
|
100 { |
|
101 DEBUG( "CWlanSystemTimeHandler::DoCancel()" ); |
|
102 iTimer.Cancel(); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------- |
|
106 // CWlanSystemTimeHandler::StartTimer |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 TInt CWlanSystemTimeHandler::StartTimer() |
|
110 { |
|
111 TTime timeout; |
|
112 timeout.HomeTime(); |
|
113 timeout += TTimeIntervalYears( KWlanSystemTimeHandlerTimeoutTwoYears ); |
|
114 |
|
115 /** |
|
116 * Set timeout to two years from now, just to receive notification when |
|
117 * system time changes. |
|
118 */ |
|
119 iTimer.At(iStatus, timeout ); |
|
120 |
|
121 SetActive(); |
|
122 |
|
123 #ifdef _DEBUG |
|
124 TBuf<KWlanSystemTimeHandlerMaxDateTimeStrLen> timeoutAt; |
|
125 TRAP_IGNORE( timeout.FormatL( timeoutAt, KWlanSystemTimeHandlerDateTimeFormat ) ); |
|
126 DEBUG1( "CWlanSystemTimeHandler::Start() - system time change notification timer started, timeout at: %S", &timeoutAt ); |
|
127 #endif |
|
128 |
|
129 return KErrNone; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------- |
|
133 // CWlanSystemTimeHandler::StopTimer |
|
134 // --------------------------------------------------------- |
|
135 // |
|
136 void CWlanSystemTimeHandler::StopTimer() |
|
137 { |
|
138 DEBUG( "CWlanSystemTimeHandler::StopTimer()" ); |
|
139 Cancel(); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CWlanSystemTimeHandler::RunL |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 void CWlanSystemTimeHandler::RunL() |
|
147 { |
|
148 DEBUG1( "CWlanSystemTimeHandler::RunL() - iStatus: %d", iStatus.Int() ); |
|
149 |
|
150 switch( iStatus.Int() ) |
|
151 { |
|
152 case KErrAbort: |
|
153 { |
|
154 DEBUG( "CWlanSystemTimeHandler::RunL() - system time changed, informing client" ); |
|
155 /** |
|
156 * RTimer is aborted when system time changes. |
|
157 * |
|
158 * Inform client that system time has now been changed. |
|
159 */ |
|
160 iClient.OnSystemTimeChange(); |
|
161 } |
|
162 case KErrNone: // flow through from KErrAbort on purpose |
|
163 { |
|
164 Cancel(); |
|
165 |
|
166 TTime newTimeout; |
|
167 newTimeout.HomeTime(); |
|
168 newTimeout += TTimeIntervalYears( KWlanSystemTimeHandlerTimeoutTwoYears ); |
|
169 |
|
170 /** |
|
171 * Set new timeout to two years from now, just to receive notification when |
|
172 * system time changes next time. |
|
173 */ |
|
174 iTimer.At( iStatus, newTimeout ); |
|
175 |
|
176 SetActive(); |
|
177 |
|
178 #ifdef _DEBUG |
|
179 TBuf<KWlanSystemTimeHandlerMaxDateTimeStrLen> timeoutAt; |
|
180 TRAP_IGNORE( newTimeout.FormatL( timeoutAt, KWlanSystemTimeHandlerDateTimeFormat ) ); |
|
181 DEBUG1( "CWlanSystemTimeHandler::RunL() - system time change notification timer restarted, timeout at: %S", &timeoutAt ); |
|
182 #endif |
|
183 |
|
184 break; |
|
185 } |
|
186 default: |
|
187 { |
|
188 DEBUG( "CWlanSystemTimeHandler::RunL() - ERROR: problem setting up system time change notifications, notifications are now disabled" ); |
|
189 Cancel(); |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 // ================= MEMBER FUNCTIONS ======================= |
|
195 |
|
196 // C++ default constructor can NOT contain any code, that |
|
197 // might leave. |
|
198 // |
|
199 CWlanPeriodicCacheClearingHandler::CWlanPeriodicCacheClearingHandler( |
|
200 MWlanSystemTimeCallback& aClient ) : |
|
201 CActive( CActive::EPriorityStandard ), |
|
202 iClearTimerCounter( 0 ), |
|
203 iClient( aClient ) |
|
204 { |
|
205 DEBUG( "CWlanPeriodicCacheClearingHandler::CWlanPeriodicCacheClearingHandler()" ); |
|
206 } |
|
207 |
|
208 // Static constructor. |
|
209 CWlanPeriodicCacheClearingHandler* CWlanPeriodicCacheClearingHandler::NewL( |
|
210 MWlanSystemTimeCallback& aClient) |
|
211 { |
|
212 DEBUG( "CWlanPeriodicCacheClearingHandler::NewL()" ); |
|
213 CWlanPeriodicCacheClearingHandler* self = |
|
214 new (ELeave) CWlanPeriodicCacheClearingHandler( aClient ); |
|
215 CleanupStack::PushL( self ); |
|
216 self->ConstructL(); |
|
217 CleanupStack::Pop( self ); |
|
218 return self; |
|
219 } |
|
220 |
|
221 // Symbian 2nd phase constructor can leave. |
|
222 void CWlanPeriodicCacheClearingHandler::ConstructL() |
|
223 { |
|
224 DEBUG( "CWlanPeriodicCacheClearingHandler::ConstructL()" ); |
|
225 |
|
226 CActiveScheduler::Add( this ); |
|
227 User::LeaveIfError( iClearTimer.CreateLocal() ); |
|
228 } |
|
229 |
|
230 // Destructor |
|
231 CWlanPeriodicCacheClearingHandler::~CWlanPeriodicCacheClearingHandler() |
|
232 { |
|
233 DEBUG( "CWlanPeriodicCacheClearingHandler::~CWlanPeriodicCacheClearingHandler()" ); |
|
234 |
|
235 Cancel(); |
|
236 iClearTimer.Close(); |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------- |
|
240 // CWlanPeriodicCacheClearingHandler::DoCancel |
|
241 // Release synchronise call. Is called by CActive::Cancel() |
|
242 // --------------------------------------------------------- |
|
243 // |
|
244 void CWlanPeriodicCacheClearingHandler::DoCancel() |
|
245 { |
|
246 DEBUG( "CWlanPeriodicCacheClearingHandler::DoCancel()" ); |
|
247 iClearTimer.Cancel(); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------- |
|
251 // CWlanPeriodicCacheClearingHandler::StartTimer |
|
252 // --------------------------------------------------------- |
|
253 // |
|
254 TInt CWlanPeriodicCacheClearingHandler::StartTimer() |
|
255 { |
|
256 DEBUG( "CWlanPeriodicCacheClearingHandler::StartTimer()" ); |
|
257 |
|
258 // Issue an Asynchronous Request |
|
259 iClearTimer.After(iStatus, KRegionCacheClearingTimer); |
|
260 |
|
261 // set it to active once request is issued |
|
262 SetActive(); |
|
263 |
|
264 return KErrNone; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CWlanPeriodicCacheClearingHandler::StopTimer |
|
269 // --------------------------------------------------------- |
|
270 // |
|
271 void CWlanPeriodicCacheClearingHandler::StopTimer() |
|
272 { |
|
273 DEBUG( "CWlanPeriodicCacheClearingHandler::StopTimer()" ); |
|
274 Cancel(); |
|
275 iClearTimerCounter = 0; |
|
276 } |
|
277 |
|
278 // --------------------------------------------------------- |
|
279 // CWlanPeriodicCacheClearingHandler::RunL |
|
280 // Timer has expired. |
|
281 // --------------------------------------------------------- |
|
282 // |
|
283 void CWlanPeriodicCacheClearingHandler::RunL() |
|
284 { |
|
285 DEBUG( "CWlanPeriodicCacheClearingHandler::RunL()" ); |
|
286 |
|
287 // This is the case when system time is changed and |
|
288 // hence will cause the timer to abort with KErrAbort. |
|
289 |
|
290 if( iStatus.Int() == KErrNone && |
|
291 iClearTimerCounter < KRegionCacheClearingTimerCount-1) |
|
292 { |
|
293 iClearTimerCounter += 1; |
|
294 |
|
295 // Issue an Asynchronous Request |
|
296 iClearTimer.After(iStatus, KRegionCacheClearingTimer); |
|
297 |
|
298 // set it to active once request is issued |
|
299 SetActive(); |
|
300 |
|
301 } |
|
302 else if ( iStatus.Int() == KErrNone && |
|
303 iClearTimerCounter >= KRegionCacheClearingTimerCount-1 ) |
|
304 { |
|
305 /* Inform client that system time has been changed so that |
|
306 * region information cache can be cleared. |
|
307 */ |
|
308 iClient.OnCacheClearTimerExpiration(); |
|
309 iClearTimerCounter = 0; |
|
310 } |
|
311 else |
|
312 { |
|
313 DEBUG( "CWlanPeriodicCacheClearingHandler::RunL() - time expired" ); |
|
314 } |
|
315 } |
|
316 |