input/Plugin: migrate open() from class Error to C++ exceptions

This commit is contained in:
Max Kellermann
2016-09-09 15:37:06 +02:00
parent 63ab7767a3
commit fc7d3f64c0
44 changed files with 359 additions and 461 deletions

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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

View File

@@ -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();