MPD: StateFile.hxx Source File

MPD 0.20.18

StateFile.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_STATE_FILE_HXX
21 #define MPD_STATE_FILE_HXX
22
23 #include "event/TimeoutMonitor.hxx"
24 #include "fs/AllocatedPath.hxx"
25 #include "Compiler.h"
26
27 #include <string>
28 #include <chrono>
29
30 struct Partition;
31 class OutputStream;
32 class BufferedOutputStream;
33
34 class StateFile final : private TimeoutMonitor {
35 const AllocatedPath path;
36 const std::string path_utf8;
37
38 const std::chrono::steady_clock::duration interval;
39
40 Partition &partition;
41
46 unsigned prev_volume_version = 0, prev_output_version = 0,
47 prev_playlist_version = 0;
48
49 #ifdef ENABLE_DATABASE
50 unsigned prev_storage_version = 0;
51 #endif
52
53 public:
54 static constexpr std::chrono::steady_clock::duration DEFAULT_INTERVAL = std::chrono::minutes(2);
55
56 StateFile(AllocatedPath &&path, std::chrono::steady_clock::duration interval,
57 Partition &partition, EventLoop &loop);
58
59 void Read();
60 void Write();
61
65 void CheckModified();
66
67 private:
68 void Write(OutputStream &os);
69 void Write(BufferedOutputStream &os);
70
74 void RememberVersions() noexcept;
75
80 gcc_pure
81 bool IsModified() const noexcept;
82
83 /* virtual methods from TimeoutMonitor */
84 void OnTimeout() override;
85 };
86
87 #endif /* STATE_FILE_H */
StateFile
Definition: StateFile.hxx:34
StateFile::Write
void Write()
TimeoutMonitor
This class monitors a timeout.
Definition: TimeoutMonitor.hxx:37
StateFile::DEFAULT_INTERVAL
static constexpr std::chrono::steady_clock::duration DEFAULT_INTERVAL
Definition: StateFile.hxx:54
StateFile::Read
void Read()
EventLoop
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:52
AllocatedPath
A path name in the native file system character set.
Definition: AllocatedPath.hxx:38
Partition
A partition of the Music Player Daemon.
Definition: Partition.hxx:42
Compiler.h
AllocatedPath.hxx
TimeoutMonitor.hxx
OutputStream
Definition: OutputStream.hxx:27
StateFile::CheckModified
void CheckModified()
Schedules a write if MPD&#39;s state was modified.
BufferedOutputStream
An OutputStream wrapper that buffers its output to reduce the number of OutputStream::Write() calls...
Definition: BufferedOutputStream.hxx:41
StateFile::StateFile
StateFile(AllocatedPath &&path, std::chrono::steady_clock::duration interval, Partition &partition, EventLoop &loop)
gcc_pure
#define gcc_pure
Definition: Compiler.h:116