summaryrefslogtreecommitdiff
path: root/sowatchd
diff options
context:
space:
mode:
Diffstat (limited to 'sowatchd')
-rw-r--r--sowatchd/daemon.cpp105
-rw-r--r--sowatchd/daemon.h8
2 files changed, 6 insertions, 107 deletions
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 <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)
+ 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<WatchPluginInterface*>(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<NotificationPluginInterface*>(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<WatchletPluginInterface*>(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<QString, WatchPluginInterface*> _drivers;
- QMap<QString, NotificationPluginInterface*> _providers;
- QMap<QString, WatchletPluginInterface*> _watchlets;
+ Registry* _registry;
QList<WatchServer*> _servers;
- void loadDrivers();
- void loadProviders();
- void loadWatchlets();
-
void initWatches();
void initWatch(Watch* watch, QSettings& settings);
};