playlist_list: add _for_each() macros
This commit is contained in:
parent
d5b9be0393
commit
5665de5ee7
@ -40,7 +40,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const struct playlist_plugin *const playlist_plugins[] = {
|
const struct playlist_plugin *const playlist_plugins[] = {
|
||||||
&extm3u_playlist_plugin,
|
&extm3u_playlist_plugin,
|
||||||
&m3u_playlist_plugin,
|
&m3u_playlist_plugin,
|
||||||
&xspf_playlist_plugin,
|
&xspf_playlist_plugin,
|
||||||
@ -62,6 +62,10 @@ static const struct playlist_plugin *const playlist_plugins[] = {
|
|||||||
/** which plugins have been initialized successfully? */
|
/** which plugins have been initialized successfully? */
|
||||||
static bool playlist_plugins_enabled[G_N_ELEMENTS(playlist_plugins)];
|
static bool playlist_plugins_enabled[G_N_ELEMENTS(playlist_plugins)];
|
||||||
|
|
||||||
|
#define playlist_plugins_for_each_enabled(plugin) \
|
||||||
|
playlist_plugins_for_each(plugin) \
|
||||||
|
if (playlist_plugins_enabled[playlist_plugin_iterator - playlist_plugins])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the "playlist" configuration block for the specified plugin.
|
* Find the "playlist" configuration block for the specified plugin.
|
||||||
*
|
*
|
||||||
@ -109,9 +113,8 @@ playlist_list_global_init(void)
|
|||||||
void
|
void
|
||||||
playlist_list_global_finish(void)
|
playlist_list_global_finish(void)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i)
|
playlist_plugins_for_each_enabled(plugin)
|
||||||
if (playlist_plugins_enabled[i])
|
playlist_plugin_finish(plugin);
|
||||||
playlist_plugin_finish(playlist_plugins[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct playlist_provider *
|
static struct playlist_provider *
|
||||||
@ -200,11 +203,8 @@ playlist_list_open_stream_mime2(struct input_stream *is, const char *mime)
|
|||||||
assert(is != NULL);
|
assert(is != NULL);
|
||||||
assert(mime != NULL);
|
assert(mime != NULL);
|
||||||
|
|
||||||
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
const struct playlist_plugin *plugin = playlist_plugins[i];
|
if (plugin->open_stream != NULL &&
|
||||||
|
|
||||||
if (playlist_plugins_enabled[i] &&
|
|
||||||
plugin->open_stream != NULL &&
|
|
||||||
plugin->mime_types != NULL &&
|
plugin->mime_types != NULL &&
|
||||||
string_array_contains(plugin->mime_types, mime)) {
|
string_array_contains(plugin->mime_types, mime)) {
|
||||||
/* rewind the stream, so each plugin gets a
|
/* rewind the stream, so each plugin gets a
|
||||||
@ -248,11 +248,8 @@ playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix)
|
|||||||
assert(is != NULL);
|
assert(is != NULL);
|
||||||
assert(suffix != NULL);
|
assert(suffix != NULL);
|
||||||
|
|
||||||
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
const struct playlist_plugin *plugin = playlist_plugins[i];
|
if (plugin->open_stream != NULL &&
|
||||||
|
|
||||||
if (playlist_plugins_enabled[i] &&
|
|
||||||
plugin->open_stream != NULL &&
|
|
||||||
plugin->suffixes != NULL &&
|
plugin->suffixes != NULL &&
|
||||||
string_array_contains(plugin->suffixes, suffix)) {
|
string_array_contains(plugin->suffixes, suffix)) {
|
||||||
/* rewind the stream, so each plugin gets a
|
/* rewind the stream, so each plugin gets a
|
||||||
@ -306,10 +303,8 @@ playlist_suffix_supported(const char *suffix)
|
|||||||
{
|
{
|
||||||
assert(suffix != NULL);
|
assert(suffix != NULL);
|
||||||
|
|
||||||
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
const struct playlist_plugin *plugin = playlist_plugins[i];
|
if (plugin->suffixes != NULL &&
|
||||||
|
|
||||||
if (playlist_plugins_enabled[i] && plugin->suffixes != NULL &&
|
|
||||||
string_array_contains(plugin->suffixes, suffix))
|
string_array_contains(plugin->suffixes, suffix))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
struct playlist_provider;
|
struct playlist_provider;
|
||||||
struct input_stream;
|
struct input_stream;
|
||||||
|
|
||||||
|
extern const struct playlist_plugin *const playlist_plugins[];
|
||||||
|
|
||||||
|
#define playlist_plugins_for_each(plugin) \
|
||||||
|
for (const struct playlist_plugin *plugin, \
|
||||||
|
*const*playlist_plugin_iterator = &playlist_plugins[0]; \
|
||||||
|
(plugin = *playlist_plugin_iterator) != NULL; \
|
||||||
|
++playlist_plugin_iterator)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes all playlist plugins.
|
* Initializes all playlist plugins.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user