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

View File

@ -35,4 +35,16 @@ input_stream_global_init(const ConfigData &config, EventLoop &event_loop);
void void
input_stream_global_finish() noexcept; 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 #endif

View File

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

View File

@ -64,7 +64,7 @@ try {
EventThread io_thread; EventThread io_thread;
io_thread.Start(); 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); playlist_list_global_init(config);
decoder_plugin_init_all(config); decoder_plugin_init_all(config);
@ -118,7 +118,6 @@ try {
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
playlist_list_global_finish(); playlist_list_global_finish();
input_stream_global_finish();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (...) { } catch (...) {

View File

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

View File

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

View File

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

View File

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