| 1 | // Copyright (C) 2018 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/opcuaattributecache_p.h> |
| 5 | #include <private/opcuaattributevalue_p.h> |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | /*! |
| 10 | \class OpcUaAttributeCache |
| 11 | \inqmlmodule QtOpcUa |
| 12 | \brief Flexible attribute value cache providing signals. |
| 13 | \internal |
| 14 | |
| 15 | This class is just for internal use in the declarative backend and not exposed to users. |
| 16 | |
| 17 | It caches node attribute values and provides access. Main purpose is to |
| 18 | let \l OpcUaAttributeValue provide separate value change signals for each attribute. |
| 19 | |
| 20 | \sa OpcUaAttributeValue |
| 21 | */ |
| 22 | |
| 23 | OpcUaAttributeCache::OpcUaAttributeCache(QObject *parent) : QObject(parent) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | void OpcUaAttributeCache::setAttributeValue(QOpcUa::NodeAttribute attr, const QVariant &value) |
| 28 | { |
| 29 | attribute(attribute: attr)->setValue(value); |
| 30 | } |
| 31 | |
| 32 | void OpcUaAttributeCache::invalidate() |
| 33 | { |
| 34 | // Reset all values in the cache to invalid. |
| 35 | // Do not clear() the cache because there are still objects with |
| 36 | // connections waiting for notifications |
| 37 | for (auto i = m_attributeCache.constBegin(); i != m_attributeCache.constEnd(); ++i) |
| 38 | i.value()->invalidate(); |
| 39 | } |
| 40 | |
| 41 | OpcUaAttributeValue *OpcUaAttributeCache::attribute(QOpcUa::NodeAttribute attr) |
| 42 | { |
| 43 | if (!m_attributeCache.contains(key: attr)) |
| 44 | m_attributeCache.insert(key: attr, value: new OpcUaAttributeValue(this)); |
| 45 | return m_attributeCache.value(key: attr); |
| 46 | } |
| 47 | |
| 48 | const QVariant &OpcUaAttributeCache::attributeValue(QOpcUa::NodeAttribute attr) |
| 49 | { |
| 50 | return attribute(attr)->value(); |
| 51 | } |
| 52 | |
| 53 | QT_END_NAMESPACE |
| 54 |
