From b45ea66175d599b430c7bb501859e8efad31a21e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 5 Nov 2016 15:24:10 +0100 Subject: [PATCH] output/pipe: migrate from class Error to C++ exceptions --- src/output/plugins/PipeOutputPlugin.cxx | 53 ++++++++----------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/src/output/plugins/PipeOutputPlugin.cxx b/src/output/plugins/PipeOutputPlugin.cxx index 4f3e72c4c..476e5ebb0 100644 --- a/src/output/plugins/PipeOutputPlugin.cxx +++ b/src/output/plugins/PipeOutputPlugin.cxx @@ -21,10 +21,10 @@ #include "PipeOutputPlugin.hxx" #include "../OutputAPI.hxx" #include "../Wrapper.hxx" -#include "config/ConfigError.hxx" -#include "util/Error.hxx" +#include "system/Error.hxx" #include +#include #include @@ -33,13 +33,10 @@ class PipeOutput { AudioOutput base; - std::string cmd; + const std::string cmd; FILE *fh; - PipeOutput() - :base(pipe_output_plugin) {} - - bool Configure(const ConfigBlock &block, Error &error); + PipeOutput(const ConfigBlock &block); public: static PipeOutput *Create(const ConfigBlock &block, Error &error); @@ -53,54 +50,36 @@ public: size_t Play(const void *chunk, size_t size, Error &error); }; -inline bool -PipeOutput::Configure(const ConfigBlock &block, Error &error) +PipeOutput::PipeOutput(const ConfigBlock &block) + :base(pipe_output_plugin, block), + cmd(block.GetBlockValue("command", "")) { - if (!base.Configure(block, error)) - return false; - - cmd = block.GetBlockValue("command", ""); - if (cmd.empty()) { - error.Set(config_domain, - "No \"command\" parameter specified"); - return false; - } - - return true; + if (cmd.empty()) + throw std::runtime_error("No \"command\" parameter specified"); } inline PipeOutput * -PipeOutput::Create(const ConfigBlock &block, Error &error) +PipeOutput::Create(const ConfigBlock &block, Error &) { - PipeOutput *po = new PipeOutput(); - - if (!po->Configure(block, error)) { - delete po; - return nullptr; - } - - return po; + return new PipeOutput(block); } inline bool -PipeOutput::Open(gcc_unused AudioFormat &audio_format, Error &error) +PipeOutput::Open(gcc_unused AudioFormat &audio_format, Error &) { fh = popen(cmd.c_str(), "w"); - if (fh == nullptr) { - error.FormatErrno("Error opening pipe \"%s\"", - cmd.c_str()); - return false; - } + if (fh == nullptr) + throw FormatErrno("Error opening pipe \"%s\"", cmd.c_str()); return true; } inline size_t -PipeOutput::Play(const void *chunk, size_t size, Error &error) +PipeOutput::Play(const void *chunk, size_t size, Error &) { size_t nbytes = fwrite(chunk, 1, size, fh); if (nbytes == 0) - error.SetErrno("Write error on pipe"); + throw MakeErrno("Write error on pipe"); return nbytes; }