diff options
author | Jannis Voelker <jannis.voelker@basyskom.com> | 2018-01-11 11:01:49 +0100 |
---|---|---|
committer | Frank Meerkoetter <frank.meerkoetter@basyskom.com> | 2018-02-23 13:16:14 +0000 |
commit | ed0a475529f2ec7be427900b08dfedb1d47e7c9a (patch) | |
tree | eefb04e36a2926f1a521b6311e4aea0161c88f4d | |
parent | aea5ec084d64b614e6c600816aa92044fd5ed938 (diff) |
Use async publish in the open62541 backend
This patch changes the open62541 backend to make use of the
new async publish mechanism.
This removes the disconnects caused by subscriptions with
publishingInterval * maxKeepAliveCount > clientTimeout
and reduces the latency between calls to the client and execution
by the backend (up to 4 seconds using the old publish mechanism).
Change-Id: Ib9be91e08072a34e05a232a612519fb82f21fd49
Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
-rw-r--r-- | src/opcua/client/qopcuamonitoringparameters_p.h | 4 | ||||
-rw-r--r-- | src/plugins/opcua/open62541/qopen62541backend.cpp | 13 | ||||
-rw-r--r-- | src/plugins/opcua/open62541/qopen62541backend.h | 1 |
3 files changed, 6 insertions, 12 deletions
diff --git a/src/opcua/client/qopcuamonitoringparameters_p.h b/src/opcua/client/qopcuamonitoringparameters_p.h index 3deafea..2c11145 100644 --- a/src/opcua/client/qopcuamonitoringparameters_p.h +++ b/src/opcua/client/qopcuamonitoringparameters_p.h @@ -65,8 +65,8 @@ public: , monitoringMode(QOpcUaMonitoringParameters::MonitoringMode::Reporting) , subscriptionId(0) , publishingInterval(0) - , lifetimeCount(0) - , maxKeepAliveCount(0) + , lifetimeCount(150) // Must be at least three times the maxKeepAliveCount (OPC-UA part 4, page 76). + , maxKeepAliveCount(50) // Allow 50 publishing intervals before a keepalive is expected to reduce the network traffic. , maxNotificationsPerPublish(0) , priority(0) , publishingEnabled(true) diff --git a/src/plugins/opcua/open62541/qopen62541backend.cpp b/src/plugins/opcua/open62541/qopen62541backend.cpp index bb30ef7..a29b847 100644 --- a/src/plugins/opcua/open62541/qopen62541backend.cpp +++ b/src/plugins/opcua/open62541/qopen62541backend.cpp @@ -65,7 +65,6 @@ Open62541AsyncBackend::Open62541AsyncBackend(QOpen62541Client *parent) , m_clientImpl(parent) , m_subscriptionTimer(this) , m_sendPublishRequests(false) - , m_shortestInterval(std::numeric_limits<qint32>::max()) { m_subscriptionTimer.setSingleShot(true); QObject::connect(&m_subscriptionTimer, &QTimer::timeout, @@ -419,7 +418,8 @@ void Open62541AsyncBackend::browseChildren(uintptr_t handle, UA_NodeId id, QOpcU void Open62541AsyncBackend::connectToEndpoint(const QUrl &url) { - m_uaclient = UA_Client_new(UA_ClientConfig_default); + UA_ClientConfig conf = UA_ClientConfig_default; + m_uaclient = UA_Client_new(conf); UA_StatusCode ret; if (url.userName().length()) { @@ -473,7 +473,7 @@ void Open62541AsyncBackend::sendPublishRequest() } // If BADSERVERNOTCONNECTED is returned, the subscriptions are gone and local information can be deleted. - if (UA_Client_Subscriptions_manuallySendPublishRequest(m_uaclient) == UA_STATUSCODE_BADSERVERNOTCONNECTED) { + if (UA_Client_runAsync(m_uaclient, 1) == UA_STATUSCODE_BADSERVERNOTCONNECTED) { qCWarning(QT_OPCUA_PLUGINS_OPEN62541) << "Unable to send publish request"; m_sendPublishRequests = false; qDeleteAll(m_subscriptions); @@ -483,7 +483,7 @@ void Open62541AsyncBackend::sendPublishRequest() return; } - m_subscriptionTimer.start(m_shortestInterval); + m_subscriptionTimer.start(0); } void Open62541AsyncBackend::modifyPublishRequests() @@ -491,14 +491,9 @@ void Open62541AsyncBackend::modifyPublishRequests() if (m_subscriptions.count() == 0) { m_subscriptionTimer.stop(); m_sendPublishRequests = false; - m_shortestInterval = std::numeric_limits<qint32>::max(); return; } - for (auto it : qAsConst(m_subscriptions)) - if (it->interval() < m_shortestInterval) - m_shortestInterval = it->interval(); - m_subscriptionTimer.stop(); m_sendPublishRequests = true; sendPublishRequest(); diff --git a/src/plugins/opcua/open62541/qopen62541backend.h b/src/plugins/opcua/open62541/qopen62541backend.h index b452932..4fa17bf 100644 --- a/src/plugins/opcua/open62541/qopen62541backend.h +++ b/src/plugins/opcua/open62541/qopen62541backend.h @@ -87,7 +87,6 @@ private: QHash<uintptr_t, QHash<QOpcUa::NodeAttribute, QOpen62541Subscription *>> m_attributeMapping; // Handle -> Attribute -> Subscription bool m_sendPublishRequests; - qint32 m_shortestInterval; }; QT_END_NAMESPACE |