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