PLCnext API Documentation  21.0.0.35466
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 
16 class RtEvent : private Loggable<RtEvent>
17 {
18 public: // typedefs
21 
22 public: // construction/destruction
24  RtEvent(const String& nameArg);
26  RtEvent(const RtEvent& arg) = delete;
28  RtEvent& operator=(const RtEvent& arg) = delete;
30  ~RtEvent(void) = default;
31 
32 public: // operators
35  String GetName();
37  void Set(void);
39  void Done(void);
43  bool WaitOne(unsigned long timeoutArg = 0, bool setSubscriberReadyArg = true);
48  bool SetAndWaitOne(unsigned long timeoutArg = 0);
51  void SetSubscriberReady(bool isSubscriberReadyArg = true);
54  bool IsSubscriberReady(void);
55 
56 public: // static operations
57 
58 public: // setter/getter operations
59 
60 public: // operations
61 
62 protected: // operations
63 
64 private: // static methods
65 
66 private: // methods
67 
68 private: // fields
69 
70 private: // static fields
71  String name;
72  boost::interprocess::interprocess_semaphore semaphore1;
73  boost::interprocess::interprocess_semaphore semaphore2;
74  std::atomic<bool> isSubscriberReady;
75 };
76 
78 // inline methods of class RtEvent
79 
81 {
82  return this->name;
83 }
84 
85 inline void RtEvent::SetSubscriberReady(bool isSubscriberReadyArg)
86 {
87  this->isSubscriberReady = isSubscriberReadyArg;
88 }
89 
90 inline bool RtEvent::IsSubscriberReady(void)
91 {
92  return this->isSubscriberReady;
93 }
94 
95 }}}} // end of namespace Arp::Plc::Commons::Esm
bool WaitOne(unsigned long timeoutArg=0, bool setSubscriberReadyArg=true)
Waits blocking on signal of the event.
RtEvent & operator=(const RtEvent &arg)=delete
Assignment operator.
void SetSubscriberReady(bool isSubscriberReadyArg=true)
Sets the state of the event subscriber.
Definition: RtEvent.hpp:85
bool IsSubscriberReady(void)
Returns state of the event subscriber.
Definition: RtEvent.hpp:90
void Set(void)
Signals the event.
boost::interprocess::offset_ptr< T > Ptr
Returned pointer types are shared memory based offset pointer.
Definition: SharedMemory.hpp:27
String GetName()
Returns name identifier of the event.
Definition: RtEvent.hpp:80
bool SetAndWaitOne(unsigned long timeoutArg=0)
Fires the event and waits blocking on that the event has been processed.
RtEventManagerSharedData::Ptr< RtEvent > Ptr
Shared pointer type of RtEvent.
Definition: RtEvent.hpp:20
Root namespace for the PLCnext API
void Done(void)
Signals that the event was processed.
~RtEvent(void)=default
Destructs this instance and frees all resources.
RtEvent(const String &nameArg)
Constructs an RtEvent instance.
This class implements a ipc event for the bidirectional exchange of realtime events.
Definition: RtEvent.hpp:16