join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicTimer< ClockPolicy > Class Template Reference

base timer class. More...

#include <timer.hpp>

Inheritance diagram for join::BasicTimer< ClockPolicy >:
Collaboration diagram for join::BasicTimer< ClockPolicy >:

Public Member Functions

 BasicTimer ()
 create instance.
 
 BasicTimer (const BasicTimer &other)=delete
 copy constructor.
 
BasicTimeroperator= (const BasicTimer &other)=delete
 copy assignment operator.
 
 BasicTimer (BasicTimer &&other) noexcept
 move constructor.
 
BasicTimeroperator= (BasicTimer &&other) noexcept
 move assignment operator.
 
virtual ~BasicTimer ()
 destroy instance.
 
template<class Rep , class Period , typename Func >
void setOneShot (std::chrono::duration< Rep, Period > duration, Func &&callback)
 arm the timer as a one-shot timer.
 
template<class Clock , class Duration , typename Func >
void setOneShot (std::chrono::time_point< Clock, Duration > timePoint, Func &&callback)
 arm the timer as a one-shot timer with absolute time.
 
template<class Rep , class Period , typename Func >
void setInterval (std::chrono::duration< Rep, Period > duration, Func &&callback)
 arm the timer as a periodic timer.
 
void cancel ()
 cancel the timer.
 
bool active () const
 check if timer is running.
 
std::chrono::nanoseconds remaining () const
 get the remaining time until expiration.
 
std::chrono::nanoseconds interval () const noexcept
 get the interval of the running periodic timer.
 
bool oneShot () const noexcept
 check if timer is a one-shot timer.
 
int type () const noexcept
 get the timer type.
 

Protected Member Functions

virtual void onReceive () override
 method called when data are ready to be read on handle.
 
virtual int handle () const noexcept override
 get native handle.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onClose ()
 method called when handle is closed.
 
virtual void onError ()
 method called when an error occured on handle.
 
 EventHandler ()=default
 create instance.
 
virtual ~EventHandler ()=default
 destroy instance.
 

Static Protected Member Functions

static itimerspec toTimerSpec (std::chrono::nanoseconds ns, bool periodic=false) noexcept
 convert nsec to itimerspec.
 

Detailed Description

template<class ClockPolicy>
class join::BasicTimer< ClockPolicy >

base timer class.

Constructor & Destructor Documentation

◆ BasicTimer() [1/3]

template<class ClockPolicy >
join::BasicTimer< ClockPolicy >::BasicTimer ( )
inline

create instance.

◆ BasicTimer() [2/3]

template<class ClockPolicy >
join::BasicTimer< ClockPolicy >::BasicTimer ( const BasicTimer< ClockPolicy > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicTimer() [3/3]

template<class ClockPolicy >
join::BasicTimer< ClockPolicy >::BasicTimer ( BasicTimer< ClockPolicy > && other)
inlinenoexcept

move constructor.

Parameters
otherother object to move.

◆ ~BasicTimer()

template<class ClockPolicy >
virtual join::BasicTimer< ClockPolicy >::~BasicTimer ( )
inlinevirtual

destroy instance.

Member Function Documentation

◆ active()

template<class ClockPolicy >
bool join::BasicTimer< ClockPolicy >::active ( ) const
inline

check if timer is running.

Returns
true if timer is active.

◆ cancel()

template<class ClockPolicy >
void join::BasicTimer< ClockPolicy >::cancel ( )
inline

cancel the timer.

◆ handle()

template<class ClockPolicy >
virtual int join::BasicTimer< ClockPolicy >::handle ( ) const
inlineoverrideprotectedvirtualnoexcept

get native handle.

Returns
native handle.

Implements join::EventHandler.

◆ interval()

template<class ClockPolicy >
std::chrono::nanoseconds join::BasicTimer< ClockPolicy >::interval ( ) const
inlinenoexcept

get the interval of the running periodic timer.

Returns
interval duration in nanoseconds, zero if one-shot or inactive.

◆ oneShot()

template<class ClockPolicy >
bool join::BasicTimer< ClockPolicy >::oneShot ( ) const
inlinenoexcept

check if timer is a one-shot timer.

Returns
true if timer is a one-shot timer.

◆ onReceive()

template<class ClockPolicy >
virtual void join::BasicTimer< ClockPolicy >::onReceive ( )
inlineoverrideprotectedvirtual

method called when data are ready to be read on handle.

Reimplemented from join::EventHandler.

◆ operator=() [1/2]

template<class ClockPolicy >
BasicTimer & join::BasicTimer< ClockPolicy >::operator= ( BasicTimer< ClockPolicy > && other)
inlinenoexcept

move assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ operator=() [2/2]

template<class ClockPolicy >
BasicTimer & join::BasicTimer< ClockPolicy >::operator= ( const BasicTimer< ClockPolicy > & other)
delete

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ remaining()

template<class ClockPolicy >
std::chrono::nanoseconds join::BasicTimer< ClockPolicy >::remaining ( ) const
inline

get the remaining time until expiration.

Returns
remaining duration.

◆ setInterval()

template<class ClockPolicy >
template<class Rep , class Period , typename Func >
void join::BasicTimer< ClockPolicy >::setInterval ( std::chrono::duration< Rep, Period > duration,
Func && callback )
inline

arm the timer as a periodic timer.

Parameters
durationinterval duration between timer expirations.
callbackfunction to call on each timer expiration.

◆ setOneShot() [1/2]

template<class ClockPolicy >
template<class Rep , class Period , typename Func >
void join::BasicTimer< ClockPolicy >::setOneShot ( std::chrono::duration< Rep, Period > duration,
Func && callback )
inline

arm the timer as a one-shot timer.

Parameters
durationtimeout duration before timer expires.
callbackfunction to call when timer expires.

◆ setOneShot() [2/2]

template<class ClockPolicy >
template<class Clock , class Duration , typename Func >
void join::BasicTimer< ClockPolicy >::setOneShot ( std::chrono::time_point< Clock, Duration > timePoint,
Func && callback )
inline

arm the timer as a one-shot timer with absolute time.

Parameters
timePointabsolute time when timer should expire.
callbackfunction to call when timer expires.

◆ toTimerSpec()

template<class ClockPolicy >
static itimerspec join::BasicTimer< ClockPolicy >::toTimerSpec ( std::chrono::nanoseconds ns,
bool periodic = false )
inlinestaticprotectednoexcept

convert nsec to itimerspec.

Parameters
nsvalue to convert.
periodicspecify if periodic.
Returns
itimerspec.

◆ type()

template<class ClockPolicy >
int join::BasicTimer< ClockPolicy >::type ( ) const
inlinenoexcept

get the timer type.

Returns
the timer type.

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