aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-10 19:24:30 +0200
committerMax Kellermann <max@duempel.org>2011-09-13 19:37:28 +0200
commit169db88c20dc7601f8589cfa298254c932f0947a (patch)
treeb0cc3af153237379a1dbbb2fa90eb37eed05752f /src/directory.c
parentca419c84b83d017c3e4309e22f92273500197eea (diff)
downloadmpd-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/directory.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/directory.c b/src/directory.c
index d8b241118..eb076d94d 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -21,6 +21,7 @@
#include "directory.h"
#include "song.h"
#include "path.h"
+#include "db_visitor.h"
#include <glib.h>
@@ -167,28 +168,33 @@ directory_sort(struct directory *directory)
directory_sort(dv->base[i]);
}
-int
+bool
directory_walk(struct directory *directory,
- int (*forEachSong)(struct song *, void *),
- int (*forEachDir)(struct directory *, void *),
- void *data)
+ const struct db_visitor *visitor, void *ctx,
+ GError **error_r)
{
- struct dirvec *dv = &directory->children;
- int err = 0;
- size_t j;
-
- if (forEachDir && (err = forEachDir(directory, data)) < 0)
- return err;
-
- if (forEachSong) {
- err = songvec_for_each(&directory->songs, forEachSong, data);
- if (err < 0)
- return err;
+ assert(directory != NULL);
+ assert(visitor != NULL);
+ assert(error_r == NULL || *error_r == NULL);
+
+ if (visitor->directory != NULL &&
+ !visitor->directory(directory, ctx, error_r))
+ return false;
+
+ if (visitor->song != NULL) {
+ struct songvec *sv = &directory->songs;
+ for (size_t i = 0; i < sv->nr; ++i)
+ if (!visitor->song(sv->base[i], ctx, error_r))
+ return false;
}
- for (j = 0; err >= 0 && j < dv->nr; ++j)
- err = directory_walk(dv->base[j], forEachSong,
- forEachDir, data);
+ if (visitor->directory != NULL) {
+ const struct dirvec *dv = &directory->children;
+ for (size_t i = 0; i < dv->nr; ++i)
+ if (!directory_walk(dv->base[i], visitor, ctx,
+ error_r))
+ return false;
+ }
- return err;
+ return true;
}