input/Init: add RAII class

This commit is contained in:
Max Kellermann 2019-02-05 21:50:31 +01:00
parent b0739eca87
commit 9e73ea77b4
9 changed files with 39 additions and 39 deletions

View File

@ -553,8 +553,8 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
}
client_manager_init(raw_config);
input_stream_global_init(raw_config,
instance->io_thread.GetEventLoop());
const ScopeInputPluginsInit input_plugins_init(raw_config,
instance->io_thread.GetEventLoop());
playlist_list_global_init(raw_config);
#ifdef ENABLE_DAEMON
@ -660,7 +660,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
#endif
playlist_list_global_finish();
input_stream_global_finish();
#ifdef ENABLE_DATABASE
mapper_finish();

View File

@ -35,4 +35,16 @@ input_stream_global_init(const ConfigData &config, EventLoop &event_loop);
void
input_stream_global_finish() noexcept;
class ScopeInputPluginsInit {
public:
ScopeInputPluginsInit(const ConfigData &config,
EventLoop &event_loop) {
input_stream_global_init(config, event_loop);
}
~ScopeInputPluginsInit() noexcept {
input_stream_global_finish();
}
};
#endif

View File

@ -90,15 +90,15 @@ ParseCommandLine(int argc, char **argv)
class GlobalInit {
const ConfigData config;
EventThread io_thread;
const ScopeInputPluginsInit input_plugins_init;
public:
explicit GlobalInit(Path config_path)
:config(AutoLoadConfigFile(config_path))
:config(AutoLoadConfigFile(config_path)),
input_plugins_init(config, io_thread.GetEventLoop())
{
io_thread.Start();
input_stream_global_init(config,
io_thread.GetEventLoop());
decoder_plugin_init_all(config);
pcm_convert_global_init(config);
@ -106,7 +106,6 @@ public:
~GlobalInit() {
decoder_plugin_deinit_all();
input_stream_global_finish();
}
};

View File

@ -64,7 +64,7 @@ try {
EventThread io_thread;
io_thread.Start();
input_stream_global_init(config, io_thread.GetEventLoop());
const ScopeInputPluginsInit input_plugins_init(config, io_thread.GetEventLoop());
playlist_list_global_init(config);
decoder_plugin_init_all(config);
@ -118,7 +118,6 @@ try {
decoder_plugin_deinit_all();
playlist_list_global_finish();
input_stream_global_finish();
return EXIT_SUCCESS;
} catch (...) {

View File

@ -42,15 +42,13 @@ class GlobalInit {
const ScopeArchivePluginsInit archive_plugins_init;
#endif
public:
GlobalInit() {
io_thread.Start();
input_stream_global_init(ConfigData(),
io_thread.GetEventLoop());
}
const ScopeInputPluginsInit input_plugins_init;
~GlobalInit() {
input_stream_global_finish();
public:
GlobalInit()
:input_plugins_init(ConfigData(), io_thread.GetEventLoop())
{
io_thread.Start();
}
};

View File

@ -93,8 +93,8 @@ try {
EventThread io_thread;
io_thread.Start();
input_stream_global_init(ConfigData(), io_thread.GetEventLoop());
AtScopeExit() { input_stream_global_finish(); };
const ScopeInputPluginsInit input_plugins_init(ConfigData(),
io_thread.GetEventLoop());
decoder_plugin_init_all(ConfigData());
AtScopeExit() { decoder_plugin_deinit_all(); };

View File

@ -88,21 +88,20 @@ ParseCommandLine(int argc, char **argv)
class GlobalInit {
const ConfigData config;
EventThread io_thread;
const ScopeInputPluginsInit input_plugins_init;
public:
explicit GlobalInit(Path config_path)
:config(AutoLoadConfigFile(config_path))
:config(AutoLoadConfigFile(config_path)),
input_plugins_init(config, io_thread.GetEventLoop())
{
io_thread.Start();
input_stream_global_init(config,
io_thread.GetEventLoop());
decoder_plugin_init_all(config);
}
~GlobalInit() {
decoder_plugin_deinit_all();
input_stream_global_finish();
}
};

View File

@ -108,18 +108,14 @@ class GlobalInit {
const ScopeArchivePluginsInit archive_plugins_init;
#endif
const ScopeInputPluginsInit input_plugins_init;
public:
explicit GlobalInit(Path config_path)
:config(AutoLoadConfigFile(config_path))
:config(AutoLoadConfigFile(config_path)),
input_plugins_init(config, io_thread.GetEventLoop())
{
io_thread.Start();
input_stream_global_init(config,
io_thread.GetEventLoop());
}
~GlobalInit() {
input_stream_global_finish();
}
};

View File

@ -42,15 +42,13 @@ class GlobalInit {
const ScopeArchivePluginsInit archive_plugins_init;
#endif
public:
GlobalInit() {
io_thread.Start();
input_stream_global_init(ConfigData(),
io_thread.GetEventLoop());
}
const ScopeInputPluginsInit input_plugins_init;
~GlobalInit() {
input_stream_global_finish();
public:
GlobalInit()
:input_plugins_init(ConfigData(), io_thread.GetEventLoop())
{
io_thread.Start();
}
};