class CPeriodic : public CTimer |
Periodic timer active object.
This class generates regular timer events and handles them with a callback function. The callback is specified as a parameter to Start().
The callback may not be called immediately after the signal from the timer request has been generated, for the following reasons:
1. the RunL() of another active object may be running at the time of the signal
2. other active objects may have a higher priority than the CPeriodic
If timing accuracy is important to your application, you can minimise the first problem by ensuring all RunL()s complete quickly, and can eliminate the second by giving the CPeriodic a higher priority than any other active object. Although it is generally recommended that timer-related active objects have a high priority, this will not address the problem of CPeriodic timers running behind, because active object scheduling is not pre-emptive.
After a timer signal generated by a CPeriodic, the next signal is requested just before running the callback, and this request can be delayed for the same reasons that running the callback can be delayed. Therefore, a large number N of periods may add up to somewhat more than N times the requested period time. If absolute precision is required in tracking time, do not rely on counting the number of times the callback is called: read the value of the system clock every time you need it.
For many applications, such precision is not required, for example, tick counting is sufficiently accurate for controlling time-outs in a communications program.
Note that you should be familiar with CActive in order to understand CPeriodic behaviour, but not necessarily with CTimer.
Public Member Functions | |
---|---|
~CPeriodic() | |
IMPORT_C CPeriodic * | New(TInt) |
IMPORT_C CPeriodic * | NewL(TInt) |
IMPORT_C void | Start(TTimeIntervalMicroSeconds32, TTimeIntervalMicroSeconds32, TCallBack) |
Protected Member Functions | |
---|---|
CPeriodic(TInt) | |
IMPORT_C void | RunL() |
Inherited Enumerations | |
---|---|
CActive:TPriority |
Private Attributes | |
---|---|
TCallBack | iCallBack |
TTimeIntervalMicroSeconds32 | iInterval |
Inherited Attributes | |
---|---|
CActive::iStatus |
IMPORT_C | CPeriodic | ( | TInt | aPriority | ) | [protected] |
Protected constructor with priority.
Use this constructor to set the priority of the active object.
Classes derived from CPeriodic must define and provide a constructor through which the priority of the active object can be passed. Such a constructor can call CPeriodic's constructor in its constructor initialisation list.
TInt aPriority | The priority of the timer. |
IMPORT_C CPeriodic * | New | ( | TInt | aPriority | ) | [static] |
Allocates and constructs a CPeriodic object - non-leaving.
Specify a high priority so the callback function is scheduled as soon as possible after the timer events complete.
TInt aPriority | The priority of the active object. If timing is critical, it should be higher than that of all other active objects owned by the scheduler. |
IMPORT_C CPeriodic * | NewL | ( | TInt | aPriority | ) | [static] |
Allocates and constructs a CPeriodic object - leaving.
Specify a high priority so the callback function is scheduled as soon as possible after the timer events complete.
TInt aPriority | The priority of the active object. If timing is critical, it should be higher than that of all other active objects owned by the scheduler. |
IMPORT_C void | RunL | ( | ) | [protected, virtual] |
Handles an active object's request completion event.
A derived class must provide an implementation to handle the completed request. If appropriate, it may issue another request.
The function is called by the active scheduler when a request completion event occurs, i.e. after the active scheduler's WaitForAnyRequest() function completes.
Before calling this active object's RunL() function, the active scheduler has:
1. decided that this is the highest priority active object with a completed request
2. marked this active object's request as complete (i.e. the request is no longer outstanding)
RunL() runs under a trap harness in the active scheduler. If it leaves, then the active scheduler calls RunError() to handle the leave.
Note that once the active scheduler's Start() function has been called, all user code is run under one of the program's active object's RunL() or RunError() functions.
CActiveScheduler::Start CActiveScheduler::Error CActiveScheduler::WaitForAnyRequest TRAPD
IMPORT_C void | Start | ( | TTimeIntervalMicroSeconds32 | aDelay, |
TTimeIntervalMicroSeconds32 | anInterval, | |||
TCallBack | aCallBack | |||
) |
Starts generating periodic events.
The event calls the protected RunL() function, which in turn calls the function specified by aCallBack. The first event is generated after aDelay microseconds; subsequent events are generated regularly thereafter at intervals of anInterval microseconds.
The TCallBack contains a function pointer and a TAny* pointer. The function will be repeatedly called with the pointer as a parameter.
Once started, periodic events are generated until the CPeriodic object is destroyed.
Notes:
1. The callback function will be run as soon as possible after the initial delay, and after each period.
2. The callback may be delayed because the RunL() of another active object, with the deepest nesting-level active scheduler on the same thread, is running when the event occurs: this cannot be avoided, but can be minimised by making all RunL()s of short duration.
3. The callback may be delayed because other, higher-priority, active objects are scheduled instead. This can be avoided by giving the CPeriodic a very high priority.
TTimeIntervalMicroSeconds32 aDelay | The delay from the Start() function to the generation of the first event, in microseconds. |
TTimeIntervalMicroSeconds32 anInterval | The interval between events generated after the initial delay, in microseconds. |
TCallBack aCallBack | A callback specifying a function to be called when the CPeriodic is scheduled after a timer event. |
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.