PLCnext API Documentation  22.9.0.33
NotificationRegistrationBase.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 
7 #pragma once
8 
9 #include "Arp/System/Core/Arp.h"
10 #include "Arp/System/Commons/Diagnostics/Logging/Loggable.hxx"
11 
12 namespace Arp { namespace System { namespace Nm
13 {
14 
15 
18 template<class Derived>
21  NotificationRegistrationBase<Derived >>
22 {
23 private:
24  friend Derived;
25 
26  NotificationRegistrationBase() = default;
28  const String notificationName, const String senderName, Severity severity);
30 
31 public:
33 
34  virtual ~NotificationRegistrationBase() = default;
35 
36  NotificationRegistrationBase& operator=(NotificationRegistrationBase&& other) = default;
38 
40  void Dispose() noexcept;
41 
43  const String GetNotificationName() const;
44 
47 
49  const String GetSenderName() const;
50 
53 
56 
57 protected:
58  virtual void DisposeImpl() = 0;
59 
60 private:
61  String NotificationName;
62  String SenderName;
63  Severity severity = Severity::Default;
64 };
65 
66 
67 template<class Derived>
69  const String notificationName, const String senderName, Severity severity)
70  : NotificationName(std::move(notificationName)),
71  SenderName(std::move(senderName)),
72  severity(std::move(severity))
73 {
74 }
75 
76 
77 template<class Derived>
79 {
80  try
81  {
82  this->DisposeImpl();
83  }
84  catch (const Arp::Exception& e)
85  {
86  this->log.Error("Caught exception while unregistering notificationName={}: {}",
87  this->NotificationName, e.ToString());
88  }
89  catch (...)
90  {
91  this->log.Error(
92  "Caught exception while unregistering notificationName={}", this->NotificationName);
93  }
94 }
95 
96 
97 template<class Derived>
99 {
100  return this->NotificationName;
101 }
102 
103 
104 template<class Derived>
106 {
107  return this->SenderName;
108 }
109 
110 
111 template<class Derived>
113 {
114  return this->severity;
115 }
116 
117 
118 template<class Derived>
120 {
121  return Derived::payload_type::GetPayloadTypeId();
122 }
123 
124 
125 }}} // namespace Arp::System::Nm
This is the base class of all Arp exception classes.
Definition: Exception.hpp:16
String ToString(void) const
Gets a reasonable string representation of this exception.
Base class with common behavior of NotificationRegistration and NonBlockingNotificationRegistration
Definition: NotificationRegistrationBase.hpp:22
const String GetSenderName() const
Returns the sender name
Definition: NotificationRegistrationBase.hpp:105
Severity GetSeverity() const
Returns the Severity
Definition: NotificationRegistrationBase.hpp:112
PayloadTypeIdType GetPayloadTypeId() const
Returns the PayloadTypeId
Definition: NotificationRegistrationBase.hpp:119
virtual NotificationNameIdType GetNotificationNameId() const =0
Returns the notification name id
const String GetNotificationName() const
Returns the notification name
Definition: NotificationRegistrationBase.hpp:98
void Dispose() noexcept
Unregisters the Notification and release all resources
Definition: NotificationRegistrationBase.hpp:78
@ System
System components used by the System, Device, Plc or Io domains.
Severity
Enumeration of Severities for notifications
Definition: Severity.hpp:15
Root namespace for the PLCnext API
Namespace of the C++ standard library