From f4da422087f77ce9a549ff73250910e5ae217ff0 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Thu, 19 Feb 2026 22:59:08 +0100 Subject: 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 --- src/BobinkClient.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/BobinkClient.cpp') 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 +#include +#include #include #include 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 (error); - if (idx > 0 && idx <= 10) - emit connectionError ( - QStringLiteral ("Client error: %1").arg (names[idx])); + if (error == QOpcUaClient::NoError) + return; + auto me = QMetaEnum::fromType (); + const char *key = me.valueToKey (static_cast (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) { -- cgit v1.2.3