Back to index

libindicate  12.10.0
test-simple-server.c
Go to the documentation of this file.
00001 
00002 #include <glib.h>
00003 #include "libindicate/listener.h"
00004 
00005 static gboolean passed = TRUE;
00006 static GMainLoop * mainloop = NULL;
00007 
00008 static void
00009 server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
00010 {
00011         g_debug("Indicator Server Added:   %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type);
00012         if (!g_strcmp0(type, "test.type")) {
00013                 if (!g_strcmp0(indicate_listener_server_get_dbuspath(server), "/com/tests/indicate/server")) {
00014                         g_main_loop_quit(mainloop);
00015               }
00016        }
00017 }
00018 
00019 static gboolean
00020 failed_cb (gpointer data)
00021 {
00022        g_debug("Failed to get a server in 5 seconds.");
00023        passed = FALSE;
00024        g_main_loop_quit(mainloop);
00025        return FALSE;
00026 }
00027 
00028 int
00029 main (int argc, char * argv)
00030 {
00031        g_type_init();
00032        // HACK: This just works around a bug
00033        indicate_server_ref_default ();
00034        
00035        IndicateListener * listener = indicate_listener_ref_default();
00036        IndicateServer * server = g_object_new (INDICATE_TYPE_SERVER, "path", "/com/tests/indicate/server", NULL);
00037        
00038        indicate_server_set_type(server, "test.type");
00039        
00040        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL);
00041 
00042        indicate_server_show (server);
00043 
00044 
00045        g_timeout_add_seconds(5, failed_cb, NULL);
00046 
00047        mainloop = g_main_loop_new(NULL, FALSE);
00048        g_main_loop_run(mainloop);
00049 
00050        return !passed;
00051 }