[Gnucash-changes] New trace subsystem
Neil Williams
codehelp at cvs.gnucash.org
Sat Oct 1 13:57:49 EDT 2005
Log Message:
-----------
New trace subsystem
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash/src/engine:
gnc-engine.c
gnc-engine.h
gnc-trace.h
gnc-trace.c
qofbook.h
qofbook.c
qofquery.c
qofsession.c
gnc-pricedb.c
Revision Data
-------------
Index: qofquery.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofquery.c,v
retrieving revision 1.10.2.9
retrieving revision 1.10.2.10
diff -Lsrc/engine/qofquery.c -Lsrc/engine/qofquery.c -u -r1.10.2.9 -r1.10.2.10
--- src/engine/qofquery.c
+++ src/engine/qofquery.c
@@ -29,8 +29,8 @@
#include <regex.h>
#include <string.h>
-#include "gnc-engine-util.h"
#include "gnc-trace.h"
+#include "gnc-engine-util.h"
#include "qofbackend-p.h"
#include "qofbook.h"
@@ -43,7 +43,7 @@
#include "qofquerycore.h"
#include "qofquerycore-p.h"
-static short module = MOD_QUERY;
+static QofLogModule log_module = QOF_MOD_QUERY;
struct _QofQueryTerm
{
@@ -409,6 +409,7 @@
}
if (and_terms_ok)
{
+ LEAVE (" (terms are OK)");
return 1;
}
}
@@ -418,8 +419,8 @@
* may want to get all objects, but in a particular sorted
* order.
*/
+ LEAVE (" ");
if (NULL == q->terms) return 1;
-
return 0;
}
@@ -477,7 +478,7 @@
sort->obj_cmp = NULL;
/* An empty param_list implies "no sort" */
- if (!sort->param_list) return;
+ if (!sort->param_list) { LEAVE (" "); return; }
/* Walk the parameter list of obtain the parameter functions */
sort->param_fcns = compile_params (sort->param_list, obj, &resObj);
@@ -702,10 +703,10 @@
GList *node;
int object_count = 0;
- ENTER (" q=%p", q);
if (!q) return NULL;
g_return_val_if_fail (q->search_for, NULL);
g_return_val_if_fail (q->books, NULL);
+ ENTER (" q=%p", q);
/* XXX: Prioritize the query terms? */
@@ -717,7 +718,7 @@
}
/* Maybe log this sucker */
- if (gnc_should_log (module, GNC_LOG_DETAIL)) qof_query_print (q);
+ if (gnc_should_log (log_module, GNC_LOG_DETAIL)) qof_query_print (q);
/* Now run the query over all the objects and save the results */
{
Index: gnc-trace.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-trace.c,v
retrieving revision 1.2.20.13
retrieving revision 1.2.20.14
diff -Lsrc/engine/gnc-trace.c -Lsrc/engine/gnc-trace.c -u -r1.2.20.13 -r1.2.20.14
--- src/engine/gnc-trace.c
+++ src/engine/gnc-trace.c
@@ -1,6 +1,7 @@
-/********************************************************************\
+/* *****************************************************************\
* gnc-trace.c -- GnuCash error loging and tracing facility *
* Copyright (C) 1997-2003 Linas Vepstas <linas at linas.org> *
+ * Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -34,45 +35,21 @@
#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
-
+#include "qof.h"
#include "gnc-trace.h"
-/* This static indicates the debugging module that this .o belongs to. */
-/* static short module = MOD_ENGINE; */
-
-gncLogLevel gnc_log_modules[MOD_LAST + 1] =
-{
- GNC_LOG_FATAL, /* DUMMY */
- GNC_LOG_WARNING, /* ENGINE */
- GNC_LOG_WARNING, /* IO */
- GNC_LOG_WARNING, /* REGISTER */
- GNC_LOG_WARNING, /* LEDGER */
- GNC_LOG_WARNING, /* HTML */
- GNC_LOG_WARNING, /* GUI */
- GNC_LOG_WARNING, /* SCRUB */
- GNC_LOG_WARNING, /* GTK_REG */
- GNC_LOG_WARNING, /* GUILE */
- GNC_LOG_WARNING, /* BACKEND */
- GNC_LOG_WARNING, /* QUERY */
- GNC_LOG_WARNING, /* PRICE */
- GNC_LOG_WARNING, /* SQL EVENT */
- GNC_LOG_WARNING, /* SQL TXN */
- GNC_LOG_WARNING, /* KVP */
- GNC_LOG_WARNING, /* SX */
- GNC_LOG_WARNING, /* BOOK */
- GNC_LOG_TRACE, /* TEST */
- GNC_LOG_WARNING, /* LOT */
- GNC_LOG_WARNING, /* ACCOUNT */
- GNC_LOG_WARNING, /* IMPORT */
- GNC_LOG_WARNING, /* BUSINESS */
- GNC_LOG_WARNING, /* DRUID */
- GNC_LOG_WARNING, /* COMMODITY */
- GNC_LOG_WARNING, /* HBCI */
- GNC_LOG_WARNING, /* PREFS */
-};
-
static FILE *fout = NULL;
+static gchar* filename = NULL;
+
static const int MAX_TRACE_FILENAME = 100;
+static GHashTable *log_table = NULL;
+
+/* uses the enum_as_string macro from QOF
+but the From macro is not required. Lookups
+are done on the string. */
+AS_STRING_FUNC(gncLogLevel, LOG_LEVEL_LIST)
+
+FROM_STRING_FUNC(gncLogLevel, LOG_LEVEL_LIST)
/* Don't be fooled: gnc_trace_num_spaces has external linkage and
static storage, but can't be defined with 'extern' because it has
@@ -95,12 +72,13 @@
void
gnc_log_init (void)
{
- char *filename;
-
- fout = fopen ("/tmp/gnucash.trace", "w");
+ if(!fout) //allow gnc_set_logfile
+ {
+ fout = fopen ("/tmp/qof.trace", "w");
+ }
if(!fout && (filename = (char *)g_malloc(MAX_TRACE_FILENAME))) {
- snprintf(filename, MAX_TRACE_FILENAME-1, "/tmp/gnucash.trace.%d",
+ snprintf(filename, MAX_TRACE_FILENAME-1, "/tmp/qof.trace.%d",
getpid());
fout = fopen (filename, "w");
g_free(filename);
@@ -114,30 +92,66 @@
/* Set the logging level of the given module. */
void
-gnc_set_log_level(gncModuleType module, gncLogLevel level)
+gnc_set_log_level(QofLogModule log_module, gncLogLevel level)
{
- if ((module < 0) || (module > MOD_LAST))
- return;
+ gchar* level_string;
- gnc_log_modules[module] = level;
+ if(!log_module || level == 0) { return; }
+ level_string = g_strdup(gncLogLevelasString(level));
+ if(!log_table)
+ {
+ log_table = g_hash_table_new(g_str_hash, g_str_equal);
+ }
+ g_hash_table_insert(log_table, (gpointer)log_module, level_string);
}
-/* Set the logging level for all modules. */
+static void
+log_module_foreach(gpointer key, gpointer value, gpointer data)
+{
+ g_hash_table_insert(log_table, key, data);
+}
+
+/* Set the logging level for all known modules. */
void
gnc_set_log_level_global(gncLogLevel level)
{
- gncModuleType module;
+ gchar* level_string;
- for (module = 0; module <= MOD_LAST; module++)
- gnc_log_modules[module] = level;
+ if(!log_table || level == 0) { return; }
+ level_string = g_strdup(gncLogLevelasString(level));
+ g_hash_table_foreach(log_table, log_module_foreach, level_string);
}
void
gnc_set_logfile (FILE *outfile)
{
+ if(!outfile) { fout = stderr; return; }
fout = outfile;
}
+void
+qof_log_init_filename (const gchar* logfilename)
+{
+ if(!logfilename)
+ {
+ fout = stderr;
+ }
+ else
+ {
+ filename = g_strdup(logfilename);
+ fout = fopen(filename, "w");
+ }
+ gnc_log_init();
+}
+
+void
+qof_log_shutdown (void)
+{
+ if(fout && fout != stderr) { fclose(fout); }
+ if(filename) { g_free(filename); }
+ g_hash_table_destroy(log_table);
+}
+
#define MAX_CHARS 50
/* gnc_log_prettify() cleans up subroutine names. AIX/xlC has the habit
* of printing signatures not names; clean this up. On other operating
@@ -185,7 +199,7 @@
};
void
-gnc_start_clock (int clockno, gncModuleType module, gncLogLevel log_level,
+gnc_start_clock (int clockno, QofLogModule log_module, gncLogLevel log_level,
const char *function_name, const char *format, ...)
{
struct timezone tz;
@@ -210,7 +224,7 @@
}
void
-gnc_report_clock (int clockno, gncModuleType module, gncLogLevel log_level,
+gnc_report_clock (int clockno, QofLogModule log_module, gncLogLevel log_level,
const char *function_name, const char *format, ...)
{
struct timezone tz;
@@ -250,7 +264,7 @@
void
gnc_report_clock_total (int clockno,
- gncModuleType module, gncLogLevel log_level,
+ QofLogModule log_module, gncLogLevel log_level,
const char *function_name, const char *format, ...)
{
va_list ap;
@@ -283,9 +297,62 @@
}
gboolean
-gnc_should_log(gncModuleType module, gncLogLevel log_level)
+gnc_should_log(QofLogModule log_module, gncLogLevel log_level)
+{
+ gchar* log_string;
+ gncLogLevel maximum; /* Any log_level less than this will be logged. */
+
+ log_string = NULL;
+ if(!log_table || log_module == NULL || log_level == 0) { return FALSE; }
+ log_string = (gchar*)g_hash_table_lookup(log_table, log_module);
+ /* if log_module not found, do not log. */
+ if(!log_string) { return FALSE; }
+ maximum = gncLogLevelfromString(log_string);
+ if(log_level <= maximum) { return TRUE; }
+ return FALSE;
+}
+
+void qof_log_set_default(gncLogLevel log_level)
+{
+ gnc_set_log_level(QOF_MOD_BACKEND, log_level);
+ gnc_set_log_level(QOF_MOD_CLASS, log_level);
+ gnc_set_log_level(QOF_MOD_ENGINE, log_level);
+ gnc_set_log_level(QOF_MOD_OBJECT, log_level);
+ gnc_set_log_level(QOF_MOD_KVP, log_level);
+ gnc_set_log_level(QOF_MOD_MERGE, log_level);
+ gnc_set_log_level(QOF_MOD_QUERY, log_level);
+ gnc_set_log_level(QOF_MOD_SESSION, log_level);
+}
+
+struct hash_s
+{
+ QofLogCB cb;
+ gpointer data;
+};
+
+static void hash_cb (gpointer key, gpointer value, gpointer data)
+{
+ struct hash_s *iter;
+
+ iter = (struct hash_s*)data;
+ if(!iter) { return; }
+ (iter->cb)(key, value, iter->data);
+}
+
+void qof_log_module_foreach(QofLogCB cb, gpointer data)
+{
+ struct hash_s iter;
+
+ if(!cb) { return; }
+ iter.cb = cb;
+ iter.data = data;
+ g_hash_table_foreach(log_table, hash_cb, (gpointer)&iter);
+}
+
+gint qof_log_module_count(void)
{
- return (log_level <= gnc_log_modules[module]);
+ if(!log_table) { return 0; }
+ return g_hash_table_size(log_table);
}
/************************* END OF FILE ******************************\
Index: gnc-trace.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-trace.h,v
retrieving revision 1.3.4.8
retrieving revision 1.3.4.9
diff -Lsrc/engine/gnc-trace.h -Lsrc/engine/gnc-trace.h -u -r1.3.4.8 -r1.3.4.9
--- src/engine/gnc-trace.h
+++ src/engine/gnc-trace.h
@@ -26,7 +26,7 @@
@{ */
/** @file gnc-trace.h
- * @brief GnuCash error loging and tracing facility */
+ * @brief QOF error logging and tracing facility */
#ifndef GNC_TRACE_H
#define GNC_TRACE_H
@@ -34,71 +34,66 @@
#include <glib.h>
#include <stdarg.h>
#include <stdio.h>
+#include "qof.h"
+#include "gnc-engine-util.h"
-/** DEBUGGING MACROS ************************************************/
-/* The debuging macros enable the setting of trace messages */
+#define QOF_MOD_ENGINE "qof-engine"
-/** If you modify this, modify the loglevel table in the .c file. */
-typedef enum
-{
- MOD_DUMMY = 0,
- MOD_ENGINE = 1,
- MOD_IO = 2,
- MOD_REGISTER = 3,
- MOD_LEDGER = 4,
- MOD_HTML = 5,
- MOD_GUI = 6,
- MOD_SCRUB = 7,
- MOD_GTK_REG = 8,
- MOD_GUILE = 9,
- MOD_BACKEND = 10,
- MOD_QUERY = 11,
- MOD_PRICE = 12,
- MOD_EVENT = 13,
- MOD_TXN = 14,
- MOD_KVP = 15,
- MOD_SX = 16,
- MOD_BOOK = 17,
- MOD_TEST = 18,
- MOD_LOT = 19,
- MOD_ACCOUNT = 20,
- MOD_IMPORT = 21,
- MOD_BUSINESS = 22,
- MOD_DRUID = 23,
- MOD_COMMODITY = 24,
- MOD_HBCI = 25,
- MOD_PREFS = 26,
- MOD_LAST = 26
-} gncModuleType;
-
-typedef enum
-{
- GNC_LOG_FATAL = 0,
- GNC_LOG_ERROR = 1,
- GNC_LOG_WARNING = 2,
- GNC_LOG_INFO = 3,
- GNC_LOG_DEBUG = 4,
- GNC_LOG_DETAIL = 5,
- GNC_LOG_TRACE = 6,
-} gncLogLevel;
+#define LOG_LEVEL_LIST(_) \
+ _(GNC_LOG_FATAL, = 0) \
+ _(GNC_LOG_ERROR, = 1) \
+ _(GNC_LOG_WARNING, = 2) \
+ _(GNC_LOG_INFO, = 3) \
+ _(GNC_LOG_DEBUG, = 4) \
+ _(GNC_LOG_DETAIL, = 5) \
+ _(GNC_LOG_TRACE, = 6)
-//extern gncLogLevel gnc_log_modules[MOD_LAST + 1];
+DEFINE_ENUM (gncLogLevel, LOG_LEVEL_LIST)
+
+AS_STRING_DEC(gncLogLevel, LOG_LEVEL_LIST)
+
+FROM_STRING_DEC(gncLogLevel, LOG_LEVEL_LIST)
#define GNC_TRACE_INDENT_WIDTH 4
-/** Initialize the error logging subsystem */
+/** Initialize the error logging subsystem
+
+\note Applications should call gnc_set_logfile
+to set the output, otherwise the
+default of \a /tmp/qof.trace will be used.
+
+As an alternative, use qof_log_init_filename
+which sets the filename and initialises the
+logging subsystem in one operation.
+*/
void gnc_log_init (void);
-/** Set the logging level of the given module. */
-void gnc_set_log_level(gncModuleType module, gncLogLevel level);
+/** Set the logging level of the given log_module. */
+void gnc_set_log_level(QofLogModule module, gncLogLevel level);
+
+/** Set the logging level for all known log_modules.
-/** Set the logging level for all modules. */
+\note Unless a log_module has been registered using
+gnc_set_log_level, it will be unaffected by this change.
+
+*/
void gnc_set_log_level_global(gncLogLevel level);
/** Specify an alternate log output, to pipe or file. By default,
- * all logging goes to STDERR. */
+ * all logging goes to /tmp/qof.trace
+
+ Needs to be called \b before gnc_log_init()
+*/
void gnc_set_logfile (FILE *outfile);
+/** Specify a filename for log output.
+
+Calls gnc_log_init() for you.
+*/
+void qof_log_init_filename (const gchar* logfilename);
+
+/** Be nice, close the logfile is possible. */
+void qof_log_shutdown (void);
/** gnc_log_prettify() cleans up subroutine names. AIX/xlC has the habit
* of printing signatures not names; clean this up. On other operating
@@ -107,21 +102,29 @@
* reasonable. Hope thread safety doesn't poke us in eye. */
const char * gnc_log_prettify (const char *name);
-/* We want logging decisions to be made inline, rather than through
- * a CPU-sucking subroutine call. Thus, this is a #define, not a
- * subroutine call. The prototype would have been:
- * gboolean gnc_should_log (gncModuleType module, gncLogLevel log_level);
- *
- * Unfortunately this doesn't work due to circular dependencies and
- * undefined symbols, so let's return it to a function call. The real
- * problem appears to be that gnc_log_modules isn't being exported
- * so engine-helpers.c has an undefined symbol when linked into libgw-engine
- * -- Derek Atkins <derek at ihtfp.com> 2004-01-06
- *
- * #define gnc_should_log(module,log_level) \
- * (log_level <= gnc_log_modules[module])
- */
-gboolean gnc_should_log(gncModuleType module, gncLogLevel log_level);
+/** Do not log log_modules that have not been enabled.
+
+ Whether to log cannot be decided inline because a hashtable is
+ now used. This is the price of extending logging to non-Gnucash
+ log_modules.
+
+*/
+gboolean gnc_should_log(QofLogModule log_module, gncLogLevel log_level);
+
+/** Set the default QOF log_modules to the log level. */
+void qof_log_set_default(gncLogLevel log_level);
+
+typedef void (*QofLogCB) (QofLogModule log_module, gncLogLevel* log_level, gpointer user_data);
+
+/** Iterate over each known log_module
+
+Only log_modules with log_levels set will
+be available.
+*/
+void qof_log_module_foreach(QofLogCB cb, gpointer data);
+
+/** Number of log_modules registered*/
+gint qof_log_module_count(void);
#define FUNK gnc_log_prettify(__FUNCTION__)
@@ -145,7 +148,7 @@
/** Log an serious error */
#define PERR(format, args...) { \
- if (gnc_should_log (module, GNC_LOG_ERROR)) { \
+ if (gnc_should_log (log_module, GNC_LOG_ERROR)) { \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
"Error: %s(): " format, FUNK , ## args); \
} \
@@ -153,7 +156,7 @@
/** Log an warning */
#define PWARN(format, args...) { \
- if (gnc_should_log (module, GNC_LOG_WARNING)) { \
+ if (gnc_should_log (log_module, GNC_LOG_WARNING)) { \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, \
"Warning: %s(): " format, FUNK , ## args); \
} \
@@ -161,7 +164,7 @@
/** Print an informational note */
#define PINFO(format, args...) { \
- if (gnc_should_log (module, GNC_LOG_INFO)) { \
+ if (gnc_should_log (log_module, GNC_LOG_INFO)) { \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, \
"Info: %s(): " format, \
FUNK , ## args); \
@@ -170,7 +173,7 @@
/** Print an debugging message */
#define DEBUG(format, args...) { \
- if (gnc_should_log (module, GNC_LOG_DEBUG)) { \
+ if (gnc_should_log (log_module, GNC_LOG_DEBUG)) { \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"Debug: %s(): " format, \
FUNK , ## args); \
@@ -180,7 +183,7 @@
/** Print an function entry debugging message */
#define ENTER(format, args...) { \
extern gint gnc_trace_num_spaces; \
- if (gnc_should_log (module, GNC_LOG_DEBUG)) { \
+ if (gnc_should_log (log_module, GNC_LOG_DEBUG)) { \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"Enter in %s: %s()" format, __FILE__, \
FUNK , ## args); \
@@ -191,7 +194,7 @@
/** Print an function exit debugging message */
#define LEAVE(format, args...) { \
extern gint gnc_trace_num_spaces; \
- if (gnc_should_log (module, GNC_LOG_DEBUG)) { \
+ if (gnc_should_log (log_module, GNC_LOG_DEBUG)) { \
gnc_trace_num_spaces -= GNC_TRACE_INDENT_WIDTH;\
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"Leave: %s()" format, \
@@ -201,51 +204,51 @@
/** Print an function trace debugging message */
#define TRACE(format, args...) { \
- if (gnc_should_log (module, GNC_LOG_TRACE)) { \
+ if (gnc_should_log (log_module, GNC_LOG_TRACE)) { \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"Trace: %s(): " format, FUNK , ## args); \
} \
}
-#define DEBUGCMD(x) { if (gnc_should_log (module, GNC_LOG_DEBUG)) { (x); }}
+#define DEBUGCMD(x) { if (gnc_should_log (log_module, GNC_LOG_DEBUG)) { (x); }}
/* -------------------------------------------------------- */
/** Infrastructure to make timing measurements for critical peices
* of code. Used for only for performance tuning & debugging.
*/
-void gnc_start_clock (int clockno, gncModuleType module, gncLogLevel log_level,
+void gnc_start_clock (int clockno, QofLogModule log_module, gncLogLevel log_level,
const char *function_name, const char *format, ...);
void gnc_report_clock (int clockno,
- gncModuleType module,
+ QofLogModule log_module,
gncLogLevel log_level,
const char *function_name,
const char *format, ...);
void gnc_report_clock_total (int clockno,
- gncModuleType module,
+ QofLogModule log_module,
gncLogLevel log_level,
const char *function_name,
const char *format, ...);
/** start a particular timer */
#define START_CLOCK(clockno,format, args...) { \
- if (gnc_should_log (module, GNC_LOG_INFO)) \
+ if (gnc_should_log (log_module, GNC_LOG_INFO)) \
gnc_start_clock (clockno, module, GNC_LOG_INFO, \
__FUNCTION__, format , ## args); \
}
/** report elapsed time since last report on a particular timer */
#define REPORT_CLOCK(clockno,format, args...) { \
- if (gnc_should_log (module, GNC_LOG_INFO)) \
+ if (gnc_should_log (log_module, GNC_LOG_INFO)) \
gnc_report_clock (clockno, module, GNC_LOG_INFO, \
__FUNCTION__, format , ## args); \
}
/** report total elapsed time since timer started */
#define REPORT_CLOCK_TOTAL(clockno,format, args...) { \
- if (gnc_should_log (module, GNC_LOG_INFO)) \
+ if (gnc_should_log (log_module, GNC_LOG_INFO)) \
gnc_report_clock_total (clockno, module, GNC_LOG_INFO, \
__FUNCTION__, format , ## args); \
}
Index: qofsession.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofsession.c,v
retrieving revision 1.2.4.23
retrieving revision 1.2.4.24
diff -Lsrc/engine/qofsession.c -Lsrc/engine/qofsession.c -u -r1.2.4.23 -r1.2.4.24
--- src/engine/qofsession.c
+++ src/engine/qofsession.c
@@ -42,9 +42,9 @@
#include <glib.h>
#include "qofla-dir.h"
+#include "gnc-trace.h"
#include "gnc-engine-util.h"
#include "gnc-event.h"
-#include "gnc-trace.h"
#include "qofsession.h"
#include "qofbackend-p.h"
#include "qof-be-utils.h"
@@ -61,7 +61,7 @@
/** \deprecated should not be static */
static QofSession * current_session = NULL;
static GHookList * session_closed_hooks = NULL;
-static short module = MOD_BACKEND;
+static QofLogModule log_module = QOF_MOD_SESSION;
static GSList *provider_list = NULL;
/* ====================================================================== */
@@ -418,7 +418,6 @@
g_return_if_fail(user_data != NULL);
context = (QofEntityCopyData*) user_data;
- ENTER (" ");
cm_date.tv_nsec = 0;
cm_date.tv_sec = 0;
importEnt = context->from;
@@ -501,7 +500,6 @@
qof_session_update_reference_list(context->new_session, reference);
}
}
- LEAVE (" ");
}
static gboolean
@@ -954,6 +952,7 @@
book = node->data;
qof_book_set_backend (book, session->backend);
}
+ LEAVE (" ");
return;
}
p = p->next;
@@ -1224,7 +1223,7 @@
book_id = g_strdup(session->book_id);
if(partial == TRUE)
{
- if(session->backend->provider) {
+ if(session->backend && session->backend->provider) {
prov = session->backend->provider;
if(TRUE == prov->partial_book_supported)
{
Index: gnc-engine.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-engine.h,v
retrieving revision 1.16.4.7
retrieving revision 1.16.4.8
diff -Lsrc/engine/gnc-engine.h -Lsrc/engine/gnc-engine.h -u -r1.16.4.7 -r1.16.4.8
--- src/engine/gnc-engine.h
+++ src/engine/gnc-engine.h
@@ -37,7 +37,32 @@
#define GNC_ENGINE_H
#include <glib.h>
-#include "qofid.h"
+#include "qof.h"
+
+/** \name QofLogModule identifiers */
+// @{
+#define GNC_MOD_ENGINE "gnucash-engine-objects"
+#define GNC_MOD_ACCOUNT "gnucash-account"
+#define GNC_MOD_SX "gnucash-schedX"
+#define GNC_MOD_QUERY "gnucash-query"
+#define GNC_MOD_SCRUB "gnucash-scrub"
+#define GNC_MOD_LOT "gnucash-lots"
+#define GNC_MOD_COMMODITY "gnucash-commodity"
+#define GNC_MOD_BACKEND "gnucash-backend-general"
+#define GNC_MOD_PRICE "gnucash-pricedb"
+#define GNC_MOD_BUSINESS "gnucash-business"
+#define GNC_MOD_IO "gnucash-inputoutput"
+#define GNC_MOD_BOOK "gnucash-book-period"
+#define GNC_MOD_GUI "gnucash-gui"
+#define GNC_MOD_GUILE "gnucash-guile"
+#define GNC_MOD_LEDGER "gnucash-ledger"
+#define GNC_MOD_REGISTER "gnucash-register"
+#define GNC_MOD_HTML "gnucash-html"
+#define GNC_MOD_PREFS "gnucash-preferences"
+#define GNC_MOD_IMPORT "gnucash-import-export"
+#define GNC_MOD_DRUID "gnucash-druids"
+#define GNC_MOD_TEST "gnucash-tests"
+//@}
/** @brief IDENTIFIERS
* GUID Identifiers can be used to reference Accounts, Transactions,
@@ -187,11 +212,13 @@
/** GnuCash version number infomation. */
unsigned int gnucash_micro_version (void);
-/** gnc_engine_init MUST be called before gnc engine functions can
- * be used. */
+/** gnc_engine_init should be called before gnc engine
+ * functions can be used - see also ::qof_init for a
+ * method that does not require Guile. */
void gnc_engine_init(int argc, char ** argv);
-/** Called to shutdown the engine */
+/** Called to shutdown the engine, see also ::qof_close
+ * for use without Guile. */
void gnc_engine_shutdown (void);
/** Pass a function pointer to gnc_engine_add_init_hook and
Index: gnc-engine.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-engine.c,v
retrieving revision 1.17.4.4
retrieving revision 1.17.4.5
diff -Lsrc/engine/gnc-engine.c -Lsrc/engine/gnc-engine.c -u -r1.17.4.4 -r1.17.4.5
--- src/engine/gnc-engine.c
+++ src/engine/gnc-engine.c
@@ -38,13 +38,7 @@
#include "SchedXactionP.h"
#include "FreqSpecP.h"
#include "gnc-pricedb-p.h"
-#include "qofbook.h"
-#include "qofbook-p.h"
-#include "qofid.h"
-#include "qofobject.h"
-#include "qofobject-p.h"
-#include "qofquery.h"
-#include "qofquery-p.h"
+#include "qof.h"
static GList * engine_init_hooks = NULL;
static int engine_is_initialized = 0;
@@ -82,8 +76,14 @@
if (1 == engine_is_initialized) return;
engine_is_initialized = 1;
- gnc_log_init();
-
+ /* initialize logging to our file. */
+ qof_log_init_filename("/tmp/gnucash.trace");
+ /* Only set the core log_modules here
+ the rest can be set locally. */
+ gnc_set_log_level(GNC_MOD_ENGINE, GNC_LOG_WARNING);
+ gnc_set_log_level(GNC_MOD_IO, GNC_LOG_WARNING);
+ gnc_set_log_level(GNC_MOD_GUI, GNC_LOG_WARNING);
+ qof_log_set_default(GNC_LOG_WARNING);
/* initialize the string cache */
gnc_engine_get_string_cache();
@@ -127,6 +127,7 @@
qof_object_shutdown ();
guid_shutdown();
gnc_engine_string_cache_destroy ();
+ qof_log_shutdown();
}
/********************************************************************
Index: qofbook.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofbook.h,v
retrieving revision 1.5.2.8
retrieving revision 1.5.2.9
diff -Lsrc/engine/qofbook.h -Lsrc/engine/qofbook.h -u -r1.5.2.8 -r1.5.2.9
--- src/engine/qofbook.h
+++ src/engine/qofbook.h
@@ -41,9 +41,7 @@
#define QOF_BOOK_H
#include <glib.h>
-
#include "qofid.h"
-//#include "qofbackend.h"
#include "kvp_frame.h"
/** @brief Encapsulates all the information about a dataset
@@ -81,6 +79,13 @@
associated with it. */
void qof_book_destroy (QofBook *book);
+/** Close a book to editing.
+
+It is up to the application to check this flag,
+and once marked closed, books cannnot be marked as open.
+*/
+void qof_book_mark_closed (QofBook *book);
+
/** \return The table of entities of the given type.
*
* When an object's constructor calls qof_instance_init(), a
Index: qofbook.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofbook.c,v
retrieving revision 1.10.2.7
retrieving revision 1.10.2.8
diff -Lsrc/engine/qofbook.c -Lsrc/engine/qofbook.c -u -r1.10.2.7 -r1.10.2.8
--- src/engine/qofbook.c
+++ src/engine/qofbook.c
@@ -53,7 +53,7 @@
#include "guid.h"
-static short module = MOD_ENGINE;
+static QofLogModule log_module = QOF_MOD_ENGINE;
/* ====================================================================== */
/* constructor / destructor */
@@ -191,6 +191,7 @@
if (!book) return;
ENTER ("book=%p be=%p", book, be);
book->backend = be;
+ LEAVE (" ");
}
void qof_book_kvp_changed (QofBook *book)
@@ -279,6 +280,12 @@
/* ====================================================================== */
+void qof_book_mark_closed (QofBook *book)
+{
+ if(!book) { return; }
+ book->book_open = 'n';
+}
+
gint64
qof_book_get_counter (QofBook *book, const char *counter_name)
{
Index: gnc-pricedb.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-pricedb.c,v
retrieving revision 1.48.4.10
retrieving revision 1.48.4.11
diff -Lsrc/engine/gnc-pricedb.c -Lsrc/engine/gnc-pricedb.c -u -r1.48.4.10 -r1.48.4.11
--- src/engine/gnc-pricedb.c
+++ src/engine/gnc-pricedb.c
@@ -26,28 +26,10 @@
#include <glib.h>
#include <string.h>
-
-#include "gnc-engine.h"
-#include "gnc-engine-util.h"
-#include "gnc-event.h"
#include "gnc-pricedb-p.h"
-#include "gnc-trace.h"
-#include "guid.h"
-#include "kvp-util.h"
-
-#include "qofbackend-p.h"
-#include "qof-be-utils.h"
-/** \todo fix backend price_lookup using define gnucash major version
-and remove the private book header. */
-#ifdef GNUCASH_MAJOR_VERSION
-#include "qofbook-p.h"
-#endif
-#include "qofclass.h"
-#include "qofid-p.h"
-#include "qofobject.h"
/* This static indicates the debugging module that this .o belongs to. */
-static short module = MOD_PRICE;
+static QofLogModule log_module = GNC_MOD_PRICE;
static gboolean add_price(GNCPriceDB *db, GNCPrice *p);
static gboolean remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup);
@@ -991,6 +973,7 @@
/* ==================================================================== */
/* lookup/query functions */
+
/** \todo Fix the backend lookup that relies on a \#define */
GNCPrice *
gnc_pricedb_lookup_latest(GNCPriceDB *db,
@@ -1000,19 +983,22 @@
GList *price_list;
GNCPrice *result;
GHashTable *currency_hash;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p currency=%p", db, commodity, currency);
if(!db || !commodity || !currency) return NULL;
-/** \todo QOF spinout: fix book->backend price_lookup in gnucash */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_LATEST;
pl.prdb = db;
pl.commodity = commodity;
pl.currency = currency;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
@@ -1051,21 +1037,24 @@
{
GList *result;
GHashTable *currency_hash;
+ QofBook *book;
+ QofBackend *be;
result = NULL;
ENTER ("db=%p commodity=%p", db, commodity);
if(!db || !commodity) return NULL;
-/** \todo QOF spinout: Fix the book->backend lookup */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_LATEST;
pl.prdb = db;
pl.commodity = commodity;
pl.currency = NULL; /* can the backend handle this??? */
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, commodity);
@@ -1097,19 +1086,22 @@
GList *price_list;
GHashTable *currency_hash;
gint size;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p currency=%p", db, commodity, currency);
if(!db || !commodity) return FALSE;
-/** \todo QOF spinout: Fix the book->backend lookup */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book && db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (book && be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_ALL;
pl.prdb = db;
pl.commodity = commodity;
pl.currency = currency;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, commodity);
@@ -1143,19 +1135,22 @@
GList *result;
GList *node;
GHashTable *currency_hash;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p currency=%p", db, commodity, currency);
if(!db || !commodity) return NULL;
-/** \todo QOF spinout: Fix the book->backend lookup */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_ALL;
pl.prdb = db;
pl.commodity = commodity;
pl.currency = currency;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, commodity);
@@ -1187,15 +1182,17 @@
GList *result = NULL;
GList *item = NULL;
GHashTable *currency_hash;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p currency=%p", db, c, currency);
if(!db || !c || !currency) return NULL;
-
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
/* Convert to noon local time. */
t = timespecCanonicalDayTime(t);
-/** \todo QOF spinout: Fix the book->backend lookup */
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_AT_TIME;
@@ -1203,7 +1200,7 @@
pl.commodity = c;
pl.currency = currency;
pl.date = t;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, c);
@@ -1256,15 +1253,17 @@
GList *result = NULL;
GHashTable *currency_hash;
GNCPriceLookupHelper lookup_helper;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p", db, c);
if(!db || !c) return NULL;
-
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
/* Convert to noon local time. */
t = timespecCanonicalDayTime(t);
-/** \todo QOF spinout: Fix the book->backend lookup */
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_AT_TIME;
@@ -1272,7 +1271,7 @@
pl.commodity = c;
pl.currency = NULL; /* can the backend handle this??? */
pl.date = t;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, c);
@@ -1301,12 +1300,15 @@
GList *result = NULL;
GList *item = NULL;
GHashTable *currency_hash;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p currency=%p", db, c, currency);
if(!db || !c || !currency) return NULL;
-/** \todo QOF spinout: Fix the book->backend lookup */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_AT_TIME;
@@ -1314,7 +1316,7 @@
pl.commodity = c;
pl.currency = currency;
pl.date = t;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, c);
@@ -1366,12 +1368,15 @@
GList *result = NULL;
GHashTable *currency_hash;
GNCPriceLookupHelper lookup_helper;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p", db, c);
if(!db || !c) return NULL;
-/** \todo QOF spinout: Fix the book->backend lookup */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_AT_TIME;
@@ -1379,7 +1384,7 @@
pl.commodity = c;
pl.currency = NULL; /* can the backend handle this??? */
pl.date = t;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, c);
@@ -1410,12 +1415,15 @@
GNCPrice *result = NULL;
GList *item = NULL;
GHashTable *currency_hash;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p currency=%p", db, c, currency);
if(!db || !c || !currency) return NULL;
-/** \todo QOF spinout: Fix the book->backend lookup */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_NEAREST_IN_TIME;
@@ -1423,7 +1431,7 @@
pl.commodity = c;
pl.currency = currency;
pl.date = t;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, c);
@@ -1535,12 +1543,15 @@
GList *result = NULL;
GHashTable *currency_hash;
GNCPriceLookupHelper lookup_helper;
+ QofBook *book;
+ QofBackend *be;
ENTER ("db=%p commodity=%p", db, c);
if(!db || !c) return NULL;
-/** \todo QOF spinout: Fix the book->backend lookup */
+ book = qof_instance_get_book(&db->inst);
+ be = qof_book_get_backend(book);
#ifdef GNUCASH_MAJOR_VERSION
- if (db->inst.book->backend && db->inst.book->backend->price_lookup)
+ if (be && be->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_NEAREST_IN_TIME;
@@ -1548,7 +1559,7 @@
pl.commodity = c;
pl.currency = NULL; /* can the backend handle this??? */
pl.date = t;
- (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl);
+ (be->price_lookup) (be, &pl);
}
#endif
currency_hash = g_hash_table_lookup(db->commodity_hash, c);
More information about the gnucash-changes
mailing list