← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/libindicate/dbus-name-owner into lp:libindicate

 

Ted Gould has proposed merging lp:~ted/libindicate/dbus-name-owner into lp:libindicate.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)

For more details, see:
https://code.launchpad.net/~ted/libindicate/dbus-name-owner/+merge/48260


-- 
https://code.launchpad.net/~ted/libindicate/dbus-name-owner/+merge/48260
Your team ayatana-commits is subscribed to branch lp:libindicate.
=== modified file 'libindicate/listener.c'
--- libindicate/listener.c	2011-01-13 22:43:05 +0000
+++ libindicate/listener.c	2011-02-02 02:07:02 +0000
@@ -68,6 +68,7 @@
 	GHashTable * indicators;
 	guint introspect_level;
 	gboolean hidden;
+	guint dbus_listener_sub;
 
 	IndicateListenerServer server;
 } proxy_t;
@@ -297,6 +298,26 @@
 	return;
 }
 
+/* Respond to a name change related to the proxy, usually mean that
+   it's falling off of the bus. */
+static void
+proxy_name_owner_changed (GDBusConnection * connection, const gchar * sender_name, const gchar * object_path, const gchar * interface_name, const gchar * signal_name, GVariant * parameters, gpointer user_data)
+{
+	const gchar * new_name;
+	g_variant_get(parameters, "(&s&s&s)", NULL, NULL, &new_name);
+
+	if (new_name == NULL || new_name[0] == 0) {
+		proxy_t * proxyt = (proxy_t *)user_data;
+
+		g_object_unref(proxyt->proxy);
+		proxyt->proxy = NULL;
+
+		proxy_destroyed(NULL, user_data);
+	}
+
+	return;
+}
+
 /* Response to connecting to the session bus */
 static void
 bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data)
@@ -457,6 +478,11 @@
 		proxy_data->indicators = NULL;
 	}
 
+	if (proxy_data->dbus_listener_sub != 0) {
+		g_dbus_connection_signal_unsubscribe(proxy_data->connection, proxy_data->dbus_listener_sub);
+		proxy_data->dbus_listener_sub = 0;
+	}
+
 	if (proxy_data->proxy != NULL) {
 		g_object_unref(G_OBJECT(proxy_data->proxy));
 	}
@@ -610,6 +636,17 @@
 	g_signal_connect(G_OBJECT(proxyt->proxy), "notify::g-name-owner", G_CALLBACK(proxy_destroyed), proxyt);
 	g_signal_connect(G_OBJECT(proxyt->proxy), "g-signal", G_CALLBACK(proxy_signal_cb), proxyt);
 
+	proxyt->dbus_listener_sub = g_dbus_connection_signal_subscribe(g_dbus_proxy_get_connection(proxy),
+	                                                               "org.freedesktop.DBus", /* sender */
+	                                                               "org.freedesktop.DBus",
+	                                                               "NameOwnerChanged",
+	                                                               "/org/freedesktop/DBus", /* path */
+	                                                               g_dbus_proxy_get_name(proxy), /* arg0 */
+	                                                               G_DBUS_SIGNAL_FLAGS_NONE,
+	                                                               proxy_name_owner_changed,
+	                                                               proxyt,
+	                                                               NULL); /* destroy notify */
+
 	/* Making sure the server has the proxy as well */
 	proxyt->server.proxy = proxyt->proxy;
 


Follow ups