forked from open62541pp/open62541pp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices_attribute.cpp
53 lines (44 loc) · 1.86 KB
/
services_attribute.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
#include "open62541pp/services/attribute.hpp"
#include "open62541pp/client.hpp"
#include "open62541pp/server.hpp"
namespace opcua::services {
ReadResponse read(Client& connection, const ReadRequest& request) noexcept {
return UA_Client_Service_read(connection.handle(), request);
}
template <>
Result<DataValue> readAttribute<Server>(
Server& connection, const NodeId& id, AttributeId attributeId, TimestampsToReturn timestamps
) noexcept {
const auto item = detail::createReadValueId(id, attributeId);
return DataValue(
UA_Server_read(connection.handle(), &item, static_cast<UA_TimestampsToReturn>(timestamps))
);
}
template <>
Result<DataValue> readAttribute<Client>(
Client& connection, const NodeId& id, AttributeId attributeId, TimestampsToReturn timestamps
) noexcept {
auto item = detail::createReadValueId(id, attributeId);
const auto request = detail::createReadRequest(timestamps, item);
auto response = read(connection, asWrapper<ReadRequest>(request));
return detail::wrapSingleResult<DataValue>(response);
}
WriteResponse write(Client& connection, const WriteRequest& request) noexcept {
return UA_Client_Service_write(connection.handle(), request);
}
template <>
StatusCode writeAttribute<Server>(
Server& connection, const NodeId& id, AttributeId attributeId, const DataValue& value
) noexcept {
const auto item = detail::createWriteValue(id, attributeId, value);
return UA_Server_write(connection.handle(), &item);
}
template <>
StatusCode writeAttribute<Client>(
Client& connection, const NodeId& id, AttributeId attributeId, const DataValue& value
) noexcept {
auto item = detail::createWriteValue(id, attributeId, value);
const auto request = detail::createWriteRequest(item);
return detail::getSingleStatus(write(connection, asWrapper<WriteRequest>(request)));
}
} // namespace opcua::services