GnuCash c935c2f+
Loading...
Searching...
No Matches
gnc-engine.cpp
1/********************************************************************
2 * gnc-engine.c -- top-level initialization for GnuCash Engine *
3 * Copyright 2000 Bill Gribble <grib@billgribble.com> *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation; either version 2 of *
8 * the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact: *
17 * *
18 * Free Software Foundation Voice: +1-617-542-5942 *
19 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20 * Boston, MA 02110-1301, USA gnu@gnu.org *
21 * *
22 ********************************************************************/
23
24#include <config.h>
25
26#include <glib.h>
27#include "gnc-engine.h"
28#include "qof.h"
29#include "cashobjects.h"
30#include "AccountP.hpp"
31#include "SX-book-p.h"
32#include "gnc-budget.h"
33#include "TransactionP.hpp"
34#include "gnc-commodity.h"
35#include "gnc-pricedb-p.h"
36
38#define GNC_LIB_NAME "gncmod-backend-xml"
39
40/* gnc-backend-file location */
41#include "gnc-path.h"
42
43static GList * engine_init_hooks = nullptr;
44static int engine_is_initialized = 0;
45
46EngineCommitErrorCallback g_error_cb;
47gpointer g_error_cb_data;
48
49// static QofLogModule log_module = GNC_MOD_ENGINE;
50
51/********************************************************************
52 * gnc_engine_init
53 * initialize backend, load any necessary databases, etc.
54 ********************************************************************/
55
56static void
57gnc_engine_init_part1()
58{
59 /* initialize QOF */
60 qof_init();
61
62 /* Now register our core types */
63 cashobjects_register();
64}
65
66static void
67gnc_engine_init_part2()
68{
69 static struct
70 {
71 const gchar* subdir;
72 const gchar* lib;
73 gboolean required;
74 } libs[] =
75 {
76#if defined( HAVE_DBI_DBI_H )
77 { "", "gncmod-backend-dbi", TRUE },
78#endif
79 { "", "gncmod-backend-xml", TRUE },
80 { nullptr, nullptr, FALSE }
81 }, *lib;
82
83 for (lib = libs; lib->lib ; lib++)
84 {
85 if (qof_load_backend_library(lib->subdir, lib->lib))
86 {
87 engine_is_initialized = 1;
88 }
89 else
90 {
91 g_warning("failed to load %s from relative path %s\n", lib->lib, lib->subdir);
92 /* If this is a required library, stop now! */
93 if (lib->required)
94 {
95 g_critical("required library %s not found.\n", lib->lib);
96 }
97 }
98 }
99}
100
101static void
102gnc_engine_init_part3(int argc, char ** argv)
103{
104 GList * cur;
105 /* call any engine hooks */
106 for (cur = engine_init_hooks; cur; cur = cur->next)
107 {
109
110 if (hook)
111 (*hook)(argc, argv);
112 }
113}
114
115void
116gnc_engine_init(int argc, char ** argv)
117{
118 if (1 == engine_is_initialized) return;
119
120 gnc_engine_init_part1();
121 gnc_engine_init_part2();
122 gnc_engine_init_part3(argc, argv);
123}
124
125void
126gnc_engine_init_static(int argc, char ** argv)
127{
128 if (1 == engine_is_initialized) return;
129
130 gnc_engine_init_part1();
131 gnc_engine_init_part3(argc, argv);
132}
133
134
135/********************************************************************
136 * gnc_engine_shutdown
137 * shutdown backend, destroy any global data, etc.
138 ********************************************************************/
139
140void
142{
144 qof_close();
145 engine_is_initialized = 0;
146}
147
148/********************************************************************
149 * gnc_engine_add_init_hook
150 * add a startup hook
151 ********************************************************************/
152
153void
155{
156 engine_init_hooks = g_list_append(engine_init_hooks, (gpointer)h);
157}
158
159gboolean
161{
162 return (engine_is_initialized == 1) ? TRUE : FALSE;
163}
164
165void
166gnc_engine_add_commit_error_callback( EngineCommitErrorCallback cb, gpointer data )
167{
168 g_error_cb = cb;
169 g_error_cb_data = data;
170}
171
172void
173gnc_engine_signal_commit_error( QofBackendError errcode )
174{
175 if ( g_error_cb != nullptr )
176 {
177 (*g_error_cb)( g_error_cb_data, errcode );
178 }
179}
This is the private header for the account structure.
GnuCash Budgets.
Commodity handling public routines.
All type declarations for the whole Gnucash engine.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition qofbackend.h:58
void gnc_engine_add_commit_error_callback(EngineCommitErrorCallback cb, gpointer data)
Set a callback function to be called in case an engine commit fails.
void gnc_engine_init(int argc, char **argv)
PROTOTYPES.
void(* gnc_engine_init_hook_t)(int, char **)
Function type for init hooks in the engine.
Definition gnc-engine.h:221
void gnc_engine_init_static(int argc, char **argv)
This is the statically linked-in version of gnc_engine_init.
void gnc_engine_add_init_hook(gnc_engine_init_hook_t h)
Pass a function pointer to gnc_engine_add_init_hook and it will be called during the evaluation of gn...
gboolean gnc_engine_is_initialized(void)
check the engine is fully initialized
void gnc_engine_shutdown(void)
Called to shutdown the engine.
void qof_log_shutdown(void)
Be nice, close the logfile if possible.
Definition qoflog.cpp:264
void qof_init(void)
Initialise the Query Object Framework.
Definition qofutil.cpp:259
void qof_close(void)
Safely close down the Query Object Framework.
Definition qofutil.cpp:269