00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00035 #ifndef QOF_BE_UTILS_H
00036 #define QOF_BE_UTILS_H
00037
00038 #include "gnc-trace.h"
00039 #include "gnc-engine-util.h"
00040 #include "qofbackend-p.h"
00041 #include "qofbook.h"
00042 #include "qofinstance.h"
00043
00054 #define QOF_BEGIN_EDIT(inst) \
00055 QofBackend * be; \
00056 if (!(inst)) return; \
00057 \
00058 (inst)->editlevel++; \
00059 if (1 < (inst)->editlevel) return; \
00060 \
00061 if (0 >= (inst)->editlevel) \
00062 { \
00063 PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
00064 (inst)->editlevel = 1; \
00065 } \
00066 ENTER ("(inst=%p)", (inst)); \
00067 \
00068 \
00069 be = qof_book_get_backend ((inst)->book); \
00070 if (be && qof_backend_begin_exists((be))) { \
00071 qof_backend_run_begin((be), (inst)); \
00072 } else { \
00073 \
00074 (inst)->dirty = TRUE; \
00075 } \
00076 LEAVE (" ");
00077
00083 gboolean qof_begin_edit(QofInstance *inst);
00084
00099 #define QOF_COMMIT_EDIT_PART1(inst) { \
00100 if (!(inst)) return; \
00101 \
00102 (inst)->editlevel--; \
00103 if (0 < (inst)->editlevel) return; \
00104 \
00105 \
00106 \
00107 \
00108 if ((-1 == (inst)->editlevel) && (inst)->dirty) \
00109 { \
00110 QofBackend * be; \
00111 be = qof_book_get_backend ((inst)->book); \
00112 if (be && qof_backend_begin_exists((be))) { \
00113 qof_backend_run_begin((be), (inst)); \
00114 } \
00115 (inst)->editlevel = 0; \
00116 } \
00117 if (0 > (inst)->editlevel) \
00118 { \
00119 PERR ("unbalanced call - resetting (was %d)", (inst)->editlevel); \
00120 (inst)->editlevel = 0; \
00121 } \
00122 ENTER ("(inst=%p) dirty=%d do-free=%d", \
00123 (inst), (inst)->dirty, (inst)->do_free); \
00124 }
00125
00131 gboolean qof_commit_edit(QofInstance *inst);
00132
00146 #define QOF_COMMIT_EDIT_PART2(inst,on_error,on_done,on_free) { \
00147 QofBackend * be; \
00148 \
00149 \
00150 be = qof_book_get_backend ((inst)->book); \
00151 if (be && qof_backend_commit_exists((be))) \
00152 { \
00153 QofBackendError errcode; \
00154 \
00155 \
00156 do { \
00157 errcode = qof_backend_get_error (be); \
00158 } while (ERR_BACKEND_NO_ERR != errcode); \
00159 \
00160 qof_backend_run_commit((be), (inst)); \
00161 errcode = qof_backend_get_error (be); \
00162 if (ERR_BACKEND_NO_ERR != errcode) \
00163 { \
00164 \
00165 (inst)->do_free = FALSE; \
00166 \
00167 \
00168 qof_backend_set_error (be, errcode); \
00169 (on_error)((inst), errcode); \
00170 } \
00171 \
00172 (inst)->dirty = FALSE; \
00173 } \
00174 (on_done)(inst); \
00175 \
00176 LEAVE ("inst=%p, dirty=%d do-free=%d", \
00177 (inst), (inst)->dirty, (inst)->do_free); \
00178 if ((inst)->do_free) { \
00179 (on_free)(inst); \
00180 return; \
00181 } \
00182 }
00183
00184 #endif
00185