From feb9ba7db9cc9dfc813304cfbc0afc0f58f46324 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Mon, 15 Sep 2008 20:42:49 +0200 Subject: [PATCH] provide some example code for the 'interface' system * test-interfaces.c is just a mockup to show how interfaces are created * fix some bugs introduced with a futile refactoring try at the last commit --- src/lib/interface.h | 37 ++++------ tests/Makefile.am | 5 ++ tests/library/test-interfaces.c | 126 ++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 tests/library/test-interfaces.c diff --git a/src/lib/interface.h b/src/lib/interface.h index dac45ee91..5c1683bae 100644 --- a/src/lib/interface.h +++ b/src/lib/interface.h @@ -54,13 +54,10 @@ * Any code which want to use this interface must then include its declaration. * * Basic definition of an interface is done by: - * LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, data, acquire, release, - * LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, data, acquire, release, - * LUMIERA_INTERFACE_MAP (slot, function, luid), - * ... - * ), - * ... - * ) + * LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, data, acquire, release, + * LUMIERA_INTERFACE_MAP (slot, function, luid), + * ... + * ) * * There are 2 ways to define collections of interfaces: * LUMIERA_EXPORT(queryfunc, @@ -149,8 +146,7 @@ LUMIERA_INTERFACE_TYPE(name, version) \ * @param name name of this slot * @param params parentized list of parameters for the function */ -#define LUMIERA_INTERFACE_SLOT(ret, name, params) ret (*name) params; lumiera_uid name##_uid; -#define PPMPL_FOREACH_LUMIERA_INTERFACE_SLOT(ret, name, params) LUMIERA_INTERFACE_SLOT(ret, name, params) +#define PPMPL_FOREACH_LUMIERA_INTERFACE_SLOT(ret, name, params) ret (*name) params; lumiera_uid name##_uid; /* @@ -169,7 +165,7 @@ LUMIERA_INTERFACE_TYPE(name, version) \ * @param release a function which is called whenever this interface is closed after use, might be NULL * @param ... map functions to interface slots @see LUMIERA_INTERFACE_MAP */ -#define LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, data, acquire, release, ...) \ +#define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, data, acquire, release, ...) \ LUMIERA_INTERFACE_TYPE(iname, version) LUMIERA_INTERFACE_DNAME(iname, name, version) = \ { \ { \ @@ -196,24 +192,23 @@ LUMIERA_INTERFACE_TYPE(iname, version) LUMIERA_INTERFACE_DNAME(iname, name, vers * this would be good style for C too anyways */ #ifdef __cplusplus -#define LUMIERA_INTERFACE_MAP(slot, function, luid) \ +#define PPMPL_FOREACH_LUMIERA_INTERFACE_MAP(slot, function, luid) \ function, LUMIERA_UID_INITIALIZER (uid), #else -#define LUMIERA_INTERFACE_MAP(slot, function, luid) \ +#define PPMPL_FOREACH_LUMIERA_INTERFACE_MAP(slot, function, luid) \ .slot = function, .slot##_uid = LUMIERA_UID_INITIALIZER (luid), #endif -#define PPMPL_FOREACH_LUMIERA_INTERFACE_MAP(slot, function, luid) LUMIERA_INTERFACE_MAP(slot, function, luid) #define PPMPL_FOREACH_L1_P1_LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, data, acquire, release, ...) \ -LUMIERA_INTERFACE_DEFINE (iname, version, \ - name, \ - descriptor, \ - data, \ - acquire, \ - release, \ - __VA_ARGS__ \ - ); +LUMIERA_INTERFACE_INSTANCE (iname, version, \ + name, \ + descriptor, \ + data, \ + acquire, \ + release, \ + __VA_ARGS__ \ + ); #define PPMPL_FOREACH_L1_P2_LUMIERA_INTERFACE_DEFINE(iname, version, name, descriptor, data, acquire, release, ...) \ diff --git a/tests/Makefile.am b/tests/Makefile.am index fa28a115f..f3ae80391 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -48,6 +48,11 @@ test_luid_SOURCES = $(tests_srcdir)/library/test-luid.c test_luid_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror test_luid_LDADD = liblumi.a $(NOBUGMT_LUMIERA_LIBS) -ldl -lm +check_PROGRAMS += test-interfaces +test_interfaces_SOURCES = $(tests_srcdir)/library/test-interfaces.c +test_interfaces_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror +test_interfaces_LDADD = liblumi.a $(NOBUGMT_LUMIERA_LIBS) -ldl -lm + check_PROGRAMS += test-filedescriptors test_filedescriptors_SOURCES = $(tests_srcdir)/backend/test-filedescriptors.c test_filedescriptors_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror diff --git a/tests/library/test-interfaces.c b/tests/library/test-interfaces.c new file mode 100644 index 000000000..97c9442c5 --- /dev/null +++ b/tests/library/test-interfaces.c @@ -0,0 +1,126 @@ +/* + test-interfaces.c - test interfaces declaration and implementation + + Copyright (C) Lumiera.org + 2008, Christian Thaeter + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "lib/interface.h" +#include "tests/test.h" + +/* + define 2 example interfaces + */ + +LUMIERA_INTERFACE_DECLARE (example1, 0, + LUMIERA_INTERFACE_SLOT (void, foo1, (const char*)), + LUMIERA_INTERFACE_SLOT (void, bar1, (const char*)), +); + +LUMIERA_INTERFACE_DECLARE (example2, 0, + LUMIERA_INTERFACE_SLOT (void, foo2, (const char*)), + LUMIERA_INTERFACE_SLOT (void, bar2, (const char*)), +); + + +/* + now the functions we want to bind to them + */ + +void +testfunc (const char* message) +{ + printf ("Called as '%s'\n", message); +} + + + +/* + implementation of some example interfaces + */ + +LUMIERA_INTERFACE_INSTANCE (example1, 0, + example1_standalone_implementation, + NULL, + NULL, + NULL, + NULL, + LUMIERA_INTERFACE_MAP (foo1, testfunc, + "\066\177\042\305\165\243\236\352\164\250\357\307\211\374\123\066"), + LUMIERA_INTERFACE_MAP (bar1, testfunc, + "\162\335\262\306\101\113\106\055\342\205\300\151\262\073\257\343") + ); + + +LUMIERA_EXPORT (interfaces_defined_here, + LUMIERA_INTERFACE_DEFINE (example1, 0, + example1_implementation, + NULL, + NULL, + NULL, + NULL, + LUMIERA_INTERFACE_MAP (foo1, testfunc, + "\214\310\136\372\003\344\163\377\075\100\070\200\375\221\227\324"), + LUMIERA_INTERFACE_MAP (bar1, testfunc, + "\262\253\067\211\157\052\212\140\114\334\231\250\340\075\214\030") + ), + LUMIERA_INTERFACE_DEFINE (example2, 0, + example2_implementation, + NULL, + NULL, + NULL, + NULL, + LUMIERA_INTERFACE_MAP (foo2, testfunc, + "\110\152\002\271\363\052\324\272\373\045\132\270\277\000\271\217"), + LUMIERA_INTERFACE_MAP (bar2, testfunc, + "\376\042\027\336\355\113\132\233\350\312\170\077\377\370\356\167") + ) + ); + + +TESTS_BEGIN + +TEST ("basic") +{ + interfaces_defined_here(); +} + +TEST ("basic") +{ +} + +TEST ("basic") +{ +} + +TEST ("basic") +{ +} + +TESTS_END + + + + + +/* +// Local Variables: +// mode: C +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +*/