database.h 1.83 KB
Newer Older
1 2 3
/*
 * Copyright (C) 2003-2009 The Music Player Daemon Project
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
18 19
 */

20 21
#ifndef MPD_DATABASE_H
#define MPD_DATABASE_H
22

23 24
#include <glib.h>

25
#include <sys/time.h>
Max Kellermann's avatar
Max Kellermann committed
26
#include <stdbool.h>
27 28 29

struct directory;

30 31
/**
 * Initialize the database library.
32 33
 *
 * @param path the absolute path of the database file
34
 */
35
void
36
db_init(const char *path);
37

38 39
void
db_finish(void);
40

41 42 43
/**
 * Clear the database.
 */
44 45
void
db_clear(void);
46

47 48 49 50
/**
 * Returns the root directory object.  Returns NULL if there is no
 * configured music directory.
 */
51
struct directory *
52
db_get_root(void);
53 54

struct directory *
55
db_get_directory(const char *name);
56 57

struct song *
58
db_get_song(const char *file);
59

60 61 62
int db_walk(const char *name,
	    int (*forEachSong)(struct song *, void *),
	    int (*forEachDir)(struct directory *, void *), void *data);
63

Max Kellermann's avatar
Max Kellermann committed
64
bool
65
db_check(void);
66

Max Kellermann's avatar
Max Kellermann committed
67
bool
68
db_save(void);
69

Max Kellermann's avatar
Max Kellermann committed
70
bool
71
db_load(GError **error);
72

73 74
time_t
db_get_mtime(void);
75

76 77 78 79 80 81 82 83 84 85 86
/**
 * Returns true if there is a valid database file on the disk.
 */
static inline bool
db_exists(void)
{
	/* mtime is set only if the database file was loaded or saved
	   successfully */
	return db_get_mtime() > 0;
}

87
#endif