test/ConfigGlue: merge duplicate code from various debug programs

This commit is contained in:
Max Kellermann 2019-02-05 21:56:20 +01:00
parent 848f6aa5ab
commit b0739eca87
9 changed files with 78 additions and 81 deletions

41
test/ConfigGlue.hxx Normal file
View File

@ -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

View File

@ -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);

View File

@ -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) {

View File

@ -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();

View File

@ -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) {

View File

@ -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 */

View File

@ -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);

View File

@ -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 */

View File

@ -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();