mpd/src/db/plugins/SimpleDatabasePlugin.hxx

114 lines
2.7 KiB
C++
Raw Normal View History

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-01-24 16:18:50 +01:00
#include "db/DatabasePlugin.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 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;
/**
* A buffer for GetSong().
*/
mutable LightSong light_song;
#ifndef NDEBUG
mutable 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
/**
* Returns true if there is a valid database file on the disk.
*/
bool FileExists() const {
return mtime > 0;
}
static Database *Create(EventLoop &loop, DatabaseListener &listener,
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;
virtual const LightSong *GetSong(const char *uri_utf8,
Error &error) const override;
virtual void ReturnSong(const LightSong *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,
TagType tag_type,
VisitString visit_string,
Error &error) const override;
virtual bool GetStats(const DatabaseSelection &selection,
DatabaseStats &stats,
Error &error) const override;
virtual time_t GetUpdateStamp() const override {
return mtime;
}
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