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