chiark / gitweb /
TABLE_FIND() now uses typeof. We're committed to GCC anyway so it
[disorder] / lib / plugin.c
index bf4179718ae30485b2aed965102b481df46c7e93..c23865d9f9f3cac377df19e0c0980421d8af7415 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2006 Richard Kettlewell
+ * Copyright (C) 2004-2008 Richard Kettlewell
  *
  * 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
@@ -19,6 +19,7 @@
  */
 
 #include <config.h>
+#include "types.h"
 
 #include <dlfcn.h>
 #include <unistd.h>
@@ -57,6 +58,7 @@ const struct plugin *open_plugin(const char *name,
   for(pl = plugins; pl && strcmp(pl->name, name); pl = pl->next)
     ;
   if(pl) return pl;
+  /* Search the plugin path */
   for(n = 0; n <= config->plugins.n; ++n) {
     byte_xasprintf(&p, "%s/%s" SOSUFFIX,
                   n == config->plugins.n ? pkglibdir : config->plugins.s[n],
@@ -82,22 +84,22 @@ const struct plugin *open_plugin(const char *name,
 function_t *get_plugin_function(const struct plugin *pl,
                                const char *symbol) {
   function_t *f;
-  const char *e;
 
   f = (function_t *)dlsym(pl->dlhandle, symbol);
-  if((e = dlerror()))
-    fatal(0, "error looking up function '%s' in '%s': %s",symbol, pl->name, e);
+  if(!f)
+    fatal(0, "error looking up function '%s' in '%s': %s",
+         symbol, pl->name, dlerror());
   return f;
 }
 
 const void *get_plugin_object(const struct plugin *pl,
                              const char *symbol) {
   void *o;
-  const char *e;
 
   o = dlsym(pl->dlhandle, symbol);
-  if((e = dlerror()))
-    fatal(0, "error looking up object '%s' in '%s': %s", symbol, pl->name, e);
+  if(!o)
+    fatal(0, "error looking up object '%s' in '%s': %s",
+         symbol, pl->name, dlerror());
   return o;
 }
 
@@ -105,13 +107,18 @@ const void *get_plugin_object(const struct plugin *pl,
 
 typedef long tracklength_fn(const char *track, const char *path);
 
-long tracklength(const char *track, const char *path) {
-  static tracklength_fn *f = 0;
+/** Compute the length of a track
+ * @param plugin plugin to use, as configured
+ * @param track UTF-8 name of track
+ * @param path file system path or 0
+ * @return length of track in seconds, 0 for unknown, -1 for error
+ */
+long tracklength(const char *plugin, const char *track, const char *path) {
+  tracklength_fn *f = 0;
 
-  if(!f)
-    f = (tracklength_fn *)get_plugin_function(open_plugin("tracklength",
-                                                         PLUGIN_FATAL),
-                                             "disorder_tracklength");
+  f = (tracklength_fn *)get_plugin_function(open_plugin(plugin,
+                                                       PLUGIN_FATAL),
+                                           "disorder_tracklength");
   return (*f)(track, path);
 }
 
@@ -301,4 +308,3 @@ c-basic-offset:2
 comment-column:40
 End:
 */
-/* arch-tag:069494ccad9bf04cf6ca9505d9528f0a */