| 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_OPCUACONNECTION_P_H |
| 5 | #define QOPCUA_OPCUACONNECTION_P_H |
| 6 | |
| 7 | #include <private/opcuareaditem_p.h> |
| 8 | #include <private/opcuaserverdiscovery_p.h> |
| 9 | |
| 10 | #include <QJSValue> |
| 11 | #include <QObject> |
| 12 | #include <QOpcUaClient> |
| 13 | #include <QOpcUaAuthenticationInformation> |
| 14 | |
| 15 | #include <QtQml/qqml.h> |
| 16 | |
| 17 | // |
| 18 | // W A R N I N G |
| 19 | // ------------- |
| 20 | // |
| 21 | // This file is not part of the Qt API. It exists purely as an |
| 22 | // implementation detail. This header file may change from version to |
| 23 | // version without notice, or even be removed. |
| 24 | // |
| 25 | // We mean it. |
| 26 | // |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QOpcUaReadResult; |
| 31 | class OpcUaEndpointDiscovery; |
| 32 | |
| 33 | class OpcUaConnection : public QObject |
| 34 | { |
| 35 | Q_OBJECT |
| 36 | Q_DISABLE_COPY(OpcUaConnection) |
| 37 | Q_PROPERTY(QStringList availableBackends READ availableBackends NOTIFY availableBackendsChanged) |
| 38 | Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) |
| 39 | Q_PROPERTY(QString backend READ backend WRITE setBackend NOTIFY backendChanged) |
| 40 | Q_PROPERTY(bool defaultConnection READ defaultConnection WRITE setDefaultConnection NOTIFY defaultConnectionChanged) |
| 41 | Q_PROPERTY(QStringList namespaces READ namespaces NOTIFY namespacesChanged) |
| 42 | Q_PROPERTY(QOpcUaAuthenticationInformation authenticationInformation READ authenticationInformation WRITE setAuthenticationInformation) |
| 43 | Q_PROPERTY(QStringList supportedSecurityPolicies READ supportedSecurityPolicies CONSTANT) |
| 44 | Q_PROPERTY(QJSValue supportedUserTokenTypes READ supportedUserTokenTypes CONSTANT) |
| 45 | Q_PROPERTY(QOpcUaEndpointDescription currentEndpoint READ currentEndpoint) |
| 46 | Q_PROPERTY(QOpcUaClient* connection READ connection WRITE setConnection NOTIFY connectionChanged) |
| 47 | QML_NAMED_ELEMENT(Connection) |
| 48 | QML_ADDED_IN_VERSION(5, 12) |
| 49 | |
| 50 | public: |
| 51 | OpcUaConnection(QObject *parent = nullptr); |
| 52 | ~OpcUaConnection(); |
| 53 | QStringList availableBackends() const; |
| 54 | bool connected() const; |
| 55 | void setBackend(const QString &name); |
| 56 | QString backend() const; |
| 57 | static OpcUaConnection *defaultConnection(); |
| 58 | bool isDefaultConnection() const; |
| 59 | QStringList namespaces() const; |
| 60 | |
| 61 | QOpcUaEndpointDescription currentEndpoint() const; |
| 62 | |
| 63 | QOpcUaAuthenticationInformation authenticationInformation() const; |
| 64 | Q_INVOKABLE bool readNodeAttributes(const QJSValue &value); |
| 65 | Q_INVOKABLE bool writeNodeAttributes(const QJSValue &value); |
| 66 | |
| 67 | QStringList supportedSecurityPolicies() const; |
| 68 | QJSValue supportedUserTokenTypes() const; |
| 69 | |
| 70 | QOpcUaClient *connection() const; |
| 71 | |
| 72 | public slots: |
| 73 | void connectToEndpoint(const QOpcUaEndpointDescription &endpointDescription); |
| 74 | void disconnectFromEndpoint(); |
| 75 | void setDefaultConnection(bool defaultConnection = true); |
| 76 | void setAuthenticationInformation(const QOpcUaAuthenticationInformation &authenticationInformation); |
| 77 | void setConnection(QOpcUaClient *client); |
| 78 | |
| 79 | signals: |
| 80 | void availableBackendsChanged(); |
| 81 | void connectedChanged(); |
| 82 | void backendChanged(); |
| 83 | void defaultConnectionChanged(); |
| 84 | void namespacesChanged(); |
| 85 | void readNodeAttributesFinished(const QVariant &value); |
| 86 | void writeNodeAttributesFinished(const QVariant &value); |
| 87 | void connectionChanged(); |
| 88 | |
| 89 | private slots: |
| 90 | void clientStateHandler(QOpcUaClient::ClientState state); |
| 91 | void handleReadNodeAttributesFinished(const QList<QOpcUaReadResult> &results); |
| 92 | void handleWriteNodeAttributesFinished(const QList<QOpcUaWriteResult> &results); |
| 93 | |
| 94 | private: |
| 95 | void removeConnection(); |
| 96 | void setupConnection(); |
| 97 | |
| 98 | QOpcUaClient *m_client = nullptr; |
| 99 | bool m_connected = false; |
| 100 | static OpcUaConnection* m_defaultConnection; |
| 101 | |
| 102 | friend class OpcUaNode; |
| 103 | friend class OpcUaValueNode; |
| 104 | friend class OpcUaMethodNode; |
| 105 | friend class OpcUaEndpointDiscovery; |
| 106 | friend class OpcUaServerDiscovery; |
| 107 | }; |
| 108 | |
| 109 | QT_END_NAMESPACE |
| 110 | |
| 111 | #endif // QOPCUA_OPCUACONNECTION_P_H |
| 112 | |