PLCnext API Documentation 25.0.2.69
|
High resolution timer for interval based executions. More...
#include <Timer.hpp>
Public Types | |
typedef event< void > | NotifyEvent |
Definition of list of delegates to be called when timer expires. | |
Public Member Functions | |
Timer (size_t interval, const String &name, size_t priority, size_t cpuAffinity=0) | |
Constructs an Timer instance. More... | |
~Timer (void) | |
Destructs this instance and frees all resources. | |
bool | IsRunning (void) const |
Checks if the timer is running, i.e. Start was already invoked. More... | |
void | SetInterval (size_t interval) |
Changes the interval in which the assigned methods are called. More... | |
size_t | GetInterval (void) const |
Returns the interval value in microseconds. More... | |
void | SetCpuAffinity (size_t affinity) |
Pins the timer to a specific CPUs inside a multiprocessor system. More... | |
size_t | GetCpuAffinity (void) const |
Returns the current used CPU affinity mask. More... | |
void | SetName (const String &value) |
Sets a new name for the timer. More... | |
const String & | GetName (void) const |
Returns the current name of the timer. More... | |
void | SetPriority (size_t value) |
Sets a new scheduling priority for the timer. More... | |
size_t | GetPriority (void) const |
Returns the current scheduling priority of the timer. More... | |
void | Start (void) |
Starts the execution of the timer. More... | |
void | Stop (void) |
Stops the execution of the timer. | |
Public Attributes | |
NotifyEvent | Notify |
List of class methods and classes that are called periodically whenever the predefined interval is expired. | |
High resolution timer for interval based executions.
Instances of this class can be used to execute class methods periodically in a defined time intervall. The timer class itself takes care of computing the next timepoint where method has to be invoked. The developer only has to implement the class method that should be invoked whenever a specific interval expires.
A simple example that implements a counter that is incremented every 100 us is implemented by the following code
It is also possible to ad more than one method to the notification list of the timer instance.
The methods will be called in the order they are assigned to the timers notification list.
Arp::System::Commons::Chrono::Timer::Timer | ( | size_t | interval, |
const String & | name, | ||
size_t | priority, | ||
size_t | cpuAffinity = 0 |
||
) |
Constructs an Timer instance.
interval | The timer interval in microseconds.
|
Arp::System::Commons::InvalidOperationException | if the timer could not be created. |
size_t Arp::System::Commons::Chrono::Timer::GetCpuAffinity | ( | void | ) | const |
Returns the current used CPU affinity mask.
For more information on CPU affinity masks see Arp::System::Commons::Threading::Timer::SetCpuAffinity.
size_t Arp::System::Commons::Chrono::Timer::GetInterval | ( | void | ) | const |
Returns the interval value in microseconds.
const String & Arp::System::Commons::Chrono::Timer::GetName | ( | void | ) | const |
Returns the current name of the timer.
size_t Arp::System::Commons::Chrono::Timer::GetPriority | ( | void | ) | const |
Returns the current scheduling priority of the timer.
bool Arp::System::Commons::Chrono::Timer::IsRunning | ( | void | ) | const |
Checks if the timer is running, i.e. Start was already invoked.
void Arp::System::Commons::Chrono::Timer::SetCpuAffinity | ( | size_t | affinity | ) |
Pins the timer to a specific CPUs inside a multiprocessor system.
For more information on CPU affinity masks see Arp::System::Commons::Threading::Timer::SetCpuAffinity.
mask | A mask determine which the CPU is allowed to execute the thread. |
void Arp::System::Commons::Chrono::Timer::SetInterval | ( | size_t | interval | ) |
Changes the interval in which the assigned methods are called.
This has no effect if the timer is already started.
interval | New interval value in microseconds. |
void Arp::System::Commons::Chrono::Timer::SetName | ( | const String & | value | ) |
Sets a new name for the timer.
value | New name for timer. |
void Arp::System::Commons::Chrono::Timer::SetPriority | ( | size_t | value | ) |
Sets a new scheduling priority for the timer.
value | New scheduling priority. |
void Arp::System::Commons::Chrono::Timer::Start | ( | void | ) |
Starts the execution of the timer.
Arp::Exception | in case of failure or timer was already started. |