diff options
author | Sebastien Bacher <seb128@ubuntu.com> | 2010-02-18 18:18:30 +0100 |
---|---|---|
committer | Sebastien Bacher <seb128@ubuntu.com> | 2010-02-18 18:18:30 +0100 |
commit | 0af5090188b1002d4cbca3e8a60b701153a8b391 (patch) | |
tree | 18ee6d3f99611b8cc84327c338525df62ee5d2d2 /tests/test-glib-proxy-proxy.c | |
parent | aadfece2677f23d685f050ec479aaee93c6ababc (diff) | |
parent | 4ee1fccc17c4734c356ee528dd3a0665f5e296f0 (diff) | |
download | libdbusmenu-0af5090188b1002d4cbca3e8a60b701153a8b391.tar.gz libdbusmenu-0af5090188b1002d4cbca3e8a60b701153a8b391.tar.bz2 libdbusmenu-0af5090188b1002d4cbca3e8a60b701153a8b391.zip |
releasing version 0.2.5-0ubuntu1
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; +} |