MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

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 public:
50 static constexpr std::chrono::steady_clock::duration DEFAULT_INTERVAL = std::chrono::minutes(2);
51
52 StateFile(AllocatedPath &&path, std::chrono::steady_clock::duration interval,
53 Partition &partition, EventLoop &loop);
54
55 void Read();
56 void Write();
57
61 void CheckModified();
62
63 private:
64 void Write(OutputStream &os);
65 void Write(BufferedOutputStream &os);
66
70 void RememberVersions();
71
76 gcc_pure
77 bool IsModified() const;
78
79 /* virtual methods from TimeoutMonitor */
80 void OnTimeout() override;
81 };
82
83 #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:50
StateFile::Read
void Read()
EventLoop
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:51
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'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