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