summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2010-06-16 16:30:18 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2010-06-19 11:19:42 +0200
commit21c3f2360967138d9dfc13a3985fb92ca1c44027 (patch)
treef5f3e326ce1d768e1dacdcc0fc0407f6fdd41523
parent161a7ba4a460f06ee15969eaf9352f25e9aa5663 (diff)
[dbus-info-service] add qt4 dbus service
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--configure.ac14
-rwxr-xr-xrun.sh.in5
-rw-r--r--services/Makefile.am3
-rw-r--r--services/qt4/Makefile.am16
-rw-r--r--services/qt4/dbus-info-service/dbus-info-service.cpp35
-rw-r--r--services/qt4/dbus-info-service/dbus-info-service.pro15
-rw-r--r--services/qt4/dbus-info-service/service.cpp98
-rw-r--r--services/qt4/dbus-info-service/service.h120
8 files changed, 305 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 0376d2d..136bc56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,18 @@ fi
AC_ARG_VAR([JSON_DBUS_BRIDGE], [json-dbus-bridge FCGI application])
AC_SUBST(JSON_DBUS_BRIDGE)
+AC_PATH_PROGS([QMAKE],[qmake-qt4 qmake],,)
+if test -z "$QMAKE"; then
+ AC_MSG_ERROR([qmake (Qt4) not found. Define QMAKE=/path/to/qmake or make sure qmake is in \$PATH])
+fi
+"$QMAKE" -v 2>&1 | grep -q "Using Qt version 4"
+if test $? -ne 0 ; then
+ AC_MSG_ERROR([$QMAKE is not qmake from Qt4. Define QMAKE=/path/to/qmake or make sure the correct qmake is found.])
+fi
+AC_ARG_VAR([QMAKE], [qmake from Qt4])
+AC_SUBST(QMAKE)
+export QMAKE
+
AC_ARG_WITH([qooxdoo-sdk],AS_HELP_STRING([--with-qooxdoo-sdk=PATH], [Path to qooxdoo sdk]),
if test -x "$withval/tool/bin/generator.py"; then
QOOXDOO_SDK="$withval"
@@ -49,6 +61,7 @@ AC_CONFIG_FILES([
lighttpd/lighttpd.conf
services/Makefile
services/python/Makefile
+ services/qt4/Makefile
web-gui/Makefile
web-gui/hello-world/Makefile
web-gui/hello-world/config.json
@@ -64,6 +77,7 @@ AC_CONFIG_FILES([web-gui/hello-world/generate.py],[chmod +x web-gui/hello-world/
AC_CONFIG_FILES([web-gui/calculator/generate.py],[chmod +x web-gui/calculator/generate.py])
AC_CONFIG_FILES([web-gui/live/generate.py],[chmod +x web-gui/live/generate.py])
AC_CONFIG_FILES([web-gui/logging/generate.py],[chmod +x web-gui/logging/generate.py])
+AC_CONFIG_COMMANDS([services/qt4/dbus-info-service/Makefile], [(cd services/qt4/dbus-info-service && $QMAKE ../../../${srcdir}/services/qt4/dbus-info-service/dbus-info-service.pro)])
AC_OUTPUT
diff --git a/run.sh.in b/run.sh.in
index 0ef7f14..45e9883 100755
--- a/run.sh.in
+++ b/run.sh.in
@@ -18,6 +18,7 @@ fi
finish() {
kill $hello_pid
kill $calculator_pid
+ kill $systeminfo_pid
kill $lighttpd_pid
exit
}
@@ -30,6 +31,10 @@ hello_pid=$!
"@abs_srcdir@/services/python/calculator.py" &
calculator_pid=$!
+"@abs_builddir@/services/qt4/dbus-info-service/dbus-info-service" &
+systeminfo_pid=$!
+
+
@LIGHTTPD@ -f "@abs_builddir@/lighttpd/lighttpd.conf" -D &
lighttpd_pid=$!
diff --git a/services/Makefile.am b/services/Makefile.am
index 3d8b377..9b22761 100644
--- a/services/Makefile.am
+++ b/services/Makefile.am
@@ -1,4 +1,5 @@
SUBDIRS = \
- python
+ python \
+ qt4
diff --git a/services/qt4/Makefile.am b/services/qt4/Makefile.am
new file mode 100644
index 0000000..9126c71
--- /dev/null
+++ b/services/qt4/Makefile.am
@@ -0,0 +1,16 @@
+
+all-local:
+ $(MAKE) -C dbus-info-service all
+
+clean-local:
+ $(MAKE) -C dbus-info-service clean
+
+distclean-local:
+ $(MAKE) -C dbus-info-service distclean
+
+EXTRA_DIST = \
+ dbus-info-service/dbus-info-service.pro \
+ dbus-info-service/dbus-info-service.cpp \
+ dbus-info-service/service.cpp \
+ dbus-info-service/service.h
+
diff --git a/services/qt4/dbus-info-service/dbus-info-service.cpp b/services/qt4/dbus-info-service/dbus-info-service.cpp
new file mode 100644
index 0000000..ef93a26
--- /dev/null
+++ b/services/qt4/dbus-info-service/dbus-info-service.cpp
@@ -0,0 +1,35 @@
+
+#include <QtCore/QCoreApplication>
+#include <QtDBus/QtDBus>
+
+#include "service.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
+ "To start it, run:\n"
+ "\teval `dbus-launch --auto-syntax`\n");
+ return 1;
+ }
+
+ if (!QDBusConnection::sessionBus().registerService("com.pengutronix.jdb.systeminfo")) {
+ fprintf(stderr, "%s\n",
+ qPrintable(QDBusConnection::sessionBus().lastError().message()));
+ exit(1);
+ }
+
+ QObject o;
+ SystemInfo systemInfo(&o);
+ if (!QDBusConnection::sessionBus().registerObject("/", &o)) {
+ fprintf(stderr, "%s\n",
+ qPrintable(QDBusConnection::sessionBus().lastError().message()));
+ exit(1);
+ }
+ app.exec();
+
+ return 0;
+}
+
diff --git a/services/qt4/dbus-info-service/dbus-info-service.pro b/services/qt4/dbus-info-service/dbus-info-service.pro
new file mode 100644
index 0000000..4367370
--- /dev/null
+++ b/services/qt4/dbus-info-service/dbus-info-service.pro
@@ -0,0 +1,15 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Wed Jun 16 16:03:40 2010
+######################################################################
+
+TEMPLATE = app
+TARGET = dbus-info-service
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT -= gui
+CONFIG += qdbus
+
+# Input
+HEADERS += service.h
+SOURCES += dbus-info-service.cpp service.cpp
diff --git a/services/qt4/dbus-info-service/service.cpp b/services/qt4/dbus-info-service/service.cpp
new file mode 100644
index 0000000..150df16
--- /dev/null
+++ b/services/qt4/dbus-info-service/service.cpp
@@ -0,0 +1,98 @@
+
+#include <QtCore/QDateTime>
+#include <QtCore/QTextStream>
+#include <QtCore/QStringList>
+#include <QtDBus/QDBusMetaType>
+
+#include "service.h"
+
+SystemInfo::SystemInfo(QObject *parent)
+ : QDBusAbstractAdaptor(parent),
+ m_syslog(200),
+ m_dbusMonitor(50),
+ m_syslogFile("/var/log/syslog")
+{
+ if (m_syslogFile.open(QIODevice::ReadOnly)) {
+ m_syslog.setDevice(&m_syslogFile);
+ }
+
+ m_dbusMonitorProcess.start("/usr/bin/dbus-monitor");
+ m_dbusMonitor.setDevice(&m_dbusMonitorProcess);
+
+ qDBusRegisterMetaType<QMap<QString, QVariant> >();
+ startTimer(1000);
+}
+
+uint SystemInfo::Date()
+{
+ return QDateTime::currentDateTime().toTime_t();
+}
+
+void SystemInfo::Noop()
+{
+}
+
+QString SystemInfo::Ping(QString text)
+{
+ return text;
+}
+
+int SystemInfo::CpuLoad()
+{
+ return m_cpuLoad;
+}
+
+void SystemInfo::timerEvent(QTimerEvent *)
+{
+ int cpuCount = -1;
+ QFile file("/proc/stat");
+ if (!file.open(QIODevice::ReadOnly))
+ return;
+ QTextStream stream(&file);
+ do {
+ QString line = stream.readLine();
+ const QStringList list = line.trimmed().split(" ", QString::SkipEmptyParts);
+ if (list[0].left(3) == "cpu")
+ ++cpuCount;
+ if ((list.count() < 6) || list[0] != "cpu")
+ continue;
+
+ int value = 0;
+ for (int i = 0; i < list.length()-1; ++i) {
+ if (i == 3) // idle
+ continue;
+ value += list[i+1].toInt();
+ }
+ m_cpuLoad = value - m_oldStat;
+ m_oldStat = value;
+ } while(!stream.atEnd());
+ m_cpuLoad /= cpuCount;
+
+ m_syslog.update();
+ m_dbusMonitor.update();
+}
+
+Q_DECLARE_METATYPE(QStringList)
+
+QMap<QString, QVariant> SystemInfo::Syslog(int last)
+{
+ QMap<QString, QVariant> ret;
+
+ m_syslog.update();
+
+ ret["last"] = QVariant(m_syslog.last());
+ ret["data"] = QVariant(m_syslog.get(last));
+ return ret;
+}
+
+QMap<QString, QVariant> SystemInfo::DBusMonitor(int last)
+{
+ QMap<QString, QVariant> ret;
+
+ m_dbusMonitor.update();
+
+ ret["last"] = QVariant(m_dbusMonitor.last());
+ ret["data"] = QVariant(m_dbusMonitor.get(last));
+ return ret;
+}
+
diff --git a/services/qt4/dbus-info-service/service.h b/services/qt4/dbus-info-service/service.h
new file mode 100644
index 0000000..0cf3a8f
--- /dev/null
+++ b/services/qt4/dbus-info-service/service.h
@@ -0,0 +1,120 @@
+
+#ifndef _SERVICE_H_
+#define _SERVICE_H_
+
+#include <QtCore/QMap>
+#include <QtCore/QFile>
+#include <QtCore/QProcess>
+#include <QtCore/QDebug>
+
+#include <QtDBus/QDBusAbstractAdaptor>
+#include <QtDBus/QDBusConnection>
+
+class StreamWatcher {
+public:
+ StreamWatcher(int max = 100)
+ : m_dev(0),
+ m_last(0),
+ m_max(max)
+ {}
+ void setDevice(QIODevice *device)
+ {
+ m_dev = device;
+ }
+ virtual void update()
+ {
+ if (!m_dev)
+ return;
+ while (!m_dev->atEnd()) {
+ append(m_dev->readLine());
+ }
+ while (m_list.count() > m_max)
+ m_list.removeFirst();
+ }
+ int last()
+ {
+ return m_last;
+ }
+ QStringList get(int from)
+ {
+ int index = m_list.count() - (m_last - from);
+ if (index < 0)
+ index = 0;
+ return m_list.mid(index);
+ }
+protected:
+ virtual void append(const QString &line)
+ {
+ m_list.append(line);
+ ++m_last;
+ }
+protected:
+ QIODevice *m_dev;
+ QStringList m_list;
+ int m_last;
+ int m_max;
+};
+
+class DBusStreamWatcher : public StreamWatcher
+{
+public:
+ DBusStreamWatcher(int max = 100)
+ : StreamWatcher(max)
+ {}
+ virtual void update()
+ {
+ StreamWatcher::update();
+ filter();
+ }
+protected:
+ void filter()
+ {
+ if (!m_list.empty() && (
+ m_list.last().contains("interface=com.pengutronix.jdb.SystemInfo") ||
+ m_list.last().contains("sender=" + QDBusConnection::sessionBus().baseService()))) {
+ m_list.removeLast();
+ --m_last;
+ }
+ }
+ virtual void append(const QString &line)
+ {
+ if (!m_list.empty() && ((line[0] == ' ') || (line[0] == '"'))) {
+ m_list.last().append(line);
+ }
+ else {
+ filter();
+ m_list.append(line);
+ ++m_last;
+ }
+ }
+};
+
+class SystemInfo : public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.pengutronix.jdb.SystemInfo")
+public:
+ SystemInfo(QObject *parent);
+
+public slots:
+ uint Date();
+ void Noop();
+ QString Ping(QString text);
+ int CpuLoad();
+ QMap<QString, QVariant> Syslog(int last);
+ QMap<QString, QVariant> DBusMonitor(int last);
+
+protected:
+ virtual void timerEvent(QTimerEvent *);
+
+private:
+ int m_cpuLoad;
+ int m_oldStat;
+ StreamWatcher m_syslog;
+ DBusStreamWatcher m_dbusMonitor;
+ QFile m_syslogFile;
+ QProcess m_dbusMonitorProcess;
+};
+
+#endif // _SERVICE_H_
+