aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/ProxyDatabasePlugin.cxx
diff options
context:
space:
mode:
authorJean-Francois Dockes <jf@dockes.org>2013-10-29 20:58:35 +0100
committerMax Kellermann <max@duempel.org>2013-10-29 20:58:35 +0100
commit205448c1e839360a2b18abc685e8b185b89eb72f (patch)
tree2b2ee16cc1636d80e871385c091f59f27174196a /src/db/ProxyDatabasePlugin.cxx
parent2d11c6ab29b2d990121dfed43b6d887280dced33 (diff)
downloadmpd-205448c1e839360a2b18abc685e8b185b89eb72f.tar.gz
mpd-205448c1e839360a2b18abc685e8b185b89eb72f.tar.xz
mpd-205448c1e839360a2b18abc685e8b185b89eb72f.zip
db/proxy: enable song matching
Diffstat (limited to 'src/db/ProxyDatabasePlugin.cxx')
-rw-r--r--src/db/ProxyDatabasePlugin.cxx32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx
index e859e11eb..c0c9f93e7 100644
--- a/src/db/ProxyDatabasePlugin.cxx
+++ b/src/db/ProxyDatabasePlugin.cxx
@@ -25,6 +25,7 @@
#include "PlaylistVector.hxx"
#include "Directory.hxx"
#include "Song.hxx"
+#include "SongFilter.hxx"
#include "Compiler.h"
#include "ConfigData.hxx"
#include "tag/TagBuilder.hxx"
@@ -220,12 +221,14 @@ ProxyDatabase::ReturnSong(Song *song) const
static bool
Visit(struct mpd_connection *connection, const char *uri,
- bool recursive, VisitDirectory visit_directory, VisitSong visit_song,
+ bool recursive, const SongFilter *filter,
+ VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist, Error &error);
static bool
Visit(struct mpd_connection *connection,
- bool recursive, const struct mpd_directory *directory,
+ bool recursive, const SongFilter *filter,
+ const struct mpd_directory *directory,
VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist, Error &error)
{
@@ -240,7 +243,7 @@ Visit(struct mpd_connection *connection,
}
if (recursive &&
- !Visit(connection, path, recursive,
+ !Visit(connection, path, recursive, filter,
visit_directory, visit_song, visit_playlist, error))
return false;
@@ -281,15 +284,23 @@ Convert(const struct mpd_song *song)
return s;
}
+gcc_pure
+static bool
+Match(const SongFilter *filter, const Song &song)
+{
+ return filter == nullptr || filter->Match(song);
+}
+
static bool
-Visit(const struct mpd_song *song,
+Visit(const SongFilter *filter,
+ const struct mpd_song *song,
VisitSong visit_song, Error &error)
{
if (!visit_song)
return true;
Song *s = Convert(song);
- bool success = visit_song(*s, error);
+ bool success = !Match(filter, *s) || visit_song(*s, error);
s->Free();
return success;
@@ -348,7 +359,8 @@ ReceiveEntities(struct mpd_connection *connection)
static bool
Visit(struct mpd_connection *connection, const char *uri,
- bool recursive, VisitDirectory visit_directory, VisitSong visit_song,
+ bool recursive, const SongFilter *filter,
+ VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist, Error &error)
{
if (!mpd_send_list_meta(connection, uri))
@@ -364,7 +376,7 @@ Visit(struct mpd_connection *connection, const char *uri,
break;
case MPD_ENTITY_TYPE_DIRECTORY:
- if (!Visit(connection, recursive,
+ if (!Visit(connection, recursive, filter,
mpd_entity_get_directory(entity),
visit_directory, visit_song, visit_playlist,
error))
@@ -372,7 +384,8 @@ Visit(struct mpd_connection *connection, const char *uri,
break;
case MPD_ENTITY_TYPE_SONG:
- if (!Visit(mpd_entity_get_song(entity), visit_song,
+ if (!Visit(filter,
+ mpd_entity_get_song(entity), visit_song,
error))
return false;
break;
@@ -398,7 +411,8 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
// TODO: match
// TODO: auto-reconnect
- return ::Visit(connection, selection.uri.c_str(), selection.recursive,
+ return ::Visit(connection, selection.uri.c_str(),
+ selection.recursive, selection.filter,
visit_directory, visit_song, visit_playlist,
error);
}