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

148 lines
3.3 KiB
C++
Raw Normal View History

2012-07-30 07:26:08 +02:00
/*
2017-01-03 20:48:59 +01:00
* Copyright 2003-2017 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
#include "check.h"
2014-02-19 22:54:52 +01:00
#include "db/Interface.hxx"
#include "fs/AllocatedPath.hxx"
2014-01-24 16:18:50 +01:00
#include "db/LightSong.hxx"
2013-10-15 09:21:13 +02:00
#include "Compiler.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
time_t mtime;
/**
* A buffer for GetSong() when prefixing the #LightSong
* instance from a mounted #Database.
*/
mutable PrefixedLightSong *prefixed_light_song;
/**
* A buffer for GetSong().
*/
mutable LightSong light_song;
#ifndef NDEBUG
mutable unsigned borrowed_song_count;
#endif
SimpleDatabase(const ConfigBlock &block);
SimpleDatabase(AllocatedPath &&_path, bool _compress);
2012-07-30 07:26:08 +02:00
public:
2014-02-25 18:17:39 +01:00
static Database *Create(EventLoop &loop, DatabaseListener &listener,
const ConfigBlock &block);
2014-02-25 18:17:39 +01:00
gcc_pure
2014-02-27 19:29:10 +01:00
Directory &GetRoot() {
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 > 0;
}
/**
* @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
bool Unmount(const char *uri);
2014-02-25 18:17:54 +01:00
/* virtual methods from class Database */
2017-01-23 18:57:23 +01:00
void Open() override;
void Close() override;
const LightSong *GetSong(const char *uri_utf8) const override;
2014-12-26 14:26:31 +01:00
void ReturnSong(const LightSong *song) const override;
void Visit(const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
VisitPlaylist visit_playlist) const override;
void VisitUniqueTags(const DatabaseSelection &selection,
2017-02-07 16:57:16 +01:00
TagType tag_type, TagMask group_mask,
VisitTag visit_tag) const override;
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
2017-01-23 18:57:23 +01:00
time_t GetUpdateStamp() const 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();
Database *LockUmountSteal(const char *uri);
2012-07-30 07:26:08 +02:00
};
extern const DatabasePlugin simple_db_plugin;
#endif