From 4da9bced6a27b92d49b9fc9392946510b8519d82 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 16 Oct 2011 04:42:30 +0200 Subject: Initial implementation of weather --- sowatchd/daemon.cpp | 105 +++------------------------------------------------- sowatchd/daemon.h | 8 +--- 2 files changed, 6 insertions(+), 107 deletions(-) (limited to 'sowatchd') diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp index 0cc6c05..3cbfb64 100644 --- a/sowatchd/daemon.cpp +++ b/sowatchd/daemon.cpp @@ -1,81 +1,16 @@ #include -#include -#include -#include #include #include "daemon.h" using namespace sowatch; Daemon::Daemon(QObject *parent) : - QObject(parent) + QObject(parent), + _registry(Registry::registry()) { - loadDrivers(); - loadProviders(); - loadWatchlets(); initWatches(); } -void Daemon::loadDrivers() -{ - QDir dir(SOWATCH_DRIVERS_DIR); - foreach (QString file, dir.entryList(QDir::Files)) { -#if defined(Q_OS_UNIX) - // Temporary workaround for QtC deploy plugin issues - if (!file.endsWith(".so")) continue; -#endif - QPluginLoader loader(dir.absoluteFilePath(file)); - QObject *pluginObj = loader.instance(); - if (pluginObj) { - WatchPluginInterface *plugin = qobject_cast(pluginObj); - if (plugin) { - QStringList drivers = plugin->drivers(); - foreach (const QString& driver, drivers) { - _drivers[driver] = plugin; - } - } else { - qWarning() << "Invalid plugin" << file; - loader.unload(); - } - } else { - qWarning() << "Invalid plugin" << file << loader.errorString(); - loader.unload(); - } - } - - qDebug() << "loaded drivers" << _drivers.keys(); -} - -void Daemon::loadProviders() -{ - QDir dir(SOWATCH_NOTIFICATIONS_DIR); - foreach (QString file, dir.entryList(QDir::Files)) { -#if defined(Q_OS_UNIX) - // Temporary workaround for QtC deploy plugin issues - if (!file.endsWith(".so")) continue; -#endif - QPluginLoader loader(dir.absoluteFilePath(file)); - QObject *pluginObj = loader.instance(); - if (pluginObj) { - NotificationPluginInterface *plugin = qobject_cast(pluginObj); - if (plugin) { - QStringList providers = plugin->providers(); - foreach (const QString& provider, providers) { - _providers[provider] = plugin; - } - } else { - qWarning() << "Invalid plugin" << file; - loader.unload(); - } - } else { - qWarning() << "Invalid plugin" << file << loader.errorString(); - loader.unload(); - } - } - - qDebug() << "loaded providers" << _providers.keys(); -} - void Daemon::initWatches() { QSettings settings; @@ -84,7 +19,7 @@ void Daemon::initWatches() for (int i = 0; i < size; i++) { settings.setArrayIndex(i); QString driver = settings.value("driver").toString().toLower(); - WatchPluginInterface *plugin = _drivers[driver]; + WatchPluginInterface *plugin = _registry->getWatchPlugin(driver); if (plugin) { Watch *watch = plugin->getWatch(driver, settings, this); if (watch) { @@ -117,7 +52,7 @@ void Daemon::initWatch(Watch* watch, QSettings& settings) for (int i = 0; i < size; i++) { settings.setArrayIndex(i); QString id = settings.value("provider").toString().toLower(); - NotificationPluginInterface *plugin = _providers[id]; + NotificationPluginInterface *plugin = _registry->getNotificationPlugin(id); if (plugin) { NotificationProvider *provider = plugin->getProvider(id, settings, server); server->addProvider(provider); @@ -132,7 +67,7 @@ void Daemon::initWatch(Watch* watch, QSettings& settings) for (int i = 0; i < size; i++) { settings.setArrayIndex(i); QString id = settings.value("id").toString().toLower(); - WatchletPluginInterface *plugin = _watchlets[id]; + WatchletPluginInterface *plugin = _registry->getWatchletPlugin(id); if (plugin) { plugin->getWatchlet(id, settings, server); // Watchlets are associated to server via parent-child relationship. @@ -142,33 +77,3 @@ void Daemon::initWatch(Watch* watch, QSettings& settings) } settings.endArray(); } - -void Daemon::loadWatchlets() -{ - QDir dir(SOWATCH_WATCHLETS_DIR); - foreach (QString file, dir.entryList(QDir::Files)) { -#if defined(Q_OS_UNIX) - // Temporary workaround for QtC deploy plugin issues - if (!file.endsWith(".so")) continue; -#endif - QPluginLoader loader(dir.absoluteFilePath(file)); - QObject *pluginObj = loader.instance(); - if (pluginObj) { - WatchletPluginInterface *plugin = qobject_cast(pluginObj); - if (plugin) { - QStringList watchlets = plugin->watchlets(); - foreach (const QString& watchlet, watchlets) { - _watchlets[watchlet] = plugin; - } - } else { - qWarning() << "Invalid plugin" << file; - loader.unload(); - } - } else { - qWarning() << "Invalid plugin" << file << loader.errorString(); - loader.unload(); - } - } - - qDebug() << "loaded watchlets" << _watchlets.keys(); -} diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h index 8885d6f..48125fb 100644 --- a/sowatchd/daemon.h +++ b/sowatchd/daemon.h @@ -18,15 +18,9 @@ public: explicit Daemon(QObject *parent = 0); protected: - QMap _drivers; - QMap _providers; - QMap _watchlets; + Registry* _registry; QList _servers; - void loadDrivers(); - void loadProviders(); - void loadWatchlets(); - void initWatches(); void initWatch(Watch* watch, QSettings& settings); }; -- cgit v1.2.3