33 PSplay lumiera_interfaceregistry;
34 PSplay lumiera_pluginregistry;
35 lumiera_recmutex lumiera_interface_mutex;
38 lumiera_interface_cmp_fn (
const void* keya,
const void* keyb);
41 lumiera_interface_key_fn (
const PSplaynode node);
45 static LumieraInterfacenode
46 lumiera_interfacenode_new (LumieraInterface iface, LumieraPlugin plugin)
51 self->interface = iface;
53 self->plugin = plugin;
63 lumiera_interfacenode_delete (LumieraInterfacenode
self)
67 REQUIRE (self->refcnt == 0);
79 TRACE (interfaceregistry_dbg);
80 REQUIRE (!lumiera_interfaceregistry);
81 REQUIRE (!lumiera_pluginregistry);
83 lumiera_interfaceregistry =
psplay_new (lumiera_interface_cmp_fn, lumiera_interface_key_fn, NULL);
84 if (!lumiera_interfaceregistry)
87 lumiera_pluginregistry =
psplay_new (lumiera_plugin_cmp_fn, lumiera_plugin_key_fn, lumiera_plugin_delete_fn);
88 if (!lumiera_pluginregistry)
91 lumiera_recmutex_init (&lumiera_interface_mutex,
"interfaceregistry", &NOBUG_FLAG(interfaceregistry), NOBUG_CONTEXT);
98 lumiera_interfaceregistry_destroy (
void)
100 TRACE (interfaceregistry_dbg);
104 if (lumiera_pluginregistry)
106 lumiera_pluginregistry = NULL;
110 REQUIRE (!
psplay_nelements (lumiera_interfaceregistry),
"some interfaces still registered at shutdown");
112 if (lumiera_interfaceregistry)
114 lumiera_interfaceregistry = NULL;
119 lumiera_interfaceregistry_register_interface (LumieraInterface
self, LumieraPlugin plugin)
121 TRACE (interfaceregistry_dbg);
126 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", self->interface, self->version, self->name);
127 psplay_insert (lumiera_interfaceregistry, &lumiera_interfacenode_new (
self, plugin)->node, 100);
133 lumiera_interfaceregistry_bulkregister_interfaces (LumieraInterface*
self, LumieraPlugin plugin)
135 TRACE (interfaceregistry_dbg);
142 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
143 psplay_insert (lumiera_interfaceregistry, &lumiera_interfacenode_new (*
self, plugin)->node, 100);
151 lumiera_interfaceregistry_remove_interface (LumieraInterface
self)
153 TRACE (interfaceregistry_dbg);
158 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", self->interface, self->version, self->name);
159 LumieraInterfacenode node = (LumieraInterfacenode)
psplay_find (lumiera_interfaceregistry,
self, 0);
160 REQUIRE (node->refcnt == 0,
"but is %d", node->refcnt);
162 lumiera_interfacenode_delete ((LumieraInterfacenode)
psplay_remove (lumiera_interfaceregistry, &node->node));
168 lumiera_interfaceregistry_bulkremove_interfaces (LumieraInterface*
self)
170 TRACE (interfaceregistry_dbg);
177 TRACE (interfaceregistry,
"interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
179 LumieraInterfacenode node = (LumieraInterfacenode)
psplay_find (lumiera_interfaceregistry, *
self, 0);
182 REQUIRE (node->refcnt == 0,
"but is %d", node->refcnt);
183 lumiera_interfacenode_delete ((LumieraInterfacenode)
psplay_remove (lumiera_interfaceregistry, &node->node));
190 WARN (interfaceregistry,
"ENTRY NOT FOUND in interfaceregistry at clean-up of interface %s, instance %s" 202 lumiera_interfaceregistry_interfacenode_find (
const char* interface,
unsigned version,
const char*
name)
204 TRACE (interfaceregistry_dbg);
210 LumieraInterfacenode ret = NULL;
214 ret = (LumieraInterfacenode)
psplay_find (lumiera_interfaceregistry, &cmp, 100);
222 lumiera_interfaceregistry_interface_find (
const char* interface,
unsigned version,
const char* name)
224 return lumiera_interfaceregistry_interfacenode_find (interface, version, name)->interface;
229 lumiera_interface_cmp_fn (
const void* keya,
const void* keyb)
231 const LumieraInterface a = (
const LumieraInterface)keya;
232 const LumieraInterface b = (
const LumieraInterface)keyb;
234 int r = strcmp (a->interface, b->interface);
240 if (a->version < b->version)
242 else if (a->version > b->version)
245 r = strcmp (a->name, b->name);
256 lumiera_interface_key_fn (
const PSplaynode node)
258 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...