PLCnext API Documentation 25.0.2.69
Timer.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Core/event.hxx"
9#include "Arp/System/Core/TypeName.hxx"
10#include "Arp/System/Commons/Logging.h"
11
12// forwards
13namespace Arp { namespace System { namespace Ve
14{
15class ITimerService;
16}}}
17
18namespace Arp { namespace System { namespace Commons { namespace Chrono
19{
20
21using namespace Arp::System::Ve;
22
54class Timer : private Loggable<Timer>
55{
56public: // typedefs
57
60
61public: // construction/destruction
62 Timer(size_t interval, const String& name, size_t priority, size_t cpuAffinity = 0);
63 ~Timer(void);
64
65public: // events
66
69
70public: // properties
71 bool IsRunning(void)const;
72 void SetInterval(size_t interval);
73 size_t GetInterval(void) const;
74 void SetCpuAffinity(size_t affinity);
75 size_t GetCpuAffinity(void) const;
76 void SetName(const String& value);
77 const String& GetName(void)const;
78 void SetPriority(size_t value);
79 size_t GetPriority(void)const;
80
81public: // operations
82 void Start(void);
83 void Stop(void);
84
85private: // static service callback
86 static void TimerServiceCallback(void* pThis);
87
88private: // deleted methods
89 Timer(const Timer& arg) = delete;
90 Timer& operator=(const Timer& arg) = delete;
91
92private: // fields
93 ITimerService* pTimerService;
94 bool isRunning = false;
95};
96
97}}}} // end of namespace Arp::System::Commons::Chrono
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Use this class to register and invoke several delegates (function pointer in OOP design).
Definition: event.hxx:32
High resolution timer for interval based executions.
Definition: Timer.hpp:55
size_t GetInterval(void) const
Returns the interval value in microseconds.
Definition: Timer.cpp:82
void SetPriority(size_t value)
Sets a new scheduling priority for the timer.
Definition: Timer.cpp:126
size_t GetCpuAffinity(void) const
Returns the current used CPU affinity mask.
Definition: Timer.cpp:102
void SetInterval(size_t interval)
Changes the interval in which the assigned methods are called.
Definition: Timer.cpp:74
void Start(void)
Starts the execution of the timer.
Definition: Timer.cpp:142
void Stop(void)
Stops the execution of the timer.
Definition: Timer.cpp:149
void SetCpuAffinity(size_t affinity)
Pins the timer to a specific CPUs inside a multiprocessor system.
Definition: Timer.cpp:92
NotifyEvent Notify
List of class methods and classes that are called periodically whenever the predefined interval is ex...
Definition: Timer.hpp:68
Timer(size_t interval, const String &name, size_t priority, size_t cpuAffinity=0)
Constructs an Timer instance.
Definition: Timer.cpp:23
~Timer(void)
Destructs this instance and frees all resources.
Definition: Timer.cpp:34
event< void > NotifyEvent
Definition of list of delegates to be called when timer expires.
Definition: Timer.hpp:59
const String & GetName(void) const
Returns the current name of the timer.
Definition: Timer.cpp:118
size_t GetPriority(void) const
Returns the current scheduling priority of the timer.
Definition: Timer.cpp:134
bool IsRunning(void) const
Checks if the timer is running, i.e. Start was already invoked.
Definition: Timer.cpp:158
void SetName(const String &value)
Sets a new name for the timer.
Definition: Timer.cpp:110
Derive from this class to inherit logging functionality.
Definition: Loggable.hxx:28
Root namespace for the PLCnext API