aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/daemon/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/daemon/daemon.c')
-rw-r--r--src/plugins/daemon/daemon.c75
1 files changed, 50 insertions, 25 deletions
diff --git a/src/plugins/daemon/daemon.c b/src/plugins/daemon/daemon.c
index 1c3b4538..0cab7e52 100644
--- a/src/plugins/daemon/daemon.c
+++ b/src/plugins/daemon/daemon.c
@@ -47,21 +47,38 @@ static struct GNUNET_GE_Context *ectx;
47static struct GNUNET_GC_Configuration *cfg; 47static struct GNUNET_GC_Configuration *cfg;
48 48
49/** 49/**
50 * Do the actual update (in event thread).
51 */
52static void *
53updateAppModelSafe (void *arg)
54{
55 GtkWidget *w;
56 GtkListStore *model = arg;
57
58 w =
59 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
60 "applicationList");
61 gtk_tree_view_set_model (GTK_TREE_VIEW (w), GTK_TREE_MODEL (model));
62 gtk_tree_selection_set_mode (gtk_tree_view_get_selection
63 (GTK_TREE_VIEW (w)), GTK_SELECTION_NONE);
64 return NULL;
65}
66
67/**
50 * cron job that periodically updates the model for the 68 * cron job that periodically updates the model for the
51 * application list. 69 * application list.
52 */ 70 */
53static void * 71static void
54updateAppModelSafe (void *unused) 72updateAppModel (void *dummy)
55{ 73{
56 struct GNUNET_ClientServerConnection *sock; 74 struct GNUNET_ClientServerConnection *sock;
57 GtkWidget *w;
58 GtkListStore *model;
59 GtkTreeIter iter; 75 GtkTreeIter iter;
60 char *apps; 76 char *apps;
61 char *next; 77 char *next;
62 char *pos; 78 char *pos;
63 char *desc; 79 char *desc;
64 80 GtkListStore *model;
81
65 model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); 82 model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
66 apps = NULL; 83 apps = NULL;
67 sock = GNUNET_client_connection_create (ectx, cfg); 84 sock = GNUNET_client_connection_create (ectx, cfg);
@@ -102,21 +119,9 @@ updateAppModelSafe (void *unused)
102 while (next != NULL); 119 while (next != NULL);
103 GNUNET_free (apps); 120 GNUNET_free (apps);
104 } 121 }
105 w =
106 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
107 "applicationList");
108 gtk_tree_view_set_model (GTK_TREE_VIEW (w), GTK_TREE_MODEL (model));
109 gtk_tree_selection_set_mode (gtk_tree_view_get_selection
110 (GTK_TREE_VIEW (w)), GTK_SELECTION_NONE);
111 g_object_unref (model);
112 GNUNET_client_connection_destroy (sock); 122 GNUNET_client_connection_destroy (sock);
113 return NULL; 123 GNUNET_GTK_save_call (&updateAppModelSafe, model);
114} 124 g_object_unref (model);
115
116static void
117updateAppModel (void *dummy)
118{
119 GNUNET_GTK_save_call (&updateAppModelSafe, NULL);
120} 125}
121 126
122 127
@@ -166,7 +171,6 @@ doUpdateMenus (void *arg)
166 isLocal = FALSE; 171 isLocal = FALSE;
167 GNUNET_free (host); 172 GNUNET_free (host);
168 } 173 }
169 updateAppModelSafe (NULL);
170 if (ret == 0) 174 if (ret == 0)
171 { 175 {
172 canStart = 0; 176 canStart = 0;
@@ -238,15 +242,24 @@ doUpdateMenus (void *arg)
238 return NULL; 242 return NULL;
239} 243}
240 244
245/**
246 * Cron job that checks if the daemon is running.
247 */
241static void 248static void
242cronCheckDaemon (void *dummy) 249cronCheckDaemon (void *dummy)
243{ 250{
251 static int last = -1;
244 int ret; 252 int ret;
245 253
246 if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg)) 254 if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg))
247 ret = 1; 255 ret = 1;
248 else 256 else
249 ret = 0; 257 ret = 0;
258 if (last != ret)
259 {
260 updateAppModel(NULL);
261 last = ret;
262 }
250 GNUNET_GTK_save_call (&doUpdateMenus, &ret); 263 GNUNET_GTK_save_call (&doUpdateMenus, &ret);
251} 264}
252 265
@@ -269,7 +282,10 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
269 gtk_widget_set_sensitive (launchEntry, FALSE); 282 gtk_widget_set_sensitive (launchEntry, FALSE);
270 if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg)) 283 if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg))
271 { 284 {
272 cronCheckDaemon (NULL); 285 GNUNET_cron_advance_job(GNUNET_GTK_get_cron_manager (),
286 &cronCheckDaemon,
287 15 * GNUNET_CRON_SECONDS,
288 NULL);
273 return; 289 return;
274 } 290 }
275 else 291 else
@@ -309,7 +325,10 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
309 GNUNET_GTK_add_log_entry (_("Launched gnunetd\n")); 325 GNUNET_GTK_add_log_entry (_("Launched gnunetd\n"));
310 } 326 }
311 g_free (fn); 327 g_free (fn);
312 cronCheckDaemon (NULL); 328 GNUNET_cron_advance_job(GNUNET_GTK_get_cron_manager (),
329 &cronCheckDaemon,
330 15 * GNUNET_CRON_SECONDS,
331 NULL);
313 return; 332 return;
314 } 333 }
315 else 334 else
@@ -329,7 +348,10 @@ on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
329 } 348 }
330 if (fn != NULL) 349 if (fn != NULL)
331 g_free (fn); 350 g_free (fn);
332 cronCheckDaemon (NULL); 351 GNUNET_cron_advance_job(GNUNET_GTK_get_cron_manager (),
352 &cronCheckDaemon,
353 15 * GNUNET_CRON_SECONDS,
354 NULL);
333 } 355 }
334} 356}
335 357
@@ -368,7 +390,10 @@ on_stopDaemon_clicked_daemon (GtkWidget * widget, gpointer data)
368 } 390 }
369 GNUNET_client_connection_destroy (sock); 391 GNUNET_client_connection_destroy (sock);
370 } 392 }
371 cronCheckDaemon (NULL); 393 GNUNET_cron_advance_job(GNUNET_GTK_get_cron_manager (),
394 &cronCheckDaemon,
395 15 * GNUNET_CRON_SECONDS,
396 NULL);
372} 397}
373 398
374void 399void
@@ -449,7 +474,7 @@ init_daemon (struct GNUNET_GE_Context *e, struct GNUNET_GC_Configuration *c)
449 GNUNET_free (daemon_config); 474 GNUNET_free (daemon_config);
450 475
451 cron = GNUNET_GTK_get_cron_manager (); 476 cron = GNUNET_GTK_get_cron_manager ();
452 GNUNET_cron_add_job (cron, &cronCheckDaemon, 0, 15 * GNUNET_CRON_SECONDS, 477 GNUNET_cron_add_job (cron, &cronCheckDaemon, 2 * GNUNET_CRON_SECONDS, 15 * GNUNET_CRON_SECONDS,
453 NULL); 478 NULL);
454 GNUNET_cron_add_job (cron, &updateAppModel, 5 * GNUNET_CRON_MINUTES, 479 GNUNET_cron_add_job (cron, &updateAppModel, 5 * GNUNET_CRON_MINUTES,
455 5 * GNUNET_CRON_MINUTES, NULL); 480 5 * GNUNET_CRON_MINUTES, NULL);