mpd/src/db/plugins/simple/SimpleDatabasePlugin.hxx

151 lines
3.7 KiB
C++
Raw Normal View History

2012-07-30 07:26:08 +02:00
/*
2018-10-31 17:54:59 +01:00
* Copyright 2003-2018 The Music Player Daemon Project
2012-07-30 07:26:08 +02:00
* 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_SIMPLE_DATABASE_PLUGIN_HXX
#define MPD_SIMPLE_DATABASE_PLUGIN_HXX
2014-02-19 22:54:52 +01:00
#include "db/Interface.hxx"
#include "fs/AllocatedPath.hxx"
#include "song/LightSong.hxx"
#include "util/Manual.hxx"
2018-08-20 16:19:17 +02:00
#include "util/Compiler.h"
#include "config.h"
2012-07-30 07:26:08 +02:00
#include <cassert>
struct ConfigBlock;
struct Directory;
2014-02-19 22:54:52 +01:00
struct DatabasePlugin;
class EventLoop;
class DatabaseListener;
class PrefixedLightSong;
2012-07-30 07:26:08 +02:00
class SimpleDatabase : public Database {
AllocatedPath path;
std::string path_utf8;
2012-07-30 07:26:08 +02:00
#ifdef ENABLE_ZLIB
bool compress;
#endif
/**
* The path where cache files for Mount() are located.
*/
AllocatedPath cache_path;
Directory *root;
2012-07-30 07:26:08 +02:00
std::chrono::system_clock::time_point mtime;
2012-07-30 07:26:08 +02:00
/**
* A buffer for GetSong() when prefixing the #LightSong
* instance from a mounted #Database.
*/
mutable PrefixedLightSong *prefixed_light_song;
/**
* A buffer for GetSong().
*/
mutable Manual<LightSong> light_song;
#ifndef NDEBUG
mutable unsigned borrowed_song_count;
#endif
SimpleDatabase(const ConfigBlock &block);
2018-09-02 10:16:43 +02:00
SimpleDatabase(AllocatedPath &&_path, bool _compress) noexcept;
2012-07-30 07:26:08 +02:00
public:
static Database *Create(EventLoop &main_event_loop,
EventLoop &io_event_loop,
DatabaseListener &listener,
const ConfigBlock &block);
2014-02-25 18:17:39 +01:00
gcc_pure
Directory &GetRoot() noexcept {
2012-07-30 07:26:08 +02:00
assert(root != NULL);
2014-02-27 19:29:10 +01:00
return *root;
2012-07-30 07:26:08 +02:00
}
void Save();
2012-07-30 07:26:08 +02:00
/**
* Returns true if there is a valid database file on the disk.
*/
bool FileExists() const {
return mtime >= std::chrono::system_clock::time_point(std::chrono::system_clock::duration::zero());
}
/**
* @param db the #Database to be mounted; must be "open"; on
* success, this object gains ownership of the given #Database
*/
gcc_nonnull_all
void Mount(const char *uri, Database *db);
/**
* Throws #std::runtime_error on error.
*/
gcc_nonnull_all
void Mount(const char *local_uri, const char *storage_uri);
gcc_nonnull_all
2018-09-02 10:16:43 +02:00
bool Unmount(const char *uri) noexcept;
2014-02-25 18:17:54 +01:00
/* virtual methods from class Database */
2017-01-23 18:57:23 +01:00
void Open() override;
2018-09-02 10:16:43 +02:00
void Close() noexcept override;
const LightSong *GetSong(const char *uri_utf8) const override;
2018-09-02 10:16:43 +02:00
void ReturnSong(const LightSong *song) const noexcept override;
void Visit(const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
VisitPlaylist visit_playlist) const override;
std::map<std::string, std::set<std::string>> CollectUniqueTags(const DatabaseSelection &selection,
TagType tag_type,
TagType group) const override;
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
std::chrono::system_clock::time_point GetUpdateStamp() const noexcept override {
return mtime;
}
private:
void Configure(const ConfigBlock &block);
2012-07-30 07:26:08 +02:00
void Check() const;
2012-07-30 07:26:08 +02:00
/**
* Throws #std::runtime_error on error.
*/
void Load();
2018-09-02 10:16:43 +02:00
Database *LockUmountSteal(const char *uri) noexcept;
2012-07-30 07:26:08 +02:00
};
extern const DatabasePlugin simple_db_plugin;
#endif