b9659ba0c0
-----BEGIN PGP SIGNATURE----- iQJEBAABCAAuFiEEA5IzWngIOJSkMBxDI26KWMbbRRIFAlo4RDQQHG1heEBtdXNp Y3BkLm9yZwAKCRAjbopYxttFEpm6EACTPaPwGbxS770jJ74vLGSltnZTohaKbRvp rIaJGkHTTzPlvw8dpLHmave9fL5ODSchTBmIHqb0loM9011oJgvXUKq3fqEQJUUW eFZ54emSDXOjholsd8ykJgrPjMBO2UNEk5T/r6bZdNZlLAN7yNOXkJHezPY8qyzA s07o9jmFEKjyLOsMlmEaV2uiCZ9UhPUSUI+vy+Q7qwwil24AfOzXc4+gAB3bV87E FFWWP8KO83X2ZrhPZdSeILFcI0i93X/l0rskvf4bgHtoegaYPWk/KnhPnmJ2DC48 GFzigB5ZbU+OGXz1We7O6DZg6KOB4Y6dDPThtxS0rBTZWCPM6biDVsDFexqACf8u sCYTzaTlvAV2gHVGp3csVwXS9gqxYOZbiyMgyMOVKygrvuhgrnQydZQW8yweoscP tRxVcKfHclbdsEJHboT1Tp4ibh4+iIT48muMpLDlX6h0KC4OOTSg8m3UGV6V4UAA bkDVueFYQcr1tyENJbFGRt6gCENY7rdJMX30TvC0DhDtHXUwY6O5G//w5iqpeztv svcOuQQURxmPcFuvIqpTpcX0bSEuYkCt9JF31xzFbvmUhB1bb4sZ+IMvBqS9fnUH HJmDLLl7mppX3hlPDc9wLc3Dmpfr5Cd1GLO0CkWhnE8KBONV1auYXh8Gtwdsa/Rv idA/53WlvQ== =+PRl -----END PGP SIGNATURE----- Merge tag 'v0.20.13' release v0.20.13
89 lines
2.3 KiB
C++
89 lines
2.3 KiB
C++
/*
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
|
* http://www.musicpd.org
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#ifndef MPD_STATE_FILE_HXX
|
|
#define MPD_STATE_FILE_HXX
|
|
|
|
#include "event/TimerEvent.hxx"
|
|
#include "fs/AllocatedPath.hxx"
|
|
#include "Compiler.h"
|
|
|
|
#include <string>
|
|
#include <chrono>
|
|
|
|
struct Partition;
|
|
class OutputStream;
|
|
class BufferedOutputStream;
|
|
|
|
class StateFile final {
|
|
const AllocatedPath path;
|
|
const std::string path_utf8;
|
|
|
|
const std::chrono::steady_clock::duration interval;
|
|
TimerEvent timer_event;
|
|
|
|
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.
|
|
*/
|
|
unsigned prev_volume_version = 0, prev_output_version = 0,
|
|
prev_playlist_version = 0;
|
|
|
|
#ifdef ENABLE_DATABASE
|
|
unsigned prev_storage_version = 0;
|
|
#endif
|
|
|
|
public:
|
|
static constexpr std::chrono::steady_clock::duration DEFAULT_INTERVAL = std::chrono::minutes(2);
|
|
|
|
StateFile(AllocatedPath &&path, std::chrono::steady_clock::duration interval,
|
|
Partition &partition, EventLoop &loop);
|
|
|
|
void Read();
|
|
void Write();
|
|
|
|
/**
|
|
* Schedules a write if MPD's state was modified.
|
|
*/
|
|
void CheckModified();
|
|
|
|
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.
|
|
*/
|
|
gcc_pure
|
|
bool IsModified() const noexcept;
|
|
|
|
/* callback for #timer_event */
|
|
void OnTimeout();
|
|
};
|
|
|
|
#endif /* STATE_FILE_H */
|