PlaylistPlugin.hxx 3.55 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 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 "thread/Mutex.hxx"
#include "thread/Cond.hxx"
25

26 27 28 29
#include <stddef.h>

struct config_param;
struct input_stream;
Max Kellermann's avatar
Max Kellermann committed
30
struct Tag;
31
struct Song;
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

/**
 * An object which provides the contents of a playlist.
 */
struct playlist_provider {
	const struct playlist_plugin *plugin;
};

static inline void
playlist_provider_init(struct playlist_provider *playlist,
		       const struct playlist_plugin *plugin)
{
	playlist->plugin = plugin;
}

struct playlist_plugin {
	const char *name;

	/**
	 * Initialize the plugin.  Optional method.
	 *
	 * @param param a configuration block for this plugin, or NULL
	 * if none is configured
	 * @return true if the plugin was initialized successfully,
	 * false if the plugin is not available
	 */
58
	bool (*init)(const config_param &param);
59 60 61 62 63 64 65 66 67 68 69

	/**
	 * Deinitialize a plugin which was initialized successfully.
	 * Optional method.
	 */
	void (*finish)(void);

	/**
	 * Opens the playlist on the specified URI.  This URI has
	 * either matched one of the schemes or one of the suffixes.
	 */
70
	struct playlist_provider *(*open_uri)(const char *uri,
71
					      Mutex &mutex, Cond &cond);
72 73 74 75 76 77 78 79 80 81

	/**
	 * Opens the playlist in the specified input stream.  It has
	 * either matched one of the suffixes or one of the MIME
	 * types.
	 */
	struct playlist_provider *(*open_stream)(struct input_stream *is);

	void (*close)(struct playlist_provider *playlist);

82
	Song *(*read)(struct playlist_provider *playlist);
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

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

/**
 * Initialize a plugin.
 *
 * @param param a configuration block for this plugin, or NULL if none
 * 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,
99
		     const config_param &param)
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
{
	return plugin->init != NULL
		? plugin->init(param)
		: true;
}

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

static inline struct playlist_provider *
117
playlist_plugin_open_uri(const struct playlist_plugin *plugin, const char *uri,
118
			 Mutex &mutex, Cond &cond)
119
{
120
	return plugin->open_uri(uri, mutex, cond);
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
}

static inline struct playlist_provider *
playlist_plugin_open_stream(const struct playlist_plugin *plugin,
			    struct input_stream *is)
{
	return plugin->open_stream(is);
}

static inline void
playlist_plugin_close(struct playlist_provider *playlist)
{
	playlist->plugin->close(playlist);
}

136
static inline Song *
137 138 139 140 141 142
playlist_plugin_read(struct playlist_provider *playlist)
{
	return playlist->plugin->read(playlist);
}

#endif