| 1 | // Copyright (C) 2016 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 QOPCUACLIENTIMPL_P_H |
| 5 | #define QOPCUACLIENTIMPL_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtOpcUa/qopcuaclient.h> |
| 19 | #include <QtOpcUa/qopcuaconnectionsettings.h> |
| 20 | #include <QtOpcUa/qopcuaglobal.h> |
| 21 | #include <QtOpcUa/qopcuaendpointdescription.h> |
| 22 | #include <private/qopcuanodeimpl_p.h> |
| 23 | |
| 24 | #include <QtCore/qobject.h> |
| 25 | #include <QtCore/qpointer.h> |
| 26 | #include <QtCore/qset.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QOpcUaNode; |
| 31 | class QOpcUaClient; |
| 32 | class QOpcUaBackend; |
| 33 | class QOpcUaMonitoringParameters; |
| 34 | |
| 35 | class Q_OPCUA_EXPORT QOpcUaClientImpl : public QObject |
| 36 | { |
| 37 | Q_OBJECT |
| 38 | |
| 39 | public: |
| 40 | QOpcUaClientImpl(QObject *parent = 0); |
| 41 | virtual ~QOpcUaClientImpl(); |
| 42 | |
| 43 | virtual void connectToEndpoint(const QOpcUaEndpointDescription &endpoint) = 0; |
| 44 | virtual void disconnectFromEndpoint() = 0; |
| 45 | virtual QOpcUaNode *node(const QString &nodeId) = 0; |
| 46 | virtual QString backend() const = 0; |
| 47 | virtual bool requestEndpoints(const QUrl &url) = 0; |
| 48 | virtual bool findServers(const QUrl &url, const QStringList &localeIds, const QStringList &serverUris) = 0; |
| 49 | virtual bool readNodeAttributes(const QList<QOpcUaReadItem> &nodesToRead) = 0; |
| 50 | virtual bool writeNodeAttributes(const QList<QOpcUaWriteItem> &nodesToWrite) = 0; |
| 51 | |
| 52 | virtual QOpcUaHistoryReadResponse *readHistoryData(const QOpcUaHistoryReadRawRequest &request) = 0; |
| 53 | virtual QOpcUaHistoryReadResponse *readHistoryEvents(const QOpcUaHistoryReadEventRequest &request) = 0; |
| 54 | |
| 55 | bool registerNode(QPointer<QOpcUaNodeImpl> obj); |
| 56 | void unregisterNode(QPointer<QOpcUaNodeImpl> obj); |
| 57 | |
| 58 | virtual bool addNode(const QOpcUaAddNodeItem &nodeToAdd) = 0; |
| 59 | virtual bool deleteNode(const QString &nodeId, bool deleteTargetReferences) = 0; |
| 60 | |
| 61 | virtual bool addReference(const QOpcUaAddReferenceItem &referenceToAdd) = 0; |
| 62 | virtual bool deleteReference(const QOpcUaDeleteReferenceItem &referenceToDelete) = 0; |
| 63 | |
| 64 | void connectBackendWithClient(QOpcUaBackend *backend); |
| 65 | |
| 66 | virtual QStringList supportedSecurityPolicies() const = 0; |
| 67 | virtual QList<QOpcUaUserTokenPolicy::TokenType> supportedUserTokenTypes() const = 0; |
| 68 | |
| 69 | virtual bool registerNodes(const QStringList &nodesToRegister) = 0; |
| 70 | virtual bool unregisterNodes(const QStringList &nodesToUnregister) = 0; |
| 71 | |
| 72 | QOpcUaClient *m_client; |
| 73 | |
| 74 | private Q_SLOTS: |
| 75 | void handleAttributesRead(quint64 handle, QList<QOpcUaReadResult> attr, QOpcUa::UaStatusCode serviceResult); |
| 76 | void handleAttributeWritten(quint64 handle, QOpcUa::NodeAttribute attr, const QVariant &value, QOpcUa::UaStatusCode statusCode); |
| 77 | void handleDataChangeOccurred(quint64 handle, const QOpcUaReadResult &value); |
| 78 | void handleMonitoringEnableDisable(quint64 handle, QOpcUa::NodeAttribute attr, bool subscribe, QOpcUaMonitoringParameters status); |
| 79 | void handleMonitoringStatusChanged(quint64 handle, QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameters items, |
| 80 | QOpcUaMonitoringParameters param); |
| 81 | void handleMethodCallFinished(quint64 handle, QString methodNodeId, QVariant result, QOpcUa::UaStatusCode statusCode); |
| 82 | void handleBrowseFinished(quint64 handle, const QList<QOpcUaReferenceDescription> &children, QOpcUa::UaStatusCode statusCode); |
| 83 | |
| 84 | void handleResolveBrowsePathFinished(quint64 handle, QList<QOpcUaBrowsePathTarget> targets, |
| 85 | QList<QOpcUaRelativePathElement> path, QOpcUa::UaStatusCode status); |
| 86 | |
| 87 | void handleNewEvent(quint64 handle, QVariantList eventFields); |
| 88 | |
| 89 | signals: |
| 90 | void connected(); |
| 91 | void disconnected(); |
| 92 | void stateAndOrErrorChanged(QOpcUaClient::ClientState state, |
| 93 | QOpcUaClient::ClientError error); |
| 94 | void endpointsRequestFinished(QList<QOpcUaEndpointDescription> endpoints, QOpcUa::UaStatusCode statusCode, QUrl requestUrl); |
| 95 | void findServersFinished(QList<QOpcUaApplicationDescription> servers, QOpcUa::UaStatusCode statusCode, QUrl requestUrl); |
| 96 | void readNodeAttributesFinished(QList<QOpcUaReadResult> results, QOpcUa::UaStatusCode serviceResult); |
| 97 | void writeNodeAttributesFinished(QList<QOpcUaWriteResult> results, QOpcUa::UaStatusCode serviceResult); |
| 98 | void addNodeFinished(QOpcUaExpandedNodeId requestedNodeId, QString assignedNodeId, QOpcUa::UaStatusCode statusCode); |
| 99 | void deleteNodeFinished(QString nodeId, QOpcUa::UaStatusCode statusCode); |
| 100 | void addReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUaExpandedNodeId targetNodeId, bool isForwardReference, |
| 101 | QOpcUa::UaStatusCode statusCode); |
| 102 | void deleteReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUaExpandedNodeId targetNodeId, bool isForwardReference, |
| 103 | QOpcUa::UaStatusCode statusCode); |
| 104 | void connectError(QOpcUaErrorState *errorState); |
| 105 | void passwordForPrivateKeyRequired(const QString keyFilePath, QString *password, bool previousTryWasInvalid); |
| 106 | void registerNodesFinished(QStringList nodesToRegister, QStringList registeredNodeIds, QOpcUa::UaStatusCode statusCode); |
| 107 | void unregisterNodesFinished(QStringList nodesToUnregister, QOpcUa::UaStatusCode statusCode); |
| 108 | |
| 109 | void connectionSettingsChanged(QOpcUaConnectionSettings settings); |
| 110 | |
| 111 | private: |
| 112 | Q_DISABLE_COPY(QOpcUaClientImpl) |
| 113 | QHash<quint64, QPointer<QOpcUaNodeImpl>> m_handles; |
| 114 | quint64 m_handleCounter; |
| 115 | }; |
| 116 | |
| 117 | #if QT_VERSION >= 0x060000 |
| 118 | inline size_t qHash(const QPointer<QOpcUaNodeImpl>& n) |
| 119 | #else |
| 120 | inline uint qHash(const QPointer<QOpcUaNodeImpl>& n) |
| 121 | #endif |
| 122 | { |
| 123 | return ::qHash(key: n.data()); |
| 124 | } |
| 125 | |
| 126 | QT_END_NAMESPACE |
| 127 | |
| 128 | #endif // QOPCUACLIENTIMPL_P_H |
| 129 | |