From 9e73ea77b4ccd4131823ddc156322a2e4082d417 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 5 Feb 2019 21:50:31 +0100 Subject: [PATCH] input/Init: add RAII class --- src/Main.cxx | 5 ++--- src/input/Init.hxx | 12 ++++++++++++ test/RunChromaprint.cxx | 7 +++---- test/dump_playlist.cxx | 3 +-- test/dump_text_file.cxx | 14 ++++++-------- test/read_tags.cxx | 4 ++-- test/run_decoder.cxx | 7 +++---- test/run_input.cxx | 12 ++++-------- test/visit_archive.cxx | 14 ++++++-------- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Main.cxx b/src/Main.cxx index a932a50ce..38f6efe2a 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -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(); diff --git a/src/input/Init.hxx b/src/input/Init.hxx index cba1a663e..ed6615131 100644 --- a/src/input/Init.hxx +++ b/src/input/Init.hxx @@ -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 diff --git a/test/RunChromaprint.cxx b/test/RunChromaprint.cxx index dcbd75d2e..3da471f77 100644 --- a/test/RunChromaprint.cxx +++ b/test/RunChromaprint.cxx @@ -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(); } }; diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index 0b2519161..699b2e930 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -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 (...) { diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx index 18cdc7061..ab3ccf12a 100644 --- a/test/dump_text_file.cxx +++ b/test/dump_text_file.cxx @@ -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(); } }; diff --git a/test/read_tags.cxx b/test/read_tags.cxx index 2ea744c95..3b3a791aa 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -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(); }; diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx index c32f56c0e..be7091498 100644 --- a/test/run_decoder.cxx +++ b/test/run_decoder.cxx @@ -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(); } }; diff --git a/test/run_input.cxx b/test/run_input.cxx index f81a8bc77..e5deafda8 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -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(); } }; diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx index 2507b0846..f14d408a4 100644 --- a/test/visit_archive.cxx +++ b/test/visit_archive.cxx @@ -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(); } };