client/Response: new Client wrapper class for writing responses
This commit is contained in:
@@ -28,48 +28,51 @@
|
||||
#include "fs/Traits.hxx"
|
||||
#include "thread/Mutex.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
#include "client/Client.hxx"
|
||||
#include "Partition.hxx"
|
||||
#include "Instance.hxx"
|
||||
|
||||
static void
|
||||
playlist_provider_print(Client &client, const char *uri,
|
||||
playlist_provider_print(Response &r, Partition &partition,
|
||||
const SongLoader &loader,
|
||||
const char *uri,
|
||||
SongEnumerator &e, bool detail)
|
||||
{
|
||||
const std::string base_uri = uri != nullptr
|
||||
? PathTraitsUTF8::GetParent(uri)
|
||||
: std::string(".");
|
||||
|
||||
const SongLoader loader(client);
|
||||
|
||||
DetachedSong *song;
|
||||
while ((song = e.NextSong()) != nullptr) {
|
||||
if (playlist_check_translate_song(*song, base_uri.c_str(),
|
||||
loader) &&
|
||||
detail)
|
||||
song_print_info(client, *song);
|
||||
song_print_info(r, partition, *song);
|
||||
else
|
||||
/* fallback if no detail was requested or no
|
||||
detail was available */
|
||||
song_print_uri(client, *song);
|
||||
song_print_uri(r, partition, *song);
|
||||
|
||||
delete song;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
playlist_file_print(Client &client, const char *uri, bool detail)
|
||||
playlist_file_print(Response &r, Partition &partition,
|
||||
const SongLoader &loader,
|
||||
const char *uri, bool detail)
|
||||
{
|
||||
Mutex mutex;
|
||||
Cond cond;
|
||||
|
||||
SongEnumerator *playlist = playlist_open_any(uri,
|
||||
#ifdef ENABLE_DATABASE
|
||||
client.GetStorage(),
|
||||
partition.instance.storage,
|
||||
#endif
|
||||
mutex, cond);
|
||||
if (playlist == nullptr)
|
||||
return false;
|
||||
|
||||
playlist_provider_print(client, uri, *playlist, detail);
|
||||
playlist_provider_print(r, partition, loader, uri, *playlist, detail);
|
||||
delete playlist;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,17 +20,20 @@
|
||||
#ifndef MPD_PLAYLIST__PRINT_HXX
|
||||
#define MPD_PLAYLIST__PRINT_HXX
|
||||
|
||||
class Client;
|
||||
class Response;
|
||||
class SongLoader;
|
||||
struct Partition;
|
||||
|
||||
/**
|
||||
* Send the playlist file to the client.
|
||||
*
|
||||
* @param client the client which requested the playlist
|
||||
* @param uri the URI of the playlist file in UTF-8 encoding
|
||||
* @param detail true if all details should be printed
|
||||
* @return true on success, false if the playlist does not exist
|
||||
*/
|
||||
bool
|
||||
playlist_file_print(Client &client, const char *uri, bool detail);
|
||||
playlist_file_print(Response &r, Partition &partition,
|
||||
const SongLoader &loader,
|
||||
const char *uri, bool detail);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user