[Gnucash-changes] checkpoint partially working code
Linas Vepstas
linas at cvs.gnucash.org
Sat Jun 12 23:33:23 EDT 2004
Log Message:
-----------
checkpoint partially working code
Tags:
----
backend-work-1
Modified Files:
--------------
gnucash/src/engine:
Account.c
Period.c
Transaction.c
gnc-pricedb-p.h
gnc-pricedb.c
qofbackend-p.h
Added Files:
-----------
gnucash/src/engine:
qof-be-utils.h
Removed Files:
-------------
gnucash/src/engine:
gnc-be-utils.h
Revision Data
-------------
Index: gnc-pricedb-p.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-pricedb-p.h,v
retrieving revision 1.29
retrieving revision 1.29.2.1
diff -Lsrc/engine/gnc-pricedb-p.h -Lsrc/engine/gnc-pricedb-p.h -u -r1.29 -r1.29.2.1
--- src/engine/gnc-pricedb-p.h
+++ src/engine/gnc-pricedb-p.h
@@ -59,12 +59,8 @@
struct gnc_price_db_s
{
+ QofInstance inst; /* globally unique object identifier */
GHashTable *commodity_hash;
- QofBook *book; /* book holding this database and all its prices */
-
- /* 'private' object management fields */
- gint32 editlevel; /* nesting level of begin/end edit calls */
- gboolean dirty;
};
/* These structs define the kind of price lookup being done
Index: Transaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Transaction.c,v
retrieving revision 1.309
retrieving revision 1.309.2.1
diff -Lsrc/engine/Transaction.c -Lsrc/engine/Transaction.c -u -r1.309 -r1.309.2.1
--- src/engine/Transaction.c
+++ src/engine/Transaction.c
@@ -38,7 +38,6 @@
#include "TransactionP.h"
#include "TransLog.h"
#include "cap-gains.h"
-#include "gnc-be-utils.h"
#include "gnc-commodity.h"
#include "gnc-date.h"
#include "gnc-engine-util.h"
@@ -50,6 +49,7 @@
#include "messages.h"
#include "qofbackend-p.h"
+#include "qof-be-utils.h"
#include "qofbook.h"
#include "qofbook-p.h"
#include "qofclass.h"
@@ -1461,7 +1461,7 @@
void
xaccTransBeginEdit (Transaction *trans)
{
- GNC_BEGIN_EDIT(&trans->inst)
+ QOF_BEGIN_EDIT(&trans->inst)
if (qof_book_shutting_down(trans->inst.book))
return;
@@ -1560,7 +1560,7 @@
xaccTransCommitEdit (Transaction *trans)
{
QofBackend *be;
- GNC_COMMIT_EDIT_PART1 (&trans->inst);
+ QOF_COMMIT_EDIT_PART1 (&trans->inst);
/* We increment this for the duration of the call
* so other functions don't result in a recursive
@@ -1600,7 +1600,7 @@
if (!trans->splits) trans->inst.do_free = TRUE;
/* XXX the code below is almost identical to
- * GNC_COMMIT_EDIT_PART1 (&trans->inst);
+ * QOF_COMMIT_EDIT_PART1 (&trans->inst);
* except for the rollback bits */
/* See if there's a backend. If there is, invoke it. */
be = qof_book_get_backend (trans->inst.book);
@@ -1613,7 +1613,7 @@
errcode = qof_backend_get_error (be);
} while (ERR_BACKEND_NO_ERR != errcode);
- (be->commit) (be, GNC_ID_TRANS, trans);
+ (be->commit) (be, &(trans->inst));
errcode = qof_backend_get_error (be);
if (ERR_BACKEND_NO_ERR != errcode)
@@ -1682,7 +1682,7 @@
int i;
ENTER ("trans addr=%p\n", trans);
- GNC_COMMIT_EDIT_PART1(&trans->inst);
+ QOF_COMMIT_EDIT_PART1(&trans->inst);
/* We increment this for the duration of the call
* so other functions don't result in a recursive
@@ -1852,7 +1852,7 @@
errcode = qof_backend_get_error (be);
} while (ERR_BACKEND_NO_ERR != errcode);
- (be->rollback) (be, GNC_ID_TRANS, trans);
+ (be->rollback) (be, &(trans->inst));
errcode = qof_backend_get_error (be);
if (ERR_BACKEND_MOD_DESTROY == errcode)
Index: qofbackend-p.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofbackend-p.h,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -Lsrc/engine/qofbackend-p.h -Lsrc/engine/qofbackend-p.h -u -r1.3 -r1.3.2.1
--- src/engine/qofbackend-p.h
+++ src/engine/qofbackend-p.h
@@ -234,9 +234,9 @@
void (*load) (QofBackend *, QofBook *);
- void (*begin) (QofBackend *, QofIdTypeConst, gpointer);
- void (*commit) (QofBackend *, QofIdTypeConst, gpointer);
- void (*rollback) (QofBackend *, QofIdTypeConst, gpointer);
+ void (*begin) (QofBackend *, QofInstance *);
+ void (*commit) (QofBackend *, QofInstance *);
+ void (*rollback) (QofBackend *, QofInstance *);
gpointer (*compile_query) (QofBackend *, QofQuery *);
void (*free_query) (QofBackend *, gpointer);
Index: Account.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Account.c,v
retrieving revision 1.273
retrieving revision 1.273.2.1
diff -Lsrc/engine/Account.c -Lsrc/engine/Account.c -u -r1.273 -r1.273.2.1
--- src/engine/Account.c
+++ src/engine/Account.c
@@ -32,7 +32,6 @@
#include "Group.h"
#include "GroupP.h"
#include "TransactionP.h"
-#include "gnc-be-utils.h"
#include "gnc-date.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
@@ -48,6 +47,7 @@
#include "qofbackend.h"
#include "qofbackend-p.h"
+#include "qof-be-utils.h"
#include "qofbook.h"
#include "qofbook-p.h"
#include "qofclass.h"
@@ -318,7 +318,7 @@
void
xaccAccountBeginEdit (Account *acc)
{
- GNC_BEGIN_EDIT (&acc->inst);
+ QOF_BEGIN_EDIT (&acc->inst);
}
static inline void noop(QofInstance *inst) {}
@@ -338,7 +338,7 @@
void
xaccAccountCommitEdit (Account *acc)
{
- GNC_COMMIT_EDIT_PART1 (&acc->inst);
+ QOF_COMMIT_EDIT_PART1 (&acc->inst);
/* If marked for deletion, get rid of subaccounts first,
* and then the splits ... */
@@ -385,7 +385,7 @@
xaccGroupInsertAccount(acc->parent, acc);
}
- GNC_COMMIT_EDIT_PART2 (&acc->inst, on_err, noop, acc_free);
+ QOF_COMMIT_EDIT_PART2 (&acc->inst, on_err, noop, acc_free);
gnc_engine_gen_event (&acc->inst.entity, GNC_EVENT_MODIFY);
}
--- /dev/null
+++ src/engine/qof-be-utils.h
@@ -0,0 +1,168 @@
+/********************************************************************\
+ * qof-be-utils.h: api for data storage backend *
+ * 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 *
+ * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
+ * Boston, MA 02111-1307, USA gnu at gnu.org *
+ * *
+\********************************************************************/
+/** @addtogroup Object
+ @{ */
+/** @addtogroup Backend
+ * @{
+ * @file gnc-be-utils.h
+ * @brief QOF Backend Utilities
+ * @author Derek Atkins <derek at ihtfp.com>
+ * Common code used by objects to define begin_edit() and
+ * commit_edit() functions.
+ *
+ */
+
+#ifndef QOF_BE_UTILS_H
+#define QOF_BE_UTILS_H
+
+#include "gnc-engine-util.h"
+#include "qofbackend-p.h"
+#include "qofbook.h"
+
+/** begin_edit helper
+ *
+ * @args:
+ * inst: an instance of QofInstance
+ *
+ * The caller should use this macro first and then perform any other operations.
+ */
+
+#define QOF_BEGIN_EDIT(inst) \
+ QofBackend * be; \
+ if (!(inst)) return; \
+ \
+ (inst)->editlevel++; \
+ if (1 < (inst)->editlevel) return; \
+ \
+ if (0 >= (inst)->editlevel) \
+ { \
+ PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
+ (inst)->editlevel = 1; \
+ } \
+ ENTER ("inst=%p", (inst)); \
+ \
+ /* See if there's a backend. If there is, invoke it. */ \
+ be = qof_book_get_backend ((inst)->book); \
+ if (be && be->begin) { \
+ (be->begin) (be, (inst)); \
+ } else { \
+ /* We tried and failed to start transaction! */ \
+ (inst)->dirty = TRUE; \
+ }
+
+
+/**
+ * commit_edit helpers
+ *
+ * The caller should call PART1 as the first thing, then
+ * perform any local operations prior to calling the backend.
+ * Then call PART2.
+ */
+
+/**
+ * part1 -- deal with the editlevel
+ *
+ * @args:
+ * inst: an instance of QofInstance
+ */
+
+#define QOF_COMMIT_EDIT_PART1(inst) { \
+ if (!(inst)) return; \
+ \
+ (inst)->editlevel--; \
+ if (0 < (inst)->editlevel) return; \
+ \
+ /* The pricedb sufffers from delayed update... */ \
+ /* This may be setting a bad precedent for other types, I fear. */ \
+ /* Other types probably really should handle begin like this. */ \
+ if ((-1 == (inst)->editlevel) && (inst)->dirty) \
+ { \
+ QofBackend * be; \
+ be = qof_book_get_backend ((inst)->book); \
+ if (be && be->begin) { \
+ (be->begin) (be, (inst)); \
+ } \
+ (inst)->editlevel = 0; \
+ } \
+ if (0 > (inst)->editlevel) \
+ { \
+ PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
+ (inst)->editlevel = 0; \
+ } \
+ ENTER ("inst=%p, dirty=%d do-free=%d", \
+ (inst), (inst)->dirty, (inst)->do_free); \
+}
+
+/**
+ * part2 -- deal with the backend
+ *
+ * @args:
+ * inst: an instance of QofInstance
+ * on_error: a function called if there is a backend error.
+ * void (*on_error)(inst, QofBackendError)
+ * on_done: a function called after the commit is complete
+ * but before the instect is freed. Perform any other
+ * operations after the commit.
+ * void (*on_done)(inst)
+ * on_free: a function called if inst->do_free is TRUE.
+ * void (*on_free)(inst)
+ */
+#define QOF_COMMIT_EDIT_PART2(inst,on_error,on_done,on_free) { \
+ QofBackend * be; \
+ \
+ /* See if there's a backend. If there is, invoke it. */ \
+ be = qof_book_get_backend ((inst)->book); \
+ if (be && be->commit) \
+ { \
+ QofBackendError errcode; \
+ \
+ /* clear errors */ \
+ do { \
+ errcode = qof_backend_get_error (be); \
+ } while (ERR_BACKEND_NO_ERR != errcode); \
+ \
+ (be->commit) (be, (inst)); \
+ errcode = qof_backend_get_error (be); \
+ if (ERR_BACKEND_NO_ERR != errcode) \
+ { \
+ /* XXX Should perform a rollback here */ \
+ (inst)->do_free = FALSE; \
+ \
+ /* Push error back onto the stack */ \
+ qof_backend_set_error (be, errcode); \
+ (on_error)((inst), errcode); \
+ } \
+ /* XXX the backend commit code should clear dirty!! */ \
+ (inst)->dirty = FALSE; \
+ } \
+ (on_done)(inst); \
+ \
+ LEAVE ("inst=%p, dirty=%d do-free=%d", \
+ (inst), (inst)->dirty, (inst)->do_free); \
+ if ((inst)->do_free) { \
+ (on_free)(inst); \
+ return; \
+ } \
+}
+
+#endif /* QOF_BE_UTILS_H */
+/** @} */
+/** @} */
Index: Period.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Period.c,v
retrieving revision 1.59
retrieving revision 1.59.4.1
diff -Lsrc/engine/Period.c -Lsrc/engine/Period.c -u -r1.59 -r1.59.4.1
--- src/engine/Period.c
+++ src/engine/Period.c
@@ -805,7 +805,7 @@
be = src_book->backend;
if (be && be->begin)
{
- (*be->begin)(be, GNC_ID_PERIOD, dest_book);
+ // (*be->begin)(be, GNC_ID_PERIOD, dest_book);
}
}
@@ -816,7 +816,7 @@
be = src_book->backend;
if (be && be->commit)
{
- (*be->commit)(be, GNC_ID_PERIOD, dest_book);
+ // (*be->commit)(be, GNC_ID_PERIOD, dest_book);
}
}
Index: gnc-pricedb.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-pricedb.c,v
retrieving revision 1.75
retrieving revision 1.75.2.1
diff -Lsrc/engine/gnc-pricedb.c -Lsrc/engine/gnc-pricedb.c -u -r1.75 -r1.75.2.1
--- src/engine/gnc-pricedb.c
+++ src/engine/gnc-pricedb.c
@@ -27,7 +27,6 @@
#include <glib.h>
#include <string.h>
-#include "gnc-be-utils.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "gnc-event-p.h"
@@ -37,6 +36,7 @@
#include "kvp-util.h"
#include "qofbackend-p.h"
+#include "qof-be-utils.h"
#include "qofbook.h"
#include "qofbook-p.h"
#include "qofclass.h"
@@ -154,7 +154,7 @@
void
gnc_price_begin_edit (GNCPrice *p)
{
- GNC_BEGIN_EDIT (&p->inst);
+ QOF_BEGIN_EDIT (&p->inst);
}
static inline void commit_err (QofInstance *inst, QofBackendError errcode)
@@ -167,8 +167,8 @@
void
gnc_price_commit_edit (GNCPrice *p)
{
- GNC_COMMIT_EDIT_PART1 (&p->inst);
- GNC_COMMIT_EDIT_PART2 (&p->inst, commit_err, noop, noop);
+ QOF_COMMIT_EDIT_PART1 (&p->inst);
+ QOF_COMMIT_EDIT_PART2 (&p->inst, commit_err, noop, noop);
}
/* ==================================================================== */
@@ -193,7 +193,7 @@
be = xaccPriceDBGetBackend (pdb);
if (be && be->begin)
{
- (be->begin) (be, GNC_ID_PRICEDB, pdb);
+ (be->begin) (be, &(pdb->inst));
}
LEAVE ("pdb=%p\n", pdb);
--- src/engine/gnc-be-utils.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/********************************************************************\
- * gnc-be-utils.h: api for data storage backend *
- * 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 *
- * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
- * Boston, MA 02111-1307, USA gnu at gnu.org *
- * *
-\********************************************************************/
-/*
- * gnc-be-utils.h -- QOF Backend Utilities
- * common code used by objects to define begin_edit() and
- * commit_edit() functions.
- *
- * Written by: Derek Atkins <derek at ihtfp.com>
- *
- */
-
-#ifndef GNC_BE_UTILS_H
-#define GNC_BE_UTILS_H
-
-#include "gnc-engine-util.h"
-#include "qofbackend-p.h"
-#include "qofbook.h"
-
-/* begin_edit helper
- *
- * @args:
- * inst: an instance of QofInstance
- *
- * The caller should use this macro first and then perform any other operations.
- */
-
-#define GNC_BEGIN_EDIT(inst) \
- QofBackend * be; \
- if (!(inst)) return; \
- \
- (inst)->editlevel++; \
- if (1 < (inst)->editlevel) return; \
- \
- if (0 >= (inst)->editlevel) \
- { \
- PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
- (inst)->editlevel = 1; \
- } \
- ENTER ("inst=%p", (inst)); \
- \
- /* See if there's a backend. If there is, invoke it. */ \
- be = qof_book_get_backend ((inst)->book); \
- if (be && be->begin) { \
- (be->begin) (be, (inst)->entity.e_type, (inst)); \
- } else { \
- /* We tried and failed to start transaction! */ \
- (inst)->dirty = TRUE; \
- }
-
-
-/*
- * commit_edit helpers
- *
- * The caller should call PART1 as the first thing, then
- * perform any local operations prior to calling the backend.
- * Then call PART2.
- */
-
-/*
- * part1 -- deal with the editlevel
- *
- * @args:
- * inst: an instance of QofInstance
- */
-
-#define GNC_COMMIT_EDIT_PART1(inst) { \
- if (!(inst)) return; \
- \
- (inst)->editlevel--; \
- if (0 < (inst)->editlevel) return; \
- \
- /* The pricedb sufffers from delayed update... */ \
- /* This may be setting a bad precedent for other types, I fear. */ \
- /* Other types probably really should handle begin like this. */ \
- if ((-1 == (inst)->editlevel) && (inst)->dirty) \
- { \
- QofBackend * be; \
- be = qof_book_get_backend ((inst)->book); \
- if (be && be->begin) { \
- (be->begin) (be, (inst)->entity.e_type, (inst)); \
- } \
- (inst)->editlevel = 0; \
- } \
- if (0 > (inst)->editlevel) \
- { \
- PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
- (inst)->editlevel = 0; \
- } \
- ENTER ("inst=%p, dirty=%d do-free=%d", \
- (inst), (inst)->dirty, (inst)->do_free); \
-}
-
-/*
- * part2 -- deal with the backend
- *
- * @args:
- * inst: an instance of QofInstance
- * on_error: a function called if there is a backend error.
- * void (*on_error)(inst, QofBackendError)
- * on_done: a function called after the commit is complete
- * but before the instect is freed. Perform any other
- * operations after the commit.
- * void (*on_done)(inst)
- * on_free: a function called if inst->do_free is TRUE.
- * void (*on_free)(inst)
- */
-#define GNC_COMMIT_EDIT_PART2(inst,on_error,on_done,on_free) { \
- QofBackend * be; \
- \
- /* See if there's a backend. If there is, invoke it. */ \
- be = qof_book_get_backend ((inst)->book); \
- if (be && be->commit) \
- { \
- QofBackendError errcode; \
- \
- /* clear errors */ \
- do { \
- errcode = qof_backend_get_error (be); \
- } while (ERR_BACKEND_NO_ERR != errcode); \
- \
- (be->commit) (be, (inst)->entity.e_type, (inst)); \
- errcode = qof_backend_get_error (be); \
- if (ERR_BACKEND_NO_ERR != errcode) \
- { \
- /* XXX Should perform a rollback here */ \
- (inst)->do_free = FALSE; \
- \
- /* Push error back onto the stack */ \
- qof_backend_set_error (be, errcode); \
- (on_error)((inst), errcode); \
- } \
- /* XXX the backend commit code should clear dirty!! */ \
- (inst)->dirty = FALSE; \
- } \
- (on_done)(inst); \
- \
- LEAVE ("inst=%p, dirty=%d do-free=%d", \
- (inst), (inst)->dirty, (inst)->do_free); \
- if ((inst)->do_free) { \
- (on_free)(inst); \
- return; \
- } \
-}
-
-
-#endif /* GNC_BE_UTILS_H */
More information about the gnucash-changes
mailing list