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.cpp | 113 ++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 46 deletions(-) (limited to 'workspace/LogReceiver/logreceiver.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: "; } -- cgit v1.2.3-55-g7522