diff --git a/dynatrace/integrationplugindynatrace.cpp b/dynatrace/integrationplugindynatrace.cpp index c9df22a2..e071caa2 100644 --- a/dynatrace/integrationplugindynatrace.cpp +++ b/dynatrace/integrationplugindynatrace.cpp @@ -44,21 +44,28 @@ IntegrationPluginDynatrace::IntegrationPluginDynatrace() void IntegrationPluginDynatrace::discoverThings(ThingDiscoveryInfo *info) { - QHostInfo::lookupHost("ufo.home", info, [this, info](const QHostInfo &host){ - if (host.error() != QHostInfo::NoError) { - qCDebug(dcDynatrace()) << "Lookup failed:" << host.errorString(); - info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("An error happened discovering the UFO in the network.")); - return; - } + m_asyncDiscoveries.append(info); - // NOTE: QHostInfo::lookupHost apparently calls back from a different thread which breaks - // QNetworkAccessManager... Decouple it here with a QueuedConnection - QMetaObject::invokeMethod(this, "resolveIds", Qt::QueuedConnection, Q_ARG(ThingDiscoveryInfo*, info), Q_ARG(QHostInfo, host)); - }); + // NOTE: QHostInfo::lookupHost will call in from another thread using the Funtor syntax! + // https://bugreports.qt.io/browse/QTBUG-83073 + // Using the old school syntax... + QHostInfo::lookupHost("ufo.home", this, SLOT(resolveIds(const QHostInfo &))); } -void IntegrationPluginDynatrace::resolveIds(ThingDiscoveryInfo *info, const QHostInfo &host) +void IntegrationPluginDynatrace::resolveIds(const QHostInfo &host) { + if (m_asyncDiscoveries.isEmpty()) { + qCWarning(dcDynatrace()) << "Discvery result came in but request has vanished..."; + return; + } + + ThingDiscoveryInfo *info = m_asyncDiscoveries.takeFirst(); + if (host.error() != QHostInfo::NoError) { + qCDebug(dcDynatrace()) << "Lookup failed:" << host.errorString(); + info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("An error happened discovering the UFO in the network.")); + return; + } + QList *pendingInfoRequests = new QList(); foreach (QHostAddress address, host.addresses()) { diff --git a/dynatrace/integrationplugindynatrace.h b/dynatrace/integrationplugindynatrace.h index a1e48051..fae00132 100644 --- a/dynatrace/integrationplugindynatrace.h +++ b/dynatrace/integrationplugindynatrace.h @@ -54,19 +54,20 @@ public: void executeAction(ThingActionInfo *info) override; void thingRemoved(Thing *thing) override; + +private slots: + void onConnectionChanged(bool connected); + + void resolveIds(const QHostInfo &host); + private: PluginTimer *m_pluginTimer = nullptr; QHash m_ufoConnections; QHash m_asyncActions; QHash m_asyncSetup; + QList m_asyncDiscoveries; void getId(const QHostAddress &address); - -private slots: - void onConnectionChanged(bool connected); - -private slots: - void resolveIds(ThingDiscoveryInfo *info, const QHostInfo &host); }; #endif // INTEGRATIONPLUGINDYNATRACE_H