2001-08-07 23:36:04 +00:00
|
|
|
/********************************************************************
|
2006-05-26 00:10:35 +00:00
|
|
|
* gnc-engine.c -- top-level initialization for GnuCash Engine *
|
2001-08-07 23:36:04 +00:00
|
|
|
* Copyright 2000 Bill Gribble <grib@billgribble.com> *
|
|
|
|
|
* *
|
|
|
|
|
* 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 *
|
2005-11-17 05:35:02 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2001-08-07 23:36:04 +00:00
|
|
|
* *
|
|
|
|
|
********************************************************************/
|
|
|
|
|
|
2017-10-26 11:14:21 +02:00
|
|
|
#include <config.h>
|
2001-08-07 23:36:04 +00:00
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include "gnc-engine.h"
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "qof.h"
|
|
|
|
|
#include "cashobjects.h"
|
2002-05-25 02:50:24 +00:00
|
|
|
#include "AccountP.h"
|
2003-06-10 22:22:47 +00:00
|
|
|
#include "SX-book-p.h"
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "gnc-budget.h"
|
2003-06-10 20:22:01 +00:00
|
|
|
#include "TransactionP.h"
|
2003-06-10 22:22:47 +00:00
|
|
|
#include "gnc-commodity.h"
|
|
|
|
|
#include "gnc-pricedb-p.h"
|
2005-11-02 03:32:36 +00:00
|
|
|
|
|
|
|
|
/** gnc file backend library name */
|
2008-08-01 16:02:07 +00:00
|
|
|
#define GNC_LIB_NAME "gncmod-backend-xml"
|
2006-05-26 00:10:35 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
/* gnc-backend-file location */
|
2006-09-07 21:02:07 +00:00
|
|
|
#include "gnc-path.h"
|
2002-05-25 02:50:24 +00:00
|
|
|
|
2001-08-07 23:36:04 +00:00
|
|
|
static GList * engine_init_hooks = NULL;
|
|
|
|
|
static int engine_is_initialized = 0;
|
2008-10-27 23:42:01 +00:00
|
|
|
|
|
|
|
|
EngineCommitErrorCallback g_error_cb;
|
|
|
|
|
gpointer g_error_cb_data;
|
|
|
|
|
|
2007-02-09 17:35:00 +00:00
|
|
|
// static QofLogModule log_module = GNC_MOD_ENGINE;
|
2001-09-07 11:12:04 +00:00
|
|
|
|
2001-08-07 23:36:04 +00:00
|
|
|
/********************************************************************
|
|
|
|
|
* gnc_engine_init
|
2010-03-02 21:40:28 +00:00
|
|
|
* initialize backend, load any necessary databases, etc.
|
2001-08-07 23:36:04 +00:00
|
|
|
********************************************************************/
|
|
|
|
|
|
2010-03-07 12:54:33 +00:00
|
|
|
static void
|
|
|
|
|
gnc_engine_init_part1()
|
|
|
|
|
{
|
|
|
|
|
/* initialize QOF */
|
|
|
|
|
qof_init();
|
|
|
|
|
|
|
|
|
|
/* Now register our core types */
|
|
|
|
|
cashobjects_register();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gnc_engine_init_part2()
|
2001-08-31 19:47:17 +00:00
|
|
|
{
|
2010-03-02 21:40:28 +00:00
|
|
|
static struct
|
|
|
|
|
{
|
2012-01-01 20:36:46 +00:00
|
|
|
const gchar* subdir;
|
2010-03-02 21:40:28 +00:00
|
|
|
const gchar* lib;
|
|
|
|
|
gboolean required;
|
|
|
|
|
} libs[] =
|
|
|
|
|
{
|
2008-08-01 16:02:07 +00:00
|
|
|
#if defined( HAVE_DBI_DBI_H )
|
2017-08-19 20:25:04 +02:00
|
|
|
{ "dbi", "gncmod-backend-dbi", TRUE },
|
2007-08-05 21:44:21 +00:00
|
|
|
#endif
|
2017-08-19 20:25:04 +02:00
|
|
|
{ "xml", "gncmod-backend-xml", TRUE },
|
|
|
|
|
{ NULL, NULL, FALSE }
|
2010-03-02 21:40:28 +00:00
|
|
|
}, *lib;
|
|
|
|
|
|
|
|
|
|
for (lib = libs; lib->lib ; lib++)
|
|
|
|
|
{
|
2017-08-07 11:37:53 +02:00
|
|
|
if (qof_load_backend_library(lib->subdir, lib->lib))
|
2010-03-02 21:40:28 +00:00
|
|
|
{
|
|
|
|
|
engine_is_initialized = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-08-07 11:37:53 +02:00
|
|
|
g_warning("failed to load %s from relative path %s\n", lib->lib, lib->subdir);
|
2010-03-02 21:40:28 +00:00
|
|
|
/* If this is a required library, stop now! */
|
|
|
|
|
if (lib->required)
|
|
|
|
|
{
|
|
|
|
|
g_critical("required library %s not found.\n", lib->lib);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-07 12:54:33 +00:00
|
|
|
}
|
2010-03-02 21:40:28 +00:00
|
|
|
|
2010-03-07 12:54:33 +00:00
|
|
|
static void
|
|
|
|
|
gnc_engine_init_part3(int argc, char ** argv)
|
|
|
|
|
{
|
|
|
|
|
GList * cur;
|
2010-03-02 21:40:28 +00:00
|
|
|
/* call any engine hooks */
|
|
|
|
|
for (cur = engine_init_hooks; cur; cur = cur->next)
|
|
|
|
|
{
|
2010-03-07 12:54:33 +00:00
|
|
|
gnc_engine_init_hook_t hook = (gnc_engine_init_hook_t)cur->data;
|
2010-03-02 21:40:28 +00:00
|
|
|
|
|
|
|
|
if (hook)
|
|
|
|
|
(*hook)(argc, argv);
|
|
|
|
|
}
|
2001-08-07 23:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-07 12:54:33 +00:00
|
|
|
void
|
|
|
|
|
gnc_engine_init(int argc, char ** argv)
|
|
|
|
|
{
|
2016-12-03 17:33:12 +01:00
|
|
|
if (1 == engine_is_initialized) return;
|
|
|
|
|
|
2010-03-07 12:54:33 +00:00
|
|
|
gnc_engine_init_part1();
|
|
|
|
|
gnc_engine_init_part2();
|
|
|
|
|
gnc_engine_init_part3(argc, argv);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-18 21:53:28 +00:00
|
|
|
void
|
|
|
|
|
gnc_engine_init_static(int argc, char ** argv)
|
|
|
|
|
{
|
2016-12-03 17:33:12 +01:00
|
|
|
if (1 == engine_is_initialized) return;
|
|
|
|
|
|
2011-11-18 21:53:28 +00:00
|
|
|
gnc_engine_init_part1();
|
|
|
|
|
gnc_engine_init_part3(argc, argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-07 23:36:04 +00:00
|
|
|
/********************************************************************
|
|
|
|
|
* gnc_engine_shutdown
|
|
|
|
|
* shutdown backend, destroy any global data, etc.
|
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gnc_engine_shutdown (void)
|
|
|
|
|
{
|
2010-03-02 21:40:28 +00:00
|
|
|
qof_log_shutdown();
|
|
|
|
|
qof_close();
|
|
|
|
|
engine_is_initialized = 0;
|
2001-08-07 23:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
|
* gnc_engine_add_init_hook
|
2010-03-02 21:40:28 +00:00
|
|
|
* add a startup hook
|
2001-08-07 23:36:04 +00:00
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
|
|
void
|
2010-03-02 21:40:28 +00:00
|
|
|
gnc_engine_add_init_hook(gnc_engine_init_hook_t h)
|
|
|
|
|
{
|
|
|
|
|
engine_init_hooks = g_list_append(engine_init_hooks, (gpointer)h);
|
2001-08-07 23:36:04 +00:00
|
|
|
}
|
2005-11-02 03:32:36 +00:00
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gnc_engine_is_initialized (void)
|
|
|
|
|
{
|
2006-05-26 00:10:35 +00:00
|
|
|
return (engine_is_initialized == 1) ? TRUE : FALSE;
|
2005-11-02 03:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-29 17:49:35 +00:00
|
|
|
/* replicate old gnc-trace enum behaviour
|
|
|
|
|
*
|
|
|
|
|
* these are only here as a convenience, they could be
|
|
|
|
|
* initialised elsewhere as appropriate.
|
|
|
|
|
* */
|
|
|
|
|
void gnc_log_default(void)
|
|
|
|
|
{
|
2010-03-02 21:40:28 +00:00
|
|
|
qof_log_set_default(QOF_LOG_WARNING);
|
2007-02-09 17:35:00 +00:00
|
|
|
qof_log_set_level(GNC_MOD_ROOT, QOF_LOG_WARNING);
|
2010-03-02 21:40:28 +00:00
|
|
|
qof_log_set_level(GNC_MOD_TEST, QOF_LOG_DEBUG);
|
2006-01-29 17:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
2008-10-27 23:42:01 +00:00
|
|
|
void
|
|
|
|
|
gnc_engine_add_commit_error_callback( EngineCommitErrorCallback cb, gpointer data )
|
|
|
|
|
{
|
|
|
|
|
g_error_cb = cb;
|
|
|
|
|
g_error_cb_data = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gnc_engine_signal_commit_error( QofBackendError errcode )
|
|
|
|
|
{
|
2010-03-02 21:40:28 +00:00
|
|
|
if ( g_error_cb != NULL )
|
|
|
|
|
{
|
|
|
|
|
(*g_error_cb)( g_error_cb_data, errcode );
|
2008-10-27 23:42:01 +00:00
|
|
|
}
|
|
|
|
|
}
|