From fa0e53c2e27f0c8ed7cbfa839265e91b4fdf8d67 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 17 Sep 2009 16:12:42 -0500 Subject: Adding in a second checking of the layout if we look for it while we're still requesting it. We're not sure if this creates an issue between the syncing of the two objects. --- libdbusmenu-glib/client.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 4ae4f75..1bf4e19 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -66,6 +66,7 @@ struct _DbusmenuClientPrivate DBusGProxy * menuproxy; DBusGProxy * propproxy; DBusGProxyCall * layoutcall; + gboolean check_layout; DBusGProxy * dbusproxy; @@ -194,6 +195,7 @@ dbusmenu_client_init (DbusmenuClient *self) priv->menuproxy = NULL; priv->propproxy = NULL; priv->layoutcall = NULL; + priv->check_layout = FALSE; priv->dbusproxy = NULL; @@ -721,6 +723,11 @@ update_layout_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) /* g_debug("Root is now: 0x%X", (unsigned int)priv->root); */ g_signal_emit(G_OBJECT(client), signals[LAYOUT_UPDATED], 0, TRUE); + if (priv->check_layout) { + priv->check_layout = FALSE; + update_layout(client); + } + return; } @@ -736,6 +743,7 @@ update_layout (DbusmenuClient * client) } if (priv->layoutcall != NULL) { + priv->check_layout = TRUE; return; } @@ -803,16 +811,9 @@ dbusmenu_client_get_root (DbusmenuClient * client) return NULL; } -#if 0 -/* Seems to be a bug in dbus-glib that assert here, I think because - multiple people try and grab it. We're going to comment this out - for now as everyone should be listening to the root changed signal - anyway. */ if (priv->layoutcall != NULL) { - /* Will end the current call and block on it's completion */ - update_layout_cb(priv->propproxy, priv->layoutcall, client); + priv->check_layout = TRUE; } -#endif return priv->root; } -- cgit v1.2.3 From be2f874303bfab096b4f06cf535637c14393ee18 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Sep 2009 15:16:00 -0500 Subject: Changing from a boolean to tracking rev numbers in the private structure. --- libdbusmenu-glib/client.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 1bf4e19..271483d 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -66,7 +66,9 @@ struct _DbusmenuClientPrivate DBusGProxy * menuproxy; DBusGProxy * propproxy; DBusGProxyCall * layoutcall; - gboolean check_layout; + + gint current_revision; + gint my_revision; DBusGProxy * dbusproxy; @@ -98,7 +100,7 @@ static void id_update (DBusGProxy * proxy, guint id, DbusmenuClient * client); static void build_proxies (DbusmenuClient * client); static guint parse_node_get_id (xmlNodePtr node); static DbusmenuMenuitem * parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * item, DbusmenuMenuitem * parent, DBusGProxy * proxy); -static void parse_layout (DbusmenuClient * client, const gchar * layout); +static gint parse_layout (DbusmenuClient * client, const gchar * layout); static void update_layout_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data); static void update_layout (DbusmenuClient * client); static void menuitem_get_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data); @@ -195,7 +197,9 @@ dbusmenu_client_init (DbusmenuClient *self) priv->menuproxy = NULL; priv->propproxy = NULL; priv->layoutcall = NULL; - priv->check_layout = FALSE; + + priv->current_revision = 0; + priv->my_revision = 0; priv->dbusproxy = NULL; @@ -673,7 +677,7 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it /* Take the layout passed to us over DBus and turn it into a set of beautiful objects */ -static void +static gint parse_layout (DbusmenuClient * client, const gchar * layout) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); @@ -696,7 +700,7 @@ parse_layout (DbusmenuClient * client, const gchar * layout) g_signal_emit(G_OBJECT(client), signals[ROOT_CHANGED], 0, priv->root, TRUE); } - return; + return 1; } /* When the layout property returns, here's where we take care of that. */ @@ -718,13 +722,18 @@ update_layout_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) const gchar * xml = g_value_get_string(&value); /* g_debug("Got layout string: %s", xml); */ - parse_layout(client, xml); + gint rev = parse_layout(client, xml); + + if (rev == 0) { + g_warning("Unable to parse layout!"); + return; + } + priv->my_revision = rev; /* g_debug("Root is now: 0x%X", (unsigned int)priv->root); */ g_signal_emit(G_OBJECT(client), signals[LAYOUT_UPDATED], 0, TRUE); - if (priv->check_layout) { - priv->check_layout = FALSE; + if (priv->my_revision < priv->current_revision) { update_layout(client); } @@ -743,7 +752,6 @@ update_layout (DbusmenuClient * client) } if (priv->layoutcall != NULL) { - priv->check_layout = TRUE; return; } @@ -811,10 +819,6 @@ dbusmenu_client_get_root (DbusmenuClient * client) return NULL; } - if (priv->layoutcall != NULL) { - priv->check_layout = TRUE; - } - return priv->root; } -- cgit v1.2.3 From d8e66642e25a08bb4096b96ab101b34305ba4f84 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Sep 2009 15:20:07 -0500 Subject: Save the 'current' version and track whether we need to request an update. --- libdbusmenu-glib/client.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 271483d..d4582a9 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -94,7 +94,7 @@ static void dbusmenu_client_finalize (GObject *object); static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); /* Private Funcs */ -static void layout_update (DBusGProxy * proxy, DbusmenuClient * client); +static void layout_update (DBusGProxy * proxy, gint revision, DbusmenuClient * client); static void id_prop_update (DBusGProxy * proxy, guint id, gchar * property, gchar * value, DbusmenuClient * client); static void id_update (DBusGProxy * proxy, guint id, DbusmenuClient * client); static void build_proxies (DbusmenuClient * client); @@ -307,9 +307,13 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) /* Annoying little wrapper to make the right function update */ static void -layout_update (DBusGProxy * proxy, DbusmenuClient * client) +layout_update (DBusGProxy * proxy, gint revision, DbusmenuClient * client) { - update_layout(client); + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + priv->current_revision = revision; + if (priv->current_revision > priv->my_revision) { + update_layout(client); + } return; } -- cgit v1.2.3 From 0e09fe611584c9af4e5e91c8c0858fc58eaf991e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Sep 2009 15:29:39 -0500 Subject: Getting the revision data off of the root node there. --- libdbusmenu-glib/client.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index d4582a9..4e11359 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -492,6 +492,34 @@ build_proxies (DbusmenuClient * client) return; } +/* Get the "revision" attribute of the node, parse it and + return it. Also we're checking to ensure the node + is a 'menu' here. */ +static gint +parse_node_get_revision (xmlNodePtr node) +{ + if (g_strcmp0((gchar *)node->name, "menu") != 0) { + /* This kills some nodes early */ + g_warning("XML Node is not 'menu' it is '%s'", node->name); + return 0; + } + + xmlAttrPtr attrib; + for (attrib = node->properties; attrib != NULL; attrib = attrib->next) { + if (g_strcmp0((gchar *)attrib->name, "revision") == 0) { + if (attrib->children != NULL) { + guint revision = (guint)g_ascii_strtoull((gchar *)attrib->children->content, NULL, 10); + /* g_debug ("Found ID: %d", id); */ + return revision; + } + break; + } + } + + g_warning("Unable to find a revision on the node"); + return 0; +} + /* Get the ID attribute of the node, parse it and return it. Also we're checking to ensure the node is a 'menu' here. */ @@ -691,6 +719,7 @@ parse_layout (DbusmenuClient * client, const gchar * layout) xmldoc = xmlReadMemory(layout, g_utf8_strlen(layout, 16*1024), "dbusmenu.xml", NULL, 0); xmlNodePtr root = xmlDocGetRootElement(xmldoc); + gint revision = parse_node_get_revision(root); DbusmenuMenuitem * oldroot = priv->root; priv->root = parse_layout_xml(client, root, priv->root, NULL, priv->menuproxy); @@ -704,7 +733,7 @@ parse_layout (DbusmenuClient * client, const gchar * layout) g_signal_emit(G_OBJECT(client), signals[ROOT_CHANGED], 0, priv->root, TRUE); } - return 1; + return revision; } /* When the layout property returns, here's where we take care of that. */ -- cgit v1.2.3 From 152034b24234c6d06649a48ae29643c5075c4bb1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Sep 2009 15:38:02 -0500 Subject: Updating prototype for signal --- libdbusmenu-glib/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 4e11359..e2679e1 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -477,7 +477,7 @@ build_proxies (DbusmenuClient * client) priv->dbusproxy = NULL; } - dbus_g_proxy_add_signal(priv->menuproxy, "LayoutUpdate", G_TYPE_INVALID); + dbus_g_proxy_add_signal(priv->menuproxy, "LayoutUpdate", G_TYPE_INT, G_TYPE_INVALID); dbus_g_proxy_connect_signal(priv->menuproxy, "LayoutUpdate", G_CALLBACK(layout_update), client, NULL); dbus_g_object_register_marshaller(_dbusmenu_server_marshal_VOID__UINT_STRING_STRING, G_TYPE_NONE, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); -- cgit v1.2.3