2 * This file is part of DisOrder.
3 * Copyright (C) 2004, 2005, 2006 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include "configuration.h"
37 /* generic plugin support *****************************************************/
40 # define SOSUFFIX ".so"
49 static struct plugin *plugins;
51 const struct plugin *open_plugin(const char *name,
58 for(pl = plugins; pl && strcmp(pl->name, name); pl = pl->next)
61 /* Search the plugin path */
62 for(n = 0; n <= config->plugins.n; ++n) {
63 byte_xasprintf(&p, "%s/%s" SOSUFFIX,
64 n == config->plugins.n ? pkglibdir : config->plugins.s[n],
66 if(access(p, R_OK) == 0) {
67 h = dlopen(p, RTLD_NOW);
69 error(0, "error opening %s: %s", p, dlerror());
72 pl = xmalloc(sizeof *pl);
74 pl->name = xstrdup(name);
80 (flags & PLUGIN_FATAL ? fatal : error)(0, "cannot find plugin '%s'", name);
84 function_t *get_plugin_function(const struct plugin *pl,
89 f = (function_t *)dlsym(pl->dlhandle, symbol);
91 fatal(0, "error looking up function '%s' in '%s': %s",symbol, pl->name, e);
95 const void *get_plugin_object(const struct plugin *pl,
100 o = dlsym(pl->dlhandle, symbol);
102 fatal(0, "error looking up object '%s' in '%s': %s", symbol, pl->name, e);
106 /* specific plugin interfaces *************************************************/
108 typedef long tracklength_fn(const char *track, const char *path);
110 /** Compute the length of a track
111 * @param plugin plugin to use, as configured
112 * @param track UTF-8 name of track
113 * @param path file system path or 0
114 * @return length of track in seconds, 0 for unknown, -1 for error
116 long tracklength(const char *plugin, const char *track, const char *path) {
117 tracklength_fn *f = 0;
119 f = (tracklength_fn *)get_plugin_function(open_plugin(plugin,
121 "disorder_tracklength");
122 return (*f)(track, path);
125 typedef void scan_fn(const char *root);
127 void scan(const char *module, const char *root) {
128 ((scan_fn *)get_plugin_function(open_plugin(module, PLUGIN_FATAL),
129 "disorder_scan"))(root);
132 typedef int check_fn(const char *root, const char *path);
135 int check(const char *module, const char *root, const char *path) {
136 return ((check_fn *)get_plugin_function(open_plugin(module, PLUGIN_FATAL),
137 "disorder_check"))(root, path);
140 typedef void notify_play_fn(const char *track, const char *submitter);
142 void notify_play(const char *track,
143 const char *submitter) {
144 static notify_play_fn *f;
147 f = (notify_play_fn *)get_plugin_function(open_plugin("notify",
149 "disorder_notify_play");
150 (*f)(track, submitter);
153 typedef void notify_scratch_fn(const char *track,
154 const char *submitter,
155 const char *scratcher,
158 void notify_scratch(const char *track,
159 const char *submitter,
160 const char *scratcher,
162 static notify_scratch_fn *f;
165 f = (notify_scratch_fn *)get_plugin_function(open_plugin("notify",
167 "disorder_notify_scratch");
168 (*f)(track, submitter, scratcher, seconds);
171 typedef void notify_not_scratched_fn(const char *track,
172 const char *submitter);
174 void notify_not_scratched(const char *track,
175 const char *submitter) {
176 static notify_not_scratched_fn *f;
179 f = (notify_not_scratched_fn *)get_plugin_function
180 (open_plugin("notify",
182 "disorder_notify_not_scratched");
183 (*f)(track, submitter);
186 typedef void notify_queue_fn(const char *track,
187 const char *submitter);
189 void notify_queue(const char *track,
190 const char *submitter) {
191 static notify_queue_fn *f;
194 f = (notify_queue_fn *)get_plugin_function(open_plugin("notify",
196 "disorder_notify_queue");
197 (*f)(track, submitter);
200 void notify_queue_remove(const char *track,
201 const char *remover) {
202 static notify_queue_fn *f;
205 f = (notify_queue_fn *)get_plugin_function(open_plugin("notify",
207 "disorder_notify_queue_remove");
208 (*f)(track, remover);
211 void notify_queue_move(const char *track,
213 static notify_queue_fn *f;
216 f = (notify_queue_fn *)get_plugin_function(open_plugin("notify",
218 "disorder_notify_queue_move");
222 void notify_pause(const char *track, const char *who) {
223 static notify_queue_fn *f;
226 f = (notify_queue_fn *)get_plugin_function(open_plugin("notify",
228 "disorder_notify_pause");
232 void notify_resume(const char *track, const char *who) {
233 static notify_queue_fn *f;
236 f = (notify_queue_fn *)get_plugin_function(open_plugin("notify",
238 "disorder_notify_resume");
242 /* player plugin interfaces ***************************************************/
246 unsigned long play_get_type(const struct plugin *pl) {
247 return *(const unsigned long *)get_plugin_object(pl, "disorder_player_type");
252 typedef void *prefork_fn(const char *track);
254 void *play_prefork(const struct plugin *pl,
256 return ((prefork_fn *)get_plugin_function(pl,
257 "disorder_play_prefork"))(track);
262 typedef void play_track_fn(const char *const *parameters,
267 void play_track(const struct plugin *pl,
268 const char *const *parameters,
272 ((play_track_fn *)get_plugin_function(pl,
273 "disorder_play_track"))(parameters,
281 typedef void cleanup_fn(void *data);
283 void play_cleanup(const struct plugin *pl, void *data) {
284 ((cleanup_fn *)get_plugin_function(pl, "disorder_play_cleanup"))(data);
289 typedef int pause_fn(long *playedp, void *data);
291 int play_pause(const struct plugin *pl, long *playedp, void *data) {
292 return (((pause_fn *)get_plugin_function(pl, "disorder_pause_track"))
298 typedef void resume_fn(void *data);
300 void play_resume(const struct plugin *pl, void *data) {
301 (((resume_fn *)get_plugin_function(pl, "disorder_resume_track"))