Cleanup discovery and fix comments
This commit is contained in:
parent
a237bb5d3a
commit
60baf97c5f
@ -40,12 +40,7 @@ SunnyWebBoxDiscovery::SunnyWebBoxDiscovery(NetworkAccessManager *networkAccessMa
|
|||||||
m_networkAccessManager(networkAccessManager),
|
m_networkAccessManager(networkAccessManager),
|
||||||
m_networkDeviceDiscovery(networkDeviceDiscovery)
|
m_networkDeviceDiscovery(networkDeviceDiscovery)
|
||||||
{
|
{
|
||||||
m_gracePeriodTimer.setSingleShot(true);
|
|
||||||
m_gracePeriodTimer.setInterval(3000);
|
|
||||||
connect(&m_gracePeriodTimer, &QTimer::timeout, this, [this](){
|
|
||||||
qCDebug(dcSma()) << "Discovery: SunnyWebBox: Grace period timer triggered.";
|
|
||||||
finishDiscovery();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunnyWebBoxDiscovery::startDiscovery()
|
void SunnyWebBoxDiscovery::startDiscovery()
|
||||||
@ -53,14 +48,13 @@ void SunnyWebBoxDiscovery::startDiscovery()
|
|||||||
// Clean up
|
// Clean up
|
||||||
m_discoveryResults.clear();
|
m_discoveryResults.clear();
|
||||||
m_verifiedNetworkDeviceInfos.clear();
|
m_verifiedNetworkDeviceInfos.clear();
|
||||||
m_gracePeriodTimer.stop();
|
|
||||||
|
|
||||||
m_startDateTime = QDateTime::currentDateTime();
|
m_startDateTime = QDateTime::currentDateTime();
|
||||||
|
|
||||||
qCInfo(dcSma()) << "Discovery: SunnyWebBox: Start discovering the network...";
|
qCInfo(dcSma()) << "Discovery: SunnyWebBox: Starting network discovery...";
|
||||||
m_discoveryReply = m_networkDeviceDiscovery->discover();
|
m_discoveryReply = m_networkDeviceDiscovery->discover();
|
||||||
|
|
||||||
// Check if all network device infos which might already be discovered here to save time...
|
// Check all network device infos which might already be discovered here to save time...
|
||||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, m_discoveryReply->networkDeviceInfos()) {
|
foreach (const NetworkDeviceInfo &networkDeviceInfo, m_discoveryReply->networkDeviceInfos()) {
|
||||||
checkNetworkDevice(networkDeviceInfo);
|
checkNetworkDevice(networkDeviceInfo);
|
||||||
}
|
}
|
||||||
@ -85,7 +79,10 @@ void SunnyWebBoxDiscovery::startDiscovery()
|
|||||||
// If there might be some response after the grace period time,
|
// If there might be some response after the grace period time,
|
||||||
// we don't care any more since there might just waiting for some timeouts...
|
// we don't care any more since there might just waiting for some timeouts...
|
||||||
// If there would be a device, if would have responded.
|
// If there would be a device, if would have responded.
|
||||||
m_gracePeriodTimer.start();
|
QTimer::singleShot(3000, this, [this](){
|
||||||
|
qCDebug(dcSma()) << "Discovery: SunnyWebBox: Grace period timer triggered.";
|
||||||
|
finishDiscovery();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +93,11 @@ NetworkDeviceInfos SunnyWebBoxDiscovery::discoveryResults() const
|
|||||||
|
|
||||||
void SunnyWebBoxDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo)
|
void SunnyWebBoxDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo)
|
||||||
{
|
{
|
||||||
|
if (m_verifiedNetworkDeviceInfos.contains(networkDeviceInfo))
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_verifiedNetworkDeviceInfos.append(networkDeviceInfo);
|
||||||
|
|
||||||
// Make a simple request and verify if it worked and the expected data gets returned.
|
// Make a simple request and verify if it worked and the expected data gets returned.
|
||||||
SunnyWebBox webBox(m_networkAccessManager, networkDeviceInfo.address(), this);
|
SunnyWebBox webBox(m_networkAccessManager, networkDeviceInfo.address(), this);
|
||||||
QNetworkReply *reply = webBox.sendRequest(networkDeviceInfo.address(), "GetPlantOverview");
|
QNetworkReply *reply = webBox.sendRequest(networkDeviceInfo.address(), "GetPlantOverview");
|
||||||
@ -147,7 +149,6 @@ void SunnyWebBoxDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDe
|
|||||||
void SunnyWebBoxDiscovery::cleanupPendingReplies()
|
void SunnyWebBoxDiscovery::cleanupPendingReplies()
|
||||||
{
|
{
|
||||||
foreach (QNetworkReply *reply, m_pendingReplies) {
|
foreach (QNetworkReply *reply, m_pendingReplies) {
|
||||||
m_pendingReplies.removeAll(reply);
|
|
||||||
reply->abort();
|
reply->abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +158,7 @@ void SunnyWebBoxDiscovery::finishDiscovery()
|
|||||||
qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_startDateTime.toMSecsSinceEpoch();
|
qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_startDateTime.toMSecsSinceEpoch();
|
||||||
qCInfo(dcSma()) << "Discovery: SunnyWebBox: Finished the discovery process. Found" << m_discoveryResults.count()
|
qCInfo(dcSma()) << "Discovery: SunnyWebBox: Finished the discovery process. Found" << m_discoveryResults.count()
|
||||||
<< "Sunny WebBoxes in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz");
|
<< "Sunny WebBoxes in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz");
|
||||||
m_gracePeriodTimer.stop();
|
|
||||||
cleanupPendingReplies();
|
cleanupPendingReplies();
|
||||||
emit discoveryFinished();
|
emit discoveryFinished();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,6 @@ private:
|
|||||||
NetworkDeviceInfos m_discoveredNetworkDeviceInfos;
|
NetworkDeviceInfos m_discoveredNetworkDeviceInfos;
|
||||||
NetworkDeviceInfos m_verifiedNetworkDeviceInfos;
|
NetworkDeviceInfos m_verifiedNetworkDeviceInfos;
|
||||||
|
|
||||||
QTimer m_gracePeriodTimer;
|
|
||||||
QDateTime m_startDateTime;
|
QDateTime m_startDateTime;
|
||||||
QList<QNetworkReply *> m_pendingReplies;
|
QList<QNetworkReply *> m_pendingReplies;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user