Instrument Neutral Distributed Interface INDI  2.0.2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
INDI::Timer Class Reference

The Timer class provides repetitive and single-shot timers. More...

#include <inditimer.h>

Public Member Functions

 Timer ()
 
virtual ~Timer ()
 
void start ()
 Starts or restarts the timer with the timeout specified in interval. More...
 
void start (int msec)
 Starts or restarts the timer with a timeout interval of msec milliseconds. More...
 
void stop ()
 Stops the timer. More...
 
void callOnTimeout (const std::function< void()> &callback)
 
void setInterval (int msec)
 Set the timeout interval in milliseconds. More...
 
void setSingleShot (bool singleShot)
 Set whether the timer is a single-shot timer. More...
 
bool isActive () const
 Returns true if the timer is running (pending); otherwise returns false. More...
 
bool isSingleShot () const
 Returns whether the timer is a single-shot timer. More...
 
int remainingTime () const
 Returns the timer's remaining value in milliseconds left until the timeout. If the timer not exists, the returned value will be -1. More...
 
int interval () const
 Returns the timeout interval in milliseconds. More...
 
virtual void timeout ()
 This function is called when the timer times out. More...
 

Static Public Member Functions

static void singleShot (int msec, const std::function< void()> &callback)
 This static function calls a the given function after a given time interval. More...
 

Protected Member Functions

 Timer (TimerPrivate &dd)
 

Protected Attributes

std::unique_ptr< TimerPrivated_ptr
 

Detailed Description

The Timer class provides repetitive and single-shot timers.

The Timer class provides a high-level programming interface for timers. To use it, create a Timer, set your function with callOnTimeout, and call start(). From then on, it will call your function at constant intervals.

You can set a timer to time out only once by calling setSingleShot(true). You can also use the static Timer::singleShot() function to call a function after a specified interval.

Definition at line 40 of file inditimer.h.

Constructor & Destructor Documentation

◆ Timer() [1/2]

INDI::Timer::Timer ( )

Definition at line 65 of file inditimer.cpp.

◆ ~Timer()

INDI::Timer::~Timer ( )
virtual

Definition at line 73 of file inditimer.cpp.

◆ Timer() [2/2]

INDI::Timer::Timer ( TimerPrivate dd)
protected

Definition at line 69 of file inditimer.cpp.

Member Function Documentation

◆ callOnTimeout()

void INDI::Timer::callOnTimeout ( const std::function< void()> &  callback)

Definition at line 76 of file inditimer.cpp.

◆ interval()

int INDI::Timer::interval ( ) const

Returns the timeout interval in milliseconds.

Definition at line 133 of file inditimer.cpp.

◆ isActive()

bool INDI::Timer::isActive ( ) const

Returns true if the timer is running (pending); otherwise returns false.

Definition at line 115 of file inditimer.cpp.

◆ isSingleShot()

bool INDI::Timer::isSingleShot ( ) const

Returns whether the timer is a single-shot timer.

Definition at line 121 of file inditimer.cpp.

◆ remainingTime()

int INDI::Timer::remainingTime ( ) const

Returns the timer's remaining value in milliseconds left until the timeout. If the timer not exists, the returned value will be -1.

Definition at line 127 of file inditimer.cpp.

◆ setInterval()

void INDI::Timer::setInterval ( int  msec)

Set the timeout interval in milliseconds.

Definition at line 103 of file inditimer.cpp.

◆ setSingleShot()

void INDI::Timer::setSingleShot ( bool  singleShot)

Set whether the timer is a single-shot timer.

Definition at line 109 of file inditimer.cpp.

◆ singleShot()

void INDI::Timer::singleShot ( int  msec,
const std::function< void()> &  callback 
)
static

This static function calls a the given function after a given time interval.

Examples
dome.cpp.

Definition at line 146 of file inditimer.cpp.

◆ start() [1/2]

void INDI::Timer::start ( )

Starts or restarts the timer with the timeout specified in interval.

Definition at line 82 of file inditimer.cpp.

◆ start() [2/2]

void INDI::Timer::start ( int  msec)

Starts or restarts the timer with a timeout interval of msec milliseconds.

Definition at line 89 of file inditimer.cpp.

◆ stop()

void INDI::Timer::stop ( )

Stops the timer.

Definition at line 97 of file inditimer.cpp.

◆ timeout()

void INDI::Timer::timeout ( )
virtual

This function is called when the timer times out.

Definition at line 139 of file inditimer.cpp.

Member Data Documentation

◆ d_ptr

std::unique_ptr<TimerPrivate> INDI::Timer::d_ptr
protected

Definition at line 92 of file inditimer.h.


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