+
+ deregister_application (spi_global_app_data);
+
+ if (spi_global_app_data->bus)
+ {
+ dbus_connection_remove_filter (spi_global_app_data->bus, signal_filter, NULL);
+ droute_context_unregister (spi_global_app_data->droute, spi_global_app_data->bus);
+ dbus_connection_unref (spi_global_app_data->bus);
+ }
+
+ for (l = spi_global_app_data->direct_connections; l; l = l->next)
+ {
+ droute_context_unregister (spi_global_app_data->droute, l->data);
+ droute_unintercept_dbus (l->data);
+ dbus_connection_unref (l);
+ }
+ g_list_free (spi_global_app_data->direct_connections);
+
+ for (l = clients; l; l = l->next)
+ g_free (l->data);
+ g_list_free (clients);
+ clients = NULL;
+
+ g_object_unref (spi_global_cache);
+ g_object_unref (spi_global_leasing);
+ g_object_unref (spi_global_register);
+
+ if (spi_global_app_data->main_context)
+ g_main_context_unref (spi_global_app_data->main_context);
+
+ droute_free (spi_global_app_data->droute);
+
+ g_free (spi_global_app_data);
+ spi_global_app_data = NULL;
+
+ /* Not currently creating an XDisplay */
+#if 0
+ if (bridge_display)
+ XCloseDisplay (bridge_display);
+#endif
+}
+
+static gchar *name_match_tmpl =
+ "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged', arg0='%s'";
+
+void
+spi_atk_add_client (const char *bus_name)
+{
+ GSList *l;
+ gchar *match;
+
+ for (l = clients; l; l = l->next)
+ {
+ if (!g_strcmp0 (l->data, bus_name))
+ return;
+ }
+ if (!clients && spi_global_app_data->events_initialized)
+ spi_atk_register_event_listeners ();
+ clients = g_slist_append (clients, g_strdup (bus_name));
+ match = g_strdup_printf (name_match_tmpl, bus_name);
+ dbus_bus_add_match (spi_global_app_data->bus, match, NULL);
+ g_free (match);
+}
+
+void
+spi_atk_remove_client (const char *bus_name)
+{
+ GSList *l;
+
+ for (l = clients; l; l = l->next)
+ {
+ if (!g_strcmp0 (l->data, bus_name))
+ {
+ gchar *match = g_strdup_printf (name_match_tmpl, l->data);
+ dbus_bus_remove_match (spi_global_app_data->bus, match, NULL);
+ g_free (match);
+ g_free (l->data);
+ clients = g_slist_remove_link (clients, l);
+ if (!clients)
+ spi_atk_deregister_event_listeners ();
+ }
+ }