libcommonc++  0.7
PulseTimer Class Referenceabstract

A timer that fires at regular intervals, with a resolution of 1 second. More...

#include <PulseTimer.h++>

Inheritance diagram for PulseTimer:
Collaboration diagram for PulseTimer:

Public Member Functions

 PulseTimer (timespan_s_t interval=1, timespan_s_t initialDelay=0)
 Construct a new PulseTimer with the given interval and initial delay. More...
 
 ~PulseTimer ()
 Destructor. More...
 
uint32_t getPulseCount () const
 Get the pluse count, i.e., the number of times the timer has fired. More...
 
time_ms_t getLastPulseTime () const
 Get the time at which the timer last fired. More...
 
virtual void start ()
 Start executing the thread. More...
 
virtual void stop ()
 Stop execution of the thread. More...
 
bool join ()
 Wait for the thread to terminate. More...
 
bool isRunning () const
 Test if the thread is currently running. More...
 
bool isDetached () const
 Test if the thread is detached. More...
 
void setPriority (Priority priority)
 Set the thread priority. More...
 
Priority getPriority () const
 Get the thread priority. More...
 
void setName (const String &name)
 Set the name of this thread. More...
 
String getName () const
 Get the name of this thread. More...
 

Static Public Member Functions

static void sleep (timespan_ms_t msec)
 Suspend the calling thread for the given time interval. More...
 
static ThreadcurrentThread ()
 Obtain a pointer to the Thread object for the calling thread. More...
 
static ThreadID currentThreadID ()
 Get the calling thread's thread ID. More...
 

Protected Member Functions

void run ()
 Main function. More...
 
void cleanup ()
 Cleanup function. More...
 
virtual void pulse (const time_ms_t &now)=0
 This method is called each time the timer fires. More...
 
bool trySleep (timespan_ms_t msec)
 Suspend the thread for the given time interval, returning early if the thread was cancelled via a call to stop(). More...
 
bool testCancel ()
 Test for asynchronous cancellation requests. More...
 
void yield ()
 Yield the CPU to (potentially) another thread. More...
 

Static Protected Member Functions

static void exit ()
 Exit (terminate) the calling thread. More...
 

Detailed Description

A timer that fires at regular intervals, with a resolution of 1 second.

This is an abstract class; subclasses should implement the pulse() method, which is called each time the timer fires. A PulseTimer is intended to run in its own thread.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ PulseTimer()

PulseTimer ( timespan_s_t  interval = 1,
timespan_s_t  initialDelay = 0 
)

Construct a new PulseTimer with the given interval and initial delay.

Parameters
intervalThe interval, in seconds, at which the timer will fire. Must be > 0.
initialDelayAn initial delay, in seconds, before the timer should begin firing.

◆ ~PulseTimer()

~PulseTimer ( )

Destructor.

Member Function Documentation

◆ cleanup()

void cleanup ( )
protectedvirtual

Cleanup function.

This function will be executed by the thread just prior to termination. The default implementation is a no-op.

Reimplemented from Thread.

◆ currentThread()

Thread * currentThread ( )
staticinherited

Obtain a pointer to the Thread object for the calling thread.

If the calling thread is the main thread, or some other thread that was not created via commonc++, a NULL pointer is returned. Never delete the object returned by this method.

◆ currentThreadID()

ccxx::ThreadID currentThreadID ( )
staticinherited

Get the calling thread's thread ID.

◆ exit()

void exit ( )
staticprotectedinherited

Exit (terminate) the calling thread.

◆ getLastPulseTime()

time_ms_t getLastPulseTime ( ) const
inline

Get the time at which the timer last fired.

Returns
The time of the last pulse, where 0 indicates that the timer has not yet fired for the first time.

◆ getName()

String getName ( ) const
inlineinherited

Get the name of this thread.

◆ getPriority()

Priority getPriority ( ) const
inherited

Get the thread priority.

◆ getPulseCount()

uint32_t getPulseCount ( ) const
inline

Get the pluse count, i.e., the number of times the timer has fired.

◆ isDetached()

bool isDetached ( ) const
inlineinherited

Test if the thread is detached.

◆ isRunning()

bool isRunning ( ) const
inherited

Test if the thread is currently running.

◆ join()

bool join ( )
inherited

Wait for the thread to terminate.

Returns
true if the join was successful, false otherwise. Note that threads which were created in a detached state are not joinable.

◆ pulse()

virtual void pulse ( const time_ms_t now)
protectedpure virtual

This method is called each time the timer fires.

Parameters
nowThe current system time.

◆ run()

void run ( )
protectedvirtual

Main function.

Thread execution begins in this function. The default implementation does nothing.

Reimplemented from Thread.

◆ setName()

void setName ( const String name)
inlineinherited

Set the name of this thread.

◆ setPriority()

void setPriority ( Priority  priority)
inherited

Set the thread priority.

◆ sleep()

void sleep ( timespan_ms_t  msec)
staticinherited

Suspend the calling thread for the given time interval.

Parameters
msecThe number of milliseconds to sleep.

◆ start()

void start ( )
virtualinherited

Start executing the thread.

If a Runnable object was supplied in the constructor, its run() method is invoked; otherwise the thread object's run() method is called. If the thread is already running, the call has no effect.

◆ stop()

void stop ( )
virtualinherited

Stop execution of the thread.

The thread is not forcibly killed; instead, an asynchronous cancellation request is posted to the thread. If the thread is not running, the call has no effect.

◆ testCancel()

bool testCancel ( )
protectedinherited

Test for asynchronous cancellation requests.

Returns
true If a cancellation request has been posted to the calling thread.

◆ trySleep()

bool trySleep ( timespan_ms_t  msec)
protectedinherited

Suspend the thread for the given time interval, returning early if the thread was cancelled via a call to stop().

Parameters
msecThe number of milliseconds to sleep.
Returns
true if the full interval elapsed, false if the thread was cancelled during the sleep.

◆ yield()

void yield ( )
protectedinherited

Yield the CPU to (potentially) another thread.


The documentation for this class was generated from the following files: