2009-03-02 20:13:08 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2009-03-02 20:13:08 +01: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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-02 20:13:08 +01:00
|
|
|
*/
|
|
|
|
|
2013-01-25 22:43:01 +01:00
|
|
|
#ifndef MPD_INPUT_PLUGIN_HXX
|
|
|
|
#define MPD_INPUT_PLUGIN_HXX
|
2009-03-02 20:13:08 +01:00
|
|
|
|
2017-12-26 20:05:22 +01:00
|
|
|
#include "Ptr.hxx"
|
2019-05-07 19:23:01 +02:00
|
|
|
#include "thread/Mutex.hxx"
|
2018-10-24 20:25:32 +02:00
|
|
|
#include "util/Compiler.h"
|
2019-04-17 20:47:55 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2017-12-26 20:05:22 +01:00
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
struct ConfigBlock;
|
2017-01-25 23:06:12 +01:00
|
|
|
class EventLoop;
|
2018-01-26 16:06:41 +01:00
|
|
|
class RemoteTagScanner;
|
|
|
|
class RemoteTagHandler;
|
2009-03-02 20:13:08 +01:00
|
|
|
|
2013-10-17 10:20:57 +02:00
|
|
|
struct InputPlugin {
|
2009-03-02 23:08:17 +01:00
|
|
|
const char *name;
|
|
|
|
|
2018-10-24 20:25:32 +02:00
|
|
|
/**
|
|
|
|
* A nullptr-terminated list of URI prefixes handled by this
|
|
|
|
* plugin. This is usually a string in the form "scheme://".
|
|
|
|
*/
|
|
|
|
const char *const*prefixes;
|
|
|
|
|
2009-03-02 20:45:50 +01:00
|
|
|
/**
|
|
|
|
* Global initialization. This method is called when MPD starts.
|
|
|
|
*
|
2016-09-09 15:11:52 +02:00
|
|
|
* Throws #PluginUnavailable if the plugin is not available
|
|
|
|
* and shall be disabled.
|
2016-09-05 12:05:54 +02:00
|
|
|
*
|
|
|
|
* Throws std::runtime_error on (fatal) error.
|
2009-03-02 20:45:50 +01:00
|
|
|
*/
|
2017-01-25 23:06:12 +01:00
|
|
|
void (*init)(EventLoop &event_loop, const ConfigBlock &block);
|
2009-03-02 20:45:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Global deinitialization. Called once before MPD shuts
|
|
|
|
* down (only if init() has returned true).
|
|
|
|
*/
|
2015-03-03 20:05:08 +01:00
|
|
|
void (*finish)();
|
2009-03-02 20:45:50 +01:00
|
|
|
|
2016-09-09 15:37:06 +02:00
|
|
|
/**
|
2018-02-17 10:32:17 +01:00
|
|
|
* Attempt to open the given URI. Returns nullptr if the
|
|
|
|
* plugin does not support this URI.
|
|
|
|
*
|
2016-09-09 15:37:06 +02:00
|
|
|
* Throws std::runtime_error on error.
|
|
|
|
*/
|
2018-06-22 19:37:18 +02:00
|
|
|
InputStreamPtr (*open)(const char *uri, Mutex &mutex);
|
2018-01-26 16:06:41 +01:00
|
|
|
|
2019-04-17 20:47:55 +02:00
|
|
|
/**
|
|
|
|
* return a set of supported protocols
|
|
|
|
*/
|
|
|
|
std::set<std::string> (*protocols)();
|
|
|
|
|
2018-01-26 16:06:41 +01:00
|
|
|
/**
|
|
|
|
* Prepare a #RemoteTagScanner. The operation must be started
|
2018-02-17 10:32:17 +01:00
|
|
|
* using RemoteTagScanner::Start(). Returns nullptr if the
|
|
|
|
* plugin does not support this URI.
|
2018-01-26 16:06:41 +01:00
|
|
|
*
|
|
|
|
* Throws on error.
|
|
|
|
*
|
|
|
|
* @return nullptr if the given URI is not supported.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<RemoteTagScanner> (*scan_tags)(const char *uri,
|
|
|
|
RemoteTagHandler &handler) = nullptr;
|
2018-10-24 20:25:32 +02:00
|
|
|
|
|
|
|
gcc_pure
|
|
|
|
bool SupportsUri(const char *uri) const noexcept;
|
2019-04-17 20:47:55 +02:00
|
|
|
|
|
|
|
template<typename F>
|
|
|
|
void ForeachSupportedUri(F lambda) const noexcept {
|
|
|
|
assert(prefixes || protocols);
|
|
|
|
|
|
|
|
if (prefixes != nullptr) {
|
|
|
|
for (auto schema = prefixes; *schema != nullptr; ++schema) {
|
|
|
|
lambda(*schema);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (protocols != nullptr) {
|
|
|
|
for (auto schema : protocols()) {
|
|
|
|
lambda(schema.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-02 20:13:08 +01:00
|
|
|
};
|
|
|
|
|
2019-04-17 20:47:55 +02:00
|
|
|
bool
|
|
|
|
protocol_is_whitelisted(const char *proto);
|
|
|
|
|
2009-03-02 20:13:08 +01:00
|
|
|
#endif
|