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
24QT_BEGIN_NAMESPACE
25
26class QOpcUaAuthenticationInformation;
27class QOpcUaApplicationDescription;
28class QOpcUaClientPrivate;
29class QOpcUaClientImpl;
30class QOpcUaConnectionSettings;
31class QOpcUaErrorState;
32class QOpcUaExpandedNodeId;
33class QOpcUaQualifiedName;
34class QOpcUaEndpointDescription;
35class QOpcUaReadRawRequest;
36
37class 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
44public:
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 InvalidAuthenticationInformation,
61 InvalidEndpointDescription,
62 NoMatchingUserIdentityTokenFound,
63 UnsupportedSecurityPolicy,
64 InvalidPki,
65 CertificateUntrusted
66 };
67 Q_ENUM(ClientError)
68
69 explicit QOpcUaClient(QOpcUaClientImpl *impl, QObject *parent = nullptr);
70 ~QOpcUaClient();
71
72 void setApplicationIdentity(const QOpcUaApplicationIdentity &identity);
73 QOpcUaApplicationIdentity applicationIdentity() const;
74
75 void setPkiConfiguration(const QOpcUaPkiConfiguration &config);
76 QOpcUaPkiConfiguration pkiConfiguration() const;
77
78 Q_INVOKABLE void connectToEndpoint(const QOpcUaEndpointDescription &endpoint);
79 Q_INVOKABLE void disconnectFromEndpoint();
80 QOpcUaNode *node(const QString &nodeId);
81 QOpcUaNode *node(const QOpcUaExpandedNodeId &expandedNodeId);
82
83 bool updateNamespaceArray();
84 QStringList namespaceArray() const;
85
86 QString resolveExpandedNodeId(const QOpcUaExpandedNodeId &expandedNodeId, bool *ok = nullptr) const;
87 QOpcUaQualifiedName qualifiedNameFromNamespaceUri(const QString &namespaceUri, const QString &name, bool *ok = nullptr) const;
88
89 bool requestEndpoints(const QUrl &url);
90 bool findServers(const QUrl &url, const QStringList &localeIds = QStringList(),
91 const QStringList &serverUris = QStringList());
92
93 bool readNodeAttributes(const QList<QOpcUaReadItem> &nodesToRead);
94 bool writeNodeAttributes(const QList<QOpcUaWriteItem> &nodesToWrite);
95
96 bool addNode(const QOpcUaAddNodeItem &nodeToAdd);
97 bool deleteNode(const QString &nodeId, bool deleteTargetReferences = true);
98
99 bool addReference(const QOpcUaAddReferenceItem &referenceToAdd);
100 bool deleteReference(const QOpcUaDeleteReferenceItem &referenceToDelete);
101
102 QOpcUaEndpointDescription endpoint() const;
103
104 ClientState state() const;
105 ClientError error() const;
106
107 QString backend() const;
108
109 void setNamespaceAutoupdate(bool isEnabled);
110 bool isNamespaceAutoupdateEnabled() const;
111 void setNamespaceAutoupdateInterval(int interval);
112 int namespaceAutoupdateInterval() const;
113
114 void setAuthenticationInformation(const QOpcUaAuthenticationInformation &authenticationInformation);
115 const QOpcUaAuthenticationInformation &authenticationInformation() const;
116
117 void setConnectionSettings(const QOpcUaConnectionSettings &connectionSettings);
118 QOpcUaConnectionSettings connectionSettings() const;
119
120 QStringList supportedSecurityPolicies() const;
121 QList<QOpcUaUserTokenPolicy::TokenType> supportedUserTokenTypes() const;
122
123 QOpcUaHistoryReadResponse *readHistoryData(const QOpcUaHistoryReadRawRequest &request);
124 QOpcUaHistoryReadResponse *readHistoryEvents(const QOpcUaHistoryReadEventRequest &request);
125
126 bool registerNodes(const QStringList &nodesToRegister);
127 bool unregisterNodes(const QStringList &nodesToUnregister);
128
129Q_SIGNALS:
130 void connected();
131 void disconnected();
132 void stateChanged(QOpcUaClient::ClientState state);
133 void errorChanged(QOpcUaClient::ClientError error);
134 void connectError(QOpcUaErrorState *errorState);
135 void namespaceArrayUpdated(QStringList namespaces);
136 void namespaceArrayChanged(QStringList namespaces);
137 void endpointsRequestFinished(QList<QOpcUaEndpointDescription> endpoints, QOpcUa::UaStatusCode statusCode, QUrl requestUrl);
138 void findServersFinished(QList<QOpcUaApplicationDescription> servers, QOpcUa::UaStatusCode statusCode, QUrl requestUrl);
139 void readNodeAttributesFinished(QList<QOpcUaReadResult> results, QOpcUa::UaStatusCode serviceResult);
140 void writeNodeAttributesFinished(QList<QOpcUaWriteResult> results, QOpcUa::UaStatusCode serviceResult);
141 void addNodeFinished(QOpcUaExpandedNodeId requestedNodeId, QString assignedNodeId, QOpcUa::UaStatusCode statusCode);
142 void deleteNodeFinished(QString nodeId, QOpcUa::UaStatusCode statusCode);
143 void addReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUaExpandedNodeId targetNodeId, bool isForwardReference,
144 QOpcUa::UaStatusCode statusCode);
145 void deleteReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUaExpandedNodeId targetNodeId, bool isForwardReference,
146 QOpcUa::UaStatusCode statusCode);
147 void passwordForPrivateKeyRequired(QString keyFilePath, QString *password, bool previousTryWasInvalid);
148 void registerNodesFinished(const QStringList &nodesToRegister, const QStringList &registeredNodeIds, QOpcUa::UaStatusCode statusCode);
149 void unregisterNodesFinished(const QStringList &nodesToUnregister, QOpcUa::UaStatusCode statusCode);
150
151private:
152 Q_DISABLE_COPY(QOpcUaClient)
153};
154
155QT_END_NAMESPACE
156
157Q_DECLARE_METATYPE(QOpcUaClient::ClientState)
158Q_DECLARE_METATYPE(QOpcUaClient::ClientError)
159
160#endif // QOPCUACLIENT_H
161

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