diff --git a/src/business/business-core/file/gnc-job-xml-v2.c b/src/business/business-core/file/gnc-job-xml-v2.c index 60cf9786ab..c384478107 100644 --- a/src/business/business-core/file/gnc-job-xml-v2.c +++ b/src/business/business-core/file/gnc-job-xml-v2.c @@ -46,7 +46,8 @@ #include "gnc-owner-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" +#include "qofobject.h" +#include "xml-helpers.h" #define _GNC_MOD_NAME GNC_JOB_MODULE_NAME @@ -64,13 +65,6 @@ const gchar *job_version_string = "2.0.0"; #define job_active_string "job:active" #define job_slots_string "job:slots" -static void -maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) -{ - if (str && strlen(str) > 0) - xmlAddChild (ptr, text_to_dom_tree (tag, str)); -} - static xmlNodePtr job_dom_tree_create (GncJob *job) { @@ -80,7 +74,7 @@ job_dom_tree_create (GncJob *job) xmlSetProp(ret, "version", job_version_string); xmlAddChild(ret, guid_to_dom_tree(job_guid_string, - gncJobGetGUID (job))); + qof_instance_get_guid (QOF_INSTANCE (job)))); xmlAddChild(ret, text_to_dom_tree(job_id_string, gncJobGetID (job))); @@ -308,7 +302,7 @@ static int job_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } @@ -331,7 +325,7 @@ xml_add_job (gpointer job_p, gpointer out_p) static void job_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out); } void @@ -347,7 +341,7 @@ gnc_job_xml_initialize (void) NULL, /* scrub */ }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/gncJob.c b/src/business/business-core/gncJob.c index 68f931583d..fbc48550de 100644 --- a/src/business/business-core/gncJob.c +++ b/src/business/business-core/gncJob.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncJob.c -- the Core Job Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncJob.c -- the Core Job Interface * Copyright (C) 2001, 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -14,52 +36,60 @@ #include "gnc-engine-util.h" #include "gnc-numeric.h" #include "gnc-book.h" -#include "qofid.h" -#include "qofquerycore.h" -#include "qofquery.h" -#include "qofclass.h" #include "gnc-event-p.h" #include "gnc-be-utils.h" + +#include "qofclass.h" +#include "qofinstance.h" +#include "qofid.h" #include "qofid-p.h" +#include "qofquerycore.h" +#include "qofquery.h" #include "gncBusiness.h" #include "gncJob.h" #include "gncJobP.h" -struct _gncJob { - QofBook * book; - GUID guid; - char * id; - char * name; - char * desc; - GncOwner owner; - gboolean active; - - int editlevel; - gboolean do_free; - gboolean dirty; +struct _gncJob +{ + QofInstance inst; + char * id; + char * name; + char * desc; + GncOwner owner; + gboolean active; }; -static short module = MOD_BUSINESS; +static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_JOB_MODULE_NAME +#define _GNC_MOD_NAME GNC_JOB_MODULE_NAME + +/* ================================================================== */ +/* misc inline functions */ #define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); #define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); -static void addObj (GncJob *job); -static void remObj (GncJob *job); - G_INLINE_FUNC void mark_job (GncJob *job); G_INLINE_FUNC void mark_job (GncJob *job) { - job->dirty = TRUE; - gncBusinessSetDirtyFlag (job->book, _GNC_MOD_NAME, TRUE); + job->inst.dirty = TRUE; + gncBusinessSetDirtyFlag (job->inst.book, _GNC_MOD_NAME, TRUE); + gnc_engine_generate_event (&job->inst.guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); +} + +static inline void addObj (GncJob *job) +{ + gncBusinessAddObject (job->inst.book, _GNC_MOD_NAME, job, &job->inst.guid); +} - gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); +static inline void remObj (GncJob *job) +{ + gncBusinessRemoveObject (job->inst.book, _GNC_MOD_NAME, &job->inst.guid); } +/* ================================================================== */ /* Create/Destroy Functions */ GncJob *gncJobCreate (QofBook *book) @@ -69,18 +99,15 @@ GncJob *gncJobCreate (QofBook *book) if (!book) return NULL; job = g_new0 (GncJob, 1); - job->book = book; - job->dirty = FALSE; + qof_instance_init (&job->inst, book); job->id = CACHE_INSERT (""); job->name = CACHE_INSERT (""); job->desc = CACHE_INSERT (""); job->active = TRUE; - qof_entity_guid_new (qof_book_get_entity_table (book), &job->guid); addObj (job); - - gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_generate_event (&job->inst.guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); return job; } @@ -88,7 +115,7 @@ GncJob *gncJobCreate (QofBook *book) void gncJobDestroy (GncJob *job) { if (!job) return; - job->do_free = TRUE; + job->inst.do_free = TRUE; gncJobCommitEdit (job); } @@ -96,7 +123,7 @@ static void gncJobFree (GncJob *job) { if (!job) return; - gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_generate_event (&job->inst.guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); CACHE_REMOVE (job->id); CACHE_REMOVE (job->name); @@ -114,21 +141,23 @@ static void gncJobFree (GncJob *job) } remObj (job); + qof_instance_release (&job->inst); g_free (job); } +/* ================================================================== */ /* Set Functions */ #define SET_STR(obj, member, str) { \ - char * tmp; \ - \ - if (!safe_strcmp (member, str)) return; \ - gncJobBeginEdit (obj); \ - tmp = CACHE_INSERT (str); \ - CACHE_REMOVE (member); \ - member = tmp; \ - } + char * tmp; \ + \ + if (!safe_strcmp (member, str)) return; \ + gncJobBeginEdit (obj); \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } void gncJobSetID (GncJob *job, const char *id) { @@ -160,11 +189,11 @@ void gncJobSetReference (GncJob *job, const char *desc) void gncJobSetGUID (GncJob *job, const GUID *guid) { if (!job || !guid) return; - if (guid_equal (guid, &job->guid)) return; + if (guid_equal (guid, &job->inst.guid)) return; gncJobBeginEdit (job); remObj (job); - job->guid = *guid; + job->inst.guid = *guid; addObj (job); gncJobCommitEdit (job); } @@ -218,34 +247,32 @@ void gncJobSetActive (GncJob *job, gboolean active) void gncJobBeginEdit (GncJob *job) { - GNC_BEGIN_EDIT (job, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&job->inst, _GNC_MOD_NAME); } -static void gncJobOnError (GncJob *job, QofBackendError errcode) +static void gncJobOnError (QofInstance *inst, QofBackendError errcode) { PERR("Job QofBackend Failure: %d", errcode); } -static void gncJobOnDone (GncJob *job) +static inline void job_free (QofInstance *inst) { - job->dirty = FALSE; + GncJob *job = (GncJob *)inst; + gncJobFree (job); } +static inline void gncJobOnDone (QofInstance *qof) { } + void gncJobCommitEdit (GncJob *job) { - GNC_COMMIT_EDIT_PART1 (job); - GNC_COMMIT_EDIT_PART2 (job, _GNC_MOD_NAME, gncJobOnError, - gncJobOnDone, gncJobFree); + GNC_COMMIT_EDIT_PART1 (&job->inst); + GNC_COMMIT_EDIT_PART2 (&job->inst, _GNC_MOD_NAME, gncJobOnError, + gncJobOnDone, job_free); } +/* ================================================================== */ /* Get Functions */ -QofBook * gncJobGetBook (GncJob *job) -{ - if (!job) return NULL; - return job->book; -} - const char * gncJobGetID (GncJob *job) { if (!job) return NULL; @@ -270,15 +297,9 @@ GncOwner * gncJobGetOwner (GncJob *job) return &(job->owner); } -const GUID * gncJobGetGUID (GncJob *job) -{ - if (!job) return NULL; - return &job->guid; -} - GUID gncJobRetGUID (GncJob *job) { - const GUID *guid = gncJobGetGUID (job); + const GUID *guid = qof_instance_get_guid (&job->inst); if (guid) return *guid; return *guid_null (); @@ -294,7 +315,7 @@ GncJob * gncJobLookup (QofBook *book, const GUID *guid) { if (!book || !guid) return NULL; return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); + guid, _GNC_MOD_NAME); } GncJob * gncJobLookupDirect (GUID guid, QofBook *book) @@ -303,12 +324,6 @@ GncJob * gncJobLookupDirect (GUID guid, QofBook *book) return gncJobLookup (book, &guid); } -gboolean gncJobIsDirty (GncJob *job) -{ - if (!job) return FALSE; - return job->dirty; -} - /* Other functions */ int gncJobCompare (const GncJob * a, const GncJob *b) { @@ -319,19 +334,9 @@ int gncJobCompare (const GncJob * a, const GncJob *b) { return (safe_strcmp(a->id, b->id)); } - +/* ================================================================== */ /* Package-Private functions */ -static void addObj (GncJob *job) -{ - gncBusinessAddObject (job->book, _GNC_MOD_NAME, job, &job->guid); -} - -static void remObj (GncJob *job) -{ - gncBusinessRemoveObject (job->book, _GNC_MOD_NAME, &job->guid); -} - static void _gncJobCreate (QofBook *book) { gncBusinessCreate (book, _GNC_MOD_NAME); @@ -353,7 +358,7 @@ static void _gncJobMarkClean (QofBook *book) } static void _gncJobForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) + gpointer user_data) { gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); } @@ -385,12 +390,12 @@ gboolean gncJobRegister (void) static QofParam params[] = { { JOB_ID, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetID, NULL }, { JOB_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetName, NULL }, + { JOB_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL }, { JOB_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetReference, NULL }, { JOB_OWNER, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncJobGetOwner, NULL }, - { JOB_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL }, - { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)gncJobGetBook, NULL }, - { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)gncJobGetGUID, NULL }, { QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; diff --git a/src/business/business-core/gncJob.h b/src/business/business-core/gncJob.h index 3b7fcce2c2..14dbefa9c6 100644 --- a/src/business/business-core/gncJob.h +++ b/src/business/business-core/gncJob.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncJob.h -- the Core Job Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncJob.h -- the Core Job Interface * Copyright (C) 2001, 2002 Derek Atkins * Author: Derek Atkins */ @@ -32,8 +53,6 @@ void gncJobCommitEdit (GncJob *job); /* Get Functions */ -QofBook * gncJobGetBook (GncJob *job); -const GUID * gncJobGetGUID (GncJob *job); const char * gncJobGetID (GncJob *job); const char * gncJobGetName (GncJob *job); const char * gncJobGetReference (GncJob *job); @@ -56,4 +75,8 @@ int gncJobCompare (const GncJob *a, const GncJob *b); #define JOB_OWNER "owner" #define JOB_ACTIVE "active" +/** deprecated functions */ +#define gncJobGetBook(x) qof_instance_get_book(QOF_INSTANCE(x)) +#define gncJobGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x)) + #endif /* GNC_JOB_H_ */ diff --git a/src/business/business-core/gncJobP.h b/src/business/business-core/gncJobP.h index 0fe7a5360f..897fa0f546 100644 --- a/src/business/business-core/gncJobP.h +++ b/src/business/business-core/gncJobP.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncJobP.h -- the Core Job Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncJobP.h -- the Core Job Interface * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ diff --git a/src/business/business-core/gncOwner.c b/src/business/business-core/gncOwner.c index f0e5a8aad6..450f0603a6 100644 --- a/src/business/business-core/gncOwner.c +++ b/src/business/business-core/gncOwner.c @@ -176,7 +176,7 @@ const GUID * gncOwnerGetGUID (GncOwner *owner) case GNC_OWNER_CUSTOMER: return qof_instance_get_guid (QOF_INSTANCE(owner->owner.customer)); case GNC_OWNER_JOB: - return gncJobGetGUID (owner->owner.job); + return qof_instance_get_guid (QOF_INSTANCE(owner->owner.job)); case GNC_OWNER_VENDOR: return gncVendorGetGUID (owner->owner.vendor); case GNC_OWNER_EMPLOYEE: diff --git a/src/business/business-core/test/test-job.c b/src/business/business-core/test/test-job.c index ea40391d2e..ee90d84a94 100644 --- a/src/business/business-core/test/test-job.c +++ b/src/business/business-core/test/test-job.c @@ -49,7 +49,7 @@ test_job (void) do_test (gncJobCreate (NULL) == NULL, "job create NULL"); job = gncJobCreate (book); do_test (job != NULL, "job create"); - do_test (gncJobGetBook (job) == book, + do_test (qof_instance_get_book(QOF_INSTANCE(job)) == book, "getbook"); gncJobBeginEdit (job); @@ -70,7 +70,7 @@ test_job (void) guid_new (&guid); job = gncJobCreate (book); count++; gncJobSetGUID (job, &guid); - do_test (guid_equal (&guid, gncJobGetGUID (job)), "guid compare"); + do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(job))), "guid compare"); } #if 0 { @@ -129,12 +129,12 @@ test_string_fcn (GNCBook *book, const char *message, GncJob *job = gncJobCreate (book); char const *str = get_random_string (); - do_test (!gncJobIsDirty (job), "test if start dirty"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty"); gncJobBeginEdit (job); set (job, str); - do_test (gncJobIsDirty (job), "test dirty later"); + do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later"); gncJobCommitEdit (job); - do_test (!gncJobIsDirty (job), "test dirty after commit"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit"); do_test (safe_strcmp (get (job), str) == 0, message); gncJobSetActive (job, FALSE); count++; } @@ -148,12 +148,12 @@ test_numeric_fcn (GNCBook *book, const char *message, GncJob *job = gncJobCreate (book); gnc_numeric num = gnc_numeric_create (17, 1); - do_test (!gncJobIsDirty (job), "test if start dirty"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty"); gncJobBeginEdit (job); set (job, num); - do_test (gncJobIsDirty (job), "test dirty later"); + do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later"); gncJobCommitEdit (job); - do_test (!gncJobIsDirty (job), "test dirty after commit"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit"); do_test (gnc_numeric_equal (get (job), num), message); gncJobSetActive (job, FALSE); count++; } @@ -167,14 +167,14 @@ test_bool_fcn (GNCBook *book, const char *message, GncJob *job = gncJobCreate (book); gboolean num = get_random_boolean (); - do_test (!gncJobIsDirty (job), "test if start dirty"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty"); gncJobBeginEdit (job); set (job, FALSE); set (job, TRUE); set (job, num); - do_test (gncJobIsDirty (job), "test dirty later"); + do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later"); gncJobCommitEdit (job); - do_test (!gncJobIsDirty (job), "test dirty after commit"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit"); do_test (get (job) == num, message); gncJobSetActive (job, FALSE); count++; } @@ -188,12 +188,12 @@ test_gint_fcn (GNCBook *book, const char *message, GncJob *job = gncJobCreate (book); gint num = 17; - do_test (!gncJobIsDirty (job), "test if start dirty"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty"); gncJobBeginEdit (job); set (job, num); - do_test (gncJobIsDirty (job), "test dirty later"); + do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later"); gncJobCommitEdit (job); - do_test (!gncJobIsDirty (job), "test dirty after commit"); + do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit"); do_test (get (job) == num, message); gncJobSetActive (job, FALSE); count++; }