open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
nodestore.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
6
7namespace opcua {
8
9/**
10 * Value callbacks for variable nodes.
11 *
12 * Value callbacks allow to synchronize a variable value with an external representation.
13 * The attached callbacks are executed before every read and after every write operation.
14 * @see https://www.open62541.org/doc/1.3/tutorial_server_datasource.html
15 */
17 /**
18 * Called before the value attribute is read.
19 *
20 * It is possible to write into the value attribute during onBeforeRead (using e.g.
21 * services::writeValue or Node::writeValue). The node is re-opened afterwards so that changes
22 * are considered in the following read operation.
23 *
24 * @param value Current value before the read operation
25 */
26 std::function<void(const DataValue& value)> onBeforeRead;
27
28 /**
29 * Called after writing the value attribute.
30 *
31 * The node is re-opened after writing so that the new value is visible in the callback.
32 *
33 * @param value New value after the write operation
34 */
35 std::function<void(const DataValue& value)> onAfterWrite;
36};
37
38/**
39 * Data source backend for variable nodes.
40 *
41 * The server redirects every read and write request to callback functions.
42 * Internally, the data source needs to implement its own memory management.
43 * @see https://www.open62541.org/doc/1.3/tutorial_server_datasource.html
44 */
46 /**
47 * Callback to set the read value, the result status and optionally a source timestamp.
48 *
49 * @note Zero-copy operations are possible. It is not required to return a copy of the actual
50 * content data. You can return a pointer to memory owned by the user. Memory can be reused
51 * between read callbacks of a data source, as the result is already encoded on the network
52 * buffer between each read operation.
53 * To use zero-copy reads, set the value of the Variant (DataValue::getValue) without copying,
54 * e.g. with Variant::setScalar or Variant::setArray.
55 *
56 * @param value The DataValue that is returned to the reader
57 * @param range If not empty, then the data source shall return only a selection of the
58 * (nonscalar) data.
59 * Set `UA_STATUSCODE_BADINDEXRANGEINVALID` in `value` if this does not apply
60 * @param timestamp Set the source timestamp of `value` if `true`
61 * @return StatusCode
62 */
63 std::function<StatusCode(DataValue& value, const NumericRange& range, bool timestamp)> read;
64
65 /**
66 * Callback to write the value into a data source.
67 * This function can be empty if the operation is unsupported.
68 *
69 * @param value The DataValue that has been written by the writer
70 * @param range If not empty, then only this selection of (non-scalar) data should be written
71 * into the data source
72 * @return StatusCode
73 */
74 std::function<StatusCode(const DataValue& value, const NumericRange& range)> write;
75};
76
77} // namespace opcua
UA_DataValue wrapper class.
Definition types.hpp:1478
Numeric range to indicate subsets of (multidimensional) arrays.
Definition types.hpp:1893
Data source backend for variable nodes.
Definition nodestore.hpp:45
std::function< StatusCode(DataValue &value, const NumericRange &range, bool timestamp)> read
Callback to set the read value, the result status and optionally a source timestamp.
Definition nodestore.hpp:63
std::function< StatusCode(const DataValue &value, const NumericRange &range)> write
Callback to write the value into a data source.
Definition nodestore.hpp:74
Value callbacks for variable nodes.
Definition nodestore.hpp:16
std::function< void(const DataValue &value)> onAfterWrite
Called after writing the value attribute.
Definition nodestore.hpp:35
std::function< void(const DataValue &value)> onBeforeRead
Called before the value attribute is read.
Definition nodestore.hpp:26