playlist/Plugin: add constructors

This commit is contained in:
Max Kellermann 2019-09-01 14:58:20 +02:00
parent 0d16772dea
commit f885e068c8
11 changed files with 80 additions and 129 deletions

View File

@ -38,20 +38,20 @@ struct PlaylistPlugin {
* @return true if the plugin was initialized successfully,
* false if the plugin is not available
*/
bool (*init)(const ConfigBlock &block);
bool (*init)(const ConfigBlock &block) = nullptr;
/**
* Deinitialize a plugin which was initialized successfully.
* Optional method.
*/
void (*finish)();
void (*finish)() = nullptr;
/**
* Opens the playlist on the specified URI. This URI has
* either matched one of the schemes or one of the suffixes.
*/
std::unique_ptr<SongEnumerator> (*open_uri)(const char *uri,
Mutex &mutex);
Mutex &mutex) = nullptr;
/**
* Opens the playlist in the specified input stream. It has
@ -61,11 +61,46 @@ struct PlaylistPlugin {
* @parm is the input stream; the pointer will not be
* invalidated when the function returns nullptr
*/
std::unique_ptr<SongEnumerator> (*open_stream)(InputStreamPtr &&is);
std::unique_ptr<SongEnumerator> (*open_stream)(InputStreamPtr &&is) = nullptr;
const char *const*schemes;
const char *const*suffixes;
const char *const*mime_types;
const char *const*schemes = nullptr;
const char *const*suffixes = nullptr;
const char *const*mime_types = nullptr;
constexpr PlaylistPlugin(const char *_name,
std::unique_ptr<SongEnumerator> (*_open_uri)(const char *uri,
Mutex &mutex)) noexcept
:name(_name), open_uri(_open_uri) {}
constexpr PlaylistPlugin(const char *_name,
std::unique_ptr<SongEnumerator> (*_open_stream)(InputStreamPtr &&is)) noexcept
:name(_name), open_stream(_open_stream) {}
constexpr auto WithInit(bool (*_init)(const ConfigBlock &block),
void (*_finish)() noexcept = nullptr) noexcept {
auto copy = *this;
copy.init = _init;
copy.finish = _finish;
return copy;
}
constexpr auto WithSchemes(const char *const*_schemes) noexcept {
auto copy = *this;
copy.schemes = _schemes;
return copy;
}
constexpr auto WithSuffixes(const char *const*_suffixes) noexcept {
auto copy = *this;
copy.suffixes = _suffixes;
return copy;
}
constexpr auto WithMimeTypes(const char *const*_mime_types) noexcept {
auto copy = *this;
copy.mime_types = _mime_types;
return copy;
}
};
/**

View File

@ -166,15 +166,7 @@ static const char *const asx_mime_types[] = {
nullptr
};
const PlaylistPlugin asx_playlist_plugin = {
"asx",
nullptr,
nullptr,
nullptr,
asx_open_stream,
nullptr,
asx_suffixes,
asx_mime_types,
};
const PlaylistPlugin asx_playlist_plugin =
PlaylistPlugin("asx", asx_open_stream)
.WithSuffixes(asx_suffixes)
.WithMimeTypes(asx_mime_types);

View File

@ -70,15 +70,7 @@ static const char *const cue_playlist_mime_types[] = {
nullptr
};
const PlaylistPlugin cue_playlist_plugin = {
"cue",
nullptr,
nullptr,
nullptr,
cue_playlist_open_stream,
nullptr,
cue_playlist_suffixes,
cue_playlist_mime_types,
};
const PlaylistPlugin cue_playlist_plugin =
PlaylistPlugin("cue", cue_playlist_open_stream)
.WithSuffixes(cue_playlist_suffixes)
.WithMimeTypes(cue_playlist_mime_types);

View File

@ -159,15 +159,6 @@ static const char *const embcue_playlist_suffixes[] = {
nullptr
};
const PlaylistPlugin embcue_playlist_plugin = {
"embcue",
nullptr,
nullptr,
embcue_playlist_open_uri,
nullptr,
nullptr,
embcue_playlist_suffixes,
nullptr,
};
const PlaylistPlugin embcue_playlist_plugin =
PlaylistPlugin("embcue", embcue_playlist_open_uri)
.WithSuffixes(embcue_playlist_suffixes);

View File

@ -147,15 +147,7 @@ static const char *const extm3u_mime_types[] = {
nullptr
};
const PlaylistPlugin extm3u_playlist_plugin = {
"extm3u",
nullptr,
nullptr,
nullptr,
extm3u_open_stream,
nullptr,
extm3u_suffixes,
extm3u_mime_types,
};
const PlaylistPlugin extm3u_playlist_plugin =
PlaylistPlugin("extm3u", extm3u_open_stream)
.WithSuffixes(extm3u_suffixes)
.WithMimeTypes(extm3u_mime_types);

View File

@ -103,15 +103,6 @@ static const char *const flac_playlist_suffixes[] = {
nullptr
};
const PlaylistPlugin flac_playlist_plugin = {
"flac",
nullptr,
nullptr,
nullptr,
flac_playlist_open_stream,
nullptr,
flac_playlist_suffixes,
nullptr,
};
const PlaylistPlugin flac_playlist_plugin =
PlaylistPlugin("flac", flac_playlist_open_stream)
.WithSuffixes(flac_playlist_suffixes);

View File

@ -69,15 +69,7 @@ static const char *const m3u_mime_types[] = {
nullptr
};
const PlaylistPlugin m3u_playlist_plugin = {
"m3u",
nullptr,
nullptr,
nullptr,
m3u_open_stream,
nullptr,
m3u_suffixes,
m3u_mime_types,
};
const PlaylistPlugin m3u_playlist_plugin =
PlaylistPlugin("m3u", m3u_open_stream)
.WithSuffixes(m3u_suffixes)
.WithMimeTypes(m3u_mime_types);

View File

@ -172,15 +172,7 @@ static const char *const pls_mime_types[] = {
nullptr
};
const PlaylistPlugin pls_playlist_plugin = {
"pls",
nullptr,
nullptr,
nullptr,
pls_open_stream,
nullptr,
pls_suffixes,
pls_mime_types,
};
const PlaylistPlugin pls_playlist_plugin =
PlaylistPlugin("pls", pls_open_stream)
.WithSuffixes(pls_suffixes)
.WithMimeTypes(pls_mime_types);

View File

@ -165,15 +165,7 @@ static const char *const rss_mime_types[] = {
nullptr
};
const PlaylistPlugin rss_playlist_plugin = {
"rss",
nullptr,
nullptr,
nullptr,
rss_open_stream,
nullptr,
rss_suffixes,
rss_mime_types,
};
const PlaylistPlugin rss_playlist_plugin =
PlaylistPlugin("rss", rss_open_stream)
.WithSuffixes(rss_suffixes)
.WithMimeTypes(rss_mime_types);

View File

@ -288,17 +288,7 @@ static const char *const soundcloud_schemes[] = {
nullptr
};
const PlaylistPlugin soundcloud_playlist_plugin = {
"soundcloud",
soundcloud_init,
nullptr,
soundcloud_open_uri,
nullptr,
soundcloud_schemes,
nullptr,
nullptr,
};
const PlaylistPlugin soundcloud_playlist_plugin =
PlaylistPlugin("soundcloud", soundcloud_open_uri)
.WithInit(soundcloud_init)
.WithSchemes(soundcloud_schemes);

View File

@ -211,15 +211,7 @@ static const char *const xspf_mime_types[] = {
nullptr
};
const PlaylistPlugin xspf_playlist_plugin = {
"xspf",
nullptr,
nullptr,
nullptr,
xspf_open_stream,
nullptr,
xspf_suffixes,
xspf_mime_types,
};
const PlaylistPlugin xspf_playlist_plugin =
PlaylistPlugin("xspf", xspf_open_stream)
.WithSuffixes(xspf_suffixes)
.WithMimeTypes(xspf_mime_types);