Symbian3/PDK/Source/GUID-078E6232-31FA-5582-84B8-F5E3E4B14A05.dita
author Graeme Price <GRAEME.PRICE@NOKIA.COM>
Fri, 15 Oct 2010 14:32:18 +0100
changeset 15 307f4279f433
parent 14 578be2adaf3e
permissions -rw-r--r--
Initial contribution of the Adaptation Documentation.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-078E6232-31FA-5582-84B8-F5E3E4B14A05" xml:lang="en"><title>How
to start a heartbeat timer</title><shortdesc>Provides code snippet to show you how to start a heartbeat timer.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>A heartbeat timer, <codeph>CHeartbeat</codeph>, invokes a function at regular
intervals. You must define a class that implements the <codeph>MBeating</codeph> interface
to define:</p>
<ul>
<li id="GUID-5B54CE88-DE53-5635-BBF4-639B693C5BEC"><p>a function <codeph>Beat()</codeph> that
is called if the heartbeat timer is in synchronisation with the system clock</p> </li>
<li id="GUID-E20AD2FD-B847-52B6-8D1E-F01B2A971ABA"><p>a function <codeph>Synchronize()</codeph> that
is called if the heartbeat timer has got out of synchronisation with the system
clock</p> </li>
</ul>
<p>First, we define a class <codeph>CHeartbeatRunner</codeph> class that derives
from <codeph>MBeating</codeph>. </p>
<codeblock id="GUID-6D0B8C93-7F24-5002-A8FF-5C9F4C41EE7B" xml:space="preserve">class CHeartbeatRunner: public MBeating
    {
public:
    // Implement MBeating
    void Beat();
    void Synchronize();

    // Start timer
    void StartTimer();
private:
    CHeartbeat* iHeartbeat;
};</codeblock>
<p>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 <codeph>TTimerLockSpec</codeph>),
and the object implementing <codeph>MBeating</codeph>.</p>
<codeblock id="GUID-C0BD2194-9FED-5C2B-B900-A028210CF78C" xml:space="preserve">void CHeartbeatRunner::StartTimer()
    {
    iHeartbeat=CHeartbeat::NewL(0); // neutral priority
    iHeartbeat-&gt;Start(ETwelveOClock,this); // 1 second intervals
    }</codeblock>
</conbody></concept>