From 8fd9d919749319fd0c2f3e78cd8c5a2d8f2e3744 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 25 Jan 2017 09:47:43 +0100 Subject: [PATCH] output/Plugin: pass EventLoop& to init() Eliminate dependency on io_thread_get(). --- src/output/Init.cxx | 2 +- src/output/OutputPlugin.cxx | 5 +++-- src/output/OutputPlugin.hxx | 6 ++++-- src/output/Wrapper.hxx | 5 +++-- src/output/plugins/AlsaOutputPlugin.cxx | 5 +++-- src/output/plugins/AoOutputPlugin.cxx | 2 +- src/output/plugins/FifoOutputPlugin.cxx | 5 +++-- src/output/plugins/HaikuOutputPlugin.cxx | 5 +++-- src/output/plugins/JackOutputPlugin.cxx | 2 +- src/output/plugins/NullOutputPlugin.cxx | 5 +++-- src/output/plugins/OSXOutputPlugin.cxx | 2 +- src/output/plugins/OpenALOutputPlugin.cxx | 5 +++-- src/output/plugins/OssOutputPlugin.cxx | 5 +++-- src/output/plugins/PipeOutputPlugin.cxx | 5 +++-- src/output/plugins/PulseOutputPlugin.cxx | 5 +++-- src/output/plugins/RecorderOutputPlugin.cxx | 5 +++-- src/output/plugins/RoarOutputPlugin.cxx | 2 +- src/output/plugins/ShoutOutputPlugin.cxx | 5 +++-- src/output/plugins/SndioOutputPlugin.cxx | 5 +++-- src/output/plugins/SolarisOutputPlugin.cxx | 2 +- src/output/plugins/WinmmOutputPlugin.cxx | 2 +- src/output/plugins/httpd/HttpdInternal.hxx | 3 ++- src/output/plugins/httpd/HttpdOutputPlugin.cxx | 7 +++---- src/output/plugins/sles/SlesOutputPlugin.cxx | 5 +++-- 24 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/output/Init.cxx b/src/output/Init.cxx index 67d33f85e..df28292e6 100644 --- a/src/output/Init.cxx +++ b/src/output/Init.cxx @@ -295,7 +295,7 @@ audio_output_new(EventLoop &event_loop, plugin->name); } - AudioOutput *ao = ao_plugin_init(*plugin, block); + AudioOutput *ao = ao_plugin_init(event_loop, *plugin, block); assert(ao != nullptr); try { diff --git a/src/output/OutputPlugin.cxx b/src/output/OutputPlugin.cxx index 23048167f..edaa50f52 100644 --- a/src/output/OutputPlugin.cxx +++ b/src/output/OutputPlugin.cxx @@ -22,12 +22,13 @@ #include "Internal.hxx" AudioOutput * -ao_plugin_init(const AudioOutputPlugin &plugin, +ao_plugin_init(EventLoop &event_loop, + const AudioOutputPlugin &plugin, const ConfigBlock &block) { assert(plugin.init != nullptr); - return plugin.init(block); + return plugin.init(event_loop, block); } void diff --git a/src/output/OutputPlugin.hxx b/src/output/OutputPlugin.hxx index f1231bda8..48e0f470e 100644 --- a/src/output/OutputPlugin.hxx +++ b/src/output/OutputPlugin.hxx @@ -31,6 +31,7 @@ struct AudioFormat; struct Tag; struct AudioOutput; struct MixerPlugin; +class EventLoop; /** * A plugin which controls an audio output device. @@ -56,7 +57,7 @@ struct AudioOutputPlugin { * @param param the configuration section, or nullptr if there is * no configuration */ - AudioOutput *(*init)(const ConfigBlock &block); + AudioOutput *(*init)(EventLoop &event_loop, const ConfigBlock &block); /** * Free resources allocated by this device. @@ -162,7 +163,8 @@ ao_plugin_test_default_device(const AudioOutputPlugin *plugin) gcc_malloc AudioOutput * -ao_plugin_init(const AudioOutputPlugin &plugin, +ao_plugin_init(EventLoop &event_loop, + const AudioOutputPlugin &plugin, const ConfigBlock &block); void diff --git a/src/output/Wrapper.hxx b/src/output/Wrapper.hxx index 8c433f721..7fa2b47ef 100644 --- a/src/output/Wrapper.hxx +++ b/src/output/Wrapper.hxx @@ -33,8 +33,9 @@ struct AudioOutputWrapper { return ContainerCast(ao, &T::base); } - static AudioOutput *Init(const ConfigBlock &block) { - T *t = T::Create(block); + static AudioOutput *Init(EventLoop &event_loop, + const ConfigBlock &block) { + T *t = T::Create(event_loop, block); return &t->base; } diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index b9878bfed..74961a224 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -136,7 +136,8 @@ public: return device.empty() ? default_device : device.c_str(); } - static AlsaOutput *Create(const ConfigBlock &block); + static AlsaOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Enable(); void Disable(); @@ -207,7 +208,7 @@ AlsaOutput::AlsaOutput(const ConfigBlock &block) } inline AlsaOutput * -AlsaOutput::Create(const ConfigBlock &block) +AlsaOutput::Create(EventLoop &, const ConfigBlock &block) { return new AlsaOutput(block); } diff --git a/src/output/plugins/AoOutputPlugin.cxx b/src/output/plugins/AoOutputPlugin.cxx index a4f8cf527..b131e8994 100644 --- a/src/output/plugins/AoOutputPlugin.cxx +++ b/src/output/plugins/AoOutputPlugin.cxx @@ -51,7 +51,7 @@ class AoOutput { ~AoOutput(); public: - static AoOutput *Create(const ConfigBlock &block) { + static AoOutput *Create(EventLoop &, const ConfigBlock &block) { return new AoOutput(block); } diff --git a/src/output/plugins/FifoOutputPlugin.cxx b/src/output/plugins/FifoOutputPlugin.cxx index 57779fa15..dfa116968 100644 --- a/src/output/plugins/FifoOutputPlugin.cxx +++ b/src/output/plugins/FifoOutputPlugin.cxx @@ -54,7 +54,8 @@ public: CloseFifo(); } - static FifoOutput *Create(const ConfigBlock &block); + static FifoOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Create(); void Check(); @@ -169,7 +170,7 @@ try { } inline FifoOutput * -FifoOutput::Create(const ConfigBlock &block) +FifoOutput::Create(EventLoop &, const ConfigBlock &block) { return new FifoOutput(block); } diff --git a/src/output/plugins/HaikuOutputPlugin.cxx b/src/output/plugins/HaikuOutputPlugin.cxx index 5d0371e9e..472d3f568 100644 --- a/src/output/plugins/HaikuOutputPlugin.cxx +++ b/src/output/plugins/HaikuOutputPlugin.cxx @@ -71,7 +71,8 @@ public: ~HaikuOutput(); - static HaikuOutput *Create(const ConfigBlock &block); + static HaikuOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format); void Close(); @@ -119,7 +120,7 @@ haiku_test_default_device(void) } inline HaikuOutput * -HaikuOutput::Create(const ConfigBlock &block) +HaikuOutput::Create(EventLoop &, const ConfigBlock &block) { initialize_application(); diff --git a/src/output/plugins/JackOutputPlugin.cxx b/src/output/plugins/JackOutputPlugin.cxx index 0ad5768d3..3f08d50a8 100644 --- a/src/output/plugins/JackOutputPlugin.cxx +++ b/src/output/plugins/JackOutputPlugin.cxx @@ -444,7 +444,7 @@ JackOutput::Disable() } static AudioOutput * -mpd_jack_init(const ConfigBlock &block) +mpd_jack_init(EventLoop &, const ConfigBlock &block) { jack_set_error_function(mpd_jack_error); diff --git a/src/output/plugins/NullOutputPlugin.cxx b/src/output/plugins/NullOutputPlugin.cxx index 5b063386d..64d0eb392 100644 --- a/src/output/plugins/NullOutputPlugin.cxx +++ b/src/output/plugins/NullOutputPlugin.cxx @@ -37,7 +37,8 @@ public: :base(null_output_plugin, block), sync(block.GetBlockValue("sync", true)) {} - static NullOutput *Create(const ConfigBlock &block); + static NullOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format) { if (sync) @@ -72,7 +73,7 @@ public: }; inline NullOutput * -NullOutput::Create(const ConfigBlock &block) +NullOutput::Create(EventLoop &, const ConfigBlock &block) { return new NullOutput(block); } diff --git a/src/output/plugins/OSXOutputPlugin.cxx b/src/output/plugins/OSXOutputPlugin.cxx index 5c9d55a2e..3e97aa132 100644 --- a/src/output/plugins/OSXOutputPlugin.cxx +++ b/src/output/plugins/OSXOutputPlugin.cxx @@ -104,7 +104,7 @@ OSXOutput::OSXOutput(const ConfigBlock &block) } static AudioOutput * -osx_output_init(const ConfigBlock &block) +osx_output_init(EventLoop &, const ConfigBlock &block) { OSXOutput *oo = new OSXOutput(block); diff --git a/src/output/plugins/OpenALOutputPlugin.cxx b/src/output/plugins/OpenALOutputPlugin.cxx index 6b0d1bfb9..bf459aaf5 100644 --- a/src/output/plugins/OpenALOutputPlugin.cxx +++ b/src/output/plugins/OpenALOutputPlugin.cxx @@ -52,7 +52,8 @@ class OpenALOutput { OpenALOutput(const ConfigBlock &block); - static OpenALOutput *Create(const ConfigBlock &block); + static OpenALOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format); void Close(); @@ -146,7 +147,7 @@ OpenALOutput::OpenALOutput(const ConfigBlock &block) } inline OpenALOutput * -OpenALOutput::Create(const ConfigBlock &block) +OpenALOutput::Create(EventLoop &, const ConfigBlock &block) { return new OpenALOutput(block); } diff --git a/src/output/plugins/OssOutputPlugin.cxx b/src/output/plugins/OssOutputPlugin.cxx index d02a8263b..8b7faceb0 100644 --- a/src/output/plugins/OssOutputPlugin.cxx +++ b/src/output/plugins/OssOutputPlugin.cxx @@ -89,7 +89,8 @@ public: :base(oss_output_plugin, block), fd(-1), device(_device) {} - static OssOutput *Create(const ConfigBlock &block); + static OssOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); #ifdef AFMT_S24_PACKED void Enable() { @@ -226,7 +227,7 @@ oss_open_default() } inline OssOutput * -OssOutput::Create(const ConfigBlock &block) +OssOutput::Create(EventLoop &, const ConfigBlock &block) { const char *device = block.GetBlockValue("device"); if (device != nullptr) diff --git a/src/output/plugins/PipeOutputPlugin.cxx b/src/output/plugins/PipeOutputPlugin.cxx index 6ffda3f49..7d5efb940 100644 --- a/src/output/plugins/PipeOutputPlugin.cxx +++ b/src/output/plugins/PipeOutputPlugin.cxx @@ -39,7 +39,8 @@ class PipeOutput { PipeOutput(const ConfigBlock &block); public: - static PipeOutput *Create(const ConfigBlock &block); + static PipeOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format); @@ -59,7 +60,7 @@ PipeOutput::PipeOutput(const ConfigBlock &block) } inline PipeOutput * -PipeOutput::Create(const ConfigBlock &block) +PipeOutput::Create(EventLoop &, const ConfigBlock &block) { return new PipeOutput(block); } diff --git a/src/output/plugins/PulseOutputPlugin.cxx b/src/output/plugins/PulseOutputPlugin.cxx index ec3ad6f5d..63a5ecb81 100644 --- a/src/output/plugins/PulseOutputPlugin.cxx +++ b/src/output/plugins/PulseOutputPlugin.cxx @@ -93,7 +93,8 @@ public: gcc_const static bool TestDefaultDevice(); - static PulseOutput *Create(const ConfigBlock &block); + static PulseOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Enable(); void Disable(); @@ -415,7 +416,7 @@ PulseOutput::SetupContext() } PulseOutput * -PulseOutput::Create(const ConfigBlock &block) +PulseOutput::Create(EventLoop &, const ConfigBlock &block) { return new PulseOutput(block); } diff --git a/src/output/plugins/RecorderOutputPlugin.cxx b/src/output/plugins/RecorderOutputPlugin.cxx index a934e3bfe..15d24b737 100644 --- a/src/output/plugins/RecorderOutputPlugin.cxx +++ b/src/output/plugins/RecorderOutputPlugin.cxx @@ -81,7 +81,8 @@ class RecorderOutput { delete prepared_encoder; } - static RecorderOutput *Create(const ConfigBlock &block); + static RecorderOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format); void Close(); @@ -141,7 +142,7 @@ RecorderOutput::RecorderOutput(const ConfigBlock &block) } RecorderOutput * -RecorderOutput::Create(const ConfigBlock &block) +RecorderOutput::Create(EventLoop &, const ConfigBlock &block) { return new RecorderOutput(block); } diff --git a/src/output/plugins/RoarOutputPlugin.cxx b/src/output/plugins/RoarOutputPlugin.cxx index b6f5521e0..a6620f7b4 100644 --- a/src/output/plugins/RoarOutputPlugin.cxx +++ b/src/output/plugins/RoarOutputPlugin.cxx @@ -58,7 +58,7 @@ public: return &base; } - static RoarOutput *Create(const ConfigBlock &block) { + static RoarOutput *Create(EventLoop &, const ConfigBlock &block) { return new RoarOutput(block); } diff --git a/src/output/plugins/ShoutOutputPlugin.cxx b/src/output/plugins/ShoutOutputPlugin.cxx index 97bab04da..38d0a9825 100644 --- a/src/output/plugins/ShoutOutputPlugin.cxx +++ b/src/output/plugins/ShoutOutputPlugin.cxx @@ -58,7 +58,8 @@ struct ShoutOutput final { explicit ShoutOutput(const ConfigBlock &block); ~ShoutOutput(); - static ShoutOutput *Create(const ConfigBlock &block); + static ShoutOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format); void Close(); @@ -246,7 +247,7 @@ ShoutOutput::~ShoutOutput() } ShoutOutput * -ShoutOutput::Create(const ConfigBlock &block) +ShoutOutput::Create(EventLoop &, const ConfigBlock &block) { if (shout_init_count == 0) shout_init(); diff --git a/src/output/plugins/SndioOutputPlugin.cxx b/src/output/plugins/SndioOutputPlugin.cxx index c5f63dfd7..8c4a7327e 100644 --- a/src/output/plugins/SndioOutputPlugin.cxx +++ b/src/output/plugins/SndioOutputPlugin.cxx @@ -47,7 +47,8 @@ class SndioOutput { public: SndioOutput(const ConfigBlock &block); - static SndioOutput *Create(const ConfigBlock &block); + static SndioOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format); void Close(); @@ -64,7 +65,7 @@ SndioOutput::SndioOutput(const ConfigBlock &block) } SndioOutput * -SndioOutput::Create(const ConfigBlock &block) +SndioOutput::Create(EventLoop &, const ConfigBlock &block) { return new SndioOutput(block); } diff --git a/src/output/plugins/SolarisOutputPlugin.cxx b/src/output/plugins/SolarisOutputPlugin.cxx index 8ef209f80..856a64ac0 100644 --- a/src/output/plugins/SolarisOutputPlugin.cxx +++ b/src/output/plugins/SolarisOutputPlugin.cxx @@ -65,7 +65,7 @@ class SolarisOutput { device(block.GetBlockValue("device", "/dev/audio")) {} public: - static SolarisOutput *Create(const ConfigBlock &block) { + static SolarisOutput *Create(EventLoop &, const ConfigBlock &block) { return new SolarisOutput(block); } diff --git a/src/output/plugins/WinmmOutputPlugin.cxx b/src/output/plugins/WinmmOutputPlugin.cxx index a29f63aca..b17c65d3f 100644 --- a/src/output/plugins/WinmmOutputPlugin.cxx +++ b/src/output/plugins/WinmmOutputPlugin.cxx @@ -63,7 +63,7 @@ public: return handle; } - static WinmmOutput *Create(const ConfigBlock &block) { + static WinmmOutput *Create(EventLoop &, const ConfigBlock &block) { return new WinmmOutput(block); } diff --git a/src/output/plugins/httpd/HttpdInternal.hxx b/src/output/plugins/httpd/HttpdInternal.hxx index a55981d7c..c4b12d92c 100644 --- a/src/output/plugins/httpd/HttpdInternal.hxx +++ b/src/output/plugins/httpd/HttpdInternal.hxx @@ -155,7 +155,8 @@ public: HttpdOutput(EventLoop &_loop, const ConfigBlock &block); ~HttpdOutput(); - static HttpdOutput *Create(const ConfigBlock &block); + static HttpdOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); #if CLANG_OR_GCC_VERSION(4,7) constexpr diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index d54eccde6..2e220d417 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -30,7 +30,6 @@ #include "Page.hxx" #include "IcyMetaDataServer.hxx" #include "system/fd_util.h" -#include "IOThread.hxx" #include "event/Call.hxx" #include "util/RuntimeError.hxx" #include "util/Domain.hxx" @@ -118,9 +117,9 @@ HttpdOutput::Unbind() } HttpdOutput * -HttpdOutput::Create(const ConfigBlock &block) +HttpdOutput::Create(EventLoop &event_loop, const ConfigBlock &block) { - return new HttpdOutput(io_thread_get(), block); + return new HttpdOutput(event_loop, block); } /** @@ -466,7 +465,7 @@ HttpdOutput::CancelAllClients() void HttpdOutput::Cancel() { - BlockingCall(io_thread_get(), [this](){ + BlockingCall(GetEventLoop(), [this](){ CancelAllClients(); }); } diff --git a/src/output/plugins/sles/SlesOutputPlugin.cxx b/src/output/plugins/sles/SlesOutputPlugin.cxx index da88662cc..b00bf1909 100644 --- a/src/output/plugins/sles/SlesOutputPlugin.cxx +++ b/src/output/plugins/sles/SlesOutputPlugin.cxx @@ -91,7 +91,8 @@ public: return &base; } - static SlesOutput *Create(const ConfigBlock &block); + static SlesOutput *Create(EventLoop &event_loop, + const ConfigBlock &block); void Open(AudioFormat &audio_format); void Close(); @@ -413,7 +414,7 @@ sles_test_default_device() } inline SlesOutput * -SlesOutput::Create(const ConfigBlock &block) +SlesOutput::Create(EventLoop &, const ConfigBlock &block) { return new SlesOutput(block); }