diff options
author | Max Kellermann <max@musicpd.org> | 2017-01-03 12:22:14 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-01-03 12:24:05 +0100 |
commit | d2046de1932039643493a6de3bec79c17406fe0a (patch) | |
tree | ccceda6219b4bcac78e0af7ea003d0398d3b2a39 /test/run_input.cxx | |
parent | 4397fe3a13add8517a2d35702c8d56a79f3af282 (diff) |
test/run_input, ...: RAII-style global initialization
Diffstat (limited to 'test/run_input.cxx')
-rw-r--r-- | test/run_input.cxx | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/test/run_input.cxx b/test/run_input.cxx index 0e519cd0e..691189148 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -38,6 +38,27 @@ #include <unistd.h> #include <stdlib.h> +class GlobalInit { + const ScopeIOThread io_thread; + +public: + GlobalInit() { + config_global_init(); +#ifdef ENABLE_ARCHIVE + archive_plugin_init_all(); +#endif + input_stream_global_init(); + } + + ~GlobalInit() { + input_stream_global_finish(); +#ifdef ENABLE_ARCHIVE + archive_plugin_deinit_all(); +#endif + config_global_finish(); + } +}; + static void tag_save(FILE *file, const Tag &tag) { @@ -91,37 +112,14 @@ try { /* initialize MPD */ - config_global_init(); - - const ScopeIOThread io_thread; - -#ifdef ENABLE_ARCHIVE - archive_plugin_init_all(); -#endif - - input_stream_global_init(); + const GlobalInit init; /* open the stream and dump it */ - int ret; - { - Mutex mutex; - Cond cond; - auto is = InputStream::OpenReady(argv[1], mutex, cond); - ret = dump_input_stream(is.get()); - } - - /* deinitialize everything */ - - input_stream_global_finish(); - -#ifdef ENABLE_ARCHIVE - archive_plugin_deinit_all(); -#endif - - config_global_finish(); - - return ret; + Mutex mutex; + Cond cond; + auto is = InputStream::OpenReady(argv[1], mutex, cond); + return dump_input_stream(is.get()); } catch (const std::exception &e) { LogError(e); return EXIT_FAILURE; |