PLCnext API Documentation 25.6.0.37
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}
86
87
89template<class Derived>
91{
92 return this->NotificationName;
93}
94
95
97template<class Derived>
99{
100 return this->SenderName;
101}
102
103
105template<class Derived>
107{
108 return this->severity;
109}
110
111
113template<class Derived>
115{
116 return Derived::payload_type::GetPayloadTypeId();
117}
118
119
120}}} // 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:106
String GetSenderName() const
Returns the sender name
Definition: NotificationRegistrationBase.hpp:98
PayloadTypeIdType GetPayloadTypeId() const
Returns the PayloadTypeId
Definition: NotificationRegistrationBase.hpp:114
String GetNotificationName() const
Returns the notification name
Definition: NotificationRegistrationBase.hpp:90
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