open62541pp 0.17.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
nodestore.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "open62541pp/detail/open62541/server.h" // nodestore plugins defined in server.h before v1.2
8
9namespace opcua {
10
11/**
12 * Value callback base class for variable nodes.
13 *
14 * Value callbacks allow to synchronize a variable value with an external representation.
15 * The attached callbacks are executed before every read and after every write operation.
16 * @see https://www.open62541.org/doc/1.3/tutorial_server_datasource.html
17 */
18class ValueCallbackBase : public PluginAdapter<UA_ValueCallback> {
19public:
20 /**
21 * Called before the value attribute is read.
22 *
23 * It is possible to write into the value attribute during onBeforeRead (using e.g.
24 * services::writeValue or Node::writeValue). The node is re-opened afterwards so that changes
25 * are considered in the following read operation.
26 *
27 * @param session Current session
28 * @param id The identifier of the node being read from
29 * @param range Optional numeric range the client wants to read from
30 * @param value Current value before the read operation
31 */
32 virtual void onRead(
33 Session& session, const NodeId& id, const NumericRange* range, const DataValue& value
34 ) = 0;
35
36 /**
37 * Called after writing the value attribute.
38 *
39 * The node is re-opened after writing so that the new value is visible in the callback.
40 *
41 * @param session Current session
42 * @param id The identifier of the node being written to
43 * @param range Optional numeric range the client wants to write to
44 * @param value New value after the write operation
45 */
46 virtual void onWrite(
47 Session& session, const NodeId& id, const NumericRange* range, const DataValue& value
48 ) = 0;
49
50 UA_ValueCallback create(bool ownsAdapter) override;
51};
52
53/**
54 * Data source base class for variable nodes.
55 *
56 * The server redirects every read and write request to callback functions.
57 * Internally, the data source needs to implement its own memory management.
58 * @see https://www.open62541.org/doc/1.3/tutorial_server_datasource.html
59 */
60class DataSourceBase : public PluginAdapter<UA_DataSource> {
61public:
62 /**
63 * Callback to set the read value, the result status and optionally a source timestamp.
64 *
65 * @note Zero-copy operations are possible. It is not required to return a copy of the actual
66 * content data. You can return a pointer to memory owned by the user. Memory can be reused
67 * between read callbacks of a data source, as the result is already encoded on the network
68 * buffer between each read operation.
69 * To use zero-copy reads, set the value of the Variant (DataValue::setValue) without copying,
70 * e.g. with Variant::assign.
71 *
72 * @param session Current session
73 * @param id The identifier of the node being read from
74 * @param range If not `nullptr`, then the data source shall return only a selection of the
75 * (non-scalar) data.
76 * Set `UA_STATUSCODE_BADINDEXRANGEINVALID` in `value` if this does not apply.
77 * @param value The DataValue that is returned to the reader
78 * @param timestamp Set the source timestamp of `value` if `true`
79 * @return StatusCode
80 */
82 Session& session,
83 const NodeId& id,
84 const NumericRange* range,
85 DataValue& value,
86 bool timestamp
87 ) = 0;
88
89 /**
90 * Callback to write the value into a data source.
91 *
92 * @param session Current session
93 * @param id The identifier of the node being written to
94 * @param range If not `nullptr`, then only this selection of (non-scalar) data should be
95 * written into the data source.
96 * @param value The DataValue that has been written by the writer
97 * @return StatusCode
98 */
100 Session& session, const NodeId& id, const NumericRange* range, const DataValue& value
101 ) = 0;
102
103 UA_DataSource create(bool ownsAdapter) override;
104};
105
106} // namespace opcua
Data source base class for variable nodes.
Definition nodestore.hpp:60
virtual StatusCode read(Session &session, const NodeId &id, const NumericRange *range, DataValue &value, bool timestamp)=0
Callback to set the read value, the result status and optionally a source timestamp.
UA_DataSource create(bool ownsAdapter) override
virtual StatusCode write(Session &session, const NodeId &id, const NumericRange *range, const DataValue &value)=0
Callback to write the value into a data source.
UA_DataValue wrapper class.
Definition types.hpp:1832
UA_NodeId wrapper class.
Definition types.hpp:666
UA_NumericRange wrapper class.
Definition types.hpp:2442
Base class to implement plugin adapters.
High-level session class to manage client sessions.
Definition session.hpp:20
UA_StatusCode wrapper class.
Definition types.hpp:46
Value callback base class for variable nodes.
Definition nodestore.hpp:18
virtual void onRead(Session &session, const NodeId &id, const NumericRange *range, const DataValue &value)=0
Called before the value attribute is read.
virtual void onWrite(Session &session, const NodeId &id, const NumericRange *range, const DataValue &value)=0
Called after writing the value attribute.
UA_ValueCallback create(bool ownsAdapter) override