open62541pp 0.16.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 <cstdint>
4#include <functional>
5
6#include "open62541pp/config.hpp"
8#include "open62541pp/types_composed.hpp" // StatusChangeNotification
9#include "open62541pp/wrapper.hpp" // asWrapper
10
11#ifdef UA_ENABLE_SUBSCRIPTIONS
12
13struct UA_Client;
14
16
18 bool stale{false};
19 std::function<void(uint32_t subId, StatusChangeNotification&)> statusChangeCallback;
20 std::function<void(uint32_t subId)> deleteCallback;
21
23 [[maybe_unused]] UA_Client* client,
24 uint32_t subId,
25 void* subContext,
26 UA_StatusChangeNotification* notification
27 ) noexcept {
28 if (subContext != nullptr && notification != nullptr) {
29 auto* self = static_cast<SubscriptionContext*>(subContext);
30 self->invoke(
31 self->statusChangeCallback,
32 subId,
34 );
35 }
36 }
37
39 [[maybe_unused]] UA_Client* client, uint32_t subId, void* subContext
40 ) noexcept {
41 if (subContext != nullptr) {
42 auto* self = static_cast<SubscriptionContext*>(subContext);
43 self->invoke(self->deleteCallback, subId);
44 self->stale = true;
45 }
46 }
47};
48
49} // namespace opcua::services::detail
50
51#endif
UA_StatusChangeNotification wrapper class.
Client * asWrapper(UA_Client *client) noexcept
Convert native UA_Client pointer to its wrapper instance.
Helper class to map open62541 / C-style callbacks to std::function objects.
void invoke(F &&callback, Args &&... args) const noexcept
static void deleteCallbackNative(UA_Client *client, uint32_t subId, void *subContext) noexcept
std::function< void(uint32_t subId, StatusChangeNotification &)> statusChangeCallback
static void statusChangeCallbackNative(UA_Client *client, uint32_t subId, void *subContext, UA_StatusChangeNotification *notification) noexcept
std::function< void(uint32_t subId)> deleteCallback