mirror of https://github.com/nymea/nymea.git
NetworkDiscovery: Fix possible crash on monitor cleanup
DateTime: Improve performance by using static current QDateTime methodpull/699/head
parent
91c3cf88a8
commit
00fc81405b
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,8 @@ private slots:
|
|||
void evaluateMonitors();
|
||||
void finishDiscovery();
|
||||
|
||||
void onPluginMonitorDeleted(QObject *);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 ¶ms) 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue