PLCnext API Documentation 25.0.2.69
NotificationRegistrationBase.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6
7#pragma once
8
10#include "Arp/System/Nm/NotificationManagerTypes.hpp"
11#include "Arp/System/Nm/Severity.hpp"
12#include "Arp/System/Commons/Diagnostics/Logging/Loggable.hxx"
13
14namespace Arp { namespace System { namespace Nm
15{
16
17
20template<class Derived>
21class ARP_CXX_SYMBOL_EXPORT NotificationRegistrationBase
23 NotificationRegistrationBase<Derived >>
24{
25private:
26 friend Derived;
27
30 const String notificationName, const String senderName, Severity severity);
32
33public:
35
36 virtual ~NotificationRegistrationBase() = default;
37
40
41 void Dispose() noexcept;
42
43
45 virtual NotificationNameIdType GetNotificationNameId() const = 0;
46
47 String GetNotificationName() const;
48 String GetSenderName() const;
49 Severity GetSeverity() const;
50 PayloadTypeIdType GetPayloadTypeId() const;
51
52protected:
53 virtual void DisposeImpl() = 0;
54
55private:
56 String NotificationName;
57 String SenderName;
58 Severity severity = Severity::Internal;
59};
60
61
62template<class Derived>
64 const String notificationName, const String senderName, Severity severity)
65 : NotificationName(std::move(notificationName)),
66 SenderName(std::move(senderName)),
67 severity(std::move(severity))
68{
69}
70
71
73template<class Derived>
75{
76 try
77 {
78 this->DisposeImpl();
79 }
80 catch (const Arp::Exception& e)
81 {
82 this->log.Error("Caught exception while unregistering notificationName={}: {}",
83 this->NotificationName, e.ToString());
84 }
85 catch (...)
86 {
87 this->log.Error(
88 "Caught exception while unregistering notificationName={}", this->NotificationName);
89 }
90}
91
92
94template<class Derived>
96{
97 return this->NotificationName;
98}
99
100
102template<class Derived>
104{
105 return this->SenderName;
106}
107
108
110template<class Derived>
112{
113 return this->severity;
114}
115
116
118template<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:21
String ToString(void) const
This operation should be used for logging and returns a reasonable description of the exception cause...
Definition: Exception.cpp:165
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
Base class with common behavior of NotificationRegistration and NonBlockingNotificationRegistration
Definition: NotificationRegistrationBase.hpp:24
Severity GetSeverity() const
Returns the Severity
Definition: NotificationRegistrationBase.hpp:111
String GetSenderName() const
Returns the sender name
Definition: NotificationRegistrationBase.hpp:103
PayloadTypeIdType GetPayloadTypeId() const
Returns the PayloadTypeId
Definition: NotificationRegistrationBase.hpp:119
String GetNotificationName() const
Returns the notification name
Definition: NotificationRegistrationBase.hpp:95
void Dispose() noexcept
Unregisters the Notification and release all resources
Definition: NotificationRegistrationBase.hpp:74
enum ARP_CXX_SYMBOL_EXPORT Severity
Enumeration of Severities for notifications
Definition: Severity.hpp:14
Root namespace for the PLCnext API
Namespace of the C++ standard library