output/httpd: add methods Init(), Finish()

This commit is contained in:
Max Kellermann 2013-12-31 16:55:26 +01:00
parent 8b65b524d5
commit 964b2661d8
2 changed files with 29 additions and 12 deletions

View File

@ -129,8 +129,27 @@ struct HttpdOutput final : private ServerSocket {
HttpdOutput(EventLoop &_loop); HttpdOutput(EventLoop &_loop);
~HttpdOutput(); ~HttpdOutput();
bool Init(const config_param &param, Error &error);
void Finish() {
ao_base_finish(&base);
}
bool Configure(const config_param &param, Error &error); bool Configure(const config_param &param, Error &error);
audio_output *InitAndConfigure(const config_param &param,
Error &error) {
if (!Init(param, error))
return nullptr;
if (!Configure(param, error)) {
Finish();
return nullptr;
}
return &base;
}
bool Bind(Error &error); bool Bind(Error &error);
void Unbind(); void Unbind();

View File

@ -128,24 +128,22 @@ HttpdOutput::Configure(const config_param &param, Error &error)
return true; return true;
} }
inline bool
HttpdOutput::Init(const config_param &param, Error &error)
{
return ao_base_init(&base, &httpd_output_plugin, param, error);
}
static struct audio_output * static struct audio_output *
httpd_output_init(const config_param &param, Error &error) httpd_output_init(const config_param &param, Error &error)
{ {
HttpdOutput *httpd = new HttpdOutput(*main_loop); HttpdOutput *httpd = new HttpdOutput(*main_loop);
if (!ao_base_init(&httpd->base, &httpd_output_plugin, param, audio_output *result = httpd->InitAndConfigure(param, error);
error)) { if (result == nullptr)
delete httpd; delete httpd;
return nullptr;
}
if (!httpd->Configure(param, error)) { return result;
ao_base_finish(&httpd->base);
delete httpd;
return nullptr;
}
return &httpd->base;
} }
#if GCC_CHECK_VERSION(4,6) || defined(__clang__) #if GCC_CHECK_VERSION(4,6) || defined(__clang__)
@ -168,7 +166,7 @@ httpd_output_finish(struct audio_output *ao)
{ {
HttpdOutput *httpd = Cast(ao); HttpdOutput *httpd = Cast(ao);
ao_base_finish(&httpd->base); httpd->Finish();
delete httpd; delete httpd;
} }