input/Registry: replace the input_plugins_for_each macros with a container class
This commit is contained in:
parent
49edb16de0
commit
fb87e19bae
|
@ -212,8 +212,8 @@ static void version()
|
||||||
" archive"
|
" archive"
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
input_plugins_for_each(plugin)
|
for (const InputPlugin &plugin : GetAllInputPlugins())
|
||||||
fmt::print(" {}", plugin->name);
|
fmt::print(" {}", plugin.name);
|
||||||
|
|
||||||
fmt::print("\n\n"
|
fmt::print("\n\n"
|
||||||
"Playlist plugins:\n");
|
"Playlist plugins:\n");
|
||||||
|
|
|
@ -73,7 +73,7 @@ input_stream_global_init(const ConfigData &config, EventLoop &event_loop)
|
||||||
void
|
void
|
||||||
input_stream_global_finish() noexcept
|
input_stream_global_finish() noexcept
|
||||||
{
|
{
|
||||||
input_plugins_for_each_enabled(plugin)
|
for (const auto &plugin : GetEnabledInputPlugins())
|
||||||
if (plugin->finish != nullptr)
|
if (plugin.finish != nullptr)
|
||||||
plugin->finish();
|
plugin.finish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,11 @@ InputStream::Open(const char *url, Mutex &mutex)
|
||||||
return OpenLocalInputStream(path, mutex);
|
return OpenLocalInputStream(path, mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
input_plugins_for_each_enabled(plugin) {
|
for (const auto &plugin : GetEnabledInputPlugins()) {
|
||||||
if (!plugin->SupportsUri(url))
|
if (!plugin.SupportsUri(url))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto is = plugin->open(url, mutex);
|
if (auto is = plugin.open(url, mutex))
|
||||||
if (is != nullptr)
|
|
||||||
return input_rewind_open(std::move(is));
|
return input_rewind_open(std::move(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,10 +72,11 @@ bool input_plugins_enabled[std::max(n_input_plugins, std::size_t(1))];
|
||||||
bool
|
bool
|
||||||
HasRemoteTagScanner(const char *uri) noexcept
|
HasRemoteTagScanner(const char *uri) noexcept
|
||||||
{
|
{
|
||||||
input_plugins_for_each_enabled(plugin)
|
for (const auto &plugin : GetEnabledInputPlugins()) {
|
||||||
if (plugin->scan_tags != nullptr &&
|
if (plugin.scan_tags != nullptr &&
|
||||||
plugin->SupportsUri(uri))
|
plugin.SupportsUri(uri))
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_INPUT_REGISTRY_HXX
|
#pragma once
|
||||||
#define MPD_INPUT_REGISTRY_HXX
|
|
||||||
|
#include "util/DereferenceIterator.hxx"
|
||||||
|
#include "util/FilteredContainer.hxx"
|
||||||
|
#include "util/TerminatedArray.hxx"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NULL terminated list of all input plugins which were enabled at
|
* NULL terminated list of all input plugins which were enabled at
|
||||||
|
@ -12,18 +15,19 @@ extern const struct InputPlugin *const input_plugins[];
|
||||||
|
|
||||||
extern bool input_plugins_enabled[];
|
extern bool input_plugins_enabled[];
|
||||||
|
|
||||||
#define input_plugins_for_each(plugin) \
|
static inline auto
|
||||||
for (const InputPlugin *plugin, \
|
GetAllInputPlugins() noexcept
|
||||||
*const*input_plugin_iterator = &input_plugins[0]; \
|
{
|
||||||
(plugin = *input_plugin_iterator) != NULL; \
|
return DereferenceContainerAdapter{TerminatedArray<const InputPlugin *const, nullptr>{input_plugins}};
|
||||||
++input_plugin_iterator)
|
}
|
||||||
|
|
||||||
#define input_plugins_for_each_enabled(plugin) \
|
static inline auto
|
||||||
input_plugins_for_each(plugin) \
|
GetEnabledInputPlugins() noexcept
|
||||||
if (input_plugins_enabled[input_plugin_iterator - input_plugins])
|
{
|
||||||
|
const auto all = GetAllInputPlugins();
|
||||||
|
return FilteredContainer{all.begin(), all.end(), input_plugins_enabled};
|
||||||
|
}
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
bool
|
bool
|
||||||
HasRemoteTagScanner(const char *uri) noexcept;
|
HasRemoteTagScanner(const char *uri) noexcept;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -9,12 +9,11 @@
|
||||||
std::unique_ptr<RemoteTagScanner>
|
std::unique_ptr<RemoteTagScanner>
|
||||||
InputScanTags(const char *uri, RemoteTagHandler &handler)
|
InputScanTags(const char *uri, RemoteTagHandler &handler)
|
||||||
{
|
{
|
||||||
input_plugins_for_each_enabled(plugin) {
|
for (const auto &plugin : GetEnabledInputPlugins()) {
|
||||||
if (plugin->scan_tags == nullptr || !plugin->SupportsUri(uri))
|
if (plugin.scan_tags == nullptr || !plugin.SupportsUri(uri))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto scanner = plugin->scan_tags(uri, handler);
|
if (auto scanner = plugin.scan_tags(uri, handler))
|
||||||
if (scanner)
|
|
||||||
return scanner;
|
return scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
src/ls.cxx
17
src/ls.cxx
|
@ -21,10 +21,12 @@ void print_supported_uri_schemes_to_fp(FILE *fp)
|
||||||
fmt::print(fp, " file://");
|
fmt::print(fp, " file://");
|
||||||
#endif
|
#endif
|
||||||
std::set<std::string, std::less<>> protocols;
|
std::set<std::string, std::less<>> protocols;
|
||||||
input_plugins_for_each(plugin)
|
|
||||||
plugin->ForeachSupportedUri([&](const char* uri) {
|
for (const auto &plugin : GetAllInputPlugins()) {
|
||||||
|
plugin.ForeachSupportedUri([&](const char* uri) {
|
||||||
protocols.emplace(uri);
|
protocols.emplace(uri);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const DecoderPlugin &plugin : GetAllDecoderPlugins()) {
|
for (const DecoderPlugin &plugin : GetAllDecoderPlugins()) {
|
||||||
if (plugin.protocols != nullptr)
|
if (plugin.protocols != nullptr)
|
||||||
|
@ -41,10 +43,12 @@ void
|
||||||
print_supported_uri_schemes(Response &r)
|
print_supported_uri_schemes(Response &r)
|
||||||
{
|
{
|
||||||
std::set<std::string, std::less<>> protocols;
|
std::set<std::string, std::less<>> protocols;
|
||||||
input_plugins_for_each_enabled(plugin)
|
|
||||||
plugin->ForeachSupportedUri([&](const char* uri) {
|
for (const auto &plugin : GetEnabledInputPlugins()) {
|
||||||
|
plugin.ForeachSupportedUri([&](const char* uri) {
|
||||||
protocols.emplace(uri);
|
protocols.emplace(uri);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||||
if (plugin.protocols != nullptr)
|
if (plugin.protocols != nullptr)
|
||||||
|
@ -61,9 +65,10 @@ uri_supported_scheme(const char *uri) noexcept
|
||||||
{
|
{
|
||||||
assert(uri_has_scheme(uri));
|
assert(uri_has_scheme(uri));
|
||||||
|
|
||||||
input_plugins_for_each_enabled(plugin)
|
for (const auto &plugin : GetEnabledInputPlugins()) {
|
||||||
if (plugin->SupportsUri(uri))
|
if (plugin.SupportsUri(uri))
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||||
if (plugin.SupportsUri(uri))
|
if (plugin.SupportsUri(uri))
|
||||||
|
|
Loading…
Reference in New Issue