| 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 | |
| 6 | QT_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 | */ | 
| 26 | class QOpcUaReadResultData : public QSharedData | 
| 27 | { | 
| 28 | public: | 
| 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 | |
| 38 | /*! | 
| 39 | Default constructs a read result with no parameters set. | 
| 40 | */ | 
| 41 | QOpcUaReadResult::QOpcUaReadResult() | 
| 42 | : data(new QOpcUaReadResultData) | 
| 43 | { | 
| 44 | } | 
| 45 | |
| 46 | /*! | 
| 47 | Constructs a read result from \a other. | 
| 48 | */ | 
| 49 | QOpcUaReadResult::QOpcUaReadResult(const QOpcUaReadResult &other) | 
| 50 | : data(other.data) | 
| 51 | { | 
| 52 | } | 
| 53 | |
| 54 | /*! | 
| 55 | Sets the values from \a rhs in this read result. | 
| 56 | */ | 
| 57 | QOpcUaReadResult &QOpcUaReadResult::operator=(const QOpcUaReadResult &rhs) | 
| 58 | { | 
| 59 | if (this != &rhs) | 
| 60 | data.operator=(o: rhs.data); | 
| 61 | return *this; | 
| 62 | } | 
| 63 | |
| 64 | QOpcUaReadResult::~QOpcUaReadResult() | 
| 65 | { | 
| 66 | } | 
| 67 | |
| 68 | /*! | 
| 69 | Returns the value. | 
| 70 | */ | 
| 71 | QVariant QOpcUaReadResult::value() const | 
| 72 | { | 
| 73 | return data->value; | 
| 74 | } | 
| 75 | |
| 76 | /*! | 
| 77 | Sets the value to \a value. | 
| 78 | */ | 
| 79 | void QOpcUaReadResult::setValue(const QVariant &value) | 
| 80 | { | 
| 81 | data->value = value; | 
| 82 | } | 
| 83 | |
| 84 | /*! | 
| 85 | Returns the attribute id. | 
| 86 | */ | 
| 87 | QOpcUa::NodeAttribute QOpcUaReadResult::attribute() const | 
| 88 | { | 
| 89 | return data->attribute; | 
| 90 | } | 
| 91 | |
| 92 | /*! | 
| 93 | Sets the attribute id to \a attribute. | 
| 94 | */ | 
| 95 | void QOpcUaReadResult::setAttribute(QOpcUa::NodeAttribute attribute) | 
| 96 | { | 
| 97 | data->attribute = attribute; | 
| 98 | } | 
| 99 | |
| 100 | /*! | 
| 101 | Returns the index range. | 
| 102 | */ | 
| 103 | QString QOpcUaReadResult::indexRange() const | 
| 104 | { | 
| 105 | return data->indexRange; | 
| 106 | } | 
| 107 | |
| 108 | /*! | 
| 109 | Sets the index range to \a indexRange. | 
| 110 | */ | 
| 111 | void QOpcUaReadResult::setIndexRange(const QString &indexRange) | 
| 112 | { | 
| 113 | data->indexRange = indexRange; | 
| 114 | } | 
| 115 | |
| 116 | /*! | 
| 117 | Returns the node id. | 
| 118 | */ | 
| 119 | QString QOpcUaReadResult::nodeId() const | 
| 120 | { | 
| 121 | return data->nodeId; | 
| 122 | } | 
| 123 | |
| 124 | /*! | 
| 125 | Sets the node id to \a nodeId. | 
| 126 | */ | 
| 127 | void QOpcUaReadResult::setNodeId(const QString &nodeId) | 
| 128 | { | 
| 129 | data->nodeId = nodeId; | 
| 130 | } | 
| 131 | |
| 132 | /*! | 
| 133 | Returns the status code for this element. If the status code is not \l {QOpcUa::UaStatusCode} {Good}, the | 
| 134 | value and the timestamps are invalid. | 
| 135 | */ | 
| 136 | QOpcUa::UaStatusCode QOpcUaReadResult::statusCode() const | 
| 137 | { | 
| 138 | return data->statusCode; | 
| 139 | } | 
| 140 | |
| 141 | /*! | 
| 142 | Sets the status code to \a statusCode. | 
| 143 | */ | 
| 144 | void QOpcUaReadResult::setStatusCode(QOpcUa::UaStatusCode statusCode) | 
| 145 | { | 
| 146 | data->statusCode = statusCode; | 
| 147 | } | 
| 148 | |
| 149 | /*! | 
| 150 | Returns the source timestamp for \l value(). | 
| 151 | */ | 
| 152 | QDateTime QOpcUaReadResult::sourceTimestamp() const | 
| 153 | { | 
| 154 | return data->sourceTimestamp; | 
| 155 | } | 
| 156 | |
| 157 | /*! | 
| 158 | Sets the source timestamp to \a sourceTimestamp. | 
| 159 | */ | 
| 160 | void QOpcUaReadResult::setSourceTimestamp(const QDateTime &sourceTimestamp) | 
| 161 | { | 
| 162 | data->sourceTimestamp = sourceTimestamp; | 
| 163 | } | 
| 164 | |
| 165 | /*! | 
| 166 | Returns the server timestamp for \l value(). | 
| 167 | */ | 
| 168 | QDateTime QOpcUaReadResult::serverTimestamp() const | 
| 169 | { | 
| 170 | return data->serverTimestamp; | 
| 171 | } | 
| 172 | |
| 173 | /*! | 
| 174 | Sets the server timestamp to \a serverTimestamp. | 
| 175 | */ | 
| 176 | void QOpcUaReadResult::setServerTimestamp(const QDateTime &serverTimestamp) | 
| 177 | { | 
| 178 | data->serverTimestamp = serverTimestamp; | 
| 179 | } | 
| 180 | |
| 181 | QT_END_NAMESPACE | 
| 182 | 
