summaryrefslogtreecommitdiff
path: root/sowatchd
diff options
context:
space:
mode:
Diffstat (limited to 'sowatchd')
-rw-r--r--sowatchd/daemon.cpp83
-rw-r--r--sowatchd/daemon.h30
-rw-r--r--sowatchd/main.cpp20
-rw-r--r--sowatchd/sowatchd.pro38
4 files changed, 171 insertions, 0 deletions
diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp
new file mode 100644
index 0000000..a2d7b5a
--- /dev/null
+++ b/sowatchd/daemon.cpp
@@ -0,0 +1,83 @@
+#include <QtCore/QDebug>
+#include <QtCore/QPluginLoader>
+#include <QtCore/QSettings>
+#include <QtCore/QDir>
+#include <sowatch.h>
+#include "daemon.h"
+
+using namespace sowatch;
+
+Daemon::Daemon(QObject *parent) :
+ QObject(parent)
+{
+ loadDrivers();
+ loadWatches();
+ loadWatchlets();
+}
+
+void Daemon::loadDrivers()
+{
+ QDir dir(SOWATCH_DRIVERS_DIR);
+ foreach (QString file, dir.entryList(QDir::Files)) {
+ QPluginLoader loader(dir.absoluteFilePath(file));
+ QObject *pluginObj = loader.instance();
+ if (pluginObj) {
+ WatchPluginInterface *plugin = qobject_cast<WatchPluginInterface*>(pluginObj);
+ if (plugin) {
+ QStringList drivers = plugin->drivers();
+ foreach (const QString& driver, drivers) {
+ _drivers[driver] = plugin;
+ }
+ }
+ } else {
+ qWarning() << "Invalid plugin" << file;
+ }
+ }
+
+ qDebug() << "loaded drivers" << _drivers.keys();
+}
+
+void Daemon::loadWatches()
+{
+ QSettings settings;
+ int size = settings.beginReadArray("watches");
+
+ for (int i = 0; i < size; i++) {
+ settings.setArrayIndex(i);
+ QString driver = settings.value("driver").toString().toLower();
+ WatchPluginInterface *plugin = _drivers[driver];
+ if (plugin) {
+ Watch *watch = plugin->getWatch(driver, settings, this);
+ if (watch) {
+ _watches.append(watch);
+ } else {
+ qWarning() << "Driver" << driver << "refused to getWatch";
+ }
+ } else {
+ qWarning() << "Invalid driver" << driver;
+ }
+ }
+
+ settings.endArray();
+ qDebug() << "handling" << _watches.size() << "watches";
+}
+
+void Daemon::loadWatchlets()
+{
+#if 0
+ QDir dir(SOWATCH_WATCHLETS_DIR);
+ foreach (QString file, dir.entryList(QDir::Files)) {
+ QPluginLoader loader(dir.absoluteFilePath(file));
+ QObject *pluginObj = loader.instance();
+ if (pluginObj) {
+ WatchPluginInterface *plugin = qobject_cast<WatchPluginInterface*>(pluginObj);
+ if (plugin) {
+ QStringList drivers = plugin->drivers();
+ foreach (const QString& driver, drivers) {
+ _drivers[driver] = plugin;
+ }
+ }
+ }
+ }
+#endif
+}
diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h
new file mode 100644
index 0000000..9346a41
--- /dev/null
+++ b/sowatchd/daemon.h
@@ -0,0 +1,30 @@
+#ifndef WATCHDAEMON_H
+#define WATCHDAEMON_H
+
+#include <QtCore/QObject>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+
+#include <sowatch.h>
+
+namespace sowatch
+{
+
+class Daemon : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Daemon(QObject *parent = 0);
+
+protected:
+ QMap<QString, WatchPluginInterface*> _drivers;
+ QList<Watch*> _watches;
+
+ void loadDrivers();
+ void loadWatches();
+ void loadWatchlets();
+};
+
+}
+
+#endif // WATCHDAEMON_H
diff --git a/sowatchd/main.cpp b/sowatchd/main.cpp
new file mode 100644
index 0000000..0d7abb9
--- /dev/null
+++ b/sowatchd/main.cpp
@@ -0,0 +1,20 @@
+#include <QtGui/QApplication>
+
+#include <sowatch.h>
+#include "daemon.h"
+
+using namespace sowatch;
+
+static Daemon* d;
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QApplication::setOrganizationDomain("com.javispedro.sowatch");
+ QApplication::setOrganizationName("sowatch");
+ QApplication::setApplicationName("sowatchd");
+
+ d = new Daemon();
+
+ return a.exec();
+}
diff --git a/sowatchd/sowatchd.pro b/sowatchd/sowatchd.pro
new file mode 100644
index 0000000..1c09046
--- /dev/null
+++ b/sowatchd/sowatchd.pro
@@ -0,0 +1,38 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2011-09-17T04:55:26
+#
+#-------------------------------------------------
+
+TEMPLATE = app
+
+TARGET = sowatchd
+
+QT += core gui
+CONFIG += console
+CONFIG -= app_bundle
+
+SOURCES += main.cpp \
+ daemon.cpp
+
+win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/release/ -llibsowatch
+else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/debug/ -llibsowatch
+else:symbian: LIBS += -llibsowatch
+else:unix: LIBS += -L$$OUT_PWD/../libsowatch/ -llibsowatch
+
+INCLUDEPATH += $$PWD/../libsowatch
+DEPENDPATH += $$PWD/../libsowatch
+
+unix {
+ maemo5 {
+ target.path = /opt/sowatch
+ } else {
+ target.path = /usr/bin
+ }
+ INSTALLS += target
+}
+
+HEADERS += \
+ daemon.h
+
+