Restructure the src directory

It is split into
- /libgnucash (for the non-gui bits)
- /gnucash (for the gui)
- /common (misc source files used by both)
- /bindings (currently only holds python bindings)

This is the first step in restructuring the code. It will need much
more fine tuning later on.
This commit is contained in:
Geert Janssens
2017-08-10 13:56:00 +02:00
parent ffc640bada
commit 83d14e1c1c
1984 changed files with 4406 additions and 4271 deletions

View File

@@ -0,0 +1,69 @@
# CMakeLists.txt for libgnucash/gnc-module
ADD_SUBDIRECTORY(test)
IF (BUILDING_FROM_VCS)
# Command to generate the swig-gnc-module.c wrapper file
SET (SWIG_GNC_MODULE_C ${CMAKE_CURRENT_BINARY_DIR}/swig-gnc-module.c)
GNC_ADD_SWIG_COMMAND (swig-gnc-module-c ${SWIG_GNC_MODULE_C} ${CMAKE_CURRENT_SOURCE_DIR}/gnc-module.i)
ELSE()
SET (SWIG_GNC_MODULE_C swig-gnc-module.c)
ENDIF()
SET (gnc_module_SOURCES gnc-module.c)
# Add dependency on config.h
SET_SOURCE_FILES_PROPERTIES (${gnc_module_SOURCES} PROPERTIES OBJECT_DEPENDS ${CONFIG_H})
SET (gnc_module_HEADERS
gnc-module.h
gnc-module-api.h
)
ADD_LIBRARY (gnc-module
${gnc_module_SOURCES}
${gnc_module_HEADERS}
${SWIG_GNC_MODULE_C}
)
TARGET_LINK_LIBRARIES(gnc-module ${GUILE_LDFLAGS} ${GMODULE_LDFLAGS} ${GLIB2_LDFLAGS})
TARGET_COMPILE_DEFINITIONS (gnc-module PRIVATE -DG_LOG_DOMAIN=\"gnc.module\")
TARGET_INCLUDE_DIRECTORIES (gnc-module
PRIVATE ${GUILE_INCLUDE_DIRS}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/common
${CMAKE_BINARY_DIR}/common # for config.h
${GLIB2_INCLUDE_DIRS}
)
INSTALL(TARGETS gnc-module
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
INSTALL(FILES ${gnc_module_HEADERS} DESTINATION include/gnucash)
# --- Compile Scheme file(s) ---
SET (gnc_module_SCHEME gnc-module.scm)
SET(GUILE_OUTPUT_DIR gnucash)
SET(GUILE_MODULES "")
SET(GUILE_LOAD_DIRS "")
SET(GUILE_LIBRARY_DIRS "")
SET(GUILE_DEPENDS gnc-module)
GNC_ADD_SCHEME_TARGETS(scm-gnc-module
"${gnc_module_SCHEME}"
${GUILE_OUTPUT_DIR}
"${GUILE_MODULES}"
"${GUILE_LOAD_DIRS}"
"${GUILE_LIBRARY_DIRS}"
"${GUILE_DEPENDS}"
FALSE
)
SET_LOCAL_DIST(gnc_module_DIST_local CMakeLists.txt Makefile.am ${gnc_module_SOURCES} ${gnc_module_HEADERS}
gnc-module.i gnc-module.scm README)
SET(gnc_module_DIST ${gnc_module_DIST_local} ${test_gnc_module_DIST} PARENT_SCOPE)

View File

@@ -0,0 +1,90 @@
# No SUBDIR variable here...
# The 'test' subdir is added via src/Makefile to handle
# it's dependency on src/engine
AM_CPPFLAGS = \
-I${top_srcdir}/lib/libc \
-I${top_srcdir}/common \
-I${top_srcdir}/libgnucash/core-utils \
${GLIB_CFLAGS} \
${GUILE_CFLAGS}
lib_LTLIBRARIES = libgnc-module.la
libgnc_module_la_SOURCES = gnc-module.c swig-gnc-module.c
libgnc_module_la_LIBADD = \
../core-utils/libgnc-core-utils.la \
${top_builddir}/lib/libc/libc-missing.la \
${GLIB_LIBS} \
${GUILE_LIBS}
gncscmmoddir = ${GNC_SCM_INSTALL_DIR}/gnucash
gncscmmod_DATA = gnc-module.scm
gncincludedir = ${GNC_INCLUDE_DIR}
gncinclude_HEADERS = \
gnc-module-api.h \
gnc-module.h
noinst_DATA = .scm-links
if BUILDING_FROM_VCS
swig-gnc-module.c: gnc-module.i ${top_srcdir}/common/base-typemaps.i
$(SWIG) -guile $(SWIG_ARGS) -Linkage module \
-I${top_srcdir}/common -o $@ $<
if ! OS_WIN32
if ! SWIG_DIST_FAIL
if ! `grep "define scm_from_utf8_string" $@ > /dev/null 2>&1`; then \
patch $@ $(top_srcdir)/common/swig-utf8.patch; \
fi
endif
endif
endif
EXTRA_DIST = \
${gncscmmod_DATA} \
gnc-module.i \
CMakeLists.txt
if GNUCASH_SEPARATE_BUILDDIR
#For executing test cases
SCM_FILE_LINKS = ${gncscmmod_DATA}
endif
.scm-links:
$(RM) -rf gnucash
mkdir -p gnucash
if GNUCASH_SEPARATE_BUILDDIR
for X in ${SCM_FILE_LINKS} ; do \
$(LN_S) -f ${srcdir}/$$X . ; \
done
endif
( cd gnucash; for A in $(gncscmmod_DATA) ; do $(LN_S) -f ../$$A . ; done )
if ! OS_WIN32
# Windows knows no "ln -s" but uses "cp": must copy every time (see bug #566567).
touch .scm-links
endif
if GNC_HAVE_GUILE_2
GUILE_COMPILE_ENV = \
--library-dir ${top_builddir}/libgnucash/gnc-module \
--library-dir ${top_builddir}/libgnucash/core-utils
%.go : %.scm .scm-links $(lib_LTLIBRARIES)
GNC_UNINSTALLED=yes \
GNC_BUILDDIR=${top_builddir} \
$(shell ${abs_top_srcdir}/common/gnc-test-env.pl --noexports ${GUILE_COMPILE_ENV}) \
$(GUILD) compile -o $@ $<
gncscmmodcachedir = ${pkglibdir}/scm/ccache/@GUILE_EFFECTIVE_VERSION@/gnucash
gncscmmodcache_DATA = $(gncscmmod_DATA:.scm=.go)
endif
clean-local:
rm -rf gnucash
CLEANFILES = .scm-links ${SCM_FILE_LINKS} ${gncscmmodcache_DATA}
MAINTAINERCLEANFILES = swig-gnc-module.c
AM_CPPFLAGS += -DG_LOG_DOMAIN=\"gnc.module\"

View File

@@ -0,0 +1,6 @@
This is gnc-module, a plugin/module system for gnucash and related
software. The documentation currently consists of 'doc/design.txt'.
Bill Gribble

View File

@@ -0,0 +1,132 @@
What is a Gnucash module?
-------------------------
A gnucash module is a dynamically loadable libtool library that
defines the following symbols:
/* what version of the module system interface is assumed */
int gnc_module_system_interface;
/* information about the module's version */
int gnc_module_current;
int gnc_module_revision;
int gnc_module_age;
/* init is called each time a module is loaded;
* 'refcount' is 0 the first time the module is loaded. */
int gnc_module_init(int refcount);
/* end is called each time the module is unloaded, if present.
* 'refcount' is 0 the last time the module is unloaded. */
void gnc_module_end(int refcount);
/* descriptive information */
char * gnc_module_path(void);
char * gnc_module_description(void);
gnc_module_system_interface is the revision number of the interface
listed above (i.e. the names and type signatures of the symbols each
module must define). The current revision number is 0; all modules
should assign gnc_module_system_interface = 0. As the interface
evolves, this should allow us to continue to load older modules.
The current, revision, age triplet describe the module version
according to libtool(1) conventions. To quote from the libtool info
pages:
1. Start with version information of `0:0:0' for each libtool library.
2. Update the version information only immediately before a public
release of your software. More frequent updates are unnecessary,
and only guarantee that the current interface number gets larger
faster.
3. If the library source code has changed at all since the last
update, then increment REVISION (`C:R:A' becomes `C:r+1:A').
4. If any interfaces have been added, removed, or changed since the
last update, increment CURRENT, and set REVISION to 0.
5. If any interfaces have been added since the last public release,
then increment AGE.
6. If any interfaces have been removed since the last public release,
then set AGE to 0.
gnc_module_path should return a newly-allocated string containing the
"module path". The module path is a logical path with elements
separated by /. The path will be used to structure views of available
modules so that similar modules can be grouped together; it may or may
not actually correspond to a filesystem path. The last element of the
module path is the name of this module. For example,
char * path = "gnucash/core/engine";
defines the "engine" module, which is in the gnucash/core group of
modules.
gnc_module_description should return a newly-allocated 1-line
description of what the module does. This can be displayed by GUI
elements to allow users to select modules to load.
Initializing the module system
------------------------------
Somewhere at program startup time, you need to call
gnc_module_system_init from C (see below from Scheme). This scans the
directories in the GNC_MODULE_PATH and builds a database of the
available modules.
In Scheme, you need to (use-modules (gnucash gnc-module)) and call
(gnc:module-system-init) if it was not called from C. You will need
to use-modules this module is you intend to use any module system
functions from Scheme.
On the Scheme side, gnc:module-system-init is not a g-wrapped
function. It uses Guile's dynamic-link to open the libgncmodule.la
library directly and call gnc_module_system_init. dynamic-link uses
lt_dlopen() under the hood, so you need to make sure that the
libgncmodule.la install directory is in your LD_LIBRARY_PATH or
LTDL_LIBRARY_PATH. The Gnucash app will set up this path by default.
You can rebuild the module database at any time (say, if you know a
new module has been installed or the user has changed the module path
via some in-program mechanism) by calling gnc_module_system_refresh.
Loading modules
---------------
From C call gnc_module_load(path, interface), or gnc:module-load from
Scheme. This returns a GNCModule (<gnc:module>) if a qualifying
module was successfully loaded, #f / FALSE otherside. GNCModule is an
opaque type.
A qualifying module is any module whose gnc_module_path matches the
path specification and for whom "interface" falls between
gnc_module_current and (gnc_module_current - gnc_module_age). If
multiple modules qualify, libtool's rules are used to determine which
to load: the larger of gnc_module_interface, gnc_module_age, and
gnc_module_revision take precedence, in that order.
Module initialization/cleanup
-----------------------------
Each time a module is loaded, its gnc_module_init function is called
with an integer argument, 'refcount'. The refcount is the number of
times that gnc_module_load has been called on that particular module.
It is 0 the first time gnc_module_load is called on a module.
Any startup/initialization code should be defined in this function.
If this module depends on other modules, put the necessary
gnc_module_load calls in the init function.
If gnc_module_init returns FALSE, the module is immediately unloaded.
Any cleanup must be done within gnc_module_init before returning.
Each time a module is unloaded via gnc_module_unload, its
gnc_module_end function is called with an integer refcount argument.
refcount is 0 if this 'unload' drops the last reference. In this
case, after the gnc_module_end handler is called the library is
dlclose()-ed.

View File

@@ -0,0 +1,33 @@
/********************************************************************\
* gnc-module-api.h -- public functions needed by gnucash modules *
* Copyright (C) 2001 Linux Developers Group, Inc. *
* *
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef GNC_MODULE_API_H
#define GNC_MODULE_API_H
#define GNC_MODULE_API_DECL(gmf) \
char * gmf##_gnc_module_path (void); \
char * gmf##_gnc_module_description (void); \
int gmf##_gnc_module_init (int refcount); \
int gmf##_gnc_module_end (int refcount);
#endif

View File

@@ -0,0 +1,615 @@
/*************************************************************
* gnc-module.c -- loadable plugin/module system for gnucash
* Copyright 2001 Linux Developers Group, Inc.
*************************************************************/
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmodule.h>
#include <sys/types.h>
#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
#include "gnc-module.h"
static GHashTable * loaded_modules = NULL;
static GList * module_info = NULL;
typedef struct
{
char * module_path;
char * module_description;
char * module_filepath;
int module_interface;
int module_age;
int module_revision;
} GNCModuleInfo;
typedef struct
{
GModule * gmodule;
gchar * filename;
int load_count;
GNCModuleInfo * info;
int (* init_func)(int refcount);
} GNCLoadedModule;
static GNCModuleInfo * gnc_module_get_info(const char * lib_path);
/*************************************************************
* gnc_module_system_search_dirs
* return a list of dirs to look in for gnc_module libraries
*************************************************************/
static GList *
gnc_module_system_search_dirs(void)
{
const char *spath = g_getenv("GNC_MODULE_PATH");
GList * list = NULL;
GString * token = g_string_new(NULL);
int escchar = 0;
const char *cpos;
if (!spath)
{
spath = DEFAULT_MODULE_PATH;
}
for (cpos = spath; *cpos; cpos++)
{
switch (*cpos)
{
#ifndef G_OS_WIN32
/* On windows, with '\' as the directory separator character,
this additional de-quoting will make every path processing
fail miserably. Anyway this should probably be thrown out
altogether, because this additional level of de-quoting
(after shell quoting) is completely unexpected and
uncommon. */
case '\\':
if (!escchar)
{
escchar = TRUE;
}
else
{
g_string_append_c(token, *cpos);
escchar = FALSE;
}
break;
#endif
/* This is ':' on UNIX machines and ';' under Windows. */
case G_SEARCHPATH_SEPARATOR:
if (!escchar)
{
list = g_list_append(list, token->str);
g_string_free(token, FALSE);
token = g_string_new(NULL);
}
else
{
g_string_append_c(token, *cpos);
escchar = FALSE;
}
break;
default:
g_string_append_c(token, *cpos);
escchar = FALSE;
break;
}
}
if (token->len)
{
list = g_list_append(list, token->str);
g_string_free(token, FALSE);
}
else
{
g_string_free(token, TRUE);
}
return list;
}
/*************************************************************
* gnc_module_system_init
* initialize the module system
*************************************************************/
void
gnc_module_system_init(void)
{
if (loaded_modules)
return;
loaded_modules = g_hash_table_new(g_direct_hash, g_direct_equal);
/* now crawl the GNC_MODULE_PATH to find likely libraries */
gnc_module_system_refresh();
}
/*************************************************************
* gnc_module_system_refresh
* build the database of modules by looking through the
* GNC_MODULE_PATH
*************************************************************/
void
gnc_module_system_refresh(void)
{
GList * search_dirs;
GList * current;
if (!loaded_modules)
{
gnc_module_system_init();
}
/* get the GNC_MODULE_PATH and split it into directories */
search_dirs = gnc_module_system_search_dirs();
/* look in each search directory */
for (current = search_dirs; current; current = current->next)
{
GDir *d = g_dir_open(current->data, 0, NULL);
const gchar *dent = NULL;
char * fullpath = NULL;
GNCModuleInfo * info;
if (!d) continue;
while ((dent = g_dir_read_name(d)) != NULL)
{
/* is the file a loadable module? */
/* Gotcha: On MacOS, G_MODULE_SUFFIX is defined as "so",
* but if we do not build clean libtool modules with
* "-module", we get dynamic libraries ending on .dylib On
* Windows, all modules will move to bin/, so they will be
* mixed with other libraries, such as gtk+. Adding a
* prefix "libgncmod" filter will prevent the module loader
* from loading other libraries. The filter should work on
* other platforms.
*/
if ((g_str_has_suffix(dent, "." G_MODULE_SUFFIX)
|| g_str_has_suffix(dent, ".dylib"))
&& g_str_has_prefix(dent, GNC_MODULE_PREFIX))
{
/* get the full path name, then dlopen the library and see
* if it has the appropriate symbols to be a gnc_module */
fullpath = g_build_filename((const gchar *)(current->data),
dent, (char*)NULL);
info = gnc_module_get_info(fullpath);
if (info)
{
module_info = g_list_prepend(module_info, info);
}
g_free(fullpath);
}
}
g_dir_close(d);
}
/* free the search dir strings */
for (current = search_dirs; current; current = current->next)
{
g_free(current->data);
}
g_list_free(current);
}
/*************************************************************
* gnc_module_system_modinfo
* return the list of module information
*************************************************************/
GList *
gnc_module_system_modinfo(void)
{
if (!loaded_modules)
{
gnc_module_system_init();
}
return module_info;
}
/*
* gnc_module_get_symbol
* gets the munged symbol from the file
*/
static gboolean
gnc_module_get_symbol(GModule* gmodule, const char* symbol, gpointer res)
{
gchar** strs;
gchar* munged_symbol;
gchar *basename;
gboolean ret;
g_return_val_if_fail(gmodule, FALSE);
g_return_val_if_fail(symbol, FALSE);
/* Separate the file from its extension */
/* Note: This currently does not work with versioned libtool dlls,
* as they are named like libgncmodbaz-0.dll */
basename = g_path_get_basename(g_module_name(gmodule));
strs = g_strsplit(basename, ".", 2);
g_free(basename);
/* Translate any dashes to underscores */
g_strdelimit(strs[0], "-", '_');
/* Create the symbol <filename>_<symbol> and retrieve that symbol */
munged_symbol = g_strdup_printf("%s_%s", strs[0], symbol);
ret = g_module_symbol(gmodule, munged_symbol, res);
/* printf("(%d) Looking for symbol %s\n", ret, munged_symbol); */
/* Free everything */
g_strfreev(strs);
g_free(munged_symbol);
return ret;
}
/*************************************************************
* gnc_module_get_info
* check a proposed gnc_module by looking for specific symbols in it;
* if it's a gnc_module, return a struct describing it.
*************************************************************/
static GNCModuleInfo *
gnc_module_get_info(const char * fullpath)
{
GModule *gmodule;
gpointer modsysver;
GNCModuleInfo *info = NULL;
gpointer initfunc, pathfunc, descripfunc, iface, revision, age;
gchar * (* f_path)(void);
gchar * (* f_descrip)(void);
/* g_debug("(init) dlopening '%s'\n", fullpath); */
gmodule = g_module_open(fullpath, G_MODULE_BIND_LAZY);
if (gmodule == NULL)
{
g_warning("Failed to dlopen() '%s': %s\n", fullpath, g_module_error());
return NULL;
}
/* the modsysver tells us what the expected symbols and their
* types are */
if (!gnc_module_get_symbol(gmodule, "gnc_module_system_interface", &modsysver))
{
/* g_debug("Module '%s' does not contain 'gnc_module_system_interface'\n", */
/* fullpath); */
goto get_info_close;
}
if (*(int *)modsysver != 0)
{
g_warning("Module '%s' requires newer module system\n", fullpath);
goto get_info_close;
}
if (!gnc_module_get_symbol(gmodule, "gnc_module_init", &initfunc) ||
!gnc_module_get_symbol(gmodule, "gnc_module_path", &pathfunc) ||
!gnc_module_get_symbol(gmodule, "gnc_module_description", &descripfunc) ||
!gnc_module_get_symbol(gmodule, "gnc_module_current", &iface) ||
!gnc_module_get_symbol(gmodule, "gnc_module_revision", &revision) ||
!gnc_module_get_symbol(gmodule, "gnc_module_age", &age))
{
g_warning("Module '%s' does not match module signature\n", fullpath);
goto get_info_close;
}
/* we have found a gnc_module. */
info = g_new0(GNCModuleInfo, 1);
f_path = pathfunc;
f_descrip = descripfunc;
info->module_path = f_path();
info->module_description = f_descrip();
info->module_filepath = g_strdup(fullpath);
info->module_interface = *(int *)iface;
info->module_age = *(int *)age;
info->module_revision = *(int *)revision;
g_module_make_resident(gmodule);
get_info_close:
/* g_debug("(init) closing '%s'\n", fullpath); */
g_module_close(gmodule);
return info;
}
/*************************************************************
* gnc_module_locate
* find the best matching module for the name, interface pair
*************************************************************/
static GNCModuleInfo *
gnc_module_locate(const gchar * module_name, int iface)
{
GNCModuleInfo * best = NULL;
GNCModuleInfo * current = NULL;
GList * lptr;
if (!loaded_modules)
{
gnc_module_system_init();
}
for (lptr = module_info; lptr; lptr = lptr->next)
{
current = lptr->data;
if (!strcmp(module_name, current->module_path) &&
(iface >= (current->module_interface - current->module_age)) &&
(iface <= current->module_interface))
{
if (best)
{
if ((current->module_interface > best->module_interface) ||
((current->module_interface == best->module_interface) &&
(current->module_age > best->module_age)) ||
((current->module_interface == best->module_interface) &&
(current->module_age == best->module_age) &&
(current->module_revision > best->module_revision)))
{
best = current;
}
}
else
{
best = current;
}
}
}
return best;
}
static void
list_loaded (gpointer k, gpointer v, gpointer data)
{
GList ** l = data;
*l = g_list_prepend(*l, v);
}
static GNCLoadedModule *
gnc_module_check_loaded(const char * module_name, gint iface)
{
GNCModuleInfo * modinfo = gnc_module_locate(module_name, iface);
GList * modules = NULL;
GList * p = NULL;
GNCLoadedModule * rv = NULL;
if (modinfo == NULL)
{
return NULL;
}
if (!loaded_modules)
{
gnc_module_system_init();
}
/* turn the loaded-modules table into a list */
g_hash_table_foreach(loaded_modules, list_loaded, &modules);
/* walk the list to see if the file we want is already open */
for (p = modules; p; p = p->next)
{
GNCLoadedModule * lm = p->data;
if (!strcmp(lm->filename, modinfo->module_filepath))
{
rv = lm;
break;
}
}
g_list_free(modules);
return rv;
}
/*************************************************************
* gnc_module_load
* Ensure that the module named by "module_name" is loaded.
*************************************************************/
static GNCModule
gnc_module_load_common(const char * module_name, gint iface, gboolean optional)
{
GNCLoadedModule * info;
GModule * gmodule;
GNCModuleInfo * modinfo;
g_debug ("module_name: %s", module_name);
if (!loaded_modules)
{
gnc_module_system_init();
}
info = gnc_module_check_loaded(module_name, iface);
/* if the module's already loaded, just increment its use count.
* otherwise, load it and check for the initializer
* "gnc_module_init". if we find that, assume it's a gnucash module
* and run the function. */
if (info)
{
/* module already loaded ... call the init thunk */
if (info->init_func)
{
if (info->init_func(info->load_count))
{
info->load_count++;
g_debug ("module %s already loaded", module_name);
return info;
}
else
{
g_warning ("module init failed: %s", module_name);
return NULL;
}
}
else
{
g_warning ("module has no init func: %s", module_name);
return NULL;
}
/* NOTREACHED */
g_error("internal error");
return NULL;
}
modinfo = gnc_module_locate(module_name, iface);
if (!modinfo)
{
if (optional)
{
g_message ("Could not locate optional module %s interface v.%d",
module_name, iface);
}
else
{
g_warning ("Could not locate module %s interface v.%d",
module_name, iface);
}
return NULL;
}
/* if (modinfo) */
/* g_debug("(init) loading '%s' from '%s'\n", module_name, */
/* modinfo->module_filepath); */
if ((gmodule = g_module_open(modinfo->module_filepath, 0)) != NULL)
{
gpointer initfunc;
if (gnc_module_get_symbol(gmodule, "gnc_module_init", &initfunc))
{
/* stick it in the hash table */
info = g_new0(GNCLoadedModule, 1);
info->gmodule = gmodule;
info->filename = g_strdup(modinfo->module_filepath);
info->load_count = 1;
info->init_func = initfunc;
g_hash_table_insert(loaded_modules, info, info);
/* now call its init function. this should load any dependent
* modules, too. If it doesn't return TRUE unload the module. */
if (!info->init_func(0))
{
/* init failed. unload the module. */
g_warning ("Initialization failed for module %s\n", module_name);
g_hash_table_remove(loaded_modules, info);
g_free(info->filename);
g_free(info);
/* g_module_close(module); */
return NULL;
}
return info;
}
else
{
g_warning ("Module %s (%s) is not a gnc-module.\n", module_name,
modinfo->module_filepath);
//lt_dlclose(handle);
}
return info;
}
g_warning ("Failed to open module %s: %s\n", module_name, g_module_error());
return NULL;
}
GNCModule
gnc_module_load(const char * module_name, gint iface)
{
return gnc_module_load_common(module_name, iface, FALSE);
}
GNCModule
gnc_module_load_optional(const char * module_name, gint iface)
{
return gnc_module_load_common(module_name, iface, TRUE);
}
/*************************************************************
* gnc_module_unload
* unload a module (only actually unload it if the use count goes to 0)
*************************************************************/
int
gnc_module_unload(GNCModule module)
{
GNCLoadedModule * info;
if (!loaded_modules)
{
gnc_module_system_init();
}
if ((info = g_hash_table_lookup(loaded_modules, module)) != NULL)
{
gpointer unload_thunk;
int unload_val = TRUE;
info->load_count--;
if (gnc_module_get_symbol(info->gmodule, "gnc_module_end", &unload_thunk))
{
int (* thunk)(int) = unload_thunk;
unload_val = thunk(info->load_count);
}
/* actually unload the module if necessary */
if (info->load_count == 0)
{
/* now close the module and free the struct */
/* g_debug("(unload) closing %s\n", info->filename); */
/* g_module_close(info->gmodule); */
g_hash_table_remove(loaded_modules, module);
g_free(info);
}
return unload_val;
}
else
{
g_warning ("Failed to unload module %p (it is not loaded)\n", module);
return 0;
}
}

View File

@@ -0,0 +1,50 @@
/*************************************************************
* gnc-module.h -- loadable plugin/module system for gnucash
* Copyright 2001 Linux Developers Group, Inc.
*************************************************************/
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef GNC_MODULE_H
#define GNC_MODULE_H
#include <glib.h>
typedef void * GNCModule;
#define DEFAULT_MODULE_PATH "/usr/local/gnucash/lib/modules"
#define GNC_MODULE_PREFIX "libgncmod"
/* the basics: initialize the module system, refresh its module
* database, and get a list of all known modules */
void gnc_module_system_init(void);
void gnc_module_system_refresh(void);
GList * gnc_module_system_modinfo(void);
/* load and unload a module. gnc_module_system_init() must be called
* before loading and unloading.
*/
/*@ dependent @*/
GNCModule gnc_module_load(const gchar * module_name, gint iface);
GNCModule gnc_module_load_optional(const gchar * module_name, gint iface);
int gnc_module_unload(GNCModule mod);
#endif

View File

@@ -0,0 +1,39 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
%module sw_gnc_module
%{
#include <gnc-module.h>
%}
#if defined(SWIGGUILE)
%{
#include "guile-mappings.h"
SCM scm_init_sw_gnc_module_module (void);
%}
#endif
%import "base-typemaps.i"
void gnc_module_system_init(void);
void gnc_module_system_refresh(void);
GNCModule gnc_module_load(gchar * module_name, gint interface);
GNCModule gnc_module_load_optional(gchar * module_name, gint interface);
int gnc_module_unload(GNCModule mod);

View File

@@ -0,0 +1,60 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; gnc-module.scm
;;; Guile module which allows initialization of the gnucash module
;;; system from Scheme
;;;
;;; Copyright 2001 Linux Developers Group
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu@gnu.org
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (gnucash gnc-module))
;; Guile 2 needs to find the symbols from the extension at compile time already
(cond-expand
(guile-2
(eval-when
(compile load eval expand)
(load-extension "libgnc-module" "scm_init_sw_gnc_module_module")))
(else
(load-extension "libgnc-module" "scm_init_sw_gnc_module_module")))
(use-modules (sw_gnc_module))
(define gnc:module-system-init gnc-module-system-init)
(define gnc:module-system-refresh gnc-module-system-refresh)
(define gnc:module-load gnc-module-load)
(define gnc:module-load-optional gnc-module-load-optional)
(define gnc:module-unload gnc-module-unload)
(export gnc:module-system-init)
(export gnc:module-system-refresh)
(export gnc:module-load)
(export gnc:module-load-optional)
(export gnc:module-unload)
(export gnc:module-begin-syntax)
;; Guile 2 needs to load external modules at compile time
(cond-expand
(guile-2
(define-syntax-rule (gnc:module-begin-syntax form ...)
(eval-when (load compile eval expand) (begin form ...))))
(else
(define gnc:module-begin-syntax begin)))

View File

@@ -0,0 +1,114 @@
ADD_SUBDIRECTORY(mod-foo)
ADD_SUBDIRECTORY(mod-bar)
ADD_SUBDIRECTORY(mod-baz)
ADD_SUBDIRECTORY(misc-mods)
SET(GNC_MODULE_TEST_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/common # for config.h
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module
${CMAKE_SOURCE_DIR}/common/test-core
${GLIB2_INCLUDE_DIRS}
${GUILE_INCLUDE_DIRS}
)
SET(GNC_MODULE_TEST_LIBS gnc-module test-core)
MACRO(ADD_GNC_MODULE_TEST _TARGET _SOURCE_FILES)
GNC_ADD_TEST(${_TARGET} "${_SOURCE_FILES}" GNC_MODULE_TEST_INCLUDE_DIRS GNC_MODULE_TEST_LIBS)
ENDMACRO()
FUNCTION(RUN_TEST_WITH_GUILE _TARGET _SOURCE_FILE)
GET_GUILE_ENV()
SET(CMAKE_COMMAND_TMP "")
IF (${CMAKE_VERSION} VERSION_GREATER 3.1)
SET(CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env "${GUILE_ENV}")
ENDIF()
ADD_TEST(NAME ${_TARGET}
COMMAND ${CMAKE_COMMAND_TMP}
${GUILE_EXECUTABLE} -s ${_SOURCE_FILE}
)
SET_TESTS_PROPERTIES(${_TARGET} PROPERTIES ENVIRONMENT "${GUILE_ENV};${ARGN}")
ENDFUNCTION()
GNC_ADD_TEST_WITH_GUILE(test-load-c test-load-c.c GNC_MODULE_TEST_INCLUDE_DIRS GNC_MODULE_TEST_LIBS)
RUN_TEST_WITH_GUILE(test-load-scm ${CMAKE_CURRENT_SOURCE_DIR}/test-load-scm.in)
RUN_TEST_WITH_GUILE(test-load-deps ${CMAKE_CURRENT_SOURCE_DIR}/test-load-deps.in)
RUN_TEST_WITH_GUILE(test-scm-init ${CMAKE_CURRENT_SOURCE_DIR}/test-scm-init.in)
RUN_TEST_WITH_GUILE(test-scm-multi ${CMAKE_CURRENT_SOURCE_DIR}/test-scm-multi.in)
RUN_TEST_WITH_GUILE(test-scm-dynload ${CMAKE_CURRENT_SOURCE_DIR}/test-scm-dynload.in)
GNC_ADD_TEST_WITH_GUILE(test-modsysver test-modsysver.c
GNC_MODULE_TEST_INCLUDE_DIRS GNC_MODULE_TEST_LIBS
)
GNC_ADD_TEST_WITH_GUILE(test-incompatdep test-incompatdep.c
GNC_MODULE_TEST_INCLUDE_DIRS GNC_MODULE_TEST_LIBS
)
GNC_ADD_TEST_WITH_GUILE(test-agedver test-agedver.c
GNC_MODULE_TEST_INCLUDE_DIRS GNC_MODULE_TEST_LIBS
)
SET(_LIBDIR ${CMAKE_BINARY_DIR}/lib)
IF (WIN32)
SET(_LIBDIR ${CMAKE_BINARY_DIR}/bin)
ENDIF()
GNC_ADD_TEST(test-dynload test-dynload.c
GNC_MODULE_TEST_INCLUDE_DIRS GNC_MODULE_TEST_LIBS
LIBDIR=${_LIBDIR}
)
SET(GUILE ${GUILE_EXECUTABLE})
CONFIGURE_FILE(test-gwrapped-c.in test-gwrapped-c @ONLY)
CONFIGURE_FILE(test-scm-module.in test-scm-module @ONLY)
CONFIGURE_FILE(test-load-deps.in test-load-deps @ONLY)
CONFIGURE_FILE(test-load-scm.in test-load-scm @ONLY)
CONFIGURE_FILE(test-scm-dynload.in test-scm-dynload @ONLY)
CONFIGURE_FILE(test-scm-init.in test-scm-init @ONLY)
CONFIGURE_FILE(test-scm-multi.in test-scm-multi @ONLY)
FUNCTION(RUN_GUILE_SHELL_TEST _TARGET _SOURCE_FILE)
GET_GUILE_ENV()
SET(CMAKE_COMMAND_TMP "")
IF (${CMAKE_VERSION} VERSION_GREATER 3.1)
SET(CMAKE_COMMAND_TMP ${CMAKE_COMMAND} -E env "${GUILE_ENV}")
ENDIF()
ADD_TEST(NAME ${_TARGET}
COMMAND ${CMAKE_COMMAND_TMP}
${SHELL} ${_SOURCE_FILE}
)
SET_TESTS_PROPERTIES(${_TARGET} PROPERTIES ENVIRONMENT "${GUILE_ENV}")
ENDFUNCTION()
RUN_GUILE_SHELL_TEST(test-gwrapped-c ${CMAKE_CURRENT_BINARY_DIR}/test-gwrapped-c)
RUN_GUILE_SHELL_TEST(test-scm-module ${CMAKE_CURRENT_BINARY_DIR}/test-scm-module)
SET(test_gnc_module_SOURCE_DIST
test-agedver.c
test-dynload.c
test-incompatdep.c
test-load-c.c
test-modsysver.c
)
SET(test_gnc_module_EXTRA_DIST
README
test-gwrapped-c.in
test-load-deps.in
test-load-scm.in
test-scm-dynload.in
test-scm-init.in
test-scm-module.in
test-scm-multi.in
)
SET_LOCAL_DIST(test_gnc_module_DIST_local CMakeLists.txt Makefile.am README ${test_gnc_module_SOURCE_DIST} ${test_gnc_module_EXTRA_DIST})
SET(test_gnc_module_DIST ${test_gnc_module_DIST_local} ${misc_mods_DIST}
${mod_bar_DIST} ${mod_baz_DIST} ${mod_foo_DIST} PARENT_SCOPE)

View File

@@ -0,0 +1,72 @@
SUBDIRS = mod-foo mod-bar mod-baz misc-mods
LDADD = \
${top_builddir}/common/test-core/libtest-core.la \
../libgnc-module.la ${GLIB_LIBS} ${GUILE_LIBS}
AM_CPPFLAGS = \
-I${top_srcdir}/common \
-I${top_srcdir}/libgnucash/gnc-module \
-I${top_srcdir}/common/test-core \
-I${top_srcdir}/libgnucash/engine \
${GUILE_CFLAGS} \
${GLIB_CFLAGS}
TESTS = \
test-load-c \
test-load-scm \
test-gwrapped-c \
test-scm-module \
test-scm-multi \
test-load-deps \
test-modsysver \
test-incompatdep \
test-agedver \
test-dynload \
test-scm-dynload \
test-scm-init
GNC_TEST_DEPS = \
--gnc-module-dir ${top_builddir}/libgnucash/gnc-module \
--gnc-module-dir ${top_builddir}/libgnucash/gnc-module/test/mod-foo \
--gnc-module-dir ${top_builddir}/libgnucash/gnc-module/test/mod-bar \
--gnc-module-dir ${top_builddir}/libgnucash/gnc-module/test/mod-baz \
--gnc-module-dir ${top_builddir}/libgnucash/gnc-module/test/misc-mods \
--guile-load-dir ${top_builddir}/common/test-core \
--guile-load-dir ${top_builddir}/libgnucash/gnc-module \
--guile-load-dir ${top_srcdir}/libgnucash/gnc-module/test/mod-foo \
--guile-load-dir ${top_srcdir}/libgnucash/gnc-module/test/mod-baz \
--guile-load-dir ${top_srcdir}/libgnucash/gnc-module/test/mod-bar \
--library-dir ${top_builddir}/libgnucash/core-utils \
--library-dir ${top_builddir}/common/test-core \
--library-dir ${top_builddir}/libgnucash/gnc-module \
--library-dir ${top_builddir}/libgnucash/gnc-module/test/mod-foo \
--library-dir ${top_builddir}/libgnucash/gnc-module/test/mod-bar \
--library-dir ${top_builddir}/libgnucash/gnc-module/test/mod-baz
TESTS_ENVIRONMENT = \
GUILE_WARN_DEPRECATED=no \
GUILE="${GUILE}" \
$(shell ${abs_top_srcdir}/common/gnc-test-env.pl --noexports ${GNC_TEST_DEPS})
check_PROGRAMS = \
test-load-c \
test-modsysver \
test-incompatdep \
test-agedver \
test-dynload
test_dynload_LDFLAGS = ${GUILE_LIBS}
EXTRA_DIST = \
test-gwrapped-c \
test-load-deps \
test-load-scm \
test-scm-dynload \
test-scm-init \
test-scm-module \
test-scm-multi \
CMakeLists.txt
foo:
${TESTS_ENVIRONMENT} strace -f -o xxx ./test-load-c

View File

@@ -0,0 +1,13 @@
gnc-module tests:
test-gwrapped-c.c: load a gnc-module from Scheme and test gwrapped fns
test-load-c.c: load a gnc-module from C
test-load-deps.{c,scm}: load a module that depends on another module
test-load-scm.scm: basic module load test from Scheme
test-scm-module.c: add a Scheme module load to the init fn and make sure
the symbols are visible
test-scm-multi.{c,scm}: load multiple gnc-modules from Scheme
gnc-module support files:
mod-{foo,bar,baz}/: sample modules for testing

View File

@@ -0,0 +1,16 @@
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module
${GLIB2_INCLUDE_DIRS}
)
ADD_LIBRARY(gncmod_agedver EXCLUDE_FROM_ALL agedver.c)
TARGET_LINK_LIBRARIES(gncmod_agedver ${GLIB2_LDFLAGS})
ADD_LIBRARY(gncmod_futuremodsys EXCLUDE_FROM_ALL futuremodsys.c)
TARGET_LINK_LIBRARIES(gncmod_futuremodsys ${GLIB2_LDFLAGS})
ADD_LIBRARY(gncmod_incompatdep EXCLUDE_FROM_ALL incompatdep.c)
TARGET_LINK_LIBRARIES(gncmod_incompatdep gnc-module ${GLIB2_LDFLAGS})
SET_DIST_LIST(misc_mods_DIST CMakeLists.txt Makefile.am agedver.c futuremodsys.c incompatdep.c)

View File

@@ -0,0 +1,30 @@
AM_CPPFLAGS = \
-I${top_srcdir}/common \
-I${top_srcdir}/libgnucash/gnc-module \
${GLIB_CFLAGS} \
${GUILE_CFLAGS}
LDADD = -L../.. -L../../.libs
PWD := $(shell pwd)
check_LTLIBRARIES=libgncmod_futuremodsys.la libgncmod_incompatdep.la libgncmod_agedver.la
libgncmod_futuremodsys_la_SOURCES=futuremodsys.c
libgncmod_futuremodsys_la_LDFLAGS=-rpath ${PWD} -avoid-version -module
libgncmod_futuremodsys_la_LIBADD = \
$(GLIB_LIBS)
libgncmod_incompatdep_la_SOURCES=incompatdep.c
libgncmod_incompatdep_la_LDFLAGS=--rpath ${PWD} -avoid-version -module
libgncmod_incompatdep_la_LIBADD = \
../../libgnc-module.la \
$(GLIB_LIBS)
libgncmod_agedver_la_SOURCES=agedver.c
libgncmod_agedver_la_LDFLAGS=-rpath ${PWD} -avoid-version -module
libgncmod_agedver_la_LIBADD = \
$(GLIB_LIBS)
CLEANFILES = *.so* *.a
EXTRA_DIST = CMakeLists.txt

View File

@@ -0,0 +1,59 @@
/* agedver.c : testing module age? */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include <gmodule.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
GNC_MODULE_API_DECL(libgncmod_agedver)
int libgncmod_agedver_gnc_module_system_interface = 0;
int libgncmod_agedver_gnc_module_current = 12;
int libgncmod_agedver_gnc_module_age = 9;
int libgncmod_agedver_gnc_module_revision = 0;
char *
libgncmod_agedver_gnc_module_path(void)
{
return g_strdup("gnucash/agedver");
}
char *
libgncmod_agedver_gnc_module_description(void)
{
return g_strdup("this is a frequently extended module");
}
int
libgncmod_agedver_gnc_module_init(int refcount)
{
return TRUE;
}
int
libgncmod_agedver_gnc_module_end(int refcount)
{
return TRUE;
}

View File

@@ -0,0 +1,55 @@
/* futuremodsys.c : a gnucash module compiled with a future version of
* the module system. gnucash should not be able to load it. but if
* it doesn't notice that, the actual interface is compatible with
* version 0 so it will load all the way before failing. */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include <gmodule.h>
#include "gnc-module-api.h"
GNC_MODULE_API_DECL(libgncmod_futuremodsys)
int libgncmod_futuremodsys_gnc_module_system_interface = 123456;
int libgncmod_futuremodsys_gnc_module_current = 0;
int libgncmod_futuremodsys_gnc_module_age = 0;
int libgncmod_futuremodsys_gnc_module_revision = 0;
char *
libgncmod_futuremodsys_gnc_module_path(void)
{
return g_strdup("gnucash/futuremodsys");
}
char *
libgncmod_futuremodsys_gnc_module_description(void)
{
return g_strdup("this is a broken future module");
}
int
libgncmod_futuremodsys_gnc_module_init(int refcount)
{
return TRUE;
}

View File

@@ -0,0 +1,62 @@
/* incompatdep.c : a gnucash module that depends on an incompatible
* version of another module. the initialization should fail. */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include <gmodule.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
GNC_MODULE_API_DECL(libgncmod_incompatdep)
int libgncmod_incompatdep_gnc_module_system_interface = 0;
int libgncmod_incompatdep_gnc_module_current = 0;
int libgncmod_incompatdep_gnc_module_age = 0;
int libgncmod_incompatdep_gnc_module_revision = 0;
char *
libgncmod_incompatdep_gnc_module_path(void)
{
return g_strdup("gnucash/incompatdep");
}
char *
libgncmod_incompatdep_gnc_module_description(void)
{
return g_strdup("this is a broken module");
}
int
libgncmod_incompatdep_gnc_module_init(int refcount)
{
if (gnc_module_load("gnucash/foo", 25))
{
return TRUE;
}
else
{
return FALSE;
}
}

View File

@@ -0,0 +1,24 @@
IF (BUILDING_FROM_VCS)
SET (SWIG_BAR_C ${CMAKE_CURRENT_BINARY_DIR}/swig-bar.c)
GNC_ADD_SWIG_COMMAND (swig-bar-c ${SWIG_BAR_C} ${CMAKE_CURRENT_SOURCE_DIR}/bar.i bar.h)
ELSE()
SET (SWIG_BAR_C ${CMAKE_CURRENT_SOURCE_DIR}/swig-bar.c)
ENDIF()
ADD_LIBRARY(bar EXCLUDE_FROM_ALL bar.c bar.h)
ADD_LIBRARY(gncmodbar EXCLUDE_FROM_ALL gnc-mod-bar.c)
SET_SOURCE_FILES_PROPERTIES (gnc-mod-bar.c PROPERTY OBJECT_DEPENDS ${SWIG_BAR_C})
TARGET_LINK_LIBRARIES(gncmodbar bar gnc-module)
TARGET_INCLUDE_DIRECTORIES(gncmodbar PRIVATE
${CMAKE_BINARY_DIR}/common
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module
${GLIB2_INCLUDE_DIRS}
${GUILE_INCLUDE_DIRS}
)
SET_DIST_LIST(mod_bar_DIST CMakeLists.txt Makefile.am bar.c gnucash/bar.scm bar.h bar.i gnc-mod-bar.c)

View File

@@ -0,0 +1,43 @@
AM_CPPFLAGS = \
-I${top_srcdir}/common \
-I${top_srcdir}/libgnucash/gnc-module \
${GUILE_CFLAGS} \
${GLIB_CFLAGS}
PWD := $(shell pwd)
check_LTLIBRARIES = libbar.la libgncmodbar.la
libbar_la_SOURCES = bar.c
libbar_la_LDFLAGS = -rpath ${PWD}
# Make swig-bar.c for dist. It is an automatic dependency
# of gnc-mod-bar.c
noinst_HEADERS = \
bar.h \
swig-bar.c
libgncmodbar_la_SOURCES=gnc-mod-bar.c
libgncmodbar_la_LDFLAGS=-rpath ${PWD} -avoid-version
libgncmodbar_la_LIBADD=libbar.la \
$(GUILE_LIBS) \
$(GLIB_LIBS)
if BUILDING_FROM_VCS
swig-bar.c: bar.i
$(SWIG) -guile $(SWIG_ARGS) -Linkage module -o $@ $<
if ! OS_WIN32
if ! SWIG_DIST_FAIL
if ! `grep "define scm_from_utf8_string" $@ > /dev/null 2>&1`; then \
patch $@ $(top_srcdir)/common/swig-utf8.patch; \
fi
endif
endif
endif
EXTRA_DIST = \
bar.i \
gnucash/bar.scm \
CMakeLists.txt
BUILT_SOURCES = swig-bar.c
MAINTAINERCLEANFILES = swig-bar.c

View File

@@ -0,0 +1,33 @@
/* libfoo. this is a dependency-free client library, equivalent to
* the engine or some other core component that's ignorant of guile
* and the module system */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include "bar.h"
int
bar_hello(void)
{
return 1;
}

View File

@@ -0,0 +1,28 @@
/* bar.h: header for a dependency-free, guile-free client lib */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef BAR_H
#define BAR_H
int bar_hello(void);
#endif

View File

@@ -0,0 +1,33 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
%module sw_bar
%{
#include <bar.h>
%}
#if defined(SWIGGUILE)
%{
#include "guile-mappings.h"
SCM scm_init_sw_bar_module (void);
%}
#endif
int bar_hello(void);

View File

@@ -0,0 +1,63 @@
/* gnc-mod-bar.c : the Gnucash plugin that wraps the library
* 'libbar.so'. it does this by being linked against libbar.so */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <gmodule.h>
#include <libguile.h>
#include "gnc-module-api.h"
#include "swig-bar.c"
GNC_MODULE_API_DECL(libgncmodbar)
int libgncmodbar_gnc_module_system_interface = 0;
int libgncmodbar_gnc_module_current = 0;
int libgncmodbar_gnc_module_age = 0;
int libgncmodbar_gnc_module_revision = 0;
char *
libgncmodbar_gnc_module_path(void)
{
return g_strdup("gnucash/bar");
}
char *
libgncmodbar_gnc_module_description(void)
{
return g_strdup("this is a bar module");
}
int
libgncmodbar_gnc_module_init(int refcount)
{
/* publish the wrapped Scheme bindings for libbar */
scm_init_sw_bar_module();
scm_c_eval_string("(use-modules (sw_bar))");
/* use the Scheme "bar" module */
scm_c_eval_string("(use-modules (gnucash bar))");
return TRUE;
}

View File

@@ -0,0 +1,31 @@
;; test of a Scheme module called gnc-mod-bar, which should get
;; loaded by the Gnucash module "bar"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu@gnu.org
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (gnucash bar))
(export bar:scheme-hello)
(define (bar:scheme-hello)
#t)

View File

@@ -0,0 +1,30 @@
IF (BUILDING_FROM_VCS)
SET (SWIG_BAZ_C ${CMAKE_CURRENT_BINARY_DIR}/swig-baz.c)
GNC_ADD_SWIG_COMMAND (swig-baz-c ${SWIG_BAZ_C} ${CMAKE_CURRENT_SOURCE_DIR}/baz.i baz.h)
ELSE()
SET (SWIG_BAZ_C ${CMAKE_CURRENT_SOURCE_DIR}/swig-baz.c)
ENDIF()
ADD_LIBRARY(baz EXCLUDE_FROM_ALL baz.c baz.h)
TARGET_INCLUDE_DIRECTORIES(baz PRIVATE
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module/test/mod-foo
)
TARGET_LINK_LIBRARIES(baz foo)
ADD_LIBRARY(gncmodbaz EXCLUDE_FROM_ALL gnc-mod-baz.c)
SET_SOURCE_FILES_PROPERTIES (gnc-mod-baz.c PROPERTY OBJECT_DEPENDS ${SWIG_BAZ_C})
TARGET_LINK_LIBRARIES(gncmodbaz baz gnc-module)
TARGET_INCLUDE_DIRECTORIES(gncmodbaz PRIVATE
${CMAKE_BINARY_DIR}/common
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module
${GLIB2_INCLUDE_DIRS}
${GUILE_INCLUDE_DIRS}
)
SET_DIST_LIST(mod_baz_DIST CMakeLists.txt Makefile.am baz.c gnucash/baz.scm baz.h baz.i gnc-mod-baz.c)

View File

@@ -0,0 +1,47 @@
AM_CPPFLAGS = \
-I${top_srcdir}/common \
-I${top_srcdir}/libgnucash/gnc-module \
-I${top_srcdir}/libgnucash/gnc-module/test/mod-foo \
${GLIB_CFLAGS} \
${GUILE_CFLAGS}
PWD := $(shell pwd)
check_LTLIBRARIES = libbaz.la libgncmodbaz.la
libbaz_la_SOURCES = baz.c
libbaz_la_LDFLAGS = -rpath ${PWD}
libbaz_la_LIBADD = ../mod-foo/libfoo.la
# Make swig-baz.c for dist. It is an automatic dependency
# of gnc-mod-baz.c
noinst_HEADERS = \
baz.h \
swig-baz.c
libgncmodbaz_la_SOURCES = gnc-mod-baz.c
libgncmodbaz_la_LDFLAGS = -rpath ${PWD} -avoid-version
libgncmodbaz_la_LIBADD = \
libbaz.la \
../../libgnc-module.la \
$(GUILE_LIBS) \
$(GLIB_LIBS)
if BUILDING_FROM_VCS
swig-baz.c: baz.i
$(SWIG) -guile $(SWIG_ARGS) -Linkage module -o $@ $<
if ! OS_WIN32
if ! SWIG_DIST_FAIL
if ! `grep "define scm_from_utf8_string" $@ > /dev/null 2>&1`; then \
patch $@ $(top_srcdir)/common/swig-utf8.patch; \
fi
endif
endif
endif
EXTRA_DIST = \
baz.i \
gnucash/baz.scm \
CMakeLists.txt
BUILT_SOURCES = swig-baz.c
MAINTAINERCLEANFILES = swig-baz.c

View File

@@ -0,0 +1,34 @@
/* libbaz. this library depends on foo */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include "baz.h"
#include "foo.h"
int
baz_hello(void)
{
foo_hello();
return 1;
}

View File

@@ -0,0 +1,28 @@
/* baz.h: header for a dependency-free, guile-free client lib */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef BAZ_H
#define BAZ_H
int baz_hello(void);
#endif

View File

@@ -0,0 +1,33 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
%module sw_baz
%{
#include <baz.h>
%}
#if defined(SWIGGUILE)
%{
#include "guile-mappings.h"
SCM scm_init_sw_baz_module (void);
%}
#endif
int baz_hello(void);

View File

@@ -0,0 +1,72 @@
/* gnc-mod-baz.c : the Gnucash plugin that wraps the library
* 'libbaz.so'. it does this by being linked against libbaz.so */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <gmodule.h>
#include <libguile.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
#include "swig-baz.c"
GNC_MODULE_API_DECL(libgncmodbaz)
int libgncmodbaz_gnc_module_system_interface = 0;
int libgncmodbaz_gnc_module_current = 0;
int libgncmodbaz_gnc_module_age = 0;
int libgncmodbaz_gnc_module_revision = 0;
char *
libgncmodbaz_gnc_module_path(void)
{
return g_strdup("gnucash/baz");
}
char *
libgncmodbaz_gnc_module_description(void)
{
return g_strdup("this is the baz module");
}
int
libgncmodbaz_gnc_module_init(int refcount)
{
/* load libfoo */
if (gnc_module_load("gnucash/foo", 0))
{
/* publish the wrapped Scheme bindings for libbaz */
scm_init_sw_baz_module();
scm_c_eval_string("(use-modules (sw_baz))");
/* use the Scheme "baz" module */
scm_c_eval_string("(use-modules (gnucash baz))");
return TRUE;
}
else
{
return FALSE;
}
}

View File

@@ -0,0 +1,31 @@
;; test of a Scheme module called gnc-mod-baz, which should get
;; loaded by the Gnucash module "baz"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu@gnu.org
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (gnucash baz))
(export baz:scheme-hello)
(define (baz:scheme-hello)
#t)

View File

@@ -0,0 +1,24 @@
IF (BUILDING_FROM_VCS)
SET (SWIG_FOO_C ${CMAKE_CURRENT_BINARY_DIR}/swig-foo.c)
GNC_ADD_SWIG_COMMAND (swig-foo-c ${SWIG_FOO_C} ${CMAKE_CURRENT_SOURCE_DIR}/foo.i foo.h)
ELSE()
SET (SWIG_FOO_C ${CMAKE_CURRENT_SOURCE_DIR}/swig-foo.c)
ENDIF()
ADD_LIBRARY(foo EXCLUDE_FROM_ALL foo.c foo.h)
ADD_LIBRARY(gncmodfoo EXCLUDE_FROM_ALL gnc-mod-foo.c)
SET_SOURCE_FILES_PROPERTIES (gnc-mod-foo.c PROPERTY OBJECT_DEPENDS ${SWIG_FOO_C})
TARGET_LINK_LIBRARIES(gncmodfoo foo gnc-module)
TARGET_INCLUDE_DIRECTORIES(gncmodfoo PRIVATE
${CMAKE_BINARY_DIR}/common
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module
${GLIB2_INCLUDE_DIRS}
${GUILE_INCLUDE_DIRS}
)
SET_DIST_LIST(mod_foo_DIST CMakeLists.txt Makefile.am foo.i gnucash/foo.scm foo.c foo.h gnc-mod-foo.c)

View File

@@ -0,0 +1,44 @@
AM_CPPFLAGS=\
-I${top_srcdir}/common \
-I${top_srcdir}/libgnucash/gnc-module \
${GUILE_CFLAGS} \
${GLIB_CFLAGS}
PWD := $(shell pwd)
check_LTLIBRARIES=libfoo.la libgncmodfoo.la
libfoo_la_SOURCES = foo.c
libfoo_la_LDFLAGS = -rpath ${PWD}
# Make swig-foo.c for dist. It is an automatic dependency
# of gnc-mod-foo.c
noinst_HEADERS = \
foo.h \
swig-foo.c
libgncmodfoo_la_SOURCES = gnc-mod-foo.c
libgncmodfoo_la_LDFLAGS = -rpath ${PWD} -avoid-version
libgncmodfoo_la_LIBADD = \
libfoo.la \
$(GUILE_LIBS) \
$(GLIB_LIBS)
EXTRA_DIST = \
foo.i \
gnucash/foo.scm \
CMakeLists.txt
if BUILDING_FROM_VCS
swig-foo.c: foo.i
$(SWIG) -guile $(SWIG_ARGS) -Linkage module -o $@ $<
if ! OS_WIN32
if ! SWIG_DIST_FAIL
if ! `grep "define scm_from_utf8_string" $@ > /dev/null 2>&1`; then \
patch $@ $(top_srcdir)/common/swig-utf8.patch; \
fi
endif
endif
endif
BUILT_SOURCES = swig-foo.c
MAINTAINERCLEANFILES = swig-foo.c

View File

@@ -0,0 +1,33 @@
/* libfoo. this is a dependency-free client library, equivalent to
* the engine or some other core component that's ignorant of guile
* and the module system */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include "foo.h"
int
foo_hello(void)
{
return 10;
}

View File

@@ -0,0 +1,28 @@
/* foo.h: header for a dependency-free, guile-free client lib */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef FOO_H
#define FOO_H
int foo_hello(void);
#endif

View File

@@ -0,0 +1,33 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
%module sw_foo
%{
#include <foo.h>
%}
#if defined(SWIGGUILE)
%{
#include "guile-mappings.h"
SCM scm_init_sw_foo_module (void);
%}
#endif
int foo_hello(void);

View File

@@ -0,0 +1,63 @@
/* gnc-mod-foo.c : the Gnucash plugin that wraps the library
* 'libfoo.so'. it does this by being linked against libfoo.so */
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <gmodule.h>
#include <libguile.h>
#include "gnc-module-api.h"
#include "swig-foo.c"
GNC_MODULE_API_DECL(libgncmodfoo)
int libgncmodfoo_gnc_module_system_interface = 0;
int libgncmodfoo_gnc_module_current = 0;
int libgncmodfoo_gnc_module_age = 0;
int libgncmodfoo_gnc_module_revision = 0;
char *
libgncmodfoo_gnc_module_path(void)
{
return g_strdup("gnucash/foo");
}
char *
libgncmodfoo_gnc_module_description(void)
{
return g_strdup("this is a foo module");
}
int
libgncmodfoo_gnc_module_init(int refcount)
{
/* publish the wrapped Scheme bindings for libfoo */
scm_init_sw_foo_module();
scm_c_eval_string("(use-modules (sw_foo))");
/* use the Scheme "foo" module */
scm_c_eval_string("(use-modules (gnucash foo))");
return TRUE;
}

View File

@@ -0,0 +1,31 @@
;; test of a Scheme module called gnc-mod-foo, which should get
;; loaded by the Gnucash module "foo"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu@gnu.org
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (gnucash foo))
(export foo:scheme-hello)
(define (foo:scheme-hello)
#t)

View File

@@ -0,0 +1,62 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <libguile.h>
#include "gnc-module.h"
#include <unittest-support.h>
static void
guile_main(void *closure, int argc, char ** argv)
{
GNCModule foo;
gchar *msg = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
gchar *logdomain = "gnc.module";
guint loglevel = G_LOG_LEVEL_WARNING;
TestErrorStruct check = { loglevel, logdomain, msg };
g_log_set_handler (logdomain, loglevel,
(GLogFunc)test_checked_handler, &check);
g_test_message(" test-agedver.c: asking for an old but supported interface ...");
gnc_module_system_init();
foo = gnc_module_load("gnucash/agedver", 5);
if (foo)
{
printf(" ok\n");
exit(0);
}
else
{
printf(" failed\n");
exit(-1);
}
}
int
main(int argc, char ** argv)
{
scm_boot_guile(argc, argv, guile_main, NULL);
return 0;
}

View File

@@ -0,0 +1,112 @@
/*********************************************************************
* test-dynload.c
* test the ability to dlopen the gnc_module library and initialize
* it via dlsym
*********************************************************************/
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <gmodule.h>
#include <libguile.h>
#include <unittest-support.h>
#include "gnc-module.h"
static void
guile_main(void *closure, int argc, char ** argv)
{
GModule *gmodule;
gchar *msg = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
gchar *logdomain = "gnc.module";
gchar *modpath;
guint loglevel = G_LOG_LEVEL_WARNING;
const char *libdir = g_getenv("LIBDIR");
TestErrorStruct check = { loglevel, logdomain, msg };
g_log_set_handler (logdomain, loglevel,
(GLogFunc)test_checked_handler, &check);
if (libdir == NULL)
{
libdir = "../.libs";
}
g_test_message(" test-dynload.c: testing dynamic linking of libgnc-module ...");
#ifdef G_OS_WIN32
/* MinGW builds libgnc-module-0.dll */
if (libdir == NULL)
{
modpath = g_module_build_path ("../.libs", "gnc-module-0");
}
else
{
modpath = g_module_build_path (libdir, "gnc-module");
}
#elif defined(GNC_PLATFORM_OSX)
/* We build libgnc-module as a shared library for testing, and on OSX
* that means that g_module_build_path (), which uses ".so", doesn't
* build the right path name.
*/
if (libdir == NULL)
{
modpath = g_build_filename ("..", ".libs", "libgnc-module.dylib", NULL);
}
else
{
modpath = g_build_filename (libdir, "libgnc-module.dylib", NULL);
}
#else /* Regular Unix */
modpath = g_module_build_path (libdir, "gnc-module");
#endif
gmodule = g_module_open(modpath, 0);
if (gmodule)
{
gpointer ptr;
if (g_module_symbol(gmodule, "gnc_module_system_init", &ptr))
{
void (* fn)(void) = ptr;
fn();
printf(" OK\n");
exit(0);
}
else
{
printf(" failed to find gnc_module_system_init\n");
exit(-1);
}
}
else
{
printf(" failed to open library.\n");
printf("%s\n", g_module_error());
exit(-1);
}
}
int
main(int argc, char ** argv)
{
scm_boot_guile(argc, argv, guile_main, NULL);
return 0;
}

View File

@@ -0,0 +1,15 @@
#! @SHELL@
${GUILE} -c "(use-modules (gnucash unittest-support))
(define log-domain \"gnc.module\")
(define check (new-TestErrorStruct))
(define log-level (G-LOG-LEVEL-WARNING))
(define msg \"Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n\")
(TestErrorStruct-log-domain-set check log-domain)
(TestErrorStruct-log-level-set check log-level)
(TestErrorStruct-msg-set check msg)
(define handler (test-set-checked-handler log-domain log-level check))
(use-modules (gnucash gnc-module))
(gnc:module-system-init)
(gnc:module-load \"gnucash/foo\" 0)
(exit (eq? 10 (foo-hello)))
(g-log-remove-handler log-domain handler)"

View File

@@ -0,0 +1,67 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <libguile.h>
#include <unittest-support.h>
#include "gnc-module.h"
static void
guile_main(void *closure, int argc, char ** argv)
{
GNCModule foo;
gchar *msg1 = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
gchar *msg2 = "Could not locate module gnucash/incompatdep interface v.0";
gchar *logdomain = "gnc.module";
guint loglevel = G_LOG_LEVEL_WARNING;
TestErrorStruct check1 = { loglevel, logdomain, msg1 };
TestErrorStruct check2 = { loglevel, logdomain, msg2 };
test_add_error (&check1);
test_add_error (&check2);
g_log_set_handler (logdomain, loglevel,
(GLogFunc)test_list_handler, NULL);
g_test_message(" test-incompatdep.c: loading a module with bad deps ...\n");
gnc_module_system_init();
foo = gnc_module_load("gnucash/incompatdep", 0);
if (!foo)
{
printf(" ok\n");
exit(0);
}
else
{
printf(" oops! loaded incompatible module\n");
exit(-1);
}
}
int
main(int argc, char ** argv)
{
scm_boot_guile(argc, argv, guile_main, NULL);
return 0;
}

View File

@@ -0,0 +1,67 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <libguile.h>
#include <unittest-support.h>
#include "gnc-module.h"
static void
guile_main(void *closure, int argc, char ** argv)
{
GNCModule foo;
gchar *msg = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
gchar *logdomain = "gnc.module";
guint loglevel = G_LOG_LEVEL_WARNING;
TestErrorStruct check = { loglevel, logdomain, msg };
g_log_set_handler (logdomain, loglevel,
(GLogFunc)test_checked_handler, &check);
g_test_message(" test-load-c.c: testing module load/unload from C ... ");
gnc_module_system_init();
foo = gnc_module_load("gnucash/foo", 0);
if (!foo)
{
g_test_message(" Failed to load foo\n");
exit(-1);
}
if (!gnc_module_unload(foo))
{
g_test_message(" Failed to unload foo\n");
exit(-1);
}
g_test_message(" successful.\n");
exit(0);
}
int
main(int argc, char ** argv)
{
scm_boot_guile(argc, argv, guile_main, NULL);
return 0;
}

View File

@@ -0,0 +1,31 @@
#! @SHELL@
exec ${GUILE} -s $0 "$@"
!#
;; test-load-deps.scm : load gnc-mod-baz, which depends on gnc-mod-foo
(use-modules (gnucash unittest-support))
(define log-domain "gnc.module")
(define check (new-TestErrorStruct))
(define log-level (G-LOG-LEVEL-WARNING))
(define msg "Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n")
(TestErrorStruct-log-domain-set check log-domain)
(TestErrorStruct-log-level-set check log-level)
(TestErrorStruct-msg-set check msg)
(define handler (test-set-checked-handler log-domain log-level check))
(use-modules (gnucash gnc-module))
(gnc:module-system-init)
(gnc:module-load "gnucash/baz" 0)
(baz-hello)
(foo-hello)
(baz:scheme-hello)
(foo:scheme-hello)
(g-log-remove-handler log-domain handler)
(exit 0)
;; Local Variables:
;; mode: scheme
;; End:

View File

@@ -0,0 +1,20 @@
#! @SHELL@
exec ${GUILE} -s $0 "$@"
!#
(use-modules (gnucash unittest-support))
(define log-domain "gnc.module")
(define check (new-TestErrorStruct))
(define log-level (G-LOG-LEVEL-WARNING))
(define msg "Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n")
(TestErrorStruct-log-domain-set check log-domain)
(TestErrorStruct-log-level-set check log-level)
(TestErrorStruct-msg-set check msg)
(define handler (test-set-checked-handler log-domain log-level check))
(use-modules (gnucash gnc-module))
(gnc:module-system-init)
(gnc:module-load "gnucash/foo" 0)
(g-log-remove-handler log-domain handler)
;; Local Variables:
;; mode: scheme
;; End:

View File

@@ -0,0 +1,68 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <libguile.h>
#include <unittest-support.h>
#include "gnc-module.h"
static void
guile_main(void *closure, int argc, char ** argv)
{
GNCModule foo;
gchar *msg1 = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
gchar *msg2 = "Could not locate module gnucash/futuremodsys interface v.0";
gchar *logdomain = "gnc.module";
guint loglevel = G_LOG_LEVEL_WARNING;
TestErrorStruct check1 = { loglevel, logdomain, msg1 };
TestErrorStruct check2 = { loglevel, logdomain, msg2 };
test_add_error (&check1);
test_add_error (&check2);
g_log_set_handler (logdomain, loglevel,
(GLogFunc)test_list_handler, NULL);
g_test_message(" test-modsysver.c: checking for a module we shouldn't find ...\n");
gnc_module_system_init();
foo = gnc_module_load("gnucash/futuremodsys", 0);
if (!foo)
{
printf(" ok\n");
exit(0);
}
else
{
printf(" oops! loaded incompatible module\n");
exit(-1);
}
test_clear_error_list ();
}
int
main(int argc, char ** argv)
{
scm_boot_guile(argc, argv, guile_main, NULL);
return 0;
}

View File

@@ -0,0 +1,15 @@
#! @SHELL@
echo " test-scm-dynload: testing dynamic-link of libgnc-module from Scheme.";
exec ${GUILE} -s $0 "$@"
!#
(if (or (string=? (version) "1.3")
(string=? (version) "1.3.4"))
(dynamic-link "libgnc-module.so")
(dynamic-link "libgnc-module"))
;; LocalVariables:
;; mode: scheme
;; End:

View File

@@ -0,0 +1,23 @@
#! @SHELL@
echo " test-scm-init: testing Scheme-only module system init. ";
exec ${GUILE} -s $0 "$@"
!#
(use-modules (gnucash unittest-support))
(define log-domain "gnc.module")
(define check (new-TestErrorStruct))
(define log-level (G-LOG-LEVEL-WARNING))
(define msg "Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n")
(TestErrorStruct-log-domain-set check log-domain)
(TestErrorStruct-log-level-set check log-level)
(TestErrorStruct-msg-set check msg)
(define handler (test-set-checked-handler log-domain log-level check))
(use-modules (gnucash gnc-module))
(gnc:module-system-init)
(g-log-remove-handler log-domain handler)
;; LocalVariables:
;; mode: scheme
;; End:

View File

@@ -0,0 +1,15 @@
#! @SHELL@
${GUILE} -c "(use-modules (gnucash unittest-support))
(define log-domain \"gnc.module\")
(define check (new-TestErrorStruct))
(define log-level (G-LOG-LEVEL-WARNING))
(define msg \"Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n\")
(TestErrorStruct-log-domain-set check log-domain)
(TestErrorStruct-log-level-set check log-level)
(TestErrorStruct-msg-set check msg)
(define handler (test-set-checked-handler log-domain log-level check))
(use-modules (gnucash gnc-module))
(gnc:module-system-init)
(if (not (gnc:module-load \"gnucash/foo\" 0)) (exit -1))
(exit (foo:scheme-hello))
(g-log-remove-handler log-domain handler)"

View File

@@ -0,0 +1,29 @@
#! @SHELL@
exec ${GUILE} -s $0 "$@"
!#
(use-modules (gnucash unittest-support))
(define log-domain "gnc.module")
(define check (new-TestErrorStruct))
(define log-level (G-LOG-LEVEL-WARNING))
(define msg "Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n")
(TestErrorStruct-log-domain-set check log-domain)
(TestErrorStruct-log-level-set check log-level)
(TestErrorStruct-msg-set check msg)
(define handler (test-set-checked-handler log-domain log-level check))
(use-modules (gnucash gnc-module))
(gnc:module-system-init)
(gnc:module-load "gnucash/foo" 0)
(foo-hello)
(foo:scheme-hello)
(gnc:module-load "gnucash/bar" 0)
(foo-hello)
(foo:scheme-hello)
(bar-hello)
(bar:scheme-hello)
(g-log-remove-handler log-domain handler)
;; Local Variables:
;; mode: scheme
;; End: