From f309ec2bb22cda3e2f763f96bb6a08652d9373d8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 10:55:58 -0500 Subject: Changing the way the static interface information is generated --- libdbusmenu-glib/server.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index c5cf2fe..bbccd73 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -30,10 +30,14 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif +#include + #include "menuitem-private.h" #include "server.h" #include "server-marshal.h" +#include "dbus-menu.xml.h" + /* DBus Prototypes */ static gboolean _dbusmenu_server_get_layout (DbusmenuServer * server, gint parent, guint * revision, gchar ** layout, GError ** error); static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); @@ -46,8 +50,6 @@ static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id static void _gvalue_array_append_int(GValueArray *array, gint i); static void _gvalue_array_append_hashtable(GValueArray *array, GHashTable * dict); -#include "dbusmenu-server.h" - static void layout_update_signal (DbusmenuServer * server); #define DBUSMENU_VERSION_NUMBER 2 @@ -91,6 +93,10 @@ enum { LAST_ERROR }; +/* Globals */ +static GDBusNodeInfo * dbusmenu_node_info = NULL; +static GDBusInterfaceInfo * dbusmenu_interface_info = NULL; + /* Prototype */ static void dbusmenu_server_class_init (DbusmenuServerClass *class); static void dbusmenu_server_init (DbusmenuServer *self); @@ -203,7 +209,23 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) DBUSMENU_VERSION_NUMBER, DBUSMENU_VERSION_NUMBER, DBUSMENU_VERSION_NUMBER, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - dbus_g_object_type_install_info(DBUSMENU_TYPE_SERVER, &dbus_glib__dbusmenu_server_object_info); + if (dbusmenu_node_info == NULL) { + GError * error = NULL; + + dbusmenu_node_info = g_dbus_node_info_new_for_xml(dbus_menu_xml, &error); + if (error != NULL) { + g_error("Unable to parse DBusmenu Interface description: %s", error->message); + g_error_free(error); + } + } + + if (dbusmenu_interface_info == NULL) { + dbusmenu_interface_info = g_dbus_node_info_lookup_interface(dbusmenu_node_info, "org.ayatana.dbusmenu"); + + if (dbusmenu_interface_info == NULL) { + g_error("Unable to find interface 'org.ayatana.dbusmenu'"); + } + } return; } -- cgit v1.2.3 From 23b8623959467e965c83b8bd6458575c0eca34cb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 11:17:23 -0500 Subject: Setting up the private variables that we're going to do need to set this stuff up --- libdbusmenu-glib/server.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index bbccd73..6f5d45c 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -61,6 +61,10 @@ struct _DbusmenuServerPrivate gchar * dbusobject; gint layout_revision; guint layout_idle; + + GDBusConnection * bus; + GCancellable * bus_lookup; + guint dbus_registration; }; #define DBUSMENU_SERVER_GET_PRIVATE(o) (DBUSMENU_SERVER(o)->priv) @@ -241,6 +245,9 @@ dbusmenu_server_init (DbusmenuServer *self) priv->dbusobject = NULL; priv->layout_revision = 1; priv->layout_idle = 0; + priv->bus = NULL; + priv->bus_lookup = NULL; + priv->dbus_registration = 0; return; } @@ -259,6 +266,27 @@ dbusmenu_server_dispose (GObject *object) g_object_unref(priv->root); } + if (priv->dbus_registration != 0) { + g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration); + priv->dbus_registration = 0; + } + + if (priv->bus != NULL) { + g_object_unref(priv->bus); + priv->bus = NULL; + } + + if (priv->bus_lookup != NULL) { + if (!g_cancellable_is_cancelled(priv->bus_lookup)) { + /* Note, this may case the async function to run at + some point in the future. That's okay, it'll get an + error, but just FYI */ + g_cancellable_cancel(priv->bus_lookup); + } + g_object_unref(priv->bus_lookup); + priv->bus_lookup = NULL; + } + G_OBJECT_CLASS (dbusmenu_server_parent_class)->dispose (object); return; } -- cgit v1.2.3 From a797369ae885c2df81620b90ce6eaa2a9de1de87 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 11:47:18 -0500 Subject: Changing the registration of the object on the bus --- libdbusmenu-glib/server.c | 87 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 10 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 6f5d45c..5729128 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -98,8 +98,9 @@ enum { }; /* Globals */ -static GDBusNodeInfo * dbusmenu_node_info = NULL; -static GDBusInterfaceInfo * dbusmenu_interface_info = NULL; +static GDBusNodeInfo * dbusmenu_node_info = NULL; +static GDBusInterfaceInfo * dbusmenu_interface_info = NULL; +static const GDBusInterfaceVTable dbusmenu_interface_table = {0}; /* Prototype */ static void dbusmenu_server_class_init (DbusmenuServerClass *class); @@ -108,6 +109,8 @@ static void dbusmenu_server_dispose (GObject *object); static void dbusmenu_server_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); +static void register_object (DbusmenuServer * server); +static void bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data); static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server); static void menuitem_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint pos, DbusmenuServer * server); static void menuitem_child_removed (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, DbusmenuServer * server); @@ -302,21 +305,21 @@ static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(obj); - GError * error = NULL; switch (id) { case PROP_DBUS_OBJECT: g_return_if_fail(priv->dbusobject == NULL); priv->dbusobject = g_value_dup_string(value); - DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - if (connection == NULL || error != NULL) { - g_warning("Unable to get session bus: %s", error == NULL ? "No message" : error->message); - if (error != NULL) { g_error_free(error); } + if (priv->bus == NULL) { + if (priv->bus_lookup == NULL) { + priv->bus_lookup = g_cancellable_new(); + g_return_if_fail(priv->bus_lookup != NULL); + } + + g_bus_get(G_BUS_TYPE_SESSION, priv->bus_lookup, bus_got_cb, obj); } else { - dbus_g_connection_register_g_object(connection, - priv->dbusobject, - obj); + register_object(DBUSMENU_SERVER(obj)); } break; case PROP_ROOT_NODE: @@ -378,6 +381,70 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) return; } +/* Register the object on the dbus bus */ +static void +register_object (DbusmenuServer * server) +{ + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + /* Object info */ + g_return_if_fail(priv->bus != NULL); + g_return_if_fail(priv->dbusobject != NULL); + + /* Class info */ + g_return_if_fail(dbusmenu_node_info != NULL); + g_return_if_fail(dbusmenu_interface_info != NULL); + + /* We might block on this in the future, but it'd be nice if + we could change the object path. Thinking about it... */ + if (priv->dbus_registration != 0) { + g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration); + priv->dbus_registration = 0; + } + + GError * error = NULL; + priv->dbus_registration = g_dbus_connection_register_object(priv->bus, + priv->dbusobject, + dbusmenu_interface_info, + &dbusmenu_interface_table, + server, + NULL, + &error); + + if (error != NULL) { + g_warning("Unable to register object on bus: %s", error->message); + g_error_free(error); + } + + return; +} + +/* Callback from asking GIO to get us the session bus */ +static void +bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data) +{ + GError * error = NULL; + + GDBusConnection * bus = g_bus_get_finish(result, &error); + + if (error != NULL) { + g_warning("Unable to get session bus: %s", error->message); + g_error_free(error); + return; + } + + /* Note: We're not using the user_data before we check for + the error so that in the cancelled case at destruction of + the object we don't end up with an invalid object. */ + + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(user_data); + priv->bus = bus; + + register_object(DBUSMENU_SERVER(user_data)); + + return; +} + /* Handle actually signalling in the idle loop. This way we collect all the updates. */ static gboolean -- cgit v1.2.3 From 0db52d9f483d8d63024c3dc83d1cb5709c4b3f81 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 11:59:43 -0500 Subject: Moving globals --- libdbusmenu-glib/server.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 5729128..3a45f62 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -97,11 +97,6 @@ enum { LAST_ERROR }; -/* Globals */ -static GDBusNodeInfo * dbusmenu_node_info = NULL; -static GDBusInterfaceInfo * dbusmenu_interface_info = NULL; -static const GDBusInterfaceVTable dbusmenu_interface_table = {0}; - /* Prototype */ static void dbusmenu_server_class_init (DbusmenuServerClass *class); static void dbusmenu_server_init (DbusmenuServer *self); @@ -118,6 +113,11 @@ static void menuitem_signals_create (DbusmenuMenuitem * mi, gpointer data); static void menuitem_signals_remove (DbusmenuMenuitem * mi, gpointer data); static GQuark error_quark (void); +/* Globals */ +static GDBusNodeInfo * dbusmenu_node_info = NULL; +static GDBusInterfaceInfo * dbusmenu_interface_info = NULL; +static const GDBusInterfaceVTable dbusmenu_interface_table = {0}; + G_DEFINE_TYPE (DbusmenuServer, dbusmenu_server, G_TYPE_OBJECT); static void -- cgit v1.2.3 From e80a7c4d027837c6d67fd4de52914b32b0bc30d4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 12:11:41 -0500 Subject: Filling out the vtable --- libdbusmenu-glib/server.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 3a45f62..df57994 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -106,6 +106,21 @@ static void set_property (GObject * obj, guint id, const GValue * value, GParamS static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); static void register_object (DbusmenuServer * server); static void bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data); +static void bus_method_call (GDBusConnection * connection, + const gchar * sender, + const gchar * path, + const gchar * interface, + const gchar * method, + GVariant * params, + GDBusMethodInvocation * invocation, + gpointer user_data); +static GVariant * bus_get_prop (GDBusConnection * connection, + const gchar * sender, + const gchar * path, + const gchar * interface, + const gchar * property, + GError ** error, + gpointer user_data); static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server); static void menuitem_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint pos, DbusmenuServer * server); static void menuitem_child_removed (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, DbusmenuServer * server); @@ -116,7 +131,11 @@ static GQuark error_quark (void); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; static GDBusInterfaceInfo * dbusmenu_interface_info = NULL; -static const GDBusInterfaceVTable dbusmenu_interface_table = {0}; +static const GDBusInterfaceVTable dbusmenu_interface_table = { + method_call: bus_method_call, + get_property: bus_get_prop, + set_property: NULL /* No properties that can be set */ +}; G_DEFINE_TYPE (DbusmenuServer, dbusmenu_server, G_TYPE_OBJECT); @@ -445,6 +464,24 @@ bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data) return; } +/* Function for the GDBus vtable to handle all method calls and dish + them out the appropriate functions */ +static void +bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data) +{ + + return; +} + +/* For the GDBus vtable but we only have one property so it's pretty + simple. */ +static GVariant * +bus_get_prop (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * property, GError ** error, gpointer user_data) +{ + + return NULL; +} + /* Handle actually signalling in the idle loop. This way we collect all the updates. */ static gboolean -- cgit v1.2.3 From 53eee1c44b504a06ca72c0f7e3d21d2b69bc6905 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 12:18:08 -0500 Subject: Whitespace --- libdbusmenu-glib/server.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index df57994..d7ccaf8 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -98,14 +98,22 @@ enum { }; /* Prototype */ -static void dbusmenu_server_class_init (DbusmenuServerClass *class); -static void dbusmenu_server_init (DbusmenuServer *self); -static void dbusmenu_server_dispose (GObject *object); -static void dbusmenu_server_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); -static void register_object (DbusmenuServer * server); -static void bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data); +static void dbusmenu_server_class_init (DbusmenuServerClass *class); +static void dbusmenu_server_init (DbusmenuServer *self); +static void dbusmenu_server_dispose (GObject *object); +static void dbusmenu_server_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); +static void register_object (DbusmenuServer * server); +static void bus_got_cb (GObject * obj, + GAsyncResult * result, + gpointer user_data); static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, @@ -121,12 +129,22 @@ static GVariant * bus_get_prop (GDBusConnection * connection, const gchar * property, GError ** error, gpointer user_data); -static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server); -static void menuitem_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint pos, DbusmenuServer * server); -static void menuitem_child_removed (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, DbusmenuServer * server); -static void menuitem_signals_create (DbusmenuMenuitem * mi, gpointer data); -static void menuitem_signals_remove (DbusmenuMenuitem * mi, gpointer data); -static GQuark error_quark (void); +static void menuitem_property_changed (DbusmenuMenuitem * mi, + gchar * property, + GValue * value, + DbusmenuServer * server); +static void menuitem_child_added (DbusmenuMenuitem * parent, + DbusmenuMenuitem * child, + guint pos, + DbusmenuServer * server); +static void menuitem_child_removed (DbusmenuMenuitem * parent, + DbusmenuMenuitem * child, + DbusmenuServer * server); +static void menuitem_signals_create (DbusmenuMenuitem * mi, + gpointer data); +static void menuitem_signals_remove (DbusmenuMenuitem * mi, + gpointer data); +static GQuark error_quark (void); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; -- cgit v1.2.3 From 9b7061a33a014f2b83d970698b31ff5e0e33e129 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 12:20:29 -0500 Subject: Moving the interface name into a define --- libdbusmenu-glib/server.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index d7ccaf8..aabad9a 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -52,7 +52,8 @@ static void _gvalue_array_append_hashtable(GValueArray *array, GHashTable * dict static void layout_update_signal (DbusmenuServer * server); -#define DBUSMENU_VERSION_NUMBER 2 +#define DBUSMENU_VERSION_NUMBER 2 +#define DBUSMENU_INTERFACE "org.ayatana.dbusmenu" /* Privates, I'll show you mine... */ struct _DbusmenuServerPrivate @@ -264,10 +265,10 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) } if (dbusmenu_interface_info == NULL) { - dbusmenu_interface_info = g_dbus_node_info_lookup_interface(dbusmenu_node_info, "org.ayatana.dbusmenu"); + dbusmenu_interface_info = g_dbus_node_info_lookup_interface(dbusmenu_node_info, DBUSMENU_INTERFACE); if (dbusmenu_interface_info == NULL) { - g_error("Unable to find interface 'org.ayatana.dbusmenu'"); + g_error("Unable to find interface '" DBUSMENU_INTERFACE "'"); } } -- cgit v1.2.3 From 1f98fff4723354444fe41fe3492b4a1681fdef14 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 12:27:33 -0500 Subject: Fleshing out the property get function --- libdbusmenu-glib/server.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index aabad9a..7a1b98e 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -497,8 +497,14 @@ bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar static GVariant * bus_get_prop (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * property, GError ** error, gpointer user_data) { + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(user_data); + + /* None of these should happen */ + g_return_val_if_fail(g_strcmp0(interface, DBUSMENU_INTERFACE) == 0, NULL); + g_return_val_if_fail(g_strcmp0(path, priv->dbusobject) == 0, NULL); + g_return_val_if_fail(g_strcmp0(property, "version") == 0, NULL); - return NULL; + return g_variant_new_uint32(DBUSMENU_VERSION_NUMBER); } /* Handle actually signalling in the idle loop. This way we collect all -- cgit v1.2.3 From 2cc94b5a4b7016d8bf01eec34b6ff7e771d8e682 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 13:42:38 -0500 Subject: Setting up a method table for the dbus interface --- libdbusmenu-glib/server.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 7a1b98e..ddf242f 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -98,6 +98,21 @@ enum { LAST_ERROR }; +/* Method Table */ +typedef void (*MethodTableFunc) (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); + +typedef struct _method_table_t method_table_t; +struct _method_table_t { + const gchar * interned_name; + MethodTableFunc func; +}; + +enum { + METHOD_GET_LAYOUT = 0, + /* Counter, do not remove! */ + METHOD_COUNT +}; + /* Prototype */ static void dbusmenu_server_class_init (DbusmenuServerClass *class); static void dbusmenu_server_init (DbusmenuServer *self); @@ -155,6 +170,7 @@ static const GDBusInterfaceVTable dbusmenu_interface_table = { get_property: bus_get_prop, set_property: NULL /* No properties that can be set */ }; +static method_table_t dbusmenu_method_table[METHOD_COUNT]; G_DEFINE_TYPE (DbusmenuServer, dbusmenu_server, G_TYPE_OBJECT); @@ -272,6 +288,10 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) } } + /* Building our Method table :( */ + dbusmenu_method_table[METHOD_GET_LAYOUT].interned_name = g_intern_static_string("GetLayout"); + dbusmenu_method_table[METHOD_GET_LAYOUT].func = NULL; + return; } -- cgit v1.2.3 From e170f6516419cf403931916ac9f6a4b3a0b1997c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 13:43:09 -0500 Subject: Fleshing out the method call function to use the table --- libdbusmenu-glib/server.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index ddf242f..493bbdf 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -508,7 +508,27 @@ bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data) static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data) { + int i; + const gchar * interned_method = g_intern_string(method); + + for (i = 0; i < METHOD_COUNT; i++) { + if (dbusmenu_method_table[i].interned_name == interned_method) { + if (dbusmenu_method_table[i].func != NULL) { + return dbusmenu_method_table[i].func(DBUSMENU_SERVER(user_data), params, invocation); + } else { + /* If we have a null function we're responding but nothing else. */ + g_dbus_method_invocation_return_value(invocation, NULL); + return; + } + } + } + /* We're here because there's an error */ + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NOT_IMPLEMENTED, + "Unable to find method '%s'", + method); return; } -- cgit v1.2.3 From a7ec487bdcf1383fc5ccbd69af543b1f6f93fd1a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 13:54:49 -0500 Subject: Porting over GetLayout --- libdbusmenu-glib/server.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 493bbdf..cc0d0b3 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -39,7 +39,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "dbus-menu.xml.h" /* DBus Prototypes */ -static gboolean _dbusmenu_server_get_layout (DbusmenuServer * server, gint parent, guint * revision, gchar ** layout, GError ** error); static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error); @@ -161,6 +160,9 @@ static void menuitem_signals_create (DbusmenuMenuitem * mi, static void menuitem_signals_remove (DbusmenuMenuitem * mi, gpointer data); static GQuark error_quark (void); +static void bus_get_layout (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; @@ -290,7 +292,7 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) /* Building our Method table :( */ dbusmenu_method_table[METHOD_GET_LAYOUT].interned_name = g_intern_static_string("GetLayout"); - dbusmenu_method_table[METHOD_GET_LAYOUT].func = NULL; + dbusmenu_method_table[METHOD_GET_LAYOUT].func = bus_get_layout; return; } @@ -670,12 +672,15 @@ error_quark (void) } /* DBus interface */ -static gboolean -_dbusmenu_server_get_layout (DbusmenuServer * server, gint parent, guint * revision, gchar ** layout, GError ** error) +static void +bus_get_layout (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - *revision = priv->layout_revision; + gint parent = 0; + g_variant_get(params, "(i)", &parent); + + guint revision = priv->layout_revision; GPtrArray * xmlarray = g_ptr_array_new(); if (parent == 0) { @@ -688,26 +693,31 @@ _dbusmenu_server_get_layout (DbusmenuServer * server, gint parent, guint * revis } else { DbusmenuMenuitem * item = dbusmenu_menuitem_find_id(priv->root, parent); if (item == NULL) { - if (error != NULL) { - g_set_error(error, - error_quark(), - INVALID_MENUITEM_ID, - "The ID supplied %d does not refer to a menu item we have", - parent); - } - return FALSE; + g_dbus_method_invocation_return_error(invocation, + error_quark(), + INVALID_MENUITEM_ID, + "The ID supplied %d does not refer to a menu item we have", + parent); + return; } dbusmenu_menuitem_buildxml(item, xmlarray); } g_ptr_array_add(xmlarray, NULL); /* build string */ - *layout = g_strjoinv("", (gchar **)xmlarray->pdata); + gchar * layout = g_strjoinv("", (gchar **)xmlarray->pdata); g_ptr_array_foreach(xmlarray, xmlarray_foreach_free, NULL); g_ptr_array_free(xmlarray, TRUE); - return TRUE; + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(us)", + revision, + layout)); + + g_free(layout); + + return; } static gboolean -- cgit v1.2.3 From d11d10ce3d399be36d889d386a3a88a8487ca4fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 16:17:19 -0500 Subject: Implement the get_properties function --- libdbusmenu-glib/server.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index cc0d0b3..73aa3c2 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -41,7 +41,6 @@ License version 3 and version 2.1 along with this program. If not, see /* DBus Prototypes */ static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); -static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); @@ -108,6 +107,7 @@ struct _method_table_t { enum { METHOD_GET_LAYOUT = 0, + METHOD_GET_GROUP_PROPERTIES, /* Counter, do not remove! */ METHOD_COUNT }; @@ -163,6 +163,9 @@ static GQuark error_quark (void); static void bus_get_layout (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_get_group_properties (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; @@ -294,6 +297,9 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) dbusmenu_method_table[METHOD_GET_LAYOUT].interned_name = g_intern_static_string("GetLayout"); dbusmenu_method_table[METHOD_GET_LAYOUT].func = bus_get_layout; + dbusmenu_method_table[METHOD_GET_GROUP_PROPERTIES].interned_name = g_intern_static_string("GetGroupProperties"); + dbusmenu_method_table[METHOD_GET_GROUP_PROPERTIES].func = bus_get_group_properties; + return; } @@ -789,36 +795,29 @@ _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** prop /* Handles getting a bunch of properties from a variety of menu items to make one mega dbus message */ -static gboolean -_dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error) +static void +bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { - /* Build an initial pointer array */ - *values = g_ptr_array_new(); + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + GVariantIter * ids = NULL; + g_variant_get_child(params, 0, "ai", &ids); - /* Go through each ID to get that ID's properties */ - int idcnt; - for (idcnt = 0; idcnt < ids->len; idcnt++) { - GHashTable * idprops = NULL; - GError * error = NULL; - gint id = g_array_index(ids, int, idcnt); + GVariantBuilder * builder = g_variant_builder_new(G_VARIANT_TYPE("a(ia{sv})")); - /* Get the properties for this ID the old fashioned way. */ - if (!_dbusmenu_server_get_properties(server, id, properties, &idprops, &error)) { - g_warning("Error getting the properties from ID %d: %s", id, error->message); - g_error_free(error); - error = NULL; - continue; - } + GVariant * id; + while ((id = g_variant_iter_next_value(ids)) != NULL) { + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, g_variant_get_int32(id)); + if (mi == NULL) continue; - GValueArray * valarray = g_value_array_new(2); + g_variant_builder_add(builder, "ia{sv}", g_variant_get_int32(id), dbusmenu_menuitem_properties_variant(mi)); + } - _gvalue_array_append_int(valarray, id); - _gvalue_array_append_hashtable(valarray, idprops); + GVariant * ret = g_variant_builder_end(builder); + g_variant_builder_unref(builder); - g_ptr_array_add(*values, valarray); - } + g_dbus_method_invocation_return_value(invocation, ret); - return TRUE; + return; } /* Allocate a value on the stack for the int and append -- cgit v1.2.3 From 1487c6bc178268b128982b40fa8d4a315dc3c72a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 16:31:14 -0500 Subject: Converting over GetChildren --- libdbusmenu-glib/server.c | 83 ++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 52 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 73aa3c2..f3fb197 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -42,11 +42,7 @@ License version 3 and version 2.1 along with this program. If not, see static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); -static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); -/* DBus Helpers */ -static void _gvalue_array_append_int(GValueArray *array, gint i); -static void _gvalue_array_append_hashtable(GValueArray *array, GHashTable * dict); static void layout_update_signal (DbusmenuServer * server); @@ -108,6 +104,7 @@ struct _method_table_t { enum { METHOD_GET_LAYOUT = 0, METHOD_GET_GROUP_PROPERTIES, + METHOD_GET_CHILDREN, /* Counter, do not remove! */ METHOD_COUNT }; @@ -166,6 +163,9 @@ static void bus_get_layout (DbusmenuServer * server, static void bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_get_children (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; @@ -300,6 +300,9 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) dbusmenu_method_table[METHOD_GET_GROUP_PROPERTIES].interned_name = g_intern_static_string("GetGroupProperties"); dbusmenu_method_table[METHOD_GET_GROUP_PROPERTIES].func = bus_get_group_properties; + dbusmenu_method_table[METHOD_GET_CHILDREN].interned_name = g_intern_static_string("GetChildren"); + dbusmenu_method_table[METHOD_GET_CHILDREN].func = bus_get_children; + return; } @@ -820,74 +823,50 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho return; } -/* Allocate a value on the stack for the int and append - it to the array. */ -static void -_gvalue_array_append_int(GValueArray *array, gint i) -{ - GValue value = {0}; - - g_value_init(&value, G_TYPE_INT); - g_value_set_int(&value, i); - g_value_array_append(array, &value); - g_value_unset(&value); -} - -/* Allocate a value on the stack for the hashtable and append - it to the array. */ -static void -_gvalue_array_append_hashtable(GValueArray *array, GHashTable * dict) -{ - GValue value = {0}; - - g_value_init(&value, dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)); - g_value_set_boxed(&value, dict); - g_value_array_append(array, &value); - g_value_unset(&value); -} - +/* Turn a menuitem into an variant and attach it to the + VariantBuilder we passed in */ static void serialize_menuitem(gpointer data, gpointer user_data) { DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data); - GPtrArray * output = (GPtrArray *)(user_data); + GVariantBuilder * builder = (GVariantBuilder *)(user_data); gint id = dbusmenu_menuitem_get_id(mi); - GHashTable * dict = dbusmenu_menuitem_properties_copy(mi); + GVariant * props = dbusmenu_menuitem_properties_variant(mi); - GValueArray * item = g_value_array_new(2); - _gvalue_array_append_int(item, id); - _gvalue_array_append_hashtable(item, dict); - - g_ptr_array_add(output, item); - - g_hash_table_unref(dict); + g_variant_builder_add(builder, "ia{sv}", id, props); return; } -static gboolean -_dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error) +/* Gets the children and their properties of the ID that is + passed into the function */ +static void +bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { - if (error != NULL) { - g_set_error(error, - error_quark(), - INVALID_MENUITEM_ID, - "The ID supplied %d does not refer to a menu item we have", - id); - } - return FALSE; + g_dbus_method_invocation_return_error(invocation, + error_quark(), + INVALID_MENUITEM_ID, + "The ID supplied %d does not refer to a menu item we have", + id); + return; } - *output = g_ptr_array_new(); + GVariantBuilder * builder = g_variant_builder_new(G_VARIANT_TYPE("a(ia{sv})")); + GList * children = dbusmenu_menuitem_get_children(mi); - g_list_foreach(children, serialize_menuitem, *output); + g_list_foreach(children, serialize_menuitem, builder); - return TRUE; + GVariant * ret = g_variant_builder_end(builder); + g_variant_builder_unref(builder); + + g_dbus_method_invocation_return_value(invocation, ret); + return; } /* Structure for holding the event data for the idle function -- cgit v1.2.3 From 966d397a36971552609e24bb8071fdb69c4c279a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Oct 2010 16:49:47 -0500 Subject: Coverting GetProperty --- libdbusmenu-glib/server.c | 49 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index f3fb197..e83015a 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -39,7 +39,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "dbus-menu.xml.h" /* DBus Prototypes */ -static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); @@ -105,6 +104,7 @@ enum { METHOD_GET_LAYOUT = 0, METHOD_GET_GROUP_PROPERTIES, METHOD_GET_CHILDREN, + METHOD_GET_PROPERTY, /* Counter, do not remove! */ METHOD_COUNT }; @@ -166,6 +166,9 @@ static void bus_get_group_properties (DbusmenuServer * server, static void bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_get_property (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; @@ -303,6 +306,9 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) dbusmenu_method_table[METHOD_GET_CHILDREN].interned_name = g_intern_static_string("GetChildren"); dbusmenu_method_table[METHOD_GET_CHILDREN].func = bus_get_children; + dbusmenu_method_table[METHOD_GET_PROPERTY].interned_name = g_intern_static_string("GetProperty"); + dbusmenu_method_table[METHOD_GET_PROPERTY].func = bus_get_property; + return; } @@ -729,49 +735,48 @@ bus_get_layout (DbusmenuServer * server, GVariant * params, GDBusMethodInvocatio return; } -static gboolean -_dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error) +/* Get a single property off of a single menuitem */ +static void +bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); + const gchar * property = g_variant_get_string(g_variant_get_child_value(params, 1), NULL); + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { - if (error != NULL) { - g_set_error(error, + g_dbus_method_invocation_return_error(invocation, error_quark(), INVALID_MENUITEM_ID, "The ID supplied %d does not refer to a menu item we have", id); - } - return FALSE; + return; } - const gchar * prop = dbusmenu_menuitem_property_get(mi, property); + const GValue * prop = dbusmenu_menuitem_property_get_value(mi, property); if (prop == NULL) { - if (error != NULL) { - g_set_error(error, + g_dbus_method_invocation_return_error(invocation, error_quark(), INVALID_PROPERTY_NAME, "The property '%s' does not exist on menuitem with ID of %d", property, id); - } - return FALSE; + return; } - if (value == NULL) { - if (error != NULL) { - g_set_error(error, - error_quark(), - UNKNOWN_DBUS_ERROR, - "Uhm, yeah. We didn't get anywhere to put the value, that's really weird. Seems impossible really."); - } - return FALSE; + GValue vval = {0}; + g_value_init(&vval, G_TYPE_VARIANT); + + if (!g_value_transform(prop, &vval)) { + g_warning("Unable to convert property '%s' value from type '%s' to variant", property, G_VALUE_TYPE_NAME(prop)); } - *value = g_strdup(prop); + g_dbus_method_invocation_return_value(invocation, g_value_get_variant(&vval)); + g_value_unset(&vval); - return TRUE; + return; } static gboolean -- cgit v1.2.3 From abfd276f1d5aa79ebc30d9dccbe4e4d58315c499 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Oct 2010 11:47:09 -0500 Subject: Converting GetProperties --- libdbusmenu-glib/server.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index e83015a..a2d34d5 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -39,7 +39,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "dbus-menu.xml.h" /* DBus Prototypes */ -static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); @@ -105,6 +104,7 @@ enum { METHOD_GET_GROUP_PROPERTIES, METHOD_GET_CHILDREN, METHOD_GET_PROPERTY, + METHOD_GET_PROPERTIES, /* Counter, do not remove! */ METHOD_COUNT }; @@ -169,6 +169,9 @@ static void bus_get_children (DbusmenuServer * server, static void bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_get_properties (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; @@ -309,6 +312,9 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) dbusmenu_method_table[METHOD_GET_PROPERTY].interned_name = g_intern_static_string("GetProperty"); dbusmenu_method_table[METHOD_GET_PROPERTY].func = bus_get_property; + dbusmenu_method_table[METHOD_GET_PROPERTIES].interned_name = g_intern_static_string("GetProperties"); + dbusmenu_method_table[METHOD_GET_PROPERTIES].func = bus_get_properties; + return; } @@ -779,26 +785,30 @@ bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat return; } -static gboolean -_dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error) +/* Get some properties off of a single menuitem */ +static void +bus_get_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { - if (error != NULL) { - g_set_error(error, + g_dbus_method_invocation_return_error(invocation, error_quark(), INVALID_MENUITEM_ID, "The ID supplied %d does not refer to a menu item we have", id); - } - return FALSE; + return; } - *dict = dbusmenu_menuitem_properties_copy(mi); + GVariant * dict = dbusmenu_menuitem_properties_variant(mi); - return TRUE; + g_dbus_method_invocation_return_value(invocation, dict); + + return; } /* Handles getting a bunch of properties from a variety of menu items -- cgit v1.2.3 From 41df5ff0de7c2b9391acf93b58a5f1c803878a05 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Oct 2010 13:41:58 -0500 Subject: Porting over the event function --- libdbusmenu-glib/server.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index a2d34d5..2fdc1ef 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -39,7 +39,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "dbus-menu.xml.h" /* DBus Prototypes */ -static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); static void layout_update_signal (DbusmenuServer * server); @@ -105,6 +104,7 @@ enum { METHOD_GET_CHILDREN, METHOD_GET_PROPERTY, METHOD_GET_PROPERTIES, + METHOD_EVENT, /* Counter, do not remove! */ METHOD_COUNT }; @@ -172,6 +172,9 @@ static void bus_get_property (DbusmenuServer * server, static void bus_get_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_event (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; @@ -315,6 +318,9 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) dbusmenu_method_table[METHOD_GET_PROPERTIES].interned_name = g_intern_static_string("GetProperties"); dbusmenu_method_table[METHOD_GET_PROPERTIES].func = bus_get_properties; + dbusmenu_method_table[METHOD_EVENT].interned_name = g_intern_static_string("Event"); + dbusmenu_method_table[METHOD_EVENT].func = bus_event; + return; } @@ -910,34 +916,37 @@ event_local_handler (gpointer user_data) return FALSE; } -/* Handles the even coming off of DBus */ -static gboolean -_dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error) +/* Handles the events coming off of DBus */ +static void +bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { - if (error != NULL) { - g_set_error(error, - error_quark(), - INVALID_MENUITEM_ID, - "The ID supplied %d does not refer to a menu item we have", - id); - } - return FALSE; + g_dbus_method_invocation_return_error(invocation, + error_quark(), + INVALID_MENUITEM_ID, + "The ID supplied %d does not refer to a menu item we have", + id); + return; } idle_event_t * event_data = g_new0(idle_event_t, 1); event_data->mi = mi; g_object_ref(event_data->mi); - event_data->eventid = g_strdup(eventid); - event_data->timestamp = timestamp; - g_value_init(&(event_data->data), G_VALUE_TYPE(data)); - g_value_copy(data, &(event_data->data)); + event_data->eventid = g_strdup(g_variant_get_string(g_variant_get_child_value(params, 1), NULL)); + event_data->timestamp = g_variant_get_uint32(g_variant_get_child_value(params, 3)); + + /* TODO: Need to figure out converting a variant to a value */ + g_value_init(&(event_data->data), G_TYPE_INT); + g_value_set_int(&(event_data->data), 0); g_timeout_add(0, event_local_handler, event_data); - return TRUE; + + g_dbus_method_invocation_return_value(invocation, NULL); + return; } /* Recieve the About To Show function. Pass it to our menu item. */ -- cgit v1.2.3 From 5c07a374c78a73fee4030a61c74ab3a99fc8bcc5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Oct 2010 13:48:05 -0500 Subject: Porting over AboutToShow --- libdbusmenu-glib/server.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 2fdc1ef..42463a9 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -38,9 +38,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "dbus-menu.xml.h" -/* DBus Prototypes */ -static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); - static void layout_update_signal (DbusmenuServer * server); #define DBUSMENU_VERSION_NUMBER 2 @@ -105,6 +102,7 @@ enum { METHOD_GET_PROPERTY, METHOD_GET_PROPERTIES, METHOD_EVENT, + METHOD_ABOUT_TO_SHOW, /* Counter, do not remove! */ METHOD_COUNT }; @@ -175,6 +173,9 @@ static void bus_get_properties (DbusmenuServer * server, static void bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_about_to_show (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); /* Globals */ static GDBusNodeInfo * dbusmenu_node_info = NULL; @@ -321,6 +322,9 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) dbusmenu_method_table[METHOD_EVENT].interned_name = g_intern_static_string("Event"); dbusmenu_method_table[METHOD_EVENT].func = bus_event; + dbusmenu_method_table[METHOD_ABOUT_TO_SHOW].interned_name = g_intern_static_string("AboutToShow"); + dbusmenu_method_table[METHOD_ABOUT_TO_SHOW].func = bus_about_to_show; + return; } @@ -950,26 +954,26 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i } /* Recieve the About To Show function. Pass it to our menu item. */ -static gboolean -_dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error) +static void +bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { - if (error != NULL) { - g_set_error(error, - error_quark(), - INVALID_MENUITEM_ID, - "The ID supplied %d does not refer to a menu item we have", - id); - } - return FALSE; + g_dbus_method_invocation_return_error(invocation, + error_quark(), + INVALID_MENUITEM_ID, + "The ID supplied %d does not refer to a menu item we have", + id); + return; } /* GTK+ does not support about-to-show concept for now */ - *need_update = FALSE; - return TRUE; + g_dbus_method_invocation_return_value(invocation, + g_variant_new_boolean(FALSE)); + return; } /* Public Interface */ -- cgit v1.2.3 From 37596991960990c127336ccc8527832a35d595ad Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Oct 2010 16:10:55 -0500 Subject: Making signals emit on dbus as well as locally. --- libdbusmenu-glib/server.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 42463a9..652b2a8 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -589,6 +589,15 @@ layout_update_idle (gpointer user_data) DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); g_signal_emit(G_OBJECT(server), signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + if (priv->dbusobject != NULL && priv->bus != NULL) { + g_dbus_connection_emit_signal(priv->bus, + NULL, + priv->dbusobject, + DBUSMENU_INTERFACE, + "LayoutUpdated", + g_variant_new("(ui)", priv->layout_revision, 0), + NULL); + } priv->layout_idle = 0; @@ -612,7 +621,29 @@ layout_update_signal (DbusmenuServer * server) static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server) { + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + g_signal_emit(G_OBJECT(server), signals[ID_PROP_UPDATE], 0, dbusmenu_menuitem_get_id(mi), property, value, TRUE); + + if (priv->dbusobject != NULL && priv->bus != NULL) { + GValue variantval = {0}; + g_value_init(&variantval, G_TYPE_VARIANT); + + if (!g_value_transform(value, &variantval)) { + g_warning("Unable to convert property '%s' of type %s to a variant", property, G_VALUE_TYPE_NAME(value)); + } + GVariant * variant = g_value_get_variant(&variantval); + + g_dbus_connection_emit_signal(priv->bus, + NULL, + priv->dbusobject, + DBUSMENU_INTERFACE, + "ItemPropertyUpdated", + g_variant_new("(isv)", dbusmenu_menuitem_get_id(mi), property, variant), + NULL); + + g_value_unset(&variantval); + } return; } @@ -663,7 +694,20 @@ menuitem_child_moved (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint static void menuitem_shown (DbusmenuMenuitem * mi, guint timestamp, DbusmenuServer * server) { + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + g_signal_emit(G_OBJECT(server), signals[ITEM_ACTIVATION], 0, dbusmenu_menuitem_get_id(mi), timestamp, TRUE); + + if (priv->dbusobject != NULL && priv->bus != NULL) { + g_dbus_connection_emit_signal(priv->bus, + NULL, + priv->dbusobject, + DBUSMENU_INTERFACE, + "ItemPropertyUpdated", + g_variant_new("(iu)", dbusmenu_menuitem_get_id(mi), timestamp), + NULL); + } + return; } -- cgit v1.2.3 From 080cf37f48dba3dc521167bd3ddc51f45681ea1d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Nov 2010 16:55:43 -0600 Subject: Cleaning out namespaces from the XML so that GDBus will read it. --- libdbusmenu-glib/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 652b2a8..63d237f 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -36,7 +36,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "server.h" #include "server-marshal.h" -#include "dbus-menu.xml.h" +#include "dbus-menu-clean.xml.h" static void layout_update_signal (DbusmenuServer * server); @@ -288,7 +288,7 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) if (dbusmenu_node_info == NULL) { GError * error = NULL; - dbusmenu_node_info = g_dbus_node_info_new_for_xml(dbus_menu_xml, &error); + dbusmenu_node_info = g_dbus_node_info_new_for_xml(dbus_menu_clean_xml, &error); if (error != NULL) { g_error("Unable to parse DBusmenu Interface description: %s", error->message); g_error_free(error); -- cgit v1.2.3 From 17af43e09f01979a4ab660bbd2a60d9212a8ef13 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 20:12:53 -0600 Subject: Removing the set_value and get_value functions from being used elsewhere in -glib --- libdbusmenu-glib/server.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 63d237f..4fdd6f8 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -815,8 +815,8 @@ bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat return; } - const GValue * prop = dbusmenu_menuitem_property_get_value(mi, property); - if (prop == NULL) { + GVariant * variant = dbusmenu_menuitem_property_get_variant(mi, property); + if (variant == NULL) { g_dbus_method_invocation_return_error(invocation, error_quark(), INVALID_PROPERTY_NAME, @@ -826,16 +826,7 @@ bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat return; } - GValue vval = {0}; - g_value_init(&vval, G_TYPE_VARIANT); - - if (!g_value_transform(prop, &vval)) { - g_warning("Unable to convert property '%s' value from type '%s' to variant", property, G_VALUE_TYPE_NAME(prop)); - } - - g_dbus_method_invocation_return_value(invocation, g_value_get_variant(&vval)); - g_value_unset(&vval); - + g_dbus_method_invocation_return_value(invocation, variant); return; } -- cgit v1.2.3 From 01603a653335b7f4f09120fc5e04f3273c36a8b5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 20:50:45 -0600 Subject: Change all the event handling to use GVariants --- libdbusmenu-glib/server.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 4fdd6f8..bd5c2ac 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -935,7 +935,7 @@ typedef struct _idle_event_t idle_event_t; struct _idle_event_t { DbusmenuMenuitem * mi; gchar * eventid; - GValue data; + GVariant * variant; guint timestamp; }; @@ -946,11 +946,11 @@ event_local_handler (gpointer user_data) { idle_event_t * data = (idle_event_t *)user_data; - dbusmenu_menuitem_handle_event(data->mi, data->eventid, &data->data, data->timestamp); + dbusmenu_menuitem_handle_event(data->mi, data->eventid, data->variant, data->timestamp); g_object_unref(data->mi); g_free(data->eventid); - g_value_unset(&data->data); + g_variant_unref(data->variant); g_free(data); return FALSE; } @@ -977,10 +977,7 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i g_object_ref(event_data->mi); event_data->eventid = g_strdup(g_variant_get_string(g_variant_get_child_value(params, 1), NULL)); event_data->timestamp = g_variant_get_uint32(g_variant_get_child_value(params, 3)); - - /* TODO: Need to figure out converting a variant to a value */ - g_value_init(&(event_data->data), G_TYPE_INT); - g_value_set_int(&(event_data->data), 0); + event_data->variant = g_variant_get_child_value(params, 2); g_timeout_add(0, event_local_handler, event_data); -- cgit v1.2.3 From 050ca49a1179f4c04d6c175e8005e8516fd80654 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 21:07:51 -0600 Subject: Variants in sending over the server connection --- libdbusmenu-glib/server.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index bd5c2ac..1005e1b 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -141,7 +141,7 @@ static GVariant * bus_get_prop (GDBusConnection * connection, gpointer user_data); static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, - GValue * value, + GVariant * variant, DbusmenuServer * server); static void menuitem_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, @@ -619,21 +619,13 @@ layout_update_signal (DbusmenuServer * server) } static void -menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server) +menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GVariant * variant, DbusmenuServer * server) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - g_signal_emit(G_OBJECT(server), signals[ID_PROP_UPDATE], 0, dbusmenu_menuitem_get_id(mi), property, value, TRUE); + g_signal_emit(G_OBJECT(server), signals[ID_PROP_UPDATE], 0, dbusmenu_menuitem_get_id(mi), property, variant, TRUE); if (priv->dbusobject != NULL && priv->bus != NULL) { - GValue variantval = {0}; - g_value_init(&variantval, G_TYPE_VARIANT); - - if (!g_value_transform(value, &variantval)) { - g_warning("Unable to convert property '%s' of type %s to a variant", property, G_VALUE_TYPE_NAME(value)); - } - GVariant * variant = g_value_get_variant(&variantval); - g_dbus_connection_emit_signal(priv->bus, NULL, priv->dbusobject, @@ -641,8 +633,6 @@ menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * val "ItemPropertyUpdated", g_variant_new("(isv)", dbusmenu_menuitem_get_id(mi), property, variant), NULL); - - g_value_unset(&variantval); } return; } -- cgit v1.2.3 From 0dea1bb0779b8cddbf631ee80f76d13aa8920ec5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 21:11:40 -0600 Subject: Fixing our signals and marshallers for them as well --- libdbusmenu-glib/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 1005e1b..8d5c558 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -216,8 +216,8 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(DbusmenuServerClass, id_prop_update), NULL, NULL, - _dbusmenu_server_marshal_VOID__INT_STRING_POINTER, - G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_VALUE); + _dbusmenu_server_marshal_VOID__INT_STRING_VARIANT, + G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_VARIANT); /** DbusmenuServer::id-update: @arg0: The #DbusmenuServer emitting the signal. -- cgit v1.2.3 From acf4557c9c5b7d87c5b7b0f1df2b535a6dd11671 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 18 Nov 2010 09:22:24 -0600 Subject: Wow, I've learned a lot about better ways to do this :) --- libdbusmenu-glib/server.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 8d5c558..fd507a2 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -852,21 +852,21 @@ static void bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - GVariantIter * ids = NULL; - g_variant_get_child(params, 0, "ai", &ids); + GVariantIter ids; + g_variant_iter_init(&ids, params); - GVariantBuilder * builder = g_variant_builder_new(G_VARIANT_TYPE("a(ia{sv})")); + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ia{sv})")); - GVariant * id; - while ((id = g_variant_iter_next_value(ids)) != NULL) { - DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, g_variant_get_int32(id)); + guint id; + while (g_variant_iter_next(&ids, "i", &id)) { + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) continue; - g_variant_builder_add(builder, "ia{sv}", g_variant_get_int32(id), dbusmenu_menuitem_properties_variant(mi)); + g_variant_builder_add(&builder, "ia{sv}", id, dbusmenu_menuitem_properties_variant(mi)); } - GVariant * ret = g_variant_builder_end(builder); - g_variant_builder_unref(builder); + GVariant * ret = g_variant_builder_end(&builder); g_dbus_method_invocation_return_value(invocation, ret); -- cgit v1.2.3 From 9ef52be8a4da1fc981e09079e142d2aea9793567 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 18 Nov 2010 13:49:27 -0600 Subject: Setting up the proper builders and interfaces for group_properties --- libdbusmenu-glib/server.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index fd507a2..b48b28a 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -851,25 +851,43 @@ bus_get_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvoc static void bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { + g_debug("Begin group prop: %s", g_variant_print(params, TRUE)); DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); GVariantIter ids; - g_variant_iter_init(&ids, params); + g_variant_iter_init(&ids, g_variant_get_child_value(params, 0)); GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ia{sv})")); + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); - guint id; + gint id; while (g_variant_iter_next(&ids, "i", &id)) { DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) continue; - g_variant_builder_add(&builder, "ia{sv}", id, dbusmenu_menuitem_properties_variant(mi)); + GVariantBuilder wbuilder; + g_variant_builder_init(&wbuilder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add(&wbuilder, "i", id); + GVariant * props = dbusmenu_menuitem_properties_variant(mi); + + if (props == NULL) { + props = g_variant_parse(g_variant_type_new("a{sv}"), "{}", NULL, NULL, NULL); + } + + g_variant_builder_add_value(&wbuilder, props); + GVariant * mi_data = g_variant_builder_end(&wbuilder); + + g_variant_builder_add_value(&builder, mi_data); } GVariant * ret = g_variant_builder_end(&builder); - g_dbus_method_invocation_return_value(invocation, ret); + g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value(&builder, ret); + GVariant * final = g_variant_builder_end(&builder); + g_dbus_method_invocation_return_value(invocation, final); + + g_debug("End group prop"); return; } @@ -907,13 +925,17 @@ bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat return; } - GVariantBuilder * builder = g_variant_builder_new(G_VARIANT_TYPE("a(ia{sv})")); - GList * children = dbusmenu_menuitem_get_children(mi); - g_list_foreach(children, serialize_menuitem, builder); + GVariant * ret = NULL; + + if (children != NULL) { + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); - GVariant * ret = g_variant_builder_end(builder); - g_variant_builder_unref(builder); + g_list_foreach(children, serialize_menuitem, &builder); + + ret = g_variant_builder_end(&builder); + } g_dbus_method_invocation_return_value(invocation, ret); return; -- cgit v1.2.3 From 9cae52b3bfcb2b86c6be362ddb03afb2ddd78e6d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 18 Nov 2010 13:52:46 -0600 Subject: Oops, drop debug messages --- libdbusmenu-glib/server.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index b48b28a..d9a3c64 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -851,7 +851,6 @@ bus_get_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvoc static void bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { - g_debug("Begin group prop: %s", g_variant_print(params, TRUE)); DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); GVariantIter ids; g_variant_iter_init(&ids, g_variant_get_child_value(params, 0)); @@ -887,7 +886,6 @@ bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMetho g_dbus_method_invocation_return_value(invocation, final); - g_debug("End group prop"); return; } -- cgit v1.2.3 From a3482b774239b10010fd9d9734333afc09c1beb8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 18 Nov 2010 16:47:30 -0600 Subject: Protecting the invalid root a little bit more and returning a better error. --- libdbusmenu-glib/server.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index d9a3c64..c738537 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -83,6 +83,7 @@ enum { INVALID_PROPERTY_NAME, UNKNOWN_DBUS_ERROR, NOT_IMPLEMENTED, + NO_VALID_LAYOUT, LAST_ERROR }; @@ -756,7 +757,11 @@ bus_get_layout (DbusmenuServer * server, GVariant * params, GDBusMethodInvocatio dbusmenu_menuitem_buildxml(priv->root, xmlarray); } } else { - DbusmenuMenuitem * item = dbusmenu_menuitem_find_id(priv->root, parent); + DbusmenuMenuitem * item = NULL; + if (priv->root != NULL) { + item = dbusmenu_menuitem_find_id(priv->root, parent); + } + if (item == NULL) { g_dbus_method_invocation_return_error(invocation, error_quark(), @@ -790,6 +795,14 @@ static void bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + if (priv->root == NULL) { + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); const gchar * property = g_variant_get_string(g_variant_get_child_value(params, 1), NULL); @@ -826,6 +839,14 @@ bus_get_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvoc { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + if (priv->root == NULL) { + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); @@ -852,6 +873,22 @@ static void bus_get_group_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + if (priv->root == NULL) { + GVariant * idlist = g_variant_get_child_value(params, 0); + if (g_variant_n_children(idlist) == 1 && g_variant_get_int32(g_variant_get_child_value(idlist, 0)) == 0) { + GVariant * final = g_variant_parse(g_variant_type_new("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, NULL); + g_dbus_method_invocation_return_value(invocation, final); + return; + } + + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } + GVariantIter ids; g_variant_iter_init(&ids, g_variant_get_child_value(params, 0)); @@ -912,6 +949,15 @@ bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); + + if (priv->root == NULL) { + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { @@ -970,6 +1016,15 @@ static void bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + if (priv->root == NULL) { + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); @@ -1000,6 +1055,15 @@ static void bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + if (priv->root == NULL) { + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } + gint id = g_variant_get_int32(g_variant_get_child_value(params, 0)); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); -- cgit v1.2.3 From de467d6d1231f6490b79ddc5a4966b9521fe8536 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 13:40:07 -0600 Subject: Wrong signal name --- libdbusmenu-glib/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index c738537..a2e0849 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -694,7 +694,7 @@ menuitem_shown (DbusmenuMenuitem * mi, guint timestamp, DbusmenuServer * server) NULL, priv->dbusobject, DBUSMENU_INTERFACE, - "ItemPropertyUpdated", + "ItemActivationRequested", g_variant_new("(iu)", dbusmenu_menuitem_get_id(mi), timestamp), NULL); } -- cgit v1.2.3 From 7a12cdc4cff4546e911bd49fd38b6fed9511d506 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:19:31 -0600 Subject: Fixing the return values from AboutToShow --- libdbusmenu-glib/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index a2e0849..4202299 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1078,7 +1078,7 @@ bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvoca /* GTK+ does not support about-to-show concept for now */ g_dbus_method_invocation_return_value(invocation, - g_variant_new_boolean(FALSE)); + g_variant_new("(b)", FALSE)); return; } -- cgit v1.2.3 From d3c6ef0dd116d888e3415b2566d7bf14cb6ee0b7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:19:52 -0600 Subject: Ensuring all returns are protected by tuples for GDBus --- libdbusmenu-glib/server.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 4202299..8a10715 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -551,6 +551,7 @@ bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar return dbusmenu_method_table[i].func(DBUSMENU_SERVER(user_data), params, invocation); } else { /* If we have a null function we're responding but nothing else. */ + g_warning("Invalid function call for '%s' with parameters: %s", method, g_variant_print(params, TRUE)); g_dbus_method_invocation_return_value(invocation, NULL); return; } @@ -829,7 +830,7 @@ bus_get_property (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat return; } - g_dbus_method_invocation_return_value(invocation, variant); + g_dbus_method_invocation_return_value(invocation, g_variant_new("(v)", variant)); return; } @@ -862,7 +863,7 @@ bus_get_properties (DbusmenuServer * server, GVariant * params, GDBusMethodInvoc GVariant * dict = dbusmenu_menuitem_properties_variant(mi); - g_dbus_method_invocation_return_value(invocation, dict); + g_dbus_method_invocation_return_value(invocation, g_variant_new("(a{sv})", dict)); return; } @@ -978,7 +979,9 @@ bus_get_children (DbusmenuServer * server, GVariant * params, GDBusMethodInvocat g_list_foreach(children, serialize_menuitem, &builder); - ret = g_variant_builder_end(&builder); + ret = g_variant_new("(a(ia{svg}))", g_variant_builder_end(&builder)); + } else { + ret = g_variant_parse(g_variant_type_new("(a(ia{sv}))"), "([(0, {})],)", NULL, NULL, NULL); } g_dbus_method_invocation_return_value(invocation, ret); -- cgit v1.2.3 From 84969770f06f78f92f8e587c779e148d1d240f99 Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Mon, 13 Dec 2010 13:45:05 +0000 Subject: * Hook in AboutToShow to the menu items --- libdbusmenu-glib/server.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 8a10715..d1d82bd 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1079,6 +1079,8 @@ bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvoca return; } + dbusmenu_menuitem_send_about_to_show(mi, NULL, NULL); + /* GTK+ does not support about-to-show concept for now */ g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", FALSE)); -- cgit v1.2.3 From a8b425c5868c73739f60997ebc2013df3b3d6d4b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 13 Jan 2011 09:53:15 -0600 Subject: Ayatana purge --- libdbusmenu-glib/server.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index d1d82bd..373cc05 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -41,7 +41,7 @@ License version 3 and version 2.1 along with this program. If not, see static void layout_update_signal (DbusmenuServer * server); #define DBUSMENU_VERSION_NUMBER 2 -#define DBUSMENU_INTERFACE "org.ayatana.dbusmenu" +#define DBUSMENU_INTERFACE "com.canonical.dbusmenu" /* Privates, I'll show you mine... */ struct _DbusmenuServerPrivate @@ -273,7 +273,7 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) g_object_class_install_property (object_class, PROP_DBUS_OBJECT, g_param_spec_string(DBUSMENU_SERVER_PROP_DBUS_OBJECT, "DBus object path", "The object that represents this set of menus on DBus", - "/org/ayatana/dbusmenu", + "/com/canonical/dbusmenu", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ROOT_NODE, g_param_spec_object(DBUSMENU_SERVER_PROP_ROOT_NODE, "Root menu node", @@ -1095,7 +1095,7 @@ bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvoca Creates a new #DbusmenuServer object with a specific object path on DBus. If @object is set to NULL the default object - name of "/org/ayatana/dbusmenu" will be used. + name of "/com/canonical/dbusmenu" will be used. Return value: A brand new #DbusmenuServer */ @@ -1103,7 +1103,7 @@ DbusmenuServer * dbusmenu_server_new (const gchar * object) { if (object == NULL) { - object = "/org/ayatana/dbusmenu"; + object = "/com/canonical/dbusmenu"; } DbusmenuServer * self = g_object_new(DBUSMENU_TYPE_SERVER, -- cgit v1.2.3