QOF: GLib GObjects

QOF 0.7.5

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

Files | Functions
GLib GObjects
Query Object Framework » Object: Describing data structure.

## Files
file | qofgobj.h
| QOF to GLib GObject mapping.

## Functions
void | qof_gobject_init (void)
void | qof_gobject_shutdown (void)
void | qof_gobject_register (QofType type, GObjectClass *obclass)
void | qof_gobject_register_instance (QofBook *book, QofType, GObject *)

## Detailed Description

The API defined in this file allows a user to register any GLib GObject (and any object derived from one, e.g. GTK/Gnome) with the QOF system, as a QOF Object Class. This allows the QOF Query routines to be used to search over collections of GObjects.

XXX Only GObject properties are searchable, data and other hanging off the GObject is not. Fix this. This needs fixing.

## Function Documentation

void qof_gobject_init | ( | void |  | ) |

Initalize and shut down this subsystem.

Definition at line 48 of file qofgobj.c.

49 {
50 if (initialized)
51 return;
52 initialized = TRUE;
53
54 // gobjectClassTable = g_hash_table_new (g_str_hash, g_str_equal);
55
56 /* Init the other subsystems that we need */
57 qof_object_initialize ();
58 qof_query_init ();
59 }
qof_query_init
void qof_query_init(void)
Definition: qofquery.c:1375

void qof_gobject_register | ( | QofType | type,
|  | GObjectClass * | obclass
| ) |  |

Register a GObject class with the QOF subsystem. Doing this will make the properties associated with this GObject searchable using the QOF subsystem.

The QofType can be any string you desire, although typically you might want to set it to G_OBJECT_CLASS_NAME() of the object class. Note that this type will become the name of the "table" that is searched by SQL queries: e.g. in order to be able to say "SELECT * FROM MyStuff;" you must first say: qof_gobject_register ("MyStuff", gobj_class);

Definition at line 222 of file qofgobj.c.

223 {
224 guint i, j;
225 QofParam *qof_param_list, *qpar;
226 QofObject *class_def;
227 GParamSpec **prop_list, *gparam;
228 guint n_props;
229
230 /* Get the GObject properties, convert to QOF properties */
231 prop_list = g_object_class_list_properties (obclass, &n_props);
232
233 qof_param_list = g_new0 (QofParam, n_props);
234 paramList = g_slist_prepend (paramList, qof_param_list);
235
236 PINFO ("object %s has %d props", e_type, n_props);
237 j = 0;
238 for (i = 0; i < n_props; i++)
239 {
240 gparam = prop_list[i];
241 qpar = &qof_param_list[j];
242
243 PINFO ("param %d %s is type %s",
244 i, gparam->name, G_PARAM_SPEC_TYPE_NAME (gparam));
245
246 qpar->param_name = g_param_spec_get_name (gparam);
247 qpar->param_getfcn = (QofAccessFunc) qof_gobject_getter;
248 qpar->param_setfcn = NULL;
249 qpar->param_userdata = gparam;
250 if ((G_IS_PARAM_SPEC_INT (gparam)) ||
251 (G_IS_PARAM_SPEC_UINT (gparam)) ||
252 (G_IS_PARAM_SPEC_ENUM (gparam)) ||
253 (G_IS_PARAM_SPEC_FLAGS (gparam)))
254 {
255 qpar->param_type = QOF_TYPE_INT32;
256 j++;
257 }
258 else if ((G_IS_PARAM_SPEC_INT64 (gparam)) ||
259 (G_IS_PARAM_SPEC_UINT64 (gparam)))
260 {
261 qpar->param_type = QOF_TYPE_INT64;
262 j++;
263 }
264 else if (G_IS_PARAM_SPEC_BOOLEAN (gparam))
265 {
266 qpar->param_type = QOF_TYPE_BOOLEAN;
267 j++;
268 }
269 else if (G_IS_PARAM_SPEC_STRING (gparam))
270 {
271 qpar->param_type = QOF_TYPE_STRING;
272 j++;
273 }
274 else if ((G_IS_PARAM_SPEC_POINTER (gparam)) ||
275 (G_IS_PARAM_SPEC_OBJECT (gparam)))
276 {
277 /* No-op, silently ignore. Someday we should handle this ... */
278 }
279 else if ((G_IS_PARAM_SPEC_FLOAT (gparam)) ||
280 (G_IS_PARAM_SPEC_DOUBLE (gparam)))
281 {
282 qpar->param_getfcn = (QofAccessFunc) qof_gobject_double_getter;
283 qpar->param_type = QOF_TYPE_DOUBLE;
284 j++;
285 }
286 else if (G_IS_PARAM_SPEC_CHAR (gparam))
287 {
288 qpar->param_type = QOF_TYPE_CHAR;
289 j++;
290 }
291 else
292 {
293 PWARN ("Unknown/unhandled parameter type %s on %s:%s\n",
294 G_PARAM_SPEC_TYPE_NAME (gparam), e_type, qpar->param_name);
295 }
296 }
297
298 /* NULL-terminated list! */
299 qof_param_list[j].param_type = NULL;
300
301 qof_class_register (e_type, NULL, qof_param_list);
302
303 /* ------------------------------------------------------ */
304 /* Now do the class itself */
305 class_def = g_new0 (QofObject, 1);
306 classList = g_slist_prepend (classList, class_def);
307
308 class_def->interface_version = QOF_OBJECT_VERSION;
309 class_def->e_type = e_type;
310 /* We could let the user specify a "nick" here, but
311 * the actual class name seems reasonable, e.g. for debugging. */
312 class_def->type_label = G_OBJECT_CLASS_NAME (obclass);
313 class_def->create = NULL;
314 class_def->book_begin = NULL;
315 class_def->book_end = NULL;
316 class_def->is_dirty = NULL;
317 class_def->mark_clean = NULL;
318 class_def->foreach = qof_gobject_foreach;
319 class_def->printable = NULL;
320 class_def->version_cmp = NULL;
321
322 qof_object_register (class_def);
323 }
PINFO
#define PINFO(format, args...)
Definition: qoflog.h:199
_QofParam
Definition: qofclass.h:195
QOF_OBJECT_VERSION
#define QOF_OBJECT_VERSION
Definition: qofobject.h:57
qof_class_register
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
registers a new object class with the Qof subsystem.
Definition: qofclass.c:93
_QofObject::create
gpointer(* create)(QofBook *)
Definition: qofobject.h:80
_QofObject::book_end
void(* book_end)(QofBook *)
Definition: qofobject.h:90
_QofObject::book_begin
void(* book_begin)(QofBook *)
Definition: qofobject.h:85
_QofObject::mark_clean
void(* mark_clean)(QofCollection *)
Definition: qofobject.h:96
_QofObject
Definition: qofobject.h:70
QofAccessFunc
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
Definition: qofclass.h:169
_QofObject::is_dirty
gboolean(* is_dirty)(QofCollection *)
Definition: qofobject.h:93
qof_object_register
gboolean qof_object_register(const QofObject *object)
Definition: qofobject.c:278
PWARN
#define PWARN(format, args...)
Definition: qoflog.h:191
_QofObject::printable
const gchar *(* printable)(gpointer instance)
Definition: qofobject.h:109
_QofObject::foreach
void(* foreach)(QofCollection *, QofEntityForeachCB, gpointer)
Definition: qofobject.h:105
_QofObject::version_cmp
gint(* version_cmp)(gpointer instance_left, gpointer instance_right)
Definition: qofobject.h:119

void qof_gobject_register_instance | ( | QofBook * | book,
|  | QofType | ,
|  | GObject * |
| ) |  |

Register an instance of a GObject with the QOF subsystem.

The QofType can be any string you desire, although typically you might want to set it to G_OBJECT_CLASS_NAME() of the object class. Note that this type will become the name of the "table" that is searched by SQL queries: e.g. in order to be able to say "SELECT * FROM MyStuff;" you must first say: qof_gobject_register_instance (book, "MyStuff", obj);

The 'book' argument specifies an anchor point for the collection of all of the registered instances. By working with disjoint books, you can have multiple disjoint searchable sets of objects.

Definition at line 93 of file qofgobj.c.

94 {
95 QofCollection *coll;
96 GSList *instance_list;
97
98 if (!book || !type)
99 return;
100
101 coll = qof_book_get_collection (book, type);
102
103 instance_list = qof_collection_get_data (coll);
104 instance_list = g_slist_prepend (instance_list, gob);
105 qof_collection_set_data (coll, instance_list);
106 }
qof_book_get_collection
QofCollection * qof_book_get_collection(QofBook *book, QofIdType entity_type)
Definition: qofbook.c:220
QofCollection
struct QofCollection_s QofCollection
Definition: qofid.h:138
qof_collection_set_data
void qof_collection_set_data(QofCollection *col, gpointer user_data)
Definition: qofid.c:394
qof_collection_get_data
gpointer qof_collection_get_data(QofCollection *col)
Definition: qofid.c:388