From 640ca88481512912c62bc59c4d5d74adc8d73853 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 23 Oct 2011 03:52:16 +0300 Subject: [PATCH] Implement JS delay workaround. #187 yoshimi-0.060.10 jack session implementation is broken. Save complete reply is sent from the jack session callback but the actual save is made asynchronously, in the main thread, on next main loop iteration. This changeset implements workaround for app bugs like this. User is able to set JS delay in seconds. Default is zero. --- daemon/conf.h | 4 ++- daemon/jack_session.c | 16 +++++++++++ daemon/main.c | 5 ++++ gui/gladish.ui | 29 ++++++++++++++++++- gui/main.c | 7 ++++- gui/settings.c | 18 ++++++++++-- proxies/conf_proxy.c | 66 +++++++++++++++++++++++++++++++++++++++++++ proxies/conf_proxy.h | 5 +++- 8 files changed, 144 insertions(+), 6 deletions(-) diff --git a/daemon/conf.h b/daemon/conf.h index 3d59fd02..5af073ee 100644 --- a/daemon/conf.h +++ b/daemon/conf.h @@ -2,7 +2,7 @@ /* * LADI Session Handler (ladish) * - * Copyright (C) 2010 Nedko Arnaudov + * Copyright (C) 2010,2011 Nedko Arnaudov * ************************************************************************** * This file contains defines for conf keys @@ -31,10 +31,12 @@ #define LADISH_CONF_KEY_DAEMON_SHELL "/org/ladish/daemon/shell" #define LADISH_CONF_KEY_DAEMON_TERMINAL "/org/ladish/daemon/terminal" #define LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART "/org/ladish/daemon/studio_autostart" +#define LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY "/org/ladish/daemon/js_save_delay" #define LADISH_CONF_KEY_DAEMON_NOTIFY_DEFAULT true #define LADISH_CONF_KEY_DAEMON_SHELL_DEFAULT "sh" #define LADISH_CONF_KEY_DAEMON_TERMINAL_DEFAULT "xterm" #define LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART_DEFAULT true +#define LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY_DEFAULT 0 #endif /* #ifndef CONF_H__795797BE_4EB8_44F8_BD9C_B8A9CB975228__INCLUDED */ diff --git a/daemon/jack_session.c b/daemon/jack_session.c index eef50551..d25a3599 100644 --- a/daemon/jack_session.c +++ b/daemon/jack_session.c @@ -30,6 +30,8 @@ #include "../common/catdup.h" #include "studio.h" #include "../proxies/jack_proxy.h" +#include "../proxies/conf_proxy.h" +#include "conf.h" struct ladish_js_find_app_client_context { @@ -143,12 +145,26 @@ struct ladish_js_save_app_context void ladish_js_save_app_complete(void * context, const char * commandline) { int iret; + unsigned int delay; if (commandline == NULL) { goto call; } + log_info("JS app save complete. commandline='%s'", commandline); + + if (!conf_get_uint(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, &delay)) + { + delay = LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY_DEFAULT; + } + + if (delay > 0) + { + log_info("sleeping for %u seconds...", delay); + sleep(delay); + } + iret = rename(ctx_ptr->client_dir, ctx_ptr->target_dir); if (iret != 0) { diff --git a/daemon/main.c b/daemon/main.c index 66ddc529..67ddc8f7 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -356,6 +356,11 @@ int main(int argc, char ** argv, char ** envp) goto uninit_conf; } + if (!conf_register(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, NULL, NULL)) + { + goto uninit_conf; + } + if (!ladish_recent_projects_init()) { goto uninit_conf; diff --git a/gui/gladish.ui b/gui/gladish.ui index d74acfcf..543ceb1c 100644 --- a/gui/gladish.ui +++ b/gui/gladish.ui @@ -1741,7 +1741,7 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, 5 2 - 2 + 3 5 True @@ -1786,6 +1786,33 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, 1 + + + JS delay (seconds): + True + 0 + + + 3 + 2 + + + + + True + + True + 0 + True + True + + + 3 + 1 + 2 + 2 + + 1 diff --git a/gui/main.c b/gui/main.c index db543ea7..58ab8de4 100644 --- a/gui/main.c +++ b/gui/main.c @@ -2,7 +2,7 @@ /* * LADI Session Handler (ladish) * - * Copyright (C) 2008, 2009, 2010 Nedko Arnaudov + * Copyright (C) 2008,2009,2010,2011 Nedko Arnaudov * ************************************************************************** * This file contains the code that implements main() and other top-level functionality @@ -161,6 +161,11 @@ int main(int argc, char** argv) return 1; } + if (!conf_register(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, NULL, NULL)) + { + return 1; + } + if (!init_jack()) { return 1; diff --git a/gui/settings.c b/gui/settings.c index b494d810..6ded1153 100644 --- a/gui/settings.c +++ b/gui/settings.c @@ -2,7 +2,7 @@ /* * LADI Session Handler (ladish) * - * Copyright (C) 2010 Nedko Arnaudov + * Copyright (C) 2010,2011 Nedko Arnaudov * ************************************************************************** * This file contains implementation of the settings dialog @@ -37,15 +37,18 @@ void menu_request_settings(void) GtkToggleButton * send_notifications_button; GtkEntry * shell_entry; GtkEntry * terminal_entry; + GtkSpinButton * js_delay_spin; bool autostart; bool notify; const char * shell; const char * terminal; + unsigned int js_delay; autostart_studio_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("settings_studio_autostart_checkbutton")); send_notifications_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("settings_send_notifications_checkbutton")); shell_entry = GTK_ENTRY(get_gtk_builder_widget("settings_shell_entry")); terminal_entry = GTK_ENTRY(get_gtk_builder_widget("settings_terminal_entry")); + js_delay_spin = GTK_SPIN_BUTTON(get_gtk_builder_widget("settings_js_delay_spin")); dialog = GTK_DIALOG(get_gtk_builder_widget("settings_dialog")); @@ -69,12 +72,21 @@ void menu_request_settings(void) terminal = LADISH_CONF_KEY_DAEMON_TERMINAL_DEFAULT; } + if (!conf_get_uint(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, &js_delay)) + { + js_delay = LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY_DEFAULT; + } + gtk_toggle_button_set_active(autostart_studio_button, autostart); gtk_toggle_button_set_active(send_notifications_button, notify); gtk_entry_set_text(shell_entry, shell); gtk_entry_set_text(terminal_entry, terminal); + gtk_spin_button_set_range(js_delay_spin, 0, 1000); + gtk_spin_button_set_increments(js_delay_spin, 1, 2); + gtk_spin_button_set_value(js_delay_spin, js_delay); + gtk_widget_show(GTK_WIDGET(dialog)); result = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(GTK_WIDGET(dialog)); @@ -87,11 +99,13 @@ void menu_request_settings(void) notify = gtk_toggle_button_get_active(send_notifications_button); shell = gtk_entry_get_text(shell_entry); terminal = gtk_entry_get_text(terminal_entry); + js_delay = gtk_spin_button_get_value(js_delay_spin); if (!conf_set_bool(LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART, autostart) || !conf_set_bool(LADISH_CONF_KEY_DAEMON_NOTIFY, notify) || !conf_set(LADISH_CONF_KEY_DAEMON_SHELL, shell) || - !conf_set(LADISH_CONF_KEY_DAEMON_TERMINAL, terminal)) + !conf_set(LADISH_CONF_KEY_DAEMON_TERMINAL, terminal) || + !conf_set_uint(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, js_delay)) { error_message_box(_("Storing settings")); } diff --git a/proxies/conf_proxy.c b/proxies/conf_proxy.c index 32a5498b..0546d16a 100644 --- a/proxies/conf_proxy.c +++ b/proxies/conf_proxy.c @@ -354,3 +354,69 @@ bool conf_get_bool(const char * key, bool * value_ptr) return true; } + +/* UINT_MAX is 10 chars + terminating nul */ +#define UINT_STRING_MAX_SIZE 11 + +static const char * conf_uint2string(unsigned int value, char * string) +{ + char * ptr; + + ptr = string + (UINT_STRING_MAX_SIZE - 1); + *ptr = 0; + + do + { + ASSERT(ptr > string); /* UINT_STRING_MAX_SIZE is too small? */ + ptr--; + *ptr = '0' + value % 10; + value /= 10; + } + while (value > 0); + + return ptr; +} + +static bool conf_string2uint(const char * string, unsigned int * value_ptr) +{ + unsigned int value; + + value = 0; + + do + { + if (*string < '0' || *string > '9') + { + return false; + } + + value *= 10; + value += *string - '0'; + + string++; + } + while (*string != 0); + + *value_ptr = value; + + return true; +} + +bool conf_set_uint(const char * key, unsigned int value) +{ + char buffer[UINT_STRING_MAX_SIZE]; + + return conf_set(key, conf_uint2string(value, buffer)); +} + +bool conf_get_uint(const char * key, unsigned int * value_ptr) +{ + const char * str; + + if (!conf_get(key, &str)) + { + return false; + } + + return conf_string2uint(str, value_ptr); +} diff --git a/proxies/conf_proxy.h b/proxies/conf_proxy.h index a2c65d48..89bf75ff 100644 --- a/proxies/conf_proxy.h +++ b/proxies/conf_proxy.h @@ -2,7 +2,7 @@ /* * LADI Session Handler (ladish) * - * Copyright (C) 2010 Nedko Arnaudov + * Copyright (C) 2010,2011 Nedko Arnaudov * ************************************************************************** * This file contains interface to code that interfaces ladiconfd through D-Bus @@ -47,4 +47,7 @@ const char * conf_bool2string(bool value); bool conf_set_bool(const char * key, bool value); bool conf_get_bool(const char * key, bool * value_ptr); +bool conf_set_uint(const char * key, unsigned int value); +bool conf_get_uint(const char * key, unsigned int * value_ptr); + #endif /* #ifndef CONF_PROXY_H__D45503B2_D49C_46BF_86F7_9A531B819B6B__INCLUDED */