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

149 lines
3.5 KiB
C++
Raw Normal View History

2012-07-30 07:26:08 +02:00
/*
2016-02-26 17:54:05 +01:00
* Copyright 2003-2016 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();
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
Error &error);
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);
gcc_nonnull_all
bool Mount(const char *local_uri, const char *storage_uri,
Error &error);
gcc_nonnull_all
bool Unmount(const char *uri);
2014-02-25 18:17:54 +01:00
/* virtual methods from class Database */
virtual bool Open(Error &error) override;
2012-07-30 07:26:08 +02:00
virtual void Close() override;
2014-12-26 14:26:31 +01:00
const LightSong *GetSong(const char *uri_utf8,
Error &error) const override;
void ReturnSong(const LightSong *song) const override;
virtual bool Visit(const DatabaseSelection &selection,
2012-07-30 07:26:08 +02:00
VisitDirectory visit_directory,
VisitSong visit_song,
VisitPlaylist visit_playlist,
Error &error) const override;
2012-07-30 07:26:08 +02:00
virtual bool VisitUniqueTags(const DatabaseSelection &selection,
TagType tag_type, tag_mask_t group_mask,
VisitTag visit_tag,
Error &error) const override;
virtual bool GetStats(const DatabaseSelection &selection,
DatabaseStats &stats,
Error &error) const override;
virtual time_t GetUpdateStamp() const override {
return mtime;
}
private:
bool Configure(const ConfigBlock &block, Error &error);
2012-07-30 07:26:08 +02:00
void Check() const;
2012-07-30 07:26:08 +02:00
bool Load(Error &error);
Database *LockUmountSteal(const char *uri);
2012-07-30 07:26:08 +02:00
};
extern const DatabasePlugin simple_db_plugin;
#endif