commit 7b73be58476929b49f3e6859c552d1dc1f33aba1
parent ceeb88257a9c2c8461654509c006757eaed248c4
Author: Jacki <jacki@thejackimonster.de>
Date: Sun, 21 Jul 2024 02:33:03 +0200
Sync calls to GNUnet chat api inside of GTK callbacks
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
19 files changed, 254 insertions(+), 24 deletions(-)
diff --git a/src/event.c b/src/event.c
@@ -469,6 +469,8 @@ _delayed_context_drop(gpointer user_data)
struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) user_data;
+ // TODO: schedule_sync_lock(&(app->chat.schedule));
+
struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group(context);
struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_context_get_contact(context);
@@ -477,6 +479,8 @@ _delayed_context_drop(gpointer user_data)
else if (contact)
GNUNET_CHAT_contact_delete(contact);
+ // TODO: schedule_sync_unlock(&(app->chat.schedule));
+
return FALSE;
}
diff --git a/src/schedule.c b/src/schedule.c
@@ -25,6 +25,8 @@
#include "schedule.h"
#include <glib-2.0/glib-unix.h>
+#include <glib-2.0/glib.h>
+#include <pthread.h>
void
schedule_init(MESSENGER_Schedule *schedule)
@@ -34,6 +36,43 @@ schedule_init(MESSENGER_Schedule *schedule)
g_assert(0 == pipe(schedule->push_pipe));
g_assert(0 == pipe(schedule->sync_pipe));
+
+ pthread_mutex_init(&(schedule->push_mutex), NULL);
+ pthread_mutex_init(&(schedule->sync_mutex), NULL);
+}
+
+static gboolean
+__schedule_pushed_handling(MESSENGER_Schedule *schedule,
+ MESSENGER_ScheduleSignal val)
+{
+ g_assert(schedule);
+
+ gboolean keep;
+
+ switch (val)
+ {
+ case MESSENGER_SCHEDULE_SIGNAL_RUN:
+ g_assert(schedule->function);
+
+ keep = schedule->function(schedule->data);
+
+ schedule->function = NULL;
+ schedule->data = NULL;
+ break;
+ case MESSENGER_SCHEDULE_SIGNAL_LOCK:
+ g_assert(!(schedule->function));
+
+ keep = TRUE;
+
+ pthread_mutex_unlock(&(schedule->push_mutex));
+ pthread_mutex_lock(&(schedule->sync_mutex));
+ pthread_mutex_unlock(&(schedule->sync_mutex));
+ break;
+ default:
+ return FALSE;
+ }
+
+ return keep;
}
static void
@@ -43,20 +82,14 @@ static void
__schedule_pushed_task(void *cls)
{
MESSENGER_Schedule *schedule = cls;
- gboolean keep;
- char val;
+ MESSENGER_ScheduleSignal val;
g_assert(schedule);
schedule->task = NULL;
g_assert(sizeof(val) == read(schedule->push_pipe[0], &val, sizeof(val)));
- keep = schedule->function(schedule->data);
-
- schedule->function = NULL;
- schedule->data = NULL;
-
- if (keep)
+ if (__schedule_pushed_handling(schedule, val))
__schedule_setup_push_task(schedule);
g_assert(sizeof(val) == write(schedule->sync_pipe[1], &val, sizeof(val)));
@@ -93,9 +126,9 @@ __schedule_pushed(gint fd,
gpointer user_data)
{
MESSENGER_Schedule *schedule = user_data;
+ MESSENGER_ScheduleSignal val;
gboolean keep;
guint task;
- char val;
g_assert(schedule);
task = schedule->poll;
@@ -103,10 +136,7 @@ __schedule_pushed(gint fd,
g_assert(sizeof(val) == read(schedule->push_pipe[0], &val, sizeof(val)));
- keep = schedule->function(schedule->data);
-
- schedule->function = NULL;
- schedule->data = NULL;
+ keep = __schedule_pushed_handling(schedule, val);
if (keep)
schedule->poll = task;
@@ -137,6 +167,9 @@ schedule_cleanup(MESSENGER_Schedule *schedule)
if (schedule->poll)
g_source_remove(schedule->poll);
+ pthread_mutex_destroy(&(schedule->push_mutex));
+ pthread_mutex_destroy(&(schedule->sync_mutex));
+
close(schedule->push_pipe[0]);
close(schedule->push_pipe[1]);
@@ -156,10 +189,39 @@ schedule_sync_run(MESSENGER_Schedule *schedule,
schedule->function = function;
schedule->data = data;
- const char push = 1;
- char sync;
+ const MESSENGER_ScheduleSignal push = MESSENGER_SCHEDULE_SIGNAL_RUN;
+ MESSENGER_ScheduleSignal sync;
g_assert(sizeof(push) == write(schedule->push_pipe[1], &push, sizeof(push)));
g_assert(sizeof(sync) == read(schedule->sync_pipe[0], &sync, sizeof(sync)));
g_assert(push == sync);
}
+
+void
+schedule_sync_lock(MESSENGER_Schedule *schedule)
+{
+ g_assert(schedule);
+
+ const MESSENGER_ScheduleSignal push = MESSENGER_SCHEDULE_SIGNAL_LOCK;
+
+ pthread_mutex_lock(&(schedule->push_mutex));
+ pthread_mutex_lock(&(schedule->sync_mutex));
+
+ g_assert(sizeof(push) == write(schedule->push_pipe[1], &push, sizeof(push)));
+
+ pthread_mutex_lock(&(schedule->push_mutex));
+ pthread_mutex_unlock(&(schedule->push_mutex));
+}
+
+void
+schedule_sync_unlock(MESSENGER_Schedule *schedule)
+{
+ g_assert(schedule);
+
+ MESSENGER_ScheduleSignal sync;
+
+ pthread_mutex_unlock(&(schedule->sync_mutex));
+
+ g_assert(sizeof(sync) == read(schedule->sync_pipe[0], &sync, sizeof(sync)));
+ g_assert(MESSENGER_SCHEDULE_SIGNAL_LOCK == sync);
+}
diff --git a/src/schedule.h b/src/schedule.h
@@ -27,11 +27,20 @@
#include <glib-2.0/glib.h>
#include <gnunet/gnunet_util_lib.h>
+#include <pthread.h>
+
+typedef enum MESSENGER_ScheduleSignal : unsigned char {
+ MESSENGER_SCHEDULE_SIGNAL_RUN = 1,
+ MESSENGER_SCHEDULE_SIGNAL_LOCK = 2,
+} MESSENGER_ScheduleSignal;
typedef struct MESSENGER_Schedule {
int push_pipe [2];
int sync_pipe [2];
+ pthread_mutex_t push_mutex;
+ pthread_mutex_t sync_mutex;
+
GSourceFunc function;
gpointer data;
@@ -56,4 +65,10 @@ schedule_sync_run(MESSENGER_Schedule *schedule,
GSourceFunc function,
gpointer data);
+void
+schedule_sync_lock(MESSENGER_Schedule *schedule);
+
+void
+schedule_sync_unlock(MESSENGER_Schedule *schedule);
+
#endif /* SCHEDULE_H_ */
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
@@ -95,8 +95,10 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
app->ui.accounts.show_queued = util_idle_add(
G_SOURCE_FUNC(_show_messenger_main_window), app
);
-
+
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_connect(app->chat.messenger.handle, account);
+ schedule_sync_unlock(&(app->chat.schedule));
gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox);
gtk_widget_set_sensitive(GTK_WIDGET(app->ui.accounts.dialog), FALSE);
diff --git a/src/ui/chat.c b/src/ui/chat.c
@@ -165,9 +165,13 @@ handle_chat_contacts_listbox_row_activated(GtkListBox *listbox,
hdy_flap_set_reveal_flap(handle->flap_chat_details, FALSE);
+ schedule_sync_lock(&(app->chat.schedule));
+
ui_contact_info_dialog_init(app, &(app->ui.contact_info));
ui_contact_info_dialog_update(&(app->ui.contact_info), contact, FALSE);
+ schedule_sync_unlock(&(app->chat.schedule));
+
gtk_widget_show(GTK_WIDGET(app->ui.contact_info.dialog));
}
@@ -214,9 +218,13 @@ handle_reveal_identity_button_click(GtkButton *button,
hdy_flap_set_reveal_flap(handle->flap_chat_details, FALSE);
+ schedule_sync_lock(&(app->chat.schedule));
+
ui_contact_info_dialog_init(app, &(app->ui.contact_info));
ui_contact_info_dialog_update(&(app->ui.contact_info), contact, TRUE);
+ schedule_sync_unlock(&(app->chat.schedule));
+
gtk_widget_show(GTK_WIDGET(app->ui.contact_info.dialog));
}
@@ -252,7 +260,9 @@ handle_block_button_click(UNUSED GtkButton *button,
if (!contact)
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_contact_set_blocked(contact, GNUNET_YES);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
gtk_stack_set_visible_child(handle->block_stack, GTK_WIDGET(handle->unblock_button));
}
@@ -272,7 +282,9 @@ handle_unblock_button_click(UNUSED GtkButton *button,
if (!contact)
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_contact_set_blocked(contact, GNUNET_NO);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
gtk_stack_set_visible_child(handle->block_stack, GTK_WIDGET(handle->block_button));
}
@@ -288,6 +300,8 @@ handle_leave_chat_button_click(UNUSED GtkButton *button,
if ((!handle) || (!(handle->context)))
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
+
struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_context_get_contact(
handle->context
);
@@ -301,6 +315,8 @@ handle_leave_chat_button_click(UNUSED GtkButton *button,
else if (group)
GNUNET_CHAT_group_leave(group);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(
handle->context
);
@@ -422,12 +438,16 @@ handle_chat_messages_filter(GtkListBoxRow *row,
filterTags.filter = &(filter[1]);
filterTags.matching = FALSE;
+ schedule_sync_lock(&(app->chat.schedule));
+
GNUNET_CHAT_message_iterate_tags(
message->msg,
_iterate_message_tags,
&filterTags
);
+ schedule_sync_unlock(&(app->chat.schedule));
+
result |= filterTags.matching;
}
@@ -589,7 +609,11 @@ _send_text_from_view(MESSENGER_Application *app,
}
if (handle->context)
+ {
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_context_send_text(handle->context, text);
+ schedule_sync_unlock(&(app->chat.schedule));
+ }
g_free(text);
gtk_text_buffer_delete(buffer, &start, &end);
@@ -664,6 +688,8 @@ handle_send_record_button_click(GtkButton *button,
ui_label_set_text(file_load->file_label, handle->recording_filename);
gtk_progress_bar_set_fraction(file_load->load_progress_bar, 0.0);
+ schedule_sync_lock(&(app->chat.schedule));
+
struct GNUNET_CHAT_File *file = GNUNET_CHAT_context_send_file(
handle->context,
handle->recording_filename,
@@ -680,6 +706,8 @@ handle_send_record_button_click(GtkButton *button,
else if (file_load)
ui_file_load_entry_delete(file_load);
+ schedule_sync_unlock(&(app->chat.schedule));
+
_drop_any_recording(handle);
return;
}
diff --git a/src/ui/chat_title.c b/src/ui/chat_title.c
@@ -131,12 +131,16 @@ _new_tag_callback(MESSENGER_Application *app,
if ((!message) || (!(message->msg)))
goto skip_row;
+ schedule_sync_lock(&(app->chat.schedule));
+
GNUNET_CHAT_context_send_tag(
handle->context,
message->msg,
tag
);
+ schedule_sync_unlock(&(app->chat.schedule));
+
skip_row:
selected = selected->next;
}
@@ -193,6 +197,8 @@ _delete_messages_callback(MESSENGER_Application *app,
if ((!message) || (!(message->msg)))
goto skip_row;
+ schedule_sync_lock(&(app->chat.schedule));
+
GNUNET_CHAT_message_delete(
message->msg,
GNUNET_TIME_relative_multiply(
@@ -201,6 +207,8 @@ _delete_messages_callback(MESSENGER_Application *app,
)
);
+ schedule_sync_unlock(&(app->chat.schedule));
+
skip_row:
selected = selected->next;
}
diff --git a/src/ui/contact_info.c b/src/ui/contact_info.c
@@ -62,6 +62,8 @@ handle_contact_edit_button_click(UNUSED GtkButton *button,
if ((name) && (0 == g_utf8_strlen(name, 1)))
name = NULL;
+ schedule_sync_lock(&(handle->app->chat.schedule));
+
if (change_own_name)
{
if (GNUNET_YES != GNUNET_CHAT_set_name(handle->app->chat.messenger.handle, name))
@@ -73,6 +75,8 @@ handle_contact_edit_button_click(UNUSED GtkButton *button,
else
GNUNET_CHAT_contact_set_name(handle->contact, name);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
skip_change_name:
gtk_image_set_from_icon_name(
handle->contact_edit_symbol,
@@ -188,6 +192,8 @@ handle_profile_chooser_file_set(GtkFileChooserButton *button,
if (!filename)
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
+
GNUNET_CHAT_upload_file(
handle->app->chat.messenger.handle,
filename,
@@ -195,6 +201,8 @@ handle_profile_chooser_file_set(GtkFileChooserButton *button,
handle->app
);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
g_free(filename);
}
@@ -256,7 +264,9 @@ handle_block_button_click(UNUSED GtkButton *button,
if (!(handle->contact))
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_contact_set_blocked(handle->contact, GNUNET_YES);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
gtk_stack_set_visible_child(
handle->block_stack,
@@ -275,7 +285,9 @@ handle_unblock_button_click(UNUSED GtkButton *button,
if (!(handle->contact))
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_contact_set_blocked(handle->contact, GNUNET_NO);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
gtk_stack_set_visible_child(
handle->block_stack,
@@ -671,8 +683,11 @@ handle_value_renderer_edit(GtkCellRendererText *renderer,
if (!chat)
return;
- if ((handle->contact) &&
- (GNUNET_YES != GNUNET_CHAT_contact_is_owned(handle->contact)))
+ schedule_sync_lock(&(handle->app->chat.schedule));
+ const gboolean owned = (GNUNET_YES == GNUNET_CHAT_contact_is_owned(handle->contact));
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
+ if ((handle->contact) && (!owned))
return;
GValue value = G_VALUE_INIT;
@@ -682,12 +697,18 @@ handle_value_renderer_edit(GtkCellRendererText *renderer,
if ((new_text) && (strlen(new_text)))
{
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_set_attribute(chat, name, new_text, GNUNET_TIME_relative_get_forever_());
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
gtk_list_store_set(handle->attributes_list, &iter, 1, new_text, -1);
}
else
{
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_delete_attribute(chat, name);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
gtk_list_store_remove(handle->attributes_list, &iter);
}
@@ -726,7 +747,10 @@ handle_add_attribute_button_click(UNUSED GtkButton *button,
if ((name) && (value))
{
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_set_attribute(chat, name, value, GNUNET_TIME_relative_get_forever_());
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
gtk_list_store_insert_with_values(
handle->attributes_list,
NULL,
@@ -772,8 +796,11 @@ handle_share_renderer_toggle(GtkCellRendererToggle *renderer,
if (!chat)
return;
- if ((!(handle->contact)) ||
- (GNUNET_YES == GNUNET_CHAT_contact_is_owned(handle->contact)))
+ schedule_sync_lock(&(handle->app->chat.schedule));
+ const gboolean owned = (GNUNET_YES == GNUNET_CHAT_contact_is_owned(handle->contact));
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
+ if ((!(handle->contact)) || (owned))
return;
GValue value_name = G_VALUE_INIT;
@@ -785,11 +812,15 @@ handle_share_renderer_toggle(GtkCellRendererToggle *renderer,
const gchar *name = g_value_get_string(&value_name);
const gboolean shared = g_value_get_boolean(&value_shared);
+ schedule_sync_lock(&(handle->app->chat.schedule));
+
if (shared)
GNUNET_CHAT_unshare_attribute_from(chat, handle->contact, name);
else
GNUNET_CHAT_share_attribute_with(chat, handle->contact, name);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
+
gtk_list_store_set(handle->sharing_list, &iter, 2, !shared, -1);
g_value_unset(&value_name);
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
@@ -70,19 +70,32 @@ handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox,
g_object_get_qdata(G_OBJECT(row), app->quarks.data)
);
- if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) ||
- (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)))
+ if (!contact)
goto close_dialog;
+ schedule_sync_lock(&(app->chat.schedule));
+ const gboolean closing = (
+ (!GNUNET_CHAT_contact_get_key(contact)) ||
+ (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact))
+ );
+ schedule_sync_unlock(&(app->chat.schedule));
+
+ if (closing)
+ goto close_dialog;
+
+ schedule_sync_lock(&(app->chat.schedule));
struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context(
contact
);
+ schedule_sync_unlock(&(app->chat.schedule));
if (!context)
goto close_dialog;
+ schedule_sync_lock(&(app->chat.schedule));
if (GNUNET_SYSERR == GNUNET_CHAT_context_get_status(context))
GNUNET_CHAT_context_request(context);
+ schedule_sync_unlock(&(app->chat.schedule));
close_dialog:
gtk_window_close(GTK_WINDOW(app->ui.contacts.dialog));
diff --git a/src/ui/discourse.c b/src/ui/discourse.c
@@ -169,11 +169,13 @@ handle_call_start_button_click(UNUSED GtkButton *button,
if (!(handle->context))
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
handle->voice_discourse = GNUNET_CHAT_context_open_discourse(
handle->context, get_voice_discourse_id()
);
_update_call_button(handle);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
}
static void
@@ -187,10 +189,12 @@ handle_call_stop_button_click(UNUSED GtkButton *button,
if ((!(handle->context)) || (!(handle->voice_discourse)))
return;
+ schedule_sync_lock(&(handle->app->chat.schedule));
GNUNET_CHAT_discourse_close(handle->voice_discourse);
handle->voice_discourse = NULL;
_update_call_button(handle);
+ schedule_sync_unlock(&(handle->app->chat.schedule));
}
static void
diff --git a/src/ui/files.c b/src/ui/files.c
@@ -70,6 +70,8 @@ handle_files_listbox_row_activated(UNUSED GtkListBox* listbox,
g_object_get_qdata(G_OBJECT(row), app->quarks.data)
);
+ schedule_sync_lock(&(app->chat.schedule));
+
const gdouble progress = (
(gdouble) GNUNET_CHAT_file_get_local_size(file) /
GNUNET_CHAT_file_get_size(file)
@@ -87,6 +89,8 @@ handle_files_listbox_row_activated(UNUSED GtkListBox* listbox,
GNUNET_YES != GNUNET_CHAT_file_is_ready(file)
);
+ schedule_sync_unlock(&(app->chat.schedule));
+
UI_FILE_ENTRY_Handle *entry = (UI_FILE_ENTRY_Handle*) (
g_object_get_qdata(G_OBJECT(row), app->quarks.ui)
);
diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c
@@ -55,6 +55,8 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox,
g_object_get_qdata(G_OBJECT(row), app->quarks.data)
);
+ schedule_sync_lock(&(app->chat.schedule));
+
if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) ||
(GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) ||
(!text_view))
@@ -75,6 +77,8 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox,
GNUNET_CHAT_group_invite_contact(group, contact);
close_dialog:
+ schedule_sync_unlock(&(app->chat.schedule));
+
gtk_window_close(GTK_WINDOW(app->ui.invite_contact.dialog));
}
diff --git a/src/ui/message.c b/src/ui/message.c
@@ -72,16 +72,25 @@ handle_file_button_click(GtkButton *button,
if (!file)
return;
+ schedule_sync_lock(&(app->chat.schedule));
uint64_t size = GNUNET_CHAT_file_get_size(file);
+ schedule_sync_unlock(&(app->chat.schedule));
if (size <= 0)
return;
+ schedule_sync_lock(&(app->chat.schedule));
+
uint64_t local_size = GNUNET_CHAT_file_get_local_size(file);
+ const gboolean downloading = (GNUNET_YES == GNUNET_CHAT_file_is_downloading(file));
+
+ schedule_sync_unlock(&(app->chat.schedule));
- if (GNUNET_YES == GNUNET_CHAT_file_is_downloading(file))
+ if (downloading)
{
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_file_stop_download(file);
+ schedule_sync_unlock(&(app->chat.schedule));
gtk_image_set_from_icon_name(
handle->file_status_image,
@@ -91,11 +100,13 @@ handle_file_button_click(GtkButton *button,
}
else if (local_size < size)
{
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_file_start_download(
file,
handle_downloading_file,
app
);
+ schedule_sync_unlock(&(app->chat.schedule));
gtk_image_set_from_icon_name(
handle->file_status_image,
@@ -105,7 +116,9 @@ handle_file_button_click(GtkButton *button,
}
else if (size > 0)
{
+ schedule_sync_lock(&(app->chat.schedule));
const gchar *preview = GNUNET_CHAT_file_open_preview(file);
+ schedule_sync_unlock(&(app->chat.schedule));
if (!preview)
return;
@@ -114,7 +127,11 @@ handle_file_button_click(GtkButton *button,
g_string_append(uri, preview);
if (!g_app_info_launch_default_for_uri(uri->str, NULL, NULL))
+ {
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_file_close_preview(file);
+ schedule_sync_unlock(&(app->chat.schedule));
+ }
g_string_free(uri, TRUE);
}
@@ -142,7 +159,9 @@ handle_media_button_click(GtkButton *button,
if (!file)
return;
+ schedule_sync_lock(&(app->chat.schedule));
const gchar *preview = GNUNET_CHAT_file_open_preview(file);
+ schedule_sync_unlock(&(app->chat.schedule));
if (!preview)
return;
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
@@ -212,17 +212,23 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
if (!account)
return;
+ schedule_sync_lock(&(app->chat.schedule));
+
const struct GNUNET_CHAT_Account *current = GNUNET_CHAT_get_connected(
app->chat.messenger.handle
);
+ schedule_sync_unlock(&(app->chat.schedule));
+
if (account == current)
return;
_switch_details_revealer_visibility(&(app->ui.messenger), FALSE);
hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE);
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_connect(app->chat.messenger.handle, account);
+ schedule_sync_unlock(&(app->chat.schedule));
}
static void
diff --git a/src/ui/new_account.c b/src/ui/new_account.c
@@ -37,7 +37,15 @@ _open_new_account(GtkEntry *entry,
const gchar *name = gtk_entry_get_text(entry);
- if (GNUNET_OK != GNUNET_CHAT_account_create(app->chat.messenger.handle, name))
+ schedule_sync_lock(&(app->chat.schedule));
+
+ const enum GNUNET_GenericReturnValue result = GNUNET_CHAT_account_create(
+ app->chat.messenger.handle, name
+ );
+
+ schedule_sync_unlock(&(app->chat.schedule));
+
+ if (GNUNET_OK != result)
return;
gtk_list_box_unselect_all(app->ui.messenger.accounts_listbox);
diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c
@@ -66,9 +66,13 @@ handle_confirm_button_click(UNUSED GtkButton *button,
if (!uri)
goto close_dialog;
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_lobby_join(app->chat.messenger.handle, uri);
+ schedule_sync_unlock(&(app->chat.schedule));
+
GNUNET_CHAT_uri_destroy(uri);
+
close_dialog:
gtk_window_close(GTK_WINDOW(app->ui.new_contact.dialog));
}
diff --git a/src/ui/new_group.c b/src/ui/new_group.c
@@ -37,6 +37,8 @@ _open_new_group(GtkEntry *entry,
const gchar *name = gtk_entry_get_text(entry);
+ schedule_sync_lock(&(app->chat.schedule));
+
struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create(
app->chat.messenger.handle,
NULL
@@ -45,6 +47,8 @@ _open_new_group(GtkEntry *entry,
if ((name) && (strlen(name) > 0))
GNUNET_CHAT_group_set_name(group, name);
+ schedule_sync_unlock(&(app->chat.schedule));
+
GList *selected = gtk_list_box_get_selected_rows(listbox);
GList *item = selected;
@@ -58,7 +62,9 @@ _open_new_group(GtkEntry *entry,
g_object_get_qdata(G_OBJECT(row), app->quarks.data)
);
+ schedule_sync_lock(&(app->chat.schedule));
GNUNET_CHAT_group_invite_contact(group, contact);
+ schedule_sync_unlock(&(app->chat.schedule));
}
item = item->next;
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c
@@ -37,6 +37,8 @@ _open_new_platform(GtkEntry *entry,
GString *topic_string = g_string_new(topic);
+ schedule_sync_lock(&(app->chat.schedule));
+
struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create(
app->chat.messenger.handle,
topic_string->str
@@ -45,6 +47,8 @@ _open_new_platform(GtkEntry *entry,
g_string_prepend_c(topic_string, '#');
GNUNET_CHAT_group_set_name(group, topic_string->str);
+ schedule_sync_unlock(&(app->chat.schedule));
+
g_string_free(topic_string, TRUE);
}
diff --git a/src/ui/send_file.c b/src/ui/send_file.c
@@ -102,12 +102,16 @@ handle_send_button_click(GtkButton *button,
gtk_label_set_text(file_load->file_label, filename);
gtk_progress_bar_set_fraction(file_load->load_progress_bar, 0.0);
+ schedule_sync_lock(&(app->chat.schedule));
+
file = GNUNET_CHAT_context_send_file(
context,
filename,
handle_sending_upload_file,
file_load
);
+
+ schedule_sync_unlock(&(app->chat.schedule));
}
g_free(filename);
diff --git a/src/ui/settings.c b/src/ui/settings.c
@@ -161,6 +161,8 @@ handle_leave_chats_button_click(UNUSED GtkButton* button,
MESSENGER_Application *app = (MESSENGER_Application*) user_data;
+ schedule_sync_lock(&(app->chat.schedule));
+
GNUNET_CHAT_iterate_groups(
app->chat.messenger.handle,
_leave_group_iteration,
@@ -172,6 +174,8 @@ handle_leave_chats_button_click(UNUSED GtkButton* button,
_delete_contact_iteration,
NULL
);
+
+ schedule_sync_unlock(&(app->chat.schedule));
}
static void