2012-07-30 07:26:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
|
|
|
* 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 "DatabasePlugin.hxx"
|
2013-01-21 19:14:37 +01:00
|
|
|
#include "fs/Path.hxx"
|
2012-07-30 07:26:08 +02:00
|
|
|
#include "gcc.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2013-01-02 23:06:20 +01:00
|
|
|
struct Directory;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
|
|
|
class SimpleDatabase : public Database {
|
2013-01-17 00:56:57 +01:00
|
|
|
Path path;
|
2013-02-02 15:27:06 +01:00
|
|
|
std::string path_utf8;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2013-01-02 23:06:20 +01:00
|
|
|
Directory *root;
|
2012-07-30 07:26:08 +02:00
|
|
|
|
|
|
|
time_t mtime;
|
|
|
|
|
2012-08-15 23:28:19 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
unsigned borrowed_song_count;
|
|
|
|
#endif
|
|
|
|
|
2013-01-17 00:56:57 +01:00
|
|
|
SimpleDatabase()
|
|
|
|
:path(Path::Null()) {}
|
|
|
|
|
2012-07-30 07:26:08 +02:00
|
|
|
public:
|
2012-08-02 18:15:49 +02:00
|
|
|
gcc_pure
|
2013-01-02 23:06:20 +01:00
|
|
|
Directory *GetRoot() {
|
2012-07-30 07:26:08 +02:00
|
|
|
assert(root != NULL);
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
bool Save(Error &error);
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2012-08-02 18:15:49 +02:00
|
|
|
gcc_pure
|
2012-07-30 07:26:08 +02:00
|
|
|
time_t GetLastModified() const {
|
|
|
|
return mtime;
|
|
|
|
}
|
|
|
|
|
2013-08-04 13:51:27 +02:00
|
|
|
static Database *Create(const config_param ¶m,
|
2013-08-10 18:02:44 +02:00
|
|
|
Error &error);
|
2012-07-30 07:26:08 +02:00
|
|
|
|
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
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
virtual Song *GetSong(const char *uri_utf8,
|
2013-08-10 18:02:44 +02:00
|
|
|
Error &error) const override;
|
2013-07-28 13:25:12 +02:00
|
|
|
virtual void ReturnSong(Song *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,
|
|
|
|
enum tag_type tag_type,
|
|
|
|
VisitString visit_string,
|
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
|
|
|
|
2012-07-30 07:26:08 +02:00
|
|
|
protected:
|
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);
|
2012-07-30 07:26:08 +02:00
|
|
|
|
2012-08-02 18:15:49 +02:00
|
|
|
gcc_pure
|
2013-01-02 23:06:20 +01:00
|
|
|
const Directory *LookupDirectory(const char *uri) const;
|
2012-07-30 07:26:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const DatabasePlugin simple_db_plugin;
|
|
|
|
|
|
|
|
#endif
|