summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-08-19 14:53:00 +0200
committerNiklas2011-08-19 14:53:00 +0200
commit74bfbbab2b0012bbfadaf742e92c78bb7bff9e0c (patch)
tree09e823757b75b24fafd19bb9bd41706690a91664
parentadded internet test. each configured interface will be tested if it is possib... (diff)
downloadfbgui-74bfbbab2b0012bbfadaf742e92c78bb7bff9e0c.tar.gz
fbgui-74bfbbab2b0012bbfadaf742e92c78bb7bff9e0c.tar.xz
fbgui-74bfbbab2b0012bbfadaf742e92c78bb7bff9e0c.zip
changed code order. added new signals
-rw-r--r--workspace/LogReceiver/logreceiver.cpp300
-rw-r--r--workspace/LogReceiver/logreceiver.h7
-rw-r--r--workspace/LogReceiver/ndgui.cpp5
-rw-r--r--workspace/LogReceiver/ndgui.h1
4 files changed, 163 insertions, 150 deletions
diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp
index c5331dc..79879e7 100644
--- a/workspace/LogReceiver/logreceiver.cpp
+++ b/workspace/LogReceiver/logreceiver.cpp
@@ -47,7 +47,7 @@ void LogReceiver::initAndRun(QString serverPath,
connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
QList<QNetworkInterface> list = getListOfNetworkInterfaces();
- //checkCarrierState(list);
+ //list = checkCarrierState(list);
pathToDhcpcdExe = pathToExe;
if(args != NULL && ! args->isEmpty()) {
@@ -60,105 +60,6 @@ void LogReceiver::initAndRun(QString serverPath,
runDHCPCD(list);
}
-void LogReceiver::handleNewConnection() {
- qDebug() << "New Connection arrived";
-
- QLocalSocket * client = server ->nextPendingConnection();
- clients.insert(client, client);
- connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
- connect(client, SIGNAL(readyRead()), this, SLOT(handleNewInput()));
-}
-
-void LogReceiver::handleNewInput() {
-
- QObject* sender = const_cast<QObject*> (QObject::sender());
- QLocalSocket* socket = static_cast<QLocalSocket*> (sender);
-
- QLocalSocket * client = clients.value(socket);
-
- QString data(client->readAll());
-
- data = data.trimmed();
-
- QStringList lines = data.split("\n");
-
- for (int i=0; i < lines.length(); i++) {
- handleNewInputLine(lines.at(i));
- }
-}
-
-void LogReceiver::handleNewInputLine(QString data) {
-
- QString logMsg(data);
- QString interface = logMsg.section(";",0,0);
- 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;
- switch (st) {
- case LOG_INFO:
- switch (sst) {
- case DHCP_DISCOVER:
- emit changeProgressBarValue(pBar, 10);
- break;
- case DHCP_OFFER:
- emit changeProgressBarValue(pBar, 20);
- break;
- case DHCP_REQUEST:
- emit changeProgressBarValue(pBar, 30);
- break;
- case DHCP_ACK:
- emit changeProgressBarValue(pBar, 40);
- break;
- case DHCP_NAK:
- emit changeProgressBarValue(pBar, 40);
- break;
- case DHCPCD_ARP_TEST:
- emit changeProgressBarValue(pBar, 50);
- break;
- case DHCP_DECLINE:
- emit changeProgressBarValue(pBar, 60);
- break;
- case DHCP_RELEASE:
-
- break;
- case DHCP_INFORM:
- break;
- case DHCPCD_CONFIGURE:
- emit changeProgressBarValue(pBar, 70);
- break;
- case DHCPCD_WRITE:
- emit changeProgressBarValue(pBar, 80);
- break;
- case DHCPCD_EXIT:
- emit changeProgressBarValue(pBar, 100);
- break;
- case DHCPCD_LOG:
-
- default:
- break;
- }
- break;
- case LOG_ERR:
- qDebug() << "received stat_error";
- break;
- default:
- qDebug() << logMsg;
- }
-}
-
QList<QNetworkInterface> LogReceiver::getListOfNetworkInterfaces() {
QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
QList<QNetworkInterface> result;
@@ -177,68 +78,39 @@ QList<QNetworkInterface> LogReceiver::getListOfNetworkInterfaces() {
// qDebug() << nI.humanReadableName();
result.append(nI);
- interfacesMap.insert(i, nI);
- indexToIfaceNameMap.insert(nI.humanReadableName(), i);
+ //interfacesMap.insert(i, nI);
+ //indexToIfaceNameMap.insert(nI.humanReadableName(), i);
emit addNewInterface(nI.humanReadableName(), i);
i++;
}
return result;
}
-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();
- }
-}
-
-void LogReceiver::runDHCPCD(QString interface) {
- dhcpcdArguments.append(interface);
- QProcess * p = new QProcess(this);
-
- qDebug() << dhcpcdArguments;
-
- clientProcessToIfNameMap.insert(p, interface);
- 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();
-}
-
-void LogReceiver::checkCarrierState(QList<QNetworkInterface> &interfaces) {
+QList<QNetworkInterface> LogReceiver::checkCarrierState(QList<QNetworkInterface> &interfaces) {
+ QList<QNetworkInterface> result;
foreach(QNetworkInterface nI, interfaces) {
if(checkCarrierState(nI.humanReadableName())) {
// everything is fine, cable is plugged,
// go on with the next interface
- continue;
+ //continue;
+ result.append(nI);
}
- else {
+ //else {
// cable is unplugged,
// remove interface out of the list,
// remove interface out ot the index maps
- int i = 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);
- }
- }
+ // 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;
}
bool LogReceiver::checkCarrierState(QString interface) {
@@ -281,6 +153,41 @@ 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(QString interface) {
+ dhcpcdArguments.append(interface);
+ QProcess * p = new QProcess(this);
+
+ qDebug() << dhcpcdArguments;
+
+ clientProcessToIfNameMap.insert(p, interface);
+ 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();
+}
+
void LogReceiver::checkInternetConnection(QString ifName) {
QString command("ping");
QStringList argList;
@@ -300,6 +207,7 @@ void LogReceiver::checkInternetConnection(QString ifName) {
//remove interface from list and inform user via debug console
} else if (exitCode == 0) {
qDebug() << "internet: check passed! for interface" << ifName;
+ emit connectionEstablished(ifName);
}
}
@@ -310,6 +218,104 @@ void LogReceiver::checkInternetConnection(QList<QNetworkInterface> &interfaces)
}
}
+void LogReceiver::handleNewConnection() {
+ qDebug() << "New Connection arrived";
+
+ QLocalSocket * client = server ->nextPendingConnection();
+ clients.insert(client, client);
+ connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
+ connect(client, SIGNAL(readyRead()), this, SLOT(handleNewInput()));
+}
+
+void LogReceiver::handleNewInput() {
+
+ QObject* sender = const_cast<QObject*> (QObject::sender());
+ QLocalSocket* socket = static_cast<QLocalSocket*> (sender);
+
+ QLocalSocket * client = clients.value(socket);
+
+ QString data(client->readAll());
+
+ data = data.trimmed();
+
+ QStringList lines = data.split("\n");
+
+ for (int i=0; i < lines.length(); i++) {
+ handleNewInputLine(lines.at(i));
+ }
+}
+
+void LogReceiver::handleNewInputLine(QString data) {
+
+ QString logMsg(data);
+ QString interface = logMsg.section(";",0,0);
+ 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;
+ switch (st) {
+ case LOG_INFO:
+ switch (sst) {
+ case DHCP_DISCOVER:
+ //emit changeProgressBarValue(pBar, 10);
+ break;
+ case DHCP_OFFER:
+ //emit changeProgressBarValue(pBar, 20);
+ break;
+ case DHCP_REQUEST:
+ //emit changeProgressBarValue(pBar, 30);
+ break;
+ case DHCP_ACK:
+ //emit changeProgressBarValue(pBar, 40);
+ break;
+ case DHCP_NAK:
+ //emit changeProgressBarValue(pBar, 40);
+ break;
+ case DHCPCD_ARP_TEST:
+ //emit changeProgressBarValue(pBar, 50);
+ break;
+ case DHCP_DECLINE:
+ //emit changeProgressBarValue(pBar, 60);
+ break;
+ case DHCP_RELEASE:
+
+ break;
+ case DHCP_INFORM:
+ break;
+ case DHCPCD_CONFIGURE:
+ //emit changeProgressBarValue(pBar, 70);
+ break;
+ case DHCPCD_WRITE:
+ //emit changeProgressBarValue(pBar, 80);
+ break;
+ case DHCPCD_EXIT:
+ //emit changeProgressBarValue(pBar, 100);
+ break;
+ case DHCPCD_LOG:
+
+ default:
+ break;
+ }
+ break;
+ case LOG_ERR:
+ qDebug() << "received stat_error";
+ break;
+ default:
+ qDebug() << logMsg;
+ }
+}
void LogReceiver::handleProcessFinished(int exitCode,
QProcess::ExitStatus exitStatus) {
diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h
index 06a1f3e..baf9ab9 100644
--- a/workspace/LogReceiver/logreceiver.h
+++ b/workspace/LogReceiver/logreceiver.h
@@ -36,12 +36,13 @@ private slots:
signals:
void addNewInterface(QString ifName, int index);
void changeProgressBarValue(int index, int newValue);
+ void connectionEstablished(QString ifName);
private:
QLocalServer *server;
quint16 blockSize;
- QMap<int, QNetworkInterface > interfacesMap;
- QMap<QString, int> indexToIfaceNameMap;
+ //QMap<int, QNetworkInterface > interfacesMap;
+ //QMap<QString, int> indexToIfaceNameMap;
QMap<QLocalSocket *, QLocalSocket *> clients;
QMap<QProcess*, QString> clientProcessToIfNameMap;
QString pathToDhcpcdExe;
@@ -52,7 +53,7 @@ private:
void runDHCPCD(QList<QNetworkInterface> &interfaces);
void runDHCPCD(QString interface);
- void checkCarrierState(QList<QNetworkInterface> &interfaces);
+ QList<QNetworkInterface> checkCarrierState(QList<QNetworkInterface> &interfaces);
bool checkCarrierState(QString interface);
void checkInternetConnection(QString ifName);
void checkInternetConnection(QList<QNetworkInterface> &interfaces);
diff --git a/workspace/LogReceiver/ndgui.cpp b/workspace/LogReceiver/ndgui.cpp
index 629a8fb..0e743ed 100644
--- a/workspace/LogReceiver/ndgui.cpp
+++ b/workspace/LogReceiver/ndgui.cpp
@@ -7,6 +7,7 @@ ndgui::ndgui(QWidget *parent)
connect(&logReceiver, SIGNAL(addNewInterface(QString, int)), this, SLOT(addNewInterface(QString, int)));
connect(&logReceiver, SIGNAL(changeProgressBarValue(int , int )), this, SLOT(handleProgress(int, int)));
+ connect(&logReceiver, SIGNAL(connectionEstablished(QString)), this, SLOT(handleConnectionEstablished(QString)));
buildGui();
@@ -93,3 +94,7 @@ void ndgui::handleProgress(int iFaceIndex, int newValue) {
qDebug() << "Error: new value is smaller than the old value!";
}
}
+
+void ndgui::handleConnectionEstablished(QString ifName) {
+
+}
diff --git a/workspace/LogReceiver/ndgui.h b/workspace/LogReceiver/ndgui.h
index 990a6b9..d3cf29f 100644
--- a/workspace/LogReceiver/ndgui.h
+++ b/workspace/LogReceiver/ndgui.h
@@ -19,6 +19,7 @@ public:
public slots:
void handleProgress(int iFaceIndex, int newValue);
void addNewInterface(QString ifName, int index);
+ void handleConnectionEstablished(QString ifName);
private:
Ui::ndguiClass ui;