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
29 #include "configuration.h"
36 /* generic plugin support *****************************************************/
39 # define SOSUFFIX ".so"
48 static struct plugin
*plugins
;
50 const struct plugin
*open_plugin(const char *name
,
57 for(pl
= plugins
; pl
&& strcmp(pl
->name
, name
); pl
= pl
->next
)
60 for(n
= 0; n
<= config
->plugins
.n
; ++n
) {
61 byte_xasprintf(&p
, "%s/%s" SOSUFFIX
,
62 n
== config
->plugins
.n ? pkglibdir
: config
->plugins
.s
[n
],
64 if(access(p
, R_OK
) == 0) {
65 h
= dlopen(p
, RTLD_NOW
);
67 error(0, "error opening %s: %s", p
, dlerror());
70 pl
= xmalloc(sizeof *pl
);
72 pl
->name
= xstrdup(name
);
78 (flags
& PLUGIN_FATAL ? fatal
: error
)(0, "cannot find plugin '%s'", name
);
82 function_t
*get_plugin_function(const struct plugin
*pl
,
87 f
= (function_t
*)dlsym(pl
->dlhandle
, symbol
);
89 fatal(0, "error looking up function '%s' in '%s': %s",symbol
, pl
->name
, e
);
93 const void *get_plugin_object(const struct plugin
*pl
,
98 o
= dlsym(pl
->dlhandle
, symbol
);
100 fatal(0, "error looking up object '%s' in '%s': %s", symbol
, pl
->name
, e
);
104 /* specific plugin interfaces *************************************************/
106 typedef long tracklength_fn(const char *track
, const char *path
);
108 long tracklength(const char *track
, const char *path
) {
109 static tracklength_fn
*f
= 0;
112 f
= (tracklength_fn
*)get_plugin_function(open_plugin("tracklength",
114 "disorder_tracklength");
115 return (*f
)(track
, path
);
118 typedef void scan_fn(const char *root
);
120 void scan(const char *module
, const char *root
) {
121 ((scan_fn
*)get_plugin_function(open_plugin(module
, PLUGIN_FATAL
),
122 "disorder_scan"))(root
);
125 typedef int check_fn(const char *root
, const char *path
);
128 int check(const char *module
, const char *root
, const char *path
) {
129 return ((check_fn
*)get_plugin_function(open_plugin(module
, PLUGIN_FATAL
),
130 "disorder_check"))(root
, path
);
133 typedef void notify_play_fn(const char *track
, const char *submitter
);
135 void notify_play(const char *track
,
136 const char *submitter
) {
137 static notify_play_fn
*f
;
140 f
= (notify_play_fn
*)get_plugin_function(open_plugin("notify",
142 "disorder_notify_play");
143 (*f
)(track
, submitter
);
146 typedef void notify_scratch_fn(const char *track
,
147 const char *submitter
,
148 const char *scratcher
,
151 void notify_scratch(const char *track
,
152 const char *submitter
,
153 const char *scratcher
,
155 static notify_scratch_fn
*f
;
158 f
= (notify_scratch_fn
*)get_plugin_function(open_plugin("notify",
160 "disorder_notify_scratch");
161 (*f
)(track
, submitter
, scratcher
, seconds
);
164 typedef void notify_not_scratched_fn(const char *track
,
165 const char *submitter
);
167 void notify_not_scratched(const char *track
,
168 const char *submitter
) {
169 static notify_not_scratched_fn
*f
;
172 f
= (notify_not_scratched_fn
*)get_plugin_function
173 (open_plugin("notify",
175 "disorder_notify_not_scratched");
176 (*f
)(track
, submitter
);
179 typedef void notify_queue_fn(const char *track
,
180 const char *submitter
);
182 void notify_queue(const char *track
,
183 const char *submitter
) {
184 static notify_queue_fn
*f
;
187 f
= (notify_queue_fn
*)get_plugin_function(open_plugin("notify",
189 "disorder_notify_queue");
190 (*f
)(track
, submitter
);
193 void notify_queue_remove(const char *track
,
194 const char *remover
) {
195 static notify_queue_fn
*f
;
198 f
= (notify_queue_fn
*)get_plugin_function(open_plugin("notify",
200 "disorder_notify_queue_remove");
201 (*f
)(track
, remover
);
204 void notify_queue_move(const char *track
,
206 static notify_queue_fn
*f
;
209 f
= (notify_queue_fn
*)get_plugin_function(open_plugin("notify",
211 "disorder_notify_queue_move");
215 void notify_pause(const char *track
, const char *who
) {
216 static notify_queue_fn
*f
;
219 f
= (notify_queue_fn
*)get_plugin_function(open_plugin("notify",
221 "disorder_notify_pause");
225 void notify_resume(const char *track
, const char *who
) {
226 static notify_queue_fn
*f
;
229 f
= (notify_queue_fn
*)get_plugin_function(open_plugin("notify",
231 "disorder_notify_resume");
235 /* player plugin interfaces ***************************************************/
239 unsigned long play_get_type(const struct plugin
*pl
) {
240 return *(const unsigned long *)get_plugin_object(pl
, "disorder_player_type");
245 typedef void *prefork_fn(const char *track
);
247 void *play_prefork(const struct plugin
*pl
,
249 return ((prefork_fn
*)get_plugin_function(pl
,
250 "disorder_play_prefork"))(track
);
255 typedef void play_track_fn(const char *const *parameters
,
260 void play_track(const struct plugin
*pl
,
261 const char *const *parameters
,
265 ((play_track_fn
*)get_plugin_function(pl
,
266 "disorder_play_track"))(parameters
,
274 typedef void cleanup_fn(void *data
);
276 void play_cleanup(const struct plugin
*pl
, void *data
) {
277 ((cleanup_fn
*)get_plugin_function(pl
, "disorder_play_cleanup"))(data
);
282 typedef int pause_fn(long *playedp
, void *data
);
284 int play_pause(const struct plugin
*pl
, long *playedp
, void *data
) {
285 return (((pause_fn
*)get_plugin_function(pl
, "disorder_pause_track"))
291 typedef void resume_fn(void *data
);
293 void play_resume(const struct plugin
*pl
, void *data
) {
294 (((resume_fn
*)get_plugin_function(pl
, "disorder_resume_track"))