Start putting an API in place for access to the members of the

QofInstance object.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16025 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2007-04-30 05:33:33 +00:00
parent 05f60bd341
commit ce65024722
22 changed files with 201 additions and 101 deletions

View File

@ -132,13 +132,6 @@ qof_instance_get_guid (const QofInstance *inst)
return &(inst->guid);
}
QofBook *
qof_instance_get_book (const QofInstance *inst)
{
if (!inst) return NULL;
return inst->book;
}
void
qof_instance_set_guid (QofInstance *ent, const GUID *guid)
{
@ -151,6 +144,20 @@ qof_instance_set_guid (QofInstance *ent, const GUID *guid)
qof_collection_insert_entity(col, ent);
}
const QofCollection *
qof_instance_get_collection (gconstpointer ptr)
{
g_return_val_if_fail(QOF_IS_INSTANCE(ptr), NULL);
return QOF_INSTANCE(ptr)->collection;
}
QofBook *
qof_instance_get_book (const QofInstance *inst)
{
if (!inst) return NULL;
return inst->book;
}
KvpFrame*
qof_instance_get_slots (const QofInstance *inst)
{
@ -169,6 +176,38 @@ qof_instance_get_last_update (const QofInstance *inst)
return inst->last_update;
}
gint
qof_instance_get_editlevel (gconstpointer ptr)
{
g_return_val_if_fail(QOF_IS_INSTANCE(ptr), 0);
return QOF_INSTANCE(ptr)->editlevel;
}
void qof_instance_increase_editlevel (gpointer ptr)
{
g_return_if_fail(QOF_IS_INSTANCE(ptr));
QOF_INSTANCE(ptr)->editlevel++;
}
void qof_instance_decrease_editlevel (gpointer ptr)
{
g_return_if_fail(QOF_IS_INSTANCE(ptr));
QOF_INSTANCE(ptr)->editlevel--;
}
void qof_instance_reset_editlevel (gpointer ptr)
{
g_return_if_fail(QOF_IS_INSTANCE(ptr));
QOF_INSTANCE(ptr)->editlevel = 0;
}
gboolean
qof_instance_check_edit(const QofInstance *inst)
{
g_return_val_if_fail(QOF_IS_INSTANCE(inst), FALSE);
return (inst->editlevel > 0);
}
int
qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
{
@ -182,6 +221,27 @@ qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
return 0;
}
gboolean
qof_instance_get_destroying (gconstpointer ptr)
{
g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
return QOF_INSTANCE(ptr)->do_free;
}
void
qof_instance_set_destroying (gpointer ptr, gboolean value)
{
g_return_if_fail(QOF_IS_INSTANCE(ptr));
QOF_INSTANCE(ptr)->do_free = value;
}
gboolean
qof_instance_get_dirty_flag (gconstpointer ptr)
{
g_return_val_if_fail(QOF_IS_INSTANCE(ptr), FALSE);
return QOF_INSTANCE(ptr)->dirty;
}
void
qof_instance_print_dirty (const QofInstance *entity, gpointer dummy)
{
@ -218,13 +278,6 @@ qof_instance_set_dirty(QofInstance* inst)
}
}
gboolean
qof_instance_check_edit(const QofInstance *inst)
{
if(inst->editlevel > 0) { return TRUE; }
return FALSE;
}
gboolean
qof_instance_do_free(const QofInstance *inst)
{

View File

@ -119,6 +119,9 @@ QofBook * qof_instance_get_book (const QofInstance *);
/** Return the GUID of this instance */
const GUID * qof_instance_get_guid (const QofInstance *);
/** Return the collection this instance belongs to */
const QofCollection* qof_instance_get_collection (gconstpointer inst);
/** Set the GUID of this instance */
void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
@ -133,6 +136,11 @@ KvpFrame* qof_instance_get_slots (const QofInstance *);
*/
Timespec qof_instance_get_last_update (const QofInstance *inst);
gint qof_instance_get_editlevel (gconstpointer ptr);
void qof_instance_increase_editlevel (gpointer ptr);
void qof_instance_decrease_editlevel (gpointer ptr);
void qof_instance_reset_editlevel (gpointer ptr);
/** Compare two instances, based on thier last update times.
* Returns a negative, zero or positive value, respectively,
* if 'left' is earlier, same as or later than 'right'.
@ -141,6 +149,37 @@ Timespec qof_instance_get_last_update (const QofInstance *inst);
*/
int qof_instance_version_cmp (const QofInstance *left, const QofInstance *right);
/** Retrieve the flag that indicates whether or not this object is
* about to be destroyed.
*
* @param ptr The object whose flag should be retrieved.
*
* @return TRUE if the object has been marked for destruction. FALSE
* if the object is not marked for destruction, or if a bad parameter
* is passed to the function. */
gboolean qof_instance_get_destroying (gconstpointer ptr);
/** Set the flag that indicates whether or not this object is about to
* be destroyed.
*
* @param ptr The object whose flag should be set.
*
* @param value The new value to be set for this object. */
void qof_instance_set_destroying (gpointer ptr, gboolean value);
/** Retrieve the flag that indicates whether or not this object has
* been modified. This is specifically the flag on the object. It
* does not perform any other checking which might normally be
* performed when testing to see if an object is dirty. If there is
* any question, use the qof_instance_is_dirty() function instead.
*
* @param ptr The object whose flag should be retrieved.
*
* @return TRUE if the object has been modified and not saved. FALSE
* if the object has not been modified, or if a bad parameter is
* passed to the function. */
gboolean qof_instance_get_dirty_flag (gconstpointer ptr);
void qof_instance_print_dirty (const QofInstance *entity, gpointer dummy);
/** Return value of is_dirty flag */

View File

@ -81,7 +81,8 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct,
const gnc_commodity *com;
if (!be || !acct) return;
if ((FALSE == do_mark) && (FALSE == acct->inst.dirty)) return;
if ((FALSE == do_mark) && (!qof_instance_get_dirty_flag(acct)))
return;
ENTER ("acct=%p, mark=%d", acct, do_mark);
@ -556,7 +557,7 @@ pgend_account_commit_edit (QofBackend * bend,
ENTER ("be=%p, acct=%p", be, acct);
if (!be || !acct) return;
if (FALSE == acct->inst.dirty)
if (!qof_instance_get_dirty_flag(acct))
{
LEAVE ("account not written because not dirty");
return;
@ -576,7 +577,7 @@ pgend_account_commit_edit (QofBackend * bend,
* made changes, and we must roll back. */
if (0 < pgendAccountCompareVersion (be, acct))
{
acct->inst.do_free = FALSE;
qof_instance_set_destroying(acct, FALSE);
p = "ROLLBACK;";
SEND_QUERY (be,p,);
FINISH_QUERY(be->connection);
@ -593,7 +594,7 @@ pgend_account_commit_edit (QofBackend * bend,
gnc_account_increment_version(acct); /* be sure to update the version !! */
gnc_account_set_version_check(acct, be->version_check);
if (acct->inst.do_free)
if (qof_instance_get_destroying(acct))
{
const GUID *guid = xaccAccountGetGUID(acct);
pgendKVPDelete (be, acct->idata);

View File

@ -452,7 +452,7 @@ pgendPriceFind (QofBackend *bend, gpointer olook)
void
pgend_price_begin_edit (QofBackend * bend, GNCPrice *pr)
{
if (pr && pr->db && pr->db->inst.dirty)
if (pr && pr->db && qof_instance_get_dirty_flag(pr->db))
{
PERR ("price db is unexpectedly dirty");
}
@ -479,7 +479,7 @@ pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr)
* made changes, and we must roll back. */
if (0 < pgendPriceCompareVersion (be, pr))
{
pr->inst.do_free = FALSE;
qof_instance_set_destroying(pr, FALSE);
bufp = "ROLLBACK;";
SEND_QUERY (be,bufp,);
FINISH_QUERY(be->connection);
@ -496,7 +496,7 @@ pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr)
pr->version ++; /* be sure to update the version !! */
pr->version_check = be->version_check;
if (pr->inst.do_free)
if (qof_instance_get_destroying(pr))
{
pgendStoreAuditPrice (be, pr, SQL_DELETE);
bufp = be->buff; *bufp = 0;

View File

@ -211,8 +211,9 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
/* Update the rest */
start = xaccTransGetSplitList(trans);
PINFO ("split-list=%p, do_free=%d", start, trans->inst.do_free);
if ((start) && !(trans->inst.do_free))
PINFO ("split-list=%p, destroying=%d", start,
qof_instance_get_destroying(trans));
if ((start) && !qof_instance_get_destroying(trans))
{
gnc_commodity *com;
@ -977,7 +978,7 @@ pgend_trans_commit_edit (QofBackend * bend,
"\ttransaction is '%s' %s\n",
xaccTransGetDescription (trans), buf);
rollback = 0;
trans->inst.do_free = TRUE;
qof_instance_set_destroying(trans, TRUE);
}
else
{

View File

@ -163,7 +163,7 @@ void
gncAddressDestroy (GncAddress *addr)
{
if (!addr) return;
addr->inst.do_free = TRUE;
qof_instance_set_destroying(addr, TRUE);
gncAddressCommitEdit (addr);
}

View File

@ -120,14 +120,14 @@ static inline void remObj (GncBillTerm *term)
static inline void
gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child)
{
g_return_if_fail(table->inst.do_free == FALSE);
g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
table->children = g_list_prepend(table->children, child);
}
static inline void
gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child)
{
if (table->inst.do_free) return;
if (qof_instance_get_destroying(table)) return;
table->children = g_list_remove(table->children, child);
}
@ -172,7 +172,7 @@ void gncBillTermDestroy (GncBillTerm *term)
if (!term) return;
DEBUG("destroying bill term %s (%p)",
guid_to_string(qof_instance_get_guid(&term->inst)), term);
term->inst.do_free = TRUE;
qof_instance_set_destroying(term, TRUE);
qof_instance_set_dirty (&term->inst);
gncBillTermCommitEdit (term);
}
@ -189,7 +189,7 @@ static void gncBillTermFree (GncBillTerm *term)
CACHE_REMOVE (term->desc);
remObj (term);
if (!term->inst.do_free)
if (!qof_instance_get_destroying(term))
PERR("free a billterm without do_free set!");
/* disconnect from parent */
@ -592,7 +592,7 @@ int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b)
gboolean gncBillTermIsDirty (GncBillTerm *term)
{
if (!term) return FALSE;
return term->inst.dirty;
return qof_instance_get_dirty_flag(term);
}
/********************************************************/

View File

@ -181,7 +181,7 @@ gncCloneCustomer (GncCustomer *from, QofBook *book)
void gncCustomerDestroy (GncCustomer *cust)
{
if (!cust) return;
cust->inst.do_free = TRUE;
qof_instance_set_destroying(cust, TRUE);
qof_instance_set_dirty (&cust->inst);
gncCustomerCommitEdit (cust);
}

View File

@ -116,7 +116,7 @@ GncEmployee *gncEmployeeCreate (QofBook *book)
void gncEmployeeDestroy (GncEmployee *employee)
{
if (!employee) return;
employee->inst.do_free = TRUE;
qof_instance_set_destroying(employee, TRUE);
gncEmployeeCommitEdit(employee);
}
@ -362,7 +362,8 @@ Account * gncEmployeeGetCCard (GncEmployee *employee)
gboolean gncEmployeeIsDirty (GncEmployee *employee)
{
if (!employee) return FALSE;
return (employee->inst.dirty || gncAddressIsDirty (employee->addr));
return (qof_instance_get_dirty_flag(employee)
|| gncAddressIsDirty (employee->addr));
}
void gncEmployeeBeginEdit (GncEmployee *employee)

View File

@ -233,7 +233,7 @@ GncEntry *gncEntryCreate (QofBook *book)
void gncEntryDestroy (GncEntry *entry)
{
if (!entry) return;
entry->inst.do_free = TRUE;
qof_instance_set_destroying(entry, TRUE);
gncEntryCommitEdit(entry);
}
@ -1181,7 +1181,7 @@ gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv)
gboolean gncEntryIsOpen (GncEntry *entry)
{
if (!entry) return FALSE;
return (entry->inst.editlevel > 0);
return (qof_instance_get_editlevel(entry) > 0);
}
/* ================================================================ */

View File

@ -150,7 +150,7 @@ GncInvoice *gncInvoiceCreate (QofBook *book)
void gncInvoiceDestroy (GncInvoice *invoice)
{
if (!invoice) return;
invoice->inst.do_free = TRUE;
qof_instance_set_destroying(invoice, TRUE);
gncInvoiceCommitEdit (invoice);
}
@ -1522,7 +1522,7 @@ static const char * _gncInvoicePrintable (gpointer obj)
g_return_val_if_fail (invoice, NULL);
if (invoice->inst.dirty || invoice->printname == NULL) {
if (qof_instance_get_dirty_flag(invoice) || invoice->printname == NULL) {
if (invoice->printname) g_free (invoice->printname);
invoice->printname =

View File

@ -131,7 +131,7 @@ gncCloneJob (GncJob *from, QofBook *book)
void gncJobDestroy (GncJob *job)
{
if (!job) return;
job->inst.do_free = TRUE;
qof_instance_set_destroying(job, TRUE);
gncJobCommitEdit (job);
}

View File

@ -122,7 +122,7 @@ GncOrder *gncOrderCreate (QofBook *book)
void gncOrderDestroy (GncOrder *order)
{
if (!order) return;
order->inst.do_free = TRUE;
qof_instance_set_destroying(order, TRUE);
gncOrderCommitEdit (order);
}
@ -408,7 +408,7 @@ _gncOrderPrintable (gpointer obj)
g_return_val_if_fail (order, NULL);
if (order->inst.dirty || order->printname == NULL) {
if (qof_instance_get_dirty_flag(order) || order->printname == NULL) {
if (order->printname) g_free (order->printname);
order->printname =

View File

@ -188,7 +188,7 @@ gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child)
{
g_return_if_fail(table);
g_return_if_fail(child);
g_return_if_fail(table->inst.do_free == FALSE);
g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
table->children = g_list_prepend(table->children, child);
}
@ -199,7 +199,7 @@ gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child)
g_return_if_fail(table);
g_return_if_fail(child);
if (table->inst.do_free) return;
if (qof_instance_get_destroying(table)) return;
table->children = g_list_remove(table->children, child);
}
@ -309,7 +309,7 @@ void
gncTaxTableDestroy (GncTaxTable *table)
{
if (!table) return;
table->inst.do_free = TRUE;
qof_instance_set_destroying(table, TRUE);
qof_instance_set_dirty (&table->inst);
gncTaxTableCommitEdit (table);
}
@ -331,7 +331,7 @@ gncTaxTableFree (GncTaxTable *table)
gncTaxTableEntryDestroy (list->data);
g_list_free (table->entries);
if (!table->inst.do_free)
if (!qof_instance_get_destroying(table))
PERR("free a taxtable without do_free set!");
/* disconnect from parent */

View File

@ -121,7 +121,7 @@ GncVendor *gncVendorCreate (QofBook *book)
void gncVendorDestroy (GncVendor *vendor)
{
if (!vendor) return;
vendor->inst.do_free = TRUE;
qof_instance_set_destroying(vendor, TRUE);
gncVendorCommitEdit (vendor);
}
@ -504,7 +504,8 @@ GList * gncVendorGetJoblist (GncVendor *vendor, gboolean show_all)
gboolean gncVendorIsDirty (GncVendor *vendor)
{
if (!vendor) return FALSE;
return (vendor->inst.dirty || gncAddressIsDirty (vendor->addr));
return (qof_instance_get_dirty_flag(vendor)
|| gncAddressIsDirty (vendor->addr));
}
/* ============================================================== */

View File

@ -949,7 +949,7 @@ xaccFreeOneChildAccount (Account *acc, gpointer dummy)
{
/* FIXME: this code is kind of hacky. actually, all this code
* seems to assume that the account edit levels are all 1. */
if (acc->inst.editlevel == 0)
if (qof_instance_get_editlevel(acc) == 0)
xaccAccountBeginEdit(acc);
xaccAccountDestroy(acc);
}
@ -1021,7 +1021,7 @@ xaccFreeAccount (Account *acc)
PERR (" instead of calling xaccFreeAccount(), please call \n"
" xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
acc->inst.editlevel = 0;
qof_instance_reset_editlevel(acc);
slist = g_list_copy(priv->splits);
for (lp = slist; lp; lp = lp->next) {
@ -1113,12 +1113,12 @@ xaccAccountCommitEdit (Account *acc)
/* If marked for deletion, get rid of subaccounts first,
* and then the splits ... */
priv = GET_PRIVATE(acc);
if (acc->inst.do_free)
if (qof_instance_get_destroying(acc))
{
GList *lp, *slist;
QofCollection *col;
acc->inst.editlevel++;
qof_instance_increase_editlevel(acc);
/* First, recursively free children */
xaccFreeAccountChildren(acc);
@ -1156,7 +1156,7 @@ xaccAccountCommitEdit (Account *acc)
priv->lots = NULL;
qof_instance_set_dirty(&acc->inst);
acc->inst.editlevel--;
qof_instance_decrease_editlevel(acc);
}
else
{
@ -1171,7 +1171,7 @@ xaccAccountDestroy (Account *acc)
{
g_return_if_fail(GNC_IS_ACCOUNT(acc));
acc->inst.do_free = TRUE;
qof_instance_set_destroying(acc, TRUE);
xaccAccountCommitEdit (acc);
}
@ -1499,7 +1499,7 @@ gnc_account_set_sort_dirty (Account *acc)
g_return_if_fail(GNC_IS_ACCOUNT(acc));
if (acc->inst.do_free)
if (qof_instance_get_destroying(acc))
return;
priv = GET_PRIVATE(acc);
@ -1520,7 +1520,7 @@ gnc_account_set_balance_dirty (Account *acc)
g_return_if_fail(GNC_IS_ACCOUNT(acc));
if (acc->inst.do_free)
if (qof_instance_get_destroying(acc))
return;
priv = GET_PRIVATE(acc);
@ -1558,7 +1558,7 @@ gnc_account_insert_split (Account *acc, Split *s)
if (node)
return FALSE;
if (acc->inst.editlevel == 0) {
if (qof_instance_get_editlevel(acc) == 0) {
priv->splits = g_list_insert_sorted(priv->splits, s,
(GCompareFunc)xaccSplitOrder);
} else {
@ -1610,7 +1610,7 @@ xaccAccountSortSplits (Account *acc, gboolean force)
g_return_if_fail(GNC_IS_ACCOUNT(acc));
priv = GET_PRIVATE(acc);
if (!priv->sort_dirty || (!force && acc->inst.editlevel > 0))
if (!priv->sort_dirty || (!force && qof_instance_get_editlevel(acc) > 0))
return;
priv->splits = g_list_sort(priv->splits, (GCompareFunc)xaccSplitOrder);
priv->sort_dirty = FALSE;
@ -1892,9 +1892,9 @@ xaccAccountRecomputeBalance (Account * acc)
if (NULL == acc) return;
priv = GET_PRIVATE(acc);
if (acc->inst.editlevel > 0) return;
if (qof_instance_get_editlevel(acc) > 0) return;
if (!priv->balance_dirty) return;
if (acc->inst.do_free) return;
if (qof_instance_get_destroying(acc)) return;
if (qof_book_shutting_down(acc->inst.book)) return;
balance = priv->starting_balance;

View File

@ -412,7 +412,7 @@ restart:
Split *s = node->data;
if (xaccSplitGetLot (s) != lot) continue;
if (s == split) continue;
if (s->inst.do_free) continue;
if (qof_instance_get_destroying(s)) continue;
/* OK, this split is in the same lot (and thus same account)
* as the indicated split. Make sure it is really a subsplit

View File

@ -173,7 +173,6 @@ xaccDupeSplit (const Split *s)
* have to fix this up.
*/
split->inst.e_type = NULL;
split->inst.collection = NULL;
split->inst.guid = s->inst.guid;
split->inst.book = s->inst.book;
@ -515,18 +514,18 @@ xaccSplitCommitEdit(Split *s)
acc = s->acc;
/* Remove from lot (but only if it hasn't been moved to
new lot already) */
if (s->lot && (s->lot->account != acc || s->inst.do_free))
if (s->lot && (s->lot->account != acc || qof_instance_get_destroying(s)))
gnc_lot_remove_split (s->lot, s);
/* Possibly remove the split from the original account... */
if (orig_acc && (orig_acc != acc || s->inst.do_free)) {
if (orig_acc && (orig_acc != acc || qof_instance_get_destroying(s))) {
if (!gnc_account_remove_split(orig_acc, s)) {
PERR("Account lost track of moved or deleted split.");
}
}
/* ... and insert it into the new account if needed */
if (acc && (orig_acc != acc) && !s->inst.do_free) {
if (acc && (orig_acc != acc) && !qof_instance_get_destroying(s)) {
if (gnc_account_insert_split(acc, s)) {
/* If the split's lot belonged to some other account, we
leave it so. */
@ -563,7 +562,7 @@ xaccSplitCommitEdit(Split *s)
g_object_set(acc, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
xaccAccountRecomputeBalance(acc);
}
if (s->inst.do_free)
if (qof_instance_get_destroying(s))
xaccFreeSplit(s);
}
@ -579,9 +578,9 @@ xaccSplitRollbackEdit(Split *s)
s->acc = s->orig_acc;
/* Undestroy if needed */
if (s->inst.do_free && s->parent) {
if (qof_instance_get_destroying(s) && s->parent) {
GncEventData ed;
s->inst.do_free = FALSE;
qof_instance_set_destroying(s, FALSE);
ed.node = s;
ed.idx = -1; /* unused */
qof_event_gen(&s->parent->inst, GNC_EVENT_ITEM_ADDED, &ed);
@ -1103,14 +1102,15 @@ xaccSplitDestroy (Split *split)
acc = split->acc;
trans = split->parent;
if (acc && !acc->inst.do_free && xaccTransGetReadOnly (trans))
if (acc && !qof_instance_get_destroying(acc)
&& xaccTransGetReadOnly(trans))
return FALSE;
xaccTransBeginEdit(trans);
ed.node = split;
ed.idx = xaccTransGetSplitIndex(trans, split);
qof_instance_set_dirty(QOF_INSTANCE(split));
split->inst.do_free = TRUE;
qof_instance_set_destroying(split, TRUE);
qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
xaccTransCommitEdit(trans);

View File

@ -178,7 +178,7 @@ static QofLogModule log_module = GNC_MOD_ENGINE;
void check_open (const Transaction *trans)
{
if (trans && 0 >= trans->inst.editlevel)
if (trans && 0 >= qof_instance_get_editlevel(trans))
PERR ("transaction %p not open for editing", trans);
}
/********************************************************************\
@ -186,7 +186,7 @@ void check_open (const Transaction *trans)
gboolean
xaccTransStillHasSplit(const Transaction *trans, const Split *s)
{
return (s->parent == trans && !s->inst.do_free);
return (s->parent == trans && !qof_instance_get_destroying(s));
}
/* Executes 'cmd_block' for each split currently in the transaction,
@ -314,7 +314,7 @@ xaccTransDump (const Transaction *trans, const char *tag)
gnc_commodity_get_printname(trans->common_currency));
printf(" version: %x\n", trans->version);
printf(" version_chk: %x\n", trans->version_check);
printf(" editlevel: %x\n", trans->editlevel);
printf(" editlevel: %x\n", qof_instance_get_editlevel(trans));
printf(" orig: %p\n", trans->orig);
printf(" idata: %x\n", trans->idata);
printf(" splits: ");
@ -397,10 +397,7 @@ xaccDupeTransaction (const Transaction *t)
*/
trans->inst.e_type = NULL;
trans->inst.guid = *guid_null();
trans->inst.collection = NULL;
trans->inst.book = t->inst.book;
trans->inst.editlevel = 0;
trans->inst.do_free = FALSE;
trans->inst.kvp_data = kvp_frame_copy (t->inst.kvp_data);
return trans;
@ -865,7 +862,7 @@ xaccTransDestroy (Transaction *trans)
if (!xaccTransGetReadOnly (trans) ||
qof_book_shutting_down(trans->inst.book)) {
xaccTransBeginEdit(trans);
trans->inst.do_free = TRUE;
qof_instance_set_destroying(trans, TRUE);
xaccTransCommitEdit(trans);
}
}
@ -965,7 +962,7 @@ static void trans_cleanup_commit(Transaction *trans)
if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
continue;
if ((s->parent != trans) || s->inst.do_free) {
if ((s->parent != trans) || qof_instance_get_destroying(s)) {
/* Existing split either moved to another transaction or
was destroyed, drop from list */
GncEventData ed;
@ -977,7 +974,7 @@ static void trans_cleanup_commit(Transaction *trans)
if (s->parent == trans) {
/* Split was either added, destroyed or just changed */
if (s->inst.do_free)
if (qof_instance_get_destroying(s))
qof_event_gen(&s->inst, QOF_EVENT_DESTROY, NULL);
else qof_event_gen(&s->inst, QOF_EVENT_MODIFY, NULL);
xaccSplitCommitEdit(s);
@ -998,8 +995,8 @@ static void trans_cleanup_commit(Transaction *trans)
xaccTransSortSplits(trans);
/* Put back to zero. */
trans->inst.editlevel--;
g_assert(trans->inst.editlevel == 0);
qof_instance_decrease_editlevel(trans);
g_assert(qof_instance_get_editlevel(trans) == 0);
gen_event_trans (trans); //TODO: could be conditional
qof_event_gen (&trans->inst, QOF_EVENT_MODIFY, NULL);
@ -1019,9 +1016,10 @@ xaccTransCommitEdit (Transaction *trans)
/* We increment this for the duration of the call
* so other functions don't result in a recursive
* call to xaccTransCommitEdit. */
trans->inst.editlevel++;
qof_instance_increase_editlevel(trans);
if (was_trans_emptied(trans)) trans->inst.do_free = TRUE;
if (was_trans_emptied(trans))
qof_instance_set_destroying(trans, TRUE);
/* Before commiting the transaction, we're gonna enforce certain
* constraints. In particular, we want to enforce the cap-gains
@ -1032,7 +1030,7 @@ xaccTransCommitEdit (Transaction *trans)
* can cause pointers to splits and transactions to disapear out
* from under the holder.
*/
if (!(trans->inst.do_free) && scrub_data &&
if (!qof_instance_get_destroying(trans) && scrub_data &&
!qof_book_shutting_down(xaccTransGetBook(trans))) {
/* If scrubbing gains recurses through here, don't call it again. */
scrub_data = 0;
@ -1201,10 +1199,10 @@ xaccTransRollbackEdit (Transaction *trans)
xaccFreeTransaction (trans->orig);
trans->orig = NULL;
trans->inst.do_free = FALSE;
qof_instance_set_destroying(trans, FALSE);
/* Put back to zero. */
trans->inst.editlevel--;
qof_instance_decrease_editlevel(trans);
/* FIXME: The register code seems to depend on the engine to
generate an event during rollback, even though the state is just
reverting to what it was. */
@ -1216,7 +1214,7 @@ xaccTransRollbackEdit (Transaction *trans)
gboolean
xaccTransIsOpen (const Transaction *trans)
{
return trans ? (0 < trans->inst.editlevel) : FALSE;
return trans ? (0 < qof_instance_get_editlevel(trans)) : FALSE;
}
/* Only used by postgres backend. Not sure if it should dirty the trans. */

View File

@ -662,7 +662,7 @@ xaccSplitGetCapGainsSplit (const Split *split)
/* Both splits will be in the same collection, so search there. */
gains_split = (Split*) qof_collection_lookup_entity (
split->inst.collection, gains_guid);
qof_instance_get_collection(split), gains_guid);
PINFO ("split=%p has gains-split=%p", split, gains_split);
return gains_split;
}
@ -685,7 +685,7 @@ xaccSplitGetGainsSourceSplit (const Split *split)
/* Both splits will be in the same collection, so search there. */
source_split = (Split*) qof_collection_lookup_entity(
split->inst.collection, source_guid);
qof_instance_get_collection(split), source_guid);
PINFO ("split=%p has source-split=%p", split, source_split);
return source_split;
}

View File

@ -146,7 +146,7 @@ gnc_budget_destroy(GncBudget *budget)
g_return_if_fail(GNC_IS_BUDGET(budget));
gnc_budget_begin_edit(budget);
qof_instance_set_dirty(&budget->inst);
budget->inst.do_free = TRUE;
qof_instance_set_destroying(budget, TRUE);
gnc_budget_commit_edit(budget);
}

View File

@ -812,8 +812,9 @@ add_price(GNCPriceDB *db, GNCPrice *p)
GHashTable *currency_hash;
if(!db || !p) return FALSE;
ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
db, p, p->inst.dirty, p->inst.do_free);
ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
db, p, qof_instance_get_dirty_flag(p),
qof_instance_get_destroying(p));
if (db->inst.book != p->inst.book)
{
@ -857,8 +858,9 @@ add_price(GNCPriceDB *db, GNCPrice *p)
p->db = db;
qof_event_gen (&p->inst, QOF_EVENT_ADD, NULL);
LEAVE ("db=%p, pr=%p dirty=%d do-free=%d commodity=%s/%s currency_hash=%p",
db, p, p->inst.dirty, p->inst.do_free,
LEAVE ("db=%p, pr=%p dirty=%d dextroying=%d commodity=%s/%s currency_hash=%p",
db, p, qof_instance_get_dirty_flag(p),
qof_instance_get_destroying(p),
gnc_commodity_get_namespace(p->commodity),
gnc_commodity_get_mnemonic(p->commodity),
currency_hash);
@ -872,8 +874,9 @@ gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p)
{
if(!db || !p) return FALSE;
ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
db, p, p->inst.dirty, p->inst.do_free);
ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
db, p, qof_instance_get_dirty_flag(p),
qof_instance_get_destroying(p));
if (FALSE == add_price(db, p))
{
@ -885,8 +888,9 @@ gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p)
qof_instance_set_dirty(&db->inst);
gnc_pricedb_commit_edit(db);
LEAVE ("db=%p, pr=%p dirty=%d do-free=%d",
db, p, p->inst.dirty, p->inst.do_free);
LEAVE ("db=%p, pr=%p dirty=%d destroying=%d",
db, p, qof_instance_get_dirty_flag(p),
qof_instance_get_destroying(p));
return TRUE;
}
@ -904,8 +908,9 @@ remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup)
GHashTable *currency_hash;
if(!db || !p) return FALSE;
ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
db, p, p->inst.dirty, p->inst.do_free);
ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
db, p, qof_instance_get_dirty_flag(p),
qof_instance_get_destroying(p));
commodity = gnc_price_get_commodity(p);
if(!commodity) { LEAVE (" no commodity"); return FALSE; }
@ -958,8 +963,9 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
{
gboolean rc;
if(!db || !p) return FALSE;
ENTER ("db=%p, pr=%p dirty=%d do-free=%d",
db, p, p->inst.dirty, p->inst.do_free);
ENTER ("db=%p, pr=%p dirty=%d destroying=%d",
db, p, qof_instance_get_dirty_flag(p),
qof_instance_get_destroying(p));
gnc_price_ref(p);
rc = remove_price (db, p, TRUE);
@ -969,7 +975,7 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
/* invoke the backend to delete this price */
gnc_price_begin_edit (p);
p->inst.do_free = TRUE;
qof_instance_set_destroying(p, TRUE);
gnc_price_commit_edit (p);
p->db = NULL;
gnc_price_unref(p);