NetworkDiscovery: Fix possible crash on monitor cleanup

DateTime: Improve performance by using static current QDateTime method
pull/699/head
Simon Stürz 2025-04-14 12:02:15 +02:00
parent 91c3cf88a8
commit 00fc81405b
3 changed files with 15 additions and 9 deletions

View File

@ -287,14 +287,14 @@ NetworkDeviceMonitor *NetworkDeviceDiscoveryImpl::registerMonitor(Thing *thing)
}
break;
case NetworkDeviceInfo::MonitorModeHostName:
// Search the unique mac address
// Search the hostname in the cache
if (networkDeviceInfo.hostName() == internalMonitor->hostName()) {
qCDebug(dcNetworkDeviceDiscovery()) << "Host name monitor:" << networkDeviceInfo;
internalMonitor->setNetworkDeviceInfo(networkDeviceInfo);
}
break;
case NetworkDeviceInfo::MonitorModeIp:
// Search the unique mac address
// Search the IP in the cache
if (networkDeviceInfo.address() == internalMonitor->address()) {
qCDebug(dcNetworkDeviceDiscovery()) << "IP monitor:" << networkDeviceInfo;
internalMonitor->setNetworkDeviceInfo(networkDeviceInfo);
@ -857,7 +857,7 @@ void NetworkDeviceDiscoveryImpl::processArpTraffic(const QNetworkInterface &inte
bool NetworkDeviceDiscoveryImpl::longerAgoThan(const QDateTime &dateTime, uint seconds)
{
uint duration = (QDateTime::currentDateTime().toMSecsSinceEpoch() - dateTime.toMSecsSinceEpoch()) / 1000.0;
uint duration = (QDateTime::currentMSecsSinceEpoch() - dateTime.toMSecsSinceEpoch()) / 1000.0;
return duration >= seconds;
}
@ -905,9 +905,7 @@ NetworkDeviceMonitorImpl *NetworkDeviceDiscoveryImpl::createPluginMonitor(Networ
});
// In case the plugin user is deleting the monitor object, we need to clean up here and check if we can remove the internal monitor
connect(pluginMonitor, &NetworkDeviceDiscoveryImpl::destroyed, this, [this, pluginMonitor](QObject *) {
cleanupPluginMonitor(pluginMonitor);
});
connect(pluginMonitor, &NetworkDeviceMonitorImpl::destroyed, this, &NetworkDeviceDiscoveryImpl::onPluginMonitorDeleted);
return pluginMonitor;
}
@ -918,6 +916,7 @@ void NetworkDeviceDiscoveryImpl::cleanupPluginMonitor(NetworkDeviceMonitorImpl *
foreach (NetworkDeviceMonitorImpl *internalMonitor, m_monitors.keys()) {
if (m_monitors.value(internalMonitor).contains(pluginMonitor)) {
m_monitors[internalMonitor].removeAll(pluginMonitor);
disconnect(pluginMonitor, &NetworkDeviceMonitorImpl::destroyed, this, &NetworkDeviceDiscoveryImpl::onPluginMonitorDeleted);
pluginMonitor->deleteLater();
if (m_monitors.value(internalMonitor).isEmpty()) {
@ -1006,4 +1005,9 @@ void NetworkDeviceDiscoveryImpl::finishDiscovery()
}
}
void NetworkDeviceDiscoveryImpl::onPluginMonitorDeleted(QObject *)
{
cleanupPluginMonitor(qobject_cast<NetworkDeviceMonitorImpl *>(sender()));
}
}

View File

@ -154,6 +154,8 @@ private slots:
void evaluateMonitors();
void finishDiscovery();
void onPluginMonitorDeleted(QObject *);
};
}

View File

@ -270,7 +270,7 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent):
});
connect(m_platform->systemController(), &PlatformSystemController::timeConfigurationChanged, this, [this](){
QVariantMap params;
params.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000);
params.insert("time", QDateTime::currentMSecsSinceEpoch() / 1000);
params.insert("timeZone", QTimeZone::systemTimeZoneId());
params.insert("automaticTimeAvailable", m_platform->systemController()->automaticTimeAvailable());
params.insert("automaticTime", m_platform->systemController()->automaticTime());
@ -401,7 +401,7 @@ JsonReply *SystemHandler::GetTime(const QVariantMap &params) const
QVariantMap returns;
returns.insert("automaticTimeAvailable", m_platform->systemController()->automaticTimeAvailable());
returns.insert("automaticTime", m_platform->systemController()->automaticTime());
returns.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000);
returns.insert("time", QDateTime::currentMSecsSinceEpoch() / 1000);
returns.insert("timeZone", QTimeZone::systemTimeZoneId());
return createReply(returns);
}