diff options
author | Niklas | 2011-08-18 14:50:37 +0200 |
---|---|---|
committer | Niklas | 2011-08-18 14:50:37 +0200 |
commit | 66bd4a4f1cc9424b3adbd14ca38a9bb6509431df (patch) | |
tree | 6fb36b5c0fca3da61586749b4e5e47bc860f3b5c | |
parent | new function for checkInternetConnection, check with sessions for each config... (diff) | |
download | fbgui-66bd4a4f1cc9424b3adbd14ca38a9bb6509431df.tar.gz fbgui-66bd4a4f1cc9424b3adbd14ca38a9bb6509431df.tar.xz fbgui-66bd4a4f1cc9424b3adbd14ca38a9bb6509431df.zip |
added internet test. each configured interface will be tested if it is possible to ping the server.
-rwxr-xr-x | workspace/LogReceiver/LogReceiver | bin | 74661 -> 82545 bytes | |||
-rw-r--r-- | workspace/LogReceiver/logreceiver.cpp | 74 | ||||
-rw-r--r-- | workspace/LogReceiver/logreceiver.h | 12 |
3 files changed, 57 insertions, 29 deletions
diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver Binary files differindex f60254e..e7aff30 100755 --- a/workspace/LogReceiver/LogReceiver +++ b/workspace/LogReceiver/LogReceiver diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 2f41e08..c5331dc 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -57,7 +57,7 @@ void LogReceiver::initAndRun(QString serverPath, //dhcpcdArguments.append("-d"); QString ifName("eth0"); - runDHCPCD(ifName); + runDHCPCD(list); } void LogReceiver::handleNewConnection() { @@ -192,7 +192,8 @@ void LogReceiver::runDHCPCD(QList<QNetworkInterface> &interfaces) { qDebug() << dhcpcdArguments; - clientProcesses.insert(p->pid(),p); + clientProcessToIfNameMap.insert(p, ni.humanReadableName()); + qDebug() << clientProcessToIfNameMap; p->start(pathToDhcpcdExe,dhcpcdArguments); connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), @@ -207,7 +208,8 @@ void LogReceiver::runDHCPCD(QString interface) { qDebug() << dhcpcdArguments; - clientProcesses.insert(p->pid(),p); + clientProcessToIfNameMap.insert(p, interface); + qDebug() << clientProcessToIfNameMap; p->start(pathToDhcpcdExe,dhcpcdArguments); connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), @@ -279,24 +281,33 @@ bool LogReceiver::checkCarrierState(QString interface) { return true; } +void LogReceiver::checkInternetConnection(QString ifName) { + QString command("ping"); + QStringList argList; + QString timeout("1"); + QString total("2"); + int exitCode = -1; + QString destination("www.google.de"); + argList << "-I" << "ifName" << "-W" << timeout << "-c" << total + << destination; + argList.replace(1, ifName); + QProcess * p = new QProcess(this); + p->start(command, argList); + p->waitForFinished(); + exitCode = p->exitCode(); + if (exitCode > 0) { + qDebug() << "no internet connection with interface" << ifName; + //remove interface from list and inform user via debug console + } else if (exitCode == 0) { + qDebug() << "internet: check passed! for interface" << ifName; + } +} -void LogReceiver::checkInternetConnection(/*QList<QNetworkInterface> &interfaces*/) { - qDebug() << "check internet connection"; - QList<QNetworkConfiguration> allConfigs = manager.allConfigurations(QNetworkConfiguration::Discovered); - foreach(QNetworkConfiguration nC, allConfigs) { - qDebug() << nC.name(); - if(nC.isValid()) { - qDebug() << "config is valid"; - qDebug() << "try to open a new session"; - QNetworkSession session = new QNetworkSession(nC, this); - conntect(session,SIGNAL(error), this, SLOT(handleSessionError())); - conntect(session,SIGNAL(opened), this, SLOT(handleSessionOpened())); - session.open(); - session.waitForOpened(); - - } - } - qDebug() << "check internet connection done"; +void LogReceiver::checkInternetConnection(QList<QNetworkInterface> &interfaces) { + foreach(QNetworkInterface ni, interfaces) + { + checkInternetConnection(ni.humanReadableName()); + } } @@ -304,18 +315,29 @@ void LogReceiver::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { QProcess* p = qobject_cast<QProcess * >(QObject::sender()); - QProcess * client = clientProcesses.value(p->pid(),0); - if(client <= 0) { - qDebug() << "--- \t [LogReceiver::handleProcessFinished] haven't found process!"; + QString ifName = clientProcessToIfNameMap.value(p,"ifName"); + + if(ifName.compare("ifName") == 0) { + qDebug() << "--- \t [LogReceiver::handleProcessFinished] haven't found process!"; } else { - qDebug() << "process finished: " << client->pid() << exitCode << exitStatus; - checkInternetConnection(); + qDebug() << "process for interface"<< ifName << "finished" << exitCode << exitStatus; + if(exitCode > 0) { + qDebug() << "process exited unexpected"; + } + else { + qDebug() << "process normal exit"; + qDebug() << "check internet connction"; + checkInternetConnection(ifName); + } + } } void LogReceiver::handleProcessStarted() { - qDebug() << "process started: "; + QProcess* p = qobject_cast<QProcess * >(QObject::sender()); + QString ifName = clientProcessToIfNameMap.value(p,"ifName"); + qDebug() << "process started for interface:" << ifName; } diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h index fb65d58..06a1f3e 100644 --- a/workspace/LogReceiver/logreceiver.h +++ b/workspace/LogReceiver/logreceiver.h @@ -4,6 +4,10 @@ #include <qprocess.h> #include <qnetworkinterface.h> #include <qnetworkconfigmanager.h> +#include <qnetworkaccessmanager.h> +#include <qnetworksession.h> +#include <qnetworkreply.h> +#include <qsslerror.h> class QLocalServer; class QLocalSocket; @@ -39,17 +43,19 @@ private: QMap<int, QNetworkInterface > interfacesMap; QMap<QString, int> indexToIfaceNameMap; QMap<QLocalSocket *, QLocalSocket *> clients; - QMap<Q_PID, QProcess * > clientProcesses; + QMap<QProcess*, QString> clientProcessToIfNameMap; QString pathToDhcpcdExe; QStringList dhcpcdArguments; - QNetworkConfigurationManager manager; + QNetworkConfigurationManager configurationManager; + QNetworkAccessManager *accessManager; void runDHCPCD(QList<QNetworkInterface> &interfaces); void runDHCPCD(QString interface); void checkCarrierState(QList<QNetworkInterface> &interfaces); bool checkCarrierState(QString interface); - void checkInternetConnection(/*QList<QNetworkInterface> &interfaces*/); + void checkInternetConnection(QString ifName); + void checkInternetConnection(QList<QNetworkInterface> &interfaces); QList<QNetworkInterface> getListOfNetworkInterfaces(); bool checkBlackList(QString i); |