summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonathan Bauer2011-04-18 02:13:18 +0200
committerJonathan Bauer2011-04-18 02:13:18 +0200
commite512c756586d5509ac11759bae40f7911fe0f948 (patch)
tree65873adce9fa6401026b1b4c89f12a1e8868e3c2 /src
parentcursor hidden by QWSServer, added loading animation for preload page, started... (diff)
downloadfbgui-e512c756586d5509ac11759bae40f7911fe0f948.tar.gz
fbgui-e512c756586d5509ac11759bae40f7911fe0f948.tar.xz
fbgui-e512c756586d5509ac11759bae40f7911fe0f948.zip
uniformed formatting...
Diffstat (limited to 'src')
-rw-r--r--src/downloadmanager.cpp342
-rw-r--r--src/downloadmanager.h115
-rw-r--r--src/fbgui.cpp116
-rw-r--r--src/fbgui.h129
-rw-r--r--src/javascriptinterface.cpp95
-rw-r--r--src/javascriptinterface.h84
-rw-r--r--src/loggerengine.cpp102
-rw-r--r--src/loggerengine.h63
-rw-r--r--src/main.cpp123
-rw-r--r--src/sysinfo.cpp330
-rw-r--r--src/sysinfo.h61
-rw-r--r--src/sysinfolibsysfs.cpp240
-rw-r--r--src/sysinfolibsysfs.h36
13 files changed, 932 insertions, 904 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index aa0682c..c9fc7fc 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -3,207 +3,217 @@
int DownloadManager::downloaded = 0;
// -------------------------------------------------------------------------------------------------------
-DownloadManager::DownloadManager(){
- qxtLog->debug() << "Initializing download manager...";
- checkDownloadDirectory();
- _qnam = new QNetworkAccessManager();
- //_qnam->moveToThread(&dmThread);
- dip = false;
+DownloadManager::DownloadManager() {
+ qxtLog->debug() << "Initializing download manager...";
+ checkDownloadDirectory();
+ _qnam = new QNetworkAccessManager();
+ //_qnam->moveToThread(&dmThread);
+ dip = false;
}
-DownloadManager::~DownloadManager(){
+DownloadManager::~DownloadManager() {
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.";
+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.";
- 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);
+void DownloadManager::downloadFile(const QString& filename) {
+ QUrl fileUrl(baseURL.resolved(QUrl(filename)));
+ this->processDownloadRequest(fileUrl);
}
// -------------------------------------------------------------------------------------------------------
-void DownloadManager::downloadFile(const QUrl& fileUrl)
-{
- this->processDownloadRequest(fileUrl);
+void DownloadManager::downloadFile(const QUrl& 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();
+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();
}
// -------------------------------------------------------------------------------------------------------
-void DownloadManager::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.)";
+ 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.)";
- // dequeue next URL to download.
- QUrl url = dlQ.dequeue();
+ // dequeue next URL to download.
+ QUrl url = dlQ.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());
+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());
}
// -------------------------------------------------------------------------------------------------------
-void DownloadManager::downloadReady()
-{
- // data ready, save it
- outfile.write(currentDownload->readAll());
+void DownloadManager::downloadReady() {
+ // 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){
+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;
+ } 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 << "\%)";
- }
+ }
+ // 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));
+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();
+ } 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();
}
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 44194d3..a7afe23 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.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 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
#define DOWNLOADMANAGER_H
@@ -29,58 +29,57 @@ extern QString binPath;
extern QString downloadPath;
extern int updateInterval;
-
-class DownloadManager : public QObject
-{
- Q_OBJECT
+class DownloadManager: public QObject {
+Q_OBJECT
public:
- DownloadManager();
- ~DownloadManager();
+ 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> dlQ;
+ 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 f27a698..add6cfc 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -31,38 +31,41 @@ int debugMode = -1;
* @see JavascriptInterface
* @see DownloadManager
*/
-fbgui::fbgui()
-{
+fbgui::fbgui() {
// test for libsys function
//SysInfoLibsysfs* sil = new SysInfoLibsysfs();
//sil->getInfoAboutNetworkInterface();
//sil->getInfoMainboardSerial();
- //SysInfo si;
- //qxtLog->debug() << si.getInfo("mbserial");
- //si.getInfo("usb");
+ //SysInfo si;
+ //qxtLog->debug() << si.getInfo("mbserial");
+ //si.getInfo("usb");
setupLayout();
createActions();
// initialize javascript interface
- JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame());
+ JavascriptInterface* jsi = new JavascriptInterface(
+ _webView->page()->mainFrame());
QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));
- QObject::connect(_webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
- jsi, SLOT(attachToDOM()));
-
+ QObject::connect(_webView->page()->mainFrame(),
+ SIGNAL(javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM()));
// 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()));
+ 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()));
// move download manager to its own thread
//dm->moveToThread(&dmThread);
@@ -81,7 +84,7 @@ fbgui::fbgui()
setWindowFlags(Qt::FramelessWindowHint);
showFullScreen();
}
-fbgui::~fbgui(){
+fbgui::~fbgui() {
//dmThread.quit();
}
//-------------------------------------------------------------------------------------------
@@ -95,27 +98,24 @@ fbgui::~fbgui(){
* - debug mode: the screen is divided into the browser and a debug
* out console
*/
-void fbgui::setupLayout()
-{
+void fbgui::setupLayout() {
// setup layout of the gui: debug split or browser
_webView = new QWebView(this);
- if (debugMode == 1){
+ 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
+ } else
setCentralWidget(_webView);
}
//-------------------------------------------------------------------------------------------
/**
* This method enables a shortcut for closing the program.
*/
-void fbgui::createActions()
-{
+void fbgui::createActions() {
// CTRL + X to kill the gui
_quit = new QAction(tr("&quit"), this);
_quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X));
@@ -134,31 +134,30 @@ void fbgui::createActions()
* fbgui::checkForTrigger(const QString& dirname) method will be called.
*
*/
-void fbgui::watchForTrigger()
-{
+void fbgui::watchForTrigger() {
// check if fileToTriggerURL already exists
QFile file(fileToTriggerURL);
- if (file.exists()){
- qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!";
+ if (file.exists()) {
+ qxtLog->debug() << "[watcher] " << fileToTriggerURL
+ << " exists already!";
// try to load URL
loadURL();
- }
- else {
+ } else {
// create it
- if (file.open(QIODevice::WriteOnly)){
+ if (file.open(QIODevice::WriteOnly)) {
qxtLog->debug() << "[gui] Created: " << fileToTriggerURL;
file.close();
- }
- else {
- qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL << " failed! Exiting...";
- exit(EXIT_FAILURE);
+ } 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()));
+ QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this,
+ SLOT(prepareURLLoad()));
}
//-------------------------------------------------------------------------------------------
@@ -172,8 +171,7 @@ void fbgui::watchForTrigger()
* @see fbgui::checkHost()
* @see fbgui::loadURL()
*/
-void fbgui::prepareURLLoad()
-{
+void fbgui::prepareURLLoad() {
qxtLog->debug() << "[watcher] " << fileToTriggerURL << " changed!";
// disconnect _watcher, his job is done
qxtLog->debug() << "[watcher] disconnected.";
@@ -190,15 +188,15 @@ void fbgui::prepareURLLoad()
*
* This method checks if is connected to the internet.
*/
-bool fbgui::checkHost() const
-{
+bool fbgui::checkHost() const {
QHostInfo hostInfo = QHostInfo::fromName(baseURL.host());
- if (hostInfo.error() != QHostInfo::NoError){
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed. Exiting...";
+ 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.";
+ } else {
+ qxtLog->debug() << "[gui] Lookup of " << baseURL.host()
+ << " succeeded.";
return true;
}
}
@@ -213,9 +211,8 @@ bool fbgui::checkHost() const
* @see fbgui::watchForTrigger()
* @see fbgui::generatePOSTData()
*/
-void fbgui::loadURL()
-{
- if (checkHost()){
+void fbgui::loadURL() {
+ if (checkHost()) {
qxtLog->debug() << "[gui] Loading URL...";
QByteArray postData = generatePOSTData();
QNetworkRequest req(baseURL);
@@ -238,8 +235,7 @@ void fbgui::loadURL()
* @see SysInfo::getMACAddress()
* @see SysInfo::getMainboardSerial()
*/
-QByteArray fbgui::generatePOSTData()
-{
+QByteArray fbgui::generatePOSTData() {
qxtLog->debug() << "[gui] Generating POST data...";
// use MAC address as base data
SysInfo si;
@@ -254,14 +250,14 @@ QByteArray fbgui::generatePOSTData()
// fetch serial number from usb
QByteArray serial;
QFile file(serialLocation);
- if (!file.open(QIODevice::ReadOnly)){
+ 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;
+ qxtLog->debug() << "[post] Serial number is: " << serial;
// construct final byte array
QByteArray postData("mac=");
@@ -274,8 +270,7 @@ QByteArray fbgui::generatePOSTData()
//-------------------------------------------------------------------------------------------
// Debug console setup / control
//-------------------------------------------------------------------------------------------
-void fbgui::createDebugConsole()
-{
+void fbgui::createDebugConsole() {
// create the debug console widget
_debugConsole = new QTextEdit(this);
_debugConsole->setWindowFlags(Qt::FramelessWindowHint);
@@ -292,10 +287,11 @@ void fbgui::createDebugConsole()
_toggleDebugConsole = new QAction(tr("&toggleDebug"), this);
_toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
addAction(_toggleDebugConsole);
- connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(toggleDebugConsole()));
+ connect(_toggleDebugConsole, SIGNAL(triggered()), this,
+ SLOT(toggleDebugConsole()));
}
//-------------------------------------------------------------------------------------------
-void fbgui::toggleDebugConsole()
-{
- (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show();
+void fbgui::toggleDebugConsole() {
+ (_debugConsole->isVisible()) ? _debugConsole->hide()
+ : _debugConsole->show();
}
diff --git a/src/fbgui.h b/src/fbgui.h
index f3c2a77..a703d6e 100644
--- a/src/fbgui.h
+++ b/src/fbgui.h
@@ -1,20 +1,20 @@
/*
-# 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
#define FBGUI_H
@@ -24,7 +24,6 @@
#include <QtWebKit>
#include <QxtCore>
-
// Internal default settings
#define DEFAULT_URL "http://www.google.com"
#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads"
@@ -33,7 +32,6 @@
#define DEFAULT_QRC_HTML_DIR ":/html"
#define DEFAULT_FILE_TRIGGER "/tmp/fbgui/trigger"
-
// Global settings variables
extern QThread dmThread;
extern QString serialLocation;
@@ -45,67 +43,66 @@ extern QUrl baseURL;
extern int debugMode;
extern int updateInterval;
-class fbgui : public QMainWindow
-{
- Q_OBJECT
+class fbgui: public QMainWindow {
+Q_OBJECT
public:
- fbgui();
- ~fbgui();
+ fbgui();
+ ~fbgui();
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.
+ //-------------------
+ // 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:
+ // 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;
+ 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();
+ // 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();
+ // triggered by fileChanged Signal of _watcher
+ // deletes _watcher, since we don't need it anymore and tries to load URL.
+ void prepareURLLoad();
};
#endif // FBGUI_H
diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp
index 634b478..ea25855 100644
--- a/src/javascriptinterface.cpp
+++ b/src/javascriptinterface.cpp
@@ -2,7 +2,6 @@
#include "javascriptinterface.h"
#include "sysinfo.h"
-
//-------------------------------------------------------------------------------------------------------
// Initialisation
//-------------------------------------------------------------------------------------------------------
@@ -12,15 +11,16 @@
* @param parent
* Is of type QWebFrame.
*/
-JavascriptInterface::JavascriptInterface(QWebFrame *parent){
- qxtLog->debug() << "Initializing javascript interface...";
- _parent = parent;
+JavascriptInterface::JavascriptInterface(QWebFrame *parent) {
+ qxtLog->debug() << "Initializing javascript interface...";
+ _parent = parent;
}
//-------------------------------------------------------------------------------------------------------
/**
* An empty destructor.
*/
-JavascriptInterface::~JavascriptInterface() { /* destructor dummy */ }
+JavascriptInterface::~JavascriptInterface() { /* destructor dummy */
+}
//-------------------------------------------------------------------------------------------------------
/**
* Attaches an instance of this class to the DOM of the HTML page.
@@ -32,9 +32,9 @@ JavascriptInterface::~JavascriptInterface() { /* destructor dummy */ }
*
* @see JavascriptInterface::loadJQuery()
*/
-void JavascriptInterface::attachToDOM(){
- _parent->addToJavaScriptWindowObject(QString("fbgui"), this);
- loadJQuery();
+void JavascriptInterface::attachToDOM() {
+ _parent->addToJavaScriptWindowObject(QString("fbgui"), this);
+ loadJQuery();
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -48,7 +48,7 @@ void JavascriptInterface::attachToDOM(){
*
* @see JavascriptInterface::attachToDOM()
*/
-void JavascriptInterface::loadJQuery(){
+void JavascriptInterface::loadJQuery() {
QString js;
QString pathToJsDir(DEFAULT_QRC_HTML_DIR);
pathToJsDir.append("/js");
@@ -57,24 +57,22 @@ void JavascriptInterface::loadJQuery(){
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();
+ 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
@@ -86,13 +84,13 @@ void JavascriptInterface::loadJQuery(){
* Can be called from inside a JavaScript function of the HTML page.
* 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);
+void JavascriptInterface::startDownload(const QString& filename) {
+ // ignore if empty filename
+ if (filename.isEmpty()) {
+ _parent->evaluateJavaScript("alert(\"No filename!\")");
+ return;
+ }
+ emit requestFile(filename);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -103,7 +101,7 @@ void JavascriptInterface::startDownload(const QString& filename){
*
* @todo add some more informations
*/
-void JavascriptInterface::setCallbackOnFinished(const QString& function){
+void JavascriptInterface::setCallbackOnFinished(const QString& function) {
qxtLog->debug() << "[jsi] Callback set: " << function;
_callbackOnDownloadsFinished = QString(function);
}
@@ -128,7 +126,7 @@ void JavascriptInterface::setCallbackOnFinished(const QString& function){
*
* @see SysInfo::getInfo(const QString& infoName)
*/
-const QString JavascriptInterface::getSysInfo(const QString& info){
+const QString JavascriptInterface::getSysInfo(const QString& info) {
SysInfo si;
return si.getInfo(info);
}
@@ -140,7 +138,7 @@ const QString JavascriptInterface::getSysInfo(const QString& info){
* Can be called from inside a JavaScript function of the HTML page.
* Emits JavascriptInterface::quitFbgui() signal
*/
-void JavascriptInterface::quit(){
+void JavascriptInterface::quit() {
emit quitFbgui();
}
//-------------------------------------------------------------------------------------------------------
@@ -153,9 +151,11 @@ void JavascriptInterface::quit(){
*
* @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);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -166,10 +166,13 @@ void JavascriptInterface::downloadInfo(const QString& filename, const double& fi
*
* @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);
}
//-------------------------------------------------------------------------------------------------------
/**
@@ -177,7 +180,7 @@ void JavascriptInterface::updateProgressBar(const int& percent, const double& sp
*
* @todo add some more informations.
*/
-void JavascriptInterface::notify(const QString& msg){
+void JavascriptInterface::notify(const QString& msg) {
qxtLog->debug() << "[jsi] Notifying: " << msg;
QString code = QString("notify('\%1')").arg(msg);
_parent->evaluateJavaScript(code);
@@ -186,9 +189,9 @@ void JavascriptInterface::notify(const QString& msg){
/**
* @todo add some more informations
*/
-void JavascriptInterface::callbackOnFinished(){
- QString code = QString("\%1").arg(_callbackOnDownloadsFinished);
- _parent->evaluateJavaScript(code);
+void JavascriptInterface::callbackOnFinished() {
+ QString code = QString("\%1").arg(_callbackOnDownloadsFinished);
+ _parent->evaluateJavaScript(code);
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
@@ -206,9 +209,9 @@ void JavascriptInterface::callbackOnFinished(){
* @see bool fbgui::checkHost()
* @see void fbgui::loadURL()
*/
-void JavascriptInterface::trigger(){
+void JavascriptInterface::trigger() {
QFile file(fileToTriggerURL);
- if (file.open(QIODevice::WriteOnly)){
+ if (file.open(QIODevice::WriteOnly)) {
file.write("data\n");
qxtLog->debug() << "[jsi] *trigger watcher*";
}
diff --git a/src/javascriptinterface.h b/src/javascriptinterface.h
index e686b77..9d7bd37 100644
--- a/src/javascriptinterface.h
+++ b/src/javascriptinterface.h
@@ -1,66 +1,66 @@
/*
-# 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_
#define JAVASCRIPTINTERFACE_H_
#include "fbgui.h"
-class JavascriptInterface : public QObject
-{
- Q_OBJECT
+class JavascriptInterface: public QObject {
+Q_OBJECT
public:
- JavascriptInterface(QWebFrame* parent);
- ~JavascriptInterface();
+ JavascriptInterface(QWebFrame* parent);
+ ~JavascriptInterface();
private:
- // pointer to parent
- QWebFrame* _parent;
- // function to be called withint javascript when downloads are done.
- QString _callbackOnDownloadsFinished;
- // loads jQuery code
- void loadJQuery();
+ // pointer to parent
+ QWebFrame* _parent;
+ // function to be called withint javascript when downloads are done.
+ QString _callbackOnDownloadsFinished;
+ // loads jQuery code
+ void loadJQuery();
signals:
// request the file from download manager
- void requestFile(const QString& filename);
- // quit the application
- void quitFbgui();
+ void requestFile(const QString& filename);
+ // quit the application
+ void quitFbgui();
public slots:
// make sure the interface stays attached on webpage reload
- void attachToDOM();
+ 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();
+ // slots for calling from the webpage
+ void startDownload(const QString& filename);
+ void setCallbackOnFinished(const QString& function);
+ const QString getSysInfo(const QString& info);
+ void quit();
- // callback when downloads are done.
+ // 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();
+ // test stuff
+ void trigger();
};
#endif // JAVASCRIPTINTERFACE_H_
diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp
index 8f051c8..d37999d 100644
--- a/src/loggerengine.cpp
+++ b/src/loggerengine.cpp
@@ -3,72 +3,84 @@
// --------------------------------------------------------------------------------------------------
// base of a custom logger engine for the framebuffer
//---------------------------------------------------------------------------------------------------
-LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){
- // TODO: silly parent storing ... to change!
- _debugConsole = parent;
- //_initialized = false;
- //setLogLevelsEnabled(QxtLogger::DebugLevel);
- //enableLogging();
+LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) :
+ QxtLoggerEngine() {
+ _debugConsole = parent;
+ //_initialized = false;
+ //setLogLevelsEnabled(QxtLogger::DebugLevel);
+ //enableLogging();
+}
+LoggerEngine_fb::~LoggerEngine_fb() {
}
-LoggerEngine_fb::~LoggerEngine_fb(){}
-void LoggerEngine_fb::initLoggerEngine(){
- //_initialized = true;
- return;
+void LoggerEngine_fb::initLoggerEngine() {
+ //_initialized = true;
+ return;
}
-void LoggerEngine_fb::killLoggerEngine(){
- return;
+void LoggerEngine_fb::killLoggerEngine() {
+ return;
}
-void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable){
+void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level,
+ bool enable) {
//QxtLoggerEngine::setLogLevelsEnabled(level, enable);
//if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel);
}
-bool LoggerEngine_fb::isInitialized() const{
- //return _initialized;
- return true;
+bool LoggerEngine_fb::isInitialized() const {
+ //return _initialized;
+ return true;
}
-void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs){
- // TODO: handle different log levels
- 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);
- }
+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);
+ }
}
//---------------------------------------------------------------------------------------------------
// slighty modified QxtBasicSTDLoggerEngine
//---------------------------------------------------------------------------------------------------
-LoggerEngine_std::LoggerEngine_std() : QxtBasicSTDLoggerEngine(){}
+LoggerEngine_std::LoggerEngine_std() :
+ QxtBasicSTDLoggerEngine() {
+}
-LoggerEngine_std::~LoggerEngine_std(){}
+LoggerEngine_std::~LoggerEngine_std() {
+}
+
+void LoggerEngine_std::writeToStdErr(const QString& str_level,
+ const QList<QVariant> &msgs) {
-void LoggerEngine_std::writeToStdErr(const QString& str_level, const QList<QVariant> &msgs){
- if (msgs.isEmpty()) return;
- QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] ";
+ 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();
- }
+ {
+ if (!out.isNull())
+ *errstream << out.toString();
+ }
*errstream << endl;
}
-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_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
}
diff --git a/src/loggerengine.h b/src/loggerengine.h
index 8e4a818..9c3ab96 100644
--- a/src/loggerengine.h
+++ b/src/loggerengine.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
-#
-#
-# 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_
@@ -23,19 +23,20 @@
//---------------------------------------------------------------------------------------------------
// base of a custom logger engine for the framebuffer
//---------------------------------------------------------------------------------------------------
-class LoggerEngine_fb : public QxtLoggerEngine {
+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);
+ // 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;
@@ -43,14 +44,14 @@ public:
//---------------------------------------------------------------------------------------------------
// slighty modified QxtBasicSTDLoggerEngine
//---------------------------------------------------------------------------------------------------
-class LoggerEngine_std : public QxtBasicSTDLoggerEngine {
+class LoggerEngine_std: public QxtBasicSTDLoggerEngine {
public:
- LoggerEngine_std();
- ~LoggerEngine_std();
+ LoggerEngine_std();
+ ~LoggerEngine_std();
- // 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 QxtBasicSTDLoggerEngineqqq
+ void writeToStdOut(const QString& level, const QList<QVariant> &msgs);
+ void writeToStdErr(const QString& str_level, const QList<QVariant> &msgs);
};
#endif // LOGGERENGINE_H_
diff --git a/src/main.cpp b/src/main.cpp
index 7d73754..0e7957c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,24 +7,30 @@
#include "loggerengine.h"
#include "fbgui.h"
-void printHelp()
-{
+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 << "-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);
+ exit( EXIT_SUCCESS);
}
-int main(int argc, char *argv[])
-{
+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.
@@ -45,42 +51,36 @@ int main(int argc, char *argv[])
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'}
- };
+ 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;
+ 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);
}
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
if (clOpts.contains("help"))
printHelp();
- if (clOpts.contains("debug")){
+ if (clOpts.contains("debug")) {
debugMode = clOpts.value("debug").toInt();
// start basic debug log
qxtLog->disableLoggerEngine("DEFAULT");
@@ -97,8 +97,7 @@ int main(int argc, char *argv[])
qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel);
qxtLog->enableLogLevels(QxtLogger::DebugLevel);
qxtLog->debug() << "Initializing fbgui...";
- }
- else
+ } else
debugMode = -1;
// look for config file either in:
@@ -111,7 +110,7 @@ int main(int argc, char *argv[])
if (clOpts.contains("configFile"))
configFilePath = clOpts.value("configFile");
else {
- confInfo = QFileInfo(QDir::home(), ".fbgui.conf");
+ confInfo = QFileInfo(QDir::home(), ".fbgui.conf");
if (confInfo.exists())
configFilePath = confInfo.absoluteFilePath();
else {
@@ -131,28 +130,31 @@ int main(int argc, char *argv[])
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;
+ 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();
+ 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;
+ 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();
+ fileToTriggerURL
+ = confFileSettings.value("default/file_trigger").toString();
else
fileToTriggerURL = DEFAULT_FILE_TRIGGER;
@@ -160,7 +162,8 @@ int main(int argc, char *argv[])
if (clOpts.contains("serialLocation"))
serialLocation = clOpts.value("serialLocation");
else if (confFileSettings.contains("default/serial_location"))
- serialLocation = confFileSettings.value("default/serial_location").toString();
+ serialLocation
+ = confFileSettings.value("default/serial_location").toString();
else
serialLocation = QString("/serial"); // tests
diff --git a/src/sysinfo.cpp b/src/sysinfo.cpp
index 569fd06..ef7dc04 100644
--- a/src/sysinfo.cpp
+++ b/src/sysinfo.cpp
@@ -1,16 +1,17 @@
#include "sysinfo.h"
-
// ------------------------------------------------------------------------------------------------
/**
* A empty constructor.
*/
-SysInfo::SysInfo(){}
+SysInfo::SysInfo() {
+}
// ------------------------------------------------------------------------------------------------
/**
* A empty destructor.
*/
-SysInfo::~SysInfo(){}
+SysInfo::~SysInfo() {
+}
// ------------------------------------------------------------------------------------------------
/**
* This method returns system informations.
@@ -32,23 +33,23 @@ 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";
+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";
}
// ------------------------------------------------------------------------------------------------
/**
@@ -66,15 +67,17 @@ const QString SysInfo::getInfo(const QString& infoName){
* @see fbgui::generatePOSTData()
* @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();
+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();
}
// ------------------------------------------------------------------------------------------------
/**
@@ -90,61 +93,64 @@ 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";
+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";
}
// ------------------------------------------------------------------------------------------------
/**
* just a test method for json.
*/
-const QByteArray SysInfo::getNames(){
+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;
}
// ------------------------------------------------------------------------------------------------
/**
* 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"));
+QString SysInfo::getAllInfos() {
+ 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;
}
// ------------------------------------------------------------------------------------------------
@@ -163,26 +169,28 @@ QString SysInfo::getAllInfos(){
* @see fbgui::generatePOSTData()
* @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);
+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);
- 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";
}
// ------------------------------------------------------------------------------------------------
/**
@@ -206,74 +214,77 @@ const QString SysInfo::getMainboardSerial(){
*
* @see SysInfo::getInfo(const QString& infoName)
*/
-const QString SysInfo::getUsbVendorIdProductIdSerialNumber()
-{
- QString tag = "[sysinfo] Usb Serial:";
- QString out = "";
- QVariantList list;
+const QString SysInfo::getUsbVendorIdProductIdSerialNumber() {
+ 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;
}
// ------------------------------------------------------------------------------------------------
@@ -290,28 +301,27 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber()
* @return QString
* output of the script.
*/
-QString SysInfo::getScriptOutput(QString cmd)
-{
+QString SysInfo::getScriptOutput(QString cmd) {
QProcess *process = new QProcess();
- qxtLog->debug()<<"[sysinfo] Script Output: try to open: "<<cmd;
+ 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();
QTextStream *txt_stream = new QTextStream(process);
- while(!txt_stream->atEnd() )
- {
- qxtLog->debug()<<"[sysinfo] Script Output: read 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: " << tmp_str;
}
- qxtLog->debug()<<"[sysinfo] Script Output: process finished: ";
+ qxtLog->debug() << "[sysinfo] Script Output: process finished: ";
return output;
}
diff --git a/src/sysinfo.h b/src/sysinfo.h
index f4968e8..7b9cf17 100644
--- a/src/sysinfo.h
+++ b/src/sysinfo.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
-#
-#
-# 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
#define SYSINFO_H
@@ -33,24 +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 2c9aafc..9030155 100644
--- a/src/sysinfolibsysfs.cpp
+++ b/src/sysinfolibsysfs.cpp
@@ -14,137 +14,135 @@
// 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);
+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);
}
-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);
+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);
}
-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 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;
}
-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);
- }
- listOfDevices << infos;
- }
-
- }
-
- sysfs_close_class(sysfsclass);
-
-
- QByteArray json = serializer.serialize(listOfDevices);
-
- qDebug() << json;
+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);
+ }
+ listOfDevices << infos;
+ }
+
+ }
+
+ sysfs_close_class(sysfsclass);
+
+ QByteArray json = serializer.serialize(listOfDevices);
+
+ qDebug() << json;
}
diff --git a/src/sysinfolibsysfs.h b/src/sysinfolibsysfs.h
index 3da58ce..d45b0f1 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
*