open62541pp 0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
monitoreditem_context.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <functional>
5
8#include "open62541pp/types_composed.hpp" // DataValue, Variant
9#include "open62541pp/wrapper.hpp" // asWrapper
10
11struct UA_Client;
12struct UA_Server;
13
15
17 bool stale{false};
18 bool inserted{false};
20 std::function<void(uint32_t subId, uint32_t monId, const DataValue&)> dataChangeCallback;
21 std::function<void(uint32_t subId, uint32_t monId, Span<const Variant>)> eventCallback;
22 std::function<void(uint32_t subId, uint32_t monId)> deleteCallback;
23
25 [[maybe_unused]] UA_Server* server,
26 uint32_t monId,
27 void* monContext,
28 [[maybe_unused]] const UA_NodeId* nodeId,
29 [[maybe_unused]] void* nodeContext,
30 [[maybe_unused]] uint32_t attributeId,
31 const UA_DataValue* value
32 ) noexcept {
33 if (monContext != nullptr && value != nullptr) {
34 auto* self = static_cast<MonitoredItemContext*>(monContext);
35 if (!self->inserted) {
36 return; // avoid immediate callbacks before insertion
37 }
38 self->invoke(self->dataChangeCallback, 0U, monId, asWrapper<DataValue>(*value));
39 }
40 }
41
43 [[maybe_unused]] UA_Client* client,
44 uint32_t subId,
45 [[maybe_unused]] void* subContext,
46 uint32_t monId,
47 void* monContext,
48 UA_DataValue* value
49 ) noexcept {
50 if (monContext != nullptr && value != nullptr) {
51 auto* self = static_cast<MonitoredItemContext*>(monContext);
52 if (!self->inserted) {
53 return; // avoid immediate callbacks before insertion
54 }
55 self->invoke(self->dataChangeCallback, subId, monId, asWrapper<DataValue>(*value));
56 }
57 }
58
60 [[maybe_unused]] UA_Client* client,
61 uint32_t subId,
62 [[maybe_unused]] void* subContext,
63 uint32_t monId,
64 void* monContext,
65 size_t nEventFields,
66 UA_Variant* eventFields
67 ) noexcept {
68 if (monContext != nullptr) {
69 auto* self = static_cast<MonitoredItemContext*>(monContext);
70 if (!self->inserted) {
71 return; // avoid immediate callbacks before insertion
72 }
73 self->invoke(
74 self->eventCallback,
75 subId,
76 monId,
77 Span<const Variant>{asWrapper<Variant>(eventFields), nEventFields}
78 );
79 }
80 }
81
83 [[maybe_unused]] UA_Client* client,
84 uint32_t subId,
85 [[maybe_unused]] void* subContext,
86 uint32_t monId,
87 void* monContext
88 ) noexcept {
89 if (monContext != nullptr) {
90 auto* self = static_cast<MonitoredItemContext*>(monContext);
91 self->invoke(self->deleteCallback, subId, monId);
92 self->stale = true;
93 }
94 }
95};
96
97} // namespace opcua::services::detail
UA_DataValue wrapper class.
Definition types.hpp:1478
UA_ReadValueId wrapper class.
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:26
constexpr WrapperType * asWrapper(NativeType *native) noexcept
Cast native object pointers to Wrapper object pointers.
Definition wrapper.hpp:164
Helper class to map open62541 / C-style callbacks to std::function objects.
void invoke(F &&callback, Args &&... args) const noexcept
std::function< void(uint32_t subId, uint32_t monId, Span< const Variant >)> eventCallback
static void dataChangeCallbackNativeClient(UA_Client *client, uint32_t subId, void *subContext, uint32_t monId, void *monContext, UA_DataValue *value) noexcept
static void eventCallbackNative(UA_Client *client, uint32_t subId, void *subContext, uint32_t monId, void *monContext, size_t nEventFields, UA_Variant *eventFields) noexcept
std::function< void(uint32_t subId, uint32_t monId)> deleteCallback
std::function< void(uint32_t subId, uint32_t monId, const DataValue &)> dataChangeCallback
static void dataChangeCallbackNativeServer(UA_Server *server, uint32_t monId, void *monContext, const UA_NodeId *nodeId, void *nodeContext, uint32_t attributeId, const UA_DataValue *value) noexcept
static void deleteCallbackNative(UA_Client *client, uint32_t subId, void *subContext, uint32_t monId, void *monContext) noexcept