PLCnext API Documentation  22.9.0.33
Timer.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/event.hxx"
9 #include "Arp/System/Commons/Logging.h"
10 
11 // forwards
12 namespace Arp { namespace System { namespace Ve
13 {
14 class ITimerService;
15 }}}
16 
17 namespace Arp { namespace System { namespace Commons { namespace Chrono
18 {
19 
20 using namespace Arp::System::Ve;
21 
53 class Timer : private Loggable<Timer>
54 {
55 public: // typedefs
56 
59 
60 public: // construction/destruction
61 
71  Timer(size_t interval, const String& name, size_t priority, size_t cpuAffinity = 0);
72 
74  ~Timer(void);
75 
76 public: // events
77 
80 
81 public: // 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 
134 public: // operations
135 
139  void Start(void);
140 
142  void Stop(void);
143 
144 private: // static service callback
145  static void TimerServiceCallback(void* pThis);
146 
147 private: // deleted methods
148  Timer(const Timer& arg) = delete;
149  Timer& operator=(const Timer& arg) = delete;
150 
151 private: // fields
152  ITimerService* pTimerService;
153  bool isRunning = false;
154 };
155 
157 // inline methods of class Timer
158 
159 inline 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.
const String & GetName(void) const
Returns the current name 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
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