diff options
author | Max Kellermann <max@duempel.org> | 2011-09-10 19:24:30 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-09-13 19:37:28 +0200 |
commit | 169db88c20dc7601f8589cfa298254c932f0947a (patch) | |
tree | b0cc3af153237379a1dbbb2fa90eb37eed05752f /src/database.c | |
parent | ca419c84b83d017c3e4309e22f92273500197eea (diff) | |
download | mpd-169db88c20dc7601f8589cfa298254c932f0947a.tar.gz mpd-169db88c20dc7601f8589cfa298254c932f0947a.tar.xz mpd-169db88c20dc7601f8589cfa298254c932f0947a.zip |
database: add struct db_visitor
Use this struct for db_walk().
Diffstat (limited to '')
-rw-r--r-- | src/database.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/database.c b/src/database.c index ea7f01eb1..6d7cc3e23 100644 --- a/src/database.c +++ b/src/database.c @@ -19,7 +19,9 @@ #include "config.h" #include "database.h" +#include "db_error.h" #include "db_save.h" +#include "db_visitor.h" #include "db_plugin.h" #include "db/simple_db_plugin.h" #include "directory.h" @@ -41,15 +43,6 @@ static struct db *db; static bool db_is_open; -/** - * The quark used for GError.domain. - */ -static inline GQuark -db_quark(void) -{ - return g_quark_from_static_string("database"); -} - bool db_init(const struct config_param *path, GError **error_r) { @@ -114,25 +107,28 @@ db_get_song(const char *file) return directory_lookup_song(music_root, file); } -int -db_walk(const char *name, - int (*forEachSong)(struct song *, void *), - int (*forEachDir)(struct directory *, void *), void *data) +bool +db_walk(const char *uri, + const struct db_visitor *visitor, void *ctx, + GError **error_r) { struct directory *directory; if (db == NULL) return -1; - if ((directory = db_get_directory(name)) == NULL) { + if ((directory = db_get_directory(uri)) == NULL) { struct song *song; - if ((song = db_get_song(name)) && forEachSong) { - return forEachSong(song, data); - } - return -1; + if (visitor->song != NULL && + (song = db_get_song(uri)) != NULL) + return visitor->song(song, ctx, error_r); + + g_set_error(error_r, db_quark(), DB_NOT_FOUND, + "No such directory: %s", uri); + return false; } - return directory_walk(directory, forEachSong, forEachDir, data); + return directory_walk(directory, visitor, ctx, error_r); } bool |