input/Plugin: migrate open() from class Error to C++ exceptions
This commit is contained in:
@@ -74,9 +74,9 @@ decoder_seek_error(gcc_unused Decoder &decoder)
|
||||
}
|
||||
|
||||
InputStreamPtr
|
||||
decoder_open_uri(Decoder &decoder, const char *uri, Error &error)
|
||||
decoder_open_uri(Decoder &decoder, const char *uri)
|
||||
{
|
||||
return InputStream::OpenReady(uri, decoder.mutex, decoder.cond, error);
|
||||
return InputStream::OpenReady(uri, decoder.mutex, decoder.cond);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "input/InputStream.hxx"
|
||||
#include "input/LocalOpen.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "util/Error.hxx"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -49,7 +48,7 @@ MyApeTagCallback(gcc_unused unsigned long flags,
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
#ifdef HAVE_LOCALE_H
|
||||
/* initialize locale */
|
||||
setlocale(LC_CTYPE,"");
|
||||
@@ -65,12 +64,7 @@ main(int argc, char **argv)
|
||||
Mutex mutex;
|
||||
Cond cond;
|
||||
|
||||
Error error;
|
||||
auto is = OpenLocalInputStream(path, mutex, cond, error);
|
||||
if (!is) {
|
||||
LogError(error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auto is = OpenLocalInputStream(path, mutex, cond);
|
||||
|
||||
if (!tag_ape_scan(*is, MyApeTagCallback)) {
|
||||
fprintf(stderr, "error\n");
|
||||
@@ -78,4 +72,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} catch (const std::exception &e) {
|
||||
LogError(e);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@@ -31,7 +31,6 @@
|
||||
#include "fs/Path.hxx"
|
||||
#include "fs/io/BufferedOutputStream.hxx"
|
||||
#include "fs/io/StdioOutputStream.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
@@ -63,7 +62,6 @@ try {
|
||||
|
||||
config_global_init();
|
||||
|
||||
Error error;
|
||||
ReadConfigFile(config_path);
|
||||
|
||||
const ScopeIOThread io_thread;
|
||||
@@ -82,15 +80,7 @@ try {
|
||||
if (playlist == NULL) {
|
||||
/* open the stream and wait until it becomes ready */
|
||||
|
||||
is = InputStream::OpenReady(uri, mutex, cond, error);
|
||||
if (!is) {
|
||||
if (error.IsDefined())
|
||||
LogError(error);
|
||||
else
|
||||
fprintf(stderr,
|
||||
"InputStream::Open() failed\n");
|
||||
return 2;
|
||||
}
|
||||
is = InputStream::OpenReady(uri, mutex, cond);
|
||||
|
||||
/* open the playlist */
|
||||
|
||||
|
@@ -24,7 +24,6 @@
|
||||
#include "config/ConfigGlobal.hxx"
|
||||
#include "thread/Mutex.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
#include "input/LocalOpen.hxx"
|
||||
@@ -47,7 +46,7 @@ config_get_string(gcc_unused enum ConfigOption option,
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
#ifdef HAVE_LOCALE_H
|
||||
/* initialize locale */
|
||||
setlocale(LC_CTYPE,"");
|
||||
@@ -63,12 +62,7 @@ int main(int argc, char **argv)
|
||||
Mutex mutex;
|
||||
Cond cond;
|
||||
|
||||
Error error;
|
||||
auto is = OpenLocalInputStream(path, mutex, cond, error);
|
||||
if (!is) {
|
||||
LogError(error);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auto is = OpenLocalInputStream(path, mutex, cond);
|
||||
|
||||
const auto tag = tag_id3_load(*is);
|
||||
if (tag == NULL) {
|
||||
@@ -96,4 +90,7 @@ int main(int argc, char **argv)
|
||||
tuple->gain, tuple->peak);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} catch (const std::exception &e) {
|
||||
LogError(e);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@@ -83,7 +83,6 @@ try {
|
||||
archive_plugin_init_all();
|
||||
#endif
|
||||
|
||||
Error error;
|
||||
input_stream_global_init();
|
||||
|
||||
/* open the stream and dump it */
|
||||
@@ -92,16 +91,8 @@ try {
|
||||
Mutex mutex;
|
||||
Cond cond;
|
||||
|
||||
auto is = InputStream::OpenReady(argv[1], mutex, cond, error);
|
||||
if (is) {
|
||||
ret = dump_input_stream(std::move(is));
|
||||
} else {
|
||||
if (error.IsDefined())
|
||||
LogError(error);
|
||||
else
|
||||
fprintf(stderr, "input_stream::Open() failed\n");
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
auto is = InputStream::OpenReady(argv[1], mutex, cond);
|
||||
ret = dump_input_stream(std::move(is));
|
||||
}
|
||||
|
||||
/* deinitialize everything */
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "AudioFormat.hxx"
|
||||
#include "tag/TagHandler.hxx"
|
||||
#include "tag/Generic.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
#include "Log.hxx"
|
||||
@@ -89,7 +88,6 @@ try {
|
||||
|
||||
const ScopeIOThread io_thread;
|
||||
|
||||
Error error;
|
||||
input_stream_global_init();
|
||||
decoder_plugin_init_all();
|
||||
|
||||
@@ -105,13 +103,7 @@ try {
|
||||
Cond cond;
|
||||
|
||||
auto is = InputStream::OpenReady(path.c_str(),
|
||||
mutex, cond,
|
||||
error);
|
||||
if (!is) {
|
||||
FormatError(error, "Failed to open %s", path.c_str());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
mutex, cond);
|
||||
success = plugin->ScanStream(*is, print_handler, nullptr);
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "input/InputStream.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <stdexcept>
|
||||
@@ -49,7 +48,6 @@ try {
|
||||
|
||||
const ScopeIOThread io_thread;
|
||||
|
||||
Error error;
|
||||
input_stream_global_init();
|
||||
|
||||
decoder_plugin_init_all();
|
||||
@@ -64,16 +62,7 @@ try {
|
||||
plugin->FileDecode(decoder, Path::FromFS(uri));
|
||||
} else if (plugin->stream_decode != nullptr) {
|
||||
auto is = InputStream::OpenReady(uri, decoder.mutex,
|
||||
decoder.cond, error);
|
||||
if (!is) {
|
||||
if (error.IsDefined())
|
||||
LogError(error);
|
||||
else
|
||||
fprintf(stderr, "InputStream::Open() failed\n");
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
decoder.cond);
|
||||
plugin->StreamDecode(decoder, *is);
|
||||
} else {
|
||||
fprintf(stderr, "Decoder plugin is not usable\n");
|
||||
|
@@ -118,16 +118,8 @@ try {
|
||||
{
|
||||
Mutex mutex;
|
||||
Cond cond;
|
||||
auto is = InputStream::OpenReady(argv[1], mutex, cond, error);
|
||||
if (is) {
|
||||
ret = dump_input_stream(is.get());
|
||||
} else {
|
||||
if (error.IsDefined())
|
||||
LogError(error);
|
||||
else
|
||||
fprintf(stderr, "input_stream::Open() failed\n");
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
auto is = InputStream::OpenReady(argv[1], mutex, cond);
|
||||
ret = dump_input_stream(is.get());
|
||||
}
|
||||
|
||||
/* deinitialize everything */
|
||||
|
Reference in New Issue
Block a user