aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-glib/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdbusmenu-glib/client.c')
-rw-r--r--libdbusmenu-glib/client.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c
index d2ba541..2e985d6 100644
--- a/libdbusmenu-glib/client.c
+++ b/libdbusmenu-glib/client.c
@@ -30,6 +30,8 @@ License version 3 and version 2.1 along with this program. If not, see
#include "config.h"
#endif
+#include <dbus/dbus-glib-bindings.h>
+
#include <libxml/parser.h>
#include <libxml/tree.h>
@@ -397,6 +399,25 @@ dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, c
return build_proxies(client);
}
+/* This is the response to see if the name has an owner. If
+ it does, then we should build the proxies here. Race condition
+ check. */
+static void
+name_owner_check (DBusGProxy *proxy, gboolean has_owner, GError *error, gpointer userdata)
+{
+ if (error != NULL) {
+ return;
+ }
+
+ if (!has_owner) {
+ return;
+ }
+
+ DbusmenuClient * client = DBUSMENU_CLIENT(userdata);
+ build_proxies(client);
+ return;
+}
+
/* This function builds the DBus proxy which will look out for
the service coming up. */
static void
@@ -426,6 +447,13 @@ build_dbus_proxy (DbusmenuClient * client)
dbus_g_proxy_connect_signal(priv->dbusproxy, "NameOwnerChanged",
G_CALLBACK(dbus_owner_change), client, NULL);
+ /* Now let's check to make sure we're not in some race
+ condition case. */
+ org_freedesktop_DBus_name_has_owner_async(priv->dbusproxy,
+ priv->dbus_name,
+ name_owner_check,
+ client);
+
return;
}
@@ -533,6 +561,12 @@ build_proxies (DbusmenuClient * client)
static gint
parse_node_get_id (xmlNodePtr node)
{
+ if (node == NULL) {
+ return -1;
+ }
+ if (node->type != XML_ELEMENT_NODE) {
+ return -1;
+ }
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);
@@ -682,6 +716,17 @@ menuitem_call_cb (DBusGProxy * proxy, GError * error, gpointer userdata)
void
dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, const GValue * value, guint timestamp)
{
+ g_return_if_fail(DBUSMENU_IS_CLIENT(client));
+ g_return_if_fail(id >= 0);
+ g_return_if_fail(name != NULL);
+
+ if (value == NULL) {
+ GValue internalval = {0};
+ g_value_init(&internalval, G_TYPE_INT);
+ g_value_set_int(&internalval, 0);
+ value = &internalval;
+ }
+
DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);
org_ayatana_dbusmenu_event_async (priv->menuproxy, id, name, value, timestamp, menuitem_call_cb, GINT_TO_POINTER(id));
return;
@@ -855,6 +900,10 @@ parse_layout (DbusmenuClient * client, const gchar * layout)
xmlNodePtr root = xmlDocGetRootElement(xmldoc);
+ if (root == NULL) {
+ g_warning("Unable to get root node of menu XML");
+ }
+
DbusmenuMenuitem * oldroot = priv->root;
priv->root = parse_layout_xml(client, root, priv->root, NULL, priv->menuproxy);