summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-06-28 10:51:08 +0200
committerNiklas2011-06-28 10:51:08 +0200
commit2842ca3160966ed1633f9d6605531e18b435de61 (patch)
treed705e55b3307985da28307e24b7ac33a0e024cce
parentadded the networkDiscovery project into a new workspace folder (diff)
parentbuild.sh dummy (diff)
downloadfbgui-2842ca3160966ed1633f9d6605531e18b435de61.tar.gz
fbgui-2842ca3160966ed1633f9d6605531e18b435de61.tar.xz
fbgui-2842ca3160966ed1633f9d6605531e18b435de61.zip
Merge branch 'master' of git.openslx.org:lsfks/projekte/fbgui
-rw-r--r--AUTHORS8
-rw-r--r--README28
-rwxr-xr-xbuild-pkg.sh36
-rw-r--r--[-rwxr-xr-x]build.sh32
-rw-r--r--fbgui.conf3
-rw-r--r--src/downloadmanager.cpp342
-rw-r--r--src/downloadmanager.h109
-rw-r--r--src/fbgui.cpp561
-rw-r--r--src/fbgui.h159
-rw-r--r--src/fbgui.qrc6
-rw-r--r--src/html/background.pngbin0 -> 364392 bytes
-rw-r--r--src/html/loadsystem.css90
-rw-r--r--src/html/loadsystem.html35
-rw-r--r--src/html/old.png (renamed from src/html/bg.png)bin316905 -> 316905 bytes
-rw-r--r--src/html/preload-debug.html12
-rw-r--r--src/html/preload.css (renamed from src/html/style.css)16
-rw-r--r--src/html/preload.html11
-rw-r--r--src/javascriptinterface.cpp126
-rw-r--r--src/javascriptinterface.h96
-rw-r--r--src/loggerengine.cpp134
-rw-r--r--src/loggerengine.h74
-rw-r--r--src/main.cpp371
-rw-r--r--src/sysinfo.cpp324
-rw-r--r--src/sysinfo.h58
-rw-r--r--src/sysinfolibsysfs.cpp217
-rw-r--r--src/sysinfolibsysfs.h53
26 files changed, 1596 insertions, 1305 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..ca9c318
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,8 @@
+Master-Teamproject at Lehrstuhl fuer Kommunikationssysteme for Uni Freiburg, 2010-2011.
+Sub-Project: Framebuffer-GUI "fbgui"
+
+Authors:
+
+Jonathan Bauer <bauer at informatik.uni-freiburg.de>
+Niklas Goby <...>
+Sebastian Wagner <sebastian.wagner at mars.uni-freiburg.de>
diff --git a/README b/README
index f3bd686..8c226d1 100644
--- a/README
+++ b/README
@@ -1 +1,27 @@
-Framebuffer GUI for OpenSLX Preboot Environment
+*****************************************************************
+ Framebuffer GUI for OpenSLX Preboot Environment
+*****************************************************************
+General Information:
+ OpensLX: http://lab.openslx.org/projects/openslx
+ fbgui: http://lab.ks.uni-freiburg.de/projects/preboot/wiki
+
+*****************************************************************
+FAQ:
+
+What is this for?
+ Provides the user with an interactive graphical interface to
+ choose an OS which one he would like to boot.
+
+What does this do excatly?
+ fbgui was designed to provide a minimalistic browser that can be run directly on the framebuffer.
+ (Note: The website content is crucial to the successfull execution of this program!)
+
+How to build/use it?
+ Simply run ./build.sh to create a package of fbgui (including all the required libs).
+ To integrate into a Preboot-Media, follow instructions on the wiki.
+
+Dependancies:
+ QT-Framework
+ QXT-Framework (QT extension)
+ sysfsutils
+ (QJSon)
diff --git a/build-pkg.sh b/build-pkg.sh
new file mode 100755
index 0000000..f3f3c36
--- /dev/null
+++ b/build-pkg.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# this script requires fbgui to be compiled.
+# To compile use:
+# ./build.sh (TODO)
+
+QT_VERSION=QtEmbedded-4.7.2
+
+[ -f fbgui.tgz ] && rm fbgui.tgz
+
+mkdir -p pkg
+
+cd pkg
+
+mkdir -p bin
+cp ../src/fbgui bin
+
+mkdir -p usr/local/Trolltech/${QT_VERSION}/lib
+cp -r /usr/local/Trolltech/${QT_VERSION}/lib/fonts \
+ usr/local/Trolltech/${QT_VERSION}/lib/
+
+for SHARED_LIBRARY in `ldd ../src/fbgui | awk '{print $3}' |grep ^/`
+do
+#echo "$SHARED_LIBRARY"
+DIR=`dirname $SHARED_LIBRARY | cut -c2-`
+[ ! -d $DIR ] && mkdir -p $DIR
+[ ! -s "`echo $SHARED_LIBRARY | cut -c2-`" ] && \
+cp $SHARED_LIBRARY `echo $SHARED_LIBRARY | cut -c2-`
+done
+
+mkdir -p etc
+cp ../fbgui.conf etc
+
+tar czf ../fbgui.tgz usr etc lib bin
+
+cd - &> /dev/null
+rm -rf pkg
diff --git a/build.sh b/build.sh
index 8ea3fc5..4ed283b 100755..100644
--- a/build.sh
+++ b/build.sh
@@ -1,32 +1,2 @@
#!/bin/bash
-QT_VERSION=QtEmbedded-4.7.2
-
-rm fbgui.tgz
-
-mkdir -p pkg
-
-cd pkg
-
-mkdir -p bin
-cp ../src/fbgui bin
-
-mkdir -p usr/local/Trolltech/${QT_VERSION}/lib
-cp -r /usr/local/Trolltech/${QT_VERSION}/lib/fonts \
- usr/local/Trolltech/${QT_VERSION}/lib/
-
-for SHARED_LIBRARY in `ldd ../src/fbgui | awk '{print $3}' |grep ^/`
-do
-#echo "$SHARED_LIBRARY"
-DIR=`dirname $SHARED_LIBRARY | cut -c2-`
-[ ! -d $DIR ] && mkdir -p $DIR
-[ ! -s "`echo $SHARED_LIBRARY | cut -c2-`" ] && \
-cp $SHARED_LIBRARY `echo $SHARED_LIBRARY | cut -c2-`
-done
-
-mkdir -p etc
-cp ../fbgui.conf etc
-
-tar czf ../fbgui.tgz usr etc lib bin
-
-cd - &> /dev/null
-rm -rf pkg
+# TODO auto-compiler with cmake
diff --git a/fbgui.conf b/fbgui.conf
index ac2cecb..af0b39f 100644
--- a/fbgui.conf
+++ b/fbgui.conf
@@ -1,7 +1,8 @@
[default]
-pbs_url=http://132.230.4.27
+pbs_url=http://pbs2.mp.openslx.org/fbgui
download_directory=/tmp
update_interval=5
file_trigger=/tmp/fbgui_trigger
serial_location=/serial
ip_config=/tmp/ip_config
+log_file=/tmp/fbgui.log
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index c772776..5bada3a 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -1,219 +1,215 @@
#include "downloadmanager.h"
-#include "fbgui.h"
-int DownloadManager::downloaded = 0;
+// static counter to save the number of successfully downloaded files.
+int DownloadManager::_downloaded = 0;
// -------------------------------------------------------------------------------------------------------
+// Initialisation
+// -------------------------------------------------------------------------------------------------------
+// Constructor initialises a QNetworkAccessManager needed to create/received download requests/replies
+// This object is then moved to the thread for the download manager, to ensure that downloads
+// are done in a separate thread (to avoid GUI blocking.)
+// The flag "_dip" starts as false, since no download is in progress.
+// This flag is needed to control queueing functionality.
+// Lastly the given download directory's existance is checked. (see below)
+
DownloadManager::DownloadManager() {
- qxtLog->debug() << "Initializing download manager...";
- checkDownloadDirectory();
- _qnam = new QNetworkAccessManager();
- //_qnam->moveToThread(&dmThread);
- dip = false;
+ qxtLog->debug() << "Initializing download manager...";
+ checkDownloadDirectory();
+ _qnam = new QNetworkAccessManager();
+ _qnam->moveToThread(&dmThread);
+ _dip = false;
}
+// Destructor
DownloadManager::~DownloadManager() {
- delete _qnam;
+ delete _qnam;
}
// -------------------------------------------------------------------------------------------------------
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.";
- // 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();
- // 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 {
- // just in case
- qxtLog->debug() << "[dm] Failed to create: "
- << downloadDir.absolutePath();
- qxtLog->debug() << "[dm] Exiting...";
- exit( EXIT_FAILURE);
- }
- } else
- qxtLog->debug() << "[dm] " << downloadDir.absolutePath()
- << " already exists.";
- }
- } else
- qxtLog->debug() << "[dm] Download directory: "
- << downloadDir.absolutePath() << " already exists.";
+ // check if downloadPath exists, if not create it.
+ _downloadDir = QDir(downloadPath);
+ if (!_downloadDir.exists()) {
+ qxtLog->debug() << "[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();
+ // 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 {
+ // just in case
+ qxtLog->debug() << "[dm] Failed to create: " << _downloadDir.absolutePath();
+ qxtLog->debug() << "[dm] Exiting...";
+ exit( EXIT_FAILURE);
+ }
+ } else
+ qxtLog->debug() << "[dm] " << _downloadDir.absolutePath() << " already exists.";
+ }
+ } else
+ qxtLog->debug() << "[dm] Download directory: " << _downloadDir.absolutePath()
+ << " already exists.";
- qxtLog->debug() << "[dm] Saving downloads to: "
- << downloadDir.absolutePath();
- downloadPath = downloadDir.absolutePath();
+ qxtLog->debug() << "[dm] Saving downloads to: " << _downloadDir.absolutePath();
+ downloadPath = _downloadDir.absolutePath();
}
// -------------------------------------------------------------------------------------------------------
// Public access
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadFile(const QString& filename) {
- QUrl fileUrl(baseURL.resolved(QUrl(filename)));
- this->processDownloadRequest(fileUrl);
+ QUrl fileUrl(baseURL.resolved(QUrl(filename)));
+ this->processDownloadRequest(fileUrl);
}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadFile(const QUrl& fileUrl) {
- this->processDownloadRequest(fileUrl);
+ this->processDownloadRequest(fileUrl);
}
// -------------------------------------------------------------------------------------------------------
// Private functions handling download requests and queueing
// -------------------------------------------------------------------------------------------------------
void DownloadManager::processDownloadRequest(const QUrl& url) {
- if (url.isEmpty()) {
- qxtLog->debug() << "[dm] No URL specified for download.";
- return;
- }
- qxtLog->debug() << "[dm] Enqueueing: " << url.toString();
- dlQ.enqueue(url);
- if (dip) {
- // download in progress, return.
- qxtLog->debug() << "[dm] Download in progress! Queued:"
- << url.toString() << "(" << dlQ.size() << " in queue)";
- return;
- }
- // no running downloads: start next in queue
- startNextDownload();
+ if (url.isEmpty()) {
+ qxtLog->debug() << "[dm] No URL specified for download.";
+ return;
+ }
+ qxtLog->debug() << "[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)";
+ return;
+ }
+ // no running downloads: start next in queue
+ startNextDownload();
}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::startNextDownload() {
- QWSServer::instance()->setCursorVisible(false);
- if (dlQ.isEmpty()) {
- emit downloadQueueEmpty();
- qxtLog->debug() << "[dm] Download manager ready. (1)";
- return;
- }
- qxtLog->debug() << "[dm] Starting next download: " << dlQ.head().toString()
- << " (" << dlQ.size() - 1 << " in queue.)";
+ QWSServer::instance()->setCursorVisible(false);
+ if (_downloadQueue.isEmpty()) {
+ emit downloadQueueEmpty();
+ qxtLog->debug() << "[dm] Download manager ready. (1)";
+ return;
+ }
+ qxtLog->debug() << "[dm] Starting next download: " << _downloadQueue.head().toString() << " ("
+ << _downloadQueue.size() - 1 << " in queue.)";
- // dequeue next URL to download.
- QUrl url = dlQ.dequeue();
+ // dequeue next URL to download.
+ QUrl url = _downloadQueue.dequeue();
- // get filename from URL.
- QString tmp = url.path();
- tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
+ // get filename from URL.
+ QString tmp = url.path();
+ tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
- // check if filename exists on target file system
- if (downloadDir.exists(tmp)) {
- qxtLog->debug() << "[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();
+ // check if filename exists on target file system
+ if (_downloadDir.exists(tmp)) {
+ qxtLog->debug() << "[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();
- // try to open for writing
- if (!outfile.open(QIODevice::WriteOnly)) {
- qxtLog->debug() << "[dm] No write access to " << outfile.fileName()
- << " . Skipping download...";
- return;
- }
+ // try to open for writing
+ if (!_outfile.open(QIODevice::WriteOnly)) {
+ qxtLog->debug() << "[dm] No write access to " << _outfile.fileName()
+ << " . Skipping download...";
+ return;
+ }
- // send the request for the file
- QNetworkRequest request(url);
- currentDownload = _qnam->get(request);
- lastProgress = 0;
- currentProgress = 0;
- dip = true;
- _time.start();
- QObject::connect(currentDownload, SIGNAL(readyRead()), this,
- SLOT(downloadReady()));
- QObject::connect(currentDownload, SIGNAL(metaDataChanged()), this,
- SLOT(processMetaInfo()));
- QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
- this, SLOT(downloadProgress(qint64, qint64)));
- QObject::connect(currentDownload, SIGNAL(finished()), this,
- SLOT(downloadFinished()));
+ // send the request for the file
+ QNetworkRequest request(url);
+ _currentDownload = _qnam->get(request);
+ _lastProgress = 0;
+ _currentProgress = 0;
+ _dip = true;
+ time.start();
+ QObject::connect(_currentDownload, SIGNAL(readyRead()), this, SLOT(
+ downloadReady()));
+ QObject::connect(_currentDownload, SIGNAL(metaDataChanged()), this, SLOT(
+ processMetaInfo()));
+ QObject::connect(_currentDownload, SIGNAL(downloadProgress(qint64, qint64)), this,
+ SLOT(downloadProgress(qint64, qint64)));
+ QObject::connect(_currentDownload, SIGNAL(finished()), this, SLOT(
+ downloadFinished()));
}
// -------------------------------------------------------------------------------------------------------
// Private slots to handle a download in progress
// -------------------------------------------------------------------------------------------------------
void DownloadManager::processMetaInfo() {
- // fetch filesize from header & filename from URL (for now)
- const QByteArray cltag = "Content-Length";
- QByteArray clinfo = currentDownload->rawHeader(cltag);
- QFileInfo fi(outfile);
- qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: "
- << clinfo.toDouble() << ")";
- emit downloadInfo(fi.fileName(), clinfo.toDouble());
+ // fetch filesize from header & filename from URL (for now)
+ const QByteArray cltag = "Content-Length";
+ QByteArray clinfo = _currentDownload->rawHeader(cltag);
+ QFileInfo fi(_outfile);
+ qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble()
+ << ")";
+ emit downloadInfo(fi.fileName(), clinfo.toDouble());
}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadReady() {
- // data ready, save it
- outfile.write(currentDownload->readAll());
+ // data ready, save it
+ _outfile.write(_currentDownload->readAll());
}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) {
- if (bytesIn > bytesTotal || bytesTotal <= 0) {
- qxtLog->debug() << "[dm] downloadProgress invalid values:" << "In:"
- << bytesIn << " / Total: " << bytesTotal;
- return;
- }
- // calculate current speed
- double speed = bytesIn * 1000 / _time.elapsed();
- QString unit;
- if (speed < 1024) {
- unit = "bytes/sec";
- } else if (speed < 1024 * 1024) {
- speed /= 1024;
- unit = "KB/s";
- } else {
- speed /= 1024 * 1024;
- unit = "MB/s";
- }
- // update progress only if difference higher than the updateInterval setting
- currentProgress = ((bytesIn * 100) / bytesTotal);
- if (currentProgress - lastProgress >= updateInterval) {
- lastProgress = currentProgress;
- emit
- updateProgress(currentProgress, speed, unit);
- qxtLog->debug() << "[dm] Download progress of "
- << currentDownload->url().toString() << ": " << bytesIn << "/"
- << bytesTotal << "(" << currentProgress << "\%)";
- }
+ if (bytesIn > bytesTotal || bytesTotal <= 0) {
+ qxtLog->debug() << "[dm] downloadProgress invalid values:" << "In:" << bytesIn
+ << " / Total: " << bytesTotal;
+ return;
+ }
+ // calculate current speed
+ double speed = bytesIn * 1000 / time.elapsed();
+ QString unit;
+ if (speed < 1024) {
+ unit = "bytes/sec";
+ } else if (speed < 1024 * 1024) {
+ speed /= 1024;
+ unit = "KB/s";
+ } else {
+ speed /= 1024 * 1024;
+ unit = "MB/s";
+ }
+ // update progress only if difference higher than the updateInterval setting
+ _currentProgress = ((bytesIn * 100) / bytesTotal);
+ if (_currentProgress - _lastProgress >= updateInterval) {
+ _lastProgress = _currentProgress;
+ emit
+ updateProgress(_currentProgress, speed, unit);
+ qxtLog->debug() << "[dm] Download progress of " << _currentDownload->url().toString() << ": "
+ << bytesIn << "/" << bytesTotal << "(" << _currentProgress << "\%)";
+ }
}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadFinished() {
- // check for errors
- if (currentDownload->error()) {
- outfile.close();
- outfile.remove();
- int statusCode = currentDownload->attribute(
- QNetworkRequest::HttpStatusCodeAttribute).toInt();
- qxtLog->debug() << "[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();
- } else {
- // end download
- outfile.close();
- downloaded++;
- qxtLog->debug() << "[dm] Download of "
- << currentDownload->url().toString()
- << " finished. (downloaded = " << downloaded << ")";
- emit
- notify(
- QString("Successfully downloaded %1").arg(
- currentDownload->url().toString()));
- currentDownload->deleteLater();
- }
- dip = false;
- // process next in queue, if any
- if (dlQ.isEmpty()) {
- emit downloadQueueEmpty();
- qxtLog->debug() << "[dm] Download manager ready. (2)";
- return;
- }
- startNextDownload();
+ // check for errors
+ if (_currentDownload->error()) {
+ _outfile.close();
+ _outfile.remove();
+ int statusCode =
+ _currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ qxtLog->debug() << "[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();
+ } else {
+ // end download
+ _outfile.close();
+ _downloaded++;
+ qxtLog->debug() << "[dm] Download of " << _currentDownload->url().toString()
+ << " finished. (downloaded = " << _downloaded << ")";
+ emit
+ notify(QString("Successfully downloaded %1").arg(_currentDownload->url().toString()));
+ _currentDownload->deleteLater();
+ }
+ _dip = false;
+ // process next in queue, if any
+ if (_downloadQueue.isEmpty()) {
+ emit downloadQueueEmpty();
+ qxtLog->debug() << "[dm] Download manager ready. (2)";
+ return;
+ }
+ startNextDownload();
}
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index a7afe23..62df4bc 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -1,21 +1,21 @@
/*
- # 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
- #
- #
- # Class managing download requests:
- # - provides queueing functionality
- # - static info: filename, filesize
- # - dynamic info: download progress, current speed
- #
+ * 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
+ *
+ *
+ * Class managing download requests:
+ * - provides queueing functionality
+ * - static info: filename, filesize
+ * - dynamic info: download progress, current speed
+ *
*/
#ifndef DOWNLOADMANAGER_H
@@ -33,53 +33,52 @@ 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> dlQ;
- 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.cpp b/src/fbgui.cpp
index 8d2135a..9e3dba5 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -10,7 +10,8 @@
#include <QtWebKit>
#include <QxtCore>
-//QThread dmThread;
+QThread dmThread;
+QString logFilePath("");
QString ipConfigFilePath("");
QString binPath("");
QUrl baseURL("");
@@ -33,63 +34,59 @@ int debugMode = -1;
* @see DownloadManager
*/
fbgui::fbgui() {
- // test for libsys function
- //SysInfoLibsysfs* sil = new SysInfoLibsysfs();
- //sil->getInfoAboutNetworkInterface();
- //sil->getInfoMainboardSerial();
- //SysInfo si;
- //qxtLog->debug() << si.getInfo("mbserial");
- //si.getInfo("usb");
- setupLayout();
- createActions();
+ // test for libsys function
+ //SysInfo si;
+ //qxtLog->debug() << si.getInfo("mbserial");
+ //si.getInfo("usb");
- // initialize javascript interface
- JavascriptInterface* jsi = new JavascriptInterface(
- _webView->page()->mainFrame());
- QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));
- QObject::connect(jsi, SIGNAL(shutDownClient()), this, SLOT(
- performShutDown()));
- QObject::connect(_webView->page()->mainFrame(), SIGNAL(
- javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM()));
+ setupLayout();
+ createActions();
- // initialize download manager
- DownloadManager* dm = new DownloadManager();
- QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)),
- jsi, SLOT(downloadInfo(const QString&, const double&)));
- QObject::connect(dm, SIGNAL(notify(const QString&)), jsi,
- SLOT(notify(const QString&)));
- QObject::connect(jsi, SIGNAL(requestFile(const QString&)), dm,
- SLOT(downloadFile(const QString&)));
- QObject::connect(
- dm,
- SIGNAL(updateProgress(const int&, const double&, const QString&)),
- jsi,
- SLOT(updateProgressBar(const int&, const double&, const QString&)));
- QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(
- callbackOnFinished()));
- QObject::connect(dm, SIGNAL(downloadQueueEmpty()), this, SLOT(
- prepareKexec()));
+ // initialize javascript interface
+ JavascriptInterface* jsi = new JavascriptInterface(
+ _webView->page()->mainFrame());
+ QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));
+ QObject::connect(jsi, SIGNAL(shutDownClient()), this,
+ SLOT(performShutDown()));
+ QObject::connect(_webView->page()->mainFrame(), SIGNAL(
+ javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM()));
- // move download manager to its own thread
- //dm->moveToThread(&dmThread);
- //dmThread.start();
+ // initialize download manager
+ DownloadManager* dm = new DownloadManager();
+ QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)), jsi,
+ SLOT(downloadInfo(const QString&, const double&)));
+ QObject::connect(dm, SIGNAL(notify(const QString&)), jsi, SLOT(notify(const QString&)));
+ QObject::connect(jsi, SIGNAL(requestFile(const QString&)), dm,
+ SLOT(downloadFile(const QString&)));
+ QObject::connect(dm, SIGNAL(updateProgress(const int&, const double&, const QString&)), jsi,
+ SLOT(updateProgressBar(const int&, const double&, const QString&)));
+ QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(
+ callbackOnFinished()));
+ QObject::connect(dm, SIGNAL(downloadQueueEmpty()), this, SLOT(loadSystem()));
- //_webView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar);
- // show page
- _webView->load(QUrl("qrc:/html/preload.html"));
- // start watching for fileToTriggerURL
- watchForTrigger();
- //if (checkHost()) loadURL();
+ // move download manager to its own thread
+ dm->moveToThread(&dmThread);
+ dmThread.start();
- // set properties
- setWindowTitle("fbgui");
- setAttribute(Qt::WA_QuitOnClose, true);
- setWindowFlags(Qt::FramelessWindowHint);
- showFullScreen();
+ // show "waiting for internet" page until triggered.
+ if (debugMode > -1) {
+ _webView->load(QUrl("qrc:/html/preload-debug.html"));
+ } else {
+ _webView->load(QUrl("qrc:/html/preload.html"));
+ }
+
+ // start watching for fileToTriggerURL
+ watchForTrigger();
+
+ // set properties
+ setWindowTitle("fbgui");
+ setAttribute(Qt::WA_QuitOnClose, true);
+ setWindowFlags(Qt::FramelessWindowHint);
+ showFullScreen();
}
fbgui::~fbgui() {
- //dmThread.quit();
+ dmThread.quit();
}
//-------------------------------------------------------------------------------------------
// Layout / actions setup
@@ -103,28 +100,28 @@ fbgui::~fbgui() {
* out console
*/
void fbgui::setupLayout() {
- // setup layout of the gui: debug split or browser
- _webView = new QWebView(this);
- if (debugMode == 1) {
- // split main window in browser & debug console
- createDebugConsole();
- _splitter = new QSplitter(Qt::Vertical, this);
- _splitter->addWidget(_webView);
- _splitter->addWidget(_debugConsole);
- setCentralWidget(_splitter);
- } else
- setCentralWidget(_webView);
+ // setup layout of the gui: debug split or browser
+ _webView = new QWebView(this);
+ if (debugMode == 1) {
+ // split main window in browser & debug console
+ createDebugConsole();
+ _splitter = new QSplitter(Qt::Vertical, this);
+ _splitter->addWidget(_webView);
+ _splitter->addWidget(_debugConsole);
+ setCentralWidget(_splitter);
+ } else
+ setCentralWidget(_webView);
}
//-------------------------------------------------------------------------------------------
/**
* This method enables a shortcut for closing the program.
+ * The shortcut itself is not configurable: CTRL + X
*/
void fbgui::createActions() {
- // CTRL + X to kill the gui
- _quit = new QAction(tr("&quit"), this);
- _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X));
- this->addAction(_quit);
- connect(_quit, SIGNAL(triggered()), this, SLOT(close()));
+ _quit = new QAction(tr("&quit"), this);
+ _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X));
+ this->addAction(_quit);
+ connect(_quit, SIGNAL(triggered()), this, SLOT(close()));
}
//-------------------------------------------------------------------------------------------
// File system watching
@@ -139,29 +136,28 @@ void fbgui::createActions() {
*
*/
void fbgui::watchForTrigger() {
- // check if fileToTriggerURL already exists
- QFile file(fileToTriggerURL);
- if (file.exists()) {
- qxtLog->debug() << "[watcher] " << fileToTriggerURL
- << " exists already!";
- // try to load URL
- loadURL();
- } else {
- // create it
- if (file.open(QIODevice::WriteOnly)) {
- qxtLog->debug() << "[gui] Created: " << fileToTriggerURL;
- file.close();
- } else {
- qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL
- << " failed! Exiting...";
- exit( EXIT_FAILURE);
- }
- }
- // watch the path where trigger file is expected
- qxtLog->debug() << "[watcher] Watching " << fileToTriggerURL;
- _watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this);
-QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this,
- SLOT(prepareURLLoad()));
+ // check if fileToTriggerURL already exists
+ QFile file(fileToTriggerURL);
+ if (file.exists()) {
+ qxtLog->debug() << "[watcher] " << fileToTriggerURL << " found.";
+ // try to load URL
+ loadURL();
+ } else {
+ // create it
+ if (file.open(QIODevice::WriteOnly)) {
+ qxtLog->debug() << "[gui] Created: " << fileToTriggerURL;
+ file.close();
+ } else {
+ qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL
+ << " failed!";
+ qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ QTimer::singleShot(5000, this, SLOT(close()));
+ }
+ }
+ // watch the path to trigger file
+ qxtLog->debug() << "[watcher] Watching " << fileToTriggerURL;
+ _watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this);
+QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepareURLLoad()));
}
//-------------------------------------------------------------------------------------------
@@ -176,37 +172,37 @@ QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this,
* @see fbgui::loadURL()
*/
void fbgui::prepareURLLoad() {
- qxtLog->debug() << "[watcher] " << fileToTriggerURL << " changed!";
- // disconnect _watcher, his job is done
- qxtLog->debug() << "[watcher] disconnected.";
- _watcher->disconnect(this);
- _watcher->deleteLater();
- // try to load URL
- loadURL();
+ qxtLog->debug() << "[watcher] " << fileToTriggerURL << " changed!";
+ // disconnect _watcher, his job is done
+ qxtLog->debug() << "[watcher] disconnected.";
+ _watcher->disconnect(this);
+ _watcher->deleteLater();
+ // try to load URL
+ loadURL();
}
//-------------------------------------------------------------------------------------------
// Preparations for URL load
//-------------------------------------------------------------------------------------------
/**
- * This method checks if is connected to the internet.
+ * This method checks the existance of the host.
*
- * This method checks if is connected to the internet.
+ * This method checks if the host exists / can be found.
+ * The host is from the URL given through the configuration.
*/
bool fbgui::checkHost() const {
- QHostInfo hostInfo = QHostInfo::fromName(baseURL.host());
- if (hostInfo.error() != QHostInfo::NoError) {
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host()
- << "failed. Exiting...";
- return false;
- } else {
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host()
- << " succeeded.";
- return true;
- }
+ 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.";
+ return false;
+ } else {
+ qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded.";
+ return true;
+ }
}
//-------------------------------------------------------------------------------------------
/**
- * This method loads the main screen.
+ * This method tries loads the URL.
*
* This method loads the main screen via an POST request. If also disconnects the watcher
* of the file, (Watcher is set in the fbgui::watchForTrigger() method).
@@ -216,15 +212,30 @@ bool fbgui::checkHost() const {
* @see fbgui::generatePOSTData()
*/
void fbgui::loadURL() {
- if (checkHost()) {
- qxtLog->debug() << "[gui] Loading URL...";
- QByteArray postData = generatePOSTData();
- QNetworkRequest req(baseURL);
- // show arrow cursor
- QWSServer::instance()->setCursorVisible(true);
- //qApp->setOverrideCursor(QCursor(Qt::ArrowCursor));
- _webView->load(req, QNetworkAccessManager::PostOperation, postData);
- }
+ if (checkHost()) {
+ qxtLog->debug() << "[gui] Loading URL: " << baseURL.toString() << " ...";
+
+ // Generate POST identification data needed by PBS.
+ QByteArray postData = generatePOSTData();
+ QNetworkRequest req(baseURL);
+
+ // show cursor again since user is about to interact.
+ QWSServer::instance()->setCursorVisible(true);
+ QObject::connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(loadURLDone(bool)));
+ _webView->load(req, QNetworkAccessManager::PostOperation, postData);
+ }
+ // TODO: error page if no host.
+}
+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 ...";
+ // TODO handle failure properly...
+ } else {
+ qxtLog->debug() << "[gui] Loaded URL: " << _webView->url().toString();
+ }
}
//-------------------------------------------------------------------------------------------
/**
@@ -235,92 +246,76 @@ void fbgui::loadURL() {
* The hardwarehash is a MD5 hash over the MAC address and the
* mainboard serial number.
* The specific serial number is set at the creation of the usb boot stick.
+ * This file has to be present on the directory specified in
+ * the configuration for this to work.
*
* @see SysInfo::getMACAddress()
* @see SysInfo::getMainboardSerial()
*/
QByteArray fbgui::generatePOSTData() {
- qxtLog->debug() << "[gui] Generating POST data...";
- // use MAC address as base data
- SysInfo si;
- QByteArray data(si.getInfo("mac").toUtf8());
- // append mainboard serial to the mac address for more unique hardwarehash
- data.append(si.getInfo("mbserial").toUtf8());
- qxtLog->debug() << "[post] Hashing: " << data;
- // generate MD5 hash of data
- QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
- qxtLog->debug() << "[post] MD5 Hash: " << hash.toHex();
+ qxtLog->debug() << "[gui] Generating POST data...";
+ // use MAC address as base data
+ SysInfo si;
+ QByteArray data(si.getInfo("mac").toUtf8());
+ // append mainboard serial to the mac address for more unique hardwarehash
+ QByteArray mbserial(si.getInfo("mbserial").toUtf8());
+ if (!mbserial.isEmpty())
+ data.append(mbserial);
+ else {
+ qxtLog->debug() << "[gui] Mainboard serial was empty. Not appending to base hash data.";
+ }
+ qxtLog->debug() << "[post] Hashing: " << data;
+ // generate MD5 hash of data
+ QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
+ qxtLog->debug() << "[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();
- }
- // everything ok, read data
- serial = file.readAll();
- file.close();
- serial.chop(1); // chop EOF
- qxtLog->debug() << "[post] Serial number is: " << serial;
+ // fetch serial number from usb
+ QByteArray serial;
+ QFile file(serialLocation);
+ if (!file.open(QIODevice::ReadOnly)) {
+ qxtLog->debug() << "[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;
- // 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;
- return postData;
+ // 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;
+ return postData;
}
+
//-------------------------------------------------------------------------------------------
-// Debug console setup / control
-//-------------------------------------------------------------------------------------------
-void fbgui::createDebugConsole() {
- // create the debug console widget
- _debugConsole = new QTextEdit(this);
- _debugConsole->setWindowFlags(Qt::FramelessWindowHint);
- // fanciness
- QPalette pal;
- 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);
- // CTRL + D toggles debug window
- _toggleDebugConsole = new QAction(tr("&toggleDebug"), this);
- _toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
- addAction(_toggleDebugConsole);
- connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(
- toggleDebugConsole()));
-}
-//-------------------------------------------------------------------------------------------
-void fbgui::toggleDebugConsole() {
- (_debugConsole->isVisible()) ? _debugConsole->hide()
- : _debugConsole->show();
-}
+// Shutdown / Reboot of the client
//-------------------------------------------------------------------------------------------
+// TODO One function for reboot and shutdown, with parameter for the action.
+// for example: doSystemCall(_REBOOT_);
/**
* This method performs the shutdown of the client.
*
* This method performs the shutdown of the client. It is triggered by the
* JavascriptInterface::shutDownClient() signal which will be emited in the
* JavascriptInterface::shutDown() method.
- * This method uses an QProcess object to execute the standard linux
- * shutdown command.
+ * This method writes the character 'o' in /proc/sysrq-trigger
+ * which will shutdown the computer immediatly.
+ * (See linux magic keys)
*
* @see JavascriptInterface::shutDownClient()
* @see JavascriptInterface::shutDown()
*/
void fbgui::performShutDown() {
- QFile file("/proc/sysrq-trigger");
- if (file.open(QIODevice::WriteOnly)) {
- file.write("o");
- file.close();
- }
- else {
- qxtLog->debug() << "[gui] Could not open /proc/sysrq-trigger";
- }
+ QFile file("/proc/sysrq-trigger");
+ if (file.open(QIODevice::WriteOnly)) {
+ file.write("o");
+ file.close();
+ } else {
+ qxtLog->debug() << "[gui] Could not open /proc/sysrq-trigger";
+ }
}
//-------------------------------------------------------------------------------------------
/**
@@ -329,81 +324,161 @@ void fbgui::performShutDown() {
* This method performs the reboot of the client. It is triggered by the
* JavascriptInterface::rebootClient() signal which will be emited in the
* JavascriptInterface::reboot() method.
- * This method uses an QProcess object to execute the standard linux
- * shutdown command.
+ * This method writes the character 'b' in /proc/sysrq-trigger
+ * which will shutdown the computer immediatly.
+ * (See linux magic keys)
*
* @see JavascriptInterface::rebootClient()
* @see JavascriptInterface::reboot()
*/
void fbgui::performReboot() {
- QFile file("/proc/sysrq-trigger");
- if (file.open(QIODevice::WriteOnly)) {
- file.write("b");
- file.close();
- }
- else {
- qxtLog->debug() << "[gui] Could not open /proc/sysrq-trigger";
- }
+ QFile file("/proc/sysrq-trigger");
+ if (file.open(QIODevice::WriteOnly)) {
+ file.write("b");
+ file.close();
+ } else {
+ qxtLog->debug() << "[gui] Could not open /proc/sysrq-trigger";
+ }
+}
+//-------------------------------------------------------------------------------------------
+// Preparing Kernel Switch per kexec (initiating Stage 3)
+//-------------------------------------------------------------------------------------------
+void fbgui::loadSystem() {
+ //show loading system page.
+ //_webView->disconnect(this);
+ //QObject::connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(prepareKexec()));
+ _webView->load(QUrl("qrc:/html/loadsystem.html"));
+ QTimer::singleShot(1000, this, SLOT(prepareKexec()));
}
//-------------------------------------------------------------------------------------------
/**
- * This method performs kexec.
+ * This method prepares kexec.
+ *
+ * The kernel command line file that should have been downloaded from the Preboot-Server
+ * and the ip config file (created by udhcpc) are merged into the final completed KCL.
+ *
+ * A process is then started to load the kernel, initramfs and kcl into kexec.
+ * The process tries to execute kexec -l with these parameters.
+ *
+ * If this succeeds, runKexec() is called
+ *
+ * @see fbgui::runKexec()
*
*/
void fbgui::prepareKexec() {
- // TODO read kcl file
- QFile file(downloadPath + "/kcl");
- if (!file.open(QIODevice::ReadOnly)) {
- qxtLog->debug() << "[gui] No such file: " << file.fileName();
- }
- // everything ok, read data
- QString kcl = file.readAll();
- file.close();
- qxtLog->debug() << "[gui] KCL from PBS: " << kcl;
-
- // TODO read IP config file
- file.setFileName("/tmp/ip_config_fbgui");
- if (!file.open(QIODevice::ReadOnly)) {
- qxtLog->debug() << "[gui] No such file: " << file.fileName();
- }
- QString ipConfig = file.readAll();
- file.close();
- qxtLog->debug() << "[gui] IP config: " << ipConfig;
+ qxtLog->debug() << "[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();
+ }
+ // everything ok, read data.
+ QString kcl = file.readAll();
+ file.close();
+ qxtLog->debug() << "[gui] KCL from PBS: " << kcl;
- kcl.append(" ip=");
- kcl.append(ipConfig);
+ // 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();
+ }
+ // everything ok, read data.
+ QString ipConfig = file.readAll();
+ file.close();
+ qxtLog->debug() << "[gui] IP config: " << ipConfig;
- qxtLog->debug() << "[gui] Complete KCL: " << kcl;
+ // append ipConfig
+ kcl.append(" ip=");
+ kcl.append(ipConfig);
+ qxtLog->debug() << "[gui] Complete KCL: " << kcl;
- 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;
- process->start(cmdline);
- bool ret = process->waitForFinished();
- if (!ret) {
- qxtLog->debug() << "[sysinfo] Failed to load kexec! Exiting...";
- exit( EXIT_FAILURE);
- } else {
- qxtLog->debug() << "[gui] Kexec load successfull.";
- if (debugMode < 0) {
- 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.";
- close();
- }
- }
+ // 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;
+ process->start(cmdline);
+ bool ret = process->waitForFinished();
+ if (!ret) {
+ qxtLog->debug() << "[gui] Failed to execute: " << cmdline;
+ qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ QTimer::singleShot(5000, this, SLOT(close()));
+ } else {
+ qxtLog->debug() << "[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.";
+ close();
+ }
+ }
}
+//-------------------------------------------------------------------------------------------
+/**
+ * This method tries to execute: kexec -e
+ *
+ * This method tries to execute: kexec -e
+ *
+ */
void fbgui::runKexec() {
- QProcess *process = new QProcess(this);
- process->startDetached("kexec -e");
- if (!process->waitForStarted()) {
- qxtLog->debug() << "[gui] Failed to execute: kexec -e";
- exit( EXIT_FAILURE);
- }
+ 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...";
+ QTimer::singleShot(5000, this, SLOT(close()));
+ //TODO: Handle failure properly...
+ }
+}
+//-------------------------------------------------------------------------------------------
+// Debug console setup / control
+//-------------------------------------------------------------------------------------------
+/**
+ * This method creates a debug console as a widget.
+ *
+ * It is basicly a QTextEdit widget as provided by QT's Framework.
+ * An action to toggle this widget is implemented (CTRL + D).
+ *
+ * @see fbgui::toggleDebugConsole()
+ */
+void fbgui::createDebugConsole() {
+ // create the debug console widget
+ _debugConsole = new QTextEdit(this);
+ _debugConsole->setWindowFlags(Qt::FramelessWindowHint);
+ // fanciness
+ QPalette pal;
+ 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);
+ // CTRL + D toggles debug window
+ _toggleDebugConsole = new QAction(tr("&toggleDebug"), this);
+ _toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
+ addAction(_toggleDebugConsole);
+ connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(
+ toggleDebugConsole()));
}
+//-------------------------------------------------------------------------------------------
+/**
+ * This method toggles the debug console.
+ *
+ * Toggle the visibility of the debug console if the action _toggleDebugConsole is triggered.
+ *
+ * @see fbgui::createDebugConsole()
+ */
+void fbgui::toggleDebugConsole() {
+ (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show();
+}
+//-------------------------------------------------------------------------------------------
+//
+
+//-------------------------------------------------------------------------------------------
diff --git a/src/fbgui.h b/src/fbgui.h
index 891e17a..35197d8 100644
--- a/src/fbgui.h
+++ b/src/fbgui.h
@@ -1,19 +1,19 @@
/*
- # 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
- #
- #
- # Main class of the fbgui:
- # - Manages display of components and their communications
- #
+ * 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
+ *
+ *
+ * Main class of the fbgui:
+ * - Manages display of components and their communications
+ *
*/
#ifndef FBGUI_H
@@ -26,13 +26,15 @@
// Internal default settings
#define DEFAULT_URL "http://www.google.com"
-#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads"
+#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui"
#define DEFAULT_CONFIG_PATH "/etc/fbgui.conf"
+#define DEFAULT_LOG_FILE_PATH "/tmp/fbgui.log"
#define DEFAULT_UPDATE_INTERVAL 1;
#define DEFAULT_QRC_HTML_DIR ":/html"
#define DEFAULT_FILE_TRIGGER "/tmp/fbgui/trigger"
// Global settings variables
+extern QString logFilePath;
extern QString ipConfigFilePath;
extern QThread dmThread;
extern QString serialLocation;
@@ -44,75 +46,78 @@ extern QUrl baseURL;
extern int debugMode;
extern int updateInterval;
-
class fbgui: public QMainWindow {
Q_OBJECT
public:
- fbgui();
- ~fbgui();
+ fbgui();
+ ~fbgui();
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();
-
- // triggered by fileChanged Signal of _watcher
- // deletes _watcher, since we don't need it anymore and tries to load URL.
- void prepareURLLoad();
-
- // shut off the system
- void performShutDown();
- // reboot the system
- void performReboot();
- // prepareKexec
- void prepareKexec();
- 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.qrc b/src/fbgui.qrc
index 10a8bd6..e378bed 100644
--- a/src/fbgui.qrc
+++ b/src/fbgui.qrc
@@ -4,9 +4,11 @@
<file>html/js/jquery-1.5.1.min.js</file>
<file>html/js/jquery-ui-1.8.11.min.js</file>
<file>html/js/test.js</file>
- <file>html/style.css</file>
+ <file>html/background.png</file>
+ <file>html/preload.css</file>
<file>html/preload.html</file>
- <file>html/bg.png</file>
<file>html/preload-debug.html</file>
+ <file>html/loadsystem.css</file>
+ <file>html/loadsystem.html</file>
</qresource>
</RCC>
diff --git a/src/html/background.png b/src/html/background.png
new file mode 100644
index 0000000..7e374f9
--- /dev/null
+++ b/src/html/background.png
Binary files differ
diff --git a/src/html/loadsystem.css b/src/html/loadsystem.css
new file mode 100644
index 0000000..6a6e64f
--- /dev/null
+++ b/src/html/loadsystem.css
@@ -0,0 +1,90 @@
+html,body{
+ height:100%;
+}
+body{
+ margin:0;
+ padding:0;
+ background-color:black;
+ /*
+ background-image:url('background.png');
+ background-repeat:no-repeat;
+ */
+ background-size:100%;
+}
+#message{
+ position:relative;
+ font-size:90%;
+ top:40%;
+}
+h1, p{
+ text-align:center;
+ color:white;
+}
+* html{
+ height:100%;
+}
+/* position the bars and balls correctly (rotate them and translate them outward)*/
+.bar1 {
+ -moz-transform:rotate(0deg) translate(0, -40px);
+ -webkit-transform:rotate(0deg) translate(0, -40px);opacity:0.12;
+}
+.bar2 {
+ -moz-transform:rotate(45deg) translate(0, -40px);
+ -webkit-transform:rotate(45deg) translate(0, -40px);opacity:0.25;
+}
+.bar3 {
+ -moz-transform:rotate(90deg) translate(0, -40px);
+ -webkit-transform:rotate(90deg) translate(0, -40px);opacity:0.37;
+}
+.bar4 {
+ -moz-transform:rotate(135deg) translate(0, -40px);
+ -webkit-transform:rotate(135deg) translate(0, -40px);opacity:0.50;
+}
+.bar5 {
+ -moz-transform:rotate(180deg) translate(0, -40px);
+ -webkit-transform:rotate(180deg) translate(0, -40px);opacity:0.62;
+}
+.bar6 {
+ -moz-transform:rotate(225deg) translate(0, -40px);
+ -webkit-transform:rotate(225deg) translate(0, -40px);opacity:0.75;
+}
+.bar7 {
+ -moz-transform:rotate(270deg) translate(0, -40px);
+ -webkit-transform:rotate(270deg) translate(0, -40px);opacity:0.87;
+}
+.bar8 {
+ -moz-transform:rotate(315deg) translate(0, -40px);
+ -webkit-transform:rotate(315deg) translate(0, -40px);opacity:1;
+}
+#div4 {
+ position:absolute;
+ left:50%;
+ top:50%;
+ margin-left:-50px;
+ margin-top:-50px;
+ width:100px;
+ height:100px;
+ -moz-border-radius:100px;
+ -webkit-border-radius:100px;
+ -moz-transform:scale(0.5);
+ -webkit-transform:scale(0.5);
+ -webkit-animation-name: rotateThis;
+ -webkit-animation-duration:2s;
+ -webkit-animation-iteration-count:infinite;
+ -webkit-animation-timing-function:linear;
+}
+#div4 div {
+ width:20px;
+ height:20px;
+ background:#fff;
+ -moz-border-radius:40px;
+ -webkit-border-radius:40px;
+ position:absolute;
+ left:40px;
+ top:40px;
+}
+/* add a shadow to the first */
+#div4 div {
+ -moz-box-shadow:black 0 0 4px;
+ -webkit-box-shadow:black 0 0 4px;
+}
diff --git a/src/html/loadsystem.html b/src/html/loadsystem.html
new file mode 100644
index 0000000..838423e
--- /dev/null
+++ b/src/html/loadsystem.html
@@ -0,0 +1,35 @@
+<html>
+<head>
+<link rel="stylesheet" type="text/css" href="loadsystem.css">
+<script type="text/javascript">
+//simple script to rotate all spinners 45 degrees on each tick
+//this works differently from the css transforms, which is smooth
+var count = 0;
+function rotate() {
+ var elem4 = document.getElementById('div4');
+ elem4.style.MozTransform = 'scale(0.5) rotate('+count+'deg)';
+ elem4.style.WebkitTransform = 'scale(0.5) rotate('+count+'deg)';
+ if (count==360) { count = 0 }
+ count+=45;
+ window.setTimeout(rotate, 100);
+}
+window.setTimeout(rotate, 100);
+</script>
+</head>
+<body>
+
+<div id="message">
+ <h1>Loading system, please wait...</h1>
+</div>
+<div id="div4">
+ <div class="bar1"></div>
+ <div class="bar2"></div>
+ <div class="bar3"></div>
+ <div class="bar4"></div>
+ <div class="bar5"></div>
+ <div class="bar6"></div>
+ <div class="bar7"></div>
+ <div class="bar8"></div>
+</div>
+</body>
+</html>
diff --git a/src/html/bg.png b/src/html/old.png
index 84dd7b3..84dd7b3 100644
--- a/src/html/bg.png
+++ b/src/html/old.png
Binary files differ
diff --git a/src/html/preload-debug.html b/src/html/preload-debug.html
index cc69aa1..29d7391 100644
--- a/src/html/preload-debug.html
+++ b/src/html/preload-debug.html
@@ -1,6 +1,6 @@
<html>
<head>
-<link rel="stylesheet" type="text/css" href="style.css">
+<link rel="stylesheet" type="text/css" href="preload.css">
<script type="text/javascript">
function gogo(){
fbgui.trigger();
@@ -12,14 +12,16 @@ function quitgui(){
</head>
<body>
<div id="top">
+</div>
+<div id="message">
<h1>Preboot GUI</h1>
+ <p>Waiting on internet...
+ <input type="button" name="go" value="load URL"
+ style="font-size:75%"
+ onclick="gogo()">
<input type="button" name="quit" value="quit"
style="font-size:75%"
onclick="quitgui()">
- <p>Waiting on internet...i
- <input type="button" name="go" value="click me"
- style="font-size:75%"
- onclick="gogo()">
</p>
</div>
<div id="container">
diff --git a/src/html/style.css b/src/html/preload.css
index 817a7ee..e1eff68 100644
--- a/src/html/style.css
+++ b/src/html/preload.css
@@ -5,17 +5,24 @@ body{
margin:0;
padding:0;
background-color:black;
- background-image:url('bg.png');
- background-repeat: no-repeat;
+ /*
+ background-image:url('background.png');
+ background-repeat:no-repeat;
+ */
background-size:100%;
}
#top{
position:absolute;
}
+#message{
+ position:absolute;
+ top:37%;
+ width:100%;
+ font-size:90%;
+}
h1, p{
- margin:10;
- padding:0.3em 0;
color:white;
+ text-align:center;
}
#container{
min-height:100%;
@@ -30,6 +37,7 @@ h1, p{
#footer{
height:30px;
}
+/* animation */
/* position the bars and balls correctly (rotate them and translate them outward)*/
.bar1 {
-moz-transform:rotate(0deg) translate(0, -40px);
diff --git a/src/html/preload.html b/src/html/preload.html
index bb63050..bc0abd9 100644
--- a/src/html/preload.html
+++ b/src/html/preload.html
@@ -1,10 +1,7 @@
<html>
<head>
-<link rel="stylesheet" type="text/css" href="style.css">
+<link rel="stylesheet" type="text/css" href="preload.css">
<script type="text/javascript">
-function gogo(){
- fbgui.trigger();
-}
//simple script to rotate all spinners 45 degrees on each tick
//this works differently from the css transforms, which is smooth
var count = 0;
@@ -21,9 +18,9 @@ window.setTimeout(rotate, 100);
</head>
<body>
<div id="top">
- <h1>Preboot GUI</h1>
- <p>Waiting on internet...
- </p>
+</div>
+<div id="message">
+ <h1>Waiting for internet...</h1>
</div>
<div id="div4">
<div class="bar1"></div>
diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp
index 66ec7a5..b480635 100644
--- a/src/javascriptinterface.cpp
+++ b/src/javascriptinterface.cpp
@@ -12,8 +12,8 @@
* Is of type QWebFrame.
*/
JavascriptInterface::JavascriptInterface(QWebFrame *parent) {
- qxtLog->debug() << "Initializing javascript interface...";
- _parent = parent;
+ qxtLog->debug() << "Initializing javascript interface...";
+ _parent = parent;
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -33,8 +33,8 @@ JavascriptInterface::~JavascriptInterface() { /* destructor dummy */
* @see JavascriptInterface::loadJQuery()
*/
void JavascriptInterface::attachToDOM() {
- _parent->addToJavaScriptWindowObject(QString("fbgui"), this);
- loadJQuery();
+ _parent->addToJavaScriptWindowObject(QString("fbgui"), this);
+ loadJQuery();
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -49,30 +49,30 @@ void JavascriptInterface::attachToDOM() {
* @see JavascriptInterface::attachToDOM()
*/
void JavascriptInterface::loadJQuery() {
- QString js;
- QString pathToJsDir(DEFAULT_QRC_HTML_DIR);
- pathToJsDir.append("/js");
+ QString js;
+ QString pathToJsDir(DEFAULT_QRC_HTML_DIR);
+ pathToJsDir.append("/js");
- QDir qrcJSDir(pathToJsDir);
- QFileInfoList fiList = qrcJSDir.entryInfoList();
- QFileInfo fi;
- foreach(fi, fiList)
- {
- if (fi.suffix() == "js") {
- //qDebug()<< fi.fileName();
- //qxtLog->debug() << fi.fileName();
- if (fi.fileName() != "test.js") {
- QFile file;
- file.setFileName(pathToJsDir + "/" + fi.fileName());
- file.open(QIODevice::ReadOnly);
- js = file.readAll();
- file.close();
+ QDir qrcJSDir(pathToJsDir);
+ QFileInfoList fiList = qrcJSDir.entryInfoList();
+ QFileInfo fi;
+ foreach(fi, fiList)
+ {
+ if (fi.suffix() == "js") {
+ //qDebug()<< fi.fileName();
+ //qxtLog->debug() << fi.fileName();
+ if (fi.fileName() != "test.js") {
+ QFile file;
+ file.setFileName(pathToJsDir + "/" + fi.fileName());
+ file.open(QIODevice::ReadOnly);
+ js = file.readAll();
+ file.close();
- _parent->evaluateJavaScript(js);
- //qxtLog->debug() << "evaluated " + fi.fileName();
- }
+ _parent->evaluateJavaScript(js);
+ //qxtLog->debug() << "evaluated " + fi.fileName();
}
- }
+ }
+ }
}
//-------------------------------------------------------------------------------------------------------
// Javascript functions for webpage
@@ -85,12 +85,12 @@ void JavascriptInterface::loadJQuery() {
* Emits the JavascriptInterface::requestFile(const QString) signal.
*/
void JavascriptInterface::startDownload(const QString& filename) {
- // ignore if empty filename
- if (filename.isEmpty()) {
- _parent->evaluateJavaScript("alert(\"No filename!\")");
- return;
- }
- emit requestFile(filename);
+ // ignore if empty filename
+ if (filename.isEmpty()) {
+ _parent->evaluateJavaScript("alert(\"No filename!\")");
+ return;
+ }
+ emit requestFile(filename);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -102,8 +102,8 @@ void JavascriptInterface::startDownload(const QString& filename) {
* @todo add some more informations
*/
void JavascriptInterface::setCallbackOnFinished(const QString& function) {
- qxtLog->debug() << "[jsi] Callback set: " << function;
- _callbackOnDownloadsFinished = QString(function);
+ qxtLog->debug() << "[jsi] Callback set: " << function;
+ _callbackOnDownloadsFinished = QString(function);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -127,8 +127,8 @@ void JavascriptInterface::setCallbackOnFinished(const QString& function) {
* @see SysInfo::getInfo(const QString& infoName)
*/
const QString JavascriptInterface::getSysInfo(const QString& info) {
- SysInfo si;
- return si.getInfo(info);
+ SysInfo si;
+ return si.getInfo(info);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -139,7 +139,7 @@ const QString JavascriptInterface::getSysInfo(const QString& info) {
* Emits JavascriptInterface::quitFbgui() signal
*/
void JavascriptInterface::quit() {
- emit quitFbgui();
+ emit quitFbgui();
}
//-------------------------------------------------------------------------------------------------------
@@ -153,7 +153,7 @@ void JavascriptInterface::quit() {
* @see fbgui::performShutDown()
*/
void JavascriptInterface::shutDown() {
- emit shutDownClient();
+ emit shutDownClient();
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -166,7 +166,7 @@ void JavascriptInterface::shutDown() {
* @see fbgui::performReboot()
*/
void JavascriptInterface::reboot() {
- emit rebootClient();
+ emit rebootClient();
}
//-------------------------------------------------------------------------------------------------------
// Download Manager information exchange
@@ -178,11 +178,9 @@ void JavascriptInterface::reboot() {
*
* @todo add some more informations
*/
-void JavascriptInterface::downloadInfo(const QString& filename,
- const double& filesize) {
- QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(
- filesize);
- _parent->evaluateJavaScript(code);
+void JavascriptInterface::downloadInfo(const QString& filename, const double& filesize) {
+ QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(filesize);
+ _parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -193,13 +191,12 @@ void JavascriptInterface::downloadInfo(const QString& filename,
*
* @todo add some more informations
*/
-void JavascriptInterface::updateProgressBar(const int& percent,
- const double& speed, const QString& unit) {
- if (percent == 0)
- return;
- QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg(
- speed).arg(unit);
- _parent->evaluateJavaScript(code);
+void JavascriptInterface::updateProgressBar(const int& percent, const double& speed,
+ const QString& unit) {
+ if (percent == 0)
+ return;
+ QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg(speed).arg(unit);
+ _parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -208,22 +205,22 @@ void JavascriptInterface::updateProgressBar(const int& percent,
* @todo add some more informations.
*/
void JavascriptInterface::notify(const QString& msg) {
- qxtLog->debug() << "[jsi] Notifying: " << msg;
- QString code = QString("notify('\%1')").arg(msg);
- _parent->evaluateJavaScript(code);
+ qxtLog->debug() << "[jsi] Notifying: " << msg;
+ QString code = QString("notify('\%1')").arg(msg);
+ _parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
/**
* @todo add some more informations
*/
void JavascriptInterface::callbackOnFinished() {
- QString code = QString("\%1").arg(_callbackOnDownloadsFinished);
- _parent->evaluateJavaScript(code);
+ QString code = QString("\%1").arg(_callbackOnDownloadsFinished);
+ _parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
/**
- * This method triggers the arriving of the IP address
+ * This method triggers the arriving of the IP address *FOR TESTING PURPOSES*
*
* Used for testing. This method triggers the arriving of the IP address.
* Not needed in the final version since the here simulated event will be
@@ -237,10 +234,15 @@ void JavascriptInterface::callbackOnFinished() {
* @see void fbgui::loadURL()
*/
void JavascriptInterface::trigger() {
- QFile file(fileToTriggerURL);
- if (file.open(QIODevice::WriteOnly)) {
- file.write("data\n");
- qxtLog->debug() << "[jsi] *trigger watcher*";
- }
- file.close();
+ QFile file(fileToTriggerURL);
+ if (file.open(QIODevice::WriteOnly)) {
+ file.write("data\n");
+ qxtLog->debug() << "[jsi] *trigger watcher*";
+ }
+ file.close();
+}
+//-------------------------------------------------------------------------------------------------------
+void JavascriptInterface::alert(const QString& message) {
+ // expects a formatted message.
+ _parent->evaluateJavaScript(QString("alert(").append(message));
}
diff --git a/src/javascriptinterface.h b/src/javascriptinterface.h
index 1f93e38..8826e46 100644
--- a/src/javascriptinterface.h
+++ b/src/javascriptinterface.h
@@ -1,18 +1,18 @@
/*
- # 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
- #
- #
- # Interface for javascript.
- #
+ * 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
+ *
+ *
+ * Interface for javascript.
+ *
*/
#ifndef JAVASCRIPTINTERFACE_H_
@@ -23,50 +23,50 @@
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();
+ // 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);
- // test stuff
- void trigger();
+ // functions to help test functionality
+ void trigger();
+ void alert(const QString& message);
};
#endif // JAVASCRIPTINTERFACE_H_
diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp
index d37999d..8a0991d 100644
--- a/src/loggerengine.cpp
+++ b/src/loggerengine.cpp
@@ -4,83 +4,113 @@
// base of a custom logger engine for the framebuffer
//---------------------------------------------------------------------------------------------------
LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) :
- QxtLoggerEngine() {
- _debugConsole = parent;
- //_initialized = false;
- //setLogLevelsEnabled(QxtLogger::DebugLevel);
- //enableLogging();
+ QxtLoggerEngine() {
+ _debugConsole = parent;
+ //_initialized = false;
+ //setLogLevelsEnabled(QxtLogger::DebugLevel);
+ //enableLogging();
}
LoggerEngine_fb::~LoggerEngine_fb() {
}
void LoggerEngine_fb::initLoggerEngine() {
- //_initialized = true;
- return;
+ //_initialized = true;
+ return;
}
void LoggerEngine_fb::killLoggerEngine() {
- return;
+ return;
}
-void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level,
- bool enable) {
- //QxtLoggerEngine::setLogLevelsEnabled(level, enable);
- //if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel);
+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;
+ //return _initialized;
+ return true;
}
-void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level,
- const QList<QVariant> & msgs) {
+void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs) {
- if (msgs.isEmpty())
- return;
- 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);
- }
+ // 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() {
+ QxtBasicSTDLoggerEngine() {
}
LoggerEngine_std::~LoggerEngine_std() {
}
-void LoggerEngine_std::writeToStdErr(const QString& str_level,
- const QList<QVariant> &msgs) {
+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;
+ 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_std::writeToStdOut(const QString& level,
- const QList<QVariant> & msgs) {
- // reimplementing this is needed for compiling,
- // we only need write to std::err, so this function is not needed
+
+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/loggerengine.h b/src/loggerengine.h
index 9c3ab96..1dfae4e 100644
--- a/src/loggerengine.h
+++ b/src/loggerengine.h
@@ -1,18 +1,18 @@
/*
- # 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.
- #
+ * 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_
@@ -20,25 +20,25 @@
#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();
+ LoggerEngine_fb(QTextEdit* parent);
+ ~LoggerEngine_fb();
- // parent widget, target of messages
- QTextEdit *_debugConsole;
- bool _initialized;
+ // 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;
+ // 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;
};
//---------------------------------------------------------------------------------------------------
@@ -46,12 +46,24 @@ public:
//---------------------------------------------------------------------------------------------------
class LoggerEngine_std: public QxtBasicSTDLoggerEngine {
public:
- LoggerEngine_std();
- ~LoggerEngine_std();
+ 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 QxtBasicSTDLoggerEngineqqq
- void writeToStdOut(const QString& level, const QList<QVariant> &msgs);
- void writeToStdErr(const QString& str_level, const QList<QVariant> &msgs);
+ // reimplemented virtual functions of QxtBasicFileLoggerEngine
+ void writeToFile(const QString& level, const QList<QVariant> &msgs);
};
#endif // LOGGERENGINE_H_
diff --git a/src/main.cpp b/src/main.cpp
index baff7af..f3d4201 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,187 +8,198 @@
#include "fbgui.h"
void printHelp() {
- QTextStream qout(stdout);
- qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl;
- qout << QObject::tr("Options:") << endl;
- qout << "-c <path>, --config=<path> " << QObject::tr(
- "Path to configuration file.") << endl;
- qout << "-u <URL>, --url=<URL> " << QObject::tr(
- "Sets the URL to be loaded.") << endl;
- qout << "-d <path>, --download=<path> " << QObject::tr(
- "Specify the download directory.") << endl;
- qout << "-t <path, --trigger=<path> " << QObject::tr(
- "Specify location of the file triggering the URL load.") << endl;
- qout << "-s <path, --serial=<path> " << QObject::tr(
- "Specify location of the file containing the serial number.")
- << endl;
- qout << "-D <level>, --debug=<level> " << QObject::tr(
- "Activate debug mode. [0,1]") << endl;
- qout << "-h, --help " << QObject::tr(
- "Prints this help.") << endl;
- qout.flush();
- exit( EXIT_SUCCESS);
+ QTextStream qout(stdout);
+ qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl;
+ qout << QObject::tr("Options:") << endl;
+ qout << "-c <path>, --config=<path> " << QObject::tr("Path to configuration file.") << endl;
+ qout << "-u <URL>, --url=<URL> " << QObject::tr("Sets the URL to be loaded.") << endl;
+ qout << "-d <path>, --download=<path> " << QObject::tr("Specify the download directory.")
+ << endl;
+ qout << "-t <path, --trigger=<path> " << QObject::tr(
+ "Specify location of the file triggering the URL load.") << endl;
+ qout << "-s <path, --serial=<path> " << QObject::tr(
+ "Specify location of the file containing the serial number.") << endl;
+ qout << "-D <level>, --debug=<level> " << QObject::tr("Activate debug mode. [0,1]") << endl;
+ qout << "-h, --help " << QObject::tr("Prints this help.") << endl;
+ qout.flush();
+ exit( EXIT_SUCCESS);
}
int main(int argc, char *argv[]) {
- // Initialisation of the QApplication:
- // In QT, every application is composed of two separate
- // components: the GUI-Client and the GUI-Server.
- //
- // The third parameter sets the application as the
- // GUI-Server (aswell as the GUI-Client).
-
- QApplication app(argc, argv, QApplication::GuiServer);
- app.setOrganizationName("team_projekt_2011");
- app.setApplicationName("prebootGUI");
- binPath = QApplication::applicationDirPath();
-
- QTranslator translator;
- translator.load(":" + QLocale::system().name());
- app.installTranslator(&translator);
-
- // parse command line arguments using getopt
- QMap<QString, QString> clOpts;
- int longIndex = 0;
- static const char *optString = "c:u:d:s:t:D:h";
- static const struct option longOpts[] = { { "config", required_argument,
- NULL, 'c' }, { "url", required_argument, NULL, 'u' }, { "download",
- required_argument, NULL, 'd' }, { "serial", required_argument,
- NULL, 's' }, { "trigger", required_argument, NULL, 't' }, {
- "debug", required_argument, NULL, 'D' }, { "help", no_argument,
- NULL, 'h' } };
- int opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
- while (opt != -1) {
- switch (opt) {
- case 'c':
- clOpts.insert("configFile", optarg);
- break;
- case 'u':
- clOpts.insert("url", optarg);
- break;
- case 'd':
- clOpts.insert("downloadDir", optarg);
- break;
- case 's':
- clOpts.insert("serialLocation", optarg);
- break;
- case 't':
- clOpts.insert("trigger", optarg);
- break;
- case 'D':
- clOpts.insert("debug", optarg);
- break;
- case 'h':
- clOpts.insert("help", "help");
- break;
- }
- opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
- }
-
- if (clOpts.contains("help"))
- printHelp();
-
- if (clOpts.contains("debug")) {
- debugMode = clOpts.value("debug").toInt();
- // start basic debug log
- qxtLog->disableLoggerEngine("DEFAULT");
- qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std);
- qxtLog->initLoggerEngine("std_logger");
- qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel);
- qxtLog->enableLogLevels(QxtLogger::DebugLevel);
- qxtLog->debug() << "Initializing fbgui...";
- } else
- debugMode = -1;
-
- // look for config file either in:
- // - the path found in the configuration file
- // - the user's home directory (as .fbgui.conf)
- // - /etc/fbgui.conf
-
- QString configFilePath;
- QFileInfo confInfo;
- if (clOpts.contains("configFile"))
- configFilePath = clOpts.value("configFile");
- else {
- confInfo = QFileInfo(QDir::home(), ".fbgui.conf");
- if (confInfo.exists())
- configFilePath = confInfo.absoluteFilePath();
- else {
- confInfo = QFileInfo(QString("/etc/fbgui.conf"));
- if (confInfo.exists())
- configFilePath = QString("/etc/fbgui.conf");
- else
- configFilePath = DEFAULT_CONFIG_PATH;
- }
- }
-
- // read the config file
- QSettings confFileSettings(configFilePath, QSettings::IniFormat);
- confFileSettings.setIniCodec("UTF-8");
-
- // set base URL to be loaded
- if (clOpts.contains("url"))
- baseURL = QUrl(clOpts.value("url"));
- else if (confFileSettings.contains("default/pbs_url"))
- baseURL = confFileSettings.value("default/pbs_url").toUrl();
- else
- baseURL = DEFAULT_URL;
-
- // set directory for downloads
- if (clOpts.contains("downloadDir"))
- downloadPath = clOpts.value("downloadDir");
- else if (confFileSettings.contains("default/download_directory"))
- downloadPath
- = confFileSettings.value("default/download_directory").toString();
- else
- downloadPath = DEFAULT_DOWNLOAD_DIR;
-
- if (confFileSettings.contains("default/update_interval"))
- updateInterval
- = confFileSettings.value("default/update_interval").toInt();
- else
- updateInterval = DEFAULT_UPDATE_INTERVAL;
-
- // set which file to watch to trigger loading of URL
- if (clOpts.contains("trigger"))
- fileToTriggerURL = clOpts.value("trigger");
- else if (confFileSettings.contains("default/file_trigger"))
- fileToTriggerURL
- = confFileSettings.value("default/file_trigger").toString();
- else
- fileToTriggerURL = DEFAULT_FILE_TRIGGER;
-
- // set serial location
- if (clOpts.contains("serialLocation"))
- serialLocation = clOpts.value("serialLocation");
- else if (confFileSettings.contains("default/serial_location"))
- serialLocation
- = confFileSettings.value("default/serial_location").toString();
- else
- serialLocation = QString("/serial"); // tests
-
- // save ip config location (file generated by uchpc)
- if (confFileSettings.contains("default/ip_config"))
- ipConfigFilePath = confFileSettings.value("default/ip_config").toString();
- //else
- // ipConfigFilePath = QString("/tmp/ip_config");
-
- // print config
- qxtLog->debug() << "************* CONFIG INFO *************";
- qxtLog->debug() << "configFilePath: " << configFilePath.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() << "*******************************************";
-
- // set invisible cursor
- QWSServer::instance()->setCursorVisible(false);
- QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0");
- QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice");
- // start fbgui
- fbgui gui;
- gui.show();
- return app.exec();
+ // Initialisation of the QApplication:
+ // In QT, every application is composed of two separate
+ // components: the GUI-Client and the GUI-Server.
+ //
+ // The third parameter sets the application as the
+ // GUI-Server (aswell as the GUI-Client).
+
+ QApplication app(argc, argv, QApplication::GuiServer);
+ app.setOrganizationName("team_projekt_2011");
+ app.setApplicationName("prebootGUI");
+ binPath = QApplication::applicationDirPath();
+
+ QTranslator translator;
+ translator.load(":" + QLocale::system().name());
+ app.installTranslator(&translator);
+
+ // parse command line arguments using getopt
+ QMap<QString, QString> clOpts;
+ int longIndex = 0;
+ static const char *optString = "c:u:d:s:t:D:hl:";
+ static const struct option longOpts[] = { { "config", required_argument, NULL, 'c' }, { "url",
+ required_argument, NULL, 'u' }, { "download", required_argument, NULL, 'd' }, { "serial",
+ required_argument, NULL, 's' }, { "trigger", required_argument, NULL, 't' }, { "debug",
+ required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "log",
+ required_argument, NULL, 'l' } };
+ int opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
+ while (opt != -1) {
+ switch (opt) {
+ case 'c':
+ clOpts.insert("configFile", optarg);
+ break;
+ case 'l':
+ clOpts.insert("logFile", optarg);
+ break;
+ case 'u':
+ clOpts.insert("url", optarg);
+ break;
+ case 'd':
+ clOpts.insert("downloadDir", optarg);
+ break;
+ case 's':
+ clOpts.insert("serialLocation", optarg);
+ break;
+ case 't':
+ clOpts.insert("trigger", optarg);
+ break;
+ case 'D':
+ clOpts.insert("debug", optarg);
+ break;
+ case 'h':
+ clOpts.insert("help", "help");
+ break;
+ }
+ opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
+ }
+
+ if (clOpts.contains("help"))
+ printHelp();
+
+ 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);
+ } else
+ debugMode = -1;
+
+ // look for config file either in:
+ // - the path found in the configuration file
+ // - the user's home directory (as .fbgui.conf)
+ // - /etc/fbgui.conf
+
+ QString configFilePath;
+ QFileInfo confInfo;
+ if (clOpts.contains("configFile"))
+ configFilePath = clOpts.value("configFile");
+ else {
+ confInfo = QFileInfo(QDir::home(), ".fbgui.conf");
+ if (confInfo.exists())
+ configFilePath = confInfo.absoluteFilePath();
+ else {
+ confInfo = QFileInfo(QString("/etc/fbgui.conf"));
+ if (confInfo.exists())
+ configFilePath = QString("/etc/fbgui.conf");
+ else
+ configFilePath = DEFAULT_CONFIG_PATH;
+ }
+ }
+
+ // read the config file
+ QSettings confFileSettings(configFilePath, QSettings::IniFormat);
+ confFileSettings.setIniCodec("UTF-8");
+
+ // set base URL to be loaded
+ if (clOpts.contains("url"))
+ baseURL = QUrl(clOpts.value("url"));
+ else if (confFileSettings.contains("default/pbs_url"))
+ baseURL = confFileSettings.value("default/pbs_url").toUrl();
+ else
+ baseURL = DEFAULT_URL;
+
+ // set directory for downloads
+ if (clOpts.contains("downloadDir"))
+ downloadPath = clOpts.value("downloadDir");
+ else if (confFileSettings.contains("default/download_directory"))
+ downloadPath = confFileSettings.value("default/download_directory").toString();
+ else
+ downloadPath = DEFAULT_DOWNLOAD_DIR;
+
+ // set update interval for download progress functions of download manager.
+ if (confFileSettings.contains("default/update_interval"))
+ updateInterval = confFileSettings.value("default/update_interval").toInt();
+ else
+ updateInterval = DEFAULT_UPDATE_INTERVAL;
+
+ // set which file to watch to trigger loading of URL
+ if (clOpts.contains("trigger"))
+ fileToTriggerURL = clOpts.value("trigger");
+ else if (confFileSettings.contains("default/file_trigger"))
+ fileToTriggerURL = confFileSettings.value("default/file_trigger").toString();
+ else
+ fileToTriggerURL = DEFAULT_FILE_TRIGGER;
+
+ // set serial location
+ if (clOpts.contains("serialLocation"))
+ serialLocation = clOpts.value("serialLocation");
+ else if (confFileSettings.contains("default/serial_location"))
+ serialLocation = confFileSettings.value("default/serial_location").toString();
+ else
+ serialLocation = QString("/serial"); // tests
+
+ // save ip config location (file generated by uchpc)
+ if (confFileSettings.contains("default/ip_config"))
+ ipConfigFilePath = confFileSettings.value("default/ip_config").toString();
+
+ // save path to log file
+ if (clOpts.contains("logFile"))
+ logFilePath = clOpts.value("logFile");
+ else if (confFileSettings.contains("default/log_file"))
+ logFilePath = confFileSettings.value("default/log_file").toString();
+ else
+ logFilePath = DEFAULT_LOG_FILE_PATH;
+
+ // 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);
+ }
+
+ // 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() << "*******************************************";
+
+ // set invisible cursor
+ QWSServer::instance()->setCursorVisible(false);
+
+ // set default keyboard / mouse drivers. TODO: fix this, doesn't work...
+ //QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0");
+ //QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice");
+
+ // start fbgui
+ qxtLog->debug() << "Initializing fbgui...";
+ fbgui gui;
+ gui.show();
+ return app.exec();
}
diff --git a/src/sysinfo.cpp b/src/sysinfo.cpp
index ef7dc04..4797a86 100644
--- a/src/sysinfo.cpp
+++ b/src/sysinfo.cpp
@@ -34,22 +34,22 @@ SysInfo::~SysInfo() {
* @see JavascriptInterface::getSysInfo(const QString& info)
*/
const QString SysInfo::getInfo(const QString& infoName) {
- qxtLog->debug() << "[sysinfo] requested " << infoName;
- if (infoName == QString("mac"))
- return getMACAddress();
- else if (infoName == QString("ip"))
- return getIPAddress();
- else if (infoName == QString("all"))
- return getAllInfos();
- else if (infoName == QString("mbserial"))
- return getMainboardSerial();
- else if (infoName == QString("usb"))
- return getUsbVendorIdProductIdSerialNumber();
- else if (infoName == QString("json"))
- return getNames();
- /* unknown code */
- qxtLog->debug() << "[sysinfo] unknown requested";
- return "info_error";
+ qxtLog->debug() << "[sysinfo] requested " << infoName;
+ if (infoName == QString("mac"))
+ return getMACAddress();
+ else if (infoName == QString("ip"))
+ return getIPAddress();
+ else if (infoName == QString("all"))
+ return getAllInfos();
+ else if (infoName == QString("mbserial"))
+ return getMainboardSerial();
+ else if (infoName == QString("usb"))
+ return getUsbVendorIdProductIdSerialNumber();
+ else if (infoName == QString("json"))
+ return getNames();
+ /* unknown code */
+ qxtLog->debug() << "[sysinfo] unknown requested";
+ return "info_error";
}
// ------------------------------------------------------------------------------------------------
/**
@@ -68,16 +68,14 @@ const QString SysInfo::getInfo(const QString& infoName) {
* @see SysInfo::getInfo(const QString& infoName)
*/
const QString SysInfo::getMACAddress() {
- // Returns MAC address of eth0 for now
- QNetworkInterface qni = QNetworkInterface::interfaceFromName(
- QString("eth0"));
- if (!qni.isValid()) {
- qxtLog->debug()
- << "[sysinfo] MAC Address: No interface matching \"eth0\" found.";
- return "no_eth0";
- }
- //eth0_index = qni.index();
- return qni.hardwareAddress();
+ // Returns MAC address of eth0 for now
+ QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0"));
+ if (!qni.isValid()) {
+ qxtLog->debug() << "[sysinfo] MAC Address: No interface matching \"eth0\" found.";
+ return "no_eth0";
+ }
+ //eth0_index = qni.index();
+ return qni.hardwareAddress();
}
// ------------------------------------------------------------------------------------------------
/**
@@ -94,22 +92,20 @@ const QString SysInfo::getMACAddress() {
* @see SysInfo::getInfo(const QString& infoName)
*/
const QString SysInfo::getIPAddress() {
- // Again for eth0 only at the moment.
- // TODO: this doesn't quite work yet...
- QNetworkInterface qni = QNetworkInterface::interfaceFromName(
- QString("eth0"));
- QList<QHostAddress> addrlist = qni.allAddresses();
- // This is does not return the right IP atm...
- foreach(QHostAddress addr, addrlist)
- {
- if (addr.protocol() == QAbstractSocket::IPv4Protocol && addr
- != QHostAddress::LocalHost) {
- return addr.toString();
- }
- }
- // still here?
- qxtLog->debug() << "[sysinfo] IP Address: ip_error";
- return "ip_error";
+ // Again for eth0 only at the moment.
+ // TODO: this doesn't quite work yet...
+ QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0"));
+ QList<QHostAddress> addrlist = qni.allAddresses();
+ // This is does not return the right IP atm...
+ foreach(QHostAddress addr, addrlist)
+ {
+ if (addr.protocol() == QAbstractSocket::IPv4Protocol && addr != QHostAddress::LocalHost) {
+ return addr.toString();
+ }
+ }
+ // still here?
+ qxtLog->debug() << "[sysinfo] IP Address: ip_error";
+ return "ip_error";
}
// ------------------------------------------------------------------------------------------------
/**
@@ -117,22 +113,22 @@ const QString SysInfo::getIPAddress() {
*/
const QByteArray SysInfo::getNames() {
- QVariantMap foo;
- foo.insert("name", "foo");
- foo.insert("type", 123);
+ QVariantMap foo;
+ foo.insert("name", "foo");
+ foo.insert("type", 123);
- QVariantMap fooo;
- fooo.insert("name", "boo");
- fooo.insert("type", 321);
+ QVariantMap fooo;
+ fooo.insert("name", "boo");
+ fooo.insert("type", 321);
- QVariantList jsonV;
- jsonV << foo << fooo;
+ QVariantList jsonV;
+ jsonV << foo << fooo;
- QJson::Serializer serializer;
- QByteArray json = serializer.serialize(jsonV);
+ QJson::Serializer serializer;
+ QByteArray json = serializer.serialize(jsonV);
- qxtLog->debug() << json;
- return json;
+ qxtLog->debug() << json;
+ return json;
}
// ------------------------------------------------------------------------------------------------
@@ -140,17 +136,17 @@ const QByteArray SysInfo::getNames() {
* just a test method for json.
*/
QString SysInfo::getAllInfos() {
- QVariantMap infos;
- infos.insert("mac", getMACAddress());
- infos.insert("ip", getIPAddress());
- infos.insert("whoami", getScriptOutput("whoami"));
- //infos.insert("pwd", getScriptOutput("pwd"));
+ QVariantMap infos;
+ infos.insert("mac", getMACAddress());
+ infos.insert("ip", getIPAddress());
+ infos.insert("whoami", getScriptOutput("whoami"));
+ //infos.insert("pwd", getScriptOutput("pwd"));
- //QJson::Serializer serializer;
- QByteArray json = serializer.serialize(infos);
+ //QJson::Serializer serializer;
+ QByteArray json = serializer.serialize(infos);
- qxtLog->debug() << json;
- return json;
+ qxtLog->debug() << json;
+ return json;
}
// ------------------------------------------------------------------------------------------------
@@ -170,27 +166,26 @@ QString SysInfo::getAllInfos() {
* @see SysInfo::getInfo(const QString& infoName)
*/
const QString SysInfo::getMainboardSerial() {
- QString out = "";
- struct sysfs_class_device *class_device = sysfs_open_class_device("dmi",
- "id");
- struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
- struct sysfs_device *device = sysfs_get_classdev_device(class_device);
+ QString out = "";
+ struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", "id");
+ struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
+ struct sysfs_device *device = sysfs_get_classdev_device(class_device);
- if (attrlist != NULL) {
- struct sysfs_attribute *attr = NULL;
- dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
- QVariantMap a;
- if(QString(attr->name) == QString("board_serial")) {
- out = QString(attr->value);
- }
- }
- qxtLog->debug() << "[sysinfo] Mainboard Serial: " + out;
- return out;
- }
- qxtLog->debug()
- << "[sysinfo] Mainboard Serial: attrlist is null! return: mainboard_serial_error";
- sysfs_close_class_device(class_device);
- return "mainboard_serial_error";
+ if (attrlist != NULL) {
+ struct sysfs_attribute *attr = NULL;
+ dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
+ QVariantMap a;
+ if(QString(attr->name) == QString("board_serial")) {
+ out = QString(attr->value);
+ }
+ }
+ qxtLog->debug() << "[sysinfo] Mainboard Serial: " + out;
+ return out;
+ }
+ qxtLog->debug()
+ << "[sysinfo] Mainboard Serial: attrlist is null! return: mainboard_serial_error";
+ sysfs_close_class_device(class_device);
+ return "mainboard_serial_error";
}
// ------------------------------------------------------------------------------------------------
/**
@@ -215,76 +210,72 @@ const QString SysInfo::getMainboardSerial() {
* @see SysInfo::getInfo(const QString& infoName)
*/
const QString SysInfo::getUsbVendorIdProductIdSerialNumber() {
- QString tag = "[sysinfo] Usb Serial:";
- QString out = "";
- QVariantList list;
+ QString tag = "[sysinfo] Usb Serial:";
+ QString out = "";
+ QVariantList list;
- libusb_device **devs;
- libusb_context *ctx = NULL; //a libusb session
- ssize_t cnt; //holding number of devices in list
- int r = 1;
- r = libusb_init(&ctx);
- if (r < 0) {
- qxtLog->debug() << 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
- }
- qxtLog->debug() << 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
- QVariantMap infos;
- libusb_device *dev = devs[i];
- libusb_device_descriptor desc;
- int re = libusb_get_device_descriptor(dev, &desc);
- if (re < 0) {
- qxtLog->debug() << tag + "failed to get device descriptor";
- return "error";
- }
- infos.insert("vendorId", desc.idVendor);
- infos.insert("productId", desc.idProduct);
- unsigned char string[256];
- libusb_device_handle *handle;
- re = libusb_open(dev, &handle);
- if (re != 0) {
- qxtLog->debug() << 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";
- 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";
- 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";
- return "error";
- }
- infos.insert("manuacturer", QString((const char *) string));
+ libusb_device **devs;
+ libusb_context *ctx = NULL; //a libusb session
+ ssize_t cnt; //holding number of devices in list
+ int r = 1;
+ r = libusb_init(&ctx);
+ if (r < 0) {
+ qxtLog->debug() << 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
+ }
+ qxtLog->debug() << 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
+ QVariantMap infos;
+ libusb_device *dev = devs[i];
+ libusb_device_descriptor desc;
+ int re = libusb_get_device_descriptor(dev, &desc);
+ if (re < 0) {
+ qxtLog->debug() << tag + "failed to get device descriptor";
+ return "error";
+ }
+ infos.insert("vendorId", desc.idVendor);
+ infos.insert("productId", desc.idProduct);
+ unsigned char string[256];
+ libusb_device_handle *handle;
+ re = libusb_open(dev, &handle);
+ if (re != 0) {
+ qxtLog->debug() << 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";
+ 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";
+ 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";
+ return "error";
+ }
+ infos.insert("manuacturer", QString((const char *) string));
- list << infos;
- libusb_close(handle);
- }
- libusb_free_device_list(devs, 1); //free the list, unref the devices in it
- libusb_exit(ctx); //close the session
+ list << infos;
+ libusb_close(handle);
+ }
+ libusb_free_device_list(devs, 1); //free the list, unref the devices in it
+ libusb_exit(ctx); //close the session
- QByteArray json = serializer.serialize(list);
- qxtLog->debug() << tag + "json object: " + json;
- return json;
+ QByteArray json = serializer.serialize(list);
+ qxtLog->debug() << tag + "json object: " + json;
+ return json;
}
// ------------------------------------------------------------------------------------------------
@@ -302,26 +293,25 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() {
* output of the script.
*/
QString SysInfo::getScriptOutput(QString cmd) {
- QProcess *process = new QProcess();
- qxtLog->debug() << "[sysinfo] Script Output: try to open: " << cmd;
- process->start(cmd, QIODevice::ReadOnly);
+ QProcess *process = new QProcess();
+ qxtLog->debug() << "[sysinfo] Script Output: try to open: " << cmd;
+ process->start(cmd, QIODevice::ReadOnly);
- if (!process->waitForStarted())
- qxtLog->debug()
- << "[sysinfo] Script Output: process couldn't get opened";
+ if (!process->waitForStarted())
+ qxtLog->debug() << "[sysinfo] Script Output: process couldn't get opened";
- QString output;
- process->waitForFinished();
+ QString output;
+ process->waitForFinished();
- QTextStream *txt_stream = new QTextStream(process);
+ QTextStream *txt_stream = new QTextStream(process);
- while (!txt_stream->atEnd()) {
- qxtLog->debug() << "[sysinfo] Script Output: read output: ";
- QString tmp_str = txt_stream->readLine();
- output += tmp_str;
- qxtLog->debug() << "[sysinfo] Script Output: " << tmp_str;
- }
- qxtLog->debug() << "[sysinfo] Script Output: process finished: ";
- return output;
+ while (!txt_stream->atEnd()) {
+ qxtLog->debug() << "[sysinfo] Script Output: read output: ";
+ QString tmp_str = txt_stream->readLine();
+ output += tmp_str;
+ qxtLog->debug() << "[sysinfo] Script Output: " << tmp_str;
+ }
+ qxtLog->debug() << "[sysinfo] Script Output: process finished: ";
+ return output;
}
diff --git a/src/sysinfo.h b/src/sysinfo.h
index 2c5d16d..131b369 100644
--- a/src/sysinfo.h
+++ b/src/sysinfo.h
@@ -1,18 +1,18 @@
/*
- # 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
- #
- #
- # Helper class to get system information.
- #
+ * 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
+ *
+ *
+ * Helper class to get system information.
+ *
*/
#ifndef SYSINFO_H
@@ -33,23 +33,23 @@ extern "C" {
class SysInfo {
public:
- SysInfo();
- ~SysInfo();
- // public access, valid infoName: "mac", "ip", ...
- const QString getInfo(const QString& infoName);
+ SysInfo();
+ ~SysInfo();
+ // public access, valid infoName: "mac", "ip", ...
+ const QString getInfo(const QString& infoName);
private:
- // private system information readers
- const QString getMACAddress();
- const QString getIPAddress();
- const QString getMainboardSerial();
- const QString getUsbVendorIdProductIdSerialNumber();
- QString getAllInfos();
- QString getScriptOutput(QString cmd);
-
- // JSon testing
- QJson::Serializer serializer;
- const QByteArray getNames();
+ // private system information readers
+ const QString getMACAddress();
+ const QString getIPAddress();
+ const QString getMainboardSerial();
+ const QString getUsbVendorIdProductIdSerialNumber();
+ QString getAllInfos();
+ QString getScriptOutput(QString cmd);
+
+ // JSon testing
+ QJson::Serializer serializer;
+ const QByteArray getNames();
};
#endif // SYSTINFO_H
diff --git a/src/sysinfolibsysfs.cpp b/src/sysinfolibsysfs.cpp
index 9030155..6dcbcd2 100644
--- a/src/sysinfolibsysfs.cpp
+++ b/src/sysinfolibsysfs.cpp
@@ -14,135 +14,132 @@
// Initialisation
//-------------------------------------------------------------------------------------------------------
SysInfoLibsysfs::SysInfoLibsysfs() {
- // TODO Auto-generated constructor stub
+ // TODO Auto-generated constructor stub
}
SysInfoLibsysfs::~SysInfoLibsysfs() {
- // TODO Auto-generated destructor stub
+ // TODO Auto-generated destructor stub
}
void SysInfoLibsysfs::getInfoAboutNetworkInterface() {
- struct sysfs_class_device *class_device = sysfs_open_class_device("net",
- "eth0");
- struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
- struct sysfs_device *device = sysfs_get_classdev_device(class_device);
- //struct sysfs_driver *driver = sysfs_get_classdev_driver(class_device);
- if (device == NULL) {
- //qxtLog->debug() << "[libsysfs] device is NULL!";
- } else {
- qDebug() << "--- print eth0 device path:";
- qDebug() << QString(device->path);
- }
-
- sysfs_close_class_device(class_device);
+ struct sysfs_class_device *class_device = sysfs_open_class_device("net", "eth0");
+ //struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
+ struct sysfs_device *device = sysfs_get_classdev_device(class_device);
+ //struct sysfs_driver *driver = sysfs_get_classdev_driver(class_device);
+ if (device == NULL) {
+ //qxtLog->debug() << "[libsysfs] device is NULL!";
+ } else {
+ qDebug() << "--- print eth0 device path:";
+ qDebug() << QString(device->path);
+ }
+
+ sysfs_close_class_device(class_device);
}
void SysInfoLibsysfs::getInfoMbSerial() {
- QJson::Serializer serializer;
- QVariantList listOfDevices;
-
- struct sysfs_class_device *class_device = sysfs_open_class_device("dmi",
- "id");
- struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
- struct sysfs_device *device = sysfs_get_classdev_device(class_device);
-
- if (attrlist != NULL) {
- struct sysfs_attribute *attr = NULL;
- QVariantList list;
- dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
- QVariantMap a;
- if(QString(attr->name) == QString("board_serial")) {
- a.insert("name", QString(attr->name));
- a.insert("value", QString(attr->value));
- a.insert("len", QString(attr->len));
- a.insert("path", QString(attr->path));
- a.insert("method", QString(attr->method));
- list << a;
- }
- }
- QByteArray json = serializer.serialize(list);
-
- qDebug() << json;
- return;
- }
- qDebug() << "attrlist is null!";
- sysfs_close_class_device(class_device);
+ QJson::Serializer serializer;
+ QVariantList listOfDevices;
+
+ struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", "id");
+ struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
+ //struct sysfs_device *device = sysfs_get_classdev_device(class_device);
+
+ if (attrlist != NULL) {
+ struct sysfs_attribute *attr = NULL;
+ QVariantList list;
+ dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
+ QVariantMap a;
+ if(QString(attr->name) == QString("board_serial")) {
+ a.insert("name", QString(attr->name));
+ a.insert("value", QString(attr->value));
+ a.insert("len", QString(attr->len));
+ a.insert("path", QString(attr->path));
+ a.insert("method", QString(attr->method));
+ list << a;
+ }
+ }
+ QByteArray json = serializer.serialize(list);
+
+ qDebug() << json;
+ return;
+ }
+ qDebug() << "attrlist is null!";
+ sysfs_close_class_device(class_device);
}
QString SysInfoLibsysfs::getInfoMainboardSerial() {
- QString out = "";
- struct sysfs_class_device *class_device = sysfs_open_class_device("dmi",
- "id");
- struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
- struct sysfs_device *device = sysfs_get_classdev_device(class_device);
-
- if (attrlist != NULL) {
- struct sysfs_attribute *attr = NULL;
- dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
- QVariantMap a;
- if(QString(attr->name) == QString("board_serial")) {
- out = QString(attr->value);
- }
- }
-
- qDebug() << out;
- return out;
- }
- qDebug() << "attrlist is null!";
- sysfs_close_class_device(class_device);
- return NULL;
+ QString out = "";
+ struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", "id");
+ struct dlist *attrlist = sysfs_get_classdev_attributes(class_device);
+ //struct sysfs_device *device = sysfs_get_classdev_device(class_device);
+
+ if (attrlist != NULL) {
+ struct sysfs_attribute *attr = NULL;
+ dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
+ QVariantMap a;
+ if(QString(attr->name) == QString("board_serial")) {
+ out = QString(attr->value);
+ }
+ }
+
+ qDebug() << out;
+ return out;
+ }
+ qDebug() << "attrlist is null!";
+ sysfs_close_class_device(class_device);
+ return NULL;
}
void SysInfoLibsysfs::getInfoAboutClassNet() {
- QJson::Serializer serializer;
- QVariantList listOfDevices;
-
- struct sysfs_class *sysfsclass = sysfs_open_class("net");
- struct dlist *devices = sysfs_get_class_devices(sysfsclass);
- struct sysfs_device *dev = NULL;
- dlist_for_each_data(devices,dev, struct sysfs_device) {
- if(dev == NULL) {
- qDebug() << "device is NULL!";
- //qxtLog->debug() << "[libsysfs] device is NULL!";
- }
- else {
-
- qDebug() << "--- print device:";
-
- QVariantMap infos;
- infos.insert("name", QString(dev->name));
- infos.insert("bus", QString(dev->bus));
- infos.insert("bus_id", QString(dev->bus_id));
- infos.insert("driver_name", QString(dev->driver_name));
- infos.insert("path", QString(dev->path));
- infos.insert("subsystem", QString(dev->subsystem));
- struct dlist *attrlist = dev->attrlist;
- if (attrlist != NULL) {
- struct sysfs_attribute *attr = NULL;
- QVariantList list;
- dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
- QVariantMap a;
- a.insert("name", QString(attr->name));
- a.insert("value", QString(attr->value));
- a.insert("len", QString(attr->len));
- a.insert("path", QString(attr->path));
- a.insert("method", QString(attr->method));
- list << a;
- }
- QByteArray json = serializer.serialize(list);
-
- qDebug() << json;
- infos.insert("attrlist", list);
+ QJson::Serializer serializer;
+ QVariantList listOfDevices;
+
+ struct sysfs_class *sysfsclass = sysfs_open_class("net");
+ struct dlist *devices = sysfs_get_class_devices(sysfsclass);
+ struct sysfs_device *dev = NULL;
+ dlist_for_each_data(devices,dev, struct sysfs_device) {
+ if(dev == NULL) {
+ qDebug() << "device is NULL!";
+ //qxtLog->debug() << "[libsysfs] device is NULL!";
+ }
+ else {
+
+ qDebug() << "--- print device:";
+
+ QVariantMap infos;
+ infos.insert("name", QString(dev->name));
+ infos.insert("bus", QString(dev->bus));
+ infos.insert("bus_id", QString(dev->bus_id));
+ infos.insert("driver_name", QString(dev->driver_name));
+ infos.insert("path", QString(dev->path));
+ infos.insert("subsystem", QString(dev->subsystem));
+ struct dlist *attrlist = dev->attrlist;
+ if (attrlist != NULL) {
+ struct sysfs_attribute *attr = NULL;
+ QVariantList list;
+ dlist_for_each_data(attrlist, attr, struct sysfs_attribute) {
+ QVariantMap a;
+ a.insert("name", QString(attr->name));
+ a.insert("value", QString(attr->value));
+ a.insert("len", QString(attr->len));
+ a.insert("path", QString(attr->path));
+ a.insert("method", QString(attr->method));
+ list << a;
}
- listOfDevices << infos;
- }
+ QByteArray json = serializer.serialize(list);
+
+ qDebug() << json;
+ infos.insert("attrlist", list);
+ }
+ listOfDevices << infos;
+ }
- }
+ }
- sysfs_close_class(sysfsclass);
+ sysfs_close_class(sysfsclass);
- QByteArray json = serializer.serialize(listOfDevices);
+ QByteArray json = serializer.serialize(listOfDevices);
- qDebug() << json;
+ qDebug() << json;
}
diff --git a/src/sysinfolibsysfs.h b/src/sysinfolibsysfs.h
index f5de0aa..c933efa 100644
--- a/src/sysinfolibsysfs.h
+++ b/src/sysinfolibsysfs.h
@@ -1,22 +1,22 @@
/*
- # 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
- #
- #
- # Class collects informations about hardware devices of the client:
- # - ip address
- # - mac address
- #
- #
- # All methods return the collected informations as json- parsable object.
+ * 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
+ *
+ *
+ * Class collects informations about hardware devices of the client:
+ * - ip address
+ * - mac address
+ *
+ *
+ * All methods return the collected informations as json- parsable object.
* sysinfolibsysfs.h
*
@@ -39,16 +39,15 @@ extern "C" {
#include "fbgui.h"
#include <qjson/serializer.h>
-class SysInfoLibsysfs : public QObject
-{
- Q_OBJECT
+class SysInfoLibsysfs: public QObject {
+Q_OBJECT
public:
- SysInfoLibsysfs();
- virtual ~SysInfoLibsysfs();
- void getInfoAboutNetworkInterface();
- void getInfoAboutClassNet();
- void getInfoMbSerial();
- QString getInfoMainboardSerial();
+ SysInfoLibsysfs();
+ virtual ~SysInfoLibsysfs();
+ void getInfoAboutNetworkInterface();
+ void getInfoAboutClassNet();
+ void getInfoMbSerial();
+ QString getInfoMainboardSerial();
};