1 | // Copyright (C) 2017 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 "qopcuamonitoringparameters.h" |
5 | #include "private/qopcuamonitoringparameters_p.h" |
6 | #include <QtOpcUa/qopcuaeventfilterresult.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \class QOpcUaMonitoringParameters |
12 | \inmodule QtOpcUa |
13 | |
14 | \brief QOpcUaMonitoringParameters provides a way to set and retrieve parameters for subscriptions and monitored items. |
15 | |
16 | This class is used in \l QOpcUaNode::enableMonitoring() requests |
17 | and as return value for \l QOpcUaNode::monitoringStatus() in which case it contains |
18 | the revised values from the server. |
19 | |
20 | \section1 Usage |
21 | For most use cases, only the publishing interval is required. |
22 | \code |
23 | QOpcUaMonitoringParameters p(100); // Set a publishing interval of 100ms and share the subscription. |
24 | node->enableMonitoring(QOpcUa::NodeAttribute::Value, p); |
25 | \endcode |
26 | If an \l {QOpcUaMonitoringParameters::SubscriptionType} {exclusive} subscription is required, use the second parameter. |
27 | \code |
28 | QOpcUaMonitoringParameters p(100, QOpcUaMonitoringParameters::SubscriptionType::Exclusive); // Create a new subscription |
29 | \endcode |
30 | To add additional items to an existing subscription, use the third parameter for the next calls to QOpcUaNode::enableMonitoring(). |
31 | \code |
32 | quint32 subscriptionId = node->monitoringStatus(QOpcUa::NodeAttribute::Value).subscriptionId(); |
33 | QOpcUaMonitoringParameters p(100, QOpcUaMonitoringParameters::SubscriptionType::Shared, subscriptionId); // Add the monitored item to this subscription |
34 | \endcode |
35 | |
36 | If other parameters are required, they must be set using the setter methods. |
37 | |
38 | \section1 Backend support |
39 | Not all parameters in this class are supported by all backends. |
40 | \table |
41 | \header |
42 | \li Parameter |
43 | \li Open62541 plugin |
44 | \li UACpp plugin |
45 | \row |
46 | \li PublishingInterval |
47 | \li X |
48 | \li X |
49 | \row |
50 | \li SamplingInterval |
51 | \li X |
52 | \li X |
53 | \row |
54 | \li LifetimeCount |
55 | \li X |
56 | \li X |
57 | \row |
58 | \li MaxKeepAliveCount |
59 | \li X |
60 | \li X |
61 | \row |
62 | \li Priority |
63 | \li X |
64 | \li X |
65 | \row |
66 | \li IndexRange |
67 | \li X |
68 | \li X |
69 | \row |
70 | \li Shared |
71 | \li X |
72 | \li X |
73 | \row |
74 | \li SubscriptionId |
75 | \li X |
76 | \li X |
77 | \row |
78 | \li PublishingEnabled |
79 | \li X |
80 | \li X |
81 | \row |
82 | \li Filter |
83 | \li X |
84 | \li X |
85 | \row |
86 | \li QueueSize |
87 | \li X |
88 | \li X |
89 | \row |
90 | \li DiscardOldest |
91 | \li X |
92 | \li X |
93 | \row |
94 | \li MonitoringMode |
95 | \li X |
96 | \li X |
97 | \row |
98 | \li IndexRange |
99 | \li X |
100 | \li X |
101 | \row |
102 | \li MaxNotificationsPerPublish |
103 | \li X |
104 | \li X |
105 | \endtable |
106 | */ |
107 | |
108 | /*! |
109 | \enum QOpcUaMonitoringParameters::MonitoringMode |
110 | |
111 | This enum is used to set the monitoring mode for a monitored item. |
112 | |
113 | \value Disabled Sampling is disabled and no notifications are being generated. |
114 | \value Sampling Sampling is enabled and notifications are generated and queued, but reporting is disabled. |
115 | \value Reporting Sampling is enabled, notifications are generated and queued, reporting is enabled. |
116 | */ |
117 | |
118 | /*! |
119 | \enum QOpcUaMonitoringParameters::SubscriptionType |
120 | |
121 | This enum is used to determine if the monitored item can be added to a shared subscription |
122 | or if a new subscription must be created. |
123 | |
124 | \value Shared Share subscription with other monitored items with the same interval |
125 | \value Exclusive Request a new subscription for this attribute |
126 | */ |
127 | |
128 | /*! |
129 | \enum QOpcUaMonitoringParameters::Parameter |
130 | |
131 | Enumerates parameters that can be modified at runtime using \l QOpcUaNode::modifyMonitoring(). |
132 | Not all values are guaranteed to be supported by all plugins. Lack of support will be reported |
133 | in the \l QOpcUaNode::monitoringStatusChanged signal. |
134 | |
135 | \value PublishingEnabled |
136 | \value PublishingInterval |
137 | \value LifetimeCount |
138 | \value MaxKeepAliveCount |
139 | \value MaxNotificationsPerPublish |
140 | \value Priority |
141 | \value SamplingInterval |
142 | \value Filter |
143 | \value QueueSize |
144 | \value DiscardOldest |
145 | \value MonitoringMode |
146 | */ |
147 | |
148 | /*! |
149 | The default constructor for QOpcUaMonitoringParameters. |
150 | */ |
151 | QOpcUaMonitoringParameters::QOpcUaMonitoringParameters() |
152 | : d_ptr(new QOpcUaMonitoringParametersPrivate()) |
153 | {} |
154 | |
155 | /*! |
156 | The destructor for QOpcUaMonitoringParameters. |
157 | */ |
158 | QOpcUaMonitoringParameters::~QOpcUaMonitoringParameters() |
159 | {} |
160 | |
161 | /*! |
162 | This is the constructor which covers most use cases for the Qt OPC UA user. |
163 | \a publishingInterval must be supplied, \a shared and \a subscriptionId are optional. |
164 | */ |
165 | QOpcUaMonitoringParameters::QOpcUaMonitoringParameters(double publishingInterval, QOpcUaMonitoringParameters::SubscriptionType shared, quint32 subscriptionId) |
166 | : d_ptr(new QOpcUaMonitoringParametersPrivate) |
167 | { |
168 | d_ptr->publishingInterval = publishingInterval; |
169 | d_ptr->shared = shared; |
170 | d_ptr->subscriptionId = subscriptionId; |
171 | |
172 | } |
173 | |
174 | /*! |
175 | Constructs a QOpcuaMonitoringParameters object from the value of \a other. |
176 | */ |
177 | QOpcUaMonitoringParameters::QOpcUaMonitoringParameters(const QOpcUaMonitoringParameters &other) |
178 | : d_ptr(other.d_ptr) |
179 | {} |
180 | |
181 | /*! |
182 | Assigns the value of \a other to this object. |
183 | */ |
184 | QOpcUaMonitoringParameters &QOpcUaMonitoringParameters::operator=(const QOpcUaMonitoringParameters &other) |
185 | { |
186 | d_ptr = other.d_ptr; |
187 | return *this; |
188 | } |
189 | |
190 | /*! |
191 | Returns the subscription type. |
192 | */ |
193 | QOpcUaMonitoringParameters::SubscriptionType QOpcUaMonitoringParameters::subscriptionType() const |
194 | { |
195 | return d_ptr->shared; |
196 | } |
197 | |
198 | /*! |
199 | Request \a shared as subscription type for the subscription. |
200 | */ |
201 | void QOpcUaMonitoringParameters::setSubscriptionType(SubscriptionType shared) |
202 | { |
203 | d_ptr->shared = shared; |
204 | } |
205 | |
206 | /*! |
207 | Returns the index range for the monitored item. |
208 | */ |
209 | QString QOpcUaMonitoringParameters::indexRange() const |
210 | { |
211 | return d_ptr->indexRange; |
212 | } |
213 | |
214 | /*! |
215 | Requests \a indexRange as index range for the monitored item. |
216 | For details on the index range string, see QOpcUaNode::readAttributeRange(). |
217 | */ |
218 | void QOpcUaMonitoringParameters::setIndexRange(const QString &indexRange) |
219 | { |
220 | d_ptr->indexRange = indexRange; |
221 | } |
222 | |
223 | /*! |
224 | Returns the status code of the monitored item creation. |
225 | */ |
226 | QOpcUa::UaStatusCode QOpcUaMonitoringParameters::statusCode() const |
227 | { |
228 | return d_ptr->statusCode; |
229 | } |
230 | |
231 | /*! |
232 | Set the status code to \a statusCode. |
233 | */ |
234 | void QOpcUaMonitoringParameters::setStatusCode(QOpcUa::UaStatusCode statusCode) |
235 | { |
236 | d_ptr->statusCode = statusCode; |
237 | } |
238 | |
239 | /*! |
240 | Returns the publishing mode for the subscription. |
241 | */ |
242 | bool QOpcUaMonitoringParameters::isPublishingEnabled() const |
243 | { |
244 | return d_ptr->publishingEnabled; |
245 | } |
246 | |
247 | /*! |
248 | Set \a publishingEnabled as publishing mode for the subscription. |
249 | */ |
250 | void QOpcUaMonitoringParameters::setPublishingEnabled(bool publishingEnabled) |
251 | { |
252 | d_ptr->publishingEnabled = publishingEnabled; |
253 | } |
254 | |
255 | /*! |
256 | Returns the priority of the subscription used for the monitored item. |
257 | */ |
258 | quint8 QOpcUaMonitoringParameters::priority() const |
259 | { |
260 | return d_ptr->priority; |
261 | } |
262 | |
263 | /*! |
264 | Set \a priority as priority for the subscription. |
265 | */ |
266 | void QOpcUaMonitoringParameters::setPriority(quint8 priority) |
267 | { |
268 | d_ptr->priority = priority; |
269 | } |
270 | |
271 | /*! |
272 | Returns the maximum notifications per publish value of the subscription. |
273 | */ |
274 | quint32 QOpcUaMonitoringParameters::maxNotificationsPerPublish() const |
275 | { |
276 | return d_ptr->maxNotificationsPerPublish; |
277 | } |
278 | |
279 | /*! |
280 | Set \a maxNotificationsPerPublish as maximum notifications per publish value for the subscription. |
281 | */ |
282 | void QOpcUaMonitoringParameters::setMaxNotificationsPerPublish(quint32 maxNotificationsPerPublish) |
283 | { |
284 | d_ptr->maxNotificationsPerPublish = maxNotificationsPerPublish; |
285 | } |
286 | |
287 | /*! |
288 | Returns the maximum keepalive count of the subscription. |
289 | */ |
290 | quint32 QOpcUaMonitoringParameters::maxKeepAliveCount() const |
291 | { |
292 | return d_ptr->maxKeepAliveCount; |
293 | } |
294 | |
295 | /*! |
296 | Request \a maxKeepAliveCount as maximum keepalive count for the subscription. |
297 | */ |
298 | void QOpcUaMonitoringParameters::setMaxKeepAliveCount(quint32 maxKeepAliveCount) |
299 | { |
300 | d_ptr->maxKeepAliveCount = maxKeepAliveCount; |
301 | } |
302 | |
303 | /*! |
304 | Returns the lifetime count of the subscription. |
305 | */ |
306 | quint32 QOpcUaMonitoringParameters::lifetimeCount() const |
307 | { |
308 | return d_ptr->lifetimeCount; |
309 | } |
310 | |
311 | /*! |
312 | Request \a lifetimeCount as lifetime count for the subscription. |
313 | */ |
314 | void QOpcUaMonitoringParameters::setLifetimeCount(quint32 lifetimeCount) |
315 | { |
316 | d_ptr->lifetimeCount = lifetimeCount; |
317 | } |
318 | |
319 | /*! |
320 | Returns the publishing interval of the subscription. |
321 | The interval is expressed in milliseconds. |
322 | */ |
323 | double QOpcUaMonitoringParameters::publishingInterval() const |
324 | { |
325 | return d_ptr->publishingInterval; |
326 | } |
327 | |
328 | /*! |
329 | Request \a publishingInterval as publishing interval for the subscription. |
330 | The interval is expressed in milliseconds. |
331 | */ |
332 | void QOpcUaMonitoringParameters::setPublishingInterval(double publishingInterval) |
333 | { |
334 | d_ptr->publishingInterval = publishingInterval; |
335 | } |
336 | |
337 | /*! |
338 | Returns the assigned subscription id. |
339 | */ |
340 | quint32 QOpcUaMonitoringParameters::subscriptionId() const |
341 | { |
342 | return d_ptr->subscriptionId; |
343 | } |
344 | |
345 | /*! |
346 | Request the monitored items to be created on a known subscription with \a subscriptionId. |
347 | */ |
348 | void QOpcUaMonitoringParameters::setSubscriptionId(quint32 subscriptionId) |
349 | { |
350 | d_ptr->subscriptionId = subscriptionId; |
351 | } |
352 | |
353 | /*! |
354 | Returns the monitored item id assigned by the server. |
355 | If the monitored item id is 0, the monitored item could |
356 | not be successfully created. |
357 | */ |
358 | quint32 QOpcUaMonitoringParameters::monitoredItemId() const |
359 | { |
360 | return d_ptr->monitoredItemId; |
361 | } |
362 | |
363 | /*! |
364 | Sets the monitored item id to \a monitoredItemId. |
365 | |
366 | Setting this value as a client has no effect. |
367 | */ |
368 | void QOpcUaMonitoringParameters::setMonitoredItemId(quint32 monitoredItemId) |
369 | { |
370 | d_ptr->monitoredItemId = monitoredItemId; |
371 | } |
372 | |
373 | /*! |
374 | Returns the monitoring mode for the monitored item. |
375 | */ |
376 | QOpcUaMonitoringParameters::MonitoringMode QOpcUaMonitoringParameters::monitoringMode() const |
377 | { |
378 | return d_ptr->monitoringMode; |
379 | } |
380 | |
381 | /*! |
382 | Set \a monitoringMode as monitoring mode for the monitored item. |
383 | */ |
384 | void QOpcUaMonitoringParameters::setMonitoringMode(MonitoringMode monitoringMode) |
385 | { |
386 | d_ptr->monitoringMode = monitoringMode; |
387 | } |
388 | |
389 | /*! |
390 | Returns the discardOldest setting of the monitored item. |
391 | */ |
392 | bool QOpcUaMonitoringParameters::discardOldest() const |
393 | { |
394 | return d_ptr->discardOldest; |
395 | } |
396 | |
397 | /*! |
398 | Set \a discardOldest as discardOldest setting for the monitored item. |
399 | */ |
400 | void QOpcUaMonitoringParameters::setDiscardOldest(bool discardOldest) |
401 | { |
402 | d_ptr->discardOldest = discardOldest; |
403 | } |
404 | |
405 | /*! |
406 | Returns the queue size of the monitored item. |
407 | */ |
408 | quint32 QOpcUaMonitoringParameters::queueSize() const |
409 | { |
410 | return d_ptr->queueSize; |
411 | } |
412 | |
413 | /*! |
414 | Request \a queueSize as queue size for the monitored item. |
415 | */ |
416 | void QOpcUaMonitoringParameters::setQueueSize(quint32 queueSize) |
417 | { |
418 | d_ptr->queueSize = queueSize; |
419 | } |
420 | |
421 | /*! |
422 | Returns the current filter. |
423 | \sa setFilter() |
424 | */ |
425 | QVariant QOpcUaMonitoringParameters::filter() const |
426 | { |
427 | return d_ptr->filter; |
428 | } |
429 | |
430 | /*! |
431 | Sets \l DataChangeFilter \a filter as filter for the monitored item. |
432 | If another data change filter or an event filter is present, it will be replaced. |
433 | |
434 | If the server does not accept the filter, this will be indicated by the |
435 | status code after the \l QOpcUaNode::enableMonitoring() request has finished. |
436 | |
437 | \sa filter() |
438 | */ |
439 | void QOpcUaMonitoringParameters::setFilter(const QOpcUaMonitoringParameters::DataChangeFilter &filter) |
440 | { |
441 | d_ptr->filter = QVariant::fromValue(value: filter); |
442 | } |
443 | |
444 | /*! |
445 | Request \a eventFilter as filter for the monitored item. |
446 | If another event filter or a data change filter is present, it will be replaced. |
447 | If the server does not accept the filter, this will be indicated by the |
448 | status code and the event filter result after the \l QOpcUaNode::enableMonitoring() |
449 | request has finished. |
450 | |
451 | \sa filter() |
452 | */ |
453 | void QOpcUaMonitoringParameters::setFilter(const EventFilter &eventFilter) |
454 | { |
455 | d_ptr->filter = QVariant::fromValue(value: eventFilter); |
456 | } |
457 | |
458 | /*! |
459 | Removes the current filter from the monitoring parameters. |
460 | |
461 | \sa filter() setFilter() |
462 | */ |
463 | void QOpcUaMonitoringParameters::clearFilter() |
464 | { |
465 | d_ptr->filter.clear(); |
466 | } |
467 | |
468 | /*! |
469 | Returns the filter result. |
470 | |
471 | This value is empty for an attribute monitoring. In case of an event monitoring, |
472 | the filter result can be empty if the server did not detect any errors in the filter. |
473 | */ |
474 | QVariant QOpcUaMonitoringParameters::filterResult() const |
475 | { |
476 | return d_ptr->filterResult; |
477 | } |
478 | |
479 | /*! |
480 | Sets the event filter result to \a eventFilterResult. |
481 | |
482 | This method must only be used by the backend, setting an event filter result as a user |
483 | does not have any effect. |
484 | |
485 | \sa filterResult() |
486 | */ |
487 | void QOpcUaMonitoringParameters::setFilterResult(const QOpcUaEventFilterResult &eventFilterResult) |
488 | { |
489 | d_ptr->filterResult = QVariant::fromValue(value: eventFilterResult); |
490 | } |
491 | |
492 | /*! |
493 | Removes the current filter result from the monitoring parameters. |
494 | |
495 | \sa filterResult() setFilterResult() |
496 | */ |
497 | void QOpcUaMonitoringParameters::clearFilterResult() |
498 | { |
499 | d_ptr->filterResult.clear(); |
500 | } |
501 | |
502 | /*! |
503 | Returns the revised sampling interval of the monitored item. |
504 | The interval is expressed in milliseconds. |
505 | */ |
506 | double QOpcUaMonitoringParameters::samplingInterval() const |
507 | { |
508 | return d_ptr->samplingInterval; |
509 | } |
510 | |
511 | /*! |
512 | Request \a samplingInterval as sampling interval for the monitored item. |
513 | The interval is expressed in milliseconds. |
514 | */ |
515 | void QOpcUaMonitoringParameters::setSamplingInterval(double samplingInterval) |
516 | { |
517 | d_ptr->samplingInterval = samplingInterval; |
518 | } |
519 | |
520 | /*! |
521 | \class QOpcUaMonitoringParameters::DataChangeFilter |
522 | \inmodule QtOpcUa |
523 | \inheaderfile QOpcUaMonitoringParameters |
524 | \brief Defines a DataChangeFilter for a monitored item. |
525 | |
526 | This class is used to set up filtering for a DataChange monitored item. |
527 | It is defined in OPC-UA part 4, 7.12.2. |
528 | */ |
529 | |
530 | /*! |
531 | \enum QOpcUaMonitoringParameters::DataChangeFilter::DataChangeTrigger |
532 | |
533 | Enumerates the possible triggers for a \l DataChangeFilter. |
534 | |
535 | \value Status Triggers if the value's status code changes. |
536 | \value StatusOrValue Triggers if the value's status code or the value itself changes. |
537 | \value StatusOrValueOrTimestamp Triggers if the value's status code, the value itself or the source timestamp changes. |
538 | */ |
539 | |
540 | /*! |
541 | \enum QOpcUaMonitoringParameters::DataChangeFilter::DeadbandType |
542 | |
543 | Enumerates the possible deadband types for a \l DataChangeFilter. |
544 | |
545 | \value None No deadband filtering. |
546 | \value Absolute A notification is generated if the absolute value of the difference between the last cached value |
547 | and the current value is greater than the deadband value. |
548 | \value Percent Only valid for AnalogItems with an EURange property. A notification is generated if the absolute value |
549 | of the difference between the last cached value and the current value is greater than value percent of the EURange. |
550 | */ |
551 | |
552 | class QOpcUaMonitoringParameters::DataChangeFilterData : public QSharedData |
553 | { |
554 | public: |
555 | DataChangeFilterData() |
556 | : trigger(DataChangeFilter::DataChangeTrigger::Status) |
557 | , deadbandType(DataChangeFilter::DeadbandType::None) |
558 | , deadbandValue(0) |
559 | {} |
560 | |
561 | DataChangeFilter::DataChangeTrigger trigger; |
562 | DataChangeFilter::DeadbandType deadbandType; |
563 | double deadbandValue; |
564 | }; |
565 | |
566 | /*! |
567 | Constructs a data change filter with trigger on \c status, deadband type \c none and deadbandValue \c 0. |
568 | */ |
569 | QOpcUaMonitoringParameters::DataChangeFilter::DataChangeFilter() |
570 | : data(new QOpcUaMonitoringParameters::DataChangeFilterData) |
571 | { |
572 | } |
573 | |
574 | /*! |
575 | Constructs a data change filter from \a rhs. |
576 | */ |
577 | QOpcUaMonitoringParameters::DataChangeFilter::DataChangeFilter(const DataChangeFilter &rhs) |
578 | : data(rhs.data) |
579 | { |
580 | } |
581 | |
582 | /*! |
583 | Constructs a data change filter with trigger \a trigger, deadband type \a deadbandType and deadband value \a deadbandValue. |
584 | */ |
585 | QOpcUaMonitoringParameters::DataChangeFilter::DataChangeFilter(DataChangeFilter::DataChangeTrigger trigger, |
586 | DataChangeFilter::DeadbandType deadbandType, double deadbandValue) |
587 | : data(new QOpcUaMonitoringParameters::DataChangeFilterData) |
588 | { |
589 | data->trigger = trigger; |
590 | data->deadbandType = deadbandType; |
591 | data->deadbandValue = deadbandValue; |
592 | } |
593 | |
594 | /*! |
595 | Sets the values from \a rhs in this data change filter. |
596 | */ |
597 | QOpcUaMonitoringParameters::DataChangeFilter &QOpcUaMonitoringParameters::DataChangeFilter::operator=(const DataChangeFilter &rhs) |
598 | { |
599 | if (this != &rhs) |
600 | data.operator=(o: rhs.data); |
601 | return *this; |
602 | } |
603 | |
604 | /*! |
605 | Returns \c true if this data change filter has the same value as \a rhs. |
606 | */ |
607 | bool QOpcUaMonitoringParameters::DataChangeFilter::operator==(const QOpcUaMonitoringParameters::DataChangeFilter &rhs) const |
608 | { |
609 | return data->deadbandType == rhs.deadbandType() && |
610 | data->trigger == rhs.trigger() && |
611 | data->deadbandValue == rhs.deadbandValue(); |
612 | } |
613 | |
614 | QOpcUaMonitoringParameters::DataChangeFilter::~DataChangeFilter() |
615 | { |
616 | } |
617 | |
618 | /*! |
619 | Returns the deadband value. |
620 | */ |
621 | double QOpcUaMonitoringParameters::DataChangeFilter::deadbandValue() const |
622 | { |
623 | return data->deadbandValue; |
624 | } |
625 | |
626 | /*! |
627 | Sets the deadband value to \a deadbandValue. |
628 | */ |
629 | void QOpcUaMonitoringParameters::DataChangeFilter::setDeadbandValue(double deadbandValue) |
630 | { |
631 | data->deadbandValue = deadbandValue; |
632 | } |
633 | |
634 | /*! |
635 | Returns the deadband type. |
636 | */ |
637 | QOpcUaMonitoringParameters::DataChangeFilter::DeadbandType QOpcUaMonitoringParameters::DataChangeFilter::deadbandType() const |
638 | { |
639 | return data->deadbandType; |
640 | } |
641 | |
642 | /*! |
643 | Sets the deadband type to \a deadbandType. |
644 | */ |
645 | void QOpcUaMonitoringParameters::DataChangeFilter::setDeadbandType(DeadbandType deadbandType) |
646 | { |
647 | data->deadbandType = deadbandType; |
648 | } |
649 | |
650 | /*! |
651 | Returns the trigger. |
652 | */ |
653 | QOpcUaMonitoringParameters::DataChangeFilter::DataChangeTrigger QOpcUaMonitoringParameters::DataChangeFilter::trigger() const |
654 | { |
655 | return data->trigger; |
656 | } |
657 | |
658 | /*! |
659 | Sets the trigger to \a trigger. |
660 | */ |
661 | void QOpcUaMonitoringParameters::DataChangeFilter::setTrigger(DataChangeTrigger trigger) |
662 | { |
663 | data->trigger = trigger; |
664 | } |
665 | |
666 | /*! |
667 | Converts this data change filter to \l QVariant. |
668 | */ |
669 | QOpcUaMonitoringParameters::DataChangeFilter::operator QVariant() const |
670 | { |
671 | return QVariant::fromValue(value: *this); |
672 | } |
673 | |
674 | /*! |
675 | \class QOpcUaMonitoringParameters::EventFilter |
676 | \inmodule QtOpcUa |
677 | \inheaderfile QOpcUaMonitoringParameters |
678 | \brief Defines an EventFilter for a monitored item. |
679 | |
680 | An event filter is required for monitoring events on the server. |
681 | It consists of \c select clauses and a \c where clause. |
682 | |
683 | The \c select clauses are used to specify the data the user wants to receive when an event occurs. |
684 | It consists of \l {QOpcUaSimpleAttributeOperand} simple attribute operands which select |
685 | attributes of child nodes of an event type, for example the value attribute of the "Message" |
686 | property of BaseEventType. |
687 | |
688 | The \c where clause is used to restrict the reported events by matching against certain criteria. |
689 | Several operators and four different operand types allow filtering based on the values of the |
690 | attributes of the child nodes of an event type. |
691 | |
692 | Filters can be constructed using the setter or the streaming operator. Streaming a \l QOpcUaSimpleAttributeOperand |
693 | into an event filter adds a new \c select clause to the filter, a \l QOpcUaContentFilterElement is appended to the \c where clause. |
694 | A content filter element can be constructed by streaming operands of the types \l QOpcUaLiteralOperand, |
695 | \l QOpcUaElementOperand, \l QOpcUaAttributeOperand and \l QOpcUaSimpleAttributeOperand and an operator into a content |
696 | filter element. Only the last operator is used, previous operators will be discarded. |
697 | |
698 | The following EventFilter tells the server to report the value of the "Message" field for events that have a "Severity" field with value >= 500: |
699 | |
700 | \code |
701 | QOpcUaMonitoringParameters::EventFilter filter; |
702 | filter << QOpcUaSimpleAttributeOperand("Message"); // Select clause of the filter |
703 | |
704 | QOpcUaContentFilterElement condition; |
705 | condition << QOpcUaContentFilterElement::FilterOperator::GreaterThanOrEqual; |
706 | condition << QOpcUaSimpleAttributeOperand("Severity"); |
707 | condition << QOpcUaLiteralOperand(500, QOpcUa::Types::UInt16); |
708 | filter << condition; // Where clause of the filter |
709 | \endcode |
710 | |
711 | For a more complex example with two conditions, see \l QOpcUaElementOperand. |
712 | */ |
713 | |
714 | class QOpcUaMonitoringParameters::EventFilterData : public QSharedData |
715 | { |
716 | public: |
717 | QList<QOpcUaSimpleAttributeOperand> selectClauses; |
718 | QList<QOpcUaContentFilterElement> whereClause; |
719 | }; |
720 | |
721 | QOpcUaMonitoringParameters::EventFilter::EventFilter() |
722 | : data(new EventFilterData) |
723 | { |
724 | } |
725 | |
726 | /*! |
727 | Constructs an event filter from \a rhs. |
728 | */ |
729 | QOpcUaMonitoringParameters::EventFilter::EventFilter(const QOpcUaMonitoringParameters::EventFilter &rhs) |
730 | : data(rhs.data) |
731 | { |
732 | } |
733 | |
734 | /*! |
735 | Sets the values from \a rhs in this event filter. |
736 | */ |
737 | QOpcUaMonitoringParameters::EventFilter &QOpcUaMonitoringParameters::EventFilter::operator=(const QOpcUaMonitoringParameters::EventFilter &rhs) |
738 | { |
739 | if (this != &rhs) |
740 | data.operator=(o: rhs.data); |
741 | return *this; |
742 | } |
743 | |
744 | /*! |
745 | Returns \c true if this event filter has the same value as \a rhs. |
746 | */ |
747 | bool QOpcUaMonitoringParameters::EventFilter::operator==(const QOpcUaMonitoringParameters::EventFilter &rhs) const |
748 | { |
749 | return selectClauses() == rhs.selectClauses() && whereClause() == rhs.whereClause(); |
750 | } |
751 | |
752 | /*! |
753 | Adds the content filter element \a whereClauseElement to the where clause of this event filter. |
754 | */ |
755 | QOpcUaMonitoringParameters::EventFilter &QOpcUaMonitoringParameters::EventFilter::operator<<(const QOpcUaContentFilterElement &whereClauseElement) |
756 | { |
757 | whereClauseRef().append(t: whereClauseElement); |
758 | return *this; |
759 | } |
760 | |
761 | /*! |
762 | Adds the simple attribute operand \a selectClauseElement to the select clause of this content filter element. |
763 | */ |
764 | QOpcUaMonitoringParameters::EventFilter &QOpcUaMonitoringParameters::EventFilter::operator<<(const QOpcUaSimpleAttributeOperand &selectClauseElement) |
765 | { |
766 | selectClausesRef().append(t: selectClauseElement); |
767 | return *this; |
768 | } |
769 | |
770 | /*! |
771 | Converts this event filter to \l QVariant. |
772 | */ |
773 | QOpcUaMonitoringParameters::EventFilter::operator const QVariant() |
774 | { |
775 | return QVariant::fromValue(value: *this); |
776 | } |
777 | |
778 | QOpcUaMonitoringParameters::EventFilter::~EventFilter() |
779 | { |
780 | } |
781 | |
782 | /*! |
783 | Returns the content filter used to restrict the reported events to events matching certain criteria. |
784 | */ |
785 | QList<QOpcUaContentFilterElement> QOpcUaMonitoringParameters::EventFilter::whereClause() const |
786 | { |
787 | return data->whereClause; |
788 | } |
789 | |
790 | /*! |
791 | Returns a reference to the where clause. |
792 | |
793 | \sa whereClause() |
794 | */ |
795 | QList<QOpcUaContentFilterElement> &QOpcUaMonitoringParameters::EventFilter::whereClauseRef() |
796 | { |
797 | return data->whereClause; |
798 | } |
799 | |
800 | /*! |
801 | Sets the where clause to \a whereClause. |
802 | */ |
803 | void QOpcUaMonitoringParameters::EventFilter::setWhereClause(const QList<QOpcUaContentFilterElement> &whereClause) |
804 | { |
805 | data->whereClause = whereClause; |
806 | } |
807 | |
808 | /*! |
809 | Returns the selected event fields that shall be included when a new event is reported. |
810 | */ |
811 | QList<QOpcUaSimpleAttributeOperand> QOpcUaMonitoringParameters::EventFilter::selectClauses() const |
812 | { |
813 | return data->selectClauses; |
814 | } |
815 | |
816 | /*! |
817 | Returns a reference to the select clauses. |
818 | */ |
819 | QList<QOpcUaSimpleAttributeOperand> &QOpcUaMonitoringParameters::EventFilter::selectClausesRef() |
820 | { |
821 | return data->selectClauses; |
822 | } |
823 | |
824 | /*! |
825 | Sets the select clauses to \a selectClauses. |
826 | */ |
827 | void QOpcUaMonitoringParameters::EventFilter::setSelectClauses(const QList<QOpcUaSimpleAttributeOperand> &selectClauses) |
828 | { |
829 | data->selectClauses = selectClauses; |
830 | } |
831 | |
832 | QT_END_NAMESPACE |
833 | |