42 PSplay lumiera_interfaceregistry;
43 PSplay lumiera_pluginregistry;
44 lumiera_recmutex lumiera_interface_mutex;
47 lumiera_interface_cmp_fn (
const void* keya,
const void* keyb);
50 lumiera_interface_key_fn (
const PSplaynode node);
54 static LumieraInterfacenode
55 lumiera_interfacenode_new (LumieraInterface iface, LumieraPlugin plugin)
60 self->interface = iface;
62 self->plugin = plugin;
72 lumiera_interfacenode_delete (LumieraInterfacenode
self)
76 REQUIRE (self->refcnt == 0);
88 TRACE (interfaceregistry_dbg);
89 REQUIRE (!lumiera_interfaceregistry);
90 REQUIRE (!lumiera_pluginregistry);
92 lumiera_interfaceregistry =
psplay_new (lumiera_interface_cmp_fn, lumiera_interface_key_fn, NULL);
93 if (!lumiera_interfaceregistry)
96 lumiera_pluginregistry =
psplay_new (lumiera_plugin_cmp_fn, lumiera_plugin_key_fn, lumiera_plugin_delete_fn);
97 if (!lumiera_pluginregistry)
100 lumiera_recmutex_init (&lumiera_interface_mutex,
"interfaceregistry", &NOBUG_FLAG(interfaceregistry), NOBUG_CONTEXT);
107 lumiera_interfaceregistry_destroy (
void)
109 TRACE (interfaceregistry_dbg);
113 if (lumiera_pluginregistry)
115 lumiera_pluginregistry = NULL;
119 REQUIRE (!
psplay_nelements (lumiera_interfaceregistry),
"some interfaces still registered at shutdown");
121 if (lumiera_interfaceregistry)
123 lumiera_interfaceregistry = NULL;
128 lumiera_interfaceregistry_register_interface (LumieraInterface
self, LumieraPlugin plugin)
130 TRACE (interfaceregistry_dbg);
135 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", self->interface, self->version, self->name);
136 psplay_insert (lumiera_interfaceregistry, &lumiera_interfacenode_new (
self, plugin)->node, 100);
142 lumiera_interfaceregistry_bulkregister_interfaces (LumieraInterface*
self, LumieraPlugin plugin)
144 TRACE (interfaceregistry_dbg);
151 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
152 psplay_insert (lumiera_interfaceregistry, &lumiera_interfacenode_new (*
self, plugin)->node, 100);
160 lumiera_interfaceregistry_remove_interface (LumieraInterface
self)
162 TRACE (interfaceregistry_dbg);
167 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", self->interface, self->version, self->name);
168 LumieraInterfacenode node = (LumieraInterfacenode)
psplay_find (lumiera_interfaceregistry,
self, 0);
169 REQUIRE (node->refcnt == 0,
"but is %d", node->refcnt);
171 lumiera_interfacenode_delete ((LumieraInterfacenode)
psplay_remove (lumiera_interfaceregistry, &node->node));
177 lumiera_interfaceregistry_bulkremove_interfaces (LumieraInterface*
self)
179 TRACE (interfaceregistry_dbg);
186 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
188 LumieraInterfacenode node = (LumieraInterfacenode)
psplay_find (lumiera_interfaceregistry, *
self, 0);
191 REQUIRE (node->refcnt == 0,
"but is %d", node->refcnt);
192 lumiera_interfacenode_delete ((LumieraInterfacenode)
psplay_remove (lumiera_interfaceregistry, &node->node));
199 WARN (interfaceregistry,
"ENTRY NOT FOUND in interfaceregistry at clean-up of interface %s, instance %s" 211 lumiera_interfaceregistry_interfacenode_find (
const char* interface,
unsigned version,
const char*
name)
213 TRACE (interfaceregistry_dbg);
219 LumieraInterfacenode ret = NULL;
223 ret = (LumieraInterfacenode)
psplay_find (lumiera_interfaceregistry, &cmp, 100);
231 lumiera_interfaceregistry_interface_find (
const char* interface,
unsigned version,
const char* name)
233 return lumiera_interfaceregistry_interfacenode_find (interface, version, name)->interface;
238 lumiera_interface_cmp_fn (
const void* keya,
const void* keyb)
240 const LumieraInterface a = (
const LumieraInterface)keya;
241 const LumieraInterface b = (
const LumieraInterface)keyb;
243 int r = strcmp (a->interface, b->interface);
249 if (a->version < b->version)
251 else if (a->version > b->version)
254 r = strcmp (a->name, b->name);
265 lumiera_interface_key_fn (
const PSplaynode node)
267 return ((LumieraInterfacenode)node)->interface;
Portable and safe wrappers around some C-Lib functions.
#define LUMIERA_RECMUTEX_SECTION(nobugflag, mtx)
Recursive Mutual exclusive section.
PSplay psplay_destroy(PSplay self)
Destroy a splay tree Frees all elements and associated resources of a splay tree. ...
void lumiera_interface_destroy(void)
deregistering implementations of the above interface
LumieraRecmutex lumiera_recmutex_destroy(LumieraRecmutex self, struct nobug_flag *flag, const struct nobug_context ctx)
Destroy a recursive mutex variable.
Header for an interface, just the absolute necessary metadata.
void lumiera_interface_init(void)
registering implementations of the above interface
Lumiera plugins define 'interfaces' as shown in interface.h, the plugin system handles the loading of...
const char * name
name of this instance
This header is for including and configuring NoBug.
unsigned version
major version, 0 means experimental
static void lumiera_free(void *mem)
Free previously allocated memory.
Lumiera error handling (C interface).
PSplaynode psplay_find(PSplay self, const void *key, int splayfactor)
Find a element in a splay tree.
LumieraRecmutex lumiera_recmutex_init(LumieraRecmutex self, const char *purpose, struct nobug_flag *flag, const struct nobug_context ctx)
Initialise a recursive mutex variable Initialises a 'recursive' mutex which might be locked by the sa...
PSplaynode psplay_insert(PSplay self, PSplaynode node, int splayfactor)
Insert a element into a splay tree.
void psplay_delete(PSplay self)
Delete a splay tree Frees all elements and associated resources of a splay tree and then itseld...
static size_t psplay_nelements(PSplay self)
Number of elements in tree.
#define LUMIERA_DIE(err)
Abort unconditionally with a 'Fatal Error!' message.
PSplay psplay_new(psplay_cmp_fn cmp, psplay_key_fn key, psplay_delete_fn del)
Allocate a splay tree.
Probabilistic splay tree.
void * lumiera_malloc(size_t size)
Allocate memory.
const char * interface
name of the interface (type)
void lumiera_interfaceregistry_init(void)
Initialise the interface registry.
Global registry for interfaces (extension points).
PSplaynode psplay_remove(PSplay self, PSplaynode node)
Remove a node from 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...