Commit 297e2747 authored by Max Kellermann's avatar Max Kellermann

PlaylistMapper: use class Storage instead of Mapper.cxx

parent 77de2331
...@@ -60,6 +60,12 @@ public: ...@@ -60,6 +60,12 @@ public:
:client(nullptr) {} :client(nullptr) {}
#endif #endif
#ifdef ENABLE_DATABASE
const Storage *GetStorage() const {
return storage;
}
#endif
gcc_nonnull_all gcc_nonnull_all
DetachedSong *LoadSong(const char *uri_utf8, Error &error) const; DetachedSong *LoadSong(const char *uri_utf8, Error &error) const;
......
...@@ -24,9 +24,17 @@ ...@@ -24,9 +24,17 @@
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
SongEnumerator * SongEnumerator *
playlist_open_any(const char *uri, Mutex &mutex, Cond &cond) playlist_open_any(const char *uri,
#ifdef ENABLE_DATABASE
const Storage *storage,
#endif
Mutex &mutex, Cond &cond)
{ {
return uri_has_scheme(uri) return uri_has_scheme(uri)
? playlist_open_remote(uri, mutex, cond) ? playlist_open_remote(uri, mutex, cond)
: playlist_mapper_open(uri, mutex, cond); : playlist_mapper_open(uri,
#ifdef ENABLE_DATABASE
storage,
#endif
mutex, cond);
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
class Mutex; class Mutex;
class Cond; class Cond;
class SongEnumerator; class SongEnumerator;
class Storage;
/** /**
* Opens a playlist from the specified URI, which can be either an * Opens a playlist from the specified URI, which can be either an
...@@ -30,6 +31,10 @@ class SongEnumerator; ...@@ -30,6 +31,10 @@ class SongEnumerator;
* music orplaylist directory. * music orplaylist directory.
*/ */
SongEnumerator * SongEnumerator *
playlist_open_any(const char *uri, Mutex &mutex, Cond &cond); playlist_open_any(const char *uri,
#ifdef ENABLE_DATABASE
const Storage *storage,
#endif
Mutex &mutex, Cond &cond);
#endif #endif
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "Mapper.hxx" #include "Mapper.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "storage/StorageInterface.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include <assert.h> #include <assert.h>
...@@ -57,21 +58,32 @@ playlist_open_in_playlist_dir(const char *uri, Mutex &mutex, Cond &cond) ...@@ -57,21 +58,32 @@ playlist_open_in_playlist_dir(const char *uri, Mutex &mutex, Cond &cond)
* Load a playlist from the configured music directory. * Load a playlist from the configured music directory.
*/ */
static SongEnumerator * static SongEnumerator *
playlist_open_in_music_dir(const char *uri, Mutex &mutex, Cond &cond) playlist_open_in_storage(const char *uri, const Storage *storage,
Mutex &mutex, Cond &cond)
{ {
assert(uri_safe_local(uri)); assert(uri_safe_local(uri));
const auto path = map_uri_fs(uri); if (storage == nullptr)
if (path.IsNull())
return nullptr; return nullptr;
{
const auto path = storage->MapFS(uri);
if (!path.IsNull())
return playlist_open_path(path.c_str(), mutex, cond); return playlist_open_path(path.c_str(), mutex, cond);
}
const auto uri2 = storage->MapUTF8(uri);
return playlist_open_remote(uri, mutex, cond);
} }
#endif #endif
SongEnumerator * SongEnumerator *
playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond) playlist_mapper_open(const char *uri,
#ifdef ENABLE_DATABASE
const Storage *storage,
#endif
Mutex &mutex, Cond &cond)
{ {
if (spl_valid_name(uri)) { if (spl_valid_name(uri)) {
auto playlist = playlist_open_in_playlist_dir(uri, auto playlist = playlist_open_in_playlist_dir(uri,
...@@ -82,7 +94,8 @@ playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond) ...@@ -82,7 +94,8 @@ playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond)
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (uri_safe_local(uri)) { if (uri_safe_local(uri)) {
auto playlist = playlist_open_in_music_dir(uri, mutex, cond); auto playlist = playlist_open_in_storage(uri, storage,
mutex, cond);
if (playlist != nullptr) if (playlist != nullptr)
return playlist; return playlist;
} }
......
...@@ -20,15 +20,22 @@ ...@@ -20,15 +20,22 @@
#ifndef MPD_PLAYLIST_MAPPER_HXX #ifndef MPD_PLAYLIST_MAPPER_HXX
#define MPD_PLAYLIST_MAPPER_HXX #define MPD_PLAYLIST_MAPPER_HXX
#include "check.h"
class Mutex; class Mutex;
class Cond; class Cond;
class SongEnumerator; class SongEnumerator;
class Storage;
/** /**
* Opens a playlist from an URI relative to the playlist or music * Opens a playlist from an URI relative to the playlist or music
* directory. * directory.
*/ */
SongEnumerator * SongEnumerator *
playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond); playlist_mapper_open(const char *uri,
#ifdef ENABLE_DATABASE
const Storage *storage,
#endif
Mutex &mutex, Cond &cond);
#endif #endif
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#ifdef ENABLE_DATABASE
#include "SongLoader.hxx"
#endif
PlaylistResult PlaylistResult
playlist_load_into_queue(const char *uri, SongEnumerator &e, playlist_load_into_queue(const char *uri, SongEnumerator &e,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
...@@ -72,7 +76,11 @@ playlist_open_into_queue(const char *uri, ...@@ -72,7 +76,11 @@ playlist_open_into_queue(const char *uri,
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
auto playlist = playlist_open_any(uri, mutex, cond); auto playlist = playlist_open_any(uri,
#ifdef ENABLE_DATABASE
loader.GetStorage(),
#endif
mutex, cond);
if (playlist == nullptr) if (playlist == nullptr)
return PlaylistResult::NO_SUCH_LIST; return PlaylistResult::NO_SUCH_LIST;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "client/Client.hxx"
static void static void
playlist_provider_print(Client &client, const char *uri, playlist_provider_print(Client &client, const char *uri,
...@@ -59,7 +60,11 @@ playlist_file_print(Client &client, const char *uri, bool detail) ...@@ -59,7 +60,11 @@ playlist_file_print(Client &client, const char *uri, bool detail)
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
SongEnumerator *playlist = playlist_open_any(uri, mutex, cond); SongEnumerator *playlist = playlist_open_any(uri,
#ifdef ENABLE_DATABASE
client.GetStorage(),
#endif
mutex, cond);
if (playlist == nullptr) if (playlist == nullptr)
return false; return false;
......
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