PLCnext API Documentation  22.9.0.33
RtEvent.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Logging.h"
9 #include "Arp/Plc/Commons/Esm/RtEventManagerSharedData.hpp"
10 #include "boost/interprocess/sync/interprocess_semaphore.hpp"
11 
12 namespace Arp { namespace Plc { namespace Commons { namespace Esm
13 {
14 
20 class RtEvent : private Loggable<RtEvent>
21 {
22 public: // typedefs
25 
26 public: // construction/destruction
28  RtEvent(const String& nameArg);
30  RtEvent(const RtEvent& arg) = delete;
32  RtEvent& operator=(const RtEvent& arg) = delete;
34  ~RtEvent(void) = default;
35 
36 protected:
38  RtEvent(const String& nameArg, uint32 value);
39 
40 public: // operators
43  String GetName();
45  void Set(void);
49  bool SetAndWaitOne(unsigned long timeoutArg = 0);
52  bool IsSubscriberReady(void);
53 
58  bool WaitOne(unsigned long timeoutArg = 0, bool setSubscriberReadyArg = true);
60  void Done(void);
63  void SetSubscriberReady(bool isSubscriberReadyArg);
64 
65 
66 private: // static fields
67  String name;
68  boost::interprocess::interprocess_semaphore semaphore1;
69  boost::interprocess::interprocess_semaphore semaphore2;
70  std::atomic<bool> isSubscriberReady;
71 };
72 
74 // inline methods of class RtEvent
75 
77 {
78  return this->name;
79 }
80 
81 inline void RtEvent::SetSubscriberReady(bool isSubscriberReadyArg)
82 {
83  this->isSubscriberReady = isSubscriberReadyArg;
84 }
85 
86 inline bool RtEvent::IsSubscriberReady(void)
87 {
88  return this->isSubscriberReady;
89 }
90 
91 }}}} // end of namespace Arp::Plc::Commons::Esm
Rt event for bidirectional exchange of events in the ESM context. E.g. this is used to trigger a task...
Definition: RtEvent.hpp:21
bool WaitOne(unsigned long timeoutArg=0, bool setSubscriberReadyArg=true)
Waits blocking on the signal of the sender.
String GetName()
Returns the identifier of the rt event.
Definition: RtEvent.hpp:76
RtEvent(const RtEvent &arg)=delete
Copy constructor.
RtEvent(const String &nameArg)
Constructs an RtEvent instance.
RtEvent & operator=(const RtEvent &arg)=delete
Assignment operator.
bool IsSubscriberReady(void)
Returns state of the subscriber to processing incoming signaled events.
Definition: RtEvent.hpp:86
RtEvent(const String &nameArg, uint32 value)
Constructs an RtEvent instance. - For internal use only!
bool SetAndWaitOne(unsigned long timeoutArg=0)
Signals the event to the subscriber and waits blocking on the done by the subscriber.
void Set(void)
Signals the event to the subscriber.
RtEventManagerSharedData::Ptr< RtEvent > Ptr
Shared pointer type of RtEvent.
Definition: RtEvent.hpp:24
void Done(void)
Signals that the event was processed by the subscriber to the sender.
~RtEvent(void)=default
Destructs this instance and frees all resources.
void SetSubscriberReady(bool isSubscriberReadyArg)
Sets the state of the subscriber to processing incoming signaled events.
Definition: RtEvent.hpp:81
boost::interprocess::offset_ptr< T > Ptr
Returned pointer types are shared memory based offset pointer.
Definition: SharedMemory.hpp:26
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
Root namespace for the PLCnext API