1// Copyright (C) 2018 basysKom GmbH, opensource@basyskom.com
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qopcuareadresult.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QOpcUaReadResult
10 \inmodule QtOpcUa
11 \brief This class stores the result of a read operation.
12
13 A read operation on an OPC UA server returns the value and timestamps which describe when a value was generated
14 by the source and when the server obtained it. It also returns a status code which describes if the value could
15 be read and if not, for what reason the read has failed.
16
17 In addition to the data returned by the server, this class also contains the node id, the attribute and the index
18 range from the request to enable a client to match the result with a request.
19
20 Objects of this class are returned in the \l QOpcUaClient::readNodeAttributesFinished()
21 signal and contain the result of a read operation that was part of a \l QOpcUaClient::readNodeAttributes()
22 request.
23
24 \sa QOpcUaClient::readNodeAttributes() QOpcUaClient::readNodeAttributesFinished() QOpcUaReadItem
25*/
26class QOpcUaReadResultData : public QSharedData
27{
28public:
29 QDateTime serverTimestamp;
30 QDateTime sourceTimestamp;
31 QOpcUa::UaStatusCode statusCode {QOpcUa::UaStatusCode::Good};
32 QString nodeId;
33 QOpcUa::NodeAttribute attribute {QOpcUa::NodeAttribute::Value};
34 QString indexRange;
35 QVariant value;
36};
37
38QOpcUaReadResult::QOpcUaReadResult()
39 : data(new QOpcUaReadResultData)
40{
41}
42
43/*!
44 Constructs a read result from \a other.
45*/
46QOpcUaReadResult::QOpcUaReadResult(const QOpcUaReadResult &other)
47 : data(other.data)
48{
49}
50
51/*!
52 Sets the values from \a rhs in this read result.
53*/
54QOpcUaReadResult &QOpcUaReadResult::operator=(const QOpcUaReadResult &rhs)
55{
56 if (this != &rhs)
57 data.operator=(o: rhs.data);
58 return *this;
59}
60
61QOpcUaReadResult::~QOpcUaReadResult()
62{
63}
64
65/*!
66 Returns the value.
67*/
68QVariant QOpcUaReadResult::value() const
69{
70 return data->value;
71}
72
73/*!
74 Sets the value to \a value.
75*/
76void QOpcUaReadResult::setValue(const QVariant &value)
77{
78 data->value = value;
79}
80
81/*!
82 Returns the attribute id.
83*/
84QOpcUa::NodeAttribute QOpcUaReadResult::attribute() const
85{
86 return data->attribute;
87}
88
89/*!
90 Sets the attribute id to \a attribute.
91*/
92void QOpcUaReadResult::setAttribute(QOpcUa::NodeAttribute attribute)
93{
94 data->attribute = attribute;
95}
96
97/*!
98 Returns the index range.
99*/
100QString QOpcUaReadResult::indexRange() const
101{
102 return data->indexRange;
103}
104
105/*!
106 Sets the index range to \a indexRange.
107*/
108void QOpcUaReadResult::setIndexRange(const QString &indexRange)
109{
110 data->indexRange = indexRange;
111}
112
113/*!
114 Returns the node id.
115*/
116QString QOpcUaReadResult::nodeId() const
117{
118 return data->nodeId;
119}
120
121/*!
122 Sets the node id to \a nodeId.
123*/
124void QOpcUaReadResult::setNodeId(const QString &nodeId)
125{
126 data->nodeId = nodeId;
127}
128
129/*!
130 Returns the status code for this element. If the status code is not \l {QOpcUa::UaStatusCode} {Good}, the
131 value and the timestamps are invalid.
132*/
133QOpcUa::UaStatusCode QOpcUaReadResult::statusCode() const
134{
135 return data->statusCode;
136}
137
138/*!
139 Sets the status code to \a statusCode.
140*/
141void QOpcUaReadResult::setStatusCode(QOpcUa::UaStatusCode statusCode)
142{
143 data->statusCode = statusCode;
144}
145
146/*!
147 Returns the source timestamp for \l value().
148*/
149QDateTime QOpcUaReadResult::sourceTimestamp() const
150{
151 return data->sourceTimestamp;
152}
153
154/*!
155 Sets the source timestamp to \a sourceTimestamp.
156*/
157void QOpcUaReadResult::setSourceTimestamp(const QDateTime &sourceTimestamp)
158{
159 data->sourceTimestamp = sourceTimestamp;
160}
161
162/*!
163 Returns the server timestamp for \l value().
164*/
165QDateTime QOpcUaReadResult::serverTimestamp() const
166{
167 return data->serverTimestamp;
168}
169
170/*!
171 Sets the server timestamp to \a serverTimestamp.
172*/
173void QOpcUaReadResult::setServerTimestamp(const QDateTime &serverTimestamp)
174{
175 data->serverTimestamp = serverTimestamp;
176}
177
178QT_END_NAMESPACE
179

source code of qtopcua/src/opcua/client/qopcuareadresult.cpp