Objects can have complex relationships and inter-dependencies. QofLogic aims to enforce logical rules for specific aspects of a QofEntity .
Rules are expressed in any of 5 levels:
Data source constraints are commonly external to QOF, e.g. XML schema, DTD's, stored procedures and other logic within the QofBackend itself. All QofBackend modules must implement sufficient data source constraints to ensure that the entire dataset is completely represented in the valid QofBook passed to QOF after loading that dataset.
Some parameter logic is implicit in the QofSetterFunc routines. Further parameter logic, entity logic, collection logic and book logic are all optional - dictated by the objects themselves.
In a similar manner to pilot-qof pack routines, QofLogic rules are defined using a static struct that sets the appropriate logic levels.
Files | |
| file | qoflogic.h |
| Logic handlers for the QOF external framework. | |
Data Structures | |
| struct | QofLogicParam |
| struct | QofLogic |
Defines | |
| #define | QOF_MOD_LOGIC "qof_logic" |
| Debug module for the logic code. | |
| #define | QOF_MAKE_LOGIC_ERR(x) (1<<(x)) |
| #define | QOF_LOGIC_BASE 12 |
| #define | ERR_LOGIC_NOT_DONE QOF_MAKE_LOGIC_ERR(0) |
| #define | ERR_LOGIC_VALID QOF_MAKE_LOGIC_ERR(1) |
| #define | ERR_LOGIC_PARAM_FAIL QOF_MAKE_LOGIC_ERR(2) |
| #define | ERR_LOGIC_PARAM_UNSET QOF_MAKE_LOGIC_ERR(3) |
| #define | ERR_LOGIC_PARAM_NULL QOF_MAKE_LOGIC_ERR(4) |
| #define | ERR_LOGIC_ENTITY_INCOMPATIBLE QOF_MAKE_LOGIC_ERR(5) |
| #define | ERR_LOGIC_COLL_INVALID QOF_MAKE_LOGIC_ERR(6) |
| #define | qof_logic_collection_pair(a, b) qof_logic_collection_check(a, (gconstpointer)b) |
Typedefs | |
| typedef guint | QofLogicError |
| typedef QofLogicError(* | QofLogicParamFunc )(QofEntity *ent, QofParam *param, gconstpointer data) |
| typedef QofLogicError(* | QofLogicEntFunc )(QofEntity *ent, gconstpointer data) |
| typedef QofLogicError(* | QofLogicCollFunc )(QofCollection *col, gconstpointer data) |
| typedef QofLogicError(* | QofLogicBookFunc )(QofBook *book, gconstpointer data) |
| Prototype for functions to verify links between entities in different collections. | |
| typedef const gchar *(* | QofLogicErrorFunc )(QofLogicError error) |
| Prototype to retrieve a sensible error message. | |
Functions | |
| gboolean | qof_logic_register (QofIdTypeConst obj_name, const QofLogic *logic) |
| gboolean | qof_logic_param_register (QofIdTypeConst obj_name, const QofLogicParam *params) |
| QofLogicError | qof_logic_book_check (QofBook *book, gconstpointer data) |
| Run logical tests on the entire book. | |
| QofLogicError | qof_logic_collection_check (QofCollection *col, gconstpointer data) |
| QofLogicError | qof_logic_entity_check (QofEntity *ent, gconstpointer data) |
| QofLogicError | qof_logic_param_check (QofEntity *ent, QofParam *param, gconstpointer data) |
| const gchar * | qof_logic_error_msg (QofLogicError error, QofIdTypeConst obj_type) |
|
|
At least one entity in this collection is incompatible with at least one other. Call qof_logic_error_msg for more information. Definition at line 100 of file qoflogic.h. |
|
|
Init value. SUCCESS. Definition at line 89 of file qoflogic.h. Referenced by qof_logic_book_check(), qof_logic_collection_check(), qof_logic_entity_check(), and qof_logic_param_check(). |
|
|
Value could not be set for this parameter. Definition at line 93 of file qoflogic.h. |
|
|
At least one parameter of this entity is incompatible with at least one other. Call qof_logic_error_msg for more information. Definition at line 97 of file qoflogic.h. |
|
|
Tried to set an unsupported NULL value. Definition at line 95 of file qoflogic.h. |
|
|
Parameter logic could not be registered. Definition at line 91 of file qoflogic.h. Referenced by qof_logic_collection_check(), qof_logic_entity_check(), and qof_logic_param_check(). |
|
|
Custom error values must be more than this. Definition at line 86 of file qoflogic.h. |
|
|
Run logical tests against entities from two collections. The QofLogicCollFunc for col_a is called with col_b as an additional parameter. col_b should not be modified by the logic test within the col_a object. Definition at line 165 of file qoflogic.h. |
|
|
Allow bitwise comparison of error result values. Definition at line 83 of file qoflogic.h. |
|
|
Prototype for functions to verify links between entities in one collection. Definition at line 113 of file qoflogic.h. |
|
|
Prototype for functions to verify all parameter data of one entity. Definition at line 110 of file qoflogic.h. |
|
|
Prototype Definition at line 80 of file qoflogic.h. |
|
|
Prototype for functions to verify data in one parameter of one entity. Definition at line 106 of file qoflogic.h. |
|
||||||||||||
|
Run logical tests on the entire book. Unlike the other routines, this calls the QofLogicBookFunc of each registered QOF type by iterating over each QofCollection. Functions should only test logic directly related to the object being tested. Use this routine sparingly, it can take some time to test an entire book. Definition at line 176 of file qoflogic.c. References logic_book_iter::data, ERR_LOGIC_NOT_DONE, and logic_book_iter::error. 00177 { 00178 struct logic_book_iter iter; 00179 00180 if (!check_init()) return ERR_LOGIC_NOT_DONE; 00181 g_return_val_if_fail(book, ERR_LOGIC_NOT_DONE); 00182 iter.error = ERR_LOGIC_NOT_DONE; 00183 iter.data = data; 00184 qof_book_foreach_collection(book, logic_book_by_coll, &iter); 00185 return iter.error; 00186 }
|
|
||||||||||||
|
Run logical tests on all entities in a collection. Definition at line 189 of file qoflogic.c. References ERR_LOGIC_NOT_DONE, and ERR_LOGIC_VALID. 00190 { 00191 QofLogicCollFunc func; 00192 00193 if (!check_init()) return ERR_LOGIC_NOT_DONE; 00194 g_return_val_if_fail(col, ERR_LOGIC_NOT_DONE); 00195 func = qof_logic_get_coll_func(qof_collection_get_type(col)); 00196 /* If no logic is defined, the collection must be valid. */ 00197 if(!func) return ERR_LOGIC_VALID; 00198 return (func)(col, data); 00199 }
|
|
||||||||||||
|
Run logical tests on all parameters of a specific entity. Definition at line 202 of file qoflogic.c. References ERR_LOGIC_NOT_DONE, and ERR_LOGIC_VALID. 00203 { 00204 QofLogicEntFunc func; 00205 00206 if (!check_init()) return ERR_LOGIC_NOT_DONE; 00207 g_return_val_if_fail(ent, ERR_LOGIC_NOT_DONE); 00208 func = qof_logic_get_ent_func(ent->e_type); 00209 /* If no logic is defined, the entity must be valid. */ 00210 if(!func) return ERR_LOGIC_VALID; 00211 return (func)(ent, data); 00212 }
|
|
||||||||||||
|
Get a sensible error message for the user. Definition at line 228 of file qoflogic.c. References logic_error_func. 00229 { 00230 QofLogic *logic; 00231 QofLogicErrorFunc func; 00232 00233 if (!check_init()) return NULL; 00234 g_return_val_if_fail((error || obj_type), NULL); 00235 logic = g_hash_table_lookup(logic_table, obj_type); 00236 func = logic->logic_error_func; 00237 if(!func) return NULL; 00238 return (func)(error); 00239 }
|
|
||||||||||||||||
|
Test the logic of this specific parameter of this specific entity. Definition at line 215 of file qoflogic.c. References ERR_LOGIC_NOT_DONE, and ERR_LOGIC_VALID. 00216 { 00217 QofLogicParamFunc func; 00218 00219 if (!check_init()) return ERR_LOGIC_NOT_DONE; 00220 g_return_val_if_fail((param || ent), ERR_LOGIC_NOT_DONE); 00221 func = qof_logic_get_param_func(ent->e_type, param); 00222 /* If no logic is defined, the param must be valid. */ 00223 if(!func) return ERR_LOGIC_VALID; 00224 return (func)(ent, param, data); 00225 }
|
|
||||||||||||
|
Register parameter logic for this object with QOF. Definition at line 69 of file qoflogic.c. References QofLogicParam::param_name. 00071 { 00072 GHashTable *pt; 00073 gint i; 00074 00075 if(!check_init()) return FALSE; 00076 g_return_val_if_fail (obj_name || params, FALSE); 00077 pt = g_hash_table_lookup (param_table, obj_name); 00078 /* If it doesn't already exist, create a new table for this object */ 00079 if (!pt) 00080 { 00081 pt = g_hash_table_new (g_str_hash, g_str_equal); 00082 g_hash_table_insert (param_table, (gchar *)obj_name, pt); 00083 } 00084 if (params) 00085 { 00086 for (i = 0; params[i].param_name; i++) 00087 g_hash_table_insert (pt, 00088 (gchar *)params[i].param_name, 00089 (gpointer)&(params[i])); 00090 } 00091 return TRUE; 00092 }
|
|
||||||||||||
|
Register object logic with QOF. Definition at line 94 of file qoflogic.c. 00095 { 00096 if(!check_init()) return FALSE; 00097 g_return_val_if_fail(obj_name || logic, FALSE); 00098 PINFO (" registering logic for %s", obj_name); 00099 g_hash_table_insert(logic_table, (gchar*)obj_name, (gpointer)logic); 00100 return TRUE; 00101 }
|
1.4.6