[Spice-devel] [PATCH spice-gtk] desktop-integration: Create D-Bus proxy only when bus name exists
Pavel Grunt
pgrunt at redhat.com
Wed Jan 28 02:12:59 PST 2015
It avoids calling D-Bus methods when the bus name
"org.gnome.SessionManager" does not exist.
GSpice-WARNING **: Error calling 'org.gnome.SessionManager.Inhibit': GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
---
The warning appears in other than Gnome desktop environment
---
gtk/desktop-integration.c | 63 +++++++++++++++++++++++++++++++++--------------
1 file changed, 45 insertions(+), 18 deletions(-)
diff --git a/gtk/desktop-integration.c b/gtk/desktop-integration.c
index c366fd0..bf6a9e3 100644
--- a/gtk/desktop-integration.c
+++ b/gtk/desktop-integration.c
@@ -44,6 +44,7 @@ struct _SpiceDesktopIntegrationPrivate {
GObject *gnome_session_proxy; /* dummy */
#endif
guint gnome_automount_inhibit_cookie;
+ guint gdbus_watcher_id;
};
G_DEFINE_TYPE(SpiceDesktopIntegration, spice_desktop_integration, G_TYPE_OBJECT);
@@ -60,33 +61,57 @@ static void handle_dbus_call_error(const char *call, GError **_error)
g_clear_error(_error);
}
-static gboolean gnome_integration_init(SpiceDesktopIntegration *self)
+#if defined(USE_GDBUS)
+static void name_appeared_cb(GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner G_GNUC_UNUSED,
+ gpointer data)
{
- G_GNUC_UNUSED SpiceDesktopIntegrationPrivate *priv = self->priv;
+ SpiceDesktopIntegration *self = SPICE_DESKTOP_INTEGRATION(data);
+ SpiceDesktopIntegrationPrivate *priv = self->priv;
GError *error = NULL;
- gboolean success = TRUE;
-
-#if defined(USE_GDBUS)
- priv->gnome_session_proxy =
- g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.gnome.SessionManager",
- "/org/gnome/SessionManager",
- "org.gnome.SessionManager",
- NULL,
- &error);
-#else
- success = FALSE;
-#endif
+ priv->gnome_session_proxy = g_dbus_proxy_new_sync(connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ name,
+ "/org/gnome/SessionManager",
+ "org.gnome.SessionManager",
+ NULL,
+ &error);
if (error) {
g_warning("Could not create org.gnome.SessionManager dbus proxy: %s",
error->message);
g_clear_error(&error);
- return FALSE;
}
+}
+
+static void name_vanished_cb(GDBusConnection *connection G_GNUC_UNUSED,
+ const gchar *name G_GNUC_UNUSED,
+ gpointer data)
+{
+ SpiceDesktopIntegration *self = SPICE_DESKTOP_INTEGRATION(data);
+ SpiceDesktopIntegrationPrivate *priv = self->priv;
+
+ g_clear_object(&priv->gnome_session_proxy);
+}
+#endif
+static gboolean gnome_integration_init(SpiceDesktopIntegration *self)
+{
+ G_GNUC_UNUSED SpiceDesktopIntegrationPrivate *priv = self->priv;
+ gboolean success = FALSE;
+
+#if defined(USE_GDBUS)
+ priv->gdbus_watcher_id = g_bus_watch_name(G_BUS_TYPE_SESSION,
+ "org.gnome.SessionManager",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ name_appeared_cb,
+ name_vanished_cb,
+ self,
+ NULL);
+ success = TRUE;
+#endif
return success;
}
@@ -150,6 +175,8 @@ static void gnome_integration_dispose(SpiceDesktopIntegration *self)
{
SpiceDesktopIntegrationPrivate *priv = self->priv;
+ if (priv->gdbus_watcher_id)
+ g_bus_unwatch_name(priv->gdbus_watcher_id);
g_clear_object(&priv->gnome_session_proxy);
}
--
1.9.3
More information about the Spice-devel
mailing list