Changeset View
Changeset View
Standalone View
Standalone View
libs/handler.cpp
Show First 20 Lines • Show All 490 Lines • ▼ Show 20 Line(s) | 490 | for (NetworkManager::Device::Ptr device : NetworkManager::networkInterfaces()) { | |||
---|---|---|---|---|---|
491 | if (device->type() == NetworkManager::Device::Wifi) { | 491 | if (device->type() == NetworkManager::Device::Wifi) { | ||
492 | NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast<NetworkManager::WirelessDevice>(); | 492 | NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast<NetworkManager::WirelessDevice>(); | ||
493 | 493 | | |||
494 | if (wifiDevice && wifiDevice->state() != NetworkManager::WirelessDevice::Unavailable) { | 494 | if (wifiDevice && wifiDevice->state() != NetworkManager::WirelessDevice::Unavailable) { | ||
495 | if (!interface.isEmpty() && interface != wifiDevice->interfaceName()) { | 495 | if (!interface.isEmpty() && interface != wifiDevice->interfaceName()) { | ||
496 | continue; | 496 | continue; | ||
497 | } | 497 | } | ||
498 | 498 | | |||
499 | if (!checkRequestScanRateLimit(wifiDevice)) { | ||||
500 | return; | ||||
501 | } | ||||
502 | | ||||
499 | qCDebug(PLASMA_NM) << "Requesting wifi scan on device" << wifiDevice->interfaceName(); | 503 | qCDebug(PLASMA_NM) << "Requesting wifi scan on device" << wifiDevice->interfaceName(); | ||
500 | QDBusPendingReply<> reply = wifiDevice->requestScan(); | 504 | QDBusPendingReply<> reply = wifiDevice->requestScan(); | ||
501 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | 505 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||
502 | watcher->setProperty("action", Handler::RequestScan); | 506 | watcher->setProperty("action", Handler::RequestScan); | ||
503 | watcher->setProperty("interface", wifiDevice->interfaceName()); | 507 | watcher->setProperty("interface", wifiDevice->interfaceName()); | ||
504 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | 508 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | ||
505 | } | 509 | } | ||
506 | } | 510 | } | ||
507 | } | 511 | } | ||
508 | } | 512 | } | ||
509 | 513 | | |||
514 | bool Handler::checkRequestScanRateLimit(const NetworkManager::WirelessDevice::Ptr &wifiDevice) | ||||
515 | { | ||||
516 | QDateTime now = QDateTime::currentDateTime(); | ||||
517 | QDateTime lastScan = wifiDevice->lastScan(); | ||||
518 | QDateTime lastRequestScan = wifiDevice->lastRequestScan(); | ||||
519 | | ||||
520 | // if the last scan finished within the last 10 seconds | ||||
521 | bool ret = lastScan.isValid() && lastScan.msecsTo(now) < 10 * 1000; | ||||
522 | // or a scan request has been sent but hasn't finished yet | ||||
523 | ret |= lastRequestScan.isValid() && lastScan.isValid() && lastScan < lastRequestScan; | ||||
524 | // or if the last Request was sent within the last 10 seconds | ||||
525 | ret |= lastRequestScan.isValid() && lastRequestScan.msecsTo(now) < 10 * 1000; | ||||
526 | // skip the request scan | ||||
527 | if (ret) { | ||||
528 | qCDebug(PLASMA_NM) << "Last scan finished " << lastScan.msecsTo(now) << "ms ago and last request scan was sent " | ||||
529 | << lastRequestScan.msecsTo(now) << "ms ago, Skipping scanning interface:" << wifiDevice->interfaceName(); | ||||
530 | return false; | ||||
531 | } | ||||
532 | return true; | ||||
533 | } | ||||
534 | | ||||
510 | void Handler::scanRequestFailed(const QString &interface) | 535 | void Handler::scanRequestFailed(const QString &interface) | ||
511 | { | 536 | { | ||
512 | if (m_wirelessScanRetryTimer.isActive()) { | 537 | if (m_wirelessScanRetryTimer.isActive()) { | ||
513 | return; | 538 | return; | ||
514 | } | 539 | } | ||
515 | qCDebug(PLASMA_NM) << "Trying soon a new scan on" << interface; | 540 | qCDebug(PLASMA_NM) << "Trying soon a new scan on" << interface; | ||
516 | 541 | | |||
517 | emit wirelessScanTimerEnabled(false); | 542 | emit wirelessScanTimerEnabled(false); | ||
518 | 543 | | |||
519 | auto retryAction = [this,interface]() { | 544 | auto retryAction = [this,interface]() { | ||
jgrulich: This timer never gets deleted. | |||||
timer will be one of the value of hash m_wirelessScanRetryTimer, which are cleaned line 516. meven: timer will be one of the value of hash m_wirelessScanRetryTimer, which are cleaned line 516.
I… | |||||
You remove it just from the map, but it doesn't get deleted, you would need to do something like delete m_wirelessScanRetryTime.take(interface); jgrulich: You remove it just from the map, but it doesn't get deleted, you would need to do something… | |||||
520 | m_wirelessScanRetryTimer.disconnect(); | 545 | m_wirelessScanRetryTimer.disconnect(); | ||
521 | requestScan(interface); | 546 | requestScan(interface); | ||
522 | }; | 547 | }; | ||
523 | connect(&m_wirelessScanRetryTimer, &QTimer::timeout, this, retryAction); | 548 | connect(&m_wirelessScanRetryTimer, &QTimer::timeout, this, retryAction); | ||
524 | m_wirelessScanRetryTimer.start(); | 549 | m_wirelessScanRetryTimer.start(); | ||
525 | } | 550 | } | ||
526 | 551 | | |||
527 | void Handler::initKdedModule() | 552 | void Handler::initKdedModule() | ||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |
This timer never gets deleted.