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