summaryrefslogtreecommitdiffstats
path: root/LogReceiver
diff options
context:
space:
mode:
authorNiklas2011-09-02 17:06:02 +0200
committerNiklas2011-09-02 17:06:02 +0200
commit603f6e47b2be2b5e03e63f6bee9c6364c92a251e (patch)
tree1cc7c4583e54691b031fe9de3a5e68f7a4bbddf3 /LogReceiver
parentjust minor changes. deltions of unuseful comments (diff)
downloadfbgui-603f6e47b2be2b5e03e63f6bee9c6364c92a251e.tar.gz
fbgui-603f6e47b2be2b5e03e63f6bee9c6364c92a251e.tar.xz
fbgui-603f6e47b2be2b5e03e63f6bee9c6364c92a251e.zip
added a new container class which holds config informations about an interface. also solved the message loss problem by setting the read an writing messages to the same size
Diffstat (limited to 'LogReceiver')
-rwxr-xr-xLogReceiver/LogReceiverbin130952 -> 141290 bytes
-rw-r--r--LogReceiver/LogReceiver.pro6
-rw-r--r--LogReceiver/Makefile27
-rw-r--r--LogReceiver/interfaceconfiguration.cpp133
-rw-r--r--LogReceiver/interfaceconfiguration.h53
-rw-r--r--LogReceiver/logreceiver.cpp63
-rw-r--r--LogReceiver/logreceiver.h4
-rw-r--r--LogReceiver/ndgui.cpp5
-rw-r--r--LogReceiver/ndgui.h3
9 files changed, 240 insertions, 54 deletions
diff --git a/LogReceiver/LogReceiver b/LogReceiver/LogReceiver
index 21d42f2..d29f4e2 100755
--- a/LogReceiver/LogReceiver
+++ b/LogReceiver/LogReceiver
Binary files differ
diff --git a/LogReceiver/LogReceiver.pro b/LogReceiver/LogReceiver.pro
index 19300fa..9666b2f 100644
--- a/LogReceiver/LogReceiver.pro
+++ b/LogReceiver/LogReceiver.pro
@@ -5,11 +5,13 @@ QT += core \
network
LIBS += -lsysfs
INCLUDEPATH += ../customdhcpcd/src
-HEADERS += ndgui.h \
+HEADERS += interfaceconfiguration.h \
+ ndgui.h \
logreceiver.h \
abortbootdialog.h \
chooseinterfacedialog.h
-SOURCES += ndgui.cpp \
+SOURCES += interfaceconfiguration.cpp \
+ ndgui.cpp \
main.cpp \
logreceiver.cpp \
abortbootdialog.cpp \
diff --git a/LogReceiver/Makefile b/LogReceiver/Makefile
index 2b6b8c6..0ba1fe1 100644
--- a/LogReceiver/Makefile
+++ b/LogReceiver/Makefile
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: LogReceiver
-# Generated by qmake (2.01a) (Qt 4.7.2) on: Thu Sep 1 13:01:39 2011
+# Generated by qmake (2.01a) (Qt 4.7.2) on: Fri Sep 2 14:15:11 2011
# Project: LogReceiver.pro
# Template: app
# Command: /usr/local/Trolltech/QtEmbedded-4.7.2/bin/qmake -o Makefile LogReceiver.pro
@@ -43,19 +43,23 @@ OBJECTS_DIR = ./
####### Files
-SOURCES = ndgui.cpp \
+SOURCES = interfaceconfiguration.cpp \
+ ndgui.cpp \
main.cpp \
logreceiver.cpp \
abortbootdialog.cpp \
- chooseinterfacedialog.cpp moc_ndgui.cpp \
+ chooseinterfacedialog.cpp moc_interfaceconfiguration.cpp \
+ moc_ndgui.cpp \
moc_logreceiver.cpp \
moc_abortbootdialog.cpp \
moc_chooseinterfacedialog.cpp
-OBJECTS = ndgui.o \
+OBJECTS = interfaceconfiguration.o \
+ ndgui.o \
main.o \
logreceiver.o \
abortbootdialog.o \
chooseinterfacedialog.o \
+ moc_interfaceconfiguration.o \
moc_ndgui.o \
moc_logreceiver.o \
moc_abortbootdialog.o \
@@ -167,7 +171,7 @@ qmake: FORCE
dist:
@$(CHK_DIR_EXISTS) .tmp/LogReceiver1.0.0 || $(MKDIR) .tmp/LogReceiver1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.h logreceiver.h abortbootdialog.h chooseinterfacedialog.h .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.cpp main.cpp logreceiver.cpp abortbootdialog.cpp chooseinterfacedialog.cpp .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.ui logreceiver.ui .tmp/LogReceiver1.0.0/ && (cd `dirname .tmp/LogReceiver1.0.0` && $(TAR) LogReceiver1.0.0.tar LogReceiver1.0.0 && $(COMPRESS) LogReceiver1.0.0.tar) && $(MOVE) `dirname .tmp/LogReceiver1.0.0`/LogReceiver1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/LogReceiver1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents interfaceconfiguration.h ndgui.h logreceiver.h abortbootdialog.h chooseinterfacedialog.h .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents interfaceconfiguration.cpp ndgui.cpp main.cpp logreceiver.cpp abortbootdialog.cpp chooseinterfacedialog.cpp .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.ui logreceiver.ui .tmp/LogReceiver1.0.0/ && (cd `dirname .tmp/LogReceiver1.0.0` && $(TAR) LogReceiver1.0.0.tar LogReceiver1.0.0 && $(COMPRESS) LogReceiver1.0.0.tar) && $(MOVE) `dirname .tmp/LogReceiver1.0.0`/LogReceiver1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/LogReceiver1.0.0
clean:compiler_clean
@@ -188,9 +192,12 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
-compiler_moc_header_make_all: moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
+compiler_moc_header_make_all: moc_interfaceconfiguration.cpp moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
compiler_moc_header_clean:
- -$(DEL_FILE) moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
+ -$(DEL_FILE) moc_interfaceconfiguration.cpp moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
+moc_interfaceconfiguration.cpp: interfaceconfiguration.h
+ /usr/local/Trolltech/QtEmbedded-4.7.2/bin/moc $(DEFINES) $(INCPATH) interfaceconfiguration.h -o moc_interfaceconfiguration.cpp
+
moc_ndgui.cpp: ui_ndgui.h \
logreceiver.h \
chooseinterfacedialog.h \
@@ -233,6 +240,9 @@ compiler_clean: compiler_moc_header_clean compiler_uic_clean
####### Compile
+interfaceconfiguration.o: interfaceconfiguration.cpp interfaceconfiguration.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o interfaceconfiguration.o interfaceconfiguration.cpp
+
ndgui.o: ndgui.cpp ndgui.h \
ui_ndgui.h \
logreceiver.h \
@@ -256,6 +266,9 @@ abortbootdialog.o: abortbootdialog.cpp abortbootdialog.h
chooseinterfacedialog.o: chooseinterfacedialog.cpp chooseinterfacedialog.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o chooseinterfacedialog.o chooseinterfacedialog.cpp
+moc_interfaceconfiguration.o: moc_interfaceconfiguration.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_interfaceconfiguration.o moc_interfaceconfiguration.cpp
+
moc_ndgui.o: moc_ndgui.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ndgui.o moc_ndgui.cpp
diff --git a/LogReceiver/interfaceconfiguration.cpp b/LogReceiver/interfaceconfiguration.cpp
new file mode 100644
index 0000000..8ab7cbb
--- /dev/null
+++ b/LogReceiver/interfaceconfiguration.cpp
@@ -0,0 +1,133 @@
+/*
+ * interfaceconfiguration.cpp
+ *
+ * Created on: Sep 2, 2011
+ * Author: niklas
+ */
+#include "interfaceconfiguration.h"
+
+interfaceconfiguration::interfaceconfiguration() {
+
+}
+
+interfaceconfiguration::~interfaceconfiguration() {
+ // TODO Auto-generated destructor stub
+}
+
+/**
+ * This method reads the configuration values out of a file.
+ *
+ * This method reads the configuration values out of a file.
+ * The file has to be created before by the customdhcpcd QProcess.
+ * (Overwrites the old values if they are already present.)
+ *
+ * @param pathToConfig
+ * contains the path to the configuration file.
+ */
+bool interfaceconfiguration::readConfigOutOfFile(QString pathToConfig) {
+ QFile file(pathToConfig);
+ if (file.exists()) {
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ qDebug() << "couldn't open file:" << pathToConfig;
+ return false;
+ }
+ while (!file.atEnd()) {
+ QString line(file.readLine());
+ QStringList splitedLine = line.split("=");
+ QString name = splitedLine.first().trimmed();
+ splitedLine.removeFirst();
+ QString values = splitedLine.first().trimmed();
+ values.remove(QChar('\''));
+ qDebug() << "read config file:" << name << values;
+ if (name.compare("IPADDR") == 0) {
+ this->ipAddress = values;
+ } else if (name.compare("NETMASK") == 0) {
+ this->netmask = values;
+ } else if (name.compare("NETWORK") == 0) {
+ this->network = values;
+ } else if (name.compare("BROADCAST") == 0) {
+ this->broadcast = values;
+ } else if (name.compare("ROUTES") == 0) {
+ this->routes = values;
+ } else if (name.compare("GATEWAYS") == 0) {
+ this->gateways = values;
+ this->gateway = this->gateways.split(" ").first().trimmed();
+ } else if (name.compare("HOSTNAME") == 0) {
+ this->hostname = values;
+ } else if (name.compare("DNSSEARCH") == 0) {
+ this->dnssearch = values;
+ } else if (name.compare("DNSSERVERS") == 0) {
+ this->dnsservers = values;
+ } else if (name.compare("DHCPSID") == 0) {
+ this->dhcpsid = values;
+ } else if (name.compare("INTERFACE") == 0) {
+ this->interface = values;
+ } else if (name.compare("CLIENTID") == 0) {
+ this->clientid = values;
+ } else if (name.compare("DHCPCHADDR") == 0) {
+ this->dhcpchaddr = values;
+ } else {
+ qDebug() << "read unknown name" << name << values;
+ }
+ }
+ } else {
+ qDebug() << "file doesn't exist:" << pathToConfig;
+ return false;
+ }
+ return true;
+}
+
+QString interfaceconfiguration::getBroadcast() {
+ return broadcast;
+}
+
+QString interfaceconfiguration::getClientid() {
+ return clientid;
+}
+
+QString interfaceconfiguration::getDhcpchaddr() {
+ return dhcpchaddr;
+}
+
+QString interfaceconfiguration::getDhcpsid() {
+ return dhcpsid;
+}
+QString interfaceconfiguration::getDnssearch() {
+ return dnssearch;
+}
+
+QString interfaceconfiguration::getDnsservers() {
+ return dnsservers;
+}
+
+QString interfaceconfiguration::getGateways() {
+ return gateways;
+}
+
+QString interfaceconfiguration::getGateway() {
+ return gateway;
+}
+
+QString interfaceconfiguration::getHostname() {
+ return hostname;
+}
+
+QString interfaceconfiguration::getInterface() {
+ return interface;
+}
+
+QString interfaceconfiguration::getIpAddress() {
+ return ipAddress;
+}
+
+QString interfaceconfiguration::getNetmask() {
+ return netmask;
+}
+
+QString interfaceconfiguration::getNetwork() {
+ return network;
+}
+
+QString interfaceconfiguration::getRoutes() {
+ return routes;
+}
diff --git a/LogReceiver/interfaceconfiguration.h b/LogReceiver/interfaceconfiguration.h
new file mode 100644
index 0000000..d12bd14
--- /dev/null
+++ b/LogReceiver/interfaceconfiguration.h
@@ -0,0 +1,53 @@
+/*
+ * interfaceconfiguration.h
+ *
+ * Created on: Sep 2, 2011
+ * Author: niklas
+ */
+
+#ifndef INTERFACECONFIGURATION_H_
+#define INTERFACECONFIGURATION_H_
+
+#include <QtCore>
+
+class interfaceconfiguration: public QObject {
+Q_OBJECT
+
+public:
+ interfaceconfiguration();
+ virtual ~interfaceconfiguration();
+
+ bool readConfigOutOfFile(QString pathToConfig);
+ QString getBroadcast();
+ QString getClientid();
+ QString getDhcpchaddr();
+ QString getDhcpsid();
+ QString getDnssearch();
+ QString getDnsservers();
+ QString getGateways();
+ QString getGateway();
+ QString getHostname();
+ QString getInterface();
+ QString getIpAddress();
+ QString getNetmask();
+ QString getNetwork();
+ QString getRoutes();
+
+private:
+ QString ipAddress;
+ QString netmask;
+ QString network;
+ QString broadcast;
+ QString routes;
+ QString gateway;
+ QString gateways;
+ QString hostname;
+ QString dnssearch;
+ QString dnsservers;
+ QString dhcpsid;
+ QString interface;
+ QString clientid;
+ QString dhcpchaddr;
+};
+
+#endif /* INTERFACECONFIGURATION_H_ */
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;
diff --git a/LogReceiver/logreceiver.h b/LogReceiver/logreceiver.h
index a8572d0..e30e85b 100644
--- a/LogReceiver/logreceiver.h
+++ b/LogReceiver/logreceiver.h
@@ -18,6 +18,7 @@ Q_OBJECT
#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default"
#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/customdhcpcd"
#define DEFAULT_GATEWAY_INFO_LOCATION "/var/tmp/gateways_"
+#define ACK_SIZE 4
public:
LogReceiver();
@@ -38,7 +39,7 @@ private slots:
signals:
void addNewInterface(QString ifName);
void changeProgressBarValue(QString ifName, int newValue);
- void connectionEstablished(QString ifName);
+ void connectionEstablished(QString ifName, QString gateway);
void abortBoot(QString msg);
void updateStatusLabel(QString ifName, QString status);
void allProcessesFinished();
@@ -57,6 +58,7 @@ private:
QNetworkConfigurationManager configurationManager;
QNetworkAccessManager *accessManager;
int numberOfProcesses;
+ //const char ack[ACK_SIZE];
void handleNewInput(QLocalSocket * client);
diff --git a/LogReceiver/ndgui.cpp b/LogReceiver/ndgui.cpp
index a839aef..5543eef 100644
--- a/LogReceiver/ndgui.cpp
+++ b/LogReceiver/ndgui.cpp
@@ -9,7 +9,7 @@ ndgui::ndgui(QWidget *parent)
connect(&logReceiver, SIGNAL(addNewInterface(QString)), this, SLOT(addNewInterface(QString)));
connect(&logReceiver, SIGNAL(changeProgressBarValue(QString , int )), this, SLOT(handleProgress(QString, int)));
- connect(&logReceiver, SIGNAL(connectionEstablished(QString)), this, SLOT(handleConnectionEstablished(QString)));
+ connect(&logReceiver, SIGNAL(connectionEstablished(QString, QString)), this, SLOT(handleConnectionEstablished(QString, QString)));
connect(&logReceiver, SIGNAL(abortBoot(QString)), this, SLOT(handleAbortBoot(QString)));
connect(&logReceiver, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(handleUpdateStatusLabel(QString, QString)));
connect(&logReceiver, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished()));
@@ -89,8 +89,9 @@ void ndgui::handleProgress(QString ifName, int newValue) {
}
}
-void ndgui::handleConnectionEstablished(QString ifName) {
+void ndgui::handleConnectionEstablished(QString ifName, QString gateway) {
finalUsableInterfaces.append(ifName);
+ // TODO:: Fix this!! use a interfaceconfiguration object instead!!!
}
void ndgui::handleAbortBoot(QString msg) {
diff --git a/LogReceiver/ndgui.h b/LogReceiver/ndgui.h
index e8b0b85..cca603d 100644
--- a/LogReceiver/ndgui.h
+++ b/LogReceiver/ndgui.h
@@ -21,7 +21,7 @@ public:
public slots:
void handleProgress(QString ifName, int newValue);
void addNewInterface(QString ifName);
- void handleConnectionEstablished(QString ifName);
+ void handleConnectionEstablished(QString ifName, QString gateway);
void handleAbortBoot(QString msg);
void handleUpdateStatusLabel(QString ifName, QString status);
void handleAllProcessesFinished();
@@ -40,6 +40,7 @@ private:
LogReceiver logReceiver;
QStringList finalUsableInterfaces;
+ QMap<QString, QString> finalUsableIntefacesMap; // maps interfaceName to its gateway
int numberOfInterfaces;