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) Lumiera.org
5  2008, Christian Thaeter <ct@pipapo.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
86 #ifndef LUMIERA_INTERFACE_H
87 #define LUMIERA_INTERFACE_H
88 
89 #include "lib/ppmpl.h"
90 #include "lib/psplay.h"
91 
92 
93 
94 /* ==== Macros to Declare an Interface */
95 
102 #define LUMIERA_INTERFACE_INAME(name, version) name##_##version
103 
111 #define LUMIERA_INTERFACE_DNAME(iname, version, dname) PPMPL_CAT (LUMIERA_INTERFACE_INAME (iname, version), _##dname)
112 
120 #define LUMIERA_INTERFACE_DSTRING(iname, version, dname) PPMPL_STRINGIFY (LUMIERA_INTERFACE_DNAME (iname, version, dname))
121 
128 #define LUMIERA_INTERFACE_REF(iname, version, dname) \
129  (LumieraInterface)&LUMIERA_INTERFACE_DNAME(iname, version, dname)
130 
131 
137 #define LUMIERA_INTERFACE_TYPE(name, version) struct LUMIERA_INTERFACE_INAME(name, version)
138 
139 
146 #define LUMIERA_INTERFACE_CAST(name, version) (LUMIERA_INTERFACE_TYPE(name, version)*)
147 
148 
163 #define LUMIERA_INTERFACE_DECLARE(name, version, ...) \
164 LUMIERA_INTERFACE_TYPE(name, version) \
165 { \
166  lumiera_interface interface_header_; \
167  PPMPL_FOREACH(_, __VA_ARGS__) \
168 }
169 
176 #define PPMPL_FOREACH_LUMIERA_INTERFACE_SLOT(ret, name, params) \
177  ret (*name) params; \
178 
179 
180 /*
181  Macros to Define an Interface
182  */
183 
194 #define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, acquire, release, ...) \
195 PPMPL_FOREACH(_P1_, __VA_ARGS__) \
196 LUMIERA_INTERFACE_TYPE(iname, version) LUMIERA_INTERFACE_DNAME(iname, version, name) = \
197 { \
198 { \
199  #iname, \
200  version, \
201  #name, \
202  sizeof (LUMIERA_INTERFACE_TYPE(iname, version)), \
203  descriptor, \
204  acquire, \
205  release \
206 }, \
207 PPMPL_FOREACH(_P2_, __VA_ARGS__) \
208 }
209 
210 
219 #define PPMPL_FOREACH_P1_LUMIERA_INTERFACE_MAP(slot, function)
220 #ifdef __cplusplus
221 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_MAP(slot, function) \
222  function,\
223 
224 #else
225 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_MAP(slot, function) \
226  .slot = function,\
227 
228 #endif
229 
230 
241 #define PPMPL_FOREACH_P1_LUMIERA_INTERFACE_INLINE(slot, ret, params, ...) \
242  static ret \
243  LUMIERA_INTERFACE_INLINE_NAME(slot) params \
244  __VA_ARGS__
245 
246 #ifdef __cplusplus
247 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_INLINE(slot, ret, params, ...) \
248  LUMIERA_INTERFACE_INLINE_NAME(slot),\
249 
250 #else
251 #define PPMPL_FOREACH_P2_LUMIERA_INTERFACE_INLINE(slot, ret, params, ...) \
252  .slot = LUMIERA_INTERFACE_INLINE_NAME(slot),\
253 
254 #endif
255 
256 #define LUMIERA_INTERFACE_INLINE_NAME(slot) PPMPL_CAT(lumiera_##slot##_l, __LINE__)
257 
258 
259 #define PPMPL_FOREACH_L1_P1_LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, acquire, release, ...) \
260 LUMIERA_INTERFACE_INSTANCE (iname, version, \
261  name, \
262  descriptor, \
263  acquire, \
264  release, \
265  __VA_ARGS__ \
266  );
267 
268 
269 #define PPMPL_FOREACH_L1_P2_LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, acquire, release, ...) \
270  &LUMIERA_INTERFACE_DNAME(iname, version, name).interface_header_,
271 
272 
282 #define LUMIERA_EXPORT(...) \
283 PPMPL_FOREACH_L1(_P1_, __VA_ARGS__) \
284 static LumieraInterface* \
285 lumiera_plugin_interfaces (void) \
286 { \
287  static LumieraInterface interfaces[] = \
288  { \
289  PPMPL_FOREACH_L1(_P2_, __VA_ARGS__) \
290  NULL \
291  }; \
292  return interfaces; \
293 } \
294 LUMIERA_PLUGININTERFACE
295 
296 
300 #ifdef LUMIERA_PLUGIN /* compile as plugin */
301 #define LUMIERA_PLUGIN_INTERFACEHANDLE static LUMIERA_INTERFACE_HANDLE(lumieraorg_interface, 0) lumiera_interface_handle
302 #define LUMIERA_PLUGIN_STORE_INTERFACEHANDLE(name) lumiera_interface_handle = LUMIERA_INTERFACE_CAST (lumieraorg_interface, 0) name
303 
304 #define LUMIERA_PLUGININTERFACE \
305 LUMIERA_INTERFACE_INSTANCE (lumieraorg__plugin, 0, \
306  lumieraorg_plugin, \
307  NULL, \
308  NULL, \
309  NULL, \
310  LUMIERA_INTERFACE_MAP (plugin_interfaces, \
311  lumiera_plugin_interfaces) \
312  );
313 #define LUMIERA_INTERFACE_REGISTEREXPORTED
314 #define LUMIERA_INTERFACE_UNREGISTEREXPORTED
315 
316 #define LUMIERA_INTERFACE_OPEN(interface, version, minminor, name) \
317  LUMIERA_INTERFACE_CAST(interface, version) lumiera_interface_handle->open (#interface, version, minminor, #name)
318 
319 #define LUMIERA_INTERFACE_CLOSE(handle) \
320  lumiera_interface_handle->close (&(handle)->interface_header_)
321 
322 
323 #else /* compile as builtin */
324 
325 #define LUMIERA_PLUGIN_INTERFACEHANDLE static LUMIERA_INTERFACE_HANDLE(lumieraorg_interface, 0) lumiera_interface_handle
326 #define LUMIERA_PLUGIN_STORE_INTERFACEHANDLE(name) lumiera_interface_handle = LUMIERA_INTERFACE_CAST (lumieraorg_interface, 0) name
327 
328 #define LUMIERA_PLUGININTERFACE
329 
333 #define LUMIERA_INTERFACE_REGISTEREXPORTED \
334  lumiera_interfaceregistry_bulkregister_interfaces (lumiera_plugin_interfaces(), NULL)
335 
339 #define LUMIERA_INTERFACE_UNREGISTEREXPORTED \
340  lumiera_interfaceregistry_bulkremove_interfaces (lumiera_plugin_interfaces())
341 
342 #define LUMIERA_INTERFACE_OPEN(interface, version, minminor, name) \
343  LUMIERA_INTERFACE_CAST(interface, version) lumiera_interface_open (#interface, version, minminor, #name)
344 
345 #define LUMIERA_INTERFACE_CLOSE(handle) \
346  lumiera_interface_close (&(handle)->interface_header_)
347 
348 #endif
349 
350 
351 
356 #define LUMIERA_INTERFACE_HANDLE(interface, version) \
357  LUMIERA_INTERFACE_TYPE(interface, version)*
358 
359 
360 typedef struct lumiera_interfaceslot_struct lumiera_interfaceslot;
361 typedef lumiera_interfaceslot* LumieraInterfaceslot;
362 
363 typedef struct lumiera_interface_struct lumiera_interface;
364 typedef lumiera_interface* LumieraInterface;
365 
372 {
373  void (*func)(void);
374 };
375 
376 
381 {
383  const char* interface;
384 
386  unsigned version;
387 
389  const char* name;
390 
392  size_t size;
393 
395  LumieraInterface descriptor;
396 
406  LumieraInterface (*acquire)(LumieraInterface self, LumieraInterface interfaces);
412  void (*release)(LumieraInterface self);
413 
414 #ifndef __cplusplus
415 
416  lumiera_interfaceslot functions[];
417 #endif
418 };
419 
420 /*
421  API to handle interfaces
422  */
423 
433 LumieraInterface
434 lumiera_interface_open (const char* interface, unsigned version, size_t minminorversion, const char* name);
435 
441 void
442 lumiera_interface_close (LumieraInterface self);
443 
450 unsigned
451 lumiera_interface_version (LumieraInterface self, const char* iname);
452 
456 LUMIERA_INTERFACE_DECLARE (lumieraorg_interface, 0,
457  LUMIERA_INTERFACE_SLOT (LumieraInterface,
458  open,
459  (const char* interface, unsigned version, size_t minminorversion, const char* name)),
460  LUMIERA_INTERFACE_SLOT (void, close, (LumieraInterface self)),
461  LUMIERA_INTERFACE_SLOT (unsigned, version, (LumieraInterface self, const char* iname)),
462 );
463 
467 void
469 
473 void
475 
476 
477 
478 
479 
483 LUMIERA_INTERFACE_DECLARE (lumieraorg__plugin, 0,
484  LUMIERA_INTERFACE_SLOT (LumieraInterface*, plugin_interfaces, (void)),
485 );
486 
487 
488 
489 #endif /* LUMIERA_INTERFACE_H */
490 /*
491 // Local Variables:
492 // mode: C
493 // c-file-style: "gnu"
494 // indent-tabs-mode: nil
495 // End:
496 */
Header for an interface, just the absolute necessary metadata.
Definition: interface.h:380
void lumiera_interface_init(void)
registering implementations of the above interface
const char * name
name of this instance
Definition: interface.h:389
#define LUMIERA_INTERFACE_DECLARE(name, version,...)
Declare an interface.
Definition: interface.h:163
unsigned version
major version, 0 means experimental
Definition: interface.h:386
This is just a placeholder for an entry in a interface table.
Definition: interface.h:371
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:58
Probabilistic splay tree.
LumieraInterface descriptor
metadata descriptor, itself a interface (or NULL)
Definition: interface.h:395
Preprocessor metaprogramming library.
const char * interface
name of the interface (type)
Definition: interface.h:383
void lumiera_interface_close(LumieraInterface self)
Close an interface after use.
Definition: interface.c:235
void lumiera_interface_destroy(void)
deregistering implementations of the above interface
Definition: interface.c:343
unsigned lumiera_interface_version(LumieraInterface self, const char *iname)
Runtime check for interface type and version.
Definition: interface.c:247
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:392