QOpcUaGdsClient Class
处理与 GDS 服务器的通信。更多
头文件: | #include <QOpcUaGdsClient> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS OpcUa) target_link_libraries(mytarget PRIVATE Qt6::OpcUa) |
qmake: | QT += opcua |
继承: | QObject |
公共类型
enum class | Error { NoError, InvalidBackend, InvalidEndpoint, ConnectionError, DirectoryNodeNotFound, …, FailedToGetCertificate } |
enum class | State { Idle, BackendInstantiated, Connecting, Connected, RegisteringApplication, …, Error } |
公共函数
QOpcUaGdsClient(QObject *parent = nullptr) | |
virtual | ~QOpcUaGdsClient() |
QString | applicationId() const |
const QOpcUaApplicationIdentity & | applicationIdentity() const |
const QOpcUaApplicationRecordDataType & | applicationRecord() const |
const QString & | backend() const |
int | certificateCheckInterval() const |
const QOpcUaX509DistinguishedName & | distinguishedNameCertificateSigningRequestPreset() const |
const QString & | dnsCertificateSigningRequestPreset() const |
const QOpcUaEndpointDescription & | endpoint() const |
QOpcUaGdsClient::Error | error() const |
const QOpcUaPkiConfiguration & | pkiConfiguration() const |
void | setApplicationIdentity(const QOpcUaApplicationIdentity &appIdentity) |
void | setApplicationRecord(const QOpcUaApplicationRecordDataType &appRecord) |
void | setBackend(const QString &backend) |
void | setCertificateCheckInterval(int interval) |
void | setCertificateSigningRequestPresets(const QOpcUaX509DistinguishedName &dn, const QString &dns) |
void | setEndpoint(const QOpcUaEndpointDescription &endpoint) |
void | setPkiConfiguration(const QOpcUaPkiConfiguration &pkiConfig) |
void | setTrustListUpdateInterval(int interval) |
void | start() |
QOpcUaGdsClient::State | state() const |
int | trustListUpdateInterval() const |
void | unregisterApplication() |
信号
void | applicationRegistered() |
void | authenticationRequired(QOpcUaAuthenticationInformation &authInfo) |
void | certificateGroupsReceived(QStringList certificateGroups) |
void | certificateUpdateRequired() |
void | certificateUpdated() |
void | errorChanged(QOpcUaGdsClient::Error error) |
void | stateChanged(QOpcUaGdsClient::State state) |
void | trustListUpdated() |
void | unregistered() |
详细说明
该类目前为技术预览版,因此其提供的 API 和功能可能会随时更改,恕不另行通知。
该类处理与 GDS 服务器通信所需的所有步骤。该类会提供应用程序的相关信息,以便与服务器进行注册并管理密钥/证书。
只需了解少量细节,即可参与安全网络。
首次注册需要使用用户名和密码进行身份验证的管理权限。接下来的所有验证都是基于应用程序的,使用的是最先收到的证书。
如果希望整个过程成功,您必须等待applicationRegistered 信号。
大部分设置结构必须与之后与QOpcUaClient 的连接相同,并且可以共享。
设置 GDS 客户端:
QOpcUaGdsClientc;// 如果需要凭证QObject连接(&c, &QOpcUaGdsClient::authenticationRequired, [&](QOpcUaAuthenticationInformationauthInfo){authInfo.setUsernameAuthentication("root", "secret"); });// 等待成功QObject连接(&c, &QOpcUaGdsClient::applicationRegistered, [&]() { qDebug() << "Application" << c.applicationId() << "registered"; }); c.setBackend(...); c.setEndpoint(...); c.setApplicationIdentity(...); c.setPkiConfiguration(...); c.setApplicationRecord(...); c.setCertificateSigningRequestPresets(...); c.start();
成员类型文档
enum class QOpcUaGdsClient::Error
该枚举用于指定注册过程中可能发生的错误。
常量 | 值 | 说明 |
---|---|---|
QOpcUaGdsClient::Error::NoError | 0 | 一切正常 |
QOpcUaGdsClient::Error::InvalidBackend | 1 | 后端无法实例化。给定的后端字符串与任何后端不匹配或加载插件失败。 |
QOpcUaGdsClient::Error::InvalidEndpoint | 2 | 给定的端点无效。 |
QOpcUaGdsClient::Error::ConnectionError | 3 | 与服务器端点的连接失败。 |
QOpcUaGdsClient::Error::DirectoryNodeNotFound | 4 | 无法解析服务器上的目录节点。 |
QOpcUaGdsClient::Error::FailedToRegisterApplication | 5 | 应用程序注册不成功。 |
QOpcUaGdsClient::Error::FailedToUnregisterApplication | 6 | 应用程序的取消注册不成功。 |
QOpcUaGdsClient::Error::FailedToGetCertificateStatus | 7 | 无法检索当前证书的状态。 |
QOpcUaGdsClient::Error::FailedToGetCertificate | 8 | 无法从服务器检索证书。 |
enum class QOpcUaGdsClient::State
该枚举用于指定 GDS 客户端当前的注册状态。
常量 | 值 | 说明 |
---|---|---|
QOpcUaGdsClient::State::Idle | 0 | 客户端尚未启动。 |
QOpcUaGdsClient::State::BackendInstantiated | 1 | 后端已实例化 |
QOpcUaGdsClient::State::Connecting | 2 | 正在连接服务器 |
QOpcUaGdsClient::State::Connected | 3 | 与服务器端点的连接成功。 |
QOpcUaGdsClient::State::RegisteringApplication | 4 | 应用程序正在向服务器注册。 |
QOpcUaGdsClient::State::ApplicationRegistered | 5 | 向服务器注册应用程序成功。 |
QOpcUaGdsClient::State::Error | 6 | 发生错误。详情请查看error() 的返回值和终端输出。 |
成员函数文档
QOpcUaGdsClient::QOpcUaGdsClient(QObject *parent = nullptr)
构建 GDS 客户端,父对象为parent 。
[virtual noexcept]
QOpcUaGdsClient::~QOpcUaGdsClient()
销毁 GDS 客户端。
QString QOpcUaGdsClient::applicationId() const
返回服务器分配的应用程序 ID。
这是从应用程序记录数据中接收应用程序 ID 的快捷方式。
另请参阅 applicationRecord()。
const QOpcUaApplicationIdentity &QOpcUaGdsClient::applicationIdentity() const
返回当前 applicationIdentity。
另请参阅 setApplicationIdentity()。
const QOpcUaApplicationRecordDataType &QOpcUaGdsClient::applicationRecord() const
返回客户端使用的应用程序记录数据。
另请参阅 setApplicationRecord()。
[signal]
void QOpcUaGdsClient::applicationRegistered()
当应用程序注册成功时会发出该信号。
[signal]
void QOpcUaGdsClient::authenticationRequired(QOpcUaAuthenticationInformation &authInfo)
当 GDS 客户端尝试与需要管理权限的服务器进行首次身份验证时,会发出该信号。
authInfo 必须填写有效的身份验证信息。此插槽不得跨线程使用。
const QString &QOpcUaGdsClient::backend() const
返回当前的后端设置。
如果在启动客户端后更改了后端,则将返回更改后的设置,而不是实际使用的实例。
另请参见 setBackend()。
int QOpcUaGdsClient::certificateCheckInterval() const
返回检查客户证书有效性的时间间隔(毫秒)。
另请参阅 setCertificateCheckInterval()。
[signal]
void QOpcUaGdsClient::certificateGroupsReceived(QStringList certificateGroups)
当 GDS 客户端收到该应用程序的certificateGroups 新列表时,会发出该信号。
[signal]
void QOpcUaGdsClient::certificateUpdateRequired()
当 GDS 客户端检测到需要更新当前使用的证书时,就会发出该信号。
这可能是由于服务器要求客户端更新证书、证书到期日已到或证书是自签名的缘故。
证书更新会自动进行。此信号仅用于通知即将进行的更新。
[signal]
void QOpcUaGdsClient::certificateUpdated()
当 GDS 客户端收到存储在磁盘上的新证书时,就会发出该信号。
const QOpcUaX509DistinguishedName &QOpcUaGdsClient::distinguishedNameCertificateSigningRequestPreset() const
返回为证书签名请求预设的区分名称。
const QString &QOpcUaGdsClient::dnsCertificateSigningRequestPreset() const
返回用于证书签名请求的 DNS 预设值。
const QOpcUaEndpointDescription &QOpcUaGdsClient::endpoint() const
返回当前端点设置。
如果在启动客户端后更改了端点,它将返回更改后的设置,而不是实际使用的端点。
另请参阅 setEndpoint()。
QOpcUaGdsClient::Error QOpcUaGdsClient::error() const
返回当前的错误状态。
[signal]
void QOpcUaGdsClient::errorChanged(QOpcUaGdsClient::Error error)
发生error 时发出该信号。
const QOpcUaPkiConfiguration &QOpcUaGdsClient::pkiConfiguration() const
返回当前 pkiConfiguration。
另请参见 setPkiConfiguration()。
void QOpcUaGdsClient::setApplicationIdentity(const QOpcUaApplicationIdentity &appIdentity)
设置客户端使用的应用程序标识appIdentity 。
该身份用于向 GDS 服务器注册。该函数必须在启动 GDS 客户端之前调用。之后更改此设置不会产生任何影响。
另请参阅 applicationIdentity().
void QOpcUaGdsClient::setApplicationRecord(const QOpcUaApplicationRecordDataType &appRecord)
设置客户端使用的应用程序记录数据appRecord 。
该数据用于向 GDS 服务器注册。必须在启动 GDS 客户端之前调用该函数。
大部分数据与应用程序标识中的数据相同。注册完成后,可检索分配的应用程序 ID。
另请参见 applicationRecord() 和setApplicationIdentity 。
void QOpcUaGdsClient::setBackend(const QString &backend)
将客户端用于与服务器通信的后端设置为backend 。
该函数必须在启动 GDS 客户端之前调用。之后更改此设置不会产生任何影响。
另请参阅 backend()、QOpcUaProvider::availableBackends() 和start()。
void QOpcUaGdsClient::setCertificateCheckInterval(int interval)
将检查客户端证书有效性的时间间隔(毫秒)设为interval 。
另请参阅 certificateCheckInterval()。
void QOpcUaGdsClient::setCertificateSigningRequestPresets(const QOpcUaX509DistinguishedName &dn, const QString &dns)
设置证书签名请求的预设值;区分名称dn 和 DNS 字符串dns 。
在创建证书签名请求时,需要一些应用程序标识不提供的附加信息。
必须在启动 GDS 客户端前调用该函数。
另请参阅 setApplicationIdentity().
void QOpcUaGdsClient::setEndpoint(const QOpcUaEndpointDescription &endpoint)
将客户端用于与服务器通信的端点设置为endpoint 。
该函数必须在启动 GDS 客户端之前调用。之后更改此设置不会产生任何影响。
只有通过加密端点才能与 GDS 服务器通信。使用未加密的端点将导致通信失败。
另请参阅 endpoint().
void QOpcUaGdsClient::setPkiConfiguration(const QOpcUaPkiConfiguration &pkiConfig)
设置客户端使用的 PKI 配置pkiConfig 。
所有证书、密钥和信任列表都将从指定位置使用或存储到指定位置。要使用从 GDS 接收的证书,必须在QOpcUaClient 中使用相同的配置。
必须在启动 GDS 客户端之前调用该函数。事后更改该设置不会产生任何影响。
另请参阅 pkiConfiguration() 。
void QOpcUaGdsClient::setTrustListUpdateInterval(int interval)
以毫秒为单位设置从服务器更新信任列表到interval 的时间间隔。
另请参阅 trustListUpdateInterval() 。
void QOpcUaGdsClient::start()
启动客户端进程。
设置完所有信息后,就可以启动客户端。
- setBackend
- 设置结束
- setApplicationIdentity
- setPkiConfiguration
- setApplicationRecord
- 设置证书认证请求预置
QOpcUaGdsClient::State QOpcUaGdsClient::state() const
返回当前客户端状态。
[signal]
void QOpcUaGdsClient::stateChanged(QOpcUaGdsClient::State state)
当客户端的内部状态发生变化时,就会发出该信号。state 表示新状态。
int QOpcUaGdsClient::trustListUpdateInterval() const
返回从服务器更新信任列表的时间间隔(毫秒)。
另请参阅 setTrustListUpdateInterval()。
[signal]
void QOpcUaGdsClient::trustListUpdated()
当 GDS 客户端从服务器接收到新的信任列表并存储到磁盘上时,就会发出该信号。
void QOpcUaGdsClient::unregisterApplication()
从服务器上取消注册应用程序。
当应用程序必须从网络中永久删除时,可以使用该函数。重启或关机时无需调用该函数。
[signal]
void QOpcUaGdsClient::unregistered()
该信号在 GDS 客户端取消注册应用程序时发出。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.