| 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/opcuawriteitem_p.h> |
| 5 | #include <private/opcuawriteresult_p.h> |
| 6 | |
| 7 | #include <QJSValue> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | /*! |
| 12 | \qmltype WriteItem |
| 13 | \inqmlmodule QtOpcUa |
| 14 | \brief Specifies an item to be written to the server. |
| 15 | \since QtOpcUa 5.13 |
| 16 | \deprecated [6.9] |
| 17 | |
| 18 | This type is used to specify items to be written to the server using the function |
| 19 | \l Connection::writeNodeAttributes. |
| 20 | */ |
| 21 | |
| 22 | /*! |
| 23 | \qmlproperty Constants.NodeAttribute WriteItem::attribute |
| 24 | |
| 25 | Determines the attribute of the node to be written. |
| 26 | */ |
| 27 | |
| 28 | /*! |
| 29 | \qmlproperty string WriteItem::indexRange |
| 30 | |
| 31 | Determines the index range of the attribute to be written. |
| 32 | If not needed, leave this property empty. |
| 33 | */ |
| 34 | |
| 35 | /*! |
| 36 | \qmlproperty string Writetem::nodeId |
| 37 | |
| 38 | Determines the node id of the node to be written. |
| 39 | */ |
| 40 | |
| 41 | /*! |
| 42 | \qmlproperty variant WriteItem::ns |
| 43 | |
| 44 | Determines the namespace of the node to be written. |
| 45 | The namespace can be given by name or index. |
| 46 | If this property is given, any namespace in the node id will be |
| 47 | ignored. |
| 48 | */ |
| 49 | |
| 50 | /*! |
| 51 | \qmlproperty datetime WriteItem::serverTimestamp |
| 52 | |
| 53 | Sets the server timestamp for the value to be written. |
| 54 | If the server timestamp is invalid, it is ignored by the client and not sent to the server. |
| 55 | If the server doesn't support writing timestamps, the write operation for this item |
| 56 | will fail. |
| 57 | */ |
| 58 | |
| 59 | /*! |
| 60 | \qmlproperty datetime WriteItem::sourceTimestamp |
| 61 | |
| 62 | Sets the source timestamp for the value to write. |
| 63 | If the source timestamp is invalid, it is ignored by the client and not sent to the server. |
| 64 | If the server doesn't support writing timestamps, the write operation for this item |
| 65 | will fail. |
| 66 | */ |
| 67 | |
| 68 | /*! |
| 69 | \qmlproperty variant WriteItem::value |
| 70 | |
| 71 | Actual data that is requested to be written. |
| 72 | */ |
| 73 | |
| 74 | /*! |
| 75 | \qmlproperty variant WriteItem::valueType |
| 76 | |
| 77 | If given, the type information will be used in converting |
| 78 | the value to a SDK specific data type. |
| 79 | */ |
| 80 | |
| 81 | /*! |
| 82 | \qmlproperty OpcUaStatus WriteItem::statusCode |
| 83 | |
| 84 | Sets the status code for the value to write. |
| 85 | If no status code is set, no status code is sent to the server. |
| 86 | */ |
| 87 | |
| 88 | class OpcUaWriteItemData : public QSharedData |
| 89 | { |
| 90 | public: |
| 91 | QOpcUa::NodeAttribute attribute; |
| 92 | QString indexRange; |
| 93 | QString nodeId; |
| 94 | QVariant namespaceIdentifier; |
| 95 | QDateTime serverTimestamp; |
| 96 | QDateTime sourceTimestamp; |
| 97 | QVariant value; |
| 98 | QOpcUa::Types valueType = QOpcUa::Types::Undefined; |
| 99 | OpcUaStatus::Status statusCode; |
| 100 | bool hasStatusCode = false; |
| 101 | }; |
| 102 | |
| 103 | OpcUaWriteItem::OpcUaWriteItem() |
| 104 | : data(new OpcUaWriteItemData) |
| 105 | { |
| 106 | data->attribute = QOpcUa::NodeAttribute::Value; |
| 107 | } |
| 108 | |
| 109 | OpcUaWriteItem::OpcUaWriteItem(const OpcUaWriteItem &other) |
| 110 | : data(other.data) |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | OpcUaWriteItem &OpcUaWriteItem::operator=(const OpcUaWriteItem &rhs) |
| 115 | { |
| 116 | if (this != &rhs) |
| 117 | data.operator=(o: rhs.data); |
| 118 | return *this; |
| 119 | } |
| 120 | |
| 121 | OpcUaWriteItem::~OpcUaWriteItem() = default; |
| 122 | |
| 123 | const QString &OpcUaWriteItem::indexRange() const |
| 124 | { |
| 125 | return data->indexRange; |
| 126 | } |
| 127 | |
| 128 | void OpcUaWriteItem::setIndexRange(const QString &indexRange) |
| 129 | { |
| 130 | data->indexRange = indexRange; |
| 131 | } |
| 132 | |
| 133 | const QString &OpcUaWriteItem::nodeId() const |
| 134 | { |
| 135 | return data->nodeId; |
| 136 | } |
| 137 | |
| 138 | void OpcUaWriteItem::setNodeId(const QString &nodeId) |
| 139 | { |
| 140 | data->nodeId = nodeId; |
| 141 | } |
| 142 | |
| 143 | QOpcUa::NodeAttribute OpcUaWriteItem::attribute() const |
| 144 | { |
| 145 | return data->attribute; |
| 146 | } |
| 147 | |
| 148 | void OpcUaWriteItem::setAttribute(QOpcUa::NodeAttribute attribute) |
| 149 | { |
| 150 | data->attribute = attribute; |
| 151 | } |
| 152 | |
| 153 | const QVariant &OpcUaWriteItem::namespaceIdentifier() const |
| 154 | { |
| 155 | return data->namespaceIdentifier; |
| 156 | } |
| 157 | |
| 158 | void OpcUaWriteItem::setNamespaceIdentifier(const QVariant &namespaceIdentifier) |
| 159 | { |
| 160 | data->namespaceIdentifier = namespaceIdentifier; |
| 161 | } |
| 162 | |
| 163 | void OpcUaWriteItem::setServerTimestamp(const QDateTime &serverTimestamp) |
| 164 | { |
| 165 | data->serverTimestamp = serverTimestamp; |
| 166 | } |
| 167 | |
| 168 | const QDateTime &OpcUaWriteItem::serverTimestamp() const |
| 169 | { |
| 170 | return data->serverTimestamp; |
| 171 | } |
| 172 | |
| 173 | void OpcUaWriteItem::setSourceTimestamp(const QDateTime &sourceTimestamp) |
| 174 | { |
| 175 | data->sourceTimestamp = sourceTimestamp; |
| 176 | } |
| 177 | |
| 178 | const QDateTime &OpcUaWriteItem::sourceTimestamp() const |
| 179 | { |
| 180 | return data->sourceTimestamp; |
| 181 | } |
| 182 | |
| 183 | void OpcUaWriteItem::setValue(const QVariant &value) |
| 184 | { |
| 185 | auto tmp = value; |
| 186 | // In case of an array value the type is QJSValue, |
| 187 | // which has to be unpacked to recognized. |
| 188 | if (tmp.userType() == qMetaTypeId<QJSValue>()) |
| 189 | tmp = tmp.value<QJSValue>().toVariant(); |
| 190 | |
| 191 | data->value = tmp; |
| 192 | } |
| 193 | |
| 194 | const QVariant &OpcUaWriteItem::value() const |
| 195 | { |
| 196 | return data->value; |
| 197 | } |
| 198 | |
| 199 | QOpcUa::Types OpcUaWriteItem::valueType() const |
| 200 | { |
| 201 | return data->valueType; |
| 202 | } |
| 203 | |
| 204 | void OpcUaWriteItem::setValueType(QOpcUa::Types type) |
| 205 | { |
| 206 | data->valueType = type; |
| 207 | } |
| 208 | |
| 209 | OpcUaStatus::Status OpcUaWriteItem::statusCode() const |
| 210 | { |
| 211 | return data->statusCode; |
| 212 | } |
| 213 | |
| 214 | bool OpcUaWriteItem::hasStatusCode() const |
| 215 | { |
| 216 | return data->hasStatusCode; |
| 217 | } |
| 218 | |
| 219 | void OpcUaWriteItem::setStatusCode(OpcUaStatus::Status statusCode) |
| 220 | { |
| 221 | data->statusCode = statusCode; |
| 222 | data->hasStatusCode = true; |
| 223 | } |
| 224 | |
| 225 | OpcUaWriteItem OpcUaWriteItemFactory::create() |
| 226 | { |
| 227 | return OpcUaWriteItem(); |
| 228 | } |
| 229 | |
| 230 | QT_END_NAMESPACE |
| 231 | |
| 232 |
