Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32base.h
Link against: euser.lib

Class CPeriodic

CPeriodic

Support

Supported from 5.0

Description

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().

Timer Accuracy:

The callback may not be called immediately after the signal from the timer request has been generated, for the following reasons:

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 instance, tick counting is sufficiently accurate for controlling time-outs in a communications program.

Note:

You should be familiar with CActive in order to understand CPeriodic behaviour, but not necessarily with CTimer.

Derivation

CActiveThe core class of the active object abstraction
CBaseBase class for all classes to be instantiated on the heap
CPeriodicPeriodic timer active object
CTimerBase class for a timer active object

Defined in CPeriodic:
CPeriodic(), New(), NewL(), Start(), ~CPeriodic()

Inherited from CActive:
Cancel(), Deque(), DoCancel(), EPriorityHigh, EPriorityIdle, EPriorityLow, EPriorityStandard, EPriorityUserInput, IsActive(), IsAdded(), Priority(), RunError(), RunL(), SetActive(), SetPriority(), TPriority, iStatus

Inherited from CBase:
operator new()

Inherited from CTimer:
After(), At(), ConstructL(), Inactivity(), Lock()

See also:


Construction and destruction


New()

static CPeriodic* New(TInt aPriority);

Description

Allocates and constructs a CPeriodic object — non-leaving.

Note:

Parameters

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.

Return value

CPeriodic*

Pointer to new CPeriodic object. The object is initialised and added to the active scheduler. This value is NULL if insufficient memory was available.


NewL()

static CPeriodic* NewL(TInt aPriority);

Description

Allocates and constructs a CPeriodic object — leaving.

Note:

Parameters

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.

Return value

CPeriodic*

Pointer to new CPeriodic object. The object is initialised and added to the active scheduler.

Leave codes

 

The function may leave with KErrNoMemory if there is insufficient memory to create the object.


~CPeriodic()

~CPeriodic();

Description

Frees resources prior to destruction.


CPeriodic()

protected: CPeriodic(TInt aPriority);

Description

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.

Parameters

TInt aPriority

The priority of the timer.

[Top]


Starting


Start()

void Start(TTimeIntervalMicroSeconds32 aDelay,TTimeIntervalMicroSeconds32 anInterval,TCallBack aCallBack);

Description

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:

Parameters

TTimeIntervalMicroSeconds32 aDelay

The delay from the Start() function to the generation of the first event, in microseconds. Must be greater than zero.

TTimeIntervalMicroSeconds32 anInterval

The interval between events generated after the initial delay, in microseconds. A panic occurs if this value is less than zero.

TCallBack aCallBack

A callback specifying a function to be called when the CPeriodic is scheduled after a timer event.