Back to index

libindicate  12.10.0
test-max-indicators-server-repeat.c
Go to the documentation of this file.
00001 
00002 #include <glib.h>
00003 #include "libindicate/listener.h"
00004 #include "test-max-indicators-list.h"
00005 
00006 gint repeat_list[MAX_INDICATOR_COUNT] = { 2, 3, 1, 4, 2, 3, 1, 20 };
00007 
00008 static gboolean passed = TRUE;
00009 static GMainLoop * mainloop = NULL;
00010 
00011 static guint count = 0;
00012 static guint repeat = 0;
00013 
00014 static IndicateListener * l = NULL;
00015 static IndicateListenerServer * s = NULL;
00016 
00017 gboolean
00018 set_max (gpointer userdata)
00019 {
00020        g_debug("Setting max indicators to: %d", max_indicator_list[count]);
00021        indicate_listener_set_server_max_indicators(l, s, max_indicator_list[count]);
00022        if (repeat == repeat_list[count]) {
00023               count++;
00024               repeat = 0;
00025        } else {
00026               repeat++;
00027        }
00028 
00029        if (count >= MAX_INDICATOR_COUNT) {
00030               return FALSE;
00031        } else {
00032               return TRUE;
00033        }
00034 }
00035 
00036 static void
00037 server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
00038 {
00039        g_debug("Indicator Server Added:   %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type);
00040 
00041        if (l != NULL || s != NULL) {
00042               g_warning("Adding a second server?  %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server));
00043               return;
00044        }
00045 
00046        l = listener;
00047        s = server;
00048 
00049        g_timeout_add(100, set_max, NULL);
00050 
00051        return;
00052 }
00053 
00054 static gboolean
00055 failed_cb (gpointer data)
00056 {
00057        g_debug("Done indicatating max indicators");
00058        g_main_loop_quit(mainloop);
00059        return FALSE;
00060 }
00061 
00062 int
00063 main (int argc, char * argv)
00064 {
00065        g_type_init();
00066 
00067        IndicateListener * listener = indicate_listener_ref_default();
00068 
00069        g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL);
00070 
00071        guint i, repeat_sum = 0;
00072        for (i = 0; i < MAX_INDICATOR_COUNT; i++) {
00073               repeat_sum += repeat_list[i];
00074        }
00075 
00076        if (repeat_sum / MAX_INDICATOR_COUNT > 9) {
00077               g_warning("Risk of client timeout.");
00078        }
00079 
00080        g_timeout_add((MAX_INDICATOR_COUNT + 4 + repeat_sum) * 100, failed_cb, NULL);
00081 
00082        mainloop = g_main_loop_new(NULL, FALSE);
00083        g_main_loop_run(mainloop);
00084 
00085        return !passed;
00086 }