aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/application.c7
-rw-r--r--src/chat/messenger.c10
-rw-r--r--src/ui/accounts.c3
3 files changed, 20 insertions, 0 deletions
diff --git a/src/application.c b/src/application.c
index 1ae2f88..67bfc82 100644
--- a/src/application.c
+++ b/src/application.c
@@ -254,6 +254,7 @@ _application_chat_thread(void *args)
254void 254void
255application_run(MESSENGER_Application *app) 255application_run(MESSENGER_Application *app)
256{ 256{
257 // Start thread to run GNUnet scheduler
257 pthread_create(&(app->chat.tid), NULL, _application_chat_thread, app); 258 pthread_create(&(app->chat.tid), NULL, _application_chat_thread, app);
258 259
259 app->ui.status = g_application_run( 260 app->ui.status = g_application_run(
@@ -265,6 +266,7 @@ application_run(MESSENGER_Application *app)
265 if (app->ui.status != 0) 266 if (app->ui.status != 0)
266 application_exit(app, MESSENGER_FAIL); 267 application_exit(app, MESSENGER_FAIL);
267 268
269 // Wait for other thread to stop properly
268 pthread_join(app->chat.tid, NULL); 270 pthread_join(app->chat.tid, NULL);
269 271
270 close(app->chat.pipe[0]); 272 close(app->chat.pipe[0]);
@@ -272,6 +274,7 @@ application_run(MESSENGER_Application *app)
272 274
273 pthread_mutex_destroy(&(app->chat.mutex)); 275 pthread_mutex_destroy(&(app->chat.mutex));
274 276
277 // Get rid of open notifications
275 GList *list = app->notifications; 278 GList *list = app->notifications;
276 279
277 while (list) { 280 while (list) {
@@ -304,6 +307,7 @@ _application_event_call(gpointer user_data)
304 307
305 call = (MESSENGER_ApplicationEventCall*) user_data; 308 call = (MESSENGER_ApplicationEventCall*) user_data;
306 309
310 // Locking the mutex for synchronization
307 pthread_mutex_lock(&(call->app->chat.mutex)); 311 pthread_mutex_lock(&(call->app->chat.mutex));
308 call->event(call->app); 312 call->event(call->app);
309 pthread_mutex_unlock(&(call->app->chat.mutex)); 313 pthread_mutex_unlock(&(call->app->chat.mutex));
@@ -344,6 +348,7 @@ _application_message_event_call(gpointer user_data)
344 348
345 call = (MESSENGER_ApplicationMessageEventCall*) user_data; 349 call = (MESSENGER_ApplicationMessageEventCall*) user_data;
346 350
351 // Locking the mutex for synchronization
347 pthread_mutex_lock(&(call->app->chat.mutex)); 352 pthread_mutex_lock(&(call->app->chat.mutex));
348 call->event(call->app, call->context, call->message); 353 call->event(call->app, call->context, call->message);
349 pthread_mutex_unlock(&(call->app->chat.mutex)); 354 pthread_mutex_unlock(&(call->app->chat.mutex));
@@ -380,6 +385,8 @@ void
380application_exit(MESSENGER_Application *app, 385application_exit(MESSENGER_Application *app,
381 MESSENGER_ApplicationSignal signal) 386 MESSENGER_ApplicationSignal signal)
382{ 387{
388 // Forward a signal to the other thread causing it to shutdown the
389 // GNUnet handles of the application.
383 write(app->chat.pipe[1], &signal, sizeof(signal)); 390 write(app->chat.pipe[1], &signal, sizeof(signal));
384} 391}
385 392
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
index 6164674..0015f25 100644
--- a/src/chat/messenger.c
+++ b/src/chat/messenger.c
@@ -51,6 +51,7 @@ _chat_messenger_quit(void *cls)
51 if (received < 0) 51 if (received < 0)
52 signal = MESSENGER_FAIL; 52 signal = MESSENGER_FAIL;
53 53
54 // Free contact infos
54 GNUNET_CHAT_iterate_contacts( 55 GNUNET_CHAT_iterate_contacts(
55 app->chat.messenger.handle, 56 app->chat.messenger.handle,
56 _chat_messenger_destroy_contacts, 57 _chat_messenger_destroy_contacts,
@@ -68,6 +69,8 @@ _chat_messenger_idle(void *cls)
68{ 69{
69 MESSENGER_Application *app = (MESSENGER_Application*) cls; 70 MESSENGER_Application *app = (MESSENGER_Application*) cls;
70 71
72 // Idling until the application shuts down
73 // (required to get events immediately).
71 app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority( 74 app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
72 GNUNET_TIME_relative_get_second_(), 75 GNUNET_TIME_relative_get_second_(),
73 GNUNET_SCHEDULER_PRIORITY_IDLE, 76 GNUNET_SCHEDULER_PRIORITY_IDLE,
@@ -82,8 +85,11 @@ _chat_messenger_message(void *cls,
82 const struct GNUNET_CHAT_Message *message) 85 const struct GNUNET_CHAT_Message *message)
83{ 86{
84 MESSENGER_Application *app = (MESSENGER_Application*) cls; 87 MESSENGER_Application *app = (MESSENGER_Application*) cls;
88
89 // Locking the mutex for synchronization
85 pthread_mutex_lock(&(app->chat.mutex)); 90 pthread_mutex_lock(&(app->chat.mutex));
86 91
92 // Handle each kind of message as proper event regarding context
87 switch (GNUNET_CHAT_message_get_kind(message)) 93 switch (GNUNET_CHAT_message_get_kind(message))
88 { 94 {
89 case GNUNET_CHAT_KIND_WARNING: 95 case GNUNET_CHAT_KIND_WARNING:
@@ -186,12 +192,14 @@ chat_messenger_run(void *cls,
186{ 192{
187 MESSENGER_Application *app = (MESSENGER_Application*) cls; 193 MESSENGER_Application *app = (MESSENGER_Application*) cls;
188 194
195 // Start libgnunetchat handle
189 app->chat.messenger.handle = GNUNET_CHAT_start( 196 app->chat.messenger.handle = GNUNET_CHAT_start(
190 cfg, 197 cfg,
191 &_chat_messenger_message, 198 &_chat_messenger_message,
192 app 199 app
193 ); 200 );
194 201
202 // Setup pipe to handle closing the application from the other thread
195 struct GNUNET_NETWORK_FDSet *fd = GNUNET_NETWORK_fdset_create (); 203 struct GNUNET_NETWORK_FDSet *fd = GNUNET_NETWORK_fdset_create ();
196 GNUNET_NETWORK_fdset_set_native(fd, app->chat.pipe[0]); 204 GNUNET_NETWORK_fdset_set_native(fd, app->chat.pipe[0]);
197 205
@@ -204,6 +212,8 @@ chat_messenger_run(void *cls,
204 app 212 app
205 ); 213 );
206 214
215 // The idle callback seems to be necessary to not wait too long for
216 // other events
207 app->chat.messenger.idle = GNUNET_SCHEDULER_add_now( 217 app->chat.messenger.idle = GNUNET_SCHEDULER_add_now(
208 &_chat_messenger_idle, 218 &_chat_messenger_idle,
209 app 219 app
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
index 16cd621..8acc438 100644
--- a/src/ui/accounts.c
+++ b/src/ui/accounts.c
@@ -51,6 +51,7 @@ _show_messenger_main_window(gpointer user_data)
51{ 51{
52 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 52 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
53 53
54 // Refresh the account list
54 ui_messenger_refresh(app, &(app->ui.messenger)); 55 ui_messenger_refresh(app, &(app->ui.messenger));
55 56
56 gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); 57 gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window));
@@ -64,6 +65,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
64{ 65{
65 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 66 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
66 67
68 // Drop activations of rows which do not contain accounts
67 if (!gtk_list_box_row_get_selectable(row)) 69 if (!gtk_list_box_row_get_selectable(row))
68 { 70 {
69 app->ui.accounts.show_queued = g_idle_add( 71 app->ui.accounts.show_queued = g_idle_add(
@@ -80,6 +82,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
80 if (!account) 82 if (!account)
81 goto close_dialog; 83 goto close_dialog;
82 84
85 // Handle the GUI swap asyncronously
83 if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window))) 86 if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))
84 app->ui.accounts.show_queued = g_idle_add( 87 app->ui.accounts.show_queued = g_idle_add(
85 G_SOURCE_FUNC(_show_messenger_main_window), app 88 G_SOURCE_FUNC(_show_messenger_main_window), app