From c672e1960c2a07a2e6382446bb1a2b9d69394f3e Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Fri, 5 Oct 2001 09:54:41 +0000 Subject: [PATCH] Work on moving entity tables into sessions. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5467 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/file/gnc-pricedb-xml-v2.c | 2 +- src/backend/file/io-gncbin-r.c | 2 +- src/backend/file/io-gncxml-v1.c | 2 +- src/backend/postgres/price.c | 2 +- src/engine/gnc-pricedb-p.h | 9 ++++++--- src/engine/gnc-pricedb.c | 22 ++++++++++++++++------ src/engine/gnc-pricedb.h | 13 +++++++------ src/engine/gw-engine-spec.scm | 4 ++-- src/engine/test-core/test-engine-stuff.c | 2 +- src/gnome/dialog-price-editor.c | 14 +++++++------- src/gnome/dialog-scheduledxaction.c | 2 +- src/gnome/druid-stock-split.c | 2 +- src/scm/price-quotes.scm | 12 ++++++------ 13 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/backend/file/gnc-pricedb-xml-v2.c b/src/backend/file/gnc-pricedb-xml-v2.c index 366c64e8e2..13327dcd28 100644 --- a/src/backend/file/gnc-pricedb-xml-v2.c +++ b/src/backend/file/gnc-pricedb-xml-v2.c @@ -156,7 +156,7 @@ price_parse_xml_end_handler(gpointer data_for_children, if(price_xml->prev) { ok = FALSE; goto cleanup_and_exit; } if(!price_xml->xmlChildrenNode) { ok = FALSE; goto cleanup_and_exit; } - p = gnc_price_create(); + p = gnc_price_create(session); if(!p) { ok = FALSE; goto cleanup_and_exit; } for(child = price_xml->xmlChildrenNode; child; child = child->next) { diff --git a/src/backend/file/io-gncbin-r.c b/src/backend/file/io-gncbin-r.c index 783f06602c..8963a093ac 100644 --- a/src/backend/file/io-gncbin-r.c +++ b/src/backend/file/io-gncbin-r.c @@ -217,7 +217,7 @@ cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices, (acct_type == CURRENCY)) { /* this is a quote -- file it in the db and kill the split */ Transaction *txn = xaccSplitGetParent(q->split); - GNCPrice *price = gnc_price_create(); + GNCPrice *price = gnc_price_create(session); Timespec time = xaccTransRetDatePostedTS(txn); gnc_price_begin_edit(price); diff --git a/src/backend/file/io-gncxml-v1.c b/src/backend/file/io-gncxml-v1.c index 930f1db158..2c9b034cd5 100644 --- a/src/backend/file/io-gncxml-v1.c +++ b/src/backend/file/io-gncxml-v1.c @@ -3627,7 +3627,7 @@ price_parse_xml_end_handler(gpointer data_for_children, if(price_xml->prev) { ok = FALSE; goto cleanup_and_exit; } if(!price_xml->xmlChildrenNode) { ok = FALSE; goto cleanup_and_exit; } - p = gnc_price_create(); + p = gnc_price_create(pstatus->session); if(!p) { ok = FALSE; goto cleanup_and_exit; } for(child = price_xml->xmlChildrenNode; child; child = child->next) { diff --git a/src/backend/postgres/price.c b/src/backend/postgres/price.c index 7025182884..3ccdf5e1c5 100644 --- a/src/backend/postgres/price.c +++ b/src/backend/postgres/price.c @@ -240,7 +240,7 @@ get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data) if (!pr) { - pr = gnc_price_create(); + pr = gnc_price_create(be->session); gnc_price_begin_edit (pr); gnc_price_set_guid (pr, &guid); not_found = 1; diff --git a/src/engine/gnc-pricedb-p.h b/src/engine/gnc-pricedb-p.h index f4f0063727..5fa889790d 100644 --- a/src/engine/gnc-pricedb-p.h +++ b/src/engine/gnc-pricedb-p.h @@ -30,7 +30,8 @@ #include "BackendP.h" #include "gnc-pricedb.h" -struct _GNCPrice { +struct gnc_price_s +{ /* 'public' data fields */ GUID guid; /* globally unique price id */ GNCPriceDB *db; @@ -52,7 +53,8 @@ struct _GNCPrice { -struct _GNCPriceDB { +struct gnc_price_db_s +{ GHashTable *commodity_hash; Backend *backend; gboolean dirty; @@ -72,7 +74,8 @@ typedef enum { } PriceLookupType; -struct _GNCPriceLookup { +struct gnc_price_lookup_s +{ PriceLookupType type; GNCPriceDB *prdb; gnc_commodity *commodity; diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c index 2f1ad4c3d8..69ba23a94f 100644 --- a/src/engine/gnc-pricedb.c +++ b/src/engine/gnc-pricedb.c @@ -49,19 +49,25 @@ static gboolean remove_price(GNCPriceDB *db, GNCPrice *p, gboolean cleanup); /* allocation */ GNCPrice * -gnc_price_create(void) +gnc_price_create (GNCSession *session) { - GNCPrice *p = g_new0(GNCPrice, 1); - ENTER(" "); + GNCPrice *p; + + g_return_val_if_fail (session, NULL); + + p = g_new0(GNCPrice, 1); + p->refcount = 1; p->editlevel = 0; p->not_saved = FALSE; p->do_free = FALSE; p->version = 0; p->version_check = 0; + xaccGUIDNew (&p->guid); xaccStoreEntity(p, &p->guid, GNC_ID_PRICE); gnc_engine_generate_event (&p->guid, GNC_EVENT_CREATE); + return p; } @@ -109,14 +115,18 @@ gnc_price_unref(GNCPrice *p) /* ==================================================================== */ GNCPrice * -gnc_price_clone(GNCPrice* p) +gnc_price_clone (GNCPrice* p, GNCSession *session) { /* the clone doesn't belong to a PriceDB */ GNCPrice *new_p; - + ENTER ("pr=%p", p); + + g_return_val_if_fail (session, NULL); + if(!p) return NULL; - new_p = gnc_price_create(); + + new_p = gnc_price_create(session); if(!new_p) return NULL; new_p->version = p->version; diff --git a/src/engine/gnc-pricedb.h b/src/engine/gnc-pricedb.h index 5e3fcc534e..40c51bffd7 100644 --- a/src/engine/gnc-pricedb.h +++ b/src/engine/gnc-pricedb.h @@ -25,8 +25,9 @@ #define GNC_PRICEDB_H #include "date.h" -#include "gnc-numeric.h" #include "gnc-commodity.h" +#include "gnc-numeric.h" +#include "gnc-engine.h" #include "guid.h" #include @@ -107,20 +108,20 @@ */ -typedef struct _GNCPrice GNCPrice; -typedef struct _GNCPriceLookup GNCPriceLookup; +typedef struct gnc_price_s GNCPrice; +typedef struct gnc_price_lookup_s GNCPriceLookup; /****************/ /* constructors */ /* gnc_price_create - returns a newly allocated and initialized price with a reference count of 1. */ -GNCPrice *gnc_price_create(void); +GNCPrice *gnc_price_create(GNCSession *session); /* gnc_price_clone - returns a newly allocated price that's a content-wise duplicate of the given price, p. The returned clone will have a reference count of 1. */ -GNCPrice *gnc_price_clone(GNCPrice* p); +GNCPrice *gnc_price_clone(GNCPrice* p, GNCSession *session); /*********************/ /* memory management */ @@ -213,7 +214,7 @@ gboolean gnc_price_list_equal(GList *prices1, GList *prices2); */ -typedef struct _GNCPriceDB GNCPriceDB; +typedef struct gnc_price_db_s GNCPriceDB; /* gnc_pricedb_create - create a new pricedb. Normally you won't need diff --git a/src/engine/gw-engine-spec.scm b/src/engine/gw-engine-spec.scm index 58c563dc6e..85d8ceacce 100644 --- a/src/engine/gw-engine-spec.scm +++ b/src/engine/gw-engine-spec.scm @@ -1313,9 +1313,9 @@ when no longer needed.") 'gnc:price-create ' "gnc_price_create" - '() + '(( session)) "Create and return a new price.") - + (gw:wrap-function mod 'gnc:price-unref diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.c index 5041bcc2bd..42c981eb06 100644 --- a/src/engine/test-core/test-engine-stuff.c +++ b/src/engine/test-core/test-engine-stuff.c @@ -131,7 +131,7 @@ get_random_price(GNCSession *session) char *string; gnc_commodity *c; - p = gnc_price_create (); + p = gnc_price_create (session); c = get_random_commodity (session); gnc_price_set_commodity (p, c); diff --git a/src/gnome/dialog-price-editor.c b/src/gnome/dialog-price-editor.c index d4a600f5b1..db8a241cde 100644 --- a/src/gnome/dialog-price-editor.c +++ b/src/gnome/dialog-price-editor.c @@ -595,7 +595,7 @@ add_clicked (GtkWidget *widget, gpointer data) if (pdb_dialog->price) gnc_price_unref (pdb_dialog->price); - pdb_dialog->price = gnc_price_create (); + pdb_dialog->price = gnc_price_create (gnc_get_current_session ()); pdb_dialog->new = TRUE; pdb_dialog->changed = TRUE; @@ -614,20 +614,20 @@ static void get_quotes_clicked (GtkWidget *widget, gpointer data) { PricesDialog *pdb_dialog = data; - GNCBook *book = gnc_get_current_book (); + GNCSession *session = gnc_get_current_session (); SCM quotes_func; - SCM book_scm; + SCM session_scm; - quotes_func = gh_eval_str ("gnc:book-add-quotes"); + quotes_func = gh_eval_str ("gnc:session-add-quotes"); if (!gh_procedure_p (quotes_func)) return; - book_scm = gnc_book_to_scm (book); - if (gh_scm2bool (gh_not (book_scm))) + session_scm = gnc_session_to_scm (session); + if (gh_scm2bool (gh_not (session_scm))) return; gnc_set_busy_cursor (NULL, TRUE); - gh_call1 (quotes_func, book_scm); + gh_call1 (quotes_func, session_scm); gnc_unset_busy_cursor (NULL); gnc_gui_refresh_all (); diff --git a/src/gnome/dialog-scheduledxaction.c b/src/gnome/dialog-scheduledxaction.c index 3413855dba..785f4646a6 100644 --- a/src/gnome/dialog-scheduledxaction.c +++ b/src/gnome/dialog-scheduledxaction.c @@ -829,7 +829,7 @@ new_button_clicked( GtkButton *b, gpointer d ) { SchedXactionDialog *sxd; SchedXaction *tmpSX = - xaccSchedXactionMalloc( gnc_get_current_book ()); + xaccSchedXactionMalloc( gnc_get_current_session ()); SchedXactionEditorDialog *sxed; sxd = (SchedXactionDialog*)d; diff --git a/src/gnome/druid-stock-split.c b/src/gnome/druid-stock-split.c index 9ece27eb8c..43b506072d 100644 --- a/src/gnome/druid-stock-split.c +++ b/src/gnome/druid-stock-split.c @@ -409,7 +409,7 @@ stock_split_finish (GnomeDruidPage *druidpage, ts.tv_sec = date; ts.tv_nsec = 0; - price = gnc_price_create (); + price = gnc_price_create (gnc_get_current_session ()); gnc_price_begin_edit (price); gnc_price_set_commodity (price, xaccAccountGetCommodity (account)); diff --git a/src/scm/price-quotes.scm b/src/scm/price-quotes.scm index f6950268d4..3948566137 100644 --- a/src/scm/price-quotes.scm +++ b/src/scm/price-quotes.scm @@ -292,7 +292,7 @@ get-quotes kill-quoter))) -(define (gnc:book-add-quotes book) +(define (gnc:session-add-quotes session) (define (find-quotables group) ;; Return a list of accounts for whose commodities we should get @@ -551,7 +551,7 @@ (if (not (and commodity currency gnc-time price price-type)) (string-append currency-str ":" (gnc:commodity-get-mnemonic commodity)) - (let ((gnc-price (gnc:price-create))) + (let ((gnc-price (gnc:price-create session))) (if (not gnc-price) (string-append currency-str ":" (gnc:commodity-get-mnemonic commodity)) @@ -575,7 +575,8 @@ ;; FIXME: uses of gnc:warn in here need to be cleaned up. Right ;; now, they'll result in funny formatting. - (let* ((group (gnc:book-get-group book)) + (let* ((book (gnc:session-get-book session)) + (group (gnc:book-get-group book)) (quotables (and group (find-quotables group))) (fq-call-data (and quotables (accounts->fq-call-data quotables))) (fq-calls (and fq-call-data @@ -693,8 +694,7 @@ Run 'update-finance-quote' as root to install them.") "\n"))) (define (gnc:add-quotes-to-book-at-url url) (let* ((session (gnc:url->loaded-session url #f #f)) - (book (gnc:session-get-book session)) - (quote-ok? (and book (gnc:book-add-quotes book)))) + (quote-ok? (and session (gnc:session-add-quotes session)))) (if (not quote-ok?) (gnc:msg "book-add-quotes failed")) (and session (gnc:session-save session)) @@ -703,7 +703,7 @@ Run 'update-finance-quote' as root to install them.") "\n"))) (gnc:session-get-error session) #f))) (set! quote-ok? #f)) (if (not quote-ok?) - (gnc:msg "book-save failed " (gnc:session-get-error session))) + (gnc:msg "session-save failed " (gnc:session-get-error session))) (and session (gnc:session-destroy session)) quote-ok?))