1 | // Copyright (C) 2021 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 "qopcuadatavalue.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QOpcUaDataValue |
10 | \inmodule QtOpcUa |
11 | \brief This class stores OPC UA value data and associated metadata. |
12 | \since 6.3 |
13 | |
14 | This class corresponds to the OPC UA DataValue type. |
15 | */ |
16 | class QOpcUaDataValueData : public QSharedData |
17 | { |
18 | public: |
19 | QDateTime serverTimestamp; |
20 | QDateTime sourceTimestamp; |
21 | QOpcUa::UaStatusCode statusCode {QOpcUa::UaStatusCode::Good}; |
22 | QVariant value; |
23 | }; |
24 | |
25 | /*! |
26 | Constructs an invalid data value. |
27 | */ |
28 | QOpcUaDataValue::QOpcUaDataValue() |
29 | : data(new QOpcUaDataValueData) |
30 | { |
31 | } |
32 | |
33 | /*! |
34 | Constructs a data value from \a other. |
35 | */ |
36 | QOpcUaDataValue::QOpcUaDataValue(const QOpcUaDataValue &other) |
37 | : data(other.data) |
38 | { |
39 | } |
40 | |
41 | /*! |
42 | Sets the values from \a other in this data value. |
43 | */ |
44 | QOpcUaDataValue &QOpcUaDataValue::operator=(const QOpcUaDataValue &other) |
45 | { |
46 | if (this != &other) |
47 | data.operator=(o: other.data); |
48 | return *this; |
49 | } |
50 | |
51 | /*! |
52 | Destroys the data value. |
53 | */ |
54 | QOpcUaDataValue::~QOpcUaDataValue() |
55 | { |
56 | } |
57 | |
58 | /*! |
59 | \fn QOpcUaDataValue::swap(QOpcUaDataValue &other) |
60 | |
61 | Swaps this data value instance with \a other. This function is very |
62 | fast and never fails. |
63 | */ |
64 | |
65 | /*! |
66 | Returns the value. |
67 | */ |
68 | QVariant QOpcUaDataValue::value() const |
69 | { |
70 | return data->value; |
71 | } |
72 | |
73 | /*! |
74 | Sets the value to \a value. |
75 | */ |
76 | void QOpcUaDataValue::setValue(const QVariant &value) |
77 | { |
78 | data.detach(); |
79 | data->value = value; |
80 | } |
81 | |
82 | /*! |
83 | Returns the status code for this data value. If the status code is not \l {QOpcUa::UaStatusCode} {Good}, the |
84 | value and the timestamps are invalid. |
85 | */ |
86 | QOpcUa::UaStatusCode QOpcUaDataValue::statusCode() const |
87 | { |
88 | return data->statusCode; |
89 | } |
90 | |
91 | /*! |
92 | Sets the status code to \a statusCode. |
93 | */ |
94 | void QOpcUaDataValue::setStatusCode(QOpcUa::UaStatusCode statusCode) |
95 | { |
96 | data.detach(); |
97 | data->statusCode = statusCode; |
98 | } |
99 | |
100 | /*! |
101 | Returns the source timestamp for \l value(). |
102 | */ |
103 | QDateTime QOpcUaDataValue::sourceTimestamp() const |
104 | { |
105 | return data->sourceTimestamp; |
106 | } |
107 | |
108 | /*! |
109 | Sets the source timestamp to \a sourceTimestamp. |
110 | */ |
111 | void QOpcUaDataValue::setSourceTimestamp(const QDateTime &sourceTimestamp) |
112 | { |
113 | data.detach(); |
114 | data->sourceTimestamp = sourceTimestamp; |
115 | } |
116 | |
117 | /*! |
118 | Returns the server timestamp for \l value(). |
119 | */ |
120 | QDateTime QOpcUaDataValue::serverTimestamp() const |
121 | { |
122 | return data->serverTimestamp; |
123 | } |
124 | |
125 | /*! |
126 | Sets the server timestamp to \a serverTimestamp. |
127 | */ |
128 | void QOpcUaDataValue::setServerTimestamp(const QDateTime &serverTimestamp) |
129 | { |
130 | data.detach(); |
131 | data->serverTimestamp = serverTimestamp; |
132 | } |
133 | |
134 | QT_END_NAMESPACE |
135 |