Back to index

dbus-test-runner  12.10.0
test-libdbustest-getname.c
Go to the documentation of this file.
00001 
00002 #include <glib.h>
00003 #include <gio/gio.h>
00004 
00005 GMainLoop * mainloop = NULL;
00006 gboolean error = FALSE;
00007 
00008 void
00009 name_acquired (GDBusConnection * connection, const gchar * name, gpointer user_data)
00010 {
00011        g_main_loop_quit(mainloop);
00012        return;
00013 }
00014 
00015 void
00016 name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data)
00017 {
00018        g_warning("Name lost!");
00019        error = TRUE;
00020        g_main_loop_quit(mainloop);
00021        return;
00022 }
00023 
00024 int
00025 main (int argc, gchar * argv[])
00026 {
00027        if (argc != 2) {
00028               g_critical("Need a name");
00029               return -1;
00030        }
00031 
00032        g_type_init();
00033 
00034        guint name = g_bus_own_name(G_BUS_TYPE_SESSION,
00035                                    argv[1], /* name */
00036                                    G_BUS_NAME_OWNER_FLAGS_NONE, /* flags */
00037                                    NULL, /* bus acquired */
00038                                    name_acquired, /* name acquired */
00039                                    name_lost, /* name lost */
00040                                    NULL, /* user data */
00041                                    NULL /* ud free */
00042                                    );
00043 
00044        mainloop = g_main_loop_new(NULL, FALSE);
00045        g_main_loop_run(mainloop);
00046 
00047        g_bus_unown_name(name);
00048 
00049        if (error) {
00050               return -1;
00051        } else {
00052               return 0;
00053        }
00054 }