Commit 205448c1 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes Committed by Max Kellermann

db/proxy: enable song matching

parent 2d11c6ab
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "PlaylistVector.hxx" #include "PlaylistVector.hxx"
#include "Directory.hxx" #include "Directory.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "SongFilter.hxx"
#include "Compiler.h" #include "Compiler.h"
#include "ConfigData.hxx" #include "ConfigData.hxx"
#include "tag/TagBuilder.hxx" #include "tag/TagBuilder.hxx"
...@@ -220,12 +221,14 @@ ProxyDatabase::ReturnSong(Song *song) const ...@@ -220,12 +221,14 @@ ProxyDatabase::ReturnSong(Song *song) const
static bool static bool
Visit(struct mpd_connection *connection, const char *uri, 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); VisitPlaylist visit_playlist, Error &error);
static bool static bool
Visit(struct mpd_connection *connection, 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, VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist, Error &error) VisitPlaylist visit_playlist, Error &error)
{ {
...@@ -240,7 +243,7 @@ Visit(struct mpd_connection *connection, ...@@ -240,7 +243,7 @@ Visit(struct mpd_connection *connection,
} }
if (recursive && if (recursive &&
!Visit(connection, path, recursive, !Visit(connection, path, recursive, filter,
visit_directory, visit_song, visit_playlist, error)) visit_directory, visit_song, visit_playlist, error))
return false; return false;
...@@ -281,15 +284,23 @@ Convert(const struct mpd_song *song) ...@@ -281,15 +284,23 @@ Convert(const struct mpd_song *song)
return s; return s;
} }
gcc_pure
static bool
Match(const SongFilter *filter, const Song &song)
{
return filter == nullptr || filter->Match(song);
}
static bool static bool
Visit(const struct mpd_song *song, Visit(const SongFilter *filter,
const struct mpd_song *song,
VisitSong visit_song, Error &error) VisitSong visit_song, Error &error)
{ {
if (!visit_song) if (!visit_song)
return true; return true;
Song *s = Convert(song); Song *s = Convert(song);
bool success = visit_song(*s, error); bool success = !Match(filter, *s) || visit_song(*s, error);
s->Free(); s->Free();
return success; return success;
...@@ -348,7 +359,8 @@ ReceiveEntities(struct mpd_connection *connection) ...@@ -348,7 +359,8 @@ ReceiveEntities(struct mpd_connection *connection)
static bool static bool
Visit(struct mpd_connection *connection, const char *uri, 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) VisitPlaylist visit_playlist, Error &error)
{ {
if (!mpd_send_list_meta(connection, uri)) if (!mpd_send_list_meta(connection, uri))
...@@ -364,7 +376,7 @@ Visit(struct mpd_connection *connection, const char *uri, ...@@ -364,7 +376,7 @@ Visit(struct mpd_connection *connection, const char *uri,
break; break;
case MPD_ENTITY_TYPE_DIRECTORY: case MPD_ENTITY_TYPE_DIRECTORY:
if (!Visit(connection, recursive, if (!Visit(connection, recursive, filter,
mpd_entity_get_directory(entity), mpd_entity_get_directory(entity),
visit_directory, visit_song, visit_playlist, visit_directory, visit_song, visit_playlist,
error)) error))
...@@ -372,7 +384,8 @@ Visit(struct mpd_connection *connection, const char *uri, ...@@ -372,7 +384,8 @@ Visit(struct mpd_connection *connection, const char *uri,
break; break;
case MPD_ENTITY_TYPE_SONG: 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)) error))
return false; return false;
break; break;
...@@ -398,7 +411,8 @@ ProxyDatabase::Visit(const DatabaseSelection &selection, ...@@ -398,7 +411,8 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
// TODO: match // TODO: match
// TODO: auto-reconnect // 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, visit_directory, visit_song, visit_playlist,
error); error);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment