open62541pp 0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
request_handling.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm> // transform
4#include <type_traits> // remove_const_t
5#include <vector>
6
7#include "open62541pp/common.hpp" // AttributeId, TimestampsToReturn, MonitoringMode
10#include "open62541pp/types.hpp"
12#include "open62541pp/typewrapper.hpp" // asNative
13
15
16template <typename T>
17inline ExtensionObject wrapNodeAttributes(const T& attributes) noexcept {
18 // NOLINTNEXTLINE(*-const-cast), won't be modified
19 return ExtensionObject::fromDecoded(const_cast<T&>(attributes));
20}
21
22template <typename T>
23inline auto* getPointer(T& value) noexcept {
24 // NOLINTNEXTLINE(*-const-cast), request object won't be modified
25 return const_cast<std::remove_const_t<T>*>(&value);
26}
27
28template <typename T>
29inline auto* getPointer(Span<T> array) noexcept {
30 // NOLINTNEXTLINE(*-const-cast), request object won't be modified
31 return const_cast<std::remove_const_t<T>*>(array.data());
32}
33
34template <typename T>
35inline auto* getNativePointer(T& wrapper) noexcept {
36 return asNative(getPointer(wrapper));
37}
38
39template <typename T>
40inline auto* getNativePointer(Span<T> array) noexcept {
41 return asNative(getPointer(array));
42}
43
44inline UA_ReadValueId createReadValueId(const NodeId& id, AttributeId attributeId) noexcept {
45 UA_ReadValueId item{};
46 item.nodeId = *id.handle();
47 item.attributeId = static_cast<uint32_t>(attributeId);
48 return item;
49}
50
52 TimestampsToReturn timestamps, UA_ReadValueId& item
53) noexcept {
54 UA_ReadRequest request{};
55 request.timestampsToReturn = static_cast<UA_TimestampsToReturn>(timestamps);
56 request.nodesToReadSize = 1;
57 request.nodesToRead = &item;
58 return request;
59}
60
62 TimestampsToReturn timestamps, Span<const ReadValueId> nodesToRead
63) noexcept {
64 UA_ReadRequest request{};
65 request.timestampsToReturn = static_cast<UA_TimestampsToReturn>(timestamps);
66 request.nodesToReadSize = nodesToRead.size();
67 request.nodesToRead = getNativePointer(nodesToRead);
68 return request;
69}
70
72 const NodeId& id, AttributeId attributeId, const DataValue& value
73) noexcept {
74 UA_WriteValue item{};
75 item.nodeId = *id.handle();
76 item.attributeId = static_cast<uint32_t>(attributeId);
77 item.value = *value.handle(); // shallow copy, avoid copy of value
78 item.value.hasValue = true;
79 return item;
80}
81
83 UA_WriteRequest request{};
84 request.nodesToWriteSize = 1;
85 request.nodesToWrite = &item;
86 return request;
87}
88
90 UA_WriteRequest request{};
91 request.nodesToWriteSize = nodesToWrite.size();
92 request.nodesToWrite = getNativePointer(nodesToWrite);
93 return request;
94}
95
97 const NodeId& objectId, const NodeId& methodId, Span<const Variant> inputArguments
98) noexcept {
99 UA_CallMethodRequest request{};
100 request.objectId = objectId;
101 request.methodId = methodId;
102 request.inputArgumentsSize = inputArguments.size();
103 request.inputArguments = getNativePointer(inputArguments);
104 return request;
105}
106
108 const BrowseDescription& bd, uint32_t maxReferences
109) noexcept {
110 UA_BrowseRequest request{};
111 request.requestedMaxReferencesPerNode = maxReferences;
112 request.nodesToBrowseSize = 1;
113 request.nodesToBrowse = getNativePointer(bd);
114 return request;
115}
116
118 bool releaseContinuationPoint, const ByteString& continuationPoint
119) noexcept {
120 UA_BrowseNextRequest request{};
121 request.releaseContinuationPoints = releaseContinuationPoint;
122 request.continuationPointsSize = 1;
123 request.continuationPoints = getNativePointer(continuationPoint);
124 return request;
125}
126
128 const BrowsePath& browsePath
129) noexcept {
131 request.browsePathsSize = 1;
132 request.browsePaths = getNativePointer(browsePath);
133 return request;
134}
135
137 std::vector<RelativePathElement> relativePathElements(browsePath.size());
138 std::transform(
139 browsePath.begin(),
140 browsePath.end(),
141 relativePathElements.begin(),
142 [](const auto& qn) {
143 return RelativePathElement(ReferenceTypeId::HierarchicalReferences, false, true, qn);
144 }
145 );
146 return {origin, RelativePath(relativePathElements)};
147}
148
149template <typename MonitoringParameters>
151 const MonitoringParameters& parameters, UA_MonitoringParameters& native
152) noexcept {
153 native.samplingInterval = parameters.samplingInterval;
154 native.filter = parameters.filter;
155 native.queueSize = parameters.queueSize;
156 native.discardOldest = parameters.discardOldest;
157}
158
159template <typename MonitoringParameters>
161 const ReadValueId& itemToMonitor,
162 MonitoringMode monitoringMode,
163 MonitoringParameters& parameters
164) noexcept {
166 request.itemToMonitor = itemToMonitor;
167 request.monitoringMode = static_cast<UA_MonitoringMode>(monitoringMode);
168 copyMonitoringParametersToNative(parameters, request.requestedParameters);
169 return request;
170}
171
172template <typename MonitoringParameters>
174 uint32_t monitoredItemId, MonitoringParameters& parameters
175) noexcept {
177 item.monitoredItemId = monitoredItemId;
178 copyMonitoringParametersToNative(parameters, item.requestedParameters);
179 return item;
180}
181
182template <typename MonitoringParameters>
184 uint32_t subscriptionId, MonitoringParameters& parameters, UA_MonitoredItemModifyRequest& item
185) noexcept {
187 request.subscriptionId = subscriptionId;
188 request.timestampsToReturn = static_cast<UA_TimestampsToReturn>(parameters.timestamps);
189 request.itemsToModifySize = 1;
190 request.itemsToModify = &item;
191 return request;
192}
193
195 uint32_t subscriptionId, Span<const uint32_t> monitoredItemIds, MonitoringMode monitoringMode
196) noexcept {
198 request.subscriptionId = subscriptionId;
199 request.monitoringMode = static_cast<UA_MonitoringMode>(monitoringMode);
200 request.monitoredItemIdsSize = monitoredItemIds.size();
201 request.monitoredItemIds = getPointer(monitoredItemIds);
202 return request;
203}
204
206 uint32_t subscriptionId,
207 uint32_t triggeringItemId,
208 Span<const uint32_t> linksToAdd,
209 Span<const uint32_t> linksToRemove
210) noexcept {
211 UA_SetTriggeringRequest request{};
212 request.subscriptionId = subscriptionId;
213 request.triggeringItemId = triggeringItemId;
214 request.linksToAddSize = linksToAdd.size();
215 request.linksToAdd = getPointer(linksToAdd);
216 request.linksToRemoveSize = linksToRemove.size();
217 request.linksToRemove = getPointer(linksToRemove);
218 return request;
219}
220
221} // namespace opcua::services::detail
UA_BrowseDescription wrapper class.
UA_BrowsePath wrapper class.
UA_ByteString wrapper class.
Definition types.hpp:490
UA_DataValue wrapper class.
Definition types.hpp:1478
UA_ExtensionObject wrapper class.
Definition types.hpp:1664
static ExtensionObject fromDecoded(T &data) noexcept
Create an ExtensionObject from a decoded object (reference).
Definition types.hpp:1672
UA_MonitoringParameters wrapper class.
UA_NodeId wrapper class.
Definition types.hpp:590
UA_ReadValueId wrapper class.
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:26
constexpr iterator begin() const noexcept
Definition span.hpp:128
constexpr size_t size() const noexcept
Definition span.hpp:101
constexpr iterator end() const noexcept
Definition span.hpp:132
constexpr NativeType * asNative(WrapperType *wrapper) noexcept
Cast Wrapper object pointers to native object pointers.
Definition wrapper.hpp:190
UA_ReadRequest createReadRequest(TimestampsToReturn timestamps, UA_ReadValueId &item) noexcept
auto * getPointer(T &value) noexcept
void copyMonitoringParametersToNative(const MonitoringParameters &parameters, UA_MonitoringParameters &native) noexcept
UA_MonitoredItemModifyRequest createMonitoredItemModifyRequest(uint32_t monitoredItemId, MonitoringParameters &parameters) noexcept
UA_ReadValueId createReadValueId(const NodeId &id, AttributeId attributeId) noexcept
UA_WriteRequest createWriteRequest(UA_WriteValue &item) noexcept
UA_BrowseRequest createBrowseRequest(const BrowseDescription &bd, uint32_t maxReferences) noexcept
UA_SetTriggeringRequest createSetTriggeringRequest(uint32_t subscriptionId, uint32_t triggeringItemId, Span< const uint32_t > linksToAdd, Span< const uint32_t > linksToRemove) noexcept
UA_MonitoredItemCreateRequest createMonitoredItemCreateRequest(const ReadValueId &itemToMonitor, MonitoringMode monitoringMode, MonitoringParameters &parameters) noexcept
UA_CallMethodRequest createCallMethodRequest(const NodeId &objectId, const NodeId &methodId, Span< const Variant > inputArguments) noexcept
UA_SetMonitoringModeRequest createSetMonitoringModeRequest(uint32_t subscriptionId, Span< const uint32_t > monitoredItemIds, MonitoringMode monitoringMode) noexcept
BrowsePath createBrowsePath(const NodeId &origin, Span< const QualifiedName > browsePath)
auto * getNativePointer(T &wrapper) noexcept
UA_WriteValue createWriteValue(const NodeId &id, AttributeId attributeId, const DataValue &value) noexcept
UA_TranslateBrowsePathsToNodeIdsRequest createTranslateBrowsePathsToNodeIdsRequest(const BrowsePath &browsePath) noexcept
ExtensionObject wrapNodeAttributes(const T &attributes) noexcept
UA_BrowseNextRequest createBrowseNextRequest(bool releaseContinuationPoint, const ByteString &continuationPoint) noexcept
UA_ModifyMonitoredItemsRequest createModifyMonitoredItemsRequest(uint32_t subscriptionId, MonitoringParameters &parameters, UA_MonitoredItemModifyRequest &item) noexcept
TimestampsToReturn
Timestamps to return.
Definition common.hpp:287
MonitoringMode
Monitoring mode.
Definition common.hpp:302
AttributeId
Attribute identifiers.
Definition common.hpp:28
UA_Boolean releaseContinuationPoints
UA_UInt32 requestedMaxReferencesPerNode
UA_TimestampsToReturn timestampsToReturn
UA_NodeId nodeId
size_t nodesToWriteSize
UA_NodeId nodeId
UA_TimestampsToReturn
UA_MonitoringMode