input/Plugin: migrate open() from class Error to C++ exceptions
This commit is contained in:
@@ -127,7 +127,7 @@ struct cdio_uri {
|
||||
};
|
||||
|
||||
static bool
|
||||
parse_cdio_uri(struct cdio_uri *dest, const char *src, Error &error)
|
||||
parse_cdio_uri(struct cdio_uri *dest, const char *src)
|
||||
{
|
||||
if (!StringStartsWith(src, "cdda://"))
|
||||
return false;
|
||||
@@ -160,10 +160,8 @@ parse_cdio_uri(struct cdio_uri *dest, const char *src, Error &error)
|
||||
|
||||
char *endptr;
|
||||
dest->track = strtoul(track, &endptr, 10);
|
||||
if (*endptr != 0) {
|
||||
error.Set(cdio_domain, "Malformed track number");
|
||||
return false;
|
||||
}
|
||||
if (*endptr != 0)
|
||||
throw std::runtime_error("Malformed track number");
|
||||
|
||||
if (endptr == track)
|
||||
/* play the whole CD */
|
||||
@@ -187,35 +185,28 @@ cdio_detect_device(void)
|
||||
|
||||
static InputStream *
|
||||
input_cdio_open(const char *uri,
|
||||
Mutex &mutex, Cond &cond,
|
||||
Error &error)
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
struct cdio_uri parsed_uri;
|
||||
if (!parse_cdio_uri(&parsed_uri, uri, error))
|
||||
if (!parse_cdio_uri(&parsed_uri, uri))
|
||||
return nullptr;
|
||||
|
||||
/* get list of CD's supporting CD-DA */
|
||||
const AllocatedPath device = parsed_uri.device[0] != 0
|
||||
? AllocatedPath::FromFS(parsed_uri.device)
|
||||
: cdio_detect_device();
|
||||
if (device.IsNull()) {
|
||||
error.Set(cdio_domain,
|
||||
"Unable find or access a CD-ROM drive with an audio CD in it.");
|
||||
return nullptr;
|
||||
}
|
||||
if (device.IsNull())
|
||||
throw std::runtime_error("Unable find or access a CD-ROM drive with an audio CD in it.");
|
||||
|
||||
/* Found such a CD-ROM with a CD-DA loaded. Use the first drive in the list. */
|
||||
const auto cdio = cdio_open(device.c_str(), DRIVER_UNKNOWN);
|
||||
if (cdio == nullptr) {
|
||||
error.Set(cdio_domain, "Failed to open CD drive");
|
||||
return nullptr;
|
||||
}
|
||||
if (cdio == nullptr)
|
||||
throw std::runtime_error("Failed to open CD drive");
|
||||
|
||||
const auto drv = cdio_cddap_identify_cdio(cdio, 1, nullptr);
|
||||
if (drv == nullptr) {
|
||||
error.Set(cdio_domain, "Unable to identify audio CD disc.");
|
||||
cdio_destroy(cdio);
|
||||
return nullptr;
|
||||
throw std::runtime_error("Unable to identify audio CD disc.");
|
||||
}
|
||||
|
||||
cdda_verbose_set(drv, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
|
||||
@@ -223,12 +214,12 @@ input_cdio_open(const char *uri,
|
||||
if (0 != cdio_cddap_open(drv)) {
|
||||
cdio_cddap_close_no_free_cdio(drv);
|
||||
cdio_destroy(cdio);
|
||||
error.Set(cdio_domain, "Unable to open disc.");
|
||||
return nullptr;
|
||||
throw std::runtime_error("Unable to open disc.");
|
||||
}
|
||||
|
||||
bool reverse_endian;
|
||||
switch (data_bigendianp(drv)) {
|
||||
const int be = data_bigendianp(drv);
|
||||
switch (be) {
|
||||
case -1:
|
||||
LogDebug(cdio_domain, "drive returns unknown audio data");
|
||||
reverse_endian = default_reverse_endian;
|
||||
@@ -245,11 +236,10 @@ input_cdio_open(const char *uri,
|
||||
break;
|
||||
|
||||
default:
|
||||
error.Format(cdio_domain, "Drive returns unknown data type %d",
|
||||
data_bigendianp(drv));
|
||||
cdio_cddap_close_no_free_cdio(drv);
|
||||
cdio_destroy(cdio);
|
||||
return nullptr;
|
||||
throw FormatRuntimeError("Drive returns unknown data type %d",
|
||||
be);
|
||||
}
|
||||
|
||||
lsn_t lsn_from, lsn_to;
|
||||
|
Reference in New Issue
Block a user