summaryrefslogtreecommitdiff
path: root/sowatchd/daemon.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-18 04:26:20 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-09-18 04:26:20 +0200
commitc42d5abff1f5f51facc169dd593725d819c4c868 (patch)
tree9aa8bdef88bf89561c7726948541a1ba3906b81e /sowatchd/daemon.cpp
parentf225345d4de3b198a557fe3566f9630163e76d51 (diff)
downloadsowatch-c42d5abff1f5f51facc169dd593725d819c4c868.tar.gz
sowatch-c42d5abff1f5f51facc169dd593725d819c4c868.zip
separation into lib and plugins complete
Diffstat (limited to 'sowatchd/daemon.cpp')
-rw-r--r--sowatchd/daemon.cpp83
1 files changed, 83 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
+}