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/opcuaeventfilter_p.h> |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \qmltype EventFilter |
10 | \inqmlmodule QtOpcUa |
11 | \brief Defines an EventFilter for a monitored item. |
12 | \since QtOpcUa 5.13 |
13 | |
14 | An event filter is required for monitoring events on the server. |
15 | It consists of \c select clauses and a \c where clause. |
16 | |
17 | The \c select clauses are used to specify the data the user wants to receive when an event occurs. |
18 | It consists of \l {SimpleAttributeOperand} simple attribute operands which select |
19 | attributes of child nodes of an event type, for example the value attribute of the "Message" |
20 | property of BaseEventType. |
21 | |
22 | The \c where clause is used to restrict the reported events by matching against certain criteria. |
23 | Several operators and four different operand types allow filtering based on the values of the |
24 | attributes of the child nodes of an event type. |
25 | |
26 | The select clause consists of an array of \l SimpleAttributeOperand. |
27 | The where clause consists of an array of \l SimpleAttributeOperand, \l LiteralOperand, \l ElementOperand or \l AttributeOperand. |
28 | |
29 | The following EventFilter tells the server to report the value of the "Message" field for events that have a "Severity" field with value >= 500: |
30 | |
31 | \code |
32 | import QtOpcUa as QtOpcUa |
33 | QtOpcUa.Node { |
34 | ... |
35 | |
36 | eventFilter: QtOpcUa.EventFilter { |
37 | select: [ |
38 | QtOpcUa.SimpleAttributeOperand { |
39 | browsePath: [ |
40 | QtOpcUa.NodeId { |
41 | identifier: "Severity" |
42 | ns: "http://opcfoundation.org/UA/" |
43 | } |
44 | ] |
45 | }, |
46 | QtOpcUa.SimpleAttributeOperand { |
47 | browsePath: [ |
48 | QtOpcUa.NodeId { |
49 | identifier: "Message" |
50 | ns: "http://opcfoundation.org/UA/" |
51 | } |
52 | ] |
53 | } |
54 | ] |
55 | |
56 | where: [ |
57 | QtOpcUa.FilterElement { |
58 | operator: QtOpcUa.FilterElement.GreaterThanOrEqual |
59 | firstOperand: QtOpcUa.SimpleAttributeOperand { |
60 | browsePath: [ |
61 | QtOpcUa.NodeId { |
62 | identifier: "Severity" |
63 | ns: "http://opcfoundation.org/UA/" |
64 | } |
65 | ] |
66 | } |
67 | secondOperand: QtOpcUa.LiteralOperand { |
68 | value: 700 |
69 | type: QtOpcUa.Constants.UInt16 |
70 | } |
71 | } |
72 | ] |
73 | } |
74 | } |
75 | \endcode |
76 | |
77 | For a more complex example with two conditions, see \l QOpcUaElementOperand. |
78 | |
79 | \sa FilterElement |
80 | */ |
81 | |
82 | /*! |
83 | \qmlproperty list<FilterElement> EventFilter::where |
84 | |
85 | Content filter used to restrict the reported events to events matching certain criteria. |
86 | */ |
87 | |
88 | /*! |
89 | \qmlproperty list<SimpleAttributeOperand> EventFilter::select |
90 | |
91 | Selected event fields that shall be included when a new event is reported. |
92 | */ |
93 | |
94 | OpcUaEventFilter::OpcUaEventFilter(QObject *parent) |
95 | : QObject(parent) |
96 | { |
97 | } |
98 | |
99 | OpcUaEventFilter::~OpcUaEventFilter() = default; |
100 | |
101 | bool OpcUaEventFilter::operator==(const OpcUaEventFilter &other) const |
102 | { |
103 | return this->m_filterElements == other.m_filterElements |
104 | && this->m_selectors == other.m_selectors; |
105 | } |
106 | |
107 | QOpcUaMonitoringParameters::EventFilter OpcUaEventFilter::filter(QOpcUaClient *client) const |
108 | { |
109 | QOpcUaMonitoringParameters::EventFilter filterValue; |
110 | for (const auto &i : std::as_const(t: m_selectors)) |
111 | filterValue.selectClausesRef().append(t: i->toSimpleAttributeOperand(client)); |
112 | |
113 | for (const auto &i : std::as_const(t: m_filterElements)) |
114 | filterValue.whereClauseRef().append(t: i->toFilterElement(client)); |
115 | |
116 | return filterValue; |
117 | } |
118 | |
119 | QQmlListProperty<OpcUaFilterElement> OpcUaEventFilter::filterElements() |
120 | { |
121 | return QQmlListProperty<OpcUaFilterElement>(this, this, |
122 | &OpcUaEventFilter::appendFilterElement, |
123 | &OpcUaEventFilter::filterElementCount, |
124 | &OpcUaEventFilter::filterElement, |
125 | &OpcUaEventFilter::clearFilterElements); |
126 | } |
127 | |
128 | void OpcUaEventFilter::appendFilterElement(OpcUaFilterElement *nodeId) |
129 | { |
130 | m_filterElements.append(t: nodeId); |
131 | emit dataChanged(); |
132 | } |
133 | |
134 | int OpcUaEventFilter::filterElementCount() const |
135 | { |
136 | return m_filterElements.size(); |
137 | } |
138 | |
139 | OpcUaFilterElement *OpcUaEventFilter::filterElement(int index) const |
140 | { |
141 | return m_filterElements.at(i: index); |
142 | } |
143 | |
144 | void OpcUaEventFilter::clearFilterElements() |
145 | { |
146 | m_filterElements.clear(); |
147 | emit dataChanged(); |
148 | } |
149 | |
150 | void OpcUaEventFilter::appendFilterElement(QQmlListProperty<OpcUaFilterElement> *list, OpcUaFilterElement *nodeId) |
151 | { |
152 | reinterpret_cast<OpcUaEventFilter*>(list->data)->appendFilterElement(nodeId); |
153 | } |
154 | |
155 | qsizetype OpcUaEventFilter::filterElementCount(QQmlListProperty<OpcUaFilterElement> *list) |
156 | { |
157 | return reinterpret_cast<OpcUaEventFilter*>(list->data)->filterElementCount(); |
158 | } |
159 | |
160 | OpcUaFilterElement *OpcUaEventFilter::filterElement(QQmlListProperty<OpcUaFilterElement> *list, qsizetype index) |
161 | { |
162 | return reinterpret_cast<OpcUaEventFilter*>(list->data)->filterElement(index); |
163 | } |
164 | |
165 | void OpcUaEventFilter::clearFilterElements(QQmlListProperty<OpcUaFilterElement> *list) |
166 | { |
167 | reinterpret_cast<OpcUaEventFilter*>(list->data)->clearFilterElements(); |
168 | } |
169 | |
170 | QQmlListProperty<OpcUaSimpleAttributeOperand> OpcUaEventFilter::selectors() |
171 | { |
172 | return QQmlListProperty<OpcUaSimpleAttributeOperand>(this, this, |
173 | &OpcUaEventFilter::appendSelector, |
174 | &OpcUaEventFilter::selectorCount, |
175 | &OpcUaEventFilter::selector, |
176 | &OpcUaEventFilter::clearSelectors); |
177 | } |
178 | |
179 | void OpcUaEventFilter::appendSelector(OpcUaSimpleAttributeOperand *nodeId) |
180 | { |
181 | m_selectors.append(t: nodeId); |
182 | emit dataChanged(); |
183 | } |
184 | |
185 | int OpcUaEventFilter::selectorCount() const |
186 | { |
187 | return m_selectors.size(); |
188 | } |
189 | |
190 | OpcUaSimpleAttributeOperand *OpcUaEventFilter::selector(int index) const |
191 | { |
192 | return m_selectors.at(i: index); |
193 | } |
194 | |
195 | void OpcUaEventFilter::clearSelectors() |
196 | { |
197 | m_selectors.clear(); |
198 | emit dataChanged(); |
199 | } |
200 | |
201 | void OpcUaEventFilter::appendSelector(QQmlListProperty<OpcUaSimpleAttributeOperand> *list, OpcUaSimpleAttributeOperand *nodeId) |
202 | { |
203 | reinterpret_cast<OpcUaEventFilter*>(list->data)->appendSelector(nodeId); |
204 | } |
205 | |
206 | qsizetype OpcUaEventFilter::selectorCount(QQmlListProperty<OpcUaSimpleAttributeOperand> *list) |
207 | { |
208 | return reinterpret_cast<OpcUaEventFilter*>(list->data)->selectorCount(); |
209 | } |
210 | |
211 | OpcUaSimpleAttributeOperand *OpcUaEventFilter::selector(QQmlListProperty<OpcUaSimpleAttributeOperand> *list, qsizetype index) |
212 | { |
213 | return reinterpret_cast<OpcUaEventFilter*>(list->data)->selector(index); |
214 | } |
215 | |
216 | void OpcUaEventFilter::clearSelectors(QQmlListProperty<OpcUaSimpleAttributeOperand> *list) |
217 | { |
218 | reinterpret_cast<OpcUaEventFilter*>(list->data)->clearSelectors(); |
219 | } |
220 | |
221 | QT_END_NAMESPACE |
222 | |