LibQof now use GType to manages objects, sustituting the actual strig type based; this means less memory and faster object type test and memory usage.

QofBackend now use GError to store backend erros, you need to call commit and begin edit with a parameter GError** to get any error in these calls, or use 
the QofBackend's API to set and delete this errors.

QofEntity and QofInstance have been merged together and now QofInstance (may in the future GncObject) manages the GUID and the book the object belongs to.
The type system use the GObject's GType system to know the object's types.

QofObject and QofClass have been modified in order to fit in the new type system, but the work pretends in the next milestones deprecate them and eventualy delete
from the GC code.

KvpValue and KvpFrame doesn't change to much, just a few to fit in the new type system; but now we can sustitud KvpValue with GValue with out afect KvpFrame,
even better, this will save too many code here and there to manage the KvpValue type system (this is diferent from the Qof object type system), and get unifed type
system using just GType. All the objects managed by KvpValue has its own GType, some derived from GObject, some from QofInstance (derived from GObject too), 
and some derived from a GBoxed (any struct type).

The file backend, has been changed in order to fit in the new type system too, but actualy it breaks the load of previews files saved in the old type system,
becouse when you save a file some data is saved with its type's name, but I'll add code to manage this converting the old type names to the new type's name. The
names used in GType is in order to avoid any problem with any previews existing one, just using a prefix Gnc or Qof in each name, this is a practice in GLib and I think we need to follow, i. e. the a type name "book" is "QofBook" and "account" is "GncAccount", this is for all the objects derived from GObject and GBoxed.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gobject-engine-dev@15690 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Daniel Espinosa committed 2007-03-08 13:23:14 +00:00
1 parent 56dd0775da
commit 0b121228ca
65 files changed
+2711 -1814

No files matched your search

+131 -130
View File
@@ -40,9 +40,9 @@
#include "strptime.h"
#endif
#define QSF_TYPE_BINARY "binary"
#define QSF_TYPE_GLIST "glist"
#define QSF_TYPE_FRAME "frame"
#define QSF_TYPE_BINARY GNC_TYPE_BINARY
#define QSF_TYPE_GLIST GNC_TYPE_GLIST
#define QSF_TYPE_FRAME GNC_TYPE_KVP_FRAME
static QofLogModule log_module = QOF_MOD_QSF;
static void qsf_object_commitCB(gpointer key, gpointer value, gpointer data);
@@ -172,18 +172,18 @@ qsf_param_init(qsf_param *params)
params->qsf_define_hash = g_hash_table_new(g_str_hash, g_str_equal);
params->qsf_calculate_hash = g_hash_table_new(g_str_hash, g_str_equal);
params->referenceList = NULL;
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_STRING);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_GUID);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_BOOLEAN);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_NUMERIC);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_DATE);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_INT32);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_INT64);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_DOUBLE);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_CHAR);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_KVP);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_COLLECT);
params->supported_types = g_slist_append(params->supported_types, QOF_TYPE_CHOICE);
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_STRING));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_GUID));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_BOOLEAN));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_NUMERIC));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_DATE));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_INT32));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_INT64));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_DOUBLE));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_CHAR));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_KVP));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_COLLECT));
params->supported_types = g_slist_append(params->supported_types, GINT_TO_POINTER (QOF_TYPE_CHOICE));
qsf_time_precision = "%j";
qsf_time_now_t = time(NULL);
qsf_ts = g_new(Timespec, 1);
@@ -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;
if(qof_object_is_choice(ent->e_type)) { type = ref->choice_type; }
ref = (QofInstanceReference*)params->referenceList->data;
if(qof_object_is_choice(G_OBJECT_TYPE (ent))) { 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 = qof_collection_lookup_element (coll, ref->ref_guid);
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);
@@ -513,19 +513,19 @@ qsf_object_sequence(QofParam *qof_param, gpointer data)
checklist = g_slist_copy(params->supported_types);
for(result = checklist; result != NULL; result = result->next)
{
if(0 == safe_strcmp((QofIdType)result->data, qof_param->param_type))
if((QofIdType)result->data == qof_param->param_type)
{
params->knowntype = TRUE;
}
}
g_slist_free(checklist);
if(0 == safe_strcmp(qof_param->param_type, params->qof_type))
if(qof_param->param_type == params->qof_type)
{
params->qsf_sequence = g_slist_append(params->qsf_sequence, qof_param);
params->knowntype = TRUE;
}
/* handle params->qof_type = QOF_TYPE_GUID and qof_param->param_type != known type */
if(0 == safe_strcmp(params->qof_type, QOF_TYPE_GUID)
if((params->qof_type == QOF_TYPE_GUID)
&& (params->knowntype == FALSE))
{
params->qsf_sequence = g_slist_append(params->qsf_sequence, qof_param);
@@ -544,7 +544,7 @@ qsf_supported_parameters(gpointer type, gpointer user_data)
g_return_if_fail(user_data != NULL);
params = (qsf_param*) user_data;
params->qof_type = (QofIdType)type;
params->qof_type = GPOINTER_TO_INT (type);
params->knowntype = FALSE;
qof_class_param_foreach(params->qof_obj_type, qsf_object_sequence, params);
}
@@ -552,15 +552,15 @@ qsf_supported_parameters(gpointer type, gpointer user_data)
static KvpValueType
qsf_to_kvp_helper(const char *type_string)
{
if(0 == safe_strcmp(QOF_TYPE_INT64, type_string)) { return KVP_TYPE_GINT64; }
if(0 == safe_strcmp(QOF_TYPE_DOUBLE, type_string)) { return KVP_TYPE_DOUBLE; }
if(0 == safe_strcmp(QOF_TYPE_NUMERIC, type_string)) { return KVP_TYPE_NUMERIC; }
if(0 == safe_strcmp(QOF_TYPE_STRING, type_string)) { return KVP_TYPE_STRING; }
if(0 == safe_strcmp(QOF_TYPE_GUID, type_string)) { return KVP_TYPE_GUID; }
if(0 == safe_strcmp(QOF_TYPE_DATE, type_string)) { return KVP_TYPE_TIMESPEC; }
if(0 == safe_strcmp(QSF_TYPE_BINARY, type_string)) { return KVP_TYPE_BINARY; }
if(0 == safe_strcmp(QSF_TYPE_GLIST, type_string)) { return KVP_TYPE_GLIST; }
if(0 == safe_strcmp(QSF_TYPE_FRAME, type_string)) { return KVP_TYPE_FRAME; }
if(0 == safe_strcmp(g_type_name(QOF_TYPE_INT64), type_string)) { return KVP_TYPE_GINT64; }
if(0 == safe_strcmp(g_type_name(QOF_TYPE_DOUBLE), type_string)) { return KVP_TYPE_DOUBLE; }
if(0 == safe_strcmp(g_type_name(QOF_TYPE_NUMERIC), type_string)) { return KVP_TYPE_NUMERIC; }
if(0 == safe_strcmp(g_type_name(QOF_TYPE_STRING), type_string)) { return KVP_TYPE_STRING; }
if(0 == safe_strcmp(g_type_name(QOF_TYPE_GUID), type_string)) { return KVP_TYPE_GUID; }
if(0 == safe_strcmp(g_type_name(QOF_TYPE_DATE), type_string)) { return KVP_TYPE_TIMESPEC; }
if(0 == safe_strcmp(g_type_name(QSF_TYPE_BINARY), type_string)) { return KVP_TYPE_BINARY; }
if(0 == safe_strcmp(g_type_name(QSF_TYPE_GLIST), type_string)) { return KVP_TYPE_GLIST; }
if(0 == safe_strcmp(g_type_name(QSF_TYPE_FRAME), type_string)) { return KVP_TYPE_FRAME; }
return 0;
}
@@ -578,7 +578,7 @@ kvp_value_to_qof_type_helper(KvpValueType n)
case KVP_TYPE_BINARY : { return QSF_TYPE_BINARY; break; }
case KVP_TYPE_GLIST : { return QSF_TYPE_GLIST; break; }
case KVP_TYPE_FRAME : { return QSF_TYPE_FRAME; break; }
default : { return NULL; }
default : { return G_TYPE_INVALID; }
}
}
@@ -612,12 +612,12 @@ qsf_from_kvp_helper(const gchar *path, KvpValue *content, gpointer data)
node = xmlAddChild(params->output_node, xmlNewNode(params->qsf_ns,
BAD_CAST qof_param->param_type));
xmlNodeAddContent(node, BAD_CAST kvp_value_to_bare_string(content));
xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
xmlNewProp(node, BAD_CAST g_type_name (QSF_OBJECT_TYPE), BAD_CAST qof_param->param_name);
full_path = g_strconcat(params->full_kvp_path, "/", path, NULL);
xmlNewProp(node, BAD_CAST QSF_OBJECT_KVP, BAD_CAST full_path);
xmlNewProp(node, BAD_CAST QSF_OBJECT_VALUE,
BAD_CAST kvp_value_to_qof_type_helper(n));
PINFO (" set %s", kvp_value_to_qof_type_helper(n));
PINFO (" set %s", g_type_name (kvp_value_to_qof_type_helper(n)));
break;
}
case KVP_TYPE_FRAME:
@@ -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,11 +654,11 @@ 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);
xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
xmlNewProp(node, BAD_CAST g_type_name (QSF_OBJECT_TYPE), BAD_CAST qof_param->param_name);
}
/******* reference handling ***********/
@@ -666,28 +666,28 @@ 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);
if((0 == guid_compare(bb->ent_guid, aa->ent_guid))
&&(0 == safe_strcmp(bb->type, aa->type))
&&(0 == safe_strcmp(bb->param->param_name, aa->param->param_name)))
g_return_val_if_fail((aa->type != G_TYPE_INVALID), 1);
if((0 == guid_compare(bb->inst_guid, aa->inst_guid))
&&((bb->type == aa->type))
&&(bb->param->param_name == aa->param->param_name))
{
return 0;
}
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,9 +718,9 @@ 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->type = g_strdup(ent->e_type);
starter = g_new(QofInstanceReference, 1);
starter->inst_guid = qof_instance_get_guid(ent);
starter->type = G_OBJECT_TYPE (ent);
starter->param = ref_param;
starter->ref_guid = NULL;
copy_list = g_list_copy(params->referenceList);
@@ -739,25 +739,25 @@ reference_list_lookup(gpointer data, gpointer user_data)
g_free(ref_name);
}
else {
ent = (QofEntity*)ref_param->param_getfcn(ent, ref_param);
ent = (QofInstance*)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)))
if((ref_param->param_type == QOF_TYPE_COLLECT) ||
(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);
xmlNewProp(node, BAD_CAST g_type_name (QSF_OBJECT_TYPE), BAD_CAST ref_param->param_name);
}
}
/*=====================================
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;
@@ -783,7 +783,7 @@ qsf_entity_foreach(QofEntity *ent, gpointer data)
choice_ent = NULL;
object_node = xmlNewChild(params->book_node, params->qsf_ns,
BAD_CAST QSF_OBJECT_TAG, NULL);
xmlNewProp(object_node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST ent->e_type);
xmlNewProp(object_node, BAD_CAST g_type_name (QSF_OBJECT_TYPE), BAD_CAST G_OBJECT_TYPE (ent));
string_buffer = g_strdup_printf("%i", param_count);
xmlNewProp(object_node, BAD_CAST QSF_OBJECT_COUNT, BAD_CAST string_buffer);
g_free(string_buffer);
@@ -791,27 +791,27 @@ qsf_entity_foreach(QofEntity *ent, gpointer data)
while(param_list != NULL) {
qof_param = (QofParam*)param_list->data;
g_return_if_fail(qof_param != NULL);
if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_GUID))
if(qof_param->param_type == QOF_TYPE_GUID)
{
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);
xmlNodeAddContent(node, BAD_CAST string_buffer);
xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE , BAD_CAST QOF_PARAM_GUID);
xmlNewProp(node, BAD_CAST g_type_name (QSF_OBJECT_TYPE) , BAD_CAST QOF_PARAM_GUID);
g_free(string_buffer);
own_guid = TRUE;
}
params->qsf_ent = ent;
params->output_node = object_node;
ref = qof_class_get_referenceList(ent->e_type);
ref = qof_class_get_referenceList(G_OBJECT_TYPE (ent));
if(ref != NULL) {
g_list_foreach(ref, reference_list_lookup, params);
}
}
if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_COLLECT))
if(qof_param->param_type == QOF_TYPE_COLLECT)
{
qsf_coll = qof_param->param_getfcn(ent, qof_param);
if(qsf_coll) {
@@ -824,26 +824,26 @@ qsf_entity_foreach(QofEntity *ent, gpointer data)
param_list = g_slist_next(param_list);
continue;
}
if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_CHOICE))
if(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 = (QofInstance*)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);
xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
xmlNewProp(node, BAD_CAST "name", BAD_CAST choice_ent->e_type);
xmlNewProp(node, BAD_CAST g_type_name (QSF_OBJECT_TYPE), BAD_CAST qof_param->param_name);
xmlNewProp(node, BAD_CAST "name", BAD_CAST g_type_name (G_OBJECT_TYPE (choice_ent)));
g_free(string_buffer);
param_list = g_slist_next(param_list);
continue;
}
if(0 == safe_strcmp(qof_param->param_type, QOF_TYPE_KVP))
if(qof_param->param_type == QOF_TYPE_KVP)
{
qsf_kvp = (KvpFrame*)qof_param->param_getfcn(ent,qof_param);
if(kvp_frame_is_empty(qsf_kvp)) { LEAVE(" "); return; }
@@ -861,7 +861,7 @@ qsf_entity_foreach(QofEntity *ent, gpointer data)
node = xmlAddChild(object_node, xmlNewNode(ns, BAD_CAST qof_param->param_type));
string_buffer = g_strdup(qof_book_merge_param_as_string(qof_param, ent));
xmlNodeAddContent(node, BAD_CAST string_buffer);
xmlNewProp(node, BAD_CAST QSF_OBJECT_TYPE, BAD_CAST qof_param->param_name);
xmlNewProp(node, BAD_CAST g_type_name (QSF_OBJECT_TYPE), BAD_CAST qof_param->param_name);
g_free(string_buffer);
}
}
@@ -881,7 +881,7 @@ qsf_foreach_obj_type(QofObject *qsf_obj, gpointer data)
params = (qsf_param*) data;
/* Skip unsupported objects */
if((qsf_obj->create == NULL)||(qsf_obj->foreach == NULL)){
PINFO (" qsf_obj QOF support failed %s", qsf_obj->e_type);
PINFO (" qsf_obj QOF support failed %s", g_type_name (qsf_obj->e_type));
return;
}
params->qof_obj_type = qsf_obj->e_type;
@@ -889,7 +889,7 @@ qsf_foreach_obj_type(QofObject *qsf_obj, gpointer data)
book = params->book;
support = g_slist_copy(params->supported_types);
g_slist_foreach(support,qsf_supported_parameters, params);
qof_object_foreach(qsf_obj->e_type, book, qsf_entity_foreach, params);
qof_book_foreach( book, qsf_obj->e_type, qsf_entity_foreach, params);
}
/*=====================================================
@@ -916,7 +916,7 @@ qofbook_to_qsf(QofBook *book, qsf_param *params)
node = xmlNewChild(top_node, params->qsf_ns, BAD_CAST QSF_BOOK_TAG, NULL);
params->book_node = node;
xmlNewProp(node, BAD_CAST QSF_BOOK_COUNT, BAD_CAST "1");
book_guid = qof_book_get_guid(book);
book_guid = qof_instance_get_guid(QOF_INSTANCE (book));
guid_to_string_buff(book_guid, buffer);
xmlNewChild(params->book_node, params->qsf_ns,
BAD_CAST QSF_BOOK_GUID, BAD_CAST 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;
@@ -1096,17 +1096,18 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
memset (&qsf_time, '\0', sizeof(qsf_time));
cm_date.tv_nsec = 0;
cm_date.tv_sec = 0;
obj_type = (gchar*)xmlGetProp(node->parent, BAD_CAST QSF_OBJECT_TYPE);
if(0 == safe_strcasecmp(obj_type, parameter_name)) { return; }
obj_type = g_type_from_name (xmlGetProp(node->parent, BAD_CAST g_type_name (QSF_OBJECT_TYPE)));
/*FIXME: verify parameter_name is the type name as in the old QOF type system, if not then make the correct comparation */
if(0 == safe_strcasecmp(g_type_name (obj_type), parameter_name)) { return; }
cm_setter = qof_class_get_parameter_setter(obj_type, parameter_name);
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;
if(g_type_from_name (qof_type) == QOF_TYPE_STRING) {
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;
if(g_type_from_name (qof_type) == QOF_TYPE_DATE) {
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);
@@ -1117,69 +1118,69 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
if(date_setter != NULL) { date_setter(qsf_ent, cm_date); }
}
}
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;
if((g_type_from_name (qof_type) == QOF_TYPE_NUMERIC) ||
(g_type_from_name (qof_type) == QOF_TYPE_DEBCRED)) {
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); }
}
if(safe_strcmp(qof_type, QOF_TYPE_GUID) == 0) {
if(g_type_from_name (qof_type) == QOF_TYPE_GUID) {
cm_guid = g_new(GUID, 1);
if(TRUE != string_to_guid((char*)xmlNodeGetContent(node), cm_guid))
{
qof_backend_set_error(params->be, ERR_QSF_BAD_OBJ_GUID);
PINFO (" string to guid conversion failed for %s:%s:%s",
xmlNodeGetContent(node), obj_type, qof_type);
xmlNodeGetContent(node), g_type_name (obj_type), qof_type);
return;
}
reference_type = (char*)xmlGetProp(node, BAD_CAST QSF_OBJECT_TYPE);
if(0 == safe_strcmp(QOF_PARAM_GUID, reference_type))
reference_type = g_type_from_name (xmlGetProp(node, BAD_CAST g_type_name (QSF_OBJECT_TYPE)));
if(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);
}
}
}
if(safe_strcmp(qof_type, QOF_TYPE_INT32) == 0) {
if(g_type_from_name (qof_type) == QOF_TYPE_INT32) {
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); }
}
if(safe_strcmp(qof_type, QOF_TYPE_INT64) == 0) {
if(g_type_from_name (qof_type) == QOF_TYPE_INT64) {
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); }
}
if(safe_strcmp(qof_type, QOF_TYPE_DOUBLE) == 0) {
if(g_type_from_name (qof_type) == QOF_TYPE_DOUBLE) {
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); }
}
}
if(safe_strcmp(qof_type, QOF_TYPE_BOOLEAN) == 0){
if(g_type_from_name (qof_type) == QOF_TYPE_BOOLEAN){
if(0 == safe_strcasecmp((gchar*)xmlNodeGetContent(node),
QSF_XML_BOOLEAN_TEST)) {
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) {
if(g_type_from_name (qof_type) == QOF_TYPE_KVP) {
cm_type = qsf_to_kvp_helper((gchar*)xmlGetProp(node, BAD_CAST QSF_OBJECT_VALUE));
if(!cm_type) { return; }
cm_value = string_to_kvp_value((gchar*)xmlNodeGetContent(node), cm_type);
@@ -1187,14 +1188,14 @@ qsf_object_commitCB(gpointer key, gpointer value, gpointer data)
cm_kvp = kvp_frame_set_value(cm_kvp, (gchar*)xmlGetProp(node,
BAD_CAST QSF_OBJECT_KVP), cm_value);
}
if(safe_strcmp(qof_type, QOF_TYPE_COLLECT) == 0) {
if(g_type_from_name (qof_type) == QOF_TYPE_COLLECT) {
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);
type = qof_collection_get_type(qsf_coll);
type = qof_collection_get_g_type(qsf_coll);
cm_guid = g_new(GUID, 1);
if(TRUE != string_to_guid((gchar*)xmlNodeGetContent(node), cm_guid))
{
@@ -1202,24 +1203,24 @@ 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->type = g_strdup(qsf_ent->e_type);
reference = g_new0(QofInstanceReference, 1);
reference->type = G_OBJECT_TYPE (qsf_ent);
reference->ref_guid = cm_guid;
reference->ent_guid = &qsf_ent->guid;
reference->inst_guid = qof_instance_get_guid (qsf_ent);
copy_param = g_new0(QofParam, 1);
copy_param->param_name = g_strdup(cm_param->param_name);
copy_param->param_type = g_strdup(cm_param->param_type);
copy_param->param_type = cm_param->param_type;
reference->param = copy_param;
params->referenceList = g_list_append(params->referenceList, reference);
}
if(safe_strcmp(qof_type, QOF_TYPE_CHAR) == 0) {
if(g_type_from_name (qof_type) == QOF_TYPE_CHAR) {
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); }
}
}
+14 -11
View File
@@ -100,16 +100,16 @@ qsf_map_validation_handler(xmlNodePtr child, xmlNsPtr ns, qsf_validator *valid)
}
if(qsf_is_element(child, ns, MAP_OBJECT_TAG)) {
match = NULL;
obj_type = xmlGetProp(child, BAD_CAST MAP_TYPE_ATTR);
match = BAD_CAST g_hash_table_lookup( valid->validation_table, obj_type);
obj_type = g_type_from_name (xmlGetProp(child, BAD_CAST MAP_TYPE_ATTR));
match = BAD_CAST g_hash_table_lookup( valid->validation_table, GINT_TO_POINTER (obj_type));
if(match) {
valid->map_calculated_count++;
if(TRUE == qof_class_is_registered((QofIdTypeConst) obj_type))
{
valid->qof_registered_count++;
PINFO (" %s is to be calculated", obj_type);
PINFO (" %s is to be calculated", g_type_name (obj_type));
}
else { PINFO (" %s to be mapped", obj_type); }
else { PINFO (" %s to be mapped", g_type_name (obj_type)); }
}
}
}
@@ -340,7 +340,7 @@ qsf_map_default_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params )
iterate = xmlGetProp(child, MAP_ITERATE_ATTR);
if(qof_util_bool_to_int(iterate) == 1)
{
params->qof_foreach = xmlGetProp(child, BAD_CAST MAP_E_TYPE);
params->qof_foreach = g_type_from_name (xmlGetProp(child, BAD_CAST MAP_E_TYPE));
}
if(NULL == g_hash_table_lookup(params->qsf_define_hash,
xmlGetProp(child, BAD_CAST MAP_E_TYPE)))
@@ -646,7 +646,10 @@ qsf_add_object_tag(qsf_param *params, gint count)
static gint
identify_source_func(gconstpointer qsf_object, gconstpointer map)
{
return safe_strcmp(((qsf_objects*)qsf_object)->object_type, (QofIdType)map);
if(((qsf_objects*)qsf_object)->object_type == (QofIdType) map)
return TRUE;
else
return FALSE;
}
static void
@@ -739,13 +742,13 @@ qsf_map_object_handler(xmlNodePtr child, xmlNsPtr ns, qsf_param *params)
static void
iterator_cb(xmlNodePtr child, xmlNsPtr ns, qsf_param *params)
{
gchar *object_name;
QofIdType object_name;
/* count the number of iterators in the QSF file */
if(qsf_is_element(child, ns, QSF_OBJECT_TAG))
{
object_name = xmlGetProp(child, QSF_OBJECT_TYPE);
if(0 == safe_strcmp(object_name, params->qof_foreach))
object_name = g_type_from_name (xmlGetProp(child, g_type_name (QSF_OBJECT_TYPE)));
if(object_name == params->qof_foreach)
{
params->foreach_limit++;
}
@@ -793,8 +796,8 @@ qsf_object_convert(xmlDocPtr mapDoc, xmlNodePtr qsf_root, qsf_param *params)
params->lister = NULL;
/* cur_node describes the target object */
if(!qof_class_is_registered(BAD_CAST
xmlGetProp(cur_node, MAP_TYPE_ATTR))) { continue; }
if(!qof_class_is_registered(g_type_from_name (BAD_CAST
xmlGetProp(cur_node, MAP_TYPE_ATTR)))) { continue; }
qsf_add_object_tag(params, params->count);
params->count++;
iter.ns = params->map_ns;
+4 -4
View File
@@ -242,7 +242,7 @@ gboolean is_qsf_object_be(qsf_param *params)
return FALSE;
}
/* skip validation if is_our_qsf_object has already been called. */
if(ERR_QSF_INVALID_OBJ == qof_backend_get_error(params->be)) { return FALSE; }
if(ERR_QSF_INVALID_OBJ == qof_backend_get_error_code (params->be)) { return FALSE; }
if(params->file_type == QSF_UNDEF)
{
doc = xmlParseFile(path);
@@ -262,7 +262,7 @@ gboolean is_qsf_object_be(qsf_param *params)
{
QofBackendError err;
result = is_qsf_object_with_map_be(maps->data, params);
err = qof_backend_get_error(params->be);
err = qof_backend_get_error_code (params->be);
if((err == ERR_BACKEND_NO_ERR) && result)
{
params->map_path = maps->data;
@@ -315,7 +315,7 @@ qsf_object_node_handler(xmlNodePtr child, xmlNsPtr qsf_ns, qsf_param *params)
params->object_set = object_set;
object_set->object_count = 0;
object_set->parameters = g_hash_table_new(g_str_hash, g_str_equal);
object_set->object_type = g_strdup((gchar*)xmlGetProp(child,
object_set->object_type = g_type_from_name ((gchar*)xmlGetProp(child,
BAD_CAST QSF_OBJECT_TYPE));
object_count_s = g_strdup((gchar*)xmlGetProp(child,
BAD_CAST QSF_OBJECT_COUNT));
@@ -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((QofInstance*)params->book, &book_guid);
xmlNewChild(params->output_node, params->qsf_ns,
BAD_CAST QSF_BOOK_GUID, BAD_CAST buffer);
g_free(buffer);
+3 -3
View File
@@ -81,7 +81,7 @@ MAX_DATE_LENGTH itself is defined in gnc-date.h */
described by this QSF object file */
#define QSF_BOOK_COUNT "count" /**< Sequential counter of each book in this file */
#define QSF_OBJECT_TAG "object" /**< Second level child: object tag */
#define QSF_OBJECT_TYPE "type" /**< QSF parameter name for object type specifiers */
#define QSF_OBJECT_TYPE G_TYPE_GTYPE /**< QSF parameter name for object type specifiers */
#define QSF_OBJECT_COUNT "count" /**< Sequential counter for each QSF object
in this file */
#define QSF_XML_VERSION "1.0" /**< The current XML version. */
@@ -358,11 +358,11 @@ typedef struct qsf_metadata
xmlNodePtr book_node; /**< Node for the book. */
xmlNodePtr lister; /**< Comparison node for map defaults. */
xmlNsPtr qsf_ns, map_ns; /**< Separate namespaces for QSF objects and QSF maps. */
const gchar *qof_type; /**< Holds details of the QOF_TYPE */
QofIdType qof_type; /**< Holds details of the QOF_TYPE */
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 */
+2 -2
View File
@@ -21,7 +21,7 @@ libgnc_qof_la_SOURCES = \
qofbackend.c \
qofclass.c \
qofchoice.c \
qofid.c \
qofid.c \
qofinstance.c \
qofquery.c \
qofbook.c \
@@ -51,7 +51,7 @@ qofinclude_HEADERS = \
qofchoice.h \
qofevent.h \
qofgobj.h \
qofid.h \
qofid.h \
qofid-p.h \
qofinstance-p.h \
qofinstance.h \
+1
View File
@@ -84,6 +84,7 @@ and include all specified fields. Remember to use gmtime() NOT localtime()!
#define QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ"
/** Enum for determining a date format */
typedef enum
{
+90
View File
@@ -33,6 +33,96 @@
#include "gnc-numeric.h"
#include "qofmath128.c"
/***************************/
static gpointer
gnc_numeric_copy (gpointer boxed)
{
GncNumeric *src = (GncNumeric*) boxed;
GncNumeric *copy = NULL;
g_return_val_if_fail (src, NULL);
copy = g_new0 (GncNumeric, 1);
copy->num = src->num;
copy->denom = src->denom;
return copy;
}
static void
string_to_numeric (const GValue *src, GValue *dest)
{
/* FIXME: add more checks*/
GncNumeric *numeric;
const gchar *as_string;
g_return_if_fail (G_VALUE_HOLDS_STRING (src) &&
GNC_VALUE_HOLDS_NUMERIC (dest));
as_string = g_value_get_string (src);
numeric = g_new0 (GncNumeric, 1);
string_to_gnc_numeric(as_string, numeric);
g_value_take_boxed (dest, numeric);
}
static void
numeric_to_string (const GValue *src, GValue *dest)
{
gchar *str;
g_return_if_fail (G_VALUE_HOLDS_STRING (dest) &&
GNC_VALUE_HOLDS_NUMERIC (src));
str = gnc_numeric_to_string(*gnc_value_get_numeric (src));
g_value_set_string (dest, str);
}
GType
gnc_numeric_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
type = g_boxed_type_register_static ("GncNumeric",
(GBoxedCopyFunc) gnc_numeric_copy,
NULL);
g_value_register_transform_func (G_TYPE_STRING,
type,
string_to_numeric);
g_value_register_transform_func (type,
G_TYPE_STRING,
numeric_to_string);
}
return type;
}
/**
* gnc_value_get_numeric
* @value: a #GValue whose value we want to get.
*
* Returns: the value stored in @value.
*/
G_CONST_RETURN GncNumeric *
gnc_value_get_numeric (const GValue *value)
{
GncNumeric *val;
g_return_val_if_fail (value && G_IS_VALUE (value), NULL);
g_return_val_if_fail (GNC_VALUE_HOLDS_NUMERIC (value), NULL);
val = (GncNumeric*) g_value_get_boxed (value);
return val;
}
/* static short module = MOD_ENGINE; */
/* =============================================================== */
+19 -9
View File
@@ -49,8 +49,18 @@ See \ref gncnumericexample
#ifndef GNC_NUMERIC_H
#define GNC_NUMERIC_H
#include <glib-object.h>
struct _gnc_numeric
#define GNC_TYPE_NUMERIC (gnc_numeric_get_type())
#define GNC_VALUE_HOLDS_NUMERIC(value) G_VALUE_HOLDS(value, GNC_TYPE_NUMERIC)
typedef struct _GncNumeric GncNumeric;
GType gnc_numeric_get_type (void);
G_CONST_RETURN GncNumeric* gnc_value_get_numeric (const GValue *value);
struct _GncNumeric
{
gint64 num;
gint64 denom;
@@ -59,7 +69,7 @@ struct _gnc_numeric
/** @brief An rational-number type
*
* This is a rational number, defined by numerator and denominator. */
typedef struct _gnc_numeric gnc_numeric;
typedef GncNumeric gnc_numeric;//Backward compatibility
/** @name Arguments Standard Arguments to most functions
@@ -238,8 +248,8 @@ typedef enum {
*/
/** Make a gnc_numeric from numerator and denominator */
static inline
gnc_numeric gnc_numeric_create(gint64 num, gint64 denom) {
gnc_numeric out;
GncNumeric gnc_numeric_create(gint64 num, gint64 denom) {
GncNumeric out;
out.num = num;
out.denom = denom;
return out;
@@ -247,7 +257,7 @@ gnc_numeric gnc_numeric_create(gint64 num, gint64 denom) {
/** create a zero-value gnc_numeric */
static inline
gnc_numeric gnc_numeric_zero(void) { return gnc_numeric_create(0, 1); }
GncNumeric gnc_numeric_zero(void) { return gnc_numeric_create(0, 1); }
/** Convert a floating-point number to a gnc_numeric.
* Both 'denom' and 'how' are used as in arithmetic,
@@ -273,10 +283,10 @@ gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code);
*/
/** Return numerator */
static inline
gint64 gnc_numeric_num(gnc_numeric a) { return a.num; }
gint64 gnc_numeric_num(GncNumeric a) { return a.num; }
/** Return denominator */
static inline
gint64 gnc_numeric_denom(gnc_numeric a) { return a.denom; }
gint64 gnc_numeric_denom(GncNumeric a) { return a.denom; }
/** Convert numeric to floating-point value. */
gdouble gnc_numeric_to_double(gnc_numeric in);
@@ -377,7 +387,7 @@ gnc_numeric gnc_numeric_abs(gnc_numeric a);
* GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
*/
static inline
gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b) {
GncNumeric gnc_numeric_add_fixed(GncNumeric a, GncNumeric b) {
return gnc_numeric_add(a, b, GNC_DENOM_AUTO,
GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
}
@@ -387,7 +397,7 @@ gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b) {
* GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
*/
static inline
gnc_numeric gnc_numeric_sub_fixed(gnc_numeric a, gnc_numeric b) {
GncNumeric gnc_numeric_sub_fixed(GncNumeric a, GncNumeric b) {
return gnc_numeric_sub(a, b, GNC_DENOM_AUTO,
GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
}
+97
View File
@@ -60,6 +60,103 @@ static struct md5_ctx guid_context;
static GMemChunk *guid_memchunk = NULL;
#endif
/***************************/
static gpointer
gnc_guid_copy (gpointer boxed)
{
GUID *src = (GUID*) boxed;
GUID *copy = NULL;
g_return_val_if_fail (src, NULL);
copy = g_memdup (src, sizeof (GUID));
return copy;
}
static void
gnc_guid_free (gpointer boxed)
{
GUID *guid = (GUID*) boxed;
guid_free (guid);
}
static void
gnc_string_to_guid (const GValue *src, GValue *dest)
{
/* FIXME: add more checks*/
GUID *guid;
const gchar *as_string;
g_return_if_fail (G_VALUE_HOLDS_STRING (src) &&
GNC_VALUE_HOLDS_GUID (dest));
as_string = g_value_get_string (src);
guid = g_new0 (GUID, 1);
string_to_guid(as_string, guid);
g_value_take_boxed (dest, guid);
}
static void
gnc_guid_to_string (const GValue *src, GValue *dest)
{
const gchar *str;
g_return_if_fail (G_VALUE_HOLDS_STRING (dest) &&
GNC_VALUE_HOLDS_GUID (src));
str = guid_to_string(gnc_value_get_guid (src));
g_value_set_string (dest, str);
}
GType
gnc_guid_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
type = g_boxed_type_register_static ("GUID",
(GBoxedCopyFunc) gnc_guid_copy,
(GBoxedFreeFunc) gnc_guid_free);
g_value_register_transform_func (G_TYPE_STRING,
type,
gnc_string_to_guid);
g_value_register_transform_func (type,
G_TYPE_STRING,
gnc_guid_to_string);
}
return type;
}
/**
* gnc_value_get_guid
* @value: a #GValue whose value we want to get.
*
* Returns: the value stored in @value.
*/
G_CONST_RETURN GUID*
gnc_value_get_guid (const GValue *value)
{
GUID *val;
g_return_val_if_fail (value && G_IS_VALUE (value), NULL);
g_return_val_if_fail (GNC_VALUE_HOLDS_GUID (value), NULL);
val = (GUID*) g_value_get_boxed (value);
return val;
}
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = QOF_MOD_ENGINE;
+9
View File
@@ -25,6 +25,7 @@
#define GUID_H
#include <stddef.h>
#include <glib-object.h>
/** @addtogroup Entity
@{ */
@@ -59,6 +60,14 @@ typedef union _GUID
} GUID;
#define GNC_TYPE_GUID (gnc_guid_get_type())
#define GNC_VALUE_HOLDS_GUID(value) G_VALUE_HOLDS(value, GNC_TYPE_GUID)
GType gnc_guid_get_type (void);
G_CONST_RETURN GUID* gnc_value_get_guid (const GValue *value);
/** number of characters needed to encode a guid as a string
* not including the null terminator. */
#define GUID_ENCODING_LENGTH 32
+141
View File
@@ -67,10 +67,151 @@ struct _KvpValue
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = QOF_MOD_KVP;
/********************************************
* Binary Type register
*********************************************/
static gpointer
gnc_binary_copy (gpointer boxed)
{
KvpValueBinaryData *src = (KvpValueBinaryData*) boxed;
KvpValueBinaryData *copy = NULL;
g_return_val_if_fail (src, NULL);
copy = g_new0 (KvpValueBinaryData, 1);
copy->data = g_memdup (src->data, src->datasize);
copy->datasize = src->datasize;
return copy;
}
static void
gnc_binary_free (gpointer boxed)
{
KvpValueBinaryData *binary = (KvpValueBinaryData*) boxed;
g_free (binary->data);
g_free (binary);
}
GType
gnc_binary_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
type = g_boxed_type_register_static ("GncBinary",
(GBoxedCopyFunc) gnc_binary_copy,
(GBoxedFreeFunc) gnc_binary_free);
}
return type;
}
/********************************************
* GList Type register
*********************************************/
static gpointer
gnc_glist_copy (gpointer boxed)
{
GList *src = (GList*) boxed;
GList *copy = NULL;
g_return_val_if_fail (src, NULL);
copy = g_list_copy (src);
return copy;
}
static void
gnc_glist_free (gpointer boxed)
{
GList *list = (GList*) boxed;
g_list_free (list);
}
GType
gnc_glist_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
type = g_boxed_type_register_static ("GncGList",
(GBoxedCopyFunc) gnc_glist_copy,
(GBoxedFreeFunc) gnc_glist_free);
}
return type;
}
/* *******************************************************************
* KvpFrame functions
********************************************************************/
static gpointer
gnc_kvp_frame_copy (gpointer boxed)
{
KvpFrame *src = (KvpFrame*) boxed;
KvpFrame *copy = NULL;
g_return_val_if_fail (src, NULL);
copy = kvp_frame_copy(src);;
return copy;
}
static void
gnc_kvp_frame_free (gpointer boxed)
{
KvpFrame *frame = (KvpFrame*) boxed;
g_return_if_fail (frame);
kvp_frame_delete (frame);
}
GType
gnc_kvp_frame_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
type = g_boxed_type_register_static ("KvpFrame",
(GBoxedCopyFunc) gnc_kvp_frame_copy,
(GBoxedFreeFunc) gnc_kvp_frame_free);
}
return type;
}
/**
* gnc_value_get_numeric
* @value: a #GValue whose value we want to get.
*
* Returns: the value stored in @value.
*/
G_CONST_RETURN KvpFrame*
gnc_value_get_kvp_frame (const GValue *value)
{
KvpFrame *val;
g_return_val_if_fail (value && G_IS_VALUE (value), NULL);
g_return_val_if_fail (GNC_VALUE_HOLDS_KVP_FRAME (value), NULL);
val = (KvpFrame*) g_value_get_boxed (value);
return val;
}
/***/
static guint
kvp_hash_func(gconstpointer v)
{
+16
View File
@@ -65,11 +65,27 @@
#include "gnc-numeric.h"
#include "guid.h"
#define QOF_MOD_KVP "qof-kvp"
#define GNC_TYPE_BINARY (gnc_binary_get_type())
#define GNC_TYPE_GLIST (gnc_glist_get_type())
GType gnc_binary_get_type (void);
GType gnc_glist_get_type (void);
/** Opaque frame structure */
typedef struct _KvpFrame KvpFrame;
#define GNC_TYPE_KVP_FRAME (gnc_kvp_frame_get_type())
#define GNC_VALUE_HOLDS_KVP_FRAME(value) G_VALUE_HOLDS(value, GNC_TYPE_KVP_FRAME)
GType gnc_kvp_frame_get_type (void);
G_CONST_RETURN KvpFrame* gnc_value_get_kvp_frame (const GValue *value);
/** A KvpValue is a union with possible types enumerated in the
* KvpValueType enum. */
typedef struct _KvpValue KvpValue;
+2 -1
View File
@@ -77,7 +77,7 @@
/** @} */
#include <glib.h>
#include "qofid.h"
#include "qofinstance.h"
#include "qoflog.h"
#include "gnc-date.h"
#include "gnc-numeric.h"
@@ -102,6 +102,7 @@
#include "qofreference.h"
#include "deprecated.h"
/** allow easy logging of QSF debug messages */
#define QOF_MOD_QSF "gncqof-backend-qsf"
/** allow easy loading of the QSF backend */
+3 -1
View File
@@ -328,6 +328,8 @@ struct QofBackend_s
* data loss, otherwise FALSE.
*/
gboolean (*save_may_clobber_data) (QofBackend *);
GError *error;
KvpFrame* backend_configuration;
gint config_count;
@@ -371,7 +373,7 @@ void qof_backend_set_message(QofBackend *be, const char *format, ...);
/** The qof_backend_get_message() pops the error message string from
* the Backend. This string should be freed with g_free().
*/
char * qof_backend_get_message(QofBackend *be);
gchar * qof_backend_get_message(QofBackend *be);
void qof_backend_init(QofBackend *be);
+38 -110
View File
@@ -46,111 +46,6 @@ static QofLogModule log_module = QOF_MOD_BACKEND;
#define QOF_CONFIG_DESC "desc"
#define QOF_CONFIG_TIP "tip"
static GHashTable *backend_data = NULL;
gboolean qof_backend_register (GType type,
const char *backend_name,
gpointer be_data)
{
GHashTable *ht;
g_return_val_if_fail (object_is_initialized, FALSE);
if (!type_name || *type_name == '\0' ||
!backend_name || *backend_name == '\0' ||
!be_data)
return FALSE;
ht = g_hash_table_lookup (backend_data, backend_name);
/* If it doesn't already exist, create a new table for this backend */
if (!ht) {
ht = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (backend_data, (char *)backend_name, ht);
}
/* Now insert the data */
g_hash_table_insert (ht, (char *)type_name, be_data);
return TRUE;
}
/* *******************************************************************\
* error handling *
\********************************************************************/
/*
THE ERROR HANDLING WILL BE USING GERROR, THIS FUNCTIONS ARE DEPRECATED
*/
void
qof_backend_set_error (QofBackend *be, QofBackendError err)
{
if (!be) return;
/* use stack-push semantics. Only the earliest error counts */
if (ERR_BACKEND_NO_ERR != be->last_err) return;
be->last_err = err;
}
QofBackendError
qof_backend_get_error (QofBackend *be)
{
QofBackendError err;
if (!be) return ERR_BACKEND_NO_BACKEND;
/* use 'stack-pop' semantics */
err = be->last_err;
be->last_err = ERR_BACKEND_NO_ERR;
return err;
}
void
qof_backend_set_message (QofBackend *be, const char *format, ...)
{
va_list args;
char * buffer;
if (!be) return;
/* If there's already something here, free it */
if (be->error_msg) g_free(be->error_msg);
if (!format) {
be->error_msg = NULL;
return;
}
va_start(args, format);
buffer = (char *)g_strdup_vprintf(format, args);
va_end(args);
be->error_msg = buffer;
}
char *
qof_backend_get_message (QofBackend *be)
{
char * msg;
if (!be) return g_strdup("ERR_BACKEND_NO_BACKEND");
if (!be->error_msg) return NULL;
/*
* Just return the contents of the error_msg and then set it to
* NULL. This is necessary, because the Backends don't seem to
* have a destroy_backend function to take care of freeing stuff
* up. The calling function should free the copy.
* Also, this is consistent with the qof_backend_get_error() popping.
*/
msg = be->error_msg;
be->error_msg = NULL;
return msg;
}
/***********************************************************************/
/* Get a clean backend */
void
@@ -176,9 +71,6 @@ qof_backend_init(QofBackend *be)
be->events_pending = NULL;
be->process_events = NULL;
be->last_err = ERR_BACKEND_NO_ERR;
if (be->error_msg) g_free (be->error_msg);
be->error_msg = NULL;
be->percentage = NULL;
be->backend_configuration = kvp_frame_new();
@@ -188,7 +80,7 @@ qof_backend_init(QofBackend *be)
}
void
qof_backend_run_begin(QofBackend *be, QofInstance *inst, GError *error)
qof_backend_run_begin(QofBackend *be, QofInstance *inst, GError **error)
{
if(!be || !inst) { return; }
if(!be->begin) { return; }
@@ -203,7 +95,7 @@ qof_backend_begin_exists(QofBackend *be)
}
void
qof_backend_run_commit(QofBackend *be, QofInstance *inst, GError *error)
qof_backend_run_commit(QofBackend *be, QofInstance *inst, GError **error)
{
if(!be || !inst) { return; }
if(!be->commit) { return; }
@@ -445,4 +337,40 @@ qof_load_backend_library (const char *directory, const char* module_name)
return TRUE;
}
GError*
qof_backend_get_error (QofBackend *be)
{
if (be->error)
return be->error;
else
return NULL;
}
QofBackendError
qof_backend_get_error_code (QofBackend *be)
{
if (be->error)
return be->error->code;
else
return ERR_BACKEND_NO_ERR;
}
void
qof_backend_error_free (QofBackend *be)
{
if(be->error)
g_error_free (be->error);
}
void
qof_backend_set_error (QofBackend *be, QofBackendError code)
{
g_return_if_fail (code == ERR_BACKEND_NO_ERR);
/*FIXME: Add conditionals to set error messages depending on error's code */
be->error = g_error_new (QOF_BACKEND_ERROR, code, "BackendError");
}
/************************* END OF FILE ********************************/
+7 -2
View File
@@ -186,12 +186,17 @@ gboolean qof_backend_commit_exists(QofBackend *be);
/** The qof_backend_set_error() routine pushes an error code onto the error
* stack. (FIXME: the stack is 1 deep in current implementation).
*/
//void qof_backend_set_error (QofBackend *be, QofBackendError err);
void qof_backend_set_error (QofBackend *be, QofBackendError err);
/** The qof_backend_get_error() routine pops an error code off the error stack.
YOU NEED TO PASS A GError* pointer to get the errors in each call
*/
//QofBackendError qof_backend_get_error (QofBackend *be);
GError* qof_backend_get_error (QofBackend *be);
QofBackendError qof_backend_get_error_code (QofBackend *be);
void qof_backend_error_free (QofBackend *be);
/** @name Backend Configuration using KVP
+106 -79
View File
@@ -42,17 +42,25 @@
#include "qof.h"
#include "qofevent-p.h"
#include "qofbackend-p.h"
#include "qofbook.h"
#include "qofbook-p.h"
#include "qofid-p.h"
//#include "qofobject-p.h"
static QofLogModule log_module = QOF_MOD_ENGINE;
static void coll_destroy(gpointer col);
static void book_final (gpointer key, gpointer value, gpointer booq);
/* GObject declarations */
static void qof_book_class_init(QofBookClass *klass);
static void qof_book_init(QofBook *sp);
static void qof_book_init(QofBook *book);
static void qof_book_finalize(GObject *object);
static void qof_book_set_property (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec);
static void qof_book_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
/* Book structure */
struct _QofBookPrivate
@@ -87,8 +95,9 @@ struct _QofBookPrivate
/* state flag: 'y' means 'open for editing',
* 'n' means 'book is closed'
* xxxxx shouldn't this be replaced by the instance editlevel ???
* Why this isn't a gboolean??????? well changing... :-)
*/
char book_open;
gboolean book_open;
/* a flag denoting whether the book is closing down, used to
* help the QOF objects shut down cleanly without maintaining
@@ -116,6 +125,7 @@ typedef enum _QofBookSignalType QofBookSignalType;
enum _QofBookSignalType {
/* Signals */
FIRST_SIGNAL,
LAST_SIGNAL
};
@@ -133,7 +143,7 @@ static guint qof_book_signals[LAST_SIGNAL] = { 0 };
static GObjectClass *parent_class = NULL;
GType
qof_book_get_type()
qof_book_get_type(void)
{
static GType type = 0;
@@ -174,44 +184,48 @@ qof_book_class_init(QofBookClass *klass)
}
static void
qof_book_init(QofBook *obj)
qof_book_init(QofBook *book)
{
/* Initialize private members, etc. */
book->hash_of_collections = g_hash_table_new_full(
book->priv->hash_of_collections = g_hash_table_new_full(
g_int_hash, g_int_equal, NULL, /* key_destroy_func */
coll_destroy); /* value_destroy_func */
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);
book->priv->data_tables = g_hash_table_new (g_str_hash, g_str_equal);
book->priv->data_table_finalizers = g_hash_table_new (g_str_hash, g_str_equal);
book->book_open = 'y';
book->version = 0;
book->idata = 0;
book->priv->book_open = TRUE;
book->priv->version = 0;
book->priv->idata = 0;
}
static void
qof_book_finalize(GObject *object)
{
QofBook *book;
book = QOF_BOOK (object);
/* Free private members, etc. */
book->shutting_down = TRUE;
qof_event_force (&book->inst.entity, QOF_EVENT_DESTROY, NULL); // signal emit with confirmation?
book->priv->shutting_down = TRUE;
qof_event_force ((QofEntity*) QOF_INSTANCE (object), QOF_EVENT_DESTROY, NULL); // signal emit with confirmation?
/* Call the list of finalizers, let them do their thing.
* Do this before tearing into the rest of the book.
*/
g_hash_table_foreach (book->data_table_finalizers, book_final, book);
g_hash_table_foreach (book->priv->data_table_finalizers, book_final, book);
g_hash_table_destroy (book->data_table_finalizers);
book->data_table_finalizers = NULL;
g_hash_table_destroy (book->data_tables);
book->data_tables = NULL;
g_hash_table_destroy (book->priv->data_table_finalizers);
book->priv->data_table_finalizers = NULL;
g_hash_table_destroy (book->priv->data_tables);
book->priv->data_tables = NULL;
g_hash_table_destroy (book->hash_of_collections);
book->hash_of_collections = NULL;
g_hash_table_destroy (book->priv->hash_of_collections);
book->priv->hash_of_collections = NULL;
G_OBJECT_CLASS(parent_class)->finalize(object);
}
@@ -228,7 +242,7 @@ qof_book_set_property (GObject *object,
switch (param_id) {
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID(object,param_id,pspec);
break;
}
}
@@ -260,10 +274,6 @@ static void coll_destroy(gpointer col)
qof_collection_destroy((QofCollection *) col);
}
static void
qof_book_init (QofBook *book)
{
}
QofBook *
qof_book_new (void)
@@ -273,11 +283,14 @@ qof_book_new (void)
ENTER (" ");
book = QOF_BOOK (g_object_new (QOF_TYPE_BOOK, NULL));
qof_object_book_begin (book);
qof_event_gen (&book->inst.entity, QOF_EVENT_CREATE, NULL);
/* FIXME: If book needs KvpFrame, a GUID, but why needs a pointer to himself? */
g_signal_emit_by_name ( QOF_ENTITY (book), "created");
qof_instance_set_book (QOF_INSTANCE (book), book);
qof_event_gen ((QofEntity*) QOF_INSTANCE (book), QOF_EVENT_CREATE, NULL);
g_signal_emit_by_name ( QOF_INSTANCE (book), "created");
LEAVE ("book=%p", book);
return book;
@@ -289,15 +302,10 @@ book_final (gpointer key, gpointer value, gpointer booq)
QofBookFinalCB cb = value;
QofBook *book = booq;
gpointer user_data = g_hash_table_lookup (book->data_tables, key);
gpointer user_data = g_hash_table_lookup (book->priv->data_tables, key);
(*cb) (book, key, user_data);
}
void
qof_book_destroy (QofBook *book)
{
g_object_unref (G_OBJECT (book));
}
/* ====================================================================== */
/* XXX this should probably be calling is_equal callbacks on gncObject */
@@ -317,7 +325,7 @@ qof_book_not_saved (const QofBook *book)
{
if (!book) return FALSE;
return(book->inst.dirty || qof_object_is_dirty (book));
return (qof_instance_is_dirty ( QOF_INSTANCE (book)));
}
void
@@ -327,35 +335,37 @@ qof_book_mark_saved (QofBook *book)
if (!book) return;
was_dirty = book->inst.dirty;
book->inst.dirty = FALSE;
book->dirty_time = 0;
qof_object_mark_clean (book);
was_dirty = qof_instance_is_dirty (QOF_INSTANCE (book));
qof_instance_set_dirty (QOF_INSTANCE (book), TRUE);
book->priv->dirty_time = 0;
qof_instance_mark_clean (QOF_INSTANCE (book));
if (was_dirty) {
if (book->dirty_cb)
book->dirty_cb(book, FALSE, book->dirty_data);
if (book->priv->dirty_cb)
book->priv->dirty_cb(book, FALSE, book->priv->dirty_data);
}
}
void qof_book_mark_dirty (QofBook *book)
void
qof_book_mark_dirty (QofBook *book)
{
gboolean was_dirty;
g_return_if_fail (QOF_IS_BOOK(book));
was_dirty = book->inst.dirty;
book->inst.dirty = TRUE;
was_dirty = qof_instance_is_dirty (QOF_INSTANCE (book));
qof_instance_set_dirty (QOF_INSTANCE (book), TRUE);
if (!was_dirty) {
book->dirty_time = time(NULL);
if (book->dirty_cb)
book->dirty_cb(book, TRUE, book->dirty_data);
book->priv->dirty_time = time(NULL);
if (book->priv->dirty_cb)
book->priv->dirty_cb(book, TRUE, book->priv->dirty_data);
}
}
void
qof_book_print_dirty (const QofBook *book)
{
if (book->inst.dirty)
if (qof_instance_is_dirty (QOF_INSTANCE (book)))
printf("book is dirty.\n");
qof_book_foreach_collection
(book, (QofCollectionForeachCB)qof_collection_print_dirty, NULL);
@@ -364,14 +374,14 @@ qof_book_print_dirty (const QofBook *book)
time_t
qof_book_get_dirty_time (const QofBook *book)
{
return book->dirty_time;
return book->priv->dirty_time;
}
void
qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
{
book->dirty_data = user_data;
book->dirty_cb = cb;
book->priv->dirty_data = user_data;
book->priv->dirty_cb = cb;
}
/* ====================================================================== */
@@ -381,14 +391,14 @@ QofBackend *
qof_book_get_backend (const QofBook *book)
{
if (!book) return NULL;
return book->backend;
return book->priv->backend;
}
gboolean
qof_book_shutting_down (const QofBook *book)
{
if (!book) return FALSE;
return book->shutting_down;
return book->priv->shutting_down;
}
/* ====================================================================== */
@@ -399,7 +409,7 @@ qof_book_set_backend (QofBook *book, QofBackend *be)
{
if (!book) return;
ENTER ("book=%p be=%p", book, be);
book->backend = be;
book->priv->backend = be;
LEAVE (" ");
}
@@ -412,30 +422,35 @@ void qof_book_kvp_changed (QofBook *book)
/* Store arbitrary pointers in the QofBook for data storage extensibility */
/* XXX if data is NULL, we should remove the key from the hash table!
*/
** DEPRECATED FUNCTIONS: use the GObject functions: g_object_set_data, g_object_set_data_full and g_object_get_data
void
qof_book_set_data (QofBook *book, const char *key, gpointer data)
{
if (!book || !key) return;
g_hash_table_insert (book->data_tables, (gpointer)key, data);
g_hash_table_insert (book->priv->data_tables, (gpointer)key, data);
}
void
qof_book_set_data_fin (QofBook *book, const char *key, gpointer data, QofBookFinalCB cb)
{
if (!book || !key) return;
g_hash_table_insert (book->data_tables, (gpointer)key, data);
g_return_if_fail (QOF_IS_BOOK(book) && key);
g_hash_table_insert (book->priv->data_tables, (gpointer)key, data);
if (!cb) return;
g_hash_table_insert (book->data_table_finalizers, (gpointer)key, cb);
g_hash_table_insert (book->priv->data_table_finalizers, (gpointer)key, cb);
}
gpointer
qof_book_get_data (const QofBook *book, const char *key)
{
if (!book || !key) return NULL;
return g_hash_table_lookup (book->data_tables, (gpointer)key);
return g_hash_table_lookup (book->priv->data_tables, (gpointer)key);
}
*/
/* ====================================================================== */
@@ -446,12 +461,12 @@ qof_book_get_collection (const QofBook *book, GType type)
g_return_val_if_fail (QOF_IS_BOOK (book) || G_TYPE_IS_OBJECT (type), NULL);
col = g_hash_table_lookup (book->hash_of_collections, type);
col = g_hash_table_lookup (book->priv->hash_of_collections, GINT_TO_POINTER (type));
if (!QOF_IS_COLLECTION(col)) {
col = qof_collection_new (type);
g_hash_table_insert(book->hash_of_collections,
type, col);
g_hash_table_insert(book->priv->hash_of_collections,
GINT_TO_POINTER (type), col);
}
return col;
}
@@ -479,7 +494,7 @@ qof_book_insert_element (QofBook *book, QofInstance *inst)
QofCollection *coll;
gboolean res;
g_return_val_if_fail (QOF_IS_BOOK (book) && QOF_IS_INSTANCE (inst));
g_return_val_if_fail (QOF_IS_BOOK (book) && QOF_IS_INSTANCE (inst), FALSE);
coll = qof_book_get_collection (book, G_OBJECT_TYPE (inst));
@@ -488,6 +503,17 @@ qof_book_insert_element (QofBook *book, QofInstance *inst)
return res;
}
QofInstance*
qof_book_get_element (QofBook *book, GType type, GUID *guid)
{
QofCollection *col;
col = qof_book_get_collection (book, type);
return qof_collection_lookup_element (col, (const GUID*) guid);
}
struct _iterate {
QofCollectionForeachCB fn;
gpointer data;
@@ -502,10 +528,6 @@ foreach_cb (gpointer key, gpointer item, gpointer arg)
iter->fn (col, iter->data);
}
/** Invoke the indicated callback on each collection in the book. */
typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data);
void qof_book_foreach_collection (const QofBook *, QofCollectionForeachCB, gpointer);
void
qof_book_foreach_collection (const QofBook *book,
QofCollectionForeachCB cb, gpointer user_data)
@@ -518,7 +540,7 @@ qof_book_foreach_collection (const QofBook *book,
iter.fn = cb;
iter.data = user_data;
g_hash_table_foreach (book->hash_of_collections, foreach_cb, &iter);
g_hash_table_foreach (book->priv->hash_of_collections, foreach_cb, &iter);
}
void
@@ -528,6 +550,7 @@ qof_book_foreach (const QofBook *book, GType type, QofInstanceForeachCB cb, gpoi
col = qof_book_get_collection (book, type);
/* By default execute cb in all the objects in the collection holding this object type */
qof_collection_foreach (col, cb, user_data);
}
@@ -536,15 +559,16 @@ qof_book_foreach (const QofBook *book, GType type, QofInstanceForeachCB cb, gpoi
void qof_book_mark_closed (QofBook *book)
{
if(!book) { return; }
book->book_open = 'n';
book->priv->book_open = 'n';
}
gchar qof_book_get_open_marker (const QofBook *book)
gboolean
qof_book_is_open (QofBook *book)
{
if(!QOF_IS_BOOK(book))
return 'n';
return FALSE;
else
return book->book_open;
return book->priv->book_open;
}
gint32 qof_book_get_version (const QofBook *book)
@@ -552,7 +576,7 @@ gint32 qof_book_get_version (const QofBook *book)
if(!QOF_IS_BOOK (book))
return -1;
else
return book->version;
return book->priv->version;
}
guint32 qof_book_get_idata (const QofBook *book)
@@ -560,21 +584,21 @@ guint32 qof_book_get_idata (const QofBook *book)
if(!QOF_IS_BOOK (book))
return 0;
else
return book->idata;
return book->priv->idata;
}
void qof_book_set_version (QofBook *book, gint32 version)
{
g_return_if_fail (QOF_IS_BOOK (book) && version < 0);
book->version = version;
book->priv->version = version;
}
void qof_book_set_idata(QofBook *book, guint32 idata)
{
g_return_if_fail (QOF_IS_BOOK (book) && idata < 0);
book->idata = idata;
book->priv->idata = idata;
}
gint64
@@ -596,7 +620,7 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
}
/* If we've got a backend with a counter method, call it */
be = book->backend;
be = book->priv->backend;
if (be && be->counter)
return ((be->counter)(be, counter_name));
@@ -630,10 +654,12 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
}
/* QofObject function implementation and registration */
/* FIXME: This is broken for now; see if you can register param by param a qof_class;
* or see if we can avoid to use this registration (GObject gives the GObjectClass framework)
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 },
};
@@ -642,5 +668,6 @@ gboolean qof_book_register (void)
return TRUE;
}
*/
/* ========================== END OF FILE =============================== */
+22 -24
View File
@@ -41,8 +41,11 @@
#ifndef QOF_BOOK_H
#define QOF_BOOK_H
#include "qofid.h"
#include "kvp_frame.h"
#include <glib-object.h>
#include "qofinstance.h"
/* GObject declarations */
@@ -56,7 +59,11 @@
typedef struct _QofBookClass QofBookClass;
typedef struct _QofBookPrivate QofBookPrivate;
#ifndef QOF_BOOK_DEFINED
#define QOF_BOOK_DEFINED
typedef struct _QofBook QofBook;
#endif
struct _QofBook {
QofInstance inst;
@@ -70,7 +77,7 @@ struct _QofBookClass {
/* Add Signal Functions Here */
};
GType qof_book_get_type ();
GType qof_book_get_type (void);
/** @brief Encapsulates all the information about a dataset
@@ -95,7 +102,7 @@ QofBook * qof_book_new (void);
/** End any editing sessions associated with book, and free all memory
associated with it. */
//void qof_book_destroy (QofBook *book);
#define qof_book_destroy (b) g_object_unref (b)
#define qof_book_destroy(b) g_object_unref (b)
/** Close a book to editing.
@@ -104,6 +111,8 @@ and once marked closed, books cannnot be marked as open.
*/
void qof_book_mark_closed (QofBook *book);
gboolean qof_book_is_open (QofBook *book);
/** Return The table of entities of the given type.
*
* When an object's constructor calls qof_instance_init(), a
@@ -117,28 +126,18 @@ void qof_book_mark_closed (QofBook *book);
* a non-NULL value. (Unless the system malloc failed (out of
* memory) in which case what happens??).
*/
QofCollection * qof_book_get_collection (const QofBook *, GType);
QofCollection* qof_book_get_collection (const QofBook *book, GType type);
/** Invoke the indicated callback on each collection in the book. */
typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data);
void qof_book_foreach_collection (const QofBook *, QofCollectionForeachCB, gpointer);
typedef void (*QofCollectionForeachCB) (QofCollection *col, gpointer user_data);
void qof_book_foreach_collection (const QofBook *book, QofCollectionForeachCB func, gpointer user_data);
/** Callback type for qof_instance_foreach */
typedef void (*QofInstanceForeachCB) (QofInstance *, gpointer user_data);
typedef void (*QofBookForeachCB) (QofBook *book, gpointer user_data);
void qof_book_foreach (const QofBook *book, GType type, QofInstanceForeachCB func, gpointer data);
void qof_book_foreach (const QofBook *book, GType type, QofInstanceForeachCB cb, gpointer user_data);
/* Deprecated */
#define qof_object_foreach(type, book, cb, data) qof_book_foreach (book, type, cb, data)
/** Return The kvp data for the book.
* Note that the book KVP data is persistent, and is stored/retrieved
* from the file/database. Thus, the book KVP is the correct place to
* store data that needs to be persistent accross sessions (or shared
* between multiple users). To store application runtime data, use
* qof_book_set_data() instead.
*/
#define qof_book_get_slots(book) qof_instance_get_slots(QOF_INSTANCE(book))
#define qof_object_foreach(t, b, f, d) qof_book_foreach(b, t, f, d);
/** The qof_book_set_data() allows arbitrary pointers to structs
* to be stored in QofBook. This is the "preferred" method for
@@ -185,8 +184,7 @@ void qof_book_mark_saved(QofBook *book);
* modified. It can be used by frontend when the used has made a
* change at the book level.
*/
//void qof_book_mark_dirty(QofBook *book);
#define qof_book_mark_dirty(b) qof_instance_set_dirty (QOF_INSTANCE (b), TRUE)
void qof_book_mark_dirty(QofBook *book);
/** This debugging function can be used to traverse the book structure
* and all subsidiary structures, printing out which structures
@@ -219,11 +217,11 @@ gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2);
gint64 qof_book_get_counter (QofBook *book, const char *counter_name);
gboolean qof_book_remove_object (QofBook *book, QofInstance *inst);
gboolean qof_book_remove_element (QofBook *book, QofInstance *inst);
gboolean qof_book_insert_object (QofBook *book, QofInstance *inst);
gboolean qof_book_insert_element (QofBook *book, QofInstance *inst);
QofInstance qof_book_get_object (QofBook *book, GType type, GUID *guid);
QofInstance* qof_book_get_element (QofBook *book, GType type, GUID *guid);
+127 -127
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;
@@ -123,10 +123,10 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch = FALSE;
knowntype = FALSE;
qtparam = paramList->data;
mergeParamName = qtparam->param_name;
g_return_val_if_fail(mergeParamName != NULL, -1);
mergeParamName = qtparam->param_type;
g_return_val_if_fail(mergeParamName != G_TYPE_INVALID, -1);
mergeType = qtparam->param_type;
if(safe_strcmp(mergeType, QOF_TYPE_STRING) == 0) {
if(mergeType == QOF_TYPE_STRING) {
stringImport = qtparam->param_getfcn(mergeEnt,qtparam);
stringTarget = qtparam->param_getfcn(targetEnt,qtparam);
/* very strict string matches may need to be relaxed. */
@@ -139,8 +139,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
stringImport = stringTarget = NULL;
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))qtparam->param_getfcn;
if(mergeType == QOF_TYPE_DATE) {
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; }
@@ -148,9 +148,9 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if((safe_strcmp(mergeType, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(mergeType, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if((mergeType == QOF_TYPE_NUMERIC) ||
(mergeType == QOF_TYPE_DEBCRED)) {
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; }
@@ -158,7 +158,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_GUID) == 0) {
if(mergeType == QOF_TYPE_GUID) {
guidImport = qtparam->param_getfcn(mergeEnt,qtparam);
guidTarget = qtparam->param_getfcn(targetEnt,qtparam);
if(guid_compare(guidImport, guidTarget) == 0) { mergeMatch = TRUE; }
@@ -166,8 +166,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if(mergeType == QOF_TYPE_INT32) {
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
i32Import = int32_getter(mergeEnt, qtparam);
i32Target = int32_getter(targetEnt, qtparam);
if(i32Target == i32Import) { mergeMatch = TRUE; }
@@ -175,8 +175,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_INT64) == 0) {
int64_getter = (gint64 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if(mergeType == QOF_TYPE_INT64) {
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
i64Import = int64_getter(mergeEnt, qtparam);
i64Target = int64_getter(targetEnt, qtparam);
if(i64Target == i64Import) { mergeMatch = TRUE; }
@@ -184,8 +184,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_DOUBLE) == 0) {
double_getter = (double (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if(mergeType == QOF_TYPE_DOUBLE) {
double_getter = (double (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
doubleImport = double_getter(mergeEnt, qtparam);
doubleTarget = double_getter(mergeEnt, qtparam);
if(doubleImport == doubleTarget) { mergeMatch = TRUE; }
@@ -193,8 +193,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_BOOLEAN) == 0){
boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if(mergeType == QOF_TYPE_BOOLEAN){
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; }
@@ -204,7 +204,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_KVP) == 0) {
if(mergeType == QOF_TYPE_KVP) {
kvpImport = kvp_frame_copy(qtparam->param_getfcn(mergeEnt,qtparam));
kvpTarget = kvp_frame_copy(qtparam->param_getfcn(targetEnt,qtparam));
if(kvp_frame_compare(kvpImport, kvpTarget) == 0) { mergeMatch = TRUE; }
@@ -212,8 +212,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype= TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_CHAR) == 0) {
char_getter = (gchar (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if(mergeType == QOF_TYPE_CHAR) {
char_getter = (gchar (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
charImport = char_getter(mergeEnt, qtparam);
charTarget = char_getter(targetEnt, qtparam);
if(charImport == charTarget) { mergeMatch = TRUE; }
@@ -223,8 +223,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
}
/* No object should have QofSetterFunc defined for the book,
but just to be safe, do nothing. */
if(safe_strcmp(mergeType, QOF_ID_BOOK) == 0) { knowntype= TRUE; }
if(safe_strcmp(mergeType, QOF_TYPE_COLLECT) == 0) {
if(mergeType == QOF_ID_BOOK) { knowntype= TRUE; }
if(mergeType == QOF_TYPE_COLLECT) {
struct collect_list_s s;
s.linkedEntList = NULL;
mergeColl = qtparam->param_getfcn(mergeEnt, qtparam);
@@ -238,7 +238,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
mergeMatch, DEFAULT_MERGE_WEIGHT);
knowntype = TRUE;
}
if(safe_strcmp(mergeType, QOF_TYPE_CHOICE) ==0) {
if(mergeType == QOF_TYPE_CHOICE) {
referenceEnt = qtparam->param_getfcn(mergeEnt, qtparam);
currentRule->linkedEntList =
g_slist_prepend(currentRule->linkedEntList, referenceEnt);
@@ -249,7 +249,7 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
if(knowntype == FALSE) {
referenceEnt = qtparam->param_getfcn(mergeEnt, qtparam);
if((referenceEnt != NULL)
&&(safe_strcmp(referenceEnt->e_type, mergeType) == 0)) {
&&(G_OBJECT_TYPE (G_OBJECT (referenceEnt)) == mergeType)) {
currentRule->linkedEntList =
g_slist_prepend(currentRule->linkedEntList, referenceEnt);
if(referenceEnt == qtparam->param_getfcn(targetEnt, qtparam))
@@ -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;
@@ -430,18 +430,18 @@ qof_book_merge_foreach_type_target ( QofObject* merge_obj, gpointer user_data)
currentRule = mergeData->currentRule;
g_return_if_fail(currentRule != NULL);
g_return_if_fail(merge_obj != NULL);
if(safe_strcmp(merge_obj->e_type, currentRule->importEnt->e_type) == 0) {
qof_object_foreach(currentRule->importEnt->e_type, mergeData->targetBook,
if(G_OBJECT_TYPE (G_OBJECT (merge_obj)) == G_OBJECT_TYPE (G_OBJECT (currentRule->importEnt))) {
qof_object_foreach(G_OBJECT_TYPE ( G_OBJECT (currentRule->importEnt)), mergeData->targetBook,
qof_book_merge_foreach_target, 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;
@@ -452,21 +452,21 @@ qof_book_merge_foreach ( QofEntity* mergeEnt, gpointer user_data)
currentRule = mergeData->currentRule;
g_return_if_fail(currentRule != NULL);
g = guid_malloc();
*g = mergeEnt->guid;
g = qof_instance_get_guid (mergeEnt);
mergeRule = g_new(QofBookMergeRule,1);
mergeRule->importEnt = mergeEnt;
mergeRule->difference = difference = 0;
mergeRule->mergeAbsolute = FALSE;
mergeRule->mergeResult = MERGE_UNDEF;
mergeRule->updated = FALSE;
mergeRule->mergeType = mergeEnt->e_type;
mergeRule->mergeLabel = qof_object_get_type_label(mergeEnt->e_type);
mergeRule->mergeType = G_OBJECT_TYPE (G_OBJECT (mergeEnt));
mergeRule->mergeLabel = qof_object_get_type_label(G_OBJECT_TYPE (G_OBJECT (mergeEnt)));
mergeRule->mergeParam = g_slist_copy(mergeData->mergeObjectParams);
mergeRule->linkedEntList = NULL;
mergeData->currentRule = mergeRule;
targetEnt = best_matchEnt = NULL;
targetEnt = qof_collection_lookup_entity (
qof_book_get_collection (mergeData->targetBook, mergeEnt->e_type), g);
targetEnt = qof_collection_lookup_element (
qof_book_get_collection (mergeData->targetBook, G_OBJECT_TYPE (G_OBJECT (mergeEnt))), g);
if( targetEnt != NULL) {
mergeRule->mergeAbsolute = TRUE;
mergeRule->targetEnt = targetEnt;
@@ -558,7 +558,7 @@ qof_book_merge_foreach_type ( QofObject* merge_obj, gpointer user_data)
g_return_if_fail((merge_obj != NULL));
/* Skip unsupported objects */
if((merge_obj->create == NULL)||(merge_obj->foreach == NULL)){
DEBUG (" merge_obj QOF support failed %s", merge_obj->e_type);
DEBUG (" merge_obj QOF support failed %s", g_type_name (merge_obj->e_type));
return;
}
if(mergeData->mergeObjectParams != NULL) g_slist_free(mergeData->mergeObjectParams);
@@ -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);
@@ -628,10 +628,10 @@ qof_book_merge_commit_rule_loop(
/* create a new object for MERGE_NEW */
/* The new object takes the GUID from the import to retain an absolute match */
if(rule->mergeResult == MERGE_NEW) {
inst = (QofInstance*)qof_object_new_instance(rule->importEnt->e_type, mergeData->targetBook);
inst = (QofInstance*)qof_object_new_instance(G_OBJECT_TYPE (G_OBJECT (rule->importEnt)), 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
@@ -643,83 +643,83 @@ qof_book_merge_commit_rule_loop(
g_return_if_fail(rule->mergeParam->data);
cm_param = rule->mergeParam->data;
rule->mergeType = cm_param->param_type;
if(safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0) {
if(rule->mergeType == QOF_TYPE_STRING) {
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;
if(rule->mergeType == QOF_TYPE_DATE) {
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;
if((rule->mergeType == QOF_TYPE_NUMERIC) ||
(rule->mergeType == QOF_TYPE_DEBCRED)) {
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) {
if(rule->mergeType == QOF_TYPE_GUID) {
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;
if(rule->mergeType == QOF_TYPE_INT32) {
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;
if(rule->mergeType == QOF_TYPE_INT64) {
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;
if(rule->mergeType == QOF_TYPE_DOUBLE) {
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;
if(rule->mergeType == QOF_TYPE_BOOLEAN){
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) {
if(rule->mergeType == QOF_TYPE_KVP) {
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;
if(rule->mergeType == QOF_TYPE_CHAR) {
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) {
if(rule->mergeType== QOF_TYPE_COLLECT) {
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) {
if(rule->mergeType == QOF_TYPE_CHOICE) {
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,69 +819,69 @@ 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;
if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0) {
if(paramType == QOF_TYPE_STRING) {
param_string = g_strdup(qtparam->param_getfcn(qtEnt,qtparam));
if(param_string == NULL) { param_string = ""; }
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))qtparam->param_getfcn;
if(paramType == QOF_TYPE_DATE) {
date_getter = (Timespec (*)(QofInstance*, QofParam*))qtparam->param_getfcn;
param_ts = date_getter(qtEnt, qtparam);
param_t = timespecToTime_t(param_ts);
strftime(param_date, QOF_DATE_STRING_LENGTH, QOF_UTC_DATE_FORMAT, gmtime(&param_t));
param_string = g_strdup(param_date);
return param_string;
}
if((safe_strcmp(paramType, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if((paramType == QOF_TYPE_NUMERIC) ||
(paramType == QOF_TYPE_DEBCRED)) {
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;
}
if(safe_strcmp(paramType, QOF_TYPE_GUID) == 0) {
if(paramType == QOF_TYPE_GUID) {
param_guid = qtparam->param_getfcn(qtEnt,qtparam);
guid_to_string_buff(param_guid, param_sa);
param_string = g_strdup(param_sa);
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
if(paramType == QOF_TYPE_INT32) {
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;
if(paramType == QOF_TYPE_INT64) {
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;
if(paramType == QOF_TYPE_DOUBLE) {
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;
if(paramType == QOF_TYPE_BOOLEAN){
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"); }
@@ -889,9 +889,9 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt)
return param_string;
}
/* "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;
if(paramType == QOF_TYPE_KVP) { return param_string; }
if(paramType == QOF_TYPE_CHAR) {
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;
+9 -9
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,9 +218,9 @@ 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
@@ -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
+12 -14
View File
@@ -35,7 +35,7 @@ static gboolean qof_choice_is_initialized(void)
{
if(!qof_choice_table)
{
qof_choice_table = g_hash_table_new(g_str_hash, g_str_equal);
qof_choice_table = g_hash_table_new(g_int_hash, g_int_equal);
}
if(!qof_choice_table) { return FALSE; }
return TRUE;
@@ -48,26 +48,25 @@ gboolean qof_object_is_choice(QofIdTypeConst type)
value = NULL;
check = NULL;
if(!qof_choice_is_initialized()) { return FALSE; }
g_return_val_if_fail(type != NULL, FALSE);
value = g_hash_table_lookup(qof_choice_table, type);
value = g_hash_table_lookup(qof_choice_table, GINT_TO_POINTER(type));
if((GHashTable*)value) { return TRUE; }
DEBUG (" QOF_TYPE_CHOICE setup failed for %s\n", type);
DEBUG (" QOF_TYPE_CHOICE setup failed for %s\n", g_type_name(type));
return FALSE;
}
gboolean
qof_choice_create(char* type)
qof_choice_create(QofIdType type)
{
GHashTable *param_table;
g_return_val_if_fail(type != NULL, FALSE);
g_return_val_if_fail(qof_choice_is_initialized() == TRUE, FALSE);
param_table = g_hash_table_new(g_str_hash, g_str_equal);
g_hash_table_insert(qof_choice_table, type, param_table);
g_hash_table_insert(qof_choice_table, GINT_TO_POINTER(type), param_table);
return TRUE;
}
gboolean qof_choice_add_class(const char* select,
gboolean qof_choice_add_class(QofIdType select,
char* option,
char* param_name)
{
@@ -76,9 +75,9 @@ gboolean qof_choice_add_class(const char* select,
option_list = NULL;
param_table = NULL;
g_return_val_if_fail(select != NULL, FALSE);
g_return_val_if_fail(qof_object_is_choice(select), FALSE);
param_table = (GHashTable*)g_hash_table_lookup(qof_choice_table, select);
param_table = (GHashTable*)g_hash_table_lookup(qof_choice_table, GINT_TO_POINTER(select));
g_return_val_if_fail(param_table, FALSE);
option_list = (GList*)g_hash_table_lookup(param_table, param_name);
option_list = g_list_append(option_list, option);
@@ -91,15 +90,14 @@ GList* qof_object_get_choices(QofIdType type, QofParam *param)
GList *choices;
GHashTable *param_table;
g_return_val_if_fail(type != NULL, NULL);
g_return_val_if_fail(qof_choice_is_initialized() == TRUE, FALSE);
choices = NULL;
param_table = g_hash_table_lookup(qof_choice_table, type);
param_table = g_hash_table_lookup(qof_choice_table, GINT_TO_POINTER(type));
choices = g_hash_table_lookup(param_table, param->param_name);
return choices;
}
gboolean qof_choice_check(const char* choice_obj,
gboolean qof_choice_check(QofIdType choice_obj,
const char *param_name,
const char* choice )
{
@@ -108,7 +106,7 @@ gboolean qof_choice_check(const char* choice_obj,
choices = result = NULL;
g_return_val_if_fail(qof_object_is_choice(choice_obj), FALSE);
param_table = g_hash_table_lookup(qof_choice_table, choice_obj);
param_table = g_hash_table_lookup(qof_choice_table, GINT_TO_POINTER(choice_obj));
choices = g_hash_table_lookup(param_table, param_name);
result = g_list_find(choices, choice);
if(!result) { return FALSE; }
+3 -5
View File
@@ -99,8 +99,6 @@ the object must return a single entity matching one of the choice types.
@{
*/
/** \brief Identify an object as containing a choice. */
#define QOF_TYPE_CHOICE "choice"
/** \brief Does this object contain a choice parameter?
@@ -116,7 +114,7 @@ registered using the object definition, otherwise FALSE.
gboolean qof_object_is_choice(QofIdTypeConst type);
/** \brief Set an object as using QOF_TYPE_CHOICE. */
gboolean qof_choice_create(char* type);
gboolean qof_choice_create(QofIdType type);
/** \brief Add the choices for this parameter to the object.
@@ -127,7 +125,7 @@ gboolean qof_choice_create(char* type);
@return FALSE if object is not a choice object or on error
otherwise TRUE.
*/
gboolean qof_choice_add_class(const char* choice, char* add, char* param_name);
gboolean qof_choice_add_class(QofIdType select, char* add, char* param_name);
/** \brief Return the list of all object types usable with this parameter.
@@ -150,7 +148,7 @@ GList* qof_object_get_choices(QofIdType type, QofParam *param);
@return TRUE if choice is found in the list of allowed choices for
this parameter of this object. Otherwise, FALSE
*/
gboolean qof_choice_check(const char* choice_obj,
gboolean qof_choice_check(QofIdType choice_obj,
const char *param_name,
const char* choice);
/** @} */
+32 -39
View File
@@ -57,8 +57,8 @@ qof_class_init(void)
if (initialized) return;
initialized = TRUE;
classTable = g_hash_table_new (g_str_hash, g_str_equal);
sortTable = g_hash_table_new (g_str_hash, g_str_equal);
classTable = g_hash_table_new (g_int_hash, g_int_equal);
sortTable = g_hash_table_new (g_int_hash, g_int_equal);
}
void
@@ -75,8 +75,7 @@ qof_class_shutdown (void)
QofSortFunc
qof_class_get_default_sort (QofIdTypeConst obj_name)
{
if (!obj_name) return NULL;
return g_hash_table_lookup (sortTable, obj_name);
return g_hash_table_lookup (sortTable, GINT_TO_POINTER (obj_name));
}
/* *******************************************************************/
@@ -90,21 +89,20 @@ qof_class_register (QofIdTypeConst obj_name,
GHashTable *ht;
int i;
if (!obj_name) return;
if (!check_init()) return;
if (default_sort_function)
{
g_hash_table_insert (sortTable, (char *)obj_name, default_sort_function);
g_hash_table_insert (sortTable, GINT_TO_POINTER (obj_name), default_sort_function);
}
ht = g_hash_table_lookup (classTable, obj_name);
ht = g_hash_table_lookup (classTable, GINT_TO_POINTER (obj_name));
/* If it doesn't already exist, create a new table for this object */
if (!ht)
{
ht = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (classTable, (char *)obj_name, ht);
g_hash_table_insert (classTable, GINT_TO_POINTER (obj_name), ht);
}
/* At least right now, we allow dummy, parameterless objects,
@@ -115,36 +113,35 @@ qof_class_register (QofIdTypeConst obj_name,
{
for (i = 0; params[i].param_name; i++)
g_hash_table_insert (ht,
(char *)params[i].param_name,
(gpointer)&(params[i]));
(gpointer) (params[i].param_name),
(gpointer) &(params[i]));
}
}
gboolean
qof_class_is_registered (QofIdTypeConst obj_name)
{
if (!obj_name) return FALSE;
if (!check_init()) return FALSE;
if (g_hash_table_lookup (classTable, obj_name)) return TRUE;
if (g_hash_table_lookup (classTable, GINT_TO_POINTER (obj_name))) return TRUE;
return FALSE;
}
const QofParam *
qof_class_get_parameter (QofIdTypeConst obj_name,
const char *parameter)
const gchar* parameter)
{
GHashTable *ht;
g_return_val_if_fail (obj_name, NULL);
g_return_val_if_fail (parameter, NULL);
if (!check_init()) return NULL;
ht = g_hash_table_lookup (classTable, obj_name);
ht = g_hash_table_lookup (classTable, GINT_TO_POINTER (obj_name));
if (!ht)
{
PWARN ("no object of type %s", obj_name);
PWARN ("no object of type %s", g_type_name (obj_name));
return NULL;
}
@@ -153,11 +150,10 @@ qof_class_get_parameter (QofIdTypeConst obj_name,
QofAccessFunc
qof_class_get_parameter_getter (QofIdTypeConst obj_name,
const char *parameter)
const gchar* parameter)
{
const QofParam *prm;
g_return_val_if_fail (obj_name, NULL);
g_return_val_if_fail (parameter, NULL);
prm = qof_class_get_parameter (obj_name, parameter);
@@ -169,11 +165,10 @@ qof_class_get_parameter_getter (QofIdTypeConst obj_name,
QofSetterFunc
qof_class_get_parameter_setter (QofIdTypeConst obj_name,
const char *parameter)
const gchar* parameter)
{
const QofParam *prm;
g_return_val_if_fail (obj_name, NULL);
g_return_val_if_fail (parameter, NULL);
prm = qof_class_get_parameter (obj_name, parameter);
@@ -185,14 +180,12 @@ qof_class_get_parameter_setter (QofIdTypeConst obj_name,
QofType
qof_class_get_parameter_type (QofIdTypeConst obj_name,
const char *param_name)
const gchar* param_name)
{
const QofParam *prm;
if (!obj_name || !param_name) return NULL;
prm = qof_class_get_parameter (obj_name, param_name);
if (!prm) return NULL;
if (!prm) return G_TYPE_INVALID;
return (prm->param_type);
}
@@ -208,7 +201,7 @@ static void
class_foreach_cb (gpointer key, gpointer item, gpointer arg)
{
struct class_iterate *iter = arg;
QofIdTypeConst id = key;
QofIdTypeConst id = GPOINTER_TO_INT (key);
iter->fcn (id, iter->data);
}
@@ -250,9 +243,9 @@ qof_class_param_foreach (QofIdTypeConst obj_name,
struct parm_iterate iter;
GHashTable *param_ht;
if (!obj_name || !cb) return;
if (!cb) return;
if (!classTable) return;
param_ht = g_hash_table_lookup (classTable, obj_name);
param_ht = g_hash_table_lookup (classTable, GINT_TO_POINTER (obj_name));
if (!param_ht) return;
iter.fcn = cb;
@@ -273,18 +266,18 @@ find_reference_param_cb(QofParam *param, gpointer user_data)
b = (struct param_ref_list*)user_data;
if((param->param_getfcn == NULL)||(param->param_setfcn == NULL)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_STRING)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_NUMERIC)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_DATE)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_CHAR)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_DEBCRED)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_GUID)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_INT32)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_INT64)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_DOUBLE)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_KVP)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_TYPE_BOOLEAN)) { return; }
if(0 == safe_strcmp(param->param_type, QOF_ID_BOOK)) { return; }
if((param->param_type == QOF_TYPE_STRING)) { return; }
if((param->param_type == QOF_TYPE_NUMERIC)) { return; }
if((param->param_type == QOF_TYPE_DATE)) { return; }
if((param->param_type == QOF_TYPE_CHAR)) { return; }
if((param->param_type == QOF_TYPE_DEBCRED)) { return; }
if((param->param_type == QOF_TYPE_GUID)) { return; }
if((param->param_type == QOF_TYPE_INT32)) { return; }
if((param->param_type == QOF_TYPE_INT64)) { return; }
if((param->param_type == QOF_TYPE_DOUBLE)) { return; }
if((param->param_type == QOF_TYPE_KVP)) { return; }
if((param->param_type == QOF_TYPE_BOOLEAN)) { return; }
if((param->param_type == QOF_ID_BOOK)) { return; }
b->list = g_list_append(b->list, param);
}
+19 -18
View File
@@ -82,18 +82,19 @@ single reference between two known objects.
@{
*/
#define QOF_TYPE_STRING "string"
#define QOF_TYPE_DATE "date"
#define QOF_TYPE_NUMERIC "numeric"
#define QOF_TYPE_DEBCRED "debcred"
#define QOF_TYPE_GUID "guid"
#define QOF_TYPE_INT32 "gint32"
#define QOF_TYPE_INT64 "gint64"
#define QOF_TYPE_DOUBLE "double"
#define QOF_TYPE_BOOLEAN "boolean"
#define QOF_TYPE_KVP "kvp"
#define QOF_TYPE_CHAR "character"
#define QOF_TYPE_COLLECT "collection" /**< secondary collections
#define QOF_TYPE_STRING G_TYPE_CHAR
#define QOF_TYPE_DATE G_TYPE_DATE
#define QOF_TYPE_NUMERIC GNC_TYPE_NUMERIC
#define QOF_TYPE_DEBCRED GNC_TYPE_NUMERIC // Used in Split, QofQuery, Session and Util to get a gnc_numeric, then asigned to this type
#define QOF_TYPE_GUID GNC_TYPE_GUID
#define QOF_TYPE_INT32 G_TYPE_INT
#define QOF_TYPE_INT64 G_TYPE_INT64
#define QOF_TYPE_DOUBLE G_TYPE_DOUBLE
#define QOF_TYPE_BOOLEAN G_TYPE_BOOLEAN
#define QOF_TYPE_KVP GNC_TYPE_KVP_FRAME
#define QOF_TYPE_CHAR G_TYPE_CHAR
#define QOF_TYPE_CHOICE G_TYPE_GTYPE // FIXME
#define QOF_TYPE_COLLECT QOF_TYPE_COLLECTION /**< secondary collections
are used for one-to-many references between entities and are
implemented using ::QofCollection.
These are \b NOT the same as the main collections in the QofBook.
@@ -123,7 +124,7 @@ n.b. Always subject to each collection holding only one type at runtime.
*/
/** @} */
/** Type of Paramters (String, Date, Numeric, GUID, etc.) */
typedef const char * QofType;
typedef GType QofType;
typedef struct _QofParam QofParam;
@@ -178,7 +179,7 @@ typedef gint (*QofCompareFunc) (gpointer a, gpointer b,
*/
struct _QofParam
{
const char * param_name;
const gchar * param_name;
QofType param_type;
QofAccessFunc param_getfcn;
QofSetterFunc param_setfcn;
@@ -232,19 +233,19 @@ gboolean qof_class_is_registered (QofIdTypeConst obj_name);
/** Return the core datatype of the specified object's parameter */
QofType qof_class_get_parameter_type (QofIdTypeConst obj_name,
const char *param_name);
const gchar* param_name);
/** Return the registered Parameter Definition for the requested parameter */
const QofParam * qof_class_get_parameter (QofIdTypeConst obj_name,
const char *parameter);
const gchar* parameter);
/** Return the object's parameter getter function */
QofAccessFunc qof_class_get_parameter_getter (QofIdTypeConst obj_name,
const char *parameter);
const gchar* parameter);
/** Return the object's parameter setter function */
QofSetterFunc qof_class_get_parameter_setter (QofIdTypeConst obj_name,
const char *parameter);
const gchar* parameter);
/** Type definition for the class callback function. */
typedef void (*QofClassForeachCB) (QofIdTypeConst, gpointer);
+2 -1
View File
@@ -43,9 +43,10 @@ typedef struct
to the QofInstance and locating the book, editlevel or dirty flag.
Use qof_event_gen instead.
*/
/*
void
qof_event_generate (const GUID *guid, QofIdType e_type,
QofEventId event_id);
QofEventId event_id); */
/* generates an event even when events are suspended! */
void qof_event_force (QofEntity *entity, QofEventId event_id, gpointer event_data);
+4 -10
View File
@@ -231,15 +231,7 @@ qof_event_generate_internal (QofEntity *entity, QofEventId event_id,
HandlerInfo *hi = node->data;
next_node = node->next;
#ifndef QOF_DISABLE_DEPRECATED
if ((hi->old_handler) && (use_old_handlers))
{
PINFO(" deprecated: id=%d hi=%p han=%p", hi->handler_id, hi,
hi->old_handler);
hi->old_handler ((GUID *)&entity->guid, entity->e_type,
event_id, hi->user_data);
}
#endif
if (hi->handler)
{
PINFO("id=%d hi=%p han=%p data=%p", hi->handler_id, hi,
@@ -296,6 +288,7 @@ qof_event_gen (QofEntity *entity, QofEventId event_id, gpointer event_data)
}
/* deprecated */
/*
void
qof_event_generate (const GUID *guid, QofIdType e_type,
QofEventId event_id)
@@ -304,8 +297,9 @@ qof_event_generate (const GUID *guid, QofIdType e_type,
ent.guid = *guid;
ent.e_type = e_type;
if (suspend_counter) return;
/* caution: this is an incomplete entity! */
// caution: this is an incomplete entity!
qof_event_generate_internal (&ent, event_id, NULL);
}
*/
/* =========================== END OF FILE ======================= */
+49 -36
View File
@@ -26,6 +26,7 @@
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "qof.h"
#include "qofid-p.h"
@@ -38,6 +39,8 @@ static gboolean qof_alt_dirty_mode = FALSE;
static void qof_collection_class_init(QofCollectionClass *klass);
static void qof_collection_init(QofCollection *sp);
static void qof_collection_finalize(GObject *object);
static void qof_collection_set_property (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec);
static void qof_collection_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
struct _QofCollectionPrivate
{
@@ -52,6 +55,7 @@ typedef enum _QofCollectionSignalType QofCollectionSignalType;
enum _QofCollectionSignalType {
/* Signals */
FIRST_SIGNAL,
LAST_SIGNAL
};
@@ -70,7 +74,7 @@ static guint qof_collection_signals[LAST_SIGNAL] = { 0 };
static GObjectClass *parent_class = NULL;
GType
qof_collection_get_type()
qof_collection_get_type(void)
{
static GType type = 0;
@@ -107,33 +111,39 @@ qof_collection_class_init(QofCollectionClass *klass)
/* Install properties */
g_object_class_install_property (object_class, PROP_TYPE,
g_param_spec_object ("type", _("Object's GType the Collection holds"), NULL,
G_TYPE_GTYPE,
g_param_spec_int ("type", NULL, _("Object's GType the Collection holds"),
G_MININT, G_MAXINT, G_TYPE_INVALID,
(G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY)));
/* Create signals here:*/
}
static guint id_hash (gconstpointer key);
static gboolean id_compare(gconstpointer key_1, gconstpointer key_2);
static void
qof_collection_init(QofCollection *obj)
{
/* Initialize private members, etc. */
col->priv = g_new0 (QofCollectionPrivate, 1);
obj->priv = g_new0 (QofCollectionPrivate, 1);
col->priv->type = G_TYPE_INVALID;
col->priv->hash_of_entities = g_hash_table_new (id_hash, id_compare);
obj->priv->type = G_TYPE_INVALID;
obj->priv->hash_of_entities = g_hash_table_new (id_hash, id_compare);
}
static void
qof_collection_finalize(GObject *object)
{
QofCollection *col;
col = QOF_COLLECTION (object);
/* Free private members, etc. */
g_hash_table_destroy(col->hash_of_entities);
col->type = G_TYPE_INVALID;
col->hash_of_entities = NULL;
g_hash_table_destroy(col->priv->hash_of_entities);
col->priv->type = G_TYPE_INVALID;
col->priv->hash_of_entities = NULL;
G_OBJECT_CLASS(parent_class)->finalize(object);
}
@@ -147,14 +157,15 @@ qof_collection_set_property (GObject *object,
QofCollection *obj;
obj = QOF_COLLECTION (object);
switch (param_id) {
case PROP_TYPE:
if (obj->priv->hash_of_entities == NULL)
obj->priv->type = g_value_get_gtype (value));
obj->priv->type = g_value_get_gtype (value);
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID(object,param_id,pspec);
break;
}
}
@@ -180,15 +191,13 @@ qof_collection_get_property (GObject *object,
}
}
static guint id_hash (gconstpointer key);
static gboolean id_compare(gconstpointer key_1, gconstpointer key_2);
QofCollection *
qof_collection_new (GType type)
{
QofCollection *col;
g_return_val_if_fail (G_TYPE_IS_OBJECT (type));
g_return_val_if_fail (G_TYPE_IS_OBJECT (type), NULL);
col = QOF_COLLECTION (g_object_new (QOF_TYPE_COLLECTION, "type", type));
@@ -203,28 +212,30 @@ qof_collection_destroy (QofCollection *col)
g_object_unref (col);
}
const GType
qof_collection_get_g_type (const QofInstance *entity)
GType
qof_collection_get_g_type (const QofCollection *col)
{
return collection->priv->type;
return col->priv->type;
}
void
gboolean
qof_collection_remove_element (QofCollection *coll, QofInstance *inst)
{
QofInstance *obj;
g_return_if_fail (QOF_IS_COLLECTION (coll) && QOF_IS_INSTANCE (inst));
g_return_val_if_fail (QOF_IS_COLLECTION (coll) && QOF_IS_INSTANCE (inst), FALSE);
obj = qof_collection_get_element (coll, qof_collection_get_guid (inst));
obj = qof_collection_lookup_element (coll, qof_instance_get_guid (inst));
g_return_if_fail (QOF_IS_INSTANCE (col));
g_return_val_if_fail (QOF_IS_INSTANCE (obj), FALSE);
g_hash_table_remove (col->priv->hash_of_entities, qof_instance_get_guid (inst));
g_hash_table_remove (coll->priv->hash_of_entities, (gpointer) qof_instance_get_guid (inst));
if (!qof_alt_dirty_mode)
qof_collection_mark_dirty (col);
qof_collection_mark_dirty (coll);
return TRUE;
}
@@ -238,7 +249,7 @@ qof_collection_add_element (QofCollection *coll, QofInstance *inst)
QOF_IS_INSTANCE (inst),
FALSE);
g_hash_table_insert (coll->hash_of_entities, qof_instance_get_guid (inst), inst);
g_hash_table_insert (coll->priv->hash_of_entities, (gpointer) qof_instance_get_guid (inst), (gpointer) inst);
if (!qof_alt_dirty_mode)
qof_collection_mark_dirty(coll);
@@ -291,7 +302,7 @@ collection_compare_cb (QofInstance *inst, gpointer user_data)
return;
}
g_return_if_fail (target->type == G_OBJECT_TYPE (inst));
g_return_if_fail (target->priv->type == G_OBJECT_TYPE (inst));
e = qof_collection_lookup_element (target, qof_instance_get_guid (inst));
@@ -344,9 +355,9 @@ qof_collection_lookup_element (const QofCollection *col, const GUID * guid)
if (guid == NULL) return NULL;
ent = g_hash_table_lookup (col->priv->hash_of_entities, guid);
inst = g_hash_table_lookup (col->priv->hash_of_entities, guid);
return ent;
return inst;
}
QofCollection *
@@ -356,7 +367,7 @@ qof_collection_from_glist (QofBook *book, GType type, GList *glist)
QofInstance *ent;
GList *list;
coll = qof_collection_new (book, type);
coll = qof_collection_new (type);
for(list = glist; list != NULL; list = list->next)
{
@@ -433,19 +444,21 @@ qof_collection_mark_clean (QofCollection *col)
void
qof_collection_mark_dirty (QofCollection *col)
{
if (col) {
col->priv->is_dirty = TRUE;
qof_collection_mark_dirty (col->priv->book);
}
}
g_return_if_fail (QOF_IS_COLLECTION (col));
col->priv->is_dirty = TRUE;
}
/*
* This code isn't used any where.... :-|?
void
qof_collection_print_dirty (const QofCollection *col, gpointer dummy)
qof_collection_print_dirty (QofCollection *col, gpointer dummy)
{
if (col->priv->is_dirty)
printf("%s collection is dirty.\n", col->priv->e_type);
printf("%s collection is dirty.\n", g_type_name (col->priv->type));
qof_collection_foreach(col, (QofInstanceForeachCB)qof_instance_print_dirty, NULL);
}
*/
/* =============================================================== */
@@ -463,7 +476,7 @@ static void foreach_cb (gpointer key, gpointer item, gpointer arg)
}
void
qof_collection_foreach (const QofCollection *col, QofInstanceForeachCB cb_func,
qof_collection_foreach (QofCollection *col, QofInstanceForeachCB cb_func,
gpointer user_data)
{
struct _iterate iter;
+25 -15
View File
@@ -73,7 +73,7 @@
@author Copyright (C) 2003 Linas Vepstas <linas@linas.org>
@author Copyright (C) 2007 Daniel Espinosa <esodan@gmail.com>
*/
#include "qofinstance.h"
#include <string.h>
#include <glib-object.h>
#include "guid.h"
@@ -85,6 +85,17 @@
/** QofLogModule declaration */
typedef const gchar* QofLogModule;
/** QofIdType declaration */
typedef GType QofIdType;
/** QofIdTypeConst declaration */
typedef GType QofIdTypeConst;
#define QOF_ID_NONE G_TYPE_NONE
#define QOF_ID_NULL G_TYPE_INVALID
#define QOF_ID_BOOK QOF_TYPE_BOOK
#define QOF_ID_SESSION "Session"
/* GObject declarations */
#define QOF_TYPE_COLLECTION (qof_collection_get_type ())
@@ -114,7 +125,7 @@ struct _QofCollectionClass {
};
GType qof_entity_get_type ();
GType qof_collection_get_type (void);
/** create a new collection of entities of type */
QofCollection * qof_collection_new (GType type);
@@ -122,17 +133,17 @@ QofCollection * qof_collection_new (GType type);
/** return the number of entities in the collection. */
guint qof_collection_count (const QofCollection *col);
/** destroy the collection */
void qof_collection_destroy (QofCollection *col);
/** return the type that the collection stores */
GType qof_collection_get_g_type (const QofCollection *);
GType qof_collection_get_g_type (const QofCollection *col);
/** Find the entity going only from its guid */
QofInstance * qof_collection_lookup_element (const QofCollection *, const GUID *);
QofInstance* qof_collection_lookup_element (const QofCollection *col, const GUID *guid);
/** Call the callback for each entity in the collection. */
void qof_collection_foreach (const QofCollection *, QofEntityForeachCB,
void qof_collection_foreach (QofCollection *col, QofInstanceForeachCB cb_func,
gpointer user_data);
/** Store and retreive arbitrary object-defined data
@@ -141,8 +152,8 @@ void qof_collection_foreach (const QofCollection *, QofEntityForeachCB,
* destroyed, so that the user has a chance to clean up anything
* that was put in the 'data' member here.
*/
gpointer qof_collection_get_data (const QofCollection *col);
void qof_collection_set_data (QofCollection *col, gpointer user_data);
#define qof_collection_get_data(col) (g_object_get_data(G_OBJECT(col), "SOME_DATA"))
#define qof_collection_set_data(col, user_data) (g_object_set_data(G_OBJECT(col), "SOME_DATA", user_data))
/** Return value of 'dirty' flag on collection */
gboolean qof_collection_is_dirty (const QofCollection *col);
@@ -167,19 +178,18 @@ will not be removed from the original collection as they would
by using ::qof_entity_insert_entity or ::qof_entity_remove_entity.
*/
gboolean
qof_collection_add_element (QofCollection *coll, QofInstance *inst);
gboolean qof_collection_add_element (QofCollection *coll, QofInstance *inst);
gboolean
qof_collection_remove_element (QofCollection *coll, QofInstance *ent);
gboolean qof_collection_remove_element (QofCollection *coll, QofInstance *inst);
/** \brief Merge two QOF_TYPE_COLLECT of the same type.
/* \brief Merge two QOF_TYPE_COLLECT of the same type.
\note \b NOT the same as the main collections in the book.
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
original collection as when using ::qof_instance_insert_entity
or ::qof_entity_remove_entity.
*/
@@ -211,7 +221,7 @@ qof_collection_compare (QofCollection *target, QofCollection *merge);
on success.
*/
QofCollection*
qof_collection_from_glist (QofIdType type, GList *glist);
qof_collection_from_glist (QofBook *book, GType type, GList *glist);
/******************************************************/
+191 -96
View File
@@ -31,9 +31,13 @@
#include <glib.h>
#include "qof.h"
#include "kvp-util-p.h"
#include "qofbook.h"
#include "qofbook-p.h"
#include "qofid.h"
#include "qofid-p.h"
#include "qofinstance-p.h"
#include <glib/gi18n-lib.h>
#include "qofbackend.h"
static QofLogModule log_module = QOF_MOD_ENGINE;
@@ -42,6 +46,9 @@ static QofLogModule log_module = QOF_MOD_ENGINE;
static void qof_instance_class_init(QofInstanceClass *klass);
static void qof_instance_init(QofInstance *sp);
static void qof_instance_finalize(GObject *object);
static void qof_instance_set_property (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec);
static void qof_instance_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
struct _QofInstancePrivate
{
@@ -86,6 +93,8 @@ typedef enum _QofInstanceSignalType QofInstanceSignalType;
enum _QofInstanceSignalType {
/* Signals */
BEGIN_EDIT,
BEGIN_COMMIT,
COMMITED,
LAST_SIGNAL
};
@@ -105,7 +114,7 @@ static guint qof_instance_signals[LAST_SIGNAL] = { 0 };
static GObjectClass *parent_class = NULL;
GType
qof_instance_get_type()
qof_instance_get_type(void)
{
static GType type = 0;
@@ -122,7 +131,7 @@ qof_instance_get_type()
(GInstanceInitFunc)qof_instance_init,
};
type = g_type_register_static(QOF_TYPE_ENTITY,
type = g_type_register_static(G_TYPE_OBJECT,
"QofInstance", &our_info, 0);
}
@@ -141,52 +150,69 @@ qof_instance_class_init(QofInstanceClass *klass)
/* Install properties */
g_object_class_install_property (object_class, PROP_BOOK,
g_param_spec_object ("book", _("Book"), NULL,
QOF_TYPE_BOOK,
g_param_spec_object ("book", NULL, _("Book"), QOF_TYPE_BOOK,
(G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY)));
/* Create signals here:*/
qof_instance_signals[COMMITED] =
g_signal_new ("commited",
GNC_TYPE_INSTANCE,
G_SIGNAL_RUN_LAST,
NULL, NULL, NULL,
g_signal_new ("commit:finished",
QOF_TYPE_INSTANCE,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, NULL);
qof_instance_signals[BEGIN_COMMIT] =
g_signal_new ("commit:beginning",
QOF_TYPE_INSTANCE,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, NULL);
qof_instance_signals[BEGIN_EDIT] =
g_signal_new ("begin_edit",
QOF_TYPE_INSTANCE,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, NULL);
}
static void
qof_instance_init(QofInstance *obj)
{
/* Initialize private members, etc. */
inst->priv = g_new0 (QofInstancePrivate, 1);
inst->priv->book = NULL;
inst->priv->kvp_data = kvp_frame_new();
inst->priv->last_update.tv_sec = 0;
inst->priv->last_update.tv_nsec = -1;
inst->priv->editlevel = 0;
inst->priv->do_free = FALSE;
inst->priv->dirty = FALSE;
inst->priv->infant = TRUE;
inst->priv->guid = NULL;
/* Initialize private members, etc. */
obj->priv = g_new0 (QofInstancePrivate, 1);
obj->priv->book = NULL;
obj->priv->kvp_data = kvp_frame_new();
obj->priv->last_update.tv_sec = 0;
obj->priv->last_update.tv_nsec = -1;
obj->priv->editlevel = 0;
obj->priv->do_free = FALSE;
obj->priv->dirty = FALSE;
obj->priv->infant = TRUE;
obj->priv->guid = NULL;
}
static void
qof_instance_finalize(GObject *object)
{
QofInstance *inst = QOF_INSTANCE (object);
/* Free private members, etc. */
kvp_frame_delete (inst->priv->kvp_data);
inst->priv->kvp_data = NULL;
inst->priv->editlevel = 0;
inst->priv->do_free = FALSE;
inst->priv->dirty = FALSE;
qof_book_remove_element (QOF_INSTANCE (object));
qof_book_remove_element (inst->priv->book, inst);
guid_free (inst->priv->guid);
G_OBJECT_CLASS(parent_class)->finalize(object);
}
@@ -203,11 +229,12 @@ qof_instance_set_property (GObject *object,
switch (param_id) {
case PROP_BOOK:
obj->priv->book = qof_instance_set_book (obj, QOF_BOOK (g_value_get_object (value)));
qof_instance_set_book (obj, QOF_BOOK (g_value_get_object (value)));
obj->priv->book = QOF_BOOK (g_value_get_object (value));
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID(object,param_id,pspec);
break;
}
}
@@ -228,7 +255,7 @@ qof_instance_get_property (GObject *object,
break;
default:
/* We don't have any other property... */
G_OBJECT_WARNinst->priv = g_new0 (QofInstancePrivate, 1);
G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
break;
}
}
@@ -239,20 +266,20 @@ qof_instance_get_property (GObject *object,
/* ========================================================== */
void
qof_instance_set_book (QofInstance *instance, QofBook *book)
qof_instance_set_book (QofInstance *inst, QofBook *book)
{
QofCollection *coll;
g_return_if_fail (QOF_IS_BOOK (book));
if ( QOF_IS_BOOK (inst->book) && instance->priv->guid != NULL)
if ( QOF_IS_BOOK (inst->priv->book) && inst->priv->guid != NULL)
{
if (QOF_IS_INSTANCE (qof_book_get_element (inst->book, G_OBJECT_TYPE (instance), ent->priv->guid)))
if (QOF_IS_INSTANCE (qof_book_get_element (inst->priv->book, G_OBJECT_TYPE (inst), inst->priv->guid)))
{
qof_collection_remove_element (qof_book_get_collection (ent->priv->book,
G_OBJECT_TYPE (instance)),
instance);
qof_collection_remove_element (qof_book_get_collection (inst->priv->book,
G_OBJECT_TYPE (inst)),
inst);
}
inst->priv->book = book;
}
@@ -271,7 +298,7 @@ qof_instance_set_book (QofInstance *instance, QofBook *book)
{
guid_new (guid);
if (NULL == qof_book_get_element (instance->priv->book, G_OBJECT_TYPE (instance), guid)) break;
if (NULL == qof_book_get_element (inst->priv->book, G_OBJECT_TYPE (inst), guid)) break;
PWARN("duplicate id created, trying again");
} while(1);
@@ -279,19 +306,14 @@ qof_instance_set_book (QofInstance *instance, QofBook *book)
inst->priv->guid = guid;
}
qof_book_insert_element (instance->priv->book, instance);
qof_book_insert_element (inst->priv->book, inst);
}
QofCollection*
qof_instance_get_collection (QofInstance *instance)
{
return qof_book_get_collection (instance->priv->book, G_OBJECT_TYPE (instance));
}
/* This is a restricted function, should be used only during
* read from file */
void
qof_instance_set_guid (QofInstance *inst, const GUID *guid)
qof_instance_set_guid (QofInstance *inst, GUID *guid)
{
if (guid_equal (guid, inst->priv->guid)) return;
@@ -311,19 +333,36 @@ qof_instance_create (GType type, QofBook *book)
return inst;
}
void
qof_instance_destroy (QofInstance *inst)
qof_instance_release (QofInstance *inst)
{
qof_instance_begin_edit (inst);
qof_instance_commit_edit (inst);
g_object_unref (G_OBJECT (inst));
}
const GUID *
qof_instance_get_guid (const QofInstance *inst)
gboolean
qof_instance_destroy (QofInstance *inst, GError **error)
{
g_return_value_if_fail (QOF_IS_INSTANCE(inst), NULL);
qof_instance_begin_edit (inst, error);
if(error) {
return FALSE;
}
qof_instance_commit_edit (inst, error);
if(error) {
/*FIXME: Add actions to cancel the commit if exist an error*/
return FALSE;
}
qof_event_gen (inst, QOF_EVENT_DESTROY, NULL);
g_object_unref (G_OBJECT (inst));
return TRUE;
}
GUID *
qof_instance_get_guid (QofInstance *inst)
{
g_return_val_if_fail (QOF_IS_INSTANCE(inst), NULL);
return inst->priv->guid;
}
@@ -359,34 +398,42 @@ qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
if (!left && !right) return 0;
if (!left) return -1;
if (!right) return +1;
if (left->last_update.tv_sec < right->last_update.tv_sec) return -1;
if (left->last_update.tv_sec > right->last_update.tv_sec) return +1;
if (left->last_update.tv_nsec < right->last_update.tv_nsec) return -1;
if (left->last_update.tv_nsec > right->last_update.tv_nsec) return +1;
if (left->priv->last_update.tv_sec < right->priv->last_update.tv_sec) return -1;
if (left->priv->last_update.tv_sec > right->priv->last_update.tv_sec) return +1;
if (left->priv->last_update.tv_nsec < right->priv->last_update.tv_nsec) return -1;
if (left->priv->last_update.tv_nsec > right->priv->last_update.tv_nsec) return +1;
return 0;
}
void
qof_instance_print_dirty (const QofEntity *entity, gpointer dummy)
qof_instance_print_dirty (QofInstance *inst, gpointer dummy)
{
QofInstance *inst = QOF_INSTANCE(entity);
if (inst->priv->dirty)
printf("%s instance %s is dirty.\n", qof_entity_get_qof_type (QOF_ENTITY (inst),
guid_to_string(qof_entity_get_guid (QOF_ENTITY (inst)))));
printf("%s instance %s is dirty.\n", g_type_name (G_OBJECT_TYPE (inst)),
guid_to_string(qof_instance_get_guid (inst)));
}
gboolean
qof_instance_is_dirty (QofInstance *inst)
{
QofCollection *coll;
g_return_val_if_fail (QOF_IS_INSTANCE (inst), FALSE);
if (!inst) { return FALSE; }
if (qof_get_alt_dirty_mode())
{
return inst->priv->dirty;
coll = qof_entity_get_collection (QOF_ENTITY (inst));
if(qof_collection_is_dirty(coll)) { return inst->priv->dirty; }
}
coll = qof_instance_get_collection (inst);
if(qof_collection_is_dirty(coll))
{
return inst->priv->dirty;
}
inst->priv->dirty = FALSE;
return FALSE;
}
@@ -398,8 +445,9 @@ qof_instance_set_dirty(QofInstance* inst, gboolean value)
if (value) {
inst->priv->dirty = TRUE;
if (!qof_get_alt_dirty_mode()) {
coll = qof_entity_get_collection (QOF_ENTITY (inst));
coll = qof_book_get_collection (inst->priv->book, G_OBJECT_TYPE (inst));
qof_collection_mark_dirty(coll);
qof_book_mark_dirty (inst->priv->book); // This actualy a macro becouse the QofBook is a QofInstane: TODO: Check if QofBook could be a GObject
}
}
inst->priv->dirty = FALSE;
@@ -462,21 +510,21 @@ qof_instance_gemini (QofInstance *to, const QofInstance *from)
time_t now;
/* Books must differ for a gemini to be meaningful */
if (!from || !to || (from->book == to->book)) return;
if (!from || !to || (from->priv->book == to->priv->book)) return;
now = time(0);
/* 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,
gnc_kvp_bag_add (to->priv->kvp_data, "gemini", now,
"inst_guid", &from->priv->guid,
"book_guid", qof_instance_get_guid (QOF_INSTANCE (from->priv->book)),
NULL);
gnc_kvp_bag_add (from->kvp_data, "gemini", now,
"inst_guid", &to->entity.guid,
"book_guid", &to->book->inst.entity.guid,
gnc_kvp_bag_add (from->priv->kvp_data, "gemini", now,
"inst_guid", &to->priv->guid,
"book_guid", qof_instance_get_guid (QOF_INSTANCE (to->priv->book)),
NULL);
to->dirty = TRUE;
to->priv->dirty = TRUE;
}
QofInstance *
@@ -490,13 +538,13 @@ qof_instance_lookup_twin (const QofInstance *src, QofBook *target_book)
if (!src || !target_book) return NULL;
ENTER (" ");
fr = gnc_kvp_bag_find_by_guid (src->kvp_data, "gemini",
"book_guid", &target_book->inst.entity.guid);
fr = gnc_kvp_bag_find_by_guid (src->priv->kvp_data, "gemini",
"book_guid", qof_instance_get_guid (QOF_INSTANCE (target_book)));
twin_guid = kvp_frame_get_guid (fr, "inst_guid");
col = qof_book_get_collection (target_book, src->entity.e_type);
twin = (QofInstance *) qof_collection_lookup_entity (col, twin_guid);
col = qof_book_get_collection (target_book, G_OBJECT_TYPE (src));
twin = (QofInstance *) qof_collection_lookup_element (col, twin_guid);
LEAVE (" found twin=%p", twin);
return twin;
@@ -507,58 +555,96 @@ qof_instance_lookup_twin (const QofInstance *src, QofBook *target_book)
KvpFrame*
qof_instance_get_kvp_data (const QofInstance *instance)
{
return instance->kvp_data;
return instance->priv->kvp_data;
}
void
qof_instance_set_kvp_data (QofInstance *instance, KvpFrame *data)
{
kvp_frame_delete (instance->kvp_data);
instance->kvp_data = kvp_frame_copy (data);
kvp_frame_delete (instance->priv->kvp_data);
instance->priv->kvp_data = kvp_frame_copy (data);
}
void
qof_instance_delete_kvp_data (QofInstance *inst)
{
kvp_frame_delete (inst->priv->kvp_data);
}
/* Gets the Instance's Edit Level*/
gint qof_instance_get_edit_level (const QofInstance *instance)
{
return instance->editlevel;
return instance->priv->editlevel;
}
void qof_instance_set_edit_level (QofInstance *instance, gint editlevel)
void
qof_instance_set_edit_level (QofInstance *instance, gint editlevel)
{
instance->editlevel = editlevel;
instance->priv->editlevel = editlevel;
}
const char* qof_instance_printable (QofInstance *inst)
void
qof_instance_foreach (QofInstance *inst,
QofInstanceForeachCB cb_func,
gpointer user_data)
{
g_return_if_fail (QOF_IS_INSTANCE (inst));
QofCollection *col;
g_return_if_fail (QOF_IS_INSTANCE (inst));
if (QOF_INSTANCE_GET_CLASS (inst)->printable)
(QOF_INSTANCE_GET_CLASS (inst)->printable) (inst);
if (QOF_INSTANCE_GET_CLASS (inst)->foreach)
(QOF_INSTANCE_GET_CLASS (inst)->foreach) (inst, cb_func, user_data);
else
{
g_warning ("%s() calling default handler\n", __FUNCTION__);
col = qof_book_get_collection (inst->priv->book, G_OBJECT_TYPE (inst));
qof_collection_foreach (col, cb_func, user_data);
}
}
gchar*
qof_instance_to_string (QofInstance *inst)
{
gchar* ret = NULL;
g_return_val_if_fail (QOF_IS_INSTANCE (inst), NULL);
if (QOF_INSTANCE_GET_CLASS (inst)->to_string)
{
ret = ((QOF_INSTANCE_GET_CLASS (inst)->to_string) (inst));
return ret;
}
else
{
g_warning ("%s() method not supported\n", __FUNCTION__);
return NULL;
}
}
gboolean
qof_instance_begin_edit (QofInstance *inst, GError **error)
{
QofBackend * be;
g_return_val_if_fail (QOF_IS_INSTANCE (inst),FALSE);
g_return_val_if_fail (QOF_IS_INSTANCE (inst), FALSE);
g_signal_emit_by_name (inst, "begin-edit");
inst->priv->editlevel++;
g_return_val_if_fail (1 < inst->priv->editlevel), FALSE);
g_return_val_if_fail ((1 < inst->priv->editlevel), FALSE);
if (0 >= inst->editlevel)
inst->editlevel = 1;
if (0 >= inst->priv->editlevel)
inst->priv->editlevel = 1;
be = qof_book_get_backend (inst->priv->book);
if (QOF_IS_BACKEND (be) && qof_backend_begin_exists(be))
if (be && qof_backend_begin_exists(be))
qof_backend_run_begin (be, inst, error);
else
inst->priv->dirty = TRUE;
inst->priv->dirty = TRUE;
return TRUE;
}
@@ -568,11 +654,18 @@ qof_instance_commit_edit (QofInstance *inst, GError **error)
QofBackend * be;
gboolean dirty;
g_return_val_if_fail(QOF_IS_INSTANCE(inst), FALSE);
g_return_val_if_fail (QOF_IS_INSTANCE(inst), FALSE);
/* IMPROVEMENT: call a callback with a return type to see if I can actualy commit or not
* for example, in GncTransaction you can check if it is readonly, if you can't commit this function
* must return and set the error variable with the error (even better the **error pointer could be
* a parameter to the callback and set by it).
*/
g_signal_emit_by_name (inst, "commit:beginning");
inst->priv->editlevel--;
dirty = inst->dirty;
dirty = inst->priv->dirty;
if (0 < inst->priv->editlevel) return FALSE;
@@ -582,16 +675,16 @@ qof_instance_commit_edit (QofInstance *inst, GError **error)
if (be && qof_backend_commit_exists(be)) {
qof_backend_run_commit(be, inst, &error);
qof_backend_run_commit(be, inst, error);
if (error) {
/* XXX Should perform a rollback here */
inst->do_free = FALSE;
inst->priv->do_free = FALSE;
return FALSE;
}
/* XXX the backend commit code should clear dirty!! */
inst->dirty = FALSE;
inst->priv->dirty = FALSE;
}
}
@@ -602,11 +695,11 @@ qof_instance_commit_edit (QofInstance *inst, GError **error)
may be qof_book_mark_dirty (QofBook, GType) the you will mark the book and the
collection with that GType
*/
qof_collection_mark_dirty(qof_book_get_collection(inst->priv->book, G_TYPE_OBJECT(inst)));
qof_collection_mark_dirty(qof_book_get_collection(inst->priv->book, G_OBJECT_TYPE(inst)));
qof_book_mark_dirty(inst->priv->book);
}
inst->infant = FALSE;
inst->priv->infant = FALSE;
if (0 > inst->priv->editlevel) {
@@ -620,7 +713,9 @@ qof_instance_commit_edit (QofInstance *inst, GError **error)
}
return FALSE;
}
}
g_signal_emit_by_name (inst, "commit:finished");
return TRUE;
+47 -21
View File
@@ -36,11 +36,15 @@
#ifndef QOF_INSTANCE_H
#define QOF_INSTANCE_H
#include <glib-object.h>
#include "guid.h"
#include "gnc-date.h"
#include "kvp_frame.h"
#include "qofbook.h"
#include "qofid.h"
#ifndef QOF_BOOK_H
#define QOF_BOOK_DEFINED
typedef struct _QofBook QofBook;
#endif
/* GObject declarations */
@@ -51,40 +55,46 @@
#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 _QofInstanceClass QofInstanceClass;
typedef struct _QofInstancePrivate QofInstancePrivate;
typedef struct _QofInstance QofInstance;
#define QofEntity QofInstance /* Backward compatibility, the QofEntity is now "part" of QofInstance */
struct _QofInstance {
GObject object;
QofInstancePrivate *priv;
};
typedef void (*QofInstanceForeachCB) (QofInstance *inst, gpointer user_data);
typedef QofInstanceForeachCB QofEntityForeachCB; /* Backward compatibility */
struct _QofInstanceClass {
GObjectClass parent_class;
/* virtual table */
void (*foreach) (const QofCollection *, QofEntityForeachCB, gpointer);
const char * (*to_string) (gpointer instance);
void (*commit) (QofInstance* instance);
void
void (*foreach) (QofInstance *inst, QofInstanceForeachCB cb_func, gpointer user_data);
gchar* (*to_string) (gpointer instance);
/* Add Signal Functions Here */
};
GType qof_instance_get_type ();
GType qof_instance_get_type (void);
/** Return the book pointer */
QofBook * qof_instance_get_book (const QofInstance *);
QofBook * qof_instance_get_book (const QofInstance *inst);
void qof_instance_set_book (QofInstance *inst, QofBook *book);
QofCollection* qof_instance_get_collection (QofInstance *entity);
#define qof_instance_get_collection(o) qof_book_get_collection(qof_instance_get_book(o), G_OBJECT_TYPE(o))
/** Return the GUID of this instance */
const GUID * qof_instance_get_guid (const QofInstance *);
GUID* qof_instance_get_guid (QofInstance *inst);
/** 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 (QofInstance *inst, const GUID *guid);
void qof_instance_set_guid (QofInstance *inst, GUID *guid);
/** Return the pointer to the kvp_data */
KvpFrame* qof_instance_get_slots (const QofInstance *);
@@ -106,7 +116,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 (QofInstance *inst, gpointer dummy);
/** Return value of is_dirty flag */
gboolean qof_instance_is_dirty (QofInstance *);
@@ -125,9 +135,11 @@ void qof_instance_mark_free(QofInstance *inst);
QofInstance* qof_instance_create (GType type, QofBook *book);
void qof_instance_destroy (QofInstance *inst);
gboolean qof_instance_destroy (QofInstance *inst, GError **error);
#define qof_instance_release(instance) qof_instance_destroy(instance)
void qof_instance_release (QofInstance *instance);
#define qof_entity_release(obj) qof_instance_release (QOF_INSTANCE (obj))
/** 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
@@ -158,21 +170,35 @@ QofInstance * qof_instance_lookup_twin (const QofInstance *src, QofBook *book);
KvpFrame* qof_instance_get_kvp_data (const QofInstance *instance);
void qof_instance_set_kvp_data (QofInstance *instance, KvpFrame *data);
void qof_instance_delete_kvp_data (QofInstance *inst);
gint qof_instance_get_edit_level (const QofInstance *instance);
void qof_instance_set_edit_level (QofInstance *instance, gint editlevel);
#define qof_object_new_instance (type, book) g_object_new (type, "book", book, NULL)
#define qof_object_new_instance(type, book) g_object_new (type, "book", book, NULL)
const char * qof_instance_to_string (QofInstance *instance);
void qof_instance_foreach (QofInstance *inst, QofInstanceForeachCB cb_func, gpointer user_data);
#define qof_object_printable (type, instance) qof_instance_to_string (instance)
gboolean qof_instance_begin_edit (QofInstance *inst, GError *error);
gchar * qof_instance_to_string (QofInstance *instance);
gboolean qof_instance_commit_edit(QofInstance *inst, GError *error);
#define qof_object_printable(type, instance) qof_instance_to_string (instance)
gboolean qof_instance_destroy (QofInstance *inst);
gboolean qof_instance_begin_edit (QofInstance *inst, GError **error);
gboolean qof_instance_commit_edit(QofInstance *inst, GError **error);
/** Return The kvp data for the book.
* Note that the book KVP data is persistent, and is stored/retrieved
* from the file/database. Thus, the book KVP is the correct place to
* store data that needs to be persistent accross sessions (or shared
* between multiple users). To store application runtime data, use
* qof_book_set_data() instead.
DEPRECATED: use qof_instance_get_slots instead
*/
#define qof_book_get_slots(book) qof_instance_get_slots(QOF_INSTANCE(book))
/* @} */
/* @} */
+17 -13
View File
@@ -38,12 +38,13 @@ static GList *object_modules = NULL;
static GList *book_list = NULL;
static GHashTable *backend_data = NULL;
/* DEPRACATED use g_object_new see qofinstance.h
gpointer
qof_object_new_instance (QofIdTypeConst type_name, QofBook *book)
{
const QofObject *obj;
if (!type_name) return NULL;
if (type_name == G_TYPE_INVALID) return NULL;
obj = qof_object_lookup (type_name);
if (!obj) return NULL;
@@ -53,6 +54,7 @@ qof_object_new_instance (QofIdTypeConst type_name, QofBook *book)
return NULL;
}
*/
void qof_object_book_begin (QofBook *book)
{
@@ -146,14 +148,14 @@ qof_object_compliance (QofIdTypeConst type_name, gboolean warn)
if((obj->create == NULL)||(obj->foreach == NULL)){
if(warn)
{
PINFO (" Object type %s is not fully QOF compliant", obj->e_type);
PINFO (" Object type %s is not fully QOF compliant", g_type_name (obj->e_type));
}
return FALSE;
}
return TRUE;
}
/* DEPRACATED see qofinstance.h
void
qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofEntityForeachCB cb, gpointer user_data)
@@ -179,6 +181,8 @@ qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
return;
}
const char *
qof_object_printable (QofIdTypeConst type_name, gpointer obj)
{
@@ -194,7 +198,7 @@ qof_object_printable (QofIdTypeConst type_name, gpointer obj)
return NULL;
}
*/
const char * qof_object_get_type_label (QofIdTypeConst type_name)
{
const QofObject *obj;
@@ -213,10 +217,10 @@ static gboolean clear_table (gpointer key, gpointer value, gpointer user_data)
return TRUE;
}
/* INITIALIZATION and PRIVATE FUNCTIONS */
void qof_object_initialize (void)
{
void qof_object_initialize (void){
if (object_is_initialized) return;
backend_data = g_hash_table_new (g_str_hash, g_str_equal);
object_is_initialized = TRUE;
@@ -275,7 +279,7 @@ const QofObject * qof_object_lookup (QofIdTypeConst name)
for (iter = object_modules; iter; iter = iter->next) {
obj = iter->data;
if (!safe_strcmp (obj->e_type, name))
if (obj->e_type == name)
return obj;
}
return NULL;
@@ -288,7 +292,7 @@ gboolean qof_object_register_backend (QofIdTypeConst type_name,
GHashTable *ht;
g_return_val_if_fail (object_is_initialized, FALSE);
if (!type_name || *type_name == '\0' ||
if (!type_name || type_name == G_TYPE_INVALID ||
!backend_name || *backend_name == '\0' ||
!be_data)
return FALSE;
@@ -297,12 +301,12 @@ gboolean qof_object_register_backend (QofIdTypeConst type_name,
/* If it doesn't already exist, create a new table for this backend */
if (!ht) {
ht = g_hash_table_new (g_str_hash, g_str_equal);
ht = g_hash_table_new (g_int_hash, g_int_equal);
g_hash_table_insert (backend_data, (char *)backend_name, ht);
}
/* Now insert the data */
g_hash_table_insert (ht, (char *)type_name, be_data);
g_hash_table_insert (ht, GINT_TO_POINTER (type_name), be_data);
return TRUE;
}
@@ -312,7 +316,7 @@ gpointer qof_object_lookup_backend (QofIdTypeConst type_name,
{
GHashTable *ht;
if (!type_name || *type_name == '\0' ||
if (!type_name || type_name == G_TYPE_INVALID ||
!backend_name || *backend_name == '\0')
return NULL;
@@ -320,7 +324,7 @@ gpointer qof_object_lookup_backend (QofIdTypeConst type_name,
if (!ht)
return NULL;
return g_hash_table_lookup (ht, (char *)type_name);
return g_hash_table_lookup (ht, GINT_TO_POINTER (type_name));
}
struct foreach_data {
@@ -330,7 +334,7 @@ struct foreach_data {
static void foreach_backend (gpointer key, gpointer be_item, gpointer arg)
{
char *data_type = key;
GType data_type = GPOINTER_TO_INT(key);
struct foreach_data *cb_data = arg;
g_return_if_fail (key && be_item && arg);
+5 -4
View File
@@ -48,6 +48,7 @@
#ifndef QOF_OBJECT_H_
#define QOF_OBJECT_H_
#include <glib.h>
#include "qofbook.h"
#include "qofid.h"
#include "qofchoice.h"
@@ -139,7 +140,7 @@ const QofObject * qof_object_lookup (QofIdTypeConst type_name);
* instance. This routine just calls the (*new) callback on the object
* definition.
*/
gpointer qof_object_new_instance (QofIdTypeConst type_name, QofBook *book);
/* gpointer qof_object_new_instance (QofIdTypeConst type_name, QofBook *book); */
/** Get the printable label for a type. This label is *not*
* translated; you must use _() on it if you want a translated version.
@@ -147,7 +148,7 @@ gpointer qof_object_new_instance (QofIdTypeConst type_name, QofBook *book);
const char * qof_object_get_type_label (QofIdTypeConst type_name);
/** @return a Human-readable string name for an instance */
const char * qof_object_printable (QofIdTypeConst type_name, gpointer instance);
/* const char * qof_object_printable (QofIdTypeConst type_name, gpointer instance); */
/** Invoke the callback 'cb' on every object class definition.
* The user_data pointer is passed back to the callback.
@@ -159,8 +160,8 @@ void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data);
* identifies a colllection of instances; thus the callback will
* be invoked only for those instances stored in the book.
*/
void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofEntityForeachCB cb, gpointer user_data);
/*void qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
QofEntityForeachCB cb, gpointer user_data);*/
/** Register and lookup backend-specific data for this particular object */
gboolean qof_object_register_backend (QofIdTypeConst type_name,
+35 -31
View File
@@ -422,14 +422,14 @@ compile_params (GSList *param_list, QofIdType start_obj,
const QofParam *objDef = NULL;
GSList *fcns = NULL;
ENTER ("param_list=%p id=%s", param_list, start_obj);
ENTER ("param_list=%p id=%s", param_list, g_type_name(start_obj));
g_return_val_if_fail (param_list, NULL);
g_return_val_if_fail (start_obj, NULL);
g_return_val_if_fail (final, NULL);
for (; param_list; param_list = param_list->next)
{
QofIdType param_name = param_list->data;
gchar* param_name = param_list->data; /*FIXME: Convert to QofParam pointer instead */
objDef = qof_class_get_parameter (start_obj, param_name);
/* If it doesn't exist, then we've reached the end */
@@ -454,7 +454,7 @@ compile_sort (QofQuerySort *sort, QofIdType obj)
{
const QofParam *resObj = NULL;
ENTER ("sort=%p id=%s params=%p", sort, obj, sort->param_list);
ENTER ("sort=%p id=%s params=%p", sort, g_type_name(obj), sort->param_list);
sort->use_default = FALSE;
g_slist_free (sort->param_fcns);
@@ -489,7 +489,7 @@ compile_sort (QofQuerySort *sort, QofIdType obj)
{
sort->use_default = TRUE;
}
LEAVE ("sort=%p id=%s", sort, obj);
LEAVE ("sort=%p id=%s", sort, g_type_name(obj));
}
static void compile_terms (QofQuery *q)
@@ -533,7 +533,7 @@ static void compile_terms (QofQuery *q)
/* Now compile the backend instances */
for (node = q->books; node; node = node->next) {
QofBook *book = node->data;
QofBackend *be = book->backend;
QofBackend *be = qof_book_get_backend (book);
if (be && be->compile_query) {
gpointer result = (be->compile_query)(be, q);
@@ -595,7 +595,7 @@ static gboolean
query_free_compiled (gpointer key, gpointer value, gpointer not_used)
{
QofBook* book = key;
QofBackend* be = book->backend;
QofBackend* be = qof_book_get_backend (book);
if (be && be->free_query)
(be->free_query)(be, value);
@@ -785,6 +785,7 @@ static GList * qof_query_run_internal (QofQuery *q,
static void qof_query_run_cb(QofQueryCB* qcb, gpointer cb_arg)
{
GList *node;
QofCollection *col;
(void)cb_arg; /* unused */
g_return_if_fail(qcb);
@@ -792,7 +793,7 @@ static void qof_query_run_cb(QofQueryCB* qcb, gpointer cb_arg)
for (node=qcb->query->books; node; node=node->next)
{
QofBook *book = node->data;
QofBackend *be = book->backend;
QofBackend *be = qof_book_get_backend (book);
/* run the query in the backend */
if (be)
@@ -807,8 +808,9 @@ 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);
col = qof_book_get_collection (book, qcb->query->search_for);
qof_collection_foreach (col, (QofInstanceForeachCB) check_item_cb, qcb);
}
}
@@ -835,8 +837,7 @@ qof_query_run_subquery (QofQuery *subq, const QofQuery* primaryq)
/* Make sure we're searching for the same thing */
g_return_val_if_fail (subq->search_for, NULL);
g_return_val_if_fail (primaryq->search_for, NULL);
g_return_val_if_fail(!safe_strcmp(subq->search_for, primaryq->search_for),
NULL);
g_return_val_if_fail(!subq->search_for == primaryq->search_for, NULL);
/* Perform the subquery */
return qof_query_run_internal(subq, qof_query_run_subq_cb,
@@ -869,6 +870,7 @@ QofQuery * qof_query_create (void)
{
QofQuery *qp = g_new0 (QofQuery, 1);
qp->be_compiled = g_hash_table_new (g_direct_hash, g_direct_equal);
qp->search_for = G_TYPE_INVALID;
query_init (qp, NULL);
return qp;
}
@@ -878,7 +880,7 @@ void qof_query_search_for (QofQuery *q, QofIdTypeConst obj_type)
if (!q || !obj_type)
return;
if (safe_strcmp (q->search_for, obj_type)) {
if (q->search_for == obj_type) {
q->search_for = (QofIdType) obj_type;
q->changed = 1;
}
@@ -1086,7 +1088,9 @@ qof_query_merge(QofQuery *q1, QofQuery *q2, QofQueryOp op)
if(!q2) return q1;
if (q1->search_for && q2->search_for)
g_return_val_if_fail (safe_strcmp (q1->search_for, q2->search_for) == 0,
g_return_val_if_fail ((q1->search_for == q2->search_for)
|| q1->search_for == G_TYPE_INVALID
|| q2->search_for == G_TYPE_INVALID,
NULL);
search_for = (q1->search_for ? q1->search_for : q2->search_for);
@@ -1277,10 +1281,10 @@ void qof_query_set_book (QofQuery *q, QofBook *book)
if (g_list_index (q->books, book) == -1)
q->books = g_list_prepend (q->books, book);
slist = g_slist_prepend (slist, QOF_PARAM_GUID);
slist = g_slist_prepend (slist, QOF_PARAM_BOOK);
slist = g_slist_prepend (slist, GINT_TO_POINTER (QOF_PARAM_GUID));
slist = g_slist_prepend (slist, GINT_TO_POINTER (QOF_PARAM_BOOK));
qof_query_add_guid_match (q, slist,
qof_book_get_guid(book), QOF_QUERY_AND);
qof_instance_get_guid(QOF_INSTANCE (book)), QOF_QUERY_AND);
}
GList * qof_query_get_books (QofQuery *q)
@@ -1324,7 +1328,7 @@ int qof_query_get_max_results (QofQuery *q)
QofIdType qof_query_get_search_for (QofQuery *q)
{
if (!q) return NULL;
if (!q) return G_TYPE_INVALID;
return q->search_for;
}
@@ -1542,7 +1546,7 @@ qof_query_printSearchFor (QofQuery * query, GList * output)
searchFor = qof_query_get_search_for (query);
gs = g_string_new ("Query Object Type: ");
g_string_append (gs, (NULL == searchFor)? "(null)" : searchFor);
g_string_append (gs, (G_TYPE_INVALID == searchFor)? "(null)" : g_type_name (searchFor));
output = g_list_append (output, gs);
return output;
@@ -1604,7 +1608,7 @@ qof_query_printSorts (QofQuerySort *s[], const gint numSorts, GList * output)
if (gsl) g_string_append_printf (gs, " Param: ");
for (n=gsl; n; n = n->next)
{
QofIdType param_name = n->data;
gchar* param_name = n->data;
if (gsl != n) g_string_append_printf (gs, " ");
g_string_append_printf (gs, "%s", param_name);
}
@@ -1683,8 +1687,8 @@ qof_query_printPredData (QofQueryPredData *pd, GList *lst)
g_string_append (gs, (gchar *) pd->type_name);
/* Char Predicate and GUID predicate don't use the 'how' field. */
if (safe_strcmp (pd->type_name, QOF_TYPE_CHAR) &&
safe_strcmp (pd->type_name, QOF_TYPE_GUID))
if ((pd->type_name == QOF_TYPE_CHAR) &&
(pd->type_name == QOF_TYPE_GUID))
{
g_string_append_printf (gs, " how: %s",
qof_query_printStringForHow (pd->how));
@@ -1728,7 +1732,7 @@ static void
qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
{
if (!safe_strcmp (pd->type_name, QOF_TYPE_GUID))
if (pd->type_name == QOF_TYPE_GUID)
{
GList *node;
query_guid_t pdata = (query_guid_t) pd;
@@ -1742,7 +1746,7 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
}
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING))
if (pd->type_name == QOF_TYPE_STRING)
{
query_string_t pdata = (query_string_t) pd;
g_string_append_printf (gs, " Match type %s",
@@ -1752,7 +1756,7 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
pdata->matchstring);
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_NUMERIC))
if (pd->type_name == QOF_TYPE_NUMERIC)
{
query_numeric_t pdata = (query_numeric_t) pd;
g_string_append_printf (gs, " Match type %s",
@@ -1761,7 +1765,7 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
gnc_num_dbg_to_string (pdata->amount));
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_KVP))
if (pd->type_name == QOF_TYPE_KVP)
{
GSList *node;
query_kvp_t pdata = (query_kvp_t) pd;
@@ -1774,25 +1778,25 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
kvp_value_to_string (pdata->value));
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_INT64))
if (pd->type_name == QOF_TYPE_INT64)
{
query_int64_t pdata = (query_int64_t) pd;
g_string_append_printf (gs, " int64: %" G_GINT64_FORMAT, pdata->val);
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_INT32))
if (pd->type_name == QOF_TYPE_INT32)
{
query_int32_t pdata = (query_int32_t) pd;
g_string_append_printf (gs, " int32: %d", pdata->val);
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_DOUBLE))
if (pd->type_name == QOF_TYPE_DOUBLE)
{
query_double_t pdata = (query_double_t) pd;
g_string_append_printf (gs, " double: %.18g", pdata->val);
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_DATE))
if (pd->type_name == QOF_TYPE_DATE)
{
query_date_t pdata = (query_date_t) pd;
g_string_append_printf (gs, " Match type %s",
@@ -1800,7 +1804,7 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
g_string_append_printf (gs, " query_date: %s", gnc_print_date (pdata->date));
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_CHAR))
if (pd->type_name, QOF_TYPE_CHAR)
{
query_char_t pdata = (query_char_t) pd;
g_string_append_printf (gs, " Match type %s",
@@ -1808,7 +1812,7 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
g_string_append_printf (gs, " char list: %s", pdata->char_list);
return;
}
if (!safe_strcmp (pd->type_name, QOF_TYPE_BOOLEAN))
if (pd->type_name == QOF_TYPE_BOOLEAN)
{
query_boolean_t pdata = (query_boolean_t) pd;
g_string_append_printf (gs, " boolean: %s", pdata->val?"TRUE":"FALSE");
+4 -3
View File
@@ -78,6 +78,7 @@ probably optimize.
#include "qofbook.h"
#include "qofquerycore.h"
#include "qofchoice.h"
#include "qofid.h"
#define QOF_MOD_QUERY "qof-query"
@@ -100,11 +101,11 @@ typedef enum {
#define QUERY_DEFAULT_SORT "QofQueryDefaultSort"
/** "Known" Object Parameters -- all objects must support these */
#define QOF_PARAM_BOOK "book"
#define QOF_PARAM_GUID "guid"
#define QOF_PARAM_BOOK QOF_TYPE_BOOK
#define QOF_PARAM_GUID GNC_TYPE_GUID
/** "Known" Object Parameters -- some objects might support these */
#define QOF_PARAM_KVP "kvp"
#define QOF_PARAM_KVP GNC_TYPE_KVP_FRAME
#define QOF_PARAM_ACTIVE "active"
#define QOF_PARAM_VERSION "version"
+2 -2
View File
@@ -46,8 +46,8 @@ typedef gint (*QofQueryPredicateFunc) (gpointer object,
QofQueryPredData *pdata);
/* Lookup functions */
QofQueryPredicateFunc qof_query_core_get_predicate (gchar const *type);
QofCompareFunc qof_query_core_get_compare (gchar const *type);
QofQueryPredicateFunc qof_query_core_get_predicate (QofType type);
QofCompareFunc qof_query_core_get_compare (QofType type);
/* Compare two predicates */
gboolean qof_query_core_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2);
+34 -37
View File
@@ -54,41 +54,41 @@ static QueryPredDataFree qof_query_predicate_free (QofType type);
/* Core Type Predicate helpers */
typedef const char * (*query_string_getter) (gpointer, QofParam *);
static const char * query_string_type = QOF_TYPE_STRING;
#define query_string_type QOF_TYPE_STRING
typedef Timespec (*query_date_getter) (gpointer, QofParam *);
static const char * query_date_type = QOF_TYPE_DATE;
#define query_date_type QOF_TYPE_DATE
typedef gnc_numeric (*query_numeric_getter) (gpointer, QofParam *);
static const char * query_numeric_type = QOF_TYPE_NUMERIC;
#define query_numeric_type QOF_TYPE_NUMERIC
typedef GList * (*query_glist_getter) (gpointer, QofParam *);
typedef const GUID * (*query_guid_getter) (gpointer, QofParam *);
static const char * query_guid_type = QOF_TYPE_GUID;
#define query_guid_type QOF_TYPE_GUID
typedef gint32 (*query_int32_getter) (gpointer, QofParam *);
static const char * query_int32_type = QOF_TYPE_INT32;
#define query_int32_type QOF_TYPE_INT32
typedef gint64 (*query_int64_getter) (gpointer, QofParam *);
static const char * query_int64_type = QOF_TYPE_INT64;
#define query_int64_type QOF_TYPE_INT64
typedef double (*query_double_getter) (gpointer, QofParam *);
static const char * query_double_type = QOF_TYPE_DOUBLE;
#define query_double_type QOF_TYPE_DOUBLE
typedef gboolean (*query_boolean_getter) (gpointer, QofParam *);
static const char * query_boolean_type = QOF_TYPE_BOOLEAN;
#define query_boolean_type QOF_TYPE_BOOLEAN
typedef char (*query_char_getter) (gpointer, QofParam *);
static const char * query_char_type = QOF_TYPE_CHAR;
#define query_char_type QOF_TYPE_CHAR
typedef KvpFrame * (*query_kvp_getter) (gpointer, QofParam *);
static const char * query_kvp_type = QOF_TYPE_KVP;
#define query_kvp_type QOF_TYPE_KVP
typedef QofCollection * (*query_collect_getter) (gpointer, QofParam*);
static const char * query_collect_type = QOF_TYPE_COLLECT;
#define query_collect_type QOF_TYPE_COLLECT
typedef const GUID * (*query_choice_getter) (gpointer, QofParam *);
static const char * query_choice_type = QOF_TYPE_CHOICE;
#define query_choice_type QOF_TYPE_CHOICE
/* Tables for predicate storage and lookup */
static gboolean initialized = FALSE;
@@ -102,23 +102,20 @@ static GHashTable *predEqualTable = NULL;
#define COMPARE_ERROR -3
#define PREDICATE_ERROR -2
#define VERIFY_PDATA(str) { \
#define VERIFY_PDATA(type) { \
g_return_if_fail (pd != NULL); \
g_return_if_fail (pd->type_name == str || \
!safe_strcmp (str, pd->type_name)); \
g_return_if_fail (pd->type_name == type); \
}
#define VERIFY_PDATA_R(str) { \
#define VERIFY_PDATA_R(type) { \
g_return_val_if_fail (pd != NULL, NULL); \
g_return_val_if_fail (pd->type_name == str || \
!safe_strcmp (str, pd->type_name), \
g_return_val_if_fail (pd->type_name == type, \
NULL); \
}
#define VERIFY_PREDICATE(str) { \
#define VERIFY_PREDICATE(type) { \
g_return_val_if_fail (getter != NULL, PREDICATE_ERROR); \
g_return_val_if_fail (getter->param_getfcn != NULL, PREDICATE_ERROR); \
g_return_val_if_fail (pd != NULL, PREDICATE_ERROR); \
g_return_val_if_fail (pd->type_name == str || \
!safe_strcmp (str, pd->type_name), \
g_return_val_if_fail (pd->type_name == type, \
PREDICATE_ERROR); \
}
@@ -1450,13 +1447,13 @@ collect_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
}
static void
query_collect_cb(QofEntity* ent, gpointer user_data)
query_collect_cb(QofInstance* inst, 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(inst);
pdata = (query_coll_t)user_data;
pdata->guids = g_list_append(pdata->guids, guid);
}
@@ -1660,7 +1657,7 @@ qof_query_register_core_object (QofType core_name,
QueryPredicateEqual pred_equal)
{
g_return_if_fail (core_name);
g_return_if_fail (*core_name != '\0');
g_return_if_fail (core_name != G_TYPE_INVALID);
if (pred)
g_hash_table_insert (predTable, (char *)core_name, pred);
@@ -1752,7 +1749,7 @@ qof_query_copy_predicate (QofType type)
{
QueryPredicateCopyFunc rc;
g_return_val_if_fail (type, NULL);
rc = g_hash_table_lookup (copyTable, type);
rc = g_hash_table_lookup (copyTable, GINT_TO_POINTER (type));
return rc;
}
@@ -1760,7 +1757,7 @@ static QueryPredDataFree
qof_query_predicate_free (QofType type)
{
g_return_val_if_fail (type, NULL);
return g_hash_table_lookup (freeTable, type);
return g_hash_table_lookup (freeTable, GINT_TO_POINTER (type));
}
/********************************************************************/
@@ -1773,12 +1770,12 @@ void qof_query_core_init (void)
initialized = TRUE;
/* Create the tables */
predTable = g_hash_table_new (g_str_hash, g_str_equal);
cmpTable = g_hash_table_new (g_str_hash, g_str_equal);
copyTable = g_hash_table_new (g_str_hash, g_str_equal);
freeTable = g_hash_table_new (g_str_hash, g_str_equal);
toStringTable = g_hash_table_new (g_str_hash, g_str_equal);
predEqualTable = g_hash_table_new (g_str_hash, g_str_equal);
predTable = g_hash_table_new (g_int_hash, g_int_equal);
cmpTable = g_hash_table_new (g_int_hash, g_int_equal);
copyTable = g_hash_table_new (g_int_hash, g_int_equal);
freeTable = g_hash_table_new (g_int_hash, g_int_equal);
toStringTable = g_hash_table_new (g_int_hash, g_int_equal);
predEqualTable = g_hash_table_new (g_int_hash, g_int_equal);
init_tables ();
}
@@ -1800,14 +1797,14 @@ QofQueryPredicateFunc
qof_query_core_get_predicate (QofType type)
{
g_return_val_if_fail (type, NULL);
return g_hash_table_lookup (predTable, type);
return g_hash_table_lookup (predTable, GINT_TO_POINTER (type));
}
QofCompareFunc
qof_query_core_get_compare (QofType type)
{
g_return_val_if_fail (type, NULL);
return g_hash_table_lookup (cmpTable, type);
return g_hash_table_lookup (cmpTable, GINT_TO_POINTER (type));
}
void
@@ -1844,7 +1841,7 @@ qof_query_core_to_string (QofType type, gpointer object,
g_return_val_if_fail (object, NULL);
g_return_val_if_fail (getter, NULL);
toString = g_hash_table_lookup (toStringTable, type);
toString = g_hash_table_lookup (toStringTable, GINT_TO_POINTER (type));
g_return_val_if_fail (toString, NULL);
return toString (object, getter);
@@ -1859,9 +1856,9 @@ qof_query_core_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
if (!p1 || !p2) return FALSE;
if (p1->how != p2->how) return FALSE;
if (safe_strcmp (p1->type_name, p2->type_name)) return FALSE;
if (p1->type_name != p2->type_name) return FALSE;
pred_equal = g_hash_table_lookup (predEqualTable, p1->type_name);
pred_equal = g_hash_table_lookup (predEqualTable, GINT_TO_POINTER (p1->type_name));
g_return_val_if_fail (pred_equal, FALSE);
return pred_equal (p1, p2);
+70 -61
View File
@@ -20,145 +20,154 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* DEPRECATED FILE
THIS FILE ISN'T USED ANY WHERE
*/
#include "config.h"
#include <glib.h>
#include "qofreference.h"
static void
entity_set_reference_cb(QofEntity *ent, gpointer user_data)
instance_set_reference_cb(QofInstance *inst, 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;
GError *error = NULL;
partial_book = (QofBook*)user_data;
g_return_if_fail(partial_book || ent);
g_return_if_fail(partial_book || QOF_IS_INSTANCE (inst));
reference = NULL;
coll = NULL;
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(inst)))
{
/* avoid setting the entity's own guid as a reference. */
/* avoid setting the instance's own guid as a reference. */
book_ref_list = g_list_next(book_ref_list);
continue;
}
if(qof_object_is_choice(ent->e_type)) { type = ref->choice_type; }
if(qof_object_is_choice(G_OBJECT_TYPE ( G_OBJECT (inst)))) { type = ref->choice_type; }
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 = qof_collection_lookup_element (coll, ref->ref_guid);
reference_setter = (void(*)(QofInstance*, QofInstance*))ref->param->param_setfcn;
if((reference) && (reference_setter))
{
qof_begin_edit((QofInstance*)ent);
qof_begin_edit(inst);
qof_begin_edit((QofInstance*)reference);
reference_setter(ent, reference);
qof_commit_edit((QofInstance*)ent);
qof_commit_edit((QofInstance*)reference);
reference_setter(inst, reference);
qof_commit_edit(inst);
qof_commit_edit(reference);
}
/* collect and choice handling */
collect_setter = (void(*)(QofEntity*, QofCollection*))ref->param->param_setfcn;
choice_setter = (void(*)(QofEntity*, QofEntity*))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 == safe_strcmp(ref->type, ent->e_type)))
collect_setter = (void(*)(QofInstance*, QofCollection*))ref->param->param_setfcn;
choice_setter = (void(*)(QofInstance*, QofInstance*))ref->param->param_setfcn;
if ((ref->param->param_type == QOF_TYPE_COLLECT) &&
(0 == guid_compare(qof_instance_get_guid(inst), ref->inst_guid)) &&
(ref->type == G_OBJECT_TYPE (G_OBJECT (inst))))
{
QofCollection *temp_col;
char cm_sa[GUID_ENCODING_LENGTH + 1];
temp_col = ref->param->param_getfcn(ent, ref->param);
temp_col = ref->param->param_getfcn(inst, ref->param);
coll = qof_book_get_collection(partial_book,
qof_collection_get_type(temp_col));
qof_collection_get_g_type((const QofCollection*) temp_col));
guid_to_string_buff(ref->ref_guid, cm_sa);
reference = qof_collection_lookup_entity(coll, ref->ref_guid);
reference = qof_collection_lookup_element (coll, ref->ref_guid);
if(reference) {
qof_collection_add_entity(temp_col, reference);
qof_begin_edit((QofInstance*)ent);
qof_begin_edit((QofInstance*)reference);
if(collect_setter) { collect_setter(ent, temp_col); }
qof_commit_edit((QofInstance*)ent);
qof_commit_edit((QofInstance*)reference);
qof_collection_add_element(temp_col, reference);
qof_begin_edit(inst);
qof_begin_edit(reference);
if(collect_setter) { collect_setter(inst, temp_col); }
qof_commit_edit(inst);
qof_commit_edit(reference);
qof_collection_destroy(temp_col);
}
}
if(0 == safe_strcmp(ref->param->param_type, QOF_TYPE_CHOICE))
if(ref->param->param_type == QOF_TYPE_CHOICE)
{
coll = qof_book_get_collection(partial_book, ref->type);
reference = qof_collection_lookup_entity(coll, ref->ref_guid);
qof_begin_edit((QofInstance*)ent);
qof_begin_edit((QofInstance*)reference);
if(choice_setter) { choice_setter(ent, reference); }
qof_commit_edit((QofInstance*)ent);
qof_commit_edit((QofInstance*)reference);
reference = qof_collection_lookup_element (coll, ref->ref_guid);
qof_begin_edit(inst);
qof_begin_edit(reference);
if(choice_setter) { choice_setter(inst, reference); }
qof_commit_edit(inst);
qof_commit_edit(reference);
}
book_ref_list = g_list_next(book_ref_list);
}
}
static void
set_each_type(QofObject *obj, gpointer user_data)
set_each_type(QofCollection *col, gpointer user_data)
{
QofBook *book;
book = (QofBook*)user_data;
qof_object_foreach(obj->e_type, book, entity_set_reference_cb, book);
qof_collection_foreach (col, instance_set_reference_cb, book);
}
static QofEntityReference*
create_reference(QofEntity *ent, const QofParam *param)
static QofInstanceReference*
create_reference(QofInstance *inst, const QofParam *param)
{
QofEntityReference *reference;
QofEntity *ref_ent;
QofInstanceReference *reference;
QofInstance *ref_inst;
const GUID *cm_guid;
char cm_sa[GUID_ENCODING_LENGTH + 1];
gchar *cm_string;
ref_ent = (QofEntity*)param->param_getfcn(ent, param);
if(!ref_ent) { return NULL; }
reference = g_new0(QofEntityReference, 1);
reference->type = ent->e_type;
ref_inst = (QofInstance*)param->param_getfcn(inst, param);
if(!ref_inst) { return NULL; }
reference = g_new0(QofInstanceReference, 1);
reference->type = G_OBJECT_TYPE (G_OBJECT (inst));
reference->ref_guid = g_new(GUID, 1);
reference->ent_guid = &ent->guid;
if(qof_object_is_choice(ent->e_type))
reference->inst_guid = qof_instance_get_guid (inst);
if(qof_object_is_choice(G_OBJECT_TYPE (G_OBJECT (inst))))
{
reference->choice_type = ref_ent->e_type;
reference->choice_type = G_OBJECT_TYPE (G_OBJECT (ref_inst));
}
reference->param = param;
cm_guid = qof_entity_get_guid(ref_ent);
cm_guid = qof_instance_get_guid(ref_inst);
guid_to_string_buff(cm_guid, cm_sa);
cm_string = g_strdup(cm_sa);
if(TRUE == string_to_guid(cm_string, reference->ref_guid)) {
g_free(cm_string);
return reference;
}
}
g_free(cm_string);
return NULL;
}
QofEntityReference*
qof_entity_get_reference_from(QofEntity *ent, const QofParam *param)
QofInstanceReference*
qof_instance_get_reference_from(QofInstance *inst, const QofParam *param)
{
g_return_val_if_fail(param, NULL);
param = qof_class_get_parameter(ent->e_type, param->param_name);
g_return_val_if_fail(0 != safe_strcmp(param->param_type, QOF_TYPE_COLLECT), NULL);
return create_reference(ent, param);
param = qof_class_get_parameter(G_OBJECT_TYPE (G_OBJECT (inst)), param->param_name);
g_return_val_if_fail(param->param_type != QOF_TYPE_COLLECT, NULL);
return create_reference (inst, param);
}
void qof_book_set_references(QofBook *book)
void
qof_book_set_references (QofBook *book)
{
gboolean partial;
QofInstance *inst;
partial =
(gboolean)GPOINTER_TO_INT(qof_book_get_data(book, PARTIAL_QOFBOOK));
g_return_if_fail(partial);
qof_object_foreach_type(set_each_type, book);
qof_book_foreach_collection (book, set_each_type, (gpointer) book);
}
+10 -6
View File
@@ -21,6 +21,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* DEPRECATED FILE
THIS FILE ISN'T USED ANY WHERE
*/
#ifndef _QOFREFERENCE_H
#define _QOFREFERENCE_H
@@ -102,7 +106,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 -
@@ -111,8 +115,8 @@ typedef struct qof_entity_reference {
GUID *ref_guid; /**< The GUID of the REFERENCE entity */
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;
const GUID *inst_guid; /**< The GUID of the original entity. */
}QofInstanceReference;
/** \brief Adds a new reference to the partial book data hash.
@@ -122,7 +126,7 @@ 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.
*
@@ -201,8 +205,8 @@ the integrity of the partial book during sequential copy operations.
@return FALSE on error, otherwise a pointer to the QofEntityReference.
*/
QofEntityReference*
qof_entity_get_reference_from(QofEntity *ent, const QofParam *param);
QofInstanceReference*
qof_instance_get_reference_from(QofInstance *inst, const QofParam *param);
/** @} */
/** @} */
+4 -1
View File
@@ -37,8 +37,11 @@ struct _QofSession
/* This is just a "fake" entry point to allow me to pass a Session as
* an Entity. NOTE: THIS IS NOT AN ENTITY! THE ONLY PART OF ENTITY
* THAT IS VALID IS E_TYPE!
*
*/
QofEntity entity;
/* FIXME: if not an entity where is used as an entity????
* QofInstance entity;
*/
/* A book holds pointers to the various types of datasets.
* A session may have multiple books. */
+146 -145
View File
@@ -110,19 +110,20 @@ static void
qof_session_clear_error (QofSession *session)
{
QofBackendError err;
GError *error;
session->last_err = ERR_BACKEND_NO_ERR;
g_free(session->error_message);
session->error_message = NULL;
/* pop the stack on the backend as well. */
if (session->backend)
{
do
{
err = qof_backend_get_error (session->backend);
} while (ERR_BACKEND_NO_ERR != err);
qof_backend_error_free (session->backend);
}
}
void
@@ -153,7 +154,7 @@ qof_session_get_error (QofSession * session)
/* maybe we should return a no-backend error ??? */
if (! session->backend) return ERR_BACKEND_NO_ERR;
err = qof_backend_get_error (session->backend);
err = qof_backend_get_error_code (session->backend);
session->last_err = err;
return err;
}
@@ -193,7 +194,7 @@ qof_session_init (QofSession *session)
{
if (!session) return;
session->entity.e_type = QOF_ID_SESSION;
/*session->entity.e_type = QOF_ID_SESSION; FIXME: ????*/
session->books = g_list_append (NULL, qof_book_new ());
session->book_id = NULL;
session->backend = NULL;
@@ -242,7 +243,7 @@ qof_session_get_book (QofSession *session)
for (node=session->books; node; node=node->next)
{
QofBook *book = node->data;
if ('y' == book->book_open) return book;
if (qof_book_is_open (book)) return book;
}
return NULL;
}
@@ -262,7 +263,7 @@ qof_session_add_book (QofSession *session, QofBook *addbook)
if (addbook == book) return;
}
if ('y' == addbook->book_open)
if (qof_book_is_open (addbook))
{
/* hack alert -- someone should free all the books in the list,
* but it should probably not be us ... since the books backends
@@ -306,14 +307,14 @@ qof_session_get_url (QofSession *session)
/* =============================================================== */
typedef struct qof_entity_copy_data {
QofEntity *from;
QofEntity *to;
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 +329,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;
@@ -343,13 +344,13 @@ qof_session_update_reference_list(QofSession *session, QofEntityReference *refer
static void
qof_entity_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)) {
if(param->param_type == QOF_TYPE_KVP) {
qecd->param_list = g_slist_prepend(qecd->param_list, param);
return;
}
@@ -359,24 +360,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->type = ent->e_type;
ref = g_new0(QofInstanceReference, 1);
ref->type = G_OBJECT_TYPE (G_OBJECT (ent));
ref->ref_guid = g_new(GUID, 1);
ref->ent_guid = &ent->guid;
ref->param = qof_class_get_parameter(ent->e_type,
ref->inst_guid = qof_instance_get_guid (ent);
ref->param = qof_class_get_parameter(G_OBJECT_TYPE (G_OBJECT (ent)),
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)) {
@@ -388,9 +389,9 @@ col_ref_cb (QofEntity* ref_ent, gpointer user_data)
static void
qof_entity_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 +400,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;
@@ -427,84 +428,84 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data)
cm_param = (QofParam*) data;
g_return_if_fail(cm_param != NULL);
context->param = cm_param;
if(safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0) {
if(cm_param->param_type == QOF_TYPE_STRING) {
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;
if(cm_param->param_type == QOF_TYPE_DATE) {
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;
if((cm_param->param_type == QOF_TYPE_NUMERIC) ||
(cm_param->param_type == QOF_TYPE_DEBCRED)) {
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) {
if(cm_param->param_type == QOF_TYPE_GUID) {
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;
if(cm_param->param_type == QOF_TYPE_INT32) {
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;
if(cm_param->param_type == QOF_TYPE_INT64) {
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;
if(cm_param->param_type == QOF_TYPE_DOUBLE) {
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;
if(cm_param->param_type == QOF_TYPE_BOOLEAN){
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) {
if(cm_param->param_type == QOF_TYPE_KVP) {
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
{
QofInstance *target_inst;
target_inst = (QofInstance*)targetEnt;
kvp_frame_delete(target_inst->kvp_data);
target_inst->kvp_data = kvp_frame_copy(cm_kvp);
target_inst = (QofInstance*) targetEnt;
qof_instance_delete_kvp_data (target_inst);
qof_instance_set_kvp_data (target_inst, cm_kvp);
}
registered_type = TRUE;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_CHAR) == 0) {
if(cm_param->param_type == QOF_TYPE_CHAR) {
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;
}
if(safe_strcmp(cm_param->param_type, QOF_TYPE_COLLECT) == 0) {
if(cm_param->param_type == QOF_TYPE_COLLECT) {
cm_col = (QofCollection*)cm_param->param_getfcn(importEnt, cm_param);
if(cm_col)
{
@@ -514,10 +515,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 = (QofInstance*)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 +526,9 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data)
}
static gboolean
qof_entity_guid_match(QofSession *new_session, QofEntity *original)
qof_entity_guid_match(QofSession *new_session, QofInstance *original)
{
QofEntity *copy;
QofInstance *copy;
const GUID *g;
QofIdTypeConst type;
QofBook *targetBook;
@@ -537,10 +538,10 @@ 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);
type = g_strdup(original->e_type);
g = qof_instance_get_guid(original);
type = G_OBJECT_TYPE (G_OBJECT (original));
coll = qof_book_get_collection(targetBook, type);
copy = qof_collection_lookup_entity(coll, g);
copy = qof_collection_lookup_element (coll, g);
if(copy) { return TRUE; }
return FALSE;
}
@@ -548,106 +549,106 @@ qof_entity_guid_match(QofSession *new_session, QofEntity *original)
static void
qof_entity_list_foreach(gpointer data, gpointer user_data)
{
QofEntityCopyData *qecd;
QofEntity *original;
QofInstanceCopyData *qecd;
QofInstance *original;
QofInstance *inst;
QofBook *book;
const GUID *g;
GUID *g;
g_return_if_fail(data != NULL);
original = (QofEntity*)data;
original = (QofInstance*)data;
g_return_if_fail(user_data != NULL);
qecd = (QofEntityCopyData*)user_data;
qecd = (QofInstanceCopyData*)user_data;
if(qof_entity_guid_match(qecd->new_session, original)) { return; }
qecd->from = original;
if(!qof_object_compliance(original->e_type, FALSE))
if(!qof_object_compliance(G_OBJECT_TYPE (G_OBJECT (original)), FALSE))
{
qecd->error = TRUE;
return;
}
book = qof_session_get_book(qecd->new_session);
inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
inst = (QofInstance*)qof_object_new_instance(G_OBJECT_TYPE (G_OBJECT (original)), book);
if(!inst)
{
PERR (" failed to create new entity type=%s.", original->e_type);
PERR (" failed to create new entity type=%s.", g_type_name (G_OBJECT_TYPE (G_OBJECT (original))));
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(G_OBJECT_TYPE (G_OBJECT (original)), qof_entity_param_cb, qecd);
qof_begin_edit(inst);
g_slist_foreach(qecd->param_list, qof_entity_foreach_copy, qecd);
qof_commit_edit(inst);
}
static void
qof_entity_coll_foreach(QofEntity *original, gpointer user_data)
qof_entity_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);
coll = qof_book_get_collection(targetBook, original->e_type);
copy = qof_collection_lookup_entity(coll, g);
g = qof_instance_get_guid(original);
coll = qof_book_get_collection(targetBook, G_OBJECT_TYPE (G_OBJECT (original)));
copy = qof_collection_lookup_element (coll, g);
if(copy) { qecd->error = TRUE; }
}
static void
qof_entity_coll_copy(QofEntity *original, gpointer user_data)
qof_entity_coll_copy(QofInstance *original, gpointer user_data)
{
QofEntityCopyData *qecd;
QofInstanceCopyData *qecd;
QofBook *book;
QofInstance *inst;
const GUID *g;
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;
if(!qof_object_compliance(G_OBJECT_TYPE (G_OBJECT (original)), TRUE)) { return; }
inst = (QofInstance*)qof_object_new_instance(G_OBJECT_TYPE (G_OBJECT (original)), book);
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);
qof_commit_edit(inst);
}
gboolean
qof_entity_copy_to_session(QofSession* new_session, QofEntity* original)
qof_entity_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_object_compliance(original->e_type, TRUE)) { return FALSE; }
if(!qof_object_compliance(G_OBJECT_TYPE (G_OBJECT (original)), TRUE)) { return FALSE; }
qof_event_suspend();
qecd.param_list = NULL;
book = qof_session_get_book(new_session);
qecd.new_session = new_session;
qof_book_set_partial(book);
inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
qecd.to = &inst->entity;
inst = (QofInstance*)qof_object_new_instance(G_OBJECT_TYPE (G_OBJECT (original)), book);
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(G_OBJECT_TYPE (G_OBJECT (original)), qof_entity_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);
@@ -658,11 +659,11 @@ qof_entity_copy_to_session(QofSession* new_session, QofEntity* original)
gboolean qof_entity_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;
@@ -681,7 +682,7 @@ gboolean qof_entity_copy_list(QofSession *new_session, GList *entity_list)
gboolean
qof_entity_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; }
@@ -690,7 +691,7 @@ qof_entity_copy_coll(QofSession *new_session, QofCollection *entity_coll)
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_class_param_foreach(qof_collection_get_type(entity_coll),
qof_class_param_foreach(qof_collection_get_g_type(entity_coll),
qof_entity_param_cb, &qecd);
qof_collection_foreach(entity_coll, qof_entity_coll_copy, &qecd);
if(qecd.param_list != NULL) { g_slist_free(qecd.param_list); }
@@ -707,7 +708,7 @@ 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;
@@ -721,11 +722,11 @@ recurse_collection_cb (QofEntity *ent, gpointer user_data)
}
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;
@@ -747,7 +748,7 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data)
if(i->data == NULL) { continue; }
ref_param = (QofParam*)i->data;
if(ref_param->param_name == NULL) { continue; }
if(0 == safe_strcmp(ref_param->param_type, QOF_TYPE_COLLECT)) {
if(ref_param->param_type == QOF_TYPE_COLLECT) {
QofCollection *col;
col = ref_param->param_getfcn(ent, ref_param);
@@ -756,8 +757,8 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data)
}
continue;
}
ref_ent = (QofEntity*)ref_param->param_getfcn(ent, ref_param);
if((ref_ent)&&(ref_ent->e_type))
ref_ent = (QofInstance*)ref_param->param_getfcn(ent, ref_param);
if((ref_ent)&&(G_OBJECT_TYPE (G_OBJECT (ref_ent))))
{
store->success = qof_entity_copy_to_session(session, ref_ent);
if(store->success) { ent_list = g_list_append(ent_list, ref_ent); }
@@ -766,9 +767,9 @@ recurse_ent_cb(QofEntity *ent, gpointer user_data)
for(i = ent_list; i != NULL; i = i->next)
{
if(i->data == NULL) { continue; }
child_ent = (QofEntity*)i->data;
child_ent = (QofInstance*)i->data;
if(child_ent == NULL) { continue; }
ref_list = qof_class_get_referenceList(child_ent->e_type);
ref_list = qof_class_get_referenceList(G_OBJECT_TYPE (G_OBJECT (child_ent)));
for(j = ref_list; j != NULL; j = j->next)
{
if(j->data == NULL) { continue; }
@@ -784,9 +785,9 @@ 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 = (QofInstance*)i->data;
if(ref_ent == NULL) { continue; }
ref_list = qof_class_get_referenceList(ref_ent->e_type);
ref_list = qof_class_get_referenceList(G_OBJECT_TYPE (G_OBJECT (ref_ent)));
for(j = ref_list; j != NULL; j = j->next)
{
if(j->data == NULL) { continue; }
@@ -811,13 +812,13 @@ qof_entity_copy_coll_r(QofSession *new_session, QofCollection *coll)
success = TRUE;
store.success = success;
store.ent_list = NULL;
store.ref_list = qof_class_get_referenceList(qof_collection_get_type(coll));
store.ref_list = qof_class_get_referenceList(qof_collection_get_g_type(coll));
success = qof_entity_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_entity_copy_one_r(QofSession *new_session, QofInstance *ent)
{
struct recurse_s store;
QofCollection *coll;
@@ -827,10 +828,10 @@ gboolean qof_entity_copy_one_r(QofSession *new_session, QofEntity *ent)
store.session = new_session;
success = TRUE;
store.success = success;
store.ref_list = qof_class_get_referenceList(ent->e_type);
store.ref_list = qof_class_get_referenceList(G_OBJECT_TYPE (G_OBJECT (ent)));
success = qof_entity_copy_to_session(new_session, ent);
if(success == TRUE) {
coll = qof_book_get_collection(qof_session_get_book(new_session), ent->e_type);
coll = qof_book_get_collection(qof_session_get_book(new_session), G_OBJECT_TYPE (G_OBJECT (ent)));
if(coll) { qof_collection_foreach(coll, recurse_ent_cb, &store); }
}
return success;
@@ -962,7 +963,7 @@ qof_session_begin (QofSession *session, const char * book_id,
gboolean ignore_lock, gboolean create_if_nonexistent)
{
char *p, *access_method, *msg;
int err;
QofBackendError err;
if (!session) return;
@@ -1045,7 +1046,7 @@ qof_session_begin (QofSession *session, const char * book_id,
session->book_id, ignore_lock,
create_if_nonexistent);
PINFO("Done running session_begin on backend");
err = qof_backend_get_error(session->backend);
err = qof_backend_get_error_code (session->backend);
msg = qof_backend_get_message(session->backend);
if (err != ERR_BACKEND_NO_ERR)
{
@@ -1119,7 +1120,7 @@ qof_session_load (QofSession *session,
if (be->load)
{
be->load (be, newbook);
qof_session_push_error (session, qof_backend_get_error(be), NULL);
qof_session_push_error (session, qof_backend_get_error_code (be), NULL);
}
}
@@ -1170,8 +1171,8 @@ qof_session_save_may_clobber_data (QofSession *session)
static gboolean
save_error_handler(QofBackend *be, QofSession *session)
{
int err;
err = qof_backend_get_error(be);
QofBackendError err;
err = qof_backend_get_error_code (be);
if (ERR_BACKEND_NO_ERR != err)
{
@@ -1191,7 +1192,7 @@ qof_session_save (QofSession *session,
QofBackendProvider *prov;
GSList *p;
QofBook *book, *abook;
int err;
QofBackendError err;
gint num;
char *msg, *book_id;
@@ -1255,7 +1256,7 @@ qof_session_save (QofSession *session,
(session->backend->session_begin)(session->backend, session,
book_id, TRUE, TRUE);
PINFO("Done running session_begin on changed backend");
err = qof_backend_get_error(session->backend);
err = qof_backend_get_error_code (session->backend);
msg = qof_backend_get_message(session->backend);
if (err != ERR_BACKEND_NO_ERR)
{
@@ -1478,10 +1479,10 @@ qof_session_export (QofSession *tmp_session,
be->percentage = percentage_func;
if (be->export) {
int err;
QofBackendError err;
(be->export)(be, book);
err = qof_backend_get_error(be);
err = qof_backend_get_error_code (be);
if (ERR_BACKEND_NO_ERR != err) { return FALSE; }
}
+9 -9
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_entity_copy_to_session(QofSession* new_session, QofInstance* original);
/** @brief Copy a GList of entities to another session
@@ -301,12 +301,12 @@ 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.
@@ -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
@@ -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_entity_copy_one_r(QofSession *new_session, QofInstance *ent);
/** @}
*/
+41 -38
View File
@@ -303,7 +303,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];
@@ -311,25 +311,25 @@ 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;
paramType = param->param_type;
if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0) {
if(paramType == QOF_TYPE_STRING) {
param_string = g_strdup(param->param_getfcn(ent, param));
if(param_string == NULL) { param_string = ""; }
known_type = TRUE;
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_DATE) == 0) {
date_getter = (Timespec (*)(QofEntity*, QofParam*))param->param_getfcn;
if(paramType == QOF_TYPE_DATE) {
date_getter = (Timespec (*)(QofInstance*, QofParam*))param->param_getfcn;
param_ts = date_getter(ent, param);
param_t = timespecToTime_t(param_ts);
strftime(param_date, MAX_DATE_LENGTH,
@@ -338,44 +338,44 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
known_type = TRUE;
return param_string;
}
if((safe_strcmp(paramType, QOF_TYPE_NUMERIC) == 0) ||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0)) {
numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*)) param->param_getfcn;
if((paramType == QOF_TYPE_NUMERIC) ||
(paramType == QOF_TYPE_DEBCRED)) {
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;
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_GUID) == 0) {
if(paramType == QOF_TYPE_GUID) {
param_guid = param->param_getfcn(ent, param);
guid_to_string_buff(param_guid, param_sa);
param_string = g_strdup(param_sa);
known_type = TRUE;
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_INT32) == 0) {
int32_getter = (gint32 (*)(QofEntity*, QofParam*)) param->param_getfcn;
if(paramType == QOF_TYPE_INT32) {
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;
if(paramType == QOF_TYPE_INT64) {
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;
if(paramType == QOF_TYPE_DOUBLE) {
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;
if(paramType == QOF_TYPE_BOOLEAN){
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"); }
@@ -384,42 +384,42 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
return param_string;
}
/* "kvp" contains repeating values, cannot be a single string for the frame. */
if(safe_strcmp(paramType, QOF_TYPE_KVP) == 0) {
if(paramType == QOF_TYPE_KVP) {
KvpFrame *frame = NULL;
frame = param->param_getfcn(ent, param);
known_type = TRUE;
if(!kvp_frame_is_empty(frame))
{
GHashTable *hash = kvp_frame_get_hash(frame);
param_string = g_strdup_printf("%s(%d)", QOF_TYPE_KVP,
param_string = g_strdup_printf("%s(%d)", g_type_name (QOF_TYPE_KVP),
g_hash_table_size(hash));
}
return param_string;
}
if(safe_strcmp(paramType, QOF_TYPE_CHAR) == 0) {
char_getter = (gchar (*)(QofEntity*, QofParam*)) param->param_getfcn;
if(paramType == QOF_TYPE_CHAR) {
char_getter = (gchar (*)(QofInstance*, QofParam*)) param->param_getfcn;
param_char = char_getter(ent, param);
known_type = TRUE;
return g_strdup_printf("%c", param_char);
}
/* "collect" contains repeating values, cannot be a single string. */
if(safe_strcmp(paramType, QOF_TYPE_COLLECT) == 0)
if(paramType == QOF_TYPE_COLLECT)
{
QofCollection *col = NULL;
col = param->param_getfcn(ent, param);
known_type = TRUE;
return g_strdup_printf("%s(%d)",
qof_collection_get_type(col), qof_collection_count(col));
g_type_name (qof_collection_get_g_type(col)), qof_collection_count(col));
}
if(safe_strcmp(paramType, QOF_TYPE_CHOICE) == 0)
if(paramType == QOF_TYPE_CHOICE)
{
QofEntity *child = NULL;
QofInstance *child = NULL;
child = param->param_getfcn(ent, param);
if(!child) { return param_string; }
known_type = TRUE;
return g_strdup(qof_object_printable(child->e_type, child));
return g_strdup(qof_instance_to_string (child));
}
if(safe_strcmp(paramType, QOF_PARAM_BOOK) == 0)
if(paramType == QOF_PARAM_BOOK)
{
QofBackend *be;
QofBook *book;
@@ -428,11 +428,14 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param)
be = qof_book_get_backend(book);
known_type = TRUE;
PINFO (" backend=%p", be);
if(!be) { return QOF_PARAM_BOOK; }
if(!be)
{
return "book"; /* FIXME: could be used g_type_name (QOF_TYPE_BOOK) */
}
param_string = g_strdup(be->fullpath);
PINFO (" fullpath=%s", param_string);
if(param_string) { return param_string; }
param_guid = qof_book_get_guid(book);
param_guid = qof_instance_get_guid(QOF_INSTANCE (book));
guid_to_string_buff(param_guid, param_sa);
PINFO (" book GUID=%s", param_sa);
param_string = g_strdup(param_sa);
@@ -440,10 +443,10 @@ 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));
return g_strdup(qof_instance_to_string (child));
}
return g_strdup("");
}
@@ -455,7 +458,7 @@ qof_init (void)
guid_init ();
qof_object_initialize ();
qof_query_init ();
qof_book_register ();
/*qof_book_register (); FIXME: This is broken for now but not needed... I think..*/
}
void
+1 -2
View File
@@ -38,7 +38,6 @@
#include "qofutil.h"
#include "qofbackend.h"
#include "qofclass.h"
#include "qofbook.h"
#include "qofinstance.h"
/** Do not use these for printf, only scanf */
@@ -235,7 +234,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:
*