PLCnext API Documentation  22.9.0.33
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 
29  , public Arp::System::Commons::Diagnostics::Logging::Loggable<NotificationSubscriber>
30 {
31 public:
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 
51  ~NotificationSubscriber() override;
52 
53  NotificationSubscriber& operator=(const NotificationSubscriber&) = delete;
55 
59 
61  void Dispose() noexcept;
62 
65  void Notify(const Notification& notification) override;
66 
68  const String GetNotificationName() const;
69 
72 
73 private: // methods
74  void Initialize();
75  bool IsInitialized() const;
76  void TranferSubscriptionFrom(NotificationSubscriber& other);
77 
78 private: // fields
79 
80  // NotificationReceiving is not used any more. It will be removed in future versions.
81  INotificationReceiving* NotificationReceiving = nullptr;
82 
83  String NotificationName;
84  NotificationNameIdType NotificationNameId;
85 
86  // Mutex is not used any more. It will be removed in future versions.
87  Arp::System::Commons::Threading::Mutex Mutex;
88 };
89 
90 }}} // namespace Arp::System::Nm
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:26
Interface for subscribers of Notifications
Definition: INotificationReceiving.hpp:20
Interface for subscribers of Notifications
Definition: INotificationSubscriber.hpp:20
Proxy class for an subscriber of notifications
Definition: NotificationSubscriber.hpp:30
Arp::event< const Notification & > OnNotification
Event to be fired on a Notification
Definition: NotificationSubscriber.hpp:58
const NotificationNameIdType GetNotificationNameId() const
Returns the NotificationNameId
void Dispose() noexcept
Unsubscribe and release alll resources
NotificationSubscriber()=default
Creates an empty subscriber
void Notify(const Notification &notification) override
Called by the NotificationManager when a Notification is dipatched
const String GetNotificationName() const
Returns the NotificationName
Contains meta data and paylod of a Notification
Definition: Notification.hpp:22
Use this class to register and invoke several delegates (function pointer in OOP design).
Definition: event.hxx:33
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API