From e0d30e3134fcbe54182d53e69f64167db408014b Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 1 Aug 2011 16:55:01 +0200 Subject: added some log statements to the dhcpcd client. But unfortunately it seems that some message will not be delivered. It happens that after the process finished message, some other messages arrived --- workspace/LogReceiver/LogReceiver | Bin 65367 -> 69772 bytes workspace/LogReceiver/LogReceiver.pro | 1 - workspace/LogReceiver/logreceiver.cpp | 113 ++++++++++++++++++++-------------- workspace/LogReceiver/logreceiver.h | 7 ++- workspace/LogReceiver/ndgui.cpp | 5 +- 5 files changed, 75 insertions(+), 51 deletions(-) (limited to 'workspace/LogReceiver') diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver index ac7b336..9119d96 100755 Binary files a/workspace/LogReceiver/LogReceiver and b/workspace/LogReceiver/LogReceiver differ diff --git a/workspace/LogReceiver/LogReceiver.pro b/workspace/LogReceiver/LogReceiver.pro index 97c9067..81c48f6 100644 --- a/workspace/LogReceiver/LogReceiver.pro +++ b/workspace/LogReceiver/LogReceiver.pro @@ -6,7 +6,6 @@ QT += core \ LIBS += -lsysfs INCLUDEPATH += ../customdhcpcd/src HEADERS += ndgui.h \ - status.h \ logreceiver.h SOURCES += ndgui.cpp \ main.cpp \ diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 1bbdec0..60e8b5c 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -25,27 +25,36 @@ LogReceiver::~LogReceiver() { } -void LogReceiver::initAndRun() { +void LogReceiver::initAndRun(QString serverPath, + QString pathToExe , + QStringList* args ) { - if (!server->listen("/var/tmp/qt_c_socket_default")) { + if (serverPath != DEFAULT_QTSOCKETADDRESS) { + dhcpcdArguments.append("-q"); + dhcpcdArguments.append(serverPath); + } + if (!server->listen(serverPath)) { /* QMessageBox::critical(this, tr("LogReceiver"), tr( "Unable to start the server: %1.") .arg(server->errorString())); close(); */ // emit signal to the gui that a critial error occoured + qDebug() << "--- \t [LogReceiver::initAndRun] Unable to start server:" << server->errorString(); return; } connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); QList list = getListOfNetworkInterfaces(); - //qDebug() << list.size(); //checkCarrierState(list); - //qDebug() << list.size(); - //checkCarrierState("eth1"); - //checkCarrierState("eth0"); - pathToDhcpcdExe = "/home/niklas/fbgui/workspace/customdhcpcd/src/dhcpcd"; + pathToDhcpcdExe = pathToExe; + + if(args != NULL && ! args->isEmpty()) { + qDebug() << "--- \t [LogReceiver::initAndRun] added additional args"; + dhcpcdArguments.append(*args); + } + dhcpcdArguments.append("-d"); QString ifName("eth1"); runDHCPCD(ifName); @@ -86,50 +95,61 @@ void LogReceiver::handleNewInputLine(QString data) { QString s_subState = logMsg.section(";", 2, 2); QString msg = logMsg.section(";", 3, 3); - int pBar = indexToIfaceNameMap.value(interface.trimmed()); - - //qDebug() << logMsg; - - //qDebug() << msg; - + 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: - qDebug() << "received LOG_INFO"; - qDebug() << sst; switch (sst) { case DHCP_DISCOVER: - emit changeProgressBarValue(pBar,10); + emit changeProgressBarValue(pBar, 10); break; case DHCP_OFFER: - emit changeProgressBarValue(pBar,20); + emit changeProgressBarValue(pBar, 20); break; case DHCP_REQUEST: - emit changeProgressBarValue(pBar,30); - break; - case DHCP_DECLINE: - + emit changeProgressBarValue(pBar, 30); break; case DHCP_ACK: - emit changeProgressBarValue(pBar,100); + 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; } - - qDebug() << msg; - break; case LOG_ERR: qDebug() << "received stat_error"; @@ -137,8 +157,6 @@ void LogReceiver::handleNewInputLine(QString data) { default: qDebug() << logMsg; } - - //statusLabel->setText(logMsg); } QList LogReceiver::getListOfNetworkInterfaces() { @@ -171,6 +189,9 @@ void LogReceiver::runDHCPCD(QList &interfaces) { foreach(QNetworkInterface ni, interfaces) { dhcpcdArguments.append(ni.humanReadableName()); QProcess * p = new QProcess(this); + + qDebug() << dhcpcdArguments; + clientProcesses.insert(p->pid(),p); p->start(pathToDhcpcdExe,dhcpcdArguments); connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); @@ -183,6 +204,9 @@ void LogReceiver::runDHCPCD(QList &interfaces) { void LogReceiver::runDHCPCD(QString interface) { dhcpcdArguments.append(interface); QProcess * p = new QProcess(this); + + qDebug() << dhcpcdArguments; + clientProcesses.insert(p->pid(),p); p->start(pathToDhcpcdExe,dhcpcdArguments); connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); @@ -202,10 +226,15 @@ void LogReceiver::checkCarrierState(QList &interfaces) { // cable is unplugged, // remove interface out of the list, // remove interface out ot the index maps - int i = indexToIfaceNameMap.value(nI.humanReadableName()); + 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); + } } } } @@ -254,26 +283,18 @@ bool LogReceiver::checkCarrierState(QString interface) { void LogReceiver::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { - - //QObject* sender = const_cast (QObject::sender()); - //QProcess* process = static_cast (sender); QProcess* p = qobject_cast(QObject::sender()); - QProcess * client = clientProcesses.value(p->pid()); - - qDebug() << "process finished: " << client->pid() << exitCode << exitStatus; + QProcess * client = clientProcesses.value(p->pid(),0); + if(client <= 0) { + qDebug() << "--- \t [LogReceiver::handleProcessFinished] haven't found process!"; + } + else { + qDebug() << "process finished: " << client->pid() << exitCode << exitStatus; + } } void LogReceiver::handleProcessStarted() { - -/* - //QObject* sender = const_cast (QObject::sender()); - QProcess* process = static_cast (QObject::sender()); -*/ - //QProcess* p = qobject_cast(QObject::sender()); - //QProcess * client = clientProcesses.value(process->pid()); - - qDebug() << "process started: "; } diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h index 26a3934..561b406 100644 --- a/workspace/LogReceiver/logreceiver.h +++ b/workspace/LogReceiver/logreceiver.h @@ -10,11 +10,16 @@ class QLocalSocket; class LogReceiver: public QObject { Q_OBJECT +#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" +#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/workspace/customdhcpcd/src/dhcpcd" + public: LogReceiver(); ~LogReceiver(); - void initAndRun(); + void initAndRun(QString serverPath = DEFAULT_QTSOCKETADDRESS, + QString pathToExe = DEFAULT_PATHTODHCPCDEXE, + QStringList* args = NULL); private slots: void handleNewConnection(); diff --git a/workspace/LogReceiver/ndgui.cpp b/workspace/LogReceiver/ndgui.cpp index e838a8c..629a8fb 100644 --- a/workspace/LogReceiver/ndgui.cpp +++ b/workspace/LogReceiver/ndgui.cpp @@ -10,7 +10,7 @@ ndgui::ndgui(QWidget *parent) buildGui(); - logReceiver.initAndRun(); + logReceiver.initAndRun("/var/tmp/qt_c_socket_custom"); setWindowTitle(tr("NetD")); @@ -23,8 +23,6 @@ ndgui::~ndgui() void ndgui::buildGui() { - - ndStatusLabel = new QLabel(tr("test")); ndStatusLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -86,6 +84,7 @@ void ndgui::addInterfacesToGroupBox(QList &interfaces) { } */ void ndgui::handleProgress(int iFaceIndex, int newValue) { + qDebug() << "<[---]> SLOT handleProgress activated with: " << iFaceIndex << newValue; QProgressBar * pBar = progressBars.value(iFaceIndex); if(newValue >= pBar->value()) { pBar->setValue(newValue); -- cgit v1.2.3-55-g7522