diff --git a/test/ConfigGlue.hxx b/test/ConfigGlue.hxx new file mode 100644 index 000000000..92b693959 --- /dev/null +++ b/test/ConfigGlue.hxx @@ -0,0 +1,41 @@ +/* + * Copyright 2003-2019 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_TEST_CONFIG_GLUE_HXX +#define MPD_TEST_CONFIG_GLUE_HXX + +#include "config/File.hxx" +#include "config/Migrate.hxx" +#include "config/Data.hxx" +#include "fs/Path.hxx" + +inline ConfigData +AutoLoadConfigFile(Path path) +{ + ConfigData data; + + if (!path.IsNull()) { + ReadConfigFile(data, path); + Migrate(data); + } + + return data; +} + +#endif diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx index 755f0904c..4a32f6e45 100644 --- a/test/DumpDatabase.cxx +++ b/test/DumpDatabase.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -26,11 +26,7 @@ #include "db/LightDirectory.hxx" #include "song/LightSong.hxx" #include "db/PlaylistVector.hxx" -#include "config/File.hxx" -#include "config/Migrate.hxx" -#include "config/Data.hxx" -#include "config/Param.hxx" -#include "config/Block.hxx" +#include "ConfigGlue.hxx" #include "tag/Config.hxx" #include "fs/Path.hxx" #include "event/Thread.hxx" @@ -124,9 +120,7 @@ try { GlobalInit init; - ConfigData config; - ReadConfigFile(config, config_path); - Migrate(config); + const auto config = AutoLoadConfigFile(config_path); TagLoadConfig(config); diff --git a/test/RunChromaprint.cxx b/test/RunChromaprint.cxx index ab68d2aa4..dcbd75d2e 100644 --- a/test/RunChromaprint.cxx +++ b/test/RunChromaprint.cxx @@ -17,9 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "config/File.hxx" -#include "config/Migrate.hxx" -#include "config/Data.hxx" +#include "ConfigGlue.hxx" #include "tag/Chromaprint.hxx" #include "pcm/PcmConvert.hxx" #include "event/Thread.hxx" @@ -90,18 +88,13 @@ ParseCommandLine(int argc, char **argv) } class GlobalInit { - ConfigData config; + const ConfigData config; EventThread io_thread; public: - GlobalInit(Path config_path, bool verbose) { - SetLogThreshold(verbose ? LogLevel::DEBUG : LogLevel::INFO); - - if (!config_path.IsNull()) { - ReadConfigFile(config, config_path); - Migrate(config); - } - + explicit GlobalInit(Path config_path) + :config(AutoLoadConfigFile(config_path)) + { io_thread.Start(); input_stream_global_init(config, @@ -245,7 +238,8 @@ int main(int argc, char **argv) try { const auto c = ParseCommandLine(argc, argv); - const GlobalInit init(c.config_path, c.verbose); + SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO); + const GlobalInit init(c.config_path); const DecoderPlugin *plugin = decoder_plugin_from_name(c.decoder); if (plugin == nullptr) { diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index 0c336ffaf..0b2519161 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -21,9 +21,7 @@ #include "song/DetachedSong.hxx" #include "playlist/SongEnumerator.hxx" #include "input/InputStream.hxx" -#include "config/File.hxx" -#include "config/Migrate.hxx" -#include "config/Data.hxx" +#include "ConfigGlue.hxx" #include "decoder/DecoderList.hxx" #include "input/Init.hxx" #include "event/Thread.hxx" @@ -61,9 +59,7 @@ try { /* initialize MPD */ - ConfigData config; - ReadConfigFile(config, config_path); - Migrate(config); + const auto config = AutoLoadConfigFile(config_path); EventThread io_thread; io_thread.Start(); diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx index c37664201..c32f56c0e 100644 --- a/test/run_decoder.cxx +++ b/test/run_decoder.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -17,9 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "config/File.hxx" -#include "config/Migrate.hxx" -#include "config/Data.hxx" +#include "ConfigGlue.hxx" #include "event/Thread.hxx" #include "decoder/DecoderList.hxx" #include "decoder/DecoderPlugin.hxx" @@ -88,18 +86,13 @@ ParseCommandLine(int argc, char **argv) } class GlobalInit { - ConfigData config; + const ConfigData config; EventThread io_thread; public: - GlobalInit(Path config_path, bool verbose) { - SetLogThreshold(verbose ? LogLevel::DEBUG : LogLevel::INFO); - - if (!config_path.IsNull()) { - ReadConfigFile(config, config_path); - Migrate(config); - } - + explicit GlobalInit(Path config_path) + :config(AutoLoadConfigFile(config_path)) + { io_thread.Start(); input_stream_global_init(config, @@ -117,7 +110,8 @@ int main(int argc, char **argv) try { const auto c = ParseCommandLine(argc, argv); - const GlobalInit init(c.config_path, c.verbose); + SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO); + const GlobalInit init(c.config_path); const DecoderPlugin *plugin = decoder_plugin_from_name(c.decoder); if (plugin == nullptr) { diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 689677592..31452f440 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -17,10 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "config/Param.hxx" -#include "config/Data.hxx" -#include "config/File.hxx" -#include "config/Migrate.hxx" +#include "ConfigGlue.hxx" #include "fs/Path.hxx" #include "AudioParser.hxx" #include "AudioFormat.hxx" @@ -77,9 +74,7 @@ try { /* read configuration file (mpd.conf) */ - ConfigData config; - ReadConfigFile(config, config_path); - Migrate(config); + const auto config = AutoLoadConfigFile(config_path); /* parse the audio format */ diff --git a/test/run_input.cxx b/test/run_input.cxx index c58316ba5..f81a8bc77 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -20,9 +20,7 @@ #include "config.h" #include "TagSave.hxx" #include "tag/Tag.hxx" -#include "config/File.hxx" -#include "config/Migrate.hxx" -#include "config/Data.hxx" +#include "ConfigGlue.hxx" #include "input/InputStream.hxx" #include "input/Init.hxx" #include "input/Registry.hxx" @@ -103,7 +101,7 @@ ParseCommandLine(int argc, char **argv) } class GlobalInit { - ConfigData config; + const ConfigData config; EventThread io_thread; #ifdef ENABLE_ARCHIVE @@ -111,14 +109,9 @@ class GlobalInit { #endif public: - GlobalInit(Path config_path, bool verbose) { - SetLogThreshold(verbose ? LogLevel::DEBUG : LogLevel::INFO); - - if (!config_path.IsNull()) { - ReadConfigFile(config, config_path); - Migrate(config); - } - + explicit GlobalInit(Path config_path) + :config(AutoLoadConfigFile(config_path)) + { io_thread.Start(); input_stream_global_init(config, @@ -234,7 +227,8 @@ try { /* initialize MPD */ - const GlobalInit init(c.config_path, c.verbose); + SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO); + const GlobalInit init(c.config_path); if (c.scan) return Scan(c.uri); diff --git a/test/run_neighbor_explorer.cxx b/test/run_neighbor_explorer.cxx index c22ed6b11..928d833fd 100644 --- a/test/run_neighbor_explorer.cxx +++ b/test/run_neighbor_explorer.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -17,9 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "config/File.hxx" -#include "config/Migrate.hxx" -#include "config/Data.hxx" +#include "ConfigGlue.hxx" #include "neighbor/Listener.hxx" #include "neighbor/Info.hxx" #include "neighbor/Glue.hxx" @@ -57,14 +55,12 @@ try { /* initialize the core */ - ConfigData config; EventLoop loop; const ShutdownHandler shutdown_handler(loop); /* read configuration file (mpd.conf) */ - ReadConfigFile(config, config_path); - Migrate(config); + const auto config = AutoLoadConfigFile(config_path); /* initialize neighbor plugins */ diff --git a/test/run_output.cxx b/test/run_output.cxx index 4b45eed7a..c69e8f67b 100644 --- a/test/run_output.cxx +++ b/test/run_output.cxx @@ -20,12 +20,7 @@ #include "output/Interface.hxx" #include "output/Registry.hxx" #include "output/OutputPlugin.hxx" -#include "config/Param.hxx" -#include "config/Data.hxx" -#include "config/File.hxx" -#include "config/Migrate.hxx" -#include "config/Option.hxx" -#include "config/Block.hxx" +#include "ConfigGlue.hxx" #include "event/Thread.hxx" #include "fs/Path.hxx" #include "AudioParser.hxx" @@ -122,9 +117,7 @@ try { /* read configuration file (mpd.conf) */ - ConfigData config; - ReadConfigFile(config, config_path); - Migrate(config); + const auto config = AutoLoadConfigFile(config_path); EventThread io_thread; io_thread.Start();