summaryrefslogtreecommitdiff
path: root/src/filter
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-18 20:57:02 +0200
committerMax Kellermann <max@musicpd.org>2018-08-18 20:57:02 +0200
commit4531e4cc55fa57964a3014fd65877ead3c23fa5d (patch)
tree7ee3cb6f3a25452739635a39bf4ede97825ea677 /src/filter
parent1ba35e1fd4871f2430d7f3bf5a799f2ad39f73ab (diff)
filter/LoadChain: move code to class FilterFactory
Eliminate a use of GetGlobalConfig().
Diffstat (limited to 'src/filter')
-rw-r--r--src/filter/Factory.cxx40
-rw-r--r--src/filter/Factory.hxx40
-rw-r--r--src/filter/LoadChain.cxx31
-rw-r--r--src/filter/LoadChain.hxx4
4 files changed, 89 insertions, 26 deletions
diff --git a/src/filter/Factory.cxx b/src/filter/Factory.cxx
new file mode 100644
index 000000000..baa4cd09e
--- /dev/null
+++ b/src/filter/Factory.cxx
@@ -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);
+}
diff --git a/src/filter/Factory.hxx b/src/filter/Factory.hxx
new file mode 100644
index 000000000..350cc2941
--- /dev/null
+++ b/src/filter/Factory.hxx
@@ -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
diff --git a/src/filter/LoadChain.cxx b/src/filter/LoadChain.cxx
index e400dcebf..df5708cff 100644
--- a/src/filter/LoadChain.cxx
+++ b/src/filter/LoadChain.cxx
@@ -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)
diff --git a/src/filter/LoadChain.hxx b/src/filter/LoadChain.hxx
index cfe4ae8b2..adbcc82b4 100644
--- a/src/filter/LoadChain.hxx
+++ b/src/filter/LoadChain.hxx
@@ -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