QOF  0.7.5
Book: The QOF Data Set.

Files

file  qofbook.h
 Encapsulate all the information about a dataset.

Macros

#define QOF_BOOK_LOOKUP_ENTITY(book, guid, e_type, c_type)
 Encapsulates all the information about a dataset manipulated by QOF. This is the top-most structure used for anchoring data.
#define qof_book_get_slots(book)   qof_instance_get_slots(QOF_INSTANCE(book))

Typedefs

typedef struct _QofBook QofBook
 QofBook reference.
typedef GList QofBookList
typedef void(* QofBookFinalCB )(QofBook *, gpointer key, gpointer user_data)
typedef void(* QofCollectionForeachCB )(QofCollection *, gpointer user_data)

Functions

gboolean qof_book_register (void)
QofBookqof_book_new (void)
void qof_book_destroy (QofBook *book)
void qof_book_mark_closed (QofBook *book)
QofCollectionqof_book_get_collection (QofBook *, QofIdType)
void qof_book_foreach_collection (QofBook *, QofCollectionForeachCB, gpointer)
void qof_book_set_data (QofBook *book, const gchar *key, gpointer data)
void qof_book_set_data_fin (QofBook *book, const gchar *key, gpointer data, QofBookFinalCB)
gpointer qof_book_get_data (QofBook *book, const gchar *key)
gboolean qof_book_shutting_down (QofBook *book)
gboolean qof_book_not_saved (QofBook *book)
void qof_book_mark_saved (QofBook *book)
void qof_book_kvp_changed (QofBook *book)
gboolean qof_book_equal (QofBook *book_1, QofBook *book_2)
gint64 qof_book_get_counter (QofBook *book, const gchar *counter_name)

Detailed Description

A QOF Book is a dataset. It provides a single handle through which all the various collections of entities can be found. In particular, given only the type of the entity, the collection can be found.

Books also provide the 'natural' place to working with a storage backend, as a book can encapsulate everything held in storage.


Macro Definition Documentation

#define qof_book_get_slots (   book)    qof_instance_get_slots(QOF_INSTANCE(book))

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.

Definition at line 113 of file qofbook.h.

#define QOF_BOOK_LOOKUP_ENTITY (   book,
  guid,
  e_type,
  c_type 
)
Value:
({ \
QofEntity *val = NULL; \
if (guid && book) { \
col = qof_book_get_collection (book, e_type); \
val = qof_collection_lookup_entity (col, guid); \
} \
(c_type *) val; \
})

Encapsulates all the information about a dataset manipulated by QOF. This is the top-most structure used for anchoring data.

Lookup an entity by guid, returning pointer to the entity

Definition at line 50 of file qofbook.h.


Typedef Documentation

typedef GList QofBookList

GList of QofBook

Definition at line 64 of file qofbook.h.

typedef void(* QofCollectionForeachCB)(QofCollection *, gpointer user_data)

Invoke the indicated callback on each collection in the book.

Definition at line 102 of file qofbook.h.


Function Documentation

void qof_book_destroy ( QofBook book)

End any editing sessions associated with book, and free all memory associated with it.

Definition at line 99 of file qofbook.c.

{
if (!book)
return;
ENTER ("book=%p", book);
book->shutting_down = TRUE;
qof_event_force (&book->inst.entity, QOF_EVENT_DESTROY, NULL);
/* 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);
qof_object_book_end (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->hash_of_collections);
book->hash_of_collections = NULL;
g_free (book);
LEAVE ("book=%p", book);
}
gboolean qof_book_equal ( QofBook book_1,
QofBook book_2 
)

The qof_book_equal() method returns TRUE if books are equal. XXX this routine is broken, and does not currently compare data.

Definition at line 125 of file qofbook.c.

{
if (book_1 == book_2)
return TRUE;
if (!book_1 || !book_2)
return FALSE;
return TRUE;
}
QofCollection* qof_book_get_collection ( QofBook ,
QofIdType   
)

Return The table of entities of the given type.

When an object's constructor calls qof_instance_init(), a reference to the object is stored in the book. The book stores all the references to initialized instances, sorted by type. This function returns a collection of the references for the specified type.

If the collection doesn't yet exist for the indicated type, it is created. Thus, this routine is gaurenteed to return a non-NULL value. (Unless the system malloc failed (out of memory) in which case what happens??).

Definition at line 220 of file qofbook.c.

{
if (!book || !entity_type)
return NULL;
col = g_hash_table_lookup (book->hash_of_collections, entity_type);
if (!col)
{
col = qof_collection_new (entity_type);
g_hash_table_insert (book->hash_of_collections,
qof_util_string_cache_insert ((gpointer) entity_type), col);
}
return col;
}
gint64 qof_book_get_counter ( QofBook book,
const gchar *  counter_name 
)

This will 'get and increment' the named counter for this book. The return value is -1 on error or the incremented counter.

Definition at line 325 of file qofbook.c.

{
KvpFrame *kvp;
KvpValue *value;
gint64 counter;
if (!book)
{
PWARN ("No book!!!");
return -1;
}
if (!counter_name || *counter_name == '\0')
{
PWARN ("Invalid counter name.");
return -1;
}
/* If we've got a backend with a counter method, call it */
be = book->backend;
if (be && be->counter)
return ((be->counter) (be, counter_name));
/* If not, then use the KVP in the book */
kvp = qof_book_get_slots (book);
if (!kvp)
{
PWARN ("Book has no KVP_Frame");
return -1;
}
value = kvp_frame_get_slot_path (kvp, "counters", counter_name, NULL);
if (value)
{
/* found it */
counter = kvp_value_get_gint64 (value);
}
else
{
/* New counter */
counter = 0;
}
/* Counter is now valid; increment it */
counter++;
/* Save off the new counter */
value = kvp_value_new_gint64 (counter);
kvp_frame_set_slot_path (kvp, value, "counters", counter_name, NULL);
/* and return the value */
return counter;
}
gpointer qof_book_get_data ( QofBook book,
const gchar *  key 
)

Retrieves arbitrary pointers to structs stored by qof_book_set_data.

Definition at line 212 of file qofbook.c.

{
if (!book || !key)
return NULL;
return g_hash_table_lookup (book->data_tables, (gpointer) key);
}
void qof_book_kvp_changed ( QofBook book)

Call this function when you change the book kvp, to make sure the book is marked 'dirty'.

Definition at line 180 of file qofbook.c.

{
if (!book)
return;
book->inst.dirty = TRUE;
}
void qof_book_mark_closed ( QofBook book)
Close a book to editing.

It is up to the application to check this flag, and once marked closed, books cannnot be marked as open.

Definition at line 265 of file qofbook.c.

{
if (!book)
{
return;
}
book->book_open = 'n';
}
void qof_book_mark_saved ( QofBook book)

The qof_book_mark_saved() routine marks the book as having been saved (to a file, to a database). Used by backends to mark the notsaved flag as FALSE just after loading. Can also be used by the frontend when the used has said to abandon any changes.

Definition at line 144 of file qofbook.c.

{
if (!book)
return;
book->inst.dirty = FALSE;
qof_object_mark_clean (book);
}
QofBook* qof_book_new ( void  )

Allocate, initialise and return a new QofBook. Books contain references to all of the top-level object containers.

Definition at line 75 of file qofbook.c.

{
QofBook *book;
ENTER (" ");
book = g_new0 (QofBook, 1);
qof_book_init (book);
LEAVE ("book=%p", book);
return book;
}
gboolean qof_book_not_saved ( QofBook book)

qof_book_not_saved() will return TRUE if any data in the book hasn't been saved to long-term storage. (Actually, that's not quite true. The book doesn't know anything about saving. Its just that whenever data is modified, the 'dirty' flag is set. This routine returns the value of the 'dirty' flag. Its up to the backend to periodically reset this flag, when it actually does save the data.)

Definition at line 135 of file qofbook.c.

{
if (!book)
return FALSE;
return (book->inst.dirty || qof_object_is_dirty (book));
}
gboolean qof_book_register ( void  )

Register the book object with the QOF object system.

Register books with the framework

Definition at line 376 of file qofbook.c.

{
static QofParam params[] = {
{QOF_PARAM_GUID, QOF_TYPE_GUID,
NULL, NULL},
{QOF_PARAM_KVP, QOF_TYPE_KVP,
NULL, NULL},
{NULL, NULL, NULL, NULL, NULL},
};
qof_class_register (QOF_ID_BOOK, NULL, params);
return TRUE;
}
void qof_book_set_data ( QofBook book,
const gchar *  key,
gpointer  data 
)

The qof_book_set_data() allows arbitrary pointers to structs to be stored in QofBook. This is the "preferred" method for extending QofBook to hold new data types. This is also the ideal location to store other arbitrary runtime data that the application may need.

The book data differs from the book KVP in that the contents of the book KVP are persistent (are saved and restored to file or database), whereas the data pointers exist only at runtime.

Definition at line 191 of file qofbook.c.

{
if (!book || !key)
return;
g_hash_table_insert (book->data_tables, (gpointer) key, data);
}
void qof_book_set_data_fin ( QofBook book,
const gchar *  key,
gpointer  data,
QofBookFinalCB   
)

Same as qof_book_set_data(), except that the callback will be called when the book is destroyed. The argument to the callback will be the book followed by the data pointer.

Definition at line 199 of file qofbook.c.

{
if (!book || !key)
return;
g_hash_table_insert (book->data_tables, (gpointer) key, data);
if (!cb)
return;
g_hash_table_insert (book->data_table_finalizers, (gpointer) key, cb);
}
gboolean qof_book_shutting_down ( QofBook book)

Is the book shutting down?

Definition at line 162 of file qofbook.c.

{
if (!book)
return FALSE;
return book->shutting_down;
}