open62541pp 0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
method.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <utility> // forward
4#include <vector>
5
7#include "open62541pp/config.hpp"
12#include "open62541pp/span.hpp"
13#include "open62541pp/types.hpp"
15
16#ifdef UA_ENABLE_METHODCALLS
17
18namespace opcua {
19class Client;
20} // namespace opcua
21
22namespace opcua::services {
23
24/**
25 * @defgroup Method Method service set
26 * Call (invoke) methods.
27 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.11
28 * @ingroup Services
29 * @{
30 *
31 * @defgroup Call Call service
32 * This Service is used to call (invoke) a list of methods.
33 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.11.2
34 * @{
35 */
36
37/**
38 * Call server methods.
39 * @param connection Instance of type Client
40 * @param request Call request
41 */
42CallResponse call(Client& connection, const CallRequest& request) noexcept;
43
44/**
45 * Asynchronously call server methods.
46 * @copydetails call
47 * @param token @completiontoken{void(CallResponse&)}
48 */
49template <typename CompletionToken = DefaultCompletionToken>
51 Client& connection,
52 const CallRequest& request,
53 CompletionToken&& token = DefaultCompletionToken()
54) {
56 connection, request, detail::Wrap<CallResponse>{}, std::forward<CompletionToken>(token)
57 );
58}
59
60/**
61 * Call a server method and return outputs.
62 * The `objectId` must have a `HasComponent` reference to the method specified in `methodId`.
63 *
64 * @param connection Instance of type Server or Client
65 * @param objectId NodeId of the object on which the method is invoked
66 * @param methodId NodeId of the method to invoke
67 * @param inputArguments Input argument values
68 * @exception BadStatus
69 * @exception BadStatus (BadInvalidArgument) If input arguments don't match expected variant types
70 * @exception BadStatus (BadArgumentsMissing) If input arguments are missing
71 * @exception BadStatus (BadTooManyArguments) If too many input arguments provided
72 */
73template <typename T>
75 T& connection,
76 const NodeId& objectId,
77 const NodeId& methodId,
78 Span<const Variant> inputArguments
79) noexcept;
80
81/**
82 * Asynchronously call a server method and return outputs.
83 *
84 * @param connection Instance of type Client
85 * @param objectId NodeId of the object on which the method is invoked
86 * @param methodId NodeId of the method to invoke
87 * @param inputArguments Input argument values
88 * @param token @completiontoken{void(Result<std::vector<Variant>>&)}
89 * @exception BadStatus
90 */
91template <typename CompletionToken = DefaultCompletionToken>
93 Client& connection,
94 const NodeId& objectId,
95 const NodeId& methodId,
96 Span<const Variant> inputArguments,
97 CompletionToken&& token = DefaultCompletionToken()
98) {
99 UA_CallMethodRequest item = detail::createCallMethodRequest(objectId, methodId, inputArguments);
100 UA_CallRequest request{};
101 request.methodsToCall = &item;
102 request.methodsToCallSize = 1;
104 connection,
105 request,
106 [](UA_CallResponse& response) {
107 return detail::getSingleResult(response).andThen(detail::getOutputArguments);
108 },
109 std::forward<CompletionToken>(token)
110 );
111}
112
113/**
114 * @}
115 * @}
116 */
117
118} // namespace opcua::services
119
120#endif
UA_CallRequest wrapper class.
UA_CallResponse wrapper class.
High-level client class.
Definition client.hpp:63
UA_NodeId wrapper class.
Definition types.hpp:590
The template class Result encapsulates a StatusCode and optionally a value.
Definition result.hpp:53
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:26
UseFutureToken DefaultCompletionToken
Default completion token for async operations.
Definition async.hpp:147
CallResponse call(Client &connection, const CallRequest &request) noexcept
Call server methods.
auto callAsync(Client &connection, const CallRequest &request, CompletionToken &&token=DefaultCompletionToken())
Asynchronously call server methods.
Definition method.hpp:50
auto getSingleResult(Response &response) noexcept -> Result< decltype(std::ref(*response.results))>
auto sendRequest(Client &client, const Request &request, TransformResponse &&transformResponse, CompletionToken &&token)
UA_CallMethodRequest createCallMethodRequest(const NodeId &objectId, const NodeId &methodId, Span< const Variant > inputArguments) noexcept
Result< std::vector< Variant > > getOutputArguments(UA_CallMethodResult &result) noexcept
OPC UA services as free functions.
Definition attribute.hpp:21