MPD 0.17~git
src/playlist_plugin.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2011 The Music Player Daemon Project
00003  * http://www.musicpd.org
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef MPD_PLAYLIST_PLUGIN_H
00021 #define MPD_PLAYLIST_PLUGIN_H
00022 
00023 #include <glib.h>
00024 
00025 #include <stdbool.h>
00026 #include <stddef.h>
00027 
00028 struct config_param;
00029 struct input_stream;
00030 struct tag;
00031 
00035 struct playlist_provider {
00036         const struct playlist_plugin *plugin;
00037 };
00038 
00039 static inline void
00040 playlist_provider_init(struct playlist_provider *playlist,
00041                        const struct playlist_plugin *plugin)
00042 {
00043         playlist->plugin = plugin;
00044 }
00045 
00046 struct playlist_plugin {
00047         const char *name;
00048 
00057         bool (*init)(const struct config_param *param);
00058 
00063         void (*finish)(void);
00064 
00069         struct playlist_provider *(*open_uri)(const char *uri,
00070                                               GMutex *mutex, GCond *cond);
00071 
00077         struct playlist_provider *(*open_stream)(struct input_stream *is);
00078 
00079         void (*close)(struct playlist_provider *playlist);
00080 
00081         struct song *(*read)(struct playlist_provider *playlist);
00082 
00083         const char *const*schemes;
00084         const char *const*suffixes;
00085         const char *const*mime_types;
00086 };
00087 
00096 static inline bool
00097 playlist_plugin_init(const struct playlist_plugin *plugin,
00098                      const struct config_param *param)
00099 {
00100         return plugin->init != NULL
00101                 ? plugin->init(param)
00102                 : true;
00103 }
00104 
00108 static inline void
00109 playlist_plugin_finish(const struct playlist_plugin *plugin)
00110 {
00111         if (plugin->finish != NULL)
00112                 plugin->finish();
00113 }
00114 
00115 static inline struct playlist_provider *
00116 playlist_plugin_open_uri(const struct playlist_plugin *plugin, const char *uri,
00117                          GMutex *mutex, GCond *cond)
00118 {
00119         return plugin->open_uri(uri, mutex, cond);
00120 }
00121 
00122 static inline struct playlist_provider *
00123 playlist_plugin_open_stream(const struct playlist_plugin *plugin,
00124                             struct input_stream *is)
00125 {
00126         return plugin->open_stream(is);
00127 }
00128 
00129 static inline void
00130 playlist_plugin_close(struct playlist_provider *playlist)
00131 {
00132         playlist->plugin->close(playlist);
00133 }
00134 
00135 static inline struct song *
00136 playlist_plugin_read(struct playlist_provider *playlist)
00137 {
00138         return playlist->plugin->read(playlist);
00139 }
00140 
00141 #endif