PlaylistPlugin.hxx 2.96 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 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.
 */

20 21
#ifndef MPD_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_PLUGIN_HXX
22

23 24
#include "input/Ptr.hxx"

25
struct ConfigBlock;
Max Kellermann's avatar
Max Kellermann committed
26
struct Tag;
27 28
class Mutex;
class Cond;
29
class SongEnumerator;
30 31 32 33 34 35 36

struct playlist_plugin {
	const char *name;

	/**
	 * Initialize the plugin.  Optional method.
	 *
Max Kellermann's avatar
Max Kellermann committed
37
	 * @param block a configuration block for this plugin, or nullptr
38 39 40 41
	 * if none is configured
	 * @return true if the plugin was initialized successfully,
	 * false if the plugin is not available
	 */
42
	bool (*init)(const ConfigBlock &block);
43 44 45 46 47

	/**
	 * Deinitialize a plugin which was initialized successfully.
	 * Optional method.
	 */
48
	void (*finish)();
49 50 51 52 53

	/**
	 * Opens the playlist on the specified URI.  This URI has
	 * either matched one of the schemes or one of the suffixes.
	 */
54 55
	SongEnumerator *(*open_uri)(const char *uri,
				    Mutex &mutex, Cond &cond);
56 57 58 59 60

	/**
	 * Opens the playlist in the specified input stream.  It has
	 * either matched one of the suffixes or one of the MIME
	 * types.
61 62 63
	 *
	 * @parm is the input stream; the pointer will not be
	 * invalidated when the function returns nullptr
64
	 */
65
	SongEnumerator *(*open_stream)(InputStreamPtr &&is);
66 67 68 69 70 71 72 73 74

	const char *const*schemes;
	const char *const*suffixes;
	const char *const*mime_types;
};

/**
 * Initialize a plugin.
 *
Max Kellermann's avatar
Max Kellermann committed
75
 * @param block a configuration block for this plugin, or nullptr if none
76 77 78 79 80 81
 * is configured
 * @return true if the plugin was initialized successfully, false if
 * the plugin is not available
 */
static inline bool
playlist_plugin_init(const struct playlist_plugin *plugin,
82
		     const ConfigBlock &block)
83
{
84
	return plugin->init != nullptr
85
		? plugin->init(block)
86 87 88 89 90 91 92 93 94
		: true;
}

/**
 * Deinitialize a plugin which was initialized successfully.
 */
static inline void
playlist_plugin_finish(const struct playlist_plugin *plugin)
{
95
	if (plugin->finish != nullptr)
96 97 98
		plugin->finish();
}

99
static inline SongEnumerator *
100
playlist_plugin_open_uri(const struct playlist_plugin *plugin, const char *uri,
101
			 Mutex &mutex, Cond &cond)
102
{
103
	return plugin->open_uri(uri, mutex, cond);
104 105
}

106
static inline SongEnumerator *
107
playlist_plugin_open_stream(const struct playlist_plugin *plugin,
108
			    InputStreamPtr &&is)
109
{
110
	return plugin->open_stream(std::move(is));
111 112 113
}

#endif