|
|
|
A heartbeat timer, CHeartbeat, invokes a function at
regular intervals. You must define a class that implements the
MBeating interface to define:
a function Beat() that is called if the heartbeat
timer is in synchronisation with the system clock
a function Synchronize() that is called if the
heartbeat timer has got out of synchronisation with the system clock
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
}