#pragma once // Qt #include #include #include // Project #include "main.h" #include "Network.h" // define #define _WifiInterface WifiInterface::I() /*! * \brief The WifiInterface class * Communicates with Access Points * \details * - Scans for Access Points * - Authenticates with Access Points * - Disconnects from Access Points */ class WifiInterface : public QObject { Q_OBJECT QThread *_thread = nullptr; bool _init = false; bool _scanRunning = false; int _defaultTimeout = 5000; int _dhcpTimeout = 10000; int _scanTimeout = 30000; int _processCounter = 0; QProcess _processScan; const QString _iface = "wlan0"; const QString _wpaSupplicantConfPath = "/etc/wpa_supplicant.conf"; // Singleton SINGLETON(WifiInterface) private: // QFutureWatcher _scanWatcher; bool generateWPASupplicant(const Network &vNetwork, const QString &vPassword); bool startWPASupplicant(); bool requestAutoAssignedIP(int vTries = 4); Network::IPSettings getIPSettings(); QString readIPSettings(); QString readGateway(); QString readDNS(); QString parseIP(const QString &vOutput); QString parseBroadcast(const QString &vOutput); QString parseSubnetMask(const QString &vOutput); QString parseGateway(const QString &vOutput); QString parseDNS(const QString &vOutput); void onInitConnections(); void onQuitThread(); void timerEvent(QTimerEvent* event); void initThread(QThread &vThread); void quitThread(); public slots: bool init(QThread &vThread); bool init(); void doScan(); void doJoinNetwork(const Network &vNetwork, const QString &vPassword); void doDisconnectNetwork(const Network &vNetwork); void doRequestIPSettings(); private slots: void quit(); signals: void didAddNetwork(const Network); void didDisconnectNetwork(const Network); void didGetIPSettings(const Network::IPSettings); void didRequestScan(); void didScan(); // emitted from separate threads void didScanStatusChanged(const bool); void didConnectToNetwork(const Network); void didError(const QString); private slots: void onQuit(); void onParseWifiScan(const QString &vOutput); void onLogFailure(const QString &vMessage); void onScanFinished(int vExitCode, QProcess::ExitStatus vExitStatus); void onScan(); };