51#define LUMIERA_PLUGIN_TYPE_PLANNED(name, ext)
59#define LUMIERA_PLUGIN_TYPES \
60 LUMIERA_PLUGIN_TYPE(DYNLIB, ".so") \
61 LUMIERA_PLUGIN_TYPE(DYNLIB, ".lum") \
62 LUMIERA_PLUGIN_TYPE_PLANNED(LUA, ".lua") \
63 LUMIERA_PLUGIN_TYPE_PLANNED(CSOURCE, ".c")
79#define LUMIERA_PLUGIN_TYPE(type, ext) \
80 LumieraPlugin lumiera_plugin_load_##type (const char*); \
81 void lumiera_plugin_unload_##type (LumieraPlugin);
83#undef LUMIERA_PLUGIN_TYPE
86#define LUMIERA_PLUGIN_TYPE(type, ext) {lumiera_plugin_load_##type, lumiera_plugin_unload_##type, ext},
92#undef LUMIERA_PLUGIN_TYPE
131 self->error = LUMIERA_ERROR_PLUGIN_INIT;
142 self->plugin = plugin;
143 self->handle = handle;
167 return self?self->name:
NULL;
190 TRACE (pluginloader_dbg);
191 REQUIRE (callback_load);
192 REQUIRE (callback_register);
200 static char* exts_globs =
NULL;
206 int flags = GLOB_PERIOD|GLOB_BRACE|GLOB_TILDE_CHECK;
212 TRACE (pluginloader_dbg,
"globbing path '%s'", path);
213 int ret = glob (path, flags,
NULL, &globs);
214 if (ret == GLOB_NOSPACE)
217 flags |= GLOB_APPEND;
224 for (
char** itr = globs.gl_pathv; *itr; ++itr)
228 TRACE (pluginloader,
"found new plugin '%s'", *itr);
229 callback_register (callback_load (*itr));
243 TRACE (pluginloader_dbg,
"plugin=%s", plugin);
246 const char* ext = strrchr (plugin,
'.');
251 if (!strcmp (itr->ext, ext))
252 return itr->lumiera_plugin_load_fn (plugin);
262 TRACE (pluginloader_dbg);
276 TRACE (pluginloader,
"registering %s", plugin->name);
299 TRACE (pluginloader_dbg);
308 const char* ext = strrchr (self->name,
'.');
313 if (!strcmp (itr->ext, ext))
327 itr->lumiera_plugin_unload_fn (self);
357 exts_sz += strlen (itr->ext) + 1;
365 strcat (exts_globs,
"*{");
369 strcat (exts_globs, itr->ext);
370 strcat (exts_globs,
",");
373 exts_globs[exts_sz-2] =
'}';
374 TRACE (pluginloader_dbg,
"initialised extension glob to '%s'", exts_globs);
381 return strcmp ((
const char*)keya, (
const char*)keyb);
397 ENSURE (!self->refcnt,
"plugin %s still in use at shutdown", self->name);
399 const char* ext = strrchr (self->name,
'.');
404 if (!strcmp (itr->ext, ext))
412 TRACE (pluginloader_dbg,
"unloading plugin/module %s", self->name);
413 itr->lumiera_plugin_unload_fn (self);
The lumiera::Config wrapper class addresses two issues.
const char * lumiera_config_wordlist_get_nth(const char *key, unsigned nth, const char *delims)
return nth word of a wordlist
LumieraConfigitem lumiera_config_setdefault(const char *line)
Installs a default value for a config key.
Interface for a lumiera configuration system (draft).
const char * lumiera_get_plugin_path_default()
lumiera_err lumiera_error_peek(void)
Check current error state without clearing it Please avoid this function and use lumiera_error() if p...
lumiera_err lumiera_error(void)
Get and clear current error state.
Lumiera error handling (C interface).
#define LUMIERA_ERROR_SET_CRITICAL(flag, err, extra)
Helper macro to raise an error for the current thread.
#define LUMIERA_ERROR_SET(flag, err, extra)
Helper macro to raise an error for the current thread.
#define LUMIERA_DIE(err)
Abort unconditionally with a 'Fatal Error!' message.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
unsigned lumiera_interface_version(LumieraInterface self, const char *iname)
Runtime check for interface type and version.
#define LUMIERA_INTERFACE_CAST(name, version)
Construct a cast to the target interface type Used to cast a generic LumieraInterface to the real typ...
lumiera_interface * LumieraInterface
#define LUMIERA_INTERFACE_HANDLE(interface, version)
create a handle for a interface (WIP)
lumiera_recmutex lumiera_interface_mutex
void lumiera_interfaceregistry_bulkremove_interfaces(LumieraInterface *self)
void lumiera_interfaceregistry_bulkregister_interfaces(LumieraInterface *self, LumieraPlugin plugin)
Global registry for interfaces (extension points).
This header is for including and configuring NoBug.
void lumiera_plugin_refdec(LumieraPlugin self)
void lumiera_plugin_refinc(LumieraPlugin self)
static char * init_exts_globs(void)
lumiera_err error
bulk loading plugins must not fail entirely, just because one plugin doesn't comply.
void lumiera_plugin_delete_fn(PSplaynode node)
LumieraPlugin lumiera_plugin_lookup(const char *name)
Lookup a plugin handle in the pluginregistry.
#define LUMIERA_PLUGIN_TYPES
Supported (and planned) plugin types and their file extensions This maps filename extensions to imple...
LumieraPlugin lumiera_plugin_load(const char *plugin)
Tries to load a plugin Creates a new plugin structure and tries to load and initialise the plugin.
int lumiera_plugin_register(LumieraPlugin plugin)
Register a plugin and its interfaces.
void * lumiera_plugin_handle(LumieraPlugin self)
Query the plugin handle.
const char * lumiera_plugin_name(LumieraPlugin self)
Query the plugin name The name is the path and filename under which it was loaded.
lumiera_plugintype * LumieraPlugintype
lumiera_err lumiera_plugin_error(LumieraPlugin self)
Query the error state of a plugin.
LumieraPlugin lumiera_plugin_init(LumieraPlugin self, void *handle, LumieraInterface plugin)
unsigned lumiera_plugin_unload(LumieraPlugin self)
Tries to unload a plugin.
int lumiera_plugin_discover(LumieraPlugin(*callback_load)(const char *plugin), int(*callback_register)(LumieraPlugin))
discover new plugins traverses the configured plugin paths and calls the callback_load function for a...
PSplay lumiera_pluginregistry
const void * lumiera_plugin_key_fn(const PSplaynode node)
static lumiera_plugintype lumiera_plugin_types[]
LumieraPlugin lumiera_plugin_new(const char *name)
Allocates an preinitialises a plugin structure.
int lumiera_plugin_cmp_fn(const void *keya, const void *keyb)
Lumiera plugins define 'interfaces' as shown in interface.h, the plugin system handles the loading of...
lumiera_plugin * LumieraPlugin
PSplaynode psplay_insert(PSplay self, PSplaynode node, int splayfactor)
Insert a element into a splay tree.
PSplaynode psplaynode_init(PSplaynode self)
Initialise a splay tree node The user has to place this nodes within his datastructure and must Initi...
PSplaynode psplay_remove(PSplay self, PSplaynode node)
Remove a node from a splay tree.
PSplaynode psplay_find(PSplay self, const void *key, int splayfactor)
Find a element in a splay tree.
Probabilistic splay tree.
Mutual exclusion locking, header.
#define LUMIERA_RECMUTEX_SECTION(nobugflag, mtx)
Recursive Mutual exclusive section.
char * lumiera_strndup(const char *str, size_t len)
Duplicate a C string.
void * lumiera_malloc(size_t size)
Allocate memory.
Portable and safe wrappers around some C-Lib functions.
record the extension and a callback function for loading the associated plugin for each plugin type
void(* lumiera_plugin_unload_fn)(LumieraPlugin)
LumieraPlugin(* lumiera_plugin_load_fn)(const char *)
char * lumiera_tmpbuf_snprintf(size_t size, const char *fmt,...)
Construct a string in a tmpbuf.
Round robin temporary buffers.