libcommonc++  0.7
PulseTimer.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_PulseTimer_hxx
24 #define __ccxx_PulseTimer_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/Thread.h++>
28 
29 namespace ccxx {
30 
40 {
41  public:
42 
51  PulseTimer(timespan_s_t interval = 1, timespan_s_t initialDelay = 0);
52 
54  ~PulseTimer();
55 
57  inline uint32_t getPulseCount() const
58  { return(_count); }
59 
66  inline time_ms_t getLastPulseTime() const
67  { return((_count > 0) ? _last : 0); }
68 
69  protected:
70 
71  void run();
72  void cleanup();
73 
79  virtual void pulse(const time_ms_t& now) = 0;
80 
81  private:
82 
83  timespan_ms_t _interval;
84  timespan_ms_t _delay;
85  time_ms_t _last;
86  uint32_t _count;
87 };
88 
89 } // namespace ccxx
90 
91 #endif // __ccxx_PulseTimer_hxx
int64_t time_ms_t
A time expressed in milliseconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:98
uint32_t getPulseCount() const
Get the pluse count, i.e., the number of times the timer has fired.
Definition: PulseTimer.h++:57
#define COMMONCPP_API
Definition: Common.h++:126
int timespan_s_t
A timespan expressed in seconds.
Definition: Integers.h++:91
time_ms_t getLastPulseTime() const
Get the time at which the timer last fired.
Definition: PulseTimer.h++:66
A timer that fires at regular intervals, with a resolution of 1 second.
Definition: PulseTimer.h++:39
int timespan_ms_t
A timespan expressed in milliseconds.
Definition: Integers.h++:104
A thread of execution.
Definition: Thread.h++:55
Definition: AllocationMap.c++:25