1// Copyright (C) 2019 The Qt Company Ltd.
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 <private/opcuareadresult_p.h>
5#include <private/universalnode_p.h>
6
7#include <QOpcUaReadResult>
8#include <QOpcUaClient>
9#include <qopcuatype.h>
10
11QT_BEGIN_NAMESPACE
12
13/*!
14 \qmltype ReadResult
15 \inqmlmodule QtOpcUa
16 \brief Contains result data after reading from the server.
17 \since QtOpcUa 5.13
18 \deprecated [6.9]
19
20 This type is used to pass the read data after reading from the server using the function
21 \l Connection::readNodeAttributes.
22*/
23
24/*!
25 \qmlproperty Constants.NodeAttribute ReadResult::attribute
26 \readonly
27
28 The node attribute of data that was read.
29*/
30
31/*!
32 \qmlproperty string ReadResult::indexRange
33 \readonly
34
35 The index range of the data that was read.
36*/
37
38/*!
39 \qmlproperty string ReadResult::nodeId
40 \readonly
41
42 The node id of the node that was read.
43*/
44
45/*!
46 \qmlproperty string ReadResult::namespaceName
47 \readonly
48
49 The namespace name of the node that was read.
50*/
51
52/*!
53 \qmlproperty datetime ReadResult::serverTimestamp
54 \readonly
55
56 The server timestamp of the data that was read.
57*/
58
59/*!
60 \qmlproperty datetime ReadResult::sourceTimestamp
61 \readonly
62
63 The source timestamp of the data that was read.
64*/
65
66/*!
67 \qmlproperty variant ReadResult::value
68 \readonly
69
70 Actual data that was requested to be read.
71*/
72
73/*!
74 \qmlproperty Status ReadResult::status
75 \readonly
76
77 Result status of this ReadResult.
78 Before using any value of this ReadResult, the status
79 should be checked for \l {Status::Status}{Status.isGood}. To make sure
80 the server has provided valid data.
81*/
82
83class OpcUaReadResultData : public QSharedData
84{
85public:
86 OpcUaStatus status;
87 QOpcUa::NodeAttribute attribute;
88 QString indexRange;
89 QString nodeId;
90 QString namespaceName;
91 QDateTime serverTimestamp;
92 QDateTime sourceTimestamp;
93 QVariant value;
94};
95
96OpcUaReadResult::OpcUaReadResult()
97 : data(new OpcUaReadResultData)
98{
99 data->attribute = QOpcUa::NodeAttribute::None;
100}
101
102OpcUaReadResult::OpcUaReadResult(const OpcUaReadResult &other)
103 : data(other.data)
104{
105}
106
107OpcUaReadResult::OpcUaReadResult(const QOpcUaReadResult &other, const QOpcUaClient *client)
108 : data(new OpcUaReadResultData)
109{
110 data->status = OpcUaStatus(other.statusCode());
111 data->attribute = other.attribute();
112 data->indexRange = other.indexRange();
113 data->serverTimestamp = other.serverTimestamp();
114 data->sourceTimestamp = other.sourceTimestamp();
115 data->value = other.value();
116
117 int namespaceIndex = -1;
118 UniversalNode::splitNodeIdAndNamespace(nodeIdentifier: other.nodeId(), namespaceIndex: &namespaceIndex, identifier: &data->nodeId);
119 data->namespaceName = client->namespaceArray().at(i: namespaceIndex);
120}
121
122OpcUaReadResult &OpcUaReadResult::operator=(const OpcUaReadResult &rhs)
123{
124 if (this != &rhs)
125 data.operator=(o: rhs.data);
126 return *this;
127}
128
129OpcUaReadResult::~OpcUaReadResult() = default;
130
131const QString &OpcUaReadResult::indexRange() const
132{
133 return data->indexRange;
134}
135
136const QString &OpcUaReadResult::nodeId() const
137{
138 return data->nodeId;
139}
140
141QOpcUa::NodeAttribute OpcUaReadResult::attribute() const
142{
143 return data->attribute;
144}
145
146const QString &OpcUaReadResult::namespaceName() const
147{
148 return data->namespaceName;
149}
150
151const QDateTime &OpcUaReadResult::serverTimestamp() const
152{
153 return data->serverTimestamp;
154}
155
156const QDateTime &OpcUaReadResult::sourceTimestamp() const
157{
158 return data->sourceTimestamp;
159}
160
161const QVariant &OpcUaReadResult::value() const
162{
163 return data->value;
164}
165
166OpcUaStatus OpcUaReadResult::status() const
167{
168 return data->status;
169}
170
171QT_END_NAMESPACE
172
173

source code of qtopcua/src/declarative_opcua/opcuareadresult.cpp