Lumiera  0.pre.03
»edit your freedom«
interface.h
Go to the documentation of this file.
1 /*
2  INTERFACE.h - Lumiera interface macros and structures
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 
77 #ifndef LUMIERA_INTERFACE_H
78 #define LUMIERA_INTERFACE_H
79 
80 #include "lib/ppmpl.h"
81 #include "lib/psplay.h"
82 
83 
84 
85 /* ==== Macros to Declare an Interface */
86 
93 #define LUMIERA_INTERFACE_INAME(name, version) name##_##version
94 
102 #define LUMIERA_INTERFACE_DNAME(iname, version, dname) PPMPL_CAT (LUMIERA_INTERFACE_INAME (iname, version), _##dname)
103 
111 #define LUMIERA_INTERFACE_DSTRING(iname, version, dname) PPMPL_STRINGIFY (LUMIERA_INTERFACE_DNAME (iname, version, dname))
112 
119 #define LUMIERA_INTERFACE_REF(iname, version, dname) \
120  (LumieraInterface)&LUMIERA_INTERFACE_DNAME(iname, version, dname)
121 
122 
128 #define LUMIERA_INTERFACE_TYPE(name, version) struct LUMIERA_INTERFACE_INAME(name, version)
129 
130 
137 #define LUMIERA_INTERFACE_CAST(name, version) (LUMIERA_INTERFACE_TYPE(name, version)*)
138 
139 
154 #define LUMIERA_INTERFACE_DECLARE(name, version, ...) \
155 LUMIERA_INTERFACE_TYPE(name, version) \
156 { \
157  lumiera_interface interface_header_; \
158  PPMPL_FOREACH(_, __VA_ARGS__) \
159 }
160 
167 #define PPMPL_FOREACH_LUMIERA_INTERFACE_SLOT(ret, name, params) \
168  ret (*name) params; \
169 
170 
171 /*
172  Macros to Define an Interface
173  */
174 
185 #define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, acquire, release, ...) \
186 PPMPL_FOREACH(_P1_, __VA_ARGS__) \
187 LUMIERA_INTERFACE_TYPE(iname, version) LUMIERA_INTERFACE_DNAME(iname, version, name) = \
188 { \
189 { \
190  #iname, \
191  version, \
192  #name, \
193  sizeof (LUMIERA_INTERFACE_TYPE(iname, version)), \
194  descriptor, \
195  acquire, \
196  release \
197 }, \
198 PPMPL_FOREACH(_P2_, __VA_ARGS__) \
199 }
200 
201 
210 #define PPMPL_FOREACH_P1_LUMIERA_INTERFACE_MAP(slot, function)
211 #ifdef __cplusplus
212 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_MAP(slot, function) \
213  function,\
214 
215 #else
216 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_MAP(slot, function) \
217  .slot = function,\
218 
219 #endif
220 
221 
232 #define PPMPL_FOREACH_P1_LUMIERA_INTERFACE_INLINE(slot, ret, params, ...) \
233  static ret \
234  LUMIERA_INTERFACE_INLINE_NAME(slot) params \
235  __VA_ARGS__
236 
237 #ifdef __cplusplus
238 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_INLINE(slot, ret, params, ...) \
239  LUMIERA_INTERFACE_INLINE_NAME(slot),\
240 
241 #else
242 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_INLINE(slot, ret, params, ...) \
243  .slot = LUMIERA_INTERFACE_INLINE_NAME(slot),\
244 
245 #endif
246 
247 #define LUMIERA_INTERFACE_INLINE_NAME(slot) PPMPL_CAT(lumiera_##slot##_l, __LINE__)
248 
249 
250 #define PPMPL_FOREACH_L1_P1_LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, acquire, release, ...) \
251 LUMIERA_INTERFACE_INSTANCE (iname, version, \
252  name, \
253  descriptor, \
254  acquire, \
255  release, \
256  __VA_ARGS__ \
257  );
258 
259 
260 #define PPMPL_FOREACH_L1_P2_LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, acquire, release, ...) \
261  &LUMIERA_INTERFACE_DNAME(iname, version, name).interface_header_,
262 
263 
273 #define LUMIERA_EXPORT(...) \
274 PPMPL_FOREACH_L1(_P1_, __VA_ARGS__) \
275 static LumieraInterface* \
276 lumiera_plugin_interfaces (void) \
277 { \
278  static LumieraInterface interfaces[] = \
279  { \
280  PPMPL_FOREACH_L1(_P2_, __VA_ARGS__) \
281  NULL \
282  }; \
283  return interfaces; \
284 } \
285 LUMIERA_PLUGININTERFACE
286 
287 
291 #ifdef LUMIERA_PLUGIN /* compile as plugin */
292 #define LUMIERA_PLUGIN_INTERFACEHANDLE static LUMIERA_INTERFACE_HANDLE(lumieraorg_interface, 0) lumiera_interface_handle
293 #define LUMIERA_PLUGIN_STORE_INTERFACEHANDLE(name) lumiera_interface_handle = LUMIERA_INTERFACE_CAST (lumieraorg_interface, 0) name
294 
295 #define LUMIERA_PLUGININTERFACE \
296 LUMIERA_INTERFACE_INSTANCE (lumieraorg__plugin, 0, \
297  lumieraorg_plugin, \
298  NULL, \
299  NULL, \
300  NULL, \
301  LUMIERA_INTERFACE_MAP (plugin_interfaces, \
302  lumiera_plugin_interfaces) \
303  );
304 #define LUMIERA_INTERFACE_REGISTEREXPORTED
305 #define LUMIERA_INTERFACE_UNREGISTEREXPORTED
306 
307 #define LUMIERA_INTERFACE_OPEN(interface, version, minminor, name) \
308  LUMIERA_INTERFACE_CAST(interface, version) lumiera_interface_handle->open (#interface, version, minminor, #name)
309 
310 #define LUMIERA_INTERFACE_CLOSE(handle) \
311  lumiera_interface_handle->close (&(handle)->interface_header_)
312 
313 
314 #else /* compile as builtin */
315 
316 #define LUMIERA_PLUGIN_INTERFACEHANDLE static LUMIERA_INTERFACE_HANDLE(lumieraorg_interface, 0) lumiera_interface_handle
317 #define LUMIERA_PLUGIN_STORE_INTERFACEHANDLE(name) lumiera_interface_handle = LUMIERA_INTERFACE_CAST (lumieraorg_interface, 0) name
318 
319 #define LUMIERA_PLUGININTERFACE
320 
324 #define LUMIERA_INTERFACE_REGISTEREXPORTED \
325  lumiera_interfaceregistry_bulkregister_interfaces (lumiera_plugin_interfaces(), NULL)
326 
330 #define LUMIERA_INTERFACE_UNREGISTEREXPORTED \
331  lumiera_interfaceregistry_bulkremove_interfaces (lumiera_plugin_interfaces())
332 
333 #define LUMIERA_INTERFACE_OPEN(interface, version, minminor, name) \
334  LUMIERA_INTERFACE_CAST(interface, version) lumiera_interface_open (#interface, version, minminor, #name)
335 
336 #define LUMIERA_INTERFACE_CLOSE(handle) \
337  lumiera_interface_close (&(handle)->interface_header_)
338 
339 #endif
340 
341 
342 
347 #define LUMIERA_INTERFACE_HANDLE(interface, version) \
348  LUMIERA_INTERFACE_TYPE(interface, version)*
349 
350 
351 typedef struct lumiera_interfaceslot_struct lumiera_interfaceslot;
352 typedef lumiera_interfaceslot* LumieraInterfaceslot;
353 
354 typedef struct lumiera_interface_struct lumiera_interface;
355 typedef lumiera_interface* LumieraInterface;
356 
363 {
364  void (*func)(void);
365 };
366 
367 
372 {
374  const char* interface;
375 
377  unsigned version;
378 
380  const char* name;
381 
383  size_t size;
384 
386  LumieraInterface descriptor;
387 
397  LumieraInterface (*acquire)(LumieraInterface self, LumieraInterface interfaces);
403  void (*release)(LumieraInterface self);
404 
405 #ifndef __cplusplus
406 
407  lumiera_interfaceslot functions[];
408 #endif
409 };
410 
411 /*
412  API to handle interfaces
413  */
414 
424 LumieraInterface
425 lumiera_interface_open (const char* interface, unsigned version, size_t minminorversion, const char* name);
426 
432 void
433 lumiera_interface_close (LumieraInterface self);
434 
441 unsigned
442 lumiera_interface_version (LumieraInterface self, const char* iname);
443 
447 LUMIERA_INTERFACE_DECLARE (lumieraorg_interface, 0,
448  LUMIERA_INTERFACE_SLOT (LumieraInterface,
449  open,
450  (const char* interface, unsigned version, size_t minminorversion, const char* name)),
451  LUMIERA_INTERFACE_SLOT (void, close, (LumieraInterface self)),
452  LUMIERA_INTERFACE_SLOT (unsigned, version, (LumieraInterface self, const char* iname)),
453 );
454 
458 void
460 
464 void
466 
467 
468 
469 
470 
474 LUMIERA_INTERFACE_DECLARE (lumieraorg__plugin, 0,
475  LUMIERA_INTERFACE_SLOT (LumieraInterface*, plugin_interfaces, (void)),
476 );
477 
478 
479 
480 #endif /* LUMIERA_INTERFACE_H */
481 /*
482 // Local Variables:
483 // mode: C
484 // c-file-style: "gnu"
485 // indent-tabs-mode: nil
486 // End:
487 */
Header for an interface, just the absolute necessary metadata.
Definition: interface.h:371
void lumiera_interface_init(void)
registering implementations of the above interface
const char * name
name of this instance
Definition: interface.h:380
#define LUMIERA_INTERFACE_DECLARE(name, version,...)
Declare an interface.
Definition: interface.h:154
unsigned version
major version, 0 means experimental
Definition: interface.h:377
This is just a placeholder for an entry in a interface table.
Definition: interface.h:362
LumieraInterface lumiera_interface_open(const char *interface, unsigned version, size_t minminorversion, const char *name)
Open an interface by version and name.
Definition: interface.c:49
Probabilistic splay tree.
LumieraInterface descriptor
metadata descriptor, itself a interface (or NULL)
Definition: interface.h:386
Preprocessor metaprogramming library.
const char * interface
name of the interface (type)
Definition: interface.h:374
void lumiera_interface_close(LumieraInterface self)
Close an interface after use.
Definition: interface.c:226
void lumiera_interface_destroy(void)
deregistering implementations of the above interface
Definition: interface.c:334
unsigned lumiera_interface_version(LumieraInterface self, const char *iname)
Runtime check for interface type and version.
Definition: interface.c:238
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
size_t size
size of the whole interface structure (minor version)
Definition: interface.h:383