diff --git a/src/engine/Account.c b/src/engine/Account.c index 1b5df57377..4169ab29ad 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -31,7 +31,6 @@ #include "AccountP.h" #include "Backend.h" #include "BackendP.h" -#include "GNCIdP.h" #include "Group.h" #include "GroupP.h" #include "TransactionP.h" @@ -48,6 +47,7 @@ #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" #include "qofobject.h" #include "qofqueryobject.h" @@ -127,8 +127,8 @@ xaccInitAccount (Account * acc, QofBook *book) acc->book = book; - xaccGUIDNew(&acc->guid, book); - xaccStoreEntity(book->entity_table, acc, &acc->guid, GNC_ID_ACCOUNT); + qof_entity_guid_new (book->entity_table, &acc->guid); + qof_entity_store(book->entity_table, acc, &acc->guid, GNC_ID_ACCOUNT); LEAVE ("account=%p\n", acc); } @@ -281,7 +281,7 @@ xaccFreeAccount (Account *acc) gnc_engine_generate_event (&acc->guid, GNC_EVENT_DESTROY); - xaccRemoveEntity (acc->book->entity_table, &acc->guid); + qof_entity_remove (acc->book->entity_table, &acc->guid); if (acc->children) { @@ -826,7 +826,7 @@ const GUID * xaccAccountGetGUID (Account *account) { if (!account) - return xaccGUIDNULL(); + return guid_null(); return &account->guid; } @@ -835,7 +835,7 @@ GUID xaccAccountReturnGUID (Account *account) { if (!account) - return *xaccGUIDNULL(); + return *guid_null(); return account->guid; } @@ -850,11 +850,11 @@ xaccAccountSetGUID (Account *account, const GUID *guid) PINFO("acct=%p", account); xaccAccountBeginEdit (account); - xaccRemoveEntity (account->book->entity_table, &account->guid); + qof_entity_remove (account->book->entity_table, &account->guid); account->guid = *guid; - xaccStoreEntity (account->book->entity_table, account, + qof_entity_store (account->book->entity_table, account, &account->guid, GNC_ID_ACCOUNT); account->core_dirty = TRUE; xaccAccountCommitEdit (account); @@ -867,7 +867,7 @@ Account * xaccAccountLookup (const GUID *guid, QofBook *book) { if (!guid || !book) return NULL; - return xaccLookupEntity (qof_book_get_entity_table (book), + return qof_entity_lookup (qof_book_get_entity_table (book), guid, GNC_ID_ACCOUNT); } @@ -875,7 +875,7 @@ Account * xaccAccountLookupDirect (GUID guid, QofBook *book) { if (!book) return NULL; - return xaccLookupEntity (qof_book_get_entity_table (book), + return qof_entity_lookup (qof_book_get_entity_table (book), &guid, GNC_ID_ACCOUNT); } @@ -3164,15 +3164,15 @@ xaccAccountGetBackend (Account * acc) /* gncObject function implementation and registration */ static void -account_foreach (QofBook *book, foreachObjectCB cb, gpointer ud) +account_foreach (QofBook *book, QofEntityForeachCB cb, gpointer ud) { - GNCEntityTable *et; + QofEntityTable *et; g_return_if_fail (book); g_return_if_fail (cb); et = qof_book_get_entity_table (book); - xaccForeachEntity (et, GNC_ID_ACCOUNT, cb, ud); + qof_entity_foreach (et, GNC_ID_ACCOUNT, cb, ud); } static QofObject account_object_def = { diff --git a/src/engine/Account.h b/src/engine/Account.h index 570f7daec3..1969e87b8f 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -28,8 +28,8 @@ #ifndef XACC_ACCOUNT_H #define XACC_ACCOUNT_H -#include "GNCId.h" #include "gnc-engine.h" +#include "guid.h" #include "kvp_frame.h" #include "qofbook.h" diff --git a/src/engine/AccountP.h b/src/engine/AccountP.h index 61774cc9ac..383016d5d3 100644 --- a/src/engine/AccountP.h +++ b/src/engine/AccountP.h @@ -43,12 +43,12 @@ #include "Account.h" #include "Backend.h" -#include "GNCIdP.h" #include "gnc-commodity.h" #include "gnc-engine.h" #include "gnc-numeric.h" #include "kvp_frame.h" #include "qofbook.h" +#include "qofid.h" /** STRUCTS *********************************************************/ diff --git a/src/engine/BackendP.h b/src/engine/BackendP.h index 2f4b17b5c3..2313ab8f42 100644 --- a/src/engine/BackendP.h +++ b/src/engine/BackendP.h @@ -235,9 +235,9 @@ struct backend_s void (*load) (Backend *, QofBook *); - void (*begin) (Backend *, GNCIdTypeConst, gpointer); - void (*commit) (Backend *, GNCIdTypeConst, gpointer); - void (*rollback) (Backend *, GNCIdTypeConst, gpointer); + void (*begin) (Backend *, QofIdTypeConst, gpointer); + void (*commit) (Backend *, QofIdTypeConst, gpointer); + void (*rollback) (Backend *, QofIdTypeConst, gpointer); gpointer (*compile_query) (Backend *, QofQuery *); void (*free_query) (Backend *, gpointer); diff --git a/src/engine/FreqSpec.c b/src/engine/FreqSpec.c index 48fc405f57..266a0caa0a 100644 --- a/src/engine/FreqSpec.c +++ b/src/engine/FreqSpec.c @@ -85,13 +85,13 @@ #endif #include "FreqSpecP.h" -#include "GNCIdP.h" #include "gnc-date.h" #include "gnc-engine-util.h" #include "gnc-event-p.h" #include "messages.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" /* I have done this to prevent compiler warnings... * This is used to convert a const GDate* to a GDate* for passing @@ -184,8 +184,8 @@ xaccFreqSpecInit( FreqSpec *fs, QofBook *book ) fs->entity_table = qof_book_get_entity_table (book); - xaccGUIDNew( &fs->guid, book ); - xaccStoreEntity( fs->entity_table, fs, &fs->guid, GNC_ID_FREQSPEC ); + qof_entity_guid_new (fs->entity_table, &fs->guid); + qof_entity_store( fs->entity_table, fs, &fs->guid, GNC_ID_FREQSPEC ); fs->type = INVALID; fs->uift = UIFREQ_ONCE; @@ -234,7 +234,7 @@ xaccFreqSpecFree( FreqSpec *fs ) { if ( fs == NULL ) return; gnc_engine_generate_event( &fs->guid, GNC_EVENT_DESTROY ); - xaccRemoveEntity( fs->entity_table, &fs->guid ); + qof_entity_remove( fs->entity_table, &fs->guid ); xaccFreqSpecCleanUp( fs ); diff --git a/src/engine/FreqSpec.h b/src/engine/FreqSpec.h index 55b62fe0de..159ee18c53 100644 --- a/src/engine/FreqSpec.h +++ b/src/engine/FreqSpec.h @@ -32,8 +32,8 @@ #include -#include "GNCId.h" #include "gnc-engine.h" +#include "guid.h" #include "qofbook.h" /** diff --git a/src/engine/FreqSpecP.h b/src/engine/FreqSpecP.h index eae13b1329..27bc9a5160 100644 --- a/src/engine/FreqSpecP.h +++ b/src/engine/FreqSpecP.h @@ -34,7 +34,7 @@ Currently the only files which include this file are: #define XACC_FREQSPECP_H #include "FreqSpec.h" -#include "GNCIdP.h" +#include "qofid.h" /** * Scheduled transactions have a frequency defined by a frequency @@ -108,7 +108,7 @@ struct gncp_freq_spec { } composites; } s; GUID guid; - GNCEntityTable *entity_table; + QofEntityTable *entity_table; }; #endif /* XACC_FREQSPECP_H */ diff --git a/src/engine/GNCId.h b/src/engine/GNCId.h index 79669ce66a..810fe17dfa 100644 --- a/src/engine/GNCId.h +++ b/src/engine/GNCId.h @@ -1,93 +1,38 @@ -/********************************************************************\ - * GNCId.h -- Gnucash entity identifier API * - * Copyright (C) 2000 Dave Peticolas * - * * - * 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@gnu.org * - * * -\********************************************************************/ -#ifndef GNC_ID_H -#define GNC_ID_H - -/* This file defines an API for using gnucash entity identifiers. - * - * Identifiers can be used to reference Accounts, Transactions, and - * Splits. These four Gnucash types are referred to as Gnucash - * entities. Identifiers are globally-unique and permanent, i.e., once - * an entity has been assigned an identifier, it retains that same - * identifier for its lifetime. - * - * Identifiers can be encoded as hex strings. */ - -#include "guid.h" - -/* Identifiers are 'typed' with strings. The ids used in gnucash are - * defined below. An id with type GNC_ID_NONE does not refer to any - * entity, although that may change as new ids are created. An id with - * type GNC_ID_NULL does not refer to any entity, and will never refer - * to any entity. An identifier with any other type may refer to an - * actual entity, but that is not guaranteed. If an id does refer to - * an entity, the type of the entity will match the type of the - * identifier. */ - -typedef const char * GNCIdType; -typedef const char * GNCIdTypeConst; - -#define GNC_ID_NONE NULL -#define GNC_ID_ACCOUNT "Account" -#define GNC_ID_BOOK "Book" -#define GNC_ID_COMMODITY_TABLE "CommodityTable" -#define GNC_ID_FREQSPEC "FreqSpec" -#define GNC_ID_GROUP "AccountGroup" -#define GNC_ID_LOT "Lot" -#define GNC_ID_NULL "null" -#define GNC_ID_PERIOD "Period" -#define GNC_ID_PRICE "Price" -#define GNC_ID_PRICEDB "PriceDB" -#define GNC_ID_SPLIT "Split" -#define GNC_ID_SCHEDXACTION "SchedXaction" -#define GNC_ID_SESSION "Session" -#define GNC_ID_SXTT "SXTT" -#define GNC_ID_TRANS "Trans" - - -typedef struct gnc_entity_table GNCEntityTable; - -GNCIdType xaccGUIDTypeEntityTable (const GUID * guid, - GNCEntityTable *entity_table); +#include "qofid.h" /* Return the type of an identifier. * Equivalent function prototype: - * GNCIdType xaccGUIDType (const GUID * guid, QofBook *book); + * QofIdType xaccGUIDType (const GUID * guid, QofBook *book); */ #define xaccGUIDType(guid,book) \ - xaccGUIDTypeEntityTable ((guid), qof_book_get_entity_table (book)) + qof_entity_type (qof_book_get_entity_table (book), (guid)) + +/* Equivalent function prototype: + * void xaccGUIDNew (GUID *guid, QofBook *book) + */ +#define xaccGUIDNew(guid,book) \ + qof_entity_guid_new (qof_book_get_entity_table (book), (guid)) + -/* Returns a GUID which is guaranteed to never reference any entity. */ -const GUID * xaccGUIDNULL (void); + #define xaccGUIDNULL guid_null + #define xaccGUIDMalloc guid_malloc + #define xaccGUIDFree guid_free -/* Efficiently allocate & free memory for GUIDs */ -GUID * xaccGUIDMalloc (void); -void xaccGUIDFree (GUID *guid); + #define GNCIdTypeConst QofIdTypeConst + #define GNCIdType QofIdType + #define GNCEntityTable QofEntityTable + #define xaccGUIDTypeEntityTable qof_guid_type -/* Callback type for xaccForeachEntity */ -typedef void (*foreachObjectCB) (gpointer object, gpointer user_data); + #define xaccEntityTableNew qof_entity_new + #define xaccEntityTableDestroy qof_entity_destroy + #define xaccGUIDNewEntityTable qof_entity_guid_new + #define xaccLookupEntity qof_entity_lookup + #define xaccStoreEntity qof_entity_store + #define xaccRemoveEntity qof_entity_remove + #define xaccForeachEntity qof_entity_foreach + + #define foreachObjectCB QofEntityForeachCB -#endif diff --git a/src/engine/Group.c b/src/engine/Group.c index d592ca9f1e..e54ec1c08e 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -31,7 +31,6 @@ #include "AccountP.h" #include "Backend.h" #include "BackendP.h" -#include "GNCIdP.h" #include "Group.h" #include "GroupP.h" #include "TransactionP.h" @@ -40,6 +39,7 @@ #include "gnc-numeric.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" #include "qofobject.h" static short module = MOD_ENGINE; @@ -746,9 +746,9 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc) PWARN ("reparenting accounts accross books is not correctly supported\n"); gnc_engine_generate_event (&acc->guid, GNC_EVENT_DESTROY); - xaccRemoveEntity (acc->book->entity_table, &acc->guid); + qof_entity_remove (acc->book->entity_table, &acc->guid); - xaccStoreEntity (grp->book->entity_table, acc, &acc->guid, GNC_ID_ACCOUNT); + qof_entity_store (grp->book->entity_table, acc, &acc->guid, GNC_ID_ACCOUNT); gnc_engine_generate_event (&acc->guid, GNC_EVENT_CREATE); } } diff --git a/src/engine/Group.h b/src/engine/Group.h index 3b0954b9d8..31cfeca4f2 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -28,8 +28,8 @@ #include #include "Account.h" -#include "GNCId.h" #include "gnc-engine.h" +#include "guid.h" #include "qofbook.h" diff --git a/src/engine/GroupP.h b/src/engine/GroupP.h index 5a4d486aef..7e04dfb502 100644 --- a/src/engine/GroupP.h +++ b/src/engine/GroupP.h @@ -39,10 +39,10 @@ #include "config.h" #include "BackendP.h" -#include "GNCIdP.h" #include "Transaction.h" #include "gnc-numeric.h" #include "qofbook.h" +#include "qofid.h" /** STRUCTS *********************************************************/ diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index 14fa562322..d0fe7c6fe7 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -12,7 +12,6 @@ libgncmod_engine_la_SOURCES = \ Account.c \ Backend.c \ FreqSpec.c \ - GNCId.c \ Group.c \ Period.c \ Query.c \ @@ -42,6 +41,7 @@ libgncmod_engine_la_SOURCES = \ md5.c \ messages.c \ qofbook.c \ + qofid.c \ qofquery.c \ qofquerycore.c \ qofqueryobject.c \ @@ -90,6 +90,7 @@ gncinclude_HEADERS = \ kvp-util.h \ messages.h \ qofbook.h \ + qofid.h \ qofquery.h \ qofquerycore.h \ qofqueryobject.h \ @@ -99,7 +100,6 @@ noinst_HEADERS = \ AccountP.h \ BackendP.h \ FreqSpecP.h \ - GNCIdP.h \ GroupP.h \ QueryP.h \ SchedXactionP.h \ @@ -117,6 +117,7 @@ noinst_HEADERS = \ gw-engine.h \ gw-kvp.h \ qofbook-p.h \ + qofid-p.h \ qofquery-p.h \ qofquerycore-p.h \ qofqueryobject-p.h \ diff --git a/src/engine/Period.c b/src/engine/Period.c index c4d9efb274..0a102765fa 100644 --- a/src/engine/Period.c +++ b/src/engine/Period.c @@ -46,6 +46,7 @@ Open questions: how do we deal with the backends ??? #include "TransactionP.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" /* This static indicates the debugging module that this .o belongs to. */ static short module = MOD_BOOK; @@ -81,7 +82,7 @@ gnc_book_insert_trans_clobber (QofBook *book, Transaction *trans) xaccTransCommitEdit (trans); /* fiddle the transaction into place in the new book */ - xaccStoreEntity(book->entity_table, newtrans, &newtrans->guid, GNC_ID_TRANS); + qof_entity_store(book->entity_table, newtrans, &newtrans->guid, GNC_ID_TRANS); newtrans->book = book; xaccTransBeginEdit (newtrans); @@ -92,7 +93,7 @@ gnc_book_insert_trans_clobber (QofBook *book, Transaction *trans) /* move the split into the new book ... */ s->book = book; - xaccStoreEntity(book->entity_table, s, &s->guid, GNC_ID_SPLIT); + qof_entity_store(book->entity_table, s, &s->guid, GNC_ID_SPLIT); /* find the twin account, and re-parent to that. */ twin = xaccAccountLookupTwin (s->acc, book); @@ -140,9 +141,9 @@ gnc_book_insert_trans (QofBook *book, Transaction *trans) /* Fiddle the transaction into place in the new book */ xaccTransBeginEdit (trans); - xaccRemoveEntity (trans->book->entity_table, &trans->guid); + qof_entity_remove (trans->book->entity_table, &trans->guid); trans->book = book; - xaccStoreEntity(book->entity_table, trans, &trans->guid, GNC_ID_TRANS); + qof_entity_store(book->entity_table, trans, &trans->guid, GNC_ID_TRANS); for (node = trans->splits; node; node = node->next) { @@ -150,9 +151,9 @@ gnc_book_insert_trans (QofBook *book, Transaction *trans) Split *s = node->data; /* move the split into the new book ... */ - xaccRemoveEntity (s->book->entity_table, &s->guid); + qof_entity_remove (s->book->entity_table, &s->guid); s->book = book; - xaccStoreEntity(book->entity_table, s, &s->guid, GNC_ID_SPLIT); + qof_entity_store(book->entity_table, s, &s->guid, GNC_ID_SPLIT); /* find the twin account, and re-parent to that. */ twin = xaccAccountLookupTwin (s->acc, book); diff --git a/src/engine/Query.c b/src/engine/Query.c index f3ff3af00d..31a367e21b 100644 --- a/src/engine/Query.c +++ b/src/engine/Query.c @@ -36,7 +36,6 @@ #include "gnc-engine-util.h" #include "gnc-numeric.h" #include "Account.h" -#include "GNCId.h" #include "Query.h" #include "Transaction.h" #include "TransactionP.h" @@ -476,7 +475,7 @@ xaccQueryAddClearedMatch(Query * q, cleared_match_t how, QofQueryOp op) void xaccQueryAddGUIDMatch(Query * q, const GUID *guid, - GNCIdType id_type, QofQueryOp op) + QofIdType id_type, QofQueryOp op) { GSList *param_list = NULL; @@ -513,7 +512,7 @@ xaccQueryAddGUIDMatchGL (QofQuery *q, GList *param_list, void xaccQueryAddKVPMatch(QofQuery *q, GSList *path, const kvp_value *value, - QofQueryCompare how, GNCIdType id_type, + QofQueryCompare how, QofIdType id_type, QofQueryOp op) { GSList *param_list = NULL; diff --git a/src/engine/Query.h b/src/engine/Query.h index b739889432..227a1d3e5c 100644 --- a/src/engine/Query.h +++ b/src/engine/Query.h @@ -30,7 +30,6 @@ #include "gnc-date.h" #include "gnc-engine.h" -#include "GNCId.h" #include "guid.h" #include "kvp_frame.h" @@ -202,13 +201,13 @@ typedef enum { void xaccQueryAddClearedMatch(Query * q, cleared_match_t how, QofQueryOp op); void xaccQueryAddGUIDMatch(Query * q, const GUID *guid, - GNCIdType id_type, QofQueryOp op); + QofIdType id_type, QofQueryOp op); void xaccQueryAddGUIDMatchGL (QofQuery *q, GList *param_list, GUID guid, QofQueryOp op); /* given kvp value is on right side of comparison */ void xaccQueryAddKVPMatch(Query *q, GSList *path, const kvp_value *value, - QofQueryCompare how, GNCIdType id_type, + QofQueryCompare how, QofIdType id_type, QofQueryOp op); void xaccQuerySetSortOrder(Query *q, GList *p1, GList *p2, GList *p3); diff --git a/src/engine/QueryP.h b/src/engine/QueryP.h index 687f980f3b..9982200b78 100644 --- a/src/engine/QueryP.h +++ b/src/engine/QueryP.h @@ -80,7 +80,7 @@ typedef struct { pr_type_t term_type; int sense; GUID guid; - GNCIdType id_type; + QofIdType id_type; } GUIDPredicateData; typedef struct { diff --git a/src/engine/SchedXaction.c b/src/engine/SchedXaction.c index 2a4791359b..e5099ad76b 100644 --- a/src/engine/SchedXaction.c +++ b/src/engine/SchedXaction.c @@ -27,7 +27,6 @@ #include #include "FreqSpec.h" -#include "GNCId.h" #include "Group.h" #include "GroupP.h" #include "SX-book.h" @@ -42,6 +41,7 @@ #include "messages.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" static short module = MOD_SX; @@ -59,8 +59,8 @@ xaccSchedXactionInit( SchedXaction *sx, QofBook *book) sx->freq = xaccFreqSpecMalloc(book); - xaccGUIDNew( &sx->guid, book ); - xaccStoreEntity( sx->entity_table, sx, + qof_entity_guid_new (sx->entity_table, &sx->guid); + qof_entity_store( sx->entity_table, sx, &sx->guid, GNC_ID_SCHEDXACTION ); g_date_clear( &sx->last_date, 1 ); g_date_clear( &sx->start_date, 1 ); @@ -154,7 +154,7 @@ xaccSchedXactionFree( SchedXaction *sx ) xaccFreqSpecFree( sx->freq ); gnc_engine_generate_event( &sx->guid, GNC_EVENT_DESTROY ); - xaccRemoveEntity( sx->entity_table, &sx->guid ); + qof_entity_remove( sx->entity_table, &sx->guid ); if ( sx->name ) g_free( sx->name ); diff --git a/src/engine/SchedXaction.h b/src/engine/SchedXaction.h index d4d8b02d0c..855ff0e633 100644 --- a/src/engine/SchedXaction.h +++ b/src/engine/SchedXaction.h @@ -32,10 +32,10 @@ #include #include -#include "GNCId.h" #include "FreqSpec.h" #include "gnc-date.h" #include "gnc-engine.h" +#include "guid.h" #include "kvp_frame.h" #include "qofbook.h" diff --git a/src/engine/SchedXactionP.h b/src/engine/SchedXactionP.h index a7a347e6df..20e7fafcb1 100644 --- a/src/engine/SchedXactionP.h +++ b/src/engine/SchedXactionP.h @@ -24,8 +24,8 @@ #ifndef XACC_SCHEDXACTION_P_H #define XACC_SCHEDXACTION_P_H -#include "GNCIdP.h" #include "SchedXaction.h" +#include "qofid.h" /** * A single scheduled transaction. @@ -75,7 +75,7 @@ struct gncp_SchedXaction Account *template_acct; GUID guid; - GNCEntityTable *entity_table; + QofEntityTable *entity_table; /** The list of deferred SX instances. This list is of temporalStateData * instances. */ diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 6c750cd0c8..cc4d321a95 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -34,7 +34,6 @@ #include "AccountP.h" #include "Backend.h" #include "BackendP.h" -#include "GNCIdP.h" #include "Group.h" #include "TransactionP.h" #include "TransLog.h" @@ -49,6 +48,7 @@ #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" #include "qofobject.h" #include "qofqueryobject.h" @@ -132,8 +132,8 @@ xaccInitSplit(Split * split, QofBook *book) split->book = book; - xaccGUIDNew (&split->guid, book); - xaccStoreEntity(book->entity_table, split, &split->guid, GNC_ID_SPLIT); + qof_entity_guid_new (book->entity_table, &split->guid); + qof_entity_store(book->entity_table, split, &split->guid, GNC_ID_SPLIT); } /********************************************************************\ @@ -213,8 +213,8 @@ xaccSplitClone (Split *s) split->reconciled_balance = s->reconciled_balance; split->idata = 0; - xaccGUIDNew(&split->guid, s->book); - xaccStoreEntity(s->book->entity_table, split, &split->guid, GNC_ID_SPLIT); + qof_entity_guid_new(s->book->entity_table, &split->guid); + qof_entity_store(s->book->entity_table, split, &split->guid, GNC_ID_SPLIT); xaccAccountInsertSplit(s->acc, split); if (s->lot) { @@ -439,14 +439,14 @@ xaccSplitGetAccount (const Split *s) const GUID * xaccSplitGetGUID (const Split *split) { - if (!split) return xaccGUIDNULL(); + if (!split) return guid_null(); return &split->guid; } GUID xaccSplitReturnGUID (const Split *split) { - if (!split) return *xaccGUIDNULL(); + if (!split) return *guid_null(); return split->guid; } @@ -458,9 +458,9 @@ xaccSplitSetGUID (Split *split, const GUID *guid) { if (!split || !guid) return; check_open (split->parent); - xaccRemoveEntity(split->book->entity_table, &split->guid); + qof_entity_remove(split->book->entity_table, &split->guid); split->guid = *guid; - xaccStoreEntity(split->book->entity_table, split, + qof_entity_store(split->book->entity_table, split, &split->guid, GNC_ID_SPLIT); } @@ -471,7 +471,7 @@ Split * xaccSplitLookup (const GUID *guid, QofBook *book) { if (!guid || !book) return NULL; - return xaccLookupEntity(qof_book_get_entity_table (book), + return qof_entity_lookup(qof_book_get_entity_table (book), guid, GNC_ID_SPLIT); } @@ -479,7 +479,7 @@ Split * xaccSplitLookupDirect (GUID guid, QofBook *book) { if (!book) return NULL; - return xaccLookupEntity(qof_book_get_entity_table (book), + return qof_entity_lookup(qof_book_get_entity_table (book), &guid, GNC_ID_SPLIT); } @@ -839,8 +839,8 @@ xaccInitTransaction (Transaction * trans, QofBook *book) trans->book = book; - xaccGUIDNew (&trans->guid, book); - xaccStoreEntity (book->entity_table, trans, &trans->guid, GNC_ID_TRANS); + qof_entity_guid_new (book->entity_table, &trans->guid); + qof_entity_store (book->entity_table, trans, &trans->guid, GNC_ID_TRANS); } /********************************************************************\ @@ -1005,8 +1005,8 @@ xaccTransClone (Transaction *t) trans->orig = NULL; trans->idata = 0; - xaccGUIDNew (&trans->guid, t->book); - xaccStoreEntity (t->book->entity_table, trans, &trans->guid, GNC_ID_TRANS); + qof_entity_guid_new (t->book->entity_table, &trans->guid); + qof_entity_store (t->book->entity_table, trans, &trans->guid, GNC_ID_TRANS); xaccTransBeginEdit(trans); for (node = t->splits; node; node = node->next) @@ -1269,14 +1269,14 @@ xaccTransSetSlots_nc (Transaction *t, kvp_frame *frm) const GUID * xaccTransGetGUID (const Transaction *trans) { - if (!trans) return xaccGUIDNULL(); + if (!trans) return guid_null(); return &trans->guid; } GUID xaccTransReturnGUID (const Transaction *trans) { - if (!trans) return *xaccGUIDNULL(); + if (!trans) return *guid_null(); return trans->guid; } @@ -1287,9 +1287,9 @@ void xaccTransSetGUID (Transaction *trans, const GUID *guid) { if (!trans || !guid) return; - xaccRemoveEntity(trans->book->entity_table, &trans->guid); + qof_entity_remove(trans->book->entity_table, &trans->guid); trans->guid = *guid; - xaccStoreEntity(trans->book->entity_table, trans, + qof_entity_store(trans->book->entity_table, trans, &trans->guid, GNC_ID_TRANS); } @@ -1301,7 +1301,7 @@ Transaction * xaccTransLookup (const GUID *guid, QofBook *book) { if (!guid || !book) return NULL; - return xaccLookupEntity (qof_book_get_entity_table (book), + return qof_entity_lookup (qof_book_get_entity_table (book), guid, GNC_ID_TRANS); } @@ -1309,7 +1309,7 @@ Transaction * xaccTransLookupDirect (GUID guid, QofBook *book) { if (!book) return NULL; - return xaccLookupEntity (qof_book_get_entity_table (book), + return qof_entity_lookup (qof_book_get_entity_table (book), &guid, GNC_ID_TRANS); } @@ -1867,7 +1867,7 @@ xaccTransCommitEdit (Transaction *trans) PINFO ("delete trans at addr=%p", trans); /* Make a log in the journal before destruction. */ xaccTransWriteLog (trans, 'D'); - xaccRemoveEntity(trans->book->entity_table, &trans->guid); + qof_entity_remove(trans->book->entity_table, &trans->guid); xaccFreeTransaction (trans); return; } @@ -1920,7 +1920,7 @@ xaccTransRollbackEdit (Transaction *trans) /* If the transaction had been deleted before the rollback, * the guid would have been unlisted. Restore that */ - xaccStoreEntity(trans->book->entity_table, trans, + qof_entity_store(trans->book->entity_table, trans, &trans->guid, GNC_ID_TRANS); trans->common_currency = orig->common_currency; @@ -2046,7 +2046,7 @@ xaccTransRollbackEdit (Transaction *trans) xaccAccountRemoveSplit (acc, s); xaccAccountRecomputeBalance (acc); gen_event (s); - xaccRemoveEntity(s->book->entity_table, &s->guid); + qof_entity_remove(s->book->entity_table, &s->guid); xaccFreeSplit (s); } @@ -2064,7 +2064,7 @@ xaccTransRollbackEdit (Transaction *trans) s->parent = trans; s->acc = NULL; - xaccStoreEntity(s->book->entity_table, s, &s->guid, GNC_ID_SPLIT); + qof_entity_store(s->book->entity_table, s, &s->guid, GNC_ID_SPLIT); xaccAccountInsertSplit (account, s); mark_split (s); xaccAccountRecomputeBalance (account); @@ -2191,7 +2191,7 @@ xaccTransDestroy (Transaction *trans) xaccAccountRemoveSplit (split->acc, split); xaccAccountRecomputeBalance (split->acc); gen_event (split); - xaccRemoveEntity(split->book->entity_table, &split->guid); + qof_entity_remove(split->book->entity_table, &split->guid); xaccFreeSplit (split); node->data = NULL; @@ -2200,7 +2200,7 @@ xaccTransDestroy (Transaction *trans) g_list_free (trans->splits); trans->splits = NULL; - xaccRemoveEntity(trans->book->entity_table, &trans->guid); + qof_entity_remove(trans->book->entity_table, &trans->guid); /* the actual free is done with the commit call, else its rolled back */ /* xaccFreeTransaction (trans); don't do this here ... */ @@ -2257,7 +2257,7 @@ xaccSplitDestroy (Split *split) xaccAccountRecomputeBalance (acc); gen_event (split); - xaccRemoveEntity (split->book->entity_table, &split->guid); + qof_entity_remove (split->book->entity_table, &split->guid); xaccFreeSplit (split); return TRUE; } @@ -3542,19 +3542,19 @@ xaccTransactionGetBackend (Transaction *trans) \********************************************************************/ /* gncObject function implementation */ static void -do_foreach (QofBook *book, GNCIdType type, foreachObjectCB cb, gpointer ud) +do_foreach (QofBook *book, QofIdType type, QofEntityForeachCB cb, gpointer ud) { - GNCEntityTable *et; + QofEntityTable *et; g_return_if_fail (book); g_return_if_fail (cb); et = qof_book_get_entity_table (book); - xaccForeachEntity (et, type, cb, ud); + qof_entity_foreach (et, type, cb, ud); } static void -split_foreach (QofBook *book, foreachObjectCB fcn, gpointer user_data) +split_foreach (QofBook *book, QofEntityForeachCB fcn, gpointer user_data) { do_foreach (book, GNC_ID_SPLIT, fcn, user_data); } @@ -3642,7 +3642,7 @@ gboolean xaccSplitRegister (void) } static void -trans_foreach (QofBook *book, foreachObjectCB fcn, gpointer user_data) +trans_foreach (QofBook *book, QofEntityForeachCB fcn, gpointer user_data) { do_foreach (book, GNC_ID_TRANS, fcn, user_data); } diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index 0a0f736457..f33fa383ca 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -33,8 +33,8 @@ #include "gnc-commodity.h" #include "gnc-date.h" #include "gnc-engine.h" +#include "guid.h" #include "kvp_frame.h" -#include "GNCId.h" #include "qofbook.h" /** @name Split Reconciled field values diff --git a/src/engine/TransactionP.h b/src/engine/TransactionP.h index a0eda7d5d2..5ab99eb5dc 100644 --- a/src/engine/TransactionP.h +++ b/src/engine/TransactionP.h @@ -53,9 +53,9 @@ #include "Backend.h" #include "gnc-engine.h" /* for typedefs */ #include "gnc-numeric.h" -#include "GNCIdP.h" #include "kvp_frame.h" #include "qofbook.h" +#include "qofid.h" /** STRUCTS *********************************************************/ diff --git a/src/engine/engine-helpers.c b/src/engine/engine-helpers.c index fdaa861cbd..8a1e9a3a29 100644 --- a/src/engine/engine-helpers.c +++ b/src/engine/engine-helpers.c @@ -434,10 +434,10 @@ gnc_scm2balance_match_how (SCM how_scm, gboolean *resp) return TRUE; } -static GNCIdType +static QofIdType gnc_scm2kvp_match_where (SCM where_scm) { - GNCIdType res; + QofIdType res; char *where; if (!SCM_LISTP (where_scm)) @@ -490,7 +490,7 @@ gnc_scm2guid_glist (SCM guids_scm) SCM guid_scm = SCM_CAR (guids_scm); GUID *guid; - guid = xaccGUIDMalloc (); + guid = guid_malloc (); *guid = gnc_scm2guid (guid_scm); guids = g_list_prepend (guids, guid); @@ -507,7 +507,7 @@ gnc_guid_glist_free (GList *guids) GList *node; for (node = guids; node; node = node->next) - xaccGUIDFree (node->data); + guid_free (node->data); g_list_free (guids); } @@ -1410,7 +1410,7 @@ gnc_scm2query_term_query_v1 (SCM query_term_scm) } else if (!safe_strcmp (pd_type, "pd-guid")) { GUID guid; - GNCIdType id_type; + QofIdType id_type; char *tmp; /* guid */ @@ -1435,7 +1435,7 @@ gnc_scm2query_term_query_v1 (SCM query_term_scm) GSList *path; kvp_value *value; QofQueryCompare how; - GNCIdType where; + QofIdType where; /* how */ if (SCM_NULLP (query_term_scm)) diff --git a/src/engine/engine-helpers.h b/src/engine/engine-helpers.h index 7769aa3f7a..b7727084e6 100644 --- a/src/engine/engine-helpers.h +++ b/src/engine/engine-helpers.h @@ -31,9 +31,9 @@ #include "gnc-engine.h" #include "gnc-session.h" #include "Account.h" -#include "GNCId.h" #include "Query.h" #include "Transaction.h" +#include "guid.h" #include "guile-mappings.h" #include "qofbook.h" diff --git a/src/engine/gnc-associate-account.c b/src/engine/gnc-associate-account.c index 76a5c3d6b4..ada5254a48 100644 --- a/src/engine/gnc-associate-account.c +++ b/src/engine/gnc-associate-account.c @@ -29,11 +29,11 @@ #include "config.h" #include "AccountP.h" -#include "GNCIdP.h" #include "gnc-associate-account.h" #include "gnc-engine.h" #include "gnc-engine-util.h" #include "qofbook.h" +#include "qofid.h" static short module = MOD_ENGINE; @@ -94,7 +94,7 @@ back_associate_expense_accounts(Account *stock_account, g_return_if_fail(kvp_value_get_type(val) == KVP_TYPE_GUID); existing_acc_guid = kvp_value_get_guid(val); - g_return_if_fail(GNC_ID_NONE == xaccGUIDType (existing_acc_guid, stock_account->book)); + g_return_if_fail(GNC_ID_NONE == qof_entity_type (qof_book_get_entity_table (stock_account->book), existing_acc_guid)); kvp_frame_set_slot_nc(acc_frame, "associated-stock-account", stock_acc_guid_kvpval); @@ -129,8 +129,7 @@ back_associate_income_accounts(Account *stock_account, g_return_if_fail(kvp_value_get_type(val) == KVP_TYPE_GUID); existing_acc_guid = kvp_value_get_guid(val); - g_return_if_fail(xaccGUIDType(existing_acc_guid, - stock_account->book) == + g_return_if_fail(qof_entity_type(qof_book_get_entity_table(stock_account->book), existing_acc_guid) == GNC_ID_NONE); kvp_frame_set_slot_nc(acc_frame, "associated-stock-account", @@ -449,7 +448,7 @@ gnc_tracking_dissociate_account(Account *inc_or_expense_account) stock_account_guid = kvp_value_get_guid(stock_account_kvpval); if(!safe_strcmp - (xaccGUIDType(stock_account_guid, inc_or_expense_account->book), + (qof_entity_type(qof_book_get_entity_table(inc_or_expense_account->book), stock_account_guid), GNC_ID_NULL)) return; diff --git a/src/engine/gnc-engine.c b/src/engine/gnc-engine.c index 540b11b102..84a9c86d35 100644 --- a/src/engine/gnc-engine.c +++ b/src/engine/gnc-engine.c @@ -25,7 +25,6 @@ #include -#include "GNCIdP.h" #include "gnc-engine.h" #include "gnc-engine-util.h" @@ -38,6 +37,7 @@ #include "gnc-pricedb-p.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid.h" #include "qofobject.h" #include "qofobject-p.h" #include "qofquery.h" @@ -82,7 +82,7 @@ gnc_engine_init(int argc, char ** argv) /* initialize the string cache */ gnc_engine_get_string_cache(); - xaccGUIDInit (); + guid_init (); qof_object_initialize (); qof_query_init (); qof_book_register (); @@ -116,11 +116,9 @@ void gnc_engine_shutdown (void) { qof_query_shutdown (); - - gnc_engine_string_cache_destroy (); - qof_object_shutdown (); - xaccGUIDShutdown (); + guid_shutdown(); + gnc_engine_string_cache_destroy (); } /******************************************************************** diff --git a/src/engine/gnc-engine.h b/src/engine/gnc-engine.h index da0ba9c8a6..4589ab7df8 100644 --- a/src/engine/gnc-engine.h +++ b/src/engine/gnc-engine.h @@ -25,6 +25,7 @@ @brief All type declarations for the whole Gnucash engine @author Copyright (C) 1997 Robin D. Clark @author Copyright (C) 2000 Bill Gribble + @author Copyright (C) 2000 Dave Peticolas @author Copyright (C) 1997-2001 Linas Vepstas */ @@ -32,6 +33,48 @@ #define GNC_ENGINE_H #include +#include "qofid.h" + +/* IDENTIFIERS *****************************************************/ +/** GUID Identifiers can be used to reference Accounts, Transactions, + * Splits and other objects. These Gnucash types are referred to as Gnucash + * entities. GUID Identifiers are globally-unique and permanent, i.e., once + * an entity has been assigned an identifier, it retains that same + * identifier for its lifetime. + * + * Identifiers are 'typed' with strings. The ids used in gnucash are + * defined below. An id with type GNC_ID_NONE does not refer to any + * entity, although that may change as new ids are created. An id with + * type GNC_ID_NULL does not refer to any entity, and will never refer + * to any entity. An identifier with any other type may refer to an + * actual entity, but that is not guaranteed. If an id does refer to + * an entity, the type of the entity will match the type of the + * identifier. + */ + +#define GNC_ID_NONE QOF_ID_NONE +#define GNC_ID_BOOK QOF_ID_BOOK +#define GNC_ID_SESSION QOF_ID_SESSION +#define GNC_ID_NULL QOF_ID_NULL + +#define GNC_ID_ACCOUNT "Account" +#define GNC_ID_COMMODITY_TABLE "CommodityTable" +#define GNC_ID_FREQSPEC "FreqSpec" +#define GNC_ID_GROUP "AccountGroup" +#define GNC_ID_LOT "Lot" +#define GNC_ID_PERIOD "Period" +#define GNC_ID_PRICE "Price" +#define GNC_ID_PRICEDB "PriceDB" +#define GNC_ID_SPLIT "Split" +#define GNC_ID_SCHEDXACTION "SchedXaction" +#define GNC_ID_SXTT "SXTT" +#define GNC_ID_TRANS "Trans" + + + + + + /* TYPES **********************************************************/ diff --git a/src/engine/gnc-lot-p.h b/src/engine/gnc-lot-p.h index 4c67d7e17e..c1e90d46bc 100644 --- a/src/engine/gnc-lot-p.h +++ b/src/engine/gnc-lot-p.h @@ -37,10 +37,10 @@ #ifndef GNC_LOT_P_H #define GNC_LOT_P_H -#include "GNCIdP.h" #include "gnc-engine.h" #include "kvp_frame.h" #include "qofbook.h" +#include "qofid.h" struct gnc_lot_struct { diff --git a/src/engine/gnc-lot.c b/src/engine/gnc-lot.c index a5e48bbbce..738e0bd905 100644 --- a/src/engine/gnc-lot.c +++ b/src/engine/gnc-lot.c @@ -44,6 +44,7 @@ #include "qofqueryobject.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" /* This static indicates the debugging module that this .o belongs to. */ static short module = MOD_LOT; @@ -60,8 +61,8 @@ gnc_lot_init (GNCLot *lot, QofBook *book) lot->is_closed = -1; lot->book = book; - xaccGUIDNew (&lot->guid, book); - xaccStoreEntity (book->entity_table, lot, &lot->guid, GNC_ID_LOT); + qof_entity_guid_new (book->entity_table, &lot->guid); + qof_entity_store (book->entity_table, lot, &lot->guid, GNC_ID_LOT); LEAVE ("(lot=%p, book=%p)", lot, book); } @@ -85,7 +86,7 @@ gnc_lot_destroy (GNCLot *lot) ENTER ("(lot=%p)", lot); gnc_engine_generate_event (&lot->guid, GNC_EVENT_DESTROY); - xaccRemoveEntity (lot->book->entity_table, &lot->guid); + qof_entity_remove (lot->book->entity_table, &lot->guid); for (node=lot->splits; node; node=node->next) { @@ -119,16 +120,16 @@ gnc_lot_set_guid (GNCLot *lot, GUID uid) if (guid_equal (&lot->guid, &uid)) return; - xaccRemoveEntity(lot->book->entity_table, &lot->guid); + qof_entity_remove(lot->book->entity_table, &lot->guid); lot->guid = uid; - xaccStoreEntity(lot->book->entity_table, lot, &lot->guid, GNC_ID_LOT); + qof_entity_store(lot->book->entity_table, lot, &lot->guid, GNC_ID_LOT); } GNCLot * gnc_lot_lookup (const GUID *guid, QofBook *book) { if (!guid || !book) return NULL; - return xaccLookupEntity (qof_book_get_entity_table (book), + return qof_entity_lookup (qof_book_get_entity_table (book), guid, GNC_ID_LOT); } diff --git a/src/engine/gnc-pricedb-p.h b/src/engine/gnc-pricedb-p.h index 1e464fcdd6..4b7603d979 100644 --- a/src/engine/gnc-pricedb-p.h +++ b/src/engine/gnc-pricedb-p.h @@ -28,10 +28,10 @@ #include #include "Backend.h" -#include "GNCIdP.h" #include "gnc-engine.h" #include "gnc-pricedb.h" #include "qofbook.h" +#include "qofid.h" struct gnc_price_s { @@ -50,7 +50,7 @@ struct gnc_price_s guint32 version_check; /* data aging timestamp */ /* 'private' object management fields */ - GNCEntityTable *entity_table; /* table in which price is stored */ + QofEntityTable *entity_table; /* table in which price is stored */ guint32 refcount; /* garbage collection reference count */ gint32 editlevel; /* nesting level of begin/end edit calls */ gboolean not_saved; /* price edit saved flag */ diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c index 720d3a3a79..7e43712b97 100644 --- a/src/engine/gnc-pricedb.c +++ b/src/engine/gnc-pricedb.c @@ -28,7 +28,6 @@ #include #include "BackendP.h" -#include "GNCIdP.h" #include "gnc-engine.h" #include "gnc-engine-util.h" #include "gnc-event-p.h" @@ -37,6 +36,7 @@ #include "kvp-util.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" #include "qofobject.h" /* This static indicates the debugging module that this .o belongs to. */ @@ -70,8 +70,8 @@ gnc_price_create (QofBook *book) p->book = book; p->entity_table = qof_book_get_entity_table (book); - xaccGUIDNew (&p->guid, book); - xaccStoreEntity (p->entity_table, p, &p->guid, GNC_ID_PRICE); + qof_entity_guid_new (p->entity_table, &p->guid); + qof_entity_store (p->entity_table, p, &p->guid, GNC_ID_PRICE); gnc_engine_generate_event (&p->guid, GNC_EVENT_CREATE); return p; @@ -82,7 +82,7 @@ gnc_price_destroy (GNCPrice *p) { ENTER(" "); gnc_engine_generate_event (&p->guid, GNC_EVENT_DESTROY); - xaccRemoveEntity(p->entity_table, &p->guid); + qof_entity_remove(p->entity_table, &p->guid); if(p->type) g_cache_remove(gnc_engine_get_string_cache(), p->type); if(p->source) g_cache_remove(gnc_engine_get_string_cache(), p->source); @@ -243,10 +243,10 @@ void gnc_price_set_guid (GNCPrice *p, const GUID *guid) { if (!p || !guid) return; - xaccRemoveEntity (p->entity_table, &p->guid); + qof_entity_remove (p->entity_table, &p->guid); p->guid = *guid; if(p->db) p->db->dirty = TRUE; - xaccStoreEntity(p->entity_table, p, &p->guid, GNC_ID_PRICE); + qof_entity_store(p->entity_table, p, &p->guid, GNC_ID_PRICE); } void @@ -380,21 +380,21 @@ gnc_price_lookup (const GUID *guid, QofBook *book) { if (!guid) return NULL; g_return_val_if_fail (book, NULL); - return xaccLookupEntity (qof_book_get_entity_table (book), + return qof_entity_lookup (qof_book_get_entity_table (book), guid, GNC_ID_PRICE); } const GUID * gnc_price_get_guid (GNCPrice *p) { - if (!p) return xaccGUIDNULL(); + if (!p) return guid_null(); return &p->guid; } const GUID gnc_price_return_guid (GNCPrice *p) { - if (!p) return *xaccGUIDNULL(); + if (!p) return *guid_null(); return p->guid; } diff --git a/src/engine/guid.c b/src/engine/guid.c index e6df7223e1..5f6fccb02f 100644 --- a/src/engine/guid.c +++ b/src/engine/guid.c @@ -56,10 +56,63 @@ /** Static global variables *****************************************/ static gboolean guid_initialized = FALSE; static struct md5_ctx guid_context; +static GMemChunk *guid_memchunk = NULL; /* This static indicates the debugging module that this .o belongs to. */ static short module = MOD_ENGINE; +/** Memory management routines ***************************************/ +static void +guid_memchunk_init (void) +{ + if (!guid_memchunk) + guid_memchunk = g_mem_chunk_create (GUID, 512, G_ALLOC_AND_FREE); +} + +static void +guid_memchunk_shutdown (void) +{ + if (guid_memchunk) + { + g_mem_chunk_destroy (guid_memchunk); + guid_memchunk = NULL; + } +} + +GUID * +guid_malloc (void) +{ + return g_chunk_new (GUID, guid_memchunk); +} + +void +guid_free (GUID *guid) +{ + if (!guid) + return; + + g_chunk_free (guid, guid_memchunk); +} + + +const GUID * +guid_null(void) +{ + static int null_inited = (0 == 1); + static GUID null_guid; + + if (!null_inited) + { + int i; + + for (i = 0; i < 16; i++) + null_guid.data[i] = 0; + + null_inited = (0 == 0); + } + + return &null_guid; +} /** Function implementations ****************************************/ @@ -230,6 +283,8 @@ guid_init(void) { size_t bytes = 0; + guid_memchunk_init(); + md5_init_ctx(&guid_context); /* entropy pool */ @@ -369,6 +424,12 @@ guid_init_only_salt(const void *salt, size_t salt_len) guid_initialized = TRUE; } +void +guid_shutdown (void) +{ + guid_memchunk_shutdown(); +} + #define GUID_PERIOD 5000 void diff --git a/src/engine/guid.h b/src/engine/guid.h index fcd623c849..c738f8f1f9 100644 --- a/src/engine/guid.h +++ b/src/engine/guid.h @@ -48,7 +48,7 @@ typedef union _GUID #define GUID_ENCODING_LENGTH 32 -/* Three functions to initialize the id generator. Only one needs to +/** Three functions to initialize the id generator. Only one needs to * be called. Calling any initialization function a second time will * reset the generator and erase the effect of the first call. * @@ -62,10 +62,12 @@ typedef union _GUID * guid_init_only_salt() will initialize the generator with the data * given in the salt argument, but not with any other source. Calling * guid_init_only_salt() with a specific argument will produce a - * specific sequence of ids reliably. */ + * specific sequence of ids reliably. + */ void guid_init(void); void guid_init_with_salt(const void *salt, size_t salt_len); void guid_init_only_salt(const void *salt, size_t salt_len); +void guid_shutdown (void); /* Generate a new id. If no initialization function has been called, @@ -73,8 +75,16 @@ void guid_init_only_salt(const void *salt, size_t salt_len); void guid_new(GUID *guid); GUID guid_new_return(void); +/** Returns a GUID which is guaranteed to never reference any entity. */ +const GUID * guid_null (void); -/* The guid_to_string() routine returns a null-terminated string +/** Efficiently allocate & free memory for GUIDs */ +GUID * guid_malloc (void); + +/* Return a guid set to all zero's */ +void guid_free (GUID *guid); + +/** The guid_to_string() routine returns a null-terminated string * encoding of the id. String encodings of identifiers are hex * numbers printed only with the characters '0' through '9' and * 'a' through 'f'. The encoding will always be GUID_ENCODING_LENGTH @@ -92,7 +102,7 @@ char * guid_to_string (const GUID * guid); char * guid_to_string_buff (const GUID * guid, char *buff); -/* Given a string, decode the id into the guid if guid is non-NULL. +/** Given a string, decode the id into the guid if guid is non-NULL. * The function returns TRUE if the string was a valid 32 character * hexadecimal number. This function accepts both upper and lower case * hex digits. If the return value is FALSE, the effect on guid is @@ -100,12 +110,12 @@ char * guid_to_string_buff (const GUID * guid, char *buff); gboolean string_to_guid(const char * string, GUID * guid); -/* Given two GUIDs, return TRUE if they are non-NULL and equal. +/** Given two GUIDs, return TRUE if they are non-NULL and equal. * Return FALSE, otherwise. */ gboolean guid_equal(const GUID *guid_1, const GUID *guid_2); gint guid_compare(const GUID *g1, const GUID *g2); -/* Given a GUID *, hash it to a guint */ +/** Given a GUID *, hash it to a guint */ guint guid_hash_to_guint(gconstpointer ptr); GHashTable *guid_hash_table_new(void); diff --git a/src/engine/gw-engine-spec.scm b/src/engine/gw-engine-spec.scm index 8729540820..a2701fd946 100644 --- a/src/engine/gw-engine-spec.scm +++ b/src/engine/gw-engine-spec.scm @@ -93,7 +93,7 @@ (gw:wrap-as-wct ws ' "GList*" "const GList*") -(gw:wrap-as-wct ws ' "GNCIdType" "GNCIdTypeConst") +(gw:wrap-as-wct ws ' "QofIdType" "QofIdTypeConst") (gw:wrap-as-wct ws ' "Account*" "const Account*") (gw:wrap-as-wct ws ' "Account**" "const Account**") (gw:wrap-as-wct ws ' "InvAcct*" "const InvAcct*") @@ -252,7 +252,7 @@ #t) ; -; Definitions from GNCId.h +; Definitions from gnc-engine.h ; (gw:wrap-value ws 'gnc:id-account ' "GNC_ID_ACCOUNT") (gw:wrap-value ws 'gnc:id-book ' "GNC_ID_BOOK") diff --git a/src/engine/kvp-util-p.h b/src/engine/kvp-util-p.h index dbb779e1f9..9b03ca5c5d 100644 --- a/src/engine/kvp-util-p.h +++ b/src/engine/kvp-util-p.h @@ -26,7 +26,7 @@ #include "config.h" -#include "GNCId.h" +#include "guid.h" #include "kvp_frame.h" /* PRIVATE FILE diff --git a/src/engine/qofbook-p.h b/src/engine/qofbook-p.h index 1f1d9e43fb..dd884ea77b 100644 --- a/src/engine/qofbook-p.h +++ b/src/engine/qofbook-p.h @@ -31,9 +31,9 @@ #define QOF_BOOK_P_H #include "Backend.h" -#include "GNCIdP.h" #include "kvp_frame.h" #include "qofbook.h" +#include "qofid.h" struct _QofBook { @@ -48,7 +48,7 @@ struct _QofBook * belonging to this book, with their pointers to the respective * objects. This allows a lookup of objects based on thier guid. */ - GNCEntityTable *entity_table; + QofEntityTable *entity_table; /* In order to store arbitrary data, for extensibility, add a table * that will be used to hold arbitrary pointers. diff --git a/src/engine/qofbook.c b/src/engine/qofbook.c index 2e59a848ec..7a2cb048d7 100644 --- a/src/engine/qofbook.c +++ b/src/engine/qofbook.c @@ -47,6 +47,7 @@ #include "gnc-trace.h" #include "qofbook.h" #include "qofbook-p.h" +#include "qofid-p.h" #include "qofobject-p.h" #include "qofqueryobject.h" @@ -60,10 +61,10 @@ qof_book_init (QofBook *book) { if (!book) return; - book->entity_table = xaccEntityTableNew (); + book->entity_table = qof_entity_new (); - xaccGUIDNew(&book->guid, book); - xaccStoreEntity(book->entity_table, book, &book->guid, GNC_ID_BOOK); + qof_entity_guid_new (book->entity_table, &book->guid); + qof_entity_store(book->entity_table, book, &book->guid, QOF_ID_BOOK); book->kvp_data = kvp_frame_new (); @@ -101,8 +102,8 @@ qof_book_destroy (QofBook *book) qof_object_book_end (book); - xaccRemoveEntity (book->entity_table, &book->guid); - xaccEntityTableDestroy (book->entity_table); + qof_entity_remove (book->entity_table, &book->guid); + qof_entity_destroy (book->entity_table); book->entity_table = NULL; /* FIXME: Make sure the data_table is empty */ @@ -159,7 +160,7 @@ qof_book_get_slots (QofBook *book) return book->kvp_data; } -GNCEntityTable * +QofEntityTable * qof_book_get_entity_table (QofBook *book) { if (!book) return NULL; @@ -183,9 +184,9 @@ qof_book_set_guid (QofBook *book, GUID uid) if (guid_equal (&book->guid, &uid)) return; - xaccRemoveEntity(book->entity_table, &book->guid); + qof_entity_remove(book->entity_table, &book->guid); book->guid = uid; - xaccStoreEntity(book->entity_table, book, &book->guid, GNC_ID_BOOK); + qof_entity_store(book->entity_table, book, &book->guid, QOF_ID_BOOK); } void @@ -298,7 +299,7 @@ gboolean qof_book_register (void) { NULL }, }; - qof_query_object_register (GNC_ID_BOOK, NULL, params); + qof_query_object_register (QOF_ID_BOOK, NULL, params); return TRUE; } diff --git a/src/engine/qofbook.h b/src/engine/qofbook.h index 1b30020b76..87a076f86b 100644 --- a/src/engine/qofbook.h +++ b/src/engine/qofbook.h @@ -35,7 +35,7 @@ #include -#include "GNCId.h" +#include "qofid.h" #include "kvp_frame.h" /** @brief Encapsulates all the information about a dataset @@ -56,7 +56,7 @@ QofBook * qof_book_new (void); void qof_book_destroy (QofBook *book); /** \return The Entity table for the book. */ -GNCEntityTable * qof_book_get_entity_table (QofBook *book); +QofEntityTable * qof_book_get_entity_table (QofBook *book); /** \return The GUID for the book. */ const GUID * qof_book_get_guid (QofBook *book); diff --git a/src/engine/GNCIdP.h b/src/engine/qofid-p.h similarity index 70% rename from src/engine/GNCIdP.h rename to src/engine/qofid-p.h index 8db33cd777..7b8e326450 100644 --- a/src/engine/GNCIdP.h +++ b/src/engine/qofid-p.h @@ -1,5 +1,5 @@ /********************************************************************\ - * GNCIdP.h -- Gnucash entity identifier engine-only API * + * qofid-p.h -- QOF entity identifier engine-only API * * Copyright (C) 2000 Dave Peticolas * * * * This program is free software; you can redistribute it and/or * @@ -21,19 +21,19 @@ * * \********************************************************************/ -#ifndef GNC_ID_P_H -#define GNC_ID_P_H 1 +#ifndef QOF_ID_P_H +#define QOF_ID_P_H #include -#include "GNCId.h" +#include "qofid.h" /* This file defines an engine-only API for using gnucash entity * identifiers. */ /* Create and destroy entity tables */ -GNCEntityTable * xaccEntityTableNew (void); -void xaccEntityTableDestroy (GNCEntityTable *table); +QofEntityTable * qof_entity_new (void); +void qof_entity_destroy (QofEntityTable *table); /* Generate a new id. This function is guaranteed to return an id that * is unique within the scope of all GnuCash entities being managed by @@ -43,39 +43,29 @@ void xaccEntityTableDestroy (GNCEntityTable *table); * When considered over all possible instances of gnucash, the odds of * this routine returning a non-unique id are still astronomically small. * If you had a gazzillion computers computing new ids, for the entire - * age of teh universe, you'd still have a one-in-a-million chance of + * age of the universe, you'd still have a one-in-a-million chance of * coming up with a duplicate. 2^128 is a really really big number. */ -void xaccGUIDNewEntityTable (GUID *guid, GNCEntityTable *entity_table); - -/* Equivalent function prototype: - * void xaccGUIDNew (GUID *guid, QofBook *book) - */ -#define xaccGUIDNew(guid,book) \ - xaccGUIDNewEntityTable ((guid), qof_book_get_entity_table (book)) - +void qof_entity_guid_new (QofEntityTable *entity_table, GUID *guid); /* Lookup an entity given an id and a type. If there is no entity * associated with the id, or if it has a different type, NULL - * is returned. */ -gpointer xaccLookupEntity (GNCEntityTable *entity_table, - const GUID * guid, GNCIdType entity_type); + * is returned. Input: GUID, returns reference (pointer) to object. + */ +gpointer qof_entity_lookup (QofEntityTable *entity_table, + const GUID * guid, QofIdType entity_type); /* Store the given entity under the given id with the given type. */ -void xaccStoreEntity (GNCEntityTable *entity_table, +void qof_entity_store (QofEntityTable *entity_table, gpointer entity, const GUID * guid, - GNCIdType entity_type); + QofIdType entity_type); /* Remove any existing association between an entity and the given * id. The entity is not changed in any way. */ -void xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid); +void qof_entity_remove (QofEntityTable *entity_table, const GUID * guid); /* Call a function for each object of type 'type' in the entity table */ -void xaccForeachEntity (GNCEntityTable *entity_table, GNCIdType type, - foreachObjectCB cb_func, gpointer user_data); +void qof_entity_foreach (QofEntityTable *entity_table, QofIdType type, + QofEntityForeachCB cb_func, gpointer user_data); -/* Initialize and shutdown the GNC Id system. */ -void xaccGUIDInit (void); -void xaccGUIDShutdown (void); - -#endif +#endif /* QOF_ID_P_H */ diff --git a/src/engine/GNCId.c b/src/engine/qofid.c similarity index 71% rename from src/engine/GNCId.c rename to src/engine/qofid.c index d8591757ea..bd7b7e4d45 100644 --- a/src/engine/GNCId.c +++ b/src/engine/qofid.c @@ -1,5 +1,5 @@ /********************************************************************\ - * GNCId.c -- Gnucash entity identifier implementation * + * qofid.c -- QOF entity identifier implementation * * Copyright (C) 2000 Dave Peticolas * * * * This program is free software; you can redistribute it and/or * @@ -26,69 +26,36 @@ #include #include -#include "GNCId.h" -#include "GNCIdP.h" +#include "qofid.h" +#include "qofid-p.h" #include "gnc-engine-util.h" #define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); #define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (gpointer)(str)); /** #defines ********************************************************/ -#define GNCID_DEBUG 0 +#define QOFID_DEBUG 0 /** Type definitions ************************************************/ typedef struct entity_node { - GNCIdType entity_type; + QofIdType entity_type; gpointer entity; } EntityNode; -struct gnc_entity_table +struct _QofEntityTable { GHashTable * hash; }; /** Static global variables *****************************************/ -static GMemChunk *guid_memchunk = NULL; static short module = MOD_ENGINE; /** Function implementations ****************************************/ -void -xaccGUIDInit (void) -{ - if (!guid_memchunk) - guid_memchunk = g_mem_chunk_create (GUID, 512, G_ALLOC_AND_FREE); -} - -void -xaccGUIDShutdown (void) -{ - if (guid_memchunk) - { - g_mem_chunk_destroy (guid_memchunk); - guid_memchunk = NULL; - } -} - -GUID * -xaccGUIDMalloc (void) -{ - return g_chunk_new (GUID, guid_memchunk); -} - -void -xaccGUIDFree (GUID *guid) -{ - if (!guid) - return; - - g_chunk_free (guid, guid_memchunk); -} - static gboolean entity_node_destroy(gpointer key, gpointer value, gpointer not_used) { @@ -96,17 +63,17 @@ entity_node_destroy(gpointer key, gpointer value, gpointer not_used) EntityNode *e_node = value; CACHE_REMOVE (e_node->entity_type); - e_node->entity_type = GNC_ID_NONE; + e_node->entity_type = QOF_ID_NONE; e_node->entity = NULL; - xaccGUIDFree(guid); + guid_free(guid); g_free(e_node); return TRUE; } void -xaccEntityTableDestroy (GNCEntityTable *entity_table) +qof_entity_destroy (QofEntityTable *entity_table) { if (entity_table == NULL) return; @@ -152,7 +119,7 @@ id_compare(gconstpointer key_1, gconstpointer key_2) return guid_equal (key_1, key_2); } -#if GNCID_DEBUG +#if QOFID_DEBUG static void print_node(gpointer key, gpointer value, gpointer not_used) { @@ -164,48 +131,48 @@ print_node(gpointer key, gpointer value, gpointer not_used) } static void -summarize_table (GNCEntityTable *entity_table) +summarize_table (QofEntityTable *entity_table) { if (entity_table == NULL) return; g_hash_table_foreach (entity_table->hash, print_node, NULL); } -#endif +#endif /* QOFID_DEBUG */ -GNCEntityTable * -xaccEntityTableNew (void) +QofEntityTable * +qof_entity_new (void) { - GNCEntityTable *entity_table; + QofEntityTable *entity_table; - entity_table = g_new0 (GNCEntityTable, 1); + entity_table = g_new0 (QofEntityTable, 1); entity_table->hash = g_hash_table_new (id_hash, id_compare); - xaccStoreEntity (entity_table, NULL, xaccGUIDNULL(), GNC_ID_NULL); + qof_entity_store (entity_table, NULL, guid_null(), QOF_ID_NULL); return entity_table; } -GNCIdType -xaccGUIDTypeEntityTable (const GUID * guid, GNCEntityTable *entity_table) +QofIdType +qof_entity_type (QofEntityTable *entity_table, const GUID * guid) { EntityNode *e_node; if (guid == NULL) - return GNC_ID_NONE; + return QOF_ID_NONE; - g_return_val_if_fail (entity_table, GNC_ID_NONE); + g_return_val_if_fail (entity_table, QOF_ID_NONE); e_node = g_hash_table_lookup (entity_table->hash, guid->data); if (e_node == NULL) - return GNC_ID_NONE; + return QOF_ID_NONE; return e_node->entity_type; } void -xaccGUIDNewEntityTable (GUID *guid, GNCEntityTable *entity_table) +qof_entity_guid_new (QofEntityTable *entity_table, GUID *guid) { if (guid == NULL) return; @@ -216,35 +183,16 @@ xaccGUIDNewEntityTable (GUID *guid, GNCEntityTable *entity_table) { guid_new(guid); - if (xaccGUIDTypeEntityTable (guid, entity_table) == GNC_ID_NONE) + if (qof_entity_type (entity_table, guid) == QOF_ID_NONE) break; PWARN("duplicate id created, trying again"); } while(1); } -const GUID * -xaccGUIDNULL(void) -{ - static int null_inited = (0 == 1); - static GUID null_guid; - - if (!null_inited) - { - int i; - - for (i = 0; i < 16; i++) - null_guid.data[i] = 0; - - null_inited = (0 == 0); - } - - return &null_guid; -} - gpointer -xaccLookupEntity (GNCEntityTable *entity_table, - const GUID * guid, GNCIdType entity_type) +qof_entity_lookup (QofEntityTable *entity_table, + const GUID * guid, QofIdType entity_type) { EntityNode *e_node; @@ -264,8 +212,8 @@ xaccLookupEntity (GNCEntityTable *entity_table, } void -xaccStoreEntity (GNCEntityTable *entity_table, gpointer entity, - const GUID * guid, GNCIdType entity_type) +qof_entity_store (QofEntityTable *entity_table, gpointer entity, + const GUID * guid, QofIdType entity_type) { EntityNode *e_node; GUID *new_guid; @@ -277,15 +225,15 @@ xaccStoreEntity (GNCEntityTable *entity_table, gpointer entity, if (!entity_type) return; - if (guid_equal(guid, xaccGUIDNULL())) return; + if (guid_equal(guid, guid_null())) return; - xaccRemoveEntity (entity_table, guid); + qof_entity_remove (entity_table, guid); e_node = g_new(EntityNode, 1); e_node->entity_type = CACHE_INSERT (entity_type); e_node->entity = entity; - new_guid = xaccGUIDMalloc (); + new_guid = guid_malloc (); if (!new_guid) return; @@ -295,7 +243,7 @@ xaccStoreEntity (GNCEntityTable *entity_table, gpointer entity, } void -xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid) +qof_entity_remove (QofEntityTable *entity_table, const GUID * guid) { EntityNode *e_node; gpointer old_guid; @@ -310,7 +258,7 @@ xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid) { e_node = node; - if (!safe_strcmp (e_node->entity_type, GNC_ID_NULL)) + if (!safe_strcmp (e_node->entity_type, QOF_ID_NULL)) return; g_hash_table_remove (entity_table->hash, old_guid); @@ -319,9 +267,9 @@ xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid) } struct _iterate { - foreachObjectCB fcn; + QofEntityForeachCB fcn; gpointer data; - GNCIdType type; + QofIdType type; }; static void foreach_cb (gpointer key, gpointer item, gpointer arg) @@ -335,8 +283,8 @@ static void foreach_cb (gpointer key, gpointer item, gpointer arg) } void -xaccForeachEntity (GNCEntityTable *entity_table, GNCIdType type, - foreachObjectCB cb_func, gpointer user_data) +qof_entity_foreach (QofEntityTable *entity_table, QofIdType type, + QofEntityForeachCB cb_func, gpointer user_data) { struct _iterate iter; diff --git a/src/engine/qofid.h b/src/engine/qofid.h new file mode 100644 index 0000000000..5644463885 --- /dev/null +++ b/src/engine/qofid.h @@ -0,0 +1,77 @@ +/********************************************************************\ + * qofid.h -- QOF entity type identification system * + * * + * 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@gnu.org * + * * +\********************************************************************/ + +#ifndef QOF_ID_H +#define QOF_ID_H + +/** @addtogroup Engine + @{ */ +/** @file qofid.h + @brief QOF entity type identification system + @author Copyright (C) 2000 Dave Peticolas + @author Copyright (C) 2003 Linas Vepstas +*/ + +/** This file defines an API that adds types to the GUID's. + * GUID's with types cna be used to identify and reference + * typed entities. + * + * GUID Identifiers can be used to reference QOF Objects. + * Identifiers are globally-unique and permanent, i.e., once + * an entity has been assigned an identifier, it retains that same + * identifier for its lifetime. + * + * Identifiers can be encoded as hex strings. + */ + +#include "guid.h" + +/** GUID Identifiers are 'typed' with strings. The native ids used + * by QOF are defined below. An id with type QOF_ID_NONE does not + * refer to any entity, although that may change (???). An id with + * type QOF_ID_NULL does not refer to any entity, and will never refer + * to any entity. An identifier with any other type may refer to an + * actual entity, but that is not guaranteed (??? Huh?). If an id + * does refer to an entity, the type of the entity will match the + * type of the identifier. + */ + +typedef const char * QofIdType; +typedef const char * QofIdTypeConst; + +#define QOF_ID_NONE NULL +#define QOF_ID_BOOK "Book" +#define QOF_ID_NULL "null" +#define QOF_ID_SESSION "Session" + + +typedef struct _QofEntityTable QofEntityTable; + +/** Return the type of the indicated guid */ +QofIdType qof_entity_type (QofEntityTable *entity_table, const GUID * guid); + +/* Callback type for qof_entity_foreach */ +typedef void (*QofEntityForeachCB) (gpointer object, gpointer user_data); + +#endif /* QOF_ID_H */ +/** @} */ + diff --git a/src/engine/qofobject.c b/src/engine/qofobject.c index e6ed38756f..0ee5a31a7a 100644 --- a/src/engine/qofobject.c +++ b/src/engine/qofobject.c @@ -106,8 +106,8 @@ void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data) } } -void qof_object_foreach (GNCIdTypeConst type_name, QofBook *book, - foreachObjectCB cb, gpointer user_data) +void qof_object_foreach (QofIdTypeConst type_name, QofBook *book, + QofEntityForeachCB cb, gpointer user_data) { const QofObject *obj; @@ -123,7 +123,7 @@ void qof_object_foreach (GNCIdTypeConst type_name, QofBook *book, } const char * -qof_object_printable (GNCIdTypeConst type_name, gpointer obj) +qof_object_printable (QofIdTypeConst type_name, gpointer obj) { const QofObject *b_obj; @@ -138,7 +138,7 @@ qof_object_printable (GNCIdTypeConst type_name, gpointer obj) return NULL; } -const char * qof_object_get_type_label (GNCIdTypeConst type_name) +const char * qof_object_get_type_label (QofIdTypeConst type_name) { const QofObject *obj; @@ -207,7 +207,7 @@ gboolean qof_object_register (const QofObject *object) return TRUE; } -const QofObject * qof_object_lookup (GNCIdTypeConst name) +const QofObject * qof_object_lookup (QofIdTypeConst name) { GList *iter; const QofObject *obj; @@ -224,7 +224,7 @@ const QofObject * qof_object_lookup (GNCIdTypeConst name) return NULL; } -gboolean qof_object_register_backend (GNCIdTypeConst type_name, +gboolean qof_object_register_backend (QofIdTypeConst type_name, const char *backend_name, gpointer be_data) { @@ -250,7 +250,7 @@ gboolean qof_object_register_backend (GNCIdTypeConst type_name, return TRUE; } -gpointer qof_object_lookup_backend (GNCIdTypeConst type_name, +gpointer qof_object_lookup_backend (QofIdTypeConst type_name, const char *backend_name) { GHashTable *ht; diff --git a/src/engine/qofobject.h b/src/engine/qofobject.h index 7609b2c067..a738ed86fb 100644 --- a/src/engine/qofobject.h +++ b/src/engine/qofobject.h @@ -29,7 +29,6 @@ #ifndef QOF_OBJECT_H_ #define QOF_OBJECT_H_ -#include "GNCId.h" #include "qofbook.h" /* Defines the version of the core object object registration @@ -40,14 +39,14 @@ typedef struct _QofObject QofObject; typedef void (*QofForeachTypeCB) (QofObject *type, gpointer user_data); -typedef void (*QofForeachBackendTypeCB) (GNCIdTypeConst type, +typedef void (*QofForeachBackendTypeCB) (QofIdTypeConst type, gpointer backend_data, gpointer user_data); /* This is the Object Object descriptor */ struct _QofObject { gint interface_version; /* of this object interface */ - GNCIdType name; /* the Object's GNC_ID */ + QofIdType name; /* the Object's GNC_ID */ const char * type_label; /* "Printable" type-label string */ /* book_begin is called from within the Book routines to create @@ -67,7 +66,7 @@ struct _QofObject { /* foreach() is used to execute a callback over each object * stored in the particular book */ - void (*foreach)(QofBook *, foreachObjectCB, gpointer); + void (*foreach)(QofBook *, QofEntityForeachCB, gpointer); /* Given a particular object, return a printable string */ const char * (*printable)(gpointer obj); @@ -76,10 +75,10 @@ struct _QofObject { void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data); -void qof_object_foreach (GNCIdTypeConst type_name, QofBook *book, - foreachObjectCB cb, gpointer user_data); +void qof_object_foreach (QofIdTypeConst type_name, QofBook *book, + QofEntityForeachCB cb, gpointer user_data); -const char * qof_object_printable (GNCIdTypeConst type_name, gpointer obj); +const char * qof_object_printable (QofIdTypeConst type_name, gpointer obj); /* REGISTRATION AND REG-LOOKUP FUNCTIONS */ @@ -90,18 +89,18 @@ gboolean qof_object_register (const QofObject *object); /** Get the printable label for a type. This label is *not* * translated; you must use _() on it if you want a translated version. */ -const char * qof_object_get_type_label (GNCIdTypeConst type_name); +const char * qof_object_get_type_label (QofIdTypeConst type_name); /** Lookup a object definition */ -const QofObject * qof_object_lookup (GNCIdTypeConst type_name); +const QofObject * qof_object_lookup (QofIdTypeConst type_name); /** Register and lookup backend-specific data for this particular object */ -gboolean qof_object_register_backend (GNCIdTypeConst type_name, +gboolean qof_object_register_backend (QofIdTypeConst type_name, const char *backend_name, gpointer be_data); -gpointer qof_object_lookup_backend (GNCIdTypeConst type_name, +gpointer qof_object_lookup_backend (QofIdTypeConst type_name, const char *backend_name); void qof_object_foreach_backend (const char *backend_name, diff --git a/src/engine/qofquery.c b/src/engine/qofquery.c index 12d9271f18..cd5a32fc54 100644 --- a/src/engine/qofquery.c +++ b/src/engine/qofquery.c @@ -80,7 +80,7 @@ typedef struct _QofSortFunc struct _QofQuery { /* The object type that we're searching for */ - GNCIdType search_for; + QofIdType search_for; /* terms is a list of the OR-terms in a sum-of-products * logical expression. */ @@ -402,7 +402,7 @@ check_object (QofQuery *q, gpointer object) * * returns NULL if the first parameter is bad (and final is unchanged). */ -static GSList * compile_params (GSList *param_list, GNCIdType start_obj, +static GSList * compile_params (GSList *param_list, QofIdType start_obj, QofQueryObject const **final) { const QofQueryObject *objDef = NULL; @@ -413,7 +413,7 @@ static GSList * compile_params (GSList *param_list, GNCIdType start_obj, g_return_val_if_fail (final, NULL); for (; param_list; param_list = param_list->next) { - GNCIdType param_name = param_list->data; + QofIdType param_name = param_list->data; objDef = qof_query_object_get_parameter (start_obj, param_name); /* If it doesn't exist, then we've reached the end */ @@ -427,14 +427,14 @@ static GSList * compile_params (GSList *param_list, GNCIdType start_obj, *final = objDef; /* And reset for the next parameter */ - start_obj = (GNCIdType) objDef->param_type; + start_obj = (QofIdType) objDef->param_type; } return (g_slist_reverse (fcns)); } static void -compile_sort (QofQuerySort *sort, GNCIdType obj) +compile_sort (QofQuerySort *sort, QofIdType obj) { const QofQueryObject *resObj = NULL; @@ -789,18 +789,18 @@ QofQuery * qof_query_create (void) return qp; } -void qof_query_search_for (QofQuery *q, GNCIdTypeConst obj_type) +void qof_query_search_for (QofQuery *q, QofIdTypeConst obj_type) { if (!q || !obj_type) return; if (safe_strcmp (q->search_for, obj_type)) { - q->search_for = (GNCIdType) obj_type; + q->search_for = (QofIdType) obj_type; q->changed = 1; } } -QofQuery * qof_query_create_for (GNCIdTypeConst obj_type) +QofQuery * qof_query_create_for (QofIdTypeConst obj_type) { QofQuery *q; if (!obj_type) @@ -975,7 +975,7 @@ QofQuery * qof_query_merge(QofQuery *q1, QofQuery *q2, QofQueryOp op) QofQuery * i1, * i2; QofQuery * t1, * t2; GList * i, * j; - GNCIdType search_for; + QofIdType search_for; if(!q1 || !q2 ) return NULL; if (q1->search_for && q2->search_for) @@ -1193,7 +1193,7 @@ int qof_query_get_max_results (QofQuery *q) return q->max_results; } -GNCIdType qof_query_get_search_for (QofQuery *q) +QofIdType qof_query_get_search_for (QofQuery *q) { if (!q) return NULL; return q->search_for; @@ -1405,7 +1405,7 @@ qof_query_printOutput (GList * output) static GList * qof_query_printSearchFor (QofQuery * query, GList * output) { - GNCIdType searchFor; + QofIdType searchFor; GString *gs; searchFor = qof_query_get_search_for (query); diff --git a/src/engine/qofquery.h b/src/engine/qofquery.h index 3e495856c8..cfb92bb2dc 100644 --- a/src/engine/qofquery.h +++ b/src/engine/qofquery.h @@ -29,7 +29,7 @@ #ifndef QOF_QUERYNEW_H #define QOF_QUERYNEW_H -#include "GNCId.h" +#include "guid.h" #include "qofquerycore.h" #include "qofbook.h" @@ -64,11 +64,11 @@ GSList * qof_query_build_param_list (char const *param, ...); /** Create a new query. A Query MUST be set with a 'search-for' type. * you can create and set this value in one step or two */ QofQuery * qof_query_create (void); -QofQuery * qof_query_create_for (GNCIdTypeConst obj_type); +QofQuery * qof_query_create_for (QofIdTypeConst obj_type); void qof_query_destroy (QofQuery *q); /** Set the object type to be searched for */ -void qof_query_search_for (QofQuery *query, GNCIdTypeConst obj_type); +void qof_query_search_for (QofQuery *query, QofIdTypeConst obj_type); /** Set the book to be searched (you can search multiple books) */ void qof_query_set_book (QofQuery *q, QofBook *book); @@ -162,7 +162,7 @@ gboolean qof_query_equal (QofQuery *q1, QofQuery *q2); void qof_query_print (QofQuery *query); /* Return the type of data we're querying for */ -GNCIdType qof_query_get_search_for (QofQuery *q); +QofIdType qof_query_get_search_for (QofQuery *q); /* Return the list of books we're using */ GList * qof_query_get_books (QofQuery *q); diff --git a/src/engine/qofquerycore.c b/src/engine/qofquerycore.c index 8b948854fb..01b6833d52 100644 --- a/src/engine/qofquerycore.c +++ b/src/engine/qofquerycore.c @@ -612,7 +612,7 @@ static void guid_free_pdata (QofQueryPredData *pd) GList *node; VERIFY_PDATA (query_guid_type); for (node = pdata->guids; node; node = node->next) - xaccGUIDFree (node->data); + guid_free (node->data); g_list_free (pdata->guids); g_free (pdata); } @@ -652,7 +652,7 @@ qof_query_guid_predicate (QofGuidMatch options, GList *guids) pdata->options = options; pdata->guids = g_list_copy (guids); for (node = pdata->guids; node; node = node->next) { - GUID *guid = xaccGUIDMalloc (); + GUID *guid = guid_malloc (); *guid = *((GUID *)node->data); node->data = guid; } diff --git a/src/engine/qofqueryobject-p.h b/src/engine/qofqueryobject-p.h index 2d17521d3f..5b84c352ca 100644 --- a/src/engine/qofqueryobject-p.h +++ b/src/engine/qofqueryobject-p.h @@ -24,12 +24,11 @@ #ifndef QOF_QUERYOBJECTP_H #define QOF_QUERYOBJECTP_H -#include "GNCId.h" #include "qofqueryobject.h" void qof_query_object_init(void); void qof_query_object_shutdown (void); -QofSortFunc qof_query_object_default_sort (GNCIdTypeConst obj_name); +QofSortFunc qof_query_object_default_sort (QofIdTypeConst obj_name); #endif /* QOF_QUERYOBJECTP_H */ diff --git a/src/engine/qofqueryobject.c b/src/engine/qofqueryobject.c index 45ff0722f4..7030475b0d 100644 --- a/src/engine/qofqueryobject.c +++ b/src/engine/qofqueryobject.c @@ -44,7 +44,7 @@ static gboolean clear_table (gpointer key, gpointer value, gpointer user_data) /********************************************************************/ /* PUBLISHED API FUNCTIONS */ -void qof_query_object_register (GNCIdTypeConst obj_name, +void qof_query_object_register (QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofQueryObject *params) { @@ -92,7 +92,7 @@ void qof_query_object_shutdown (void) } -const QofQueryObject * qof_query_object_get_parameter (GNCIdTypeConst obj_name, +const QofQueryObject * qof_query_object_get_parameter (QofIdTypeConst obj_name, const char *parameter) { GHashTable *ht; @@ -108,7 +108,7 @@ const QofQueryObject * qof_query_object_get_parameter (GNCIdTypeConst obj_name, return (g_hash_table_lookup (ht, parameter)); } -QofAccessFunc qof_query_object_get_parameter_getter (GNCIdTypeConst obj_name, +QofAccessFunc qof_query_object_get_parameter_getter (QofIdTypeConst obj_name, const char *parameter) { const QofQueryObject *obj; @@ -123,7 +123,7 @@ QofAccessFunc qof_query_object_get_parameter_getter (GNCIdTypeConst obj_name, return NULL; } -QofQueryCoreType qof_query_object_parameter_type (GNCIdTypeConst obj_name, +QofQueryCoreType qof_query_object_parameter_type (QofIdTypeConst obj_name, const char *param_name) { const QofQueryObject *obj; @@ -137,7 +137,7 @@ QofQueryCoreType qof_query_object_parameter_type (GNCIdTypeConst obj_name, } QofSortFunc -qof_query_object_default_sort (GNCIdTypeConst obj_name) +qof_query_object_default_sort (QofIdTypeConst obj_name) { if (!obj_name) return NULL; return g_hash_table_lookup (sortTable, obj_name); diff --git a/src/engine/qofqueryobject.h b/src/engine/qofqueryobject.h index 166c217492..05f1155bc5 100644 --- a/src/engine/qofqueryobject.h +++ b/src/engine/qofqueryobject.h @@ -54,7 +54,7 @@ typedef int (*QofSortFunc)(gpointer, gpointer); * "converters" are NULL-terminated arrays of structures. Either * argument may be NULL if there is nothing to be registered. */ -void qof_query_object_register (GNCIdTypeConst obj_name, +void qof_query_object_register (QofIdTypeConst obj_name, QofSortFunc default_sort_fcn, const QofQueryObject *params); @@ -79,15 +79,15 @@ void qof_query_object_register (GNCIdTypeConst obj_name, */ /** Return the core datatype of the specified object's parameter */ -QofQueryCoreType qof_query_object_parameter_type (GNCIdTypeConst obj_name, +QofQueryCoreType qof_query_object_parameter_type (QofIdTypeConst obj_name, const char *param_name); /** Return the registered Object Definition for the requested parameter */ -const QofQueryObject * qof_query_object_get_parameter (GNCIdTypeConst obj_name, +const QofQueryObject * qof_query_object_get_parameter (QofIdTypeConst obj_name, const char *parameter); /** Return the object's parameter getter function */ -QofAccessFunc qof_query_object_get_parameter_getter (GNCIdTypeConst obj_name, +QofAccessFunc qof_query_object_get_parameter_getter (QofIdTypeConst obj_name, const char *parameter); diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.c index 0e4426fae8..436ef1b907 100644 --- a/src/engine/test-core/test-engine-stuff.c +++ b/src/engine/test-core/test-engine-stuff.c @@ -1265,7 +1265,7 @@ free_random_kvp_path (GSList *path) g_slist_free (path); } -static GNCIdType +static QofIdType get_random_id_type (void) { switch (get_random_int_in_range (1,3)) { @@ -1621,7 +1621,7 @@ make_random_changes_to_session (GNCSession *session) typedef struct { - GNCIdType where; + QofIdType where; GSList *path; Query *q; } KVPQueryData; @@ -1648,7 +1648,7 @@ add_kvp_value_query (const char *key, kvp_value *value, gpointer data) } static void -add_kvp_query (Query *q, kvp_frame *frame, GNCIdType where) +add_kvp_query (Query *q, kvp_frame *frame, QofIdType where) { KVPQueryData kqd; diff --git a/src/engine/test/test-freq-spec.c b/src/engine/test/test-freq-spec.c index ecae34685e..da5ec0477c 100644 --- a/src/engine/test/test-freq-spec.c +++ b/src/engine/test/test-freq-spec.c @@ -13,7 +13,6 @@ #include "test-stuff.h" #include "FreqSpec.h" -#include "GNCIdP.h" #include "gnc-engine.h" #include "gnc-module.h" #include "gnc-book.h" diff --git a/src/engine/test/test-group-vs-book.c b/src/engine/test/test-group-vs-book.c index ea484f8741..9478e1e88c 100644 --- a/src/engine/test/test-group-vs-book.c +++ b/src/engine/test/test-group-vs-book.c @@ -4,7 +4,6 @@ #include "Group.h" #include "GroupP.h" -#include "GNCIdP.h" #include "TransLog.h" #include "gnc-engine.h" #include "gnc-module.h" diff --git a/src/engine/test/test-object.c b/src/engine/test/test-object.c index 6da755a1d9..1cb6bfc03c 100644 --- a/src/engine/test/test-object.c +++ b/src/engine/test/test-object.c @@ -13,7 +13,7 @@ #define TEST_MODULE_NAME "object-test" #define TEST_MODULE_DESC "Test Object" -static void foreach (QofBook *, foreachObjectCB, gpointer); +static void foreach (QofBook *, QofEntityForeachCB, gpointer); static const char * printable (gpointer obj); static void test_printable (const char *name, gpointer obj); static void test_foreach (QofBook *, const char *); @@ -52,7 +52,7 @@ static void test_object (void) } static void -foreach (QofBook *book, foreachObjectCB cb, gpointer u_d) +foreach (QofBook *book, QofEntityForeachCB cb, gpointer u_d) { int *foo = u_d; diff --git a/src/engine/test/test-split-vs-account.c b/src/engine/test/test-split-vs-account.c index 72c472bbf6..6d74bd4f31 100644 --- a/src/engine/test/test-split-vs-account.c +++ b/src/engine/test/test-split-vs-account.c @@ -2,8 +2,6 @@ #include #include -#include "GNCIdP.h" - #include "AccountP.h" #include "TransLog.h" #include "gnc-engine.h" diff --git a/src/engine/test/test-transaction-reversal.c b/src/engine/test/test-transaction-reversal.c index ae0b39d9e9..647dcab9d8 100644 --- a/src/engine/test/test-transaction-reversal.c +++ b/src/engine/test/test-transaction-reversal.c @@ -2,8 +2,6 @@ #include #include -#include "GNCIdP.h" - #include "Account.h" #include "TransLog.h" #include "Transaction.h" diff --git a/src/engine/test/test-transaction-voiding.c b/src/engine/test/test-transaction-voiding.c index 121ba59ad6..1ebd11d8b0 100644 --- a/src/engine/test/test-transaction-voiding.c +++ b/src/engine/test/test-transaction-voiding.c @@ -2,8 +2,6 @@ #include #include -#include "GNCIdP.h" - #include "Account.h" #include "TransLog.h" #include "Transaction.h" diff --git a/src/engine/xlate.pl b/src/engine/xlate.pl index 635066f370..5d9edb27ce 100755 --- a/src/engine/xlate.pl +++ b/src/engine/xlate.pl @@ -159,12 +159,24 @@ foreach (@files) # s/gncQueryObjectShutdown/qof_query_object_shutdown/g; # s/gncQueryObjectDefaultSort/qof_query_object_default_sort/g; - s/QofQueryAccessFunc/QofAccessFunc/g; - s/QofQueryAccess/QofAccessFunc/g; - s/QofQueryCompareFunc/QofCompareFunc/g; - s/QofQueryCompare/QofCompareFunc/g; - s/QofQuerySortFunc/QofSortFunc/g; - s/QofQuerySort/QofSortFunc/g; + # s/xaccGUIDNULL/guid_null/g; + # s/xaccGUIDMalloc/guid_malloc/g; + # s/xaccGUIDFree/guid_free/g; + + # s/GNCIdTypeConst/QofIdTypeConst/g; + # s/GNCIdType/QofIdType/g; + # s/GNCEntityTable/QofEntityTable/g; + # s/xaccGUIDTypeEntityTable/qof_guid_type/g; + + # s/xaccEntityTableNew/qof_entity_new/g; + # s/xaccEntityTableDestroy/qof_entity_destroy/g; + # s/xaccGUIDNewEntityTable/qof_entity_guid_new/g; + # s/xaccLookupEntity/qof_entity_lookup/g; + # s/xaccStoreEntity/qof_entity_store/g; + # s/xaccRemoveEntity/qof_entity_remove/g; + # s/xaccForeachEntity/qof_entity_foreach/g; + + s/foreachObjectCB/QofEntityForeachCB/g; print OF $_; }