summaryrefslogtreecommitdiffstats
path: root/LogReceiver/networkdiscovery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LogReceiver/networkdiscovery.cpp')
-rw-r--r--LogReceiver/networkdiscovery.cpp163
1 files changed, 133 insertions, 30 deletions
diff --git a/LogReceiver/networkdiscovery.cpp b/LogReceiver/networkdiscovery.cpp
index ee0b5ad..052663f 100644
--- a/LogReceiver/networkdiscovery.cpp
+++ b/LogReceiver/networkdiscovery.cpp
@@ -11,14 +11,18 @@ NetworkDiscovery::~NetworkDiscovery() {
}
-void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice,QString serverPath, QString pathToExe,
+void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp, QString pathToLogFile, QString serverPath, QString pathToExe,
QStringList* args) {
_serverIp = serverIp;
_userChoice = userChoice;
- _blocked = false;
+ _autoUp = autoUp;
+ _pathToLogFile = pathToLogFile;
+
_pathToDhcpcdExe = pathToExe;
+ _blocked = false;
_numberOfProcesses = 0;
+ _ifUpCountdown = 10;
if (serverPath != DEFAULT_QTSOCKETADDRESS) {
_dhcpcdArguments.append("-q");
@@ -48,6 +52,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice,QString serv
}
connect(_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
+ connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun()));
// check if the path to the customdhcpcd file is correct
@@ -69,24 +74,90 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice,QString serv
// start the main work:
- QList<QString> list = getListOfNetworkInterfaces();
+ // if autoup enabled
+ // emit ... up
+ // else get list uped ifs (einmal simpel ohne autoup)
+ // emit run
- if (list.size() > 0) {
+ if (_autoUp) {
+ getListOfNetworkInterfacesWithAutoUp();
+ _timer = new QTimer(this);
+ connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
+ _timer->start(1000);
- //list = checkCarrierState(list);
+ } else {
+ getListOfNetworkInterfaces();
+ emit readyForRun();
+ }
+}
- //dhcpcdArguments.append("-d");
- _numberOfProcesses = list.size();
- runDHCPCD(list);
+void NetworkDiscovery::slotReadyForRun() {
+ if (_ifUpList.size() > 0) {
+ foreach(QString i, _ifUpList) {
+ emit addInterface(i);
+ }
+ _numberOfProcesses = _ifUpList.size();
+ runDHCPCD( _ifUpList);
} else {
qDebug() << "list is empty. Have not found usable interface.";
- emit abortBoot("Haven not found usable interface");
+ emit
+ abortBoot("Have not found usable interface");
return;
}
+}
+
+void NetworkDiscovery::checkForIsRunning() {
+ bool isRunning = false;
+ QList<QString> copyOfIfDownList(_ifDownList);
+ foreach(QString i, _ifDownList) {
+ QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(i);
+ isRunning = (networkInterface.flags() & QNetworkInterface::IsRunning);
+ if (isRunning) {
+ _ifUpList.append(i);
+ _ifDownList.removeAt(_ifDownList.indexOf(i));
+ }
+ }
+ _ifUpCountdown--;
+ if ((_ifUpCountdown <= 0 ) || _ifDownList.isEmpty()) {
+ // shut down timer
+ _timer->stop();
+ emit readyForRun();
+ }
+ /*
+ for (int ii = 0; ii < copyOfIfDownList.size(); ii++) {
+ QNetworkInterface networkInterface =
+ QNetworkInterface::interfaceFromName(_ifDownList.value(ii));
+ isRunning = (networkInterface.flags() & QNetworkInterface::IsRunning);
+ if (isRunning) {
+ _ifUpList.append(_ifDownList.value(ii));
+ _ifDownList.removeAt(ii);
+ }
+ }
+ */
}
+// autoup mit qtimer
+
+/*
+ if(!(nI.flags() & QNetworkInterface::IsRunning)) {
+ continue;
+ }
+
+// if(!checkForIsRunning(nI)) {
+// qDebug() << "--- still down";
+// continue;
+// }
+ /*
+ if (!checkCarrierState(nI.humanReadableName())) {
+ continue;
+ }
+ */
+
+
+
+
int NetworkDiscovery::replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss) {
_networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET);
}
@@ -138,7 +209,27 @@ QString NetworkDiscovery::getGatewayForInterface(QString ifName) {
return ifConf->getGateway();
}
-QList<QString> NetworkDiscovery::getListOfNetworkInterfaces() {
+QString NetworkDiscovery::readLogFile() {
+ // path to log file is in _pathToLogFile. initialized in initAndRun().
+ QString retval("the log file");
+ QFile logFile(_pathToLogFile);
+ if (logFile.exists()) {
+ if (logFile.open(QIODevice::ReadOnly | QIODevice::Text));
+ return retval;
+ }
+ while (!logFile.atEnd()) {
+ retval.append(logFile.readLine());
+ }
+ return retval;
+}
+
+/**
+ * ================================================================================
+ ********************************* Private Methods ********************************
+ * ================================================================================
+ **/
+
+QList<QString> NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
QList<QString> result;
@@ -151,19 +242,17 @@ QList<QString> NetworkDiscovery::getListOfNetworkInterfaces() {
|| checkBlackList(nI.humanReadableName())) {
continue;
}
- if(!(nI.flags() & QNetworkInterface::IsUp)) {
- _networkManager.bringInterfaceUP(nI.humanReadableName());
- }
- /*
- * if(!checkForIsRunning(nI)) {
- continue;
+ if ((nI.flags() & QNetworkInterface::IsRunning)) {
+ _ifUpList.append(nI.humanReadableName());
+ _ifMap.insert(nI.humanReadableName(), true);
}
- */
- if (!checkCarrierState(nI.humanReadableName())) {
- continue;
+ else if (!(nI.flags() & QNetworkInterface::IsUp)) {
+ _networkManager.bringInterfaceUP(nI.humanReadableName());
+ qDebug() << "--- bring up ..";
+ _ifDownList.append(nI.humanReadableName());
+ _ifMap.insert(nI.humanReadableName(), false);
}
result.append(nI.humanReadableName());
- emit addInterface(nI.humanReadableName());
}
} else {
qDebug() << "no interfaces found!";
@@ -171,18 +260,32 @@ QList<QString> NetworkDiscovery::getListOfNetworkInterfaces() {
return result;
}
-bool NetworkDiscovery::checkForIsRunning(QNetworkInterface networkInterface) {
- bool retval = false;
- for (int i = 0; i < 4; i++) {
- retval = (networkInterface.flags() & QNetworkInterface::IsRunning);
- if(retval) {
- return retval;
- }
- sleep(1);
+QList<QString> NetworkDiscovery::getListOfNetworkInterfaces() {
+ QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
+ QList<QString> result;
+
+ if (nIList.size() > 0) {
+ foreach(QNetworkInterface nI, nIList)
+ {
+ if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
+ || nI.flags() & QNetworkInterface::IsLoopBack)
+ || nI.flags() & QNetworkInterface::IsPointToPoint)
+ || !(nI.flags() & QNetworkInterface::IsUp)
+ || !(nI.flags() & QNetworkInterface::IsRunning)
+ || checkBlackList(nI.humanReadableName())) {
+ continue;
+ }
+ _ifUpList.append(nI.humanReadableName());
+ _ifMap.insert(nI.humanReadableName(), true);
+ result.append(nI.humanReadableName());
+ }
+ } else {
+ qDebug() << "no interfaces found!";
}
- return retval;
+ return result;
}
+
QList<QString> NetworkDiscovery::checkCarrierState(QList<QString> &interfaces) {
QList<QString> result;
foreach(QString nI, interfaces)
@@ -264,7 +367,7 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
int metric = 0;
// get gateway address
- QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION);
+ QString pathToGatewayFile(DEFAULT_INTERFACE_CONF_LOCATION);
pathToGatewayFile += ifName;
interfaceconfiguration *ifConf = new interfaceconfiguration();
ifConf->readConfigOutOfFile(pathToGatewayFile);