diff --git a/src/backend/file/gnc-backend-file.c b/src/backend/file/gnc-backend-file.c index 8a8afb6e61..c45b74e46f 100644 --- a/src/backend/file/gnc-backend-file.c +++ b/src/backend/file/gnc-backend-file.c @@ -236,12 +236,15 @@ build_period_filepath (FileBackend *fbe, QofBook *book) } static void -file_begin_edit (QofBackend *be, QofIdTypeConst typ, gpointer gp) +file_begin_edit (QofBackend *be, QofInstance *inst) { + if (0) build_period_filepath(0, 0); +#if BORKEN_FOR_NOW FileBackend *fbe = (FileBackend *) be; QofBook *book = gp; const char * filepath; + QofIdTypeConst typ = QOF_ENTITY(inst)->e_type; if (strcmp (GNC_ID_PERIOD, typ)) return; filepath = build_period_filepath(fbe, book); PINFO (" ====================== book=%p filepath=%s\n", book, filepath); @@ -257,20 +260,24 @@ file_begin_edit (QofBackend *be, QofIdTypeConst typ, gpointer gp) * modify books that are closed (They should be treated as * 'read-only'). */ +#endif } static void -file_rollback_edit (QofBackend *be, QofIdTypeConst typ, gpointer gp) +file_rollback_edit (QofBackend *be, QofInstance *inst) { +#if BORKEN_FOR_NOW QofBook *book = gp; if (strcmp (GNC_ID_PERIOD, typ)) return; PINFO ("book=%p", book); +#endif } static void -file_commit_edit (QofBackend *be, QofIdTypeConst typ, gpointer gp) +file_commit_edit (QofBackend *be, QofInstance *inst) { +#if BORKEN_FOR_NOW FileBackend *fbe = (FileBackend *) be; QofBook *book = gp; const char * filepath; @@ -285,6 +292,7 @@ file_commit_edit (QofBackend *be, QofIdTypeConst typ, gpointer gp) * there'll be the same transactions in the closed book, * and also in the current book. */ gnc_file_be_write_to_file (fbe, fbe->primary_book, fbe->fullpath, TRUE); +#endif } /* ================================================================= */ diff --git a/src/backend/file/io-gncbin-r.c b/src/backend/file/io-gncbin-r.c index abdc4125a2..ba617ce988 100644 --- a/src/backend/file/io-gncbin-r.c +++ b/src/backend/file/io-gncbin-r.c @@ -509,10 +509,8 @@ gnc_load_financials_from_fd(QofBook *book, int fd) { GNCPriceDB *tmpdb; - if(cvt_potential_prices_to_pricedb_and_cleanup(&tmpdb, book)) + if(!cvt_potential_prices_to_pricedb_and_cleanup(&tmpdb, book)) { - gnc_pricedb_set_db(book, tmpdb); - } else { PWARN("pricedb import failed."); error_code = ERR_BACKEND_MISC; gnc_pricedb_destroy(tmpdb); diff --git a/src/backend/file/io-gncxml-v1.c b/src/backend/file/io-gncxml-v1.c index fd747d552f..a44d4c128b 100644 --- a/src/backend/file/io-gncxml-v1.c +++ b/src/backend/file/io-gncxml-v1.c @@ -389,11 +389,6 @@ qof_session_load_from_xml_file(QofBook *book, const char *filename) xaccSetAccountGroup(book, global_parse_status.account_group); - if(global_parse_status.pricedb) - { - gnc_pricedb_set_db(book, global_parse_status.pricedb); - } - /* Fix account and transaction commodities */ xaccGroupScrubCommodities (gnc_book_get_group(book)); diff --git a/src/backend/file/io-gncxml-v2.c b/src/backend/file/io-gncxml-v2.c index aca05c0429..e7d658d1cb 100644 --- a/src/backend/file/io-gncxml-v2.c +++ b/src/backend/file/io-gncxml-v2.c @@ -305,13 +305,7 @@ add_template_transaction_local( sixtp_gdv2 *data, static gboolean add_pricedb_local(sixtp_gdv2 *data, GNCPriceDB *db) { - QofBook *book; - - book = data->book; - /* gnc_pricedb_print_contents(db, stdout); */ - gnc_pricedb_set_db(book, db); - return TRUE; } diff --git a/src/backend/postgres/PostgresBackend.c b/src/backend/postgres/PostgresBackend.c index 1674d92e72..e66af9079f 100644 --- a/src/backend/postgres/PostgresBackend.c +++ b/src/backend/postgres/PostgresBackend.c @@ -1643,20 +1643,21 @@ pgendDoSync (QofBackend *bend, QofBook *book) } static void -pgend_do_begin (QofBackend *bend, QofIdTypeConst type, gpointer object) +pgend_do_begin (QofBackend *bend, QofInstance *inst) { PGBackend *be = (PGBackend*)bend; + QofIdTypeConst type = inst->entity.e_type; ENTER ("be=%p, type=%s", bend, type); - if (!safe_strcmp (type, GNC_ID_PERIOD)) - return pgend_book_transfer_begin (bend, object); + // if (!safe_strcmp (type, GNC_ID_PERIOD)) + // return pgend_book_transfer_begin (bend, object); switch (be->session_mode) { case MODE_EVENT: case MODE_POLL: case MODE_SINGLE_UPDATE: if (!safe_strcmp (type, GNC_ID_PRICE)) - return pgend_price_begin_edit (bend, object); + return pgend_price_begin_edit (bend, (GNCPrice *) inst); case MODE_SINGLE_FILE: case MODE_NONE: @@ -1668,13 +1669,14 @@ pgend_do_begin (QofBackend *bend, QofIdTypeConst type, gpointer object) } static void -pgend_do_commit (QofBackend *bend, QofIdTypeConst type, gpointer object) +pgend_do_commit (QofBackend *bend, QofInstance *inst) { PGBackend *be = (PGBackend*)bend; + QofIdTypeConst type = inst->entity.e_type; ENTER ("be=%p, type=%s", bend, type); - if (!safe_strcmp (type, GNC_ID_PERIOD)) - return pgend_book_transfer_commit (bend, object); + // if (!safe_strcmp (type, GNC_ID_PERIOD)) + // return pgend_book_transfer_commit (bend, object); switch (be->session_mode) { case MODE_EVENT: @@ -1682,15 +1684,15 @@ pgend_do_commit (QofBackend *bend, QofIdTypeConst type, gpointer object) case MODE_SINGLE_UPDATE: if (!safe_strcmp (type, GNC_ID_TRANS)) { - Transaction *txn = (Transaction*) object; + Transaction *txn = (Transaction*) inst; return pgend_trans_commit_edit (bend, txn, txn->orig); } if (!safe_strcmp (type, GNC_ID_PRICE)) - return pgend_price_commit_edit (bend, object); + return pgend_price_commit_edit (bend, (GNCPrice *) inst); if (!safe_strcmp (type, GNC_ID_ACCOUNT)) - return pgend_account_commit_edit (bend, object); + return pgend_account_commit_edit (bend, (Account *) inst); case MODE_SINGLE_FILE: case MODE_NONE: @@ -1703,9 +1705,10 @@ pgend_do_commit (QofBackend *bend, QofIdTypeConst type, gpointer object) } static void -pgend_do_rollback (QofBackend *bend, QofIdTypeConst type, gpointer object) +pgend_do_rollback (QofBackend *bend, QofInstance *inst) { PGBackend *be = (PGBackend*)bend; + QofIdTypeConst type = inst->entity.e_type; ENTER ("be=%p, type=%s", bend, type); switch (be->session_mode) { @@ -1713,7 +1716,7 @@ pgend_do_rollback (QofBackend *bend, QofIdTypeConst type, gpointer object) case MODE_POLL: if (!safe_strcmp (type, GNC_ID_TRANS)) - return pgend_trans_rollback_edit (bend, object); + return pgend_trans_rollback_edit (bend, (Transaction *)inst); case MODE_SINGLE_UPDATE: case MODE_SINGLE_FILE: diff --git a/src/backend/postgres/book.c b/src/backend/postgres/book.c index e3839f45b4..fc953ad991 100644 --- a/src/backend/postgres/book.c +++ b/src/backend/postgres/book.c @@ -97,7 +97,7 @@ pgendStoreBookNoLock (PGBackend *be, QofBook *book, if (book->idata) { pgendKVPDelete (be, book->idata); - pgendKVPStore (be, book->idata, book->kvp_data); + pgendKVPStore (be, book->idata, book->inst.kvp_data); } LEAVE(" "); } @@ -172,7 +172,7 @@ pgendBookRestore (PGBackend *be, QofBook *book) if (0 != book->idata) { - book->kvp_data = pgendKVPFetch (be, book->idata, book->kvp_data); + book->inst.kvp_data = pgendKVPFetch (be, book->idata, book->inst.kvp_data); } LEAVE (" "); @@ -200,7 +200,7 @@ get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) for (node=blist; node; node=node->next) { book = node->data; - if (guid_equal (&book->entity.guid, &guid)) break; + if (guid_equal (&book->inst.entity.guid, &guid)) break; book = NULL; } @@ -237,7 +237,7 @@ pgendGetAllBooks (PGBackend *be, QofBookList *blist) QofBook *book = node->data; if (0 != book->idata) { - book->kvp_data = pgendKVPFetch (be, book->idata, book->kvp_data); + book->inst.kvp_data = pgendKVPFetch (be, book->idata, book->inst.kvp_data); } } diff --git a/src/backend/postgres/gncquery.c b/src/backend/postgres/gncquery.c index 5169445da6..2d001c6d05 100644 --- a/src/backend/postgres/gncquery.c +++ b/src/backend/postgres/gncquery.c @@ -314,7 +314,7 @@ sql_sort_need_entry(QofQuery * q) } /* =========================================================== */ -/* Macro for QOF_QUERYCORE_STRING query types +/* Macro for QOF_TYPE_STRING query types * Note that postgres supports both case-sensitive and * case-insensitve string searches, and it also supports * regex! yahooo! @@ -346,7 +346,7 @@ sql_sort_need_entry(QofQuery * q) } /* =========================================================== */ -/* Macro for QOF_QUERYCORE_NUMERIC type terms. The logic used here in the +/* Macro for QOF_TYPE_NUMERIC type terms. The logic used here in the * SQL exactly matches that used in the qofquery.c code. If * that code is incorrect or has changed, then the code below is * broken as well. @@ -756,7 +756,7 @@ sqlQuery_build(sqlQuery * sq, Query * q) need_entry = TRUE; need_trans_commodity = TRUE; } else if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID)) { - if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID)) + if (!safe_strcmp(path->data, QOF_PARAM_GUID)) need_entry = TRUE; else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) { need_account = TRUE; @@ -862,17 +862,17 @@ sqlQuery_build(sqlQuery * sq, Query * q) PINFO("term is QOF_TYPE_GUID"); - if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID)) { + if (!safe_strcmp(path->data, QOF_PARAM_GUID)) { field = "gncSplit.splitGuid"; g_assert(pdata->options != QOF_GUID_MATCH_ALL); } else if (!safe_strcmp(path->data, SPLIT_TRANS) && - !safe_strcmp(path->next->data, QOF_QUERY_PARAM_GUID)) { + !safe_strcmp(path->next->data, QOF_PARAM_GUID)) { field = "gncSplit.transGUID"; g_assert(pdata->options != QOF_GUID_MATCH_ALL); } else if (!safe_strcmp(path->data, SPLIT_ACCOUNT) && - !safe_strcmp(path->next->data, QOF_QUERY_PARAM_GUID)) { + !safe_strcmp(path->next->data, QOF_PARAM_GUID)) { field = "gncSplit.accountGUID"; g_assert(pdata->options != QOF_GUID_MATCH_ALL); @@ -883,8 +883,8 @@ sqlQuery_build(sqlQuery * sq, Query * q) field = "gncSplit.accountGUID"; g_assert(pdata->options == QOF_GUID_MATCH_ALL); - } else if (!safe_strcmp(path->data, QOF_QUERY_PARAM_BOOK) && - !safe_strcmp(path->next->data, QOF_QUERY_PARAM_GUID)) { + } else if (!safe_strcmp(path->data, QOF_PARAM_BOOK) && + !safe_strcmp(path->next->data, QOF_PARAM_GUID)) { /* XXX: Need to support the Book GUID? (gncAccount.bookGUID) */ field = "gncAccount.bookGUID"; g_assert(pdata->options != QOF_GUID_MATCH_ALL); diff --git a/src/backend/postgres/price.c b/src/backend/postgres/price.c index 2f3f5c6673..fc72c7af0a 100644 --- a/src/backend/postgres/price.c +++ b/src/backend/postgres/price.c @@ -462,7 +462,7 @@ pgendPriceFind (QofBackend *bend, gpointer olook) void pgend_price_begin_edit (QofBackend * bend, GNCPrice *pr) { - if (pr && pr->db && pr->db->dirty) + if (pr && pr->db && pr->db->inst.dirty) { PERR ("price db is unexpectedly dirty"); } @@ -527,7 +527,7 @@ pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr) SEND_QUERY (be,bufp,); FINISH_QUERY(be->connection); - if (pr->db) pr->db->dirty = FALSE; + if (pr->db) pr->db->inst.dirty = FALSE; LEAVE ("commited"); return; diff --git a/src/backend/postgres/putil.h b/src/backend/postgres/putil.h index 283d7cbecc..cac1a744b2 100644 --- a/src/backend/postgres/putil.h +++ b/src/backend/postgres/putil.h @@ -362,7 +362,7 @@ int finishQuery(PGBackend *be); for (node=be->blist; node; node=node->next) \ { \ book = node->data; \ - if (guid_equal (&book->entity.guid, &book_guid)) break; \ + if (guid_equal (&book->inst.entity.guid, &book_guid)) break; \ book = NULL; \ } \ if (!book) return data; \ diff --git a/src/business/business-core/gncBillTerm.c b/src/business/business-core/gncBillTerm.c index 22f9fdfedb..55f41f1e9c 100644 --- a/src/business/business-core/gncBillTerm.c +++ b/src/business/business-core/gncBillTerm.c @@ -36,9 +36,9 @@ #include "gnc-engine-util.h" #include "qofquerycore.h" #include "gnc-event-p.h" -#include "gnc-be-utils.h" #include "kvp_frame.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid.h" @@ -404,7 +404,7 @@ void gncBillTermChanged (GncBillTerm *term) void gncBillTermBeginEdit (GncBillTerm *term) { - GNC_BEGIN_EDIT (&term->inst); + QOF_BEGIN_EDIT (&term->inst); } static void gncBillTermOnError (QofInstance *inst, QofBackendError errcode) @@ -422,8 +422,8 @@ static inline void on_done (QofInstance *inst) {} void gncBillTermCommitEdit (GncBillTerm *term) { - GNC_COMMIT_EDIT_PART1 (&term->inst); - GNC_COMMIT_EDIT_PART2 (&term->inst, gncBillTermOnError, + QOF_COMMIT_EDIT_PART1 (&term->inst); + QOF_COMMIT_EDIT_PART2 (&term->inst, gncBillTermOnError, on_done, bill_free); } diff --git a/src/business/business-core/gncCustomer.c b/src/business/business-core/gncCustomer.c index e40b6aff3d..ad89731717 100644 --- a/src/business/business-core/gncCustomer.c +++ b/src/business/business-core/gncCustomer.c @@ -36,8 +36,8 @@ #include "gnc-commodity.h" #include "gnc-numeric.h" #include "gnc-event-p.h" -#include "gnc-be-utils.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid-p.h" @@ -377,7 +377,7 @@ void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job) void gncCustomerBeginEdit (GncCustomer *cust) { - GNC_BEGIN_EDIT (&cust->inst); + QOF_BEGIN_EDIT (&cust->inst); } static inline void gncCustomerOnError (QofInstance *inst, QofBackendError errcode) @@ -400,8 +400,8 @@ static inline void cust_free (QofInstance *inst) void gncCustomerCommitEdit (GncCustomer *cust) { - GNC_COMMIT_EDIT_PART1 (&cust->inst); - GNC_COMMIT_EDIT_PART2 (&cust->inst, gncCustomerOnError, + QOF_COMMIT_EDIT_PART1 (&cust->inst); + QOF_COMMIT_EDIT_PART2 (&cust->inst, gncCustomerOnError, gncCustomerOnDone, cust_free); } diff --git a/src/business/business-core/gncEmployee.c b/src/business/business-core/gncEmployee.c index d568fbc829..d4d815291c 100644 --- a/src/business/business-core/gncEmployee.c +++ b/src/business/business-core/gncEmployee.c @@ -32,6 +32,7 @@ #include #include "guid.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid.h" @@ -47,7 +48,6 @@ #include "gnc-commodity.h" #include "gnc-engine-util.h" #include "gnc-event-p.h" -#include "gnc-be-utils.h" #include "gncAddressP.h" #include "gncBusiness.h" @@ -349,7 +349,7 @@ gboolean gncEmployeeIsDirty (GncEmployee *employee) void gncEmployeeBeginEdit (GncEmployee *employee) { - GNC_BEGIN_EDIT (&employee->inst); + QOF_BEGIN_EDIT (&employee->inst); } static inline void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode) @@ -372,8 +372,8 @@ static inline void emp_free (QofInstance *inst) void gncEmployeeCommitEdit (GncEmployee *employee) { - GNC_COMMIT_EDIT_PART1 (&employee->inst); - GNC_COMMIT_EDIT_PART2 (&employee->inst, gncEmployeeOnError, + QOF_COMMIT_EDIT_PART1 (&employee->inst); + QOF_COMMIT_EDIT_PART2 (&employee->inst, gncEmployeeOnError, gncEmployeeOnDone, emp_free); } diff --git a/src/business/business-core/gncEntry.c b/src/business/business-core/gncEntry.c index 86a8f84faf..f89b91a48b 100644 --- a/src/business/business-core/gncEntry.c +++ b/src/business/business-core/gncEntry.c @@ -34,8 +34,8 @@ #include "gnc-engine-util.h" #include "gnc-event-p.h" #include "gnc-numeric.h" -#include "gnc-be-utils.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid.h" @@ -1115,7 +1115,7 @@ gboolean gncEntryIsOpen (GncEntry *entry) void gncEntryBeginEdit (GncEntry *entry) { - GNC_BEGIN_EDIT (&entry->inst); + QOF_BEGIN_EDIT (&entry->inst); } static inline void gncEntryOnError (QofInstance *entry, QofBackendError errcode) @@ -1133,8 +1133,8 @@ static inline void entry_free (QofInstance *inst) void gncEntryCommitEdit (GncEntry *entry) { - GNC_COMMIT_EDIT_PART1 (&entry->inst); - GNC_COMMIT_EDIT_PART2 (&entry->inst, gncEntryOnError, + QOF_COMMIT_EDIT_PART1 (&entry->inst); + QOF_COMMIT_EDIT_PART2 (&entry->inst, gncEntryOnError, gncEntryOnDone, entry_free); } diff --git a/src/business/business-core/gncInvoice.c b/src/business/business-core/gncInvoice.c index 9be86c9b4e..558ea9b4ed 100644 --- a/src/business/business-core/gncInvoice.c +++ b/src/business/business-core/gncInvoice.c @@ -30,6 +30,7 @@ #include +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid.h" @@ -49,7 +50,6 @@ #include "gnc-event-p.h" #include "gnc-lot.h" -#include "gnc-be-utils.h" #include "gncBusiness.h" #include "gncBillTermP.h" @@ -1295,7 +1295,7 @@ gboolean gncInvoiceIsPaid (GncInvoice *invoice) void gncInvoiceBeginEdit (GncInvoice *invoice) { - GNC_BEGIN_EDIT (&invoice->inst); + QOF_BEGIN_EDIT (&invoice->inst); } static inline void gncInvoiceOnError (QofInstance *inst, QofBackendError errcode) @@ -1313,8 +1313,8 @@ static inline void invoice_free (QofInstance *inst) void gncInvoiceCommitEdit (GncInvoice *invoice) { - GNC_COMMIT_EDIT_PART1 (&invoice->inst); - GNC_COMMIT_EDIT_PART2 (&invoice->inst, gncInvoiceOnError, + QOF_COMMIT_EDIT_PART1 (&invoice->inst); + QOF_COMMIT_EDIT_PART2 (&invoice->inst, gncInvoiceOnError, gncInvoiceOnDone, invoice_free); } diff --git a/src/business/business-core/gncJob.c b/src/business/business-core/gncJob.c index 985904b091..db5804ea88 100644 --- a/src/business/business-core/gncJob.c +++ b/src/business/business-core/gncJob.c @@ -36,8 +36,8 @@ #include "gnc-engine-util.h" #include "gnc-numeric.h" #include "gnc-event-p.h" -#include "gnc-be-utils.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofinstance.h" @@ -271,7 +271,7 @@ void gncJobSetActive (GncJob *job, gboolean active) void gncJobBeginEdit (GncJob *job) { - GNC_BEGIN_EDIT (&job->inst); + QOF_BEGIN_EDIT (&job->inst); } static void gncJobOnError (QofInstance *inst, QofBackendError errcode) @@ -289,8 +289,8 @@ static inline void gncJobOnDone (QofInstance *qof) { } void gncJobCommitEdit (GncJob *job) { - GNC_COMMIT_EDIT_PART1 (&job->inst); - GNC_COMMIT_EDIT_PART2 (&job->inst, gncJobOnError, + QOF_COMMIT_EDIT_PART1 (&job->inst); + QOF_COMMIT_EDIT_PART2 (&job->inst, gncJobOnError, gncJobOnDone, job_free); } diff --git a/src/business/business-core/gncOrder.c b/src/business/business-core/gncOrder.c index 4e7260fdc3..3bf1586c4b 100644 --- a/src/business/business-core/gncOrder.c +++ b/src/business/business-core/gncOrder.c @@ -34,6 +34,7 @@ #include "kvp_frame.h" #include "gnc-engine-util.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid.h" @@ -45,7 +46,6 @@ #include "qofquerycore.h" #include "gnc-event-p.h" -#include "gnc-be-utils.h" #include "gncBusiness.h" #include "gncEntry.h" @@ -356,7 +356,7 @@ gboolean gncOrderIsClosed (GncOrder *order) void gncOrderBeginEdit (GncOrder *order) { - GNC_BEGIN_EDIT (&order->inst); + QOF_BEGIN_EDIT (&order->inst); } static inline void gncOrderOnError (QofInstance *order, QofBackendError errcode) @@ -374,8 +374,8 @@ static inline void order_free (QofInstance *inst) void gncOrderCommitEdit (GncOrder *order) { - GNC_COMMIT_EDIT_PART1 (&order->inst); - GNC_COMMIT_EDIT_PART2 (&order->inst, gncOrderOnError, + QOF_COMMIT_EDIT_PART1 (&order->inst); + QOF_COMMIT_EDIT_PART2 (&order->inst, gncOrderOnError, gncOrderOnDone, order_free); } diff --git a/src/business/business-core/gncTaxTable.c b/src/business/business-core/gncTaxTable.c index fa6161cf3e..b7b39a4c0d 100644 --- a/src/business/business-core/gncTaxTable.c +++ b/src/business/business-core/gncTaxTable.c @@ -34,8 +34,8 @@ #include "gnc-numeric.h" #include "gnc-engine-util.h" #include "gnc-event-p.h" -#include "gnc-be-utils.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid.h" @@ -527,7 +527,7 @@ void gncTaxTableChanged (GncTaxTable *table) void gncTaxTableBeginEdit (GncTaxTable *table) { - GNC_BEGIN_EDIT (&table->inst); + QOF_BEGIN_EDIT (&table->inst); } static inline void gncTaxTableOnError (QofInstance *inst, QofBackendError errcode) @@ -545,8 +545,8 @@ static inline void table_free (QofInstance *inst) void gncTaxTableCommitEdit (GncTaxTable *table) { - GNC_COMMIT_EDIT_PART1 (&table->inst); - GNC_COMMIT_EDIT_PART2 (&table->inst, gncTaxTableOnError, + QOF_COMMIT_EDIT_PART1 (&table->inst); + QOF_COMMIT_EDIT_PART2 (&table->inst, gncTaxTableOnError, gncTaxTableOnDone, table_free); } diff --git a/src/business/business-core/gncVendor.c b/src/business/business-core/gncVendor.c index 7702f66213..f2d4ff192b 100644 --- a/src/business/business-core/gncVendor.c +++ b/src/business/business-core/gncVendor.c @@ -32,6 +32,7 @@ #include #include "guid.h" +#include "qof-be-utils.h" #include "qofbook.h" #include "qofclass.h" #include "qofid.h" @@ -46,7 +47,6 @@ #include "gnc-commodity.h" #include "gnc-engine-util.h" #include "gnc-event-p.h" -#include "gnc-be-utils.h" #include "gncAddressP.h" #include "gncBillTermP.h" @@ -409,7 +409,7 @@ void gncVendorRemoveJob (GncVendor *vendor, GncJob *job) void gncVendorBeginEdit (GncVendor *vendor) { - GNC_BEGIN_EDIT (&vendor->inst); + QOF_BEGIN_EDIT (&vendor->inst); } static inline void gncVendorOnError (QofInstance *vendor, QofBackendError errcode) @@ -431,8 +431,8 @@ static inline void vendor_free (QofInstance *inst) void gncVendorCommitEdit (GncVendor *vendor) { - GNC_COMMIT_EDIT_PART1 (&vendor->inst); - GNC_COMMIT_EDIT_PART2 (&vendor->inst, gncVendorOnError, + QOF_COMMIT_EDIT_PART1 (&vendor->inst); + QOF_COMMIT_EDIT_PART2 (&vendor->inst, gncVendorOnError, gncVendorOnDone, vendor_free); } diff --git a/src/engine/Account.c b/src/engine/Account.c index a94415a03f..7482b963dd 100644 --- a/src/engine/Account.c +++ b/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 @@ xaccFreeAccount (Account *acc) void xaccAccountBeginEdit (Account *acc) { - GNC_BEGIN_EDIT (&acc->inst); + QOF_BEGIN_EDIT (&acc->inst); } static inline void noop(QofInstance *inst) {} @@ -338,7 +338,7 @@ static inline void acc_free (QofInstance *inst) 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 @@ xaccAccountCommitEdit (Account *acc) 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); } diff --git a/src/engine/Group.h b/src/engine/Group.h index db540a8741..d06850feef 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -59,7 +59,10 @@ AccountGroup *xaccMallocAccountGroup (QofBook *book); */ AccountGroup * xaccGetAccountGroup (QofBook *book); -/** huh ?? */ +/** + * The xaccCollAccountGroup() routine will return the top-most + * account group associated with the indicated collection. + */ AccountGroup * xaccCollGetAccountGroup (QofCollection *col); /** The xaccAccountDestroy() routine will destroy and free all diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index a10e61a9bd..2a741265e9 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -77,7 +77,6 @@ gncinclude_HEADERS = \ engine-helpers.h \ glib-helpers.h \ gnc-associate-account.h \ - gnc-be-utils.h \ gnc-book.h \ gnc-commodity.h \ gnc-date.h \ @@ -98,6 +97,7 @@ gncinclude_HEADERS = \ policy.h \ qof.h \ qofbackend.h \ + qof-be-utils.h \ qofbook.h \ qofclass.h \ qofid.h \ diff --git a/src/engine/Period.c b/src/engine/Period.c index 81e1fe291f..0615d0236c 100644 --- a/src/engine/Period.c +++ b/src/engine/Period.c @@ -546,8 +546,8 @@ gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query) /* hack alert -- FIXME -- this should really be a merge, not a * clobber copy, but I am too lazy to write a kvp merge routine, * and it is not needed for the current usage. */ - kvp_frame_delete (dest_book->kvp_data); - dest_book->kvp_data = kvp_frame_copy (src_book->kvp_data); + kvp_frame_delete (dest_book->inst.kvp_data); + dest_book->inst.kvp_data = kvp_frame_copy (src_book->inst.kvp_data); /* Next, copy the commodity tables */ src_tbl = gnc_commodity_table_get_table (src_book); @@ -598,11 +598,11 @@ gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query) /* Make note of the sibling books */ now = time(0); - gnc_kvp_bag_add (src_book->kvp_data, "gemini", now, - "book_guid", &dest_book->entity.guid, + gnc_kvp_bag_add (src_book->inst.kvp_data, "gemini", now, + "book_guid", &dest_book->inst.entity.guid, NULL); - gnc_kvp_bag_add (dest_book->kvp_data, "gemini", now, - "book_guid", &src_book->entity.guid, + gnc_kvp_bag_add (dest_book->inst.kvp_data, "gemini", now, + "book_guid", &src_book->inst.entity.guid, NULL); LEAVE (" "); } @@ -693,7 +693,7 @@ add_closing_balances (AccountGroup *closed_grp, xaccAccountBeginEdit (twin); cwd = xaccAccountGetSlots (twin); kvp_frame_set_guid (cwd, "/book/prev-acct", xaccAccountGetGUID (candidate)); - kvp_frame_set_guid (cwd, "/book/prev-book", &closed_book->entity.guid); + kvp_frame_set_guid (cwd, "/book/prev-book", &closed_book->inst.entity.guid); xaccAccountSetSlots_nc (twin, twin->inst.kvp_data); @@ -702,7 +702,7 @@ add_closing_balances (AccountGroup *closed_grp, * the next book is. */ xaccAccountBeginEdit (candidate); cwd = xaccAccountGetSlots (candidate); - kvp_frame_set_guid (cwd, "/book/next-book", &open_book->entity.guid); + kvp_frame_set_guid (cwd, "/book/next-book", &open_book->inst.entity.guid); kvp_frame_set_guid (cwd, "/book/next-acct", xaccAccountGetGUID (twin)); xaccAccountSetSlots_nc (candidate, candidate->inst.kvp_data); @@ -760,7 +760,7 @@ add_closing_balances (AccountGroup *closed_grp, /* Add KVP data showing where the balancing * transaction came from */ cwd = xaccTransGetSlots (trans); - kvp_frame_set_guid (cwd, "/book/closed-book", &closed_book->entity.guid); + kvp_frame_set_guid (cwd, "/book/closed-book", &closed_book->inst.entity.guid); kvp_frame_set_guid (cwd, "/book/closed-acct", xaccAccountGetGUID(candidate)); xaccTransCommitEdit (trans); @@ -805,7 +805,7 @@ period_begin_edit (QofBook *src_book, QofBook *dest_book) 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 @@ period_commit_edit (QofBook *src_book, QofBook *dest_book) be = src_book->backend; if (be && be->commit) { - (*be->commit)(be, GNC_ID_PERIOD, dest_book); + // (*be->commit)(be, GNC_ID_PERIOD, dest_book); } } @@ -870,8 +870,8 @@ gnc_book_close_period (QofBook *existing_book, Timespec calve_date, /* Now add the various identifying kvp's */ /* cwd == 'current working directory' */ - exist_cwd = existing_book->kvp_data; - partn_cwd = closing_book->kvp_data; + exist_cwd = existing_book->inst.kvp_data; + partn_cwd = closing_book->inst.kvp_data; /* Mark the boundary date between the books */ kvp_frame_set_timespec (exist_cwd, "/book/open-date", calve_date); @@ -883,8 +883,8 @@ gnc_book_close_period (QofBook *existing_book, Timespec calve_date, kvp_frame_set_timespec (partn_cwd, "/book/log-date", ts); /* Set up pointers to each book from the other. */ - kvp_frame_set_guid (partn_cwd, "/book/next-book", &existing_book->entity.guid); - kvp_frame_set_guid (exist_cwd, "/book/prev-book", &closing_book->entity.guid); + kvp_frame_set_guid (partn_cwd, "/book/next-book", &existing_book->inst.entity.guid); + kvp_frame_set_guid (exist_cwd, "/book/prev-book", &closing_book->inst.entity.guid); /* add in transactions to equity accounts that will * hold the colsing balances */ diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index b98abb098a..dc1ad04daa 100644 --- a/src/engine/Transaction.c +++ b/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 @@ xaccTransSetCurrency (Transaction *trans, gnc_commodity *curr) 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 @@ void 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 @@ xaccTransCommitEdit (Transaction *trans) 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 @@ xaccTransCommitEdit (Transaction *trans) 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 @@ xaccTransRollbackEdit (Transaction *trans) 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 @@ xaccTransRollbackEdit (Transaction *trans) 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) diff --git a/src/engine/gnc-pricedb-p.h b/src/engine/gnc-pricedb-p.h index a5e521a50a..e0f46bd442 100644 --- a/src/engine/gnc-pricedb-p.h +++ b/src/engine/gnc-pricedb-p.h @@ -59,12 +59,8 @@ struct gnc_price_s 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 @@ -98,12 +94,7 @@ typedef struct gnc_price_lookup_helper_s } GNCPriceLookupHelper; #define gnc_price_set_guid(P,G) qof_entity_set_guid(QOF_ENTITY(P),(G)) - -void gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db); -void gnc_collection_set_pricedb(QofCollection *col, GNCPriceDB *db); - - -void gnc_pricedb_mark_clean(GNCPriceDB *db); +#define gnc_pricedb_mark_clean(db) qof_instance_mark_clean(QOF_INSTANCE(db)) void gnc_pricedb_substitute_commodity(GNCPriceDB *db, gnc_commodity *old_c, gnc_commodity *new_c); diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c index 6b32820698..cb1647f10f 100644 --- a/src/engine/gnc-pricedb.c +++ b/src/engine/gnc-pricedb.c @@ -27,7 +27,6 @@ #include #include -#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 @@ gnc_price_clone (GNCPrice* p, QofBook *book) 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 @@ static inline void noop (QofInstance *inst) {} 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); } /* ==================================================================== */ @@ -176,81 +176,14 @@ gnc_price_commit_edit (GNCPrice *p) void gnc_pricedb_begin_edit (GNCPriceDB *pdb) { - QofBackend *be; - - if (!pdb) return; - pdb->editlevel++; - if (1 < pdb->editlevel) return; - ENTER ("pdb=%p\n", pdb); - - if (0 >= pdb->editlevel) - { - PERR ("unbalanced call - resetting (was %d)", pdb->editlevel); - pdb->editlevel = 1; - } - - /* See if there's a backend. If there is, invoke it. */ - be = xaccPriceDBGetBackend (pdb); - if (be && be->begin) - { - (be->begin) (be, GNC_ID_PRICEDB, pdb); - } - - LEAVE ("pdb=%p\n", pdb); + QOF_BEGIN_EDIT (&pdb->inst); } void gnc_pricedb_commit_edit (GNCPriceDB *pdb) { - QofBackend *be; - if (!pdb) return; - - pdb->editlevel--; - if (0 < pdb->editlevel) return; - - ENTER ("pdb=%p\n", pdb); - if (0 > pdb->editlevel) - { - PERR ("unbalanced call - resetting (was %d)", pdb->editlevel); - pdb->editlevel = 0; - } - - /* See if there's a backend. If there is, invoke it. */ - /* We may not be able to find the backend, so make not of that .. */ - be = xaccPriceDBGetBackend (pdb); - if (be && be->commit) - { - QofBackendError errcode; - - /* clear errors */ - do { - errcode = qof_backend_get_error (be); - } while (ERR_BACKEND_NO_ERR != errcode); - - /* if we haven't been able to call begin edit before, call it now */ - if (TRUE == pdb->dirty) - { - if (be->begin) - { - (be->begin) (be, GNC_ID_PRICEDB, pdb); - } - } - - (be->commit) (be, GNC_ID_PRICEDB, pdb); - errcode = qof_backend_get_error (be); - if (ERR_BACKEND_NO_ERR != errcode) - { - /* XXX hack alert FIXME implement price rollback */ - PERR (" backend asked engine to rollback, but this isn't" - " handled yet. Return code=%d", errcode); - - /* push error back onto the stack */ - qof_backend_set_error (be, errcode); - } - } - pdb->dirty = FALSE; - - LEAVE ("pdb=%p\n", pdb); + QOF_COMMIT_EDIT_PART1 (&pdb->inst); + QOF_COMMIT_EDIT_PART2 (&pdb->inst, commit_err, noop, noop); } /* ==================================================================== */ @@ -270,7 +203,7 @@ gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c) remove_price (p->db, p, TRUE); gnc_price_begin_edit (p); p->commodity = c; - if(p->db) p->db->dirty = TRUE; + if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); add_price (p->db, p); gnc_price_unref (p); @@ -292,7 +225,7 @@ gnc_price_set_currency(GNCPrice *p, gnc_commodity *c) remove_price (p->db, p, TRUE); gnc_price_begin_edit (p); p->currency = c; - if(p->db) p->db->dirty = TRUE; + if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); add_price (p->db, p); gnc_price_unref (p); @@ -312,7 +245,7 @@ gnc_price_set_time(GNCPrice *p, Timespec t) remove_price (p->db, p, FALSE); gnc_price_begin_edit (p); p->tmspec = t; - if(p->db) p->db->dirty = TRUE; + if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); add_price (p->db, p); gnc_price_unref (p); @@ -333,7 +266,7 @@ gnc_price_set_source(GNCPrice *p, const char *s) tmp = g_cache_insert(cache, (gpointer) s); if(p->source) g_cache_remove(cache, p->source); p->source = tmp; - if(p->db) p->db->dirty = TRUE; + if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); } } @@ -352,7 +285,7 @@ gnc_price_set_type(GNCPrice *p, const char* type) tmp = g_cache_insert(cache, (gpointer) type); if(p->type) g_cache_remove(cache, p->type); p->type = tmp; - if(p->db) p->db->dirty = TRUE; + if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); } } @@ -365,7 +298,7 @@ gnc_price_set_value(GNCPrice *p, gnc_numeric value) { gnc_price_begin_edit (p); p->value = value; - if(p->db) p->db->dirty = TRUE; + if(p->db) p->db->inst.dirty = TRUE; gnc_price_commit_edit (p); } } @@ -623,10 +556,22 @@ gnc_pricedb_create(QofBook * book) g_return_val_if_fail (book, NULL); + /* There can only be one pricedb per book. So if one exits already, + * then use that. Warn user, they shouldn't be creating two ... + */ + QofCollection *col = qof_book_get_collection (book, GNC_ID_PRICEDB); + result = qof_collection_get_data (col); + if (result) + { + PWARN ("A price database already exists for this book!"); + return result; + } + result = g_new0(GNCPriceDB, 1); - result->book = book; - result->editlevel = 0; - result->dirty = FALSE; + qof_instance_init (&result->inst, GNC_ID_PRICEDB, book); + + qof_collection_set_data (col, result); + result->commodity_hash = g_hash_table_new(commodity_hash, commodity_equal); g_return_val_if_fail (result->commodity_hash, NULL); return result; @@ -672,11 +617,16 @@ gnc_pricedb_destroy(GNCPriceDB *db) NULL); g_hash_table_destroy (db->commodity_hash); db->commodity_hash = NULL; - db->book = NULL; + qof_instance_release (&db->inst); g_free(db); } /* ==================================================================== */ +/* This is kind of weird, the way its done. Each collection of prices + * for a given commodity should get its own guid, be its own entity, etc. + * We really shouldn't be using the collection data. But, hey I guess its OK, + * yeah? + */ GNCPriceDB * gnc_collection_get_pricedb(QofCollection *col) @@ -689,50 +639,10 @@ gnc_pricedb_get_db(QofBook *book) { QofCollection *col; if (!book) return NULL; - col = qof_book_get_collection (book, GNC_ID_PRICE); + col = qof_book_get_collection (book, GNC_ID_PRICEDB); return gnc_collection_get_pricedb (col); } -void -gnc_collection_set_pricedb(QofCollection *col, GNCPriceDB *db) -{ - GNCPriceDB *old_db; - - if(!col) return; - - old_db = qof_collection_get_data (col); - if (db == old_db) return; - - qof_collection_set_data (col, db); - gnc_pricedb_destroy (old_db); -} - -void -gnc_pricedb_set_db(QofBook *book, GNCPriceDB *db) -{ - QofCollection *col; - if(!book) return; - col = qof_book_get_collection (book, GNC_ID_PRICE); - gnc_collection_set_pricedb (col, db); - if (db) db->book = book; -} - -/* ==================================================================== */ - -gboolean -gnc_pricedb_dirty(GNCPriceDB *p) -{ - if(!p) return FALSE; - return p->dirty; -} - -void -gnc_pricedb_mark_clean(GNCPriceDB *p) -{ - if(!p) return; - p->dirty = FALSE; -} - /* ==================================================================== */ static gboolean @@ -841,9 +751,7 @@ add_price(GNCPriceDB *db, GNCPrice *p) ENTER ("db=%p, pr=%p dirty=%d do-free=%d", db, p, p->inst.dirty, p->inst.do_free); - /* initialize the book pointer for the first time, if needed */ - if (NULL == db->book) db->book = p->inst.book; - if (db->book != p->inst.book) + if (db->inst.book != p->inst.book) { PERR ("attempted to mix up prices across different books"); return FALSE; @@ -897,7 +805,7 @@ gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p) if (TRUE == p->inst.dirty) { gnc_price_begin_edit(p); - db->dirty = TRUE; + db->inst.dirty = TRUE; gnc_price_commit_edit(p); } @@ -976,7 +884,7 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p) /* invoke the backend to delete this price */ gnc_price_begin_edit (p); - db->dirty = TRUE; + db->inst.dirty = TRUE; p->inst.do_free = TRUE; gnc_price_commit_edit (p); @@ -1001,14 +909,14 @@ gnc_pricedb_lookup_latest(GNCPriceDB *db, ENTER ("db=%p commodity=%p currency=%p", db, commodity, currency); if(!db || !commodity || !currency) return NULL; - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_LATEST; pl.prdb = db; pl.commodity = commodity; pl.currency = currency; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, commodity); @@ -1052,14 +960,14 @@ gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db, ENTER ("db=%p commodity=%p", db, commodity); if(!db || !commodity) return NULL; - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_LATEST; pl.prdb = db; pl.commodity = commodity; pl.currency = NULL; /* can the backend handle this??? */ - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, commodity); @@ -1096,14 +1004,14 @@ gnc_pricedb_get_prices(GNCPriceDB *db, ENTER ("db=%p commodity=%p currency=%p", db, commodity, currency); if(!db || !commodity) return NULL; - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_ALL; pl.prdb = db; pl.commodity = commodity; pl.currency = currency; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, commodity); @@ -1142,7 +1050,7 @@ gnc_pricedb_lookup_day(GNCPriceDB *db, /* Convert to noon local time. */ t = timespecCanonicalDayTime(t); - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_AT_TIME; @@ -1150,7 +1058,7 @@ gnc_pricedb_lookup_day(GNCPriceDB *db, pl.commodity = c; pl.currency = currency; pl.date = t; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, c); @@ -1210,7 +1118,7 @@ gnc_pricedb_lookup_day_any_currency(GNCPriceDB *db, /* Convert to noon local time. */ t = timespecCanonicalDayTime(t); - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_AT_TIME; @@ -1218,7 +1126,7 @@ gnc_pricedb_lookup_day_any_currency(GNCPriceDB *db, pl.commodity = c; pl.currency = NULL; /* can the backend handle this??? */ pl.date = t; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, c); @@ -1251,7 +1159,7 @@ gnc_pricedb_lookup_at_time(GNCPriceDB *db, ENTER ("db=%p commodity=%p currency=%p", db, c, currency); if(!db || !c || !currency) return NULL; - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_AT_TIME; @@ -1259,7 +1167,7 @@ gnc_pricedb_lookup_at_time(GNCPriceDB *db, pl.commodity = c; pl.currency = currency; pl.date = t; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, c); @@ -1315,7 +1223,7 @@ gnc_pricedb_lookup_at_time_any_currency(GNCPriceDB *db, ENTER ("db=%p commodity=%p", db, c); if(!db || !c) return NULL; - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_AT_TIME; @@ -1323,7 +1231,7 @@ gnc_pricedb_lookup_at_time_any_currency(GNCPriceDB *db, pl.commodity = c; pl.currency = NULL; /* can the backend handle this??? */ pl.date = t; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, c); @@ -1358,7 +1266,7 @@ gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db, ENTER ("db=%p commodity=%p currency=%p", db, c, currency); if(!db || !c || !currency) return NULL; - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_NEAREST_IN_TIME; @@ -1366,7 +1274,7 @@ gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db, pl.commodity = c; pl.currency = currency; pl.date = t; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, c); @@ -1482,7 +1390,7 @@ gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db, ENTER ("db=%p commodity=%p", db, c); if(!db || !c) return NULL; - if (db->book && db->book->backend && db->book->backend->price_lookup) + if (db->inst.book->backend && db->inst.book->backend->price_lookup) { GNCPriceLookup pl; pl.type = LOOKUP_NEAREST_IN_TIME; @@ -1490,7 +1398,7 @@ gnc_pricedb_lookup_nearest_in_time_any_currency(GNCPriceDB *db, pl.commodity = c; pl.currency = NULL; /* can the backend handle this??? */ pl.date = t; - (db->book->backend->price_lookup) (db->book->backend, &pl); + (db->inst.book->backend->price_lookup) (db->inst.book->backend, &pl); } currency_hash = g_hash_table_lookup(db->commodity_hash, c); @@ -1930,29 +1838,19 @@ gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f) fprintf(f, "\n"); } -/* ==================================================================== */ - -QofBackend * -xaccPriceDBGetBackend (GNCPriceDB *prdb) -{ - if (!prdb || !prdb->book) return NULL; - return prdb->book->backend; -} - /* ==================================================================== */ /* gncObject function implementation and registration */ static void pricedb_book_begin (QofBook *book) { - gnc_pricedb_set_db (book, gnc_pricedb_create(book)); + gnc_pricedb_create(book); } static void pricedb_book_end (QofBook *book) { - /* unhook the prices */ - gnc_pricedb_set_db (book, NULL); + /* ????? */ } static gboolean diff --git a/src/engine/gnc-pricedb.h b/src/engine/gnc-pricedb.h index c2991afab8..bff1fdb1bc 100644 --- a/src/engine/gnc-pricedb.h +++ b/src/engine/gnc-pricedb.h @@ -374,7 +374,7 @@ gboolean gnc_pricedb_foreach_price(GNCPriceDB *db, /** gnc_pricedb_dirty - return FALSE if the database has not been modified. */ -gboolean gnc_pricedb_dirty(GNCPriceDB *db); +#define gnc_pricedb_dirty(db) qof_instance_is_dirty(QOF_INSTANCE(db)) /** gnc_pricedb_get_num_prices - return the number of prices in the database. */ diff --git a/src/engine/gnc-be-utils.h b/src/engine/qof-be-utils.h similarity index 90% rename from src/engine/gnc-be-utils.h rename to src/engine/qof-be-utils.h index e55112b42c..14a38517e3 100644 --- a/src/engine/gnc-be-utils.h +++ b/src/engine/qof-be-utils.h @@ -1,5 +1,5 @@ /********************************************************************\ - * gnc-be-utils.h: api for data storage backend * + * 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 * @@ -18,23 +18,26 @@ * Boston, MA 02111-1307, USA gnu@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 +/** @addtogroup Object + @{ */ +/** @addtogroup Backend + * @{ + * @file qof-be-utils.h + * @brief QOF Backend Utilities + * @author Derek Atkins + * Common code used by objects to define begin_edit() and + * commit_edit() functions. * */ -#ifndef GNC_BE_UTILS_H -#define GNC_BE_UTILS_H +#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 +/** begin_edit helper * * @args: * inst: an instance of QofInstance @@ -42,7 +45,7 @@ * The caller should use this macro first and then perform any other operations. */ -#define GNC_BEGIN_EDIT(inst) \ +#define QOF_BEGIN_EDIT(inst) \ QofBackend * be; \ if (!(inst)) return; \ \ @@ -59,14 +62,14 @@ /* 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)); \ + (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 @@ -74,14 +77,14 @@ * Then call PART2. */ -/* +/** * part1 -- deal with the editlevel * * @args: * inst: an instance of QofInstance */ -#define GNC_COMMIT_EDIT_PART1(inst) { \ +#define QOF_COMMIT_EDIT_PART1(inst) { \ if (!(inst)) return; \ \ (inst)->editlevel--; \ @@ -95,7 +98,7 @@ QofBackend * be; \ be = qof_book_get_backend ((inst)->book); \ if (be && be->begin) { \ - (be->begin) (be, (inst)->entity.e_type, (inst)); \ + (be->begin) (be, (inst)); \ } \ (inst)->editlevel = 0; \ } \ @@ -108,7 +111,7 @@ (inst), (inst)->dirty, (inst)->do_free); \ } -/* +/** * part2 -- deal with the backend * * @args: @@ -122,7 +125,7 @@ * 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) { \ +#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. */ \ @@ -136,7 +139,7 @@ errcode = qof_backend_get_error (be); \ } while (ERR_BACKEND_NO_ERR != errcode); \ \ - (be->commit) (be, (inst)->entity.e_type, (inst)); \ + (be->commit) (be, (inst)); \ errcode = qof_backend_get_error (be); \ if (ERR_BACKEND_NO_ERR != errcode) \ { \ @@ -160,5 +163,6 @@ } \ } - -#endif /* GNC_BE_UTILS_H */ +#endif /* QOF_BE_UTILS_H */ +/** @} */ +/** @} */ diff --git a/src/engine/qofbackend-p.h b/src/engine/qofbackend-p.h index 6a20a2b6c8..4ca197814b 100644 --- a/src/engine/qofbackend-p.h +++ b/src/engine/qofbackend-p.h @@ -43,6 +43,7 @@ #include "qofbackend.h" #include "qofbook.h" +#include "qofinstance.h" #include "qofquery.h" #include "qofsession.h" @@ -108,11 +109,11 @@ * to ERR_BACKEND_MOD_DESTROY from this routine, so that the * engine can properly clean up. * - * The compile_query() method compiles a Gnucash query object into + * The compile_query() method compiles a QOF query object into * a backend-specific data structure and returns the compiled * query. For an SQL backend, the contents of the query object - * need to be turned into a corresponding SQL query statement, and - * sent to the database for evaluation. + * are typically turned into a corresponding SQL query statement, + * and sent to the database for evaluation. * * The free_query() method frees the data structure returned from * compile_query() @@ -234,9 +235,9 @@ struct _QofBackend 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); diff --git a/src/engine/qofbook-p.h b/src/engine/qofbook-p.h index 1edd3a2546..c92cf9dd14 100644 --- a/src/engine/qofbook-p.h +++ b/src/engine/qofbook-p.h @@ -41,16 +41,13 @@ #include "qofbook.h" #include "qofid.h" #include "qofid-p.h" +#include "qofinstance-p.h" /** Book structure */ struct _QofBook { - QofEntity entity; /**< Unique guid for this book. */ + QofInstance inst; /**< Unique guid for this book. */ - /** The KvpFrame provides a place for top-level data associated - * with this book. */ - KvpFrame *kvp_data; - /** The entity table associates the GUIDs of all the objects * belonging to this book, with their pointers to the respective * objects. This allows a lookup of objects based on thier guid. @@ -67,17 +64,14 @@ struct _QofBook /** state flag: 'y' means 'open for editing', * 'n' means 'book is closed' + * xxxxx shouldn't this be replaced by the instance editlevel ??? */ char book_open; - /** dirty/clean flag. If dirty, then this book has been modified, - * but has not yet been written out to storage (file/database) - */ - gboolean dirty; - /** a flag denoting whether the book is closing down, used to * help the QOF objects shut down cleanly without maintaining * internal consistency. + * XXX shouldn't this be replaced by instance->do_free ??? */ gboolean shutting_down; diff --git a/src/engine/qofbook.c b/src/engine/qofbook.c index 800dc46b01..9d76355e6f 100644 --- a/src/engine/qofbook.c +++ b/src/engine/qofbook.c @@ -58,16 +58,12 @@ static short module = MOD_ENGINE; static void qof_book_init (QofBook *book) { - QofCollection *col; if (!book) return; book->hash_of_collections = g_hash_table_new (g_str_hash, g_str_equal); - col = qof_book_get_collection (book, QOF_ID_BOOK); - qof_entity_init (&book->entity, QOF_ID_BOOK, col); + qof_instance_init (&book->inst, QOF_ID_BOOK, book); - book->kvp_data = kvp_frame_new (); - book->data_tables = g_hash_table_new (g_str_hash, g_str_equal); book->data_table_finalizers = g_hash_table_new (g_str_hash, g_str_equal); @@ -86,7 +82,7 @@ qof_book_new (void) qof_book_init(book); qof_object_book_begin (book); - gnc_engine_gen_event (&book->entity, GNC_EVENT_CREATE); + gnc_engine_gen_event (&book->inst.entity, GNC_EVENT_CREATE); LEAVE ("book=%p", book); return book; } @@ -116,7 +112,7 @@ qof_book_destroy (QofBook *book) ENTER ("book=%p", book); book->shutting_down = TRUE; - gnc_engine_force_event (&book->entity, GNC_EVENT_DESTROY); + gnc_engine_force_event (&book->inst.entity, GNC_EVENT_DESTROY); /* Call the list of finalizers, let them do thier thing. * Do this before tearing into the rest of the book. @@ -125,12 +121,10 @@ qof_book_destroy (QofBook *book) qof_object_book_end (book); - kvp_frame_delete (book->kvp_data); - g_hash_table_destroy (book->data_table_finalizers); g_hash_table_destroy (book->data_tables); - qof_entity_release (&book->entity); + qof_instance_release (&book->inst); g_hash_table_foreach_remove (book->hash_of_collections, coll_destroy, NULL); @@ -159,7 +153,7 @@ qof_book_not_saved(QofBook *book) { if (!book) return FALSE; - return(book->dirty || qof_object_is_dirty (book)); + return(book->inst.dirty || qof_object_is_dirty (book)); } void @@ -167,20 +161,13 @@ qof_book_mark_saved(QofBook *book) { if (!book) return; - book->dirty = FALSE; + book->inst.dirty = FALSE; qof_object_mark_clean (book); } /* ====================================================================== */ /* getters */ -KvpFrame * -qof_book_get_slots (QofBook *book) -{ - if (!book) return NULL; - return book->kvp_data; -} - QofBackend * qof_book_get_backend (QofBook *book) { @@ -209,7 +196,7 @@ qof_book_set_backend (QofBook *book, QofBackend *be) void qof_book_kvp_changed (QofBook *book) { if (!book) return; - book->dirty = TRUE; + book->inst.dirty = TRUE; } /* ====================================================================== */ @@ -352,8 +339,8 @@ qof_book_get_counter (QofBook *book, const char *counter_name) gboolean qof_book_register (void) { static QofParam params[] = { - { QOF_BOOK_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_book_get_slots, NULL }, { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL }, + { QOF_PARAM_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL }, { NULL }, }; diff --git a/src/engine/qofbook.h b/src/engine/qofbook.h index 96df2ecb0b..9ce6eac77a 100644 --- a/src/engine/qofbook.h +++ b/src/engine/qofbook.h @@ -99,7 +99,7 @@ void qof_book_foreach_collection (QofBook *, QofCollectionForeachCB, gpointer); * between multiple users). To store application runtime data, use * qof_book_set_data() isntead. */ -KvpFrame * qof_book_get_slots (QofBook *book); +#define qof_book_get_slots(book) qof_instance_get_slots(QOF_INSTANCE(book)) /** The qof_book_set_data() allows arbitrary pointers to structs * to be stored in QofBook. This is the "prefered" method for @@ -154,13 +154,6 @@ gboolean qof_book_equal (QofBook *book_1, QofBook *book_2); */ gint64 qof_book_get_counter (QofBook *book, const char *counter_name); -/** Book parameter names */ -/**@{*/ - -#define QOF_BOOK_KVP "qof-kvp" - -/**@}*/ - /** deprecated */ #define qof_book_get_guid(X) qof_entity_get_guid (QOF_ENTITY(X)) diff --git a/src/engine/qofinstance-p.h b/src/engine/qofinstance-p.h index fbfa6416b4..7dd474f494 100644 --- a/src/engine/qofinstance-p.h +++ b/src/engine/qofinstance-p.h @@ -73,7 +73,9 @@ struct QofInstance_s /** In process of being destroyed */ gboolean do_free; - /** This instance has not been saved yet */ + /** dirty/clean flag. If dirty, then this instance has been modified, + * but has not yet been written out to storage (file/database) + */ gboolean dirty; }; diff --git a/src/engine/qofinstance.c b/src/engine/qofinstance.c index b546c99b6a..3e9726c660 100644 --- a/src/engine/qofinstance.c +++ b/src/engine/qofinstance.c @@ -165,11 +165,11 @@ qof_instance_gemini (QofInstance *to, QofInstance *from) /* Make a note of where the copy came from */ gnc_kvp_bag_add (to->kvp_data, "gemini", now, "inst_guid", &from->entity.guid, - "book_guid", &from->book->entity.guid, + "book_guid", &from->book->inst.entity.guid, NULL); gnc_kvp_bag_add (from->kvp_data, "gemini", now, "inst_guid", &to->entity.guid, - "book_guid", &to->book->entity.guid, + "book_guid", &to->book->inst.entity.guid, NULL); to->dirty = TRUE; @@ -187,7 +187,7 @@ qof_instance_lookup_twin (QofInstance *src, QofBook *target_book) ENTER (" "); fr = gnc_kvp_bag_find_by_guid (src->kvp_data, "gemini", - "book_guid", &target_book->entity.guid); + "book_guid", &target_book->inst.entity.guid); twin_guid = kvp_frame_get_guid (fr, "inst_guid"); diff --git a/src/engine/qofquery.h b/src/engine/qofquery.h index 1b4a33f446..4af66399cb 100644 --- a/src/engine/qofquery.h +++ b/src/engine/qofquery.h @@ -109,6 +109,7 @@ typedef enum { #define QOF_PARAM_GUID "guid" /** "Known" Object Parameters -- some objects might support these */ +#define QOF_PARAM_KVP "kvp" #define QOF_PARAM_ACTIVE "active" /* --------------------------------------------------------- */