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"
|
2002-06-27 23:20:46 -05:00
|
|
|
#include "gnc-lot-p.h"
|
2003-06-10 17:22:47 -05:00
|
|
|
#include "gnc-pricedb-p.h"
|
2005-11-01 21:32:36 -06:00
|
|
|
|
|
|
|
/** gnc file backend library name */
|
2007-01-07 01:04:23 -06:00
|
|
|
#define GNC_LIB_NAME "gncmod-backend-file"
|
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;
|
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)
|
|
|
|
{
|
|
|
|
return GNUCASH_MAJOR_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
gnucash_minor_version (void)
|
|
|
|
{
|
|
|
|
return GNUCASH_MINOR_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
gnucash_micro_version (void)
|
|
|
|
{
|
|
|
|
return GNUCASH_MICRO_VERSION;
|
|
|
|
}
|
|
|
|
|
2001-08-07 18:36:04 -05:00
|
|
|
/********************************************************************
|
|
|
|
* gnc_engine_init
|
|
|
|
* initialize backend, load any necessary databases, etc.
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
void
|
2001-08-31 14:47:17 -05:00
|
|
|
gnc_engine_init(int argc, char ** argv)
|
|
|
|
{
|
2006-05-26 10:41:38 -05:00
|
|
|
static struct {
|
|
|
|
const gchar* lib;
|
2006-05-26 14:45:26 -05:00
|
|
|
gboolean required;
|
2006-05-26 10:41:38 -05:00
|
|
|
} libs[] = {
|
2006-09-07 16:02:07 -05:00
|
|
|
{ GNC_LIB_NAME, TRUE },
|
2007-08-05 16:44:21 -05:00
|
|
|
#ifdef SQL_DIR
|
2006-05-26 10:41:38 -05:00
|
|
|
/* shouldn't the PG gnc-module do this instead of US doing it? */
|
2006-09-07 16:02:07 -05:00
|
|
|
{ "gnc-backend-postgres", FALSE },
|
2007-08-05 16:44:21 -05:00
|
|
|
#endif
|
2006-09-07 16:02:07 -05:00
|
|
|
{ NULL, FALSE } }, *lib;
|
2001-08-07 18:36:04 -05:00
|
|
|
gnc_engine_init_hook_t hook;
|
2006-05-25 19:10:35 -05:00
|
|
|
GList * cur;
|
2007-01-07 01:04:23 -06:00
|
|
|
gchar *pkglibdir;
|
2001-08-07 18:36:04 -05:00
|
|
|
|
|
|
|
if (1 == engine_is_initialized) return;
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
/* initialize QOF */
|
|
|
|
qof_init();
|
2006-05-06 01:03:48 -05:00
|
|
|
qof_set_alt_dirty_mode(TRUE);
|
2001-08-07 18:36:04 -05:00
|
|
|
|
* 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
|
|
|
/* Now register our core types */
|
2005-11-01 21:32:36 -06:00
|
|
|
cashobjects_register();
|
|
|
|
|
2007-01-07 01:04:23 -06:00
|
|
|
pkglibdir = gnc_path_get_pkglibdir ();
|
2006-09-07 16:02:07 -05:00
|
|
|
for (lib = libs; lib->lib ; lib++)
|
2006-05-26 14:45:26 -05:00
|
|
|
{
|
2007-01-07 01:04:23 -06:00
|
|
|
if (qof_load_backend_library(pkglibdir, lib->lib))
|
2006-05-26 14:45:26 -05:00
|
|
|
{
|
2006-05-25 19:10:35 -05:00
|
|
|
engine_is_initialized = 1;
|
2006-05-26 14:45:26 -05:00
|
|
|
}
|
2006-05-26 10:41:38 -05:00
|
|
|
else
|
2006-05-26 14:45:26 -05:00
|
|
|
{
|
2007-02-09 20:31:35 -06:00
|
|
|
g_warning("failed to load %s from %s\n", lib->lib, pkglibdir);
|
2007-02-09 11:35:00 -06:00
|
|
|
/* If this is a required library, stop now! */
|
|
|
|
if (lib->required)
|
|
|
|
{
|
2007-02-09 20:31:35 -06:00
|
|
|
g_critical("required library %s not found.\n", lib->lib);
|
2007-02-09 11:35:00 -06:00
|
|
|
}
|
2006-05-26 14:45:26 -05:00
|
|
|
}
|
2006-05-25 19:10:35 -05:00
|
|
|
}
|
2007-01-07 01:04:23 -06:00
|
|
|
g_free (pkglibdir);
|
* 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
|
|
|
/* call any engine hooks */
|
2001-10-03 05:07:45 -05:00
|
|
|
for (cur = engine_init_hooks; cur; cur = cur->next)
|
|
|
|
{
|
2001-08-07 18:36:04 -05:00
|
|
|
hook = (gnc_engine_init_hook_t)cur->data;
|
2001-10-03 05:07:45 -05:00
|
|
|
|
|
|
|
if (hook)
|
2001-08-07 18:36:04 -05:00
|
|
|
(*hook)(argc, argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* gnc_engine_shutdown
|
|
|
|
* shutdown backend, destroy any global data, etc.
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
gnc_engine_shutdown (void)
|
|
|
|
{
|
2005-11-01 21:32:36 -06:00
|
|
|
qof_log_shutdown();
|
2006-04-10 17:20:12 -05:00
|
|
|
qof_close();
|
2005-11-01 21:32:36 -06:00
|
|
|
engine_is_initialized = 0;
|
2001-08-07 18:36:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* gnc_engine_add_init_hook
|
|
|
|
* add a startup hook
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
gnc_engine_add_init_hook(gnc_engine_init_hook_t h) {
|
|
|
|
engine_init_hooks = g_list_append(engine_init_hooks, (gpointer)h);
|
|
|
|
}
|
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)
|
|
|
|
{
|
2006-01-29 13:21:25 -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);
|
2007-02-09 15:52:09 -06:00
|
|
|
qof_log_set_level(GNC_MOD_TEST, QOF_LOG_DEBUG);
|
2006-01-29 11:49:35 -06:00
|
|
|
}
|
|
|
|
|