mpd/src/db/SimpleDatabasePlugin.hxx

103 lines
2.4 KiB
C++
Raw Normal View History

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"
#include "fs/AllocatedPath.hxx"
2013-10-15 09:21:13 +02:00
#include "Compiler.h"
2012-07-30 07:26:08 +02:00
#include <cassert>
#include <time.h>
struct Directory;
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
Directory *root;
2012-07-30 07:26:08 +02:00
time_t mtime;
#ifndef NDEBUG
unsigned borrowed_song_count;
#endif
SimpleDatabase()
:path(AllocatedPath::Null()) {}
2012-07-30 07:26:08 +02:00
public:
gcc_pure
Directory *GetRoot() {
2012-07-30 07:26:08 +02:00
assert(root != NULL);
return root;
}
bool Save(Error &error);
2012-07-30 07:26:08 +02:00
gcc_pure
2012-07-30 07:26:08 +02:00
time_t GetLastModified() const {
return mtime;
}
static Database *Create(const config_param &param,
Error &error);
2012-07-30 07:26:08 +02:00
virtual bool Open(Error &error) override;
2012-07-30 07:26:08 +02:00
virtual void Close() override;
2013-07-28 13:25:12 +02:00
virtual Song *GetSong(const char *uri_utf8,
Error &error) const override;
2013-07-28 13:25:12 +02:00
virtual void ReturnSong(Song *song) const;
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,
enum tag_type tag_type,
VisitString visit_string,
Error &error) const override;
virtual bool GetStats(const DatabaseSelection &selection,
DatabaseStats &stats,
Error &error) const override;
2012-07-30 07:26:08 +02:00
protected:
bool Configure(const config_param &param, Error &error);
2012-07-30 07:26:08 +02:00
gcc_pure
bool Check(Error &error) const;
2012-07-30 07:26:08 +02:00
bool Load(Error &error);
2012-07-30 07:26:08 +02:00
gcc_pure
const Directory *LookupDirectory(const char *uri) const;
2012-07-30 07:26:08 +02:00
};
extern const DatabasePlugin simple_db_plugin;
#endif