summaryrefslogtreecommitdiffstats
path: root/src/fbgui
diff options
context:
space:
mode:
authorSebastian Schmelzer2011-12-03 13:31:09 +0100
committerSebastian Schmelzer2011-12-03 13:31:09 +0100
commit1b48532c662470f5dd4090d47e1e2c333e967caf (patch)
tree8c23d3eca5fa088b91887d528138b9e0462382fb /src/fbgui
parentlet cmake find qxt (diff)
downloadfbgui-1b48532c662470f5dd4090d47e1e2c333e967caf.tar.gz
fbgui-1b48532c662470f5dd4090d47e1e2c333e967caf.tar.xz
fbgui-1b48532c662470f5dd4090d47e1e2c333e967caf.zip
codeformating, change to log4cxx
Diffstat (limited to 'src/fbgui')
-rw-r--r--src/fbgui/downloadmanager.cpp74
-rw-r--r--src/fbgui/downloadmanager.h79
-rw-r--r--src/fbgui/fbgui.cpp99
-rw-r--r--src/fbgui/fbgui.h135
-rw-r--r--src/fbgui/fbgui.pro50
-rw-r--r--src/fbgui/interfaceconfiguration.h73
-rw-r--r--src/fbgui/javascriptinterface.cpp21
-rw-r--r--src/fbgui/javascriptinterface.h75
-rw-r--r--src/fbgui/loggerengine.cpp116
-rw-r--r--src/fbgui/loggerengine.h69
-rw-r--r--src/fbgui/main.cpp51
-rw-r--r--src/fbgui/ndgui.cpp50
-rw-r--r--src/fbgui/ndgui.h104
-rw-r--r--src/fbgui/networkdiscovery.cpp147
-rw-r--r--src/fbgui/networkdiscovery.h164
-rw-r--r--src/fbgui/networkmanager.cpp979
-rw-r--r--src/fbgui/networkmanager.h53
-rw-r--r--src/fbgui/qlog4cxx.h25
-rw-r--r--src/fbgui/sysinfo.cpp36
-rw-r--r--src/fbgui/sysinfo.h21
20 files changed, 1151 insertions, 1270 deletions
diff --git a/src/fbgui/downloadmanager.cpp b/src/fbgui/downloadmanager.cpp
index 653bc7b..79b51fc 100644
--- a/src/fbgui/downloadmanager.cpp
+++ b/src/fbgui/downloadmanager.cpp
@@ -1,5 +1,14 @@
#include "downloadmanager.h"
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr dmLogger(Logger::getLogger("fbgui.dm"));
+
+
// static counter to save the number of successfully downloaded files.
int DownloadManager::_downloaded = 0;
// -------------------------------------------------------------------------------------------------------
@@ -13,7 +22,7 @@ int DownloadManager::_downloaded = 0;
// Lastly the given download directory's existance is checked. (see below)
DownloadManager::DownloadManager() {
- qxtLog->debug() << "Initializing download manager...";
+ LOG4CXX_DEBUG(dmLogger, "Initializing download manager...");
checkDownloadDirectory();
_qnam = new QNetworkAccessManager();
_qnam->moveToThread(&dmThread);
@@ -28,31 +37,30 @@ void DownloadManager::checkDownloadDirectory() {
// check if downloadPath exists, if not create it.
_downloadDir = QDir(downloadPath);
if (!_downloadDir.exists()) {
- qxtLog->debug() << "[dm] Download directory: " << _downloadDir.path() << " doesn't exist.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download directory: " << _downloadDir.path() << " doesn't exist.");
// try to create the directory
- if (QDir::current().mkdir(downloadPath))
- qxtLog->debug() << "[dm] Created download directory: " << _downloadDir.path();
- else {
- qxtLog->debug() << "[dm] Failed to create directory: " << _downloadDir.path();
+ if (QDir::current().mkdir(downloadPath)){
+ LOG4CXX_DEBUG(dmLogger, "[dm] Created download directory: " << _downloadDir.path());
+ } else {
+ LOG4CXX_DEBUG(dmLogger, "[dm] Failed to create directory: " << _downloadDir.path());
// try to save to /tmp/fbgui
_downloadDir.setPath(QDir::tempPath() + "/fbgui");
if (!_downloadDir.exists()) {
- if (QDir::current().mkdir(QDir::tempPath() + "/fbgui"))
- qxtLog->debug() << "[dm] Successfully created: " << _downloadDir.absolutePath();
- else {
+ if (QDir::current().mkdir(QDir::tempPath() + "/fbgui")) {
+ LOG4CXX_DEBUG(dmLogger, "[dm] Successfully created: " << _downloadDir.absolutePath());
+ } else {
// just in case
- qxtLog->debug() << "[dm] Failed to create: " << _downloadDir.absolutePath();
- qxtLog->debug() << "[dm] Exiting...";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Failed to create: " << _downloadDir.absolutePath());
+ LOG4CXX_DEBUG(dmLogger, "[dm] Exiting...");
exit( EXIT_FAILURE);
}
} else
- qxtLog->debug() << "[dm] " << _downloadDir.absolutePath() << " already exists.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] " << _downloadDir.absolutePath() << " already exists.");
}
} else
- qxtLog->debug() << "[dm] Download directory: " << _downloadDir.absolutePath()
- << " already exists.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download directory: " << _downloadDir.absolutePath() << " already exists.");
- qxtLog->debug() << "[dm] Saving downloads to: " << _downloadDir.absolutePath();
+ LOG4CXX_DEBUG(dmLogger, "[dm] Saving downloads to: " << _downloadDir.absolutePath());
downloadPath = _downloadDir.absolutePath();
}
// -------------------------------------------------------------------------------------------------------
@@ -71,15 +79,14 @@ void DownloadManager::downloadFile(const QUrl& fileUrl) {
// -------------------------------------------------------------------------------------------------------
void DownloadManager::processDownloadRequest(const QUrl& url) {
if (url.isEmpty()) {
- qxtLog->debug() << "[dm] No URL specified for download.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] No URL specified for download.");
return;
}
- qxtLog->debug() << "[dm] Enqueueing: " << url.toString();
+ LOG4CXX_DEBUG(dmLogger, "[dm] Enqueueing: " << url.toString());
_downloadQueue.enqueue(url);
if (_dip) {
// download in progress, return.
- qxtLog->debug() << "[dm] Download in progress! Queued:" << url.toString() << "("
- << _downloadQueue.size() << " in queue)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download in progress! Queued:" << url.toString() << "(" << _downloadQueue.size() << " in queue)");
return;
}
// no running downloads: start next in queue
@@ -90,11 +97,10 @@ void DownloadManager::startNextDownload() {
//QWSServer::instance()->setCursorVisible(false);
if (_downloadQueue.isEmpty()) {
emit downloadQueueEmpty();
- qxtLog->debug() << "[dm] Download manager ready. (1)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download manager ready. (1)");
return;
}
- qxtLog->debug() << "[dm] Starting next download: " << _downloadQueue.head().toString() << " ("
- << _downloadQueue.size() - 1 << " in queue.)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Starting next download: " << _downloadQueue.head().toString() << " (" << _downloadQueue.size() - 1 << " in queue.)");
// dequeue next URL to download.
QUrl url = _downloadQueue.dequeue();
@@ -105,17 +111,16 @@ void DownloadManager::startNextDownload() {
// check if filename exists on target file system
if (_downloadDir.exists(tmp)) {
- qxtLog->debug() << "[dm] File already exists: " << _downloadDir.absoluteFilePath(tmp);
+ LOG4CXX_DEBUG(dmLogger, "[dm] File already exists: " << _downloadDir.absoluteFilePath(tmp));
_outfile.setFileName(
QString(_downloadDir.absolutePath() + "/" + tmp + ".\%1").arg(_downloaded));
} else
_outfile.setFileName(_downloadDir.absoluteFilePath(tmp));
- qxtLog->debug() << "[dm] Saving to: " << _outfile.fileName();
+ LOG4CXX_DEBUG(dmLogger, "[dm] Saving to: " << _outfile.fileName());
// try to open for writing
if (!_outfile.open(QIODevice::WriteOnly)) {
- qxtLog->debug() << "[dm] No write access to " << _outfile.fileName()
- << " . Skipping download...";
+ LOG4CXX_DEBUG(dmLogger, "[dm] No write access to " << _outfile.fileName() << " . Skipping download...");
return;
}
@@ -143,8 +148,7 @@ void DownloadManager::processMetaInfo() {
const QByteArray cltag = "Content-Length";
QByteArray clinfo = _currentDownload->rawHeader(cltag);
QFileInfo fi(_outfile);
- qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble()
- << ")";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble() << ")");
emit downloadInfo(fi.fileName(), clinfo.toDouble());
}
// -------------------------------------------------------------------------------------------------------
@@ -155,8 +159,7 @@ void DownloadManager::downloadReady() {
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) {
if (bytesIn > bytesTotal || bytesTotal <= 0) {
- qxtLog->debug() << "[dm] downloadProgress invalid values:" << "In:" << bytesIn
- << " / Total: " << bytesTotal;
+ LOG4CXX_DEBUG(dmLogger, "[dm] downloadProgress invalid values:" << "In:" << bytesIn << " / Total: " << bytesTotal);
return;
}
// calculate current speed
@@ -177,8 +180,7 @@ void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) {
_lastProgress = _currentProgress;
emit
updateProgress(_currentProgress, speed, unit);
- qxtLog->debug() << "[dm] Download progress of " << _currentDownload->url().toString() << ": "
- << bytesIn << "/" << bytesTotal << "(" << _currentProgress << "\%)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download progress of " << _currentDownload->url().toString() << ": " << bytesIn << "/" << bytesTotal << "(" << _currentProgress << "\%)");
}
}
// -------------------------------------------------------------------------------------------------------
@@ -189,8 +191,7 @@ void DownloadManager::downloadFinished() {
_outfile.remove();
int statusCode =
_currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- qxtLog->debug() << "[dm] Download of " << _currentDownload->url().toString()
- << " failed with HTTP error code: " << statusCode;
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download of " << _currentDownload->url().toString() << " failed with HTTP error code: " << statusCode);
emit
notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode));
_currentDownload->deleteLater();
@@ -198,8 +199,7 @@ void DownloadManager::downloadFinished() {
// end download
_outfile.close();
_downloaded++;
- qxtLog->debug() << "[dm] Download of " << _currentDownload->url().toString()
- << " finished. (downloaded = " << _downloaded << ")";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download of " << _currentDownload->url().toString() << " finished. (downloaded = " << _downloaded << ")");
emit
notify(QString("Successfully downloaded %1").arg(_currentDownload->url().toString()));
_currentDownload->deleteLater();
@@ -208,7 +208,7 @@ void DownloadManager::downloadFinished() {
// process next in queue, if any
if (_downloadQueue.isEmpty()) {
emit downloadQueueEmpty();
- qxtLog->debug() << "[dm] Download manager ready. (2)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download manager ready. (2)");
return;
}
startNextDownload();
diff --git a/src/fbgui/downloadmanager.h b/src/fbgui/downloadmanager.h
index 62df4bc..044d841 100644
--- a/src/fbgui/downloadmanager.h
+++ b/src/fbgui/downloadmanager.h
@@ -29,56 +29,57 @@ extern QString binPath;
extern QString downloadPath;
extern int updateInterval;
-class DownloadManager: public QObject {
-Q_OBJECT
+class DownloadManager: public QObject
+{
+ Q_OBJECT
public:
- DownloadManager();
- ~DownloadManager();
- QTime time;
+ DownloadManager();
+ ~DownloadManager();
+ QTime time;
private:
- // checks for valid download directory, ran once in constructor
- void checkDownloadDirectory();
- // private control function for queueing mechanism.
- void processDownloadRequest(const QUrl& url);
+ // checks for valid download directory, ran once in constructor
+ void checkDownloadDirectory();
+ // private control function for queueing mechanism.
+ void processDownloadRequest(const QUrl& url);
- // base objects for downloading
- QNetworkAccessManager* _qnam;
- QQueue<QUrl> _downloadQueue;
- QNetworkReply* _currentDownload;
- QFile _outfile;
- QDir _downloadDir;
- // download progress variables
- int _currentProgress, _lastProgress;
- // download in progress flag
- bool _dip;
- // static counter
- static int _downloaded;
+ // base objects for downloading
+ QNetworkAccessManager* _qnam;
+ QQueue<QUrl> _downloadQueue;
+ QNetworkReply* _currentDownload;
+ QFile _outfile;
+ QDir _downloadDir;
+ // download progress variables
+ int _currentProgress, _lastProgress;
+ // download in progress flag
+ bool _dip;
+ // static counter
+ static int _downloaded;
signals:
- // notify sends a message to the javascript interface to be evaluated there
- void notify(const QString& msg);
- // downloadInfo sends static information (name, size) to the interface.
- void downloadInfo(const QString& filename, const double& filesize);
- // updateProgress sends download progress information to the interface.
- void updateProgress(const int& percent, const double& speed, const QString& unit);
- // signal emitted when download queue is empty.
- void downloadQueueEmpty();
+ // notify sends a message to the javascript interface to be evaluated there
+ void notify(const QString& msg);
+ // downloadInfo sends static information (name, size) to the interface.
+ void downloadInfo(const QString& filename, const double& filesize);
+ // updateProgress sends download progress information to the interface.
+ void updateProgress(const int& percent, const double& speed, const QString& unit);
+ // signal emitted when download queue is empty.
+ void downloadQueueEmpty();
public slots:
- // public slots to receive download requests.
- void downloadFile(const QUrl& fileUrl);
- // convenience function
- void downloadFile(const QString& fileUrl);
+ // public slots to receive download requests.
+ void downloadFile(const QUrl& fileUrl);
+ // convenience function
+ void downloadFile(const QString& fileUrl);
private slots:
- // private slots to manage the downloading process
- void startNextDownload();
- void processMetaInfo();
- void downloadReady();
- void downloadProgress(qint64 bytesIn, qint64 bytesTotal);
- void downloadFinished();
+ // private slots to manage the downloading process
+ void startNextDownload();
+ void processMetaInfo();
+ void downloadReady();
+ void downloadProgress(qint64 bytesIn, qint64 bytesTotal);
+ void downloadFinished();
};
#endif // DOWNLOADMANAGER_H
diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp
index 437568e..85a0660 100644
--- a/src/fbgui/fbgui.cpp
+++ b/src/fbgui/fbgui.cpp
@@ -1,9 +1,17 @@
#include "fbgui.h"
#include "sysinfo.h"
-#include "loggerengine.h"
#include "downloadmanager.h"
#include "javascriptinterface.h"
+
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr coreLogger(Logger::getLogger("fbgui.core"));
+
+
#include <iostream>
#include <QThread>
#include <QtWebKit>
@@ -45,7 +53,7 @@ fbgui::~fbgui() {
*/
void fbgui::init() {
// start fbgui
- qxtLog->debug() << "Initializing fbgui...";
+ LOG4CXX_DEBUG(coreLogger, "Initializing fbgui...");
setupLayout();
createActions();
@@ -150,23 +158,22 @@ void fbgui::watchForTrigger() {
// check if fileToTriggerURL already exists
QFile file(fileToTriggerURL);
if (file.exists()) {
- qxtLog->debug() << "[watcher] " << fileToTriggerURL << " found.";
+ LOG4CXX_DEBUG(coreLogger, "[watcher] " << fileToTriggerURL << " found.");
// try to load URL
loadURL();
} else {
// create it
if (file.open(QIODevice::WriteOnly)) {
- qxtLog->debug() << "[gui] Created: " << fileToTriggerURL;
+ LOG4CXX_DEBUG(coreLogger, "[gui] Created: " << fileToTriggerURL);
file.close();
} else {
- qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL
- << " failed!";
- qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Creation of " << fileToTriggerURL << " failed!");
+ LOG4CXX_DEBUG(coreLogger, "[gui] Exiting in 5 seconds...");
QTimer::singleShot(5000, this, SLOT(close()));
}
}
// watch the path to trigger file
- qxtLog->debug() << "[watcher] Watching " << fileToTriggerURL;
+ LOG4CXX_DEBUG(coreLogger, "[watcher] Watching " << fileToTriggerURL);
_watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this);
QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepareURLLoad()));
@@ -183,9 +190,9 @@ QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepa
* @see fbgui::loadURL()
*/
void fbgui::prepareURLLoad() {
- qxtLog->debug() << "[watcher] " << fileToTriggerURL << " changed!";
+ LOG4CXX_DEBUG(coreLogger, "[watcher] " << fileToTriggerURL << " changed!");
// disconnect _watcher, his job is done
- qxtLog->debug() << "[watcher] disconnected.";
+ LOG4CXX_DEBUG(coreLogger, "[watcher] disconnected.");
_watcher->disconnect(this);
_watcher->deleteLater();
// try to load URL
@@ -203,11 +210,11 @@ void fbgui::prepareURLLoad() {
bool fbgui::checkHost() const {
QHostInfo hostInfo = QHostInfo::fromName(baseURL.host());
if (hostInfo.error() != QHostInfo::NoError) {
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed.";
- qxtLog->debug() << "[gui] Host can not be reached.";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Lookup of " << baseURL.host() << "failed.");
+ LOG4CXX_DEBUG(coreLogger, "[gui] Host can not be reached.");
return false;
} else {
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded.";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Lookup of " << baseURL.host() << " succeeded.");
return true;
}
}
@@ -224,7 +231,7 @@ bool fbgui::checkHost() const {
*/
void fbgui::loadURL() {
if (checkHost()) {
- qxtLog->debug() << "[gui] Loading URL: " << baseURL.toString() << " ...";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Loading URL: " << baseURL.toString() << " ...");
// Generate POST identification data needed by PBS.
QByteArray postData = generatePOSTData();
@@ -240,12 +247,11 @@ void fbgui::loadURL() {
void fbgui::loadURLDone(bool success) {
// done contains the success of the loading: false / true
if (!success) {
- qxtLog->debug() << "[gui] Loading failed. URL: "
- << _webView->url().toString();
- qxtLog->debug() << "[gui] You can quit with CTRL + X ...";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Loading failed. URL: " << _webView->url().toString());
+ LOG4CXX_DEBUG(coreLogger, "[gui] You can quit with CTRL + X ...");
// TODO handle failure properly...
} else {
- qxtLog->debug() << "[gui] Loaded URL: " << _webView->url().toString();
+ LOG4CXX_DEBUG(coreLogger, "[gui] Loaded URL: " << _webView->url().toString());
}
}
//-------------------------------------------------------------------------------------------
@@ -264,7 +270,7 @@ void fbgui::loadURLDone(bool success) {
* @see SysInfo::getMainboardSerial()
*/
QByteArray fbgui::generatePOSTData() {
- qxtLog->debug() << "[gui] Generating POST data...";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Generating POST data...");
// use MAC address as base data
SysInfo si;
QByteArray data(si.getInfo("mac").toUtf8());
@@ -273,32 +279,31 @@ QByteArray fbgui::generatePOSTData() {
if (!mbserial.isEmpty())
data.append(mbserial);
else {
- qxtLog->debug()
- << "[gui] Mainboard serial was empty. Not appending to base hash data.";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Mainboard serial was empty. Not appending to base hash data.");
}
- qxtLog->debug() << "[post] Hashing: " << data;
+ LOG4CXX_DEBUG(coreLogger, "[post] Hashing: " << data);
// generate MD5 hash of data
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
- qxtLog->debug() << "[post] MD5 Hash: " << hash.toHex();
+ LOG4CXX_DEBUG(coreLogger, "[post] MD5 Hash: " << hash.toHex());
// fetch serial number from usb
QByteArray serial;
QFile file(serialLocation);
if (!file.open(QIODevice::ReadOnly)) {
- qxtLog->debug() << "[post] No such file: " << file.fileName();
+ LOG4CXX_DEBUG(coreLogger, "[post] No such file: " << file.fileName());
}
// everything ok, read data
serial = file.readAll();
file.close();
serial.chop(1); // chop EOF
- qxtLog->debug() << "[post] Serial number is: " << serial;
+ LOG4CXX_DEBUG(coreLogger, "[post] Serial number is: " << serial);
// construct final byte array
QByteArray postData("mac=");
postData.append(si.getInfo("mac"));
postData.append("&hardwarehash=" + hash.toHex());
postData.append("&serialnumber=" + serial);
- qxtLog->debug() << "[post] POST data: " << postData;
+ LOG4CXX_DEBUG(coreLogger, "[post] POST data: " << postData);
return postData;
}
@@ -326,7 +331,7 @@ void fbgui::performShutDown() {
file.write("o");
file.close();
} else {
- qxtLog->debug() << "[gui] Could not open /proc/sysrq-trigger";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Could not open /proc/sysrq-trigger");
}
}
//-------------------------------------------------------------------------------------------
@@ -349,7 +354,7 @@ void fbgui::performReboot() {
file.write("b");
file.close();
} else {
- qxtLog->debug() << "[gui] Could not open /proc/sysrq-trigger";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Could not open /proc/sysrq-trigger");
}
}
//-------------------------------------------------------------------------------------------
@@ -379,54 +384,52 @@ void fbgui::loadSystem() {
*/
void fbgui::prepareKexec() {
- qxtLog->debug() << "[gui] Preparing kexec ...";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Preparing kexec ...");
// try to read KCL file that was downloaded.
QFile file(downloadPath + "/kcl");
if (!file.open(QIODevice::ReadOnly)) {
- qxtLog->debug() << "[gui] No such file: " << file.fileName();
+ LOG4CXX_DEBUG(coreLogger, "[gui] No such file: " << file.fileName());
}
// everything ok, read data.
QString kcl = file.readAll();
file.close();
- qxtLog->debug() << "[gui] KCL from PBS: " << kcl;
+ LOG4CXX_DEBUG(coreLogger, "[gui] KCL from PBS: " << kcl);
// try to read ipconfig file generated by udhcpc.
file.setFileName("/tmp/ip_config_fbgui");
if (!file.open(QIODevice::ReadOnly)) {
- qxtLog->debug() << "[gui] No such file: " << file.fileName();
+ LOG4CXX_DEBUG(coreLogger, "[gui] No such file: " << file.fileName());
}
// everything ok, read data.
QString ipConfig = file.readAll();
file.close();
- qxtLog->debug() << "[gui] IP config: " << ipConfig;
+ LOG4CXX_DEBUG(coreLogger, "[gui] IP config: " << ipConfig);
// append ipConfig
kcl.append(" ip=");
kcl.append(ipConfig);
- qxtLog->debug() << "[gui] Complete KCL: " << kcl;
+ LOG4CXX_DEBUG(coreLogger, "[gui] Complete KCL: " << kcl);
// load the kernel + initramfs + append of kcl into kexec.
QProcess *process = new QProcess(this);
QString cmdline = "kexec -l " + downloadPath.toUtf8() + "/kernel --initrd="
+ downloadPath.toUtf8() + "/initramfs --append=\"" + kcl.toUtf8()
+ "\"";
- qxtLog->debug() << "[gui] kexec cmdline: " << cmdline;
+ LOG4CXX_DEBUG(coreLogger, "[gui] kexec cmdline: " << cmdline);
process->start(cmdline);
bool ret = process->waitForFinished();
if (!ret) {
- qxtLog->debug() << "[gui] Failed to execute: " << cmdline;
- qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Failed to execute: " << cmdline);
+ LOG4CXX_DEBUG(coreLogger, "[gui] Exiting in 5 seconds...");
QTimer::singleShot(5000, this, SLOT(close()));
} else {
- qxtLog->debug() << "[gui] Kexec load was successfull.";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Kexec load was successfull.");
if (debugMode < 0) {
// if process successfully finished, try to run kexec -e
runKexec();
} else {
- qxtLog->debug()
- << "[gui] Skipping execution of kexec - open debug shell.";
- qxtLog->debug()
- << "[gui] To start the system execute \"kexec -e\" in your shell.";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Skipping execution of kexec - open debug shell.");
+ LOG4CXX_DEBUG(coreLogger, "[gui] To start the system execute \"kexec -e\" in your shell.");
close();
}
}
@@ -442,8 +445,8 @@ void fbgui::runKexec() {
QProcess *process = new QProcess(this);
process->start("kexec -e");
if (!process->waitForStarted()) {
- qxtLog->debug() << "[gui] Failed to execute: kexec -e";
- qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ LOG4CXX_DEBUG(coreLogger, "[gui] Failed to execute: kexec -e");
+ LOG4CXX_DEBUG(coreLogger, "[gui] Exiting in 5 seconds...");
QTimer::singleShot(5000, this, SLOT(close()));
//TODO: Handle failure properly...
}
@@ -468,10 +471,10 @@ void fbgui::createDebugConsole() {
pal.setColor(QPalette::Base, Qt::black);
_debugConsole->setPalette(pal);
_debugConsole->setTextColor(Qt::white);
- // enable custom logger engine
- qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole));
- //qxtLog->initLoggerEngine("fb_logger");
- qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel);
+ // enable custom coreLogger engine
+// qxtLog->addLoggerEngine("fb_coreLogger", new LoggerEngine_fb(_debugConsole));
+ //qxtLog->initLoggerEngine("fb_coreLogger");
+// qxtLog->setMinimumLevel("fb_coreLogger", QxtLogger::DebugLevel);
// CTRL + D toggles debug window
_toggleDebugConsole = new QAction(tr("&toggleDebug"), this);
_toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
diff --git a/src/fbgui/fbgui.h b/src/fbgui/fbgui.h
index ee42469..7843741 100644
--- a/src/fbgui/fbgui.h
+++ b/src/fbgui/fbgui.h
@@ -46,81 +46,82 @@ extern QUrl baseURL;
extern int debugMode;
extern int updateInterval;
-class fbgui: public QMainWindow {
-Q_OBJECT
+class fbgui: public QMainWindow
+{
+ Q_OBJECT
public:
- fbgui();
- ~fbgui();
+ fbgui();
+ ~fbgui();
public slots:
- void init();
+ void init();
private:
- //-------------------
- // layout setup:
- //-------------------
- // Sets the layout depending on the debug mode:
- // no debug or debugMode = 0 -> only browser shown.
- // debugMode = 1 -> split main window in browser and debug console.
- void setupLayout();
- // Create all actions for the GUI. (Currently only quit.)
- void createActions();
- // Create a debug console widget as QTextEdit in order to print debug messages
- // directly within the GUI. This was needed since ttys can't really be used
- // for debugging purposes in the preboot environment.
- void createDebugConsole();
-
- //----------------------------------------
- // control the display of components:
- //----------------------------------------
- // watches for the file triggering the loading of the URL.
- // the file can be specified by the corresponding option.
- void watchForTrigger();
- bool checkHost() const;
- void loadURL();
- QByteArray generatePOSTData();
-
- //----------------------------------
- // widgets constituing the gui:
- //----------------------------------
- // QWebView for displaying internet content
- QWebView* _webView;
- // QSplitter to split the main window in two resizable frames.
- QSplitter* _splitter;
- // QTextEdit implementing a minimalistic debug console.
- QTextEdit* _debugConsole;
-
- //------------------
- // action list:
- //------------------
- // closes the main window provoking the application to quit.
- QAction* _quit;
- // triggers toggleDebugConsole()
- QAction* _toggleDebugConsole;
-
- // watcher to detect changes in the observed directory.
- QFileSystemWatcher* _watcher;
+ //-------------------
+ // layout setup:
+ //-------------------
+ // Sets the layout depending on the debug mode:
+ // no debug or debugMode = 0 -> only browser shown.
+ // debugMode = 1 -> split main window in browser and debug console.
+ void setupLayout();
+ // Create all actions for the GUI. (Currently only quit.)
+ void createActions();
+ // Create a debug console widget as QTextEdit in order to print debug messages
+ // directly within the GUI. This was needed since ttys can't really be used
+ // for debugging purposes in the preboot environment.
+ void createDebugConsole();
+
+ //----------------------------------------
+ // control the display of components:
+ //----------------------------------------
+ // watches for the file triggering the loading of the URL.
+ // the file can be specified by the corresponding option.
+ void watchForTrigger();
+ bool checkHost() const;
+ void loadURL();
+ QByteArray generatePOSTData();
+
+ //----------------------------------
+ // widgets constituing the gui:
+ //----------------------------------
+ // QWebView for displaying internet content
+ QWebView* _webView;
+ // QSplitter to split the main window in two resizable frames.
+ QSplitter* _splitter;
+ // QTextEdit implementing a minimalistic debug console.
+ QTextEdit* _debugConsole;
+
+ //------------------
+ // action list:
+ //------------------
+ // closes the main window provoking the application to quit.
+ QAction* _quit;
+ // triggers toggleDebugConsole()
+ QAction* _toggleDebugConsole;
+
+ // watcher to detect changes in the observed directory.
+ QFileSystemWatcher* _watcher;
private slots:
- // toggles debug console when action _toggleDebugConsole happens.
- void toggleDebugConsole();
-
- // This function is triggered by fileChanged Signal of _watcher.
- // It deletes _watcher, since we don't need it anymore and tries to load URL.
- void prepareURLLoad();
- void loadURLDone(bool success);
-
- // shut off the system
- void performShutDown();
- // reboot the system
- void performReboot();
- // shows "loading system" page
- void loadSystem();
- // prepares kexec by loading downloaded initramfs, kernel into kexec
- void prepareKexec();
- // executes: kexec -e
- void runKexec();
+ // toggles debug console when action _toggleDebugConsole happens.
+ void toggleDebugConsole();
+
+ // This function is triggered by fileChanged Signal of _watcher.
+ // It deletes _watcher, since we don't need it anymore and tries to load URL.
+ void prepareURLLoad();
+ void loadURLDone(bool success);
+
+ // shut off the system
+ void performShutDown();
+ // reboot the system
+ void performReboot();
+ // shows "loading system" page
+ void loadSystem();
+ // prepares kexec by loading downloaded initramfs, kernel into kexec
+ void prepareKexec();
+ // executes: kexec -e
+ void runKexec();
};
#endif // FBGUI_H
diff --git a/src/fbgui/fbgui.pro b/src/fbgui/fbgui.pro
deleted file mode 100644
index 701402b..0000000
--- a/src/fbgui/fbgui.pro
+++ /dev/null
@@ -1,50 +0,0 @@
-TEMPLATE = app
-TARGET = fbgui
-CONFIG += qt \
- debug
-QT += core \
- gui \
- network \
- webkit
-LIBS += -L/usr/local/qjson/lib \
- -lqjson \
- -L/usr/local/Qxt/lib \
- -lQxtCore \
- -L/usr/lib \
- -lsysfs \
- -lnl \
- -lusb-1.0 \
- -L/usr/local/lib \
- -lcustomdhcpcd
-INCLUDEPATH += /usr/local/qjson/include \
- /usr/local/Qxt/include \
- /usr/local/Qxt/include/QxtCore \
- /usr/include/sysfs \
- /usr/include/libusb-1.0 \
- /usr/include/net \
- /usr/include/netlink \
- /usr/include/netlink/route \
- /usr/include/arpa \
- ./../customdhcpcd/src
-HEADERS += ../common/fbgui.h \
- downloadmanager.h \
- fbgui.h \
- interfaceconfiguration.h \
- javascriptinterface.h \
- loggerengine.h \
- ndgui.h \
- networkdiscovery.h \
- networkmanager.h \
- sysinfo.h
-SOURCES += networkdiscovery.cpp \
- networkmanager.cpp \
- ndgui.cpp \
- interfaceconfiguration.cpp \
- sysinfo.cpp \
- loggerengine.cpp \
- javascriptinterface.cpp \
- downloadmanager.cpp \
- fbgui.cpp \
- main.cpp
-FORMS +=
-RESOURCES += fbgui.qrc
diff --git a/src/fbgui/interfaceconfiguration.h b/src/fbgui/interfaceconfiguration.h
index 475f689..9376fbb 100644
--- a/src/fbgui/interfaceconfiguration.h
+++ b/src/fbgui/interfaceconfiguration.h
@@ -18,49 +18,50 @@
#include <QtCore>
-class interfaceconfiguration: public QObject {
-Q_OBJECT
+class interfaceconfiguration: public QObject
+{
+ Q_OBJECT
public:
- interfaceconfiguration();
- interfaceconfiguration(const interfaceconfiguration &other);
+ interfaceconfiguration();
+ interfaceconfiguration(const interfaceconfiguration &other);
- interfaceconfiguration &operator=(const interfaceconfiguration &other);
- virtual ~interfaceconfiguration();
+ interfaceconfiguration &operator=(const interfaceconfiguration &other);
+ 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();
+ 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 _tag;
+ QString _tag;
- 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;
+ 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/src/fbgui/javascriptinterface.cpp b/src/fbgui/javascriptinterface.cpp
index b45a2f9..9db803a 100644
--- a/src/fbgui/javascriptinterface.cpp
+++ b/src/fbgui/javascriptinterface.cpp
@@ -2,6 +2,15 @@
#include "javascriptinterface.h"
#include "sysinfo.h"
+
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr jsiLogger(Logger::getLogger("fbgui.jsi"));
+
+
//-------------------------------------------------------------------------------------------------------
// Initialisation
//-------------------------------------------------------------------------------------------------------
@@ -12,7 +21,7 @@
* Is of type QWebFrame.
*/
JavascriptInterface::JavascriptInterface(QWebFrame *parent) {
- qxtLog->debug() << "Initializing javascript interface...";
+ LOG4CXX_DEBUG(jsiLogger, "Initializing javascript interface...");
_parent = parent;
}
//-------------------------------------------------------------------------------------------------------
@@ -61,7 +70,7 @@ foreach(fi, fiList)
{
if (fi.suffix() == "js") {
//qDebug()<< fi.fileName();
- //qxtLog->debug() << fi.fileName();
+ //LOG4CXX_DEBUG(jsiLogger, fi.fileName());
if (fi.fileName() != "test.js") {
QFile file;
file.setFileName(pathToJsDir + "/" + fi.fileName());
@@ -70,7 +79,7 @@ foreach(fi, fiList)
file.close();
_parent->evaluateJavaScript(js);
- //qxtLog->debug() << "evaluated " + fi.fileName();
+ //LOG4CXX_DEBUG(jsiLogger, "evaluated " + fi.fileName());
}
}
}
@@ -103,7 +112,7 @@ void JavascriptInterface::startDownload(const QString& filename) {
* @todo add some more informations
*/
void JavascriptInterface::setCallbackOnFinished(const QString& function) {
- qxtLog->debug() << "[jsi] Callback set: " << function;
+ LOG4CXX_DEBUG(jsiLogger, "[jsi] Callback set: " << function);
_callbackOnDownloadsFinished = QString(function);
}
//-------------------------------------------------------------------------------------------------------
@@ -208,7 +217,7 @@ void JavascriptInterface::updateProgressBar(const int& percent,
* on the webpage to receive these.
*/
void JavascriptInterface::notify(const QString& msg) {
- qxtLog->debug() << "[jsi] Notifying: " << msg;
+ LOG4CXX_DEBUG(jsiLogger, "[jsi] Notifying: " << msg);
QString code = QString("notify('\%1')").arg(msg);
_parent->evaluateJavaScript(code);
}
@@ -229,7 +238,7 @@ void JavascriptInterface::trigger() {
QFile file(fileToTriggerURL);
if (file.open(QIODevice::WriteOnly)) {
file.write("data\n");
- qxtLog->debug() << "[jsi] *trigger watcher*";
+ LOG4CXX_DEBUG(jsiLogger, "[jsi] *trigger watcher*");
}
file.close();
}
diff --git a/src/fbgui/javascriptinterface.h b/src/fbgui/javascriptinterface.h
index cf2ec5b..5d45964 100644
--- a/src/fbgui/javascriptinterface.h
+++ b/src/fbgui/javascriptinterface.h
@@ -20,53 +20,54 @@
#include "fbgui.h"
-class JavascriptInterface: public QObject {
-Q_OBJECT
+class JavascriptInterface: public QObject
+{
+ Q_OBJECT
public:
- JavascriptInterface(QWebFrame* parent);
- ~JavascriptInterface();
+ JavascriptInterface(QWebFrame* parent);
+ ~JavascriptInterface();
private:
- // pointer to parent
- QWebFrame* _parent;
- // function to be called withint javascript when downloads are done.
- QString _callbackOnDownloadsFinished;
- // loads jQuery code
- void loadJQuery();
+ // pointer to parent
+ QWebFrame* _parent;
+ // function to be called withint javascript when downloads are done.
+ QString _callbackOnDownloadsFinished;
+ // loads jQuery code
+ void loadJQuery();
- signals:
- // request the file from download manager
- void requestFile(const QString& filename);
- // quit the application
- void quitFbgui();
- // shut off the system. connected to fbgui::performShutDown()
- void shutDownClient();
- // reboot the system. connected to fbgui::performReboot()
- void rebootClient();
+signals:
+ // request the file from download manager
+ void requestFile(const QString& filename);
+ // quit the application
+ void quitFbgui();
+ // shut off the system. connected to fbgui::performShutDown()
+ void shutDownClient();
+ // reboot the system. connected to fbgui::performReboot()
+ void rebootClient();
public slots:
- // make sure the interface stays attached on webpage reload
- void attachToDOM();
+ // make sure the interface stays attached on webpage reload
+ void attachToDOM();
- // slots for calling from the webpage
- void startDownload(const QString& filename);
- void setCallbackOnFinished(const QString& function);
- const QString getSysInfo(const QString& info);
- void quit();
- void shutDown();
- void reboot();
+ // slots for calling from the webpage
+ void startDownload(const QString& filename);
+ void setCallbackOnFinished(const QString& function);
+ const QString getSysInfo(const QString& info);
+ void quit();
+ void shutDown();
+ void reboot();
- // callback when downloads are done.
- void callbackOnFinished();
+ // callback when downloads are done.
+ void callbackOnFinished();
- // slots for information exchange with the download manager.
- void updateProgressBar(const int& percent, const double& speed,
- const QString& unit);
- void downloadInfo(const QString& filename, const double& filesize);
- void notify(const QString& msg);
+ // slots for information exchange with the download manager.
+ void updateProgressBar(const int& percent, const double& speed,
+ const QString& unit);
+ void downloadInfo(const QString& filename, const double& filesize);
+ void notify(const QString& msg);
- // functions to help test functionality
- void trigger();
+ // functions to help test functionality
+ void trigger();
};
#endif // JAVASCRIPTINTERFACE_H_
diff --git a/src/fbgui/loggerengine.cpp b/src/fbgui/loggerengine.cpp
deleted file mode 100644
index 8a0991d..0000000
--- a/src/fbgui/loggerengine.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-#include "loggerengine.h"
-
-// --------------------------------------------------------------------------------------------------
-// base of a custom logger engine for the framebuffer
-//---------------------------------------------------------------------------------------------------
-LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) :
- QxtLoggerEngine() {
- _debugConsole = parent;
- //_initialized = false;
- //setLogLevelsEnabled(QxtLogger::DebugLevel);
- //enableLogging();
-}
-LoggerEngine_fb::~LoggerEngine_fb() {
-}
-
-void LoggerEngine_fb::initLoggerEngine() {
- //_initialized = true;
- return;
-}
-
-void LoggerEngine_fb::killLoggerEngine() {
- return;
-}
-
-void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels, bool) {
- //QxtLoggerEngine::setLogLevelsEnabled(level, enable);
- //if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel);
-}
-bool LoggerEngine_fb::isInitialized() const {
- //return _initialized;
- return true;
-}
-
-void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs) {
-
- // ignore in case no messages was passed.
- if (msgs.isEmpty())
- return;
-
- // write timestamp header in format: [hh:mm:ss.zzz]
- // example: [23:58:99.999]
- QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] ";
- _debugConsole->insertPlainText(header);
-
- // only write to console for debug level
- if (level == QxtLogger::DebugLevel) {
- Q_FOREACH(const QVariant& out, msgs)
- {
- if (!out.isNull())
- _debugConsole->insertPlainText(out.toString());
- }
- _debugConsole->insertPlainText(QString("\n"));
- // autoscroll
- QTextCursor c = _debugConsole->textCursor();
- c.movePosition(QTextCursor::End);
- _debugConsole->setTextCursor(c);
- }
-}
-//---------------------------------------------------------------------------------------------------
-// slighty modified QxtBasicSTDLoggerEngine
-//---------------------------------------------------------------------------------------------------
-LoggerEngine_std::LoggerEngine_std() :
- QxtBasicSTDLoggerEngine() {
-}
-
-LoggerEngine_std::~LoggerEngine_std() {
-}
-
-void LoggerEngine_std::writeToStdErr(const QString&, const QList<QVariant> &msgs) {
-
- if (msgs.isEmpty())
- return;
- QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] ";
- QTextStream* errstream = stdErrStream();
- Q_ASSERT(errstream);
- *errstream << header;
- Q_FOREACH(const QVariant& out, msgs)
- {
- if (!out.isNull())
- *errstream << out.toString();
- }
- *errstream << endl;
-}
-void LoggerEngine_std::writeToStdOut(const QString&, const QList<QVariant> &) {
- // (level, msgs)
- // reimplementing this is needed for compiling,
- // we only need write to std::err, so this function is not needed
-}
-//---------------------------------------------------------------------------------------------------
-// slighty modified QxtBasicFileLoggerEngine
-//---------------------------------------------------------------------------------------------------
-LoggerEngine_file::LoggerEngine_file(const QString& logFileName) :
- QxtBasicFileLoggerEngine(logFileName) {
- //setLogFileName(logFileName);
-}
-
-LoggerEngine_file::~LoggerEngine_file() {
-}
-
-void LoggerEngine_file::initLoggerEngine() {
-}
-
-void LoggerEngine_file::writeToFile(const QString&, const QList<QVariant> &msgs) {
-
- if (msgs.isEmpty())
- return;
- QIODevice* file = device();
- QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] ";
- file->write(header.toUtf8());
- Q_FOREACH(const QVariant& out, msgs)
- {
- if (!out.isNull())
- file->write(out.toString().toUtf8());
- }
- file->write("\n");
-}
diff --git a/src/fbgui/loggerengine.h b/src/fbgui/loggerengine.h
deleted file mode 100644
index 1dfae4e..0000000
--- a/src/fbgui/loggerengine.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2010,2011 - RZ Uni Freiburg
- * Copyright (c) 2010,2011 - OpenSLX Project
- *
- * This program/file is free software distributed under the GPL version 2.
- * See http://openslx.org/COPYING
- *
- * If you have any feedback please consult http://openslx.org/feedback and
- * send your feedback to feedback@openslx.org
- *
- * General information about OpenSLX can be found under http://openslx.org
- *
- *
- * Base for custom logger engines based on QxtLogger libs.
- *
- */
-#ifndef LOGGERENGINE_H_
-#define LOGGERENGINE_H_
-
-#include <QxtCore>
-#include <QTime>
-#include <QTextEdit>
-
-//---------------------------------------------------------------------------------------------------
-// base of a custom logger engine for the framebuffer
-//---------------------------------------------------------------------------------------------------
-class LoggerEngine_fb: public QxtLoggerEngine {
-public:
- LoggerEngine_fb(QTextEdit* parent);
- ~LoggerEngine_fb();
-
- // parent widget, target of messages
- QTextEdit *_debugConsole;
- bool _initialized;
-
- // reimplemented virtual functions of QxtLoggerEngine
- void initLoggerEngine();
- void killLoggerEngine();
- void writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & messages);
- void setLogLevelEnabled(QxtLogger::LogLevels level, bool enable = true);
- bool isInitialized() const;
-
-};
-//---------------------------------------------------------------------------------------------------
-// slighty modified QxtBasicSTDLoggerEngine
-//---------------------------------------------------------------------------------------------------
-class LoggerEngine_std: public QxtBasicSTDLoggerEngine {
-public:
- LoggerEngine_std();
- ~LoggerEngine_std();
-
- // reimplemented virtual functions of QxtBasicSTDLoggerEngine
- void writeToStdOut(const QString& level, const QList<QVariant> &msgs);
- void writeToStdErr(const QString& str_level, const QList<QVariant> &msgs);
-};
-//---------------------------------------------------------------------------------------------------
-// slighty modified QxtBasicFileLoggerEngine
-//---------------------------------------------------------------------------------------------------
-class LoggerEngine_file: public QxtBasicFileLoggerEngine {
-public:
- LoggerEngine_file(const QString& logFileName);
- ~LoggerEngine_file();
- void initLoggerEngine();
-
- // reimplemented virtual functions of QxtBasicFileLoggerEngine
- void writeToFile(const QString& level, const QList<QVariant> &msgs);
-};
-
-#endif // LOGGERENGINE_H_
diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp
index a187d01..d733b43 100644
--- a/src/fbgui/main.cpp
+++ b/src/fbgui/main.cpp
@@ -4,12 +4,19 @@
#include <getopt.h>
#include <cstdlib>
#include <iostream>
-#include "loggerengine.h"
+
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
#include "fbgui.h"
#include "ndgui.h"
#include "../common/fbgui.h"
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr logger(Logger::getLogger("fbgui"));
+
void printHelp() {
QTextStream qout(stdout);
qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl;
@@ -108,11 +115,11 @@ int main(int argc, char *argv[]) {
if (clOpts.contains("debug")) {
debugMode = clOpts.value("debug").toInt();
// start basic debug output on terminal
- qxtLog->disableLoggerEngine("DEFAULT");
- qxtLog->enableLogLevels(QxtLogger::DebugLevel);
- qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std);
- qxtLog->initLoggerEngine("std_logger");
- qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel);
+// qxtLog->disableLoggerEngine("DEFAULT");
+// qxtLog->enableLogLevels(QxtLogger::DebugLevel);
+// qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std);
+// qxtLog->initLoggerEngine("std_logger");
+// qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel);
} else
debugMode = -1;
@@ -230,24 +237,24 @@ int main(int argc, char *argv[]) {
// // activate file logger if debug mode activated.
// if (debugMode > -1) {
// start debug logging to file.
- qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath));
- qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel);
+// qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath));
+// qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel);
// }
// print config
- qxtLog->debug() << "************* CONFIG INFO *************";
- qxtLog->debug() << "configFilePath: " << configFilePath.toUtf8();
- qxtLog->debug() << "logFilePath: " << logFilePath.toUtf8();
- qxtLog->debug() << "ipConfigFilePath: " << ipConfigFilePath.toUtf8();
- qxtLog->debug() << "baseURL: " << baseURL.toString().toUtf8();
- qxtLog->debug() << "downloadDir : " << downloadPath.toUtf8();
- qxtLog->debug() << "trigger: " << fileToTriggerURL.toUtf8();
- qxtLog->debug() << "serialLocation: " << serialLocation.toUtf8();
- qxtLog->debug() << "server: " << gServerIp.toUtf8();
- qxtLog->debug() << "autoup: " << gAutoUp;
- qxtLog->debug() << "socketserverpath: " << gSocketServerPath.toUtf8();
- qxtLog->debug() << "pathtoexe: " << gPathToDhcpExe.toUtf8();
- qxtLog->debug() << "*******************************************";
+ LOG4CXX_DEBUG(logger, "************* CONFIG INFO *************");
+ LOG4CXX_DEBUG(logger, "configFilePath: " << configFilePath);
+ LOG4CXX_DEBUG(logger, "logFilePath: " << logFilePath);
+ LOG4CXX_DEBUG(logger, "ipConfigFilePath: " << ipConfigFilePath);
+ LOG4CXX_DEBUG(logger, "baseURL: " << baseURL.toString());
+ LOG4CXX_DEBUG(logger, "downloadDir : " << downloadPath);
+ LOG4CXX_DEBUG(logger, "trigger: " << fileToTriggerURL);
+ LOG4CXX_DEBUG(logger, "serialLocation: " << serialLocation);
+ LOG4CXX_DEBUG(logger, "server: " << gServerIp);
+ LOG4CXX_DEBUG(logger, "autoup: " << gAutoUp);
+ LOG4CXX_DEBUG(logger, "socketserverpath: " << gSocketServerPath);
+ LOG4CXX_DEBUG(logger, "pathtoexe: " << gPathToDhcpExe);
+ LOG4CXX_DEBUG(logger, "*******************************************");
// set invisible cursor
//QWSServer::instance()->setCursorVisible(false);
@@ -258,7 +265,7 @@ int main(int argc, char *argv[]) {
// start ndgui
- qxtLog->debug() << "Initializing ndgui...";
+ LOG4CXX_DEBUG(logger, "Initializing ndgui...");
ndgui ngui;
fbgui gui;
diff --git a/src/fbgui/ndgui.cpp b/src/fbgui/ndgui.cpp
index 3034051..0ff4fdf 100644
--- a/src/fbgui/ndgui.cpp
+++ b/src/fbgui/ndgui.cpp
@@ -11,6 +11,15 @@
#include "ndgui.h"
+
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr ndLogger(Logger::getLogger("fbgui.nd"));
+
+
QString gServerIp("");
bool gAutoUp = true;
QString gSocketServerPath("");
@@ -144,9 +153,9 @@ void ndgui::createDebugConsole() {
_debugConsole->setPalette(pal);
_debugConsole->setTextColor(Qt::white);
// enable custom logger engine
- qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole));
+// qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole));
//qxtLog->initLoggerEngine("fb_logger");
- qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel);
+// qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel);
// CTRL + D toggles debug window
_toggleDebugConsole = new QAction(tr("&toggleDebug"), this);
_toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
@@ -211,7 +220,7 @@ void ndgui::setUserChoiceTrue() {
*/
void ndgui::startSingleShot() {
- qxtLog->debug() << _tag << "start singel shot";
+ LOG4CXX_DEBUG(ndLogger, _tag << "start singel shot");
QTimer::singleShot(3000, this, SLOT(startNetworkDiscovery()));
}
@@ -232,7 +241,7 @@ void ndgui::startNetworkDiscovery() {
_networkDiscovery->initAndRun(gServerIp, _userChoice, gAutoUp,
logFilePath, gSocketServerPath, gPathToDhcpExe);
} else {
- qxtLog->debug() << _tag << "NetworkDiscovery already started";
+ LOG4CXX_DEBUG(ndLogger, _tag << "NetworkDiscovery already started");
}
}
@@ -263,7 +272,7 @@ void ndgui::handleConnectionEstablished(QString ifName) {
* handleConnectionEstablished)).
*/
void ndgui::handleAllProcessesFinished() {
- qxtLog->debug() << _tag << "all Processes finished";
+ LOG4CXX_DEBUG(ndLogger, _tag << "all Processes finished");
_allowUserChoice->setEnabled(false);
if (_ifNameList.size() > 0) {
if (_userChoice) {
@@ -283,9 +292,8 @@ void ndgui::handleAllProcessesFinished() {
}
}
} else {
- qxtLog->debug() << _tag << " No usable interfaces found!: "
- << _networkDiscovery->GetErrorStr();
- qxtLog->debug() << _tag << " list is empty";
+ LOG4CXX_DEBUG(ndLogger, _tag << " No usable interfaces found!: " << _networkDiscovery->GetErrorStr());
+ LOG4CXX_DEBUG(ndLogger, _tag << " list is empty");
abortBoot("No usable interfaces found!"
+ _networkDiscovery->GetErrorStr());
}
@@ -305,7 +313,7 @@ void ndgui::restartSystem() {
file.write("b");
file.close();
} else {
- qxtLog->debug() << _tag << "Could not open /proc/sysrq-trigger";
+ LOG4CXX_DEBUG(ndLogger, _tag << "Could not open /proc/sysrq-trigger");
}
}
@@ -323,7 +331,7 @@ void ndgui::shutDownSystem() {
file.write("o");
file.close();
} else {
- qxtLog->debug() << _tag << "Could not open /proc/sysrq-trigger";
+ LOG4CXX_DEBUG(ndLogger, _tag << "Could not open /proc/sysrq-trigger");
}
}
@@ -339,7 +347,7 @@ void ndgui::shutDownSystem() {
//void ndgui::continueBoot(QString ifName, int userChoice) {
void ndgui::continueBoot(QString ifName) {
if (_networkDiscovery->checkConnectivity(ifName)) {
- qxtLog->debug() << _tag << " continue with interface: " << ifName;
+ LOG4CXX_DEBUG(ndLogger, _tag << " continue with interface: " << ifName);
emit initFbgui();
this->close();
} else {
@@ -355,7 +363,7 @@ void ndgui::continueBoot(QString ifName) {
* @brief continue the boot sequence without further checking if the connection is still possible.
*/
void ndgui::continueBootWithoutCheck(QString ifName) {
- qxtLog->debug() << _tag << " continue with interface: " << ifName;
+ LOG4CXX_DEBUG(ndLogger, _tag << " continue with interface: " << ifName);
emit initFbgui();
this->close();
}
@@ -366,7 +374,7 @@ void ndgui::continueBootWithoutCheck(QString ifName) {
* @brief read the log file. Log File will be presented inside of a dialog.
*/
QString ndgui::readLogFile() {
- qxtLog->debug() << _tag << "show log";
+ LOG4CXX_DEBUG(ndLogger, _tag << "show log");
return _networkDiscovery->readLogFile();
}
@@ -376,7 +384,7 @@ QString ndgui::readLogFile() {
* @brief starts the whole application again.
*/
void ndgui::tryAgain() {
- qxtLog->debug()<< _tag << " try again ";
+ LOG4CXX_DEBUG(ndLogger, _tag << " try again ");
_networkDiscovery->prepareTryAgain();
if(debugMode > -1) {
delete _splitter;
@@ -401,13 +409,15 @@ void ndgui::tryAgain() {
* dialog.
*/
QVariantList ndgui::getManualConfInterfaces() {
- qxtLog->debug() << _tag << "call getManualConfInterfaces";
+ LOG4CXX_DEBUG(ndLogger, _tag << "call getManualConfInterfaces");
QVariantList jsonArr;
+ QString debugOut;
foreach (QString s, _manConfList) {
QVariant e(s);
jsonArr << e;
+ debugOut += s + "; ";
}
- qxtLog->debug() << _tag << "value of jsonArr:" << jsonArr;
+ LOG4CXX_DEBUG(ndLogger, _tag << "value of jsonArr:" << debugOut);
return jsonArr;
}
@@ -468,8 +478,8 @@ void ndgui::loadJQuery() {
foreach(fi, fiList)
{
if (fi.suffix() == "js") {
- //qxtLog->debug()<< fi.fileName();
- //qxtLog->debug() << fi.fileName();
+ //LOG4CXX_DEBUG(ndLogger, fi.fileName());
+ //LOG4CXX_DEBUG(ndLogger, fi.fileName());
//if (fi.fileName() != "test.js" && fi.fileName() != "nd-functions.js") {
QFile file;
file.setFileName(pathToJsDir + "/" + fi.fileName());
@@ -478,7 +488,7 @@ void ndgui::loadJQuery() {
file.close();
_webView->page()->mainFrame()->evaluateJavaScript(js);
- //qxtLog->debug() << "evaluated " + fi.fileName();
+ //LOG4CXX_DEBUG(ndLogger, "evaluated " + fi.fileName());
//}
}
}
@@ -584,5 +594,5 @@ void ndgui::addInterface(const QString &ifName) {
* @brief just for debugging.
*/
void ndgui::notifyCall(QString msg){
- qxtLog->debug() << _tag << "------ called:" << msg;
+ LOG4CXX_DEBUG(ndLogger, _tag << "------ called:" << msg);
}
diff --git a/src/fbgui/ndgui.h b/src/fbgui/ndgui.h
index 41a7bbf..d4ab0b1 100644
--- a/src/fbgui/ndgui.h
+++ b/src/fbgui/ndgui.h
@@ -21,7 +21,6 @@
#include <QVariant>
#include "fbgui.h"
-#include "loggerengine.h"
#include "networkdiscovery.h"
@@ -30,84 +29,85 @@ extern bool gAutoUp;
extern QString gSocketServerPath;
extern QString gPathToDhcpExe;
-class ndgui: public QMainWindow {
-Q_OBJECT
+class ndgui: public QMainWindow
+{
+ Q_OBJECT
public:
- ndgui(QMainWindow *parent = 0);
- ~ndgui();
- Q_INVOKABLE QVariantList getManualConfInterfaces();
- Q_INVOKABLE int ip4_setManualConfiguration(QVariantMap result);
- Q_INVOKABLE QString readLogFile();
- Q_INVOKABLE QVariantMap getInterfaceConf(QString ifName);
+ ndgui(QMainWindow *parent = 0);
+ ~ndgui();
+ Q_INVOKABLE QVariantList getManualConfInterfaces();
+ Q_INVOKABLE int ip4_setManualConfiguration(QVariantMap result);
+ Q_INVOKABLE QString readLogFile();
+ Q_INVOKABLE QVariantMap getInterfaceConf(QString ifName);
public slots:
- void handleConnectionEstablished(QString ifName);
- void abortBoot(QString msg);
- void chooseInterfaceDialog(QString msg);
- void handleAllProcessesFinished();
+ void handleConnectionEstablished(QString ifName);
+ void abortBoot(QString msg);
+ void chooseInterfaceDialog(QString msg);
+ void handleAllProcessesFinished();
- void restartSystem();
- void shutDownSystem();
- void continueBoot(QString ifName);
- void continueBootWithoutCheck(QString ifName);
- void tryAgain();
+ void restartSystem();
+ void shutDownSystem();
+ void continueBoot(QString ifName);
+ void continueBootWithoutCheck(QString ifName);
+ void tryAgain();
- void startSingleShot();
- void startNetworkDiscovery();
+ void startSingleShot();
+ void startNetworkDiscovery();
- /*test for html gui version*/
- void attachToDOM();
- void loadJQuery();
- void addInterface(const QString &ifName);
- void updateIfStatus(const QString &ifName, const QString &status);
- void updateStatus(const QString &status);
- void updateIfProgressBar(const QString &ifName, const int& percent);
- void notifyCall(QString msg);
+ /*test for html gui version*/
+ void attachToDOM();
+ void loadJQuery();
+ void addInterface(const QString &ifName);
+ void updateIfStatus(const QString &ifName, const QString &status);
+ void updateStatus(const QString &status);
+ void updateIfProgressBar(const QString &ifName, const int& percent);
+ void notifyCall(QString msg);
- signals:
- void initFbgui();
+signals:
+ void initFbgui();
private slots:
- void setUserChoiceTrue();
+ void setUserChoiceTrue();
private:
- QString _tag;
+ QString _tag;
- void createAction();
+ void createAction();
- bool _userChoice;
+ bool _userChoice;
- bool _started;
+ bool _started;
- QWebView* _webView;
+ QWebView* _webView;
- QAction* _allowUserChoice;
+ QAction* _allowUserChoice;
- QAction* _tryAgain;
+ QAction* _tryAgain;
- NetworkDiscovery* _networkDiscovery;
+ NetworkDiscovery* _networkDiscovery;
- QList<QString> _ifNameList; // maps interfaceName to its gateway
+ QList<QString> _ifNameList; // maps interfaceName to its gateway
- QList<QString> _manConfList;
+ QList<QString> _manConfList;
- QString _manualConfInterfaces;
+ QString _manualConfInterfaces;
- // QSplitter to split the main window in two resizable frames.
- QSplitter* _splitter;
- // QTextEdit implementing a minimalistic debug console.
- QTextEdit* _debugConsole;
+ // QSplitter to split the main window in two resizable frames.
+ QSplitter* _splitter;
+ // QTextEdit implementing a minimalistic debug console.
+ QTextEdit* _debugConsole;
- // triggers toggleDebugConsole()
- QAction* _toggleDebugConsole;
+ // triggers toggleDebugConsole()
+ QAction* _toggleDebugConsole;
- void init();
- void setupLayout();
- void createDebugConsole();
- void toggleDebugConsole();
+ void init();
+ void setupLayout();
+ void createDebugConsole();
+ void toggleDebugConsole();
};
diff --git a/src/fbgui/networkdiscovery.cpp b/src/fbgui/networkdiscovery.cpp
index 132429c..a347adb 100644
--- a/src/fbgui/networkdiscovery.cpp
+++ b/src/fbgui/networkdiscovery.cpp
@@ -16,6 +16,13 @@
#include "networkdiscovery.h"
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr ndcLogger(Logger::getLogger("fbgui.nd.core"));
+
@@ -109,8 +116,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
emit updateStatus("try to create server socket");
if (!_server->listen(serverPath)) {
// emit signal to the gui that a critial error occoured
- qxtLog->debug() << _tag << " Unable to start server: "
- << _server->errorString();
+ LOG4CXX_DEBUG(ndcLogger, _tag << " Unable to start server: " << _server->errorString());
emit
abortBoot("Unable to start server: " + _server->errorString());
return;
@@ -122,8 +128,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
emit updateStatus("check if cdhcpcd is available");
QFileInfo fInfo(_pathToDhcpcdExe);
if (!fInfo.exists()) {
- qxtLog->debug() << _tag
- << " could not find customdhcpcd exe. Please check the path to this file.";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " could not find customdhcpcd exe. Please check the path to this file.");
emit abortBoot(
"could not find customdhcpcd exe. Please check the path to this file.");
return;
@@ -133,7 +138,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun()));
if (args != NULL && !args->isEmpty()) {
- qxtLog->debug() << _tag << "added additional args";
+ LOG4CXX_DEBUG(ndcLogger, _tag << "added additional args");
_dhcpcdArguments.append(*args);
}
emit updateStatus("start mainwork");
@@ -179,21 +184,21 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
if (nIList.size() > 0) {
foreach(QNetworkInterface nI, nIList)
{
- qxtLog->debug() << _tag << "found Interface:" << nI.humanReadableName();
+ LOG4CXX_DEBUG(ndcLogger, _tag << "found Interface:" << nI.humanReadableName());
if ((nI.flags() & QNetworkInterface::CanBroadcast)) {
- qxtLog->debug() << _tag << " flags: can broadcast ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: can broadcast ");
}
if ((nI.flags() & QNetworkInterface::IsLoopBack)) {
- qxtLog->debug() << _tag << " flags: is LoopBack ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is LoopBack ");
}
if ((nI.flags() & QNetworkInterface::IsPointToPoint)) {
- qxtLog->debug() << _tag << " flags: is Point to Point ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is Point to Point ");
}
if ((nI.flags() & QNetworkInterface::IsRunning)) {
- qxtLog->debug() << _tag << " flags: is Running ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is Running ");
}
if ((nI.flags() & QNetworkInterface::IsUp)) {
- qxtLog->debug() << _tag << " flags: is Up ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is Up ");
}
if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
@@ -207,7 +212,7 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
}
else if (!(nI.flags() & QNetworkInterface::IsUp)) {
_networkManager->bringInterfaceUP(nI.humanReadableName());
- qxtLog->debug() << _tag << " interface is down, try to bring up: " << nI.humanReadableName() ;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " interface is down, try to bring up: " << nI.humanReadableName() );
_ifDownList.append(nI.humanReadableName());
}
else if (!(nI.flags() & QNetworkInterface::IsRunning)) {
@@ -215,7 +220,7 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
}
}
} else {
- qxtLog->debug() << _tag << " no interfaces found! ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " no interfaces found! ");
}
}
@@ -232,22 +237,21 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
if (nIList.size() > 0) {
foreach(QNetworkInterface nI, nIList)
{
- qxtLog->debug() << _tag << "found Interface:"
- << nI.humanReadableName();
+ LOG4CXX_DEBUG(ndcLogger, _tag << "found Interface:" << nI.humanReadableName());
if ((nI.flags() & QNetworkInterface::CanBroadcast)) {
- qxtLog->debug() << _tag << " flags: can broadcast ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: can broadcast ");
}
if ((nI.flags() & QNetworkInterface::IsLoopBack)) {
- qxtLog->debug() << _tag << " flags: is LoopBack ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is LoopBack ");
}
if ((nI.flags() & QNetworkInterface::IsPointToPoint)) {
- qxtLog->debug() << _tag << " flags: is Point to Point ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is Point to Point ");
}
if ((nI.flags() & QNetworkInterface::IsRunning)) {
- qxtLog->debug() << _tag << " flags: is Running ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is Running ");
}
if ((nI.flags() & QNetworkInterface::IsUp)) {
- qxtLog->debug() << _tag << " flags: is Up ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " flags: is Up ");
}
if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
|| nI.flags() & QNetworkInterface::IsLoopBack)
@@ -263,7 +267,7 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
}
}
} else {
- qxtLog->debug() << _tag << " no interfaces found! ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " no interfaces found! ");
}
}
@@ -304,17 +308,17 @@ void NetworkDiscovery::checkForIsRunning() {
void NetworkDiscovery::slotReadyForRun() {
if (_ifUpList.size() > 0) {
foreach(QString i, _ifUpList) {
- qxtLog->debug() << _tag << " emit addInterface : " << i;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " emit addInterface : " << i);
emit addInterface(i);
}
_numberOfProcesses = _ifUpList.size();
emit updateStatus("start dhcp client for each interface");
runDHCPCD( _ifUpList);
} else {
- qxtLog->debug() << _tag << " list is empty. Have not found usable interface. ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " list is empty. Have not found usable interface. ");
emit
foreach(QString i, _ifDownList) {
- qxtLog->debug() << _tag << " " << i << " is not in running state. (check cable)";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << i << " is not in running state. (check cable)");
}
abortBoot("All interfaces are not usable. (e.g. please check if all network cables are plugged in. Read the log for more informations.)");
return;
@@ -349,7 +353,7 @@ void NetworkDiscovery::runDHCPCD(QString interface) {
_dhcpcdArguments.append(interface);
QProcess * p = new QProcess(this);
- qxtLog->debug() << _tag << " start cdhcpcd with arguments: " << _dhcpcdArguments;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " start cdhcpcd with arguments: " << _dhcpcdArguments.join(", "));
_clientProcessToIfNameMap.insert(p, interface);
p->start(_pathToDhcpcdExe, _dhcpcdArguments);
@@ -370,7 +374,7 @@ void NetworkDiscovery::runDHCPCD(QString interface) {
void NetworkDiscovery::handleProcessStarted() {
QProcess* p = qobject_cast<QProcess *> (QObject::sender());
QString ifName = _clientProcessToIfNameMap.value(p, "ifName");
- qxtLog->debug() << _tag << " process started for interface: " << ifName;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " process started for interface: " << ifName);
}
@@ -410,18 +414,15 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
_numberOfProcesses = _numberOfProcesses - 1;
if (!_blocked) { //_blocked becomes true, if _userChoice is false and we already found a usable interface
if (ifName.compare("ifName") == 0) {
- qxtLog->debug() << _tag << " haven't found process!";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " haven't found process!");
} else {
- qxtLog->debug() << _tag << " process for interface " << ifName
- << " finished " << " exit code: " << exitCode
- << " exit status " << exitStatus;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " process for interface " << ifName << " finished " << " exit code: " << exitCode << " exit status " << exitStatus);
if (exitCode > 0) {
- qxtLog->debug() << _tag << " process exited unexpected: "
- << p->errorString();
+ LOG4CXX_DEBUG(ndcLogger, _tag << " process exited unexpected: " << p->errorString());
emit updateIfStatus(ifName, "process exited unexpected"
+ p->errorString());
} else {
- qxtLog->debug() << _tag << " process normal exit ";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " process normal exit ");
emit
changeProgressBarValue(ifName, 100);
emit
@@ -447,7 +448,7 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
}
}
} else {
- qxtLog->debug() << _tag << " already blocked";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " already blocked");
emit updateIfStatus(ifName, "finished DHCP");
}
}
@@ -485,17 +486,17 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
ifConf->readConfigOutOfFile(pathToGatewayFile);
// replace default route
- qxtLog->debug() << _tag << "replace default route";
+ LOG4CXX_DEBUG(ndcLogger, _tag << "replace default route");
_networkManager->replaceDefaultRoute(ifName,
ifConf->getGateway(), mss, AF_INET);
if (checkConnectivityViaTcp(_serverIp)) {
- qxtLog->debug() << _tag << " passed connectivity check! for interface " << ifName;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " passed connectivity check! for interface " << ifName);
emit
updateIfStatus(ifName, "connection possible");
return true;
} else {
- qxtLog->debug() << _tag << " failed connectivity check! for interface " << ifName;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " failed connectivity check! for interface " << ifName);
emit
updateIfStatus(ifName, "connection not possible");
return false;
@@ -523,14 +524,14 @@ bool NetworkDiscovery::checkConnectivityViaTcp() {
*/
bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
// check connectivity via tcp connection
- qxtLog->debug() << _tag << " check connectivity to server: " << server;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " check connectivity to server: " << server);
// do host lookup
//QHostInfo hostInfo = QHostInfo::fromName(server);
QTcpSocket *tcpSocket = new QTcpSocket(this);
- //qxtLog->debug() << _tag << " hostInfo first address: " << hostInfo.addresses().first().toString(); //hostInfo.addresses().first()
+ //LOG4CXX_DEBUG(ndcLogger, _tag << " hostInfo first address: " << hostInfo.addresses().first().toString()); //hostInfo.addresses().first()
tcpSocket->connectToHost(server, 80);
if (!tcpSocket->waitForConnected(500)) {
- qxtLog->debug() << _tag << tcpSocket->errorString();
+ LOG4CXX_DEBUG(ndcLogger, _tag << tcpSocket->errorString());
_errorStr += tcpSocket->errorString();
return false;
} else {
@@ -548,12 +549,12 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
* a client
*/
void NetworkDiscovery::handleNewInput(QLocalSocket * client) {
- qxtLog->debug() << _tag << "last read before exit";
+ LOG4CXX_DEBUG(ndcLogger, _tag << "last read before exit");
while (client->canReadLine()) {
QString data(client->readLine());
data = data.trimmed();
- qxtLog->debug() << _tag << data;
+ LOG4CXX_DEBUG(ndcLogger, _tag << data);
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
@@ -612,7 +613,7 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
QString msg = logMsg.section(";", 3, 3);
int st = s_state.trimmed().toInt();
int sst = s_subState.trimmed().toInt();
- //qxtLog->debug() << _tag << logMsg;
+ //LOG4CXX_DEBUG(ndcLogger, _tag << logMsg);
if (_ifNameToClient.size() < _numberOfProcesses && !_ifNameToClient.contains(
interface)) {
@@ -624,60 +625,60 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
switch (sst) {
case DHCP_DISCOVER:
emit changeProgressBarValue(interface, 10);
- qxtLog->debug() << _tag << " " << interface << " send discover";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " send discover");
break;
case DHCP_OFFER:
emit changeProgressBarValue(interface, 20);
- qxtLog->debug() << _tag << " " << interface << " got offer";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " got offer");
break;
case DHCP_REQUEST:
emit changeProgressBarValue(interface, 30);
- qxtLog->debug() << _tag << " " << interface << " send request";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " send request");
break;
case DHCP_ACK:
emit changeProgressBarValue(interface, 40);
- qxtLog->debug() << _tag << " " << interface << " ack";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " ack");
break;
case DHCP_NAK:
emit changeProgressBarValue(interface, 40);
- qxtLog->debug() << _tag << " " << interface << " nak";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " nak");
break;
case DHCPCD_ARP_TEST:
emit changeProgressBarValue(interface, 50);
- qxtLog->debug() << _tag << " " << interface << " do arp test";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " do arp test");
break;
case DHCP_DECLINE:
emit changeProgressBarValue(interface, 60);
break;
case DHCP_RELEASE:
- qxtLog->debug() << _tag << " " << interface << " release";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " release");
break;
case DHCP_INFORM:
break;
case DHCPCD_CONFIGURE:
emit changeProgressBarValue(interface, 70);
- qxtLog->debug() << _tag << " " << interface << " do configure interface";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " do configure interface");
break;
case DHCPCD_WRITE:
emit changeProgressBarValue(interface, 80);
- qxtLog->debug() << _tag << " " << interface << " write conf file";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " write conf file");
break;
case DHCPCD_EXIT:
emit changeProgressBarValue(interface, 100);
- qxtLog->debug() << _tag << " " << interface << " exiting";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << interface << " exiting");
break;
case DHCPCD_LOG:
- qxtLog->debug() << _tag << " received dhcpcd log: " << msg;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " received dhcpcd log: " << msg);
default:
- qxtLog->debug() << _tag << " received unknown substatus: " << msg;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " received unknown substatus: " << msg);
break;
}
break;
case LOG_ERR:
- qxtLog->debug() << _tag << " received error: " << msg;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " received error: " << msg);
break;
default:
- qxtLog->debug() << _tag << " " << logMsg;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " " << logMsg);
break;
}
}
@@ -721,10 +722,10 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
result["broadcast"].toString(), result["gateway"].toString(), 0,
AF_INET, "/etc/", dns);
- qxtLog->debug() << _tag << " set man conf. and check connectivity";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " set man conf. and check connectivity");
if (!checkConnectivityViaTcp(_serverIp)) {
- qxtLog->debug() << _tag << " no connectivity. reset conf.";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " no connectivity. reset conf.");
interfaceconfiguration * ifc = _ifcMap.value(
result["ifname"].toString(), NULL);
if (ifc != NULL) {
@@ -738,7 +739,7 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
return 0;
}
- qxtLog->debug() << _tag << " emit signal continueBootWithoutCheck(" << result["ifname"].toString() << ")";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " emit signal continueBootWithoutCheck(" << result["ifname"].toString() << ")");
emit
continueBootWithoutCheck(result["ifname"].toString());
return 0;
@@ -762,7 +763,7 @@ QString NetworkDiscovery::getGatewayForInterface(QString ifName) {
return ifConf->getGateway();
}
else {
- qxtLog->debug() << _tag << " could not find interface configuration";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " could not find interface configuration");
return "";
}
@@ -786,12 +787,12 @@ QString NetworkDiscovery::readLogFile() {
}
}
else {
- qxtLog->debug() << _tag << " could not open log file";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " could not open log file");
retval = "could not open log file";
}
}
else {
- qxtLog->debug() << _tag << " log file does not exist at: " << _pathToLogFile;
+ LOG4CXX_DEBUG(ndcLogger, _tag << " log file does not exist at: " << _pathToLogFile);
retval = " log file does not exist at: " + _pathToLogFile;
}
return retval;
@@ -801,12 +802,12 @@ QString NetworkDiscovery::readLogFile() {
/**/
void NetworkDiscovery::killDHCPCD() {
- qxtLog->debug() << " kill cdhcpcd processes";
+ LOG4CXX_DEBUG(ndcLogger, " kill cdhcpcd processes");
QProcess * p = new QProcess(this);
p->start("killall cdhcpcd");
p->waitForFinished();
if (p->exitCode() > 0)
- qxtLog->debug() << _tag << " [tryAgain] " << p->errorString();
+ LOG4CXX_DEBUG(ndcLogger, _tag << " [tryAgain] " << p->errorString());
delete p;
}
@@ -875,7 +876,7 @@ QVariantMap NetworkDiscovery::getInterfaceConfig(QString ifName) {
* connects the client readyRead signal with the handleNewInput slot.
*/
void NetworkDiscovery::handleNewConnection() {
- qxtLog->debug() << _tag << " New Connection arrived";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " New Connection arrived");
/*QLocalSocket **/
_client = _server->nextPendingConnection();
@@ -895,7 +896,7 @@ void NetworkDiscovery::handleClientDisconnect() {
QLocalSocket * client = _clients.value(socket);
- qxtLog->debug() << _tag << " disconnect client";
+ LOG4CXX_DEBUG(ndcLogger, _tag << " disconnect client");
handleNewInput(client);
client->deleteLater();
}
@@ -951,7 +952,7 @@ QString NetworkDiscovery::GetErrorStr() {
*/
bool NetworkDiscovery::checkCarrierState(QString interface) {
- qxtLog->debug() << _tag << "check carrier state for interface " << interface;
+ LOG4CXX_DEBUG(ndcLogger, _tag << "check carrier state for interface " << interface);
QByteArray ba = interface.toAscii();
const char * iface = ba.data();
@@ -968,21 +969,19 @@ bool NetworkDiscovery::checkCarrierState(QString interface) {
int v = value.toInt(pok);
if (*pok) {
if (v == 1) {
- qxtLog->debug()
- << "carrier is 1. Cable is plugged. return true";
+ LOG4CXX_DEBUG(ndcLogger, "carrier is 1. Cable is plugged. return true");
return true;
} else {
- qxtLog->debug()
- << "carrier is 0. Cable is unplugged. return false";
+ LOG4CXX_DEBUG(ndcLogger, "carrier is 0. Cable is unplugged. return false");
return false;
}
} else {
- qxtLog->debug() << _tag << "conversion error";
+ LOG4CXX_DEBUG(ndcLogger, _tag << "conversion error");
}
}
}
} else {
- qxtLog->debug() << _tag << "attrlist is Null";
+ LOG4CXX_DEBUG(ndcLogger, _tag << "attrlist is Null");
}
sysfs_close_class_device(class_device);
diff --git a/src/fbgui/networkdiscovery.h b/src/fbgui/networkdiscovery.h
index c422b18..d63ad0b 100644
--- a/src/fbgui/networkdiscovery.h
+++ b/src/fbgui/networkdiscovery.h
@@ -27,7 +27,6 @@
#include <syslog.h>
#include <sysfs/libsysfs.h>
-#include "loggerengine.h"
#include "interfaceconfiguration.h"
#include "networkmanager.h"
@@ -40,98 +39,99 @@
#define DEFAULT_PATHTODHCPCDEXE "/bin/cdhcpcd"
-class NetworkDiscovery: public QObject {
-Q_OBJECT
+class NetworkDiscovery: public QObject
+{
+ Q_OBJECT
public:
- NetworkDiscovery(QObject *parent=0);
- ~NetworkDiscovery();
-
- void initAndRun(QString serverIp, bool userChoice,
- bool autoUp,
- QString pathToLogFile,
- QString serverPath = DEFAULT_QTSOCKETADDRESS,
- QString pathToExe = DEFAULT_PATHTODHCPCDEXE,
- QStringList* args = NULL);
- int ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss);
- QString getGatewayForInterface(QString ifName);
-
- int ip4_setManualConfiguration(QVariantMap result);
- QString readLogFile();
- void tryAgain();
- void prepareTryAgain();
- bool checkConnectivity(QString ifName);
- bool checkConnectivityViaTcp();
- QVariantMap getInterfaceConfig(QString ifName);
- QString GetErrorStr();
+ NetworkDiscovery(QObject *parent = 0);
+ ~NetworkDiscovery();
+
+ void initAndRun(QString serverIp, bool userChoice,
+ bool autoUp,
+ QString pathToLogFile,
+ QString serverPath = DEFAULT_QTSOCKETADDRESS,
+ QString pathToExe = DEFAULT_PATHTODHCPCDEXE,
+ QStringList* args = NULL);
+ int ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss);
+ QString getGatewayForInterface(QString ifName);
+
+ int ip4_setManualConfiguration(QVariantMap result);
+ QString readLogFile();
+ void tryAgain();
+ void prepareTryAgain();
+ bool checkConnectivity(QString ifName);
+ bool checkConnectivityViaTcp();
+ QVariantMap getInterfaceConfig(QString ifName);
+ QString GetErrorStr();
public slots:
- void handleNewConnection();
- void handleNewInput();
- void handleNewInputLine(QLocalSocket * client, QString data);
- void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
- void handleProcessStarted();
- void handleClientDisconnect();
+ void handleNewConnection();
+ void handleNewInput();
+ void handleNewInputLine(QLocalSocket * client, QString data);
+ void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
+ void handleProcessStarted();
+ void handleClientDisconnect();
- void slotReadyForRun();
+ void slotReadyForRun();
- void checkForIsRunning();
+ void checkForIsRunning();
signals:
- void addInterface(const QString &ifName);
- void changeProgressBarValue(const QString & ifName, const int $newValue);
- void connectionEstablished(QString ifName);
- void abortBoot(QString msg);
- void updateIfStatus(QString ifName, QString status);
- void updateStatus(QString status);
- void allProcessesFinished();
- void continueBoot(QString ifName);
- void continueBootWithoutCheck(QString ifName);
- void setManualConfInterfaces(QString jsonArr);
-
- void readyForRun();
+ void addInterface(const QString &ifName);
+ void changeProgressBarValue(const QString & ifName, const int $newValue);
+ void connectionEstablished(QString ifName);
+ void abortBoot(QString msg);
+ void updateIfStatus(QString ifName, QString status);
+ void updateStatus(QString status);
+ void allProcessesFinished();
+ void continueBoot(QString ifName);
+ void continueBootWithoutCheck(QString ifName);
+ void setManualConfInterfaces(QString jsonArr);
+
+ void readyForRun();
private:
- QString _tag;
- QLocalServer *_server;
- QMap<QLocalSocket*,QLocalSocket*> _clients;
- QLocalSocket *_client;
- QMap<QString,QLocalSocket*> _ifNameToClient;
- QMap<QProcess*,QString> _clientProcessToIfNameMap;
- QString _serverPath;
- QString _pathToDhcpcdExe;
- QStringList _dhcpcdArguments;
- int _numberOfProcesses;
- NetworkManager* _networkManager;
- bool _userChoice;
- bool _blocked;
- bool _autoUp;
- QString _serverIp;
- QString _pathToLogFile;
- QList<QString> _ifUpList;
- QList<QString> _ifDownList;
- int _ifUpCountdown;
- QTimer*_timer;
- QList<Q_PID> _pidsList;
- QString _errorStr;
- QMap<QString,interfaceconfiguration*> _ifcMap;
- void mainWork();
-
- void killDHCPCD();
-
- void handleNewInput(QLocalSocket * client);
-
- void runDHCPCD(QList<QString> &interfaces);
- void runDHCPCD(QString interface);
-
- bool checkCarrierState(QString interface);
- bool checkConnectivityViaTcp(QString server);
-
- bool checkBlackList(QString i);
-
- void getListOfNetworkInterfaces();
- void getListOfNetworkInterfacesWithAutoUp();
+ QString _tag;
+ QLocalServer *_server;
+ QMap<QLocalSocket*, QLocalSocket*> _clients;
+ QLocalSocket *_client;
+ QMap<QString, QLocalSocket*> _ifNameToClient;
+ QMap<QProcess*, QString> _clientProcessToIfNameMap;
+ QString _serverPath;
+ QString _pathToDhcpcdExe;
+ QStringList _dhcpcdArguments;
+ int _numberOfProcesses;
+ NetworkManager* _networkManager;
+ bool _userChoice;
+ bool _blocked;
+ bool _autoUp;
+ QString _serverIp;
+ QString _pathToLogFile;
+ QList<QString> _ifUpList;
+ QList<QString> _ifDownList;
+ int _ifUpCountdown;
+ QTimer*_timer;
+ QList<Q_PID> _pidsList;
+ QString _errorStr;
+ QMap<QString, interfaceconfiguration*> _ifcMap;
+ void mainWork();
+
+ void killDHCPCD();
+
+ void handleNewInput(QLocalSocket * client);
+
+ void runDHCPCD(QList<QString> &interfaces);
+ void runDHCPCD(QString interface);
+
+ bool checkCarrierState(QString interface);
+ bool checkConnectivityViaTcp(QString server);
+
+ bool checkBlackList(QString i);
+
+ void getListOfNetworkInterfaces();
+ void getListOfNetworkInterfacesWithAutoUp();
};
diff --git a/src/fbgui/networkmanager.cpp b/src/fbgui/networkmanager.cpp
index 2dc774f..63e5740 100644
--- a/src/fbgui/networkmanager.cpp
+++ b/src/fbgui/networkmanager.cpp
@@ -8,23 +8,19 @@
*
*/
-
-
#include "networkmanager.h"
-NetworkManager::NetworkManager() {
- // TODO Auto-generated constructor stub
- _tag = "[nd:NetworkManager]";
+NetworkManager::NetworkManager()
+{
+ // TODO Auto-generated constructor stub
+ _tag = "[nd:NetworkManager]";
}
-
-
-NetworkManager::~NetworkManager() {
- // TODO Auto-generated destructor stub
+NetworkManager::~NetworkManager()
+{
+ // TODO Auto-generated destructor stub
}
-
-
/**
* This method adds /replaces the default route.
* This method adds /replaces the default route.
@@ -48,159 +44,172 @@ NetworkManager::~NetworkManager() {
* return -1 if an error happened.
* return 0 if everything was ok.
*/
-int NetworkManager::replaceDefaultRoute(QString ifname, QString gateway,
- int mss, int af) {
- struct nl_cache *cache;
- struct nl_handle* rtsock;
- struct nl_addr * gw;
- struct rtnl_route * route;
- int retval, iface_idx;
+int
+NetworkManager::replaceDefaultRoute(QString ifname, QString gateway, int mss,
+ int af)
+{
+ struct nl_cache *cache;
+ struct nl_handle* rtsock;
+ struct nl_addr * gw;
+ struct rtnl_route * route;
+ int retval, iface_idx;
- QByteArray ba_ifn = ifname.toAscii();
- char * ifn = ba_ifn.data();
+ QByteArray ba_ifn = ifname.toAscii();
+ char * ifn = ba_ifn.data();
- QByteArray ba_gw = gateway.toAscii();
- char * gwaddr = ba_gw.data();
+ QByteArray ba_gw = gateway.toAscii();
+ char * gwaddr = ba_gw.data();
- qDebug() << _tag << "---doRoute() gwaddr" << gwaddr;
+ qDebug() << _tag << "---doRoute() gwaddr" << gwaddr;
- if (!(gw = nl_addr_parse(gwaddr, af))) {
- qDebug() << _tag << "Invalid router address given:" << gwaddr;
- return -1;
- }
+ if (!(gw = nl_addr_parse(gwaddr, af)))
+ {
+ qDebug() << _tag << "Invalid router address given:" << gwaddr;
+ return -1;
+ }
- rtsock = nl_handle_alloc();
- nl_connect(rtsock, NETLINK_ROUTE);
+ rtsock = nl_handle_alloc();
+ nl_connect(rtsock, NETLINK_ROUTE);
- if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) {
- qDebug() << _tag << "error with link cache alloc \n";
- }
+ if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL)
+ {
+ qDebug() << _tag << "error with link cache alloc \n";
+ }
- iface_idx = rtnl_link_name2i(cache, ifn);
+ iface_idx = rtnl_link_name2i(cache, ifn);
- route = rtnl_route_alloc();
- rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
- rtnl_route_set_gateway(route, gw);
- rtnl_route_set_oif(route, iface_idx);
+ route = rtnl_route_alloc();
+ rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
+ rtnl_route_set_gateway(route, gw);
+ rtnl_route_set_oif(route, iface_idx);
- if (mss > 0) {
- rtnl_route_set_metric(route, RTAX_ADVMSS, mss);
- }
+ if (mss > 0)
+ {
+ rtnl_route_set_metric(route, RTAX_ADVMSS, mss);
+ }
- retval = rtnl_route_add(rtsock, route, NLM_F_REPLACE);
- qDebug() << _tag << "return value:" << retval << ":" << strerror(-retval);
+ retval = rtnl_route_add(rtsock, route, NLM_F_REPLACE);
+ qDebug() << _tag << "return value:" << retval << ":" << strerror(-retval);
- rtnl_route_put(route);
- nl_addr_put(gw);
- nl_handle_destroy(rtsock);
+ rtnl_route_put(route);
+ nl_addr_put(gw);
+ nl_handle_destroy(rtsock);
- return retval;
+ return retval;
}
+/**/
+int
+NetworkManager::ip6_addRoute(const char *iface, const struct in6_addr *ip6_dest,
+ int ip6_prefix, const struct in6_addr *ip6_gateway, int metric, int mss)
+{
+ struct nl_cache *cache;
+ struct nl_handle *nlh;
+ struct rtnl_route *route;
+ struct nl_addr *dest_addr;
+ struct nl_addr *gw_addr = NULL;
+ int err, iface_idx;
+
+ nlh = nl_handle_alloc();
+ nl_connect(nlh, NETLINK_ROUTE);
+
+ if ((cache = rtnl_link_alloc_cache(nlh)) == NULL)
+ {
+ //qDebug() << _tag << "error with link cache alloc \n";
+ printf("error with link cache alloc \n");
+ }
+ iface_idx = rtnl_link_name2i(cache, iface);
+
+ route = rtnl_route_alloc();
+
+ /* Destination */
+ dest_addr = nl_addr_build(AF_INET6, (struct in6_addr *) ip6_dest,
+ sizeof(*ip6_dest));
+ nl_addr_set_prefixlen(dest_addr, (int) ip6_prefix);
+
+ rtnl_route_set_dst(route, dest_addr);
+ nl_addr_put(dest_addr);
+
+ /* Gateway */
+ if (ip6_gateway && !IN6_IS_ADDR_UNSPECIFIED (ip6_gateway))
+ {
+ gw_addr = nl_addr_build(AF_INET6, (struct in6_addr *) ip6_gateway,
+ sizeof(*ip6_gateway));
+ if (gw_addr)
+ {
+ rtnl_route_set_gateway(route, gw_addr);
+ rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
+ }
+ else
+ {
+ rtnl_route_put(route);
+ return -1;
+ }
+ }
-/**/
-int NetworkManager::ip6_addRoute(const char *iface,
- const struct in6_addr *ip6_dest, int ip6_prefix,
- const struct in6_addr *ip6_gateway, int metric, int mss) {
- struct nl_cache *cache;
- struct nl_handle *nlh;
- struct rtnl_route *route;
- struct nl_addr *dest_addr;
- struct nl_addr *gw_addr = NULL;
- int err, iface_idx;
-
- nlh = nl_handle_alloc();
- nl_connect(nlh, NETLINK_ROUTE);
-
- if ((cache = rtnl_link_alloc_cache(nlh)) == NULL) {
- //qDebug() << _tag << "error with link cache alloc \n";
- printf("error with link cache alloc \n");
- }
-
- iface_idx = rtnl_link_name2i(cache, iface);
-
- route = rtnl_route_alloc();
-
- /* Destination */
- dest_addr = nl_addr_build(AF_INET6, (struct in6_addr *) ip6_dest,
- sizeof(*ip6_dest));
- nl_addr_set_prefixlen(dest_addr, (int) ip6_prefix);
-
- rtnl_route_set_dst(route, dest_addr);
- nl_addr_put(dest_addr);
-
- /* Gateway */
- if (ip6_gateway && !IN6_IS_ADDR_UNSPECIFIED (ip6_gateway)) {
- gw_addr = nl_addr_build(AF_INET6, (struct in6_addr *) ip6_gateway,
- sizeof(*ip6_gateway));
- if (gw_addr) {
- rtnl_route_set_gateway(route, gw_addr);
- rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
- } else {
- rtnl_route_put(route);
- return -1;
- }
- }
-
- /* Metric */
- if (metric)
- rtnl_route_set_prio(route, metric);
-
- /* Add the route */
- err = rtnl_route_add(nlh, route, 0);
- if (err == -ESRCH && ip6_gateway) {
- /* Gateway might be over a bridge; try adding a route to gateway first */
- struct rtnl_route *route2;
-
- route2 = create_route(iface_idx, mss);
- if (route2) {
- /* Add route to gateway over bridge */
- rtnl_route_set_dst(route2, gw_addr);
- err = rtnl_route_add(nlh, route2, 0);
- if (!err) {
- /* Try adding the route again */
- err = rtnl_route_add(nlh, route, 0);
- if (err)
- rtnl_route_del(nlh, route2, 0);
- }
- rtnl_route_put(route2);
- }
- }
-
- if (gw_addr)
- nl_addr_put(gw_addr);
-
- if (err) {
- //nm_warning ("Failed to set IPv6 route on '%s': %s", iface, nl_geterror ());
- rtnl_route_put(route);
- route = NULL;
- }
-
- return 0;
-}
+ /* Metric */
+ if (metric)
+ rtnl_route_set_prio(route, metric);
+
+ /* Add the route */
+ err = rtnl_route_add(nlh, route, 0);
+ if (err == -ESRCH && ip6_gateway)
+ {
+ /* Gateway might be over a bridge; try adding a route to gateway first */
+ struct rtnl_route *route2;
+
+ route2 = create_route(iface_idx, mss);
+ if (route2)
+ {
+ /* Add route to gateway over bridge */
+ rtnl_route_set_dst(route2, gw_addr);
+ err = rtnl_route_add(nlh, route2, 0);
+ if (!err)
+ {
+ /* Try adding the route again */
+ err = rtnl_route_add(nlh, route, 0);
+ if (err)
+ rtnl_route_del(nlh, route2, 0);
+ }
+ rtnl_route_put(route2);
+ }
+ }
+ if (gw_addr)
+ nl_addr_put(gw_addr);
+ if (err)
+ {
+ //nm_warning ("Failed to set IPv6 route on '%s': %s", iface, nl_geterror ());
+ rtnl_route_put(route);
+ route = NULL;
+ }
-struct rtnl_route * NetworkManager::create_route (int iface_idx, int mss)
+ return 0;
+}
+
+struct rtnl_route *
+NetworkManager::create_route(int iface_idx, int mss)
{
- struct rtnl_route *route;
+ struct rtnl_route *route;
- route = rtnl_route_alloc ();
- if (route) {
- rtnl_route_set_oif (route, iface_idx);
+ route = rtnl_route_alloc();
+ if (route)
+ {
+ rtnl_route_set_oif(route, iface_idx);
- if (mss && rtnl_route_set_metric (route, RTAX_ADVMSS, mss) < 0) {
- //nm_warning ("Could not set mss");
- }
- } else
- //nm_warning ("Could not allocate route");
+ if (mss && rtnl_route_set_metric(route, RTAX_ADVMSS, mss) < 0)
+ {
+ //nm_warning ("Could not set mss");
+ }
+ }
+ else
+ //nm_warning ("Could not allocate route");
- return route;
+ return route;
}
-
-
/**
* The method brings an interface up.
*
@@ -211,12 +220,12 @@ struct rtnl_route * NetworkManager::create_route (int iface_idx, int mss)
* 0 -> success
* -1 -> error
*/
-int NetworkManager::bringInterfaceUP(QString ifname) {
- return bringInterfaceUpDown(ifname, true);
+int
+NetworkManager::bringInterfaceUP(QString ifname)
+{
+ return bringInterfaceUpDown(ifname, true);
}
-
-
/**
* The method brings an interface down.
*
@@ -227,12 +236,12 @@ int NetworkManager::bringInterfaceUP(QString ifname) {
* 0 -> success
* -1 -> error
*/
-int NetworkManager::bringInterfaceDown(QString ifname) {
- return bringInterfaceUpDown(ifname, false);
+int
+NetworkManager::bringInterfaceDown(QString ifname)
+{
+ return bringInterfaceUpDown(ifname, false);
}
-
-
/**
* This method brings an interface up or down.
*
@@ -246,52 +255,60 @@ int NetworkManager::bringInterfaceDown(QString ifname) {
* 0 if everything is ok
* else an error
*/
-int NetworkManager::bringInterfaceUpDown(QString ifname, bool up) {
- struct nl_cache *cache;
- struct nl_handle* rtsock;
- struct rtnl_link* request = NULL;
- struct rtnl_link* old = NULL;
- int retval;
-
- QByteArray ba_ifn = ifname.toAscii();
- char * ifn = ba_ifn.data();
-
- if (!(request = rtnl_link_alloc())) {
- qDebug() << _tag << "error. couldn't allocate a rtnl link";
- return -1;
- }
-
- rtsock = nl_handle_alloc();
- nl_connect(rtsock, NETLINK_ROUTE);
-
- if (up) {
- rtnl_link_set_flags(request, IFF_UP);
- } else {
- rtnl_link_unset_flags(request, IFF_UP);
- }
-
- if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) {
- qDebug() << _tag << "error with link cache alloc ";
- }
-
- old = rtnl_link_get_by_name(cache, ifn);
- if (old) {
- qDebug() << _tag << "change link";
- retval = rtnl_link_change(rtsock, old, request, 0);
- } else {
- qDebug() << _tag << "change failed";
- retval = -1;
- qDebug() << _tag << "return value:" << retval << ":" << strerror(-retval);
- }
-
- rtnl_link_put(old);
- rtnl_link_put(request);
- nl_handle_destroy(rtsock);
-
- return retval;
-}
+int
+NetworkManager::bringInterfaceUpDown(QString ifname, bool up)
+{
+ struct nl_cache *cache;
+ struct nl_handle* rtsock;
+ struct rtnl_link* request = NULL;
+ struct rtnl_link* old = NULL;
+ int retval;
+
+ QByteArray ba_ifn = ifname.toAscii();
+ char * ifn = ba_ifn.data();
+
+ if (!(request = rtnl_link_alloc()))
+ {
+ qDebug() << _tag << "error. couldn't allocate a rtnl link";
+ return -1;
+ }
+ rtsock = nl_handle_alloc();
+ nl_connect(rtsock, NETLINK_ROUTE);
+ if (up)
+ {
+ rtnl_link_set_flags(request, IFF_UP);
+ }
+ else
+ {
+ rtnl_link_unset_flags(request, IFF_UP);
+ }
+
+ if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL)
+ {
+ qDebug() << _tag << "error with link cache alloc ";
+ }
+
+ old = rtnl_link_get_by_name(cache, ifn);
+ if (old)
+ {
+ qDebug() << _tag << "change link";
+ retval = rtnl_link_change(rtsock, old, request, 0);
+ }
+ else
+ {
+ qDebug() << _tag << "change failed";
+ retval = -1;
+ qDebug() << _tag << "return value:" << retval << ":" << strerror(-retval);
+ }
+
+ rtnl_link_put(old);
+ rtnl_link_put(request);
+ nl_handle_destroy(rtsock);
+
+ return retval;
+}
/**
* This method is used when the manual configuration is needed.
@@ -324,88 +341,93 @@ int NetworkManager::bringInterfaceUpDown(QString ifname, bool up) {
* @param nameServer
* the name server addresses.
*/
-int NetworkManager::ip4_setManualConfiguration(QString ifname, QString ipAddress, QString netmask,
- QString broadcast, QString gateway, int metric, int af, QString pathToResolvConf, QList<QString> nameServer) {
-
- //bring the interface up
- bringInterfaceUP(ifname);
- //set configuration
- ip4_configureInterface(ifname, ipAddress, broadcast, netmask,af);
- //set default route
- replaceDefaultRoute(ifname, gateway, metric, af);
- //write resolv.conf
- writeResolvConf(pathToResolvConf, ifname, nameServer);
- return 0;
-}
-
-
+int
+NetworkManager::ip4_setManualConfiguration(QString ifname, QString ipAddress,
+ QString netmask, QString broadcast, QString gateway, int metric, int af,
+ QString pathToResolvConf, QList<QString> nameServer)
+{
-int NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress,
- QString broadcast, QString netmask, int af) {
+ //bring the interface up
+ bringInterfaceUP(ifname);
+ //set configuration
+ ip4_configureInterface(ifname, ipAddress, broadcast, netmask, af);
+ //set default route
+ replaceDefaultRoute(ifname, gateway, metric, af);
+ //write resolv.conf
+ writeResolvConf(pathToResolvConf, ifname, nameServer);
+ return 0;
+}
- struct nl_cache *cache;
- struct nl_handle* rtsock;
- struct nl_addr * local;
- struct rtnl_addr * addr = NULL;
- int retval = 0;
- int iface_idx, err, prefixLength;
+int
+NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress,
+ QString broadcast, QString netmask, int af)
+{
- QByteArray ba_ifn = ifname.trimmed().toAscii();
- char * ifn = ba_ifn.data();
+ struct nl_cache *cache;
+ struct nl_handle* rtsock;
+ struct nl_addr * local;
+ struct rtnl_addr * addr = NULL;
+ int retval = 0;
+ int iface_idx, err, prefixLength;
- QByteArray ba_ip = ipAddress.trimmed().toAscii();
- char * ipaddr = ba_ip.data();
+ QByteArray ba_ifn = ifname.trimmed().toAscii();
+ char * ifn = ba_ifn.data();
- QByteArray ba_bc = broadcast.trimmed().toAscii();
- char * bcaddr = ba_bc.data();
+ QByteArray ba_ip = ipAddress.trimmed().toAscii();
+ char * ipaddr = ba_ip.data();
- rtsock = nl_handle_alloc();
- nl_connect(rtsock, NETLINK_ROUTE);
+ QByteArray ba_bc = broadcast.trimmed().toAscii();
+ char * bcaddr = ba_bc.data();
- if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) {
- qDebug() << _tag << "error with link cache alloc";
- return -1;
- }
+ rtsock = nl_handle_alloc();
+ nl_connect(rtsock, NETLINK_ROUTE);
- iface_idx = rtnl_link_name2i(cache, ifn);
+ if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL)
+ {
+ qDebug() << _tag << "error with link cache alloc";
+ return -1;
+ }
- if (!(addr = rtnl_addr_alloc())) {
- qDebug() << _tag << "error with addr alloc";
- return -1;
- }
+ iface_idx = rtnl_link_name2i(cache, ifn);
- local = nl_addr_parse(ipaddr, af);
- err = rtnl_addr_set_local(addr, local);
- nl_addr_put(local);
- if (err != 0) {
- qDebug() << _tag << "error with set local addr";
- }
+ if (!(addr = rtnl_addr_alloc()))
+ {
+ qDebug() << _tag << "error with addr alloc";
+ return -1;
+ }
- prefixLength = ip4_netmaskToPrefix(ipAddress,netmask);
- qDebug() << _tag << "prefix length:" << prefixLength;
- rtnl_addr_set_prefixlen(addr, prefixLength);
+ local = nl_addr_parse(ipaddr, af);
+ err = rtnl_addr_set_local(addr, local);
+ nl_addr_put(local);
+ if (err != 0)
+ {
+ qDebug() << _tag << "error with set local addr";
+ }
- local = nl_addr_parse(bcaddr, af);
- err = rtnl_addr_set_broadcast(addr, local);
- nl_addr_put(local);
- if (err != 0) {
- qDebug() << _tag << "error with set broadcast addr";
- }
+ prefixLength = ip4_netmaskToPrefix(ipAddress, netmask);
+ qDebug() << _tag << "prefix length:" << prefixLength;
+ rtnl_addr_set_prefixlen(addr, prefixLength);
- rtnl_addr_set_ifindex(addr, iface_idx);
+ local = nl_addr_parse(bcaddr, af);
+ err = rtnl_addr_set_broadcast(addr, local);
+ nl_addr_put(local);
+ if (err != 0)
+ {
+ qDebug() << _tag << "error with set broadcast addr";
+ }
+ rtnl_addr_set_ifindex(addr, iface_idx);
- retval = sync_address(ifn, iface_idx, af, addr);
- if(retval < 0) {
- qDebug() << _tag << "error in sync_address";
- }
- rtnl_addr_put(addr);
+ retval = sync_address(ifn, iface_idx, af, addr);
+ if (retval < 0)
+ {
+ qDebug() << _tag << "error in sync_address";
+ }
+ rtnl_addr_put(addr);
- return retval;
+ return retval;
}
-
-
/**
* This Method returns the length of the IP-Address netmask prefix.
*
@@ -417,235 +439,255 @@ int NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress,
* @return
* the length of the IP-Address netmask prefix
*/
-int NetworkManager::ip4_netmaskToPrefix(QString ipAddr, QString netmask) {
- int retval = -1;
- QNetworkAddressEntry nae;
-
- if (netmask == "") {
- qDebug() << _tag << "error: netmask is empty";
- return retval;
- }
- nae.setIp(QHostAddress(ipAddr));
- nae.setNetmask(QHostAddress(netmask.trimmed()));
- retval = nae.prefixLength();
-
- return retval;
-}
-
-
+int
+NetworkManager::ip4_netmaskToPrefix(QString ipAddr, QString netmask)
+{
+ int retval = -1;
+ QNetworkAddressEntry nae;
-int NetworkManager::ip6_addAddress(struct ip6_addr* ip6Addr, const char *iface) {
- int num_addrs, i, iface_idx;
- struct rtnl_addr* addr = NULL;
- struct nl_cache *cache;
- struct nl_handle* rtsock;
+ if (netmask == "")
+ {
+ qDebug() << _tag << "error: netmask is empty";
+ return retval;
+ }
+ nae.setIp(QHostAddress(ipAddr));
+ nae.setNetmask(QHostAddress(netmask.trimmed()));
+ retval = nae.prefixLength();
- rtsock = nl_handle_alloc();
- nl_connect(rtsock, NETLINK_ROUTE);
+ return retval;
+}
- if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) {
- qDebug() << _tag << "error with link cache alloc";
- return -1;
- }
+int
+NetworkManager::ip6_addAddress(struct ip6_addr* ip6Addr, const char *iface)
+{
+ int num_addrs, i, iface_idx;
+ struct rtnl_addr* addr = NULL;
+ struct nl_cache *cache;
+ struct nl_handle* rtsock;
+
+ rtsock = nl_handle_alloc();
+ nl_connect(rtsock, NETLINK_ROUTE);
+
+ if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL)
+ {
+ qDebug() << _tag << "error with link cache alloc";
+ return -1;
+ }
- iface_idx = rtnl_link_name2i(cache, iface);
+ iface_idx = rtnl_link_name2i(cache, iface);
- addr = ip6AddrToRtnlAddr(ip6Addr);
- if (!addr) {
- //nm_warning("couldn't create rtnl address!\n");
- return -1;
- }
- rtnl_addr_set_ifindex(addr, iface_idx);
+ addr = ip6AddrToRtnlAddr(ip6Addr);
+ if (!addr)
+ {
+ //nm_warning("couldn't create rtnl address!\n");
+ return -1;
+ }
+ rtnl_addr_set_ifindex(addr, iface_idx);
- return sync_address(iface, iface_idx, AF_INET6, addr);
+ return sync_address(iface, iface_idx, AF_INET6, addr);
}
-
-
/**/
-struct rtnl_addr* NetworkManager::ip6AddrToRtnlAddr(struct ip6_addr* ip6Addr) {
- struct rtnl_addr *addr;
- bool success = true;
+struct rtnl_addr*
+NetworkManager::ip6AddrToRtnlAddr(struct ip6_addr* ip6Addr)
+{
+ struct rtnl_addr *addr;
+ bool success = true;
- if (!(addr = rtnl_addr_alloc()))
- return NULL;
+ if (!(addr = rtnl_addr_alloc()))
+ return NULL;
- success = (nlAddrToRtnlAddr(ip6Addr, addr) >= 0);
+ success = (nlAddrToRtnlAddr(ip6Addr, addr) >= 0);
- if (!success) {
- rtnl_addr_put(addr);
- addr = NULL;
- }
+ if (!success)
+ {
+ rtnl_addr_put(addr);
+ addr = NULL;
+ }
- return addr;
+ return addr;
}
-
-
/**/
-struct nl_addr* NetworkManager::ip6AddrToNlAddr(const struct ip6_addr *ip6Addr) {
- struct nl_addr * nla = NULL;
+struct nl_addr*
+NetworkManager::ip6AddrToNlAddr(const struct ip6_addr *ip6Addr)
+{
+ struct nl_addr * nla = NULL;
- if (!(nla = nl_addr_alloc(sizeof(struct in6_addr))))
- return NULL;
- nl_addr_set_family(nla, AF_INET6);
- nl_addr_set_binary_addr(nla, (struct in6_addr *) ip6Addr, sizeof(struct in6_addr));
+ if (!(nla = nl_addr_alloc(sizeof(struct in6_addr))))
+ return NULL;
+ nl_addr_set_family(nla, AF_INET6);
+ nl_addr_set_binary_addr(nla, (struct in6_addr *) ip6Addr,
+ sizeof(struct in6_addr));
- return nla;
+ return nla;
}
-
-
/**/
-int NetworkManager::nlAddrToRtnlAddr(
- const struct ip6_addr* ip6Addr, struct rtnl_addr* addr) {
- struct nl_addr * local = NULL;
- int err = 0;
+int
+NetworkManager::nlAddrToRtnlAddr(const struct ip6_addr* ip6Addr,
+ struct rtnl_addr* addr)
+{
+ struct nl_addr * local = NULL;
+ int err = 0;
- local = ip6AddrToNlAddr(ip6Addr);
- err = rtnl_addr_set_local(addr, local);
- nl_addr_put(local);
+ local = ip6AddrToNlAddr(ip6Addr);
+ err = rtnl_addr_set_local(addr, local);
+ nl_addr_put(local);
- return -err;
+ return -err;
}
-
-
/**
* delete all addresses of this interface but not the one we just set
*
* @return
* -1 if something went wrong. else 0
*/
-int NetworkManager::sync_address(const char *iface, int ifindex, int family,
- struct rtnl_addr *addr) {
-
- struct nl_handle *nlh;
- struct nl_cache *addr_cache;
- struct rtnl_addr *filter_addr, *match_addr;
- struct nl_object *match;
- struct nl_addr *nladdr;
- int err;
- char buf[INET6_ADDRSTRLEN + 1];
-
- nlh = nl_handle_alloc();
- nl_connect(nlh, NETLINK_ROUTE);
-
- if (!nlh)
- return -1;
-
- addr_cache = rtnl_addr_alloc_cache(nlh);
-
- if (!addr_cache)
- return -1;
-
- filter_addr = rtnl_addr_alloc();
- if (!filter_addr) {
- nl_cache_free(addr_cache);
- return -1;
- }
- rtnl_addr_set_ifindex(filter_addr, ifindex);
- if (family)
- rtnl_addr_set_family(filter_addr, family);
-
- //nm_log_dbg (log_domain, "(%s): syncing addresses (family %d)", iface, family);
-
- /* Walk through the cache, comparing the addresses already on
- * the interface to the addresses in addrs.
- */
- for (match = nl_cache_get_first(addr_cache); match; match
- = nl_cache_get_next(match)) {
- int buf_valid = -1;
- match_addr = (struct rtnl_addr *) match;
-
- /* Skip addresses not on our interface */
- if (!nl_object_match_filter(match, (struct nl_object *) filter_addr))
- continue;
-
- if (addr) {
- if (addr && nl_object_identical(match, (struct nl_object *) addr)) {
- continue;
- }
- }
-
- nladdr = rtnl_addr_get_local(match_addr);
-
- /* Don't delete IPv6 link-local addresses; they don't belong to NM */
- if (rtnl_addr_get_family(match_addr) == AF_INET6) {
- struct in6_addr *tmp;
-
- if (rtnl_addr_get_scope(match_addr) == RT_SCOPE_LINK) {
- //nm_log_dbg (log_domain, "(%s): ignoring IPv6 link-local address", iface);
- continue;
- }
-
- tmp = (in6_addr*) nl_addr_get_binary_addr(nladdr);
- if (inet_ntop(AF_INET6, tmp, buf, sizeof(buf)))
- buf_valid = 0;
- } else if (rtnl_addr_get_family(match_addr) == AF_INET) {
- struct in_addr *tmp;
-
- tmp = (in_addr *) nl_addr_get_binary_addr(nladdr);
- if (inet_ntop(AF_INET, tmp, buf, sizeof(buf)))
- buf_valid = 0;
- }
-
- if (buf_valid == 0) {
- //nm_log_dbg (log_domain, "(%s): removing address '%s/%d'",
- // iface, buf, nl_addr_get_prefixlen (nladdr));
- }
-
- /* Otherwise, match_addr should be removed from the interface. */
- err = rtnl_addr_delete(nlh, match_addr, 0);
- if (err < 0) {
- //nm_log_err (log_domain, "(%s): error %d returned from rtnl_addr_delete(): %s",
- // iface, err, nl_geterror ());
- qDebug() << _tag << "error with delete addr";
- }
- }
-
- rtnl_addr_put(filter_addr);
- nl_cache_free(addr_cache);
-
- /* Now add the remaining new addresses */
- if (!addr)
- return -1;
-
- struct in6_addr *in6tmp;
- struct in_addr *in4tmp;
- int buf_valid = -1;
-
- nladdr = rtnl_addr_get_local(addr);
- if (rtnl_addr_get_family(addr) == AF_INET6) {
- in6tmp = (in6_addr*) nl_addr_get_binary_addr(nladdr);
- if (inet_ntop(AF_INET6, in6tmp, buf, sizeof(buf)))
- buf_valid = 0;
- } else if (rtnl_addr_get_family(addr) == AF_INET) {
- in4tmp = (in_addr*) nl_addr_get_binary_addr(nladdr);
- if (inet_ntop(AF_INET, in4tmp, buf, sizeof(buf)))
- buf_valid = 0;
- }
-
- if (buf_valid == 0) {
- //nm_log_dbg (log_domain, "(%s): adding address '%s/%d'",
- //iface, buf, nl_addr_get_prefixlen (nladdr));
- qDebug() << _tag << "buf valid adding addr";
- }
-
- err = rtnl_addr_add(nlh, addr, 0);
- if (err < 0) {
- //nm_log_err (log_domain,
- // "(%s): error %d returned from rtnl_addr_add():\n%s",
- // iface, err, nl_geterror ());
- qDebug() << _tag << "error with add addr"<< strerror(-err);
- }
-
- rtnl_addr_put(addr);
-
- return err;
-}
+int
+NetworkManager::sync_address(const char *iface, int ifindex, int family,
+ struct rtnl_addr *addr)
+{
+
+ struct nl_handle *nlh;
+ struct nl_cache *addr_cache;
+ struct rtnl_addr *filter_addr, *match_addr;
+ struct nl_object *match;
+ struct nl_addr *nladdr;
+ int err;
+ char buf[INET6_ADDRSTRLEN + 1];
+
+nlh = nl_handle_alloc();
+ nl_connect(nlh, NETLINK_ROUTE);
+ if (!nlh)
+ return -1;
+ addr_cache = rtnl_addr_alloc_cache(nlh);
+
+ if (!addr_cache)
+ return -1;
+
+ filter_addr = rtnl_addr_alloc();
+ if (!filter_addr)
+ {
+ nl_cache_free(addr_cache);
+ return -1;
+ }
+ rtnl_addr_set_ifindex(filter_addr, ifindex);
+ if (family)
+ rtnl_addr_set_family(filter_addr, family);
+
+ //nm_log_dbg (log_domain, "(%s): syncing addresses (family %d)", iface, family);
+
+ /* Walk through the cache, comparing the addresses already on
+ * the interface to the addresses in addrs.
+ */
+ for (match = nl_cache_get_first(addr_cache); match;
+ match = nl_cache_get_next(match))
+ {
+ int buf_valid = -1;
+ match_addr = (struct rtnl_addr *) match;
+
+ /* Skip addresses not on our interface */
+ if (!nl_object_match_filter(match, (struct nl_object *) filter_addr))
+ continue;
+
+ if (addr)
+ {
+ if (addr && nl_object_identical(match, (struct nl_object *) addr))
+ {
+ continue;
+ }
+ }
+
+ nladdr = rtnl_addr_get_local(match_addr);
+
+ /* Don't delete IPv6 link-local addresses; they don't belong to NM */
+ if (rtnl_addr_get_family(match_addr) == AF_INET6)
+ {
+ struct in6_addr *tmp;
+
+ if (rtnl_addr_get_scope(match_addr) == RT_SCOPE_LINK)
+ {
+ //nm_log_dbg (log_domain, "(%s): ignoring IPv6 link-local address", iface);
+ continue;
+ }
+
+ tmp = (in6_addr*) nl_addr_get_binary_addr(nladdr);
+ if (inet_ntop(AF_INET6, tmp, buf, sizeof(buf)))
+ buf_valid = 0;
+ }
+ else if (rtnl_addr_get_family(match_addr) == AF_INET)
+ {
+ struct in_addr *tmp;
+
+ tmp = (in_addr *) nl_addr_get_binary_addr(nladdr);
+ if (inet_ntop(AF_INET, tmp, buf, sizeof(buf)))
+ buf_valid = 0;
+ }
+
+ if (buf_valid == 0)
+ {
+ //nm_log_dbg (log_domain, "(%s): removing address '%s/%d'",
+ // iface, buf, nl_addr_get_prefixlen (nladdr));
+ }
+
+ /* Otherwise, match_addr should be removed from the interface. */
+ err = rtnl_addr_delete(nlh, match_addr, 0);
+ if (err < 0)
+ {
+ //nm_log_err (log_domain, "(%s): error %d returned from rtnl_addr_delete(): %s",
+ // iface, err, nl_geterror ());
+ qDebug() << _tag << "error with delete addr";
+ }
+ }
+
+rtnl_addr_put(filter_addr);
+nl_cache_free(addr_cache);
+
+/* Now add the remaining new addresses */
+if (!addr)
+ return -1;
+
+struct in6_addr *in6tmp;
+struct in_addr *in4tmp;
+int buf_valid = -1;
+
+nladdr = rtnl_addr_get_local(addr);
+if (rtnl_addr_get_family(addr) == AF_INET6)
+ {
+ in6tmp = (in6_addr*) nl_addr_get_binary_addr(nladdr);
+ if (inet_ntop(AF_INET6, in6tmp, buf, sizeof(buf)))
+ buf_valid = 0;
+ }
+else if (rtnl_addr_get_family(addr) == AF_INET)
+ {
+ in4tmp = (in_addr*) nl_addr_get_binary_addr(nladdr);
+ if (inet_ntop(AF_INET, in4tmp, buf, sizeof(buf)))
+ buf_valid = 0;
+ }
+
+if (buf_valid == 0)
+ {
+ //nm_log_dbg (log_domain, "(%s): adding address '%s/%d'",
+ //iface, buf, nl_addr_get_prefixlen (nladdr));
+ qDebug() << _tag << "buf valid adding addr";
+ }
+
+err = rtnl_addr_add(nlh, addr, 0);
+if (err < 0)
+ {
+ //nm_log_err (log_domain,
+ // "(%s): error %d returned from rtnl_addr_add():\n%s",
+ // iface, err, nl_geterror ());
+ qDebug() << _tag << "error with add addr" << strerror(-err);
+ }
+
+rtnl_addr_put(addr);
+
+return err;
+}
/**
* This method writes a resolv.conf file.
@@ -661,21 +703,28 @@ int NetworkManager::sync_address(const char *iface, int ifindex, int family,
* return 0 if success
* else -1
*/
-int NetworkManager::writeResolvConf(QString path, QString ifname, QList<QString> nameServer){
-
- QFile file(path + "resolv.conf");
- if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- qDebug() << _tag << "error couldn't open file:" << path;
- return -1;
- }
- QTextStream out(&file);
- out << "# Generated by networkdiscovery manual configuration for interface " + ifname +"\n";
- foreach(QString ns, nameServer ) {
- out << "nameserver " + ns +"\n";
- }
+int
+NetworkManager::writeResolvConf(QString path, QString ifname,
+ QList<QString> nameServer)
+{
+
+QFile file(path + "resolv.conf");
+if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
+ {
+ qDebug() << _tag << "error couldn't open file:" << path;
+ return -1;
+ }
+QTextStream out(&file);
+out
+ << "# Generated by networkdiscovery manual configuration for interface "
+ + ifname + "\n";
+foreach(QString ns, nameServer )
+ {
+ out << "nameserver " + ns + "\n";
+}
- file.close();
+file.close();
- return 0;
+return 0;
}
diff --git a/src/fbgui/networkmanager.h b/src/fbgui/networkmanager.h
index fbb8993..2ef6ff8 100644
--- a/src/fbgui/networkmanager.h
+++ b/src/fbgui/networkmanager.h
@@ -29,43 +29,44 @@
#include <QtCore>
#include <QNetworkAddressEntry>
-class NetworkManager: public QObject {
-Q_OBJECT
+class NetworkManager: public QObject
+{
+ Q_OBJECT
public:
- NetworkManager();
- virtual ~NetworkManager();
+ NetworkManager();
+ virtual ~NetworkManager();
- int replaceDefaultRoute(QString ifname, QString gateway, int metric,
- int af);
+ int replaceDefaultRoute(QString ifname, QString gateway, int metric,
+ int af);
- int bringInterfaceUP(QString ifname);
- int bringInterfaceDown(QString ifname);
+ int bringInterfaceUP(QString ifname);
+ int bringInterfaceDown(QString ifname);
- int ip4_setManualConfiguration(QString ifname, QString ipAddress, QString netmask,
- QString broadcast, QString gateway, int metric, int af, QString pathToResolvConf, QList<QString> nameServer);
- int ip4_configureInterface(QString ifname, QString ipAddress,
- QString broadcast, QString netmask, int af);
+ int ip4_setManualConfiguration(QString ifname, QString ipAddress, QString netmask,
+ QString broadcast, QString gateway, int metric, int af, QString pathToResolvConf, QList<QString> nameServer);
+ int ip4_configureInterface(QString ifname, QString ipAddress,
+ QString broadcast, QString netmask, int af);
- int ip6_addRoute(const char *iface,
- const struct in6_addr *ip6_dest, int ip6_prefix,
- const struct in6_addr *ip6_gateway, int metric, int mss);
- int ip6_addAddress(struct ip6_addr* ip6Addr, const char *iface);
+ int ip6_addRoute(const char *iface,
+ const struct in6_addr *ip6_dest, int ip6_prefix,
+ const struct in6_addr *ip6_gateway, int metric, int mss);
+ int ip6_addAddress(struct ip6_addr* ip6Addr, const char *iface);
- int writeResolvConf(QString path, QString ifname, QList<QString> nameServer);
+ int writeResolvConf(QString path, QString ifname, QList<QString> nameServer);
private:
- QString _tag;
- int bringInterfaceUpDown(QString ifname, bool up);
- int ip4_netmaskToPrefix(QString ipAddr, QString netmask);
+ QString _tag;
+ int bringInterfaceUpDown(QString ifname, bool up);
+ int ip4_netmaskToPrefix(QString ipAddr, QString netmask);
- int sync_address(const char *iface, int ifindex, int family,
- struct rtnl_addr *addr);
+ int sync_address(const char *iface, int ifindex, int family,
+ struct rtnl_addr *addr);
- struct rtnl_route* create_route (int iface_idx, int mss);
- struct nl_addr* ip6AddrToNlAddr (const struct ip6_addr* ip6Addr);
- int nlAddrToRtnlAddr (const struct ip6_addr* ip6Addr, struct rtnl_addr* addr);
- struct rtnl_addr* ip6AddrToRtnlAddr(struct ip6_addr* ip6Addr);
+ struct rtnl_route* create_route (int iface_idx, int mss);
+ struct nl_addr* ip6AddrToNlAddr (const struct ip6_addr* ip6Addr);
+ int nlAddrToRtnlAddr (const struct ip6_addr* ip6Addr, struct rtnl_addr* addr);
+ struct rtnl_addr* ip6AddrToRtnlAddr(struct ip6_addr* ip6Addr);
};
diff --git a/src/fbgui/qlog4cxx.h b/src/fbgui/qlog4cxx.h
new file mode 100644
index 0000000..d2f73a4
--- /dev/null
+++ b/src/fbgui/qlog4cxx.h
@@ -0,0 +1,25 @@
+/*
+ * qlog4cxx.h
+ *
+ * Created on: Dec 3, 2011
+ * Author: ssc
+ */
+
+#ifndef QLOG4CXX_H_
+#define QLOG4CXX_H_
+
+namespace std
+{
+ inline ostream& operator<<(ostream& os, const QString& a)
+ {
+ return os << a.toStdString();
+ }
+
+ inline ostream& operator<<(ostream& os, const QByteArray& a)
+ {
+ return os << a.constData();
+ }
+
+}
+
+#endif /* QLOG4CXX_H_ */
diff --git a/src/fbgui/sysinfo.cpp b/src/fbgui/sysinfo.cpp
index 7d6ac92..59fe577 100644
--- a/src/fbgui/sysinfo.cpp
+++ b/src/fbgui/sysinfo.cpp
@@ -1,5 +1,14 @@
#include "sysinfo.h"
+
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr siLogger(Logger::getLogger("fbgui.sysinfo"));
+
+
// ------------------------------------------------------------------------------------------------
/**
* A empty constructor.
@@ -32,13 +41,13 @@ SysInfo::~SysInfo() {
* @see JavascriptInterface::getSysInfo(const QString& info)
*/
const QString SysInfo::getInfo(const QString& infoName) {
- qxtLog->debug() << "[sysinfo] requested " << infoName;
+ LOG4CXX_DEBUG(siLogger, "[sysinfo] requested " << infoName);
if (infoName == QString("mbserial"))
return getMainboardSerial();
else if (infoName == QString("usb"))
return getUsbVendorIdProductIdSerialNumber();
/* unknown code */
- qxtLog->debug() << "[sysinfo] unknown requested";
+ LOG4CXX_DEBUG(siLogger, "[sysinfo] unknown requested");
return "info_error";
}
// -----------------------------------------------------------------------------------------------
@@ -74,11 +83,10 @@ const QString SysInfo::getMainboardSerial() {
out = QString(attr->value);
}
}
- qxtLog->debug() << "[sysinfo] Mainboard Serial: " + out;
+ LOG4CXX_DEBUG(siLogger, "[sysinfo] Mainboard Serial: " + out);
return out;
}
- qxtLog->debug()
- << "[sysinfo] Mainboard Serial: attrlist is null! return: mainboard_serial_error";
+ LOG4CXX_DEBUG(siLogger, "[sysinfo] Mainboard Serial: attrlist is null! return: mainboard_serial_error");
sysfs_close_class_device(class_device);
return "mainboard_serial_error";
}
@@ -116,14 +124,14 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() {
int r = 1;
r = libusb_init(&ctx);
if (r < 0) {
- qxtLog->debug() << tag + "failed to initialise libusb";
+ LOG4CXX_DEBUG(siLogger, tag + "failed to initialise libusb");
return "error";
}
cnt = libusb_get_device_list(ctx, &devs); //get the list of devices
if (cnt < 0) {
- qxtLog->debug() << tag + "Get Device Error"; //there was an error
+ LOG4CXX_DEBUG(siLogger, tag + "Get Device Error"); //there was an error
}
- qxtLog->debug() << tag + cnt + " Devices in list."; //print total number of usb devices
+ LOG4CXX_DEBUG(siLogger, tag + cnt + " Devices in list."); //print total number of usb devices
ssize_t i; //for iterating through the list#
for (i = 0; i < cnt; i++) {
//printdev(devs[i]); //print specs of this device
@@ -132,7 +140,7 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() {
libusb_device_descriptor desc;
int re = libusb_get_device_descriptor(dev, &desc);
if (re < 0) {
- qxtLog->debug() << tag + "failed to get device descriptor";
+ LOG4CXX_DEBUG(siLogger, tag + "failed to get device descriptor");
return "error";
}
infos.insert("vendorId", desc.idVendor);
@@ -141,27 +149,27 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() {
libusb_device_handle *handle;
re = libusb_open(dev, &handle);
if (re != 0) {
- qxtLog->debug() << tag + "failed to get handler / fail to open device";
+ LOG4CXX_DEBUG(siLogger, tag + "failed to get handler / fail to open device");
return "error";
}
re = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber,
string, sizeof(string));
if (re < 0) {
- qxtLog->debug() << tag + "failed to get SerialNumber";
+ LOG4CXX_DEBUG(siLogger, tag + "failed to get SerialNumber");
return "error";
}
infos.insert("serialnumber", QString((const char *) string));
re = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string,
sizeof(string));
if (re < 0) {
- qxtLog->debug() << tag + "failed to get Product";
+ LOG4CXX_DEBUG(siLogger, tag + "failed to get Product");
return "error";
}
infos.insert("product", QString((const char *) string));
re = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer,
string, sizeof(string));
if (re < 0) {
- qxtLog->debug() << tag + "failed to get Product";
+ LOG4CXX_DEBUG(siLogger, tag + "failed to get Product");
return "error";
}
infos.insert("manuacturer", QString((const char *) string));
@@ -174,7 +182,7 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() {
/*
QByteArray json = serializer.serialize(list);
- qxtLog->debug() << tag + "json object: " + json;
+ LOG4CXX_DEBUG(siLogger, tag + "json object: " + json);
return json;
*/
}
diff --git a/src/fbgui/sysinfo.h b/src/fbgui/sysinfo.h
index c860cca..a4c5a48 100644
--- a/src/fbgui/sysinfo.h
+++ b/src/fbgui/sysinfo.h
@@ -31,20 +31,21 @@ extern "C" {
#include "fbgui.h"
//#include <qjson/serializer.h>
-class SysInfo {
+class SysInfo
+{
public:
- SysInfo();
- ~SysInfo();
- // public access, valid infoName: "mbserial", "usb"
- const QString getInfo(const QString& infoName);
+ SysInfo();
+ ~SysInfo();
+ // public access, valid infoName: "mbserial", "usb"
+ const QString getInfo(const QString& infoName);
private:
- // private system information readers
- const QString getMainboardSerial();
- const QString getUsbVendorIdProductIdSerialNumber();
+ // private system information readers
+ const QString getMainboardSerial();
+ const QString getUsbVendorIdProductIdSerialNumber();
- // JSon testing
- //QJson::Serializer serializer;
+ // JSon testing
+ //QJson::Serializer serializer;
};
#endif // SYSTINFO_H