When a parameter is set, jackdbus used to save immediately. This was quite annoying and ineffective when configuring lot of parameters without delay. It caused log line to appear for each parameter set and xml file serialization as well. This changeset implements delayed save. Parameters are saved two seconds after last parameter set. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4583 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.8
@@ -27,6 +27,8 @@ | |||||
#include <dbus/dbus.h> | #include <dbus/dbus.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <sys/sysinfo.h> | |||||
#include <errno.h> | |||||
#include "controller.h" | #include "controller.h" | ||||
#include "controller_internal.h" | #include "controller_internal.h" | ||||
@@ -560,6 +562,8 @@ jack_controller_create( | |||||
controller_ptr->client = NULL; | controller_ptr->client = NULL; | ||||
controller_ptr->started = false; | controller_ptr->started = false; | ||||
controller_ptr->pending_save = 0; | |||||
INIT_LIST_HEAD(&controller_ptr->slave_drivers); | INIT_LIST_HEAD(&controller_ptr->slave_drivers); | ||||
controller_ptr->slave_drivers_set = false; | controller_ptr->slave_drivers_set = false; | ||||
controller_ptr->slave_drivers_vparam_value.str[0] = 0; | controller_ptr->slave_drivers_vparam_value.str[0] = 0; | ||||
@@ -776,3 +780,45 @@ jack_controller_destroy( | |||||
free(controller_ptr); | free(controller_ptr); | ||||
} | } | ||||
void | |||||
jack_controller_run( | |||||
void * context) | |||||
{ | |||||
struct sysinfo si; | |||||
if (controller_ptr->pending_save == 0) | |||||
{ | |||||
return; | |||||
} | |||||
if (sysinfo(&si) != 0) | |||||
{ | |||||
jack_error("sysinfo() failed with %d", errno); | |||||
} | |||||
else if (si.uptime < controller_ptr->pending_save + 2) /* delay save by two seconds */ | |||||
{ | |||||
return; | |||||
} | |||||
controller_ptr->pending_save = 0; | |||||
jack_controller_settings_save_auto(controller_ptr); | |||||
} | |||||
#undef controller_ptr | |||||
void | |||||
jack_controller_pending_save( | |||||
struct jack_controller * controller_ptr) | |||||
{ | |||||
struct sysinfo si; | |||||
if (sysinfo(&si) != 0) | |||||
{ | |||||
jack_error("sysinfo() failed with %d.", errno); | |||||
controller_ptr->pending_save = 0; | |||||
jack_controller_settings_save_auto(controller_ptr); | |||||
return; | |||||
} | |||||
controller_ptr->pending_save = si.uptime; | |||||
} |
@@ -24,6 +24,10 @@ void * | |||||
jack_controller_create( | jack_controller_create( | ||||
DBusConnection *connection); | DBusConnection *connection); | ||||
void | |||||
jack_controller_run( | |||||
void *controller_ptr); | |||||
void | void | ||||
jack_controller_destroy( | jack_controller_destroy( | ||||
void *controller_ptr); | void *controller_ptr); | ||||
@@ -903,7 +903,7 @@ jack_controller_dbus_set_parameter_value( | |||||
param_ptr->vtable.set_value(param_ptr->obj, &value); | param_ptr->vtable.set_value(param_ptr->obj, &value); | ||||
jack_controller_settings_save_auto(controller_ptr); | |||||
jack_controller_pending_save(controller_ptr); | |||||
jack_dbus_construct_method_return_empty(call); | jack_dbus_construct_method_return_empty(call); | ||||
@@ -945,7 +945,7 @@ jack_controller_dbus_reset_parameter_value( | |||||
param_ptr->vtable.reset(param_ptr->obj); | param_ptr->vtable.reset(param_ptr->obj); | ||||
jack_controller_settings_save_auto(controller_ptr); | |||||
jack_controller_pending_save(controller_ptr); | |||||
jack_dbus_construct_method_return_empty(call); | jack_dbus_construct_method_return_empty(call); | ||||
} | } | ||||
@@ -261,7 +261,7 @@ jack_control_run_method( | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
jack_controller_settings_save_auto(controller_ptr); | |||||
jack_controller_pending_save(controller_ptr); | |||||
} | } | ||||
} | } | ||||
else if (strcmp (call->method_name, "RemoveSlaveDriver") == 0) | else if (strcmp (call->method_name, "RemoveSlaveDriver") == 0) | ||||
@@ -290,7 +290,7 @@ jack_control_run_method( | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
jack_controller_settings_save_auto(controller_ptr); | |||||
jack_controller_pending_save(controller_ptr); | |||||
} | } | ||||
} | } | ||||
else if (strcmp (call->method_name, "UnloadInternal") == 0) | else if (strcmp (call->method_name, "UnloadInternal") == 0) | ||||
@@ -68,6 +68,8 @@ struct jack_controller | |||||
pthread_mutex_t lock; | pthread_mutex_t lock; | ||||
struct list_head session_pending_commands; | struct list_head session_pending_commands; | ||||
long pending_save; /* uptime seconds */ | |||||
}; | }; | ||||
#define DEFAULT_DRIVER "dummy" | #define DEFAULT_DRIVER "dummy" | ||||
@@ -77,6 +79,10 @@ struct jack_controller | |||||
"You probably don't want to edit this because\n" \ | "You probably don't want to edit this because\n" \ | ||||
"it will be overwritten next time jackdbus saves.\n" | "it will be overwritten next time jackdbus saves.\n" | ||||
void | |||||
jack_controller_pending_save( | |||||
struct jack_controller *controller_ptr); | |||||
bool | bool | ||||
jack_controller_start_server( | jack_controller_start_server( | ||||
struct jack_controller *controller_ptr, | struct jack_controller *controller_ptr, | ||||
@@ -948,7 +948,10 @@ main (int argc, char **argv) | |||||
jack_info("Listening for D-Bus messages"); | jack_info("Listening for D-Bus messages"); | ||||
g_exit_command = FALSE; | g_exit_command = FALSE; | ||||
while (!g_exit_command && dbus_connection_read_write_dispatch (g_connection, 200)); | |||||
while (!g_exit_command && dbus_connection_read_write_dispatch (g_connection, 200)) | |||||
{ | |||||
jack_controller_run(controller_ptr); | |||||
} | |||||
jack_controller_destroy(controller_ptr); | jack_controller_destroy(controller_ptr); | ||||