jackdbus: group batch of saves into one

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-9f06e86f4224
This commit is contained in:
nedko 2011-11-12 19:23:44 +00:00
parent f58e9abb51
commit 7bbe5971bf
6 changed files with 64 additions and 5 deletions

View File

@ -27,6 +27,8 @@
#include <dbus/dbus.h>
#include <assert.h>
#include <unistd.h>
#include <sys/sysinfo.h>
#include <errno.h>
#include "controller.h"
#include "controller_internal.h"
@ -560,6 +562,8 @@ jack_controller_create(
controller_ptr->client = NULL;
controller_ptr->started = false;
controller_ptr->pending_save = 0;
INIT_LIST_HEAD(&controller_ptr->slave_drivers);
controller_ptr->slave_drivers_set = false;
controller_ptr->slave_drivers_vparam_value.str[0] = 0;
@ -776,3 +780,45 @@ jack_controller_destroy(
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;
}

View File

@ -24,6 +24,10 @@ void *
jack_controller_create(
DBusConnection *connection);
void
jack_controller_run(
void *controller_ptr);
void
jack_controller_destroy(
void *controller_ptr);

View File

@ -903,7 +903,7 @@ jack_controller_dbus_set_parameter_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);
@ -945,7 +945,7 @@ jack_controller_dbus_reset_parameter_value(
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);
}

View File

@ -261,7 +261,7 @@ jack_control_run_method(
}
else
{
jack_controller_settings_save_auto(controller_ptr);
jack_controller_pending_save(controller_ptr);
}
}
else if (strcmp (call->method_name, "RemoveSlaveDriver") == 0)
@ -290,7 +290,7 @@ jack_control_run_method(
}
else
{
jack_controller_settings_save_auto(controller_ptr);
jack_controller_pending_save(controller_ptr);
}
}
else if (strcmp (call->method_name, "UnloadInternal") == 0)

View File

@ -68,6 +68,8 @@ struct jack_controller
pthread_mutex_t lock;
struct list_head session_pending_commands;
long pending_save; /* uptime seconds */
};
#define DEFAULT_DRIVER "dummy"
@ -77,6 +79,10 @@ struct jack_controller
"You probably don't want to edit this because\n" \
"it will be overwritten next time jackdbus saves.\n"
void
jack_controller_pending_save(
struct jack_controller *controller_ptr);
bool
jack_controller_start_server(
struct jack_controller *controller_ptr,

View File

@ -948,7 +948,10 @@ main (int argc, char **argv)
jack_info("Listening for D-Bus messages");
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);