aboutsummaryrefslogtreecommitdiff
path: root/tests/test-json-server.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-11-16 22:04:47 -0600
committerTed Gould <ted@gould.cx>2010-11-16 22:04:47 -0600
commit1100e05ca534449b557a1f2993c405f01781bd72 (patch)
treecd05a0079f327e90beef1c8cece34bb6b81e6a04 /tests/test-json-server.c
parentf6108371c958c994b451d9c7c80f530bae4fd7c3 (diff)
downloadlibdbusmenu-1100e05ca534449b557a1f2993c405f01781bd72.tar.gz
libdbusmenu-1100e05ca534449b557a1f2993c405f01781bd72.tar.bz2
libdbusmenu-1100e05ca534449b557a1f2993c405f01781bd72.zip
Getting names the GDBus way
Diffstat (limited to 'tests/test-json-server.c')
-rw-r--r--tests/test-json-server.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/tests/test-json-server.c b/tests/test-json-server.c
index fe9507a..083de60 100644
--- a/tests/test-json-server.c
+++ b/tests/test-json-server.c
@@ -20,11 +20,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <gio/gio.h>
#include <libdbusmenu-glib/server.h>
#include <libdbusmenu-glib/menuitem.h>
@@ -40,38 +36,49 @@ timer_func (gpointer data)
return FALSE;
}
-int
-main (int argc, char ** argv)
+static void
+on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data)
{
- GError * error = NULL;
-
- g_type_init();
-
- 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(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
-
- 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, "org.dbusmenu.test", 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;
- }
+ gchar ** argv = (gchar **)user_data;
DbusmenuServer * server = dbusmenu_server_new("/org/test");
DbusmenuMenuitem * root = dbusmenu_json_build_from_file(argv[1]);
- g_return_val_if_fail(root!=NULL, 1);
+ if (root == NULL) {
+ g_warning("Unable to build root");
+ g_main_loop_quit(mainloop);
+ return;
+ }
dbusmenu_server_set_root(server, root);
g_timeout_add(10000, timer_func, NULL);
+ return;
+}
+
+static void
+name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data)
+{
+ g_error("Unable to get name '%s' on DBus", name);
+ g_main_loop_quit(mainloop);
+ return;
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ g_bus_own_name(G_BUS_TYPE_SESSION,
+ "org.dbusmenu.test",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus,
+ NULL,
+ name_lost,
+ argv,
+ NULL);
+
mainloop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(mainloop);