2009-10-12 22:34:04 +02:00
|
|
|
/*
|
2019-06-11 19:24:57 +02:00
|
|
|
* Copyright 2003-2019 The Music Player Daemon Project
|
2009-10-12 22:34:04 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-01-27 17:38:09 +01:00
|
|
|
#ifndef MPD_PLAYLIST_PLUGIN_HXX
|
|
|
|
#define MPD_PLAYLIST_PLUGIN_HXX
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2016-02-21 12:53:47 +01:00
|
|
|
#include "input/Ptr.hxx"
|
2019-05-07 19:23:01 +02:00
|
|
|
#include "thread/Mutex.hxx"
|
2016-02-21 12:53:47 +01:00
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
struct ConfigBlock;
|
2013-07-30 20:11:57 +02:00
|
|
|
struct Tag;
|
2013-09-05 09:37:54 +02:00
|
|
|
class SongEnumerator;
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2019-09-01 14:58:49 +02:00
|
|
|
struct PlaylistPlugin {
|
2009-10-12 22:34:04 +02:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the plugin. Optional method.
|
|
|
|
*
|
2019-06-11 19:24:57 +02:00
|
|
|
* @param block a configuration block for this plugin (may be
|
|
|
|
* empty if none is configured)
|
2009-10-12 22:34:04 +02:00
|
|
|
* @return true if the plugin was initialized successfully,
|
|
|
|
* false if the plugin is not available
|
|
|
|
*/
|
2019-09-01 14:58:20 +02:00
|
|
|
bool (*init)(const ConfigBlock &block) = nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deinitialize a plugin which was initialized successfully.
|
|
|
|
* Optional method.
|
|
|
|
*/
|
2019-09-01 14:58:20 +02:00
|
|
|
void (*finish)() = nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the playlist on the specified URI. This URI has
|
|
|
|
* either matched one of the schemes or one of the suffixes.
|
|
|
|
*/
|
2018-01-20 19:56:44 +01:00
|
|
|
std::unique_ptr<SongEnumerator> (*open_uri)(const char *uri,
|
2019-09-01 14:58:20 +02:00
|
|
|
Mutex &mutex) = nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the playlist in the specified input stream. It has
|
|
|
|
* either matched one of the suffixes or one of the MIME
|
|
|
|
* types.
|
2016-02-21 12:53:47 +01:00
|
|
|
*
|
|
|
|
* @parm is the input stream; the pointer will not be
|
|
|
|
* invalidated when the function returns nullptr
|
2009-10-12 22:34:04 +02:00
|
|
|
*/
|
2019-09-01 14:58:20 +02:00
|
|
|
std::unique_ptr<SongEnumerator> (*open_stream)(InputStreamPtr &&is) = nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2019-09-01 14:58:20 +02:00
|
|
|
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;
|
|
|
|
}
|
2009-10-12 22:34:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize a plugin.
|
|
|
|
*
|
2015-03-17 11:21:29 +01:00
|
|
|
* @param block a configuration block for this plugin, or nullptr if none
|
2009-10-12 22:34:04 +02:00
|
|
|
* is configured
|
|
|
|
* @return true if the plugin was initialized successfully, false if
|
|
|
|
* the plugin is not available
|
|
|
|
*/
|
|
|
|
static inline bool
|
2019-09-01 14:58:49 +02:00
|
|
|
playlist_plugin_init(const PlaylistPlugin *plugin,
|
2015-01-21 22:13:44 +01:00
|
|
|
const ConfigBlock &block)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
2013-09-05 09:40:32 +02:00
|
|
|
return plugin->init != nullptr
|
2015-01-21 22:13:44 +01:00
|
|
|
? plugin->init(block)
|
2009-10-12 22:34:04 +02:00
|
|
|
: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deinitialize a plugin which was initialized successfully.
|
|
|
|
*/
|
|
|
|
static inline void
|
2019-09-01 14:58:49 +02:00
|
|
|
playlist_plugin_finish(const PlaylistPlugin *plugin) noexcept
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
2013-09-05 09:40:32 +02:00
|
|
|
if (plugin->finish != nullptr)
|
2009-10-12 22:34:04 +02:00
|
|
|
plugin->finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|