PLCnext API Documentation  21.0.0.35466
NotificationSubscriber.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 
7 #pragma once
8 
9 #include "Arp/System/Core/event.hxx"
10 #include "Arp/System/Commons/Diagnostics/Logging/Loggable.hxx"
11 #include "Arp/System/Commons/Threading/Mutex.hpp"
12 #include "Arp/System/Nm/INotificationReceiving.hpp"
13 #include "Arp/System/Nm/INotificationSubscriber.hpp"
14 
15 namespace Arp { namespace System { namespace Nm
16 {
17 
18 
30 {
31 public:
35  NotificationSubscriber() = default;
36 
40  ARP_DEPRECATED("Use NotificationSubscriber(notificationName) instead. notificationReceiving is ignored.")
42  const String& notificationName, INotificationReceiving& notificationReceiving);
43 
47  explicit NotificationSubscriber(const String& notificationName);
48 
50  ~NotificationSubscriber() override;
51 
53 
55  NotificationSubscriber& operator=(const NotificationSubscriber&) = delete;
56 
60 
62  void Dispose() noexcept;
63 
66  void Notify(const Notification& notification) override;
67 
69  const String GetNotificationName() const;
70 
73 
74 private: // methods
75  void Initialize();
76  bool IsInitialized() const;
77  void TranferSubscriptionFrom(NotificationSubscriber& other);
78 
79 private: // fields
80 
81  // NotificationReceiving is not used any more. It will be removed in future versions.
82  INotificationReceiving* NotificationReceiving = nullptr;
83 
84  String NotificationName;
85  NotificationNameIdType NotificationNameId;
86 
87  // Mutex is not used any more. It will be removed in future versions.
88  Arp::System::Commons::Threading::Mutex Mutex;
89 };
90 
91 }}} // namespace Arp::System::Nm
Contains meta data and paylod of a Notification
Definition: Notification.hpp:21
Interface for subscribers of Notifications
Definition: INotificationReceiving.hpp:19
const String GetNotificationName() const
Returns the NotificationName
void Dispose() noexcept
Unsubscribe and release alll resources
NotificationSubscriber()=default
Creates an empty subscriber
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:25
void Notify(const Notification &notification) override
Called by the NotificationManager when a Notification is dipatched
Arp::event< const Notification & > OnNotification
Event to be fired on a Notification
Definition: NotificationSubscriber.hpp:59
Use this class to register and invoke several delegates (function pointer in OOP design).
Definition: event.hxx:32
Interface for subscribers of Notifications
Definition: INotificationSubscriber.hpp:19
Root namespace for the PLCnext API
System components used by the System, Device, Plc or Io domains.
const NotificationNameIdType GetNotificationNameId() const
Returns the NotificationNameId
Proxy class for an subscriber of notifications
Definition: NotificationSubscriber.hpp:27