2012-07-30 07:26:08 +02:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 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"
|
2013-10-17 21:59:35 +02:00
|
|
|
#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>
|
|
|
|
|
2014-02-19 22:54:52 +01:00
|
|
|
struct config_param;
|
2013-01-02 23:06:20 +01:00
|
|
|
struct Directory;
|
2014-02-19 22:54:52 +01:00
|
|
|
struct DatabasePlugin;
|
|
|
|
class EventLoop;
|
|
|
|
class DatabaseListener;
|
2014-02-26 08:39:44 +01:00
|
|
|
class PrefixedLightSong;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
|
|
|
class SimpleDatabase : public Database {
|
2013-10-17 21:59:35 +02:00
|
|
|
AllocatedPath path;
|
2013-02-02 15:27:06 +01:00
|
|
|
std::string path_utf8;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2014-02-26 08:39:44 +01:00
|
|
|
/**
|
|
|
|
* The path where cache files for Mount() are located.
|
|
|
|
*/
|
|
|
|
AllocatedPath cache_path;
|
|
|
|
|
2013-01-02 23:06:20 +01:00
|
|
|
Directory *root;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
|
|
|
time_t mtime;
|
|
|
|
|
2014-02-26 08:39:44 +01:00
|
|
|
/**
|
|
|
|
* A buffer for GetSong() when prefixing the #LightSong
|
|
|
|
* instance from a mounted #Database.
|
|
|
|
*/
|
|
|
|
mutable PrefixedLightSong *prefixed_light_song;
|
|
|
|
|
2014-01-19 10:51:34 +01:00
|
|
|
/**
|
|
|
|
* A buffer for GetSong().
|
|
|
|
*/
|
|
|
|
mutable LightSong light_song;
|
|
|
|
|
2012-08-15 23:28:19 +02:00
|
|
|
#ifndef NDEBUG
|
2014-01-19 11:23:02 +01:00
|
|
|
mutable unsigned borrowed_song_count;
|
2012-08-15 23:28:19 +02:00
|
|
|
#endif
|
|
|
|
|
2014-02-19 23:17:21 +01:00
|
|
|
SimpleDatabase();
|
2013-01-17 00:56:57 +01:00
|
|
|
|
2014-02-26 08:39:44 +01:00
|
|
|
SimpleDatabase(AllocatedPath &&_path);
|
|
|
|
|
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 config_param ¶m,
|
|
|
|
Error &error);
|
|
|
|
|
2012-08-02 18:15:49 +02: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
|
|
|
}
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
bool Save(Error &error);
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2014-02-01 00:26:34 +01:00
|
|
|
/**
|
|
|
|
* Returns true if there is a valid database file on the disk.
|
|
|
|
*/
|
2014-02-04 08:37:05 +01:00
|
|
|
bool FileExists() const {
|
|
|
|
return mtime > 0;
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:39:44 +01:00
|
|
|
/**
|
|
|
|
* @param db the #Database to be mounted; must be "open"; on
|
|
|
|
* success, this object gains ownership of the given #Database
|
|
|
|
*/
|
|
|
|
gcc_nonnull_all
|
|
|
|
bool Mount(const char *uri, Database *db, Error &error);
|
|
|
|
|
|
|
|
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 */
|
2013-08-10 18:02:44 +02:00
|
|
|
virtual bool Open(Error &error) override;
|
2012-07-30 07:26:08 +02:00
|
|
|
virtual void Close() override;
|
2012-08-15 22:20:28 +02:00
|
|
|
|
2014-01-19 10:51:34 +01:00
|
|
|
virtual const LightSong *GetSong(const char *uri_utf8,
|
|
|
|
Error &error) const override;
|
|
|
|
virtual void ReturnSong(const LightSong *song) const;
|
2012-08-15 23:28:19 +02:00
|
|
|
|
2012-08-07 23:06:41 +02:00
|
|
|
virtual bool Visit(const DatabaseSelection &selection,
|
2012-07-30 07:26:08 +02:00
|
|
|
VisitDirectory visit_directory,
|
|
|
|
VisitSong visit_song,
|
|
|
|
VisitPlaylist visit_playlist,
|
2013-08-10 18:02:44 +02:00
|
|
|
Error &error) const override;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2012-08-15 21:32:34 +02:00
|
|
|
virtual bool VisitUniqueTags(const DatabaseSelection &selection,
|
2014-04-24 10:20:24 +02:00
|
|
|
TagType tag_type, uint32_t group_mask,
|
|
|
|
VisitTag visit_tag,
|
2013-08-10 18:02:44 +02:00
|
|
|
Error &error) const override;
|
2012-08-15 21:32:34 +02:00
|
|
|
|
2012-08-15 22:20:28 +02:00
|
|
|
virtual bool GetStats(const DatabaseSelection &selection,
|
|
|
|
DatabaseStats &stats,
|
2013-08-10 18:02:44 +02:00
|
|
|
Error &error) const override;
|
2012-08-15 22:20:28 +02:00
|
|
|
|
2013-11-22 00:35:29 +01:00
|
|
|
virtual time_t GetUpdateStamp() const override {
|
|
|
|
return mtime;
|
|
|
|
}
|
|
|
|
|
2014-02-25 19:48:01 +01:00
|
|
|
private:
|
2013-08-10 18:02:44 +02:00
|
|
|
bool Configure(const config_param ¶m, Error &error);
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2012-08-02 18:15:49 +02:00
|
|
|
gcc_pure
|
2013-08-10 18:02:44 +02:00
|
|
|
bool Check(Error &error) const;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
bool Load(Error &error);
|
2014-02-26 08:39:44 +01:00
|
|
|
|
|
|
|
Database *LockUmountSteal(const char *uri);
|
2012-07-30 07:26:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const DatabasePlugin simple_db_plugin;
|
|
|
|
|
|
|
|
#endif
|