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