summaryrefslogtreecommitdiff
path: root/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-10-29 10:04:43 +0200
committerMax Kellermann <max@musicpd.org>2016-10-29 10:04:43 +0200
commit3ff728ab02644ac4f84d4bc931ade91fc0667cc8 (patch)
treed63f4b148d5e243993a8ed606643eecfd9be3a2c /src/db/plugins/upnp/UpnpDatabasePlugin.cxx
parent78bf4ef5fa20cad2d91566ca82ad57de2dad0efb (diff)
db/Visitor: remove the Error parameter
Implementations shall use exceptions instead.
Diffstat (limited to 'src/db/plugins/upnp/UpnpDatabasePlugin.cxx')
-rw-r--r--src/db/plugins/upnp/UpnpDatabasePlugin.cxx137
1 files changed, 58 insertions, 79 deletions
diff --git a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
index 684ee4c40..702a37602 100644
--- a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
+++ b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx
@@ -103,23 +103,21 @@ public:
}
private:
- bool VisitServer(const ContentDirectoryService &server,
+ void VisitServer(const ContentDirectoryService &server,
const std::list<std::string> &vpath,
const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
- VisitPlaylist visit_playlist,
- Error &error) const;
+ VisitPlaylist visit_playlist) const;
/**
* Run an UPnP search according to MPD parameters, and
* visit_song the results.
*/
- bool SearchSongs(const ContentDirectoryService &server,
+ void SearchSongs(const ContentDirectoryService &server,
const char *objid,
const DatabaseSelection &selection,
- VisitSong visit_song,
- Error &error) const;
+ VisitSong visit_song) const;
UPnPDirContent SearchSongs(const ContentDirectoryService &server,
const char *objid,
@@ -307,13 +305,13 @@ UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
return server.search(handle, objid, cond.c_str());
}
-static bool
+static void
visitSong(const UPnPDirObject &meta, const char *path,
const DatabaseSelection &selection,
- VisitSong visit_song, Error& error)
+ VisitSong visit_song)
{
if (!visit_song)
- return true;
+ return;
LightSong song;
song.directory = nullptr;
@@ -323,7 +321,8 @@ visitSong(const UPnPDirObject &meta, const char *path,
song.mtime = 0;
song.start_time = song.end_time = SongTime::zero();
- return !selection.Match(song) || visit_song(song, error);
+ if (selection.Match(song))
+ visit_song(song);
}
/**
@@ -338,15 +337,14 @@ songPath(const std::string &servername,
return servername + "/" + rootid + "/" + objid;
}
-bool
+void
UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
const char *objid,
const DatabaseSelection &selection,
- VisitSong visit_song,
- Error &error) const
+ VisitSong visit_song) const
{
if (!visit_song)
- return true;
+ return;
for (auto &dirent : SearchSongs(server, objid, selection).objects) {
if (dirent.type != UPnPDirObject::Type::ITEM ||
@@ -371,13 +369,9 @@ UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
// which we later have to detect.
const std::string path = songPath(server.getFriendlyName(),
dirent.id);
- if (!visitSong(std::move(dirent), path.c_str(),
- selection, visit_song,
- error))
- return false;
+ visitSong(std::move(dirent), path.c_str(),
+ selection, visit_song);
}
-
- return true;
}
UPnPDirObject
@@ -444,19 +438,17 @@ UpnpDatabase::Namei(const ContentDirectoryService &server,
}
}
-static bool
+static void
VisitItem(const UPnPDirObject &object, const char *uri,
const DatabaseSelection &selection,
- VisitSong visit_song, VisitPlaylist visit_playlist,
- Error &error)
+ VisitSong visit_song, VisitPlaylist visit_playlist)
{
assert(object.type == UPnPDirObject::Type::ITEM);
switch (object.item_class) {
case UPnPDirObject::ItemClass::MUSIC:
- return !visit_song ||
- visitSong(object, uri,
- selection, visit_song, error);
+ visitSong(object, uri, selection, visit_song);
+ break;
case UPnPDirObject::ItemClass::PLAYLIST:
if (visit_playlist) {
@@ -468,23 +460,19 @@ VisitItem(const UPnPDirObject &object, const char *uri,
see one... */
}
- return true;
+ break;
case UPnPDirObject::ItemClass::UNKNOWN:
- return true;
+ break;
}
-
- assert(false);
- gcc_unreachable();
}
-static bool
+static void
VisitObject(const UPnPDirObject &object, const char *uri,
const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
- VisitPlaylist visit_playlist,
- Error &error)
+ VisitPlaylist visit_playlist)
{
switch (object.type) {
case UPnPDirObject::Type::UNKNOWN:
@@ -492,29 +480,26 @@ VisitObject(const UPnPDirObject &object, const char *uri,
gcc_unreachable();
case UPnPDirObject::Type::CONTAINER:
- return !visit_directory ||
- visit_directory(LightDirectory(uri, 0), error);
+ if (visit_directory)
+ visit_directory(LightDirectory(uri, 0));
+ break;
case UPnPDirObject::Type::ITEM:
- return VisitItem(object, uri, selection,
- visit_song, visit_playlist,
- error);
+ VisitItem(object, uri, selection,
+ visit_song, visit_playlist);
+ break;
}
-
- assert(false);
- gcc_unreachable();
}
// vpath is a parsed and writeable version of selection.uri. There is
// really just one path parameter.
-bool
+void
UpnpDatabase::VisitServer(const ContentDirectoryService &server,
const std::list<std::string> &vpath,
const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
- VisitPlaylist visit_playlist,
- Error &error) const
+ VisitPlaylist visit_playlist) const
{
/* If the path begins with rootid, we know that this is a
song, not a directory (because that's how we set things
@@ -527,7 +512,7 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server,
if (!vpath.empty() && vpath.front() == rootid) {
switch (vpath.size()) {
case 1:
- return true;
+ return;
case 2:
break;
@@ -547,12 +532,11 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server,
std::string path = songPath(server.getFriendlyName(),
dirent.id);
- if (!visitSong(std::move(dirent), path.c_str(),
- selection,
- visit_song, error))
- return false;
+ visitSong(std::move(dirent), path.c_str(),
+ selection, visit_song);
}
- return true;
+
+ return;
}
// Translate the target path into an object id and the associated metadata.
@@ -562,19 +546,20 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server,
if the filter is empty. In this case, we implement limited
recursion (1-deep) here, which will handle the "add dir"
case. */
- if (selection.recursive && selection.filter)
- return SearchSongs(server, tdirent.id.c_str(), selection,
- visit_song, error);
+ if (selection.recursive && selection.filter) {
+ SearchSongs(server, tdirent.id.c_str(), selection, visit_song);
+ return;
+ }
const char *const base_uri = selection.uri.empty()
? server.getFriendlyName()
: selection.uri.c_str();
if (tdirent.type == UPnPDirObject::Type::ITEM) {
- return VisitItem(tdirent, base_uri,
- selection,
- visit_song, visit_playlist,
- error);
+ VisitItem(tdirent, base_uri,
+ selection,
+ visit_song, visit_playlist);
+ return;
}
/* Target was a a container. Visit it. We could read slices
@@ -583,15 +568,11 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server,
for (const auto &dirent : server.readDir(handle, tdirent.id.c_str()).objects) {
const std::string uri = PathTraitsUTF8::Build(base_uri,
dirent.name.c_str());
- if (!VisitObject(dirent, uri.c_str(),
- selection,
- visit_directory,
- visit_song, visit_playlist,
- error))
- return false;
+ VisitObject(dirent, uri.c_str(),
+ selection,
+ visit_directory,
+ visit_song, visit_playlist);
}
-
- return true;
}
// Deal with the possibly multiple servers, call VisitServer if needed.
@@ -600,22 +581,20 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
VisitPlaylist visit_playlist,
- Error &error) const
+ Error &) const
{
auto vpath = stringToTokens(selection.uri, "/", true);
if (vpath.empty()) {
for (const auto &server : discovery->GetDirectories()) {
if (visit_directory) {
const LightDirectory d(server.getFriendlyName(), 0);
- if (!visit_directory(d, error))
- return false;
+ visit_directory(d);
}
- if (selection.recursive &&
- !VisitServer(server, vpath, selection,
- visit_directory, visit_song, visit_playlist,
- error))
- return false;
+ if (selection.recursive)
+ VisitServer(server, vpath, selection,
+ visit_directory, visit_song,
+ visit_playlist);
}
return true;
@@ -626,15 +605,16 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
vpath.pop_front();
auto server = discovery->GetServer(servername.c_str());
- return VisitServer(server, vpath, selection,
- visit_directory, visit_song, visit_playlist, error);
+ VisitServer(server, vpath, selection,
+ visit_directory, visit_song, visit_playlist);
+ return true;
}
bool
UpnpDatabase::VisitUniqueTags(const DatabaseSelection &selection,
TagType tag, gcc_unused tag_mask_t group_mask,
VisitTag visit_tag,
- Error &error) const
+ Error &) const
{
// TODO: use group_mask
@@ -664,8 +644,7 @@ UpnpDatabase::VisitUniqueTags(const DatabaseSelection &selection,
for (const auto& value : values) {
TagBuilder builder;
builder.AddItem(tag, value.c_str());
- if (!visit_tag(builder.Commit(), error))
- return false;
+ visit_tag(builder.Commit());
}
return true;