From 2a04cb4147eb9c583fae8d0b3120a74eaf1af68a Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 1 Aug 2011 12:31:12 +0200 Subject: seperation of logic and gui completed. --- workspace/LogReceiver/logreceiver.cpp | 77 ++++++++++++----------------------- 1 file changed, 27 insertions(+), 50 deletions(-) (limited to 'workspace/LogReceiver/logreceiver.cpp') diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 554b721..1bbdec0 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -19,12 +19,20 @@ LogReceiver::LogReceiver() { server = new QLocalServer(this); +} + +LogReceiver::~LogReceiver() { + +} + +void LogReceiver::initAndRun() { + if (!server->listen("/var/tmp/qt_c_socket_default")) { /* - QMessageBox::critical(this, tr("LogReceiver"), tr( - "Unable to start the server: %1.") .arg(server->errorString())); - close(); - */ + 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 return; } @@ -41,14 +49,8 @@ LogReceiver::LogReceiver() { dhcpcdArguments.append("-d"); QString ifName("eth1"); runDHCPCD(ifName); - -} - -LogReceiver::~LogReceiver() { - } - void LogReceiver::handleNewConnection() { qDebug() << "New Connection arrived"; @@ -84,14 +86,14 @@ void LogReceiver::handleNewInputLine(QString data) { QString s_subState = logMsg.section(";", 2, 2); QString msg = logMsg.section(";", 3, 3); - int pBar = indexToIfaceNameMap.value(interface); + int pBar = indexToIfaceNameMap.value(interface.trimmed()); //qDebug() << logMsg; //qDebug() << msg; - int st = s_state.toInt(); - int sst = s_subState.toInt(); + int st = s_state.trimmed().toInt(); + int sst = s_subState.trimmed().toInt(); switch (st) { case LOG_INFO: @@ -99,19 +101,19 @@ void LogReceiver::handleNewInputLine(QString data) { qDebug() << sst; switch (sst) { case DHCP_DISCOVER: - handleProgress(pBar,10); + emit changeProgressBarValue(pBar,10); break; case DHCP_OFFER: - handleProgress(pBar,20); + emit changeProgressBarValue(pBar,20); break; case DHCP_REQUEST: - handleProgress(pBar,30); + emit changeProgressBarValue(pBar,30); break; case DHCP_DECLINE: break; case DHCP_ACK: - handleProgress(pBar,40); + emit changeProgressBarValue(pBar,100); break; case DHCP_NAK: @@ -151,40 +153,15 @@ QList LogReceiver::getListOfNetworkInterfaces() { { continue; } - /* - if(!(nI.flags() & QNetworkInterface::IsUp)) { - qDebug() << nI.humanReadableName() + " is DOWN "; - - QProcess * p = new QProcess(this); - QStringList args; - args.append(nI.humanReadableName()); - args.append("up"); - p->start("ifconfig",args); - connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); - p->waitForFinished(); - qDebug() << nI.humanReadableName() + " is UP "; -/* - QNetworkConfigurationManager manager; - QList confList = manager.allConfigurations(); - foreach(QNetworkConfiguration nC, confList){ - if( nC.name() == "Auto eth1") { - QNetworkConfiguration conf = manager.configurationFromIdentifier(nC.identifier()); - if(conf.isValid()) { - QNetworkSession *session = new QNetworkSession(conf); - session->open(); - } - qDebug() << "conf is not valid"; - } - qDebug() << nC.name(); - qDebug() << nC.identifier(); - } -*/ + if (!checkCarrierState(nI.humanReadableName())) { + continue; + } - //} - qDebug() << nI.humanReadableName(); + // qDebug() << nI.humanReadableName(); result.append(nI); interfacesMap.insert(i, nI); indexToIfaceNameMap.insert(nI.humanReadableName(), i); + emit addNewInterface(nI.humanReadableName(), i); i++; } return result; @@ -278,11 +255,11 @@ bool LogReceiver::checkCarrierState(QString interface) { void LogReceiver::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { - QObject* sender = const_cast (QObject::sender()); - QProcess* process = static_cast (sender); + //QObject* sender = const_cast (QObject::sender()); + //QProcess* process = static_cast (sender); QProcess* p = qobject_cast(QObject::sender()); - QProcess * client = clientProcesses.value(process->pid()); + QProcess * client = clientProcesses.value(p->pid()); qDebug() << "process finished: " << client->pid() << exitCode << exitStatus; } -- cgit v1.2.3-55-g7522