db/upnp: move code to VisitObject()

This commit is contained in:
Max Kellermann 2014-01-23 00:28:27 +01:00
parent c455d2c1de
commit b61a2c722c

View File

@ -552,6 +552,33 @@ VisitItem(const UPnPDirObject &object, const char *uri,
gcc_unreachable(); gcc_unreachable();
} }
static bool
VisitObject(const UPnPDirObject &object, const char *uri,
const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
VisitPlaylist visit_playlist,
Error &error)
{
switch (object.type) {
case UPnPDirObject::Type::UNKNOWN:
assert(false);
gcc_unreachable();
case UPnPDirObject::Type::CONTAINER:
return !visit_directory ||
visit_directory(LightDirectory(uri, 0), error);
case UPnPDirObject::Type::ITEM:
return VisitItem(object, uri, selection,
visit_song, visit_playlist,
error);
}
assert(false);
gcc_unreachable();
}
// vpath is a parsed and writeable version of selection.uri. There is // vpath is a parsed and writeable version of selection.uri. There is
// really just one path parameter. // really just one path parameter.
bool bool
@ -623,28 +650,12 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server,
for (auto &dirent : dirbuf.objects) { for (auto &dirent : dirbuf.objects) {
const std::string uri = PathTraitsUTF8::Build(base_uri, const std::string uri = PathTraitsUTF8::Build(base_uri,
dirent.name.c_str()); dirent.name.c_str());
if (!VisitObject(dirent, uri.c_str(),
switch (dirent.type) { selection,
case UPnPDirObject::Type::UNKNOWN: visit_directory,
assert(false); visit_song, visit_playlist,
gcc_unreachable(); error))
return false;
case UPnPDirObject::Type::CONTAINER:
if (visit_directory) {
const LightDirectory d(uri.c_str(), 0);
if (!visit_directory(d, error))
return false;
}
break;
case UPnPDirObject::Type::ITEM:
if (!VisitItem(dirent, uri.c_str(),
selection,
visit_song, visit_playlist,
error))
return false;
}
} }
return true; return true;