PLCnext API Documentation  20.0.0.24462
NotificationManager.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 
7 #pragma once
8 
9 #include "Arp/System/Core/AppDomainSingleton.hxx"
10 #include "Arp/System/Commons/Logging.h"
11 
12 #include "Arp/System/Nm/INonBlockingNotificationSending.hpp"
13 #include "Arp/System/Nm/INotificationManagerInfo.hpp"
14 #include "Arp/System/Nm/INotificationReceiving.hpp"
15 #include "Arp/System/Nm/INotificationSending.hpp"
16 #include "Arp/System/Nm/NonBlockingNotificationRegistration.hpp"
17 #include "Arp/System/Nm/NonBlockingNotificationSendingAdapter.hpp"
18 #include "Arp/System/Nm/NotificationRegistration.hpp"
19 #include "Arp/System/Nm/NotificationSubscriber.hpp"
20 
21 
22 namespace Arp { namespace System { namespace Nm
23 {
24 
25 
44  : public AppDomainSingleton<NotificationManager>
45  , public INotificationSending
48  , public INotificationReceiving
49  , private Loggable<NotificationManager, true>
50 {
51  friend class AppDomainSingleton<NotificationManager>;
52 
53 private:
54  struct Impl;
55 
56 protected:
57  explicit NotificationManager(size_t nonBlockingNotificationSendingProxyQueueLength = 128);
58  virtual ~NotificationManager();
59 
60 public:
61  NotificationManager(const NotificationManager&) = delete;
62  NotificationManager(NotificationManager&&) = delete;
63 
64  NotificationManager& operator=(const NotificationManager&) = delete;
65  NotificationManager& operator=(NotificationManager&&) = delete;
66 
67 
68  // High level operations using proxy objects
76  template<typename PayloadType>
78  const String& notificationName, const String& senderName, Severity severity);
79 
87  template<typename PayloadType>
89  const String& notificationName, const String& senderName, Severity severity);
90 
91  template<typename PayloadType>
92  NonBlockingNotificationRegistration<PayloadType> CreateNonBlockingNotificationRegistration2(
93  const String& notificationName, const String& senderName, Severity severity);
94 
98 
99 
100  // Methods of INotificationSending
101  NotificationNameIdType RegisterNotification(const String& notificationName,
102  const String& senderName, Severity severity, PayloadTypeIdType payloadTypeId) override;
103  void UnregisterNotification(NotificationNameIdType notificationNameId) override;
104 
106  Arp::DateTime timestamp, const RawPayloadType& payload) override;
108  Arp::DateTime timestamp, const IPayload& payload) override;
109 
110 
111  // Methods of INonBlockingNotificationSending
113  const String& senderName, Severity severity, PayloadTypeIdType payloadTypeId) override;
114 
115  void NonBlockingRegisterNotification(const String& notificationName, const String& senderName,
116  Severity severity, PayloadTypeIdType payloadTypeId, Future<NotificationNameIdType> result);
117 
119  NotificationNameIdType notificationNameId) override;
120 
122  NotificationNameIdType notificationNameId, Future<void> result);
123 
125  NotificationNameIdType notificationNameId, Arp::DateTime timestamp,
126  const RawPayloadType& payload) override;
127 
128  void NonBlockingSendNotification(NotificationNameIdType notificationNameId,
129  Arp::DateTime timestamp, std::function<RawPayloadType()> createPayloadFunctor,
131 
133  NotificationNameIdType notificationNameId, Arp::DateTime timestamp,
134  const IPayload& payload) override;
135 
136 
137  // Methods of INotificationManagerInfo
138  const String GetNotificationName(NotificationNameIdType notificationNameId) const override;
139  const NotificationNameIdType GetNotificationNameId(const String& notificationName) override;
140 
142  const NotificationRegistrationStatus& status) const override;
145  NotificationNameIdType notificationNameId) const override;
146 
147  const PayloadTypeIdType GetPayloadTypeId(const String& payloadTypeName) override;
148  const String GetPayloadTypeName(const PayloadTypeIdType& payloadTypeId) const override;
149 
151 
152 
153  // Methods of INotificationReceiving
155  const String& notificationName, INotificationSubscriber* subscriber) override;
156  void Unsubscribe(
157  NotificationNameIdType notificationNameId, INotificationSubscriber* subscriber) override;
158  void UnsubscribeFromAll(INotificationSubscriber* subscriber) override;
159 
160  void ReplaceSubscriber(
161  INotificationSubscriber* oldSubscriber, INotificationSubscriber* newSubscriber);
162 
163 
164 private:
165  const std::unique_ptr<Impl> pImpl;
166 };
167 
168 
169 template<typename PayloadType>
171  const String& notificationName, const String& senderName, Severity severity)
172 {
173  return NotificationRegistration<PayloadType>(notificationName, senderName, severity, *(this));
174 }
175 
176 
177 template<typename PayloadType>
180  const String& notificationName, const String& senderName, Severity severity)
181 {
183  notificationName, senderName, severity, *this);
184 }
185 
186 
187 template<typename PayloadType>
189 NotificationManager::CreateNonBlockingNotificationRegistration2(
190  const String& notificationName, const String& senderName, Severity severity)
191 {
193  notificationName, senderName, severity, new NonBlockingNotificationSendingAdapter(*this));
194 }
195 
196 
197 }}} // end of namespace Arp::System::Nm
Interface for non blocking sending of Notifications
Definition: INonBlockingNotificationSending.hpp:21
const PayloadTypeIdType GetPayloadTypeId(const String &payloadTypeName) override
Query an id for a given PayloadType
Interface for subscribers of Notifications
Definition: INotificationReceiving.hpp:19
Future< NotificationIdType > NonBlockingSendNotification(NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const RawPayloadType &payload) override
Sends a notification (non-blocking)
NotificationNameIdType RegisterNotification(const String &notificationName, const String &senderName, Severity severity, PayloadTypeIdType payloadTypeId) override
Registers a new Notification
Interface for Paylo objects
Definition: IPayload.hpp:18
NotificationNameIdType Subscribe(const String &notificationName, INotificationSubscriber *subscriber) override
Subscribe to a Notification
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:198
The class contains date and time informations.
Definition: DateTime.hpp:43
Proxy object for a non-blocking NotificationRegistration
Definition: NonBlockingNotificationRegistration.hpp:32
Future< NotificationNameIdType > NonBlockingRegisterNotification(const String &notificationName, const String &senderName, Severity severity, PayloadTypeIdType payloadTypeId) override
Registers a new Notification (non-blocking)
const NotificationNameIdList GetNotificationNameIdsByStatus(const NotificationRegistrationStatus &status) const override
Queries the ids of Notifications with a given NotificationRegistrationStatus
const String GetNotificationName(NotificationNameIdType notificationNameId) const override
Queries the NotifictionName
void UnregisterNotification(NotificationNameIdType notificationNameId) override
Unregisters a Nototification
NotificationRegistration< PayloadType > CreateNotificationRegistration(const String &notificationName, const String &senderName, Severity severity)
Creates a NotificationRegistration proxy
Definition: NotificationManager.hpp:170
Interface for sending of notifications
Definition: INotificationSending.hpp:20
const NotificationNameIdList GetAllKnownNotificationNameIds() const override
Queries of all known NotificationNameIds
const NotificationRegistrationInfo GetNotificationRegistration(NotificationNameIdType notificationNameId) const override
Queries information about an Notification
std::vector< Arp::System::Rsc::Services::RscVariant< RawPayloadTypeLength > > RawPayloadType
type for the internally transferred payloads
Definition: NotificationManagerTypes.hpp:34
Future< void > NonBlockingUnregisterNotification(NotificationNameIdType notificationNameId) override
Unregisters a Nototification (non-blocking)
NotificationIdType SendNotification(NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const RawPayloadType &payload) override
Sends a notification
const String GetPayloadTypeName(const PayloadTypeIdType &payloadTypeId) const override
Query the payload type name of a given id
Interface for information about the Notification Manager
Definition: INotificationManagerInfo.hpp:20
NotificationRegistrationStatus
Enumeration to represent the status of the Notification
Definition: NotificationRegistrationStatus.hpp:16
Interface for subscribers of Notifications
Definition: INotificationSubscriber.hpp:19
Severity
Enumeration of Severities for notifications
Definition: Severity.hpp:15
Root namespace for the PLCnext API
Information about the registration of a Notification
Definition: NotificationRegistrationInfo.hpp:21
This class implements the singleton pattern for singletons with process wide scope.
Definition: AppDomainSingleton.hxx:24
std::uint64_t uint64
The Arp unsigned integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:39
NotificationSubscriber CreateNotificationSubscriber(const String &notificationName)
Creates a NotificationSubscriber proxy
Proxy object for a NotificationRegistration
Definition: NotificationRegistration.hpp:29
void UnsubscribeFromAll(INotificationSubscriber *subscriber) override
Unsubscribe from all Notification
const NotificationNameIdType GetNotificationNameId(const String &notificationName) override
Queries the id of an NotificationName
Arp::uint64 GetNumberOfSubmittedNotifications() const override
Returns the number of Notifications submitted since startup of the controller
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:114
System components used by the System, Device, Plc or Io domains.
NonBlockingNotificationRegistration< PayloadType > CreateNonBlockingNotificationRegistration(const String &notificationName, const String &senderName, Severity severity)
Creates a NonBlockingNotificationRegistration proxy
Definition: NotificationManager.hpp:179
Adapter for INonBlockingNotificationSending with additional functions
Definition: NonBlockingNotificationSendingAdapter.hpp:24
std::vector< NotificationNameIdType > NotificationNameIdList
collection of Notification name ids
Definition: NotificationManagerTypes.hpp:25
Primary access to the NotificationManager
Definition: NotificationManager.hpp:43
void Unsubscribe(NotificationNameIdType notificationNameId, INotificationSubscriber *subscriber) override
Unsubscribe from a Notification
Proxy class for an subscriber of notifications
Definition: NotificationSubscriber.hpp:27