Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
interfaceregistry.c
Go to the documentation of this file.
1/*
2 InterfaceRegistry - registry for extension points
3
4 Copyright (C)
5 2008, Christian Thaeter <ct@pipapo.org>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
21#include "include/logging.h"
22#include "lib/error.h"
23#include "lib/psplay.h"
24#include "lib/safeclib.h"
25
26#include <nobug.h>
27
28#include "common/plugin.h"
30
31
32
35lumiera_recmutex lumiera_interface_mutex;
36
37static int
38lumiera_interface_cmp_fn (const void* keya, const void* keyb);
39
40static const void*
42
43
44
47{
48 LumieraInterfacenode self = lumiera_malloc (sizeof (*self));
49
50 psplaynode_init (&self->node);
51 self->interface = iface;
52 self->refcnt = 0;
53 self->plugin = plugin;
54 self->lnk = NULL;
55 self->deps_size = 0;
56 self->deps = NULL;
57
58 return self;
59}
60
61
62static void
64{
65 if (self)
66 {
67 REQUIRE (self->refcnt == 0);
68 lumiera_free (self->deps);
69 lumiera_free (self);
70 }
71}
72
73
75void
95
96
97void
99{
100 TRACE (interfaceregistry_dbg);
101
103
107
108 lumiera_recmutex_destroy (&lumiera_interface_mutex, &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT);
109
110 REQUIRE (!psplay_nelements (lumiera_interfaceregistry), "some interfaces still registered at shutdown");
111
115}
116
117
118void
120{
121 TRACE (interfaceregistry_dbg);
122 REQUIRE (self);
123
125 {
126 TRACE (interfaceregistry, "interface %s, version %d, instance %s", self->interface, self->version, self->name);
128 }
129}
130
131
132void
134{
135 TRACE (interfaceregistry_dbg);
136 REQUIRE (self);
137
139 {
140 while (*self)
141 {
142 TRACE (interfaceregistry, "interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
144 ++self;
145 }
146 }
147}
148
149
150void
152{
153 TRACE (interfaceregistry_dbg);
154 REQUIRE (self);
155
157 {
158 TRACE (interfaceregistry, "interface %s, version %d, instance %s", self->interface, self->version, self->name);
160 REQUIRE (node->refcnt == 0, "but is %d", node->refcnt);
161
163 }
164}
165
166
167void
169{
170 TRACE (interfaceregistry_dbg);
171 REQUIRE (self);
172
174 {
175 while (*self)
176 {
177 TRACE (interfaceregistry, "interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
178
180 if (node)
181 {
182 REQUIRE (node->refcnt == 0, "but is %d", node->refcnt);
184 }
185 else
186 {
189
190 WARN (interfaceregistry, "ENTRY NOT FOUND in interfaceregistry at clean-up of interface %s, instance %s"
191 , (*self)->interface
192 , (*self)->name);
193 }
194
195 ++self;
196 }
197 }
198}
199
200
202lumiera_interfaceregistry_interfacenode_find (const char* interface, unsigned version, const char* name)
203{
204 TRACE (interfaceregistry_dbg);
207 cmp.version = version;
208 cmp.name = name;
209
211
213 {
215 }
216
217 return ret;
218}
219
220
226
227
228static int
229lumiera_interface_cmp_fn (const void* keya, const void* keyb)
230{
231 const LumieraInterface a = (const LumieraInterface)keya;
232 const LumieraInterface b = (const LumieraInterface)keyb;
233
234 int r = strcmp (a->interface, b->interface);
235 if (r<0)
236 return -1;
237 else if (r>0)
238 return 1;
239
240 if (a->version < b->version)
241 return -1;
242 else if (a->version > b->version)
243 return 1;
244
245 r = strcmp (a->name, b->name);
246 if (r<0)
247 return -1;
248 else if (r>0)
249 return 1;
250
251 return 0;
252}
253
254
255static const void*
257{
258 return ((LumieraInterfacenode)node)->interface;
259}
260
261/*
262// Local Variables:
263// mode: C
264// c-file-style: "gnu"
265// indent-tabs-mode: nil
266// End:
267*/
Lumiera error handling (C interface).
#define LUMIERA_DIE(err)
Abort unconditionally with a 'Fatal Error!' message.
Definition error.h:54
void lumiera_interface_destroy(void)
deregistering implementations of the above interface
Definition interface.c:334
lumiera_interface * LumieraInterface
Definition interface.h:355
void lumiera_interface_init(void)
registering implementations of the above interface
void lumiera_interfaceregistry_register_interface(LumieraInterface self, LumieraPlugin plugin)
static LumieraInterfacenode lumiera_interfacenode_new(LumieraInterface iface, LumieraPlugin plugin)
void lumiera_interfaceregistry_init(void)
Initialise the interface registry.
LumieraInterfacenode lumiera_interfaceregistry_interfacenode_find(const char *interface, unsigned version, const char *name)
static void lumiera_interfacenode_delete(LumieraInterfacenode self)
void lumiera_interfaceregistry_remove_interface(LumieraInterface self)
lumiera_recmutex lumiera_interface_mutex
void lumiera_interfaceregistry_bulkremove_interfaces(LumieraInterface *self)
LumieraInterface lumiera_interfaceregistry_interface_find(const char *interface, unsigned version, const char *name)
void lumiera_interfaceregistry_destroy(void)
PSplay lumiera_interfaceregistry
static int lumiera_interface_cmp_fn(const void *keya, const void *keyb)
void lumiera_interfaceregistry_bulkregister_interfaces(LumieraInterface *self, LumieraPlugin plugin)
PSplay lumiera_pluginregistry
static const void * lumiera_interface_key_fn(const PSplaynode node)
Global registry for interfaces (extension points).
lumiera_interfacenode * LumieraInterfacenode
return NULL
Definition llist.h:586
const_LList llist_cmpfn cmp
Definition llist.h:580
This header is for including and configuring NoBug.
void lumiera_plugin_delete_fn(PSplaynode node)
Definition plugin.c:393
const void * lumiera_plugin_key_fn(const PSplaynode node)
Definition plugin.c:386
int lumiera_plugin_cmp_fn(const void *keya, const void *keyb)
Definition plugin.c:379
Lumiera plugins define 'interfaces' as shown in interface.h, the plugin system handles the loading of...
lumiera_plugin * LumieraPlugin
Definition plugin.h:64
void psplay_delete(PSplay self)
Delete a splay tree Frees all elements and associated resources of a splay tree and then itseld.
Definition psplay.c:115
PSplay psplay_destroy(PSplay self)
Destroy a splay tree Frees all elements and associated resources of a splay tree.
Definition psplay.c:101
PSplaynode psplay_insert(PSplay self, PSplaynode node, int splayfactor)
Insert a element into a splay tree.
Definition psplay.c:246
PSplay psplay_new(psplay_cmp_fn cmp, psplay_key_fn key, psplay_delete_fn del)
Allocate a splay tree.
Definition psplay.c:88
PSplaynode psplaynode_init(PSplaynode self)
Initialise a splay tree node The user has to place this nodes within his datastructure and must Initi...
Definition psplay.c:122
PSplaynode psplay_remove(PSplay self, PSplaynode node)
Remove a node from a splay tree.
Definition psplay.c:340
PSplaynode psplay_find(PSplay self, const void *key, int splayfactor)
Find a element in a splay tree.
Definition psplay.c:300
Probabilistic splay tree.
static size_t psplay_nelements(PSplay self)
Number of elements in tree.
Definition psplay.h:103
psplaynode * PSplaynode
Definition psplay.h:40
psplay * PSplay
Definition psplay.h:82
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...
Definition recmutex.c:32
LumieraRecmutex lumiera_recmutex_destroy(LumieraRecmutex self, struct nobug_flag *flag, const struct nobug_context ctx)
Destroy a recursive mutex variable.
Definition recmutex.c:53
#define LUMIERA_RECMUTEX_SECTION(nobugflag, mtx)
Recursive Mutual exclusive section.
Definition recmutex.h:32
void * lumiera_malloc(size_t size)
Allocate memory.
Definition safeclib.c:113
Portable and safe wrappers around some C-Lib functions.
static void lumiera_free(void *mem)
Free previously allocated memory.
Definition safeclib.h:73
Header for an interface, just the absolute necessary metadata.
Definition interface.h:372
unsigned version
major version, 0 means experimental
Definition interface.h:377
const char * interface
name of the interface (type)
Definition interface.h:374
const char * name
name of this instance
Definition interface.h:380