diff options
author | Ted Gould <ted@gould.cx> | 2010-02-18 10:53:38 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-02-18 10:53:38 -0600 |
commit | de00d014bce1def051bacc11abbd429c38acebfc (patch) | |
tree | 1d3cc7be1260d14d488934e002613e3d1003f4e1 /tests/test-glib-proxy-proxy.c | |
parent | c1ab2f992a08d7ab9a34db1c9b6fb1136e4af7e4 (diff) | |
parent | 1664971299f0495c531ac2c46a599ae52f4abe0d (diff) | |
download | libdbusmenu-de00d014bce1def051bacc11abbd429c38acebfc.tar.gz libdbusmenu-de00d014bce1def051bacc11abbd429c38acebfc.tar.bz2 libdbusmenu-de00d014bce1def051bacc11abbd429c38acebfc.zip |
* Upstream Merge
* Adding in menuitem proxy object.
Diffstat (limited to 'tests/test-glib-proxy-proxy.c')
-rw-r--r-- | tests/test-glib-proxy-proxy.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/test-glib-proxy-proxy.c b/tests/test-glib-proxy-proxy.c new file mode 100644 index 0000000..1059cfd --- /dev/null +++ b/tests/test-glib-proxy-proxy.c @@ -0,0 +1,80 @@ +#include <glib.h> + +#include <dbus/dbus.h> +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-lowlevel.h> +#include <dbus/dbus-glib-bindings.h> + +#include <libdbusmenu-glib/menuitem.h> +#include <libdbusmenu-glib/menuitem-proxy.h> +#include <libdbusmenu-glib/server.h> +#include <libdbusmenu-glib/client.h> + +#include "test-glib-proxy.h" + +static DbusmenuServer * server = NULL; +static DbusmenuClient * client = NULL; +static GMainLoop * mainloop = NULL; + +void +root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer user_data) +{ + g_debug("New root: %X", (guint)newroot); + + if (newroot == NULL) { + g_debug("Root removed, exiting"); + g_main_loop_quit(mainloop); + return; + } + + DbusmenuMenuitemProxy * pmi = dbusmenu_menuitem_proxy_new(newroot); + dbusmenu_server_set_root(server, DBUSMENU_MENUITEM(pmi)); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + if (argc != 3) { + g_error ("Need two params"); + return 1; + } + + gchar * whoami = argv[1]; + gchar * myproxy = argv[2]; + + g_debug("I am '%s' and I'm proxying '%s'", whoami, myproxy); + + GError * error = NULL; + 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(connection))); + + 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, whoami, 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"); + client = dbusmenu_client_new(myproxy, "/org/test"); + + g_signal_connect(client, DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(root_changed), server); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_object_unref(G_OBJECT(server)); + g_debug("Quiting"); + + return 0; +} |