StateFile: configurable interval

This commit is contained in:
Max Kellermann 2014-08-24 12:59:45 +02:00
parent d383d617c2
commit 42af040fbd
6 changed files with 27 additions and 4 deletions

View File

@ -898,6 +898,18 @@ systemctl start mpd.socket</programlisting>
(<parameter>+wx</parameter>).
</entry>
</row>
<row>
<entry>
<varname>state_file_interval</varname>
<parameter>SECONDS</parameter>
</entry>
<entry>
Auto-save the state file this number of seconds
after each state change. Defaults to
<parameter>120</parameter> (2 minutes).
</entry>
</row>
</tbody>
</tgroup>
</informaltable>

View File

@ -279,7 +279,10 @@ glue_state_file_init(Error &error)
#endif
}
state_file = new StateFile(std::move(path_fs),
unsigned interval = config_get_unsigned(CONF_STATE_FILE_INTERVAL,
StateFile::DEFAULT_INTERVAL);
state_file = new StateFile(std::move(path_fs), interval,
*instance->partition,
*instance->event_loop);
state_file->Read();

View File

@ -36,10 +36,11 @@
static constexpr Domain state_file_domain("state_file");
StateFile::StateFile(AllocatedPath &&_path,
StateFile::StateFile(AllocatedPath &&_path, unsigned _interval,
Partition &_partition, EventLoop &_loop)
:TimeoutMonitor(_loop),
path(std::move(_path)), path_utf8(path.ToUTF8()),
interval(_interval),
partition(_partition),
prev_volume_version(0), prev_output_version(0),
prev_playlist_version(0)
@ -137,7 +138,7 @@ void
StateFile::CheckModified()
{
if (!IsActive() && IsModified())
ScheduleSeconds(2 * 60);
ScheduleSeconds(interval);
}
void

View File

@ -34,6 +34,8 @@ class StateFile final : private TimeoutMonitor {
const AllocatedPath path;
const std::string path_utf8;
const unsigned interval;
Partition &partition;
/**
@ -44,7 +46,10 @@ class StateFile final : private TimeoutMonitor {
prev_playlist_version;
public:
StateFile(AllocatedPath &&path, Partition &partition, EventLoop &loop);
static constexpr unsigned DEFAULT_INTERVAL = 2 * 60;
StateFile(AllocatedPath &&path, unsigned interval,
Partition &partition, EventLoop &loop);
void Read();
void Write();

View File

@ -32,6 +32,7 @@ enum ConfigOption {
CONF_LOG_FILE,
CONF_PID_FILE,
CONF_STATE_FILE,
CONF_STATE_FILE_INTERVAL,
CONF_RESTORE_PAUSED,
CONF_USER,
CONF_GROUP,

View File

@ -32,6 +32,7 @@ const ConfigTemplate config_templates[] = {
{ "log_file", false, false },
{ "pid_file", false, false },
{ "state_file", false, false },
{ "state_file_interval", false, false },
{ "restore_paused", false, false },
{ "user", false, false },
{ "group", false, false },