|
commonlib
|
Provides a mechanism for executing a method on a thread pool thread at specified intervals. More...
#include <timerthread.h>
Public Types | |
| using | CallbackFunction = std::function< void(void)> |
Public Member Functions | |
| TimerThread (int intervalMs=1000, CallbackFunction callback=nullptr, int delayMs=-1, TimerMode timerMode=TimerMode::FixedDelay) | |
| Initializes a new instance of the TimerThread class with default 1000 milliseconds period. More... | |
| TimerThread (std::chrono::microseconds interval, CallbackFunction callback=nullptr, std::optional< std::chrono::microseconds > delay=std::nullopt, TimerMode timerMode=TimerMode::FixedDelay) | |
| Initializes a new instance of the TimerThread class. More... | |
| void | start () override |
| Starts thread. | |
| void | stop () override |
| Stops thread. | |
| int | getIntervalMs () const |
| Get the amount of time in milliseconds. More... | |
| int | getIntervalMcs () const |
| Get the amount of time in microseconds. More... | |
| void | setIntervalMs (const int value) |
| Set the amount of time in milliseconds. More... | |
| void | setIntervalMcs (const int value) |
| Set the amount of time in microseconds. More... | |
| int | getDelayMs () const |
| Get start delay (amount of time until first execution). More... | |
| int | getDelayMcs () const |
| Get start delay (amount of time until first execution). More... | |
| void | setDelayMs (const int value) |
| Set start delay (the amount of time until first execution). More... | |
| void | setDelayMcs (const int value) |
| Set start delay (the amount of time until first execution). More... | |
| void | setTimerMode (TimerMode timerMode) |
| Set timer mode. More... | |
| TimerMode | getTimerMode () const |
| Get timer mode. More... | |
| CallbackFunction & | getCallback () |
| Get callback function. More... | |
| void | setCallback (const CallbackFunction &value) |
| Set callback function. More... | |
| int64_t | getNoOfCallbacks () const |
| Function returns how many times Execute function was called. More... | |
Public Member Functions inherited from ThreadEx | |
| void | terminate () |
| Terminate sets the thread's Terminated property to true, signaling that the thread should be terminated as soon as possible. | |
| void | waitFor () |
| Waits for the thread to terminate. | |
| const ThreadExPriority & | getPriority () const |
| Get thread's scheduling priority relative to other threads in the process. More... | |
| void | setPriority (ThreadExPriority priority) |
| Set thread's scheduling priority relative to other threads in the process. More... | |
| std::recursive_mutex & | getLock () |
| Get thread's locking object. More... | |
| const std::atomic< bool > & | getTerminated () const |
| Returns thread's terminated signal. More... | |
| const std::atomic< bool > & | getFinished () const |
| Returns true if thread has already been finished. More... | |
| bool | getStarted () const |
| Returns true if thread is started. More... | |
| ThreadExceptionAdapter * | getExceptionAdapter () |
| Returns exception information holder. More... | |
| void | setExceptionAdapter (ThreadExceptionAdapter *exceptionAdapter) |
| Sets exception information holder. More... | |
| const std::thread::id | getThreadId () const |
| Returns thread id. | |
Protected Member Functions | |
| void | execute () override |
| Provides an abstract or pure virtual method to contain the code which executes when the thread is run. | |
| virtual void | executeTimerCallback () |
Protected Member Functions inherited from ThreadEx | |
| void | setThreadName (const char *name) |
| Set current thread name (you must call it from the thread) | |
Additional Inherited Members | |
Protected Attributes inherited from ThreadEx | |
| std::recursive_mutex | lock |
| std::atomic< bool > | terminated |
| std::atomic< bool > | finished |
| ThreadExceptionAdapter * | exceptionAdapter {} |
Provides a mechanism for executing a method on a thread pool thread at specified intervals.
| TimerThread::TimerThread | ( | int | intervalMs = 1000, |
| CallbackFunction | callback = nullptr, |
||
| int | delayMs = -1, |
||
| TimerMode | timerMode = TimerMode::FixedDelay |
||
| ) |
Initializes a new instance of the TimerThread class with default 1000 milliseconds period.
| intervalMs | a interval in milliseconds. |
| callback | a callback function you want the TimerThread to execute. |
| delayMs | start delay (amount of time before first execution) in milliseconds. If negative, then the interval time is used for start delay. |
| timerMode | a timer mode. |
| TimerThread::TimerThread | ( | std::chrono::microseconds | interval, |
| CallbackFunction | callback = nullptr, |
||
| std::optional< std::chrono::microseconds > | delay = std::nullopt, |
||
| TimerMode | timerMode = TimerMode::FixedDelay |
||
| ) |
Initializes a new instance of the TimerThread class.
| interval | a interval in microseconds. |
| callback | a callback function you want the TimerThread to execute. |
| delay | start delay (amount of time before first execution) in microseconds. If empty, then the interval time is used for start delay. |
| timerMode | a timer mode. |
| CallbackFunction& TimerThread::getCallback | ( | ) |
Get callback function.
| int TimerThread::getDelayMcs | ( | ) | const |
Get start delay (amount of time until first execution).
| int TimerThread::getDelayMs | ( | ) | const |
Get start delay (amount of time until first execution).
| int TimerThread::getIntervalMcs | ( | ) | const |
Get the amount of time in microseconds.
| int TimerThread::getIntervalMs | ( | ) | const |
Get the amount of time in milliseconds.
| int64_t TimerThread::getNoOfCallbacks | ( | ) | const |
Function returns how many times Execute function was called.
| TimerMode TimerThread::getTimerMode | ( | ) | const |
| void TimerThread::setCallback | ( | const CallbackFunction & | value | ) |
Set callback function.
| value | A function that will be called every interval. |
| void TimerThread::setDelayMcs | ( | const int | value | ) |
Set start delay (the amount of time until first execution).
| value | a interval in microseconds. |
| void TimerThread::setDelayMs | ( | const int | value | ) |
Set start delay (the amount of time until first execution).
| value | a interval in milliseconds. |
| void TimerThread::setIntervalMcs | ( | const int | value | ) |
Set the amount of time in microseconds.
| value | a interval in microseconds. |
| void TimerThread::setIntervalMs | ( | const int | value | ) |
Set the amount of time in milliseconds.
| value | a interval in milliseconds. |
| void TimerThread::setTimerMode | ( | TimerMode | timerMode | ) |
Set timer mode.
| timerMode | timer mode |