PLCnext API Documentation 23.6.0.37
RtEvent.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Commons/Logging.h"
9#include "Arp/Plc/Commons/Esm/RtEventManagerSharedData.hpp"
10#include "boost/interprocess/sync/interprocess_semaphore.hpp"
11#include <atomic>
12
13namespace Arp { namespace Plc { namespace Commons { namespace Esm
14{
15
21class RtEvent : private Loggable<RtEvent>
22{
23public: // typedefs
26
27public: // construction/destruction
29 RtEvent(const String& nameArg);
31 RtEvent(const RtEvent& arg) = delete;
33 RtEvent& operator=(const RtEvent& arg) = delete;
35 ~RtEvent(void) = default;
36
37protected:
39 RtEvent(const String& nameArg, uint32 value);
40
41public: // operators
46 void Set(void);
51 bool SetAndWaitOne(unsigned long timeout = 0);
54 bool IsSubscriberReady(void);
55
61 bool WaitOne(unsigned long timeout = 0, bool setSubscriberReady = true);
63 void Done(void);
66 void SetSubscriberReady(bool isSubscriberReadyArg);
67
68private: // fields
69 String name;
70 boost::interprocess::interprocess_semaphore semaphore1;
71 boost::interprocess::interprocess_semaphore semaphore2;
72 std::atomic<bool> isSubscriberReady;
73};
74
76// inline methods of class RtEvent
77
79{
80 return this->name;
81}
82
83inline void RtEvent::SetSubscriberReady(bool isSubscriberReadyArg)
84{
85 this->isSubscriberReady = isSubscriberReadyArg;
86}
87
89{
90 return this->isSubscriberReady;
91}
92
93}}}} // 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:22
bool WaitOne(unsigned long timeout=0, bool setSubscriberReady=true)
Waits blocking on the signal of the sender.
String GetName()
Returns the identifier of the rt event.
Definition: RtEvent.hpp:78
RtEvent & operator=(const RtEvent &arg)=delete
Assignment operator.
RtEvent(const RtEvent &arg)=delete
Copy constructor.
RtEvent(const String &nameArg)
Constructs an RtEvent instance.
bool IsSubscriberReady(void)
Returns state of the subscriber to processing incoming signaled events.
Definition: RtEvent.hpp:88
RtEvent(const String &nameArg, uint32 value)
Constructs an RtEvent instance. - For internal use only!
bool SetAndWaitOne(unsigned long timeout=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:25
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:83
boost::interprocess::offset_ptr< T > Ptr
Returned pointer types are shared memory based offset pointer.
Definition: SharedMemory.hpp:25
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:36
Root namespace for the PLCnext API