| 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 QOPCUACLIENT_H | 
| 5 | #define QOPCUACLIENT_H | 
| 6 |  | 
| 7 | #include <QtOpcUa/qopcuaglobal.h> | 
| 8 | #include <QtOpcUa/qopcuaapplicationidentity.h> | 
| 9 | #include <QtOpcUa/qopcuapkiconfiguration.h> | 
| 10 | #include <QtOpcUa/qopcuanode.h> | 
| 11 | #include <QtOpcUa/qopcuareaditem.h> | 
| 12 | #include <QtOpcUa/qopcuareadresult.h> | 
| 13 | #include <QtOpcUa/qopcuawriteitem.h> | 
| 14 | #include <QtOpcUa/qopcuawriteresult.h> | 
| 15 | #include <QtOpcUa/qopcuaaddnodeitem.h> | 
| 16 | #include <QtOpcUa/qopcuaaddreferenceitem.h> | 
| 17 | #include <QtOpcUa/qopcuadeletereferenceitem.h> | 
| 18 | #include <QtOpcUa/qopcuaendpointdescription.h> | 
| 19 | #include <QtOpcUa/QOpcUaHistoryReadEventRequest> | 
| 20 |  | 
| 21 | #include <QtCore/qobject.h> | 
| 22 | #include <QtCore/qurl.h> | 
| 23 |  | 
| 24 | QT_BEGIN_NAMESPACE | 
| 25 |  | 
| 26 | class QOpcUaAuthenticationInformation; | 
| 27 | class QOpcUaApplicationDescription; | 
| 28 | class QOpcUaClientPrivate; | 
| 29 | class QOpcUaClientImpl; | 
| 30 | class QOpcUaConnectionSettings; | 
| 31 | class QOpcUaErrorState; | 
| 32 | class QOpcUaExpandedNodeId; | 
| 33 | class QOpcUaQualifiedName; | 
| 34 | class QOpcUaEndpointDescription; | 
| 35 | class QOpcUaReadRawRequest; | 
| 36 |  | 
| 37 | class Q_OPCUA_EXPORT QOpcUaClient : public QObject | 
| 38 | { | 
| 39 |     Q_OBJECT | 
| 40 |     Q_PROPERTY(ClientState state READ state NOTIFY stateChanged) | 
| 41 |     Q_PROPERTY(ClientError error READ error NOTIFY errorChanged) | 
| 42 |     Q_DECLARE_PRIVATE(QOpcUaClient) | 
| 43 |  | 
| 44 | public: | 
| 45 |     enum ClientState { | 
| 46 |         Disconnected, | 
| 47 |         Connecting, | 
| 48 |         Connected, | 
| 49 |         Closing, | 
| 50 |     }; | 
| 51 |     Q_ENUM(ClientState) | 
| 52 |  | 
| 53 |     enum ClientError { | 
| 54 |         NoError, | 
| 55 |         InvalidUrl, | 
| 56 |         AccessDenied, | 
| 57 |         ConnectionError, | 
| 58 |         UnknownError, | 
| 59 |         UnsupportedAuthenticationInformation, | 
| 60 |     }; | 
| 61 |     Q_ENUM(ClientError) | 
| 62 |  | 
| 63 |     explicit QOpcUaClient(QOpcUaClientImpl *impl, QObject *parent = nullptr); | 
| 64 |     ~QOpcUaClient(); | 
| 65 |  | 
| 66 |     void setApplicationIdentity(const QOpcUaApplicationIdentity &identity); | 
| 67 |     QOpcUaApplicationIdentity applicationIdentity() const; | 
| 68 |  | 
| 69 |     void setPkiConfiguration(const QOpcUaPkiConfiguration &config); | 
| 70 |     QOpcUaPkiConfiguration pkiConfiguration() const; | 
| 71 |  | 
| 72 |     Q_INVOKABLE void connectToEndpoint(const QOpcUaEndpointDescription &endpoint); | 
| 73 |     Q_INVOKABLE void disconnectFromEndpoint(); | 
| 74 |     QOpcUaNode *node(const QString &nodeId); | 
| 75 |     QOpcUaNode *node(const QOpcUaExpandedNodeId &expandedNodeId); | 
| 76 |  | 
| 77 |     bool updateNamespaceArray(); | 
| 78 |     QStringList namespaceArray() const; | 
| 79 |  | 
| 80 |     QString resolveExpandedNodeId(const QOpcUaExpandedNodeId &expandedNodeId, bool *ok = nullptr) const; | 
| 81 |     QOpcUaQualifiedName qualifiedNameFromNamespaceUri(const QString &namespaceUri, const QString &name, bool *ok = nullptr) const; | 
| 82 |  | 
| 83 |     bool requestEndpoints(const QUrl &url); | 
| 84 |     bool findServers(const QUrl &url, const QStringList &localeIds = QStringList(), | 
| 85 |                      const QStringList &serverUris = QStringList()); | 
| 86 |  | 
| 87 |     bool readNodeAttributes(const QList<QOpcUaReadItem> &nodesToRead); | 
| 88 |     bool writeNodeAttributes(const QList<QOpcUaWriteItem> &nodesToWrite); | 
| 89 |  | 
| 90 |     bool addNode(const QOpcUaAddNodeItem &nodeToAdd); | 
| 91 |     bool deleteNode(const QString &nodeId, bool deleteTargetReferences = true); | 
| 92 |  | 
| 93 |     bool addReference(const QOpcUaAddReferenceItem &referenceToAdd); | 
| 94 |     bool deleteReference(const QOpcUaDeleteReferenceItem &referenceToDelete); | 
| 95 |  | 
| 96 |     QOpcUaEndpointDescription endpoint() const; | 
| 97 |  | 
| 98 |     ClientState state() const; | 
| 99 |     ClientError error() const; | 
| 100 |  | 
| 101 |     QString backend() const; | 
| 102 |  | 
| 103 |     void setNamespaceAutoupdate(bool isEnabled); | 
| 104 |     bool isNamespaceAutoupdateEnabled() const; | 
| 105 |     void setNamespaceAutoupdateInterval(int interval); | 
| 106 |     int namespaceAutoupdateInterval() const; | 
| 107 |  | 
| 108 |     void setAuthenticationInformation(const QOpcUaAuthenticationInformation &authenticationInformation); | 
| 109 |     const QOpcUaAuthenticationInformation &authenticationInformation() const; | 
| 110 |  | 
| 111 |     void setConnectionSettings(const QOpcUaConnectionSettings &connectionSettings); | 
| 112 |     QOpcUaConnectionSettings connectionSettings() const; | 
| 113 |  | 
| 114 |     QStringList supportedSecurityPolicies() const; | 
| 115 |     QList<QOpcUaUserTokenPolicy::TokenType> supportedUserTokenTypes() const; | 
| 116 |  | 
| 117 |     QOpcUaHistoryReadResponse *readHistoryData(const QOpcUaHistoryReadRawRequest &request); | 
| 118 |     QOpcUaHistoryReadResponse *readHistoryEvents(const QOpcUaHistoryReadEventRequest &request); | 
| 119 |  | 
| 120 |     bool registerNodes(const QStringList &nodesToRegister); | 
| 121 |     bool unregisterNodes(const QStringList &nodesToUnregister); | 
| 122 |  | 
| 123 | Q_SIGNALS: | 
| 124 |     void connected(); | 
| 125 |     void disconnected(); | 
| 126 |     void stateChanged(QOpcUaClient::ClientState state); | 
| 127 |     void errorChanged(QOpcUaClient::ClientError error); | 
| 128 |     void connectError(QOpcUaErrorState *errorState); | 
| 129 |     void namespaceArrayUpdated(QStringList namespaces); | 
| 130 |     void namespaceArrayChanged(QStringList namespaces); | 
| 131 |     void endpointsRequestFinished(QList<QOpcUaEndpointDescription> endpoints, QOpcUa::UaStatusCode statusCode, QUrl requestUrl); | 
| 132 |     void findServersFinished(QList<QOpcUaApplicationDescription> servers, QOpcUa::UaStatusCode statusCode, QUrl requestUrl); | 
| 133 |     void readNodeAttributesFinished(QList<QOpcUaReadResult> results, QOpcUa::UaStatusCode serviceResult); | 
| 134 |     void writeNodeAttributesFinished(QList<QOpcUaWriteResult> results, QOpcUa::UaStatusCode serviceResult); | 
| 135 |     void addNodeFinished(QOpcUaExpandedNodeId requestedNodeId, QString assignedNodeId, QOpcUa::UaStatusCode statusCode); | 
| 136 |     void deleteNodeFinished(QString nodeId, QOpcUa::UaStatusCode statusCode); | 
| 137 |     void addReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUaExpandedNodeId targetNodeId, bool isForwardReference, | 
| 138 |                               QOpcUa::UaStatusCode statusCode); | 
| 139 |     void deleteReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUaExpandedNodeId targetNodeId, bool isForwardReference, | 
| 140 |                               QOpcUa::UaStatusCode statusCode); | 
| 141 |     void passwordForPrivateKeyRequired(QString keyFilePath, QString *password, bool previousTryWasInvalid); | 
| 142 |     void registerNodesFinished(const QStringList &nodesToRegister, const QStringList ®isteredNodeIds, QOpcUa::UaStatusCode statusCode); | 
| 143 |     void unregisterNodesFinished(const QStringList &nodesToUnregister, QOpcUa::UaStatusCode statusCode); | 
| 144 |  | 
| 145 | private: | 
| 146 |     Q_DISABLE_COPY(QOpcUaClient) | 
| 147 | }; | 
| 148 |  | 
| 149 | QT_END_NAMESPACE | 
| 150 |  | 
| 151 | Q_DECLARE_METATYPE(QOpcUaClient::ClientState) | 
| 152 | Q_DECLARE_METATYPE(QOpcUaClient::ClientError) | 
| 153 |  | 
| 154 | #endif // QOPCUACLIENT_H | 
| 155 |  |