summaryrefslogtreecommitdiffstats
path: root/workspace/LogReceiver/logreceiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'workspace/LogReceiver/logreceiver.cpp')
-rw-r--r--workspace/LogReceiver/logreceiver.cpp146
1 files changed, 67 insertions, 79 deletions
diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp
index 79879e7..70d49e6 100644
--- a/workspace/LogReceiver/logreceiver.cpp
+++ b/workspace/LogReceiver/logreceiver.cpp
@@ -25,9 +25,8 @@ LogReceiver::~LogReceiver() {
}
-void LogReceiver::initAndRun(QString serverPath,
- QString pathToExe ,
- QStringList* args ) {
+void LogReceiver::initAndRun(QString serverPath, QString pathToExe,
+ QStringList* args) {
if (serverPath != DEFAULT_QTSOCKETADDRESS) {
dhcpcdArguments.append("-q");
@@ -40,75 +39,77 @@ void LogReceiver::initAndRun(QString serverPath,
close();
*/
// emit signal to the gui that a critial error occoured
- qDebug() << "--- \t [LogReceiver::initAndRun] Unable to start server:" << server->errorString();
+ qDebug() << "--- \t [LogReceiver::initAndRun] Unable to start server:"
+ << server->errorString();
return;
}
connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
- QList<QNetworkInterface> list = getListOfNetworkInterfaces();
- //list = checkCarrierState(list);
pathToDhcpcdExe = pathToExe;
- if(args != NULL && ! args->isEmpty()) {
+ if (args != NULL && !args->isEmpty()) {
qDebug() << "--- \t [LogReceiver::initAndRun] added additional args";
dhcpcdArguments.append(*args);
}
- //dhcpcdArguments.append("-d");
- QString ifName("eth0");
- runDHCPCD(list);
+ numberOfProcesses = 0;
+
+ // start the main work:
+
+ QList<QString> list = getListOfNetworkInterfaces();
+
+ if (list.size() > 0) {
+
+ //list = checkCarrierState(list);
+
+
+ //dhcpcdArguments.append("-d");
+ QString ifName("eth0");
+ numberOfProcesses = list.size();
+ runDHCPCD(list);
+ } else {
+ qDebug() << "list is empty. Haven't found usable interface.";
+ emit abortBoot("Haven't found usable interface");
+ return;
+ }
+
}
-QList<QNetworkInterface> LogReceiver::getListOfNetworkInterfaces() {
+QList<QString> LogReceiver::getListOfNetworkInterfaces() {
QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
- QList<QNetworkInterface> result;
- int i = 0;
- foreach(QNetworkInterface nI, nIList) {
- if (((!(nI.flags() & QNetworkInterface::CanBroadcast)||
- nI.flags() & QNetworkInterface::IsLoopBack) ||
- nI.flags() & QNetworkInterface::IsPointToPoint) ||
- checkBlackList(nI.humanReadableName()))
- {
- continue;
- }
- if (!checkCarrierState(nI.humanReadableName())) {
- continue;
- }
-
- // qDebug() << nI.humanReadableName();
- result.append(nI);
- //interfacesMap.insert(i, nI);
- //indexToIfaceNameMap.insert(nI.humanReadableName(), i);
- emit addNewInterface(nI.humanReadableName(), i);
- i++;
+ QList<QString> result;
+
+ if (nIList.size() > 0) {
+ foreach(QNetworkInterface nI, nIList)
+ {
+ if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
+ || nI.flags() & QNetworkInterface::IsLoopBack)
+ || nI.flags() & QNetworkInterface::IsPointToPoint)
+ || checkBlackList(nI.humanReadableName())) {
+ continue;
+ }
+ if (!checkCarrierState(nI.humanReadableName())) {
+ continue;
+ }
+ result.append(nI.humanReadableName());
+ emit addNewInterface(nI.humanReadableName());
+ }
+ } else {
+ qDebug() << "no interfaces found!";
}
return result;
}
-QList<QNetworkInterface> LogReceiver::checkCarrierState(QList<QNetworkInterface> &interfaces) {
- QList<QNetworkInterface> result;
- foreach(QNetworkInterface nI, interfaces) {
- if(checkCarrierState(nI.humanReadableName())) {
+QList<QString> LogReceiver::checkCarrierState(QList<QString> &interfaces) {
+ QList<QString> result;
+ foreach(QString nI, interfaces) {
+ if(checkCarrierState(nI)) {
// everything is fine, cable is plugged,
// go on with the next interface
//continue;
result.append(nI);
}
- //else {
- // cable is unplugged,
- // remove interface out of the list,
- // remove interface out ot the index maps
- // int i = 0; //indexToIfaceNameMap.value(nI.humanReadableName(), -1);
- //if(i < 0) {
- // qDebug() << "--- \t [LogReceiver::checkCarrierState] no interface with name:" << nI.humanReadableName();
- //}
- //else {
- //indexToIfaceNameMap.remove(nI.humanReadableName());
- //interfacesMap.remove(i);
- //interfaces.removeAt(i);
- //}
- //}
}
return result;
}
@@ -153,27 +154,14 @@ bool LogReceiver::checkCarrierState(QString interface) {
return true;
}
-void LogReceiver::runDHCPCD(QList<QNetworkInterface> &interfaces) {
- foreach(QNetworkInterface ni, interfaces) {
- /*
- dhcpcdArguments.append(ni.humanReadableName());
- QProcess * p = new QProcess(this);
-
- qDebug() << dhcpcdArguments;
-
- 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)),
- this, SLOT(handleProcessFinished(int, QProcess::ExitStatus)));
- dhcpcdArguments.removeLast();
- */
- runDHCPCD(ni.humanReadableName());
+void LogReceiver::runDHCPCD(QList<QString> &interfaces) {
+ foreach(QString nI, interfaces) {
+ runDHCPCD(nI);
}
}
void LogReceiver::runDHCPCD(QString interface) {
+ emit updateStatusLabel(interface,"start DHCP");
dhcpcdArguments.append(interface);
QProcess * p = new QProcess(this);
@@ -205,16 +193,18 @@ void LogReceiver::checkInternetConnection(QString ifName) {
if (exitCode > 0) {
qDebug() << "no internet connection with interface" << ifName;
//remove interface from list and inform user via debug console
+ emit updateStatusLabel(ifName, "connection not possible");
} else if (exitCode == 0) {
qDebug() << "internet: check passed! for interface" << ifName;
+ emit updateStatusLabel(ifName, "connection possible");
emit connectionEstablished(ifName);
}
}
-void LogReceiver::checkInternetConnection(QList<QNetworkInterface> &interfaces) {
- foreach(QNetworkInterface ni, interfaces)
+void LogReceiver::checkInternetConnection(QList<QString> &interfaces) {
+ foreach(QString nI, interfaces)
{
- checkInternetConnection(ni.humanReadableName());
+ checkInternetConnection(nI);
}
}
@@ -252,16 +242,6 @@ void LogReceiver::handleNewInputLine(QString data) {
QString s_state = logMsg.section(";", 1, 1);
QString s_subState = logMsg.section(";", 2, 2);
QString msg = logMsg.section(";", 3, 3);
-
- //int pBar = indexToIfaceNameMap.value(interface.trimmed(), -1);
-/*
- if(pBar < 0) {
- qDebug() << "--- \t no pBar with index: " << pBar;
- }
- else {
- qDebug() << "--- \t get pBar for Interface: " << interface.trimmed() << "index: " << pBar;
- }
-*/
int st = s_state.trimmed().toInt();
int sst = s_subState.trimmed().toInt();
qDebug() << logMsg;
@@ -321,6 +301,8 @@ void LogReceiver::handleProcessFinished(int exitCode,
QProcess::ExitStatus exitStatus) {
QProcess* p = qobject_cast<QProcess * >(QObject::sender());
+
+
QString ifName = clientProcessToIfNameMap.value(p,"ifName");
if(ifName.compare("ifName") == 0) {
@@ -330,14 +312,20 @@ void LogReceiver::handleProcessFinished(int exitCode,
qDebug() << "process for interface"<< ifName << "finished" << exitCode << exitStatus;
if(exitCode > 0) {
qDebug() << "process exited unexpected";
+ emit updateStatusLabel(ifName, "process exited unexpected");
}
else {
qDebug() << "process normal exit";
qDebug() << "check internet connction";
+ emit updateStatusLabel(ifName, "check connectivity");
checkInternetConnection(ifName);
}
}
+ numberOfProcesses = numberOfProcesses -1;
+ if (numberOfProcesses <= 0) {
+ emit allProcessesFinished();
+ }
}
void LogReceiver::handleProcessStarted() {