diff --git a/applications/launcher/controller.cpp b/applications/launcher/controller.cpp index 0a2564219..6d8960289 100644 --- a/applications/launcher/controller.cpp +++ b/applications/launcher/controller.cpp @@ -296,18 +296,6 @@ inline void updateUI(QObject* ui, const char* name, const QVariant& value){ ui->setProperty(name, value); } } -std::string Controller::exec(const char* cmd) { - std::array buffer; - std::string result; - std::unique_ptr pipe(popen(cmd, "r"), pclose); - if (!pipe) { - throw std::runtime_error("popen() failed!"); - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - return result; -} void Controller::updateUIElements(){} void Controller::setAutomaticSleep(bool state){ m_automaticSleep = state; diff --git a/applications/launcher/controller.h b/applications/launcher/controller.h index 510d38585..ff1388525 100644 --- a/applications/launcher/controller.h +++ b/applications/launcher/controller.h @@ -58,7 +58,6 @@ class Controller : public QObject Q_PROPERTY(int maxTouchWidth READ maxTouchWidth) Q_PROPERTY(int maxTouchHeight READ maxTouchHeight) public: - static std::string exec(const char* cmd); QObject* stateController; QObject* root = nullptr; explicit Controller(QObject* parent = 0) diff --git a/applications/system-service/wlan.cpp b/applications/system-service/wlan.cpp index 138388a7d..cb9ca9637 100644 --- a/applications/system-service/wlan.cpp +++ b/applications/system-service/wlan.cpp @@ -67,8 +67,12 @@ bool Wlan::pingIP(std::string ip, const char* port) { } bool Wlan::isConnected(){ - auto ip = exec("/sbin/ip r | /bin/grep " + iface() + " | /bin/grep default | /usr/bin/awk '{print $3}'"); - return ip != "" && (pingIP(ip, "53") || pingIP(ip, "80")); + try{ + auto ip = exec("/sbin/ip r | /bin/grep " + iface() + " | /bin/grep default | /usr/bin/awk '{print $3}'"); + return ip != "" && (pingIP(ip, "53") || pingIP(ip, "80")); + }catch(const std::runtime_error&){ + return false; + } } int Wlan::link(){ @@ -83,15 +87,18 @@ int Wlan::link(){ return result; } O_WARNING("SignalPoll error: " << res.error()); - auto out = exec("/bin/grep " + iface() + " /proc/net/wireless | /usr/bin/awk '{print $3}'"); - if(QString(out.c_str()).isEmpty()){ - return 0; - } - try { - return std::stoi(out); - } - catch (const std::invalid_argument& e) { - O_WARNING("link failed: " << out.c_str()); + try{ + auto out = exec("/bin/grep " + iface() + " /proc/net/wireless | /usr/bin/awk '{print $3}'"); + if(QString(out.c_str()).isEmpty()){ + return 0; + } + try{ + return std::stoi(out); + }catch(const std::invalid_argument& e){ + O_WARNING("link failed: " << out.c_str()); + return 0; + } + }catch(const std::runtime_error&){ return 0; } return -100; @@ -109,17 +116,22 @@ signed int Wlan::rssi(){ return result; } O_WARNING("SignalPoll error: " << res.error()); - auto out = exec("/bin/grep " + iface() + " /proc/net/wireless | /usr/bin/awk '{print $4}'"); - if(QString(out.c_str()).isEmpty()){ - return 0; - } - try { - return std::stoi(out); - } - catch (const std::invalid_argument& e) { - O_WARNING("signal failed: " << out.c_str()); + try{ + auto out = exec("/bin/grep " + iface() + " /proc/net/wireless | /usr/bin/awk '{print $4}'"); + if(QString(out.c_str()).isEmpty()){ + return 0; + } + try { + return std::stoi(out); + } + catch (const std::invalid_argument& e) { + O_WARNING("signal failed: " << out.c_str()); + return 0; + } + }catch(const std::runtime_error&){ return 0; } + return -100; } @@ -158,7 +170,7 @@ std::string Wlan::exec(QString cmd) { std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd.toStdString().c_str(), "r"), pclose); - if (!pipe) { + if(!pipe){ throw std::runtime_error("popen() failed!"); } while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { diff --git a/shared/liboxide/devicesettings.cpp b/shared/liboxide/devicesettings.cpp index dfc5bedc6..c78ad0fb1 100644 --- a/shared/liboxide/devicesettings.cpp +++ b/shared/liboxide/devicesettings.cpp @@ -2,6 +2,9 @@ #include "debug.h" #include "liboxide.h" +#include "signalhandler.h" + +#include #define BITS_PER_LONG (sizeof(long) * 8) #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) @@ -77,7 +80,6 @@ namespace Oxide { }else{ O_DEBUG(("Buttons input device: " + buttonsPath).c_str()); } - watcher = new QFileSystemWatcher(QStringList() << "/dev/input", qApp); } DeviceSettings::~DeviceSettings(){} bool DeviceSettings::checkBitSet(int fd, int type, int i) { @@ -251,11 +253,17 @@ namespace Oxide { } void DeviceSettings::onInputDevicesChanged(std::function callback){ - watcher->connect(watcher, &QFileSystemWatcher::directoryChanged, qApp, [callback](const QString& path){ - qDebug() << path; - if(path == "/dev/input"){ - callback(); - } + static auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_InputMask, qApp); + QObject::connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected, qApp, [callback](const QString& device){ + Q_UNUSED(device); + callback(); + }); + QObject::connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved, qApp, [callback](const QString& device){ + Q_UNUSED(device); + callback(); + }); + QObject::connect(signalHandler, &SignalHandler::sigCont, qApp, [callback]{ + callback(); }); } diff --git a/shared/liboxide/liboxide.pro b/shared/liboxide/liboxide.pro index 87408d311..8e256b1a8 100644 --- a/shared/liboxide/liboxide.pro +++ b/shared/liboxide/liboxide.pro @@ -3,6 +3,7 @@ QT += quick QT += dbus QT += core_private QT += gui-private +QT += input_support-private TEMPLATE = lib DEFINES += LIBOXIDE_LIBRARY diff --git a/shared/liboxide/signalhandler.cpp b/shared/liboxide/signalhandler.cpp index 5c4413981..1823cf8de 100644 --- a/shared/liboxide/signalhandler.cpp +++ b/shared/liboxide/signalhandler.cpp @@ -9,13 +9,14 @@ static int sigUsr1Fd[2]; static int sigUsr2Fd[2]; +static int sigContFd[2]; namespace Oxide { int SignalHandler::setup_unix_signal_handlers(){ if(!signalHandler){ new SignalHandler(qApp); } - struct sigaction usr1, usr2; + struct sigaction usr1, usr2, cont; usr1.sa_handler = SignalHandler::usr1SignalHandler; sigemptyset(&usr1.sa_mask); @@ -33,6 +34,14 @@ namespace Oxide { return 2; } + cont.sa_handler = SignalHandler::contSignalHandler; + sigemptyset(&cont.sa_mask); + cont.sa_flags = 0; + cont.sa_flags |= SA_RESTART; + if(sigaction(SIGCONT, &cont, 0)){ + return 3; + } + return 0; } SignalHandler* SignalHandler::singleton(SignalHandler* self){ @@ -55,6 +64,8 @@ namespace Oxide { connect(snUsr1, &QSocketNotifier::activated, this, &SignalHandler::handleSigUsr1, Qt::QueuedConnection); snUsr2 = new QSocketNotifier(sigUsr2Fd[1], QSocketNotifier::Read, this); connect(snUsr2, &QSocketNotifier::activated, this, &SignalHandler::handleSigUsr2, Qt::QueuedConnection); + snCont = new QSocketNotifier(sigContFd[1], QSocketNotifier::Read, this); + connect(snCont, &QSocketNotifier::activated, this, &SignalHandler::handleSigCont, Qt::QueuedConnection); } SignalHandler::~SignalHandler(){} void SignalHandler::usr1SignalHandler(int unused){ @@ -67,6 +78,11 @@ namespace Oxide { char a = 1; ::write(sigUsr2Fd[0], &a, sizeof(a)); } + void SignalHandler::contSignalHandler(int unused){ + Q_UNUSED(unused) + char a = 1; + ::write(sigContFd[0], &a, sizeof(a)); + } void SignalHandler::handleSigUsr1(){ snUsr1->setEnabled(false); char tmp; @@ -81,6 +97,13 @@ namespace Oxide { emit sigUsr2(); snUsr2->setEnabled(true); } + void SignalHandler::handleSigCont(){ + snCont->setEnabled(false); + char tmp; + ::read(sigContFd[1], &tmp, sizeof(tmp)); + emit sigCont(); + snCont->setEnabled(true); + } } #include "moc_signalhandler.cpp" diff --git a/shared/liboxide/signalhandler.h b/shared/liboxide/signalhandler.h index ac45f3d6a..a77ce0c2f 100644 --- a/shared/liboxide/signalhandler.h +++ b/shared/liboxide/signalhandler.h @@ -27,6 +27,7 @@ namespace Oxide { * \brief Setup the unix signal handlers to listen to SIGUSR1 and SIGUSR2 * \retval 1 Failed to setup SIGUSR1 * \retval 2 Failed to setup SIGUSR2 + * \retval 3 Failed to setup SIGUSR2 * \retval 0 Successfully setup both signal handlers * * This method will automatically create and register the singleton with a parent of qApp. @@ -48,10 +49,12 @@ namespace Oxide { ~SignalHandler(); static void usr1SignalHandler(int unused); static void usr2SignalHandler(int unused); + static void contSignalHandler(int unused); public slots: void handleSigUsr1(); void handleSigUsr2(); + void handleSigCont(); signals: /*! @@ -62,10 +65,15 @@ namespace Oxide { * \brief The process has recieved a SIGUSR2 */ void sigUsr2(); + /* + * \brief The process has recieved a SIGCONT + */ + void sigCont(); private: QSocketNotifier* snUsr1; QSocketNotifier* snUsr2; + QSocketNotifier* snCont; }; } /*! @} */