db/Print: move sort/window emulation code to class DatabaseVisitorHelper

That way, each plugin can decide to implement it better.
This commit is contained in:
Max Kellermann
2018-09-02 12:35:10 +02:00
parent 53170ca2f2
commit c7c32a3ce9
7 changed files with 248 additions and 92 deletions

View File

@@ -23,6 +23,7 @@
#include "db/DatabasePlugin.hxx"
#include "db/DatabaseListener.hxx"
#include "db/Selection.hxx"
#include "db/VHelper.hxx"
#include "db/DatabaseError.hxx"
#include "db/PlaylistInfo.hxx"
#include "db/LightDirectory.hxx"
@@ -804,6 +805,15 @@ try {
throw;
}
gcc_const
static DatabaseSelection
CheckSelection(DatabaseSelection selection) noexcept
{
selection.uri.clear();
selection.filter = nullptr;
return selection;
}
void
ProxyDatabase::Visit(const DatabaseSelection &selection,
VisitDirectory visit_directory,
@@ -813,11 +823,14 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
// TODO: eliminate the const_cast
const_cast<ProxyDatabase *>(this)->EnsureConnected();
DatabaseVisitorHelper helper(CheckSelection(selection), visit_song);
if (!visit_directory && !visit_playlist && selection.recursive &&
!selection.IsEmpty()) {
/* this optimized code path can only be used under
certain conditions */
::SearchSongs(connection, selection, visit_song);
helper.Commit();
return;
}
@@ -825,6 +838,8 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
::Visit(connection, selection.uri.c_str(),
selection.recursive, selection.filter,
visit_directory, visit_song, visit_playlist);
helper.Commit();
}
void

View File

@@ -26,6 +26,7 @@
#include "db/Helpers.hxx"
#include "db/Stats.hxx"
#include "db/UniqueTags.hxx"
#include "db/VHelper.hxx"
#include "db/LightDirectory.hxx"
#include "Directory.hxx"
#include "Song.hxx"
@@ -265,6 +266,15 @@ SimpleDatabase::ReturnSong(gcc_unused const LightSong *song) const noexcept
}
}
gcc_const
static DatabaseSelection
CheckSelection(DatabaseSelection selection) noexcept
{
selection.uri.clear();
selection.filter = nullptr;
return selection;
}
void
SimpleDatabase::Visit(const DatabaseSelection &selection,
VisitDirectory visit_directory,
@@ -286,6 +296,8 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
return;
}
DatabaseVisitorHelper helper(CheckSelection(selection), visit_song);
if (r.uri == nullptr) {
/* it's a directory */
@@ -295,6 +307,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
r.directory->Walk(selection.recursive, selection.filter,
visit_directory, visit_song,
visit_playlist);
helper.Commit();
return;
}
@@ -306,6 +319,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
if (selection.Match(song2))
visit_song(song2);
helper.Commit();
return;
}
}

View File

@@ -27,6 +27,7 @@
#include "db/Interface.hxx"
#include "db/DatabasePlugin.hxx"
#include "db/Selection.hxx"
#include "db/VHelper.hxx"
#include "db/DatabaseError.hxx"
#include "db/LightDirectory.hxx"
#include "song/LightSong.hxx"
@@ -576,6 +577,15 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server,
}
}
gcc_const
static DatabaseSelection
CheckSelection(DatabaseSelection selection) noexcept
{
selection.uri.clear();
selection.filter = nullptr;
return selection;
}
// Deal with the possibly multiple servers, call VisitServer if needed.
void
UpnpDatabase::Visit(const DatabaseSelection &selection,
@@ -583,6 +593,8 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
VisitSong visit_song,
VisitPlaylist visit_playlist) const
{
DatabaseVisitorHelper helper(CheckSelection(selection), visit_song);
auto vpath = SplitString(selection.uri.c_str(), '/');
if (vpath.empty()) {
for (const auto &server : discovery->GetDirectories()) {
@@ -598,6 +610,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
visit_playlist);
}
helper.Commit();
return;
}
@@ -608,6 +621,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
auto server = discovery->GetServer(servername.c_str());
VisitServer(server, std::move(vpath), selection,
visit_directory, visit_song, visit_playlist);
helper.Commit();
}
void