Commit e2425592 authored by Max Kellermann's avatar Max Kellermann

output/httpd: move Cast() into the class

parent 964b2661
......@@ -129,6 +129,19 @@ struct HttpdOutput final : private ServerSocket {
HttpdOutput(EventLoop &_loop);
~HttpdOutput();
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif
static constexpr HttpdOutput *Cast(audio_output *ao) {
return (HttpdOutput *)((char *)ao - offsetof(HttpdOutput, base));
}
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
bool Init(const config_param &param, Error &error);
void Finish() {
......
......@@ -146,25 +146,10 @@ httpd_output_init(const config_param &param, Error &error)
return result;
}
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif
static inline constexpr HttpdOutput *
Cast(audio_output *ao)
{
return (HttpdOutput *)((char *)ao - offsetof(HttpdOutput, base));
}
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
static void
httpd_output_finish(struct audio_output *ao)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
httpd->Finish();
delete httpd;
......@@ -265,7 +250,7 @@ HttpdOutput::ReadPage()
static bool
httpd_output_enable(struct audio_output *ao, Error &error)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
return httpd->Bind(error);
}
......@@ -273,7 +258,7 @@ httpd_output_enable(struct audio_output *ao, Error &error)
static void
httpd_output_disable(struct audio_output *ao)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
httpd->Unbind();
}
......@@ -319,7 +304,7 @@ static bool
httpd_output_open(struct audio_output *ao, AudioFormat &audio_format,
Error &error)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
assert(httpd->clients.empty());
......@@ -347,7 +332,7 @@ HttpdOutput::Close()
static void
httpd_output_close(struct audio_output *ao)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
const ScopeLock protect(httpd->mutex);
httpd->Close();
......@@ -379,7 +364,7 @@ HttpdOutput::SendHeader(HttpdClient &client) const
static unsigned
httpd_output_delay(struct audio_output *ao)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
if (!httpd->LockHasClients() && httpd->base.pause) {
/* if there's no client and this output is paused,
......@@ -445,7 +430,7 @@ static size_t
httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
Error &error)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
if (httpd->LockHasClients()) {
if (!httpd->EncodeAndPlay(chunk, size, error))
......@@ -462,7 +447,7 @@ httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
static bool
httpd_output_pause(struct audio_output *ao)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
if (httpd->LockHasClients()) {
static const char silence[1020] = { 0 };
......@@ -525,7 +510,7 @@ HttpdOutput::SendTag(const Tag *tag)
static void
httpd_output_tag(struct audio_output *ao, const Tag *tag)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
httpd->SendTag(tag);
}
......@@ -533,7 +518,7 @@ httpd_output_tag(struct audio_output *ao, const Tag *tag)
static void
httpd_output_cancel(struct audio_output *ao)
{
HttpdOutput *httpd = Cast(ao);
HttpdOutput *httpd = HttpdOutput::Cast(ao);
const ScopeLock protect(httpd->mutex);
for (auto &client : httpd->clients)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment