MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

SimpleDatabasePlugin.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_SIMPLE_DATABASE_PLUGIN_HXX
21 #define MPD_SIMPLE_DATABASE_PLUGIN_HXX
22
23 #include "check.h"
24 #include "db/Interface.hxx"
25 #include "fs/AllocatedPath.hxx"
26 #include "db/LightSong.hxx"
27 #include "Compiler.h"
28
29 #include <cassert>
30
31 struct ConfigBlock;
32 struct Directory;
33 struct DatabasePlugin;
34 class EventLoop;
35 class DatabaseListener;
36 class PrefixedLightSong;
37
38 class SimpleDatabase : public Database {
39 AllocatedPath path;
40 std::string path_utf8;
41
42 #ifdef ENABLE_ZLIB
43 bool compress;
44 #endif
45
49 AllocatedPath cache_path;
50
51 Directory *root;
52
53 time_t mtime;
54
59 mutable PrefixedLightSong *prefixed_light_song;
60
64 mutable LightSong light_song;
65
66 #ifndef NDEBUG
67 mutable unsigned borrowed_song_count;
68 #endif
69
70 SimpleDatabase(const ConfigBlock &block);
71
72 SimpleDatabase(AllocatedPath &&_path, bool _compress);
73
74 public:
75 static Database *Create(EventLoop &loop, DatabaseListener &listener,
76 const ConfigBlock &block);
77
78 gcc_pure
79 Directory &GetRoot() {
80 assert(root != NULL);
81
82 return *root;
83 }
84
85 void Save();
86
90 bool FileExists() const {
91 return mtime > 0;
92 }
93
98 gcc_nonnull_all
99 void Mount(const char *uri, Database *db);
100
104 gcc_nonnull_all
105 void Mount(const char *local_uri, const char *storage_uri);
106
107 gcc_nonnull_all
108 bool Unmount(const char *uri);
109
110 /* virtual methods from class Database */
111 void Open() override;
112 void Close() override;
113
114 const LightSong *GetSong(const char *uri_utf8) const override;
115 void ReturnSong(const LightSong *song) const override;
116
117 void Visit(const DatabaseSelection &selection,
118 VisitDirectory visit_directory,
119 VisitSong visit_song,
120 VisitPlaylist visit_playlist) const override;
121
122 void VisitUniqueTags(const DatabaseSelection &selection,
123 TagType tag_type, tag_mask_t group_mask,
124 VisitTag visit_tag) const override;
125
126 DatabaseStats GetStats(const DatabaseSelection &selection) const override;
127
128 time_t GetUpdateStamp() const override {
129 return mtime;
130 }
131
132 private:
133 void Configure(const ConfigBlock &block);
134
135 void Check() const;
136
140 void Load();
141
142 Database *LockUmountSteal(const char *uri);
143 };
144
145 extern const DatabasePlugin simple_db_plugin;
146
147 #endif
SimpleDatabase::Visit
void Visit(const DatabaseSelection &selection, VisitDirectory visit_directory, VisitSong visit_song, VisitPlaylist visit_playlist) const override
Visit the selected entities.
check.h
SimpleDatabase::Mount
gcc_nonnull_all void Mount(const char *uri, Database *db)
gcc_nonnull_all
#define gcc_nonnull_all
Definition: Compiler.h:122
Database
Definition: Interface.hxx:35
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
DatabasePlugin
Definition: DatabasePlugin.hxx:34
VisitDirectory
std::function< void(const LightDirectory &)> VisitDirectory
Definition: Visitor.hxx:28
SimpleDatabase::GetStats
DatabaseStats GetStats(const DatabaseSelection &selection) const override
DatabaseListener
An object that listens to events from the Database.
Definition: DatabaseListener.hxx:30
VisitPlaylist
std::function< void(const PlaylistInfo &, const LightDirectory &)> VisitPlaylist
Definition: Visitor.hxx:33
LightSong.hxx
simple_db_plugin
const DatabasePlugin simple_db_plugin
SimpleDatabase::GetUpdateStamp
time_t GetUpdateStamp() const override
Returns the time stamp of the last database update.
Definition: SimpleDatabasePlugin.hxx:128
ConfigBlock
Definition: Block.hxx:57
SimpleDatabase::GetSong
const LightSong * GetSong(const char *uri_utf8) const override
Look up a song (including tag data) in the database.
Compiler.h
AllocatedPath.hxx
TagType
TagType
Codes for the type of a tag item.
Definition: TagType.h:30
DatabaseStats
Definition: Stats.hxx:25
SimpleDatabase::Unmount
gcc_nonnull_all bool Unmount(const char *uri)
tag_mask_t
uint_least32_t tag_mask_t
Definition: Mask.hxx:25
SimpleDatabase
Definition: SimpleDatabasePlugin.hxx:38
VisitSong
std::function< void(const LightSong &)> VisitSong
Definition: Visitor.hxx:31
VisitTag
std::function< void(const Tag &)> VisitTag
Definition: Visitor.hxx:35
SimpleDatabase::Save
void Save()
SimpleDatabase::Open
void Open() override
Open the database.
SimpleDatabase::Close
void Close() override
Close the database, free allocated memory.
SimpleDatabase::Create
static Database * Create(EventLoop &loop, DatabaseListener &listener, const ConfigBlock &block)
SimpleDatabase::FileExists
bool FileExists() const
Returns true if there is a valid database file on the disk.
Definition: SimpleDatabasePlugin.hxx:90
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
PrefixedLightSong
Definition: PrefixedLightSong.hxx:29
Directory
Definition: Directory.hxx:49
Interface.hxx
SimpleDatabase::VisitUniqueTags
void VisitUniqueTags(const DatabaseSelection &selection, TagType tag_type, tag_mask_t group_mask, VisitTag visit_tag) const override
Visit all unique tag values.
SimpleDatabase::ReturnSong
void ReturnSong(const LightSong *song) const override
Mark the song object as "unused".
SimpleDatabase::GetRoot
gcc_pure Directory & GetRoot()
Definition: SimpleDatabasePlugin.hxx:79
uri
const Storage const char * uri
Definition: DatabasePlaylist.hxx:31
DatabaseSelection
Definition: Selection.hxx:30
LightSong
A reference to a song file.
Definition: LightSong.hxx:40