output/pipe: migrate from class Error to C++ exceptions
This commit is contained in:
parent
543c5034af
commit
b45ea66175
@ -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 <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user