[Gnucash-changes] r13926 - gnucash/trunk - Add an alternate mode for handling the dirty state of instances and

David Hampton hampton at cvs.gnucash.org
Sat May 6 02:01:16 EDT 2006


Author: hampton
Date: 2006-05-06 02:01:14 -0400 (Sat, 06 May 2006)
New Revision: 13926
Trac: http://svn.gnucash.org/trac/changeset/13926

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/lib/libqof/qof/qofbook.c
   gnucash/trunk/lib/libqof/qof/qofbook.h
   gnucash/trunk/lib/libqof/qof/qofid-p.h
   gnucash/trunk/lib/libqof/qof/qofid.c
   gnucash/trunk/lib/libqof/qof/qofid.h
   gnucash/trunk/lib/libqof/qof/qofinstance.c
   gnucash/trunk/lib/libqof/qof/qofinstance.h
   gnucash/trunk/lib/libqof/qof/qofutil.c
Log:
Add an alternate mode for handling the dirty state of instances and
collections.  In this mode, marking an instance as dirty does not
immediately mark the collection as dirty.  The collection is only
dirtied when a dirty instance is actually committed to the collection.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/ChangeLog	2006-05-06 06:01:14 UTC (rev 13926)
@@ -1,3 +1,16 @@
+2006-05-06  David Hampton  <hampton at employees.org>
+
+	* lib/libqof/qof/qofbook.[ch]:
+	* lib/libqof/qof/qofid-p.h:
+	* lib/libqof/qof/qofinstance.[ch]:
+	* lib/libqof/qof/qofid.[ch]:
+	* lib/libqof/qof/qofutil.c: Add an alternate mode for handling the
+	dirty state of instances and collections.  In this mode, marking
+	an instance as dirty does not immediately mark the collection as
+	dirty.  The collection is only dirtied when a dirty instance is
+	actually committed to the collection.  Also add some debugging
+	functions.
+
 2006-05-05  David Hampton  <hampton at employees.org>
 
 	* configure.in: Bump the version number for setting the

Modified: gnucash/trunk/lib/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbook.c	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofbook.c	2006-05-06 06:01:14 UTC (rev 13926)
@@ -145,7 +145,7 @@
 /* ====================================================================== */
 
 gboolean
-qof_book_not_saved(QofBook *book)
+qof_book_not_saved (QofBook *book)
 {
   if (!book) return FALSE;
 
@@ -153,7 +153,7 @@
 }
 
 void
-qof_book_mark_saved(QofBook *book)
+qof_book_mark_saved (QofBook *book)
 {
   if (!book) return;
 
@@ -161,6 +161,14 @@
   qof_object_mark_clean (book);
 }
 
+void
+qof_book_print_dirty (QofBook *book)
+{
+  if (book->inst.dirty)
+    printf("book is dirty.\n");
+  qof_book_foreach_collection(book, qof_collection_print_dirty, NULL);
+}
+
 /* ====================================================================== */
 /* getters */
 

Modified: gnucash/trunk/lib/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbook.h	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofbook.h	2006-05-06 06:01:14 UTC (rev 13926)
@@ -154,6 +154,7 @@
  *    by the frontend when the used has said to abandon any changes.
  */
 void qof_book_mark_saved(QofBook *book);
+void qof_book_print_dirty (QofBook *book);
 
 /** Call this function when you change the book kvp, to make sure the book
  * is marked 'dirty'. */

Modified: gnucash/trunk/lib/libqof/qof/qofid-p.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid-p.h	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofid-p.h	2006-05-06 06:01:14 UTC (rev 13926)
@@ -49,6 +49,7 @@
 /** reset value of dirty flag */
 void qof_collection_mark_clean (QofCollection *);
 void qof_collection_mark_dirty (QofCollection *);
+void qof_collection_print_dirty (QofCollection *col, gpointer dummy);
 
 /* @} */
 /* @} */

Modified: gnucash/trunk/lib/libqof/qof/qofid.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid.c	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofid.c	2006-05-06 06:01:14 UTC (rev 13926)
@@ -31,6 +31,7 @@
 #include "qofid-p.h"
 
 static QofLogModule log_module = QOF_MOD_ENGINE;
+static gboolean qof_alt_dirty_mode = FALSE;
 
 struct QofCollection_s
 {
@@ -43,6 +44,20 @@
 
 /* =============================================================== */
 
+gboolean
+qof_get_alt_dirty_mode (void)
+{
+  return qof_alt_dirty_mode;
+}
+
+void
+qof_set_alt_dirty_mode (gboolean enabled)
+{
+  qof_alt_dirty_mode = enabled;
+}
+
+/* =============================================================== */
+
 static void qof_collection_remove_entity (QofEntity *ent);
 
 void
@@ -182,7 +197,8 @@
   col = ent->collection;
   if (!col) return;
   g_hash_table_remove (col->hash_of_entities, &ent->guid);
-  qof_collection_mark_dirty(col);
+  if (!qof_alt_dirty_mode)
+    qof_collection_mark_dirty(col);
   ent->collection = NULL;
 }
 
@@ -194,7 +210,8 @@
   g_return_if_fail (col->e_type == ent->e_type);
   qof_collection_remove_entity (ent);
   g_hash_table_insert (col->hash_of_entities, &ent->guid, ent);
-  qof_collection_mark_dirty(col);
+  if (!qof_alt_dirty_mode)
+    qof_collection_mark_dirty(col);
   ent->collection = col;
 }
 
@@ -210,7 +227,8 @@
 	e = qof_collection_lookup_entity(coll, &ent->guid);
 	if ( e != NULL ) { return FALSE; }
 	g_hash_table_insert (coll->hash_of_entities, &ent->guid, ent);
-	qof_collection_mark_dirty(coll);
+	if (!qof_alt_dirty_mode)
+	  qof_collection_mark_dirty(coll);
 	return TRUE;
 }
 
@@ -342,6 +360,14 @@
    if (col) { col->is_dirty = TRUE; }
 }
 
+void
+qof_collection_print_dirty (QofCollection *col, gpointer dummy)
+{
+  if (col->is_dirty)
+    printf("%s collection is dirty.\n", col->e_type);
+  qof_collection_foreach(col, qof_instance_print_dirty, NULL);
+}
+
 /* =============================================================== */
 
 gpointer 

Modified: gnucash/trunk/lib/libqof/qof/qofid.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofid.h	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofid.h	2006-05-06 06:01:14 UTC (rev 13926)
@@ -160,6 +160,23 @@
 void qof_entity_release (QofEntity *);
 /** @} */
 
+/** Is QOF operating in "alternate" dirty mode.  In normal mode,
+ *  whenever an instance is dirtied, the collection (and therefore the
+ *  book) is immediately marked as dirty.  In alternate mode, the
+ *  collection is only marked dirty when a dirty instance is
+ *  committed.  If a dirty instance is freed instead of committed, the
+ *  dirty state of collection (and therefore the book) is never
+ *  changed. */
+gboolean qof_get_alt_dirty_mode (void);
+
+/** Set QOF into "alternate" dirty mode.  In normal mode, whenever an
+ *  instance is dirtied, the collection (and therefore the book) is
+ *  immediately marked as dirty.  In alternate mode, the collection is
+ *  only marked dirty when a dirty instance is committed.  If a dirty
+ *  instance is freed instead of committed, the dirty state of
+ *  collection (and therefore the book) is never changed. */
+void qof_set_alt_dirty_mode (gboolean enabled);
+
 /** Return the GUID of this entity */
 const GUID * qof_entity_get_guid (QofEntity *);
 

Modified: gnucash/trunk/lib/libqof/qof/qofinstance.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.c	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.c	2006-05-06 06:01:14 UTC (rev 13926)
@@ -121,12 +121,24 @@
 	return 0;
 }
 
+void
+qof_instance_print_dirty (QofEntity *entity, gpointer dummy)
+{
+  QofInstance *inst = QOF_INSTANCE(entity);
+
+  if (inst->dirty)
+    printf("%s instance %s is dirty.\n", inst->entity.e_type,
+	   guid_to_string(&inst->entity.guid));
+}
+
 gboolean
 qof_instance_is_dirty (QofInstance *inst)
 {
 	QofCollection *coll;
 
 	if (!inst) { return FALSE; }
+	if (qof_get_alt_dirty_mode())
+	  return inst->dirty;
 	coll = inst->entity.collection;
 	if(qof_collection_is_dirty(coll)) { return inst->dirty; }
 	inst->dirty = FALSE;
@@ -139,8 +151,10 @@
 	QofCollection *coll;
 
 	inst->dirty = TRUE;
-	coll = inst->entity.collection;
-	qof_collection_mark_dirty(coll);
+	if (!qof_get_alt_dirty_mode()) {
+	  coll = inst->entity.collection;
+	  qof_collection_mark_dirty(coll);
+	}
 }
 
 gboolean

Modified: gnucash/trunk/lib/libqof/qof/qofinstance.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofinstance.h	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofinstance.h	2006-05-06 06:01:14 UTC (rev 13926)
@@ -81,6 +81,8 @@
  */
 int qof_instance_version_cmp (QofInstance *left, QofInstance *right);
 
+void qof_instance_print_dirty (QofEntity *entity, gpointer dummy);
+
 /** Return value of is_dirty flag */
 gboolean qof_instance_is_dirty (QofInstance *);
 

Modified: gnucash/trunk/lib/libqof/qof/qofutil.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofutil.c	2006-05-06 01:27:40 UTC (rev 13925)
+++ gnucash/trunk/lib/libqof/qof/qofutil.c	2006-05-06 06:01:14 UTC (rev 13926)
@@ -269,6 +269,7 @@
                       void (*on_free)(QofInstance *)) 
 {
     QofBackend * be;
+    gboolean dirty = inst->dirty;
 
     /* See if there's a backend.  If there is, invoke it. */
     be = qof_book_get_backend(inst->book);
@@ -300,6 +301,9 @@
             on_free(inst);
         return TRUE;
     }
+
+    if (dirty && qof_get_alt_dirty_mode())
+      qof_collection_mark_dirty(inst->entity.collection);
     if (on_done)
         on_done(inst);
     return TRUE;



More information about the gnucash-changes mailing list