summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-11-09 11:18:19 +0100
committerMax Kellermann <max@musicpd.org>2016-11-09 11:18:19 +0100
commitdd072912e8862c8bd373192def71adc2cef73c66 (patch)
tree7fb7ffc618e7b2f9efd83acbb19459761a8f9ede
parent9dbdc756894282146201532f9ce9b944552f4e15 (diff)
output/solaris: migrate from class Error to C++ exceptions
-rw-r--r--src/output/plugins/SolarisOutputPlugin.cxx45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/output/plugins/SolarisOutputPlugin.cxx b/src/output/plugins/SolarisOutputPlugin.cxx
index 901b01cb9..5de3b9734 100644
--- a/src/output/plugins/SolarisOutputPlugin.cxx
+++ b/src/output/plugins/SolarisOutputPlugin.cxx
@@ -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;
}