12#include "Arp/System/Nm/NonBlockingNotificationSendingAdapter.hpp"
13#include "Arp/System/Nm/NotificationRegistrationBase.hpp"
16namespace Arp {
namespace System {
namespace Nm
32template<
typename PayloadType>
41 using payload_type = PayloadType;
72 template<
typename... Args>
79 template<
typename... Args>
81 const DateTime& timestamp, Args&& ... args);
94 void DisposeImpl()
override;
96 bool IsNotificationNameIdValid()
const;
112 State state = State::Uninitialized;
116template<
typename PayloadType>
120 :
base_type(notificationName, senderName, severity), NotificationSending(¬ificationSending)
125template<
typename PayloadType>
129 : base_type(notificationName, senderName, severity),
130 NotificationSending(adapter)
136template<
typename PayloadType>
139 : base_type(
std::move(other)),
140 NotificationSending(
std::move(other.NotificationSending)),
141 futureNotificationNameId(
std::move(other.futureNotificationNameId)),
142 futureNotificationId(
std::move(other.futureNotificationId)),
143 futureUnregister(
std::move(other.futureUnregister)),
144 state(
std::move(other.state))
146 other.NotificationSending =
nullptr;
147 other.state = State::Uninitialized;
151template<
typename PayloadType>
158template<
typename PayloadType>
159NonBlockingNotificationRegistration<PayloadType>& NonBlockingNotificationRegistration<PayloadType>::
160operator=(NonBlockingNotificationRegistration<PayloadType>&& other)
167 base_type::operator=(std::move(other));
169 this->NotificationSending = std::move(other.NotificationSending);
170 other.NotificationSending =
nullptr;
172 this->futureNotificationNameId = std::move(other.futureNotificationNameId);
173 this->futureNotificationId = std::move(other.futureNotificationId);
174 this->futureUnregister = std::move(other.futureUnregister);
176 this->state = std::move(other.state);
177 other.state = State::Uninitialized;
183template<
typename PayloadType>
184void NonBlockingNotificationRegistration<PayloadType>::Initialize()
186 if ((this->NotificationSending !=
nullptr) && (!this->IsNotificationNameIdValid()))
189 dynamic_cast<NonBlockingNotificationSendingAdapter*
>(this->NotificationSending);
190 if (adapterPtr !=
nullptr)
192 adapterPtr->NonBlockingRegisterNotification(this->NotificationName, this->SenderName,
193 this->severity, this->GetPayloadTypeId(), this->futureNotificationNameId);
197 this->futureNotificationNameId =
198 this->NotificationSending->NonBlockingRegisterNotification(this->NotificationName,
199 this->SenderName, this->severity, this->GetPayloadTypeId());
201 this->state = State::RegisterCalled;
206template<
typename PayloadType>
207void NonBlockingNotificationRegistration<PayloadType>::DisposeImpl()
209 if ((this->NotificationSending !=
nullptr) && this->IsNotificationNameIdValid())
212 dynamic_cast<NonBlockingNotificationSendingAdapter*
>(this->NotificationSending);
213 if (adapterPtr !=
nullptr)
215 adapterPtr->NonBlockingUnregisterNotification(
216 this->GetNotificationNameId(), this->futureUnregister);
220 this->futureUnregister = this->NotificationSending->NonBlockingUnregisterNotification(
221 this->GetNotificationNameId());
223 this->futureNotificationNameId = Future<NotificationNameIdType>();
224 this->futureNotificationId = Future<NotificationIdType>();
225 this->state = State::UnregisterCalled;
227 if (adapterPtr !=
nullptr)
229 delete this->NotificationSending;
231 this->NotificationSending =
nullptr;
236template<
typename PayloadType>
237template<
typename... Args>
241 return this->SendNotificationWithTimestamp(
DateTime::GetUtcNow(), std::forward<Args>(args)...);
245template<
typename PayloadType>
246template<
typename... Args>
249 const DateTime& timestamp, Args&& ... args)
251 if ((this->NotificationSending ==
nullptr) || (!this->IsNotificationNameIdValid()))
257#ifndef ARP_CXX_COMPILER_MSC
261 if (adapterPtr !=
nullptr)
263 std::function<
RawPayloadType()> createPayloadFunctor = [args...]()
265 return PayloadType{args...}.MoveOutRawPayload();
267 adapterPtr->NonBlockingSendNotification(this->futureNotificationNameId.GetValue(),
268 timestamp, std::move(createPayloadFunctor), this->futureNotificationId);
273 this->futureNotificationId = this->NotificationSending->NonBlockingSendNotification(
274 this->futureNotificationNameId.GetValue(), timestamp,
275 PayloadType{std::forward<Args>(args)...});
277 this->state = State::SendCalled;
279 return this->futureNotificationId;
283template<
class PayloadType>
287 return this->futureNotificationNameId.
GetValue();
291template<
class PayloadType>
294 return this->futureNotificationId.
GetValue();
298template<
class PayloadType>
303 case State::Uninitialized:
306 case State::RegisterCalled:
307 return this->futureNotificationNameId.HasValue();
309 case State::SendCalled:
310 return this->futureNotificationId.HasValue();
312 case State::UnregisterCalled:
313 return this->futureUnregister.HasValue();
321template<
class PayloadType>
324 return this->futureNotificationNameId.HasValue() &&
325 this->futureNotificationNameId.GetValue().IsValid();
This class contains date and time informations.
Definition: DateTime.hpp:27
static DateTime GetUtcNow(void)
Gets the current time in UTC.
Definition: DateTime.cpp:186
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:144
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:68
Interface for non blocking sending of Notifications
Definition: INonBlockingNotificationSending.hpp:23
constexpr T GetValue() const noexcept
Returns the underlying value
Definition: IdType.hpp:95
Proxy object for a non-blocking NotificationRegistration
Definition: NonBlockingNotificationRegistration.hpp:35
NonBlockingNotificationRegistration(const String ¬ificationName, const String &senderName, Severity severity, INonBlockingNotificationSending ¬ificationSending)
Creates a NotificationRegistration
Definition: NonBlockingNotificationRegistration.hpp:117
Future< NotificationIdType > SendNotification(Args &&... args)
Sends a notification
Definition: NonBlockingNotificationRegistration.hpp:238
bool IsCompleted() const
Returns true if the last operation is completed
Definition: NonBlockingNotificationRegistration.hpp:299
Future< NotificationIdType > SendNotificationWithTimestamp(const DateTime ×tamp, Args &&... args)
Sends a notification with a specified timestamp
Definition: NonBlockingNotificationRegistration.hpp:248
NotificationNameIdType GetNotificationNameId() const override
Returns the NotificationNameId
Definition: NonBlockingNotificationRegistration.hpp:285
NonBlockingNotificationRegistration()=default
Creates an empty NotificationRegistration
NotificationIdType GetLastNotificationId() const
Returns the id of the last send Notification
Definition: NonBlockingNotificationRegistration.hpp:292
Adapter for INonBlockingNotificationSending with additional functions
Definition: NonBlockingNotificationSendingAdapter.hpp:26
Base class with common behavior of NotificationRegistration and NonBlockingNotificationRegistration
Definition: NotificationRegistrationBase.hpp:24
enum ARP_CXX_SYMBOL_EXPORT Severity
Enumeration of Severities for notifications
Definition: Severity.hpp:14
std::vector< Arp::Base::Rsc::Commons::RscVariant< RawPayloadTypeLength > > RawPayloadType
type for the internally transferred payloads
Definition: NotificationManagerTypes.hpp:32
Root namespace for the PLCnext API
Namespace of the C++ standard library