|
1 /* |
|
2 * Copyright (c) 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 "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: CFlexTimer class for Flexible Timer server access. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 1 % |
|
20 */ |
|
21 |
|
22 #ifndef CFLEXTIMER_H |
|
23 #define CFLEXTIMER_H |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include <e32base.h> |
|
27 #include "rflextimer.h" |
|
28 |
|
29 // CLASS DECLARATION |
|
30 /** |
|
31 * Class providing access to flexible timer service. |
|
32 * This class uses RFlexTimer to provide user with timeout services. Each |
|
33 * timeout that is requested with this class has a time window during which |
|
34 * it may expire. The size of this window needs to be configured by the user. |
|
35 * If not configured, a default window size is used. See RFlexTimer for |
|
36 * details about default window. |
|
37 * |
|
38 * This class can not be instantiated; it needs to be inherited by a |
|
39 * user's derived class. The user also needs to implement the RunL |
|
40 * function. |
|
41 * |
|
42 * The timer returns one of the following values for TRequestStatus or any |
|
43 * other system-wide error codes: |
|
44 * |
|
45 * <table border=1 bordercolor="#84B0C7" cellspacing="0" align="center"> |
|
46 * <tr> |
|
47 * <th>Return value</th> |
|
48 * <th>Description</th> |
|
49 * <th>@c At()</th> |
|
50 * <th>@c AtUTC()</th> |
|
51 * <th>@c After()</th> |
|
52 * </tr> |
|
53 * <tr> |
|
54 * <td>@c KErrNone</td> |
|
55 * <td>Timer has expired normally</td> |
|
56 * <td align="center">X</td> |
|
57 * <td align="center">X</td> |
|
58 * <td align="center">X</td> |
|
59 * </tr> |
|
60 * <tr> |
|
61 * <td>@c KErrCancel</td> |
|
62 * <td>Timer has been cancelled</td> |
|
63 * <td align="center">X</td> |
|
64 * <td align="center">X</td> |
|
65 * <td align="center">X</td> |
|
66 * </tr> |
|
67 * <tr> |
|
68 * <td>@c KErrAbort</td> |
|
69 * <td>Timer has been aborted due time change</td> |
|
70 * <td align="center">X</td> |
|
71 * <td align="center">X</td> |
|
72 * <td align="center"> </td> |
|
73 * </tr> |
|
74 * </table> |
|
75 * |
|
76 * Any object derived from this class needs to connect to the flextimer |
|
77 * server by calling CFlexTimer::ConstructL() function before calling |
|
78 * configuration or timeout functions. Otherwise any timeout function will |
|
79 * result in panic. |
|
80 * |
|
81 * @see RFlexTimer |
|
82 * @see CTimer |
|
83 * |
|
84 * Example: |
|
85 * |
|
86 * Class definition: |
|
87 * @code |
|
88 * class CMyNetworkServiceMonitor : public CFlexTimer |
|
89 * { |
|
90 * public: // Members |
|
91 * |
|
92 * // Public two-phased constructor |
|
93 * static CMyNetworkServiceMonitor* NewL( |
|
94 * TTimeIntervalMicroSeconds aWindow, |
|
95 * TTimeIntervalMicroSeconds aInterval ); |
|
96 * |
|
97 * // Destructor |
|
98 * virtual ~CMyNetworkServiceMonitor(); |
|
99 * |
|
100 * protected: // From CActive |
|
101 * |
|
102 * // Handles an active object's request completion event |
|
103 * virtual void RunL(); |
|
104 * |
|
105 * private: // Members |
|
106 * |
|
107 * // Private constructor |
|
108 * CMyNetworkServiceMonitor( TTimeIntervalMicroSeconds aInterval ); |
|
109 * |
|
110 * // Second phase constructor |
|
111 * void ConstructL( TTimeIntervalMicroSeconds aWindow ); |
|
112 * |
|
113 * // Does the network server monitoring. |
|
114 * // Implementation is not provided by this example. |
|
115 * DoNetworkServiceMonitoring(); |
|
116 * |
|
117 * private: // Data |
|
118 * |
|
119 * TTimeIntervalMicroSeconds iInterval; |
|
120 * }; |
|
121 * @endcode |
|
122 * |
|
123 * Class implementation: |
|
124 * @code |
|
125 * CMyNetworkServiceMonitor::CMyNetworkServiceMonitor( TTimeIntervalMicroSeconds aInterval ) : |
|
126 * CFlexTimer( CActive::EPriorityStandard ), |
|
127 * iInterval( aInterval ) |
|
128 * { |
|
129 * // Nothing to do |
|
130 * } |
|
131 * |
|
132 * // --------------------------------------------------------------------------- |
|
133 * // |
|
134 * CMyNetworkServiceMonitor::~CMyNetworkServiceMonitor() |
|
135 * { |
|
136 * Cancel(); // DoCancel() is implemented by CFlexTimer |
|
137 * } |
|
138 * |
|
139 * // --------------------------------------------------------------------------- |
|
140 * // |
|
141 * void CMyNetworkServiceMonitor::ConstructL( TTimeIntervalMicroSeconds aWindow ) |
|
142 * { |
|
143 * const TTimeIntervalMicroSeconds KImmediately( 0 ); |
|
144 * |
|
145 * CFlexTimer::ConstructL(); |
|
146 * CActiveScheduler::Add( this ); |
|
147 * |
|
148 * Configure( aWindow ); |
|
149 * |
|
150 * After( KImmediately ); // Kick-off the timer |
|
151 * } |
|
152 * |
|
153 * // --------------------------------------------------------------------------- |
|
154 * // |
|
155 * CMyNetworkServiceMonitor* CMyNetworkServiceMonitor::NewL( |
|
156 * TTimeIntervalMicroSeconds aWindow, |
|
157 * TTimeIntervalMicroSeconds aInterval ) |
|
158 * { |
|
159 * CMyNetworkServiceMonitor* self = |
|
160 * new (ELeave) CMyNetworkServiceMonitor( aInterval ); |
|
161 * CleanupStack::PushL( self ); |
|
162 * self->ConstructL( aWindow ); |
|
163 * CleanupStack::Pop( self ); |
|
164 * return self; |
|
165 * } |
|
166 * |
|
167 * // --------------------------------------------------------------------------- |
|
168 * // |
|
169 * void CMyNetworkServiceMonitor::RunL() |
|
170 * { |
|
171 * // Note! If used RFlexTimer::At() or RFlexTimer::AtUTC() |
|
172 * // iStatus == KErrAbort should also be handled. |
|
173 * |
|
174 * if ( iStatus == KErrNone ) |
|
175 * { |
|
176 * // Do the network server monitor actions |
|
177 * DoNetworkServiceMonitoring(); |
|
178 * |
|
179 * // Refresh the timer |
|
180 * After( iInterval ); |
|
181 * } |
|
182 * else if ( iStatus == KErrCancel ) |
|
183 * { |
|
184 * // Timer was cancelled. Do not activate it again... |
|
185 * } |
|
186 * else |
|
187 * { |
|
188 * // Handle the error by implementing RunError() |
|
189 * // See also: CActive::RunError() |
|
190 * User::Leave( iStatus ); |
|
191 * } |
|
192 * } |
|
193 * @endcode |
|
194 */ |
|
195 class CFlexTimer : public CActive |
|
196 { |
|
197 public: |
|
198 |
|
199 /** |
|
200 * Destructs the object. |
|
201 */ |
|
202 IMPORT_C virtual ~CFlexTimer(); |
|
203 |
|
204 /** |
|
205 * Fire timer at latest on the given interval. 32-bit interval value. |
|
206 * @param aInterval the interval value until which the timer must expire. |
|
207 * |
|
208 * @panic CFlexTimer 10 CFlexTimer::ConstructL() has not been called yet |
|
209 * @panic RFlexTimer 15 Timer is already active. Wait it to expire or |
|
210 * cancel it first. |
|
211 * @panic RFlexTimer 1 aInterval is negative |
|
212 * |
|
213 * Example: |
|
214 * @code |
|
215 * const TTimeIntervalMicroSeconds32 KInterval32( 600000000 ); // 10 min |
|
216 * After( KInterval32 ); |
|
217 * @endcode |
|
218 */ |
|
219 IMPORT_C void After( TTimeIntervalMicroSeconds32 aInterval ); |
|
220 |
|
221 /** |
|
222 * Fire timer at latest on the given interval. 64-bit interval value. |
|
223 * |
|
224 * @param aInterval the interval value until which the timer must expire. |
|
225 * |
|
226 * @panic CFlexTimer 10 CFlexTimer::ConstructL() has not been called yet |
|
227 * @panic RFlexTimer 1 aInterval is negative |
|
228 * @panic RFlexTimer 15 Timer is already active. Wait it to expire or |
|
229 * cancel it first. |
|
230 * @panic RFlexTimer 24 aInterval is too big (over 730 days) |
|
231 * |
|
232 * Example: |
|
233 * @code |
|
234 * const TTimeIntervalMicroSeconds KInterval64( 600000000 ); // 10 min |
|
235 * After( KInterval64 ); |
|
236 * @endcode |
|
237 */ |
|
238 IMPORT_C void After( TTimeIntervalMicroSeconds aInterval ); |
|
239 |
|
240 /** |
|
241 * Fire timer at latest by the given time value. The time value provided |
|
242 * here is related to HomeTime. @see TTime. If the system |
|
243 * time changes before the timer requested with At-function expires, it |
|
244 * will cancel itself. This will result in the aStatus argument to have |
|
245 * KErrAbort-value. |
|
246 * |
|
247 * @param aTime indicates the latest time when this timer should be fired. |
|
248 * |
|
249 * @panic CFlexTimer 10 CFlexTimer::ConstructL() has not been called yet |
|
250 * @panic RFlexTimer 3 aTime is in the past |
|
251 * @panic RFlexTimer 15 Timer is already active. Wait it to expire or |
|
252 * cancel it first. |
|
253 * @panic RFlexTimer 24 aTime is too far to the future (over 730 days) |
|
254 * |
|
255 * Example: |
|
256 * @code |
|
257 * const TTimeIntervalMinutes KWaitTime( 5 ); |
|
258 * |
|
259 * TTime now; |
|
260 * now.HomeTime(); |
|
261 * |
|
262 * At( nowUtc + KWaitTime ); |
|
263 * @endcode |
|
264 */ |
|
265 IMPORT_C void At( const TTime& aTime ); |
|
266 |
|
267 /** |
|
268 * Fire timer at latest by the given UTC (Coordinated Universal Time) |
|
269 * time value. If the system |
|
270 * time changes before the timer requested with At-function expires, it |
|
271 * will cancel itself. This will result in the aStatus argument to have |
|
272 * KErrAbort-value. |
|
273 * @param aTime indicates the latest UTC time when this timer should be |
|
274 * fired. |
|
275 * |
|
276 * @panic CFlexTimer 10 CFlexTimer::ConstructL() has not been called yet |
|
277 * @panic RFlexTimer 3 aTime is in the past |
|
278 * @panic RFlexTimer 15 Timer is already active. Wait it to expire or |
|
279 * cancel it first. |
|
280 * @panic RFlexTimer 24 aTime is too far to the future (over 730 days) |
|
281 * |
|
282 * Example: |
|
283 * @code |
|
284 * const TTimeIntervalMinutes KWaitTime( 5 ); |
|
285 * |
|
286 * TTime nowUtc; |
|
287 * nowUtc.UniversalTime(); |
|
288 * |
|
289 * AtUTC( nowUtc + KWaitTime ); |
|
290 * @endcode |
|
291 */ |
|
292 IMPORT_C void AtUTC( const TTime& aTime ); |
|
293 |
|
294 /** |
|
295 * Sets the window size in which flexibility is possible for the timer. |
|
296 * @see RFlexTimer::Configure |
|
297 * @param aWindowSize is the window size in 32-bit microseconds in which |
|
298 * timer flexiblity is possible. |
|
299 * @return KErrNone on success. KErrInUse, if timer has been |
|
300 * started already. |
|
301 * |
|
302 * @panic CFlexTimer 10 CFlexTimer::ConstructL() has not been called yet |
|
303 * @panic RFlexTimer 5 aWindowSize is negative |
|
304 * |
|
305 * Example: |
|
306 * @code |
|
307 * const TTimeIntervalMicroSeconds32 KWindow32( 120000000 ); // 2 mins |
|
308 * Configure( KWindow32 ); |
|
309 * @endcode |
|
310 */ |
|
311 IMPORT_C TInt Configure( TTimeIntervalMicroSeconds32 aWindowSize ); |
|
312 |
|
313 /** |
|
314 * Sets the window size in which flexibility is possible for the timer. |
|
315 * @see RFlexTimer::Configure |
|
316 * @param aWindowSize is the window size in 64-bit microseconds in which |
|
317 * timer flexiblity is possible. |
|
318 * @return KErrNone on success. KErrInUse, if timer has been |
|
319 * started already. |
|
320 * |
|
321 * @panic CFlexTimer 10 CFlexTimer::ConstructL() has not been called yet |
|
322 * @panic RFlexTimer 5 aWindowSize is negative |
|
323 * @panic RFlexTimer 24 aWindowSize is too big (max 730 days) |
|
324 * |
|
325 * Example: |
|
326 * @code |
|
327 * const TTimeIntervalMicroSeconds KWindow64( 120000000 ); // 2 mins |
|
328 * Configure( KWindow64 ); |
|
329 * @endcode |
|
330 */ |
|
331 IMPORT_C TInt Configure( TTimeIntervalMicroSeconds aWindowSize ); |
|
332 |
|
333 protected: |
|
334 |
|
335 /** |
|
336 * 2nd phase constructor for this the object. Connects to the flextimer |
|
337 * server and creates a session. This function needs to be called by the |
|
338 * object that is derived from this class. |
|
339 */ |
|
340 IMPORT_C void ConstructL(); |
|
341 |
|
342 /** |
|
343 * Constructs the object. |
|
344 */ |
|
345 IMPORT_C CFlexTimer( TInt aPriority ); |
|
346 |
|
347 /** |
|
348 * Inherited from CActive. |
|
349 */ |
|
350 IMPORT_C virtual void DoCancel(); |
|
351 |
|
352 private: |
|
353 |
|
354 /** |
|
355 * The timer resource used by this object. |
|
356 */ |
|
357 RFlexTimer iTimer; |
|
358 |
|
359 }; |
|
360 |
|
361 #endif // CFLEXTIMER_H |
|
362 |
|
363 |