Back to index

dbus-test-runner  12.10.0
test-own-name.c
Go to the documentation of this file.
00001 #include <glib.h>
00002 #include <gio/gio.h>
00003 
00004 void
00005 name_aquired (GDBusConnection * connection, const gchar * name, gpointer user_data)
00006 {
00007        g_debug("Got name: %s", name);
00008        return;
00009 }
00010 
00011 gboolean
00012 end_of_line (gpointer user_data)
00013 {
00014        g_main_loop_quit((GMainLoop *)user_data);
00015        return FALSE;
00016 }
00017 
00018 int
00019 main (int argc, char * argv[])
00020 {
00021        g_type_init();
00022 
00023        if (argc != 2) {
00024               g_error("ARG, need a single argument");
00025               return 1;
00026        }
00027 
00028        g_debug("Trying for name: %s", argv[1]);
00029 
00030        g_bus_own_name(G_BUS_TYPE_SESSION,
00031                       argv[1],
00032                       G_BUS_NAME_OWNER_FLAGS_NONE,
00033                       NULL, /* bus aquired */
00034                       name_aquired,
00035                       NULL, /* lost */
00036                       NULL, /* data */
00037                       NULL); /* destroy */
00038 
00039        GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
00040 
00041        g_timeout_add_seconds(2, end_of_line, mainloop);
00042 
00043        g_main_loop_run(mainloop);
00044        g_main_loop_unref(mainloop);
00045 
00046        g_debug("Quitting");
00047 
00048        return 0;
00049 }