filter/LoadChain: move code to class FilterFactory
Eliminate a use of GetGlobalConfig().
This commit is contained in:
40
src/filter/Factory.cxx
Normal file
40
src/filter/Factory.cxx
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2003-2018 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.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "Factory.hxx"
|
||||
#include "LoadOne.hxx"
|
||||
#include "Prepared.hxx"
|
||||
#include "config/Data.hxx"
|
||||
#include "config/Block.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
std::unique_ptr<PreparedFilter>
|
||||
FilterFactory::MakeFilter(const char *name)
|
||||
{
|
||||
const auto *cfg = config.FindBlock(ConfigBlockOption::AUDIO_FILTER,
|
||||
"name", name);
|
||||
if (cfg == nullptr)
|
||||
throw FormatRuntimeError("Filter template not found: %s",
|
||||
name);
|
||||
|
||||
cfg->SetUsed();
|
||||
|
||||
return filter_configured_new(*cfg);
|
||||
}
|
40
src/filter/Factory.hxx
Normal file
40
src/filter/Factory.hxx
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2003-2018 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_FILTER_FACTORY_HXX
|
||||
#define MPD_FILTER_FACTORY_HXX
|
||||
|
||||
#include "check.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct ConfigData;
|
||||
class PreparedFilter;
|
||||
|
||||
class FilterFactory {
|
||||
const ConfigData &config;
|
||||
|
||||
public:
|
||||
explicit FilterFactory(const ConfigData &_config) noexcept
|
||||
:config(_config) {}
|
||||
|
||||
std::unique_ptr<PreparedFilter> MakeFilter(const char *name);
|
||||
};
|
||||
|
||||
#endif
|
@@ -19,43 +19,26 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "LoadChain.hxx"
|
||||
#include "LoadOne.hxx"
|
||||
#include "Factory.hxx"
|
||||
#include "Prepared.hxx"
|
||||
#include "plugins/ChainFilterPlugin.hxx"
|
||||
#include "config/Param.hxx"
|
||||
#include "config/Option.hxx"
|
||||
#include "config/Data.hxx"
|
||||
#include "config/Domain.hxx"
|
||||
#include "config/Block.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
filter_chain_append_new(PreparedFilter &chain, const ConfigData &config,
|
||||
filter_chain_append_new(PreparedFilter &chain, FilterFactory &factory,
|
||||
const char *template_name)
|
||||
{
|
||||
const auto *cfg = config.FindBlock(ConfigBlockOption::AUDIO_FILTER,
|
||||
"name", template_name);
|
||||
if (cfg == nullptr)
|
||||
throw FormatRuntimeError("Filter template not found: %s",
|
||||
template_name);
|
||||
|
||||
cfg->SetUsed();
|
||||
|
||||
// Instantiate one of those filter plugins with the template name as a hint
|
||||
auto f = filter_configured_new(*cfg);
|
||||
|
||||
const char *plugin_name = cfg->GetBlockValue("plugin",
|
||||
"unknown");
|
||||
filter_chain_append(chain, plugin_name, std::move(f));
|
||||
filter_chain_append(chain, template_name,
|
||||
factory.MakeFilter(template_name));
|
||||
}
|
||||
|
||||
void
|
||||
filter_chain_parse(PreparedFilter &chain,
|
||||
const ConfigData &config,
|
||||
FilterFactory &factory,
|
||||
const char *spec)
|
||||
{
|
||||
const char *const end = spec + strlen(spec);
|
||||
@@ -64,7 +47,7 @@ filter_chain_parse(PreparedFilter &chain,
|
||||
const char *comma = std::find(spec, end, ',');
|
||||
if (comma > spec) {
|
||||
const std::string name(spec, comma);
|
||||
filter_chain_append_new(chain, config, name.c_str());
|
||||
filter_chain_append_new(chain, factory, name.c_str());
|
||||
}
|
||||
|
||||
if (comma == end)
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#ifndef MPD_FILTER_LOAD_CHAIN_HXX
|
||||
#define MPD_FILTER_LOAD_CHAIN_HXX
|
||||
|
||||
struct ConfigData;
|
||||
class FilterFactory;
|
||||
class PreparedFilter;
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ class PreparedFilter;
|
||||
*/
|
||||
void
|
||||
filter_chain_parse(PreparedFilter &chain,
|
||||
const ConfigData &config,
|
||||
FilterFactory &factory,
|
||||
const char *spec);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user