diff options
author | Max Kellermann <max@duempel.org> | 2014-02-07 00:29:07 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-07 00:42:14 +0100 |
commit | c13810ebaa7075284691eb2add089ba407dfd1ea (patch) | |
tree | 1ebeb2104ee4a3e73f49416267aec2e79943821b /src/db | |
parent | 19a982cf693e660ce296a29a9830f1e94d9f1b4c (diff) | |
download | mpd-c13810ebaa7075284691eb2add089ba407dfd1ea.tar.gz mpd-c13810ebaa7075284691eb2add089ba407dfd1ea.tar.xz mpd-c13810ebaa7075284691eb2add089ba407dfd1ea.zip |
Mapper: move map_song_detach() to db/DatabaseSong.cxx
Use Storage::MapUTF8() internally, don't use global variables.
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/DatabasePlaylist.cxx | 13 | ||||
-rw-r--r-- | src/db/DatabasePlaylist.hxx | 5 | ||||
-rw-r--r-- | src/db/DatabaseQueue.cxx | 7 | ||||
-rw-r--r-- | src/db/DatabaseSong.cxx | 23 | ||||
-rw-r--r-- | src/db/DatabaseSong.hxx | 13 |
5 files changed, 47 insertions, 14 deletions
diff --git a/src/db/DatabasePlaylist.cxx b/src/db/DatabasePlaylist.cxx index 814901227..90a7f7b1a 100644 --- a/src/db/DatabasePlaylist.cxx +++ b/src/db/DatabasePlaylist.cxx @@ -19,24 +19,26 @@ #include "config.h" #include "DatabasePlaylist.hxx" +#include "DatabaseSong.hxx" #include "Selection.hxx" #include "PlaylistFile.hxx" #include "DatabasePlugin.hxx" #include "DetachedSong.hxx" -#include "Mapper.hxx" +#include "storage/StorageInterface.hxx" #include <functional> static bool -AddSong(const char *playlist_path_utf8, +AddSong(const Storage &storage, const char *playlist_path_utf8, const LightSong &song, Error &error) { - return spl_append_song(playlist_path_utf8, map_song_detach(song), + return spl_append_song(playlist_path_utf8, + DatabaseDetachSong(storage, song), error); } bool -search_add_to_playlist(const Database &db, +search_add_to_playlist(const Database &db, const Storage &storage, const char *uri, const char *playlist_path_utf8, const SongFilter *filter, Error &error) @@ -44,6 +46,7 @@ search_add_to_playlist(const Database &db, const DatabaseSelection selection(uri, true, filter); using namespace std::placeholders; - const auto f = std::bind(AddSong, playlist_path_utf8, _1, _2); + const auto f = std::bind(AddSong, std::ref(storage), + playlist_path_utf8, _1, _2); return db.Visit(selection, f, error); } diff --git a/src/db/DatabasePlaylist.hxx b/src/db/DatabasePlaylist.hxx index 5feafa190..9dc3526bb 100644 --- a/src/db/DatabasePlaylist.hxx +++ b/src/db/DatabasePlaylist.hxx @@ -23,12 +23,13 @@ #include "Compiler.h" class Database; +class Storage; class SongFilter; class Error; -gcc_nonnull(2,3) +gcc_nonnull(3,4) bool -search_add_to_playlist(const Database &db, +search_add_to_playlist(const Database &db, const Storage &storage, const char *uri, const char *path_utf8, const SongFilter *filter, Error &error); diff --git a/src/db/DatabaseQueue.cxx b/src/db/DatabaseQueue.cxx index f2a0951a6..77fd57fe3 100644 --- a/src/db/DatabaseQueue.cxx +++ b/src/db/DatabaseQueue.cxx @@ -19,22 +19,23 @@ #include "config.h" #include "DatabaseQueue.hxx" -#include "DatabaseGlue.hxx" +#include "DatabaseSong.hxx" #include "DatabasePlugin.hxx" #include "Partition.hxx" #include "Instance.hxx" #include "util/Error.hxx" #include "DetachedSong.hxx" -#include "Mapper.hxx" #include <functional> static bool AddToQueue(Partition &partition, const LightSong &song, Error &error) { + const Storage &storage = *partition.instance.storage; PlaylistResult result = partition.playlist.AppendSong(partition.pc, - map_song_detach(song), + DatabaseDetachSong(storage, + song), nullptr); if (result != PlaylistResult::SUCCESS) { error.Set(playlist_domain, int(result), "Playlist error"); diff --git a/src/db/DatabaseSong.cxx b/src/db/DatabaseSong.cxx index f6229194b..d9adad7a0 100644 --- a/src/db/DatabaseSong.cxx +++ b/src/db/DatabaseSong.cxx @@ -19,18 +19,35 @@ #include "config.h" #include "DatabaseSong.hxx" +#include "LightSong.hxx" #include "DatabasePlugin.hxx" #include "DetachedSong.hxx" -#include "Mapper.hxx" +#include "storage/StorageInterface.hxx" + +DetachedSong +DatabaseDetachSong(const Storage &storage, const LightSong &song) +{ + DetachedSong detached(song); + assert(detached.IsInDatabase()); + + if (!detached.HasRealURI()) { + const auto uri = song.GetURI(); + detached.SetRealURI(storage.MapUTF8(uri.c_str())); + } + + return detached; +} DetachedSong * -DatabaseDetachSong(const Database &db, const char *uri, Error &error) +DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri, + Error &error) { const LightSong *tmp = db.GetSong(uri, error); if (tmp == nullptr) return nullptr; - DetachedSong *song = new DetachedSong(map_song_detach(*tmp)); + DetachedSong *song = new DetachedSong(DatabaseDetachSong(storage, + *tmp)); db.ReturnSong(tmp); return song; } diff --git a/src/db/DatabaseSong.hxx b/src/db/DatabaseSong.hxx index 1197068bc..4daaf4047 100644 --- a/src/db/DatabaseSong.hxx +++ b/src/db/DatabaseSong.hxx @@ -22,11 +22,21 @@ #include "Compiler.h" +struct LightSong; class Database; +class Storage; class DetachedSong; class Error; /** + * "Detach" the #Song object, i.e. convert it to a #DetachedSong + * instance. + */ +gcc_pure +DetachedSong +DatabaseDetachSong(const Storage &storage, const LightSong &song); + +/** * Look up a song in the database and convert it to a #DetachedSong * instance. The caller is responsible for freeing it. * @@ -34,6 +44,7 @@ class Error; */ gcc_malloc gcc_nonnull_all DetachedSong * -DatabaseDetachSong(const Database &db, const char *uri, Error &error); +DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri, + Error &error); #endif |