PLCnext API Documentation 25.0.2.69
NotificationManager.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6
7#pragma once
8
10#include "Arp/System/Commons/Logging.h"
11#include "Arp/System/Nm/INonBlockingNotificationSending.hpp"
12#include "Arp/System/Nm/INotificationManagerInfo.hpp"
13#include "Arp/System/Nm/INotificationReceiving.hpp"
14#include "Arp/System/Nm/INotificationSending.hpp"
15#include "Arp/System/Nm/NonBlockingNotificationRegistration.hpp"
16#include "Arp/System/Nm/NonBlockingNotificationRegistration3.hpp"
17#include "Arp/System/Nm/NonBlockingNotificationSendingAdapter.hpp"
18#include "Arp/System/Nm/NotificationRegistration.hpp"
19#include "Arp/System/Nm/NotificationSubscriber.hpp"
20#include <memory>
21
22namespace Arp { namespace System { namespace Nm
23{
24
47 , private Loggable<NotificationManager, true>
48{
50
51public: // usings
53 using InstancePtr = std::unique_ptr<Instance>;
54
55private:
56 class Impl;
57
58public:
59 explicit NotificationManager(size_t nonBlockingNotificationSendingProxyQueueLength = 128);
61 NotificationManager(NotificationManager&&)noexcept = delete;
62 NotificationManager& operator=(const NotificationManager&) = delete;
63 NotificationManager& operator=(NotificationManager&&)noexcept = delete;
64 ~NotificationManager(void)override;
65
66public: // static singleton operations
67 static Instance& CreateInstance(size_t nonBlockingNotificationSendingProxyQueueLength = 128);
68 static bool IsCreated(void);
69 static void DisposeInstance(void);
70 static Instance& GetInstance(void);
71
72public: // operations
73 // High level operations using proxy objects
81 template<typename PayloadType>
83 const String& notificationName, const String& senderName, Severity severity);
84
96 template<typename PayloadType>
98 const String& notificationName, const String& senderName, Severity severity);
99
115 template<typename PayloadType>
117 const String& notificationName, const String& senderName, Severity severity);
118
130 template<typename PayloadType, typename ArgumentsType = typename PayloadType::ArgumentsType>
132 const String& notificationName, const String& senderName, Severity severity,
133 size_t argumentsBufferCapacity = GetDefaultArgumentsBufferCapacity());
134
136
137 // Methods of INotificationSending
138 NotificationNameIdType RegisterNotification(const String& notificationName, const String& senderName,
139 Severity severity, PayloadTypeIdType payloadTypeId) override;
140 void UnregisterNotification(NotificationNameIdType notificationNameId) override;
141
143 NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const RawPayloadType& payload) override;
145 NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const IPayload& payload) override;
146
147 // Methods of INonBlockingNotificationSending
149 const String& senderName, Severity severity, PayloadTypeIdType payloadTypeId) override;
150
151 void NonBlockingRegisterNotification(const String& notificationName, const String& senderName, Severity severity,
153
155
157
159 NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const RawPayloadType& payload) override;
160
161 void NonBlockingSendNotification(NotificationNameIdType notificationNameId, Arp::DateTime timestamp,
162 std::function<RawPayloadType()> createPayloadFunctor, Future<NotificationIdType> result);
163
165 NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const IPayload& payload) override;
166
167private:
168 void NonBlockingSendNotification(NotificationNameIdType notificationNameId, Arp::DateTime timestamp,
169 NonBlockingNotificationSendingAdapter::CreatePayloadFunctor createPayloadFunctor,
172
173 static size_t GetDefaultArgumentsBufferCapacity();
174
175public:
176 // Methods of INotificationManagerInfo
177 String GetNotificationName(NotificationNameIdType notificationNameId) const override;
178 NotificationNameIdType GetNotificationNameId(const String& notificationName) override;
179
181 const NotificationRegistrationStatus& status) const override;
184 NotificationNameIdType notificationNameId) const override;
185
186 PayloadTypeIdType GetPayloadTypeId(const String& payloadTypeName) override;
187 String GetPayloadTypeName(const PayloadTypeIdType& payloadTypeId) const override;
188
190
191 // Methods of INotificationReceiving
192 NotificationNameIdType Subscribe(const String& notificationName, INotificationSubscriber* subscriber) override;
193 void Unsubscribe(NotificationNameIdType notificationNameId, INotificationSubscriber* subscriber) override;
194 void UnsubscribeFromAll(INotificationSubscriber* subscriber) override;
195
196 void ReplaceSubscriber(INotificationSubscriber* oldSubscriber, INotificationSubscriber* newSubscriber);
197
198private:
199 const std::unique_ptr<Impl> pImpl;
200
201private: // static fields
202 static InstancePtr instancePtr;
203};
204
205template<typename PayloadType>
207 const String& notificationName, const String& senderName, Severity severity)
208{
209 return NotificationRegistration<PayloadType>(notificationName, senderName, severity, *(this));
210}
211
212template<typename PayloadType>
214 const String& notificationName, const String& senderName, Severity severity)
215{
216 return NonBlockingNotificationRegistration<PayloadType>(notificationName, senderName, severity, *this);
217}
218
219template<typename PayloadType>
221 const String& notificationName, const String& senderName, Severity severity)
222{
224 notificationName, senderName, severity, new NonBlockingNotificationSendingAdapter(*this));
225}
226
227template<typename PayloadType, typename ArgumentsType>
230 const String& notificationName, const String& senderName, Severity severity, size_t argumentsBufferCapacity)
231{
232 return NonBlockingNotificationRegistration3<PayloadType, ArgumentsType>(notificationName, senderName, severity,
233 argumentsBufferCapacity, std::make_unique<NonBlockingNotificationSendingAdapter>(*this));
234}
235
236}}} // end of namespace Arp::System::Nm
This class contains date and time informations.
Definition: DateTime.hpp:27
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Derive from this class to inherit logging functionality.
Definition: Loggable.hxx:28
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:144
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:68
Interface for non blocking sending of Notifications
Definition: INonBlockingNotificationSending.hpp:23
Interface for information about the Notification Manager
Definition: INotificationManagerInfo.hpp:22
Interface for subscribers of Notifications
Definition: INotificationReceiving.hpp:20
Interface for sending of notifications
Definition: INotificationSending.hpp:21
Interface for subscribers of Notifications
Definition: INotificationSubscriber.hpp:21
Interface for Paylo objects
Definition: IPayload.hpp:19
Proxy object for a non-blocking NotificationRegistration
Definition: NonBlockingNotificationRegistration3.hpp:54
Proxy object for a non-blocking NotificationRegistration
Definition: NonBlockingNotificationRegistration.hpp:35
Adapter for INonBlockingNotificationSending with additional functions
Definition: NonBlockingNotificationSendingAdapter.hpp:26
Definition: NotificationManager.cpp:31
Primary access to the NotificationManager
Definition: NotificationManager.hpp:48
NonBlockingNotificationRegistration< PayloadType > CreateNonBlockingNotificationRegistration2(const String &notificationName, const String &senderName, Severity severity)
Creates a NonBlockingNotificationRegistration proxy
Definition: NotificationManager.hpp:220
NotificationSubscriber CreateNotificationSubscriber(const String &notificationName)
Creates a NotificationSubscriber proxy
Definition: NotificationManager.cpp:245
NotificationNameIdType Subscribe(const String &notificationName, INotificationSubscriber *subscriber) override
Subscribe to a Notification
Definition: NotificationManager.cpp:221
Future< NotificationNameIdType > NonBlockingRegisterNotification(const String &notificationName, const String &senderName, Severity severity, PayloadTypeIdType payloadTypeId) override
Registers a new Notification (non-blocking)
Definition: NotificationManager.cpp:91
NotificationRegistration< PayloadType > CreateNotificationRegistration(const String &notificationName, const String &senderName, Severity severity)
Creates a NotificationRegistration proxy
Definition: NotificationManager.hpp:206
NotificationNameIdList GetAllKnownNotificationNameIds() const override
Queries of all known NotificationNameIds
Definition: NotificationManager.cpp:194
Future< NotificationIdType > NonBlockingSendNotification(NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const RawPayloadType &payload) override
Sends a notification (non-blocking)
Definition: NotificationManager.cpp:120
void UnregisterNotification(NotificationNameIdType notificationNameId) override
Unregisters a Nototification
Definition: NotificationManager.cpp:66
NotificationNameIdType GetNotificationNameId(const String &notificationName) override
Queries the id of an NotificationName
Definition: NotificationManager.cpp:182
Future< void > NonBlockingUnregisterNotification(NotificationNameIdType notificationNameId) override
Unregisters a Nototification (non-blocking)
Definition: NotificationManager.cpp:107
NotificationNameIdList GetNotificationNameIdsByStatus(const NotificationRegistrationStatus &status) const override
Queries the ids of Notifications with a given NotificationRegistrationStatus
Definition: NotificationManager.cpp:187
PayloadTypeIdType GetPayloadTypeId(const String &payloadTypeName) override
Query an id for a given PayloadType
Definition: NotificationManager.cpp:206
void Unsubscribe(NotificationNameIdType notificationNameId, INotificationSubscriber *subscriber) override
Unsubscribe from a Notification
Definition: NotificationManager.cpp:227
NonBlockingNotificationRegistration< PayloadType > CreateNonBlockingNotificationRegistration(const String &notificationName, const String &senderName, Severity severity)
Creates a NonBlockingNotificationRegistration proxy
Definition: NotificationManager.hpp:213
String GetPayloadTypeName(const PayloadTypeIdType &payloadTypeId) const override
Query the payload type name of a given id
Definition: NotificationManager.cpp:211
NotificationRegistrationInfo GetNotificationRegistration(NotificationNameIdType notificationNameId) const override
Queries information about an Notification
Definition: NotificationManager.cpp:200
NotificationIdType SendNotification(NotificationNameIdType notificationNameId, Arp::DateTime timestamp, const RawPayloadType &payload) override
Sends a notification
Definition: NotificationManager.cpp:71
Arp::uint64 GetNumberOfSubmittedNotifications() const override
Returns the number of Notifications submitted since startup of the controller
Definition: NotificationManager.cpp:216
NonBlockingNotificationRegistration3< PayloadType, ArgumentsType > CreateNonBlockingNotificationRegistration3(const String &notificationName, const String &senderName, Severity severity, size_t argumentsBufferCapacity=GetDefaultArgumentsBufferCapacity())
Creates a NonBlockingNotificationRegistration3 proxy
Definition: NotificationManager.hpp:229
String GetNotificationName(NotificationNameIdType notificationNameId) const override
Queries the NotifictionName
Definition: NotificationManager.cpp:177
NotificationNameIdType RegisterNotification(const String &notificationName, const String &senderName, Severity severity, PayloadTypeIdType payloadTypeId) override
Registers a new Notification
Definition: NotificationManager.cpp:59
void UnsubscribeFromAll(INotificationSubscriber *subscriber) override
Unsubscribe from all Notification
Definition: NotificationManager.cpp:232
Information about the registration of a Notification
Definition: NotificationRegistrationInfo.hpp:21
Proxy object for a NotificationRegistration
Definition: NotificationRegistration.hpp:31
Proxy class for an subscriber of notifications
Definition: NotificationSubscriber.hpp:30
std::uint64_t uint64
The Arp unsigned integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:37
enum ARP_CXX_SYMBOL_EXPORT Severity
Enumeration of Severities for notifications
Definition: Severity.hpp:14
enum ARP_CXX_SYMBOL_EXPORT NotificationRegistrationStatus
Enumeration to represent the status of the Notification
Definition: NotificationRegistrationStatus.hpp:14
std::vector< NotificationNameIdType > NotificationNameIdList
collection of Notification name ids
Definition: NotificationManagerTypes.hpp:23
std::vector< Arp::Base::Rsc::Commons::RscVariant< RawPayloadTypeLength > > RawPayloadType
type for the internally transferred payloads
Definition: NotificationManagerTypes.hpp:32
Root namespace for the PLCnext API
Definition: NonBlockingNotificationSendingAdapter.hpp:29