mpd/src/StateFile.hxx

70 lines
1.4 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
2013-01-02 19:52:57 +01:00
#ifndef MPD_STATE_FILE_HXX
#define MPD_STATE_FILE_HXX
2018-07-17 23:27:50 +02:00
#include "StateFileConfig.hxx"
#include "event/FarTimerEvent.hxx"
#include "config.h"
2013-01-14 11:00:22 +01:00
#include <string>
struct Partition;
class OutputStream;
class BufferedOutputStream;
2013-01-14 11:00:22 +01:00
class StateFile final {
2018-07-17 23:27:50 +02:00
const StateFileConfig config;
2014-08-24 13:00:30 +02:00
const std::string path_utf8;
2013-01-14 11:00:22 +01:00
FarTimerEvent timer_event;
2014-08-24 12:59:45 +02:00
2013-01-14 11:00:22 +01:00
Partition &partition;
/**
* These version numbers determine whether we need to save the state
* file. If nothing has changed, we won't let the hard drive spin up.
*/
2016-12-27 23:13:03 +01:00
unsigned prev_volume_version = 0, prev_output_version = 0,
prev_playlist_version = 0;
#ifdef ENABLE_DATABASE
unsigned prev_storage_version = 0;
#endif
2013-01-14 11:00:22 +01:00
public:
2018-07-17 23:27:50 +02:00
StateFile(StateFileConfig &&_config,
2014-08-24 12:59:45 +02:00
Partition &partition, EventLoop &loop);
2013-01-14 11:00:22 +01:00
void Read();
void Write();
/**
* Schedules a write if MPD's state was modified.
*/
2019-04-24 14:54:17 +02:00
void CheckModified() noexcept;
2013-01-14 11:00:22 +01:00
private:
void Write(OutputStream &os);
void Write(BufferedOutputStream &os);
/**
* Save the current state versions for use with IsModified().
*/
void RememberVersions() noexcept;
/**
* Check if MPD's state was modified since the last
* RememberVersions() call.
*/
2021-10-13 11:28:04 +02:00
[[gnu::pure]]
bool IsModified() const noexcept;
/* callback for #timer_event */
2019-04-24 14:54:17 +02:00
void OnTimeout() noexcept;
2013-01-14 11:00:22 +01:00
};
#endif /* STATE_FILE_H */