From 9c74f60c5f8a943bebe62c141e9bc77c7135a7f3 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Mon, 11 Jun 2001 04:19:08 +0000 Subject: [PATCH] handle account creation events git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4607 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/sql/README | 3 +++ src/engine/sql/events.c | 32 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/engine/sql/README b/src/engine/sql/README index b4305007a9..7beb9a9616 100644 --- a/src/engine/sql/README +++ b/src/engine/sql/README @@ -298,6 +298,8 @@ operation is probably OK. -- NOTIFY is not updating main window balances ... +-- implement price change events + -- during sync, detect and report conflicting edits to accounts and transactions. See the notes for pgendSync() for details as to what this is about. For the first pass, this is not a @@ -314,6 +316,7 @@ operation is probably OK. Otherwise, any edit of this account will incorrectly add the deleted account back in. (Note that from the user perspective, deleting accounts is a bad idea ...) + (this is handled with an event, but is not handled via poll) -- fix caching in the face of lost contact to the backend. If the backend can't contact its server, then we should just save up caches, diff --git a/src/engine/sql/events.c b/src/engine/sql/events.c index 06acd7e357..cf228b60b4 100644 --- a/src/engine/sql/events.c +++ b/src/engine/sql/events.c @@ -258,15 +258,22 @@ pgendProcessEvents (Backend *bend) for (node = pending; node; node = node->next) { Event *ev = (Event *) node->data; - GNCIdType obj_type; + GNCIdType local_obj_type; /* lets see if the local cache has this item in it */ - obj_type = xaccGUIDType (&(ev->guid)); - switch (obj_type) + local_obj_type = xaccGUIDType (&(ev->guid)); + if ((local_obj_type != GNC_ID_NONE) && (local_obj_type != ev->obj_type)) + { + PERR ("ouch! object type mismatch, local=%d, event=%d", local_obj_type, ev->obj_type); + g_free (ev); + continue; + } + + switch (ev->obj_type) { case GNC_ID_NONE: case GNC_ID_NULL: - PINFO ("object not present in local cache"); + PERR ("bad event type"); break; case GNC_ID_ACCOUNT: if (0 < timespec_cmp(&(ev->stamp), &(be->last_account))) @@ -280,6 +287,7 @@ pgendProcessEvents (Backend *bend) break; case GNC_EVENT_CREATE: case GNC_EVENT_MODIFY: + /* if the remote user created an account, mirror it here */ pgendCopyAccountToEngine (be, &(ev->guid)); break; case GNC_EVENT_DESTROY: { @@ -300,9 +308,13 @@ pgendProcessEvents (Backend *bend) switch (ev->type) { default: - case GNC_EVENT_CREATE: PERR ("transaction: cant' happen !!!!!!!"); break; + case GNC_EVENT_CREATE: + /* don't mirror transaction creations. If a register needs + * it, it will do a query. */ + PINFO ("create transaction"); + break; case GNC_EVENT_MODIFY: pgendCopyTransactionToEngine (be, &(ev->guid)); break; @@ -326,10 +338,15 @@ pgendProcessEvents (Backend *bend) break; default: - PERR ("unknown guid type %d", obj_type); + PERR ("unknown guid type %d", ev->obj_type); } - gnc_engine_generate_event (&(ev->guid), ev->type); + /* get the local type again, since we created guid above */ + local_obj_type = xaccGUIDType (&(ev->guid)); + if (GNC_ID_NONE != local_obj_type) + { + gnc_engine_generate_event (&(ev->guid), local_obj_type); + } g_free (ev); } @@ -385,6 +402,7 @@ get_latest_cb (PGBackend *be, PGresult *result, int j, gpointer data) /* get event timestamp */ latest = gnc_iso8601_to_timespec_local (DB_GET_VAL("date_changed",j)); + latest.tv_sec ++; /* ignore old, pre-logon events */ be->last_account = latest; be->last_price = latest;