summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-08-30 16:16:30 +0200
committerNiklas2011-08-30 16:16:30 +0200
commit0c23447d55c144c6c7e2bfb1b526a64bb5051f2e (patch)
tree745cabb945a4f5a53e642199aae78b4263f2fd8d
parentadded check for file existens. renamed the dhcpcd bin to customdhcpcd. tempo... (diff)
downloadfbgui-0c23447d55c144c6c7e2bfb1b526a64bb5051f2e.tar.gz
fbgui-0c23447d55c144c6c7e2bfb1b526a64bb5051f2e.tar.xz
fbgui-0c23447d55c144c6c7e2bfb1b526a64bb5051f2e.zip
changed sleep(1) to usleep(500) after every send to socket in logwriter.c Main Problem with this workaround: with increasing number of messages, the program will become slower and slower. also added a new map in which i store the pair (interfacename, qlocalsocket client) with this i can check if there are still some messages left, when a process finishes
-rwxr-xr-xworkspace/LogReceiver/LogReceiverbin117864 -> 122366 bytes
-rw-r--r--workspace/LogReceiver/logreceiver.cpp208
-rw-r--r--workspace/LogReceiver/logreceiver.h3
-rwxr-xr-xworkspace/customdhcpcd/src/customdhcpcdbin173204 -> 173205 bytes
-rw-r--r--workspace/customdhcpcd/src/logwriter.c2
5 files changed, 115 insertions, 98 deletions
diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver
index a2450ce..0aaf570 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 9f73862..9bc86e3 100644
--- a/workspace/LogReceiver/logreceiver.cpp
+++ b/workspace/LogReceiver/logreceiver.cpp
@@ -1,20 +1,18 @@
- #include <QMap>
- #include <QtNetwork>
- #include <QProcess>
-
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <syslog.h>
- #include <sysfs/libsysfs.h>
-
- #include "logreceiver.h"
- #include <qlocalserver.h>
- #include <qlocalsocket.h>
- #include "status.h"
- #include "dhcp.h"
-
+#include <QMap>
+#include <QtNetwork>
+#include <QProcess>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include <sysfs/libsysfs.h>
+
+#include "logreceiver.h"
+#include <qlocalserver.h>
+#include <qlocalsocket.h>
+#include "status.h"
+#include "dhcp.h"
LogReceiver::LogReceiver() {
@@ -42,7 +40,8 @@ void LogReceiver::initAndRun(QString serverPath, QString pathToExe,
QString errorInfo("Unable to start server: ");
qDebug() << "--- \t [LogReceiver::initAndRun] " + errorInfo
<< server->errorString();
- emit abortBoot(errorInfo + server->errorString());
+ emit
+ abortBoot(errorInfo + server->errorString());
return;
}
@@ -52,8 +51,11 @@ void LogReceiver::initAndRun(QString serverPath, QString pathToExe,
// check if the path to the customdhcpcd file is correct
QFileInfo fInfo(pathToDhcpcdExe);
if (!fInfo.exists()) {
- qDebug() << "couldn't find customdhcpcd exe. Please check the path to this file.";
- emit abortBoot("couldn't find customdhcpcd exe. Please check the path to this file.");
+ qDebug()
+ << "couldn't find customdhcpcd exe. Please check the path to this file.";
+ emit
+ abortBoot(
+ "couldn't find customdhcpcd exe. Please check the path to this file.");
return;
}
@@ -79,7 +81,8 @@ void LogReceiver::initAndRun(QString serverPath, QString pathToExe,
runDHCPCD(list);
} else {
qDebug() << "list is empty. Haven't found usable interface.";
- emit abortBoot("Haven't found usable interface");
+ emit
+ abortBoot("Haven't found usable interface");
return;
}
@@ -112,14 +115,15 @@ QList<QString> LogReceiver::getListOfNetworkInterfaces() {
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);
+ foreach(QString nI, interfaces)
+ {
+ if (checkCarrierState(nI)) {
+ // everything is fine, cable is plugged,
+ // go on with the next interface
+ //continue;
+ result.append(nI);
+ }
}
- }
return result;
}
@@ -164,25 +168,26 @@ bool LogReceiver::checkCarrierState(QString interface) {
}
void LogReceiver::runDHCPCD(QList<QString> &interfaces) {
- foreach(QString nI, interfaces) {
- runDHCPCD(nI);
- }
+ foreach(QString nI, interfaces)
+ {
+ runDHCPCD(nI);
+ }
}
void LogReceiver::runDHCPCD(QString interface) {
- emit updateStatusLabel(interface,"start DHCP");
- 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();
+ emit updateStatusLabel(interface, "start DHCP");
+ 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) {
@@ -205,16 +210,17 @@ void LogReceiver::checkInternetConnection(QString ifName) {
emit updateStatusLabel(ifName, "connection not possible");
} else if (exitCode == 0) {
qDebug() << "internet: check passed! for interface" << ifName;
- emit updateStatusLabel(ifName, "connection possible");
+ emit
+ updateStatusLabel(ifName, "connection possible");
emit connectionEstablished(ifName);
}
}
void LogReceiver::checkInternetConnection(QList<QString> &interfaces) {
foreach(QString nI, interfaces)
- {
- checkInternetConnection(nI);
- }
+ {
+ checkInternetConnection(nI);
+ }
}
void LogReceiver::checkInternetConnectionViaTCP(QString ifName) {
@@ -242,15 +248,14 @@ void LogReceiver::checkInternetConnectionViaTCP(QString ifName) {
QTcpSocket *tcpSocket = new QTcpSocket(this);
tcpSocket->connectToHost(QString("209.85.148.105"), 80);
- if (!tcpSocket->waitForConnected()) {
+ if (!tcpSocket->waitForConnected(2000)) {
qDebug() << tcpSocket->errorString();
emit updateStatusLabel(ifName, "connection not possible");
} else {
emit updateStatusLabel(ifName, "connection possible");
emit connectionEstablished(ifName);
}
- }
- else {
+ } else {
qDebug() << "couldn't open session";
}
session->close();
@@ -259,9 +264,11 @@ void LogReceiver::checkInternetConnectionViaTCP(QString ifName) {
void LogReceiver::handleNewConnection() {
qDebug() << "New Connection arrived";
- /*QLocalSocket **/ client = server ->nextPendingConnection();
+ /*QLocalSocket **/
+ client = server ->nextPendingConnection();
clients.insert(client, client);
- connect(client, SIGNAL(disconnected()), this, SLOT(handleClientDisconnect()));
+ connect(client, SIGNAL(disconnected()), this,
+ SLOT(handleClientDisconnect()));
connect(client, SIGNAL(readyRead()), this, SLOT(handleNewInput()));
}
@@ -276,46 +283,52 @@ void LogReceiver::handleClientDisconnect() {
}
void LogReceiver::handleNewInput(QLocalSocket * client) {
- QString data(client->readAll());
+ qDebug() << "last read before exit";
+ while (client->canReadLine()) {
+ QString data(client->readLine());
- data = data.trimmed();
- qDebug() << data;
- QStringList lines = data.split("\n");
+ data = data.trimmed();
+ qDebug() << data;
+ QStringList lines = data.split("\n");
- for (int i = 0; i < lines.length(); i++) {
- handleNewInputLine(lines.at(i));
+ for (int i = 0; i < lines.length(); i++) {
+ handleNewInputLine(client, lines.at(i));
+ }
}
}
void LogReceiver::handleNewInput() {
-
- //QObject* sender = const_cast<QObject*> (QObject::sender());
- //QLocalSocket* socket = static_cast<QLocalSocket*> (sender);
- QLocalSocket* socket = qobject_cast<QLocalSocket * >(QObject::sender());
+ QLocalSocket* socket = qobject_cast<QLocalSocket *> (QObject::sender());
QLocalSocket * client = clients.value(socket);
QString data(client->readAll());
data = data.trimmed();
- qDebug() << data;
+ qDebug() << data;
QStringList lines = data.split("\n");
- for (int i=0; i < lines.length(); i++) {
- handleNewInputLine(lines.at(i));
+ for (int i = 0; i < lines.length(); i++) {
+ handleNewInputLine(client, lines.at(i));
}
}
-void LogReceiver::handleNewInputLine(QString data) {
+void LogReceiver::handleNewInputLine(QLocalSocket * client, QString data) {
QString logMsg(data);
- QString interface = logMsg.section(";",0,0);
+ 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 st = s_state.trimmed().toInt();
int sst = s_subState.trimmed().toInt();
//qDebug() << logMsg;
+
+ if (ifNameToClient.size() < numberOfProcesses && !ifNameToClient.contains(
+ interface)) {
+ ifNameToClient.insert(interface, client);
+ }
+
switch (st) {
case LOG_INFO:
switch (sst) {
@@ -370,48 +383,51 @@ void LogReceiver::handleNewInputLine(QString data) {
void LogReceiver::handleProcessFinished(int exitCode,
QProcess::ExitStatus exitStatus) {
- QProcess* p = qobject_cast<QProcess * >(QObject::sender());
- QString ifName = clientProcessToIfNameMap.value(p,"ifName");
+ QProcess* p = qobject_cast<QProcess *> (QObject::sender());
+ QString ifName = clientProcessToIfNameMap.value(p, "ifName");
- if(ifName.compare("ifName") == 0) {
- qDebug() << "--- \t [LogReceiver::handleProcessFinished] haven't found process!";
+ if (ifName.compare("ifName") == 0) {
+ qDebug()
+ << "--- \t [LogReceiver::handleProcessFinished] haven't found process!";
+ } else {
+ 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
+ changeProgressBarValue(ifName, 100);
+ emit
+ updateStatusLabel(ifName, "check connectivity");
+ //checkInternetConnection(ifName);
+ checkInternetConnectionViaTCP(ifName);
+ }
}
- else {
- 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 changeProgressBarValue(ifName, 100);
- emit updateStatusLabel(ifName, "check connectivity");
- //checkInternetConnection(ifName);
- checkInternetConnectionViaTCP(ifName);
- }
+ QLocalSocket *client = ifNameToClient.value(ifName, 0);
+ if(client != 0) {
+ handleNewInput(client);
}
- numberOfProcesses = numberOfProcesses -1;
+ numberOfProcesses = numberOfProcesses - 1;
if (numberOfProcesses <= 0) {
emit allProcessesFinished();
}
}
void LogReceiver::handleProcessStarted() {
- QProcess* p = qobject_cast<QProcess * >(QObject::sender());
- QString ifName = clientProcessToIfNameMap.value(p,"ifName");
- qDebug() << "process started for interface:" << ifName;
+ QProcess* p = qobject_cast<QProcess *> (QObject::sender());
+ QString ifName = clientProcessToIfNameMap.value(p, "ifName");
+ qDebug() << "process started for interface:" << ifName;
}
-
bool LogReceiver::checkBlackList(QString i) {
if (i.startsWith("v", Qt::CaseInsensitive)) {
- return true;
- }
- else if(i.startsWith("d", Qt::CaseInsensitive)) {
return true;
- }
- else {
+ } else if (i.startsWith("d", Qt::CaseInsensitive)) {
+ return true;
+ } else {
return false;
}
}
diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h
index 6b32aa8..ce6d070 100644
--- a/workspace/LogReceiver/logreceiver.h
+++ b/workspace/LogReceiver/logreceiver.h
@@ -29,7 +29,7 @@ public:
private slots:
void handleNewConnection();
void handleNewInput();
- void handleNewInputLine(QString data);
+ void handleNewInputLine(QLocalSocket * client, QString data);
void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void handleProcessStarted();
void handleClientDisconnect();
@@ -49,6 +49,7 @@ private:
//QMap<QString, int> indexToIfaceNameMap;
QMap<QLocalSocket *, QLocalSocket *> clients;
QLocalSocket * client;
+ QMap<QString, QLocalSocket*> ifNameToClient;
QMap<QProcess*, QString> clientProcessToIfNameMap;
QString pathToDhcpcdExe;
QStringList dhcpcdArguments;
diff --git a/workspace/customdhcpcd/src/customdhcpcd b/workspace/customdhcpcd/src/customdhcpcd
index 38b7696..c1b9cc1 100755
--- a/workspace/customdhcpcd/src/customdhcpcd
+++ b/workspace/customdhcpcd/src/customdhcpcd
Binary files differ
diff --git a/workspace/customdhcpcd/src/logwriter.c b/workspace/customdhcpcd/src/logwriter.c
index a6adbe3..77a662c 100644
--- a/workspace/customdhcpcd/src/logwriter.c
+++ b/workspace/customdhcpcd/src/logwriter.c
@@ -97,7 +97,7 @@ void sendToQt(log_msg * msg) {
syslog (LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)", msg->status, msg->substatus, msg->msg, msg->device);
// fprintf(stdout, "ERROR writing to socket: %s", msg);
}
- sleep(1);
+ usleep(500);
}
void logToQt(int status, int substatus, const char * msg) {