1// Copyright (C) 2023 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 "qopcuahistoryreadeventrequest.h"
5
6#include <QtOpcUa/qopcuareaditem.h>
7
8#include <QtCore/qdatetime.h>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \class QOpcUaHistoryReadEventRequest
14 \inmodule QtOpcUa
15 \brief This class stores the necessary information to request historic data from a server.
16 \since 6.7
17
18 This is the Qt OPC UA representation for the OPC UA ReadEventDetails for reading historical data
19 defined in \l {https://reference.opcfoundation.org/Core/docs/Part11/6.4.2/} {OPC-UA part 11, 6.4.2}.
20
21 When requesting historic data from a server, several values need to be provided to the server
22 to know which data to collect. The QOpcUaHistoryReadEventRequest class provides the required values.
23 \a startTimestamp and \a endTimestamp define the timerange where historic events should be collected from.
24 \a nodesToRead defines from which nodes historic data should be collected.
25 \a numValuesPerNode defines the maximum number of events that should be returned per node.
26 \a filter is the event filter used to determine which events and which of their fields to return.
27*/
28class QOpcUaHistoryReadEventRequestData : public QSharedData
29{
30public:
31 QDateTime startTimestamp;
32 QDateTime endTimestamp;
33 quint32 numValuesPerNode = 0;
34 QList<QOpcUaReadItem> nodesToRead;
35 QOpcUaMonitoringParameters::EventFilter filter;
36};
37
38QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QOpcUaHistoryReadEventRequestData)
39
40/*!
41 Constructs an invalid QOpcUaHistoryReadEventRequest.
42 */
43QOpcUaHistoryReadEventRequest::QOpcUaHistoryReadEventRequest()
44 : data(new QOpcUaHistoryReadEventRequestData)
45{
46}
47
48/*!
49 Constructs a QOpcUaHistoryReadEventRequest item with the given values.
50*/
51QOpcUaHistoryReadEventRequest::QOpcUaHistoryReadEventRequest(const QList<QOpcUaReadItem> &nodesToRead,
52 const QDateTime &startTimestamp,
53 const QDateTime &endTimestamp,
54 const QOpcUaMonitoringParameters::EventFilter &filter)
55 : data(new QOpcUaHistoryReadEventRequestData)
56{
57 data->startTimestamp = startTimestamp;
58 data->endTimestamp = endTimestamp;
59 data->nodesToRead = nodesToRead;
60 data->filter = filter;
61}
62
63/*!
64 Constructs a QOpcUaHistoryReadEventRequest item from \a other.
65*/
66QOpcUaHistoryReadEventRequest::QOpcUaHistoryReadEventRequest(const QOpcUaHistoryReadEventRequest &other)
67 : data(other.data)
68{
69}
70
71/*!
72 Destroys the request object.
73 */
74QOpcUaHistoryReadEventRequest::~QOpcUaHistoryReadEventRequest()
75{
76}
77
78/*!
79 \fn QOpcUaHistoryReadEventRequest::QOpcUaHistoryReadEventRequest(QOpcUaHistoryReadEventRequest &&other)
80
81 Move-constructs a new read event request object from \a other.
82
83 \note The moved-from object \a other is placed in a
84 partially-formed state, in which the only valid operations are
85 destruction and assignment of a new value.
86*/
87
88/*!
89 \fn QOpcUaHistoryReadEventRequest &QOpcUaHistoryReadEventRequest::operator=(QOpcUaHistoryReadEventRequest &&other)
90
91 Move-assigns \a other to this QOpcUaHistoryReadEventRequest instance.
92
93 \note The moved-from object \a other is placed in a
94 partially-formed state, in which the only valid operations are
95 destruction and assignment of a new value.
96*/
97
98/*!
99 \fn void QOpcUaHistoryReadEventRequest::swap(QOpcUaHistoryReadEventRequest &other)
100
101 Swaps read event request object \a other with this read event request
102 object. This operation is very fast and never fails.
103*/
104
105/*!
106 Returns the start time stamp.
107*/
108QDateTime QOpcUaHistoryReadEventRequest::startTimestamp() const
109{
110 return data->startTimestamp;
111}
112
113/*!
114 Sets \a startTimestamp for the historical data to be fetched.
115*/
116void QOpcUaHistoryReadEventRequest::setStartTimestamp(const QDateTime &startTimestamp)
117{
118 if (!(data->startTimestamp == startTimestamp)) {
119 data.detach();
120 data->startTimestamp = startTimestamp;
121 }
122}
123
124/*!
125 Returns the end time stamp.
126*/
127QDateTime QOpcUaHistoryReadEventRequest::endTimestamp() const
128{
129 return data->endTimestamp;
130}
131
132/*!
133 Sets \a endTimestamp for the historical data to be fetched.
134*/
135void QOpcUaHistoryReadEventRequest::setEndTimestamp(const QDateTime &endTimestamp)
136{
137 if (!(data->endTimestamp == endTimestamp)) {
138 data.detach();
139 data->endTimestamp = endTimestamp;
140 }
141}
142
143/*!
144 Returns the number of values per node.
145*/
146quint32 QOpcUaHistoryReadEventRequest::numValuesPerNode() const
147{
148 return data->numValuesPerNode;
149}
150
151/*!
152 Sets \a numValuesPerNode to indicate the number of values per node to be
153 fetched.
154*/
155void QOpcUaHistoryReadEventRequest::setNumValuesPerNode(quint32 numValuesPerNode)
156{
157 if (!(data->numValuesPerNode == numValuesPerNode)) {
158 data.detach();
159 data->numValuesPerNode = numValuesPerNode;
160 }
161}
162
163/*!
164 Returns the event filter used to retrieve historical events.
165*/
166QOpcUaMonitoringParameters::EventFilter QOpcUaHistoryReadEventRequest::filter() const
167{
168 return data->filter;
169}
170
171/*!
172 Sets the event filter used to retrieve historical events to \a filter.
173*/
174void QOpcUaHistoryReadEventRequest::setFilter(const QOpcUaMonitoringParameters::EventFilter &filter)
175{
176 if (!(filter == data->filter)) {
177 data.detach();
178 data->filter = filter;
179 }
180}
181
182/*!
183 Returns the list of nodes to read.
184*/
185QList<QOpcUaReadItem> QOpcUaHistoryReadEventRequest::nodesToRead() const
186{
187 return data->nodesToRead;
188}
189
190/*!
191 Sets the \a nodesToRead list.
192*/
193void QOpcUaHistoryReadEventRequest::setNodesToRead(const QList<QOpcUaReadItem> &nodesToRead)
194{
195 if (nodesToRead != data->nodesToRead) {
196 data.detach();
197 data->nodesToRead = nodesToRead;
198 }
199}
200
201/*!
202 Adds a node to the \a nodeToRead list.
203*/
204void QOpcUaHistoryReadEventRequest::addNodeToRead(const QOpcUaReadItem &nodeToRead)
205{
206 data.detach();
207 data->nodesToRead.append(t: nodeToRead);
208}
209
210/*!
211 Sets the values from \a other in this QOpcUaHistoryReadEventRequest item.
212*/
213QOpcUaHistoryReadEventRequest &QOpcUaHistoryReadEventRequest::operator=(const QOpcUaHistoryReadEventRequest &other)
214{
215 if (this != &other)
216 data.operator=(o: other.data);
217 return *this;
218}
219
220/*!
221 \fn bool QOpcUaHistoryReadEventRequest::operator==(const QOpcUaHistoryReadEventRequest& lhs,
222 const QOpcUaHistoryReadEventRequest &rhs)
223
224 Returns \c true if \a lhs is equal to \a rhs; otherwise returns \c false.
225
226 Two QOpcUaHistoryReadEventRequest items are considered equal if their \c startTimestamp,
227 \c endTimestamp, \c numValuesPerNode, \c filter and \c nodesToRead are equal.
228*/
229bool comparesEqual(const QOpcUaHistoryReadEventRequest &lhs,
230 const QOpcUaHistoryReadEventRequest &rhs) noexcept
231{
232 return (lhs.data->startTimestamp == rhs.data->startTimestamp &&
233 lhs.data->endTimestamp == rhs.data->endTimestamp &&
234 lhs.data->numValuesPerNode == rhs.data->numValuesPerNode &&
235 lhs.data->nodesToRead == rhs.data->nodesToRead);
236}
237
238/*!
239 \fn bool QOpcUaHistoryReadEventRequest::operator!=(const QOpcUaHistoryReadEventRequest &lhs,
240 const QOpcUaHistoryReadEventRequest &rhs)
241
242 Returns \c true if \a lhs is not equal to \a rhs; otherwise returns \c false.
243
244 Two QOpcUaHistoryReadEventRequest items are considered not equal if their \c startTimestamp,
245 \c endTimestamp, \c numValuesPerNode, \c filter or \c nodesToRead are not equal.
246*/
247
248QT_END_NAMESPACE
249

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtopcua/src/opcua/client/qopcuahistoryreadeventrequest.cpp