From 951db8ebf3f95ec6252f170bef7d3294b7bd6bc8 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 21 Oct 2011 13:11:40 +0200 Subject: now the two versions of the NetworkDiscovery code should be the same (except for the qDebug...) --- src/networkdiscovery.cpp | 103 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 22 deletions(-) (limited to 'src/networkdiscovery.cpp') diff --git a/src/networkdiscovery.cpp b/src/networkdiscovery.cpp index 94d1f63..938c504 100644 --- a/src/networkdiscovery.cpp +++ b/src/networkdiscovery.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "networkdiscovery.h" #include "../common/fbgui.h" @@ -97,24 +100,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp qxtLog->debug() << _tag << "added additional args"; _dhcpcdArguments.append(*args); } - - // start the main work: - if (_autoUp) { - qxtLog->debug() << _tag << " call getListOfNetworkInterfacesWithAutoUp ..."; - getListOfNetworkInterfacesWithAutoUp(); - qxtLog->debug() << _tag << " ifUpList size: " << _ifUpList.size(); - qxtLog->debug() << _tag << " ifDownList size: " << _ifDownList.size(); - - } else { - qxtLog->debug() << _tag << " call getListOfNetworkInterfaces ..."; - getListOfNetworkInterfaces(); - } - - qxtLog->debug() << _tag << " init timer ..."; - _timer = new QTimer(this); - qxtLog->debug() << _tag << " call checkForIsRunning ..."; - connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning())); - _timer->start(1000); + mainWork(); } @@ -276,9 +262,59 @@ QString NetworkDiscovery::readLogFile() { -/**/ +/* + *TODO: to be bug fixed + *TODO: do it with kill and not QProcess("killall cdhcpcd") + *TODO: still some bugs. if you press tryAgain it can happen that the app stops with the mainscreen. + *TODO: reproducible: start normal with user choice. plug out the cable. press continue. abort screen should appear. + *TODO: press tryAgain. + */ void NetworkDiscovery::tryAgain() { + // kill all cdhcpcd processes + qDebug() << " kill cdhcpcd processes"; + QProcess * p = new QProcess(this); + p->start("killall cdhcpcd"); + p->waitForFinished(); + qDebug() << _tag << "[tryAgain]" << p->errorString(); + /* + foreach(Q_PID pid , _pidsList) { + if (kill(pid,SIGKILL) <= -1) + qDebug() << _tag << " error: trying to kill process: " << pid << " error: " << strerror(errno); + } + */ + // reset everything + _clients.clear(); + _clientProcessToIfNameMap.clear(); + _ifNameToClient.clear(); + _numberOfProcesses = 0; + _blocked = false; + _ifUpCountdown = 10; + _ifUpList.clear(); + _ifDownList.clear(); + _pidsList.clear(); + _ifcMap.clear(); + + // start again + mainWork(); + //SIGK + //kill(); +} + + +/**/ +QVariantMap NetworkDiscovery::getInterfaceConfig(QString ifName) { + QList dns; + interfaceconfiguration * ifc = _ifcMap.value(ifName, NULL); + if (ifc != NULL) { +// +// dns.clear(); +// dns = ifc->getDnsservers().trimmed().split(" "); +// +// //ifc->getIpAddress(), ifc->getNetmask(), ifc->getBroadcast(), +// //ifc->getGateway(), 0, AF_INET, "/etc/", dns); +// + } } @@ -290,6 +326,22 @@ void NetworkDiscovery::tryAgain() { **/ +/**/ +void NetworkDiscovery::mainWork() +{ + if (_autoUp) { + getListOfNetworkInterfacesWithAutoUp(); + _timer = new QTimer(this); + connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning())); + _timer->start(1000); + + } else { + getListOfNetworkInterfaces(); + emit readyForRun(); + } +} + + /** * searches for usable interfaces and puts them into a list. @@ -364,7 +416,7 @@ void NetworkDiscovery::getListOfNetworkInterfaces() { continue; } if (!(nI.flags() & QNetworkInterface::IsRunning)) { - _ifDownList.append(nI.humanReadableName()) + _ifDownList.append(nI.humanReadableName()); } else { _ifUpList.append(nI.humanReadableName()); } @@ -516,6 +568,13 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { +/**/ +bool NetworkDiscovery::checkConnectivityViaTcp() { + return checkConnectivityViaTcp(_serverIp); +} + + + /** * try to open a tcp connection to the server * @@ -605,8 +664,8 @@ void NetworkDiscovery::handleNewInput() { QLocalSocket * client = _clients.value(socket); QString data(client->read(DHCP_MESSAGE_SIZE)); - client->write("ACK", ACK_SIZE); - client->waitForBytesWritten(); + //client->write("ACK", ACK_SIZE); + //client->waitForBytesWritten(); data = data.trimmed(); //qxtLog->debug() << _tag << data; QStringList lines = data.split("\n"); -- cgit v1.2.3-55-g7522