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

@@ -258,7 +258,7 @@ void decoder_seek_error(Decoder & decoder)
}
InputStreamPtr
decoder_open_uri(Decoder &decoder, const char *uri, Error &error)
decoder_open_uri(Decoder &decoder, const char *uri)
{
assert(decoder.dc.state == DecoderState::START ||
decoder.dc.state == DecoderState::DECODE);
@@ -267,9 +267,7 @@ decoder_open_uri(Decoder &decoder, const char *uri, Error &error)
Mutex &mutex = dc.mutex;
Cond &cond = dc.cond;
auto is = InputStream::Open(uri, mutex, cond, error);
if (!is)
return nullptr;
auto is = InputStream::Open(uri, mutex, cond);
const ScopeLock lock(mutex);
while (true) {

View File

@@ -121,11 +121,12 @@ decoder_seek_error(Decoder &decoder);
/**
* Open a new #InputStream and wait until it's ready. Can get
* cancelled by DecoderCommand::STOP (returns nullptr without setting
* #Error).
* cancelled by DecoderCommand::STOP (returns nullptr).
*
* Throws std::runtime_error on error.
*/
InputStreamPtr
decoder_open_uri(Decoder &decoder, const char *uri, Error &error);
decoder_open_uri(Decoder &decoder, const char *uri);
/**
* Blocking read from the input stream.

View File

@@ -56,10 +56,7 @@ static constexpr Domain decoder_thread_domain("decoder_thread");
static InputStreamPtr
decoder_input_stream_open(DecoderControl &dc, const char *uri)
{
Error error;
auto is = InputStream::Open(uri, dc.mutex, dc.cond, error);
if (is == nullptr)
throw error;
auto is = InputStream::Open(uri, dc.mutex, dc.cond);
/* wait for the input stream to become ready; its metadata
will be available then */
@@ -76,6 +73,7 @@ decoder_input_stream_open(DecoderControl &dc, const char *uri)
is->Update();
}
Error error;
if (!is->Check(error))
throw error;
@@ -85,10 +83,7 @@ decoder_input_stream_open(DecoderControl &dc, const char *uri)
static InputStreamPtr
decoder_input_stream_open(DecoderControl &dc, Path path)
{
Error error;
auto is = OpenLocalInputStream(path, dc.mutex, dc.cond, error);
if (is == nullptr)
throw error;
auto is = OpenLocalInputStream(path, dc.mutex, dc.cond);
assert(is->IsReady());

View File

@@ -34,6 +34,8 @@
#include <wavpack/wavpack.h>
#include <stdexcept>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -490,7 +492,11 @@ wavpack_open_wvc(Decoder &decoder, const char *uri)
free(wvc_url);
};
return decoder_open_uri(decoder, uri, IgnoreError());
try {
return decoder_open_uri(decoder, uri);
} catch (const std::runtime_error &) {
return nullptr;
}
}
/*