Back to index

libindicate  12.10.0
test-interests-client.c
Go to the documentation of this file.
00001 
00002 #include <glib.h>
00003 #include "libindicate/indicator.h"
00004 #include "libindicate/server.h"
00005 #include "libindicate/interests.h"
00006 
00007 static gboolean passed = TRUE;
00008 static GMainLoop * mainloop = NULL;
00009 static gboolean interests[INDICATE_INTEREST_LAST] = {0};
00010 
00011 static gboolean
00012 check_interests (void)
00013 {
00014        guint i;
00015        for (i = INDICATE_INTEREST_NONE + 1; i < INDICATE_INTEREST_LAST; i++) {
00016               if (!interests[i]) {
00017                      return FALSE;
00018               }
00019        }
00020 
00021        return TRUE;
00022 }
00023 
00024 static void
00025 interest_added (IndicateServer * server, IndicateInterests interest)
00026 {
00027        g_debug("Oh, someone is interested in my for: %d", interest);
00028        interests[interest] = TRUE;
00029 
00030        if (check_interests()) {
00031               g_main_loop_quit(mainloop);
00032        }
00033 
00034        return;
00035 }
00036 
00037 static gboolean
00038 done_timeout_cb (gpointer data)
00039 {
00040        g_debug("All interests not set");
00041        passed = FALSE;
00042        g_main_loop_quit(mainloop);
00043        return FALSE;
00044 }
00045 
00046 int
00047 main (int argc, char * argv)
00048 {
00049        g_type_init();
00050 
00051        IndicateIndicator * indicator = indicate_indicator_new();
00052        indicate_indicator_show(indicator);
00053 
00054        IndicateServer * server = indicate_server_ref_default();
00055        g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL);
00056 
00057        g_timeout_add_seconds(2, done_timeout_cb, indicator);
00058 
00059        mainloop = g_main_loop_new(NULL, FALSE);
00060        g_main_loop_run(mainloop);
00061 
00062        return !passed;
00063 }