Update internal reply clean up order. Fix #588
This commit is contained in:
parent
5272ab8b9c
commit
b7f5a260ac
@ -64,7 +64,7 @@ NetworkDeviceDiscoveryImpl::NetworkDeviceDiscoveryImpl(QObject *parent) :
|
|||||||
m_discoveryTimer->setInterval(20000);
|
m_discoveryTimer->setInterval(20000);
|
||||||
m_discoveryTimer->setSingleShot(true);
|
m_discoveryTimer->setSingleShot(true);
|
||||||
connect(m_discoveryTimer, &QTimer::timeout, this, [=](){
|
connect(m_discoveryTimer, &QTimer::timeout, this, [=](){
|
||||||
if (m_runningPingRepies.isEmpty() && m_currentReply) {
|
if (m_runningPingReplies.isEmpty() && m_currentReply) {
|
||||||
finishDiscovery();
|
finishDiscovery();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -105,30 +105,48 @@ NetworkDeviceDiscoveryReply *NetworkDeviceDiscoveryImpl::discover()
|
|||||||
// Create the internal object if required
|
// Create the internal object if required
|
||||||
bool alreadyRunning = (m_currentReply != nullptr);
|
bool alreadyRunning = (m_currentReply != nullptr);
|
||||||
if (alreadyRunning) {
|
if (alreadyRunning) {
|
||||||
qCDebug(dcNetworkDeviceDiscovery()) << "Discovery internally already running. Re-using the current running discovery reply.";
|
if (m_currentReply->isFinished()) {
|
||||||
|
qCDebug(dcNetworkDeviceDiscovery()) << "Discovery internally already running and finished.";
|
||||||
|
} else {
|
||||||
|
qCDebug(dcNetworkDeviceDiscovery()) << "Discovery internally already running. Re-using the current running discovery reply.";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcNetworkDeviceDiscovery()) << "Starting internally a new discovery.";
|
qCDebug(dcNetworkDeviceDiscovery()) << "Starting internally a new discovery.";
|
||||||
m_currentReply = new NetworkDeviceDiscoveryReplyImpl(this);
|
m_currentReply = new NetworkDeviceDiscoveryReplyImpl(this);
|
||||||
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::networkDeviceInfoAdded, this, &NetworkDeviceDiscoveryImpl::updateCache);
|
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::networkDeviceInfoAdded, this, &NetworkDeviceDiscoveryImpl::updateCache);
|
||||||
|
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::finished, this, [this](){
|
||||||
|
// Finish all pending replies
|
||||||
|
foreach (NetworkDeviceDiscoveryReplyImpl *reply, m_pendingReplies) {
|
||||||
|
|
||||||
|
// Sync all network device infos with all pending replies
|
||||||
|
foreach (const NetworkDeviceInfo &info, m_currentReply->networkDeviceInfos()) {
|
||||||
|
reply->addCompleteNetworkDeviceInfo(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const NetworkDeviceInfo &info, m_currentReply->virtualNetworkDeviceInfos()) {
|
||||||
|
reply->addVirtualNetworkDeviceInfo(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the current reply before finishing the pending replies.
|
||||||
|
// Just in case some one restarts a discovery on finished, a new internal
|
||||||
|
// object should be created
|
||||||
|
m_currentReply->deleteLater();
|
||||||
|
m_currentReply = nullptr;
|
||||||
|
|
||||||
|
foreach (NetworkDeviceDiscoveryReplyImpl *reply, m_pendingReplies) {
|
||||||
|
m_pendingReplies.removeAll(reply);
|
||||||
|
reply->setFinished(true);
|
||||||
|
emit reply->finished();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the reply for the user
|
// Create the reply for the user
|
||||||
NetworkDeviceDiscoveryReplyImpl *reply = new NetworkDeviceDiscoveryReplyImpl(this);
|
NetworkDeviceDiscoveryReplyImpl *reply = new NetworkDeviceDiscoveryReplyImpl(this);
|
||||||
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::networkDeviceInfoAdded, reply, &NetworkDeviceDiscoveryReplyImpl::addCompleteNetworkDeviceInfo);
|
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::networkDeviceInfoAdded, reply, &NetworkDeviceDiscoveryReplyImpl::addCompleteNetworkDeviceInfo);
|
||||||
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::hostAddressDiscovered, reply, &NetworkDeviceDiscoveryReplyImpl::hostAddressDiscovered);
|
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::hostAddressDiscovered, reply, &NetworkDeviceDiscoveryReplyImpl::hostAddressDiscovered);
|
||||||
connect(m_currentReply, &NetworkDeviceDiscoveryReplyImpl::finished, reply, [this, reply](){
|
m_pendingReplies.append(reply);
|
||||||
// Sync all network device infos with all pending replies
|
|
||||||
foreach (const NetworkDeviceInfo &info, m_currentReply->networkDeviceInfos()) {
|
|
||||||
reply->addCompleteNetworkDeviceInfo(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const NetworkDeviceInfo &info, m_currentReply->virtualNetworkDeviceInfos()) {
|
|
||||||
reply->addVirtualNetworkDeviceInfo(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
reply->setFinished(true);
|
|
||||||
emit reply->finished();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!available()) {
|
if (!available()) {
|
||||||
qCWarning(dcNetworkDeviceDiscovery()) << "The network discovery is not available. Please make sure the binary has the required capability (CAP_NET_RAW) or start the application as root.";
|
qCWarning(dcNetworkDeviceDiscovery()) << "The network discovery is not available. Please make sure the binary has the required capability (CAP_NET_RAW) or start the application as root.";
|
||||||
@ -141,6 +159,9 @@ NetworkDeviceDiscoveryReply *NetworkDeviceDiscoveryImpl::discover()
|
|||||||
// Add already discovered network device infos in the next event loop
|
// Add already discovered network device infos in the next event loop
|
||||||
// so any connections after this method call will work as expected
|
// so any connections after this method call will work as expected
|
||||||
QTimer::singleShot(0, reply, [this, reply](){
|
QTimer::singleShot(0, reply, [this, reply](){
|
||||||
|
if (!m_currentReply)
|
||||||
|
return;
|
||||||
|
|
||||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, m_currentReply->networkDeviceInfos()) {
|
foreach (const NetworkDeviceInfo &networkDeviceInfo, m_currentReply->networkDeviceInfos()) {
|
||||||
reply->addCompleteNetworkDeviceInfo(networkDeviceInfo);
|
reply->addCompleteNetworkDeviceInfo(networkDeviceInfo);
|
||||||
}
|
}
|
||||||
@ -340,9 +361,9 @@ void NetworkDeviceDiscoveryImpl::pingAllNetworkDevices()
|
|||||||
|
|
||||||
// Retry only once to ping a device and lookup the hostname on success
|
// Retry only once to ping a device and lookup the hostname on success
|
||||||
PingReply *reply = ping(targetAddress, true, 1);
|
PingReply *reply = ping(targetAddress, true, 1);
|
||||||
m_runningPingRepies.append(reply);
|
m_runningPingReplies.append(reply);
|
||||||
connect(reply, &PingReply::finished, this, [=](){
|
connect(reply, &PingReply::finished, this, [=](){
|
||||||
m_runningPingRepies.removeAll(reply);
|
m_runningPingReplies.removeAll(reply);
|
||||||
if (reply->error() == PingReply::ErrorNoError) {
|
if (reply->error() == PingReply::ErrorNoError) {
|
||||||
qCDebug(dcNetworkDeviceDiscovery()) << "Ping response from" << targetAddress.toString() << reply->hostName() << reply->duration() << "ms";
|
qCDebug(dcNetworkDeviceDiscovery()) << "Ping response from" << targetAddress.toString() << reply->hostName() << reply->duration() << "ms";
|
||||||
if (m_currentReply) {
|
if (m_currentReply) {
|
||||||
@ -350,7 +371,7 @@ void NetworkDeviceDiscoveryImpl::pingAllNetworkDevices()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_runningPingRepies.isEmpty() && m_currentReply && !m_discoveryTimer->isActive()) {
|
if (m_runningPingReplies.isEmpty() && m_currentReply && !m_discoveryTimer->isActive()) {
|
||||||
qCWarning(dcNetworkDeviceDiscovery()) << "All ping replies finished for discovery." << m_currentReply->networkDeviceInfos().count();
|
qCWarning(dcNetworkDeviceDiscovery()) << "All ping replies finished for discovery." << m_currentReply->networkDeviceInfos().count();
|
||||||
finishDiscovery();
|
finishDiscovery();
|
||||||
}
|
}
|
||||||
@ -695,9 +716,9 @@ void NetworkDeviceDiscoveryImpl::finishDiscovery()
|
|||||||
m_lastDiscovery = QDateTime::currentDateTime();
|
m_lastDiscovery = QDateTime::currentDateTime();
|
||||||
|
|
||||||
// Clean up internal reply
|
// Clean up internal reply
|
||||||
m_currentReply->processDiscoveryFinished();
|
if (m_currentReply) {
|
||||||
m_currentReply->deleteLater();
|
m_currentReply->processDiscoveryFinished();
|
||||||
m_currentReply = nullptr;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,7 +102,8 @@ private:
|
|||||||
uint m_cacheCleanupPeriod = 30; // days
|
uint m_cacheCleanupPeriod = 30; // days
|
||||||
|
|
||||||
NetworkDeviceDiscoveryReplyImpl *m_currentReply = nullptr;
|
NetworkDeviceDiscoveryReplyImpl *m_currentReply = nullptr;
|
||||||
QList<PingReply *> m_runningPingRepies;
|
QList<NetworkDeviceDiscoveryReplyImpl *> m_pendingReplies;
|
||||||
|
QList<PingReply *> m_runningPingReplies;
|
||||||
|
|
||||||
QHash<MacAddress, NetworkDeviceMonitorImpl *> m_monitors;
|
QHash<MacAddress, NetworkDeviceMonitorImpl *> m_monitors;
|
||||||
QHash<MacAddress, int> m_monitorsReferenceCount;
|
QHash<MacAddress, int> m_monitorsReferenceCount;
|
||||||
|
|||||||
@ -183,13 +183,12 @@ void NetworkDeviceDiscoveryReplyImpl::processDiscoveryFinished()
|
|||||||
qCDebug(dcNetworkDeviceDiscovery()) << "--> " << info;
|
qCDebug(dcNetworkDeviceDiscovery()) << "--> " << info;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(dcNetworkDeviceDiscovery()) << "Rest:";
|
|
||||||
foreach (const MacAddress &macAddress, m_networkDeviceCache.keys()) {
|
foreach (const MacAddress &macAddress, m_networkDeviceCache.keys()) {
|
||||||
if (m_networkDeviceInfos.hasMacAddress(macAddress))
|
if (m_networkDeviceInfos.hasMacAddress(macAddress))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
NetworkDeviceInfo info = m_networkDeviceCache.value(macAddress);
|
NetworkDeviceInfo info = m_networkDeviceCache.value(macAddress);
|
||||||
qCDebug(dcNetworkDeviceDiscovery()) << "--> " << info << "Valid:" << info.isValid() << "Complete:" << info.isComplete() << info.incompleteProperties();
|
qCDebug(dcNetworkDeviceDiscovery()) << "Unhandled information:" << info << "Valid:" << info.isValid() << "Complete:" << info.isComplete() << info.incompleteProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isFinished = true;
|
m_isFinished = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user