diff options
-rw-r--r-- | debian/changelog | 3 | ||||
-rw-r--r-- | libindicator/gen-indicator-service.xml.c | 1 | ||||
-rw-r--r-- | libindicator/indicator-service.c | 39 | ||||
-rw-r--r-- | libindicator/indicator-service.xml | 1 |
4 files changed, 41 insertions, 3 deletions
diff --git a/debian/changelog b/debian/changelog index a3b7905..bec326f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,8 +6,9 @@ libindicator (0.3.90-0ubuntu2~ppa1) UNRELEASED; urgency=low * Adding annotations for GIR files * Fixing watchers hashtable to detect when we have none * Fix testing so no tests are XFAIL anymore + * Adding a replace mode for testing indicator services - -- Ted Gould <ted@ubuntu.com> Tue, 12 Jul 2011 10:54:31 -0500 + -- Ted Gould <ted@ubuntu.com> Tue, 12 Jul 2011 10:55:26 -0500 libindicator (0.3.90-0ubuntu1) oneiric; urgency=low diff --git a/libindicator/gen-indicator-service.xml.c b/libindicator/gen-indicator-service.xml.c index 2a2b590..5c873df 100644 --- a/libindicator/gen-indicator-service.xml.c +++ b/libindicator/gen-indicator-service.xml.c @@ -14,6 +14,7 @@ const char * _indicator_service = " <method name=\"UnWatch\">\n" " <annotation name=\"org.freedesktop.DBus.GLib.Async\" value=\"true\" />\n" " </method>\n" +" <method name=\"Shutdown\" />\n" "\n" "<!-- Signals -->\n" " <!-- None currently -->\n" diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 1b4bc8c..e9f3133 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -57,6 +57,7 @@ struct _IndicatorServicePrivate { GHashTable * watchers; guint this_service_version; guint dbus_registration; + gboolean replace_mode; }; /* Signals Stuff */ @@ -192,6 +193,7 @@ indicator_service_init (IndicatorService *self) priv->this_service_version = 0; priv->timeout_length = 500; priv->dbus_registration = 0; + priv->replace_mode = FALSE; const gchar * timeoutenv = g_getenv("INDICATOR_SERVICE_SHUTDOWN_TIMEOUT"); if (timeoutenv != NULL) { @@ -202,6 +204,12 @@ indicator_service_init (IndicatorService *self) } } + const gchar * replaceenv = g_getenv("INDICATOR_SERVICE_REPLACE_MODE"); + if (replaceenv != NULL) { + priv->replace_mode = TRUE; + g_debug("Putting into replace mode"); + } + /* NOTE: We're using g_free here because that's what needs to happen and we're watchers_remove as well to clean up the dbus watches we've setup. */ @@ -397,6 +405,8 @@ bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar retval = bus_watch(service, sender); } else if (g_strcmp0(method, "UnWatch") == 0) { unwatch_core(service, sender); + } else if (g_strcmp0(method, "Shutdown") == 0) { + g_signal_emit(G_OBJECT(service), signals[SHUTDOWN], 0, TRUE); } else { g_warning("Calling method '%s' on the indicator service and it's unknown", method); } @@ -462,8 +472,33 @@ try_and_get_name_lost_cb (GDBusConnection * connection, const gchar * name, gpoi g_return_if_fail(connection != NULL); g_return_if_fail(INDICATOR_IS_SERVICE(user_data)); - g_warning("Name request failed."); - g_signal_emit(G_OBJECT(user_data), signals[SHUTDOWN], 0, TRUE); + IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(user_data); + + if (!priv->replace_mode) { + g_warning("Name request failed."); + g_signal_emit(G_OBJECT(user_data), signals[SHUTDOWN], 0, TRUE); + } else { + /* If we're in replace mode we can be a little more trickey + here. We're going to tell the other guy to shutdown and hope + that we get the name. */ + GDBusMessage * message = NULL; + message = g_dbus_message_new_method_call(name, + INDICATOR_SERVICE_OBJECT, + INDICATOR_SERVICE_INTERFACE, + "Shutdown"); + + g_dbus_connection_send_message(connection, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref(message); + + /* Check to see if we need to clean up a timeout */ + if (priv->timeout != 0) { + g_source_remove(priv->timeout); + priv->timeout = 0; + } + + /* Set a timeout for no watchers if we can't get the name */ + priv->timeout = g_timeout_add(priv->timeout_length * 4, timeout_no_watchers, user_data); + } return; } diff --git a/libindicator/indicator-service.xml b/libindicator/indicator-service.xml index 6bd7d80..71ef4df 100644 --- a/libindicator/indicator-service.xml +++ b/libindicator/indicator-service.xml @@ -13,6 +13,7 @@ <method name="UnWatch"> <annotation name="org.freedesktop.DBus.GLib.Async" value="true" /> </method> + <method name="Shutdown" /> <!-- Signals --> <!-- None currently --> |