open62541pp 0.17.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
subscription_context.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
5#include "open62541pp/config.hpp"
7#include "open62541pp/ua/types.hpp" // IntegerId, StatusChangeNotification
8#include "open62541pp/wrapper.hpp" // asWrapper
9
10#ifdef UA_ENABLE_SUBSCRIPTIONS
11
12struct UA_Client;
13
14namespace opcua::services::detail {
15
16struct SubscriptionContext : CallbackAdapter {
17 bool stale{false};
18 std::function<void(IntegerId subId, StatusChangeNotification&)> statusChangeCallback;
19 std::function<void(IntegerId subId)> deleteCallback;
20
21 static void statusChangeCallbackNative(
22 [[maybe_unused]] UA_Client* client,
23 IntegerId subId,
24 void* subContext,
25 UA_StatusChangeNotification* notification
26 ) noexcept {
27 if (subContext != nullptr && notification != nullptr) {
28 auto* self = static_cast<SubscriptionContext*>(subContext);
29 self->invoke(
30 self->statusChangeCallback,
31 subId,
33 );
34 }
35 }
36
37 static void deleteCallbackNative(
38 [[maybe_unused]] UA_Client* client, IntegerId subId, void* subContext
39 ) noexcept {
40 if (subContext != nullptr) {
41 auto* self = static_cast<SubscriptionContext*>(subContext);
42 self->invoke(self->deleteCallback, subId);
43 self->stale = true;
44 }
45 }
46};
47
48} // namespace opcua::services::detail
49
50#endif
Client * asWrapper(UA_Client *client) noexcept
Convert native UA_Client pointer to its wrapper instance.
uint32_t IntegerId
IntegerId.
Definition types.hpp:123