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 "qopcuawriteitem.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QOpcUaWriteItem |
10 | \inmodule QtOpcUa |
11 | \brief This class stores the options for a write operation. |
12 | |
13 | A write operation on an OPC UA server overwrites the entire value or a certain index range of the value of an |
14 | attribute of a node on the server. This class contains the necessary information for the backend to make |
15 | a write request to the server. |
16 | |
17 | One or multiple objects of this class make up the request of a \l QOpcUaClient::writeNodeAttributes() operation. |
18 | |
19 | \sa QOpcUaClient::writeNodeAttributes() QOpcUaWriteResult |
20 | */ |
21 | class QOpcUaWriteItemData : public QSharedData |
22 | { |
23 | public: |
24 | QString nodeId; |
25 | QOpcUa::NodeAttribute attribute {QOpcUa::NodeAttribute::Value}; |
26 | QString indexRange; |
27 | QVariant value; |
28 | QOpcUa::Types type {QOpcUa::Types::Undefined}; |
29 | QDateTime sourceTimestamp; |
30 | QDateTime serverTimestamp; |
31 | QOpcUa::UaStatusCode statusCode {QOpcUa::UaStatusCode::Good}; |
32 | bool hasStatusCode {false}; |
33 | }; |
34 | |
35 | QOpcUaWriteItem::QOpcUaWriteItem() |
36 | : data(new QOpcUaWriteItemData) |
37 | { |
38 | } |
39 | |
40 | /*! |
41 | Creates a new write item from \a other. |
42 | */ |
43 | QOpcUaWriteItem::QOpcUaWriteItem(const QOpcUaWriteItem &other) |
44 | : data(other.data) |
45 | { |
46 | } |
47 | |
48 | /*! |
49 | Creates a write item for the attribute \a attribute from node \a nodeId. |
50 | The value \a value of type \a type will be written at position \a indexRange of \a attribute. |
51 | */ |
52 | QOpcUaWriteItem::QOpcUaWriteItem(const QString &nodeId, QOpcUa::NodeAttribute attribute, |
53 | const QVariant &value, QOpcUa::Types type, const QString &indexRange) |
54 | : data(new QOpcUaWriteItemData) |
55 | { |
56 | setNodeId(nodeId); |
57 | setAttribute(attribute); |
58 | setValue(value); |
59 | setType(type); |
60 | setIndexRange(indexRange); |
61 | } |
62 | |
63 | /*! |
64 | Sets the values from \a rhs in this write item. |
65 | */ |
66 | QOpcUaWriteItem &QOpcUaWriteItem::operator=(const QOpcUaWriteItem &rhs) |
67 | { |
68 | if (this != &rhs) |
69 | data.operator=(o: rhs.data); |
70 | return *this; |
71 | } |
72 | |
73 | QOpcUaWriteItem::~QOpcUaWriteItem() |
74 | { |
75 | } |
76 | |
77 | /*! |
78 | Returns the node id of the write item. |
79 | */ |
80 | QString QOpcUaWriteItem::nodeId() const |
81 | { |
82 | return data->nodeId; |
83 | } |
84 | |
85 | /*! |
86 | Sets the node id of the write item to \a nodeId. |
87 | */ |
88 | void QOpcUaWriteItem::setNodeId(const QString &nodeId) |
89 | { |
90 | data->nodeId = nodeId; |
91 | } |
92 | |
93 | /*! |
94 | Returns the attribute of the write item. |
95 | */ |
96 | QOpcUa::NodeAttribute QOpcUaWriteItem::attribute() const |
97 | { |
98 | return data->attribute; |
99 | } |
100 | |
101 | /*! |
102 | Sets the attribute of the write item to \a attribute. |
103 | */ |
104 | void QOpcUaWriteItem::setAttribute(QOpcUa::NodeAttribute attribute) |
105 | { |
106 | data->attribute = attribute; |
107 | } |
108 | |
109 | /*! |
110 | Returns the index range of the write item. |
111 | */ |
112 | QString QOpcUaWriteItem::indexRange() const |
113 | { |
114 | return data->indexRange; |
115 | } |
116 | |
117 | /*! |
118 | Sets the index range of the write item to \a indexRange. |
119 | */ |
120 | void QOpcUaWriteItem::setIndexRange(const QString &indexRange) |
121 | { |
122 | data->indexRange = indexRange; |
123 | } |
124 | |
125 | /*! |
126 | Returns the value of the write item. |
127 | */ |
128 | QVariant QOpcUaWriteItem::value() const |
129 | { |
130 | return data->value; |
131 | } |
132 | |
133 | /*! |
134 | Sets the value of the write item to \a value. |
135 | If given, the type information from \l setType() will be used in converting |
136 | the value to a SDK specific data type. |
137 | |
138 | \sa setType() |
139 | */ |
140 | void QOpcUaWriteItem::setValue(const QVariant &value) |
141 | { |
142 | data->value = value; |
143 | } |
144 | |
145 | /*! |
146 | Sets the value of the write item to \value and the type of the value to \a type. |
147 | */ |
148 | void QOpcUaWriteItem::setValue(const QVariant &value, QOpcUa::Types type) |
149 | { |
150 | data->value = value; |
151 | data->type = type; |
152 | } |
153 | |
154 | /*! |
155 | Returns the type of the value of the write item. |
156 | */ |
157 | QOpcUa::Types QOpcUaWriteItem::type() const |
158 | { |
159 | return data->type; |
160 | } |
161 | |
162 | /*! |
163 | Sets the type of the value of the write item to \a type. |
164 | */ |
165 | void QOpcUaWriteItem::setType(QOpcUa::Types type) |
166 | { |
167 | data->type = type; |
168 | } |
169 | |
170 | /*! |
171 | Returns the source timestamp for the value to write. |
172 | */ |
173 | QDateTime QOpcUaWriteItem::sourceTimestamp() const |
174 | { |
175 | return data->sourceTimestamp; |
176 | } |
177 | |
178 | /*! |
179 | Sets the source timestamp for the value to write to \a sourceTimestamp. |
180 | If the source timestamp is invalid, it is ignored by the client and not sent to the server. |
181 | If the server doesn't support writing timestamps, the write operation for this item |
182 | will fail with status code \l {QOpcUa::UaStatusCode} {BadWriteNotSupported}. |
183 | */ |
184 | void QOpcUaWriteItem::setSourceTimestamp(const QDateTime &sourceTimestamp) |
185 | { |
186 | data->sourceTimestamp = sourceTimestamp; |
187 | } |
188 | |
189 | /*! |
190 | Returns the server timestamp for the value to write. |
191 | */ |
192 | QDateTime QOpcUaWriteItem::serverTimestamp() const |
193 | { |
194 | return data->serverTimestamp; |
195 | } |
196 | |
197 | /*! |
198 | Sets the server timestamp for the value to write to \a serverTimestamp. |
199 | If the server timestamp is invalid, it is ignored by the client and not sent to the server. |
200 | If the server doesn't support writing timestamps, the write operation for this item |
201 | will fail with status code \l {QOpcUa::UaStatusCode} {BadWriteNotSupported}. |
202 | */ |
203 | void QOpcUaWriteItem::setServerTimestamp(const QDateTime &serverTimestamp) |
204 | { |
205 | data->serverTimestamp = serverTimestamp; |
206 | } |
207 | |
208 | /*! |
209 | Returns the status code for the value to write. |
210 | */ |
211 | QOpcUa::UaStatusCode QOpcUaWriteItem::statusCode() const |
212 | { |
213 | return data->statusCode; |
214 | } |
215 | |
216 | /*! |
217 | Returns true if a status code for the value to write has been set. |
218 | */ |
219 | bool QOpcUaWriteItem::hasStatusCode() const |
220 | { |
221 | return data->statusCode; |
222 | } |
223 | |
224 | /*! |
225 | Sets the status code for the value to write to \a statusCode. |
226 | If no status code is set, no status code is sent to the server. |
227 | */ |
228 | void QOpcUaWriteItem::setStatusCode(QOpcUa::UaStatusCode statusCode) |
229 | { |
230 | data->statusCode = statusCode; |
231 | data->hasStatusCode = true; |
232 | } |
233 | |
234 | QT_END_NAMESPACE |
235 | |