From cf5d24b94d96b722c6d76c2225293a56a50d3c2b Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 25 Sep 2011 04:53:46 +0200 Subject: watchlets working! --- sowatchd/daemon.cpp | 31 +++++++++++++++++++++---------- sowatchd/daemon.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'sowatchd') diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp index 26cbad0..0cc6c05 100644 --- a/sowatchd/daemon.cpp +++ b/sowatchd/daemon.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "daemon.h" using namespace sowatch; @@ -13,6 +12,7 @@ Daemon::Daemon(QObject *parent) : { loadDrivers(); loadProviders(); + loadWatchlets(); initWatches(); } @@ -121,12 +121,25 @@ void Daemon::initWatch(Watch* watch, QSettings& settings) if (plugin) { NotificationProvider *provider = plugin->getProvider(id, settings, server); server->addProvider(provider); + } else { + qWarning() << "Unknown notification provider" << id; } } + settings.endArray(); - // Initialize test watchlets - new TestWatchlet(server); - + // Initialize watchlets + size = settings.beginReadArray("watchlets"); + for (int i = 0; i < size; i++) { + settings.setArrayIndex(i); + QString id = settings.value("id").toString().toLower(); + WatchletPluginInterface *plugin = _watchlets[id]; + if (plugin) { + plugin->getWatchlet(id, settings, server); + // Watchlets are associated to server via parent-child relationship. + } else { + qWarning() << "Unknown watchlet" << id; + } + } settings.endArray(); } @@ -141,23 +154,21 @@ void Daemon::loadWatchlets() QPluginLoader loader(dir.absoluteFilePath(file)); QObject *pluginObj = loader.instance(); if (pluginObj) { -#if 0 WatchletPluginInterface *plugin = qobject_cast(pluginObj); if (plugin) { - QStringList providers = plugin->providers(); - foreach (const QString& provider, providers) { - _providers[provider] = plugin; + QStringList watchlets = plugin->watchlets(); + foreach (const QString& watchlet, watchlets) { + _watchlets[watchlet] = plugin; } } else { qWarning() << "Invalid plugin" << file; loader.unload(); } -#endif } else { qWarning() << "Invalid plugin" << file << loader.errorString(); loader.unload(); } } - qDebug() << "loaded watchlets"; + qDebug() << "loaded watchlets" << _watchlets.keys(); } diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h index 607e887..8885d6f 100644 --- a/sowatchd/daemon.h +++ b/sowatchd/daemon.h @@ -20,6 +20,7 @@ public: protected: QMap _drivers; QMap _providers; + QMap _watchlets; QList _servers; void loadDrivers(); -- cgit v1.2.3