summaryrefslogtreecommitdiffstats
path: root/workspace/LogReceiver/logreceiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'workspace/LogReceiver/logreceiver.cpp')
-rw-r--r--workspace/LogReceiver/logreceiver.cpp184
1 files changed, 104 insertions, 80 deletions
diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp
index 4aeebfc..554b721 100644
--- a/workspace/LogReceiver/logreceiver.cpp
+++ b/workspace/LogReceiver/logreceiver.cpp
@@ -1,4 +1,3 @@
- #include <QtGui>
#include <QMap>
#include <QtNetwork>
#include <QProcess>
@@ -8,55 +7,41 @@
#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(QWidget *parent) :
- QDialog(parent) {
- ui.setupUi(this);
-
- statusLabel = new QLabel;
- quitButton = new QPushButton(tr("Quit"));
- quitButton->setAutoDefault(false);
+LogReceiver::LogReceiver() {
server = new QLocalServer(this);
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();
+ */
+ // emit signal to the gui that a critial error occoured
return;
}
- statusLabel->setText(tr("The server is running.\n"
- "Run the C Client example now."));
-
- connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
- QHBoxLayout *buttonLayout = new QHBoxLayout;
- buttonLayout->addStretch(1);
- buttonLayout->addWidget(quitButton);
- buttonLayout->addStretch(1);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(statusLabel);
- mainLayout->addLayout(buttonLayout);
- //setLayout(mainLayout);
-
QList<QNetworkInterface> list = getListOfNetworkInterfaces();
- buildGui();
- addInterfacesToGroupBox(interfacesMap);
+ //qDebug() << list.size();
+ //checkCarrierState(list);
+ //qDebug() << list.size();
+ //checkCarrierState("eth1");
+ //checkCarrierState("eth0");
pathToDhcpcdExe = "/home/niklas/fbgui/workspace/customdhcpcd/src/dhcpcd";
- //dhcpcdArguments.append("-d");
+ dhcpcdArguments.append("-d");
QString ifName("eth1");
- runDHCPCD(list);
-
+ runDHCPCD(ifName);
- setWindowTitle(tr("NetD"));
}
LogReceiver::~LogReceiver() {
@@ -166,6 +151,36 @@ QList<QNetworkInterface> 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<QNetworkConfiguration> 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();
+ }
+*/
+
+ //}
qDebug() << nI.humanReadableName();
result.append(nI);
interfacesMap.insert(i, nI);
@@ -199,6 +214,67 @@ void LogReceiver::runDHCPCD(QString interface) {
dhcpcdArguments.removeLast();
}
+void LogReceiver::checkCarrierState(QList<QNetworkInterface> &interfaces) {
+ foreach(QNetworkInterface nI, interfaces) {
+ if(checkCarrierState(nI.humanReadableName())) {
+ // everything is fine, cable is plugged,
+ // go on with the next interface
+ continue;
+ }
+ else {
+ // cable is unplugged,
+ // remove interface out of the list,
+ // remove interface out ot the index maps
+ int i = indexToIfaceNameMap.value(nI.humanReadableName());
+ indexToIfaceNameMap.remove(nI.humanReadableName());
+ interfacesMap.remove(i);
+ interfaces.removeAt(i);
+ }
+ }
+}
+
+bool LogReceiver::checkCarrierState(QString interface) {
+
+ qDebug() << "check carrier state for interface " << interface;
+ QByteArray ba = interface.toAscii();
+ const char * iface = ba.data();
+
+ struct sysfs_class_device *class_device = sysfs_open_class_device("net",
+ iface);
+ struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
+ if (attrlist != NULL) {
+ struct sysfs_attribute *attr = NULL;
+ dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
+ if (strcmp("carrier", attr->name) == 0) {
+ QString value(attr->value);
+ bool ok = false;
+ bool * pok = &ok;
+ int v = value.toInt(pok);
+ if (*pok) {
+ if (v == 1) {
+ qDebug()
+ << "carrier is 1. Cable is plugged. return true";
+ return true;
+ } else {
+ qDebug()
+ << "carrier is 0. Cable is unplugged. return false";
+ return false;
+ }
+ } else {
+ qDebug() << "conversion error";
+ }
+ }
+ }
+ } else {
+ qDebug() << "attrlist is Null";
+ }
+ sysfs_close_class_device(class_device);
+
+ return true;
+}
+
+
+
void LogReceiver::handleProcessFinished(int exitCode,
QProcess::ExitStatus exitStatus) {
@@ -224,59 +300,7 @@ void LogReceiver::handleProcessStarted() {
qDebug() << "process started: ";
}
-void LogReceiver::buildGui() {
-
- ndStatusLabel = new QLabel(tr("test"));
- ndStatusLabel->setSizePolicy(QSizePolicy::Expanding,
- QSizePolicy::Expanding);
- ndStatusLabel->setAlignment(Qt::AlignCenter);
- ndStatusLabel->setMinimumSize(100, 20);
-
- // create interface group box
- createInterfaceGroupBox();
-
- mainLayout = new QVBoxLayout;
- mainLayout->addWidget(ndStatusLabel);
- mainLayout->addWidget(interfaceGroupBox);
-
- setLayout(mainLayout);
-}
-
-void LogReceiver::createInterfaceGroupBox(){
- interfaceGroupBox = new QGroupBox(tr("Interfaces"));
-
- interfaceGroupBoxLayout = new QVBoxLayout;
- /* add interfaces via addInterfacesToGroupBox()*/
-
- interfaceGroupBox->setLayout(interfaceGroupBoxLayout);
-}
-
-void LogReceiver::addInterfacesToGroupBox(QMap<int , QNetworkInterface> &interfaces) {
- for(int i = 0; i < interfaces.size(); i++) {
- QHBoxLayout *hBoxLayout = new QHBoxLayout;
- QLabel *label = new QLabel(interfaces.value(i).humanReadableName());
- QProgressBar *pBar = new QProgressBar(this);
- pBar->setRange(1,100);
- pBar->setMaximumSize(200,20);
-
- progressBars.insert(i,pBar);
-
- hBoxLayout->addWidget(label, Qt::AlignLeft);
- hBoxLayout->addWidget(pBar, Qt::AlignRight);
-
- interfaceGroupBoxLayout->addLayout(hBoxLayout,2);
- }
-}
-void LogReceiver::handleProgress(int iFaceIndex, int newValue) {
- QProgressBar * pBar = progressBars.value(iFaceIndex);
- if(newValue >= pBar->value()) {
- pBar->setValue(newValue);
- }
- else {
- qDebug() << "Error: new value is smaller than the old value!";
- }
-}
bool LogReceiver::checkBlackList(QString i) {
if (i.startsWith("v", Qt::CaseInsensitive)) {