1// Copyright (C) 2015 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#ifndef QOPCUANODE_H
5#define QOPCUANODE_H
6
7#include <QtOpcUa/qopcuabrowserequest.h>
8#include <QtOpcUa/qopcuaglobal.h>
9#include <QtOpcUa/qopcuamonitoringparameters.h>
10#include <QtOpcUa/qopcuareferencedescription.h>
11#include <QtOpcUa/qopcuatype.h>
12#include <QtOpcUa/qopcuabrowsepathtarget.h>
13#include <QtOpcUa/qopcuarelativepathelement.h>
14
15#include <QtCore/qdatetime.h>
16#include <QtCore/qdebug.h>
17#include <QtCore/qvariant.h>
18#include <QtCore/qobject.h>
19#include <QtCore/qmap.h>
20
21QT_BEGIN_NAMESPACE
22
23class QOpcUaNodePrivate;
24class QOpcUaNodeImpl;
25class QOpcUaClient;
26class QOpcUaHistoryReadRawRequest;
27class QOpcUaHistoryReadResponse;
28
29class Q_OPCUA_EXPORT QOpcUaNode : public QObject
30{
31 Q_OBJECT
32
33public:
34 Q_DECLARE_PRIVATE(QOpcUaNode)
35
36 static Q_DECL_CONSTEXPR QOpcUa::NodeAttributes mandatoryBaseAttributes();
37 static Q_DECL_CONSTEXPR QOpcUa::NodeAttributes allBaseAttributes();
38 typedef QMap<QOpcUa::NodeAttribute, QVariant> AttributeMap;
39
40 QOpcUaNode(QOpcUaNodeImpl *impl, QOpcUaClient *client, QObject *parent = nullptr);
41 virtual ~QOpcUaNode();
42
43 bool readAttributes(QOpcUa::NodeAttributes attributes = mandatoryBaseAttributes());
44 bool readAttributeRange(QOpcUa::NodeAttribute attribute, const QString &indexRange);
45 bool readValueAttribute();
46 QVariant attribute(QOpcUa::NodeAttribute attribute) const;
47 QVariant valueAttribute() const;
48 QOpcUa::UaStatusCode attributeError(QOpcUa::NodeAttribute attribute) const;
49 QOpcUa::UaStatusCode valueAttributeError() const;
50 QDateTime sourceTimestamp(QOpcUa::NodeAttribute attribute) const;
51 QDateTime serverTimestamp(QOpcUa::NodeAttribute attribute) const;
52 bool writeAttribute(QOpcUa::NodeAttribute attribute, const QVariant &value, QOpcUa::Types type = QOpcUa::Types::Undefined);
53 bool writeAttributeRange(QOpcUa::NodeAttribute attribute, const QVariant &value,
54 const QString &indexRange, QOpcUa::Types type = QOpcUa::Types::Undefined);
55 bool writeAttributes(const AttributeMap &toWrite, QOpcUa::Types valueAttributeType = QOpcUa::Types::Undefined);
56 bool writeValueAttribute(const QVariant &value, QOpcUa::Types type = QOpcUa::Types::Undefined);
57
58 bool enableMonitoring(QOpcUa::NodeAttributes attr, const QOpcUaMonitoringParameters &settings);
59 bool disableMonitoring(QOpcUa::NodeAttributes attr);
60 bool modifyMonitoring(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameter item, const QVariant &value);
61 QOpcUaMonitoringParameters monitoringStatus(QOpcUa::NodeAttribute attr);
62 bool modifyEventFilter(const QOpcUaMonitoringParameters::EventFilter &eventFilter);
63 bool modifyDataChangeFilter(QOpcUa::NodeAttribute attr, const QOpcUaMonitoringParameters::DataChangeFilter &filter);
64
65 bool browseChildren(QOpcUa::ReferenceTypeId referenceType = QOpcUa::ReferenceTypeId::HierarchicalReferences,
66 QOpcUa::NodeClasses nodeClassMask = QOpcUa::NodeClass::Undefined);
67
68 QString nodeId() const;
69 QOpcUaClient *client() const;
70
71 bool callMethod(const QString &methodNodeId, const QList<QOpcUa::TypedVariant> &args = QList<QOpcUa::TypedVariant>());
72
73 bool resolveBrowsePath(const QList<QOpcUaRelativePathElement> &path);
74
75 bool browse(const QOpcUaBrowseRequest &request);
76
77 QOpcUaHistoryReadResponse *readHistoryRaw(const QDateTime &startTime, const QDateTime &endTime, quint32 numValues, bool returnBounds);
78
79Q_SIGNALS:
80 void attributeRead(QOpcUa::NodeAttributes attributes);
81 void attributeWritten(QOpcUa::NodeAttribute attribute, QOpcUa::UaStatusCode statusCode);
82 void dataChangeOccurred(QOpcUa::NodeAttribute attr, QVariant value);
83 void attributeUpdated(QOpcUa::NodeAttribute attr, QVariant value);
84 void eventOccurred(QVariantList eventFields);
85
86 void monitoringStatusChanged(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameters items,
87 QOpcUa::UaStatusCode statusCode);
88 void enableMonitoringFinished(QOpcUa::NodeAttribute attr, QOpcUa::UaStatusCode statusCode);
89 void disableMonitoringFinished(QOpcUa::NodeAttribute attr, QOpcUa::UaStatusCode statusCode);
90 void methodCallFinished(QString methodNodeId, QVariant result, QOpcUa::UaStatusCode statusCode);
91 void browseFinished(QList<QOpcUaReferenceDescription> children, QOpcUa::UaStatusCode statusCode);
92 void resolveBrowsePathFinished(QList<QOpcUaBrowsePathTarget> targets,
93 QList<QOpcUaRelativePathElement> path, QOpcUa::UaStatusCode statusCode);
94
95private:
96 Q_DISABLE_COPY(QOpcUaNode)
97};
98
99Q_OPCUA_EXPORT QDebug operator<<(QDebug dbg, const QOpcUaNode &node);
100
101QT_END_NAMESPACE
102
103Q_DECLARE_METATYPE(QOpcUaNode::AttributeMap)
104
105inline Q_DECL_CONSTEXPR QOpcUa::NodeAttributes QOpcUaNode::mandatoryBaseAttributes()
106{
107 return QOpcUa::NodeAttribute::NodeId | QOpcUa::NodeAttribute::NodeClass |
108 QOpcUa::NodeAttribute::BrowseName | QOpcUa::NodeAttribute::DisplayName;
109}
110
111inline Q_DECL_CONSTEXPR QOpcUa::NodeAttributes QOpcUaNode::allBaseAttributes()
112{
113 return QOpcUa::NodeAttribute::NodeId | QOpcUa::NodeAttribute::NodeClass | QOpcUa::NodeAttribute::BrowseName |
114 QOpcUa::NodeAttribute::DisplayName | QOpcUa::NodeAttribute::Description | QOpcUa::NodeAttribute::WriteMask |
115 QOpcUa::NodeAttribute::UserWriteMask;
116}
117
118#endif // QOPCUANODE_H
119

source code of qtopcua/src/opcua/client/qopcuanode.h