First step of QOF/Object GObjectification.

- Merge QofEntity into QofInstance
- Derive QofInstance from GObject
- Convert all QofInstance-derived objects to use GObject framework
- renamed qof_instance_init() to qof_instance_init_data()
- removed qof_instance_release() because it's no longer needed

Merge from branches/gobject-engine-dev-warlord  (r15827)


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15846 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2007-04-07 16:02:27 +00:00
157 changed files with 2277 additions and 1202 deletions

View File

@@ -80,7 +80,7 @@ in the QSF QofBackend to contain the reference data so that when the book is
written out, the reference can be included. When the file is imported back in, a
little extra code then rebuilds those references during the merge.
Copying entites from an existing QofBook using the qof_entity_copy routines will
Copying entites from an existing QofBook using the qof_instance_copy routines will
automatically create the reference table. If your QOF objects use references to other
entities, books that are created manually also need to create a reference table.

View File

@@ -295,12 +295,12 @@ qsf_destroy_backend (QofBackend *be)
}
static void
ent_ref_cb (QofEntity* ent, gpointer user_data)
ent_ref_cb (QofInstance* ent, gpointer user_data)
{
qsf_param *params;
QofEntityReference *ref;
void (*reference_setter) (QofEntity*, QofEntity*);
QofEntity *reference;
QofInstanceReference *ref;
void (*reference_setter) (QofInstance*, QofInstance*);
QofInstance *reference;
QofCollection *coll;
QofIdType type;
@@ -308,12 +308,12 @@ ent_ref_cb (QofEntity* ent, gpointer user_data)
g_return_if_fail(params);
while(params->referenceList)
{
ref = (QofEntityReference*)params->referenceList->data;
ref = (QofInstanceReference*)params->referenceList->data;
if(qof_object_is_choice(ent->e_type)) { type = ref->choice_type; }
else { type = ref->type; }
coll = qof_book_get_collection(params->book, type);
reference = qof_collection_lookup_entity(coll, ref->ref_guid);
reference_setter = (void(*)(QofEntity*, QofEntity*))ref->param->param_setfcn;
reference_setter = (void(*)(QofInstance*, QofInstance*))ref->param->param_setfcn;
if(reference_setter != NULL)
{
qof_begin_edit((QofInstance*)ent);
@@ -337,7 +337,7 @@ insert_ref_cb(QofObject *obj, gpointer user_data)
}
/*================================================
Load QofEntity into QofBook from XML in memory
Load QofInstance into QofBook from XML in memory
==================================================*/
static gboolean
@@ -370,7 +370,7 @@ qsfdoc_to_qofbook(xmlDocPtr doc, qsf_param *params)
if(!qof_class_is_registered(params->object_set->object_type)) { continue; }
inst = (QofInstance*)qof_object_new_instance(params->object_set->object_type, book);
g_return_val_if_fail(inst != NULL, FALSE);
params->qsf_ent = &inst->entity;
params->qsf_ent = inst;
qof_begin_edit(inst);
g_hash_table_foreach(params->qsf_parameter_hash, qsf_object_commitCB, params);
qof_commit_edit(inst);
@@ -644,7 +644,7 @@ qsf_from_kvp_helper(const gchar *path, KvpValue *content, gpointer data)
}
static void
qsf_from_coll_cb (QofEntity *ent, gpointer user_data)
qsf_from_coll_cb (QofInstance *ent, gpointer user_data)
{
qsf_param *params;
QofParam *qof_param;
@@ -654,7 +654,7 @@ qsf_from_coll_cb (QofEntity *ent, gpointer user_data)
params = (qsf_param*)user_data;
if(!ent || !params) { return; }
qof_param = params->qof_param;
guid_to_string_buff(qof_entity_get_guid(ent), qsf_guid);
guid_to_string_buff(qof_instance_get_guid(ent), qsf_guid);
node = xmlAddChild(params->output_node, xmlNewNode(params->qsf_ns,
BAD_CAST qof_param->param_type));
xmlNodeAddContent(node, BAD_CAST qsf_guid);
@@ -666,11 +666,11 @@ qsf_from_coll_cb (QofEntity *ent, gpointer user_data)
static gint
qof_reference_list_cb(gconstpointer a, gconstpointer b)
{
const QofEntityReference *aa;
const QofEntityReference *bb;
const QofInstanceReference *aa;
const QofInstanceReference *bb;
aa = (QofEntityReference*) a;
bb = (QofEntityReference*) b;
aa = (QofInstanceReference*) a;
bb = (QofInstanceReference*) b;
if(aa == NULL) { return 1; }
g_return_val_if_fail((bb != NULL), 1);
g_return_val_if_fail((aa->type != NULL), 1);
@@ -683,11 +683,11 @@ qof_reference_list_cb(gconstpointer a, gconstpointer b)
return 1;
}
static QofEntityReference*
qof_reference_lookup(GList *referenceList, QofEntityReference *find)
static QofInstanceReference*
qof_reference_lookup(GList *referenceList, QofInstanceReference *find)
{
GList *single_ref;
QofEntityReference *ent_ref;
QofInstanceReference *ent_ref;
if(referenceList == NULL) { return NULL; }
g_return_val_if_fail(find != NULL, NULL);
@@ -695,7 +695,7 @@ qof_reference_lookup(GList *referenceList, QofEntityReference *find)
ent_ref = NULL;
single_ref = g_list_find_custom(referenceList, find, qof_reference_list_cb);
if(single_ref == NULL) { return ent_ref; }
ent_ref = (QofEntityReference*)single_ref->data;
ent_ref = (QofInstanceReference*)single_ref->data;
g_list_free(single_ref);
return ent_ref;
}
@@ -703,9 +703,9 @@ qof_reference_lookup(GList *referenceList, QofEntityReference *find)
static void
reference_list_lookup(gpointer data, gpointer user_data)
{
QofEntity *ent;
QofInstance *ent;
QofParam *ref_param;
QofEntityReference *reference, *starter;
QofInstanceReference *reference, *starter;
qsf_param *params;
const GUID *guid;
xmlNodePtr node, object_node;
@@ -718,8 +718,8 @@ reference_list_lookup(gpointer data, gpointer user_data)
object_node = params->output_node;
ent = params->qsf_ent;
ns = params->qsf_ns;
starter = g_new(QofEntityReference, 1);
starter->ent_guid = qof_entity_get_guid(ent);
starter = g_new(QofInstanceReference, 1);
starter->ent_guid = qof_instance_get_guid(ent);
starter->type = g_strdup(ent->e_type);
starter->param = ref_param;
starter->ref_guid = NULL;
@@ -739,13 +739,13 @@ reference_list_lookup(gpointer data, gpointer user_data)
g_free(ref_name);
}
else {
ent = (QofEntity*)ref_param->param_getfcn(ent, ref_param);
ent = QOF_INSTANCE(ref_param->param_getfcn(ent, ref_param));
if(!ent) { return; }
if((0 == safe_strcmp(ref_param->param_type, QOF_TYPE_COLLECT)) ||
(0 == safe_strcmp(ref_param->param_type, QOF_TYPE_CHOICE)))
{ return; }
node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
guid = qof_entity_get_guid(ent);
guid = qof_instance_get_guid(ent);
guid_to_string_buff(guid, qsf_guid);
xmlNodeAddContent(node, BAD_CAST qsf_guid);
xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ref_param->param_name);
@@ -753,11 +753,11 @@ reference_list_lookup(gpointer data, gpointer user_data)
}
/*=====================================
Convert QofEntity to QSF XML node
Convert QofInstance to QSF XML node
qof_param holds the parameter sequence.
=======================================*/
static void
qsf_entity_foreach(QofEntity *ent, gpointer data)
qsf_entity_foreach(QofInstance *ent, gpointer data)
{
qsf_param *params;
GSList *param_list, *supported;
@@ -766,7 +766,7 @@ qsf_entity_foreach(QofEntity *ent, gpointer data)
xmlNsPtr ns;
gchar *string_buffer;
QofParam *qof_param;
QofEntity *choice_ent;
QofInstance *choice_ent;
KvpFrame *qsf_kvp;
QofCollection *qsf_coll;
gint param_count;
@@ -795,7 +795,7 @@ qsf_entity_foreach(QofEntity *ent, gpointer data)
{
if(!own_guid)
{
cm_guid = qof_entity_get_guid(ent);
cm_guid = qof_instance_get_guid(ent);
node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST QOF_TYPE_GUID));
guid_to_string_buff(cm_guid, cm_sa);
string_buffer = g_strdup(cm_sa);
@@ -827,13 +827,13 @@ qsf_entity_foreach(QofEntity *ent, gpointer data)
if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_CHOICE))
{
/** \todo use the reference list here. */
choice_ent = (QofEntity*)qof_param->param_getfcn(ent, qof_param);
choice_ent = QOF_INSTANCE(qof_param->param_getfcn(ent, qof_param));
if(!choice_ent) {
param_list = g_slist_next(param_list);
continue;
}
node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST qof_param->param_type));
cm_guid = qof_entity_get_guid(choice_ent);
cm_guid = qof_instance_get_guid(choice_ent);
guid_to_string_buff(cm_guid, cm_sa);
string_buffer = g_strdup(cm_sa);
xmlNodeAddContent(node, BAD_CAST string_buffer);
@@ -1047,7 +1047,7 @@ string_to_kvp_value(const gchar *content, KvpValueType type)
}
/* ======================================================
Commit XML data from file to QofEntity in a QofBook
Commit XML data from file to QofInstance in a QofBook
========================================================= */
void
qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
@@ -1055,8 +1055,8 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
qsf_param *params;
qsf_objects *object_set;
xmlNodePtr node;
QofEntityReference *reference;
QofEntity *qsf_ent;
QofInstanceReference *reference;
QofInstance *qsf_ent;
QofBook *targetBook;
const char *qof_type, *parameter_name, *timechk;
QofIdType obj_type, reference_type;
@@ -1077,14 +1077,14 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
KvpValueType cm_type;
QofSetterFunc cm_setter;
const QofParam *cm_param;
void (*string_setter) (QofEntity*, const gchar*);
void (*date_setter) (QofEntity*, Timespec);
void (*numeric_setter) (QofEntity*, gnc_numeric);
void (*double_setter) (QofEntity*, double);
void (*boolean_setter) (QofEntity*, gboolean);
void (*i32_setter) (QofEntity*, gint32);
void (*i64_setter) (QofEntity*, gint64);
void (*char_setter) (QofEntity*, gchar);
void (*string_setter) (QofInstance*, const gchar*);
void (*date_setter) (QofInstance*, Timespec);
void (*numeric_setter) (QofInstance*, gnc_numeric);
void (*double_setter) (QofInstance*, double);
void (*boolean_setter) (QofInstance*, gboolean);
void (*i32_setter) (QofInstance*, gint32);
void (*i64_setter) (QofInstance*, gint64);
void (*char_setter) (QofInstance*, gchar);
g_return_if_fail(data && value && key);
params = (qsf_param*)data;
@@ -1102,11 +1102,11 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
cm_param = qof_class_get_parameter(obj_type, parameter_name);
object_set = params->object_set;
if(safe_strcmp(qof_type, QOF_TYPE_STRING) == 0) {
string_setter = (void(*)(QofEntity*, const gchar*))cm_setter;
string_setter = (void(*)(QofInstance*, const gchar*))cm_setter;
if(string_setter != NULL) { string_setter(qsf_ent, (gchar*)xmlNodeGetContent(node)); }
}
if(safe_strcmp(qof_type, QOF_TYPE_DATE) == 0) {
date_setter = (void(*)(QofEntity*, Timespec))cm_setter;
date_setter = (void(*)(QofInstance*, Timespec))cm_setter;
timechk = NULL;
timechk = strptime((char*)xmlNodeGetContent(node), QSF_XSD_TIME, &qsf_time);
g_return_if_fail(timechk != NULL);
@@ -1119,7 +1119,7 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
}
if((safe_strcmp(qof_type, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(qof_type, QOF_TYPE_DEBCRED) == 0)) {
numeric_setter = (void(*)(QofEntity*, gnc_numeric))cm_setter;
numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_setter;
string_to_gnc_numeric((char*)xmlNodeGetContent(node), &cm_numeric);
if(numeric_setter != NULL) { numeric_setter(qsf_ent, cm_numeric); }
}
@@ -1135,10 +1135,10 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
reference_type = (char*)xmlGetProp(node, BAD_CAST QSF_OBJECT_TYPE);
if(0 == safe_strcmp(QOF_PARAM_GUID, reference_type))
{
qof_entity_set_guid(qsf_ent, cm_guid);
qof_instance_set_guid(qsf_ent, cm_guid);
}
else {
reference = qof_entity_get_reference_from(qsf_ent, cm_param);
reference = qof_instance_get_reference_from(qsf_ent, cm_param);
if(reference) {
params->referenceList = g_list_append(params->referenceList, reference);
}
@@ -1148,7 +1148,7 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
errno = 0;
cm_i32 = (gint32)strtol ((char*)xmlNodeGetContent(node), &tail, 0);
if(errno == 0) {
i32_setter = (void(*)(QofEntity*, gint32))cm_setter;
i32_setter = (void(*)(QofInstance*, gint32))cm_setter;
if(i32_setter != NULL) { i32_setter(qsf_ent, cm_i32); }
}
else { qof_backend_set_error(params->be, ERR_QSF_OVERFLOW); }
@@ -1157,7 +1157,7 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
errno = 0;
cm_i64 = strtoll((gchar*)xmlNodeGetContent(node), &tail, 0);
if(errno == 0) {
i64_setter = (void(*)(QofEntity*, gint64))cm_setter;
i64_setter = (void(*)(QofInstance*, gint64))cm_setter;
if(i64_setter != NULL) { i64_setter(qsf_ent, cm_i64); }
}
else { qof_backend_set_error(params->be, ERR_QSF_OVERFLOW); }
@@ -1166,7 +1166,7 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
errno = 0;
cm_double = strtod((gchar*)xmlNodeGetContent(node), &tail);
if(errno == 0) {
double_setter = (void(*)(QofEntity*, double))cm_setter;
double_setter = (void(*)(QofInstance*, double))cm_setter;
if(double_setter != NULL) { double_setter(qsf_ent, cm_double); }
}
}
@@ -1176,7 +1176,7 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
cm_boolean = TRUE;
}
else { cm_boolean = FALSE; }
boolean_setter = (void(*)(QofEntity*, gboolean))cm_setter;
boolean_setter = (void(*)(QofInstance*, gboolean))cm_setter;
if(boolean_setter != NULL) { boolean_setter(qsf_ent, cm_boolean); }
}
if(safe_strcmp(qof_type, QOF_TYPE_KVP) == 0) {
@@ -1190,7 +1190,7 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
if(safe_strcmp(qof_type, QOF_TYPE_COLLECT) == 0) {
QofCollection *qsf_coll;
QofIdType type;
QofEntityReference *reference;
QofInstanceReference *reference;
QofParam *copy_param;
/* retrieve the *type* of the collection, ignore any contents. */
qsf_coll = cm_param->param_getfcn(qsf_ent, cm_param);
@@ -1202,11 +1202,11 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
PINFO (" string to guid collect failed for %s", xmlNodeGetContent(node));
return;
}
/* create a QofEntityReference with this type and GUID.
/* create a QofInstanceReference with this type and GUID.
there is only one entity each time.
cm_guid contains the GUID of the reference.
type is the type of the reference. */
reference = g_new0(QofEntityReference, 1);
reference = g_new0(QofInstanceReference, 1);
reference->type = g_strdup(qsf_ent->e_type);
reference->ref_guid = cm_guid;
reference->ent_guid = &qsf_ent->guid;
@@ -1219,7 +1219,7 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
if(safe_strcmp(qof_type, QOF_TYPE_CHAR) == 0) {
char_getter = (gchar (*)(xmlNodePtr))xmlNodeGetContent;
cm_char = char_getter(node);
char_setter = (void(*)(QofEntity*, gchar))cm_setter;
char_setter = (void(*)(QofInstance*, gchar))cm_setter;
if(char_setter != NULL) { char_setter(qsf_ent, cm_char); }
}
}

View File

@@ -355,7 +355,7 @@ qsf_book_node_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params)
DEBUG (" trying to set book GUID");
buffer = g_strdup((gchar*)xmlNodeGetContent(child_node));
g_return_if_fail(TRUE == string_to_guid(buffer, &book_guid));
qof_entity_set_guid((QofEntity*)params->book, &book_guid);
qof_instance_set_guid(QOF_INSTANCE(params->book), &book_guid);
xmlNewChild(params->output_node, params->qsf_ns,
BAD_CAST QSF_BOOK_GUID, BAD_CAST buffer);
g_free(buffer);

View File

@@ -344,7 +344,7 @@ typedef struct qsf_metadata
gint count; /**< sequential counter for each object in the book */
GList *qsf_object_list; /**< list of qsf_objects */
GSList *qsf_sequence; /**< Parameter list sorted into QSF order */
GList *referenceList; /**< Table of references, ::QofEntityReference. */
GList *referenceList; /**< Table of references, ::QofInstanceReference. */
GHashTable *qsf_parameter_hash; /**< Hashtable of parameters for each object */
GHashTable *qsf_calculate_hash, *qsf_default_hash, *qsf_define_hash;
GSList *supported_types; /**< The list of QOF types currently supported, in QSF order. */
@@ -362,7 +362,7 @@ typedef struct qsf_metadata
QofIdType qof_obj_type; /**< current QofObject type (e_type) for the parameters. */
QofIdType qof_foreach; /**< How to iterate over hierarchical entities. */
gint foreach_limit; /**< How many iterations are found in the QSF */
QofEntity *qsf_ent; /**< Current entity in the book. */
QofInstance *qsf_ent; /**< Current entity in the book. */
QofBackend *be; /**< the current QofBackend for this operation. */
gboolean knowntype; /**< detect references by comparing with known QOF types. */
QofParam *qof_param; /**< used by kvp to handle the frame hash table */

View File

@@ -57,7 +57,7 @@ void gnc_engine_resume_events (void)
{
qof_event_resume();
}
void gnc_engine_gen_event (QofEntity *entity, GNCEngineEventType event_type)
void gnc_engine_gen_event (QofInstance *entity, GNCEngineEventType event_type)
{
qof_event_gen(entity, event_type, NULL);
}

View File

@@ -104,7 +104,7 @@ gint gnc_engine_register_event_handler (GNCEngineEventHandler handler,
/** \deprecated use qof_event_unregister_handler instead. */
void gnc_engine_unregister_event_handler (gint handler_id);
/** \deprecated use qof_event_gen instead. */
void gnc_engine_gen_event (QofEntity *entity, GNCEngineEventType event_type);
void gnc_engine_gen_event (QofInstance *entity, GNCEngineEventType event_type);
/** \deprecated use qof_event_suspend instead. */
void gnc_engine_suspend_events (void);
/** \deprecated use qof_event_resume instead. */

View File

@@ -0,0 +1,98 @@
/********************************************************************\
* qof-gobject.h -- helper macros for qof objects using gobject *
* *
* 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 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef QOF_GOBJECT_H
#define QOF_GOBJECT_H
#include <glib-object.h>
/**
* This is a simple macro for use in your QOF header files.
* In addition to using this macro (which you don't need to use,
* you can define the get_type() function directory if you wish)
* you also need to define the gobject type cast macros. For example,
* for the QofInstance type you would need to define the following
* macros:
*
* #define QOF_TYPE_INSTANCE (qof_instance_get_type ())
* #define QOF_INSTANCE(o) \
* (G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_INSTANCE, QofInstance))
* #define QOF_INSTANCE_CLASS(k) \
* (G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_INSTANCE, QofInstanceClass))
* #define QOF_IS_INSTANCE(o) \
* (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_INSTANCE))
* #define QOF_IS_INSTANCE_CLASS(k) \
* (G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_INSTANCE))
* #define QOF_INSTANCE_GET_CLASS(o) \
* (G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_INSTANCE, QofInstanceClass))
*
* @param type_name The function type_name for this type
*/
#define QOF_GOBJECT_DECL(type_name) \
GType type_name##_get_type(void);
/**
* The following macros are for convenience in your QOF object
* implementation files. Generally you only need to use
* QOF_GOBJECT_IMPL() or QOF_GOBJECT_IMPL_WITH_CODE()
*/
#define QOF_GOBJECT_GET_TYPE(TypeName, type_name, TYPE_PARENT, CODE) \
G_DEFINE_TYPE_WITH_CODE(TypeName, type_name, TYPE_PARENT, CODE);
#define QOF_GOBJECT_CLASS_INIT(type_name, TypeName) \
static void type_name##_dispose(GObject *object); \
static void type_name##_finalize(GObject *object); \
static void type_name##_class_init(TypeName##Class *klass) \
{ \
GObjectClass *object_class = G_OBJECT_CLASS(klass); \
object_class->dispose = type_name##_dispose; \
object_class->finalize = type_name##_finalize; \
}
#define QOF_GOBJECT_DISPOSE(type_name) \
static void type_name##_dispose_real(GObject* object); \
static void type_name##_dispose(GObject *object) \
{ \
type_name##_dispose_real(object); \
G_OBJECT_CLASS(type_name##_parent_class)->dispose(object); \
}
#define QOF_GOBJECT_FINALIZE(type_name) \
static void type_name##_finalize_real(GObject* object); \
static void type_name##_finalize(GObject *object) \
{ \
type_name##_finalize_real(object); \
G_OBJECT_CLASS(type_name##_parent_class)->finalize(object); \
}
#define QOF_GOBJECT_IMPL_WITH_CODE(type_name, TypeName, TYPE_PARENT, CODE) \
QOF_GOBJECT_GET_TYPE(TypeName, type_name, TYPE_PARENT, CODE); \
QOF_GOBJECT_CLASS_INIT(type_name, TypeName); \
QOF_GOBJECT_DISPOSE(type_name); \
QOF_GOBJECT_FINALIZE(type_name);
#define QOF_GOBJECT_IMPL(type_name, TypeName, TYPE_PARENT) \
QOF_GOBJECT_IMPL_WITH_CODE(type_name, TypeName, TYPE_PARENT, {})
#endif /* QOF_GOBJECT_H */

View File

@@ -43,65 +43,6 @@
#include "qofid-p.h"
#include "qofinstance-p.h"
/* Book structure */
struct _QofBook
{
QofInstance inst; /* Unique guid for this book. */
/* The time when the book was first dirtied. This is a secondary
* indicator. It should only be used when inst.dirty is TRUE. */
time_t dirty_time;
/* This callback function is called any time the book dirty flag
* changes state. Both clean->dirty and dirty->clean transitions
* trigger a callback. */
QofBookDirtyCB dirty_cb;
/* This is the user supplied data that is returned in the dirty
* callback function.*/
gpointer dirty_data;
/* The entity table associates the GUIDs of all the objects
* belonging to this book, with their pointers to the respective
* objects. This allows a lookup of objects based on thier guid.
*/
GHashTable * hash_of_collections;
/* In order to store arbitrary data, for extensibility, add a table
* that will be used to hold arbitrary pointers.
*/
GHashTable *data_tables;
/* Hash table of destroy callbacks for the data table. */
GHashTable *data_table_finalizers;
/* state flag: 'y' means 'open for editing',
* 'n' means 'book is closed'
* xxxxx shouldn't this be replaced by the instance editlevel ???
*/
char book_open;
/* a flag denoting whether the book is closing down, used to
* help the QOF objects shut down cleanly without maintaining
* internal consistency.
* XXX shouldn't this be replaced by instance->do_free ???
*/
gboolean shutting_down;
/* version number, used for tracking multiuser updates */
gint32 version;
/* To be technically correct, backends belong to sessions and
* not books. So the pointer below "really shouldn't be here",
* except that it provides a nice convenience, avoiding a lookup
* from the session. Better solutions welcome ... */
QofBackend *backend;
/* -------------------------------------------------------------- */
/* Backend private expansion data */
guint32 idata; /* used by the sql backend for kvp management */
};
/*
* qof_book_set_backend() is used by backends to
* initialize the pointers in the book structure to
@@ -115,10 +56,10 @@ void qof_book_set_backend (QofBook *book, QofBackend *be);
/* Register books with the engine */
gboolean qof_book_register (void);
/** @deprecated use qof_entity_set_guid instead but only in
/** @deprecated use qof_instance_set_guid instead but only in
backends (when reading the GUID from the data source). */
#define qof_book_set_guid(book,guid) \
qof_entity_set_guid(QOF_ENTITY(book), guid)
qof_instance_set_guid(QOF_INSTANCE(book), guid)
/* @} */
/* @} */

View File

@@ -48,6 +48,8 @@
static QofLogModule log_module = QOF_MOD_ENGINE;
QOF_GOBJECT_IMPL(qof_book, QofBook, QOF_TYPE_INSTANCE);
/* ====================================================================== */
/* constructor / destructor */
@@ -66,7 +68,7 @@ qof_book_init (QofBook *book)
(GDestroyNotify)qof_util_string_cache_remove, /* key_destroy_func */
coll_destroy); /* value_destroy_func */
qof_instance_init (&book->inst, QOF_ID_BOOK, book);
qof_instance_init_data (&book->inst, QOF_ID_BOOK, book);
book->data_tables = g_hash_table_new (g_str_hash, g_str_equal);
book->data_table_finalizers = g_hash_table_new (g_str_hash, g_str_equal);
@@ -82,11 +84,10 @@ qof_book_new (void)
QofBook *book;
ENTER (" ");
book = g_new0(QofBook, 1);
qof_book_init(book);
book = g_object_new(QOF_TYPE_BOOK, NULL);
qof_object_book_begin (book);
qof_event_gen (&book->inst.entity, QOF_EVENT_CREATE, NULL);
qof_event_gen (&book->inst, QOF_EVENT_CREATE, NULL);
LEAVE ("book=%p", book);
return book;
}
@@ -101,14 +102,26 @@ book_final (gpointer key, gpointer value, gpointer booq)
(*cb) (book, key, user_data);
}
static void
qof_book_dispose_real (GObject *bookp)
{
}
static void
qof_book_finalize_real (GObject *bookp)
{
}
void
qof_book_destroy (QofBook *book)
{
GHashTable* cols;
if (!book) return;
ENTER ("book=%p", book);
book->shutting_down = TRUE;
qof_event_force (&book->inst.entity, QOF_EVENT_DESTROY, NULL);
qof_event_force (&book->inst, QOF_EVENT_DESTROY, NULL);
/* Call the list of finalizers, let them do their thing.
* Do this before tearing into the rest of the book.
@@ -122,12 +135,18 @@ qof_book_destroy (QofBook *book)
g_hash_table_destroy (book->data_tables);
book->data_tables = NULL;
qof_instance_release (&book->inst);
/* qof_instance_release (&book->inst); */
g_hash_table_destroy (book->hash_of_collections);
/* Note: we need to save this hashtable until after we remove ourself
* from it, otherwise we'll crash in our dispose() function when we
* DO remove ourself from the collection but the collection had already
* been destroyed.
*/
cols = book->hash_of_collections;
g_object_unref (book);
g_hash_table_destroy (cols);
book->hash_of_collections = NULL;
g_free (book);
LEAVE ("book=%p", book);
}
@@ -411,7 +430,7 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
gboolean qof_book_register (void)
{
static QofParam params[] = {
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL },
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
{ QOF_PARAM_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL },
{ NULL },
};

View File

@@ -40,8 +40,92 @@
#ifndef QOF_BOOK_H
#define QOF_BOOK_H
typedef struct _QofBookClass QofBookClass;
#include "qofid.h"
#include "kvp_frame.h"
#include "qofinstance.h"
/* --- type macros --- */
#define QOF_TYPE_BOOK (qof_book_get_type ())
#define QOF_BOOK(o) \
(G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_BOOK, QofBook))
#define QOF_BOOK_CLASS(k) \
(G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_BOOK, QofBookClass))
#define QOF_IS_BOOK(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_BOOK))
#define QOF_IS_BOOK_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_BOOK))
#define QOF_BOOK_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_BOOK, QofBookClass))
typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data);
/* Book structure */
struct _QofBook
{
QofInstance inst; /* Unique guid for this book. */
/* The time when the book was first dirtied. This is a secondary
* indicator. It should only be used when inst.dirty is TRUE. */
time_t dirty_time;
/* This callback function is called any time the book dirty flag
* changes state. Both clean->dirty and dirty->clean transitions
* trigger a callback. */
QofBookDirtyCB dirty_cb;
/* This is the user supplied data that is returned in the dirty
* callback function.*/
gpointer dirty_data;
/* The entity table associates the GUIDs of all the objects
* belonging to this book, with their pointers to the respective
* objects. This allows a lookup of objects based on thier guid.
*/
GHashTable * hash_of_collections;
/* In order to store arbitrary data, for extensibility, add a table
* that will be used to hold arbitrary pointers.
*/
GHashTable *data_tables;
/* Hash table of destroy callbacks for the data table. */
GHashTable *data_table_finalizers;
/* state flag: 'y' means 'open for editing',
* 'n' means 'book is closed'
* xxxxx shouldn't this be replaced by the instance editlevel ???
*/
char book_open;
/* a flag denoting whether the book is closing down, used to
* help the QOF objects shut down cleanly without maintaining
* internal consistency.
* XXX shouldn't this be replaced by instance->do_free ???
*/
gboolean shutting_down;
/* version number, used for tracking multiuser updates */
gint32 version;
/* To be technically correct, backends belong to sessions and
* not books. So the pointer below "really shouldn't be here",
* except that it provides a nice convenience, avoiding a lookup
* from the session. Better solutions welcome ... */
QofBackend *backend;
/* -------------------------------------------------------------- */
/* Backend private expansion data */
guint32 idata; /* used by the sql backend for kvp management */
};
struct _QofBookClass
{
QofInstanceClass parent_class;
};
GType qof_book_get_type(void);
/** @brief Encapsulates all the information about a dataset
* manipulated by QOF. This is the top-most structure
@@ -50,7 +134,7 @@
/** Lookup an entity by guid, returning pointer to the entity */
#define QOF_BOOK_LOOKUP_ENTITY(book,guid,e_type,c_type) ({ \
QofEntity *val = NULL; \
QofInstance *val = NULL; \
if (guid && book) { \
QofCollection *col; \
col = qof_book_get_collection (book, e_type); \
@@ -59,14 +143,10 @@
(c_type *) val; \
})
/** \brief QofBook reference */
typedef struct _QofBook QofBook;
/** GList of QofBook */
typedef GList QofBookList;
typedef void (*QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data);
typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data);
/** Register the book object with the QOF object system. */
gboolean qof_book_register (void);
@@ -191,7 +271,7 @@ gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2);
gint64 qof_book_get_counter (QofBook *book, const char *counter_name);
/** deprecated */
#define qof_book_get_guid(X) qof_entity_get_guid (QOF_ENTITY(X))
#define qof_book_get_guid(X) qof_instance_get_guid (QOF_INSTANCE(X))
#endif /* QOF_BOOK_H */
/** @} */

View File

@@ -74,7 +74,7 @@ struct collect_list_s
};
static void
collect_reference_cb (QofEntity *ent, gpointer user_data)
collect_reference_cb (QofInstance *ent, gpointer user_data)
{
struct collect_list_s *s;
@@ -89,7 +89,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
QofBookMergeRule *currentRule;
QofCollection *mergeColl, *targetColl;
gchar *stringImport, *stringTarget;
QofEntity *mergeEnt, *targetEnt, *referenceEnt;
QofInstance *mergeEnt, *targetEnt, *referenceEnt;
const GUID *guidImport, *guidTarget;
QofParam *qtparam;
KvpFrame *kvpImport, *kvpTarget;
@@ -97,13 +97,13 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
QofType mergeType;
GSList *paramList;
gboolean absolute, mergeError, knowntype, mergeMatch, booleanImport, booleanTarget,
(*boolean_getter) (QofEntity*, QofParam*);
Timespec tsImport, tsTarget, (*date_getter) (QofEntity*, QofParam*);
gnc_numeric numericImport, numericTarget, (*numeric_getter) (QofEntity*, QofParam*);
double doubleImport, doubleTarget, (*double_getter) (QofEntity*, QofParam*);
gint32 i32Import, i32Target, (*int32_getter) (QofEntity*, QofParam*);
gint64 i64Import, i64Target, (*int64_getter) (QofEntity*, QofParam*);
gchar charImport, charTarget, (*char_getter) (QofEntity*, QofParam*);
(*boolean_getter) (QofInstance*, QofParam*);
Timespec tsImport, tsTarget, (*date_getter) (QofInstance*, QofParam*);
gnc_numeric numericImport, numericTarget, (*numeric_getter) (QofInstance*, QofParam*);
double doubleImport, doubleTarget, (*double_getter) (QofInstance*, QofParam*);
gint32 i32Import, i32Target, (*int32_getter) (QofInstance*, QofParam*);
gint64 i64Import, i64Target, (*int64_getter) (QofInstance*, QofParam*);
gchar charImport, charTarget, (*char_getter) (QofInstance*, QofParam*);
g_return_val_if_fail((mergeData != NULL), -1);
currentRule = mergeData->currentRule;
@@ -140,7 +140,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))qtparam->param_getfcn;
date_getter = (Timespec (*)(QofInstance*, QofParam*))qtparam->param_getfcn;
tsImport = date_getter(mergeEnt, qtparam);
tsTarget = date_getter(targetEnt, qtparam);
if(timespec_cmp(&tsImport, &tsTarget) == 0) { mergeMatch = TRUE; }
@@ -150,7 +150,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
}
if((safe_strcmp(mergeType, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(mergeType, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
numericImport = numeric_getter(mergeEnt,qtparam);
numericTarget = numeric_getter(targetEnt,qtparam);
if(gnc_numeric_compare (numericImport, numericTarget) == 0) { mergeMatch = TRUE; }
@@ -167,7 +167,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
i32Import = int32_getter(mergeEnt, qtparam);
i32Target = int32_getter(targetEnt, qtparam);
if(i32Target == i32Import) { mergeMatch = TRUE; }
@@ -176,7 +176,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_INT64) == 0) {
int64_getter = (gint64 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
i64Import = int64_getter(mergeEnt, qtparam);
i64Target = int64_getter(targetEnt, qtparam);
if(i64Target == i64Import) { mergeMatch = TRUE; }
@@ -185,7 +185,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_DOUBLE) == 0) {
double_getter = (double (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
double_getter = (double (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
doubleImport = double_getter(mergeEnt, qtparam);
doubleTarget = double_getter(mergeEnt, qtparam);
if(doubleImport == doubleTarget) { mergeMatch = TRUE; }
@@ -194,7 +194,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_BOOLEAN) == 0){
boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
booleanImport = boolean_getter(mergeEnt, qtparam);
booleanTarget = boolean_getter(targetEnt, qtparam);
if(booleanImport != FALSE && booleanImport != TRUE) { booleanImport = FALSE; }
@@ -213,7 +213,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_CHAR) == 0) {
char_getter = (gchar (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
char_getter = (gchar (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
charImport = char_getter(mergeEnt, qtparam);
charTarget = char_getter(targetEnt, qtparam);
if(charImport == charTarget) { mergeMatch = TRUE; }
@@ -325,7 +325,7 @@ The next mergeEnt may be a much better match for that targetEnt and the target_t
is designed to solve the issues that result from this conflict. The previous match
must be re-assigned because if two mergeEnt's are matched with only one targetEnt,
data loss \b WILL follow. Equally, the current mergeEnt must replace the previous
one as it is a better match. qof_entity_rating holds the details required to identify
one as it is a better match. qof_instance_rating holds the details required to identify
the correct mergeEnt to be re-assigned and these mergeEnt entities are therefore
orphaned - to be re-matched later.
@@ -372,7 +372,7 @@ qof_book_merge_match_orphans(QofBookMergeData *mergeData)
{
GSList *orphans, *targets;
QofBookMergeRule *rule, *currentRule;
QofEntity *best_matchEnt;
QofInstance *best_matchEnt;
double difference;
g_return_if_fail(mergeData != NULL);
@@ -409,7 +409,7 @@ qof_book_merge_match_orphans(QofBookMergeData *mergeData)
}
static void
qof_book_merge_foreach_target (QofEntity* targetEnt, gpointer user_data)
qof_book_merge_foreach_target (QofInstance* targetEnt, gpointer user_data)
{
QofBookMergeData *mergeData;
@@ -437,11 +437,11 @@ qof_book_merge_foreach_type_target ( QofObject* merge_obj, gpointer user_data)
}
static void
qof_book_merge_foreach ( QofEntity* mergeEnt, gpointer user_data)
qof_book_merge_foreach ( QofInstance* mergeEnt, gpointer user_data)
{
QofBookMergeRule *mergeRule, *currentRule;
QofBookMergeData *mergeData;
QofEntity *targetEnt, *best_matchEnt;
QofInstance *targetEnt, *best_matchEnt;
GUID *g;
double difference;
GSList *c;
@@ -592,7 +592,7 @@ qof_book_merge_commit_rule_loop(
{
QofInstance *inst;
gboolean registered_type;
QofEntity *referenceEnt;
QofInstance *referenceEnt;
/* cm_ prefix used for variables that hold the data to commit */
QofCollection *cm_coll;
QofParam *cm_param;
@@ -600,26 +600,26 @@ qof_book_merge_commit_rule_loop(
const GUID *cm_guid;
KvpFrame *cm_kvp;
/* function pointers and variables for parameter getters that don't use pointers normally */
gnc_numeric cm_numeric, (*numeric_getter) (QofEntity*, QofParam*);
double cm_double, (*double_getter) (QofEntity*, QofParam*);
gboolean cm_boolean, (*boolean_getter) (QofEntity*, QofParam*);
gint32 cm_i32, (*int32_getter) (QofEntity*, QofParam*);
gint64 cm_i64, (*int64_getter) (QofEntity*, QofParam*);
Timespec cm_date, (*date_getter) (QofEntity*, QofParam*);
gchar cm_char, (*char_getter) (QofEntity*, QofParam*);
gnc_numeric cm_numeric, (*numeric_getter) (QofInstance*, QofParam*);
double cm_double, (*double_getter) (QofInstance*, QofParam*);
gboolean cm_boolean, (*boolean_getter) (QofInstance*, QofParam*);
gint32 cm_i32, (*int32_getter) (QofInstance*, QofParam*);
gint64 cm_i64, (*int64_getter) (QofInstance*, QofParam*);
Timespec cm_date, (*date_getter) (QofInstance*, QofParam*);
gchar cm_char, (*char_getter) (QofInstance*, QofParam*);
/* function pointers to the parameter setters */
void (*string_setter) (QofEntity*, const gchar*);
void (*date_setter) (QofEntity*, Timespec);
void (*numeric_setter) (QofEntity*, gnc_numeric);
void (*guid_setter) (QofEntity*, const GUID*);
void (*double_setter) (QofEntity*, double);
void (*boolean_setter) (QofEntity*, gboolean);
void (*i32_setter) (QofEntity*, gint32);
void (*i64_setter) (QofEntity*, gint64);
void (*char_setter) (QofEntity*, gchar);
void (*kvp_frame_setter) (QofEntity*, KvpFrame*);
void (*reference_setter) (QofEntity*, QofEntity*);
void (*collection_setter)(QofEntity*, QofCollection*);
void (*string_setter) (QofInstance*, const gchar*);
void (*date_setter) (QofInstance*, Timespec);
void (*numeric_setter) (QofInstance*, gnc_numeric);
void (*guid_setter) (QofInstance*, const GUID*);
void (*double_setter) (QofInstance*, double);
void (*boolean_setter) (QofInstance*, gboolean);
void (*i32_setter) (QofInstance*, gint32);
void (*i64_setter) (QofInstance*, gint64);
void (*char_setter) (QofInstance*, gchar);
void (*kvp_frame_setter) (QofInstance*, KvpFrame*);
void (*reference_setter) (QofInstance*, QofInstance*);
void (*collection_setter)(QofInstance*, QofCollection*);
g_return_if_fail(rule != NULL);
g_return_if_fail(mergeData != NULL);
@@ -630,8 +630,8 @@ qof_book_merge_commit_rule_loop(
if(rule->mergeResult == MERGE_NEW) {
inst = (QofInstance*)qof_object_new_instance(rule->importEnt->e_type, mergeData->targetBook);
g_return_if_fail(inst != NULL);
rule->targetEnt = &inst->entity;
qof_entity_set_guid(rule->targetEnt, qof_entity_get_guid(rule->importEnt));
rule->targetEnt = inst;
qof_instance_set_guid(rule->targetEnt, qof_instance_get_guid(rule->importEnt));
}
/* currentRule->targetEnt is now set,
1. by an absolute GUID match or
@@ -645,81 +645,81 @@ qof_book_merge_commit_rule_loop(
rule->mergeType = cm_param->param_type;
if(safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0) {
cm_string = cm_param->param_getfcn(rule->importEnt, cm_param);
string_setter = (void(*)(QofEntity*, const gchar*))cm_param->param_setfcn;
string_setter = (void(*)(QofInstance*, const gchar*))cm_param->param_setfcn;
if(string_setter != NULL) { string_setter(rule->targetEnt, cm_string); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))cm_param->param_getfcn;
date_getter = (Timespec (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
cm_date = date_getter(rule->importEnt, cm_param);
date_setter = (void(*)(QofEntity*, Timespec))cm_param->param_setfcn;
date_setter = (void(*)(QofInstance*, Timespec))cm_param->param_setfcn;
if(date_setter != NULL) { date_setter(rule->targetEnt, cm_date); }
registered_type = TRUE;
}
if((safe_strcmp(rule->mergeType, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(rule->mergeType, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*))cm_param->param_getfcn;
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
cm_numeric = numeric_getter(rule->importEnt, cm_param);
numeric_setter = (void(*)(QofEntity*, gnc_numeric))cm_param->param_setfcn;
numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_param->param_setfcn;
if(numeric_setter != NULL) { numeric_setter(rule->targetEnt, cm_numeric); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_GUID) == 0) {
cm_guid = cm_param->param_getfcn(rule->importEnt, cm_param);
guid_setter = (void(*)(QofEntity*, const GUID*))cm_param->param_setfcn;
guid_setter = (void(*)(QofInstance*, const GUID*))cm_param->param_setfcn;
if(guid_setter != NULL) { guid_setter(rule->targetEnt, cm_guid); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_i32 = int32_getter(rule->importEnt, cm_param);
i32_setter = (void(*)(QofEntity*, gint32))cm_param->param_setfcn;
i32_setter = (void(*)(QofInstance*, gint32))cm_param->param_setfcn;
if(i32_setter != NULL) { i32_setter(rule->targetEnt, cm_i32); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_INT64) == 0) {
int64_getter = (gint64 (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_i64 = int64_getter(rule->importEnt, cm_param);
i64_setter = (void(*)(QofEntity*, gint64))cm_param->param_setfcn;
i64_setter = (void(*)(QofInstance*, gint64))cm_param->param_setfcn;
if(i64_setter != NULL) { i64_setter(rule->targetEnt, cm_i64); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_DOUBLE) == 0) {
double_getter = (double (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
double_getter = (double (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_double = double_getter(rule->importEnt, cm_param);
double_setter = (void(*)(QofEntity*, double))cm_param->param_setfcn;
double_setter = (void(*)(QofInstance*, double))cm_param->param_setfcn;
if(double_setter != NULL) { double_setter(rule->targetEnt, cm_double); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_BOOLEAN) == 0){
boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_boolean = boolean_getter(rule->importEnt, cm_param);
boolean_setter = (void(*)(QofEntity*, gboolean))cm_param->param_setfcn;
boolean_setter = (void(*)(QofInstance*, gboolean))cm_param->param_setfcn;
if(boolean_setter != NULL) { boolean_setter(rule->targetEnt, cm_boolean); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_KVP) == 0) {
cm_kvp = kvp_frame_copy(cm_param->param_getfcn(rule->importEnt,cm_param));
kvp_frame_setter = (void(*)(QofEntity*, KvpFrame*))cm_param->param_setfcn;
kvp_frame_setter = (void(*)(QofInstance*, KvpFrame*))cm_param->param_setfcn;
if(kvp_frame_setter != NULL) { kvp_frame_setter(rule->targetEnt, cm_kvp); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_CHAR) == 0) {
char_getter = (gchar (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
char_getter = (gchar (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_char = char_getter(rule->importEnt,cm_param);
char_setter = (void(*)(QofEntity*, gchar))cm_param->param_setfcn;
char_setter = (void(*)(QofInstance*, gchar))cm_param->param_setfcn;
if(char_setter != NULL) { char_setter(rule->targetEnt, cm_char); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_COLLECT) == 0) {
cm_coll = cm_param->param_getfcn(rule->importEnt, cm_param);
collection_setter = (void(*)(QofEntity*, QofCollection*))cm_param->param_setfcn;
collection_setter = (void(*)(QofInstance*, QofCollection*))cm_param->param_setfcn;
if(collection_setter != NULL) { collection_setter(rule->targetEnt, cm_coll); }
registered_type = TRUE;
}
if(safe_strcmp(rule->mergeType, QOF_TYPE_CHOICE) == 0) {
referenceEnt = cm_param->param_getfcn(rule->importEnt, cm_param);
reference_setter = (void(*)(QofEntity*, QofEntity*))cm_param->param_setfcn;
reference_setter = (void(*)(QofInstance*, QofInstance*))cm_param->param_setfcn;
if(reference_setter != NULL)
{
reference_setter(rule->targetEnt, referenceEnt);
@@ -729,7 +729,7 @@ qof_book_merge_commit_rule_loop(
if(registered_type == FALSE) {
referenceEnt = cm_param->param_getfcn(rule->importEnt, cm_param);
if(referenceEnt) {
reference_setter = (void(*)(QofEntity*, QofEntity*))cm_param->param_setfcn;
reference_setter = (void(*)(QofInstance*, QofInstance*))cm_param->param_setfcn;
if(reference_setter != NULL)
{
reference_setter(rule->targetEnt, referenceEnt);
@@ -819,20 +819,20 @@ and then add
gchar* qof_class_get_param_as_string(QofIdTypeConst, QofInstance*); ?
*/
gchar*
qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt)
qof_book_merge_param_as_string(QofParam *qtparam, QofInstance *qtEnt)
{
gchar *param_string, param_date[QOF_DATE_STRING_LENGTH];
gchar param_sa[GUID_ENCODING_LENGTH + 1];
QofType paramType;
const GUID *param_guid;
time_t param_t;
gnc_numeric param_numeric, (*numeric_getter) (QofEntity*, QofParam*);
Timespec param_ts, (*date_getter) (QofEntity*, QofParam*);
double param_double, (*double_getter) (QofEntity*, QofParam*);
gboolean param_boolean, (*boolean_getter) (QofEntity*, QofParam*);
gint32 param_i32, (*int32_getter) (QofEntity*, QofParam*);
gint64 param_i64, (*int64_getter) (QofEntity*, QofParam*);
gchar param_char, (*char_getter) (QofEntity*, QofParam*);
gnc_numeric param_numeric, (*numeric_getter) (QofInstance*, QofParam*);
Timespec param_ts, (*date_getter) (QofInstance*, QofParam*);
double param_double, (*double_getter) (QofInstance*, QofParam*);
gboolean param_boolean, (*boolean_getter) (QofInstance*, QofParam*);
gint32 param_i32, (*int32_getter) (QofInstance*, QofParam*);
gint64 param_i64, (*int64_getter) (QofInstance*, QofParam*);
gchar param_char, (*char_getter) (QofInstance*, QofParam*);
param_string = NULL;
paramType = qtparam->param_type;
@@ -842,7 +842,7 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt)
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))qtparam->param_getfcn;
date_getter = (Timespec (*)(QofInstance*, QofParam*))qtparam->param_getfcn;
param_ts = date_getter(qtEnt, qtparam);
param_t = timespecToTime_t(param_ts);
qof_strftime(param_date, QOF_DATE_STRING_LENGTH, QOF_UTC_DATE_FORMAT, gmtime(&param_t));
@@ -851,7 +851,7 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt)
}
if((safe_strcmp(paramType, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
param_numeric = numeric_getter(qtEnt,qtparam);
param_string = g_strdup(gnc_numeric_to_string(param_numeric));
return param_string;
@@ -863,25 +863,25 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt)
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
param_i32 = int32_getter(qtEnt, qtparam);
param_string = g_strdup_printf("%d", param_i32);
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_INT64) == 0) {
int64_getter = (gint64 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
param_i64 = int64_getter(qtEnt, qtparam);
param_string = g_strdup_printf("%" G_GINT64_FORMAT, param_i64);
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_DOUBLE) == 0) {
double_getter = (double (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
double_getter = (double (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
param_double = double_getter(qtEnt, qtparam);
param_string = g_strdup_printf("%f", param_double);
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_BOOLEAN) == 0){
boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
param_boolean = boolean_getter(qtEnt, qtparam);
/* Boolean values need to be lowercase for QSF validation. */
if(param_boolean == TRUE) { param_string = g_strdup("true"); }
@@ -891,7 +891,7 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt)
/* "kvp" contains repeating values, cannot be a single string for the frame. */
if(safe_strcmp(paramType, QOF_TYPE_KVP) == 0) { return param_string; }
if(safe_strcmp(paramType, QOF_TYPE_CHAR) == 0) {
char_getter = (gchar (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
char_getter = (gchar (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
param_char = char_getter(qtEnt, qtparam);
param_string = g_strdup_printf("%c", param_char);
return param_string;

View File

@@ -175,7 +175,7 @@ typedef struct
GSList *mergeParam; /**< list of usable parameters for the object type */
GSList *linkedEntList; /**< list of complex data types included in this object.
linkedEntList contains an ::QofEntity reference to any parameter that is not
linkedEntList contains an ::QofInstance reference to any parameter that is not
one of the core QOF_TYPE data types. This entity must be already
registered with QOF and the results of the comparison for the linked entity
will modulate the mergeResult of this object. e.g. if an invoice is the
@@ -183,8 +183,8 @@ typedef struct
MERGE_REPORT and the customer as MERGE_NEW.
*/
QofBookMergeResult mergeResult; /**< result of comparison with main ::QofBook */
QofEntity *importEnt; /**< pointer to the current entity in the import book. */
QofEntity *targetEnt; /**< pointer to the corresponding entity in the
QofInstance *importEnt; /**< pointer to the current entity in the import book. */
QofInstance *targetEnt; /**< pointer to the corresponding entity in the
target book, if any. */
}QofBookMergeRule;
@@ -194,7 +194,7 @@ typedef struct
Used to dictate what to merge, how to merge it, where to get the new data and
where to put the amended data.
Combines lists of \a ::QofParam, \a ::QofEntity and \a ::QofBookMergeRule
Combines lists of \a ::QofParam, \a ::QofInstance and \a ::QofBookMergeRule
into one struct that can be easily passed between callbacks. Also holds the
pointers to the import and target ::QofBook structures.
@@ -209,7 +209,7 @@ typedef struct
parameter in the current object. */
GList *mergeList; /**< GList of all ::qof_book_mergeRule rules
for the merge operation. */
GSList *targetList; /**< GSList of ::QofEntity * for each object
GSList *targetList; /**< GSList of ::QofInstance * for each object
of this type in the target book */
QofBook *mergeBook; /**< pointer to the import book for this
merge operation. */
@@ -218,16 +218,16 @@ typedef struct
gboolean abort; /**< set to TRUE if MERGE_INVALID is set. */
QofBookMergeRule *currentRule; /**< placeholder for the rule currently
being tested or applied. */
GSList *orphan_list; /**< List of QofEntity's that need to be rematched.
GSList *orphan_list; /**< List of QofInstance's that need to be rematched.
When one QofEntity has a lower difference to the targetEnt than the
When one QofInstance has a lower difference to the targetEnt than the
previous best_match, the new match takes precedence. This list holds those
orphaned entities that are not a good enough match so that these can be
rematched later. The ranking is handled using the private QofEntityRating
rematched later. The ranking is handled using the private QofInstanceRating
struct and the GHashTable ::QofBookMergeData::target_table.
*/
GHashTable *target_table; /**< The GHashTable to hold the
QofEntityRating values. */
QofInstanceRating values. */
}QofBookMergeData;
@@ -335,7 +335,7 @@ process must handle the NULL targetEnt and NOT call any param_getfcn
routines for the target entity. The import entity is available for display.
Uses ::qof_book_get_collection with the QofBookMergeRule::mergeType object
type to return a collection of ::QofEntity entities from either the
type to return a collection of ::QofInstance entities from either the
QofBookMergeData::mergeBook or QofBookMergeData::targetBook. Then
uses ::qof_collection_lookup_entity to lookup the QofBookMergeRule::importEnt
and again the qof_book_mergeRule::targetEnt to return the two specific entities.
@@ -359,7 +359,7 @@ This allows the dialog to display the description of the object and all
parameter data.
*/
gchar* qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt);
gchar* qof_book_merge_param_as_string(QofParam *qtparam, QofInstance *qtEnt);
/** \brief called by dialogue callback to set the result of user intervention

View File

@@ -267,7 +267,7 @@ void qof_class_param_foreach (QofIdTypeConst obj_name,
Simple check to return a GList of all parameters
of this object type that are not known QOF data types.
Used for partial QofBook support, see ::QofEntityReference
Used for partial QofBook support, see ::QofInstanceReference
*/
GList* qof_class_get_referenceList(QofIdTypeConst type);

View File

@@ -48,6 +48,6 @@ qof_event_generate (const GUID *guid, QofIdType e_type,
QofEventId event_id);
/* generates an event even when events are suspended! */
void qof_event_force (QofEntity *entity, QofEventId event_id, gpointer event_data);
void qof_event_force (QofInstance *entity, QofEventId event_id, gpointer event_data);
#endif

View File

@@ -203,7 +203,7 @@ qof_event_resume (void)
}
static void
qof_event_generate_internal (QofEntity *entity, QofEventId event_id,
qof_event_generate_internal (QofInstance *entity, QofEventId event_id,
gpointer event_data)
{
GList *node;
@@ -275,7 +275,7 @@ qof_event_generate_internal (QofEntity *entity, QofEventId event_id,
}
void
qof_event_force (QofEntity *entity, QofEventId event_id, gpointer event_data)
qof_event_force (QofInstance *entity, QofEventId event_id, gpointer event_data)
{
if (!entity)
return;
@@ -284,7 +284,7 @@ qof_event_force (QofEntity *entity, QofEventId event_id, gpointer event_data)
}
void
qof_event_gen (QofEntity *entity, QofEventId event_id, gpointer event_data)
qof_event_gen (QofInstance *entity, QofEventId event_id, gpointer event_data)
{
if (!entity)
return;
@@ -300,7 +300,7 @@ void
qof_event_generate (const GUID *guid, QofIdType e_type,
QofEventId event_id)
{
QofEntity ent;
QofInstance ent;
ent.guid = *guid;
ent.e_type = e_type;
if (suspend_counter) return;

View File

@@ -81,7 +81,7 @@ for future libqof1 or libqof2 usage.
* @param handler_data: data supplied when handler was registered.
* @param event_data: data to be supplied when handler is invoked.
*/
typedef void (*QofEventHandler) (QofEntity *ent, QofEventId event_type,
typedef void (*QofEventHandler) (QofInstance *ent, QofEventId event_type,
gpointer handler_data, gpointer event_data);
/** \brief Register a handler for events.
@@ -113,14 +113,14 @@ void qof_event_unregister_handler (gint handler_id);
Any other events are entirely the concern of the application.
\note QofEventHandler routines do \b NOT support generating
events from a GUID and QofIdType - you must specify a genuine QofEntity.
events from a GUID and QofIdType - you must specify a genuine QofInstance.
@param entity: the entity generating the event
@param event_type: the name of the event.
@param event_data: Data to be passed to the event handler just for
this one event. Can be NULL.
*/
void qof_event_gen (QofEntity *entity, QofEventId event_type,
void qof_event_gen (QofInstance *entity, QofEventId event_type,
gpointer event_data);
/** \brief Suspend all engine events.

View File

@@ -202,7 +202,7 @@ qof_gobject_double_getter (gpointer data, QofParam *getter)
* of instances that we have on hand.
*/
static void
qof_gobject_foreach (QofCollection *coll, QofEntityForeachCB cb, gpointer ud)
qof_gobject_foreach (QofCollection *coll, QofInstanceForeachCB cb, gpointer ud)
{
GSList *n;
n = qof_collection_get_data (coll);

View File

@@ -38,13 +38,13 @@
/** Set the ID of the entity, over-riding the previous ID.
* Very dangerous, use only for file i/o work.
*/
void qof_entity_set_guid (QofEntity *ent, const GUID *guid);
void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
/** Take entity, remove it from whatever collection its currently
* in, and place it in a new collection. To be used only for
* moving entity from one book to another.
*/
void qof_collection_insert_entity (QofCollection *, QofEntity *);
void qof_collection_insert_entity (QofCollection *, QofInstance *);
/** reset value of dirty flag */
void qof_collection_mark_clean (QofCollection *);

View File

@@ -58,10 +58,8 @@ qof_set_alt_dirty_mode (gboolean enabled)
/* =============================================================== */
static void qof_collection_remove_entity (QofEntity *ent);
void
qof_entity_init (QofEntity *ent, QofIdType type, QofCollection * tab)
qof_entity_init (QofInstance *ent, QofIdType type, QofCollection * tab)
{
g_return_if_fail (NULL != tab);
@@ -75,7 +73,7 @@ qof_entity_init (QofEntity *ent, QofIdType type, QofCollection * tab)
ent->e_type = CACHE_INSERT (type);
do
{
{
guid_new(&ent->guid);
if (NULL == qof_collection_lookup_entity (tab, &ent->guid)) break;
@@ -89,7 +87,7 @@ qof_entity_init (QofEntity *ent, QofIdType type, QofCollection * tab)
}
void
qof_entity_release (QofEntity *ent)
qof_entity_release (QofInstance *ent)
{
if (!ent->collection) return;
qof_collection_remove_entity (ent);
@@ -101,7 +99,7 @@ qof_entity_release (QofEntity *ent)
/* This is a restricted function, should be used only during
* read from file */
void
qof_entity_set_guid (QofEntity *ent, const GUID *guid)
qof_instance_set_guid (QofInstance *ent, const GUID *guid)
{
QofCollection *col;
if (guid_equal (guid, &ent->guid)) return;
@@ -112,13 +110,6 @@ qof_entity_set_guid (QofEntity *ent, const GUID *guid)
qof_collection_insert_entity (col, ent);
}
const GUID *
qof_entity_get_guid (const QofEntity *ent)
{
if (!ent) return guid_null();
return &ent->guid;
}
/* =============================================================== */
static guint
@@ -189,8 +180,8 @@ qof_collection_get_type (const QofCollection *col)
/* =============================================================== */
static void
qof_collection_remove_entity (QofEntity *ent)
void
qof_collection_remove_entity (QofInstance *ent)
{
QofCollection *col;
if (!ent) return;
@@ -203,7 +194,7 @@ qof_collection_remove_entity (QofEntity *ent)
}
void
qof_collection_insert_entity (QofCollection *col, QofEntity *ent)
qof_collection_insert_entity (QofCollection *col, QofInstance *ent)
{
if (!col || !ent) return;
if (guid_equal(&ent->guid, guid_null())) return;
@@ -216,9 +207,9 @@ qof_collection_insert_entity (QofCollection *col, QofEntity *ent)
}
gboolean
qof_collection_add_entity (QofCollection *coll, QofEntity *ent)
qof_collection_add_entity (QofCollection *coll, QofInstance *ent)
{
QofEntity *e;
QofInstance *e;
e = NULL;
if (!coll || !ent) { return FALSE; }
@@ -233,7 +224,7 @@ qof_collection_add_entity (QofCollection *coll, QofEntity *ent)
}
static void
collection_merge_cb (QofEntity *ent, gpointer data)
collection_merge_cb (QofInstance *ent, gpointer data)
{
QofCollection *target;
@@ -251,10 +242,10 @@ qof_collection_merge (QofCollection *target, QofCollection *merge)
}
static void
collection_compare_cb (QofEntity *ent, gpointer user_data)
collection_compare_cb (QofInstance *ent, gpointer user_data)
{
QofCollection *target;
QofEntity *e;
QofInstance *e;
gint value;
e = NULL;
@@ -302,10 +293,10 @@ qof_collection_compare (QofCollection *target, QofCollection *merge)
return value;
}
QofEntity *
QofInstance *
qof_collection_lookup_entity (const QofCollection *col, const GUID * guid)
{
QofEntity *ent;
QofInstance *ent;
g_return_val_if_fail (col, NULL);
if (guid == NULL) return NULL;
ent = g_hash_table_lookup (col->hash_of_entities, guid);
@@ -316,13 +307,13 @@ QofCollection *
qof_collection_from_glist (QofIdType type, GList *glist)
{
QofCollection *coll;
QofEntity *ent;
QofInstance *ent;
GList *list;
coll = qof_collection_new(type);
for(list = glist; list != NULL; list = list->next)
{
ent = (QofEntity*)list->data;
ent = QOF_INSTANCE(list->data);
if(FALSE == qof_collection_add_entity(coll, ent))
{
return NULL;
@@ -365,7 +356,7 @@ qof_collection_print_dirty (const QofCollection *col, gpointer dummy)
{
if (col->is_dirty)
printf("%s collection is dirty.\n", col->e_type);
qof_collection_foreach(col, (QofEntityForeachCB)qof_instance_print_dirty, NULL);
qof_collection_foreach(col, (QofInstanceForeachCB)qof_instance_print_dirty, NULL);
}
/* =============================================================== */
@@ -385,20 +376,20 @@ qof_collection_set_data (QofCollection *col, gpointer user_data)
/* =============================================================== */
struct _iterate {
QofEntityForeachCB fcn;
QofInstanceForeachCB fcn;
gpointer data;
};
static void foreach_cb (gpointer key, gpointer item, gpointer arg)
{
struct _iterate *iter = arg;
QofEntity *ent = item;
QofInstance *ent = item;
iter->fcn (ent, iter->data);
}
void
qof_collection_foreach (const QofCollection *col, QofEntityForeachCB cb_func,
qof_collection_foreach (const QofCollection *col, QofInstanceForeachCB cb_func,
gpointer user_data)
{
struct _iterate iter;

View File

@@ -83,15 +83,16 @@ typedef const gchar * QofIdTypeConst;
/** QofLogModule declaration */
typedef const gchar* QofLogModule;
typedef struct QofCollection_s QofCollection;
#include "qofinstance.h"
#define QOF_ID_NONE NULL
#define QOF_ID_NULL "null"
#define QOF_ID_BOOK "Book"
#define QOF_ID_SESSION "Session"
/** simple,cheesy cast but holds water for now */
#define QOF_ENTITY(object) ((QofEntity *)(object))
/** Inline string comparision; compiler will optimize away most of this */
#define QSTRCMP(da,db) ({ \
gint val = 0; \
@@ -111,7 +112,7 @@ typedef const gchar* QofLogModule;
/** return TRUE if object is of the given type */
#define QOF_CHECK_TYPE(obj,type) (((obj) != NULL) && \
(0 == QSTRCMP((type),(((QofEntity *)(obj))->e_type))))
(0 == QSTRCMP((type),(((QofInstance *)(obj))->e_type))))
/** cast object to the indicated type,
print error message if its bad */
@@ -120,12 +121,11 @@ print error message if its bad */
(c_type *) (obj) : \
(c_type *) ({ \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \
"Error: Bad QofEntity at %s:%d", __FILE__, __LINE__); \
"Error: Bad QofInstance at %s:%d", __FILE__, __LINE__); \
(obj); \
}))
/** QofEntity declaration */
typedef struct QofEntity_s QofEntity;
/** QofCollection declaration
@param e_type QofIdType
@@ -134,31 +134,9 @@ typedef struct QofEntity_s QofEntity;
@param data gpointer, place where object class can hang arbitrary data
*/
typedef struct QofCollection_s QofCollection;
/** QofEntity structure
@param e_type Entity type
@param guid GUID for the entity
@param collection Entity collection
*/
struct QofEntity_s
{
QofIdType e_type;
GUID guid;
QofCollection * collection;
};
/** @name QOF Entity Initialization & Shutdown
@{ */
/** Initialise the memory associated with an entity */
void qof_entity_init (QofEntity *, QofIdType, QofCollection *);
/** Release the data associated with this entity. Dont actually free
* the memory associated with the instance. */
void qof_entity_release (QofEntity *);
/** @} */
void qof_entity_init (QofInstance *ent, QofIdType type, QofCollection * tab);
void qof_entity_release (QofInstance *ent);
void qof_instance_set_guid (QofInstance *ent, const GUID *guid);
/** Is QOF operating in "alternate" dirty mode. In normal mode,
* whenever an instance is dirtied, the collection (and therefore the
@@ -178,7 +156,7 @@ gboolean qof_get_alt_dirty_mode (void);
void qof_set_alt_dirty_mode (gboolean enabled);
/** Return the GUID of this entity */
const GUID * qof_entity_get_guid (const QofEntity *);
const GUID * qof_instance_get_guid (const QofInstance *);
/** @name Collections of Entities
@{ */
@@ -196,13 +174,13 @@ void qof_collection_destroy (QofCollection *col);
QofIdType qof_collection_get_type (const QofCollection *);
/** Find the entity going only from its guid */
QofEntity * qof_collection_lookup_entity (const QofCollection *, const GUID *);
QofInstance * qof_collection_lookup_entity (const QofCollection *, const GUID *);
/** Callback type for qof_entity_foreach */
typedef void (*QofEntityForeachCB) (QofEntity *, gpointer user_data);
/** Callback type for qof_collection_foreach */
typedef void (*QofInstanceForeachCB) (QofInstance *, gpointer user_data);
/** Call the callback for each entity in the collection. */
void qof_collection_foreach (const QofCollection *, QofEntityForeachCB,
void qof_collection_foreach (const QofCollection *, QofInstanceForeachCB,
gpointer user_data);
/** Store and retreive arbitrary object-defined data
@@ -234,11 +212,13 @@ of one object type as references of another entity.
Entities can be
freely added and merged across these secondary collections, they
will not be removed from the original collection as they would
by using ::qof_entity_insert_entity or ::qof_entity_remove_entity.
by using ::qof_instance_insert_entity or ::qof_instance_remove_entity.
*/
gboolean
qof_collection_add_entity (QofCollection *coll, QofEntity *ent);
qof_collection_add_entity (QofCollection *coll, QofInstance *ent);
void qof_collection_remove_entity (QofInstance *ent);
/** \brief Merge two QOF_TYPE_COLLECT of the same type.
@@ -246,8 +226,8 @@ qof_collection_add_entity (QofCollection *coll, QofEntity *ent);
QOF_TYPE_COLLECT uses a secondary collection, independent of
those in the book. Entities will not be removed from the
original collection as when using ::qof_entity_insert_entity
or ::qof_entity_remove_entity.
original collection as when using ::qof_instance_insert_entity
or ::qof_instance_remove_entity.
*/
gboolean
@@ -255,7 +235,7 @@ qof_collection_merge (QofCollection *target, QofCollection *merge);
/** \brief Compare two secondary collections.
Performs a deep comparision of the collections. Each QofEntity in
Performs a deep comparision of the collections. Each QofInstance in
each collection is looked up in the other collection, via the GUID.
\return 0 if the collections are identical or both are NULL

View File

@@ -31,49 +31,6 @@
#include "qofinstance.h"
/*
* UNDER CONSTRUCTION!
* This is mostly scaffolding for now,
* eventually, it may hold more fields, such as refrence counting...
*
*/
struct QofInstance_s
{
/* Globally unique id identifying this instance */
QofEntity entity;
/* The entity_table in which this instance is stored */
QofBook * book;
/* kvp_data is a key-value pair database for storing arbirtary
* information associated with this instance.
* See src/engine/kvp_doc.txt for a list and description of the
* important keys. */
KvpFrame *kvp_data;
/* Timestamp used to track the last modification to this
* instance. Typically used to compare two versions of the
* same object, to see which is newer. When used with the
* SQL backend, this field is reserved for SQL use, to compare
* the version in local memory to the remote, server version.
*/
Timespec last_update;
/* Keep track of nesting level of begin/end edit calls */
int editlevel;
/* In process of being destroyed */
gboolean do_free;
/* dirty/clean flag. If dirty, then this instance has been modified,
* but has not yet been written out to storage (file/database)
*/
gboolean dirty;
/* True iff this instance has never been committed. */
gboolean infant;
};
void qof_instance_set_slots (QofInstance *, KvpFrame *);
/* Set the last_update time. Reserved for use by the SQL backend;

View File

@@ -39,22 +39,21 @@ static QofLogModule log_module = QOF_MOD_ENGINE;
/* ========================================================== */
QofInstance*
qof_instance_create (QofIdType type, QofBook *book)
{
QofInstance *inst;
QOF_GOBJECT_GET_TYPE(QofInstance, qof_instance, G_TYPE_OBJECT, {});
QOF_GOBJECT_FINALIZE(qof_instance);
inst = g_new0(QofInstance, 1);
qof_instance_init(inst, type, book);
return inst;
static void qof_instance_dispose(GObject*);
static void qof_instance_class_init(QofInstanceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = qof_instance_finalize;
object_class->dispose = qof_instance_dispose;
}
void
qof_instance_init (QofInstance *inst, QofIdType type, QofBook *book)
static void
qof_instance_init (QofInstance *inst)
{
QofCollection *col;
inst->book = book;
inst->book = NULL;
inst->kvp_data = kvp_frame_new();
inst->last_update.tv_sec = 0;
inst->last_update.tv_nsec = -1;
@@ -62,27 +61,45 @@ qof_instance_init (QofInstance *inst, QofIdType type, QofBook *book)
inst->do_free = FALSE;
inst->dirty = FALSE;
inst->infant = TRUE;
col = qof_book_get_collection (book, type);
qof_entity_init (&inst->entity, type, col);
}
void
qof_instance_release (QofInstance *inst)
qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book)
{
QofCollection *col;
g_return_if_fail(QOF_IS_INSTANCE(inst));
g_return_if_fail(!inst->book);
inst->book = book;
col = qof_book_get_collection (book, type);
qof_entity_init (inst, type, col);
}
static void
qof_instance_dispose (GObject *instp)
{
QofInstance* inst = QOF_INSTANCE(instp);
qof_entity_release (inst);
G_OBJECT_CLASS(qof_instance_parent_class)->dispose(instp);
}
static void
qof_instance_finalize_real (GObject *instp)
{
QofInstance* inst = QOF_INSTANCE(instp);
kvp_frame_delete (inst->kvp_data);
inst->kvp_data = NULL;
inst->editlevel = 0;
inst->do_free = FALSE;
inst->dirty = FALSE;
qof_entity_release (&inst->entity);
}
const GUID *
qof_instance_get_guid (const QofInstance *inst)
{
if (!inst) return NULL;
return &inst->entity.guid;
if (!inst) return guid_null();
return &(inst->guid);
}
QofBook *
@@ -124,13 +141,13 @@ qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
}
void
qof_instance_print_dirty (const QofEntity *entity, gpointer dummy)
qof_instance_print_dirty (const QofInstance *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));
printf("%s instance %s is dirty.\n", inst->e_type,
guid_to_string(&inst->guid));
}
gboolean
@@ -141,7 +158,7 @@ qof_instance_is_dirty (QofInstance *inst)
if (!inst) { return FALSE; }
if (qof_get_alt_dirty_mode())
return inst->dirty;
coll = inst->entity.collection;
coll = inst->collection;
if(qof_collection_is_dirty(coll)) { return inst->dirty; }
inst->dirty = FALSE;
return FALSE;
@@ -154,7 +171,7 @@ qof_instance_set_dirty(QofInstance* inst)
inst->dirty = TRUE;
if (!qof_get_alt_dirty_mode()) {
coll = inst->entity.collection;
coll = inst->collection;
qof_collection_mark_dirty(coll);
}
}
@@ -222,12 +239,12 @@ qof_instance_gemini (QofInstance *to, const QofInstance *from)
/* Make a note of where the copy came from */
gnc_kvp_bag_add (to->kvp_data, "gemini", now,
"inst_guid", &from->entity.guid,
"book_guid", &from->book->inst.entity.guid,
"inst_guid", &from->guid,
"book_guid", &from->book->inst.guid,
NULL);
gnc_kvp_bag_add (from->kvp_data, "gemini", now,
"inst_guid", &to->entity.guid,
"book_guid", &to->book->inst.entity.guid,
"inst_guid", &to->guid,
"book_guid", &to->book->inst.guid,
NULL);
to->dirty = TRUE;
@@ -245,11 +262,11 @@ qof_instance_lookup_twin (const QofInstance *src, QofBook *target_book)
ENTER (" ");
fr = gnc_kvp_bag_find_by_guid (src->kvp_data, "gemini",
"book_guid", &target_book->inst.entity.guid);
"book_guid", &target_book->inst.guid);
twin_guid = kvp_frame_get_guid (fr, "inst_guid");
col = qof_book_get_collection (target_book, src->entity.e_type);
col = qof_book_get_collection (target_book, src->e_type);
twin = (QofInstance *) qof_collection_lookup_entity (col, twin_guid);
LEAVE (" found twin=%p", twin);

View File

@@ -22,7 +22,7 @@
/** @addtogroup Entity
@{ */
/** @addtogroup Instance
Qof Instances are a derived type of QofEntity. The Instance
Qof Instances are a derived type of QofInstance. The Instance
adds some common features and functions that most objects
will want to use.
@@ -36,25 +36,82 @@
#ifndef QOF_INSTANCE_H
#define QOF_INSTANCE_H
typedef struct _QofInstanceClass QofInstanceClass;
typedef struct QofInstance_s QofInstance;
/** \brief QofBook reference */
typedef struct _QofBook QofBook;
#include "qofid.h"
#include "guid.h"
#include "gnc-date.h"
#include "kvp_frame.h"
#include "qofbook.h"
#include "qofid.h"
#include "qof-gobject.h"
/* --- type macros --- */
/* cheesy, but will do for now, eventually should be more gtk-like, handle
* thunks, etc. */
#define QOF_INSTANCE(object) ((QofInstance *)(object))
#define QOF_TYPE_INSTANCE (qof_instance_get_type ())
#define QOF_INSTANCE(o) \
(G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_INSTANCE, QofInstance))
#define QOF_INSTANCE_CLASS(k) \
(G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_INSTANCE, QofInstanceClass))
#define QOF_IS_INSTANCE(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_INSTANCE))
#define QOF_IS_INSTANCE_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_INSTANCE))
#define QOF_INSTANCE_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_INSTANCE, QofInstanceClass))
typedef struct QofInstance_s QofInstance;
struct QofInstance_s
{
GObject object;
/** Initialise the memory associated with an instance */
void qof_instance_init (QofInstance *, QofIdType, QofBook *);
/* Globally unique id identifying this instance */
QofIdType e_type; /**< Entity type */
GUID guid; /**< GUID for the entity */
QofCollection * collection; /**< Entity collection */
/** release the data associated with this instance. Dont actually free
* the memory associated with the instance. */
void qof_instance_release (QofInstance *inst);
/* The entity_table in which this instance is stored */
QofBook * book;
/* kvp_data is a key-value pair database for storing arbirtary
* information associated with this instance.
* See src/engine/kvp_doc.txt for a list and description of the
* important keys. */
KvpFrame *kvp_data;
/* Timestamp used to track the last modification to this
* instance. Typically used to compare two versions of the
* same object, to see which is newer. When used with the
* SQL backend, this field is reserved for SQL use, to compare
* the version in local memory to the remote, server version.
*/
Timespec last_update;
/* Keep track of nesting level of begin/end edit calls */
int editlevel;
/* In process of being destroyed */
gboolean do_free;
/* dirty/clean flag. If dirty, then this instance has been modified,
* but has not yet been written out to storage (file/database)
*/
gboolean dirty;
/* True iff this instance has never been committed. */
gboolean infant;
};
struct _QofInstanceClass
{
GObjectClass parent_class;
};
/** Return the GType of a QofInstance */
GType qof_instance_get_type(void);
/** Initialise the settings associated with an instance */
void qof_instance_init_data (QofInstance *, QofIdType, QofBook *);
/** Return the book pointer */
QofBook * qof_instance_get_book (const QofInstance *);
@@ -81,7 +138,7 @@ Timespec qof_instance_get_last_update (const QofInstance *inst);
*/
int qof_instance_version_cmp (const QofInstance *left, const QofInstance *right);
void qof_instance_print_dirty (const QofEntity *entity, gpointer dummy);
void qof_instance_print_dirty (const QofInstance *entity, gpointer dummy);
/** Return value of is_dirty flag */
gboolean qof_instance_is_dirty (QofInstance *);
@@ -101,8 +158,6 @@ gboolean qof_instance_do_free(const QofInstance *inst);
void qof_instance_mark_free(QofInstance *inst);
QofInstance* qof_instance_create (QofIdType type, QofBook *book);
/** Pair things up. This routine inserts a kvp value into each instance
* containing the guid of the other. In this way, if one has one of the
* pair, one can always find the other by looking up it's guid. Typically,

View File

@@ -156,7 +156,7 @@ qof_object_compliance (QofIdTypeConst type_name, gboolean warn)
void
qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofEntityForeachCB cb, gpointer user_data)
QofInstanceForeachCB cb, gpointer user_data)
{
QofCollection *col;
const QofObject *obj;

View File

@@ -104,7 +104,7 @@ struct _QofObject
* provide this routine, as without it, little of interest can
* be done.
*/
void (*foreach)(const QofCollection *, QofEntityForeachCB, gpointer);
void (*foreach)(const QofCollection *, QofInstanceForeachCB, gpointer);
/** Given a particular item of this type, return a printable string.
*/
@@ -160,7 +160,7 @@ void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data);
* be invoked only for those instances stored in the book.
*/
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofEntityForeachCB cb, gpointer user_data);
QofInstanceForeachCB cb, gpointer user_data);
/** Register and lookup backend-specific data for this particular object */
gboolean qof_object_register_backend (QofIdTypeConst type_name,

View File

@@ -809,7 +809,7 @@ static void qof_query_run_cb(QofQueryCB* qcb, gpointer cb_arg)
/* And then iterate over all the objects */
qof_object_foreach (qcb->query->search_for, book,
(QofEntityForeachCB) check_item_cb, qcb);
(QofInstanceForeachCB) check_item_cb, qcb);
}
}

View File

@@ -1450,13 +1450,13 @@ collect_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
}
static void
query_collect_cb(QofEntity* ent, gpointer user_data)
query_collect_cb(QofInstance* ent, gpointer user_data)
{
query_coll_t pdata;
GUID *guid;
guid = guid_malloc();
guid = (GUID*)qof_entity_get_guid(ent);
guid = (GUID*)qof_instance_get_guid(ent);
pdata = (query_coll_t)user_data;
pdata->guids = g_list_append(pdata->guids, guid);
}

View File

@@ -26,16 +26,16 @@
#include "qofreference.h"
static void
entity_set_reference_cb(QofEntity *ent, gpointer user_data)
entity_set_reference_cb(QofInstance *ent, gpointer user_data)
{
void (*reference_setter) (QofEntity*, QofEntity*);
void (*choice_setter) (QofEntity*, QofEntity*);
void (*collect_setter)(QofEntity*, QofCollection*);
QofEntityReference *ref;
void (*reference_setter) (QofInstance*, QofInstance*);
void (*choice_setter) (QofInstance*, QofInstance*);
void (*collect_setter)(QofInstance*, QofCollection*);
QofInstanceReference *ref;
GList *book_ref_list;
QofCollection *coll;
QofIdType type;
QofEntity *reference;
QofInstance *reference;
QofBook *partial_book;
partial_book = (QofBook*)user_data;
@@ -45,8 +45,8 @@ entity_set_reference_cb(QofEntity *ent, gpointer user_data)
book_ref_list = qof_book_get_data(partial_book, ENTITYREFERENCE);
while(book_ref_list)
{
ref = (QofEntityReference*)book_ref_list->data;
if(0 == guid_compare(ref->ref_guid, qof_entity_get_guid(ent)))
ref = (QofInstanceReference*)book_ref_list->data;
if(0 == guid_compare(ref->ref_guid, qof_instance_get_guid(ent)))
{
/* avoid setting the entity's own guid as a reference. */
book_ref_list = g_list_next(book_ref_list);
@@ -56,7 +56,7 @@ entity_set_reference_cb(QofEntity *ent, gpointer user_data)
type = ref->param->param_type;
coll = qof_book_get_collection(partial_book, type);
reference = qof_collection_lookup_entity(coll, ref->ref_guid);
reference_setter = (void(*)(QofEntity*, QofEntity*))ref->param->param_setfcn;
reference_setter = (void(*)(QofInstance*, QofInstance*))ref->param->param_setfcn;
if((reference) && (reference_setter))
{
qof_begin_edit((QofInstance*)ent);
@@ -66,10 +66,10 @@ entity_set_reference_cb(QofEntity *ent, gpointer user_data)
qof_commit_edit((QofInstance*)reference);
}
/* collect and choice handling */
collect_setter = (void(*)(QofEntity*, QofCollection*))ref->param->param_setfcn;
choice_setter = (void(*)(QofEntity*, QofEntity*))ref->param->param_setfcn;
collect_setter = (void(*)(QofInstance*, QofCollection*))ref->param->param_setfcn;
choice_setter = (void(*)(QofInstance*, QofInstance*))ref->param->param_setfcn;
if ((0 == safe_strcmp(ref->param->param_type, QOF_TYPE_COLLECT)) &&
(0 == guid_compare(qof_entity_get_guid(ent), ref->ent_guid)) &&
(0 == guid_compare(qof_instance_get_guid(ent), ref->ent_guid)) &&
(0 == safe_strcmp(ref->type, ent->e_type)))
{
QofCollection *temp_col;
@@ -113,18 +113,18 @@ set_each_type(QofObject *obj, gpointer user_data)
qof_object_foreach(obj->e_type, book, entity_set_reference_cb, book);
}
static QofEntityReference*
create_reference(QofEntity *ent, const QofParam *param)
static QofInstanceReference*
create_reference(QofInstance *ent, const QofParam *param)
{
QofEntityReference *reference;
QofEntity *ref_ent;
QofInstanceReference *reference;
QofInstance *ref_ent;
const GUID *cm_guid;
char cm_sa[GUID_ENCODING_LENGTH + 1];
gchar *cm_string;
ref_ent = (QofEntity*)param->param_getfcn(ent, param);
ref_ent = QOF_INSTANCE(param->param_getfcn(ent, param));
if(!ref_ent) { return NULL; }
reference = g_new0(QofEntityReference, 1);
reference = g_new0(QofInstanceReference, 1);
reference->type = ent->e_type;
reference->ref_guid = g_new(GUID, 1);
reference->ent_guid = &ent->guid;
@@ -133,7 +133,7 @@ create_reference(QofEntity *ent, const QofParam *param)
reference->choice_type = ref_ent->e_type;
}
reference->param = param;
cm_guid = qof_entity_get_guid(ref_ent);
cm_guid = qof_instance_get_guid(ref_ent);
guid_to_string_buff(cm_guid, cm_sa);
cm_string = g_strdup(cm_sa);
if(TRUE == string_to_guid(cm_string, reference->ref_guid)) {
@@ -144,8 +144,8 @@ create_reference(QofEntity *ent, const QofParam *param)
return NULL;
}
QofEntityReference*
qof_entity_get_reference_from(QofEntity *ent, const QofParam *param)
QofInstanceReference*
qof_instance_get_reference_from(QofInstance *ent, const QofParam *param)
{
g_return_val_if_fail(param, NULL);
param = qof_class_get_parameter(ent->e_type, param->param_name);

View File

@@ -39,15 +39,15 @@ a partial book and then convert the same book to a standard book.
Different backends have different requirements for a complete book - some
(like gnucash) are highly customised to that application - however all complete
QofBooks must be self-contained, only a partial book uses QofEntityReference.
QofBooks must be self-contained, only a partial book uses QofInstanceReference.
To retain the relationships between entities, including between a partial and
a complete book, QofEntityReference data is stored in the QofBook. This data
a complete book, QofInstanceReference data is stored in the QofBook. This data
should be read by backends that support partial books so that the exported
data contains the GUID and QofIdType of the referenced entity. Even if that
entity does not then exist within the partial book, it can be located when
the partial book is merged back into the original, complete, book. (Remember
that given the GUID and QofIdType of any QofEntity it is possible to uniquely
that given the GUID and QofIdType of any QofInstance it is possible to uniquely
identify that entity in another book.)
Entities in partial books may need to refer to the entities that remain within
@@ -81,7 +81,7 @@ When the file is imported back in, the list needs to be rebuilt.
The QSF backend rebuilds the references by linking to real entities.
Other backends can process the list in similar ways.
The list stores the QofEntityReference to the referenced entity -
The list stores the QofInstanceReference to the referenced entity -
a struct that contains the GUID and the QofIdType of the referenced
entity as well as the parameter used to obtain the reference.
@@ -102,7 +102,7 @@ It is used by the entity copy functions and by the QSF backend.
Creates a GList stored in the Book hashtable to contain
repeated references for a single entity.
*/
typedef struct qof_entity_reference {
typedef struct qof_instance_reference {
QofIdType choice_type;/**< Used when the reference is a QOF_TYPE_CHOICE type
- stores the actual type of the reference from the list of available choices. */
QofIdType type; /**< The type of the original entity -
@@ -112,7 +112,7 @@ typedef struct qof_entity_reference {
const QofParam *param; /**< The parameter of the original entity to use
to get or set the reference. */
const GUID *ent_guid; /**< The GUID of the original entity. */
}QofEntityReference;
}QofInstanceReference;
/** \brief Adds a new reference to the partial book data hash.
@@ -122,17 +122,17 @@ If the book is not already marked as partial, it will be marked as
partial.
*/
void
qof_session_update_reference_list(QofSession *session, QofEntityReference *reference);
qof_session_update_reference_list(QofSession *session, QofInstanceReference *reference);
/** Used as the key value for the QofBook data hash.
*
* Retrieved later by QSF (or any other suitable backend) to
* rebuild the references from the QofEntityReference struct
* rebuild the references from the QofInstanceReference struct
* that contains the QofIdType and GUID of the referenced entity
* of the original QofBook as well as the parameter data and the
* GUID of the original entity.
* */
#define ENTITYREFERENCE "QofEntityReference"
#define ENTITYREFERENCE "QofInstanceReference"
/** \brief Flag indicating a partial QofBook.
@@ -143,11 +143,11 @@ books can be used to save this session.
#define PARTIAL_QOFBOOK "PartialQofBook"
/** \brief Read QofEntityReference data for this book and set values.
/** \brief Read QofInstanceReference data for this book and set values.
@param book The partial book containing the referenceList
The referenceList is a GList of QofEntityReference structures that contain
The referenceList is a GList of QofInstanceReference structures that contain
the GUID of each end of a reference. e.g. where one entity refers to another.
The referenceList is used in partial books to store relationships between
@@ -173,14 +173,14 @@ void qof_book_set_references(QofBook *book);
been checked \b NOT to be QOF_TYPE_COLLECT or other known QOF types
because this function expects to return a single reference and
a collect parameter would need to return a list of references, other
parameters would not return a viable QofEntity. (A string cannot be
parameters would not return a viable QofInstance. (A string cannot be
cast to an entity.)
Used in the preparation of a partial QofBook when the known entity
(the one currently being copied into the partial book) refers to
any other entity, usually as a parent or child.
The routine calls the param_getfcn of the supplied parameter,
which must return an object (QofEntity*), not a known QOF data type, to
which must return an object (QofInstance*), not a known QOF data type, to
retrieve the referenced entity and therefore the GUID. The GUID of
both entities are stored in the reference which then needs to be added
to the reference list which is added to the partial book data hash.
@@ -199,10 +199,10 @@ the integrity of the partial book during sequential copy operations.
@param ent The known entity.
@param param The parameter to use to get the referenced entity.
@return FALSE on error, otherwise a pointer to the QofEntityReference.
@return FALSE on error, otherwise a pointer to the QofInstanceReference.
*/
QofEntityReference*
qof_entity_get_reference_from(QofEntity *ent, const QofParam *param);
QofInstanceReference*
qof_instance_get_reference_from(QofInstance *ent, const QofParam *param);
/** @} */
/** @} */

View File

@@ -38,7 +38,7 @@ struct _QofSession
* an Entity. NOTE: THIS IS NOT AN ENTITY! THE ONLY PART OF ENTITY
* THAT IS VALID IS E_TYPE!
*/
QofEntity entity;
QofInstance entity;
/* A book holds pointers to the various types of datasets.
* A session may have multiple books. */

View File

@@ -305,15 +305,15 @@ qof_session_get_url (QofSession *session)
/* =============================================================== */
typedef struct qof_entity_copy_data {
QofEntity *from;
QofEntity *to;
typedef struct qof_instance_copy_data {
QofInstance *from;
QofInstance *to;
QofParam *param;
GList *referenceList;
GSList *param_list;
QofSession *new_session;
gboolean error;
}QofEntityCopyData;
}QofInstanceCopyData;
static void
qof_book_set_partial(QofBook *book)
@@ -328,7 +328,7 @@ qof_book_set_partial(QofBook *book)
}
void
qof_session_update_reference_list(QofSession *session, QofEntityReference *reference)
qof_session_update_reference_list(QofSession *session, QofInstanceReference *reference)
{
QofBook *book;
GList *book_ref_list;
@@ -341,12 +341,12 @@ qof_session_update_reference_list(QofSession *session, QofEntityReference *refer
}
static void
qof_entity_param_cb(QofParam *param, gpointer data)
qof_instance_param_cb(QofParam *param, gpointer data)
{
QofEntityCopyData *qecd;
QofInstanceCopyData *qecd;
g_return_if_fail(data != NULL);
qecd = (QofEntityCopyData*)data;
qecd = (QofInstanceCopyData*)data;
g_return_if_fail(param != NULL);
/* KVP doesn't need a set routine to be copied. */
if(0 == safe_strcmp(param->param_type, QOF_TYPE_KVP)) {
@@ -359,24 +359,24 @@ qof_entity_param_cb(QofParam *param, gpointer data)
}
static void
col_ref_cb (QofEntity* ref_ent, gpointer user_data)
col_ref_cb (QofInstance* ref_ent, gpointer user_data)
{
QofEntityReference *ref;
QofEntityCopyData *qecd;
QofEntity *ent;
QofInstanceReference *ref;
QofInstanceCopyData *qecd;
QofInstance *ent;
const GUID *cm_guid;
char cm_sa[GUID_ENCODING_LENGTH + 1];
gchar *cm_string;
qecd = (QofEntityCopyData*)user_data;
qecd = (QofInstanceCopyData*)user_data;
ent = qecd->from;
ref = g_new0(QofEntityReference, 1);
ref = g_new0(QofInstanceReference, 1);
ref->type = ent->e_type;
ref->ref_guid = g_new(GUID, 1);
ref->ent_guid = &ent->guid;
ref->param = qof_class_get_parameter(ent->e_type,
qecd->param->param_name);
cm_guid = qof_entity_get_guid(ref_ent);
cm_guid = qof_instance_get_guid(ref_ent);
guid_to_string_buff(cm_guid, cm_sa);
cm_string = g_strdup(cm_sa);
if(TRUE == string_to_guid(cm_string, ref->ref_guid)) {
@@ -386,11 +386,11 @@ col_ref_cb (QofEntity* ref_ent, gpointer user_data)
}
static void
qof_entity_foreach_copy(gpointer data, gpointer user_data)
qof_instance_foreach_copy(gpointer data, gpointer user_data)
{
QofEntity *importEnt, *targetEnt/*, *referenceEnt*/;
QofEntityCopyData *context;
QofEntityReference *reference;
QofInstance *importEnt, *targetEnt/*, *referenceEnt*/;
QofInstanceCopyData *context;
QofInstanceReference *reference;
gboolean registered_type;
/* cm_ prefix used for variables that hold the data to commit */
QofParam *cm_param;
@@ -399,26 +399,26 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data)
KvpFrame *cm_kvp;
QofCollection *cm_col;
/* function pointers and variables for parameter getters that don't use pointers normally */
gnc_numeric cm_numeric, (*numeric_getter) (QofEntity*, QofParam*);
double cm_double, (*double_getter) (QofEntity*, QofParam*);
gboolean cm_boolean, (*boolean_getter) (QofEntity*, QofParam*);
gint32 cm_i32, (*int32_getter) (QofEntity*, QofParam*);
gint64 cm_i64, (*int64_getter) (QofEntity*, QofParam*);
Timespec cm_date, (*date_getter) (QofEntity*, QofParam*);
gnc_numeric cm_numeric, (*numeric_getter) (QofInstance*, QofParam*);
double cm_double, (*double_getter) (QofInstance*, QofParam*);
gboolean cm_boolean, (*boolean_getter) (QofInstance*, QofParam*);
gint32 cm_i32, (*int32_getter) (QofInstance*, QofParam*);
gint64 cm_i64, (*int64_getter) (QofInstance*, QofParam*);
Timespec cm_date, (*date_getter) (QofInstance*, QofParam*);
/* function pointers to the parameter setters */
void (*string_setter) (QofEntity*, const char*);
void (*date_setter) (QofEntity*, Timespec);
void (*numeric_setter) (QofEntity*, gnc_numeric);
void (*guid_setter) (QofEntity*, const GUID*);
void (*double_setter) (QofEntity*, double);
void (*boolean_setter) (QofEntity*, gboolean);
void (*i32_setter) (QofEntity*, gint32);
void (*i64_setter) (QofEntity*, gint64);
void (*char_setter) (QofEntity*, char*);
void (*kvp_frame_setter) (QofEntity*, KvpFrame*);
void (*string_setter) (QofInstance*, const char*);
void (*date_setter) (QofInstance*, Timespec);
void (*numeric_setter) (QofInstance*, gnc_numeric);
void (*guid_setter) (QofInstance*, const GUID*);
void (*double_setter) (QofInstance*, double);
void (*boolean_setter) (QofInstance*, gboolean);
void (*i32_setter) (QofInstance*, gint32);
void (*i64_setter) (QofInstance*, gint64);
void (*char_setter) (QofInstance*, char*);
void (*kvp_frame_setter) (QofInstance*, KvpFrame*);
g_return_if_fail(user_data != NULL);
context = (QofEntityCopyData*) user_data;
context = (QofInstanceCopyData*) user_data;
cm_date.tv_nsec = 0;
cm_date.tv_sec = 0;
importEnt = context->from;
@@ -430,63 +430,63 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data)
if(safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0) {
cm_string = (gchar*)cm_param->param_getfcn(importEnt, cm_param);
if(cm_string) {
string_setter = (void(*)(QofEntity*, const char*))cm_param->param_setfcn;
string_setter = (void(*)(QofInstance*, const char*))cm_param->param_setfcn;
if(string_setter != NULL) { string_setter(targetEnt, cm_string); }
}
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))cm_param->param_getfcn;
date_getter = (Timespec (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
cm_date = date_getter(importEnt, cm_param);
date_setter = (void(*)(QofEntity*, Timespec))cm_param->param_setfcn;
date_setter = (void(*)(QofInstance*, Timespec))cm_param->param_setfcn;
if(date_setter != NULL) { date_setter(targetEnt, cm_date); }
registered_type = TRUE;
}
if((safe_strcmp(cm_param->param_type, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(cm_param->param_type, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*))cm_param->param_getfcn;
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
cm_numeric = numeric_getter(importEnt, cm_param);
numeric_setter = (void(*)(QofEntity*, gnc_numeric))cm_param->param_setfcn;
numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_param->param_setfcn;
if(numeric_setter != NULL) { numeric_setter(targetEnt, cm_numeric); }
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_GUID) == 0) {
cm_guid = (const GUID*)cm_param->param_getfcn(importEnt, cm_param);
guid_setter = (void(*)(QofEntity*, const GUID*))cm_param->param_setfcn;
guid_setter = (void(*)(QofInstance*, const GUID*))cm_param->param_setfcn;
if(guid_setter != NULL) { guid_setter(targetEnt, cm_guid); }
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_i32 = int32_getter(importEnt, cm_param);
i32_setter = (void(*)(QofEntity*, gint32))cm_param->param_setfcn;
i32_setter = (void(*)(QofInstance*, gint32))cm_param->param_setfcn;
if(i32_setter != NULL) { i32_setter(targetEnt, cm_i32); }
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_INT64) == 0) {
int64_getter = (gint64 (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_i64 = int64_getter(importEnt, cm_param);
i64_setter = (void(*)(QofEntity*, gint64))cm_param->param_setfcn;
i64_setter = (void(*)(QofInstance*, gint64))cm_param->param_setfcn;
if(i64_setter != NULL) { i64_setter(targetEnt, cm_i64); }
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_DOUBLE) == 0) {
double_getter = (double (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
double_getter = (double (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_double = double_getter(importEnt, cm_param);
double_setter = (void(*)(QofEntity*, double))cm_param->param_setfcn;
double_setter = (void(*)(QofInstance*, double))cm_param->param_setfcn;
if(double_setter != NULL) { double_setter(targetEnt, cm_double); }
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_BOOLEAN) == 0){
boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) cm_param->param_getfcn;
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
cm_boolean = boolean_getter(importEnt, cm_param);
boolean_setter = (void(*)(QofEntity*, gboolean))cm_param->param_setfcn;
boolean_setter = (void(*)(QofInstance*, gboolean))cm_param->param_setfcn;
if(boolean_setter != NULL) { boolean_setter(targetEnt, cm_boolean); }
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_KVP) == 0) {
cm_kvp = (KvpFrame*)cm_param->param_getfcn(importEnt,cm_param);
kvp_frame_setter = (void(*)(QofEntity*, KvpFrame*))cm_param->param_setfcn;
kvp_frame_setter = (void(*)(QofInstance*, KvpFrame*))cm_param->param_setfcn;
if(kvp_frame_setter != NULL) { kvp_frame_setter(targetEnt, cm_kvp); }
else
{
@@ -500,7 +500,7 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data)
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_CHAR) == 0) {
cm_char = (gchar*)cm_param->param_getfcn(importEnt,cm_param);
char_setter = (void(*)(QofEntity*, char*))cm_param->param_setfcn;
char_setter = (void(*)(QofInstance*, char*))cm_param->param_setfcn;
if(char_setter != NULL) { char_setter(targetEnt, cm_char); }
registered_type = TRUE;
}
@@ -514,10 +514,10 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data)
registered_type = TRUE;
}
if(registered_type == FALSE) {
/* referenceEnt = (QofEntity*)cm_param->param_getfcn(importEnt, cm_param);
/* referenceEnt = QOF_INSTANCE(cm_param->param_getfcn(importEnt, cm_param));
if(!referenceEnt) { return; }
if(!referenceEnt->e_type) { return; }*/
reference = qof_entity_get_reference_from(importEnt, cm_param);
reference = qof_instance_get_reference_from(importEnt, cm_param);
if(reference) {
qof_session_update_reference_list(context->new_session, reference);
}
@@ -525,9 +525,9 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data)
}
static gboolean
qof_entity_guid_match(QofSession *new_session, QofEntity *original)
qof_instance_guid_match(QofSession *new_session, QofInstance *original)
{
QofEntity *copy;
QofInstance *copy;
const GUID *g;
QofIdTypeConst type;
QofBook *targetBook;
@@ -537,7 +537,7 @@ qof_entity_guid_match(QofSession *new_session, QofEntity *original)
g_return_val_if_fail(original != NULL, FALSE);
targetBook = qof_session_get_book(new_session);
g_return_val_if_fail(targetBook != NULL, FALSE);
g = qof_entity_get_guid(original);
g = qof_instance_get_guid(original);
type = g_strdup(original->e_type);
coll = qof_book_get_collection(targetBook, type);
copy = qof_collection_lookup_entity(coll, g);
@@ -546,19 +546,19 @@ qof_entity_guid_match(QofSession *new_session, QofEntity *original)
}
static void
qof_entity_list_foreach(gpointer data, gpointer user_data)
qof_instance_list_foreach(gpointer data, gpointer user_data)
{
QofEntityCopyData *qecd;
QofEntity *original;
QofInstanceCopyData *qecd;
QofInstance *original;
QofInstance *inst;
QofBook *book;
const GUID *g;
g_return_if_fail(data != NULL);
original = (QofEntity*)data;
original = QOF_INSTANCE(data);
g_return_if_fail(user_data != NULL);
qecd = (QofEntityCopyData*)user_data;
if(qof_entity_guid_match(qecd->new_session, original)) { return; }
qecd = (QofInstanceCopyData*)user_data;
if(qof_instance_guid_match(qecd->new_session, original)) { return; }
qecd->from = original;
if(!qof_object_compliance(original->e_type, FALSE))
{
@@ -573,69 +573,69 @@ qof_entity_list_foreach(gpointer data, gpointer user_data)
qecd->error = TRUE;
return;
}
qecd->to = &inst->entity;
g = qof_entity_get_guid(original);
qof_entity_set_guid(qecd->to, g);
qecd->to = inst;
g = qof_instance_get_guid(original);
qof_instance_set_guid(qecd->to, g);
if(qecd->param_list != NULL) {
g_slist_free(qecd->param_list);
qecd->param_list = NULL;
}
qof_class_param_foreach(original->e_type, qof_entity_param_cb, qecd);
qof_class_param_foreach(original->e_type, qof_instance_param_cb, qecd);
qof_begin_edit(inst);
g_slist_foreach(qecd->param_list, qof_entity_foreach_copy, qecd);
g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd);
qof_commit_edit(inst);
}
static void
qof_entity_coll_foreach(QofEntity *original, gpointer user_data)
qof_instance_coll_foreach(QofInstance *original, gpointer user_data)
{
QofEntityCopyData *qecd;
QofInstanceCopyData *qecd;
const GUID *g;
QofBook *targetBook;
QofCollection *coll;
QofEntity *copy;
QofInstance *copy;
g_return_if_fail(user_data != NULL);
copy = NULL;
qecd = (QofEntityCopyData*)user_data;
qecd = (QofInstanceCopyData*)user_data;
targetBook = qof_session_get_book(qecd->new_session);
g = qof_entity_get_guid(original);
g = qof_instance_get_guid(original);
coll = qof_book_get_collection(targetBook, original->e_type);
copy = qof_collection_lookup_entity(coll, g);
if(copy) { qecd->error = TRUE; }
}
static void
qof_entity_coll_copy(QofEntity *original, gpointer user_data)
qof_instance_coll_copy(QofInstance *original, gpointer user_data)
{
QofEntityCopyData *qecd;
QofInstanceCopyData *qecd;
QofBook *book;
QofInstance *inst;
const GUID *g;
g_return_if_fail(user_data != NULL);
qecd = (QofEntityCopyData*)user_data;
qecd = (QofInstanceCopyData*)user_data;
book = qof_session_get_book(qecd->new_session);
if(!qof_object_compliance(original->e_type, TRUE)) { return; }
inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
qecd->to = &inst->entity;
qecd->to = inst;
qecd->from = original;
g = qof_entity_get_guid(original);
qof_entity_set_guid(qecd->to, g);
g = qof_instance_get_guid(original);
qof_instance_set_guid(qecd->to, g);
qof_begin_edit(inst);
g_slist_foreach(qecd->param_list, qof_entity_foreach_copy, qecd);
g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd);
qof_commit_edit(inst);
}
gboolean
qof_entity_copy_to_session(QofSession* new_session, QofEntity* original)
qof_instance_copy_to_session(QofSession* new_session, QofInstance* original)
{
QofEntityCopyData qecd;
QofInstanceCopyData qecd;
QofInstance *inst;
QofBook *book;
if(!new_session || !original) { return FALSE; }
if(qof_entity_guid_match(new_session, original)) { return FALSE; }
if(qof_instance_guid_match(new_session, original)) { return FALSE; }
if(!qof_object_compliance(original->e_type, TRUE)) { return FALSE; }
qof_event_suspend();
qecd.param_list = NULL;
@@ -643,31 +643,31 @@ qof_entity_copy_to_session(QofSession* new_session, QofEntity* original)
qecd.new_session = new_session;
qof_book_set_partial(book);
inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
qecd.to = &inst->entity;
qecd.to = inst;
qecd.from = original;
qof_entity_set_guid(qecd.to, qof_entity_get_guid(original));
qof_instance_set_guid(qecd.to, qof_instance_get_guid(original));
qof_begin_edit(inst);
qof_class_param_foreach(original->e_type, qof_entity_param_cb, &qecd);
qof_class_param_foreach(original->e_type, qof_instance_param_cb, &qecd);
qof_commit_edit(inst);
if(g_slist_length(qecd.param_list) == 0) { return FALSE; }
g_slist_foreach(qecd.param_list, qof_entity_foreach_copy, &qecd);
g_slist_foreach(qecd.param_list, qof_instance_foreach_copy, &qecd);
g_slist_free(qecd.param_list);
qof_event_resume();
return TRUE;
}
gboolean qof_entity_copy_list(QofSession *new_session, GList *entity_list)
gboolean qof_instance_copy_list(QofSession *new_session, GList *entity_list)
{
QofEntityCopyData *qecd;
QofInstanceCopyData *qecd;
if(!new_session || !entity_list) { return FALSE; }
ENTER (" list=%d", g_list_length(entity_list));
qecd = g_new0(QofEntityCopyData, 1);
qecd = g_new0(QofInstanceCopyData, 1);
qof_event_suspend();
qecd->param_list = NULL;
qecd->new_session = new_session;
qof_book_set_partial(qof_session_get_book(new_session));
g_list_foreach(entity_list, qof_entity_list_foreach, qecd);
g_list_foreach(entity_list, qof_instance_list_foreach, qecd);
qof_event_resume();
if(qecd->error)
{
@@ -679,9 +679,9 @@ gboolean qof_entity_copy_list(QofSession *new_session, GList *entity_list)
}
gboolean
qof_entity_copy_coll(QofSession *new_session, QofCollection *entity_coll)
qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll)
{
QofEntityCopyData qecd;
QofInstanceCopyData qecd;
g_return_val_if_fail(new_session, FALSE);
if(!entity_coll) { return FALSE; }
@@ -689,10 +689,10 @@ qof_entity_copy_coll(QofSession *new_session, QofCollection *entity_coll)
qecd.param_list = NULL;
qecd.new_session = new_session;
qof_book_set_partial(qof_session_get_book(qecd.new_session));
qof_collection_foreach(entity_coll, qof_entity_coll_foreach, &qecd);
qof_collection_foreach(entity_coll, qof_instance_coll_foreach, &qecd);
qof_class_param_foreach(qof_collection_get_type(entity_coll),
qof_entity_param_cb, &qecd);
qof_collection_foreach(entity_coll, qof_entity_coll_copy, &qecd);
qof_instance_param_cb, &qecd);
qof_collection_foreach(entity_coll, qof_instance_coll_copy, &qecd);
if(qecd.param_list != NULL) { g_slist_free(qecd.param_list); }
qof_event_resume();
return TRUE;
@@ -707,25 +707,25 @@ struct recurse_s
};
static void
recurse_collection_cb (QofEntity *ent, gpointer user_data)
recurse_collection_cb (QofInstance *ent, gpointer user_data)
{
struct recurse_s *store;
if(user_data == NULL) { return; }
store = (struct recurse_s*)user_data;
if(!ent || !store) { return; }
store->success = qof_entity_copy_to_session(store->session, ent);
store->success = qof_instance_copy_to_session(store->session, ent);
if(store->success) {
store->ent_list = g_list_append(store->ent_list, ent);
}
}
static void
recurse_ent_cb(QofEntity *ent, gpointer user_data)
recurse_ent_cb(QofInstance *ent, gpointer user_data)
{
GList *ref_list, *i, *j, *ent_list, *child_list;
QofParam *ref_param;
QofEntity *ref_ent, *child_ent;
QofInstance *ref_ent, *child_ent;
QofSession *session;
struct recurse_s *store;
gboolean success;
@@ -756,17 +756,17 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data)
}
continue;
}
ref_ent = (QofEntity*)ref_param->param_getfcn(ent, ref_param);
ref_ent = QOF_INSTANCE(ref_param->param_getfcn(ent, ref_param));
if((ref_ent)&&(ref_ent->e_type))
{
store->success = qof_entity_copy_to_session(session, ref_ent);
store->success = qof_instance_copy_to_session(session, ref_ent);
if(store->success) { ent_list = g_list_append(ent_list, ref_ent); }
}
}
for(i = ent_list; i != NULL; i = i->next)
{
if(i->data == NULL) { continue; }
child_ent = (QofEntity*)i->data;
child_ent = QOF_INSTANCE(i->data);
if(child_ent == NULL) { continue; }
ref_list = qof_class_get_referenceList(child_ent->e_type);
for(j = ref_list; j != NULL; j = j->next)
@@ -776,7 +776,7 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data)
ref_ent = ref_param->param_getfcn(child_ent, ref_param);
if(ref_ent != NULL)
{
success = qof_entity_copy_to_session(session, ref_ent);
success = qof_instance_copy_to_session(session, ref_ent);
if(success) { child_list = g_list_append(child_list, ref_ent); }
}
}
@@ -784,7 +784,7 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data)
for(i = child_list; i != NULL; i = i->next)
{
if(i->data == NULL) { continue; }
ref_ent = (QofEntity*)i->data;
ref_ent = QOF_INSTANCE(i->data);
if(ref_ent == NULL) { continue; }
ref_list = qof_class_get_referenceList(ref_ent->e_type);
for(j = ref_list; j != NULL; j = j->next)
@@ -794,14 +794,14 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data)
child_ent = ref_param->param_getfcn(ref_ent, ref_param);
if(child_ent != NULL)
{
qof_entity_copy_to_session(session, child_ent);
qof_instance_copy_to_session(session, child_ent);
}
}
}
}
gboolean
qof_entity_copy_coll_r(QofSession *new_session, QofCollection *coll)
qof_instance_copy_coll_r(QofSession *new_session, QofCollection *coll)
{
struct recurse_s store;
gboolean success;
@@ -812,12 +812,12 @@ qof_entity_copy_coll_r(QofSession *new_session, QofCollection *coll)
store.success = success;
store.ent_list = NULL;
store.ref_list = qof_class_get_referenceList(qof_collection_get_type(coll));
success = qof_entity_copy_coll(new_session, coll);
success = qof_instance_copy_coll(new_session, coll);
if(success){ qof_collection_foreach(coll, recurse_ent_cb, &store); }
return success;
}
gboolean qof_entity_copy_one_r(QofSession *new_session, QofEntity *ent)
gboolean qof_instance_copy_one_r(QofSession *new_session, QofInstance *ent)
{
struct recurse_s store;
QofCollection *coll;
@@ -828,7 +828,7 @@ gboolean qof_entity_copy_one_r(QofSession *new_session, QofEntity *ent)
success = TRUE;
store.success = success;
store.ref_list = qof_class_get_referenceList(ent->e_type);
success = qof_entity_copy_to_session(new_session, ent);
success = qof_instance_copy_to_session(new_session, ent);
if(success == TRUE) {
coll = qof_book_get_collection(qof_session_get_book(new_session), ent->e_type);
if(coll) { qof_collection_foreach(coll, recurse_ent_cb, &store); }

View File

@@ -264,7 +264,7 @@ using the GnuCash XML v2 file backend will be switched to QSF.
Copied entities are identical to the source entity, all parameters
defined with ::QofAccessFunc and ::QofSetterFunc in QOF are copied
and the ::GUID of the original ::QofEntity is set in the new entity.
and the ::GUID of the original ::QofInstance is set in the new entity.
Sessions containing copied entities are intended for use
as mechanisms for data export.
@@ -280,19 +280,19 @@ see \ref BookMerge
*/
/** \brief Copy a single QofEntity to another session
/** \brief Copy a single QofInstance to another session
Checks first that no entity in the session book contains
the GUID of the source entity.
@param new_session - the target session
@param original - the QofEntity* to copy
@param original - the QofInstance* to copy
@return FALSE without copying if the session contains an entity
with the same GUID already, otherwise TRUE.
*/
gboolean qof_entity_copy_to_session(QofSession* new_session, QofEntity* original);
gboolean qof_instance_copy_to_session(QofSession* new_session, QofInstance* original);
/** @brief Copy a GList of entities to another session
@@ -301,18 +301,18 @@ with the same GUID as any of the source entities - there is
no support for handling collisions, instead use \ref BookMerge
Note that the GList (e.g. from ::qof_sql_query_run) can contain
QofEntity pointers of any ::QofIdType, in any sequence. As long
as all members of the list are ::QofEntity*, and all GUID's are
QofInstance pointers of any ::QofIdType, in any sequence. As long
as all members of the list are ::QofInstance*, and all GUID's are
unique, the list can be copied.
@param new_session - the target session
@param entity_list - a GList of QofEntity pointers of any type(s).
@param entity_list - a GList of QofInstance pointers of any type(s).
@return FALSE, without copying, if new_session contains any entities
with the same GUID. Otherwise TRUE.
*/
gboolean qof_entity_copy_list(QofSession *new_session, GList *entity_list);
gboolean qof_instance_copy_list(QofSession *new_session, GList *entity_list);
/** @brief Copy a QofCollection of entities.
@@ -327,12 +327,12 @@ no support for handling collisions - instead, use \ref BookMerge
with the same GUID. Otherwise TRUE.
*/
gboolean qof_entity_copy_coll(QofSession *new_session, QofCollection *entity_coll);
gboolean qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll);
/** \brief Recursively copy a collection of entities to a session.
\note This function creates a <b>partial QofBook</b>. See
::qof_entity_copy_to_session for more information.
::qof_instance_copy_to_session for more information.
The QofBook in the new_session must \b not contain any entities
with the same GUID as any entities to be copied - there is
@@ -341,7 +341,7 @@ no support for handling collisions - instead, use \ref BookMerge
Objects can be defined solely in terms of QOF data types or
as a mix of data types and other objects, which may in turn
include other objects. These references can be copied recursively
down to the third level. See ::QofEntityReference.
down to the third level. See ::QofInstanceReference.
\note This is a deep recursive copy - every referenced entity is copied
to the new session, including all parameters. The starting point is all
@@ -358,7 +358,7 @@ one of the references fails to copy.
*/
gboolean
qof_entity_copy_coll_r(QofSession *new_session, QofCollection *coll);
qof_instance_copy_coll_r(QofSession *new_session, QofCollection *coll);
/** \brief Recursively copy a single entity to a new session.
@@ -369,7 +369,7 @@ copied.
This is a deep copy - all parameters of all referenced entities are copied. If
the top level entity has no references, this is identical to
::qof_entity_copy_to_session.
::qof_instance_copy_to_session.
@param ent A single entity that may or may not have references.
@@ -380,7 +380,7 @@ the top level entity has no references, this is identical to
one of the references fails to copy.
*/
gboolean
qof_entity_copy_one_r(QofSession *new_session, QofEntity *ent);
qof_instance_copy_one_r(QofSession *new_session, QofInstance *ent);
/** @}
*/

View File

@@ -52,7 +52,7 @@ struct _QofSqlQuery
char * single_global_tablename;
KvpFrame *kvp_join;
GList *param_list;
QofEntity *inserted_entity;
QofInstance *inserted_entity;
};
/* ========================================================== */
@@ -573,7 +573,7 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
QofIdTypeConst type;
sql_insert_statement *sis;
gboolean registered_type;
QofEntity *ent;
QofInstance *ent;
struct tm query_time;
time_t query_time_t;
/* cm_ prefix used for variables that hold the data to commit */
@@ -588,15 +588,15 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
/* KvpFrame *cm_kvp;
KvpValue *cm_value;
KvpValueType cm_type;*/
void (*string_setter) (QofEntity*, const char*);
void (*date_setter) (QofEntity*, Timespec);
void (*numeric_setter) (QofEntity*, gnc_numeric);
void (*double_setter) (QofEntity*, double);
void (*boolean_setter) (QofEntity*, gboolean);
void (*i32_setter) (QofEntity*, gint32);
void (*i64_setter) (QofEntity*, gint64);
void (*char_setter) (QofEntity*, char);
/* void (*kvp_frame_setter) (QofEntity*, KvpFrame*);*/
void (*string_setter) (QofInstance*, const char*);
void (*date_setter) (QofInstance*, Timespec);
void (*numeric_setter) (QofInstance*, gnc_numeric);
void (*double_setter) (QofInstance*, double);
void (*boolean_setter) (QofInstance*, gboolean);
void (*i32_setter) (QofInstance*, gint32);
void (*i64_setter) (QofInstance*, gint64);
void (*char_setter) (QofInstance*, char);
/* void (*kvp_frame_setter) (QofInstance*, KvpFrame*);*/
g_return_if_fail(param || insert_string || query);
ent = query->inserted_entity;
@@ -606,12 +606,12 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
ENTER (" param=%s param_type=%s type=%s content=%s",
param->param_name, param->param_type, type, insert_string);
if(safe_strcmp(param->param_type, QOF_TYPE_STRING) == 0) {
string_setter = (void(*)(QofEntity*, const char*))param->param_setfcn;
string_setter = (void(*)(QofInstance*, const char*))param->param_setfcn;
if(string_setter != NULL) { string_setter(ent, insert_string); }
registered_type = TRUE;
}
if(safe_strcmp(param->param_type, QOF_TYPE_DATE) == 0) {
date_setter = (void(*)(QofEntity*, Timespec))param->param_setfcn;
date_setter = (void(*)(QofInstance*, Timespec))param->param_setfcn;
strptime(insert_string, QOF_UTC_DATE_FORMAT, &query_time);
query_time_t = mktime(&query_time);
timespecFromTime_t(&cm_date, query_time_t);
@@ -619,7 +619,7 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
}
if((safe_strcmp(param->param_type, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(param->param_type, QOF_TYPE_DEBCRED) == 0)) {
numeric_setter = (void(*)(QofEntity*, gnc_numeric))param->param_setfcn;
numeric_setter = (void(*)(QofInstance*, gnc_numeric))param->param_setfcn;
string_to_gnc_numeric(insert_string, &cm_numeric);
if(numeric_setter != NULL) { numeric_setter(ent, cm_numeric); }
}
@@ -633,10 +633,10 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
/* reference_type = xmlGetProp(node, QSF_OBJECT_TYPE);
if(0 == safe_strcmp(QOF_PARAM_GUID, reference_type))
{
qof_entity_set_guid(qsf_ent, cm_guid);
qof_instance_set_guid(qsf_ent, cm_guid);
}
else {
reference = qof_entity_get_reference_from(qsf_ent, cm_param);
reference = qof_instance_get_reference_from(qsf_ent, cm_param);
if(reference) {
params->referenceList = g_list_append(params->referenceList, reference);
}
@@ -646,7 +646,7 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
errno = 0;
cm_i32 = (gint32)strtol (insert_string, &tail, 0);
if(errno == 0) {
i32_setter = (void(*)(QofEntity*, gint32))param->param_setfcn;
i32_setter = (void(*)(QofInstance*, gint32))param->param_setfcn;
if(i32_setter != NULL) { i32_setter(ent, cm_i32); }
}
else
@@ -663,7 +663,7 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
errno = 0;
cm_i64 = strtoll(insert_string, &tail, 0);
if(errno == 0) {
i64_setter = (void(*)(QofEntity*, gint64))param->param_setfcn;
i64_setter = (void(*)(QofInstance*, gint64))param->param_setfcn;
if(i64_setter != NULL) { i64_setter(ent, cm_i64); }
}
else
@@ -680,7 +680,7 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
errno = 0;
cm_double = strtod(insert_string, &tail);
if(errno == 0) {
double_setter = (void(*)(QofEntity*, double))param->param_setfcn;
double_setter = (void(*)(QofInstance*, double))param->param_setfcn;
if(double_setter != NULL) { double_setter(ent, cm_double); }
}
}
@@ -691,7 +691,7 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
cm_boolean = TRUE;
}
else { cm_boolean = FALSE; }
boolean_setter = (void(*)(QofEntity*, gboolean))param->param_setfcn;
boolean_setter = (void(*)(QofInstance*, gboolean))param->param_setfcn;
if(boolean_setter != NULL) { boolean_setter(ent, cm_boolean); }
}
if(safe_strcmp(param->param_type, QOF_TYPE_KVP) == 0) {
@@ -699,7 +699,7 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
}
if(safe_strcmp(param->param_type, QOF_TYPE_CHAR) == 0) {
cm_char = *insert_string;
char_setter = (void(*)(QofEntity*, char))param->param_setfcn;
char_setter = (void(*)(QofInstance*, char))param->param_setfcn;
if(char_setter != NULL) { char_setter(ent, cm_char); }
}
LEAVE (" ");
@@ -725,7 +725,7 @@ qof_query_set_insert_table(QofSqlQuery *query)
}
}
static QofEntity*
static QofInstance*
qof_query_insert(QofSqlQuery *query)
{
GList *field_list, *value_list, *cur;
@@ -755,7 +755,7 @@ qof_query_insert(QofSqlQuery *query)
LEAVE (" unable to create instance of type %s", type);
return NULL;
}
query->inserted_entity = &inst->entity;
query->inserted_entity = inst;
value_list = sis->values;
for (field_list = sis->fields; field_list != NULL; field_list = field_list->next)
{

View File

@@ -62,7 +62,7 @@ search loop, aka a 'join', which is not currently supported in the
underlying QofQuery code.
However, by repeating queries and adding the entities to a new session using
::qof_entity_copy_list, a series of queries can be added to a single
::qof_instance_copy_list, a series of queries can be added to a single
book. e.g. You can insert multiple entities and save out as a QSF XML
file or use multiple SELECT queries to build a precise list - this
can be used to replicate most of the functionality of a SQL join.
@@ -77,7 +77,7 @@ When combined with a foreach callback on the value of param_id for each
entity in the QofBook, you can produce the effect of a join from running
the two SELECT queries for each value of param_id held in 'value'.
See ::QofEntityForeachCB and ::qof_object_foreach.
See ::QofInstanceForeachCB and ::qof_object_foreach.
Date queries handle full date and time strings, using the format
exported by the QSF backend. To query dates and times, convert

View File

@@ -306,7 +306,7 @@ qof_commit_edit_part2(QofInstance *inst,
}
if (dirty && qof_get_alt_dirty_mode() &&
!(inst->infant && inst->do_free)) {
qof_collection_mark_dirty(inst->entity.collection);
qof_collection_mark_dirty(inst->collection);
qof_book_mark_dirty(inst->book);
}
inst->infant = FALSE;
@@ -397,7 +397,7 @@ qof_util_string_cache_insert(gconstpointer key)
}
gchar*
qof_util_param_as_string(QofEntity *ent, QofParam *param)
qof_util_param_as_string(QofInstance *ent, QofParam *param)
{
gchar *param_string, param_date[MAX_DATE_LENGTH];
gchar param_sa[GUID_ENCODING_LENGTH + 1];
@@ -405,13 +405,13 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
QofType paramType;
const GUID *param_guid;
time_t param_t;
gnc_numeric param_numeric, (*numeric_getter) (QofEntity*, QofParam*);
Timespec param_ts, (*date_getter) (QofEntity*, QofParam*);
double param_double, (*double_getter) (QofEntity*, QofParam*);
gboolean param_boolean, (*boolean_getter) (QofEntity*, QofParam*);
gint32 param_i32, (*int32_getter) (QofEntity*, QofParam*);
gint64 param_i64, (*int64_getter) (QofEntity*, QofParam*);
gchar param_char, (*char_getter) (QofEntity*, QofParam*);
gnc_numeric param_numeric, (*numeric_getter) (QofInstance*, QofParam*);
Timespec param_ts, (*date_getter) (QofInstance*, QofParam*);
double param_double, (*double_getter) (QofInstance*, QofParam*);
gboolean param_boolean, (*boolean_getter) (QofInstance*, QofParam*);
gint32 param_i32, (*int32_getter) (QofInstance*, QofParam*);
gint64 param_i64, (*int64_getter) (QofInstance*, QofParam*);
gchar param_char, (*char_getter) (QofInstance*, QofParam*);
param_string = NULL;
known_type = FALSE;
@@ -423,7 +423,7 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))param->param_getfcn;
date_getter = (Timespec (*)(QofInstance*, QofParam*))param->param_getfcn;
param_ts = date_getter(ent, param);
param_t = timespecToTime_t(param_ts);
qof_strftime(param_date, MAX_DATE_LENGTH,
@@ -434,7 +434,7 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
}
if((safe_strcmp(paramType, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*)) param->param_getfcn;
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*)) param->param_getfcn;
param_numeric = numeric_getter(ent, param);
param_string = g_strdup(gnc_numeric_to_string(param_numeric));
known_type = TRUE;
@@ -448,28 +448,28 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) param->param_getfcn;
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) param->param_getfcn;
param_i32 = int32_getter(ent, param);
param_string = g_strdup_printf("%d", param_i32);
known_type = TRUE;
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_INT64) == 0) {
int64_getter = (gint64 (*)(QofEntity*, QofParam*)) param->param_getfcn;
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) param->param_getfcn;
param_i64 = int64_getter(ent, param);
param_string = g_strdup_printf("%"G_GINT64_FORMAT, param_i64);
known_type = TRUE;
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_DOUBLE) == 0) {
double_getter = (double (*)(QofEntity*, QofParam*)) param->param_getfcn;
double_getter = (double (*)(QofInstance*, QofParam*)) param->param_getfcn;
param_double = double_getter(ent, param);
param_string = g_strdup_printf("%f", param_double);
known_type = TRUE;
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_BOOLEAN) == 0){
boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) param->param_getfcn;
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) param->param_getfcn;
param_boolean = boolean_getter(ent, param);
/* Boolean values need to be lowercase for QSF validation. */
if(param_boolean == TRUE) { param_string = g_strdup("true"); }
@@ -491,7 +491,7 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_CHAR) == 0) {
char_getter = (gchar (*)(QofEntity*, QofParam*)) param->param_getfcn;
char_getter = (gchar (*)(QofInstance*, QofParam*)) param->param_getfcn;
param_char = char_getter(ent, param);
known_type = TRUE;
return g_strdup_printf("%c", param_char);
@@ -507,7 +507,7 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
}
if(safe_strcmp(paramType, QOF_TYPE_CHOICE) == 0)
{
QofEntity *child = NULL;
QofInstance *child = NULL;
child = param->param_getfcn(ent, param);
if(!child) { return param_string; }
known_type = TRUE;
@@ -534,7 +534,7 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
}
if(!known_type)
{
QofEntity *child = NULL;
QofInstance *child = NULL;
child = param->param_getfcn(ent, param);
if(!child) { return param_string; }
return g_strdup(qof_object_printable(child->e_type, child));
@@ -545,7 +545,8 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
void
qof_init (void)
{
qof_log_init();
g_type_init();
qof_log_init();
qof_util_get_string_cache ();
guid_init ();
qof_object_initialize ();

View File

@@ -235,7 +235,7 @@ gint qof_util_bool_to_int (const gchar * val);
The returned string must be freed by the caller.
*/
gchar* qof_util_param_as_string(QofEntity *ent, QofParam *param);
gchar* qof_util_param_as_string(QofInstance *ent, QofParam *param);
/** The QOF String Cache:
*