diff options
author | Max Kellermann <max@musicpd.org> | 2016-09-09 15:37:06 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2016-09-09 18:15:01 +0200 |
commit | fc7d3f64c007672e4c01172ccb1c46d083a8abd5 (patch) | |
tree | 3c72f16ee6cc919a17558678a1e270568182b8af /src/lib | |
parent | 63ab7767a37a99b5651f32e067aeb5fcbb7bd033 (diff) |
input/Plugin: migrate open() from class Error to C++ exceptions
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ffmpeg/Error.cxx | 8 | ||||
-rw-r--r-- | src/lib/ffmpeg/Error.hxx | 5 | ||||
-rw-r--r-- | src/lib/nfs/FileReader.cxx | 23 | ||||
-rw-r--r-- | src/lib/nfs/FileReader.hxx | 6 |
4 files changed, 26 insertions, 16 deletions
diff --git a/src/lib/ffmpeg/Error.cxx b/src/lib/ffmpeg/Error.cxx index 9dc193bfa..92608300f 100644 --- a/src/lib/ffmpeg/Error.cxx +++ b/src/lib/ffmpeg/Error.cxx @@ -26,6 +26,14 @@ extern "C" { #include <libavutil/error.h> } +std::runtime_error +MakeFfmpegError(int errnum) +{ + char msg[256]; + av_strerror(errnum, msg, sizeof(msg)); + return std::runtime_error(msg); +} + void SetFfmpegError(Error &error, int errnum) { diff --git a/src/lib/ffmpeg/Error.hxx b/src/lib/ffmpeg/Error.hxx index 7dc7fc550..3a6eb876d 100644 --- a/src/lib/ffmpeg/Error.hxx +++ b/src/lib/ffmpeg/Error.hxx @@ -20,8 +20,13 @@ #ifndef MPD_FFMPEG_ERROR_HXX #define MPD_FFMPEG_ERROR_HXX +#include <stdexcept> + class Error; +std::runtime_error +MakeFfmpegError(int errnum); + void SetFfmpegError(Error &error, int errnum); diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx index 523690de7..54b59e09a 100644 --- a/src/lib/nfs/FileReader.cxx +++ b/src/lib/nfs/FileReader.cxx @@ -91,23 +91,19 @@ NfsFileReader::DeferClose() BlockingCall(io_thread_get(), [this](){ Close(); }); } -bool -NfsFileReader::Open(const char *uri, Error &error) +void +NfsFileReader::Open(const char *uri) { assert(state == State::INITIAL); - if (!StringStartsWith(uri, "nfs://")) { - error.Set(nfs_domain, "Malformed nfs:// URI"); - return false; - } + if (!StringStartsWith(uri, "nfs://")) + throw std::runtime_error("Malformed nfs:// URI"); uri += 6; const char *slash = strchr(uri, '/'); - if (slash == nullptr) { - error.Set(nfs_domain, "Malformed nfs:// URI"); - return false; - } + if (slash == nullptr) + throw std::runtime_error("Malformed nfs:// URI"); server = std::string(uri, slash); @@ -121,10 +117,8 @@ NfsFileReader::Open(const char *uri, Error &error) path = new_path; } else { slash = strrchr(uri + 1, '/'); - if (slash == nullptr || slash[1] == 0) { - error.Set(nfs_domain, "Malformed nfs:// URI"); - return false; - } + if (slash == nullptr || slash[1] == 0) + throw std::runtime_error("Malformed nfs:// URI"); export_name = std::string(uri, slash); path = slash; @@ -132,7 +126,6 @@ NfsFileReader::Open(const char *uri, Error &error) state = State::DEFER; DeferredMonitor::Schedule(); - return true; } bool diff --git a/src/lib/nfs/FileReader.hxx b/src/lib/nfs/FileReader.hxx index ab88299cc..177fb66f2 100644 --- a/src/lib/nfs/FileReader.hxx +++ b/src/lib/nfs/FileReader.hxx @@ -61,7 +61,11 @@ public: void Close(); void DeferClose(); - bool Open(const char *uri, Error &error); + /** + * Throws std::runtime_error on error. + */ + void Open(const char *uri); + bool Read(uint64_t offset, size_t size, Error &error); void CancelRead(); |