summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-04-17 17:34:30 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-04-17 17:34:30 +0200
commit9ad1e9f834085b034262f9724400bcb52b55b70c (patch)
tree23f1e8df1fd843310a1052eb120012eaec142816
parent6e6a4f7f612c14fa0188eab6fc6e2906b717540b (diff)
Added some comments for clarification
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-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)
void
application_run(MESSENGER_Application *app)
{
+ // Start thread to run GNUnet scheduler
pthread_create(&(app->chat.tid), NULL, _application_chat_thread, app);
app->ui.status = g_application_run(
@@ -265,6 +266,7 @@ application_run(MESSENGER_Application *app)
if (app->ui.status != 0)
application_exit(app, MESSENGER_FAIL);
+ // Wait for other thread to stop properly
pthread_join(app->chat.tid, NULL);
close(app->chat.pipe[0]);
@@ -272,6 +274,7 @@ application_run(MESSENGER_Application *app)
pthread_mutex_destroy(&(app->chat.mutex));
+ // Get rid of open notifications
GList *list = app->notifications;
while (list) {
@@ -304,6 +307,7 @@ _application_event_call(gpointer user_data)
call = (MESSENGER_ApplicationEventCall*) user_data;
+ // Locking the mutex for synchronization
pthread_mutex_lock(&(call->app->chat.mutex));
call->event(call->app);
pthread_mutex_unlock(&(call->app->chat.mutex));
@@ -344,6 +348,7 @@ _application_message_event_call(gpointer user_data)
call = (MESSENGER_ApplicationMessageEventCall*) user_data;
+ // Locking the mutex for synchronization
pthread_mutex_lock(&(call->app->chat.mutex));
call->event(call->app, call->context, call->message);
pthread_mutex_unlock(&(call->app->chat.mutex));
@@ -380,6 +385,8 @@ void
application_exit(MESSENGER_Application *app,
MESSENGER_ApplicationSignal signal)
{
+ // Forward a signal to the other thread causing it to shutdown the
+ // GNUnet handles of the application.
write(app->chat.pipe[1], &signal, sizeof(signal));
}
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)
if (received < 0)
signal = MESSENGER_FAIL;
+ // Free contact infos
GNUNET_CHAT_iterate_contacts(
app->chat.messenger.handle,
_chat_messenger_destroy_contacts,
@@ -68,6 +69,8 @@ _chat_messenger_idle(void *cls)
{
MESSENGER_Application *app = (MESSENGER_Application*) cls;
+ // Idling until the application shuts down
+ // (required to get events immediately).
app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
GNUNET_TIME_relative_get_second_(),
GNUNET_SCHEDULER_PRIORITY_IDLE,
@@ -82,8 +85,11 @@ _chat_messenger_message(void *cls,
const struct GNUNET_CHAT_Message *message)
{
MESSENGER_Application *app = (MESSENGER_Application*) cls;
+
+ // Locking the mutex for synchronization
pthread_mutex_lock(&(app->chat.mutex));
+ // Handle each kind of message as proper event regarding context
switch (GNUNET_CHAT_message_get_kind(message))
{
case GNUNET_CHAT_KIND_WARNING:
@@ -186,12 +192,14 @@ chat_messenger_run(void *cls,
{
MESSENGER_Application *app = (MESSENGER_Application*) cls;
+ // Start libgnunetchat handle
app->chat.messenger.handle = GNUNET_CHAT_start(
cfg,
&_chat_messenger_message,
app
);
+ // Setup pipe to handle closing the application from the other thread
struct GNUNET_NETWORK_FDSet *fd = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set_native(fd, app->chat.pipe[0]);
@@ -204,6 +212,8 @@ chat_messenger_run(void *cls,
app
);
+ // The idle callback seems to be necessary to not wait too long for
+ // other events
app->chat.messenger.idle = GNUNET_SCHEDULER_add_now(
&_chat_messenger_idle,
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)
{
MESSENGER_Application *app = (MESSENGER_Application*) user_data;
+ // Refresh the account list
ui_messenger_refresh(app, &(app->ui.messenger));
gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window));
@@ -64,6 +65,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
{
MESSENGER_Application *app = (MESSENGER_Application*) user_data;
+ // Drop activations of rows which do not contain accounts
if (!gtk_list_box_row_get_selectable(row))
{
app->ui.accounts.show_queued = g_idle_add(
@@ -80,6 +82,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
if (!account)
goto close_dialog;
+ // Handle the GUI swap asyncronously
if (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))
app->ui.accounts.show_queued = g_idle_add(
G_SOURCE_FUNC(_show_messenger_main_window), app