forked from open62541pp/open62541pp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices_view.cpp
111 lines (95 loc) · 3.64 KB
/
services_view.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "open62541pp/services/view.hpp"
#include <cstddef> // size_t
#include "open62541pp/client.hpp"
#include "open62541pp/server.hpp"
#include "open62541pp/services/detail/client_service.hpp"
#include "open62541pp/types.hpp"
namespace opcua::services {
BrowseResponse browse(Client& connection, const BrowseRequest& request) noexcept {
return UA_Client_Service_browse(connection.handle(), request);
}
template <>
BrowseResult browse<Server>(
Server& connection, const BrowseDescription& bd, uint32_t maxReferences
) noexcept {
return UA_Server_browse(connection.handle(), maxReferences, bd.handle());
}
template <>
BrowseResult browse<Client>(
Client& connection, const BrowseDescription& bd, uint32_t maxReferences
) noexcept {
const auto request = detail::createBrowseRequest(bd, maxReferences);
auto response = browse(connection, asWrapper<BrowseRequest>(request));
return detail::wrapSingleResultWithStatus<BrowseResult>(response);
}
BrowseNextResponse browseNext(Client& connection, const BrowseNextRequest& request) noexcept {
return UA_Client_Service_browseNext(connection.handle(), request);
}
template <>
BrowseResult browseNext<Server>(
Server& connection, bool releaseContinuationPoint, const ByteString& continuationPoint
) noexcept {
return UA_Server_browseNext(
connection.handle(), releaseContinuationPoint, continuationPoint.handle()
);
}
template <>
BrowseResult browseNext<Client>(
Client& connection, bool releaseContinuationPoint, const ByteString& continuationPoint
) noexcept {
const auto request = detail::createBrowseNextRequest(
releaseContinuationPoint, continuationPoint
);
auto response = browseNext(connection, asWrapper<BrowseNextRequest>(request));
return detail::wrapSingleResultWithStatus<BrowseResult>(response);
}
TranslateBrowsePathsToNodeIdsResponse translateBrowsePathsToNodeIds(
Client& connection, const TranslateBrowsePathsToNodeIdsRequest& request
) noexcept {
return UA_Client_Service_translateBrowsePathsToNodeIds(connection.handle(), request);
}
template <>
BrowsePathResult translateBrowsePathToNodeIds<Server>(
Server& connection, const BrowsePath& browsePath
) noexcept {
return UA_Server_translateBrowsePathToNodeIds(connection.handle(), browsePath.handle());
}
template <>
BrowsePathResult translateBrowsePathToNodeIds<Client>(
Client& connection, const BrowsePath& browsePath
) noexcept {
const auto request = detail::createTranslateBrowsePathsToNodeIdsRequest(browsePath);
auto response = translateBrowsePathsToNodeIds(
connection, asWrapper<TranslateBrowsePathsToNodeIdsRequest>(request)
);
return detail::wrapSingleResultWithStatus<BrowsePathResult>(response);
}
RegisterNodesResponse registerNodes(
Client& connection, const RegisterNodesRequest& request
) noexcept {
return UA_Client_Service_registerNodes(connection.handle(), request);
}
UnregisterNodesResponse unregisterNodes(
Client& connection, const UnregisterNodesRequest& request
) noexcept {
return UA_Client_Service_unregisterNodes(connection.handle(), request);
}
Result<std::vector<ExpandedNodeId>> browseRecursive(
Server& connection, const BrowseDescription& bd
) {
size_t arraySize{};
UA_ExpandedNodeId* array{};
const StatusCode status = UA_Server_browseRecursive(
connection.handle(), bd.handle(), &arraySize, &array
);
std::vector<ExpandedNodeId> result(
std::make_move_iterator(array),
std::make_move_iterator(array + arraySize) // NOLINT
);
UA_free(array); // NOLINT
if (status.isBad()) {
return BadResult(status);
}
return result;
}
} // namespace opcua::services