SimpleDatabasePlugin.hxx 2.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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"
24
#include "fs/Path.hxx"
25 26 27 28 29 30
#include "gcc.h"

#include <cassert>

#include <time.h>

31
struct Directory;
32 33

class SimpleDatabase : public Database {
34
	Path path;
35
	std::string path_utf8;
36

37
	Directory *root;
38 39 40

	time_t mtime;

41 42 43 44
#ifndef NDEBUG
	unsigned borrowed_song_count;
#endif

45 46 47
	SimpleDatabase()
		:path(Path::Null()) {}

48
public:
49
	gcc_pure
50
	Directory *GetRoot() {
51 52 53 54 55 56 57
		assert(root != NULL);

		return root;
	}

	bool Save(GError **error_r);

58
	gcc_pure
59 60 61 62 63 64 65 66 67
	time_t GetLastModified() const {
		return mtime;
	}

	static Database *Create(const struct config_param *param,
				GError **error_r);

	virtual bool Open(GError **error_r) override;
	virtual void Close() override;
68

69
	virtual struct song *GetSong(const char *uri_utf8,
70
				     GError **error_r) const override;
71 72
	virtual void ReturnSong(struct song *song) const;

73
	virtual bool Visit(const DatabaseSelection &selection,
74 75 76
			   VisitDirectory visit_directory,
			   VisitSong visit_song,
			   VisitPlaylist visit_playlist,
77
			   GError **error_r) const override;
78

79 80 81 82 83
	virtual bool VisitUniqueTags(const DatabaseSelection &selection,
				     enum tag_type tag_type,
				     VisitString visit_string,
				     GError **error_r) const override;

84 85 86 87
	virtual bool GetStats(const DatabaseSelection &selection,
			      DatabaseStats &stats,
			      GError **error_r) const override;

88 89 90
protected:
	bool Configure(const struct config_param *param, GError **error_r);

91
	gcc_pure
92 93 94 95
	bool Check(GError **error_r) const;

	bool Load(GError **error_r);

96
	gcc_pure
97
	const Directory *LookupDirectory(const char *uri) const;
98 99 100 101 102
};

extern const DatabasePlugin simple_db_plugin;

#endif