aboutsummaryrefslogtreecommitdiff
path: root/libindicator/indicator-service.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2009-12-02 08:37:01 -0600
committerTed Gould <ted@gould.cx>2009-12-02 08:37:01 -0600
commitc986e2ca5d546d434431902c2951ca2d1bc6478c (patch)
tree043621081240413fa9973bab07164dd9d1b02409 /libindicator/indicator-service.c
parent0d1af254e912f1982fb4be75acc3cb214b4338ed (diff)
parentde38fc85d228bb2de6de86f31805ad0de748318e (diff)
downloadlibayatana-indicator-c986e2ca5d546d434431902c2951ca2d1bc6478c.tar.gz
libayatana-indicator-c986e2ca5d546d434431902c2951ca2d1bc6478c.tar.bz2
libayatana-indicator-c986e2ca5d546d434431902c2951ca2d1bc6478c.zip
Adding an 'UnWatch' command to the standard DBus interface
for graceful disconnection from a service.
Diffstat (limited to 'libindicator/indicator-service.c')
-rw-r--r--libindicator/indicator-service.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c
index 69422c5..5fb939d 100644
--- a/libindicator/indicator-service.c
+++ b/libindicator/indicator-service.c
@@ -8,6 +8,7 @@
/* DBus Prototypes */
static gboolean _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocation * method);
+static gboolean _indicator_service_server_un_watch (IndicatorService * service, DBusGMethodInvocation * method);
#include "indicator-service-server.h"
#include "dbus-shared.h"
@@ -305,7 +306,48 @@ _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocati
priv->timeout = 0;
}
- dbus_g_method_return(method, 1);
+ dbus_g_method_return(method, INDICATOR_SERVICE_VERSION);
+ return TRUE;
+}
+
+static gint
+find_watcher (gconstpointer a, gconstpointer b)
+{
+ return g_strcmp0((const gchar *)a, (const gchar *)b);
+}
+
+static gboolean
+_indicator_service_server_un_watch (IndicatorService * service, DBusGMethodInvocation * method)
+{
+ g_return_val_if_fail(INDICATOR_IS_SERVICE(service), FALSE);
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service);
+
+ /* Remove us from the watcher list here */
+ GList * watcher_item = g_list_find_custom(priv->watchers, dbus_g_method_get_sender(method), find_watcher);
+ if (watcher_item != NULL) {
+ /* Free the watcher */
+ gchar * name = watcher_item->data;
+ priv->watchers = g_list_remove(priv->watchers, name);
+ g_free(name);
+ } else {
+ /* Odd that we couldn't find the person, but, eh */
+ g_warning("Unable to find watcher who is unwatching: %s", dbus_g_method_get_sender(method));
+ }
+
+ /* If we're out of watchers set the timeout for shutdown */
+ if (priv->watchers == NULL) {
+ if (priv->timeout != 0) {
+ /* This should never really happen, but let's ensure that
+ bad things don't happen if it does. */
+ g_warning("No watchers timeout set twice. Resolving, but odd.");
+ g_source_remove(priv->timeout);
+ priv->timeout = 0;
+ }
+ /* If we don't get a new watcher quickly, we'll shutdown. */
+ priv->timeout = g_timeout_add(500, timeout_no_watchers, service);
+ }
+
+ dbus_g_method_return(method);
return TRUE;
}