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 | #ifndef QOPCUA_OPCUANODE_P_H |
5 | #define QOPCUA_OPCUANODE_P_H |
6 | |
7 | #include <private/opcuaconnection_p.h> |
8 | #include <private/opcuanodeid_p.h> |
9 | #include <private/universalnode_p.h> |
10 | #include <private/opcuaattributecache_p.h> |
11 | #include <private/opcuaeventfilter_p.h> |
12 | #include <private/opcuanodeidtype_p.h> |
13 | |
14 | #include <QtOpcUa/qopcualocalizedtext.h> |
15 | |
16 | #include <QDateTime> |
17 | #include <QObject> |
18 | |
19 | #include <QtQml/qqml.h> |
20 | |
21 | // |
22 | // W A R N I N G |
23 | // ------------- |
24 | // |
25 | // This file is not part of the Qt API. It exists purely as an |
26 | // implementation detail. This header file may change from version to |
27 | // version without notice, or even be removed. |
28 | // |
29 | // We mean it. |
30 | // |
31 | |
32 | QT_BEGIN_NAMESPACE |
33 | |
34 | class OpcUaNode : public QObject |
35 | { |
36 | Q_OBJECT |
37 | Q_DISABLE_COPY(OpcUaNode) |
38 | Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
39 | |
40 | Q_PROPERTY(OpcUaNodeIdType* nodeId READ nodeId WRITE setNodeId NOTIFY nodeIdChanged) |
41 | Q_PROPERTY(OpcUaConnection* connection READ connection WRITE setConnection NOTIFY connectionChanged) |
42 | Q_PROPERTY(bool readyToUse READ readyToUse NOTIFY readyToUseChanged) |
43 | Q_PROPERTY(OpcUaNode::Status status READ status NOTIFY statusChanged) |
44 | Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) |
45 | Q_PROPERTY(OpcUaEventFilter *eventFilter READ eventFilter WRITE setEventFilter NOTIFY eventFilterChanged) |
46 | |
47 | // basic node properties |
48 | Q_PROPERTY(QString browseName READ browseName WRITE setBrowseName NOTIFY browseNameChanged) |
49 | Q_PROPERTY(QOpcUa::NodeClass nodeClass READ nodeClass NOTIFY nodeClassChanged) |
50 | Q_PROPERTY(QOpcUaLocalizedText displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) |
51 | Q_PROPERTY(QOpcUaLocalizedText description READ description WRITE setDescription NOTIFY descriptionChanged) |
52 | |
53 | Q_ENUM(QOpcUa::NodeClass); |
54 | |
55 | QML_NAMED_ELEMENT(Node) |
56 | QML_ADDED_IN_VERSION(5, 12) |
57 | |
58 | public: |
59 | enum class Status { |
60 | Valid, |
61 | InvalidNodeId, |
62 | NoConnection, |
63 | InvalidNodeType, |
64 | InvalidClient, |
65 | FailedToResolveNode, |
66 | InvalidObjectNode, |
67 | FailedToReadAttributes, |
68 | FailedToSetupMonitoring, |
69 | FailedToWriteAttribute, |
70 | FailedToModifyMonitoring, |
71 | FailedToDisableMonitoring, |
72 | }; |
73 | Q_ENUM(Status); |
74 | |
75 | OpcUaNode(QObject *parent = nullptr); |
76 | ~OpcUaNode(); |
77 | OpcUaNodeIdType *nodeId() const; |
78 | OpcUaConnection *connection(); |
79 | bool readyToUse() const; |
80 | |
81 | void setBrowseName(const QString &value); |
82 | QString browseName(); |
83 | |
84 | QOpcUa::NodeClass nodeClass(); |
85 | |
86 | void setDisplayName(const QOpcUaLocalizedText &value); |
87 | QOpcUaLocalizedText displayName(); |
88 | |
89 | void setDescription(const QOpcUaLocalizedText &value); |
90 | QOpcUaLocalizedText description(); |
91 | |
92 | OpcUaNode::Status status() const; |
93 | const QString &errorMessage() const; |
94 | |
95 | using QObject::eventFilter; |
96 | OpcUaEventFilter *eventFilter() const; |
97 | void setEventFilter(OpcUaEventFilter *eventFilter); |
98 | |
99 | Q_INVOKABLE QDateTime getSourceTimestamp(QOpcUa::NodeAttribute) const; |
100 | Q_INVOKABLE QDateTime getServerTimestamp(QOpcUa::NodeAttribute) const; |
101 | |
102 | // This function is not exposed to QML |
103 | const UniversalNode &resolvedNode() const; |
104 | |
105 | // This function is not exposed to QML |
106 | QOpcUaNode* node() const; |
107 | |
108 | public slots: |
109 | void setNodeId(OpcUaNodeIdType *nodeId); |
110 | void setConnection(OpcUaConnection *); |
111 | |
112 | signals: |
113 | void nodeIdChanged(OpcUaNodeIdType *nodeId); |
114 | void connectionChanged(OpcUaConnection *); |
115 | void nodeChanged(); |
116 | void readyToUseChanged(); |
117 | void browseNameChanged(); |
118 | void nodeClassChanged(); |
119 | void displayNameChanged(); |
120 | void descriptionChanged(); |
121 | void statusChanged(); |
122 | void errorMessageChanged(); |
123 | void eventFilterChanged(); |
124 | void eventOccurred(const QVariantList&values); |
125 | |
126 | protected slots: |
127 | virtual void setupNode(const QString &absoluteNodePath); |
128 | void updateNode(); |
129 | void updateEventFilter(); |
130 | |
131 | protected: |
132 | void setStatus(Status status, const QString &message = QString()); |
133 | void setAttributesToRead(QOpcUa::NodeAttributes attributes); |
134 | QOpcUa::NodeAttributes attributesToRead() const; |
135 | void retrieveAbsoluteNodePath(OpcUaNodeIdType *, std::function<void (const QString &)>); |
136 | void setReadyToUse(bool value = true); |
137 | virtual bool checkValidity(); |
138 | |
139 | OpcUaNodeIdType *m_nodeId = nullptr; |
140 | QOpcUaNode *m_node = nullptr; |
141 | OpcUaConnection *m_connection = nullptr; |
142 | QString m_absoluteNodePath; // not exposed |
143 | bool m_readyToUse = false; |
144 | UniversalNode m_resolvedNode; |
145 | OpcUaAttributeCache m_attributeCache; |
146 | QOpcUa::NodeAttributes m_attributesToRead; |
147 | Status m_status; |
148 | QString m_errorMessage; |
149 | OpcUaEventFilter *m_eventFilter = nullptr; |
150 | bool m_eventFilterActive = false; |
151 | |
152 | QMetaObject::Connection m_attributeUpdatedConnection; |
153 | QMetaObject::Connection m_attributeReadConnection; |
154 | QMetaObject::Connection m_enableMonitoringFinishedConnection; |
155 | QMetaObject::Connection m_disableMonitoringFinishedConnection; |
156 | QMetaObject::Connection m_monitoringStatusChangedConnection; |
157 | QMetaObject::Connection m_eventOccurredConnection; |
158 | }; |
159 | |
160 | QT_END_NAMESPACE |
161 | |
162 | #endif // QOPCUA_OPCUANODE_P_H |
163 | |