SimpleDatabasePlugin.hxx 2.42 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/AllocatedPath.hxx"
25
#include "Compiler.h"
26 27 28 29 30

#include <cassert>

#include <time.h>

31
struct Directory;
32 33

class SimpleDatabase : public Database {
34
	AllocatedPath 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
	SimpleDatabase()
46
		:path(AllocatedPath::Null()) {}
47

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

		return root;
	}

56
	bool Save(Error &error);
57

58
	gcc_pure
59 60 61 62
	time_t GetLastModified() const {
		return mtime;
	}

63
	static Database *Create(const config_param &param,
64
				Error &error);
65

66
	virtual bool Open(Error &error) override;
67
	virtual void Close() override;
68

69
	virtual Song *GetSong(const char *uri_utf8,
70
			      Error &error) const override;
71
	virtual void ReturnSong(Song *song) const;
72

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

79
	virtual bool VisitUniqueTags(const DatabaseSelection &selection,
80
				     TagType tag_type,
81
				     VisitString visit_string,
82
				     Error &error) const override;
83

84 85
	virtual bool GetStats(const DatabaseSelection &selection,
			      DatabaseStats &stats,
86
			      Error &error) const override;
87

88
protected:
89
	bool Configure(const config_param &param, Error &error);
90

91
	gcc_pure
92
	bool Check(Error &error) const;
93

94
	bool Load(Error &error);
95

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

extern const DatabasePlugin simple_db_plugin;

#endif