[Gnucash-changes] r13390 - gnucash/trunk/lib/libqof/qof - Implement QOF_COMMIT_EDIT_PART2 as a function instead of a macro.

Chris Shoemaker chris at cvs.gnucash.org
Sat Feb 25 23:56:48 EST 2006


Author: chris
Date: 2006-02-25 23:56:47 -0500 (Sat, 25 Feb 2006)
New Revision: 13390
Trac: http://svn.gnucash.org/trac/changeset/13390

Modified:
   gnucash/trunk/lib/libqof/qof/qof-be-utils.h
   gnucash/trunk/lib/libqof/qof/qofbackend.c
Log:
   Implement QOF_COMMIT_EDIT_PART2 as a function instead of a macro.
   Any of the callbacks passed to this function may be NULL to decline the 
   use of that callback.  Also, the three callbacks are now called in three
   mutually exclusive cases, corresponding to: 
      1) a failed commit, ('on_error')
      2) a successful commit where the object remains valid, ('on_done'), and 
      3) a successful commit where the object has been destroyed, ('on_free').


Modified: gnucash/trunk/lib/libqof/qof/qof-be-utils.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qof-be-utils.h	2006-02-26 03:30:02 UTC (rev 13389)
+++ gnucash/trunk/lib/libqof/qof/qof-be-utils.h	2006-02-26 04:56:47 UTC (rev 13390)
@@ -138,51 +138,28 @@
  * @param inst: an instance of QofInstance
  * @param on_error: a function called if there is a backend error.
  *                void (*on_error)(inst, QofBackendError)
- * @param on_done: a function called after the commit is complete 
- *                but before the instect is freed. Perform any other 
- *                operations after the commit.
+ * @param on_done: a function called after the commit is completed 
+ *                successfully for an object which remained valid.
  *                void (*on_done)(inst)
- * @param on_free: a function called if inst->do_free is TRUE. 
+ * @param on_free: a function called if the commit succeeded and the instance
+ *                 is to be freed. 
  *                void (*on_free)(inst)
+ * 
+ * Note that only *one* callback will be called (or zero, if that
+ * callback is NULL).  In particular, 'on_done' will not be called for
+ * an object which is to be freed.
+ *
+ * Returns TRUE, if the commit succeeded, FALSE otherwise.
  */
-#define QOF_COMMIT_EDIT_PART2(inst,on_error,on_done,on_free) {   \
-  QofBackend * be;                                               \
-                                                                 \
-  /* See if there's a backend.  If there is, invoke it. */       \
-  be = qof_book_get_backend ((inst)->book);                      \
-  if (be && qof_backend_commit_exists(be))                       \
-  {                                                              \
-    QofBackendError errcode;                                     \
-                                                                 \
-    /* clear errors */                                           \
-    do {                                                         \
-      errcode = qof_backend_get_error (be);                      \
-    } while (ERR_BACKEND_NO_ERR != errcode);                     \
-                                                                 \
-    qof_backend_run_commit(be, (inst));                          \
-    errcode = qof_backend_get_error (be);                        \
-    if (ERR_BACKEND_NO_ERR != errcode)                           \
-    {                                                            \
-      /* XXX Should perform a rollback here */                   \
-      (inst)->do_free = FALSE;                                   \
-                                                                 \
-      /* Push error back onto the stack */                       \
-      qof_backend_set_error (be, errcode);                       \
-      (on_error)((inst), errcode);                               \
-    }                                                            \
-    /* XXX the backend commit code should clear dirty!! */       \
-    (inst)->dirty = FALSE;                                       \
-  }                                                              \
-  (on_done)(inst);                                               \
-                                                                 \
-  LEAVE ("inst=%p, dirty=%d do-free=%d",                         \
-            (inst), (inst)->dirty, (inst)->do_free);             \
-  if ((inst)->do_free) {                                         \
-     (on_free)(inst);                                            \
-     return;                                                     \
-  }                                                              \
-}
+gboolean
+qof_commit_edit_part2(QofInstance *inst, 
+                      void (*on_error)(QofInstance *, QofBackendError), 
+                      void (*on_done)(QofInstance *), 
+                      void (*on_free)(QofInstance *));
 
+#define QOF_COMMIT_EDIT_PART2(inst, on_error, on_done, on_free)         \
+    qof_commit_edit_part2((inst), (on_error), (on_done), (on_free))
+
 #endif /* QOF_BE_UTILS_H */
 /** @} */
 /** @} */

Modified: gnucash/trunk/lib/libqof/qof/qofbackend.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbackend.c	2006-02-26 03:30:02 UTC (rev 13389)
+++ gnucash/trunk/lib/libqof/qof/qofbackend.c	2006-02-26 04:56:47 UTC (rev 13390)
@@ -382,7 +382,51 @@
   return TRUE;
 }
 
+
 gboolean
+qof_commit_edit_part2(QofInstance *inst, 
+                      void (*on_error)(QofInstance *, QofBackendError), 
+                      void (*on_done)(QofInstance *), 
+                      void (*on_free)(QofInstance *)) 
+{
+    QofBackend * be;
+
+    /* See if there's a backend.  If there is, invoke it. */
+    be = qof_book_get_backend(inst->book);
+    if (be && qof_backend_commit_exists(be)) {
+        QofBackendError errcode;
+        
+        /* clear errors */
+        do {
+            errcode = qof_backend_get_error(be);
+        } while (ERR_BACKEND_NO_ERR != errcode);
+
+        qof_backend_run_commit(be, inst);
+        errcode = qof_backend_get_error(be);
+        if (ERR_BACKEND_NO_ERR != errcode) {
+            /* XXX Should perform a rollback here */
+            inst->do_free = FALSE;
+
+            /* Push error back onto the stack */
+            qof_backend_set_error (be, errcode);
+            if (on_error)
+                on_error(inst, errcode);
+            return FALSE;
+        }   
+        /* XXX the backend commit code should clear dirty!! */
+        inst->dirty = FALSE;
+    }
+    if (inst->do_free) {
+        if (on_free)
+            on_free(inst);
+        return TRUE;
+    }
+    if (on_done)
+        on_done(inst);
+    return TRUE;
+}
+
+gboolean
 qof_load_backend_library (const char *directory, 
 				const char* filename, const char* init_fcn)
 {



More information about the gnucash-changes mailing list