2007-07-15 17:08:45 +02:00
|
|
|
/*
|
2008-03-10 06:09:44 +01:00
|
|
|
plugin.c - Lumiera Plugin loader
|
2007-07-15 17:08:45 +02:00
|
|
|
|
2008-03-10 04:25:03 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Christian Thaeter <ct@pipapo.org>
|
2007-07-15 17:08:45 +02:00
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
2008-10-15 22:18:17 +02:00
|
|
|
#include "lib/safeclib.h"
|
2008-11-03 08:07:22 +01:00
|
|
|
#include "lib/psplay.h"
|
|
|
|
|
#include "lib/mutex.h"
|
|
|
|
|
#include "lib/error.h"
|
2008-10-15 22:18:17 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
#include "backend/interfaceregistry.h"
|
|
|
|
|
#include "backend/config.h"
|
2008-10-15 22:18:17 +02:00
|
|
|
#include "backend/plugin.h"
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
#include <glob.h>
|
|
|
|
|
|
|
|
|
|
#include <nobug.h>
|
|
|
|
|
|
2007-10-20 17:27:27 +02:00
|
|
|
/**
|
2008-04-10 02:40:34 +02:00
|
|
|
* @file
|
|
|
|
|
* Plugin loader.
|
2007-10-20 17:27:27 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
extern PSplay lumiera_pluginregistry;
|
2007-10-20 17:27:27 +02:00
|
|
|
|
2007-07-17 04:40:07 +02:00
|
|
|
/* TODO should be set by the build system to the actual plugin path */
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2007-07-15 16:56:21 +02:00
|
|
|
/* errors */
|
2008-03-10 06:09:44 +01:00
|
|
|
LUMIERA_ERROR_DEFINE(PLUGIN_DLOPEN, "Could not open plugin");
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2007-07-17 04:40:07 +02:00
|
|
|
/*
|
|
|
|
|
supported (planned) plugin types and their file extensions
|
|
|
|
|
*/
|
|
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
#define LUMIERA_PLUGIN_TYPES \
|
|
|
|
|
LUMIERA_PLUGIN_TYPE(DYNLIB, ".so")
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
only .so dynlibs for now, later we may support some more
|
|
|
|
|
LUMIERA_PLUGIN_TYPE(LUA, ".lua")
|
|
|
|
|
LUMIERA_PLUGIN_TYPE(CSOURCE, ".c")
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define LUMIERA_PLUGIN_TYPE(type, ext) LUMIERA_PLUGIN_##type,
|
2008-03-10 06:09:44 +01:00
|
|
|
enum lumiera_plugin_type
|
2007-07-17 04:40:07 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
LUMIERA_PLUGIN_TYPES
|
|
|
|
|
LUMIERA_PLUGIN_NONE
|
2007-07-17 04:40:07 +02:00
|
|
|
};
|
2008-11-03 08:07:22 +01:00
|
|
|
#undef LUMIERA_PLUGIN_TYPE
|
2007-07-17 04:40:07 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
#define LUMIERA_PLUGIN_TYPE(type, ext) ext,
|
|
|
|
|
static const char* const lumiera_plugin_ext[] =
|
2007-07-17 04:40:07 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
LUMIERA_PLUGIN_TYPES
|
|
|
|
|
NULL
|
2007-07-17 04:40:07 +02:00
|
|
|
};
|
2008-11-03 08:07:22 +01:00
|
|
|
#undef LUMIERA_PLUGIN_TYPE
|
2007-07-17 04:40:07 +02:00
|
|
|
|
|
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
struct lumiera_plugin_struct
|
2007-07-15 02:23:37 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
psplaynode node;
|
2007-07-15 16:56:21 +02:00
|
|
|
|
2008-03-10 06:09:44 +01:00
|
|
|
/* long names as looked up ("/usr/local/lib/lumiera/plugins/effects/audio/normalize.so") */
|
2008-11-03 08:07:22 +01:00
|
|
|
const char* name;
|
2007-07-15 16:56:21 +02:00
|
|
|
|
2007-07-15 02:23:37 +02:00
|
|
|
/* use count for all interfaces of this plugin */
|
2008-11-03 08:07:22 +01:00
|
|
|
unsigned refcnt;
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2007-07-15 16:56:21 +02:00
|
|
|
/* time when the last open or close action happened */
|
2007-07-15 02:23:37 +02:00
|
|
|
time_t last;
|
|
|
|
|
|
2007-07-17 04:40:07 +02:00
|
|
|
/* kind of plugin */
|
2008-03-10 06:09:44 +01:00
|
|
|
enum lumiera_plugin_type type;
|
2007-07-17 04:40:07 +02:00
|
|
|
|
2007-07-15 02:23:37 +02:00
|
|
|
/* dlopen handle */
|
|
|
|
|
void* handle;
|
|
|
|
|
};
|
|
|
|
|
|
2007-07-17 04:40:07 +02:00
|
|
|
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2007-07-17 04:40:07 +02:00
|
|
|
int
|
2008-11-03 08:07:22 +01:00
|
|
|
lumiera_plugin_discover (LumieraPlugin (*callback_load)(const char* plugin),
|
|
|
|
|
int (*callback_register) (LumieraPlugin))
|
2007-07-15 16:56:21 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
TRACE (plugin);
|
|
|
|
|
REQUIRE (callback_load);
|
|
|
|
|
REQUIRE (callback_register);
|
2007-07-15 16:56:21 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
/* construct glob trail {.so,.c,.foo} ... */
|
|
|
|
|
static char* exts_globs = NULL;
|
|
|
|
|
if (!exts_globs)
|
2007-07-17 04:40:07 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
size_t exts_sz = 4; /* / * { } \0 less one comma */
|
|
|
|
|
const char*const* itr = lumiera_plugin_ext;
|
|
|
|
|
while (*itr)
|
2007-07-17 04:40:07 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
exts_sz += strlen (*itr) + 1;
|
|
|
|
|
++itr;
|
|
|
|
|
}
|
2007-07-17 04:40:07 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
exts_globs = lumiera_malloc (exts_sz);
|
|
|
|
|
*exts_globs = '\0';
|
2007-07-17 04:40:07 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
itr = lumiera_plugin_ext;
|
|
|
|
|
strcat (exts_globs, "/*{");
|
2008-03-26 18:09:56 +01:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
while (*itr)
|
|
|
|
|
{
|
|
|
|
|
strcat (exts_globs, *itr);
|
|
|
|
|
strcat (exts_globs, ",");
|
|
|
|
|
++itr;
|
2007-07-17 04:40:07 +02:00
|
|
|
}
|
2008-11-03 08:07:22 +01:00
|
|
|
exts_globs[exts_sz-2] = '}';
|
|
|
|
|
TRACE (plugin, "initialized extension glob to '%s'", exts_globs);
|
2007-07-17 04:40:07 +02:00
|
|
|
}
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
const char* path;
|
|
|
|
|
unsigned i = 0;
|
|
|
|
|
int flags = GLOB_PERIOD|GLOB_BRACE|GLOB_TILDE_CHECK;
|
|
|
|
|
glob_t globs;
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
while ((path = lumiera_config_wordlist_get_nth ("plugin.path", i, ":")))
|
2007-07-15 02:23:37 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
path = lumiera_tmpbuf_snprintf (SIZE_MAX,"%s%s", path, exts_globs);
|
|
|
|
|
TRACE (plugin, "globbing path '%s'", path);
|
|
|
|
|
int ret = glob (path, flags, NULL, &globs);
|
|
|
|
|
if (ret == GLOB_NOSPACE)
|
|
|
|
|
LUMIERA_DIE (NO_MEMORY);
|
|
|
|
|
|
|
|
|
|
flags |= GLOB_APPEND;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
LUMIERA_RECMUTEX_SECTION (plugin, &lumiera_interface_mutex)
|
|
|
|
|
{
|
|
|
|
|
for (char** itr = globs.gl_pathv; *itr; ++itr)
|
2007-07-15 20:06:20 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
|
|
|
|
|
if (!psplay_find (lumiera_pluginregistry, *itr, 100))
|
2007-07-17 04:40:07 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
TRACE (plugin, "found new plugin '%s'", *itr);
|
|
|
|
|
|
|
|
|
|
LumieraPlugin plugin = callback_load (*itr);
|
|
|
|
|
if (plugin)
|
|
|
|
|
callback_register (plugin);
|
2007-07-17 04:40:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
2008-11-03 08:07:22 +01:00
|
|
|
}
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
globfree (&globs);
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
return !lumiera_error_peek ();
|
|
|
|
|
}
|
2007-07-17 04:40:07 +02:00
|
|
|
|
2007-08-18 05:05:38 +02:00
|
|
|
|
2007-07-15 02:23:37 +02:00
|
|
|
|
|
|
|
|
|
2007-08-18 05:05:38 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
LumieraPlugin
|
|
|
|
|
lumiera_plugin_load (const char* plugin)
|
|
|
|
|
{
|
|
|
|
|
TRACE (plugin);
|
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
|
(void) plugin;
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2007-07-15 02:23:37 +02:00
|
|
|
|
|
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
int
|
|
|
|
|
lumiera_plugin_register (LumieraPlugin plugin)
|
|
|
|
|
{
|
|
|
|
|
TRACE (plugin);
|
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
|
|
|
|
|
|
LUMIERA_RECMUTEX_SECTION (plugin, &lumiera_interface_mutex)
|
2007-07-15 02:23:37 +02:00
|
|
|
{
|
2008-11-03 08:07:22 +01:00
|
|
|
(void) plugin;
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
}
|
|
|
|
|
return 0;
|
2007-07-15 02:23:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-07-19 06:15:55 +02:00
|
|
|
|
2007-07-15 16:56:21 +02:00
|
|
|
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
int
|
|
|
|
|
lumiera_plugin_cmp_fn (const void* keya, const void* keyb)
|
|
|
|
|
{
|
|
|
|
|
return strcmp ((const char*)keya, (const char*)keyb);
|
|
|
|
|
}
|
2007-07-15 02:23:37 +02:00
|
|
|
|
2008-11-03 08:07:22 +01:00
|
|
|
|
|
|
|
|
const void*
|
|
|
|
|
lumiera_plugin_key_fn (const PSplaynode node)
|
|
|
|
|
{
|
|
|
|
|
return ((LumieraPlugin)node)->name;
|
2007-07-15 02:23:37 +02:00
|
|
|
}
|
2008-11-03 08:07:22 +01:00
|
|
|
|