summaryrefslogtreecommitdiffstats
path: root/LogReceiver/logreceiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LogReceiver/logreceiver.cpp')
-rw-r--r--LogReceiver/logreceiver.cpp63
1 files changed, 22 insertions, 41 deletions
diff --git a/LogReceiver/logreceiver.cpp b/LogReceiver/logreceiver.cpp
index 1e3f388..199f6ed 100644
--- a/LogReceiver/logreceiver.cpp
+++ b/LogReceiver/logreceiver.cpp
@@ -9,11 +9,14 @@
#include <sysfs/libsysfs.h>
#include "logreceiver.h"
+#include "interfaceconfiguration.h"
#include <qlocalserver.h>
#include <qlocalsocket.h>
#include "status.h"
#include "dhcp.h"
+#include "../common/fbgui.h"
+
LogReceiver::LogReceiver() {
server = new QLocalServer(this);
@@ -212,7 +215,7 @@ void LogReceiver::checkInternetConnection(QString ifName) {
qDebug() << "internet: check passed! for interface" << ifName;
emit
updateStatusLabel(ifName, "connection possible");
- emit connectionEstablished(ifName);
+ emit connectionEstablished(ifName, "");
}
}
@@ -231,22 +234,8 @@ void LogReceiver::checkConnectivity(QString ifName) {
// get gateway address
QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION);
pathToGatewayFile += ifName;
- QFile file(pathToGatewayFile);
- if(file.exists()) {
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug() << "couldnt open file:" << pathToGatewayFile;
- return;
- }
- while(!file.atEnd()) {
- QString line(file.readLine());
- QStringList gateways = line.split(",");
- gateway = gateways.first().trimmed();
- }
- }
- else {
- qDebug() << "file doesn't exist:" << pathToGatewayFile;
- return;
- }
+ interfaceconfiguration ifConf;
+ ifConf.readConfigOutOfFile(pathToGatewayFile);
// delete default route
argList << "del" << "default";
@@ -256,7 +245,10 @@ void LogReceiver::checkConnectivity(QString ifName) {
// add new default route
argList.clear();
- argList << "add" << "default" << "gw" << gateway << ifName;
+ qDebug() << "add default route with:" << ifConf.getGateway()
+ << ifConf.getInterface();
+ argList << "add" << "default" << "gw" << ifConf.getGateway()
+ << ifConf.getInterface();
p = new QProcess(this);
p->start(command, argList);
p->waitForFinished();
@@ -272,7 +264,7 @@ void LogReceiver::checkConnectivity(QString ifName) {
qDebug() << "internet: check passed! for interface" << ifName;
emit
updateStatusLabel(ifName, "connection possible");
- emit connectionEstablished(ifName);
+ emit connectionEstablished(ifName, gateway);
}
}
@@ -300,7 +292,8 @@ void LogReceiver::checkInternetConnectionViaTCP(QString ifName) {
session->open();
if (session->waitForOpened(-1)) {
- qDebug () << "used interface for connectivity check:" <<session->interface().humanReadableName();
+ qDebug() << "used interface for connectivity check:"
+ << session->interface().humanReadableName();
QTcpSocket *tcpSocket = new QTcpSocket(this);
tcpSocket->connectToHost(QString("209.85.148.105"), 80);
if (!tcpSocket->waitForConnected(2000)) {
@@ -308,7 +301,7 @@ void LogReceiver::checkInternetConnectionViaTCP(QString ifName) {
emit updateStatusLabel(ifName, "connection not possible");
} else {
emit updateStatusLabel(ifName, "connection possible");
- emit connectionEstablished(ifName);
+ emit connectionEstablished(ifName, "");
}
} else {
qDebug() << "couldn't open session";
@@ -363,34 +356,24 @@ void LogReceiver::handleNewInput(QLocalSocket * client) {
/**
*
+ * This method is connected to the readyRead Signal of the QLocalSocket
+ * client.
+ * send an ACK to the client with every received message.
*/
void LogReceiver::handleNewInput() {
QLocalSocket* socket = qobject_cast<QLocalSocket *> (QObject::sender());
QLocalSocket * client = clients.value(socket);
-
- while(!client->atEnd()) {
- QString data(client->readLine());
-
- data = data.trimmed();
- //qDebug() << data;
- QStringList lines = data.split("\n");
-
- for (int i = 0; i < lines.length(); i++) {
- handleNewInputLine(client, lines.at(i));
- }
- }
-/*
- QString data(client->readAll());
-
+ QString data(client->read(DHCP_MESSAGE_SIZE));
+ client->write("ACK", ACK_SIZE);
+ client->waitForBytesWritten();
data = data.trimmed();
- qDebug() << data;
+ //qDebug() << data;
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
handleNewInputLine(client, lines.at(i));
}
- */
}
/**
@@ -412,8 +395,6 @@ void LogReceiver::handleNewInput() {
*
* @param data
* the message. (format <interfaceName>;<state>;<subState>;<msg> )
- *
- *
*/
void LogReceiver::handleNewInputLine(QLocalSocket * client, QString data) {
@@ -539,7 +520,7 @@ void LogReceiver::handleProcessFinished(int exitCode,
}
}
QLocalSocket *client = ifNameToClient.value(ifName, 0);
- if(client != 0) {
+ if (client != 0) {
handleNewInput(client);
}
numberOfProcesses = numberOfProcesses - 1;