Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



How to start a heartbeat timer

A heartbeat timer, CHeartbeat, invokes a function at regular intervals. You must define a class that implements the MBeating interface to define:

First, we define a class CHeartbeatRunner class that derives from MBeating.

class CHeartbeatRunner: public MBeating
    {
public:
    // Implement MBeating
    void Beat();
    void Synchronize();

    // Start timer
    void StartTimer();
private:
    CHeartbeat* iHeartbeat;
};

Then, we can start the heartbeat timer. We pass the time interval for the beats (allowable intervals are defined in 1/12s of a second by TTimerLockSpec), and the object implementing MBeating.

void CHeartbeatRunner::StartTimer()
    {
    iHeartbeat=CHeartbeat::NewL(0); // neutral priority
    iHeartbeat->Start(ETwelveOClock,this); // 1 second intervals
    }