2005-11-07 09:45:58 -06:00
|
|
|
/********************************************************************\
|
|
|
|
* qofbook.h -- Encapsulate all the information about a dataset. *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2005-11-07 09:45:58 -06:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
|
|
|
/** @addtogroup Object
|
|
|
|
@{ */
|
|
|
|
/** @addtogroup Book
|
2006-01-08 11:51:29 -06:00
|
|
|
A QOF Book is a dataset. It provides a single handle
|
2005-11-07 09:45:58 -06:00
|
|
|
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.
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
Books also provide the 'natural' place to working with
|
2006-01-08 11:51:29 -06:00
|
|
|
a storage backend, as a book can encapsulate everything
|
2005-11-07 09:45:58 -06:00
|
|
|
held in storage.
|
|
|
|
@{ */
|
|
|
|
/** @file qofbook.h
|
|
|
|
* @brief Encapsulate all the information about a dataset.
|
|
|
|
*
|
|
|
|
* @author Copyright (c) 1998, 1999, 2001, 2003 Linas Vepstas <linas@linas.org>
|
|
|
|
* @author Copyright (c) 2000 Dave Peticolas
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QOF_BOOK_H
|
|
|
|
#define QOF_BOOK_H
|
|
|
|
|
2007-04-03 17:30:58 -05:00
|
|
|
typedef struct _QofBookClass QofBookClass;
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
#include "qofid.h"
|
|
|
|
#include "kvp_frame.h"
|
2007-04-03 17:30:58 -05:00
|
|
|
#include "qofinstance.h"
|
|
|
|
|
|
|
|
/* --- type macros --- */
|
|
|
|
#define QOF_TYPE_BOOK (qof_book_get_type ())
|
|
|
|
#define QOF_BOOK(o) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_BOOK, QofBook))
|
|
|
|
#define QOF_BOOK_CLASS(k) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_BOOK, QofBookClass))
|
|
|
|
#define QOF_IS_BOOK(o) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_BOOK))
|
|
|
|
#define QOF_IS_BOOK_CLASS(k) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_BOOK))
|
|
|
|
#define QOF_BOOK_GET_CLASS(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_BOOK, QofBookClass))
|
|
|
|
|
|
|
|
typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data);
|
|
|
|
|
|
|
|
/* Book structure */
|
|
|
|
struct _QofBook
|
|
|
|
{
|
|
|
|
QofInstance inst; /* Unique guid for this book. */
|
|
|
|
|
|
|
|
/* The time when the book was first dirtied. This is a secondary
|
|
|
|
* indicator. It should only be used when inst.dirty is TRUE. */
|
|
|
|
time_t dirty_time;
|
|
|
|
|
|
|
|
/* This callback function is called any time the book dirty flag
|
|
|
|
* changes state. Both clean->dirty and dirty->clean transitions
|
|
|
|
* trigger a callback. */
|
|
|
|
QofBookDirtyCB dirty_cb;
|
|
|
|
|
|
|
|
/* This is the user supplied data that is returned in the dirty
|
|
|
|
* callback function.*/
|
|
|
|
gpointer dirty_data;
|
|
|
|
|
|
|
|
/* The entity table associates the GUIDs of all the objects
|
|
|
|
* belonging to this book, with their pointers to the respective
|
|
|
|
* objects. This allows a lookup of objects based on thier guid.
|
|
|
|
*/
|
|
|
|
GHashTable * hash_of_collections;
|
|
|
|
|
|
|
|
/* In order to store arbitrary data, for extensibility, add a table
|
|
|
|
* that will be used to hold arbitrary pointers.
|
|
|
|
*/
|
|
|
|
GHashTable *data_tables;
|
|
|
|
|
|
|
|
/* Hash table of destroy callbacks for the data table. */
|
|
|
|
GHashTable *data_table_finalizers;
|
|
|
|
|
|
|
|
/* state flag: 'y' means 'open for editing',
|
|
|
|
* 'n' means 'book is closed'
|
|
|
|
* xxxxx shouldn't this be replaced by the instance editlevel ???
|
|
|
|
*/
|
|
|
|
char book_open;
|
|
|
|
|
|
|
|
/* a flag denoting whether the book is closing down, used to
|
|
|
|
* help the QOF objects shut down cleanly without maintaining
|
|
|
|
* internal consistency.
|
|
|
|
* XXX shouldn't this be replaced by instance->do_free ???
|
|
|
|
*/
|
|
|
|
gboolean shutting_down;
|
|
|
|
|
|
|
|
/* version number, used for tracking multiuser updates */
|
|
|
|
gint32 version;
|
|
|
|
|
|
|
|
/* To be technically correct, backends belong to sessions and
|
|
|
|
* not books. So the pointer below "really shouldn't be here",
|
|
|
|
* except that it provides a nice convenience, avoiding a lookup
|
|
|
|
* from the session. Better solutions welcome ... */
|
|
|
|
QofBackend *backend;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _QofBookClass
|
|
|
|
{
|
|
|
|
QofInstanceClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
GType qof_book_get_type(void);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** @brief Encapsulates all the information about a dataset
|
2006-01-08 11:51:29 -06:00
|
|
|
* manipulated by QOF. This is the top-most structure
|
2005-11-07 09:45:58 -06:00
|
|
|
* used for anchoring data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Lookup an entity by guid, returning pointer to the entity */
|
|
|
|
#define QOF_BOOK_LOOKUP_ENTITY(book,guid,e_type,c_type) ({ \
|
2007-04-01 17:18:50 -05:00
|
|
|
QofInstance *val = NULL; \
|
2005-11-07 09:45:58 -06:00
|
|
|
if (guid && book) { \
|
|
|
|
QofCollection *col; \
|
|
|
|
col = qof_book_get_collection (book, e_type); \
|
|
|
|
val = qof_collection_lookup_entity (col, guid); \
|
|
|
|
} \
|
|
|
|
(c_type *) val; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/** GList of QofBook */
|
|
|
|
typedef GList QofBookList;
|
|
|
|
|
|
|
|
typedef void (*QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data);
|
|
|
|
|
|
|
|
/** Register the book object with the QOF object system. */
|
|
|
|
gboolean qof_book_register (void);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
/** Allocate, initialise and return a new QofBook. Books contain references
|
|
|
|
* to all of the top-level object containers. */
|
|
|
|
QofBook * qof_book_new (void);
|
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
/** End any editing sessions associated with book, and free all memory
|
2005-11-07 09:45:58 -06:00
|
|
|
associated with it. */
|
|
|
|
void qof_book_destroy (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.
|
|
|
|
*/
|
|
|
|
void qof_book_mark_closed (QofBook *book);
|
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
/** Return The table of entities of the given type.
|
2005-11-07 09:45:58 -06:00
|
|
|
*
|
|
|
|
* 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.
|
2006-01-08 11:51:29 -06:00
|
|
|
*
|
2005-11-07 09:45:58 -06:00
|
|
|
* If the collection doesn't yet exist for the indicated type,
|
|
|
|
* it is created. Thus, this routine is gaurenteed to return
|
2006-01-08 11:51:29 -06:00
|
|
|
* a non-NULL value. (Unless the system malloc failed (out of
|
2005-11-07 09:45:58 -06:00
|
|
|
* memory) in which case what happens??).
|
|
|
|
*/
|
2006-08-17 23:48:18 -05:00
|
|
|
QofCollection * qof_book_get_collection (const QofBook *, QofIdType);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** Invoke the indicated callback on each collection in the book. */
|
|
|
|
typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data);
|
2006-08-17 23:48:18 -05:00
|
|
|
void qof_book_foreach_collection (const QofBook *, QofCollectionForeachCB, gpointer);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
/** Return The kvp data for the book.
|
|
|
|
* Note that the book KVP data is persistent, and is stored/retrieved
|
2005-11-07 09:45:58 -06:00
|
|
|
* from the file/database. Thus, the book KVP is the correct place to
|
2006-01-08 11:51:29 -06:00
|
|
|
* store data that needs to be persistent accross sessions (or shared
|
2005-11-07 09:45:58 -06:00
|
|
|
* 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))
|
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
/** The qof_book_set_data() allows arbitrary pointers to structs
|
|
|
|
* to be stored in QofBook. This is the "preferred" method for
|
2005-11-07 09:45:58 -06:00
|
|
|
* extending QofBook to hold new data types. This is also
|
2006-01-08 11:51:29 -06:00
|
|
|
* the ideal location to store other arbitrary runtime data
|
2005-11-07 09:45:58 -06:00
|
|
|
* that the application may need.
|
|
|
|
*
|
|
|
|
* The book data differs from the book KVP in that the contents
|
2006-01-08 11:51:29 -06:00
|
|
|
* of the book KVP are persistent (are saved and restored to file
|
2005-11-07 09:45:58 -06:00
|
|
|
* or database), whereas the data pointers exist only at runtime.
|
|
|
|
*/
|
2006-04-07 13:50:08 -05:00
|
|
|
void qof_book_set_data (QofBook *book, const gchar *key, gpointer data);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** Same as qof_book_set_data(), except that the callback will be called
|
2006-01-08 11:51:29 -06:00
|
|
|
* when the book is destroyed. The argument to the callback will be
|
2005-11-07 09:45:58 -06:00
|
|
|
* the book followed by the data pointer.
|
|
|
|
*/
|
2006-04-07 13:50:08 -05:00
|
|
|
void qof_book_set_data_fin (QofBook *book, const gchar *key, gpointer data,
|
2005-11-07 12:23:46 -06:00
|
|
|
QofBookFinalCB);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** Retrieves arbitrary pointers to structs stored by qof_book_set_data. */
|
2006-08-17 23:48:18 -05:00
|
|
|
gpointer qof_book_get_data (const QofBook *book, const gchar *key);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** Is the book shutting down? */
|
2006-08-17 23:48:18 -05:00
|
|
|
gboolean qof_book_shutting_down (const QofBook *book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
/** qof_book_not_saved() will return TRUE if any
|
2005-11-07 09:45:58 -06:00
|
|
|
* data in the book hasn't been saved to long-term storage.
|
2006-01-08 11:51:29 -06:00
|
|
|
* (Actually, that's not quite true. The book doesn't know
|
2005-11-07 09:45:58 -06:00
|
|
|
* anything about saving. Its just that whenever data is modified,
|
2006-01-08 11:51:29 -06:00
|
|
|
* the 'dirty' flag is set. This routine returns the value of the
|
|
|
|
* 'dirty' flag. Its up to the backend to periodically reset this
|
2005-11-07 09:45:58 -06:00
|
|
|
* flag, when it actually does save the data.)
|
|
|
|
*/
|
2006-08-17 23:48:18 -05:00
|
|
|
gboolean qof_book_not_saved (const QofBook *book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** 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
|
2006-01-08 11:51:29 -06:00
|
|
|
* notsaved flag as FALSE just after loading. Can also be used
|
|
|
|
* by the frontend when the used has said to abandon any changes.
|
2005-11-07 09:45:58 -06:00
|
|
|
*/
|
|
|
|
void qof_book_mark_saved(QofBook *book);
|
2006-05-06 16:09:59 -05:00
|
|
|
|
|
|
|
/** The qof_book_mark_dirty() routine marks the book as having been
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/** This debugging function can be used to traverse the book structure
|
|
|
|
* and all subsidiary structures, printing out which structures
|
|
|
|
* have been marked dirty.
|
|
|
|
*/
|
2006-08-17 23:48:18 -05:00
|
|
|
void qof_book_print_dirty (const QofBook *book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2006-05-06 16:09:59 -05:00
|
|
|
/** Retrieve the earliest modification time on the book. */
|
2006-08-17 23:48:18 -05:00
|
|
|
time_t qof_book_get_dirty_time(const QofBook *book);
|
2006-05-06 16:09:59 -05:00
|
|
|
|
|
|
|
/** Set the function to call when a book transitions from clean to
|
|
|
|
* dirty, or vice versa.
|
|
|
|
*/
|
|
|
|
void qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data);
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
/** Call this function when you change the book kvp, to make sure the book
|
|
|
|
* is marked 'dirty'. */
|
|
|
|
void qof_book_kvp_changed (QofBook *book);
|
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
/** The qof_book_equal() method returns TRUE if books are equal.
|
2005-11-07 09:45:58 -06:00
|
|
|
* XXX this routine is broken, and does not currently compare data.
|
|
|
|
*/
|
2006-08-17 23:48:18 -05:00
|
|
|
gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** This will 'get and increment' the named counter for this book.
|
|
|
|
* The return value is -1 on error or the incremented counter.
|
|
|
|
*/
|
2007-12-29 13:40:28 -06:00
|
|
|
gint64 qof_book_get_counter (const QofBook *book, const char *counter_name);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
/** deprecated */
|
2007-06-25 12:18:28 -05:00
|
|
|
#define qof_book_get_guid(X) qof_entity_get_guid (QOF_INSTANCE(X))
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
#endif /* QOF_BOOK_H */
|
|
|
|
/** @} */
|
|
|
|
/** @} */
|