summaryrefslogtreecommitdiffstats
path: root/src/BobinkClient.cpp
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-19 22:59:08 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-19 22:59:08 +0100
commitf4da422087f77ce9a549ff73250910e5ae217ff0 (patch)
tree239aa732304bc77f6767aad7e17a9c46d8740b1a /src/BobinkClient.cpp
parent364430e417600c68133673254b58b4d35608777a (diff)
downloadBobinkQtOpcUa-f4da422087f77ce9a549ff73250910e5ae217ff0.tar.gz
BobinkQtOpcUa-f4da422087f77ce9a549ff73250910e5ae217ff0.zip
Refactor BobinkClient and clean up comments
- Format BobinkAuth.cpp to match GNU style used elsewhere - Replace brittle error name array with QMetaEnum in BobinkClient - Move QOpcUaPkiConfiguration include from header to .cpp - Replace m_discoveryInterval member with file-scope constant - Add doc comments to SecurityMode and SecurityPolicy enums - Comment endpoint selection strategy in handleEndpointsReceived - Add missing QML ids to connectionPage and serverListView
Diffstat (limited to 'src/BobinkClient.cpp')
-rw-r--r--src/BobinkClient.cpp31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/BobinkClient.cpp b/src/BobinkClient.cpp
index 6d1c608..7355a0c 100644
--- a/src/BobinkClient.cpp
+++ b/src/BobinkClient.cpp
@@ -6,11 +6,15 @@
#include "BobinkAuth.h"
#include <QDir>
+#include <QMetaEnum>
+#include <QOpcUaPkiConfiguration>
#include <QOpcUaUserTokenPolicy>
#include <QStandardPaths>
using namespace Qt::Literals::StringLiterals;
+static constexpr qint32 DISCOVERY_INTERVAL = 30000; // ms
+
static QString
defaultPkiDir ()
{
@@ -87,23 +91,13 @@ BobinkClient::setupClient ()
connect (m_client, &QOpcUaClient::errorChanged, this,
[this] (QOpcUaClient::ClientError error)
{
- static const QLatin1StringView names[] = {
- "NoError"_L1,
- "InvalidUrl"_L1,
- "AccessDenied"_L1,
- "ConnectionError"_L1,
- "UnknownError"_L1,
- "UnsupportedAuthenticationInformation"_L1,
- "InvalidAuthenticationInformation"_L1,
- "InvalidEndpointDescription"_L1,
- "NoMatchingUserIdentityTokenFound"_L1,
- "UnsupportedSecurityPolicy"_L1,
- "InvalidPki"_L1,
- };
- qint32 idx = static_cast<qint32> (error);
- if (idx > 0 && idx <= 10)
- emit connectionError (
- QStringLiteral ("Client error: %1").arg (names[idx]));
+ if (error == QOpcUaClient::NoError)
+ return;
+ auto me = QMetaEnum::fromType<QOpcUaClient::ClientError> ();
+ const char *key = me.valueToKey (static_cast<int> (error));
+ emit connectionError (
+ QStringLiteral ("Client error: %1")
+ .arg (key ? QLatin1StringView (key) : "Unknown"_L1));
});
}
@@ -290,6 +284,7 @@ BobinkClient::handleEndpointsReceived (
return;
}
+ // Pick the endpoint with the highest securityLevel (server-assigned score).
QOpcUaEndpointDescription best = endpoints.first ();
for (const auto &ep : endpoints)
{
@@ -381,7 +376,7 @@ BobinkClient::startDiscovery ()
return;
doDiscovery ();
- m_discoveryTimer.start (m_discoveryInterval);
+ m_discoveryTimer.start (DISCOVERY_INTERVAL);
if (!m_discovering)
{