|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-078E6232-31FA-5582-84B8-F5E3E4B14A05" xml:lang="en"><title>How |
|
13 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> |
|
14 <p>A heartbeat timer, <codeph>CHeartbeat</codeph>, invokes a function at regular |
|
15 intervals. You must define a class that implements the <codeph>MBeating</codeph> interface |
|
16 to define:</p> |
|
17 <ul> |
|
18 <li id="GUID-5B54CE88-DE53-5635-BBF4-639B693C5BEC"><p>a function <codeph>Beat()</codeph> that |
|
19 is called if the heartbeat timer is in synchronisation with the system clock</p> </li> |
|
20 <li id="GUID-E20AD2FD-B847-52B6-8D1E-F01B2A971ABA"><p>a function <codeph>Synchronize()</codeph> that |
|
21 is called if the heartbeat timer has got out of synchronisation with the system |
|
22 clock</p> </li> |
|
23 </ul> |
|
24 <p>First, we define a class <codeph>CHeartbeatRunner</codeph> class that derives |
|
25 from <codeph>MBeating</codeph>. </p> |
|
26 <codeblock id="GUID-6D0B8C93-7F24-5002-A8FF-5C9F4C41EE7B" xml:space="preserve">class CHeartbeatRunner: public MBeating |
|
27 { |
|
28 public: |
|
29 // Implement MBeating |
|
30 void Beat(); |
|
31 void Synchronize(); |
|
32 |
|
33 // Start timer |
|
34 void StartTimer(); |
|
35 private: |
|
36 CHeartbeat* iHeartbeat; |
|
37 };</codeblock> |
|
38 <p>Then, we can start the heartbeat timer. We pass the time interval for the |
|
39 beats (allowable intervals are defined in 1/12s of a second by <codeph>TTimerLockSpec</codeph>), |
|
40 and the object implementing <codeph>MBeating</codeph>.</p> |
|
41 <codeblock id="GUID-C0BD2194-9FED-5C2B-B900-A028210CF78C" xml:space="preserve">void CHeartbeatRunner::StartTimer() |
|
42 { |
|
43 iHeartbeat=CHeartbeat::NewL(0); // neutral priority |
|
44 iHeartbeat->Start(ETwelveOClock,this); // 1 second intervals |
|
45 }</codeblock> |
|
46 </conbody></concept> |