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 (Reactor &reactor=ReactorThread::reactor())
 create instance.
 
 BasicTimer (const BasicTimer &other)=delete
 copy constructor.
 
BasicTimeroperator= (const BasicTimer &other)=delete
 copy assignment operator.
 
 BasicTimer (BasicTimer &&other)=delete
 move constructor.
 
BasicTimeroperator= (BasicTimer &&other)=delete
 move assignment operator.
 
 ~BasicTimer () noexcept
 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 () noexcept
 cancel the timer.
 
bool active () const noexcept
 check if timer is running.
 
std::chrono::nanoseconds remaining () const noexcept
 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.
 

Static Public Member Functions

static constexpr int type () noexcept
 get the timer type.
 

Additional Inherited Members

- Protected Member Functions inherited from join::EventHandler
virtual void onWriteable (int fd)
 method called when data are ready to be written on handle.
 
virtual void onClose (int fd)
 method called when handle was closed by the peer.
 
virtual void onError (int fd)
 method called when an error occurred on handle.
 
 EventHandler ()=default
 create instance.
 
 EventHandler (const EventHandler &other)=default
 copy constructor.
 
EventHandleroperator= (const EventHandler &other)=default
 copy assignment operator.
 
 EventHandler (EventHandler &&other)=default
 move constructor.
 
EventHandleroperator= (EventHandler &&other)=default
 move assignment operator.
 
virtual ~EventHandler ()=default
 destroy instance.
 

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 ( Reactor & reactor = ReactorThread::reactor ())
inlineexplicit

create instance.

Parameters
reactorevent loop reactor.

◆ 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)
delete

move constructor.

Parameters
otherother object to move.

◆ ~BasicTimer()

template<class ClockPolicy >
join::BasicTimer< ClockPolicy >::~BasicTimer ( )
inlinenoexcept

destroy instance.

Member Function Documentation

◆ active()

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

check if timer is running.

Returns
true if timer is active.

◆ cancel()

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

cancel the timer.

◆ 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.

◆ operator=() [1/2]

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

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
inlinenoexcept

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.

◆ type()

template<class ClockPolicy >
static constexpr int join::BasicTimer< ClockPolicy >::type ( )
inlinestaticconstexprnoexcept

get the timer type.

Returns
the timer type.

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