decoder/List: add iterable container for decoder plugins
This commit is contained in:
parent
f6a687dc2b
commit
a27fb71c4c
|
@ -139,7 +139,7 @@ static void version()
|
||||||
"\n"
|
"\n"
|
||||||
"Decoder plugins:\n");
|
"Decoder plugins:\n");
|
||||||
|
|
||||||
decoder_plugins_for_each([](const DecoderPlugin &plugin){
|
for (const DecoderPlugin &plugin : GetAllDecoderPlugins()) {
|
||||||
fmt::print(" [{}]", plugin.name);
|
fmt::print(" [{}]", plugin.name);
|
||||||
|
|
||||||
const char *const*suffixes = plugin.suffixes;
|
const char *const*suffixes = plugin.suffixes;
|
||||||
|
@ -156,7 +156,7 @@ static void version()
|
||||||
fmt::print(" {}", i);
|
fmt::print(" {}", i);
|
||||||
|
|
||||||
fmt::print("\n");
|
fmt::print("\n");
|
||||||
});
|
}
|
||||||
|
|
||||||
fmt::print("\n"
|
fmt::print("\n"
|
||||||
"Filters:\n"
|
"Filters:\n"
|
||||||
|
|
|
@ -157,9 +157,8 @@ decoder_plugin_init_all(const ConfigData &config)
|
||||||
void
|
void
|
||||||
decoder_plugin_deinit_all() noexcept
|
decoder_plugin_deinit_all() noexcept
|
||||||
{
|
{
|
||||||
decoder_plugins_for_each_enabled([=](const DecoderPlugin &plugin){
|
for (const auto &plugin : GetEnabledDecoderPlugins())
|
||||||
plugin.Finish();
|
plugin.Finish();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -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_DECODER_LIST_HXX
|
#pragma once
|
||||||
#define MPD_DECODER_LIST_HXX
|
|
||||||
|
#include "util/DereferenceIterator.hxx"
|
||||||
|
#include "util/FilteredContainer.hxx"
|
||||||
|
#include "util/TerminatedArray.hxx"
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
@ -37,13 +40,26 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline auto
|
||||||
|
GetAllDecoderPlugins() noexcept
|
||||||
|
{
|
||||||
|
return DereferenceContainerAdapter{TerminatedArray<const DecoderPlugin *const, nullptr>{decoder_plugins}};
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline auto
|
||||||
|
GetEnabledDecoderPlugins() noexcept
|
||||||
|
{
|
||||||
|
const auto all = GetAllDecoderPlugins();
|
||||||
|
return FilteredContainer{all.begin(), all.end(), decoder_plugins_enabled};
|
||||||
|
}
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
static inline const DecoderPlugin *
|
static inline const DecoderPlugin *
|
||||||
decoder_plugins_find(F f) noexcept
|
decoder_plugins_find(F f) noexcept
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
|
for (const auto &plugin : GetEnabledDecoderPlugins())
|
||||||
if (decoder_plugins_enabled[i] && f(*decoder_plugins[i]))
|
if (f(plugin))
|
||||||
return decoder_plugins[i];
|
return &plugin;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -52,30 +68,13 @@ template<typename F>
|
||||||
static inline bool
|
static inline bool
|
||||||
decoder_plugins_try(F f)
|
decoder_plugins_try(F f)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
|
for (const auto &plugin : GetEnabledDecoderPlugins())
|
||||||
if (decoder_plugins_enabled[i] && f(*decoder_plugins[i]))
|
if (f(plugin))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F>
|
|
||||||
static inline void
|
|
||||||
decoder_plugins_for_each(F f)
|
|
||||||
{
|
|
||||||
for (auto i = decoder_plugins; *i != nullptr; ++i)
|
|
||||||
f(**i);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename F>
|
|
||||||
static inline void
|
|
||||||
decoder_plugins_for_each_enabled(F f)
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i)
|
|
||||||
if (decoder_plugins_enabled[i])
|
|
||||||
f(*decoder_plugins[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is there at least once #DecoderPlugin that supports the specified
|
* Is there at least once #DecoderPlugin that supports the specified
|
||||||
* file name suffix?
|
* file name suffix?
|
||||||
|
@ -83,5 +82,3 @@ decoder_plugins_for_each_enabled(F f)
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
bool
|
bool
|
||||||
decoder_plugins_supports_suffix(std::string_view suffix) noexcept;
|
decoder_plugins_supports_suffix(std::string_view suffix) noexcept;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ decoder_plugin_print(Response &r,
|
||||||
void
|
void
|
||||||
decoder_list_print(Response &r)
|
decoder_list_print(Response &r)
|
||||||
{
|
{
|
||||||
const auto f = [&](const auto &plugin)
|
for (const auto &plugin : GetEnabledDecoderPlugins())
|
||||||
{ return decoder_plugin_print(r, plugin); };
|
decoder_plugin_print(r, plugin);
|
||||||
decoder_plugins_for_each_enabled(f);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,10 @@ void print_supported_uri_schemes_to_fp(FILE *fp)
|
||||||
protocols.emplace(uri);
|
protocols.emplace(uri);
|
||||||
});
|
});
|
||||||
|
|
||||||
decoder_plugins_for_each([&protocols](const auto &plugin){
|
for (const DecoderPlugin &plugin : GetAllDecoderPlugins()) {
|
||||||
if (plugin.protocols != nullptr)
|
if (plugin.protocols != nullptr)
|
||||||
protocols.merge(plugin.protocols());
|
protocols.merge(plugin.protocols());
|
||||||
});
|
};
|
||||||
|
|
||||||
for (const auto& protocol : protocols) {
|
for (const auto& protocol : protocols) {
|
||||||
fmt::print(fp, " {}", protocol);
|
fmt::print(fp, " {}", protocol);
|
||||||
|
@ -46,10 +46,10 @@ print_supported_uri_schemes(Response &r)
|
||||||
protocols.emplace(uri);
|
protocols.emplace(uri);
|
||||||
});
|
});
|
||||||
|
|
||||||
decoder_plugins_for_each_enabled([&protocols](const auto &plugin){
|
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||||
if (plugin.protocols != nullptr)
|
if (plugin.protocols != nullptr)
|
||||||
protocols.merge(plugin.protocols());
|
protocols.merge(plugin.protocols());
|
||||||
});
|
}
|
||||||
|
|
||||||
for (const auto& protocol : protocols) {
|
for (const auto& protocol : protocols) {
|
||||||
r.Fmt(FMT_STRING("handler: {}\n"), protocol);
|
r.Fmt(FMT_STRING("handler: {}\n"), protocol);
|
||||||
|
|
Loading…
Reference in New Issue