Skip to content

Commit

Permalink
async refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Jan 10, 2022
1 parent bfc0352 commit 615a404
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions selfdrive/ui/qt/offroad/wifiManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ void WifiManager::stop() {
void WifiManager::refreshNetworks() {
if (adapter.isEmpty()) return;

ipv4_address = get_ipv4_address();
QDBusInterface nm = QDBusInterface(NM_DBUS_SERVICE, adapter, NM_DBUS_INTERFACE_DEVICE_WIRELESS, bus);
nm.setTimeout(DBUS_TIMEOUT);
QDBusPendingCall pending_call = nm.asyncCall("GetAllAccessPoints");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending_call);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &WifiManager::activationFinished);
}

void WifiManager::activationFinished(QDBusPendingCallWatcher *call) {
QMap<QString, Network> networks;
const QDBusReply<QList<QDBusObjectPath>> &response = call(adapter, NM_DBUS_INTERFACE_DEVICE_WIRELESS, "GetAllAccessPoints");
for (const QDBusObjectPath &path : response.value()) {
const QDBusReply<QList<QDBusObjectPath>> reply = *call;
for (const QDBusObjectPath &path : reply.value()) {
const QByteArray &ssid = get_property(path.path(), "Ssid");
if (ssid.isEmpty()) continue;

Expand All @@ -74,8 +80,11 @@ void WifiManager::refreshNetworks() {
}
networks[ssid] = {ssid, strength, ctype, security};
}

seenNetworks = networks;
ipv4_address = get_ipv4_address();
emit refreshSignal();
call->deleteLater();
}

QString WifiManager::get_ipv4_address() {
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/ui/qt/offroad/wifiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <optional>

#include <QDBusPendingCallWatcher>
#include <QtDBus>
#include <QTimer>

Expand Down Expand Up @@ -124,4 +125,5 @@ private slots:
void deviceAdded(const QDBusObjectPath &path);
void connectionRemoved(const QDBusObjectPath &path);
void newConnection(const QDBusObjectPath &path);
void activationFinished(QDBusPendingCallWatcher *call);
};

0 comments on commit 615a404

Please sign in to comment.