← Back to team overview

ayatana-commits team mailing list archive

[Branch ~dbusmenu-team/dbusmenu/trunk] Rev 46: Fixing the dbus handling so that we can pick up the menu again if the server is not initially the...

 

Merge authors:
  Ted Gould (ted)
Related merge proposals:
  https://code.launchpad.net/~ted/dbusmenu/lightweight-proxy/+merge/16947
  proposed by: Ted Gould (ted)
  review: Approve - David Barth (dbarth)
------------------------------------------------------------
revno: 46 [merge]
committer: Ted Gould <ted@xxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-01-07 10:46:21 -0600
message:
  Fixing the dbus handling so that we can pick up the menu again if the server is not initially there, or comes back after disappearing.
modified:
  libdbusmenu-glib/client.c
  tests/test-glib-layout-client.c
  tests/test-glib-layout-server.c


--
lp:dbusmenu
https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk

Your team ayatana-commits is subscribed to branch lp:dbusmenu.
To unsubscribe from this branch go to https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk/+edit-subscription.
=== modified file 'libdbusmenu-glib/client.c'
--- libdbusmenu-glib/client.c	2009-12-22 14:01:25 +0000
+++ libdbusmenu-glib/client.c	2010-01-07 05:27:49 +0000
@@ -367,8 +367,9 @@
 dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, DbusmenuClient * client)
 {
 	DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);
+	/* g_debug("Owner change: %s %s %s", name, prev, new); */
 
-	if (!(new != NULL && prev == NULL)) {
+	if (!(new[0] != '\0' && prev[0] == '\0')) {
 		/* If it's not someone new getting on the bus, sorry we
 		   simply just don't care.  It's not that your service isn't
 		   important to someone, just not us.  You'll find the right
@@ -376,7 +377,7 @@
 		return;
 	}
 
-	if (g_strcmp0(new, priv->dbus_name)) {
+	if (g_strcmp0(name, priv->dbus_name)) {
 		/* Again, someone else's service. */
 		return;
 	}
@@ -471,6 +472,7 @@
 	if (error != NULL) {
 		g_warning("Unable to get property proxy for %s on %s: %s", priv->dbus_name, priv->dbus_object, error->message);
 		g_error_free(error);
+		build_dbus_proxy(client);
 		return;
 	}
 	g_object_add_weak_pointer(G_OBJECT(priv->propproxy), (gpointer *)&priv->propproxy);
@@ -484,6 +486,7 @@
 	if (error != NULL) {
 		g_warning("Unable to get dbusmenu proxy for %s on %s: %s", priv->dbus_name, priv->dbus_object, error->message);
 		g_error_free(error);
+		build_dbus_proxy(client);
 		return;
 	}
 	g_object_add_weak_pointer(G_OBJECT(priv->menuproxy), (gpointer *)&priv->menuproxy);

=== modified file 'tests/test-glib-layout-client.c'
--- tests/test-glib-layout-client.c	2009-12-23 02:51:37 +0000
+++ tests/test-glib-layout-client.c	2010-01-07 14:55:35 +0000
@@ -109,9 +109,7 @@
 {
 	g_type_init();
 
-	g_usleep(500000);
-
-	DbusmenuClient * client = dbusmenu_client_new(":1.0", "/org/test");
+	DbusmenuClient * client = dbusmenu_client_new("org.dbusmenu.test", "/org/test");
 	g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL);
 
 	g_timeout_add_seconds(10, timer_func, client);

=== modified file 'tests/test-glib-layout-server.c'
--- tests/test-glib-layout-server.c	2009-05-27 08:11:12 +0000
+++ tests/test-glib-layout-server.c	2010-01-07 14:55:35 +0000
@@ -24,6 +24,7 @@
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib-bindings.h>
 
 #include <libdbusmenu-glib/server.h>
 #include <libdbusmenu-glib/menuitem.h>
@@ -74,10 +75,26 @@
 int
 main (int argc, char ** argv)
 {
+	GError * error = NULL;
+
 	g_type_init();
 
+	DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
 	g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
 
+	DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+	guint nameret = 0;
+
+	if (!org_freedesktop_DBus_request_name(bus_proxy, "org.dbusmenu.test", 0, &nameret, &error)) {
+		g_error("Unable to call to request name");
+		return 1;
+	}
+
+	if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		g_error("Unable to get name");
+		return 1;
+	}
+
 	server = dbusmenu_server_new("/org/test");
 
 	timer_func(NULL);