PLCnext API Documentation 23.6.0.37
Timer.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/event.hxx"
9#include "Arp/System/Commons/Logging.h"
10
11// forwards
12namespace Arp { namespace System { namespace Ve
13{
14class ITimerService;
15}}}
16
17namespace Arp { namespace System { namespace Commons { namespace Chrono
18{
19
20using namespace Arp::System::Ve;
21
53class Timer : private Loggable<Timer>
54{
55public: // typedefs
56
59
60public: // construction/destruction
61
71 Timer(size_t interval, const String& name, size_t priority, size_t cpuAffinity = 0);
72
74 ~Timer(void);
75
76public: // events
77
80
81public: // properties
82
86 bool IsRunning(void)const;
87
93 void SetInterval(size_t interval);
94
98 size_t GetInterval(void) const;
99
105 void SetCpuAffinity(size_t affinity);
106
112 size_t GetCpuAffinity(void) const;
113
117 void SetName(const String& value);
118
122 const String& GetName(void)const;
123
127 void SetPriority(size_t value);
128
132 size_t GetPriority(void)const;
133
134public: // operations
135
139 void Start(void);
140
142 void Stop(void);
143
144private: // static service callback
145 static void TimerServiceCallback(void* pThis);
146
147private: // deleted methods
148 Timer(const Timer& arg) = delete;
149 Timer& operator=(const Timer& arg) = delete;
150
151private: // fields
152 ITimerService* pTimerService;
153 bool isRunning = false;
154};
155
157// inline methods of class Timer
158
159inline bool Timer::IsRunning(void)const
160{
161 return this->isRunning;
162}
163
164}}}} // end of namespace Arp::System::Commons::Chrono
High resolution timer for interval based executions.
Definition: Timer.hpp:54
size_t GetInterval(void) const
Returns the interval value in microseconds.
void SetPriority(size_t value)
Sets a new scheduling priority for the timer.
size_t GetCpuAffinity(void) const
Returns the current used CPU affinity mask.
void SetInterval(size_t interval)
Changes the interval in which the assigned methods are called.
void Start(void)
Starts the execution of the timer.
void Stop(void)
Stops the execution of the timer.
void SetCpuAffinity(size_t affinity)
Pins the timer to a specific CPUs inside a multiprocessor system.
NotifyEvent Notify
List of class methods and classes that are called periodically whenever the predefined interval is ex...
Definition: Timer.hpp:79
Timer(size_t interval, const String &name, size_t priority, size_t cpuAffinity=0)
Constructs an Timer instance.
~Timer(void)
Destructs this instance and frees all resources.
event< void > NotifyEvent
Definition of list of delegates to be called when timer expires.
Definition: Timer.hpp:58
const String & GetName(void) const
Returns the current name of the timer.
size_t GetPriority(void) const
Returns the current scheduling priority of the timer.
bool IsRunning(void) const
Checks if the timer is running, i.e. Start was already invoked.
Definition: Timer.hpp:159
void SetName(const String &value)
Sets a new name for the timer.
Use this class to register and invoke several delegates (function pointer in OOP design).
Definition: event.hxx:193
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API