Skip to content

Commit

Permalink
Add ndbWifiKeepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
shermp committed Apr 24, 2024
1 parent e2a6484 commit 8ea8308
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/ndb/NDBDbus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ NDBDbus::NDBDbus(QObject* parent) : QObject(parent), QDBusContext() {
}
// Image
NDB_RESOLVE_SYMBOL("_ZN5Image11sizeForTypeERK6DeviceRK7QString", nh_symoutptr(nSym.Image__sizeForType));
NDB_RESOLVE_SYMBOL("_ZN16WirelessWatchdog14sharedInstanceEv", nh_symoutptr(nSym.WirelessWatchdog__sharedInstance));
}

/*!
Expand Down Expand Up @@ -840,6 +841,36 @@ void NDBDbus::ndbWireless(const char *act) {
nm_action_result_free(res);
}

void NDBDbus::onWWAboutToKillWifi(PermissionRequest* allow) {
if (allow != nullptr) {
NDB_DEBUG("WirelessWatchdog wants to kill Wifi. Denying request.");
*allow = false;
}
return;
}

/*!
* \brief Keep Wifi connection alive
*
* Prevents Nickel from killing the Wifi connection after a short amount of time.
* Set \a keepalive to \c true to enable the keepalive, and \c false to disable it.
* It is best to only keep Wifi enabled as long as necessary.
*
* \since 0.3.0
*/
void NDBDbus::ndbWifiKeepalive(bool keepalive) {
NDB_DBUS_USB_ASSERT((void) 0);
NDB_DBUS_ASSERT((void) 0, QDBusError::InternalError, nSym.WirelessWatchdog__sharedInstance, "no WirelessWatchdog::sharedInstance() symbol");
WirelessWatchdog *wd = nSym.WirelessWatchdog__sharedInstance();
NDB_DBUS_ASSERT((void) 0, QDBusError::InternalError, wd, "could not get WirelessWatchdog::sharedInstance()");
if (keepalive) {
QObject::connect(wd, SIGNAL(aboutToKillWifi(PermissionRequest*)), this, SLOT(onWWAboutToKillWifi(PermissionRequest*)), Qt::UniqueConnection);
} else {
QObject::disconnect(wd, SIGNAL(aboutToKillWifi(PermissionRequest*)), this, SLOT(onWWAboutToKillWifi(PermissionRequest*)));
}
return;
}

/*!
* \brief Open the web browser.
*
Expand Down
6 changes: 6 additions & 0 deletions src/ndb/NDBDbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ typedef QWidget N3Dialog;
typedef void Device;
typedef QObject FSSyncManager;
typedef FSSyncManager N3FSSyncManager;
typedef bool PermissionRequest;
typedef QObject WirelessWatchdog;

#ifndef NDB_DBUS_IFACE_NAME
#define NDB_DBUS_IFACE_NAME "com.github.shermp.nickeldbus"
Expand Down Expand Up @@ -108,6 +110,8 @@ class NDBDbus : public QObject, protected QDBusContext {
void wfmConnectWireless();
void wfmConnectWirelessSilently();
void wfmSetAirplaneMode(QString const& action);
// Wireless watchdog
void ndbWifiKeepalive(bool keepalive);
// Web Browser (BrowserWorkflowManager)
void bwmOpenBrowser(bool modal = false, QString const& url = QString(), QString const& css = QString());
// Nickel Settings
Expand All @@ -129,6 +133,7 @@ class NDBDbus : public QObject, protected QDBusContext {
void handleStackedWidgetDestroyed();
void onDlgLineEditAccepted();
void onDlgLineEditRejected();
void onWWAboutToKillWifi(PermissionRequest* allow);
private:
void *libnickel;
QSet<QString> connectedSignals;
Expand All @@ -150,6 +155,7 @@ class NDBDbus : public QObject, protected QDBusContext {
QSize (*Image__sizeForType)(Device*, QString const&);
N3FSSyncManager* (*N3FSSyncManager__sharedInstance)();
void (*N3FSSyncManager__sync)(N3FSSyncManager* _this, QStringList* paths);
WirelessWatchdog* (*WirelessWatchdog__sharedInstance)();
} nSym;
QTimer *viewTimer;
bool ndbInUSBMS();
Expand Down

0 comments on commit 8ea8308

Please sign in to comment.