2001-08-07 18:36:04 -05:00
|
|
|
/********************************************************************
|
2006-05-25 19:10:35 -05:00
|
|
|
* gnc-engine.c -- top-level initialization for GnuCash Engine *
|
2001-08-07 18:36:04 -05: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-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2001-08-07 18:36:04 -05:00
|
|
|
* *
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include "gnc-engine.h"
|
2005-11-01 21:32:36 -06:00
|
|
|
#include "qof.h"
|
|
|
|
#include "cashobjects.h"
|
* src/engine/GNCId.c: Implement xaccForeachEntity() as a which
allows a traversal of all entities of a particular type.
* Register GncObject_t descriptions for Splits, Transactions, and
Accounts. Move the QueryObject definitions into the actual module
sources for Transactions, Splits, Accounts, and Books. This
allows QueryNew searches for Splits, Transactions, and Accounts.
* gnc-engine.c: call the registration functions for Splits,
Transactions, Accounts, and Books to enable searching using the
new search subsystem.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6913 57a11ea4-9604-0410-9ed3-97b8803252fd
2002-05-24 21:50:24 -05:00
|
|
|
#include "AccountP.h"
|
2003-06-10 17:22:47 -05:00
|
|
|
#include "SX-book-p.h"
|
2005-11-01 21:32:36 -06:00
|
|
|
#include "gnc-budget.h"
|
2003-06-10 15:22:01 -05:00
|
|
|
#include "TransactionP.h"
|
2003-06-10 17:22:47 -05:00
|
|
|
#include "gnc-commodity.h"
|
|
|
|
#include "gnc-pricedb-p.h"
|
2005-11-01 21:32:36 -06:00
|
|
|
|
|
|
|
/** gnc file backend library name */
|
2008-08-01 11:02:07 -05:00
|
|
|
#define GNC_LIB_NAME "gncmod-backend-xml"
|
2006-05-25 19:10:35 -05:00
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
/* gnc-backend-file location */
|
2006-09-07 16:02:07 -05:00
|
|
|
#include "gnc-path.h"
|
* src/engine/GNCId.c: Implement xaccForeachEntity() as a which
allows a traversal of all entities of a particular type.
* Register GncObject_t descriptions for Splits, Transactions, and
Accounts. Move the QueryObject definitions into the actual module
sources for Transactions, Splits, Accounts, and Books. This
allows QueryNew searches for Splits, Transactions, and Accounts.
* gnc-engine.c: call the registration functions for Splits,
Transactions, Accounts, and Books to enable searching using the
new search subsystem.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6913 57a11ea4-9604-0410-9ed3-97b8803252fd
2002-05-24 21:50:24 -05:00
|
|
|
|
2001-08-07 18:36:04 -05:00
|
|
|
static GList * engine_init_hooks = NULL;
|
|
|
|
static int engine_is_initialized = 0;
|
2008-10-27 18:42:01 -05:00
|
|
|
|
|
|
|
EngineCommitErrorCallback g_error_cb;
|
|
|
|
gpointer g_error_cb_data;
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
// static QofLogModule log_module = GNC_MOD_ENGINE;
|
2001-09-07 06:12:04 -05:00
|
|
|
|
|
|
|
/* GnuCash version functions */
|
|
|
|
unsigned int
|
|
|
|
gnucash_major_version (void)
|
|
|
|
{
|
2010-03-02 15:40:28 -06:00
|
|
|
return GNUCASH_MAJOR_VERSION;
|
2001-09-07 06:12:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
gnucash_minor_version (void)
|
|
|
|
{
|
2010-03-02 15:40:28 -06:00
|
|
|
return GNUCASH_MINOR_VERSION;
|
2001-09-07 06:12:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
gnucash_micro_version (void)
|
|
|
|
{
|
2010-03-02 15:40:28 -06:00
|
|
|
return GNUCASH_MICRO_VERSION;
|
2001-09-07 06:12:04 -05:00
|
|
|
}
|
|
|
|
|
2001-08-07 18:36:04 -05:00
|
|
|
/********************************************************************
|
|
|
|
* gnc_engine_init
|
2010-03-02 15:40:28 -06:00
|
|
|
* initialize backend, load any necessary databases, etc.
|
2001-08-07 18:36:04 -05:00
|
|
|
********************************************************************/
|
|
|
|
|
2010-03-02 15:40:28 -06:00
|
|
|
void
|
2001-08-31 14:47:17 -05:00
|
|
|
gnc_engine_init(int argc, char ** argv)
|
|
|
|
{
|
2010-03-02 15:40:28 -06:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const gchar* lib;
|
|
|
|
gboolean required;
|
|
|
|
} libs[] =
|
|
|
|
{
|
2008-08-01 11:02:07 -05:00
|
|
|
#if defined( HAVE_DBI_DBI_H )
|
2010-03-02 15:40:28 -06:00
|
|
|
{ "gncmod-backend-dbi", TRUE },
|
2007-08-05 16:44:21 -05:00
|
|
|
#endif
|
2010-03-02 15:40:28 -06:00
|
|
|
{ "gncmod-backend-xml", TRUE },
|
|
|
|
{ NULL, FALSE }
|
|
|
|
}, *lib;
|
|
|
|
gnc_engine_init_hook_t hook;
|
|
|
|
GList * cur;
|
|
|
|
gchar *pkglibdir;
|
|
|
|
|
|
|
|
if (1 == engine_is_initialized) return;
|
|
|
|
|
|
|
|
/* initialize QOF */
|
|
|
|
qof_init();
|
|
|
|
qof_set_alt_dirty_mode(TRUE);
|
|
|
|
|
|
|
|
/* Now register our core types */
|
|
|
|
cashobjects_register();
|
|
|
|
|
|
|
|
pkglibdir = gnc_path_get_pkglibdir ();
|
|
|
|
for (lib = libs; lib->lib ; lib++)
|
|
|
|
{
|
|
|
|
if (qof_load_backend_library(pkglibdir, lib->lib))
|
|
|
|
{
|
|
|
|
engine_is_initialized = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning("failed to load %s from %s\n", lib->lib, pkglibdir);
|
|
|
|
/* If this is a required library, stop now! */
|
|
|
|
if (lib->required)
|
|
|
|
{
|
|
|
|
g_critical("required library %s not found.\n", lib->lib);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (pkglibdir);
|
|
|
|
|
|
|
|
/* call any engine hooks */
|
|
|
|
for (cur = engine_init_hooks; cur; cur = cur->next)
|
|
|
|
{
|
|
|
|
hook = (gnc_engine_init_hook_t)cur->data;
|
|
|
|
|
|
|
|
if (hook)
|
|
|
|
(*hook)(argc, argv);
|
|
|
|
}
|
2001-08-07 18:36:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* gnc_engine_shutdown
|
|
|
|
* shutdown backend, destroy any global data, etc.
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
gnc_engine_shutdown (void)
|
|
|
|
{
|
2010-03-02 15:40:28 -06:00
|
|
|
qof_log_shutdown();
|
|
|
|
qof_close();
|
|
|
|
engine_is_initialized = 0;
|
2001-08-07 18:36:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* gnc_engine_add_init_hook
|
2010-03-02 15:40:28 -06:00
|
|
|
* add a startup hook
|
2001-08-07 18:36:04 -05:00
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
void
|
2010-03-02 15:40:28 -06: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 18:36:04 -05:00
|
|
|
}
|
2005-11-01 21:32:36 -06:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gnc_engine_is_initialized (void)
|
|
|
|
{
|
2006-05-25 19:10:35 -05:00
|
|
|
return (engine_is_initialized == 1) ? TRUE : FALSE;
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2006-01-29 11:49:35 -06: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 15:40:28 -06:00
|
|
|
qof_log_set_default(QOF_LOG_WARNING);
|
2007-02-09 11:35:00 -06:00
|
|
|
qof_log_set_level(GNC_MOD_ROOT, QOF_LOG_WARNING);
|
2010-03-02 15:40:28 -06:00
|
|
|
qof_log_set_level(GNC_MOD_TEST, QOF_LOG_DEBUG);
|
2006-01-29 11:49:35 -06:00
|
|
|
}
|
|
|
|
|
2008-10-27 18:42:01 -05: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 15:40:28 -06:00
|
|
|
if ( g_error_cb != NULL )
|
|
|
|
{
|
|
|
|
(*g_error_cb)( g_error_cb_data, errcode );
|
2008-10-27 18:42:01 -05:00
|
|
|
}
|
|
|
|
}
|