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=nullptr)
 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.
 
virtual ~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
 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 (int fd) override
 method called when data are ready to be read on handle.
 
int handle () const noexcept
 get native handle.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onClose (int fd)
 method called when handle is closed.
 
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.
 

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 ( Reactor * reactor = nullptr)
inline

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 >
virtual join::BasicTimer< ClockPolicy >::~BasicTimer ( )
inlinevirtualnoexcept

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.

◆ handle()

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

get native handle.

Returns
native handle.

◆ 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 ( int fd)
inlineoverrideprotectedvirtual

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

Parameters
fdfile descriptor.

Reimplemented from join::EventHandler.

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