summaryrefslogtreecommitdiff
path: root/sowatchd
diff options
context:
space:
mode:
Diffstat (limited to 'sowatchd')
-rw-r--r--sowatchd/daemon.cpp1
-rw-r--r--sowatchd/daemon.h1
-rw-r--r--sowatchd/sowatchd.conf5
-rw-r--r--sowatchd/watchhandler.cpp63
-rw-r--r--sowatchd/watchhandler.h3
5 files changed, 66 insertions, 7 deletions
diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp
index bcf3686..b8d5d0e 100644
--- a/sowatchd/daemon.cpp
+++ b/sowatchd/daemon.cpp
@@ -6,7 +6,6 @@ using namespace sowatch;
Daemon::Daemon(QObject *parent) :
QObject(parent),
- _registry(Registry::registry()),
_config(new GConfKey("/apps/sowatch", this)),
_watches_list(_config->getSubkey("watches", this)),
_status_mapper(new QSignalMapper(this))
diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h
index e3f748b..45a2d60 100644
--- a/sowatchd/daemon.h
+++ b/sowatchd/daemon.h
@@ -27,7 +27,6 @@ signals:
void WatchStatusChanged(const QString &watch, const QString &status);
private:
- Registry* _registry;
ConfigKey* _config;
ConfigKey* _watches_list;
QMap<QString, WatchHandler*> _watches;
diff --git a/sowatchd/sowatchd.conf b/sowatchd/sowatchd.conf
index 2cebb82..77bdca4 100644
--- a/sowatchd/sowatchd.conf
+++ b/sowatchd/sowatchd.conf
@@ -4,10 +4,9 @@ author "maemo@javispedro.com"
stop on stopping xsession
console none
-
respawn
respawn limit 3 10
-
-nice 2
+normal exit 0 TERM
+nice 1
exec /usr/bin/aegis-exec -s -u user -l "exec /opt/sowatch/bin/sowatchd"
diff --git a/sowatchd/watchhandler.cpp b/sowatchd/watchhandler.cpp
index 314156a..4bebb9c 100644
--- a/sowatchd/watchhandler.cpp
+++ b/sowatchd/watchhandler.cpp
@@ -13,12 +13,26 @@ WatchHandler::WatchHandler(ConfigKey *config, QObject *parent)
connect(_config, SIGNAL(subkeyChanged(QString)),
SLOT(handleConfigSubkeyChanged(QString)));
+ // Connect to the registry in case plugins are unloaded
+ connect(registry, SIGNAL(driverUnloaded(QString)),
+ SLOT(handleDriverUnloaded(QString)));
+ connect(registry, SIGNAL(watchletLoaded(QString)),
+ SLOT(updateWatchlets()));
+ connect(registry, SIGNAL(watchletUnloaded(QString)),
+ SLOT(handleWatchletUnloaded(QString)));
+ connect(registry, SIGNAL(notificationProviderLoaded(QString)),
+ SLOT(updateProviders()));
+ connect(registry, SIGNAL(notificationProviderUnloaded(QString)),
+ SLOT(handleProviderUnloaded(QString)));
+
+ // Get the watch driver
const QString driver = _config->value("driver").toString();
if (driver.isEmpty()) {
qWarning() << "Watch" << _config->value("name") << "has no driver setting";
return;
}
+
WatchPluginInterface *watchPlugin = registry->getWatchPlugin(driver);
if (!watchPlugin) {
qWarning() << "Invalid driver" << driver;
@@ -50,7 +64,7 @@ WatchHandler::WatchHandler(ConfigKey *config, QObject *parent)
QString WatchHandler::status() const
{
- if (_watch->isConnected()) {
+ if (_watch && _watch->isConnected()) {
return "connected";
} else if (_config->value("enable").toBool()) {
return "enabled";
@@ -62,6 +76,9 @@ QString WatchHandler::status() const
void WatchHandler::updateWatchlets()
{
Registry *registry = Registry::registry();
+
+ if (!_server) return;
+
QStringList newWatchlets = _config->value("watchlets").toStringList();
QStringList curWatchlets = _watchlet_order;
@@ -97,6 +114,9 @@ void WatchHandler::updateWatchlets()
void WatchHandler::updateProviders()
{
Registry *registry = Registry::registry();
+
+ if (!_server) return;
+
QSet<QString> curProviders = _providers.keys().toSet();
QSet<QString> newProviders = _config->value("providers").toStringList().toSet();
QSet<QString> removed = curProviders - newProviders;
@@ -128,7 +148,46 @@ void WatchHandler::handleConfigSubkeyChanged(const QString &subkey)
updateWatchlets();
} else if (subkey == "providers") {
updateProviders();
- } else if (subkey == "next-watchlet-button") {
+ } else if (subkey == "next-watchlet-button" && _server) {
_server->setNextWatchletButton(_config->value("next-watchlet-button").toString());
}
}
+
+void WatchHandler::handleDriverUnloaded(const QString &id)
+{
+ if (id == _config->value("driver").toString()) {
+ // Emergency disconnection!
+ qWarning("Unloading driver of active watch!");
+ if (_server) {
+ delete _server;
+ _server = 0;
+ }
+ if (_watch) {
+ delete _watch;
+ _watch = 0;
+ }
+ emit statusChanged();
+ }
+}
+
+void WatchHandler::handleWatchletUnloaded(const QString &id)
+{
+ if (_watchlets.contains(id)) {
+ qDebug() << "Unloading watchlet" << id << "from watch";
+ Watchlet* watchlet = _watchlets[id];
+ _server->removeWatchlet(watchlet);
+ _watchlets.remove(id);
+ delete watchlet;
+ }
+}
+
+void WatchHandler::handleProviderUnloaded(const QString &id)
+{
+ if (_providers.contains(id)) {
+ qDebug() << "Unloading provider" << id << "from watch";
+ NotificationProvider *provider = _providers[id];
+ _server->removeProvider(provider);
+ _providers.remove(id);
+ delete provider;
+ }
+}
diff --git a/sowatchd/watchhandler.h b/sowatchd/watchhandler.h
index 3fa7c6b..39c1d17 100644
--- a/sowatchd/watchhandler.h
+++ b/sowatchd/watchhandler.h
@@ -26,6 +26,9 @@ private slots:
void updateWatchlets();
void updateProviders();
void handleConfigSubkeyChanged(const QString& key);
+ void handleDriverUnloaded(const QString& id);
+ void handleWatchletUnloaded(const QString& id);
+ void handleProviderUnloaded(const QString& id);
private:
ConfigKey *_config;