summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-08-22 16:00:24 +0200
committerNiklas2011-08-22 16:00:24 +0200
commit23bc13f690a08cb049adf5145f115f45cbb9950f (patch)
tree1ee48e74cf2f6c43503bc90341e4fd6c4ccfe2bb
parentchanged code order. added new signals (diff)
downloadfbgui-23bc13f690a08cb049adf5145f115f45cbb9950f.tar.gz
fbgui-23bc13f690a08cb049adf5145f115f45cbb9950f.tar.xz
fbgui-23bc13f690a08cb049adf5145f115f45cbb9950f.zip
added a additional status label and some signals
-rwxr-xr-xworkspace/LogReceiver/LogReceiverbin82545 -> 78251 bytes
-rw-r--r--workspace/LogReceiver/logreceiver.cpp146
-rw-r--r--workspace/LogReceiver/logreceiver.h16
-rw-r--r--workspace/LogReceiver/ndgui.cpp59
-rw-r--r--workspace/LogReceiver/ndgui.h18
-rw-r--r--workspace/customdhcpcd/src/logwriter.c2
6 files changed, 122 insertions, 119 deletions
diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver
index e7aff30..d0aab5a 100755
--- a/workspace/LogReceiver/LogReceiver
+++ b/workspace/LogReceiver/LogReceiver
Binary files differ
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() {
diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h
index baf9ab9..c4e165d 100644
--- a/workspace/LogReceiver/logreceiver.h
+++ b/workspace/LogReceiver/logreceiver.h
@@ -34,9 +34,12 @@ private slots:
void handleProcessStarted();
signals:
- void addNewInterface(QString ifName, int index);
- void changeProgressBarValue(int index, int newValue);
+ void addNewInterface(QString ifName);
+ void changeProgressBarValue(QString ifName, int newValue);
void connectionEstablished(QString ifName);
+ void abortBoot(QString msg);
+ void updateStatusLabel(QString ifName, QString status);
+ void allProcessesFinished();
private:
QLocalServer *server;
@@ -49,15 +52,16 @@ private:
QStringList dhcpcdArguments;
QNetworkConfigurationManager configurationManager;
QNetworkAccessManager *accessManager;
+ int numberOfProcesses;
- void runDHCPCD(QList<QNetworkInterface> &interfaces);
+ void runDHCPCD(QList<QString> &interfaces);
void runDHCPCD(QString interface);
- QList<QNetworkInterface> checkCarrierState(QList<QNetworkInterface> &interfaces);
+ QList<QString>checkCarrierState(QList<QString> &interfaces);
bool checkCarrierState(QString interface);
void checkInternetConnection(QString ifName);
- void checkInternetConnection(QList<QNetworkInterface> &interfaces);
- QList<QNetworkInterface> getListOfNetworkInterfaces();
+ void checkInternetConnection(QList<QString> &interfaces);
+ QList<QString> getListOfNetworkInterfaces();
bool checkBlackList(QString i);
};
diff --git a/workspace/LogReceiver/ndgui.cpp b/workspace/LogReceiver/ndgui.cpp
index 0e743ed..78aa280 100644
--- a/workspace/LogReceiver/ndgui.cpp
+++ b/workspace/LogReceiver/ndgui.cpp
@@ -5,13 +5,17 @@ ndgui::ndgui(QWidget *parent)
{
ui.setupUi(this);
- 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(addNewInterface(QString)), this, SLOT(addNewInterface(QString)));
+ connect(&logReceiver, SIGNAL(changeProgressBarValue(QString , int )), this, SLOT(handleProgress(QString, int)));
connect(&logReceiver, SIGNAL(connectionEstablished(QString)), this, SLOT(handleConnectionEstablished(QString)));
+ connect(&logReceiver, SIGNAL(abortBoot(QString)), this, SLOT(handleAbortBoot(QString)));
+ connect(&logReceiver, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(handleUpdateStatusLabel(QString, QString)));
+ connect(&logReceiver, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished()));
buildGui();
logReceiver.initAndRun("/var/tmp/qt_c_socket_custom");
+ numberOfInterfaces = 0;
setWindowTitle(tr("NetD"));
@@ -51,42 +55,30 @@ void ndgui::createInterfaceGroupBox(){
interfaceGroupBox->setLayout(interfaceGroupBoxLayout);
}
-void ndgui::addNewInterface(QString ifName, int index) {
+void ndgui::addNewInterface(QString ifName) {
+ qDebug() << "receive interface to add:" << ifName;
QHBoxLayout *hBoxLayout = new QHBoxLayout;
QLabel *label = new QLabel(ifName);
+ QLabel *labelStatus = new QLabel("waiting");
QProgressBar *pBar = new QProgressBar(this);
pBar->setRange(1, 100);
pBar->setMaximumSize(200, 20);
- progressBars.insert(index, pBar);
+ statusLabels.insert(ifName, labelStatus);
+ progressBars.insert(ifName, pBar);
hBoxLayout->addWidget(label, Qt::AlignLeft);
+ hBoxLayout->addWidget(labelStatus, Qt::AlignCenter);
hBoxLayout->addWidget(pBar, Qt::AlignRight);
+ numberOfInterfaces++;
+
interfaceGroupBoxLayout->addLayout(hBoxLayout, 2);
}
-/*
-void ndgui::addInterfacesToGroupBox(QList<QNetworkInterface> &interfaces) {
- foreach(QNetworkInterface nI, interfaces){
- int index = indexToIfaceNameMap.value(nI.humanReadableName());
- QHBoxLayout *hBoxLayout = new QHBoxLayout;
- QLabel *label = new QLabel(nI.humanReadableName());
- QProgressBar *pBar = new QProgressBar(this);
- pBar->setRange(1,100);
- pBar->setMaximumSize(200,20);
-
- progressBars.insert(index,pBar);
-
- hBoxLayout->addWidget(label, Qt::AlignLeft);
- hBoxLayout->addWidget(pBar, Qt::AlignRight);
-
- interfaceGroupBoxLayout->addLayout(hBoxLayout,2);
- }
-}
-*/
-void ndgui::handleProgress(int iFaceIndex, int newValue) {
- qDebug() << "<[---]> SLOT handleProgress activated with: " << iFaceIndex << newValue;
- QProgressBar * pBar = progressBars.value(iFaceIndex);
+
+void ndgui::handleProgress(QString ifName, int newValue) {
+ qDebug() << "<[---]> SLOT handleProgress activated with: " << ifName << newValue;
+ QProgressBar * pBar = progressBars.value(ifName);
if(newValue >= pBar->value()) {
pBar->setValue(newValue);
}
@@ -96,5 +88,20 @@ void ndgui::handleProgress(int iFaceIndex, int newValue) {
}
void ndgui::handleConnectionEstablished(QString ifName) {
+ finalUsableInterfaces.append(ifName);
+}
+
+void ndgui::handleAbortBoot(QString msg) {
+ qDebug() << "abort boot. reason:" << msg;
+}
+
+void ndgui::handleUpdateStatusLabel(QString ifName, QString status) {
+ QLabel* label = statusLabels.value(ifName);
+ label->setText(status);
+}
+
+void ndgui::handleAllProcessesFinished() {
+ qDebug() << "all Processes finished";
+ mainLayout->
}
diff --git a/workspace/LogReceiver/ndgui.h b/workspace/LogReceiver/ndgui.h
index d3cf29f..a3b1e70 100644
--- a/workspace/LogReceiver/ndgui.h
+++ b/workspace/LogReceiver/ndgui.h
@@ -17,17 +17,25 @@ public:
~ndgui();
public slots:
- void handleProgress(int iFaceIndex, int newValue);
- void addNewInterface(QString ifName, int index);
+ void handleProgress(QString ifName, int newValue);
+ void addNewInterface(QString ifName);
void handleConnectionEstablished(QString ifName);
+ void handleAbortBoot(QString msg);
+ void handleUpdateStatusLabel(QString ifName, QString status);
+ void handleAllProcessesFinished();
private:
Ui::ndguiClass ui;
LogReceiver logReceiver;
+ QList<QString> finalUsableInterfaces;
+
+ int numberOfInterfaces;
+
/*gui elements*/
- QMap<int, QProgressBar *> progressBars;
+ QMap<QString, QProgressBar *> progressBars;
+ QMap<QString, QLabel*> statusLabels;
QLabel *ndStatusLabel;
QGroupBox *interfaceGroupBox;
QVBoxLayout *mainLayout;
@@ -37,10 +45,6 @@ private:
/*gui functions*/
void buildGui();
void createInterfaceGroupBox();
- //void addInterfacesToGroupBox(QList<QNetworkInterface> &interfaces);
-
-
-
};
diff --git a/workspace/customdhcpcd/src/logwriter.c b/workspace/customdhcpcd/src/logwriter.c
index 89aadb6..2ef257c 100644
--- a/workspace/customdhcpcd/src/logwriter.c
+++ b/workspace/customdhcpcd/src/logwriter.c
@@ -21,7 +21,7 @@ int sockfd, ns;
int retval = -1;
char socketName[QTSOCKETADDRESSLENGTH];
char interfaceName[IF_NAMESIZE];
-char mesg[256] = {0};
+char mesg[1024];
void setSocketName(const char * sn) {
snprintf(socketName, sizeof(socketName), "%s", sn);