Merge remote-tracking branches 'neheb/bind', 'neheb/move' and 'neheb/str'

This commit is contained in:
Max Kellermann 2020-02-04 17:03:49 +01:00
commit 7bcccbedad
17 changed files with 50 additions and 46 deletions

View File

@ -91,7 +91,7 @@ class ZzipInputStream final : public InputStream {
ZZIP_FILE *const file; ZZIP_FILE *const file;
public: public:
ZzipInputStream(const std::shared_ptr<ZzipDir> _dir, const char *_uri, ZzipInputStream(const std::shared_ptr<ZzipDir>& _dir, const char *_uri,
Mutex &_mutex, Mutex &_mutex,
ZZIP_FILE *_file) ZZIP_FILE *_file)
:InputStream(_uri, _mutex), :InputStream(_uri, _mutex),

View File

@ -82,7 +82,7 @@ ToAck(DatabaseErrorCode code) noexcept
gcc_pure gcc_pure
static enum ack static enum ack
ToAck(std::exception_ptr ep) noexcept ToAck(const std::exception_ptr& ep) noexcept
{ {
try { try {
std::rethrow_exception(ep); std::rethrow_exception(ep);
@ -113,7 +113,7 @@ ToAck(std::exception_ptr ep) noexcept
} }
void void
PrintError(Response &r, std::exception_ptr ep) PrintError(Response &r, const std::exception_ptr& ep)
{ {
LogError(ep); LogError(ep);
r.Error(ToAck(ep), GetFullMessage(ep).c_str()); r.Error(ToAck(ep), GetFullMessage(ep).c_str());

View File

@ -28,6 +28,6 @@ class Response;
* Send the exception to the client. * Send the exception to the client.
*/ */
void void
PrintError(Response &r, std::exception_ptr ep); PrintError(Response &r, const std::exception_ptr& ep);
#endif #endif

View File

@ -39,7 +39,6 @@ search_add_to_playlist(const Database &db, const Storage *storage,
const DatabaseSelection &selection) const DatabaseSelection &selection)
{ {
using namespace std::placeholders; using namespace std::placeholders;
const auto f = std::bind(AddSong, storage, const auto f = [=](auto && arg1) { return AddSong(storage, playlist_path_utf8, arg1); };
playlist_path_utf8, _1);
db.Visit(selection, f); db.Visit(selection, f);
} }

View File

@ -50,8 +50,9 @@
#include <mpd/async.h> #include <mpd/async.h>
#include <cassert> #include <cassert>
#include <string>
#include <list> #include <list>
#include <string>
#include <utility>
class LibmpdclientError final : public std::runtime_error { class LibmpdclientError final : public std::runtime_error {
enum mpd_error code; enum mpd_error code;
@ -674,15 +675,15 @@ ProxyDatabase::ReturnSong(const LightSong *_song) const noexcept
static void static void
Visit(struct mpd_connection *connection, const char *uri, Visit(struct mpd_connection *connection, const char *uri,
bool recursive, const SongFilter *filter, bool recursive, const SongFilter *filter,
VisitDirectory visit_directory, VisitSong visit_song, const VisitDirectory& visit_directory, const VisitSong& visit_song,
VisitPlaylist visit_playlist); const VisitPlaylist& visit_playlist);
static void static void
Visit(struct mpd_connection *connection, Visit(struct mpd_connection *connection,
bool recursive, const SongFilter *filter, bool recursive, const SongFilter *filter,
const struct mpd_directory *directory, const struct mpd_directory *directory,
VisitDirectory visit_directory, VisitSong visit_song, const VisitDirectory& visit_directory, const VisitSong& visit_song,
VisitPlaylist visit_playlist) const VisitPlaylist& visit_playlist)
{ {
const char *path = mpd_directory_get_path(directory); const char *path = mpd_directory_get_path(directory);
@ -697,7 +698,7 @@ Visit(struct mpd_connection *connection,
if (recursive) if (recursive)
Visit(connection, path, recursive, filter, Visit(connection, path, recursive, filter,
visit_directory, visit_song, visit_playlist); visit_directory, std::move(visit_song), std::move(visit_playlist));
} }
gcc_pure gcc_pure
@ -710,7 +711,7 @@ Match(const SongFilter *filter, const LightSong &song) noexcept
static void static void
Visit(const SongFilter *filter, Visit(const SongFilter *filter,
const mpd_song *_song, const mpd_song *_song,
VisitSong visit_song) const VisitSong& visit_song)
{ {
if (!visit_song) if (!visit_song)
return; return;
@ -722,7 +723,7 @@ Visit(const SongFilter *filter,
static void static void
Visit(const struct mpd_playlist *playlist, Visit(const struct mpd_playlist *playlist,
VisitPlaylist visit_playlist) const VisitPlaylist& visit_playlist)
{ {
if (!visit_playlist) if (!visit_playlist)
return; return;
@ -778,8 +779,8 @@ ReceiveEntities(struct mpd_connection *connection) noexcept
static void static void
Visit(struct mpd_connection *connection, const char *uri, Visit(struct mpd_connection *connection, const char *uri,
bool recursive, const SongFilter *filter, bool recursive, const SongFilter *filter,
VisitDirectory visit_directory, VisitSong visit_song, const VisitDirectory& visit_directory, const VisitSong& visit_song,
VisitPlaylist visit_playlist) const VisitPlaylist& visit_playlist)
{ {
if (!mpd_send_list_meta(connection, uri)) if (!mpd_send_list_meta(connection, uri))
ThrowError(connection); ThrowError(connection);
@ -813,7 +814,7 @@ Visit(struct mpd_connection *connection, const char *uri,
static void static void
SearchSongs(struct mpd_connection *connection, SearchSongs(struct mpd_connection *connection,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitSong visit_song) const VisitSong& visit_song)
try { try {
assert(selection.recursive); assert(selection.recursive);
assert(visit_song); assert(visit_song);

View File

@ -220,8 +220,8 @@ Directory::Sort() noexcept
void void
Directory::Walk(bool recursive, const SongFilter *filter, Directory::Walk(bool recursive, const SongFilter *filter,
VisitDirectory visit_directory, VisitSong visit_song, const VisitDirectory& visit_directory, const VisitSong& visit_song,
VisitPlaylist visit_playlist) const const VisitPlaylist& visit_playlist) const
{ {
if (IsMount()) { if (IsMount()) {
assert(IsEmpty()); assert(IsEmpty());

View File

@ -284,8 +284,8 @@ public:
* Caller must lock #db_mutex. * Caller must lock #db_mutex.
*/ */
void Walk(bool recursive, const SongFilter *match, void Walk(bool recursive, const SongFilter *match,
VisitDirectory visit_directory, VisitSong visit_song, const VisitDirectory& visit_directory, const VisitSong& visit_song,
VisitPlaylist visit_playlist) const; const VisitPlaylist& visit_playlist) const;
gcc_pure gcc_pure
LightDirectory Export() const noexcept; LightDirectory Export() const noexcept;

View File

@ -41,6 +41,7 @@
#include "util/SplitString.hxx" #include "util/SplitString.hxx"
#include <string> #include <string>
#include <utility>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -107,9 +108,9 @@ private:
void VisitServer(const ContentDirectoryService &server, void VisitServer(const ContentDirectoryService &server,
std::forward_list<std::string> &&vpath, std::forward_list<std::string> &&vpath,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitDirectory visit_directory, const VisitDirectory& visit_directory,
VisitSong visit_song, const VisitSong& visit_song,
VisitPlaylist visit_playlist) const; const VisitPlaylist& visit_playlist) const;
/** /**
* Run an UPnP search according to MPD parameters, and * Run an UPnP search according to MPD parameters, and
@ -118,7 +119,7 @@ private:
void SearchSongs(const ContentDirectoryService &server, void SearchSongs(const ContentDirectoryService &server,
const char *objid, const char *objid,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitSong visit_song) const; const VisitSong& visit_song) const;
UPnPDirContent SearchSongs(const ContentDirectoryService &server, UPnPDirContent SearchSongs(const ContentDirectoryService &server,
const char *objid, const char *objid,
@ -311,7 +312,7 @@ UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
static void static void
visitSong(const UPnPDirObject &meta, const char *path, visitSong(const UPnPDirObject &meta, const char *path,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitSong visit_song) const VisitSong& visit_song)
{ {
if (!visit_song) if (!visit_song)
return; return;
@ -339,7 +340,7 @@ void
UpnpDatabase::SearchSongs(const ContentDirectoryService &server, UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
const char *objid, const char *objid,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitSong visit_song) const const VisitSong& visit_song) const
{ {
if (!visit_song) if (!visit_song)
return; return;
@ -440,13 +441,13 @@ UpnpDatabase::Namei(const ContentDirectoryService &server,
static void static void
VisitItem(const UPnPDirObject &object, const char *uri, VisitItem(const UPnPDirObject &object, const char *uri,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitSong visit_song, VisitPlaylist visit_playlist) const VisitSong& visit_song, const VisitPlaylist& visit_playlist)
{ {
assert(object.type == UPnPDirObject::Type::ITEM); assert(object.type == UPnPDirObject::Type::ITEM);
switch (object.item_class) { switch (object.item_class) {
case UPnPDirObject::ItemClass::MUSIC: case UPnPDirObject::ItemClass::MUSIC:
visitSong(object, uri, selection, visit_song); visitSong(object, uri, selection, std::move(visit_song));
break; break;
case UPnPDirObject::ItemClass::PLAYLIST: case UPnPDirObject::ItemClass::PLAYLIST:
@ -469,9 +470,9 @@ VisitItem(const UPnPDirObject &object, const char *uri,
static void static void
VisitObject(const UPnPDirObject &object, const char *uri, VisitObject(const UPnPDirObject &object, const char *uri,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitDirectory visit_directory, const VisitDirectory& visit_directory,
VisitSong visit_song, const VisitSong& visit_song,
VisitPlaylist visit_playlist) const VisitPlaylist& visit_playlist)
{ {
switch (object.type) { switch (object.type) {
case UPnPDirObject::Type::UNKNOWN: case UPnPDirObject::Type::UNKNOWN:
@ -486,7 +487,7 @@ VisitObject(const UPnPDirObject &object, const char *uri,
case UPnPDirObject::Type::ITEM: case UPnPDirObject::Type::ITEM:
VisitItem(object, uri, selection, VisitItem(object, uri, selection,
visit_song, visit_playlist); std::move(visit_song), std::move(visit_playlist));
break; break;
} }
} }
@ -497,9 +498,9 @@ void
UpnpDatabase::VisitServer(const ContentDirectoryService &server, UpnpDatabase::VisitServer(const ContentDirectoryService &server,
std::forward_list<std::string> &&vpath, std::forward_list<std::string> &&vpath,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitDirectory visit_directory, const VisitDirectory& visit_directory,
VisitSong visit_song, const VisitSong& visit_song,
VisitPlaylist visit_playlist) const const VisitPlaylist& visit_playlist) const
{ {
/* If the path begins with rootid, we know that this is a /* If the path begins with rootid, we know that this is a
song, not a directory (because that's how we set things song, not a directory (because that's how we set things

View File

@ -30,11 +30,13 @@
#include <nfsc/libnfs-raw-nfs.h> #include <nfsc/libnfs-raw-nfs.h>
#endif #endif
#include <utility>
bool bool
IsFileNotFound(std::exception_ptr ep) noexcept IsFileNotFound(std::exception_ptr ep) noexcept
{ {
try { try {
std::rethrow_exception(ep); std::rethrow_exception(std::move(ep));
} catch (const std::system_error &e) { } catch (const std::system_error &e) {
return IsFileNotFound(e); return IsFileNotFound(e);
#ifdef ENABLE_CURL #ifdef ENABLE_CURL

View File

@ -65,7 +65,7 @@ public:
} }
private: private:
void Failed(std::exception_ptr e) { void Failed(const std::exception_ptr& e) {
SetInput(std::make_unique<FailingInputStream>(GetURI(), e, SetInput(std::make_unique<FailingInputStream>(GetURI(), e,
mutex)); mutex));
} }

View File

@ -35,6 +35,7 @@
#include "Log.hxx" #include "Log.hxx"
#include <memory> #include <memory>
#include <utility>
static constexpr Domain tidal_domain("tidal"); static constexpr Domain tidal_domain("tidal");
@ -77,7 +78,7 @@ public:
} }
private: private:
void Failed(std::exception_ptr e) { void Failed(const std::exception_ptr& e) {
SetInput(std::make_unique<FailingInputStream>(GetURI(), e, SetInput(std::make_unique<FailingInputStream>(GetURI(), e,
mutex)); mutex));
} }
@ -133,7 +134,7 @@ static bool
IsInvalidSession(std::exception_ptr e) noexcept IsInvalidSession(std::exception_ptr e) noexcept
{ {
try { try {
std::rethrow_exception(e); std::rethrow_exception(std::move(e));
} catch (const TidalError &te) { } catch (const TidalError &te) {
return te.IsInvalidSession(); return te.IsInvalidSession();
} catch (...) { } catch (...) {

View File

@ -37,7 +37,7 @@ ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device,
m_modelName(device.modelName), m_modelName(device.modelName),
m_rdreqcnt(200) m_rdreqcnt(200)
{ {
if (!m_modelName.compare("MediaTomb")) { if (m_modelName == "MediaTomb") {
// Readdir by 200 entries is good for most, but MediaTomb likes // Readdir by 200 entries is good for most, but MediaTomb likes
// them really big. Actually 1000 is better but I don't dare // them really big. Actually 1000 is better but I don't dare
m_rdreqcnt = 500; m_rdreqcnt = 500;

View File

@ -94,5 +94,5 @@ DsdToDopConverter::Convert(ConstBuffer<uint8_t> src) noexcept
{ {
using namespace std::placeholders; using namespace std::placeholders;
return rest_buffer.Process<uint32_t>(buffer, src, 2 * channels, return rest_buffer.Process<uint32_t>(buffer, src, 2 * channels,
std::bind(DsdToDop, _1, _2, _3, channels)); [=](auto && arg1, auto && arg2, auto && arg3) { return DsdToDop(arg1, arg2, arg3, channels); });
} }

View File

@ -65,5 +65,5 @@ Dsd16Converter::Convert(ConstBuffer<uint8_t> src) noexcept
{ {
using namespace std::placeholders; using namespace std::placeholders;
return rest_buffer.Process<uint16_t>(buffer, src, channels, return rest_buffer.Process<uint16_t>(buffer, src, channels,
std::bind(Dsd8To16, _1, _2, _3, channels)); [=](auto && arg1, auto && arg2, auto && arg3) { return Dsd8To16(arg1, arg2, arg3, channels); });
} }

View File

@ -67,5 +67,5 @@ Dsd32Converter::Convert(ConstBuffer<uint8_t> src) noexcept
{ {
using namespace std::placeholders; using namespace std::placeholders;
return rest_buffer.Process<uint32_t>(buffer, src, channels, return rest_buffer.Process<uint32_t>(buffer, src, channels,
std::bind(Dsd8To32, _1, _2, _3, channels)); [=](auto && arg1, auto && arg2, auto && arg3) { return Dsd8To32(arg1, arg2, arg3, channels); });
} }

View File

@ -38,7 +38,7 @@ struct ApeFooter {
}; };
bool bool
tag_ape_scan(InputStream &is, ApeTagCallback callback) tag_ape_scan(InputStream &is, const ApeTagCallback& callback)
try { try {
std::unique_lock<Mutex> lock(is.mutex); std::unique_lock<Mutex> lock(is.mutex);

View File

@ -37,6 +37,6 @@ typedef std::function<bool(unsigned long flags, const char *key,
* present * present
*/ */
bool bool
tag_ape_scan(InputStream &is, ApeTagCallback callback); tag_ape_scan(InputStream &is, const ApeTagCallback& callback);
#endif #endif