output/solaris: migrate from class Error to C++ exceptions
This commit is contained in:
parent
9dbdc75689
commit
dd072912e8
@ -21,7 +21,7 @@
|
||||
#include "SolarisOutputPlugin.hxx"
|
||||
#include "../OutputAPI.hxx"
|
||||
#include "system/fd_util.h"
|
||||
#include "util/Error.hxx"
|
||||
#include "system/Error.hxx"
|
||||
|
||||
#include <sys/stropts.h>
|
||||
#include <sys/types.h>
|
||||
@ -53,12 +53,13 @@ struct SolarisOutput {
|
||||
AudioOutput base;
|
||||
|
||||
/* configuration */
|
||||
const char *device;
|
||||
const char *const device;
|
||||
|
||||
int fd;
|
||||
|
||||
SolarisOutput()
|
||||
:base(solaris_output_plugin) {}
|
||||
explicit SolarisOutput(const ConfigBlock &block)
|
||||
:base(solaris_output_plugin, block),
|
||||
device(block.GetBlockValue("device", "/dev/audio")) {}
|
||||
|
||||
bool Initialize(const ConfigBlock &block, Error &error_r) {
|
||||
return base.Configure(block, error_r);
|
||||
@ -75,16 +76,9 @@ solaris_output_test_default_device(void)
|
||||
}
|
||||
|
||||
static AudioOutput *
|
||||
solaris_output_init(const ConfigBlock &block, Error &error_r)
|
||||
solaris_output_init(const ConfigBlock &block, Error &)
|
||||
{
|
||||
SolarisOutput *so = new SolarisOutput();
|
||||
if (!so->Initialize(block, error_r)) {
|
||||
delete so;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
so->device = block.GetBlockValue("device", "/dev/audio");
|
||||
|
||||
SolarisOutput *so = new SolarisOutput(block);
|
||||
return &so->base;
|
||||
}
|
||||
|
||||
@ -97,8 +91,7 @@ solaris_output_finish(AudioOutput *ao)
|
||||
}
|
||||
|
||||
static bool
|
||||
solaris_output_open(AudioOutput *ao, AudioFormat &audio_format,
|
||||
Error &error)
|
||||
solaris_output_open(AudioOutput *ao, AudioFormat &audio_format, Error &)
|
||||
{
|
||||
SolarisOutput *so = (SolarisOutput *)ao;
|
||||
struct audio_info info;
|
||||
@ -111,11 +104,9 @@ solaris_output_open(AudioOutput *ao, AudioFormat &audio_format,
|
||||
/* open the device in non-blocking mode */
|
||||
|
||||
so->fd = open_cloexec(so->device, O_WRONLY|O_NONBLOCK, 0);
|
||||
if (so->fd < 0) {
|
||||
error.FormatErrno("Failed to open %s",
|
||||
if (so->fd < 0)
|
||||
throw FormatErrno("Failed to open %s",
|
||||
so->device);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* restore blocking mode */
|
||||
|
||||
@ -127,9 +118,9 @@ solaris_output_open(AudioOutput *ao, AudioFormat &audio_format,
|
||||
|
||||
ret = ioctl(so->fd, AUDIO_GETINFO, &info);
|
||||
if (ret < 0) {
|
||||
error.SetErrno("AUDIO_GETINFO failed");
|
||||
const int e = errno;
|
||||
close(so->fd);
|
||||
return false;
|
||||
throw MakeErrno(e, "AUDIO_GETINFO failed");
|
||||
}
|
||||
|
||||
info.play.sample_rate = audio_format.sample_rate;
|
||||
@ -139,9 +130,9 @@ solaris_output_open(AudioOutput *ao, AudioFormat &audio_format,
|
||||
|
||||
ret = ioctl(so->fd, AUDIO_SETINFO, &info);
|
||||
if (ret < 0) {
|
||||
error.SetErrno("AUDIO_SETINFO failed");
|
||||
const int e = errno;
|
||||
close(so->fd);
|
||||
return false;
|
||||
throw MakeErrno(e, "AUDIO_SETINFO failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -157,16 +148,14 @@ solaris_output_close(AudioOutput *ao)
|
||||
|
||||
static size_t
|
||||
solaris_output_play(AudioOutput *ao, const void *chunk, size_t size,
|
||||
Error &error)
|
||||
Error &)
|
||||
{
|
||||
SolarisOutput *so = (SolarisOutput *)ao;
|
||||
ssize_t nbytes;
|
||||
|
||||
nbytes = write(so->fd, chunk, size);
|
||||
if (nbytes <= 0) {
|
||||
error.SetErrno("Write failed");
|
||||
return 0;
|
||||
}
|
||||
if (nbytes <= 0)
|
||||
throw MakeErrno("Write failed");
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user