11 #include "Arp/System/Nm/NonBlockingNotificationSendingAdapter.hpp"
12 #include "Arp/System/Nm/NotificationRegistrationBase.hpp"
15 namespace Arp {
namespace System {
namespace Nm
31 template<
typename PayloadType>
40 using payload_type = PayloadType;
71 template<
typename... Args>
78 template<
typename... Args>
80 const DateTime& timestamp, Args&& ... args);
93 void DisposeImpl()
override;
95 bool IsNotificationNameIdValid()
const;
111 State state = State::Uninitialized;
115 template<
typename PayloadType>
119 :
base_type(notificationName, senderName, severity), NotificationSending(¬ificationSending)
124 template<
typename PayloadType>
128 : base_type(notificationName, senderName, severity),
129 NotificationSending(adapter)
135 template<
typename PayloadType>
137 NonBlockingNotificationRegistration<PayloadType>&& other)
138 : base_type(
std::move(other)),
139 NotificationSending(
std::move(other.NotificationSending)),
140 futureNotificationNameId(
std::move(other.futureNotificationNameId)),
141 futureNotificationId(
std::move(other.futureNotificationId)),
142 futureUnregister(
std::move(other.futureUnregister)),
143 state(
std::move(other.state))
145 other.NotificationSending =
nullptr;
146 other.state = State::Uninitialized;
150 template<
typename PayloadType>
151 NonBlockingNotificationRegistration<PayloadType>::~NonBlockingNotificationRegistration()
157 template<
typename PayloadType>
158 NonBlockingNotificationRegistration<PayloadType>& NonBlockingNotificationRegistration<PayloadType>::
159 operator=(NonBlockingNotificationRegistration<PayloadType>&& other)
166 base_type::operator=(std::move(other));
168 this->NotificationSending = std::move(other.NotificationSending);
169 other.NotificationSending =
nullptr;
171 this->futureNotificationNameId = std::move(other.futureNotificationNameId);
172 this->futureNotificationId = std::move(other.futureNotificationId);
173 this->futureUnregister = std::move(other.futureUnregister);
175 this->state = std::move(other.state);
176 other.state = State::Uninitialized;
182 template<
typename PayloadType>
183 void NonBlockingNotificationRegistration<PayloadType>::Initialize()
185 if ((this->NotificationSending !=
nullptr) && (!this->IsNotificationNameIdValid()))
188 dynamic_cast<NonBlockingNotificationSendingAdapter*
>(this->NotificationSending);
189 if (adapterPtr !=
nullptr)
191 adapterPtr->NonBlockingRegisterNotification(this->NotificationName, this->SenderName,
192 this->severity, this->GetPayloadTypeId(), this->futureNotificationNameId);
196 this->futureNotificationNameId =
197 this->NotificationSending->NonBlockingRegisterNotification(this->NotificationName,
198 this->SenderName, this->severity, this->GetPayloadTypeId());
200 this->state = State::RegisterCalled;
205 template<
typename PayloadType>
206 void NonBlockingNotificationRegistration<PayloadType>::DisposeImpl()
208 if ((this->NotificationSending !=
nullptr) && this->IsNotificationNameIdValid())
211 dynamic_cast<NonBlockingNotificationSendingAdapter*
>(this->NotificationSending);
212 if (adapterPtr !=
nullptr)
214 adapterPtr->NonBlockingUnregisterNotification(
215 this->GetNotificationNameId(), this->futureUnregister);
219 this->futureUnregister = this->NotificationSending->NonBlockingUnregisterNotification(
220 this->GetNotificationNameId());
222 this->futureNotificationNameId = Future<NotificationNameIdType>();
223 this->futureNotificationId = Future<NotificationIdType>();
224 this->state = State::UnregisterCalled;
226 if (adapterPtr !=
nullptr)
228 delete this->NotificationSending;
230 this->NotificationSending =
nullptr;
235 template<
typename PayloadType>
236 template<
typename... Args>
240 return this->SendNotificationWithTimestamp(
DateTime::Now(), std::forward<Args>(args)...);
244 template<
typename PayloadType>
245 template<
typename... Args>
248 const DateTime& timestamp, Args&& ... args)
250 if ((this->NotificationSending ==
nullptr) || (!this->IsNotificationNameIdValid()))
256 #ifndef ARP_CXX_COMPILER_MSC
260 if (adapterPtr !=
nullptr)
262 std::function<
RawPayloadType()> createPayloadFunctor = [args...]()
264 return PayloadType{args...}.MoveOutRawPayload();
266 adapterPtr->NonBlockingSendNotification(this->futureNotificationNameId.GetValue(),
267 timestamp, std::move(createPayloadFunctor), this->futureNotificationId);
272 this->futureNotificationId = this->NotificationSending->NonBlockingSendNotification(
273 this->futureNotificationNameId.GetValue(), timestamp,
274 PayloadType{std::forward<Args>(args)...});
276 this->state = State::SendCalled;
278 return this->futureNotificationId;
282 template<
class PayloadType>
286 return this->futureNotificationNameId.
GetValue();
290 template<
class PayloadType>
293 return this->futureNotificationId.
GetValue();
297 template<
class PayloadType>
302 case State::Uninitialized:
305 case State::RegisterCalled:
306 return this->futureNotificationNameId.HasValue();
308 case State::SendCalled:
309 return this->futureNotificationId.HasValue();
311 case State::UnregisterCalled:
312 return this->futureUnregister.HasValue();
320 template<
class PayloadType>
323 return this->futureNotificationNameId.HasValue() &&
324 this->futureNotificationNameId.GetValue().IsValid();
The class contains date and time informations.
Definition: DateTime.hpp:45
static DateTime Now(void)
Gets the current time as DateTime, expressed as the UTC time.
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:191
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:114
Interface for non blocking sending of Notifications
Definition: INonBlockingNotificationSending.hpp:22
constexpr T GetValue() const noexcept
Returns the underlying value
Definition: IdType.hpp:94
Proxy object for a non-blocking NotificationRegistration
Definition: NonBlockingNotificationRegistration.hpp:34
NonBlockingNotificationRegistration(const String ¬ificationName, const String &senderName, Severity severity, INonBlockingNotificationSending ¬ificationSending)
Creates a NotificationRegistration
Definition: NonBlockingNotificationRegistration.hpp:116
Future< NotificationIdType > SendNotification(Args &&... args)
Sends a notification
Definition: NonBlockingNotificationRegistration.hpp:237
bool IsCompleted() const
Returns true if the last operation is completed
Definition: NonBlockingNotificationRegistration.hpp:298
Future< NotificationIdType > SendNotificationWithTimestamp(const DateTime ×tamp, Args &&... args)
Sends a notification with a specified timestamp
Definition: NonBlockingNotificationRegistration.hpp:247
NotificationNameIdType GetNotificationNameId() const override
Returns the NotificationNameId
Definition: NonBlockingNotificationRegistration.hpp:284
NonBlockingNotificationRegistration()=default
Creates an empty NotificationRegistration
NotificationIdType GetLastNotificationId() const
Returns the id of the last send Notification
Definition: NonBlockingNotificationRegistration.hpp:291
Adapter for INonBlockingNotificationSending with additional functions
Definition: NonBlockingNotificationSendingAdapter.hpp:25
Base class with common behavior of NotificationRegistration and NonBlockingNotificationRegistration
Definition: NotificationRegistrationBase.hpp:22
@ System
System components used by the System, Device, Plc or Io domains.
Severity
Enumeration of Severities for notifications
Definition: Severity.hpp:15
std::vector< Arp::System::Rsc::Services::RscVariant< RawPayloadTypeLength > > RawPayloadType
type for the internally transferred payloads
Definition: NotificationManagerTypes.hpp:34
Root namespace for the PLCnext API
Namespace of the C++ standard library