RADLib
RADical C++ application framework
RADCore::Timer Class Reference

High-precision timer that emits timeout through a RADCore EventLoop. More...

#include <RADCore.h>

+ Inheritance diagram for RADCore::Timer:
+ Collaboration diagram for RADCore::Timer:

Public Member Functions

 Timer ()
 Creates an inactive timer. More...
 
 ~Timer ()
 Stops the timer if active. More...
 
void start (int intervalMs, EventLoop &targetLoop)
 Starts the timer with intervalMs and posts timeout to targetLoop. More...
 
void start (EventLoop &targetLoop)
 Starts the timer using the previously configured interval. More...
 
void stop ()
 Stops the timer. More...
 
void setInterval (int intervalMs)
 Sets timer interval in milliseconds. More...
 
int interval () const
 Returns timer interval in milliseconds. More...
 
bool isActive () const
 Returns true while the timer is active. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Static Public Member Functions

static void singleShot (int intervalMs, EventLoop &targetLoop, EventLoop::Task task)
 Posts task once after intervalMs milliseconds. More...
 

Public Attributes

RADCore::Event< void() > timeout
 Raised each time the timer interval expires. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when the timer cannot be configured or started. More...
 

Detailed Description

High-precision timer that emits timeout through a RADCore EventLoop.

Constructor & Destructor Documentation

◆ Timer()

RADCore::Timer::Timer ( )

Creates an inactive timer.

◆ ~Timer()

RADCore::Timer::~Timer ( )

Stops the timer if active.

Member Function Documentation

◆ interval()

int RADCore::Timer::interval ( ) const

Returns timer interval in milliseconds.

◆ isActive()

bool RADCore::Timer::isActive ( ) const

Returns true while the timer is active.

◆ setInterval()

void RADCore::Timer::setInterval ( int  intervalMs)

Sets timer interval in milliseconds.

◆ singleShot()

static void RADCore::Timer::singleShot ( int  intervalMs,
EventLoop targetLoop,
EventLoop::Task  task 
)
static

Posts task once after intervalMs milliseconds.

◆ start() [1/2]

void RADCore::Timer::start ( EventLoop targetLoop)

Starts the timer using the previously configured interval.

◆ start() [2/2]

void RADCore::Timer::start ( int  intervalMs,
EventLoop targetLoop 
)

Starts the timer with intervalMs and posts timeout to targetLoop.

◆ stop()

void RADCore::Timer::stop ( )

Stops the timer.

Member Data Documentation

◆ errorOccurred

RADCore::Event<void (std::string) > RADCore::Timer::errorOccurred

Raised when the timer cannot be configured or started.

◆ timeout

RADCore::Event<void () > RADCore::Timer::timeout

Raised each time the timer interval expires.


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