Index: sources/wifi/WifiInterface.cpp =================================================================== diff -u -r3403122944ec8f31dfd33b387e21204783579f60 -r60db0ce19666f04ea58992a7670497d83f9bf7c4 --- sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 3403122944ec8f31dfd33b387e21204783579f60) +++ sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 60db0ce19666f04ea58992a7670497d83f9bf7c4) @@ -23,7 +23,7 @@ _processRequestAutoAssignedIP.setParent(this); } -void WifiInterface::onInitConnections() +void WifiInterface::initConnections() { connect(this, SIGNAL(didError(const QString)), this, SLOT(onLogFailure(const QString))); @@ -124,7 +124,7 @@ if (_init) return false; _init = true; - onInitConnections(); + initConnections(); LOG_EVENT("UI," + tr("%1 Initialized").arg(metaObject()->className())); return true; } @@ -136,24 +136,10 @@ */ void WifiInterface::onQuit() { - onQuitThread(); // verified + quitThread(); // verified } - /*! - * \brief WifiInterface::quitThread - * \details Moves this object to main thread to be handled by QApplicaiton - * It will also be destroyed there. - */ -void WifiInterface::onQuitThread() -{ - if (!_thread) - return; - - moveToThread(qApp->thread()); -} - -/*! * \brief WifiInterface::timerEvent * Built in QObject timer * \param event (QTimerEvent*) - the event timer @@ -169,17 +155,26 @@ */ void WifiInterface::doScan() { - qDebug() << __FUNCTION__ << QThread::currentThread()->objectName(); + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); + if (_scanRunning) { LOG_DEBUG("Wifi network scan is already running."); return; } LOG_DEBUG("Scanning for Wifi Access Points..."); + if (_processScan.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processScan.objectName())); + return; + } _processScan.setWorkingDirectory(Wifi_Scripts_Dir); _scanRunning = true; emit didScanStatusChanged(_scanRunning); _processScan.start(Wifi_Scan_For_Networks); + LOG_DEBUG(QString("WifiInterface::%1 Finished").arg(__FUNCTION__)); } /*! @@ -190,6 +185,7 @@ */ void WifiInterface::onProcessFinishedScan(int vExitCode, QProcess::ExitStatus vExitStatus) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); Q_UNUSED(vExitCode) Q_UNUSED(vExitStatus) QString out = _processScan.readAllStandardOutput(); @@ -198,17 +194,41 @@ LOG_DEBUG(QString("stderr: %1").arg(err)); _scanRunning = false; emit didScanStatusChanged(_scanRunning); - onParseWifiScan(out); + parseWifiScan(out); + LOG_DEBUG(QString("WifiInterface: %1 Finished").arg(__FUNCTION__)); } /*! - * \brief Network::onParseWifiScan + * \brief getTextBetweenDelimiters + * Gets the text between two delimiters + * \param vText - (QString) the text to search + * \param vLeftDelim - (QString) the left delimiter + * \param vRightDelim - (QString) the right delimiter + * \return (QString) the text between the delimiters if found, "" otherwise + */ +QString getTextBetweenDelimiters(const QString &vText, const QString &vLeftDelim, const QString &vRightDelim) +{ + QString result = ""; + QString rightHalf = ""; + QStringList tokenList = vText.split(vLeftDelim); + if (tokenList.length() > 1) + rightHalf = tokenList[1]; + + tokenList = rightHalf.split(vRightDelim); + if (tokenList.length() > 1) + result = tokenList[0]; + return result; +} + +/*! + * \brief Network::parseWifiScan * Extract desired information from the wifi scan output. Sorts by signal stength * * \param vOutput - (QString) output collected from QProcess execution */ -void WifiInterface::onParseWifiScan(const QString &vOutput) +void WifiInterface::parseWifiScan(const QString &vOutput) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); QList networks; QStringList temp = vOutput.split("Cell"); const QString signalLevelSearchTerm = "Signal level="; @@ -221,15 +241,13 @@ { if (line.contains(ssidSearchTerm) && line.contains(macAddressSearchTerm) && line.contains(signalLevelSearchTerm)) { - QString ssid = line.split(ssidSearchTerm)[1].split("\n")[0].replace("\"", "").trimmed(); - if (ssid == "") - continue; - QString macAddress = line.split(macAddressSearchTerm)[1].split("\n")[0].trimmed(); - int signalLevel = line.split(signalLevelSearchTerm)[1].split("dBm")[0].trimmed().toInt(); + QString ssid = getTextBetweenDelimiters(line, ssidSearchTerm, "\n").replace("\"", "").trimmed(); + QString macAddress = getTextBetweenDelimiters(line, macAddressSearchTerm, "\n").trimmed(); + int signalLevel = getTextBetweenDelimiters(line, signalLevelSearchTerm, "dBm").trimmed().toInt(); - bool isCCMP = line.split(groupCipherSearchTerm)[1].split("\n")[0].contains("CCMP"); - bool isEnterprise = line.split(authSuitesSearchTerm)[1].split("\n")[0].contains("802.1x"); - bool isPersonal = line.split(authSuitesSearchTerm)[1].split("\n")[0].contains("PSK"); + bool isCCMP = getTextBetweenDelimiters(line, groupCipherSearchTerm, "\n").contains("CCMP"); + bool isEnterprise = getTextBetweenDelimiters(line, authSuitesSearchTerm, "\n").contains("802.1x"); + bool isPersonal = getTextBetweenDelimiters(line, authSuitesSearchTerm, "\n").contains("PSK"); Network::SECURITY_LEVEL securityLevel = Network::SECURITY_LEVEL::UNSUPPORTED; @@ -243,14 +261,15 @@ emit didAddNetwork(network); } } + LOG_DEBUG(QString("WifiInterface::%1 Finished").arg(__FUNCTION__)); } /*! * \brief WifiInterface::onLogFailure * Ensures any failures reported are logged * \param vMessage (QString) the message detail of the failure */ -void WifiInterface::onLogFailure(const QString &vMessage) +void WifiInterface::onError(const QString &vMessage) { LOG_DEBUG(vMessage); } @@ -263,8 +282,16 @@ */ void WifiInterface::doJoinNetwork(const Network &vNetwork, const QString &vPassword) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); _network = vNetwork; LOG_DEBUG(QString("Joining Network %1").arg(vNetwork.ssid())); + if (_processGenerateWPASupplicant.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processGenerateWPASupplicant.objectName())); + return; + } _processGenerateWPASupplicant.start(Wifi_Generate_WPA_Supplicant, QStringList() << vNetwork.ssid() << vPassword @@ -286,6 +313,13 @@ return; } + if (_processStartWPASupplicant.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processStartWPASupplicant.objectName())); + return; + } _processStartWPASupplicant.start(Wifi_Start_WPA_Supplicant, QStringList() << _iface << _wpaSupplicantConfPath); @@ -305,6 +339,13 @@ emit didError("Could not configure network."); return; } + if (_processRequestAutoAssignedIP.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processRequestAutoAssignedIP.objectName())); + return; + } _processRequestAutoAssignedIP.start(Wifi_Get_Auto_Assigned_IP, QStringList() << _iface); } @@ -332,7 +373,15 @@ */ void WifiInterface::doRequestIPSettings() { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); QString result = ""; + if (_processReadIPSettings.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processReadIPSettings.objectName())); + return; + } _processReadIPSettings.start(Wifi_Read_IP_Settings, QStringList() << _iface); } @@ -351,6 +400,13 @@ _network.mIPSettings.mIPAddress = parseIP(output); _network.mIPSettings.mBroadcast = parseBroadcast(output); _network.mIPSettings.mSubnetMask = parseSubnetMask(output); + if (_processReadGateway.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processReadGateway.objectName())); + return; + } _processReadGateway.start(Wifi_Read_Gateway); } @@ -366,6 +422,13 @@ Q_UNUSED(vExitCode); Q_UNUSED(vExitStatus); _network.mIPSettings.mGateway = parseGateway(_processReadGateway.readAllStandardOutput()); + if (_processReadDNS.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processReadDNS.objectName())); + return; + } _processReadDNS.start(Wifi_Read_DNS); } @@ -391,6 +454,7 @@ */ void WifiInterface::doDisconnectNetwork(const Network &vNetwork) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); LOG_DEBUG(QString("Disconnecting from Network %1").arg(vNetwork.ssid())); QProcess process; process.start(Wifi_Disconnect_Network,