Work on moving entity tables into sessions.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5468 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas
2001-10-06 08:12:55 +00:00
parent c672e1960c
commit 2408e0f983
46 changed files with 300 additions and 161 deletions

View File

@@ -364,7 +364,8 @@ gnc_copy_split(Split *split, gboolean use_cut_semantics)
* Returns: Nothing *
\********************************************************************/
void
gnc_copy_split_scm_onto_split(SCM split_scm, Split *split)
gnc_copy_split_scm_onto_split(SCM split_scm, Split *split,
GNCSession *session)
{
static SCM split_type = SCM_UNDEFINED;
SCM result;
@@ -377,6 +378,8 @@ gnc_copy_split_scm_onto_split(SCM split_scm, Split *split)
if (split == NULL)
return;
g_return_if_fail (session);
func = gh_eval_str("gnc:split-scm?");
if (!gh_procedure_p(func))
return;
@@ -396,7 +399,8 @@ gnc_copy_split_scm_onto_split(SCM split_scm, Split *split)
}
arg = gw_wcp_assimilate_ptr(split, split_type);
gh_call2(func, split_scm, arg);
gh_call3(func, split_scm, arg, gnc_session_to_scm (session));
}

View File

@@ -52,7 +52,8 @@ gboolean gnc_is_split_scm(SCM scm);
gboolean gnc_is_trans_scm(SCM scm);
SCM gnc_copy_split(Split *split, gboolean use_cut_semantics);
void gnc_copy_split_scm_onto_split(SCM split_scm, Split *split);
void gnc_copy_split_scm_onto_split(SCM split_scm, Split *split,
GNCSession *session);
void gnc_split_scm_set_account(SCM split_scm, Account *account);
void gnc_split_scm_set_memo(SCM split_scm, const char *memo);

View File

@@ -487,7 +487,7 @@
(define (convert-to-account item)
(if (string? item)
(gnc:account-lookup item)
(gnc:account-lookup item (gnc:get-current-session))
item))
(let* ((option (map convert-to-guid (default-getter)))
@@ -510,7 +510,8 @@
(if (not account-list) (set! account-list (default-getter)))
(set! account-list
(filter (lambda (x) (if (string? x)
(gnc:account-lookup x)
(gnc:account-lookup
x (gnc:get-current-session))
x)) account-list))
(let* ((result (validator account-list))
(valid (car result))

View File

@@ -277,7 +277,7 @@ account_parent_handler (xmlNodePtr node, gpointer act_pdata)
gid = dom_tree_to_guid(node);
g_return_val_if_fail(gid, FALSE);
parent = xaccAccountLookup(gid);
parent = xaccAccountLookup(gid, pdata->session);
if (!parent)
{
g_free (gid);

View File

@@ -213,68 +213,94 @@ gnc_schedXaction_dom_tree_create(SchedXaction *sx)
return ret;
}
struct sx_pdata
{
SchedXaction *sx;
GNCSession *session;
};
static
gboolean
sx_id_handler( xmlNodePtr node, gpointer sx )
sx_id_handler( xmlNodePtr node, gpointer sx_pdata )
{
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
GUID *tmp = dom_tree_to_guid( node );
g_return_val_if_fail( tmp, FALSE );
xaccSchedXactionSetGUID( (SchedXaction*)sx, *tmp );
xaccSchedXactionSetGUID(sx, *tmp);
g_free( tmp );
return TRUE;
}
static
gboolean
sx_name_handler( xmlNodePtr node, gpointer sx )
sx_name_handler( xmlNodePtr node, gpointer sx_pdata )
{
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gchar *tmp = dom_tree_to_text( node );
g_return_val_if_fail( tmp, FALSE );
xaccSchedXactionSetName( (SchedXaction*)sx, tmp );
xaccSchedXactionSetName( sx, tmp );
g_free( tmp );
return TRUE;
}
static gboolean
sx_autoCreate_handler( xmlNodePtr node, gpointer sx )
sx_autoCreate_handler( xmlNodePtr node, gpointer sx_pdata )
{
gchar *tmp = dom_tree_to_text( node );
((SchedXaction*)sx)->autoCreateOption = (safe_strcmp( tmp, "y" ) == 0 ? TRUE : FALSE );
return TRUE;
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gchar *tmp = dom_tree_to_text( node );
sx->autoCreateOption = (safe_strcmp( tmp, "y" ) == 0 ? TRUE : FALSE );
return TRUE;
}
static gboolean
sx_notify_handler( xmlNodePtr node, gpointer sx )
sx_notify_handler( xmlNodePtr node, gpointer sx_pdata )
{
gchar *tmp = dom_tree_to_text( node );
((SchedXaction*)sx)->autoCreateNotify = (safe_strcmp( tmp, "y" ) == 0 ? TRUE : FALSE );
return TRUE;
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gchar *tmp = dom_tree_to_text( node );
sx->autoCreateNotify = (safe_strcmp( tmp, "y" ) == 0 ? TRUE : FALSE );
return TRUE;
}
static gboolean
sx_advCreate_handler( xmlNodePtr node, gpointer sx )
sx_advCreate_handler( xmlNodePtr node, gpointer sx_pdata )
{
gint64 advCreate;
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gint64 advCreate;
if ( ! dom_tree_to_integer( node, &advCreate ) ) {
return FALSE;
}
if ( ! dom_tree_to_integer( node, &advCreate ) ) {
return FALSE;
}
xaccSchedXactionSetAdvanceCreation( (SchedXaction*)sx, advCreate );
return TRUE;
xaccSchedXactionSetAdvanceCreation( sx, advCreate );
return TRUE;
}
static gboolean
sx_advRemind_handler( xmlNodePtr node, gpointer sx )
sx_advRemind_handler( xmlNodePtr node, gpointer sx_pdata )
{
gint64 advRemind;
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gint64 advRemind;
if ( ! dom_tree_to_integer( node, &advRemind ) ) {
return FALSE;
}
if ( ! dom_tree_to_integer( node, &advRemind ) ) {
return FALSE;
}
xaccSchedXactionSetAdvanceReminder( (SchedXaction*)sx, advRemind );
return TRUE;
xaccSchedXactionSetAdvanceReminder( sx, advRemind );
return TRUE;
}
static
@@ -293,96 +319,114 @@ sx_set_date( xmlNodePtr node, SchedXaction *sx,
static
gboolean
sx_start_handler( xmlNodePtr node, gpointer sx )
sx_start_handler( xmlNodePtr node, gpointer sx_pdata )
{
return sx_set_date( node, (SchedXaction*)sx,
xaccSchedXactionSetStartDate );
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
return sx_set_date( node, sx, xaccSchedXactionSetStartDate );
}
static
gboolean
sx_last_handler( xmlNodePtr node, gpointer sx )
sx_last_handler( xmlNodePtr node, gpointer sx_pdata )
{
return sx_set_date( node, (SchedXaction*)sx,
xaccSchedXactionSetLastOccurDate );
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
return sx_set_date( node, sx, xaccSchedXactionSetLastOccurDate );
}
static
gboolean
sx_end_handler( xmlNodePtr node, gpointer sx )
sx_end_handler( xmlNodePtr node, gpointer sx_pdata )
{
return sx_set_date( node, (SchedXaction*)sx,
xaccSchedXactionSetEndDate );
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
return sx_set_date( node, sx, xaccSchedXactionSetEndDate );
}
static
gboolean
sx_freqspec_handler( xmlNodePtr node, gpointer sx )
sx_freqspec_handler( xmlNodePtr node, gpointer sx_pdata )
{
xmlNodePtr mark;
FreqSpec *fs;
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
xmlNodePtr mark;
FreqSpec *fs;
g_return_val_if_fail( node, FALSE );
fs = dom_tree_to_freqSpec( xmlGetLastChild( node ) );
xaccSchedXactionSetFreqSpec( (SchedXaction*)sx, fs );
xaccSchedXactionSetFreqSpec( sx, fs );
return TRUE;
}
static
gboolean
sx_numOccur_handler( xmlNodePtr node, gpointer sx )
sx_numOccur_handler( xmlNodePtr node, gpointer sx_pdata )
{
gint64 numOccur;
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gint64 numOccur;
if ( ! dom_tree_to_integer( node, &numOccur ) ) {
return FALSE;
}
xaccSchedXactionSetNumOccur( (SchedXaction*)sx, numOccur );
xaccSchedXactionSetNumOccur( sx, numOccur );
return TRUE;
}
static
gboolean
sx_templ_acct_handler( xmlNodePtr node, gpointer p)
sx_templ_acct_handler( xmlNodePtr node, gpointer sx_pdata)
{
SchedXaction *sx = (SchedXaction *) p;
GUID *templ_acct_guid
= dom_tree_to_guid(node);
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
GUID *templ_acct_guid = dom_tree_to_guid(node);
if( ! templ_acct_guid)
if (!templ_acct_guid)
{
return FALSE;
}
sx->template_acct = xaccAccountLookup(templ_acct_guid);
sx->template_acct = xaccAccountLookup(templ_acct_guid, pdata->session);
g_free(templ_acct_guid);
return TRUE;
}
static
gboolean
sx_remOccur_handler( xmlNodePtr node, gpointer sx )
sx_remOccur_handler( xmlNodePtr node, gpointer sx_pdata )
{
gint64 remOccur;
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gint64 remOccur;
if ( ! dom_tree_to_integer( node, &remOccur ) ) {
return FALSE;
}
if ( ! dom_tree_to_integer( node, &remOccur ) ) {
return FALSE;
}
xaccSchedXactionSetRemOccur( (SchedXaction*)sx, remOccur );
return TRUE;
xaccSchedXactionSetRemOccur( sx, remOccur );
return TRUE;
}
static
gboolean
sx_slots_handler( xmlNodePtr node, gpointer sx )
sx_slots_handler( xmlNodePtr node, gpointer sx_pdata )
{
return dom_tree_to_kvp_frame_given( node, xaccSchedXactionGetSlots (sx) );
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
return dom_tree_to_kvp_frame_given( node, xaccSchedXactionGetSlots (sx) );
}
struct dom_tree_handler sx_dom_handlers[] = {
@@ -408,11 +452,12 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag)
{
SchedXaction *sx;
gboolean successful = FALSE;
xmlNodePtr achild;
xmlNodePtr tree = (xmlNodePtr)data_for_children;
gxpf_data *gdata = (gxpf_data*)global_data;
SchedXaction *sx;
gboolean successful = FALSE;
xmlNodePtr achild;
xmlNodePtr tree = (xmlNodePtr)data_for_children;
gxpf_data *gdata = (gxpf_data*)global_data;
struct sx_pdata sx_pdata;
if ( parent_data ) {
return TRUE;
@@ -436,7 +481,10 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
sx->template_acct = NULL;
}
successful = dom_tree_generic_parse( tree, sx_dom_handlers, sx );
sx_pdata.sx = sx;
sx_pdata.session = gdata->sessiondata;
successful = dom_tree_generic_parse( tree, sx_dom_handlers, &sx_pdata );
if ( successful ) {
gdata->cb( tag, gdata->parsedata, sx );

View File

@@ -305,7 +305,7 @@ gnc_read_example_account(GNCSession *session, const gchar *filename)
gea->session = session;
gea->filename = g_strdup(filename);
gea->group = xaccMallocAccountGroup();
gea->group = xaccMallocAccountGroup(session);
top_parser = sixtp_new();
main_parser = sixtp_new();

View File

@@ -476,7 +476,7 @@ gnc_load_financials_from_fd(GNCSession *session, int fd)
/* disable logging during load; otherwise its just a mess */
xaccLogDisable();
holder = xaccMallocAccountGroup();
holder = xaccMallocAccountGroup(session);
grp = readGroup (session, fd, NULL, token);
/* the number of unclaimed accounts should be zero if the
@@ -580,7 +580,7 @@ readGroup (GNCSession *session, int fd, Account *aparent, int token)
int numAcc;
int err=0;
int i;
AccountGroup *grp = xaccMallocAccountGroup();
AccountGroup *grp = xaccMallocAccountGroup(session);
ENTER (" ");

View File

@@ -1123,11 +1123,12 @@ ledger_data_start_handler(GSList* sibling_data, gpointer parent_data,
gpointer global_data, gpointer *data_for_children,
gpointer *result, const gchar *tag, gchar **attrs)
{
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
AccountGroup *ag;
/* disable logging during load; otherwise its just a mess */
xaccLogDisable();
ag = xaccMallocAccountGroup();
ag = xaccMallocAccountGroup(pstatus->session);
g_return_val_if_fail(ag, FALSE);
@@ -1487,6 +1488,7 @@ acc_restore_guid_end_handler(gpointer data_for_children,
gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag)
{
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
Account *acc = (Account *) parent_data;
gchar *txt = NULL;
GUID gid;
@@ -1502,7 +1504,7 @@ acc_restore_guid_end_handler(gpointer data_for_children,
g_return_val_if_fail(ok, FALSE);
if(xaccAccountLookup(&gid)) {
if(xaccAccountLookup(&gid, pstatus->session)) {
return(FALSE);
}
@@ -1697,7 +1699,7 @@ acc_restore_parent_end_handler(gpointer data_for_children,
gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag)
{
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
Account *acc = (Account *) parent_data;
Account *parent;
sixtp_child_result *child_result;
@@ -1716,7 +1718,7 @@ acc_restore_parent_end_handler(gpointer data_for_children,
/* otherwise this must be a good result - use it */
gid = *((GUID *) child_result->data);
parent = xaccAccountLookup(&gid);
parent = xaccAccountLookup(&gid, pstatus->session);
g_return_val_if_fail(parent, FALSE);
@@ -3381,6 +3383,7 @@ txn_restore_split_account_end_handler(gpointer data_for_children,
gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag)
{
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
Split *s = (Split *) parent_data;
Account *acct;
gchar *txt = NULL;
@@ -3397,7 +3400,7 @@ txn_restore_split_account_end_handler(gpointer data_for_children,
g_return_val_if_fail(ok, FALSE);
acct = xaccAccountLookup(&gid);
acct = xaccAccountLookup(&gid, pstatus->session);
g_return_val_if_fail(acct, FALSE);
xaccAccountInsertSplit(acct, s);

View File

@@ -247,7 +247,7 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
PINFO ("account GUID=%s", DB_GET_VAL("accountGUID",j));
guid = nullguid; /* just in case the read fails ... */
string_to_guid (DB_GET_VAL("accountGUID",j), &guid);
acc = xaccAccountLookup (&guid);
acc = xaccAccountLookup (&guid, be->session);
if (!acc)
{
acc = xaccMallocAccount(be->session);
@@ -283,7 +283,7 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{
/* if we haven't restored the parent account, create
* an empty holder for it */
parent = xaccAccountLookup (&guid);
parent = xaccAccountLookup (&guid, be->session);
if (!parent)
{
parent = xaccMallocAccount(be->session);
@@ -315,7 +315,7 @@ pgendGetAllAccounts (PGBackend *be, AccountGroup *topgrp)
if (!topgrp)
{
topgrp = xaccMallocAccountGroup();
topgrp = xaccMallocAccountGroup(be->session);
}
/* Get them ALL */
@@ -355,14 +355,15 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid)
pgendDisable(be);
/* first, see if we already have such an account */
acc = xaccAccountLookup (acct_guid);
acc = xaccAccountLookup (acct_guid, be->session);
if (!acc)
{
engine_data_is_newer = -1;
}
else
{
/* save some performance, don't go to the backend if the data is recent. */
/* save some performance, don't go to the
* backend if the data is recent. */
if (MAX_VERSION_AGE >= be->version_check - acc->version_check)
{
PINFO ("fresh data, skip check");
@@ -387,7 +388,7 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid)
SEND_QUERY (be,be->buff, 0);
pgendGetResults (be, get_account_cb, pgendGetTopGroup (be));
acc = xaccAccountLookup (acct_guid);
acc = xaccAccountLookup (acct_guid, be->session);
/* restore any kvp data associated with the transaction and splits */
if (acc->idata)
{

View File

@@ -51,7 +51,6 @@
#include "gnc-engine-util.h"
#include "guid.h"
#include "GNCId.h"
#include "GNCIdP.h"
#include "builder.h"
#include "checkpoint.h"
@@ -86,8 +85,9 @@ pgendAccountRecomputeAllCheckpoints (PGBackend *be, const GUID *acct_guid)
ENTER("be=%p", be);
guid_string = guid_to_string (acct_guid);
acc = xaccLookupEntity (acct_guid, GNC_ID_ACCOUNT);
commodity_name = gnc_commodity_get_unique_name (xaccAccountGetCommodity(acc));
acc = xaccAccountLookup (acct_guid, be->session);
commodity_name =
gnc_commodity_get_unique_name (xaccAccountGetCommodity(acc));
chunk = g_mem_chunk_create (Checkpoint, 300, G_ALLOC_ONLY);

View File

@@ -292,7 +292,7 @@ pgendProcessEvents (Backend *bend)
xaccGroupMarkSaved (pgendGetTopGroup (be));
break;
case GNC_EVENT_DESTROY: {
Account * acc = xaccAccountLookup (&(ev->guid));
Account * acc = xaccAccountLookup (&(ev->guid), be->session);
xaccAccountBeginEdit (acc);
xaccAccountDestroy (acc);
xaccGroupMarkSaved (pgendGetTopGroup (be));

View File

@@ -425,7 +425,7 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans)
/* next, find the account that this split goes into */
guid = nullguid; /* just in case the read fails ... */
string_to_guid (DB_GET_VAL("accountGUID",j), &guid);
acc = xaccAccountLookup (&guid);
acc = xaccAccountLookup (&guid, be->session);
if (!acc)
{
PERR ("account not found, will delete this split\n"

View File

@@ -176,7 +176,7 @@ get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data)
/* next, find the account that this split goes into */
guid = nullguid; /* just in case the read fails ... */
string_to_guid (DB_GET_VAL("accountGUID",j), &guid);
acc = xaccAccountLookup (&guid);
acc = xaccAccountLookup (&guid, be->session);
if (!acc)
{
PERR ("account not found, will delete this split\n"

View File

@@ -38,6 +38,7 @@
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "gnc-event-p.h"
#include "gnc-session-p.h"
#include "kvp_frame.h"
#include "messages.h"
@@ -105,6 +106,8 @@ xaccInitAccount (Account * acc, GNCSession *session)
acc->core_dirty = FALSE;
acc->do_free = FALSE;
acc->entity_table = gnc_session_get_entity_table (session);
xaccGUIDNew(&acc->guid);
xaccStoreEntity(acc, &acc->guid, GNC_ID_ACCOUNT);
LEAVE ("account=%p\n", acc);
@@ -537,18 +540,30 @@ xaccAccountSetGUID (Account *account, const GUID *guid)
\********************************************************************/
Account *
xaccAccountLookup (const GUID *guid)
xaccAccountLookup (const GUID *guid, GNCSession *session)
{
if (!guid) return NULL;
g_return_val_if_fail (session, NULL);
return xaccLookupEntity (guid, GNC_ID_ACCOUNT);
}
Account *
xaccAccountLookupDirect (GUID guid)
xaccAccountLookupDirect (GUID guid, GNCSession *session)
{
g_return_val_if_fail (session, NULL);
return xaccLookupEntity (&guid, GNC_ID_ACCOUNT);
}
Account *
xaccAccountLookupEntityTable (const GUID *guid,
GNCEntityTable *entity_table)
{
if (!guid) return NULL;
/* FIXME: uncomment when entity tables are in sessions */
/* g_return_val_if_fail (entity_table, NULL); */
return xaccLookupEntity (guid, GNC_ID_ACCOUNT);
}
/********************************************************************\
\********************************************************************/

View File

@@ -150,8 +150,8 @@ void xaccAccountSetSlots_nc(Account *account, kvp_frame *frame);
*/
const GUID * xaccAccountGetGUID (Account *account);
GUID xaccAccountReturnGUID (Account *account);
Account * xaccAccountLookup (const GUID *guid);
Account * xaccAccountLookupDirect (GUID guid);
Account * xaccAccountLookup (const GUID *guid, GNCSession *session);
Account * xaccAccountLookupDirect (GUID guid, GNCSession *session);
/*
* The xaccAccountInsertSplit() method will insert the indicated

View File

@@ -45,7 +45,7 @@
#include "config.h"
#include "Account.h"
#include "GNCId.h"
#include "GNCIdP.h"
#include "Transaction.h"
#include "gnc-commodity.h"
#include "gnc-numeric.h"
@@ -58,6 +58,9 @@ struct account_s
/* public data, describes account */
GUID guid; /* globally unique account id */
GNCEntityTable *entity_table; /* Entity table this account is
* stored in. */
/* The accountName is an arbitrary string assigned by the user.
* It is intended to a short, 5 to 30 character long string that
* is displayed by the GUI as the account mnemonic.
@@ -150,6 +153,11 @@ struct account_s
};
/* The xaccAccountLookupEntityTable() routine is like xaccAccountLookup
* but accepts and entity table instead of a session. */
Account * xaccAccountLookupEntityTable (const GUID *guid,
GNCEntityTable *entity_table);
/* The xaccAccountRemoveSplit() routine will remove the indicated split
* from the indicated account. Note that this will leave the split
* "dangling", i.e. unassigned to any account, and therefore will put

View File

@@ -38,6 +38,7 @@
#include "gnc-engine-util.h"
#include "gnc-event-p.h"
#include "gnc-numeric.h"
#include "gnc-session-p.h"
static short module = MOD_ENGINE;
@@ -52,7 +53,7 @@ static short module = MOD_ENGINE;
\********************************************************************/
static void
xaccInitializeAccountGroup (AccountGroup *grp)
xaccInitializeAccountGroup (AccountGroup *grp, GNCEntityTable *entity_table)
{
grp->saved = 1;
@@ -61,21 +62,36 @@ xaccInitializeAccountGroup (AccountGroup *grp)
grp->backend = NULL;
grp->book = NULL;
grp->entity_table = entity_table;
}
/********************************************************************\
\********************************************************************/
AccountGroup *
xaccMallocAccountGroup (void)
static AccountGroup *
xaccMallocAccountGroupEntityTable (GNCEntityTable *entity_table)
{
AccountGroup *grp = g_new (AccountGroup, 1);
AccountGroup *grp;
xaccInitializeAccountGroup (grp);
/* FIXME: uncomment when entity tables are finally in sessions. */
/* g_return_val_if_fail (entity_table, NULL); */
grp = g_new (AccountGroup, 1);
xaccInitializeAccountGroup (grp, entity_table);
return grp;
}
AccountGroup *
xaccMallocAccountGroup (GNCSession *session)
{
g_return_val_if_fail (session, NULL);
return xaccMallocAccountGroupEntityTable
(gnc_session_get_entity_table (session));
}
/********************************************************************\
\********************************************************************/
@@ -634,10 +650,14 @@ xaccAccountInsertSubAccount (Account *adult, Account *child)
{
if (!adult || !child) return;
/* FIXME: uncomment when entity tables are finished. */
/* g_return_if_fail (adult->entity_table); */
g_return_if_fail (adult->entity_table == child->entity_table);
/* if a container for the children doesn't yet exist, add it */
if (adult->children == NULL)
{
adult->children = xaccMallocAccountGroup ();
adult->children = xaccMallocAccountGroupEntityTable (adult->entity_table);
xaccGroupSetBook (adult->children, xaccGroupGetBook (adult->parent));
}

View File

@@ -29,10 +29,11 @@
#include "Account.h"
#include "GNCId.h"
#include "gnc-engine.h"
/** PROTOTYPES ******************************************************/
AccountGroup *xaccMallocAccountGroup (void);
AccountGroup *xaccMallocAccountGroup (GNCSession *session);
void xaccFreeAccountGroup (AccountGroup *account_group);
void xaccAccountGroupBeginEdit (AccountGroup *grp);
void xaccAccountGroupCommitEdit (AccountGroup *grp);

View File

@@ -39,7 +39,7 @@
#include "config.h"
#include "BackendP.h"
#include "GNCId.h"
#include "GNCIdP.h"
#include "Transaction.h"
#include "gnc-book.h"
#include "gnc-numeric.h"
@@ -51,6 +51,9 @@ struct account_group_s
/* The flags: */
unsigned int saved : 1;
GNCEntityTable *entity_table; /* table which child accounts must
* be stored in. */
Account *parent; /* back-pointer to parent */
GList *accounts; /* list of account pointers */

View File

@@ -36,12 +36,11 @@
#include "gnc-engine-util.h"
#include "gnc-numeric.h"
#include "Account.h"
#include "AccountP.h"
#include "BackendP.h"
#include "GNCId.h"
#include "Group.h"
#include "GroupP.h"
#include "Query.h"
#include "Transaction.h"
#include "TransactionP.h"
static short module = MOD_QUERY;
@@ -1021,11 +1020,14 @@ copy_guid_list (GList *guids)
}
static GList *
guid_list_to_account_list (GList *guids)
guid_list_to_account_list (Query * q, GList *guids)
{
GList *accounts = NULL;
GList *node;
if (!q || !q->acct_group)
return NULL;
for (node = guids; node; node = node->next)
{
GUID *guid = node->data;
@@ -1034,7 +1036,7 @@ guid_list_to_account_list (GList *guids)
if (!guid)
continue;
account = xaccAccountLookup (guid);
account = xaccAccountLookupEntityTable (guid, q->acct_group->entity_table);
if (!account)
continue;
@@ -1061,7 +1063,7 @@ xaccQueryCompileTerms (Query *q)
case PD_ACCOUNT:
g_list_free (qt->data.acct.accounts);
qt->data.acct.accounts =
guid_list_to_account_list (qt->data.acct.account_guids);
guid_list_to_account_list (q, qt->data.acct.account_guids);
break;
default:
@@ -2358,8 +2360,9 @@ xaccGUIDMatchPredicate(Split * s, PredicateData * pd)
GUIDPredicateData *gpd;
GUID *guid;
assert(s && pd);
assert(pd->type == PD_GUID);
g_return_val_if_fail (s, 0);
g_return_val_if_fail (pd, 0);
g_return_val_if_fail (pd->type == PD_GUID, 0);
guid = &pd->guid.guid;
@@ -2371,7 +2374,8 @@ xaccGUIDMatchPredicate(Split * s, PredicateData * pd)
return 0;
case GNC_ID_ACCOUNT:
return xaccSplitGetAccount (s) == xaccAccountLookup (guid);
return (xaccSplitGetAccount (s) ==
xaccAccountLookupEntityTable (guid, s->entity_table));
case GNC_ID_TRANS:
return xaccSplitGetParent (s) == xaccTransLookup (guid);

View File

@@ -114,6 +114,8 @@ xaccInitSplit(Split * split, GNCEntityTable *entity_table)
split->kvp_data = kvp_frame_new();
split->idata = 0;
split->entity_table = entity_table;
xaccGUIDNew(&split->guid);
xaccStoreEntity(split, &split->guid, GNC_ID_SPLIT);
}
@@ -293,9 +295,12 @@ xaccSplitGetAccount(Split *s)
{
if(!s) return NULL;
if(!s->acc)
if (!s->acc)
{
xaccSplitSetAccount_Internal(s, xaccAccountLookup(&s->acc_guid));
Account *account;
account = xaccAccountLookupEntityTable (&s->acc_guid, s->entity_table);
xaccSplitSetAccount_Internal (s, account);
}
return s->acc;
@@ -649,9 +654,10 @@ xaccInitTransaction (Transaction * trans, GNCSession *session)
trans->kvp_data = kvp_frame_new();
trans->idata = 0;
trans->entity_table = gnc_session_get_entity_table (session);
xaccGUIDNew(&trans->guid);
xaccStoreEntity(trans, &trans->guid, GNC_ID_TRANS);
trans->entity_table = NULL;
}
/********************************************************************\

View File

@@ -78,6 +78,8 @@ struct split_s
{
GUID guid; /* globally unique id */
GNCEntityTable *entity_table; /* The table where this split is stored. */
GUID acc_guid; /* the guid of the associated account */
Account *acc; /* back-pointer to debited/credited account */

View File

@@ -110,7 +110,7 @@
;; scheme split. Not all values are copied. The reconcile
;; status and date are not copied. The C split's guid is,
;; of course, unchanged.
(define (gnc:split-scm-onto-split split-scm split)
(define (gnc:split-scm-onto-split split-scm split session)
(if (not split)
#f
(begin
@@ -123,7 +123,8 @@
(if amount (gnc:split-set-amount split amount))
(if value (gnc:split-set-value split value)))
(let ((account (gnc:account-lookup
(gnc:split-scm-get-account-guid split-scm))))
(gnc:split-scm-get-account-guid split-scm)
session)))
(if account
(begin
(gnc:account-begin-edit account)
@@ -279,7 +280,7 @@
(if (not new-guid)
(set! new-guid old-guid))
(gnc:split-scm-set-account-guid split-scm new-guid)
(gnc:split-scm-onto-split split-scm new-split)
(gnc:split-scm-onto-split split-scm new-split session)
(gnc:split-scm-set-account-guid split-scm old-guid)
(gnc:transaction-append-split trans new-split)
(loop (cdr split-scms)))))

View File

@@ -28,6 +28,8 @@
#include "config.h"
#include "AccountP.h"
#include "GNCIdP.h"
#include "gnc-associate-account.h"
#include "gnc-engine-util.h"
@@ -166,7 +168,7 @@ make_kvpd_on_list(GList *account_list)
}
static GList *
de_kvp_account_list(kvp_value *kvpd_list)
de_kvp_account_list(kvp_value *kvpd_list, GNCEntityTable *entity_table)
{
GList *guid_account_list = kvp_value_get_glist(kvpd_list);
if (guid_account_list)
@@ -175,7 +177,8 @@ de_kvp_account_list(kvp_value *kvpd_list)
for(; guid_account_list; guid_account_list=g_list_next(guid_account_list))
{
g_list_prepend(expense_acc_list,
xaccAccountLookup(guid_account_list->data));
xaccAccountLookupEntityTable(guid_account_list->data,
entity_table));
}
expense_acc_list = g_list_reverse(expense_acc_list);
@@ -304,8 +307,9 @@ gnc_tracking_find_expense_accounts(Account *stock_account,
expense_acc_frame = get_assoc_acc_frame(account_frame);
kvpd_on_account_list = kvp_frame_get_slot(account_frame,
expense_to_key[category]);
return de_kvp_account_list(kvpd_on_account_list);
return de_kvp_account_list(kvpd_on_account_list,
stock_account->entity_table);
}
/*********************************************************************\
@@ -339,7 +343,8 @@ gnc_tracking_find_income_accounts(Account *stock_account,
kvpd_on_account_list = kvp_frame_get_slot(income_acc_frame,
income_to_key[category]);
return de_kvp_account_list(kvpd_on_account_list);
return de_kvp_account_list(kvpd_on_account_list,
stock_account->entity_table);
}
/*********************************************************************\
@@ -451,7 +456,8 @@ gnc_tracking_dissociate_account(Account *inc_or_expense_account)
inc_or_expense_account_guid = xaccAccountGetGUID(inc_or_expense_account);
stock_account = xaccAccountLookup(stock_account_guid);
stock_account = xaccAccountLookupEntityTable
(stock_account_guid, inc_or_expense_account->entity_table);
stock_account_kvpframe = xaccAccountGetSlots(stock_account);

View File

@@ -63,18 +63,18 @@ static short module = MOD_IO;
/* ---------------------------------------------------------------------- */
static void
gnc_book_init (GNCBook *book)
gnc_book_init (GNCBook *book, GNCSession *session)
{
Account *template_acct;
if (!book) return;
book->topgroup = xaccMallocAccountGroup();
book->topgroup = xaccMallocAccountGroup(session);
book->pricedb = gnc_pricedb_create();
book->sched_xactions = NULL;
book->sx_notsaved = FALSE;
book->template_group = xaccMallocAccountGroup();
book->template_group = xaccMallocAccountGroup(session);
book->commodity_table = gnc_engine_commodity_table_new ();
@@ -83,10 +83,15 @@ gnc_book_init (GNCBook *book)
}
GNCBook *
gnc_book_new (void)
gnc_book_new (GNCSession *session)
{
GNCBook *book = g_new0(GNCBook, 1);
gnc_book_init(book);
GNCBook *book;
g_return_val_if_fail (session, NULL);
book = g_new0(GNCBook, 1);
gnc_book_init(book, session);
return book;
}

View File

@@ -36,6 +36,7 @@
#ifndef GNC_BOOK_H
#define GNC_BOOK_H
#include "gnc-engine.h"
#include "gnc-pricedb.h"
#include "Backend.h"
#include "Group.h"
@@ -48,7 +49,7 @@ typedef struct gnc_book_struct GNCBook;
/** PROTOTYPES ******************************************************/
GNCBook * gnc_book_new (void);
GNCBook * gnc_book_new (GNCSession *session);
void gnc_book_destroy (GNCBook *book);
AccountGroup *gnc_book_get_group (GNCBook *book);

View File

@@ -119,7 +119,7 @@ gnc_session_init (GNCSession *session)
{
if (!session) return;
session->book = gnc_book_new ();
session->book = gnc_book_new (session);
session->entity_table = NULL;
session->book_id = NULL;
session->fullpath = NULL;
@@ -350,7 +350,7 @@ gnc_session_load (GNCSession *session)
xaccLogDisable();
gnc_book_destroy (session->book);
session->book = gnc_book_new ();
session->book = gnc_book_new (session);
xaccLogSetBaseName(session->logpath);
xaccLogEnable();

View File

@@ -991,7 +991,7 @@ description of the nature of a particular account.")
'gnc:account-lookup
'<gnc:Account*>
"xaccAccountLookupDirect"
'((<gnc:guid-scm> guid))
'((<gnc:guid-scm> guid) (<gnc:Session*> session))
"Lookup the account with GUID guid.")
(gw:wrap-function
@@ -1164,8 +1164,8 @@ children to this account.")
'gnc:malloc-account-group
'<gnc:AccountGroup*>
"xaccMallocAccountGroup"
'()
"Create a newaccount group.")
'((<gnc:Session*> session))
"Create a new account group.")
(gw:wrap-function
mod

View File

@@ -430,7 +430,7 @@ get_random_group_depth(GNCSession *session, int depth)
if (depth == 0)
return NULL;
group = xaccMallocAccountGroup ();
group = xaccMallocAccountGroup (session);
num_accounts = get_random_int_in_range (1, max_group_accounts);
@@ -824,7 +824,7 @@ get_random_book (GNCSession *session)
{
GNCBook *book;
book = gnc_book_new ();
book = gnc_book_new (session);
gnc_book_set_group (book, get_random_group (session));

View File

@@ -8,7 +8,7 @@
(gnc:module-load "gnucash/engine" 0)
(let* ((session (gnc:session-new))
(group (gnc:malloc-account-group))
(group (gnc:malloc-account-group session))
(acct (gnc:malloc-account session)))
(gnc:account-begin-edit acct)
(gnc:account-set-name acct "foo")

View File

@@ -61,7 +61,7 @@ run_test (void)
exit(get_rv());
}
book = gnc_book_new ();
book = gnc_book_new (session);
if (!book)
{
failure("book not created");

View File

@@ -363,7 +363,8 @@ gnc_account_tree_refresh(GNCAccountTree * tree)
gtk_clist_clear(clist);
root_account = xaccAccountLookup (&tree->root_account);
root_account = xaccAccountLookup (&tree->root_account,
gnc_get_current_session ());
gnc_account_tree_fill (tree, expanded_accounts,
gnc_account_tree_insert_row (tree, NULL, NULL,

View File

@@ -130,7 +130,7 @@ aw_get_account (AccountWindow *aw)
if (!aw)
return NULL;
return xaccAccountLookup (&aw->account);
return xaccAccountLookup (&aw->account, gnc_get_current_session ());
}
/* Copy the account values to the GUI widgets */

View File

@@ -325,7 +325,8 @@ create_each_transaction( Transaction *t, void *d )
PERR( "Null kvp_val for account\n" );
}
acct_guid = kvp_value_get_guid( kvp_val );
acct = xaccAccountLookup( acct_guid );
acct = xaccAccountLookup( acct_guid,
gnc_get_current_session () );
DEBUG( "Got account with name \"%s\"\n",
xaccAccountGetName( acct ) );
/* xaccSplitSetAccount( split, acct ); */

View File

@@ -1155,7 +1155,8 @@ _create_each_transaction_helper( Transaction *t, void *d )
PERR( "Null kvp_val for account" );
}
acct_guid = kvp_value_get_guid( kvp_val );
acct = xaccAccountLookup( acct_guid );
acct = xaccAccountLookup( acct_guid,
gnc_get_current_session ());
DEBUG( "Got account with name \"%s\"",
xaccAccountGetName( acct ) );
if ( commonCommodity != NULL ) {

View File

@@ -634,7 +634,7 @@ hierarchy_merge_groups (GSList *dalist)
{
GSList *mark;
gnc_commodity *com;
AccountGroup *ret = xaccMallocAccountGroup ();
AccountGroup *ret = xaccMallocAccountGroup (gnc_get_current_session ());
com = gnc_commodity_edit_get_commodity (get_commodity_editor ());

View File

@@ -173,7 +173,7 @@ refresh_details_page (StockSplitInfo *info)
GNCPrintAmountInfo print_info;
Account *account;
account = xaccAccountLookup (&info->account);
account = xaccAccountLookup (&info->account, gnc_get_current_session ());
g_return_if_fail (account != NULL);
@@ -197,7 +197,7 @@ account_next (GnomeDruidPage *druidpage,
StockSplitInfo *info = user_data;
Account *account;
account = xaccAccountLookup (&info->account);
account = xaccAccountLookup (&info->account, gnc_get_current_session ());
g_return_val_if_fail (account != NULL, TRUE);
@@ -357,7 +357,7 @@ stock_split_finish (GnomeDruidPage *druidpage,
Split *split;
time_t date;
account = xaccAccountLookup (&info->account);
account = xaccAccountLookup (&info->account, gnc_get_current_session ());
g_return_if_fail (account != NULL);
amount = gnc_amount_edit_get_amount
@@ -498,7 +498,8 @@ static gboolean
account_currency_filter (Account *account, gpointer user_data)
{
StockSplitInfo *info = user_data;
Account *split_account = xaccAccountLookup (&info->account);
Account *split_account = xaccAccountLookup (&info->account,
gnc_get_current_session ());
if (!account)
return FALSE;
@@ -677,7 +678,7 @@ refresh_handler (GHashTable *changes, gpointer user_data)
GladeXML *xml;
id_type = xaccGUIDType (&info->account);
old_account = xaccAccountLookup (&info->account);
old_account = xaccAccountLookup (&info->account, gnc_get_current_session ());
if (fill_account_list (info, old_account) == 0)
{
@@ -685,7 +686,7 @@ refresh_handler (GHashTable *changes, gpointer user_data)
return;
}
new_account = xaccAccountLookup (&info->account);
new_account = xaccAccountLookup (&info->account, gnc_get_current_session ());
if (id_type == GNC_ID_NULL || old_account == new_account)
return;

View File

@@ -225,7 +225,7 @@ gnc_html_register_url_cb (const char *location, const char *label,
return FALSE;
case GNC_ID_ACCOUNT:
account = xaccAccountLookup (&guid);
account = xaccAccountLookup (&guid, gnc_get_current_session ());
reg = regWindowSimple (account);
break;

View File

@@ -201,7 +201,7 @@ recn_get_account (RecnWindow *recnData)
if (!recnData)
return NULL;
return xaccAccountLookup (&recnData->account);
return xaccAccountLookup (&recnData->account, gnc_get_current_session ());
}
/********************************************************************\

View File

@@ -177,7 +177,7 @@
(gnc:backtrace-if-exception
(lambda ()
(let* ((old-group (gnc:get-current-group))
(new-group (gnc:malloc-account-group))
(new-group (gnc:malloc-account-group (gnc:get-current-session)))
(gnc-acct-hash (make-hash-table 20))
(separator (string-ref (gnc:account-separator-char) 0))
(default-currency

View File

@@ -50,7 +50,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-io:acct-table-make-gnc-group acct-table qif-file commodity)
(let ((group (gnc:malloc-account-group)))
(let ((group (gnc:malloc-account-group (gnc:get-current-session))))
;; poke through the qif-file accounts to see if any of them
;; show up in the data
(let ((qif-acct-table (qif-io:acct-table-accounts acct-table)))

View File

@@ -89,7 +89,7 @@ gnc_ledger_display_leader (GNCLedgerDisplay *ld)
if (!ld)
return NULL;
return xaccAccountLookup (&ld->leader);
return xaccAccountLookup (&ld->leader, gnc_get_current_session ());
}
GNCLedgerDisplayType

View File

@@ -321,7 +321,8 @@ gnc_split_register_save_template_cells (gpointer save_data,
trans = sd->trans;
split = sd->split;
template_acc = xaccAccountLookup (&info->template_account);
template_acc = xaccAccountLookup (&info->template_account,
gnc_get_current_session ());
if (gnc_table_layout_get_cell_changed (reg->table->layout,
DATE_CELL, TRUE) ||

View File

@@ -1315,6 +1315,7 @@ gnc_template_register_get_xfrm_entry (VirtualLocation virt_loc,
if (kvpf)
{
Account *account;
GUID *guid;
guid = kvp_value_get_guid (kvp_frame_get_slot_path
@@ -1323,8 +1324,9 @@ gnc_template_register_get_xfrm_entry (VirtualLocation virt_loc,
"account",
NULL));
name = xaccAccountGetFullName (xaccAccountLookup (guid),
gnc_get_account_separator ());
account = xaccAccountLookup (guid, gnc_get_current_session ());
name = xaccAccountGetFullName (account, gnc_get_account_separator ());
}
else
name = NULL;

View File

@@ -127,7 +127,8 @@ gnc_split_register_get_default_account (SplitRegister *reg)
{
SRInfo *info = gnc_split_register_get_info (reg);
return xaccAccountLookup (&info->default_account);
return xaccAccountLookup (&info->default_account,
gnc_get_current_session ());
}
void

View File

@@ -182,7 +182,7 @@ gnc_copy_split_onto_split(Split *from, Split *to, gboolean use_cut_semantics)
if (split_scm == SCM_UNDEFINED)
return;
gnc_copy_split_scm_onto_split(split_scm, to);
gnc_copy_split_scm_onto_split(split_scm, to, gnc_get_current_session ());
}
/* Uses the scheme transaction copying routines */
@@ -807,7 +807,8 @@ gnc_split_register_paste_current (SplitRegister *reg)
xaccTransAppendSplit(trans, split);
}
gnc_copy_split_scm_onto_split(copied_item, split);
gnc_copy_split_scm_onto_split(copied_item, split,
gnc_get_current_session ());
xaccTransCommitEdit(trans);
}
else